file: fix numjobs > 1 and implied jobname as filename
authorJens Axboe <axboe@fb.com>
Fri, 26 Aug 2016 03:00:55 +0000 (21:00 -0600)
committerJens Axboe <axboe@fb.com>
Fri, 26 Aug 2016 03:00:55 +0000 (21:00 -0600)
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 <axboe@fb.com>
file.h
filesetup.c
init.c

diff --git a/file.h b/file.h
index f7e5d2046a3e98cbce18ae94665a4318215c0dec..aff3ce9f301dcf004473af965d6c84cdba993ed3 100644 (file)
--- 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
index 5db44c294d2de3fccb2ac669a7abf4cc3f3d09fe..fc9f3067226ee48276071af7343659a939cef43e 100644 (file)
@@ -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 5ff73859d50d444ed371c33a36c710182aa0bb38..0221ab2f18e7fe2b82e4555869c9aa7f87680b85 100644 (file)
--- 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;