Enfore that lockfile= must precede filename=
authorJens Axboe <axboe@fb.com>
Tue, 11 Feb 2014 16:12:06 +0000 (09:12 -0700)
committerJens Axboe <axboe@fb.com>
Tue, 11 Feb 2014 16:12:06 +0000 (09:12 -0700)
The way fio parses options, we need to have the file locking
defined before we start adding files. Normally we can handle
this with option priorities, but that doesn't work across
job section boundaries. So catch this case and error out,
otherwise fio will segfault when it attempts to unlock files
at the end of a job.

Signed-off-by: Jens Axboe <axboe@fb.com>
filesetup.c
options.c

index bae60929df32f7f80f1dfa4ba00ab3ffbb9514b0..544ecb1c53dce5f336faf3294c0acfc75ace53e3 100644 (file)
@@ -1266,7 +1266,7 @@ void unlock_file(struct thread_data *td, struct fio_file *f)
 
 void unlock_file_all(struct thread_data *td, struct fio_file *f)
 {
 
 void unlock_file_all(struct thread_data *td, struct fio_file *f)
 {
-       if (td->o.file_lock_mode == FILE_LOCK_NONE)
+       if (td->o.file_lock_mode == FILE_LOCK_NONE || !td->file_locks)
                return;
        if (td->file_locks[f->fileno] != FILE_LOCK_NONE)
                unlock_file(td, f);
                return;
        if (td->file_locks[f->fileno] != FILE_LOCK_NONE)
                unlock_file(td, f);
index 57e9af5b4676296f22a1aee8a97fd379826afb53..29b181a020ac5a62cdfd7b6eaed3fc6db133ab17 100644 (file)
--- a/options.c
+++ b/options.c
@@ -821,6 +821,18 @@ static int str_directory_cb(void *data, const char fio_unused *str)
        return 0;
 }
 
        return 0;
 }
 
+static int str_lockfile_cb(void *data, const char fio_unused *str)
+{
+       struct thread_data *td = data;
+
+       if (td->files_index) {
+               log_err("fio: lockfile= option must precede filename=\n");
+               return 1;
+       }
+
+       return 0;
+}
+
 static int str_opendir_cb(void *data, const char fio_unused *str)
 {
        struct thread_data *td = data;
 static int str_opendir_cb(void *data, const char fio_unused *str)
 {
        struct thread_data *td = data;
@@ -1231,6 +1243,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .parent = "filename",
                .hide   = 0,
                .def    = "none",
                .parent = "filename",
                .hide   = 0,
                .def    = "none",
+               .cb     = str_lockfile_cb,
                .category = FIO_OPT_C_FILE,
                .group  = FIO_OPT_G_FILENAME,
                .posval = {
                .category = FIO_OPT_C_FILE,
                .group  = FIO_OPT_G_FILENAME,
                .posval = {