15184Sek110237 /* 25184Sek110237 * CDDL HEADER START 35184Sek110237 * 45184Sek110237 * The contents of this file are subject to the terms of the 55184Sek110237 * Common Development and Distribution License (the "License"). 65184Sek110237 * You may not use this file except in compliance with the License. 75184Sek110237 * 85184Sek110237 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95184Sek110237 * or http://www.opensolaris.org/os/licensing. 105184Sek110237 * See the License for the specific language governing permissions 115184Sek110237 * and limitations under the License. 125184Sek110237 * 135184Sek110237 * When distributing Covered Code, include this CDDL HEADER in each 145184Sek110237 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155184Sek110237 * If applicable, add the following below this CDDL HEADER, with the 165184Sek110237 * fields enclosed by brackets "[]" replaced with your own identifying 175184Sek110237 * information: Portions Copyright [yyyy] [name of copyright owner] 185184Sek110237 * 195184Sek110237 * CDDL HEADER END 205184Sek110237 */ 215184Sek110237 /* 228615SAndrew.W.Wilson@sun.com * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 235184Sek110237 * Use is subject to license terms. 245184Sek110237 */ 255184Sek110237 265184Sek110237 #ifndef _FB_FILESET_H 275184Sek110237 #define _FB_FILESET_H 285184Sek110237 297556SAndrew.W.Wilson@sun.com #include "filebench.h" 305184Sek110237 #include "config.h" 315184Sek110237 325184Sek110237 #ifndef HAVE_OFF64_T 335184Sek110237 /* 345184Sek110237 * We are probably on linux. 355184Sek110237 * According to http://www.suse.de/~aj/linux_lfs.html, defining the 365184Sek110237 * above, automatically changes type of off_t to off64_t. so let 375184Sek110237 * us use only off_t as off64_t is not defined 385184Sek110237 */ 395184Sek110237 #define off64_t off_t 405184Sek110237 #endif /* HAVE_OFF64_T */ 415184Sek110237 425184Sek110237 #include <stdio.h> 435184Sek110237 #include <stdlib.h> 445184Sek110237 #include <unistd.h> 455184Sek110237 #include <sys/stat.h> 465184Sek110237 #include <sys/types.h> 475184Sek110237 #include <sys/param.h> 485184Sek110237 #include <sys/resource.h> 495184Sek110237 #include <pthread.h> 505184Sek110237 515673Saw148015 #include "vars.h" 528404SAndrew.W.Wilson@sun.com #include "fb_avl.h" 538615SAndrew.W.Wilson@sun.com 545673Saw148015 #define FILE_ALLOC_BLOCK (off64_t)(1024 * 1024) 555184Sek110237 565184Sek110237 #ifdef __cplusplus 575184Sek110237 extern "C" { 585184Sek110237 #endif 595184Sek110237 605184Sek110237 #define FSE_MAXTID 16384 615184Sek110237 625184Sek110237 #define FSE_MAXPATHLEN 16 637946SAndrew.W.Wilson@sun.com #define FSE_TYPE_FILE 0x00 647946SAndrew.W.Wilson@sun.com #define FSE_TYPE_DIR 0x01 657946SAndrew.W.Wilson@sun.com #define FSE_TYPE_LEAFDIR 0x02 667946SAndrew.W.Wilson@sun.com #define FSE_TYPE_MASK 0x03 677946SAndrew.W.Wilson@sun.com #define FSE_FREE 0x04 687946SAndrew.W.Wilson@sun.com #define FSE_EXISTS 0x08 697946SAndrew.W.Wilson@sun.com #define FSE_BUSY 0x10 707946SAndrew.W.Wilson@sun.com #define FSE_REUSING 0x20 717946SAndrew.W.Wilson@sun.com #define FSE_THRD_WAITNG 0x40 725184Sek110237 735184Sek110237 typedef struct filesetentry { 748404SAndrew.W.Wilson@sun.com struct filesetentry *fse_next; /* master list of entries */ 758404SAndrew.W.Wilson@sun.com struct filesetentry *fse_parent; /* link to directory */ 768404SAndrew.W.Wilson@sun.com avl_node_t fse_link; /* links in avl btree, prot. */ 778404SAndrew.W.Wilson@sun.com /* by fs_pick_lock */ 788404SAndrew.W.Wilson@sun.com uint_t fse_index; /* file order number */ 798404SAndrew.W.Wilson@sun.com struct filesetentry *fse_nextoftype; /* List of specific fse */ 805184Sek110237 struct fileset *fse_fileset; /* Parent fileset */ 815184Sek110237 char *fse_path; 825184Sek110237 int fse_depth; 835184Sek110237 off64_t fse_size; 848404SAndrew.W.Wilson@sun.com int fse_open_cnt; /* protected by fs_pick_lock */ 857556SAndrew.W.Wilson@sun.com int fse_flags; /* protected by fs_pick_lock */ 865184Sek110237 } filesetentry_t; 875184Sek110237 888404SAndrew.W.Wilson@sun.com #define FSE_OFFSETOF(f) ((size_t)(&(((filesetentry_t *)0)->f))) 898404SAndrew.W.Wilson@sun.com 907946SAndrew.W.Wilson@sun.com /* type of fileset entry to obtain */ 917946SAndrew.W.Wilson@sun.com #define FILESET_PICKFILE 0x00 /* Pick a file from the set */ 927946SAndrew.W.Wilson@sun.com #define FILESET_PICKDIR 0x01 /* Pick a directory */ 937946SAndrew.W.Wilson@sun.com #define FILESET_PICKLEAFDIR 0x02 /* Pick a leaf directory */ 947946SAndrew.W.Wilson@sun.com #define FILESET_PICKMASK 0x03 /* Pick type mask */ 957946SAndrew.W.Wilson@sun.com /* other pick flags */ 967946SAndrew.W.Wilson@sun.com #define FILESET_PICKUNIQUE 0x04 /* Pick a unique file or leafdir from the */ 977946SAndrew.W.Wilson@sun.com /* fileset until empty */ 985184Sek110237 #define FILESET_PICKEXISTS 0x10 /* Pick an existing file */ 995184Sek110237 #define FILESET_PICKNOEXIST 0x20 /* Pick a file that doesn't exist */ 1008404SAndrew.W.Wilson@sun.com #define FILESET_PICKBYINDEX 0x40 /* use supplied index number to select file */ 1018404SAndrew.W.Wilson@sun.com #define FILESET_PICKFREE FILESET_PICKUNIQUE 1025184Sek110237 1035673Saw148015 /* fileset attributes */ 1045673Saw148015 #define FILESET_IS_RAW_DEV 0x01 /* fileset is a raw device */ 1055673Saw148015 #define FILESET_IS_FILE 0x02 /* Fileset is emulating a single file */ 1065673Saw148015 1075184Sek110237 typedef struct fileset { 1085184Sek110237 struct fileset *fs_next; /* Next in list */ 1096212Saw148015 avd_t fs_name; /* Name */ 1106212Saw148015 avd_t fs_path; /* Pathname prefix in fileset */ 1116212Saw148015 avd_t fs_entries; /* Number of entries attr */ 1126212Saw148015 /* (possibly random) */ 1136212Saw148015 fbint_t fs_constentries; /* Constant version of enties attr */ 1147946SAndrew.W.Wilson@sun.com avd_t fs_leafdirs; /* Number of leaf directories attr */ 1157946SAndrew.W.Wilson@sun.com /* (possibly random) */ 1167946SAndrew.W.Wilson@sun.com fbint_t fs_constleafdirs; /* Constant version of leafdirs */ 1177946SAndrew.W.Wilson@sun.com /* attr */ 1186212Saw148015 avd_t fs_preallocpercent; /* Prealloc size */ 1195184Sek110237 int fs_attrs; /* Attributes */ 1206212Saw148015 avd_t fs_dirwidth; /* Explicit or mean for distribution */ 1216212Saw148015 avd_t fs_dirdepthrv; /* random variable for dir depth */ 1226212Saw148015 avd_t fs_size; /* Explicit or mean for distribution */ 1236212Saw148015 avd_t fs_dirgamma; /* Dirdepth Gamma distribution */ 1246212Saw148015 /* (* 1000) defaults to 1500, set */ 1256212Saw148015 /* to 0 for explicit depth */ 1266212Saw148015 avd_t fs_sizegamma; /* Filesize and dirwidth Gamma */ 1276212Saw148015 /* distribution (* 1000), default */ 1286212Saw148015 /* is 1500, set to 0 for explicit */ 1296212Saw148015 avd_t fs_create; /* Attr */ 1306212Saw148015 avd_t fs_prealloc; /* Attr */ 1316212Saw148015 avd_t fs_paralloc; /* Attr */ 1326212Saw148015 avd_t fs_cached; /* Attr */ 1336212Saw148015 avd_t fs_reuse; /* Attr */ 1349326SAndrew.W.Wilson@sun.com avd_t fs_readonly; /* Attr */ 1359326SAndrew.W.Wilson@sun.com avd_t fs_trust_tree; /* Attr */ 1365184Sek110237 double fs_meandepth; /* Computed mean depth */ 1375184Sek110237 double fs_meanwidth; /* Specified mean dir width */ 1385184Sek110237 double fs_meansize; /* Specified mean file size */ 1395184Sek110237 int fs_realfiles; /* Actual files */ 1407946SAndrew.W.Wilson@sun.com int fs_realleafdirs; /* Actual explicit leaf directories */ 1416212Saw148015 off64_t fs_bytes; /* Total space consumed by files */ 1427946SAndrew.W.Wilson@sun.com 1437946SAndrew.W.Wilson@sun.com int64_t fs_idle_files; /* number of files NOT busy */ 1447946SAndrew.W.Wilson@sun.com pthread_cond_t fs_idle_files_cv; /* idle files condition variable */ 1458404SAndrew.W.Wilson@sun.com 1467946SAndrew.W.Wilson@sun.com int64_t fs_idle_dirs; /* number of dirs NOT busy */ 1477946SAndrew.W.Wilson@sun.com pthread_cond_t fs_idle_dirs_cv; /* idle dirs condition variable */ 1487946SAndrew.W.Wilson@sun.com 1497946SAndrew.W.Wilson@sun.com int64_t fs_idle_leafdirs; /* number of dirs NOT busy */ 1507946SAndrew.W.Wilson@sun.com pthread_cond_t fs_idle_leafdirs_cv; /* idle dirs condition variable */ 1518404SAndrew.W.Wilson@sun.com 1527556SAndrew.W.Wilson@sun.com pthread_mutex_t fs_pick_lock; /* per fileset "pick" function lock */ 1537556SAndrew.W.Wilson@sun.com pthread_cond_t fs_thrd_wait_cv; /* per fileset file busy wait cv */ 1548404SAndrew.W.Wilson@sun.com avl_tree_t fs_free_files; /* btree of free files */ 1558404SAndrew.W.Wilson@sun.com avl_tree_t fs_exist_files; /* btree of files on device */ 1568404SAndrew.W.Wilson@sun.com avl_tree_t fs_noex_files; /* btree of files NOT on device */ 1578404SAndrew.W.Wilson@sun.com avl_tree_t fs_dirs; /* btree of internal dirs */ 1588404SAndrew.W.Wilson@sun.com avl_tree_t fs_free_leaf_dirs; /* btree of free leaf dirs */ 1598404SAndrew.W.Wilson@sun.com avl_tree_t fs_exist_leaf_dirs; /* btree of leaf dirs on device */ 1608404SAndrew.W.Wilson@sun.com avl_tree_t fs_noex_leaf_dirs; /* btree of leaf dirs NOT */ 1618404SAndrew.W.Wilson@sun.com /* currently on device */ 1625184Sek110237 filesetentry_t *fs_filelist; /* List of files */ 1638404SAndrew.W.Wilson@sun.com uint_t fs_file_exrotor[FSE_MAXTID]; /* next file to */ 1646212Saw148015 /* select */ 1658404SAndrew.W.Wilson@sun.com uint_t fs_file_nerotor; /* next non existent file */ 1667556SAndrew.W.Wilson@sun.com /* to select for createfile */ 1677946SAndrew.W.Wilson@sun.com filesetentry_t *fs_dirlist; /* List of directories */ 1688404SAndrew.W.Wilson@sun.com uint_t fs_dirrotor; /* index of next directory to select */ 1697946SAndrew.W.Wilson@sun.com filesetentry_t *fs_leafdirlist; /* List of leaf directories */ 1708404SAndrew.W.Wilson@sun.com uint_t fs_leafdir_exrotor; /* Ptr to next existing leaf */ 1717946SAndrew.W.Wilson@sun.com /* directory to select */ 1728404SAndrew.W.Wilson@sun.com uint_t fs_leafdir_nerotor; /* Ptr to next non-existing */ 1738404SAndrew.W.Wilson@sun.com int *fs_filehistop; /* Ptr to access histogram */ 1748404SAndrew.W.Wilson@sun.com int fs_histo_id; /* shared memory id for filehisto */ 1758404SAndrew.W.Wilson@sun.com pthread_mutex_t fs_histo_lock; /* lock for incr of histo */ 1765184Sek110237 } fileset_t; 1775184Sek110237 1785184Sek110237 int fileset_createset(fileset_t *); 179*9356SAndrew.W.Wilson@sun.com void fileset_delete_all_filesets(void); 1808615SAndrew.W.Wilson@sun.com int fileset_openfile(fb_fdesc_t *fd, fileset_t *fileset, 1818615SAndrew.W.Wilson@sun.com filesetentry_t *entry, int flag, int mode, int attrs); 1826212Saw148015 fileset_t *fileset_define(avd_t); 1835184Sek110237 fileset_t *fileset_find(char *name); 1848404SAndrew.W.Wilson@sun.com filesetentry_t *fileset_pick(fileset_t *fileset, int flags, int tid, 1858404SAndrew.W.Wilson@sun.com int index); 1865184Sek110237 char *fileset_resolvepath(filesetentry_t *entry); 1875184Sek110237 void fileset_usage(void); 1888404SAndrew.W.Wilson@sun.com int fileset_iter(int (*cmd)(fileset_t *fileset, int first)); 1895673Saw148015 int fileset_print(fileset_t *fileset, int first); 1907556SAndrew.W.Wilson@sun.com void fileset_unbusy(filesetentry_t *entry, int update_exist, 1918404SAndrew.W.Wilson@sun.com int new_exist_val, int open_cnt_incr); 1928404SAndrew.W.Wilson@sun.com int fileset_dump_histo(fileset_t *fileset, int first); 1938404SAndrew.W.Wilson@sun.com void fileset_attach_all_histos(void); 1945184Sek110237 1955184Sek110237 #ifdef __cplusplus 1965184Sek110237 } 1975184Sek110237 #endif 1985184Sek110237 1995184Sek110237 #endif /* _FB_FILESET_H */ 200