xref: /onnv-gate/usr/src/cmd/filebench/common/fileset.h (revision 7556:55f6926392fe)
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 2008 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 #include "filebench.h"
30 #include "config.h"
31 
32 #ifndef HAVE_OFF64_T
33 /*
34  * We are probably on linux.
35  * According to http://www.suse.de/~aj/linux_lfs.html, defining the
36  * above, automatically changes type of off_t to off64_t. so let
37  * us use only off_t as off64_t is not defined
38  */
39 #define	off64_t off_t
40 #endif /* HAVE_OFF64_T */
41 
42 
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <unistd.h>
46 #include <sys/stat.h>
47 #include <sys/types.h>
48 #include <sys/param.h>
49 #include <sys/resource.h>
50 #include <pthread.h>
51 
52 #include "vars.h"
53 #define	FILE_ALLOC_BLOCK (off64_t)(1024 * 1024)
54 
55 #ifdef	__cplusplus
56 extern "C" {
57 #endif
58 
59 #define	FSE_MAXTID 16384
60 
61 #define	FSE_MAXPATHLEN 16
62 #define	FSE_DIR		0x01
63 #define	FSE_FREE	0x02
64 #define	FSE_EXISTS	0x04
65 #define	FSE_BUSY	0x08
66 #define	FSE_THRD_WAITNG	0x10
67 #define	FSE_REUSING	0x20
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 	char			*fse_path;
76 	int			fse_depth;
77 	off64_t			fse_size;
78 	int			fse_flags;	/* protected by fs_pick_lock */
79 } filesetentry_t;
80 
81 #define	FILESET_PICKANY	    0x1 /* Pick any file from the set */
82 #define	FILESET_PICKUNIQUE  0x2 /* Pick a unique file from set until empty */
83 #define	FILESET_PICKRESET   0x4 /* Reset FILESET_PICKUNIQUE selection list */
84 #define	FILESET_PICKDIR	    0x8 /* Pick a directory */
85 #define	FILESET_PICKEXISTS  0x10 /* Pick an existing file */
86 #define	FILESET_PICKNOEXIST 0x20 /* Pick a file that doesn't exist */
87 
88 /* fileset attributes */
89 #define	FILESET_IS_RAW_DEV  0x01 /* fileset is a raw device */
90 #define	FILESET_IS_FILE	    0x02 /* Fileset is emulating a single file */
91 
92 typedef struct fileset {
93 	struct fileset	*fs_next;	/* Next in list */
94 	avd_t		fs_name;	/* Name */
95 	avd_t		fs_path;	/* Pathname prefix in fileset */
96 	avd_t		fs_entries;	/* Number of entries attr */
97 					/* (possibly random) */
98 	fbint_t		fs_constentries; /* Constant version of enties attr */
99 	avd_t		fs_preallocpercent; /* Prealloc size */
100 	int		fs_attrs;	/* Attributes */
101 	avd_t		fs_dirwidth;	/* Explicit or mean for distribution */
102 	avd_t		fs_dirdepthrv;	/* random variable for dir depth */
103 	avd_t		fs_size;	/* Explicit or mean for distribution */
104 	avd_t		fs_dirgamma;	/* Dirdepth Gamma distribution */
105 					/* (* 1000) defaults to 1500, set */
106 					/* to 0 for explicit depth */
107 	avd_t		fs_sizegamma;	/* Filesize and dirwidth Gamma */
108 					/* distribution (* 1000), default */
109 					/* is 1500, set to 0 for explicit */
110 	avd_t		fs_create;	/* Attr */
111 	avd_t		fs_prealloc;	/* Attr */
112 	avd_t		fs_paralloc;	/* Attr */
113 	avd_t		fs_cached;	/* Attr */
114 	avd_t		fs_reuse;	/* Attr */
115 	double		fs_meandepth;	/* Computed mean depth */
116 	double		fs_meanwidth;	/* Specified mean dir width */
117 	double		fs_meansize;	/* Specified mean file size */
118 	int		fs_realfiles;	/* Actual files */
119 	off64_t		fs_bytes;	/* Total space consumed by files */
120 	fbint_t		fs_num_act_files;   /* total number of files */
121 					    /* actually existing in the */
122 					    /* host or server's file system */
123 	fbint_t		fs_num_act_dirs;   /* total number of directories */
124 					    /* actually existing in the */
125 					    /* host or server's file system */
126 	int64_t		fs_idle_files;	/* number of files NOT busy */
127 	pthread_cond_t	fs_idle_files_cv; /* idle files condition variable */
128 	int64_t		fs_idle_dirs;	/* number of dirs NOT busy */
129 	pthread_cond_t	fs_idle_dirs_cv; /* idle dirs condition variable */
130 	pthread_mutex_t	fs_pick_lock;	/* per fileset "pick" function lock */
131 	pthread_cond_t	fs_thrd_wait_cv; /* per fileset file busy wait cv */
132 	filesetentry_t	*fs_filelist;	/* List of files */
133 	filesetentry_t	*fs_dirlist;	/* List of directories */
134 	filesetentry_t	*fs_filefree;	/* Ptr to next free file */
135 	filesetentry_t	*fs_dirfree;	/* Ptr to next free directory */
136 	filesetentry_t	*fs_filerotor[FSE_MAXTID];	/* next file to */
137 							/* select */
138 	filesetentry_t	*fs_file_ne_rotor;	/* next non existent file */
139 						/* to select for createfile */
140 	filesetentry_t	*fs_dirrotor;	/* Ptr to next directory to select */
141 } fileset_t;
142 
143 int fileset_createset(fileset_t *);
144 int fileset_openfile(fileset_t *fileset, filesetentry_t *entry,
145     int flag, int mode, int attrs);
146 fileset_t *fileset_define(avd_t);
147 fileset_t *fileset_find(char *name);
148 filesetentry_t *fileset_pick(fileset_t *fileset, int flags, int tid);
149 char *fileset_resolvepath(filesetentry_t *entry);
150 void fileset_usage(void);
151 void fileset_iter(int (*cmd)(fileset_t *fileset, int first));
152 int fileset_print(fileset_t *fileset, int first);
153 void fileset_unbusy(filesetentry_t *entry, int update_exist,
154     int new_exist_val);
155 
156 #ifdef	__cplusplus
157 }
158 #endif
159 
160 #endif	/* _FB_FILESET_H */
161