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 #include <stdio.h> 43 #include <stdlib.h> 44 #include <unistd.h> 45 #include <sys/stat.h> 46 #include <sys/types.h> 47 #include <sys/param.h> 48 #include <sys/resource.h> 49 #include <pthread.h> 50 51 #include "vars.h" 52 #include "fb_avl.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_TYPE_FILE 0x00 63 #define FSE_TYPE_DIR 0x01 64 #define FSE_TYPE_LEAFDIR 0x02 65 #define FSE_TYPE_MASK 0x03 66 #define FSE_FREE 0x04 67 #define FSE_EXISTS 0x08 68 #define FSE_BUSY 0x10 69 #define FSE_REUSING 0x20 70 #define FSE_THRD_WAITNG 0x40 71 72 typedef struct filesetentry { 73 struct filesetentry *fse_next; /* master list of entries */ 74 struct filesetentry *fse_parent; /* link to directory */ 75 avl_node_t fse_link; /* links in avl btree, prot. */ 76 /* by fs_pick_lock */ 77 uint_t fse_index; /* file order number */ 78 struct filesetentry *fse_nextoftype; /* List of specific fse */ 79 struct fileset *fse_fileset; /* Parent fileset */ 80 char *fse_path; 81 int fse_depth; 82 off64_t fse_size; 83 int fse_open_cnt; /* protected by fs_pick_lock */ 84 int fse_flags; /* protected by fs_pick_lock */ 85 } filesetentry_t; 86 87 #define FSE_OFFSETOF(f) ((size_t)(&(((filesetentry_t *)0)->f))) 88 89 /* type of fileset entry to obtain */ 90 #define FILESET_PICKFILE 0x00 /* Pick a file from the set */ 91 #define FILESET_PICKDIR 0x01 /* Pick a directory */ 92 #define FILESET_PICKLEAFDIR 0x02 /* Pick a leaf directory */ 93 #define FILESET_PICKMASK 0x03 /* Pick type mask */ 94 /* other pick flags */ 95 #define FILESET_PICKUNIQUE 0x04 /* Pick a unique file or leafdir from the */ 96 /* fileset until empty */ 97 #define FILESET_PICKEXISTS 0x10 /* Pick an existing file */ 98 #define FILESET_PICKNOEXIST 0x20 /* Pick a file that doesn't exist */ 99 #define FILESET_PICKBYINDEX 0x40 /* use supplied index number to select file */ 100 #define FILESET_PICKFREE FILESET_PICKUNIQUE 101 102 /* fileset attributes */ 103 #define FILESET_IS_RAW_DEV 0x01 /* fileset is a raw device */ 104 #define FILESET_IS_FILE 0x02 /* Fileset is emulating a single file */ 105 106 typedef struct fileset { 107 struct fileset *fs_next; /* Next in list */ 108 avd_t fs_name; /* Name */ 109 avd_t fs_path; /* Pathname prefix in fileset */ 110 avd_t fs_entries; /* Number of entries attr */ 111 /* (possibly random) */ 112 fbint_t fs_constentries; /* Constant version of enties attr */ 113 avd_t fs_leafdirs; /* Number of leaf directories attr */ 114 /* (possibly random) */ 115 fbint_t fs_constleafdirs; /* Constant version of leafdirs */ 116 /* attr */ 117 avd_t fs_preallocpercent; /* Prealloc size */ 118 int fs_attrs; /* Attributes */ 119 avd_t fs_dirwidth; /* Explicit or mean for distribution */ 120 avd_t fs_dirdepthrv; /* random variable for dir depth */ 121 avd_t fs_size; /* Explicit or mean for distribution */ 122 avd_t fs_dirgamma; /* Dirdepth Gamma distribution */ 123 /* (* 1000) defaults to 1500, set */ 124 /* to 0 for explicit depth */ 125 avd_t fs_sizegamma; /* Filesize and dirwidth Gamma */ 126 /* distribution (* 1000), default */ 127 /* is 1500, set to 0 for explicit */ 128 avd_t fs_create; /* Attr */ 129 avd_t fs_prealloc; /* Attr */ 130 avd_t fs_paralloc; /* Attr */ 131 avd_t fs_cached; /* Attr */ 132 avd_t fs_reuse; /* Attr */ 133 double fs_meandepth; /* Computed mean depth */ 134 double fs_meanwidth; /* Specified mean dir width */ 135 double fs_meansize; /* Specified mean file size */ 136 int fs_realfiles; /* Actual files */ 137 int fs_realleafdirs; /* Actual explicit leaf directories */ 138 off64_t fs_bytes; /* Total space consumed by files */ 139 140 int64_t fs_idle_files; /* number of files NOT busy */ 141 pthread_cond_t fs_idle_files_cv; /* idle files condition variable */ 142 143 int64_t fs_idle_dirs; /* number of dirs NOT busy */ 144 pthread_cond_t fs_idle_dirs_cv; /* idle dirs condition variable */ 145 146 int64_t fs_idle_leafdirs; /* number of dirs NOT busy */ 147 pthread_cond_t fs_idle_leafdirs_cv; /* idle dirs condition variable */ 148 149 pthread_mutex_t fs_pick_lock; /* per fileset "pick" function lock */ 150 pthread_cond_t fs_thrd_wait_cv; /* per fileset file busy wait cv */ 151 avl_tree_t fs_free_files; /* btree of free files */ 152 avl_tree_t fs_exist_files; /* btree of files on device */ 153 avl_tree_t fs_noex_files; /* btree of files NOT on device */ 154 avl_tree_t fs_dirs; /* btree of internal dirs */ 155 avl_tree_t fs_free_leaf_dirs; /* btree of free leaf dirs */ 156 avl_tree_t fs_exist_leaf_dirs; /* btree of leaf dirs on device */ 157 avl_tree_t fs_noex_leaf_dirs; /* btree of leaf dirs NOT */ 158 /* currently on device */ 159 filesetentry_t *fs_filelist; /* List of files */ 160 uint_t fs_file_exrotor[FSE_MAXTID]; /* next file to */ 161 /* select */ 162 uint_t fs_file_nerotor; /* next non existent file */ 163 /* to select for createfile */ 164 filesetentry_t *fs_dirlist; /* List of directories */ 165 uint_t fs_dirrotor; /* index of next directory to select */ 166 filesetentry_t *fs_leafdirlist; /* List of leaf directories */ 167 uint_t fs_leafdir_exrotor; /* Ptr to next existing leaf */ 168 /* directory to select */ 169 uint_t fs_leafdir_nerotor; /* Ptr to next non-existing */ 170 int *fs_filehistop; /* Ptr to access histogram */ 171 int fs_histo_id; /* shared memory id for filehisto */ 172 pthread_mutex_t fs_histo_lock; /* lock for incr of histo */ 173 } fileset_t; 174 175 int fileset_createset(fileset_t *); 176 int fileset_openfile(fileset_t *fileset, filesetentry_t *entry, 177 int flag, int mode, int attrs); 178 fileset_t *fileset_define(avd_t); 179 fileset_t *fileset_find(char *name); 180 filesetentry_t *fileset_pick(fileset_t *fileset, int flags, int tid, 181 int index); 182 char *fileset_resolvepath(filesetentry_t *entry); 183 void fileset_usage(void); 184 int fileset_iter(int (*cmd)(fileset_t *fileset, int first)); 185 int fileset_print(fileset_t *fileset, int first); 186 void fileset_unbusy(filesetentry_t *entry, int update_exist, 187 int new_exist_val, int open_cnt_incr); 188 int fileset_dump_histo(fileset_t *fileset, int first); 189 void fileset_attach_all_histos(void); 190 191 #ifdef __cplusplus 192 } 193 #endif 194 195 #endif /* _FB_FILESET_H */ 196