fio: inherit IO engine flags to 'td'
authorJens Axboe <axboe@fb.com>
Mon, 15 Aug 2016 15:42:37 +0000 (09:42 -0600)
committerJens Axboe <axboe@fb.com>
Mon, 15 Aug 2016 15:42:37 +0000 (09:42 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c
diskutil.c
filesetup.c
fio.c
fio.h
init.c
io_u.c
ioengines.c
memory.c
rate-submit.c
verify.c

index c051c13c1aea34b2ab8666927eccc9d7ea1d746a..b43486dc7b2ff016b6d76d281dc479692e90b231 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1024,7 +1024,7 @@ reap:
                if (ret < 0)
                        break;
                if (!ddir_rw_sum(td->bytes_done) &&
                if (ret < 0)
                        break;
                if (!ddir_rw_sum(td->bytes_done) &&
-                   !(td->io_ops->flags & FIO_NOIO))
+                   !td_ioengine_flagged(td, FIO_NOIO))
                        continue;
 
                if (!in_ramp_time(td) && should_check_rate(td)) {
                        continue;
 
                if (!in_ramp_time(td) && should_check_rate(td)) {
@@ -1175,7 +1175,7 @@ static int init_io_u(struct thread_data *td)
        td->orig_buffer_size = (unsigned long long) max_bs
                                        * (unsigned long long) max_units;
 
        td->orig_buffer_size = (unsigned long long) max_bs
                                        * (unsigned long long) max_units;
 
-       if ((td->io_ops->flags & FIO_NOIO) || !(td_read(td) || td_write(td)))
+       if (td_ioengine_flagged(td, FIO_NOIO) || !(td_read(td) || td_write(td)))
                data_xfer = 0;
 
        err = 0;
                data_xfer = 0;
 
        err = 0;
@@ -1195,7 +1195,7 @@ static int init_io_u(struct thread_data *td)
         * lucky and the allocator gives us an aligned address.
         */
        if (td->o.odirect || td->o.mem_align || td->o.oatomic ||
         * lucky and the allocator gives us an aligned address.
         */
        if (td->o.odirect || td->o.mem_align || td->o.oatomic ||
-           (td->io_ops->flags & FIO_RAWIO))
+           td_ioengine_flagged(td, FIO_RAWIO))
                td->orig_buffer_size += page_mask + td->o.mem_align;
 
        if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) {
                td->orig_buffer_size += page_mask + td->o.mem_align;
 
        if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) {
@@ -1214,7 +1214,7 @@ static int init_io_u(struct thread_data *td)
                return 1;
 
        if (td->o.odirect || td->o.mem_align || td->o.oatomic ||
                return 1;
 
        if (td->o.odirect || td->o.mem_align || td->o.oatomic ||
-           (td->io_ops->flags & FIO_RAWIO))
+           td_ioengine_flagged(td, FIO_RAWIO))
                p = PAGE_ALIGN(td->orig_buffer) + td->o.mem_align;
        else
                p = td->orig_buffer;
                p = PAGE_ALIGN(td->orig_buffer) + td->o.mem_align;
        else
                p = td->orig_buffer;
@@ -1288,7 +1288,7 @@ static int switch_ioscheduler(struct thread_data *td)
        FILE *f;
        int ret;
 
        FILE *f;
        int ret;
 
-       if (td->io_ops->flags & FIO_DISKLESSIO)
+       if (td_ioengine_flagged(td, FIO_DISKLESSIO))
                return 0;
 
        sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
                return 0;
 
        sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
@@ -1748,7 +1748,7 @@ static void *thread_main(void *data)
 
                if (!o->do_verify ||
                    o->verify == VERIFY_NONE ||
 
                if (!o->do_verify ||
                    o->verify == VERIFY_NONE ||
-                   (td->io_ops->flags & FIO_UNIDIR))
+                   td_ioengine_flagged(td, FIO_UNIDIR))
                        continue;
 
                clear_io_state(td, 0);
                        continue;
 
                clear_io_state(td, 0);
index a1077d4001459a159c37076478fa4e04f882ecc8..0f7a64209b57747139e66705a8fd2f71ebbe4697 100644 (file)
@@ -491,7 +491,7 @@ void init_disk_util(struct thread_data *td)
        unsigned int i;
 
        if (!td->o.do_disk_util ||
        unsigned int i;
 
        if (!td->o.do_disk_util ||
-           (td->io_ops->flags & (FIO_DISKLESSIO | FIO_NODISKUTIL)))
+           td_ioengine_flagged(td, FIO_DISKLESSIO | FIO_NODISKUTIL))
                return;
 
        for_each_file(td, f, i)
                return;
 
        for_each_file(td, f, i)
index 42a9f4155fbf13a8a284c9070de8f110d80c6001..5db44c294d2de3fccb2ac669a7abf4cc3f3d09fe 100644 (file)
@@ -52,7 +52,7 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
         */
        if (td_read(td) ||
           (td_write(td) && td->o.overwrite && !td->o.file_append) ||
         */
        if (td_read(td) ||
           (td_write(td) && td->o.overwrite && !td->o.file_append) ||
-           (td_write(td) && td->io_ops->flags & FIO_NOEXTEND))
+           (td_write(td) && td_ioengine_flagged(td, FIO_NOEXTEND)))
                new_layout = 1;
        if (td_write(td) && !td->o.overwrite && !td->o.file_append)
                unlink_file = 1;
                new_layout = 1;
        if (td_write(td) && !td->o.overwrite && !td->o.file_append)
                unlink_file = 1;
@@ -217,7 +217,7 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f)
        unsigned int bs;
        char *b;
 
        unsigned int bs;
        char *b;
 
-       if (td->io_ops->flags & FIO_PIPEIO)
+       if (td_ioengine_flagged(td, FIO_PIPEIO))
                return 0;
 
        if (!fio_file_open(f)) {
                return 0;
 
        if (!fio_file_open(f)) {
@@ -827,7 +827,7 @@ int setup_files(struct thread_data *td)
         * device/file sizes are zero and no size given, punt
         */
        if ((!total_size || total_size == -1ULL) && !o->size &&
         * device/file sizes are zero and no size given, punt
         */
        if ((!total_size || total_size == -1ULL) && !o->size &&
-           !(td->io_ops->flags & FIO_NOIO) && !o->fill_device &&
+           !td_ioengine_flagged(td, FIO_NOIO) && !o->fill_device &&
            !(o->nr_files && (o->file_size_low || o->file_size_high))) {
                log_err("%s: you need to specify size=\n", o->name);
                td_verror(td, EINVAL, "total_file_size");
            !(o->nr_files && (o->file_size_low || o->file_size_high))) {
                log_err("%s: you need to specify size=\n", o->name);
                td_verror(td, EINVAL, "total_file_size");
@@ -903,7 +903,7 @@ int setup_files(struct thread_data *td)
 
                if (f->filetype == FIO_TYPE_FILE &&
                    (f->io_size + f->file_offset) > f->real_file_size &&
 
                if (f->filetype == FIO_TYPE_FILE &&
                    (f->io_size + f->file_offset) > f->real_file_size &&
-                   !(td->io_ops->flags & FIO_DISKLESSIO)) {
+                   !td_ioengine_flagged(td, FIO_DISKLESSIO)) {
                        if (!o->create_on_open) {
                                need_extend++;
                                extend_size += (f->io_size + f->file_offset);
                        if (!o->create_on_open) {
                                need_extend++;
                                extend_size += (f->io_size + f->file_offset);
@@ -1374,7 +1374,7 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc)
        /*
         * init function, io engine may not be loaded yet
         */
        /*
         * init function, io engine may not be loaded yet
         */
-       if (td->io_ops && (td->io_ops->flags & FIO_DISKLESSIO))
+       if (td->io_ops && td_ioengine_flagged(td, FIO_DISKLESSIO))
                f->real_file_size = -1ULL;
 
        f->file_name = smalloc_strdup(file_name);
                f->real_file_size = -1ULL;
 
        f->file_name = smalloc_strdup(file_name);
diff --git a/fio.c b/fio.c
index 69014ddbb14b2c8d631755337010b50f73684dc2..7b3a50b6cba12df253bed9517be46cdc950fde2d 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -32,6 +32,8 @@ int main(int argc, char *argv[], char *envp[])
 {
        int ret = 1;
 
 {
        int ret = 1;
 
+       compiletime_assert(TD_NR <= TD_ENG_FLAG_SHIFT, "TD_ENG_FLAG_SHIFT");
+
        if (initialize_fio(envp))
                return 1;
 
        if (initialize_fio(envp))
                return 1;
 
diff --git a/fio.h b/fio.h
index 33b431939a9ee916e297ed0b62f8a5fce7eb4235..e96a4dd1dcd1058071e20502d58003be38e88dae 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -556,8 +556,27 @@ enum {
        TD_EXITED,
        TD_REAPED,
        TD_LAST,
        TD_EXITED,
        TD_REAPED,
        TD_LAST,
+       TD_NR,
 };
 
 };
 
+#define TD_ENG_FLAG_SHIFT      16
+#define TD_ENG_FLAG_MASK       ((1U << 16) - 1)
+
+static inline enum fio_ioengine_flags td_ioengine_flags(struct thread_data *td)
+{
+       return (td->flags >> TD_ENG_FLAG_SHIFT) & TD_ENG_FLAG_MASK;
+}
+
+static inline void td_set_ioengine_flags(struct thread_data *td)
+{
+       td->flags |= (td->io_ops->flags << TD_ENG_FLAG_SHIFT);
+}
+
+static inline bool td_ioengine_flagged(struct thread_data *td, unsigned int val)
+{
+       return ((td->flags >> TD_ENG_FLAG_SHIFT) & val) != 0;
+}
+
 extern void td_set_runstate(struct thread_data *, int);
 extern int td_bump_runstate(struct thread_data *, int);
 extern void td_restore_runstate(struct thread_data *, int);
 extern void td_set_runstate(struct thread_data *, int);
 extern int td_bump_runstate(struct thread_data *, int);
 extern void td_restore_runstate(struct thread_data *, int);
diff --git a/init.c b/init.c
index fb07daadbb7a6ee12118e99f4999e0b5017c0eb3..a1a008797d4a9eead366f304388e665eeb98a4ca 100644 (file)
--- a/init.c
+++ b/init.c
@@ -677,7 +677,7 @@ static int fixup_options(struct thread_data *td)
                        "verify limited\n");
                ret = warnings_fatal;
        }
                        "verify limited\n");
                ret = warnings_fatal;
        }
-       if (o->bs_unaligned && (o->odirect || td->io_ops->flags & FIO_RAWIO))
+       if (o->bs_unaligned && (o->odirect || td_ioengine_flagged(td, FIO_RAWIO)))
                log_err("fio: bs_unaligned may not work with raw io\n");
 
        /*
                log_err("fio: bs_unaligned may not work with raw io\n");
 
        /*
@@ -764,7 +764,7 @@ static int fixup_options(struct thread_data *td)
 
        if (o->pre_read) {
                o->invalidate_cache = 0;
 
        if (o->pre_read) {
                o->invalidate_cache = 0;
-               if (td->io_ops->flags & FIO_PIPEIO) {
+               if (td_ioengine_flagged(td, FIO_PIPEIO)) {
                        log_info("fio: cannot pre-read files with an IO engine"
                                 " that isn't seekable. Pre-read disabled.\n");
                        ret = warnings_fatal;
                        log_info("fio: cannot pre-read files with an IO engine"
                                 " that isn't seekable. Pre-read disabled.\n");
                        ret = warnings_fatal;
@@ -772,7 +772,7 @@ static int fixup_options(struct thread_data *td)
        }
 
        if (!o->unit_base) {
        }
 
        if (!o->unit_base) {
-               if (td->io_ops->flags & FIO_BIT_BASED)
+               if (td_ioengine_flagged(td, FIO_BIT_BASED))
                        o->unit_base = 1;
                else
                        o->unit_base = 8;
                        o->unit_base = 1;
                else
                        o->unit_base = 8;
@@ -795,7 +795,7 @@ static int fixup_options(struct thread_data *td)
         * Windows doesn't support O_DIRECT or O_SYNC with the _open interface,
         * so fail if we're passed those flags
         */
         * Windows doesn't support O_DIRECT or O_SYNC with the _open interface,
         * so fail if we're passed those flags
         */
-       if ((td->io_ops->flags & FIO_SYNCIO) && (td->o.odirect || td->o.sync_io)) {
+       if (td_ioengine_flagged(td, FIO_SYNCIO) && (td->o.odirect || td->o.sync_io)) {
                log_err("fio: Windows does not support direct or non-buffered io with"
                                " the synchronous ioengines. Use the 'windowsaio' ioengine"
                                " with 'direct=1' and 'iodepth=1' instead.\n");
                log_err("fio: Windows does not support direct or non-buffered io with"
                                " the synchronous ioengines. Use the 'windowsaio' ioengine"
                                " with 'direct=1' and 'iodepth=1' instead.\n");
@@ -844,7 +844,7 @@ static int fixup_options(struct thread_data *td)
        if (fio_option_is_set(&td->o, rand_seed))
                td->o.rand_repeatable = 0;
 
        if (fio_option_is_set(&td->o, rand_seed))
                td->o.rand_repeatable = 0;
 
-       if ((td->io_ops->flags & FIO_NOEXTEND) && td->o.file_append) {
+       if (td_ioengine_flagged(td, FIO_NOEXTEND) && td->o.file_append) {
                log_err("fio: can't append/extent with IO engine %s\n", td->io_ops->name);
                ret = 1;
        }
                log_err("fio: can't append/extent with IO engine %s\n", td->io_ops->name);
                ret = 1;
        }
@@ -1069,6 +1069,10 @@ int ioengine_load(struct thread_data *td)
                *(struct thread_data **)td->eo = td;
        }
 
                *(struct thread_data **)td->eo = td;
        }
 
+       if (td->o.odirect)
+               td->io_ops->flags |= FIO_RAWIO;
+
+       td_set_ioengine_flags(td);
        return 0;
 }
 
        return 0;
 }
 
@@ -1340,9 +1344,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
        if (ioengine_load(td))
                goto err;
 
        if (ioengine_load(td))
                goto err;
 
-       if (o->odirect)
-               td->io_ops->flags |= FIO_RAWIO;
-
        file_alloced = 0;
        if (!o->filename && !td->files_index && !o->read_iolog_file) {
                file_alloced = 1;
        file_alloced = 0;
        if (!o->filename && !td->files_index && !o->read_iolog_file) {
                file_alloced = 1;
@@ -1373,7 +1374,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
        if (td->eo)
                *(struct thread_data **)td->eo = NULL;
 
        if (td->eo)
                *(struct thread_data **)td->eo = NULL;
 
-       if (td->io_ops->flags & FIO_DISKLESSIO) {
+       if (td_ioengine_flagged(td, FIO_DISKLESSIO)) {
                struct fio_file *f;
 
                for_each_file(td, f, i)
                struct fio_file *f;
 
                for_each_file(td, f, i)
@@ -1537,7 +1538,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
                        if (is_backend && !recursed)
                                fio_server_send_add_job(td);
 
                        if (is_backend && !recursed)
                                fio_server_send_add_job(td);
 
-                       if (!(td->io_ops->flags & FIO_NOIO)) {
+                       if (!td_ioengine_flagged(td, FIO_NOIO)) {
                                char *c1, *c2, *c3, *c4;
                                char *c5 = NULL, *c6 = NULL;
 
                                char *c1, *c2, *c3, *c4;
                                char *c5 = NULL, *c6 = NULL;
 
diff --git a/io_u.c b/io_u.c
index 34acc5698e37cc4b7f1e8572ffa55ecd49d342bb..22701274cf3cc5aa2fe78d70a0d25171432281df 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -768,7 +768,7 @@ static void set_rw_ddir(struct thread_data *td, struct io_u *io_u)
 
        io_u->ddir = io_u->acct_ddir = ddir;
 
 
        io_u->ddir = io_u->acct_ddir = ddir;
 
-       if (io_u->ddir == DDIR_WRITE && (td->io_ops->flags & FIO_BARRIER) &&
+       if (io_u->ddir == DDIR_WRITE && td_ioengine_flagged(td, FIO_BARRIER) &&
            td->o.barrier_blocks &&
           !(td->io_issues[DDIR_WRITE] % td->o.barrier_blocks) &&
             td->io_issues[DDIR_WRITE])
            td->o.barrier_blocks &&
           !(td->io_issues[DDIR_WRITE] % td->o.barrier_blocks) &&
             td->io_issues[DDIR_WRITE])
@@ -843,7 +843,7 @@ static int fill_io_u(struct thread_data *td, struct io_u *io_u)
 {
        unsigned int is_random;
 
 {
        unsigned int is_random;
 
-       if (td->io_ops->flags & FIO_NOIO)
+       if (td_ioengine_flagged(td, FIO_NOIO))
                goto out;
 
        set_rw_ddir(td, io_u);
                goto out;
 
        set_rw_ddir(td, io_u);
@@ -1622,7 +1622,7 @@ struct io_u *get_io_u(struct thread_data *td)
        assert(fio_file_open(f));
 
        if (ddir_rw(io_u->ddir)) {
        assert(fio_file_open(f));
 
        if (ddir_rw(io_u->ddir)) {
-               if (!io_u->buflen && !(td->io_ops->flags & FIO_NOIO)) {
+               if (!io_u->buflen && !td_ioengine_flagged(td, FIO_NOIO)) {
                        dprint(FD_IO, "get_io_u: zero buflen on %p\n", io_u);
                        goto err_put;
                }
                        dprint(FD_IO, "get_io_u: zero buflen on %p\n", io_u);
                        goto err_put;
                }
index 1c7a93b45de44aac844442156c11441e901aeb5f..ae55f951d413fbaeaf92dae3c8eb0746167d4c9d 100644 (file)
@@ -272,7 +272,7 @@ int td_io_queue(struct thread_data *td, struct io_u *io_u)
        io_u->error = 0;
        io_u->resid = 0;
 
        io_u->error = 0;
        io_u->resid = 0;
 
-       if (td->io_ops->flags & FIO_SYNCIO) {
+       if (td_ioengine_flagged(td, FIO_SYNCIO)) {
                if (fio_fill_issue_time(td))
                        fio_gettime(&io_u->issue_time, NULL);
 
                if (fio_fill_issue_time(td))
                        fio_gettime(&io_u->issue_time, NULL);
 
@@ -346,7 +346,7 @@ int td_io_queue(struct thread_data *td, struct io_u *io_u)
                }
        }
 
                }
        }
 
-       if ((td->io_ops->flags & FIO_SYNCIO) == 0) {
+       if (!td_ioengine_flagged(td, FIO_SYNCIO)) {
                if (fio_fill_issue_time(td))
                        fio_gettime(&io_u->issue_time, NULL);
 
                if (fio_fill_issue_time(td))
                        fio_gettime(&io_u->issue_time, NULL);
 
@@ -375,7 +375,7 @@ int td_io_init(struct thread_data *td)
                        td->error = ret;
        }
 
                        td->error = ret;
        }
 
-       if (!ret && (td->io_ops->flags & FIO_NOIO))
+       if (!ret && td_ioengine_flagged(td, FIO_NOIO))
                td->flags |= TD_F_NOIO;
 
        return ret;
                td->flags |= TD_F_NOIO;
 
        return ret;
@@ -441,7 +441,7 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f)
                }
        }
 
                }
        }
 
-       if (td->io_ops->flags & FIO_DISKLESSIO)
+       if (td_ioengine_flagged(td, FIO_DISKLESSIO))
                goto done;
 
        if (td->o.invalidate_cache && file_invalidate_cache(td, f))
                goto done;
 
        if (td->o.invalidate_cache && file_invalidate_cache(td, f))
index af4d5ef8ee371701f02806369a3581ecfdc42628..91241175978ec1ce32310c9c58fef6c38f79da71 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -215,13 +215,13 @@ int allocate_io_mem(struct thread_data *td)
        size_t total_mem;
        int ret = 0;
 
        size_t total_mem;
        int ret = 0;
 
-       if (td->io_ops->flags & FIO_NOIO)
+       if (td_ioengine_flagged(td, FIO_NOIO))
                return 0;
 
        total_mem = td->orig_buffer_size;
 
        if (td->o.odirect || td->o.mem_align || td->o.oatomic ||
                return 0;
 
        total_mem = td->orig_buffer_size;
 
        if (td->o.odirect || td->o.mem_align || td->o.oatomic ||
-           (td->io_ops->flags & FIO_MEMALIGN)) {
+           td_ioengine_flagged(td, FIO_MEMALIGN)) {
                total_mem += page_mask;
                if (td->o.mem_align && td->o.mem_align > page_size)
                        total_mem += td->o.mem_align - page_size;
                total_mem += page_mask;
                if (td->o.mem_align && td->o.mem_align > page_size)
                        total_mem += td->o.mem_align - page_size;
index 48b7a58ca182ddf255fcbbde30395f5af2082242..2efbdcba610902dd2c344c45f8a980dbd15c819e 100644 (file)
@@ -110,9 +110,6 @@ static int io_workqueue_init_worker_fn(struct submit_worker *sw)
        if (ioengine_load(td))
                goto err;
 
        if (ioengine_load(td))
                goto err;
 
-       if (td->o.odirect)
-               td->io_ops->flags |= FIO_RAWIO;
-
        td->pid = gettid();
 
        INIT_FLIST_HEAD(&td->io_log_list);
        td->pid = gettid();
 
        INIT_FLIST_HEAD(&td->io_log_list);
index 40cfbabfb049882ba748a709aca73b229f5ee360..3d9e26879f0adb914298386b02f9e3c4e9ea2416 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -802,7 +802,7 @@ int verify_io_u(struct thread_data *td, struct io_u **io_u_ptr)
         * If the IO engine is faking IO (like null), then just pretend
         * we verified everything.
         */
         * If the IO engine is faking IO (like null), then just pretend
         * we verified everything.
         */
-       if (td->io_ops->flags & FIO_FAKEIO)
+       if (td_ioengine_flagged(td, FIO_FAKEIO))
                return 0;
 
        if (io_u->flags & IO_U_F_TRIMMED) {
                return 0;
 
        if (io_u->flags & IO_U_F_TRIMMED) {