xref: /onnv-gate/usr/src/cmd/filebench/common/fileset.h (revision 5184:da60d2b4a9e2)
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 "fileobj.h"
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		0x1
63 #define	FSE_FREE	0x2
64 #define	FSE_EXISTS	0x4
65 #define	FSE_BUSY	0x8
66 
67 typedef struct filesetentry {
68 	struct filesetentry	*fse_next;
69 	struct filesetentry	*fse_parent;
70 	struct filesetentry	*fse_filenext;	/* List of files */
71 	struct filesetentry	*fse_dirnext;	/* List of directories */
72 	struct fileset		*fse_fileset;	/* Parent fileset */
73 	pthread_mutex_t		fse_lock;
74 	char			*fse_path;
75 	int			fse_depth;
76 	off64_t			fse_size;
77 	int			fse_flags;
78 } filesetentry_t;
79 
80 #define	FILESET_PICKANY	    0x1 /* Pick any file from the set */
81 #define	FILESET_PICKUNIQUE  0x2 /* Pick a unique file from set until empty */
82 #define	FILESET_PICKRESET   0x4 /* Reset FILESET_PICKUNIQUE selection list */
83 #define	FILESET_PICKDIR	    0x8 /* Pick a directory */
84 #define	FILESET_PICKEXISTS  0x10 /* Pick an existing file */
85 #define	FILESET_PICKNOEXIST 0x20 /* Pick a file that doesn't exist */
86 
87 typedef struct fileset {
88 	struct fileset	*fs_next;	/* Next in list */
89 	char		fs_name[128];	/* Name */
90 	pthread_t	fs_tid;		/* Thread id, for par alloc */
91 	var_string_t	fs_path;	/* Pathname prefix in fs */
92 	var_integer_t	fs_entries;	/* Set size */
93 	var_integer_t	fs_preallocpercent; /* Prealloc size */
94 	int		fs_attrs;	/* Attributes */
95 	var_integer_t	fs_dirwidth;	/* Explicit or 0 for distribution */
96 	var_integer_t	fs_size;	/* Explicit or 0 for distribution */
97 	var_integer_t	fs_dirgamma;  /* Dirwidth Gamma distribution (* 1000) */
98 	var_integer_t	fs_sizegamma; /* Filesize Gamma distribution (* 1000) */
99 	var_integer_t	fs_create;	/* Attr */
100 	var_integer_t	fs_prealloc;	/* Attr */
101 	var_integer_t	fs_cached;	/* Attr */
102 	var_integer_t	fs_reuse;	/* Attr */
103 	double		fs_meandepth;	/* Computed mean depth */
104 	double		fs_meanwidth;	/* Specified mean dir width */
105 	double		fs_meansize;	/* Specified mean file size */
106 	int		fs_realfiles;	/* Actual files */
107 	off64_t		fs_bytes; /* Space potentially consumed by all files */
108 	filesetentry_t	*fs_filelist;	/* List of files */
109 	filesetentry_t	*fs_dirlist;	/* List of directories */
110 	filesetentry_t	*fs_filefree;	/* Ptr to next free file */
111 	filesetentry_t	*fs_dirfree;	/* Ptr to next free directory */
112 	filesetentry_t	*fs_filerotor[FSE_MAXTID]; /* next file to select */
113 	filesetentry_t	*fs_dirrotor;	/* Ptr to next directory to select */
114 } fileset_t;
115 
116 int fileset_createset(fileset_t *);
117 int fileset_openfile(fileset_t *fileset, filesetentry_t *entry,
118     int flag, int mode, int attrs);
119 fileset_t *fileset_define(char *);
120 fileset_t *fileset_find(char *name);
121 filesetentry_t *fileset_pick(fileset_t *fileset, int flags, int tid);
122 char *fileset_resolvepath(filesetentry_t *entry);
123 void fileset_usage(void);
124 
125 #ifdef	__cplusplus
126 }
127 #endif
128 
129 #endif	/* _FB_FILESET_H */
130