Add 'fsync_on_close' option
[fio.git] / init.c
diff --git a/init.c b/init.c
index 66a50b03dbb8187b88db9fee3f6865a1fd0b26e7..cf66ec0e8ee9875ded959cb616be5c633c4e13fc 100644 (file)
--- a/init.c
+++ b/init.c
@@ -499,6 +499,13 @@ static struct fio_option options[] = {
                .help   = "Include fsync at the end of job",
                .def    = "0",
        },
+       {
+               .name   = "fsync_on_close",
+               .type   = FIO_OPT_BOOL,
+               .off1   = td_var_offset(fsync_on_close),
+               .help   = "fsync files on close",
+               .def    = "0",
+       },
        {
                .name   = "unlink",
                .type   = FIO_OPT_BOOL,
@@ -753,8 +760,11 @@ static void fixup_options(struct thread_data *td)
                td->iodepth_batch = td->iodepth;
 
        if (!td->nr_files)
-               td->nr_files = td->open_files;
-       else if (td->open_files > td->nr_files || !td->open_files)
+               td->nr_files = td->files_index;
+       else if (td->nr_files > td->files_index)
+               td->nr_files = td->files_index;
+
+       if (td->open_files > td->nr_files || !td->open_files)
                td->open_files = td->nr_files;
 }
 
@@ -832,9 +842,13 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        if (!td->filename) {
                td->filename = strdup(jobname);
 
-               for (i = 0; i < td->nr_files; i++) {
-                       sprintf(fname, "%s.%d.%d", td->filename, td->thread_number, i);
-                       add_file(td, fname);
+               if (td->nr_files == 1)
+                       add_file(td, td->filename);
+               else {
+                       for (i = 0; i < td->nr_files; i++) {
+                               sprintf(fname, "%s.%d.%d", td->filename, td->thread_number, i);
+                               add_file(td, fname);
+                       }
                }
        }
 
@@ -845,9 +859,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                        sprintf(fname, "%s/%s", td->directory, f->file_name);
                        f->file_name = strdup(fname);
                }
-
-               f->file_size = td->total_file_size / td->nr_files;
-               f->file_offset = td->start_offset;
        }
                
        td->mutex = fio_sem_init(0);
@@ -1103,15 +1114,20 @@ static int str_fst_cb(void *data, const char *str)
 static int str_filename_cb(void *data, const char *input)
 {
        struct thread_data *td = data;
-       char *fname, *str;
+       char *fname, *str, *p;
+
+       p = str = strdup(input);
+
+       strip_blank_front(&str);
+       strip_blank_end(str);
 
-       td->nr_files = 0;
-       str = strdup(input);
        while ((fname = strsep(&str, ":")) != NULL) {
+               if (!strlen(fname))
+                       break;
                add_file(td, fname);
-               td->nr_files++;
        }
 
+       free(p);
        return 0;
 }