[PATCH] Fix division by zero in deviance calculation
[fio.git] / init.c
diff --git a/init.c b/init.c
index edaec144f3aaaa5895339df4f2a703bdff7d9c48..c450a4c117001e0a3189e240df31d100001bf09f 100644 (file)
--- a/init.c
+++ b/init.c
@@ -52,6 +52,7 @@
 #define DEF_WRITE_BW_LOG       (0)
 #define DEF_WRITE_LAT_LOG      (0)
 #define DEF_NO_RAND_MAP                (0)
+#define DEF_HUGEPAGE_SIZE      FIO_HUGE_PAGE
 
 #define td_var_offset(var)     ((size_t) &((struct thread_data *)0)->var)
 
@@ -358,6 +359,11 @@ static struct fio_option options[] = {
                .type   = FIO_OPT_STR_SET,
                .off1   = td_var_offset(bs_unaligned),
        },
+       {
+               .name   = "hugepage-size",
+               .type   = FIO_OPT_STR_VAL,
+               .off1   = td_var_offset(hugepage_size),
+       },
        {
                .name = NULL,
        },
@@ -409,7 +415,7 @@ static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
 
 static int def_timeout = DEF_TIMEOUT;
 
-static char fio_version_string[] = "fio 1.9";
+static char fio_version_string[] = "fio 1.10";
 
 static char **ini_file;
 static int max_jobs = MAX_JOBS;
@@ -826,6 +832,22 @@ static int str_verify_cb(void *data, const char *mem)
        return 1;
 }
 
+/*
+ * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
+ */
+static char *get_mmap_file(const char *str)
+{
+       char *p = strstr(str, ":");
+
+       if (!p)
+               return NULL;
+
+       p++;
+       strip_blank_front(&p);
+       strip_blank_end(p);
+       return strdup(p);
+}
+
 static int str_mem_cb(void *data, const char *mem)
 {
        struct thread_data *td = data;
@@ -835,21 +857,15 @@ static int str_mem_cb(void *data, const char *mem)
                return 0;
        } else if (!strncmp(mem, "mmaphuge", 8)) {
 #ifdef FIO_HAVE_HUGETLB
-               char *hugefile;
-
                /*
                 * mmaphuge must be appended with the actual file
                 */
-               hugefile = strstr(mem, ":");
-               if (!hugefile) {
+               td->mmapfile = get_mmap_file(mem);
+               if (!td->mmapfile) {
                        log_err("fio: mmaphuge:/path/to/file\n");
                        return 1;
                }
 
-               hugefile++;
-               strip_blank_front(&hugefile);
-               strip_blank_end(hugefile);
-               td->hugefile = strdup(hugefile);
                td->mem_type = MEM_MMAPHUGE;
                return 0;
 #else
@@ -857,6 +873,11 @@ static int str_mem_cb(void *data, const char *mem)
                return 1;
 #endif
        } else if (!strncmp(mem, "mmap", 4)) {
+               /*
+                * Check if the user wants file backed memory. It's ok
+                * if there's no file given, we'll just use anon mamp then.
+                */
+               td->mmapfile = get_mmap_file(mem);
                td->mem_type = MEM_MMAP;
                return 0;
        } else if (!strncmp(mem, "shmhuge", 7)) {
@@ -1058,6 +1079,7 @@ static int fill_def_thread(void)
        def_thread.write_bw_log = write_bw_log;
        def_thread.write_lat_log = write_lat_log;
        def_thread.norandommap = DEF_NO_RAND_MAP;
+       def_thread.hugepage_size = DEF_HUGEPAGE_SIZE;
 #ifdef FIO_HAVE_DISK_UTIL
        def_thread.do_disk_util = 1;
 #endif
@@ -1138,7 +1160,6 @@ static int parse_cmd_line(int argc, char *argv[])
                        break;
                }
                default:
-                       printf("optarg <<%s>>\n", argv[optind]);
                        break;
                }
        }