X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=filesetup.c;h=7669d704663d52bf2d1d8ffeefeb5a45fd155861;hp=544ecb1c53dce5f336faf3294c0acfc75ace53e3;hb=bcd27f7ae1ccebd2ac1778752bf8f13fa99600e9;hpb=f2a2803a4982a1516eb75d9f98de68cf21d1ae7d diff --git a/filesetup.c b/filesetup.c index 544ecb1c..7669d704 100644 --- a/filesetup.c +++ b/filesetup.c @@ -11,6 +11,7 @@ #include "fio.h" #include "smalloc.h" #include "filehash.h" +#include "options.h" #include "os/os.h" #include "hash.h" #include "lib/axmap.h" @@ -21,6 +22,8 @@ static int root_warn; +static FLIST_HEAD(filename_list); + static inline void clear_error(struct thread_data *td) { td->error = 0; @@ -1101,7 +1104,48 @@ static void get_file_type(struct fio_file *f) } } -int add_file(struct thread_data *td, const char *fname) +static void set_already_allocated(const char *fname) { + struct file_name *fn; + + fn = malloc(sizeof(struct file_name)); + fn->filename = strdup(fname); + flist_add_tail(&fn->list, &filename_list); +} + +static int is_already_allocated(const char *fname) +{ + struct flist_head *entry; + char *filename; + + if (!flist_empty(&filename_list)) + { + flist_for_each(entry, &filename_list) { + filename = flist_entry(entry, struct file_name, list)->filename; + + if (strcmp(filename, fname) == 0) + return 1; + } + } + + return 0; +} + +static void free_already_allocated() { + struct flist_head *entry, *tmp; + struct file_name *fn; + + if (!flist_empty(&filename_list)) + { + flist_for_each_safe(entry, tmp, &filename_list) { + fn = flist_entry(entry, struct file_name, list); + free(fn->filename); + flist_del(&fn->list); + free(fn); + } + } +} + +int add_file(struct thread_data *td, const char *fname, int numjob) { int cur_files = td->files_index; char file_name[PATH_MAX]; @@ -1110,6 +1154,15 @@ int add_file(struct thread_data *td, const char *fname) dprint(FD_FILE, "add file %s\n", fname); + if (td->o.directory) + len = set_name_idx(file_name, td->o.directory, numjob); + + sprintf(file_name + len, "%s", fname); + + /* clean cloned siblings using existing files */ + if (numjob && is_already_allocated(file_name)) + return 0; + f = smalloc(sizeof(*f)); if (!f) { log_err("fio: smalloc OOM\n"); @@ -1149,10 +1202,6 @@ int add_file(struct thread_data *td, const char *fname) if (td->io_ops && (td->io_ops->flags & FIO_DISKLESSIO)) f->real_file_size = -1ULL; - if (td->o.directory) - len = sprintf(file_name, "%s/", td->o.directory); - - sprintf(file_name + len, "%s", fname); f->file_name = smalloc_strdup(file_name); if (!f->file_name) { log_err("fio: smalloc OOM\n"); @@ -1179,6 +1228,15 @@ int add_file(struct thread_data *td, const char *fname) if (f->filetype == FIO_TYPE_FILE) td->nr_normal_files++; + set_already_allocated(file_name); + + /* + * For adding files after the fact - if openfiles= isn't + * given as an option, ensure we allow at least one file open + */ + if (!td->o.open_files) + td->o.open_files = 1; + dprint(FD_FILE, "file %p \"%s\" added at %d\n", f, f->file_name, cur_files); @@ -1195,7 +1253,7 @@ int add_file_exclusive(struct thread_data *td, const char *fname) return i; } - return add_file(td, fname); + return add_file(td, fname, 0); } void get_file(struct fio_file *f) @@ -1304,7 +1362,7 @@ static int recurse_dir(struct thread_data *td, const char *dirname) } if (S_ISREG(sb.st_mode)) { - add_file(td, full_path); + add_file(td, full_path, 0); td->o.nr_files++; continue; } @@ -1421,3 +1479,8 @@ int fio_files_done(struct thread_data *td) return 1; } + +/* free memory used in initialization phase only */ +void filesetup_mem_free() { + free_already_allocated(); +}