xref: /onnv-gate/usr/src/cmd/filebench/common/fileset.h (revision 5673:043503f0cca3)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _FB_FILESET_H
27 #define	_FB_FILESET_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include "config.h"
32 
33 #ifndef HAVE_OFF64_T
34 /*
35  * We are probably on linux.
36  * According to http://www.suse.de/~aj/linux_lfs.html, defining the
37  * above, automatically changes type of off_t to off64_t. so let
38  * us use only off_t as off64_t is not defined
39  */
40 #define	off64_t off_t
41 #endif /* HAVE_OFF64_T */
42 
43 
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <unistd.h>
47 #include <sys/stat.h>
48 #include <sys/types.h>
49 #include <sys/param.h>
50 #include <sys/resource.h>
51 #include <pthread.h>
52 
53 #include "vars.h"
54 #define	FILE_ALLOC_BLOCK (off64_t)(1024 * 1024)
55 
56 #ifdef	__cplusplus
57 extern "C" {
58 #endif
59 
60 #define	FSE_MAXTID 16384
61 
62 #define	FSE_MAXPATHLEN 16
63 #define	FSE_DIR		0x01
64 #define	FSE_FREE	0x02
65 #define	FSE_EXISTS	0x04
66 #define	FSE_BUSY	0x08
67 #define	FSE_REUSING	0x10
68 
69 typedef struct filesetentry {
70 	struct filesetentry	*fse_next;
71 	struct filesetentry	*fse_parent;
72 	struct filesetentry	*fse_filenext;	/* List of files */
73 	struct filesetentry	*fse_dirnext;	/* List of directories */
74 	struct fileset		*fse_fileset;	/* Parent fileset */
75 	pthread_mutex_t		fse_lock;
76 	char			*fse_path;
77 	int			fse_depth;
78 	off64_t			fse_size;
79 	int			fse_flags;
80 } filesetentry_t;
81 
82 #define	FILESET_PICKANY	    0x1 /* Pick any file from the set */
83 #define	FILESET_PICKUNIQUE  0x2 /* Pick a unique file from set until empty */
84 #define	FILESET_PICKRESET   0x4 /* Reset FILESET_PICKUNIQUE selection list */
85 #define	FILESET_PICKDIR	    0x8 /* Pick a directory */
86 #define	FILESET_PICKEXISTS  0x10 /* Pick an existing file */
87 #define	FILESET_PICKNOEXIST 0x20 /* Pick a file that doesn't exist */
88 
89 /* fileset attributes */
90 #define	FILESET_IS_RAW_DEV  0x01 /* fileset is a raw device */
91 #define	FILESET_IS_FILE	    0x02 /* Fileset is emulating a single file */
92 
93 typedef struct fileset {
94 	struct fileset	*fs_next;	/* Next in list */
95 	char		fs_name[128];	/* Name */
96 	var_string_t	fs_path;	/* Pathname prefix in fs */
97 	var_integer_t	fs_entries;	/* Set size */
98 	var_integer_t	fs_preallocpercent; /* Prealloc size */
99 	int		fs_attrs;	/* Attributes */
100 	var_integer_t	fs_dirwidth;	/* Explicit or 0 for distribution */
101 	var_integer_t	fs_size;	/* Explicit or 0 for distribution */
102 	var_integer_t	fs_dirgamma;  /* Dirwidth Gamma distribution (* 1000) */
103 	var_integer_t	fs_sizegamma; /* Filesize Gamma distribution (* 1000) */
104 	var_integer_t	fs_create;	/* Attr */
105 	var_integer_t	fs_prealloc;	/* Attr */
106 	var_integer_t	fs_paralloc;	/* Attr */
107 	var_integer_t	fs_cached;	/* Attr */
108 	var_integer_t	fs_reuse;	/* Attr */
109 	double		fs_meandepth;	/* Computed mean depth */
110 	double		fs_meanwidth;	/* Specified mean dir width */
111 	double		fs_meansize;	/* Specified mean file size */
112 	int		fs_realfiles;	/* Actual files */
113 	off64_t		fs_bytes; /* Space potentially consumed by all files */
114 	filesetentry_t	*fs_filelist;	/* List of files */
115 	filesetentry_t	*fs_dirlist;	/* List of directories */
116 	filesetentry_t	*fs_filefree;	/* Ptr to next free file */
117 	filesetentry_t	*fs_dirfree;	/* Ptr to next free directory */
118 	filesetentry_t	*fs_filerotor[FSE_MAXTID]; /* next file to select */
119 	filesetentry_t	*fs_dirrotor;	/* Ptr to next directory to select */
120 } fileset_t;
121 
122 int fileset_createset(fileset_t *);
123 int fileset_openfile(fileset_t *fileset, filesetentry_t *entry,
124     int flag, int mode, int attrs);
125 fileset_t *fileset_define(char *);
126 fileset_t *fileset_find(char *name);
127 filesetentry_t *fileset_pick(fileset_t *fileset, int flags, int tid);
128 char *fileset_resolvepath(filesetentry_t *entry);
129 void fileset_usage(void);
130 void fileset_iter(int (*cmd)(fileset_t *fileset, int first));
131 int fileset_print(fileset_t *fileset, int first);
132 int fileset_checkraw(fileset_t *fileset);
133 
134 
135 #ifdef	__cplusplus
136 }
137 #endif
138 
139 #endif	/* _FB_FILESET_H */
140