/* Private version of above function used only for reusing a * fileset. */ static struct ffsb_file *add_file_named(struct benchfiles *b, uint64_t size, char *name) { struct ffsb_file *newfile = NULL; newfile = ffsb_malloc(sizeof(struct ffsb_file)); memset(newfile, 0, sizeof(struct ffsb_file)); newfile->name = ffsb_strdup(name); newfile->size = size; init_rwlock(&newfile->lock); /* Write lock the filelist, begin critical section */ rw_lock_write(&b->fileslock); newfile->num = b->listsize; b->listsize++; /* Add a new file to the rbtree */ rbtree_insert(b->files, newfile); rw_lock_write(&newfile->lock); /* Unlock filelist */ rw_unlock_write(&b->fileslock); return newfile; }
struct ffsb_file *add_file(struct benchfiles *b, uint64_t size, randdata_t *rd) { struct ffsb_file *newfile, *oldfile = NULL; int filenum = 0; /* We pre-allocate here, because I don't want to spend time * malloc'ing while the list is locked we free it later if * necessary */ newfile = ffsb_malloc(sizeof(struct ffsb_file)); newfile->size = size; init_rwlock(&(newfile->lock)); /* Write lock the filelist, begin critical section */ rw_lock_write(&b->fileslock); /* First check "holes" for a file */ if (!cl_empty(b->holes)) { oldfile = cl_remove_head(b->holes); rbtree_insert(b->files, oldfile); rw_lock_write(&oldfile->lock); } else { filenum = b->listsize; b->listsize++; newfile->num = filenum; rbtree_insert(b->files, newfile); rw_lock_write(&newfile->lock); } /* unlock filelist */ rw_unlock_write(&b->fileslock); if (oldfile == NULL) { char buf[FILENAME_MAX]; int randdir = getrandom(rd, b->numsubdirs+1); int namesize = 0; if (randdir == 0) namesize = snprintf(buf, FILENAME_MAX, "%s/%s%s%d", b->basedir, b->basename, FILENAME_BASE, filenum); else namesize = snprintf(buf, FILENAME_MAX, "%s/%s%s%d/%s%s%d", b->basedir, b->basename, SUBDIRNAME_BASE, randdir - 1, b->basename, FILENAME_BASE, filenum); if (namesize >= FILENAME_MAX) /* !!! do something about this ? */ printf("warning: filename \"%s\" too long\n", buf); newfile->name = ffsb_strdup(buf); return newfile; } else { free(newfile); return oldfile; } }
void init_filelist(struct benchfiles *b, char *basedir, char *basename, uint32_t numsubdirs, int builddirs) { memset(b, 0, sizeof(struct benchfiles)); b->basedir = ffsb_strdup(basedir); b->basename = ffsb_strdup(basename); b->numsubdirs = numsubdirs; init_rwlock(&b->fileslock); b->files = rbtree_construct(); b->dirs = rbtree_construct(); b->holes = ffsb_malloc(sizeof(struct cirlist)); b->dholes = ffsb_malloc(sizeof(struct cirlist)); init_cirlist(b->holes); init_cirlist(b->dholes); if (builddirs) build_dirs(b); }
struct ffsb_file *add_dir(struct benchfiles *b, uint64_t size, randdata_t *rd) { struct ffsb_file *newdir, *olddir = NULL; int dirnum = 0; newdir = ffsb_malloc(sizeof(struct ffsb_file)); init_rwlock(&newdir->lock); /* write lock the filelist, beging critical section */ rw_lock_write(&b->fileslock); /* First check "holes" for a file */ if (!cl_empty(b->dholes)) { olddir = cl_remove_head(b->dholes); rbtree_insert(b->files, olddir); rw_lock_write(&olddir->lock); } else { dirnum = b->numsubdirs; b->numsubdirs++; printf("dirnum: %d\n", dirnum); newdir->num = dirnum; rbtree_insert(b->dirs, newdir); rw_lock_write(&newdir->lock); } /* unlock filelist */ rw_unlock_write(&b->fileslock); if (olddir == NULL) { char buf[FILENAME_MAX]; int namesize = 0; namesize = snprintf(buf, FILENAME_MAX, "%s/%s%s%d", b->basedir, b->basename, SUBDIRNAME_BASE, dirnum); if (namesize >= FILENAME_MAX) printf("warning: filename \"%s\" too long\n", buf); /* TODO: take action here... */ newdir->name = ffsb_strdup(buf); return newdir; } else { free(newdir); return olddir; } }
void fc_set_callout(ffsb_config_t *fc, char *callout) { if (fc->callout) free(fc->callout); fc->callout = ffsb_strdup(callout); }