[PATCH] Add 'bs_unaligned' option
[fio.git] / init.c
diff --git a/init.c b/init.c
index 2cfa6d286544421dfd033bd9fecdb94890fa3d0b..6ad3c64c4221124d779ae982ac3b96ee12ced5bc 100644 (file)
--- a/init.c
+++ b/init.c
@@ -51,6 +51,7 @@
 #define DEF_UNLINK             (0)
 #define DEF_WRITE_BW_LOG       (0)
 #define DEF_WRITE_LAT_LOG      (0)
+#define DEF_NO_RAND_MAP                (0)
 
 #define td_var_offset(var)     ((size_t) &((struct thread_data *)0)->var)
 
@@ -342,6 +343,16 @@ static struct fio_option options[] = {
                .type   = FIO_OPT_STR_SET,
                .off1   = td_var_offset(write_lat_log),
        },
+       {
+               .name   = "norandommap",
+               .type   = FIO_OPT_STR_SET,
+               .off1   = td_var_offset(norandommap),
+       },
+       {
+               .name   = "bs_unaligned",
+               .type   = FIO_OPT_STR_SET,
+               .off1   = td_var_offset(bs_unaligned),
+       },
        {
                .name = NULL,
        },
@@ -479,6 +490,13 @@ static void fixup_options(struct thread_data *td)
                td->max_bs = td->bs;
        if (td_read(td) && !td_rw(td))
                td->verify = 0;
+
+       if (td->norandommap && td->verify != VERIFY_NONE) {
+               log_err("fio: norandommap given, verify disabled\n");
+               td->verify = VERIFY_NONE;
+       }
+       if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
+               log_err("fio: bs_unaligned may not work with raw io\n");
 }
 
 /*
@@ -524,6 +542,9 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                }
        }
 
+       if (td->odirect)
+               td->io_ops->flags |= FIO_RAWIO;
+
        fixup_options(td);
 
        td->filetype = FIO_TYPE_FILE;
@@ -534,9 +555,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                        td->filetype = FIO_TYPE_CHAR;
        }
 
-       if (td->odirect)
-               td->io_ops->flags |= FIO_RAWIO;
-
        if (td->filename)
                td->nr_uniq_files = 1;
        else
@@ -674,12 +692,14 @@ int init_random_state(struct thread_data *td)
        if (td->rand_repeatable)
                seeds[3] = DEF_RANDSEED;
 
-       for_each_file(td, f, i) {
-               blocks = (f->file_size + td->min_bs - 1) / td->min_bs;
-               num_maps = blocks / BLOCKS_PER_MAP;
-               f->file_map = malloc(num_maps * sizeof(long));
-               f->num_maps = num_maps;
-               memset(f->file_map, 0, num_maps * sizeof(long));
+       if (!td->norandommap) {
+               for_each_file(td, f, i) {
+                       blocks = (f->file_size + td->min_bs - 1) / td->min_bs;
+                       num_maps = blocks / BLOCKS_PER_MAP;
+                       f->file_map = malloc(num_maps * sizeof(long));
+                       f->num_maps = num_maps;
+                       memset(f->file_map, 0, num_maps * sizeof(long));
+               }
        }
 
        os_random_seed(seeds[3], &td->random_state);
@@ -843,7 +863,7 @@ int parse_jobs_ini(char *file, int stonewall_flag)
 {
        unsigned int global;
        struct thread_data *td;
-       char *string, *name, *tmpbuf;
+       char *string, *name;
        fpos_t off;
        FILE *f;
        char *p;
@@ -857,15 +877,16 @@ int parse_jobs_ini(char *file, int stonewall_flag)
 
        string = malloc(4096);
        name = malloc(256);
-       tmpbuf = malloc(4096);
+       memset(name, 0, 256);
 
        stonewall = stonewall_flag;
-       while ((p = fgets(string, 4096, f)) != NULL) {
-               if (ret)
+       do {
+               p = fgets(string, 4095, f);
+               if (!p)
                        break;
                if (is_empty_or_comment(p))
                        continue;
-               if (sscanf(p, "[%s]", name) != 1)
+               if (sscanf(p, "[%255s]", name) != 1)
                        continue;
 
                global = !strncmp(name, "global", 6);
@@ -890,10 +911,12 @@ int parse_jobs_ini(char *file, int stonewall_flag)
                while ((p = fgets(string, 4096, f)) != NULL) {
                        if (is_empty_or_comment(p))
                                continue;
-                       if (strstr(p, "["))
-                               break;
 
                        strip_blank_front(&p);
+
+                       if (p[0] == '[')
+                               break;
+
                        strip_blank_end(p);
 
                        fgetpos(f, &off);
@@ -903,20 +926,17 @@ int parse_jobs_ini(char *file, int stonewall_flag)
                         * dump all the bad ones. Makes trial/error fixups
                         * easier on the user.
                         */
-                       ret = parse_option(p, options, td);
+                       ret |= parse_option(p, options, td);
                }
 
                if (!ret) {
                        fsetpos(f, &off);
                        ret = add_job(td, name, 0);
                }
-               if (ret)
-                       break;
-       }
+       } while (!ret);
 
        free(string);
        free(name);
-       free(tmpbuf);
        fclose(f);
        return ret;
 }
@@ -962,6 +982,7 @@ static int fill_def_thread(void)
        def_thread.unlink = DEF_UNLINK;
        def_thread.write_bw_log = write_bw_log;
        def_thread.write_lat_log = write_lat_log;
+       def_thread.norandommap = DEF_NO_RAND_MAP;
 #ifdef FIO_HAVE_DISK_UTIL
        def_thread.do_disk_util = 1;
 #endif