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_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; 74 struct filesetentry *fse_parent; 75 struct filesetentry *fse_filenext; /* List of files */ 76 struct filesetentry *fse_dirnext; /* List of directories */ 77 struct filesetentry *fse_leafdirnext; /* List of leaf dirs */ 78 struct fileset *fse_fileset; /* Parent fileset */ 79 char *fse_path; 80 int fse_depth; 81 off64_t fse_size; 82 int fse_flags; /* protected by fs_pick_lock */ 83 } filesetentry_t; 84 85 /* type of fileset entry to obtain */ 86 #define FILESET_PICKFILE 0x00 /* Pick a file from the set */ 87 #define FILESET_PICKDIR 0x01 /* Pick a directory */ 88 #define FILESET_PICKLEAFDIR 0x02 /* Pick a leaf directory */ 89 #define FILESET_PICKMASK 0x03 /* Pick type mask */ 90 /* other pick flags */ 91 #define FILESET_PICKUNIQUE 0x04 /* Pick a unique file or leafdir from the */ 92 /* fileset until empty */ 93 #define FILESET_PICKRESET 0x08 /* Reset FILESET_PICKUNIQUE selection list */ 94 #define FILESET_PICKEXISTS 0x10 /* Pick an existing file */ 95 #define FILESET_PICKNOEXIST 0x20 /* Pick a file that doesn't exist */ 96 97 /* fileset attributes */ 98 #define FILESET_IS_RAW_DEV 0x01 /* fileset is a raw device */ 99 #define FILESET_IS_FILE 0x02 /* Fileset is emulating a single file */ 100 101 typedef struct fileset { 102 struct fileset *fs_next; /* Next in list */ 103 avd_t fs_name; /* Name */ 104 avd_t fs_path; /* Pathname prefix in fileset */ 105 avd_t fs_entries; /* Number of entries attr */ 106 /* (possibly random) */ 107 fbint_t fs_constentries; /* Constant version of enties attr */ 108 avd_t fs_leafdirs; /* Number of leaf directories attr */ 109 /* (possibly random) */ 110 fbint_t fs_constleafdirs; /* Constant version of leafdirs */ 111 /* attr */ 112 avd_t fs_preallocpercent; /* Prealloc size */ 113 int fs_attrs; /* Attributes */ 114 avd_t fs_dirwidth; /* Explicit or mean for distribution */ 115 avd_t fs_dirdepthrv; /* random variable for dir depth */ 116 avd_t fs_size; /* Explicit or mean for distribution */ 117 avd_t fs_dirgamma; /* Dirdepth Gamma distribution */ 118 /* (* 1000) defaults to 1500, set */ 119 /* to 0 for explicit depth */ 120 avd_t fs_sizegamma; /* Filesize and dirwidth Gamma */ 121 /* distribution (* 1000), default */ 122 /* is 1500, set to 0 for explicit */ 123 avd_t fs_create; /* Attr */ 124 avd_t fs_prealloc; /* Attr */ 125 avd_t fs_paralloc; /* Attr */ 126 avd_t fs_cached; /* Attr */ 127 avd_t fs_reuse; /* Attr */ 128 double fs_meandepth; /* Computed mean depth */ 129 double fs_meanwidth; /* Specified mean dir width */ 130 double fs_meansize; /* Specified mean file size */ 131 int fs_realfiles; /* Actual files */ 132 int fs_realleafdirs; /* Actual explicit leaf directories */ 133 off64_t fs_bytes; /* Total space consumed by files */ 134 135 int64_t fs_idle_files; /* number of files NOT busy */ 136 pthread_cond_t fs_idle_files_cv; /* idle files condition variable */ 137 fbint_t fs_num_act_files; /* total number of files */ 138 /* actually existing in the */ 139 /* host or server's file system */ 140 int64_t fs_idle_dirs; /* number of dirs NOT busy */ 141 pthread_cond_t fs_idle_dirs_cv; /* idle dirs condition variable */ 142 143 int64_t fs_idle_leafdirs; /* number of dirs NOT busy */ 144 pthread_cond_t fs_idle_leafdirs_cv; /* idle dirs condition variable */ 145 fbint_t fs_num_act_leafdirs; /* total number of leaf dirs */ 146 /* actually existing in the */ 147 /* host or server's file system */ 148 pthread_mutex_t fs_pick_lock; /* per fileset "pick" function lock */ 149 pthread_cond_t fs_thrd_wait_cv; /* per fileset file busy wait cv */ 150 filesetentry_t *fs_filelist; /* List of files */ 151 filesetentry_t *fs_filefree; /* Ptr to next free file */ 152 filesetentry_t *fs_filerotor[FSE_MAXTID]; /* next file to */ 153 /* select */ 154 filesetentry_t *fs_file_ne_rotor; /* next non existent file */ 155 /* to select for createfile */ 156 filesetentry_t *fs_dirlist; /* List of directories */ 157 filesetentry_t *fs_dirfree; /* List of free directories */ 158 filesetentry_t *fs_dirrotor; /* Ptr to next directory to select */ 159 filesetentry_t *fs_leafdirlist; /* List of leaf directories */ 160 filesetentry_t *fs_leafdirfree; /* Ptr to next free leaf directory */ 161 filesetentry_t *fs_leafdirrotor; /* Ptr to next leaf */ 162 /* directory to select */ 163 } fileset_t; 164 165 int fileset_createset(fileset_t *); 166 int fileset_openfile(fileset_t *fileset, filesetentry_t *entry, 167 int flag, int mode, int attrs); 168 fileset_t *fileset_define(avd_t); 169 fileset_t *fileset_find(char *name); 170 filesetentry_t *fileset_pick(fileset_t *fileset, int flags, int tid); 171 char *fileset_resolvepath(filesetentry_t *entry); 172 void fileset_usage(void); 173 void fileset_iter(int (*cmd)(fileset_t *fileset, int first)); 174 int fileset_print(fileset_t *fileset, int first); 175 void fileset_unbusy(filesetentry_t *entry, int update_exist, 176 int new_exist_val); 177 178 #ifdef __cplusplus 179 } 180 #endif 181 182 #endif /* _FB_FILESET_H */ 183