Home | History | Annotate | Download | only in common
      1  5184  ek110237 /*
      2  5184  ek110237  * CDDL HEADER START
      3  5184  ek110237  *
      4  5184  ek110237  * The contents of this file are subject to the terms of the
      5  5184  ek110237  * Common Development and Distribution License (the "License").
      6  5184  ek110237  * You may not use this file except in compliance with the License.
      7  5184  ek110237  *
      8  5184  ek110237  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  5184  ek110237  * or http://www.opensolaris.org/os/licensing.
     10  5184  ek110237  * See the License for the specific language governing permissions
     11  5184  ek110237  * and limitations under the License.
     12  5184  ek110237  *
     13  5184  ek110237  * When distributing Covered Code, include this CDDL HEADER in each
     14  5184  ek110237  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  5184  ek110237  * If applicable, add the following below this CDDL HEADER, with the
     16  5184  ek110237  * fields enclosed by brackets "[]" replaced with your own identifying
     17  5184  ek110237  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  5184  ek110237  *
     19  5184  ek110237  * CDDL HEADER END
     20  5184  ek110237  */
     21  5184  ek110237 /*
     22  8615    Andrew  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     23  5184  ek110237  * Use is subject to license terms.
     24  5184  ek110237  */
     25  5184  ek110237 
     26  5184  ek110237 #ifndef _FB_FILESET_H
     27  5184  ek110237 #define	_FB_FILESET_H
     28  5184  ek110237 
     29  7556    Andrew #include "filebench.h"
     30  5184  ek110237 #include "config.h"
     31  5184  ek110237 
     32  5184  ek110237 #ifndef HAVE_OFF64_T
     33  5184  ek110237 /*
     34  5184  ek110237  * We are probably on linux.
     35  5184  ek110237  * According to http://www.suse.de/~aj/linux_lfs.html, defining the
     36  5184  ek110237  * above, automatically changes type of off_t to off64_t. so let
     37  5184  ek110237  * us use only off_t as off64_t is not defined
     38  5184  ek110237  */
     39  5184  ek110237 #define	off64_t off_t
     40  5184  ek110237 #endif /* HAVE_OFF64_T */
     41  5184  ek110237 
     42  5184  ek110237 #include <stdio.h>
     43  5184  ek110237 #include <stdlib.h>
     44  5184  ek110237 #include <unistd.h>
     45  5184  ek110237 #include <sys/stat.h>
     46  5184  ek110237 #include <sys/types.h>
     47  5184  ek110237 #include <sys/param.h>
     48  5184  ek110237 #include <sys/resource.h>
     49  5184  ek110237 #include <pthread.h>
     50  5184  ek110237 
     51  5673  aw148015 #include "vars.h"
     52  8404    Andrew #include "fb_avl.h"
     53  8615    Andrew 
     54  5673  aw148015 #define	FILE_ALLOC_BLOCK (off64_t)(1024 * 1024)
     55  5184  ek110237 
     56  5184  ek110237 #ifdef	__cplusplus
     57  5184  ek110237 extern "C" {
     58  5184  ek110237 #endif
     59  5184  ek110237 
     60  5184  ek110237 #define	FSE_MAXTID 16384
     61  5184  ek110237 
     62  5184  ek110237 #define	FSE_MAXPATHLEN 16
     63  7946    Andrew #define	FSE_TYPE_FILE		0x00
     64  7946    Andrew #define	FSE_TYPE_DIR		0x01
     65  7946    Andrew #define	FSE_TYPE_LEAFDIR	0x02
     66  7946    Andrew #define	FSE_TYPE_MASK		0x03
     67  7946    Andrew #define	FSE_FREE		0x04
     68  7946    Andrew #define	FSE_EXISTS		0x08
     69  7946    Andrew #define	FSE_BUSY		0x10
     70  7946    Andrew #define	FSE_REUSING		0x20
     71  7946    Andrew #define	FSE_THRD_WAITNG		0x40
     72  5184  ek110237 
     73  5184  ek110237 typedef struct filesetentry {
     74  8404    Andrew 	struct filesetentry	*fse_next;	/* master list of entries */
     75  8404    Andrew 	struct filesetentry	*fse_parent;	/* link to directory */
     76  8404    Andrew 	avl_node_t		fse_link;	/* links in avl btree, prot. */
     77  8404    Andrew 						/*    by fs_pick_lock */
     78  8404    Andrew 	uint_t			fse_index;	/* file order number */
     79  8404    Andrew 	struct filesetentry	*fse_nextoftype; /* List of specific fse */
     80  5184  ek110237 	struct fileset		*fse_fileset;	/* Parent fileset */
     81  5184  ek110237 	char			*fse_path;
     82  5184  ek110237 	int			fse_depth;
     83  5184  ek110237 	off64_t			fse_size;
     84  8404    Andrew 	int			fse_open_cnt;	/* protected by fs_pick_lock */
     85  7556    Andrew 	int			fse_flags;	/* protected by fs_pick_lock */
     86  5184  ek110237 } filesetentry_t;
     87  8404    Andrew 
     88  8404    Andrew #define	FSE_OFFSETOF(f)	((size_t)(&(((filesetentry_t *)0)->f)))
     89  5184  ek110237 
     90  7946    Andrew /* type of fileset entry to obtain */
     91  7946    Andrew #define	FILESET_PICKFILE    0x00 /* Pick a file from the set */
     92  7946    Andrew #define	FILESET_PICKDIR	    0x01 /* Pick a directory */
     93  7946    Andrew #define	FILESET_PICKLEAFDIR 0x02 /* Pick a leaf directory */
     94  7946    Andrew #define	FILESET_PICKMASK    0x03 /* Pick type mask */
     95  7946    Andrew /* other pick flags */
     96  7946    Andrew #define	FILESET_PICKUNIQUE  0x04 /* Pick a unique file or leafdir from the */
     97  7946    Andrew 				    /* fileset until empty */
     98  5184  ek110237 #define	FILESET_PICKEXISTS  0x10 /* Pick an existing file */
     99  5184  ek110237 #define	FILESET_PICKNOEXIST 0x20 /* Pick a file that doesn't exist */
    100  8404    Andrew #define	FILESET_PICKBYINDEX 0x40 /* use supplied index number to select file */
    101  8404    Andrew #define	FILESET_PICKFREE    FILESET_PICKUNIQUE
    102  5184  ek110237 
    103  5673  aw148015 /* fileset attributes */
    104  5673  aw148015 #define	FILESET_IS_RAW_DEV  0x01 /* fileset is a raw device */
    105  5673  aw148015 #define	FILESET_IS_FILE	    0x02 /* Fileset is emulating a single file */
    106  5673  aw148015 
    107  5184  ek110237 typedef struct fileset {
    108  5184  ek110237 	struct fileset	*fs_next;	/* Next in list */
    109  6212  aw148015 	avd_t		fs_name;	/* Name */
    110  6212  aw148015 	avd_t		fs_path;	/* Pathname prefix in fileset */
    111  6212  aw148015 	avd_t		fs_entries;	/* Number of entries attr */
    112  6212  aw148015 					/* (possibly random) */
    113  6212  aw148015 	fbint_t		fs_constentries; /* Constant version of enties attr */
    114  7946    Andrew 	avd_t		fs_leafdirs;	/* Number of leaf directories attr */
    115  7946    Andrew 					/* (possibly random) */
    116  7946    Andrew 	fbint_t		fs_constleafdirs; /* Constant version of leafdirs */
    117  7946    Andrew 					    /* attr */
    118  6212  aw148015 	avd_t		fs_preallocpercent; /* Prealloc size */
    119  5184  ek110237 	int		fs_attrs;	/* Attributes */
    120  6212  aw148015 	avd_t		fs_dirwidth;	/* Explicit or mean for distribution */
    121  6212  aw148015 	avd_t		fs_dirdepthrv;	/* random variable for dir depth */
    122  6212  aw148015 	avd_t		fs_size;	/* Explicit or mean for distribution */
    123  6212  aw148015 	avd_t		fs_dirgamma;	/* Dirdepth Gamma distribution */
    124  6212  aw148015 					/* (* 1000) defaults to 1500, set */
    125  6212  aw148015 					/* to 0 for explicit depth */
    126  6212  aw148015 	avd_t		fs_sizegamma;	/* Filesize and dirwidth Gamma */
    127  6212  aw148015 					/* distribution (* 1000), default */
    128  6212  aw148015 					/* is 1500, set to 0 for explicit */
    129  6212  aw148015 	avd_t		fs_create;	/* Attr */
    130  6212  aw148015 	avd_t		fs_prealloc;	/* Attr */
    131  6212  aw148015 	avd_t		fs_paralloc;	/* Attr */
    132  6212  aw148015 	avd_t		fs_cached;	/* Attr */
    133  6212  aw148015 	avd_t		fs_reuse;	/* Attr */
    134  9326    Andrew 	avd_t		fs_readonly;	/* Attr */
    135  9326    Andrew 	avd_t		fs_trust_tree;	/* Attr */
    136  5184  ek110237 	double		fs_meandepth;	/* Computed mean depth */
    137  5184  ek110237 	double		fs_meanwidth;	/* Specified mean dir width */
    138  5184  ek110237 	double		fs_meansize;	/* Specified mean file size */
    139  5184  ek110237 	int		fs_realfiles;	/* Actual files */
    140  7946    Andrew 	int		fs_realleafdirs; /* Actual explicit leaf directories */
    141  6212  aw148015 	off64_t		fs_bytes;	/* Total space consumed by files */
    142  7946    Andrew 
    143  7946    Andrew 	int64_t		fs_idle_files;	/* number of files NOT busy */
    144  7946    Andrew 	pthread_cond_t	fs_idle_files_cv; /* idle files condition variable */
    145  8404    Andrew 
    146  7946    Andrew 	int64_t		fs_idle_dirs;	/* number of dirs NOT busy */
    147  7946    Andrew 	pthread_cond_t	fs_idle_dirs_cv; /* idle dirs condition variable */
    148  7946    Andrew 
    149  7946    Andrew 	int64_t		fs_idle_leafdirs; /* number of dirs NOT busy */
    150  7946    Andrew 	pthread_cond_t	fs_idle_leafdirs_cv; /* idle dirs condition variable */
    151  8404    Andrew 
    152  7556    Andrew 	pthread_mutex_t	fs_pick_lock;	/* per fileset "pick" function lock */
    153  7556    Andrew 	pthread_cond_t	fs_thrd_wait_cv; /* per fileset file busy wait cv */
    154  8404    Andrew 	avl_tree_t	fs_free_files;	/* btree of free files */
    155  8404    Andrew 	avl_tree_t	fs_exist_files;	/* btree of files on device */
    156  8404    Andrew 	avl_tree_t	fs_noex_files;	/* btree of files NOT on device */
    157  8404    Andrew 	avl_tree_t	fs_dirs;	/* btree of internal dirs */
    158  8404    Andrew 	avl_tree_t	fs_free_leaf_dirs; /* btree of free leaf dirs */
    159  8404    Andrew 	avl_tree_t	fs_exist_leaf_dirs; /* btree of leaf dirs on device */
    160  8404    Andrew 	avl_tree_t	fs_noex_leaf_dirs;  /* btree of leaf dirs NOT */
    161  8404    Andrew 					    /* currently on device */
    162  5184  ek110237 	filesetentry_t	*fs_filelist;	/* List of files */
    163  8404    Andrew 	uint_t		fs_file_exrotor[FSE_MAXTID];	/* next file to */
    164  6212  aw148015 							/* select */
    165  8404    Andrew 	uint_t		fs_file_nerotor;	/* next non existent file */
    166  7556    Andrew 						/* to select for createfile */
    167  7946    Andrew 	filesetentry_t	*fs_dirlist;	/* List of directories */
    168  8404    Andrew 	uint_t		fs_dirrotor;	/* index of next directory to select */
    169  7946    Andrew 	filesetentry_t	*fs_leafdirlist; /* List of leaf directories */
    170  8404    Andrew 	uint_t		fs_leafdir_exrotor;	/* Ptr to next existing leaf */
    171  7946    Andrew 						/* directory to select */
    172  8404    Andrew 	uint_t		fs_leafdir_nerotor;	/* Ptr to next non-existing */
    173  8404    Andrew 	int		*fs_filehistop;		/* Ptr to access histogram */
    174  8404    Andrew 	int		fs_histo_id;	/* shared memory id for filehisto */
    175  8404    Andrew 	pthread_mutex_t	fs_histo_lock;	/* lock for incr of histo */
    176  5184  ek110237 } fileset_t;
    177  5184  ek110237 
    178  5184  ek110237 int fileset_createset(fileset_t *);
    179  9356    Andrew void fileset_delete_all_filesets(void);
    180  8615    Andrew int fileset_openfile(fb_fdesc_t *fd, fileset_t *fileset,
    181  8615    Andrew     filesetentry_t *entry, int flag, int mode, int attrs);
    182  6212  aw148015 fileset_t *fileset_define(avd_t);
    183  5184  ek110237 fileset_t *fileset_find(char *name);
    184  8404    Andrew filesetentry_t *fileset_pick(fileset_t *fileset, int flags, int tid,
    185  8404    Andrew     int index);
    186  5184  ek110237 char *fileset_resolvepath(filesetentry_t *entry);
    187  5184  ek110237 void fileset_usage(void);
    188  8404    Andrew int fileset_iter(int (*cmd)(fileset_t *fileset, int first));
    189  5673  aw148015 int fileset_print(fileset_t *fileset, int first);
    190  7556    Andrew void fileset_unbusy(filesetentry_t *entry, int update_exist,
    191  8404    Andrew     int new_exist_val, int open_cnt_incr);
    192  8404    Andrew int fileset_dump_histo(fileset_t *fileset, int first);
    193  8404    Andrew void fileset_attach_all_histos(void);
    194  5184  ek110237 
    195  5184  ek110237 #ifdef	__cplusplus
    196  5184  ek110237 }
    197  5184  ek110237 #endif
    198  5184  ek110237 
    199  5184  ek110237 #endif	/* _FB_FILESET_H */
    200