Start the process of making options more gfio friendly
authorJens Axboe <axboe@kernel.dk>
Wed, 28 Mar 2012 12:01:46 +0000 (14:01 +0200)
committerJens Axboe <axboe@kernel.dk>
Wed, 28 Mar 2012 12:01:46 +0000 (14:01 +0200)
We either need to eliminate the option callbacks, or ensure that
they don't have side effects outside of touching td->o. We will
need to use &td->o as the data passed in for the callbacks, not
the full td.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c
cconv.c
fio.h
goptions.c
memory.c
options.c
thread_options.h
verify.c
verify.h

index 319bd253342e164405d04cc5d1506a1e6f29337e..4c784e866a9cbbd91810660b11c3da82a38bda63 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1080,6 +1080,8 @@ static void *thread_main(void *data)
                        goto err;
        }
 
+       fio_verify_init(td);
+
        fio_gettime(&td->epoch, NULL);
        getrusage(RUSAGE_SELF, &td->ru_start);
 
diff --git a/cconv.c b/cconv.c
index 502cf82eaa5fc213b83f2189090c2d878ed0f6d1..8edfde09dcedd5dccac3fed2a9a1b27ac178a91e 100644 (file)
--- a/cconv.c
+++ b/cconv.c
@@ -29,6 +29,7 @@ void convert_thread_options_to_cpu(struct thread_options *o,
        string_to_cpu(&o->filename, top->filename);
        string_to_cpu(&o->opendir, top->opendir);
        string_to_cpu(&o->ioengine, top->ioengine);
+       string_to_cpu(&o->mmapfile, top->mmapfile);
        string_to_cpu(&o->read_iolog_file, top->read_iolog_file);
        string_to_cpu(&o->write_iolog_file, top->write_iolog_file);
        string_to_cpu(&o->bw_log_file, top->bw_log_file);
@@ -207,6 +208,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top,
        string_to_net(top->filename, o->filename);
        string_to_net(top->opendir, o->opendir);
        string_to_net(top->ioengine, o->ioengine);
+       string_to_net(top->mmapfile, o->mmapfile);
        string_to_net(top->read_iolog_file, o->read_iolog_file);
        string_to_net(top->write_iolog_file, o->write_iolog_file);
        string_to_net(top->bw_log_file, o->bw_log_file);
diff --git a/fio.h b/fio.h
index 6a7bd03ca92fa00d84719551cdfc673712a80511..0aa24a5a7db3626aad690ea48785e26841cfc81b 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -110,7 +110,6 @@ struct thread_data {
        unsigned int last_was_sync;
        enum fio_ddir last_ddir;
 
-       char *mmapfile;
        int mmapfd;
 
        void *iolog_buf;
index 28df6930e0abd74c929c186847c8ba2d1cb5c83a..b78accdaf3a141a7258680994cfe4f0b73f608a0 100644 (file)
@@ -523,7 +523,7 @@ static struct gopt_int *__gopt_new_int(struct gopt_job_view *gjv,
        else if (o->def) {
                long long val;
 
-               check_str_bytes(o->def, &val, NULL);
+               check_str_bytes(o->def, &val, o);
                defval = val;
        }
 
@@ -730,7 +730,7 @@ static struct gopt *gopt_new_int_range(struct gopt_job_view *gjv,
        if (o->def) {
                long long val;
 
-               check_str_bytes(o->def, &val, NULL);
+               check_str_bytes(o->def, &val, o);
                for (i = 0; i < GOPT_RANGE_SPIN; i++)
                        defvals[i] = val;
        }
index 82a79bd7175b9a74ca0846a669d767e06d50b84d..0135abb1b0eb42d574eed3fe646a69908de12983 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -121,8 +121,8 @@ static int alloc_mem_mmap(struct thread_data *td, size_t total_mem)
 
        td->mmapfd = 1;
 
-       if (td->mmapfile) {
-               td->mmapfd = open(td->mmapfile, O_RDWR|O_CREAT, 0644);
+       if (td->o.mmapfile) {
+               td->mmapfd = open(td->o.mmapfile, O_RDWR|O_CREAT, 0644);
 
                if (td->mmapfd < 0) {
                        td_verror(td, errno, "open mmap file");
@@ -146,7 +146,7 @@ static int alloc_mem_mmap(struct thread_data *td, size_t total_mem)
                td->orig_buffer = NULL;
                if (td->mmapfd) {
                        close(td->mmapfd);
-                       unlink(td->mmapfile);
+                       unlink(td->o.mmapfile);
                }
 
                return 1;
@@ -159,10 +159,10 @@ static void free_mem_mmap(struct thread_data *td, size_t total_mem)
 {
        dprint(FD_MEM, "munmap %u %p\n", total_mem, td->orig_buffer);
        munmap(td->orig_buffer, td->orig_buffer_size);
-       if (td->mmapfile) {
+       if (td->o.mmapfile) {
                close(td->mmapfd);
-               unlink(td->mmapfile);
-               free(td->mmapfile);
+               unlink(td->o.mmapfile);
+               free(td->o.mmapfile);
        }
 }
 
index d051da12c0b02f8dd8f2774c53f9e1bd5a8ae455..937a76e17cea9a518985a0d9973f1f6cdc062cf3 100644 (file)
--- a/options.c
+++ b/options.c
@@ -61,7 +61,7 @@ static int bs_cmp(const void *p1, const void *p2)
        return bsp1->perc < bsp2->perc;
 }
 
-static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
+static int bssplit_ddir(struct thread_options *o, int ddir, char *str)
 {
        struct bssplit *bssplit;
        unsigned int i, perc, perc_missing;
@@ -69,7 +69,7 @@ static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
        long long val;
        char *fname;
 
-       td->o.bssplit_nr[ddir] = 4;
+       o->bssplit_nr[ddir] = 4;
        bssplit = malloc(4 * sizeof(struct bssplit));
 
        i = 0;
@@ -84,9 +84,9 @@ static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
                /*
                 * grow struct buffer, if needed
                 */
-               if (i == td->o.bssplit_nr[ddir]) {
-                       td->o.bssplit_nr[ddir] <<= 1;
-                       bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
+               if (i == o->bssplit_nr[ddir]) {
+                       o->bssplit_nr[ddir] <<= 1;
+                       bssplit = realloc(bssplit, o->bssplit_nr[ddir]
                                                  * sizeof(struct bssplit));
                }
 
@@ -102,9 +102,9 @@ static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
                } else
                        perc = -1;
 
-               if (str_to_decimal(fname, &val, 1, td)) {
+               if (str_to_decimal(fname, &val, 1, o)) {
                        log_err("fio: bssplit conversion failed\n");
-                       free(td->o.bssplit);
+                       free(o->bssplit);
                        return 1;
                }
 
@@ -118,13 +118,13 @@ static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
                i++;
        }
 
-       td->o.bssplit_nr[ddir] = i;
+       o->bssplit_nr[ddir] = i;
 
        /*
         * Now check if the percentages add up, and how much is missing
         */
        perc = perc_missing = 0;
-       for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
+       for (i = 0; i < o->bssplit_nr[ddir]; i++) {
                struct bssplit *bsp = &bssplit[i];
 
                if (bsp->perc == (unsigned char) -1)
@@ -143,7 +143,7 @@ static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
         * them.
         */
        if (perc_missing) {
-               for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
+               for (i = 0; i < o->bssplit_nr[ddir]; i++) {
                        struct bssplit *bsp = &bssplit[i];
 
                        if (bsp->perc == (unsigned char) -1)
@@ -151,14 +151,14 @@ static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
                }
        }
 
-       td->o.min_bs[ddir] = min_bs;
-       td->o.max_bs[ddir] = max_bs;
+       o->min_bs[ddir] = min_bs;
+       o->max_bs[ddir] = max_bs;
 
        /*
         * now sort based on percentages, for ease of lookup
         */
-       qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
-       td->o.bssplit[ddir] = bssplit;
+       qsort(bssplit, o->bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
+       o->bssplit[ddir] = bssplit;
        return 0;
 }
 
@@ -175,19 +175,19 @@ static int str_bssplit_cb(void *data, const char *input)
 
        odir = strchr(str, ',');
        if (odir) {
-               ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
+               ret = bssplit_ddir(&td->o, DDIR_WRITE, odir + 1);
                if (!ret) {
                        *odir = '\0';
-                       ret = bssplit_ddir(td, DDIR_READ, str);
+                       ret = bssplit_ddir(&td->o, DDIR_READ, str);
                }
        } else {
                char *op;
 
                op = strdup(str);
 
-               ret = bssplit_ddir(td, DDIR_READ, str);
+               ret = bssplit_ddir(&td->o, DDIR_READ, str);
                if (!ret)
-                       ret = bssplit_ddir(td, DDIR_WRITE, op);
+                       ret = bssplit_ddir(&td->o, DDIR_WRITE, op);
 
                free(op);
        }
@@ -199,26 +199,27 @@ static int str_bssplit_cb(void *data, const char *input)
 static int str_rw_cb(void *data, const char *str)
 {
        struct thread_data *td = data;
+       struct thread_options *o = &td->o;
        char *nr = get_opt_postfix(str);
 
-       td->o.ddir_seq_nr = 1;
-       td->o.ddir_seq_add = 0;
+       o->ddir_seq_nr = 1;
+       o->ddir_seq_add = 0;
 
        if (!nr)
                return 0;
 
        if (td_random(td))
-               td->o.ddir_seq_nr = atoi(nr);
+               o->ddir_seq_nr = atoi(nr);
        else {
                long long val;
 
-               if (str_to_decimal(nr, &val, 1, td)) {
+               if (str_to_decimal(nr, &val, 1, o)) {
                        log_err("fio: rw postfix parsing failed\n");
                        free(nr);
                        return 1;
                }
 
-               td->o.ddir_seq_add = val;
+               o->ddir_seq_add = val;
        }
 
        free(nr);
@@ -228,10 +229,11 @@ static int str_rw_cb(void *data, const char *str)
 static int str_mem_cb(void *data, const char *mem)
 {
        struct thread_data *td = data;
+       struct thread_options *o = &td->o;
 
-       if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
-               td->mmapfile = get_opt_postfix(mem);
-               if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
+       if (o->mem_type == MEM_MMAPHUGE || o->mem_type == MEM_MMAP) {
+               o->mmapfile = get_opt_postfix(mem);
+               if (o->mem_type == MEM_MMAPHUGE && !o->mmapfile) {
                        log_err("fio: mmaphuge:/path/to/file\n");
                        return 1;
                }
@@ -240,18 +242,6 @@ static int str_mem_cb(void *data, const char *mem)
        return 0;
 }
 
-static int str_verify_cb(void *data, const char *mem)
-{
-       struct thread_data *td = data;
-
-       if (td->o.verify == VERIFY_CRC32C_INTEL ||
-           td->o.verify == VERIFY_CRC32C) {
-               crc32c_intel_probe();
-       }
-
-       return 0;
-}
-
 static int fio_clock_source_cb(void *data, const char *str)
 {
        struct thread_data *td = data;
@@ -1784,7 +1774,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .type   = FIO_OPT_STR,
                .off1   = td_var_offset(verify),
                .help   = "Verify data written",
-               .cb     = str_verify_cb,
                .def    = "0",
                .category = FIO_OPT_C_IO,
                .group  = FIO_OPT_G_VERIFY,
@@ -3256,11 +3245,11 @@ void fio_options_mem_dupe(struct thread_data *td)
 
 unsigned int fio_get_kb_base(void *data)
 {
-       struct thread_data *td = data;
+       struct thread_options *o = data;
        unsigned int kb_base = 0;
 
-       if (td)
-               kb_base = td->o.kb_base;
+       if (o)
+               kb_base = o->kb_base;
        if (!kb_base)
                kb_base = 1024;
 
index 61f4f5766e0904181689c09b1d15a4b664b25611..e9c67ee96d012e3bcd591c1f68dab25e98beddea 100644 (file)
@@ -43,6 +43,7 @@ struct thread_options {
        char *filename;
        char *opendir;
        char *ioengine;
+       char *mmapfile;
        enum td_ddir td_ddir;
        unsigned int rw_seq;
        unsigned int kb_base;
@@ -226,6 +227,7 @@ struct thread_options_pack {
        uint8_t filename[FIO_TOP_STR_MAX];
        uint8_t opendir[FIO_TOP_STR_MAX];
        uint8_t ioengine[FIO_TOP_STR_MAX];
+       uint8_t mmapfile[FIO_TOP_STR_MAX];
        uint32_t td_ddir;
        uint32_t rw_seq;
        uint32_t kb_base;
index f25eab921fc379691466b9e8c3866efd3a2133eb..0846d39276df52f71ab566d66a6d07eb3aeda635 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -1004,6 +1004,14 @@ int get_next_verify(struct thread_data *td, struct io_u *io_u)
        return 1;
 }
 
+void fio_verify_init(struct thread_data *td)
+{
+       if (td->o.verify == VERIFY_CRC32C_INTEL ||
+           td->o.verify == VERIFY_CRC32C) {
+               crc32c_intel_probe();
+       }
+}
+
 static void *verify_async_thread(void *data)
 {
        struct thread_data *td = data;
index 7c238c8d2de6c07f19497061e12a4c60ba6b06c3..6a81e9b012bc6fa0632a90ea0dc2e9acfe26755f 100644 (file)
--- a/verify.h
+++ b/verify.h
@@ -75,6 +75,7 @@ extern int __must_check get_next_verify(struct thread_data *td, struct io_u *);
 extern int __must_check verify_io_u(struct thread_data *, struct io_u *);
 extern int verify_io_u_async(struct thread_data *, struct io_u *);
 extern void fill_pattern(struct thread_data *td, void *p, unsigned int len, struct io_u *io_u, unsigned long seed, int use_seed);
+extern void fio_verify_init(struct thread_data *td);
 
 /*
  * Async verify offload