Add fill_device option
[fio.git] / options.c
index cd4b90a79271bc524d43d90ccfb9084c745f7dcc..36f80fce61a7f6fe24dda2c474580bc3b74bb4bf 100644 (file)
--- a/options.c
+++ b/options.c
@@ -28,6 +28,120 @@ static char *get_opt_postfix(const char *str)
        return strdup(p);
 }
 
+static int bs_cmp(const void *p1, const void *p2)
+{
+       const struct bssplit *bsp1 = p1;
+       const struct bssplit *bsp2 = p2;
+
+       return bsp1->perc < bsp2->perc;
+}
+
+static int str_bssplit_cb(void *data, const char *input)
+{
+       struct thread_data *td = data;
+       char *fname, *str, *p;
+       unsigned int i, perc, perc_missing;
+       unsigned int max_bs, min_bs;
+       long long val;
+
+       p = str = strdup(input);
+
+       strip_blank_front(&str);
+       strip_blank_end(str);
+
+       td->o.bssplit_nr = 4;
+       td->o.bssplit = malloc(4 * sizeof(struct bssplit));
+
+       i = 0;
+       max_bs = 0;
+       min_bs = -1;
+       while ((fname = strsep(&str, ":")) != NULL) {
+               char *perc_str;
+
+               if (!strlen(fname))
+                       break;
+
+               /*
+                * grow struct buffer, if needed
+                */
+               if (i == td->o.bssplit_nr) {
+                       td->o.bssplit_nr <<= 1;
+                       td->o.bssplit = realloc(td->o.bssplit, td->o.bssplit_nr * sizeof(struct bssplit));
+               }
+
+               perc_str = strstr(fname, "/");
+               if (perc_str) {
+                       *perc_str = '\0';
+                       perc_str++;
+                       perc = atoi(perc_str);
+                       if (perc > 100)
+                               perc = 100;
+                       else if (!perc)
+                               perc = -1;
+               } else
+                       perc = -1;
+
+               if (str_to_decimal(fname, &val, 1)) {
+                       log_err("fio: bssplit conversion failed\n");
+                       free(td->o.bssplit);
+                       return 1;
+               }
+
+               if (val > max_bs)
+                       max_bs = val;
+               if (val < min_bs)
+                       min_bs = val;
+
+               td->o.bssplit[i].bs = val;
+               td->o.bssplit[i].perc = perc;
+               i++;
+       }
+
+       td->o.bssplit_nr = 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; i++) {
+               struct bssplit *bsp = &td->o.bssplit[i];
+
+               if (bsp->perc == (unsigned char) -1)
+                       perc_missing++;
+               else
+                       perc += bsp->perc;
+       }
+
+       if (perc > 100) {
+               log_err("fio: bssplit percentages add to more than 100%%\n");
+               free(td->o.bssplit);
+               return 1;
+       }
+       /*
+        * If values didn't have a percentage set, divide the remains between
+        * them.
+        */
+       if (perc_missing) {
+               for (i = 0; i < td->o.bssplit_nr; i++) {
+                       struct bssplit *bsp = &td->o.bssplit[i];
+
+                       if (bsp->perc == (unsigned char) -1)
+                               bsp->perc = (100 - perc) / perc_missing;
+               }
+       }
+
+       td->o.min_bs[DDIR_READ] = td->o.min_bs[DDIR_WRITE] = min_bs;
+       td->o.max_bs[DDIR_READ] = td->o.max_bs[DDIR_WRITE] = max_bs;
+
+       /*
+        * now sort based on percentages, for ease of lookup
+        */
+       qsort(td->o.bssplit, td->o.bssplit_nr, sizeof(struct bssplit), bs_cmp);
+
+       free(p);
+       return 0;
+}
+
 static int str_rw_cb(void *data, const char *str)
 {
        struct thread_data *td = data;
@@ -74,6 +188,7 @@ static int str_prioclass_cb(void *data, unsigned int *val)
        td->ioprio &= mask;
 
        td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
+       td->ioprio_set = 1;
        return 0;
 }
 
@@ -89,6 +204,7 @@ static int str_prio_cb(void *data, unsigned int *val)
        if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
                td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
 
+       td->ioprio_set = 1;
        return 0;
 }
 #endif
@@ -217,12 +333,27 @@ static int str_verify_offset_cb(void *data, unsigned int *off)
        return 0;
 }
 
-static int str_verify_pattern_cb(void *data, unsigned int *off)
+static int str_verify_cb(void *data, const char *mem)
 {
        struct thread_data *td = data;
-       unsigned int msb;
+       unsigned int nr, msb;
+       char *pat;
+
+       if (td->o.verify != VERIFY_PATTERN)
+               return 0;
+
+       pat = get_opt_postfix(mem);
+       if (!pat) {
+               log_err("fio: missing pattern\n");
+               return 1;
+       }
+
+       if (strstr(pat, "0x") || strstr(pat, "0X"))
+               nr = strtol(pat, NULL, 16);
+       else
+               nr = strtol(pat, NULL, 16);
 
-       msb = fls(*off);
+       msb = fls(nr);
        if (msb <= 8)
                td->o.verify_pattern_bytes = 1;
        else if (msb <= 16)
@@ -232,7 +363,7 @@ static int str_verify_pattern_cb(void *data, unsigned int *off)
        else
                td->o.verify_pattern_bytes = 4;
 
-       td->o.verify_pattern = *off;
+       td->o.verify_pattern = nr;
        return 0;
 }
 
@@ -321,6 +452,9 @@ static struct fio_option options[] = {
                          { .ival = "sync",
                            .help = "Use read/write",
                          },
+                         { .ival = "psync",
+                           .help = "Use pread/pwrite",
+                         },
 #ifdef FIO_HAVE_LIBAIO
                          { .ival = "libaio",
                            .help = "Linux native asynchronous IO",
@@ -376,6 +510,7 @@ static struct fio_option options[] = {
                .type   = FIO_OPT_INT,
                .off1   = td_var_offset(iodepth),
                .help   = "Amount of IO buffers to keep in flight",
+               .minval = 1,
                .def    = "1",
        },
        {
@@ -399,6 +534,13 @@ static struct fio_option options[] = {
                .minval = 1,
                .help   = "Total size of device or files",
        },
+       {
+               .name   = "fill_device",
+               .type   = FIO_OPT_BOOL,
+               .off1   = td_var_offset(fill_device),
+               .help   = "Write until an ENOSPC error occurs",
+               .def    = "0",
+       },
        {
                .name   = "filesize",
                .type   = FIO_OPT_STR_VAL,
@@ -438,6 +580,13 @@ static struct fio_option options[] = {
                .help   = "Set block size range (in more detail than bs)",
                .parent = "rw",
        },
+       {
+               .name   = "bssplit",
+               .type   = FIO_OPT_STR,
+               .cb     = str_bssplit_cb,
+               .help   = "Set a specific mix of block sizes",
+               .parent = "rw",
+       },
        {
                .name   = "bs_unaligned",
                .alias  = "blocksize_unaligned",
@@ -599,17 +748,11 @@ static struct fio_option options[] = {
 #endif
                  },
        },
-       {
-               .name   = "do_verify",
-               .type   = FIO_OPT_INT,
-               .off1   = td_var_offset(do_verify),
-               .help   = "Run verification stage after write",
-               .def    = "1",
-       },
        {
                .name   = "verify",
                .type   = FIO_OPT_STR,
                .off1   = td_var_offset(verify),
+               .cb     = str_verify_cb,
                .help   = "Verify data written",
                .def    = "0",
                .posval = {
@@ -649,6 +792,10 @@ static struct fio_option options[] = {
                            .oval = VERIFY_META,
                            .help = "Use io information",
                          },
+                         { .ival = "pattern",
+                           .oval = VERIFY_PATTERN,
+                           .help = "Verify a specific buffer pattern",
+                         },
                          {
                            .ival = "null",
                            .oval = VERIFY_NULL,
@@ -656,6 +803,14 @@ static struct fio_option options[] = {
                          },
                },
        },
+       {
+               .name   = "do_verify",
+               .type   = FIO_OPT_BOOL,
+               .off1   = td_var_offset(do_verify),
+               .help   = "Run verification stage after write",
+               .def    = "1",
+               .parent = "verify",
+       },
        {
                .name   = "verifysort",
                .type   = FIO_OPT_BOOL,
@@ -681,11 +836,12 @@ static struct fio_option options[] = {
                .parent = "verify",
        },
        {
-               .name   = "verify_pattern",
-               .type   = FIO_OPT_INT,
-               .cb     = str_verify_pattern_cb,
-               .help   = "Fill pattern for IO buffers",
-               .parent = "verify",
+               .name   = "verify_fatal",
+               .type   = FIO_OPT_BOOL,
+               .off1   = td_var_offset(verify_fatal),
+               .def    = "0",
+               .help   = "Exit on a single verify failure, don't continue",
+               .parent = "verify",
        },
        {
                .name   = "write_iolog",