From 04d6530f6ecd50520e99732b0b6bb90f71ff131a Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 25 Aug 2016 21:00:55 -0600 Subject: [PATCH] file: fix numjobs > 1 and implied jobname as filename If we have a jobfile that looks like: [global] numjobs=4 [/dev/somedevice] Then we fail jobs 2 and on, since we don't properly add those files. Fix this by checking if we're generating a filename based on the jobname. Fixes: bcbfeefa7bce ("fio: add multi directory support") Signed-off-by: Jens Axboe --- file.h | 1 + filesetup.c | 43 +++++++++++++++++++++++++++++++++---------- init.c | 20 -------------------- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/file.h b/file.h index f7e5d204..aff3ce9f 100644 --- a/file.h +++ b/file.h @@ -211,5 +211,6 @@ extern void free_release_files(struct thread_data *); extern void filesetup_mem_free(void); extern void fio_file_reset(struct thread_data *, struct fio_file *); extern int fio_files_done(struct thread_data *); +extern bool exists_and_not_regfile(const char *); #endif diff --git a/filesetup.c b/filesetup.c index 5db44c29..fc9f3067 100644 --- a/filesetup.c +++ b/filesetup.c @@ -1242,31 +1242,33 @@ static void get_file_type(struct fio_file *f) } } -static int __is_already_allocated(const char *fname) +static bool __is_already_allocated(const char *fname) { struct flist_head *entry; - char *filename; if (flist_empty(&filename_list)) - return 0; + return false; flist_for_each(entry, &filename_list) { - filename = flist_entry(entry, struct file_name, list)->filename; + struct file_name *fn; - if (strcmp(filename, fname) == 0) - return 1; + fn = flist_entry(entry, struct file_name, list); + + if (!strcmp(fn->filename, fname)) + return true; } - return 0; + return false; } -static int is_already_allocated(const char *fname) +static bool is_already_allocated(const char *fname) { - int ret; + bool ret; fio_file_hash_lock(); ret = __is_already_allocated(fname); fio_file_hash_unlock(); + return ret; } @@ -1327,6 +1329,26 @@ static struct fio_file *alloc_new_file(struct thread_data *td) return f; } +bool exists_and_not_regfile(const char *filename) +{ + struct stat sb; + + if (lstat(filename, &sb) == -1) + return false; + +#ifndef WIN32 /* NOT Windows */ + if (S_ISREG(sb.st_mode)) + return false; +#else + /* \\.\ is the device namespace in Windows, where every file + * is a device node */ + if (S_ISREG(sb.st_mode) && strncmp(filename, "\\\\.\\", 4) != 0) + return false; +#endif + + return true; +} + int add_file(struct thread_data *td, const char *fname, int numjob, int inc) { int cur_files = td->files_index; @@ -1343,7 +1365,8 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc) sprintf(file_name + len, "%s", fname); /* clean cloned siblings using existing files */ - if (numjob && is_already_allocated(file_name)) + if (numjob && is_already_allocated(file_name) && + !exists_and_not_regfile(fname)) return 0; f = alloc_new_file(td); diff --git a/init.c b/init.c index 5ff73859..0221ab2f 100644 --- a/init.c +++ b/init.c @@ -903,26 +903,6 @@ static const char *get_engine_name(const char *str) return p; } -static int exists_and_not_regfile(const char *filename) -{ - struct stat sb; - - if (lstat(filename, &sb) == -1) - return 0; - -#ifndef WIN32 /* NOT Windows */ - if (S_ISREG(sb.st_mode)) - return 0; -#else - /* \\.\ is the device namespace in Windows, where every file - * is a device node */ - if (S_ISREG(sb.st_mode) && strncmp(filename, "\\\\.\\", 4) != 0) - return 0; -#endif - - return 1; -} - static void init_rand_file_service(struct thread_data *td) { unsigned long nranges = td->o.nr_files << FIO_FSERVICE_SHIFT; -- 2.25.1