Make kb_base apply to parser k/m/g etc values
[fio.git] / options.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <ctype.h>
5 #include <string.h>
6 #include <getopt.h>
7 #include <assert.h>
8 #include <libgen.h>
9 #include <fcntl.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12
13 #include "fio.h"
14 #include "verify.h"
15 #include "parse.h"
16 #include "lib/fls.h"
17
18 unsigned int fio_kb_base = 1024;
19
20 #define td_var_offset(var)      ((size_t) &((struct thread_options *)0)->var)
21
22 /*
23  * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
24  */
25 static char *get_opt_postfix(const char *str)
26 {
27         char *p = strstr(str, ":");
28
29         if (!p)
30                 return NULL;
31
32         p++;
33         strip_blank_front(&p);
34         strip_blank_end(p);
35         return strdup(p);
36 }
37
38 static int bs_cmp(const void *p1, const void *p2)
39 {
40         const struct bssplit *bsp1 = p1;
41         const struct bssplit *bsp2 = p2;
42
43         return bsp1->perc < bsp2->perc;
44 }
45
46 static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
47 {
48         struct bssplit *bssplit;
49         unsigned int i, perc, perc_missing;
50         unsigned int max_bs, min_bs;
51         long long val;
52         char *fname;
53
54         td->o.bssplit_nr[ddir] = 4;
55         bssplit = malloc(4 * sizeof(struct bssplit));
56
57         i = 0;
58         max_bs = 0;
59         min_bs = -1;
60         while ((fname = strsep(&str, ":")) != NULL) {
61                 char *perc_str;
62
63                 if (!strlen(fname))
64                         break;
65
66                 /*
67                  * grow struct buffer, if needed
68                  */
69                 if (i == td->o.bssplit_nr[ddir]) {
70                         td->o.bssplit_nr[ddir] <<= 1;
71                         bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
72                                                   * sizeof(struct bssplit));
73                 }
74
75                 perc_str = strstr(fname, "/");
76                 if (perc_str) {
77                         *perc_str = '\0';
78                         perc_str++;
79                         perc = atoi(perc_str);
80                         if (perc > 100)
81                                 perc = 100;
82                         else if (!perc)
83                                 perc = -1;
84                 } else
85                         perc = -1;
86
87                 if (str_to_decimal(fname, &val, 1)) {
88                         log_err("fio: bssplit conversion failed\n");
89                         free(td->o.bssplit);
90                         return 1;
91                 }
92
93                 if (val > max_bs)
94                         max_bs = val;
95                 if (val < min_bs)
96                         min_bs = val;
97
98                 bssplit[i].bs = val;
99                 bssplit[i].perc = perc;
100                 i++;
101         }
102
103         td->o.bssplit_nr[ddir] = i;
104
105         /*
106          * Now check if the percentages add up, and how much is missing
107          */
108         perc = perc_missing = 0;
109         for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
110                 struct bssplit *bsp = &bssplit[i];
111
112                 if (bsp->perc == (unsigned char) -1)
113                         perc_missing++;
114                 else
115                         perc += bsp->perc;
116         }
117
118         if (perc > 100) {
119                 log_err("fio: bssplit percentages add to more than 100%%\n");
120                 free(bssplit);
121                 return 1;
122         }
123         /*
124          * If values didn't have a percentage set, divide the remains between
125          * them.
126          */
127         if (perc_missing) {
128                 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
129                         struct bssplit *bsp = &bssplit[i];
130
131                         if (bsp->perc == (unsigned char) -1)
132                                 bsp->perc = (100 - perc) / perc_missing;
133                 }
134         }
135
136         td->o.min_bs[ddir] = min_bs;
137         td->o.max_bs[ddir] = max_bs;
138
139         /*
140          * now sort based on percentages, for ease of lookup
141          */
142         qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
143         td->o.bssplit[ddir] = bssplit;
144         return 0;
145
146 }
147
148 static int str_bssplit_cb(void *data, const char *input)
149 {
150         struct thread_data *td = data;
151         char *str, *p, *odir;
152         int ret = 0;
153
154         p = str = strdup(input);
155
156         strip_blank_front(&str);
157         strip_blank_end(str);
158
159         odir = strchr(str, ',');
160         if (odir) {
161                 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
162                 if (!ret) {
163                         *odir = '\0';
164                         ret = bssplit_ddir(td, DDIR_READ, str);
165                 }
166         } else {
167                 char *op;
168
169                 op = strdup(str);
170
171                 ret = bssplit_ddir(td, DDIR_READ, str);
172                 if (!ret)
173                         ret = bssplit_ddir(td, DDIR_WRITE, op);
174
175                 free(op);
176         }
177
178         free(p);
179         return ret;
180 }
181
182 static int str_rw_cb(void *data, const char *str)
183 {
184         struct thread_data *td = data;
185         char *nr = get_opt_postfix(str);
186
187         td->o.ddir_nr = 1;
188         if (nr) {
189                 td->o.ddir_nr = atoi(nr);
190                 free(nr);
191         }
192
193         return 0;
194 }
195
196 static int str_mem_cb(void *data, const char *mem)
197 {
198         struct thread_data *td = data;
199
200         if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
201                 td->mmapfile = get_opt_postfix(mem);
202                 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
203                         log_err("fio: mmaphuge:/path/to/file\n");
204                         return 1;
205                 }
206         }
207
208         return 0;
209 }
210
211 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
212 {
213         mlock_size = *val;
214         return 0;
215 }
216
217 static int str_rwmix_read_cb(void *data, unsigned int *val)
218 {
219         struct thread_data *td = data;
220
221         td->o.rwmix[DDIR_READ] = *val;
222         td->o.rwmix[DDIR_WRITE] = 100 - *val;
223         return 0;
224 }
225
226 static int str_rwmix_write_cb(void *data, unsigned int *val)
227 {
228         struct thread_data *td = data;
229
230         td->o.rwmix[DDIR_WRITE] = *val;
231         td->o.rwmix[DDIR_READ] = 100 - *val;
232         return 0;
233 }
234
235 #ifdef FIO_HAVE_IOPRIO
236 static int str_prioclass_cb(void *data, unsigned int *val)
237 {
238         struct thread_data *td = data;
239         unsigned short mask;
240
241         /*
242          * mask off old class bits, str_prio_cb() may have set a default class
243          */
244         mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
245         td->ioprio &= mask;
246
247         td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
248         td->ioprio_set = 1;
249         return 0;
250 }
251
252 static int str_prio_cb(void *data, unsigned int *val)
253 {
254         struct thread_data *td = data;
255
256         td->ioprio |= *val;
257
258         /*
259          * If no class is set, assume BE
260          */
261         if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
262                 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
263
264         td->ioprio_set = 1;
265         return 0;
266 }
267 #endif
268
269 static int str_exitall_cb(void)
270 {
271         exitall_on_terminate = 1;
272         return 0;
273 }
274
275 #ifdef FIO_HAVE_CPU_AFFINITY
276 static int str_cpumask_cb(void *data, unsigned int *val)
277 {
278         struct thread_data *td = data;
279         unsigned int i;
280         long max_cpu;
281         int ret;
282
283         ret = fio_cpuset_init(&td->o.cpumask);
284         if (ret < 0) {
285                 log_err("fio: cpuset_init failed\n");
286                 td_verror(td, ret, "fio_cpuset_init");
287                 return 1;
288         }
289
290         max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
291
292         for (i = 0; i < sizeof(int) * 8; i++) {
293                 if ((1 << i) & *val) {
294                         if (i > max_cpu) {
295                                 log_err("fio: CPU %d too large (max=%ld)\n", i,
296                                                                 max_cpu);
297                                 return 1;
298                         }
299                         dprint(FD_PARSE, "set cpu allowed %d\n", i);
300                         fio_cpu_set(&td->o.cpumask, i);
301                 }
302         }
303
304         td->o.cpumask_set = 1;
305         return 0;
306 }
307
308 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
309                             const char *input)
310 {
311         char *cpu, *str, *p;
312         long max_cpu;
313         int ret = 0;
314
315         ret = fio_cpuset_init(mask);
316         if (ret < 0) {
317                 log_err("fio: cpuset_init failed\n");
318                 td_verror(td, ret, "fio_cpuset_init");
319                 return 1;
320         }
321
322         p = str = strdup(input);
323
324         strip_blank_front(&str);
325         strip_blank_end(str);
326
327         max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
328
329         while ((cpu = strsep(&str, ",")) != NULL) {
330                 char *str2, *cpu2;
331                 int icpu, icpu2;
332
333                 if (!strlen(cpu))
334                         break;
335
336                 str2 = cpu;
337                 icpu2 = -1;
338                 while ((cpu2 = strsep(&str2, "-")) != NULL) {
339                         if (!strlen(cpu2))
340                                 break;
341
342                         icpu2 = atoi(cpu2);
343                 }
344
345                 icpu = atoi(cpu);
346                 if (icpu2 == -1)
347                         icpu2 = icpu;
348                 while (icpu <= icpu2) {
349                         if (icpu >= FIO_MAX_CPUS) {
350                                 log_err("fio: your OS only supports up to"
351                                         " %d CPUs\n", (int) FIO_MAX_CPUS);
352                                 ret = 1;
353                                 break;
354                         }
355                         if (icpu > max_cpu) {
356                                 log_err("fio: CPU %d too large (max=%ld)\n",
357                                                         icpu, max_cpu);
358                                 ret = 1;
359                                 break;
360                         }
361         
362                         dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
363                         fio_cpu_set(mask, icpu);
364                         icpu++;
365                 }
366                 if (ret)
367                         break;
368         }
369
370         free(p);
371         if (!ret)
372                 td->o.cpumask_set = 1;
373         return ret;
374 }
375
376 static int str_cpus_allowed_cb(void *data, const char *input)
377 {
378         struct thread_data *td = data;
379         int ret;
380
381         ret = set_cpus_allowed(td, &td->o.cpumask, input);
382         if (!ret)
383                 td->o.cpumask_set = 1;
384
385         return ret;
386 }
387
388 static int str_verify_cpus_allowed_cb(void *data, const char *input)
389 {
390         struct thread_data *td = data;
391         int ret;
392
393         ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
394         if (!ret)
395                 td->o.verify_cpumask_set = 1;
396
397         return ret;
398 }
399 #endif
400
401 static int str_fst_cb(void *data, const char *str)
402 {
403         struct thread_data *td = data;
404         char *nr = get_opt_postfix(str);
405
406         td->file_service_nr = 1;
407         if (nr) {
408                 td->file_service_nr = atoi(nr);
409                 free(nr);
410         }
411
412         return 0;
413 }
414
415 static int check_dir(struct thread_data *td, char *fname)
416 {
417         char file[PATH_MAX], *dir;
418         int elen = 0;
419
420         if (td->o.directory) {
421                 strcpy(file, td->o.directory);
422                 strcat(file, "/");
423                 elen = strlen(file);
424         }
425
426         sprintf(file + elen, "%s", fname);
427         dir = dirname(file);
428
429 #if 0
430         {
431         struct stat sb;
432         /*
433          * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
434          * yet, so we can't do this check right here...
435          */
436         if (lstat(dir, &sb) < 0) {
437                 int ret = errno;
438
439                 log_err("fio: %s is not a directory\n", dir);
440                 td_verror(td, ret, "lstat");
441                 return 1;
442         }
443
444         if (!S_ISDIR(sb.st_mode)) {
445                 log_err("fio: %s is not a directory\n", dir);
446                 return 1;
447         }
448         }
449 #endif
450
451         return 0;
452 }
453
454 static int str_filename_cb(void *data, const char *input)
455 {
456         struct thread_data *td = data;
457         char *fname, *str, *p;
458
459         p = str = strdup(input);
460
461         strip_blank_front(&str);
462         strip_blank_end(str);
463
464         if (!td->files_index)
465                 td->o.nr_files = 0;
466
467         while ((fname = strsep(&str, ":")) != NULL) {
468                 if (!strlen(fname))
469                         break;
470                 if (check_dir(td, fname)) {
471                         free(p);
472                         return 1;
473                 }
474                 add_file(td, fname);
475                 td->o.nr_files++;
476         }
477
478         free(p);
479         return 0;
480 }
481
482 static int str_directory_cb(void *data, const char fio_unused *str)
483 {
484         struct thread_data *td = data;
485         struct stat sb;
486
487         if (lstat(td->o.directory, &sb) < 0) {
488                 int ret = errno;
489
490                 log_err("fio: %s is not a directory\n", td->o.directory);
491                 td_verror(td, ret, "lstat");
492                 return 1;
493         }
494         if (!S_ISDIR(sb.st_mode)) {
495                 log_err("fio: %s is not a directory\n", td->o.directory);
496                 return 1;
497         }
498
499         return 0;
500 }
501
502 static int str_opendir_cb(void *data, const char fio_unused *str)
503 {
504         struct thread_data *td = data;
505
506         if (!td->files_index)
507                 td->o.nr_files = 0;
508
509         return add_dir_files(td, td->o.opendir);
510 }
511
512 static int str_verify_offset_cb(void *data, unsigned int *off)
513 {
514         struct thread_data *td = data;
515
516         if (*off && *off < sizeof(struct verify_header)) {
517                 log_err("fio: verify_offset too small\n");
518                 return 1;
519         }
520
521         td->o.verify_offset = *off;
522         return 0;
523 }
524
525 static int str_verify_pattern_cb(void *data, unsigned int *off)
526 {
527         struct thread_data *td = data;
528         unsigned int msb;
529
530         msb = __fls(*off);
531         if (msb <= 8)
532                 td->o.verify_pattern_bytes = 1;
533         else if (msb <= 16)
534                 td->o.verify_pattern_bytes = 2;
535         else if (msb <= 24)
536                 td->o.verify_pattern_bytes = 3;
537         else
538                 td->o.verify_pattern_bytes = 4;
539
540         td->o.verify_pattern = *off;
541         return 0;
542 }
543
544 static int str_lockfile_cb(void *data, const char *str)
545 {
546         struct thread_data *td = data;
547         char *nr = get_opt_postfix(str);
548
549         td->o.lockfile_batch = 1;
550         if (nr) {
551                 td->o.lockfile_batch = atoi(nr);
552                 free(nr);
553         }
554
555         return 0;
556 }
557
558 static int str_write_bw_log_cb(void *data, const char *str)
559 {
560         struct thread_data *td = data;
561
562         if (str)
563                 td->o.bw_log_file = strdup(str);
564
565         td->o.write_bw_log = 1;
566         return 0;
567 }
568
569 static int str_write_lat_log_cb(void *data, const char *str)
570 {
571         struct thread_data *td = data;
572
573         if (str)
574                 td->o.lat_log_file = strdup(str);
575
576         td->o.write_lat_log = 1;
577         return 0;
578 }
579
580 static int str_gtod_reduce_cb(void *data, int *il)
581 {
582         struct thread_data *td = data;
583         int val = *il;
584
585         td->o.disable_clat = !!val;
586         td->o.disable_slat = !!val;
587         td->o.disable_bw = !!val;
588         if (val)
589                 td->tv_cache_mask = 63;
590
591         return 0;
592 }
593
594 static int str_gtod_cpu_cb(void *data, int *il)
595 {
596         struct thread_data *td = data;
597         int val = *il;
598
599         td->o.gtod_cpu = val;
600         td->o.gtod_offload = 1;
601         return 0;
602 }
603
604 static int rw_verify(struct fio_option *o, void *data)
605 {
606         struct thread_data *td = data;
607
608         if (read_only && td_write(td)) {
609                 log_err("fio: job <%s> has write bit set, but fio is in"
610                         " read-only mode\n", td->o.name);
611                 return 1;
612         }
613
614         return 0;
615 }
616
617 static int gtod_cpu_verify(struct fio_option *o, void *data)
618 {
619 #ifndef FIO_HAVE_CPU_AFFINITY
620         struct thread_data *td = data;
621
622         if (td->o.gtod_cpu) {
623                 log_err("fio: platform must support CPU affinity for"
624                         "gettimeofday() offloading\n");
625                 return 1;
626         }
627 #endif
628
629         return 0;
630 }
631
632 static int kb_base_verify(struct fio_option *o, void *data)
633 {
634         struct thread_data *td = data;
635
636         if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
637                 log_err("fio: kb_base set to nonsensical value: %u\n",
638                                 td->o.kb_base);
639                 return 1;
640         }
641
642         fio_kb_base = td->o.kb_base;
643         return 0;
644 }
645
646 #define __stringify_1(x)        #x
647 #define __stringify(x)          __stringify_1(x)
648
649 /*
650  * Map of job/command line options
651  */
652 static struct fio_option options[] = {
653         {
654                 .name   = "description",
655                 .type   = FIO_OPT_STR_STORE,
656                 .off1   = td_var_offset(description),
657                 .help   = "Text job description",
658         },
659         {
660                 .name   = "name",
661                 .type   = FIO_OPT_STR_STORE,
662                 .off1   = td_var_offset(name),
663                 .help   = "Name of this job",
664         },
665         {
666                 .name   = "directory",
667                 .type   = FIO_OPT_STR_STORE,
668                 .off1   = td_var_offset(directory),
669                 .cb     = str_directory_cb,
670                 .help   = "Directory to store files in",
671         },
672         {
673                 .name   = "filename",
674                 .type   = FIO_OPT_STR_STORE,
675                 .off1   = td_var_offset(filename),
676                 .cb     = str_filename_cb,
677                 .prio   = -1, /* must come after "directory" */
678                 .help   = "File(s) to use for the workload",
679         },
680         {
681                 .name   = "kb_base",
682                 .type   = FIO_OPT_INT,
683                 .off1   = td_var_offset(kb_base),
684                 .verify = kb_base_verify,
685                 .prio   = 1,
686                 .def    = "1024",
687                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
688         },
689         {
690                 .name   = "lockfile",
691                 .type   = FIO_OPT_STR,
692                 .cb     = str_lockfile_cb,
693                 .off1   = td_var_offset(file_lock_mode),
694                 .help   = "Lock file when doing IO to it",
695                 .parent = "filename",
696                 .def    = "none",
697                 .posval = {
698                           { .ival = "none",
699                             .oval = FILE_LOCK_NONE,
700                             .help = "No file locking",
701                           },
702                           { .ival = "exclusive",
703                             .oval = FILE_LOCK_EXCLUSIVE,
704                             .help = "Exclusive file lock",
705                           },
706                           {
707                             .ival = "readwrite",
708                             .oval = FILE_LOCK_READWRITE,
709                             .help = "Read vs write lock",
710                           },
711                 },
712         },
713         {
714                 .name   = "opendir",
715                 .type   = FIO_OPT_STR_STORE,
716                 .off1   = td_var_offset(opendir),
717                 .cb     = str_opendir_cb,
718                 .help   = "Recursively add files from this directory and down",
719         },
720         {
721                 .name   = "rw",
722                 .alias  = "readwrite",
723                 .type   = FIO_OPT_STR,
724                 .cb     = str_rw_cb,
725                 .off1   = td_var_offset(td_ddir),
726                 .help   = "IO direction",
727                 .def    = "read",
728                 .verify = rw_verify,
729                 .posval = {
730                           { .ival = "read",
731                             .oval = TD_DDIR_READ,
732                             .help = "Sequential read",
733                           },
734                           { .ival = "write",
735                             .oval = TD_DDIR_WRITE,
736                             .help = "Sequential write",
737                           },
738                           { .ival = "randread",
739                             .oval = TD_DDIR_RANDREAD,
740                             .help = "Random read",
741                           },
742                           { .ival = "randwrite",
743                             .oval = TD_DDIR_RANDWRITE,
744                             .help = "Random write",
745                           },
746                           { .ival = "rw",
747                             .oval = TD_DDIR_RW,
748                             .help = "Sequential read and write mix",
749                           },
750                           { .ival = "randrw",
751                             .oval = TD_DDIR_RANDRW,
752                             .help = "Random read and write mix"
753                           },
754                 },
755         },
756         {
757                 .name   = "ioengine",
758                 .type   = FIO_OPT_STR_STORE,
759                 .off1   = td_var_offset(ioengine),
760                 .help   = "IO engine to use",
761                 .def    = "sync",
762                 .posval = {
763                           { .ival = "sync",
764                             .help = "Use read/write",
765                           },
766                           { .ival = "psync",
767                             .help = "Use pread/pwrite",
768                           },
769                           { .ival = "vsync",
770                              .help = "Use readv/writev",
771                           },
772 #ifdef FIO_HAVE_LIBAIO
773                           { .ival = "libaio",
774                             .help = "Linux native asynchronous IO",
775                           },
776 #endif
777 #ifdef FIO_HAVE_POSIXAIO
778                           { .ival = "posixaio",
779                             .help = "POSIX asynchronous IO",
780                           },
781 #endif
782 #ifdef FIO_HAVE_SOLARISAIO
783                           { .ival = "solarisaio",
784                             .help = "Solaris native asynchronous IO",
785                           },
786 #endif
787                           { .ival = "mmap",
788                             .help = "Memory mapped IO",
789                           },
790 #ifdef FIO_HAVE_SPLICE
791                           { .ival = "splice",
792                             .help = "splice/vmsplice based IO",
793                           },
794                           { .ival = "netsplice",
795                             .help = "splice/vmsplice to/from the network",
796                           },
797 #endif
798 #ifdef FIO_HAVE_SGIO
799                           { .ival = "sg",
800                             .help = "SCSI generic v3 IO",
801                           },
802 #endif
803                           { .ival = "null",
804                             .help = "Testing engine (no data transfer)",
805                           },
806                           { .ival = "net",
807                             .help = "Network IO",
808                           },
809 #ifdef FIO_HAVE_SYSLET
810                           { .ival = "syslet-rw",
811                             .help = "syslet enabled async pread/pwrite IO",
812                           },
813 #endif
814                           { .ival = "cpuio",
815                             .help = "CPU cycler burner engine",
816                           },
817 #ifdef FIO_HAVE_GUASI
818                           { .ival = "guasi",
819                             .help = "GUASI IO engine",
820                           },
821 #endif
822                           { .ival = "external",
823                             .help = "Load external engine (append name)",
824                           },
825                 },
826         },
827         {
828                 .name   = "iodepth",
829                 .type   = FIO_OPT_INT,
830                 .off1   = td_var_offset(iodepth),
831                 .help   = "Amount of IO buffers to keep in flight",
832                 .minval = 1,
833                 .def    = "1",
834         },
835         {
836                 .name   = "iodepth_batch",
837                 .alias  = "iodepth_batch_submit",
838                 .type   = FIO_OPT_INT,
839                 .off1   = td_var_offset(iodepth_batch),
840                 .help   = "Number of IO buffers to submit in one go",
841                 .parent = "iodepth",
842                 .minval = 1,
843                 .def    = "1",
844         },
845         {
846                 .name   = "iodepth_batch_complete",
847                 .type   = FIO_OPT_INT,
848                 .off1   = td_var_offset(iodepth_batch_complete),
849                 .help   = "Number of IO buffers to retrieve in one go",
850                 .parent = "iodepth",
851                 .minval = 0,
852                 .def    = "1",
853         },
854         {
855                 .name   = "iodepth_low",
856                 .type   = FIO_OPT_INT,
857                 .off1   = td_var_offset(iodepth_low),
858                 .help   = "Low water mark for queuing depth",
859                 .parent = "iodepth",
860         },
861         {
862                 .name   = "size",
863                 .type   = FIO_OPT_STR_VAL,
864                 .off1   = td_var_offset(size),
865                 .minval = 1,
866                 .help   = "Total size of device or files",
867         },
868         {
869                 .name   = "fill_device",
870                 .type   = FIO_OPT_BOOL,
871                 .off1   = td_var_offset(fill_device),
872                 .help   = "Write until an ENOSPC error occurs",
873                 .def    = "0",
874         },
875         {
876                 .name   = "filesize",
877                 .type   = FIO_OPT_STR_VAL,
878                 .off1   = td_var_offset(file_size_low),
879                 .off2   = td_var_offset(file_size_high),
880                 .minval = 1,
881                 .help   = "Size of individual files",
882         },
883         {
884                 .name   = "offset",
885                 .alias  = "fileoffset",
886                 .type   = FIO_OPT_STR_VAL,
887                 .off1   = td_var_offset(start_offset),
888                 .help   = "Start IO from this offset",
889                 .def    = "0",
890         },
891         {
892                 .name   = "bs",
893                 .alias  = "blocksize",
894                 .type   = FIO_OPT_INT,
895                 .off1   = td_var_offset(bs[DDIR_READ]),
896                 .off2   = td_var_offset(bs[DDIR_WRITE]),
897                 .minval = 1,
898                 .help   = "Block size unit",
899                 .def    = "4k",
900                 .parent = "rw",
901         },
902         {
903                 .name   = "ba",
904                 .alias  = "blockalign",
905                 .type   = FIO_OPT_INT,
906                 .off1   = td_var_offset(ba[DDIR_READ]),
907                 .off2   = td_var_offset(ba[DDIR_WRITE]),
908                 .minval = 1,
909                 .help   = "IO block offset alignment",
910                 .parent = "rw",
911         },
912         {
913                 .name   = "bsrange",
914                 .alias  = "blocksize_range",
915                 .type   = FIO_OPT_RANGE,
916                 .off1   = td_var_offset(min_bs[DDIR_READ]),
917                 .off2   = td_var_offset(max_bs[DDIR_READ]),
918                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
919                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
920                 .minval = 1,
921                 .help   = "Set block size range (in more detail than bs)",
922                 .parent = "rw",
923         },
924         {
925                 .name   = "bssplit",
926                 .type   = FIO_OPT_STR,
927                 .cb     = str_bssplit_cb,
928                 .help   = "Set a specific mix of block sizes",
929                 .parent = "rw",
930         },
931         {
932                 .name   = "bs_unaligned",
933                 .alias  = "blocksize_unaligned",
934                 .type   = FIO_OPT_STR_SET,
935                 .off1   = td_var_offset(bs_unaligned),
936                 .help   = "Don't sector align IO buffer sizes",
937                 .parent = "rw",
938         },
939         {
940                 .name   = "randrepeat",
941                 .type   = FIO_OPT_BOOL,
942                 .off1   = td_var_offset(rand_repeatable),
943                 .help   = "Use repeatable random IO pattern",
944                 .def    = "1",
945                 .parent = "rw",
946         },
947         {
948                 .name   = "norandommap",
949                 .type   = FIO_OPT_STR_SET,
950                 .off1   = td_var_offset(norandommap),
951                 .help   = "Accept potential duplicate random blocks",
952                 .parent = "rw",
953         },
954         {
955                 .name   = "softrandommap",
956                 .type   = FIO_OPT_BOOL,
957                 .off1   = td_var_offset(softrandommap),
958                 .help   = "Set norandommap if randommap allocation fails",
959                 .parent = "norandommap",
960                 .def    = "0",
961         },
962         {
963                 .name   = "nrfiles",
964                 .type   = FIO_OPT_INT,
965                 .off1   = td_var_offset(nr_files),
966                 .help   = "Split job workload between this number of files",
967                 .def    = "1",
968         },
969         {
970                 .name   = "openfiles",
971                 .type   = FIO_OPT_INT,
972                 .off1   = td_var_offset(open_files),
973                 .help   = "Number of files to keep open at the same time",
974         },
975         {
976                 .name   = "file_service_type",
977                 .type   = FIO_OPT_STR,
978                 .cb     = str_fst_cb,
979                 .off1   = td_var_offset(file_service_type),
980                 .help   = "How to select which file to service next",
981                 .def    = "roundrobin",
982                 .posval = {
983                           { .ival = "random",
984                             .oval = FIO_FSERVICE_RANDOM,
985                             .help = "Choose a file at random",
986                           },
987                           { .ival = "roundrobin",
988                             .oval = FIO_FSERVICE_RR,
989                             .help = "Round robin select files",
990                           },
991                           { .ival = "sequential",
992                             .oval = FIO_FSERVICE_SEQ,
993                             .help = "Finish one file before moving to the next",
994                           },
995                 },
996                 .parent = "nrfiles",
997         },
998         {
999                 .name   = "fadvise_hint",
1000                 .type   = FIO_OPT_BOOL,
1001                 .off1   = td_var_offset(fadvise_hint),
1002                 .help   = "Use fadvise() to advise the kernel on IO pattern",
1003                 .def    = "1",
1004         },
1005         {
1006                 .name   = "fsync",
1007                 .type   = FIO_OPT_INT,
1008                 .off1   = td_var_offset(fsync_blocks),
1009                 .help   = "Issue fsync for writes every given number of blocks",
1010                 .def    = "0",
1011         },
1012         {
1013                 .name   = "fdatasync",
1014                 .type   = FIO_OPT_INT,
1015                 .off1   = td_var_offset(fdatasync_blocks),
1016                 .help   = "Issue fdatasync for writes every given number of blocks",
1017                 .def    = "0",
1018         },
1019         {
1020                 .name   = "direct",
1021                 .type   = FIO_OPT_BOOL,
1022                 .off1   = td_var_offset(odirect),
1023                 .help   = "Use O_DIRECT IO (negates buffered)",
1024                 .def    = "0",
1025         },
1026         {
1027                 .name   = "buffered",
1028                 .type   = FIO_OPT_BOOL,
1029                 .off1   = td_var_offset(odirect),
1030                 .neg    = 1,
1031                 .help   = "Use buffered IO (negates direct)",
1032                 .def    = "1",
1033         },
1034         {
1035                 .name   = "overwrite",
1036                 .type   = FIO_OPT_BOOL,
1037                 .off1   = td_var_offset(overwrite),
1038                 .help   = "When writing, set whether to overwrite current data",
1039                 .def    = "0",
1040         },
1041         {
1042                 .name   = "loops",
1043                 .type   = FIO_OPT_INT,
1044                 .off1   = td_var_offset(loops),
1045                 .help   = "Number of times to run the job",
1046                 .def    = "1",
1047         },
1048         {
1049                 .name   = "numjobs",
1050                 .type   = FIO_OPT_INT,
1051                 .off1   = td_var_offset(numjobs),
1052                 .help   = "Duplicate this job this many times",
1053                 .def    = "1",
1054         },
1055         {
1056                 .name   = "startdelay",
1057                 .type   = FIO_OPT_INT,
1058                 .off1   = td_var_offset(start_delay),
1059                 .help   = "Only start job when this period has passed",
1060                 .def    = "0",
1061         },
1062         {
1063                 .name   = "runtime",
1064                 .alias  = "timeout",
1065                 .type   = FIO_OPT_STR_VAL_TIME,
1066                 .off1   = td_var_offset(timeout),
1067                 .help   = "Stop workload when this amount of time has passed",
1068                 .def    = "0",
1069         },
1070         {
1071                 .name   = "time_based",
1072                 .type   = FIO_OPT_STR_SET,
1073                 .off1   = td_var_offset(time_based),
1074                 .help   = "Keep running until runtime/timeout is met",
1075         },
1076         {
1077                 .name   = "ramp_time",
1078                 .type   = FIO_OPT_STR_VAL_TIME,
1079                 .off1   = td_var_offset(ramp_time),
1080                 .help   = "Ramp up time before measuring performance",
1081         },
1082         {
1083                 .name   = "mem",
1084                 .alias  = "iomem",
1085                 .type   = FIO_OPT_STR,
1086                 .cb     = str_mem_cb,
1087                 .off1   = td_var_offset(mem_type),
1088                 .help   = "Backing type for IO buffers",
1089                 .def    = "malloc",
1090                 .posval = {
1091                           { .ival = "malloc",
1092                             .oval = MEM_MALLOC,
1093                             .help = "Use malloc(3) for IO buffers",
1094                           },
1095                           { .ival = "shm",
1096                             .oval = MEM_SHM,
1097                             .help = "Use shared memory segments for IO buffers",
1098                           },
1099 #ifdef FIO_HAVE_HUGETLB
1100                           { .ival = "shmhuge",
1101                             .oval = MEM_SHMHUGE,
1102                             .help = "Like shm, but use huge pages",
1103                           },
1104 #endif
1105                           { .ival = "mmap",
1106                             .oval = MEM_MMAP,
1107                             .help = "Use mmap(2) (file or anon) for IO buffers",
1108                           },
1109 #ifdef FIO_HAVE_HUGETLB
1110                           { .ival = "mmaphuge",
1111                             .oval = MEM_MMAPHUGE,
1112                             .help = "Like mmap, but use huge pages",
1113                           },
1114 #endif
1115                   },
1116         },
1117         {
1118                 .name   = "iomem_align",
1119                 .alias  = "mem_align",
1120                 .type   = FIO_OPT_INT,
1121                 .off1   = td_var_offset(mem_align),
1122                 .minval = 0,
1123                 .help   = "IO memory buffer offset alignment",
1124                 .def    = "0",
1125                 .parent = "iomem",
1126         },
1127         {
1128                 .name   = "verify",
1129                 .type   = FIO_OPT_STR,
1130                 .off1   = td_var_offset(verify),
1131                 .help   = "Verify data written",
1132                 .def    = "0",
1133                 .posval = {
1134                           { .ival = "0",
1135                             .oval = VERIFY_NONE,
1136                             .help = "Don't do IO verification",
1137                           },
1138                           { .ival = "md5",
1139                             .oval = VERIFY_MD5,
1140                             .help = "Use md5 checksums for verification",
1141                           },
1142                           { .ival = "crc64",
1143                             .oval = VERIFY_CRC64,
1144                             .help = "Use crc64 checksums for verification",
1145                           },
1146                           { .ival = "crc32",
1147                             .oval = VERIFY_CRC32,
1148                             .help = "Use crc32 checksums for verification",
1149                           },
1150                           { .ival = "crc32c-intel",
1151                             .oval = VERIFY_CRC32C_INTEL,
1152                             .help = "Use hw crc32c checksums for verification",
1153                           },
1154                           { .ival = "crc32c",
1155                             .oval = VERIFY_CRC32C,
1156                             .help = "Use crc32c checksums for verification",
1157                           },
1158                           { .ival = "crc16",
1159                             .oval = VERIFY_CRC16,
1160                             .help = "Use crc16 checksums for verification",
1161                           },
1162                           { .ival = "crc7",
1163                             .oval = VERIFY_CRC7,
1164                             .help = "Use crc7 checksums for verification",
1165                           },
1166                           { .ival = "sha256",
1167                             .oval = VERIFY_SHA256,
1168                             .help = "Use sha256 checksums for verification",
1169                           },
1170                           { .ival = "sha512",
1171                             .oval = VERIFY_SHA512,
1172                             .help = "Use sha512 checksums for verification",
1173                           },
1174                           { .ival = "meta",
1175                             .oval = VERIFY_META,
1176                             .help = "Use io information",
1177                           },
1178                           {
1179                             .ival = "null",
1180                             .oval = VERIFY_NULL,
1181                             .help = "Pretend to verify",
1182                           },
1183                 },
1184         },
1185         {
1186                 .name   = "do_verify",
1187                 .type   = FIO_OPT_BOOL,
1188                 .off1   = td_var_offset(do_verify),
1189                 .help   = "Run verification stage after write",
1190                 .def    = "1",
1191                 .parent = "verify",
1192         },
1193         {
1194                 .name   = "verifysort",
1195                 .type   = FIO_OPT_BOOL,
1196                 .off1   = td_var_offset(verifysort),
1197                 .help   = "Sort written verify blocks for read back",
1198                 .def    = "1",
1199                 .parent = "verify",
1200         },
1201         {
1202                 .name   = "verify_interval",
1203                 .type   = FIO_OPT_INT,
1204                 .off1   = td_var_offset(verify_interval),
1205                 .minval = 2 * sizeof(struct verify_header),
1206                 .help   = "Store verify buffer header every N bytes",
1207                 .parent = "verify",
1208         },
1209         {
1210                 .name   = "verify_offset",
1211                 .type   = FIO_OPT_INT,
1212                 .help   = "Offset verify header location by N bytes",
1213                 .def    = "0",
1214                 .cb     = str_verify_offset_cb,
1215                 .parent = "verify",
1216         },
1217         {
1218                 .name   = "verify_pattern",
1219                 .type   = FIO_OPT_INT,
1220                 .cb     = str_verify_pattern_cb,
1221                 .help   = "Fill pattern for IO buffers",
1222                 .parent = "verify",
1223         },
1224         {
1225                 .name   = "verify_fatal",
1226                 .type   = FIO_OPT_BOOL,
1227                 .off1   = td_var_offset(verify_fatal),
1228                 .def    = "0",
1229                 .help   = "Exit on a single verify failure, don't continue",
1230                 .parent = "verify",
1231         },
1232         {
1233                 .name   = "verify_async",
1234                 .type   = FIO_OPT_INT,
1235                 .off1   = td_var_offset(verify_async),
1236                 .def    = "0",
1237                 .help   = "Number of async verifier threads to use",
1238                 .parent = "verify",
1239         },
1240 #ifdef FIO_HAVE_CPU_AFFINITY
1241         {
1242                 .name   = "verify_async_cpus",
1243                 .type   = FIO_OPT_STR,
1244                 .cb     = str_verify_cpus_allowed_cb,
1245                 .help   = "Set CPUs allowed for async verify threads",
1246                 .parent = "verify_async",
1247         },
1248 #endif
1249         {
1250                 .name   = "write_iolog",
1251                 .type   = FIO_OPT_STR_STORE,
1252                 .off1   = td_var_offset(write_iolog_file),
1253                 .help   = "Store IO pattern to file",
1254         },
1255         {
1256                 .name   = "read_iolog",
1257                 .type   = FIO_OPT_STR_STORE,
1258                 .off1   = td_var_offset(read_iolog_file),
1259                 .help   = "Playback IO pattern from file",
1260         },
1261         {
1262                 .name   = "exec_prerun",
1263                 .type   = FIO_OPT_STR_STORE,
1264                 .off1   = td_var_offset(exec_prerun),
1265                 .help   = "Execute this file prior to running job",
1266         },
1267         {
1268                 .name   = "exec_postrun",
1269                 .type   = FIO_OPT_STR_STORE,
1270                 .off1   = td_var_offset(exec_postrun),
1271                 .help   = "Execute this file after running job",
1272         },
1273 #ifdef FIO_HAVE_IOSCHED_SWITCH
1274         {
1275                 .name   = "ioscheduler",
1276                 .type   = FIO_OPT_STR_STORE,
1277                 .off1   = td_var_offset(ioscheduler),
1278                 .help   = "Use this IO scheduler on the backing device",
1279         },
1280 #endif
1281         {
1282                 .name   = "zonesize",
1283                 .type   = FIO_OPT_STR_VAL,
1284                 .off1   = td_var_offset(zone_size),
1285                 .help   = "Give size of an IO zone",
1286                 .def    = "0",
1287         },
1288         {
1289                 .name   = "zoneskip",
1290                 .type   = FIO_OPT_STR_VAL,
1291                 .off1   = td_var_offset(zone_skip),
1292                 .help   = "Space between IO zones",
1293                 .def    = "0",
1294         },
1295         {
1296                 .name   = "lockmem",
1297                 .type   = FIO_OPT_STR_VAL,
1298                 .cb     = str_lockmem_cb,
1299                 .help   = "Lock down this amount of memory",
1300                 .def    = "0",
1301         },
1302         {
1303                 .name   = "rwmixread",
1304                 .type   = FIO_OPT_INT,
1305                 .cb     = str_rwmix_read_cb,
1306                 .maxval = 100,
1307                 .help   = "Percentage of mixed workload that is reads",
1308                 .def    = "50",
1309         },
1310         {
1311                 .name   = "rwmixwrite",
1312                 .type   = FIO_OPT_INT,
1313                 .cb     = str_rwmix_write_cb,
1314                 .maxval = 100,
1315                 .help   = "Percentage of mixed workload that is writes",
1316                 .def    = "50",
1317         },
1318         {
1319                 .name   = "rwmixcycle",
1320                 .type   = FIO_OPT_DEPRECATED,
1321         },
1322         {
1323                 .name   = "nice",
1324                 .type   = FIO_OPT_INT,
1325                 .off1   = td_var_offset(nice),
1326                 .help   = "Set job CPU nice value",
1327                 .minval = -19,
1328                 .maxval = 20,
1329                 .def    = "0",
1330         },
1331 #ifdef FIO_HAVE_IOPRIO
1332         {
1333                 .name   = "prio",
1334                 .type   = FIO_OPT_INT,
1335                 .cb     = str_prio_cb,
1336                 .help   = "Set job IO priority value",
1337                 .minval = 0,
1338                 .maxval = 7,
1339         },
1340         {
1341                 .name   = "prioclass",
1342                 .type   = FIO_OPT_INT,
1343                 .cb     = str_prioclass_cb,
1344                 .help   = "Set job IO priority class",
1345                 .minval = 0,
1346                 .maxval = 3,
1347         },
1348 #endif
1349         {
1350                 .name   = "thinktime",
1351                 .type   = FIO_OPT_INT,
1352                 .off1   = td_var_offset(thinktime),
1353                 .help   = "Idle time between IO buffers (usec)",
1354                 .def    = "0",
1355         },
1356         {
1357                 .name   = "thinktime_spin",
1358                 .type   = FIO_OPT_INT,
1359                 .off1   = td_var_offset(thinktime_spin),
1360                 .help   = "Start think time by spinning this amount (usec)",
1361                 .def    = "0",
1362                 .parent = "thinktime",
1363         },
1364         {
1365                 .name   = "thinktime_blocks",
1366                 .type   = FIO_OPT_INT,
1367                 .off1   = td_var_offset(thinktime_blocks),
1368                 .help   = "IO buffer period between 'thinktime'",
1369                 .def    = "1",
1370                 .parent = "thinktime",
1371         },
1372         {
1373                 .name   = "rate",
1374                 .type   = FIO_OPT_INT,
1375                 .off1   = td_var_offset(rate[0]),
1376                 .off2   = td_var_offset(rate[1]),
1377                 .help   = "Set bandwidth rate",
1378         },
1379         {
1380                 .name   = "ratemin",
1381                 .type   = FIO_OPT_INT,
1382                 .off1   = td_var_offset(ratemin[0]),
1383                 .off2   = td_var_offset(ratemin[1]),
1384                 .help   = "Job must meet this rate or it will be shutdown",
1385                 .parent = "rate",
1386         },
1387         {
1388                 .name   = "rate_iops",
1389                 .type   = FIO_OPT_INT,
1390                 .off1   = td_var_offset(rate_iops[0]),
1391                 .off2   = td_var_offset(rate_iops[1]),
1392                 .help   = "Limit IO used to this number of IO operations/sec",
1393         },
1394         {
1395                 .name   = "rate_iops_min",
1396                 .type   = FIO_OPT_INT,
1397                 .off1   = td_var_offset(rate_iops_min[0]),
1398                 .off2   = td_var_offset(rate_iops_min[1]),
1399                 .help   = "Job must meet this rate or it will be shutdown",
1400                 .parent = "rate_iops",
1401         },
1402         {
1403                 .name   = "ratecycle",
1404                 .type   = FIO_OPT_INT,
1405                 .off1   = td_var_offset(ratecycle),
1406                 .help   = "Window average for rate limits (msec)",
1407                 .def    = "1000",
1408                 .parent = "rate",
1409         },
1410         {
1411                 .name   = "invalidate",
1412                 .type   = FIO_OPT_BOOL,
1413                 .off1   = td_var_offset(invalidate_cache),
1414                 .help   = "Invalidate buffer/page cache prior to running job",
1415                 .def    = "1",
1416         },
1417         {
1418                 .name   = "sync",
1419                 .type   = FIO_OPT_BOOL,
1420                 .off1   = td_var_offset(sync_io),
1421                 .help   = "Use O_SYNC for buffered writes",
1422                 .def    = "0",
1423                 .parent = "buffered",
1424         },
1425         {
1426                 .name   = "bwavgtime",
1427                 .type   = FIO_OPT_INT,
1428                 .off1   = td_var_offset(bw_avg_time),
1429                 .help   = "Time window over which to calculate bandwidth"
1430                           " (msec)",
1431                 .def    = "500",
1432         },
1433         {
1434                 .name   = "create_serialize",
1435                 .type   = FIO_OPT_BOOL,
1436                 .off1   = td_var_offset(create_serialize),
1437                 .help   = "Serialize creating of job files",
1438                 .def    = "1",
1439         },
1440         {
1441                 .name   = "create_fsync",
1442                 .type   = FIO_OPT_BOOL,
1443                 .off1   = td_var_offset(create_fsync),
1444                 .help   = "Fsync file after creation",
1445                 .def    = "1",
1446         },
1447         {
1448                 .name   = "create_on_open",
1449                 .type   = FIO_OPT_BOOL,
1450                 .off1   = td_var_offset(create_on_open),
1451                 .help   = "Create files when they are opened for IO",
1452                 .def    = "0",
1453         },
1454         {
1455                 .name   = "pre_read",
1456                 .type   = FIO_OPT_BOOL,
1457                 .off1   = td_var_offset(pre_read),
1458                 .help   = "Preread files before starting official testing",
1459                 .def    = "0",
1460         },
1461         {
1462                 .name   = "cpuload",
1463                 .type   = FIO_OPT_INT,
1464                 .off1   = td_var_offset(cpuload),
1465                 .help   = "Use this percentage of CPU",
1466         },
1467         {
1468                 .name   = "cpuchunks",
1469                 .type   = FIO_OPT_INT,
1470                 .off1   = td_var_offset(cpucycle),
1471                 .help   = "Length of the CPU burn cycles (usecs)",
1472                 .def    = "50000",
1473                 .parent = "cpuload",
1474         },
1475 #ifdef FIO_HAVE_CPU_AFFINITY
1476         {
1477                 .name   = "cpumask",
1478                 .type   = FIO_OPT_INT,
1479                 .cb     = str_cpumask_cb,
1480                 .help   = "CPU affinity mask",
1481         },
1482         {
1483                 .name   = "cpus_allowed",
1484                 .type   = FIO_OPT_STR,
1485                 .cb     = str_cpus_allowed_cb,
1486                 .help   = "Set CPUs allowed",
1487         },
1488 #endif
1489         {
1490                 .name   = "end_fsync",
1491                 .type   = FIO_OPT_BOOL,
1492                 .off1   = td_var_offset(end_fsync),
1493                 .help   = "Include fsync at the end of job",
1494                 .def    = "0",
1495         },
1496         {
1497                 .name   = "fsync_on_close",
1498                 .type   = FIO_OPT_BOOL,
1499                 .off1   = td_var_offset(fsync_on_close),
1500                 .help   = "fsync files on close",
1501                 .def    = "0",
1502         },
1503         {
1504                 .name   = "unlink",
1505                 .type   = FIO_OPT_BOOL,
1506                 .off1   = td_var_offset(unlink),
1507                 .help   = "Unlink created files after job has completed",
1508                 .def    = "0",
1509         },
1510         {
1511                 .name   = "exitall",
1512                 .type   = FIO_OPT_STR_SET,
1513                 .cb     = str_exitall_cb,
1514                 .help   = "Terminate all jobs when one exits",
1515         },
1516         {
1517                 .name   = "stonewall",
1518                 .type   = FIO_OPT_STR_SET,
1519                 .off1   = td_var_offset(stonewall),
1520                 .help   = "Insert a hard barrier between this job and previous",
1521         },
1522         {
1523                 .name   = "new_group",
1524                 .type   = FIO_OPT_STR_SET,
1525                 .off1   = td_var_offset(new_group),
1526                 .help   = "Mark the start of a new group (for reporting)",
1527         },
1528         {
1529                 .name   = "thread",
1530                 .type   = FIO_OPT_STR_SET,
1531                 .off1   = td_var_offset(use_thread),
1532                 .help   = "Use threads instead of forks",
1533         },
1534         {
1535                 .name   = "write_bw_log",
1536                 .type   = FIO_OPT_STR,
1537                 .off1   = td_var_offset(write_bw_log),
1538                 .cb     = str_write_bw_log_cb,
1539                 .help   = "Write log of bandwidth during run",
1540         },
1541         {
1542                 .name   = "write_lat_log",
1543                 .type   = FIO_OPT_STR,
1544                 .off1   = td_var_offset(write_lat_log),
1545                 .cb     = str_write_lat_log_cb,
1546                 .help   = "Write log of latency during run",
1547         },
1548         {
1549                 .name   = "hugepage-size",
1550                 .type   = FIO_OPT_INT,
1551                 .off1   = td_var_offset(hugepage_size),
1552                 .help   = "When using hugepages, specify size of each page",
1553                 .def    = __stringify(FIO_HUGE_PAGE),
1554         },
1555         {
1556                 .name   = "group_reporting",
1557                 .type   = FIO_OPT_STR_SET,
1558                 .off1   = td_var_offset(group_reporting),
1559                 .help   = "Do reporting on a per-group basis",
1560         },
1561         {
1562                 .name   = "zero_buffers",
1563                 .type   = FIO_OPT_STR_SET,
1564                 .off1   = td_var_offset(zero_buffers),
1565                 .help   = "Init IO buffers to all zeroes",
1566         },
1567         {
1568                 .name   = "refill_buffers",
1569                 .type   = FIO_OPT_STR_SET,
1570                 .off1   = td_var_offset(refill_buffers),
1571                 .help   = "Refill IO buffers on every IO submit",
1572         },
1573 #ifdef FIO_HAVE_DISK_UTIL
1574         {
1575                 .name   = "disk_util",
1576                 .type   = FIO_OPT_BOOL,
1577                 .off1   = td_var_offset(do_disk_util),
1578                 .help   = "Log disk utilization statistics",
1579                 .def    = "1",
1580         },
1581 #endif
1582         {
1583                 .name   = "gtod_reduce",
1584                 .type   = FIO_OPT_BOOL,
1585                 .help   = "Greatly reduce number of gettimeofday() calls",
1586                 .cb     = str_gtod_reduce_cb,
1587                 .def    = "0",
1588         },
1589         {
1590                 .name   = "disable_clat",
1591                 .type   = FIO_OPT_BOOL,
1592                 .off1   = td_var_offset(disable_clat),
1593                 .help   = "Disable completion latency numbers",
1594                 .parent = "gtod_reduce",
1595                 .def    = "0",
1596         },
1597         {
1598                 .name   = "disable_slat",
1599                 .type   = FIO_OPT_BOOL,
1600                 .off1   = td_var_offset(disable_slat),
1601                 .help   = "Disable submissionn latency numbers",
1602                 .parent = "gtod_reduce",
1603                 .def    = "0",
1604         },
1605         {
1606                 .name   = "disable_bw_measurement",
1607                 .type   = FIO_OPT_BOOL,
1608                 .off1   = td_var_offset(disable_bw),
1609                 .help   = "Disable bandwidth logging",
1610                 .parent = "gtod_reduce",
1611                 .def    = "0",
1612         },
1613         {
1614                 .name   = "gtod_cpu",
1615                 .type   = FIO_OPT_INT,
1616                 .cb     = str_gtod_cpu_cb,
1617                 .help   = "Setup dedicated gettimeofday() thread on this CPU",
1618                 .verify = gtod_cpu_verify,
1619         },
1620         {
1621                 .name   = "continue_on_error",
1622                 .type   = FIO_OPT_BOOL,
1623                 .off1   = td_var_offset(continue_on_error),
1624                 .help   = "Continue on non-fatal errors during I/O",
1625                 .def    = "0",
1626         },
1627         {
1628                 .name = NULL,
1629         },
1630 };
1631
1632 void fio_options_dup_and_init(struct option *long_options)
1633 {
1634         struct fio_option *o;
1635         unsigned int i;
1636
1637         options_init(options);
1638
1639         i = 0;
1640         while (long_options[i].name)
1641                 i++;
1642
1643         o = &options[0];
1644         while (o->name) {
1645                 long_options[i].name = (char *) o->name;
1646                 long_options[i].val = FIO_GETOPT_JOB;
1647                 if (o->type == FIO_OPT_STR_SET)
1648                         long_options[i].has_arg = no_argument;
1649                 else
1650                         long_options[i].has_arg = required_argument;
1651
1652                 i++;
1653                 o++;
1654                 assert(i < FIO_NR_OPTIONS);
1655         }
1656 }
1657
1658 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
1659 {
1660         int i, ret;
1661
1662         sort_options(opts, options, num_opts);
1663
1664         for (ret = 0, i = 0; i < num_opts; i++)
1665                 ret |= parse_option(opts[i], options, td);
1666
1667         return ret;
1668 }
1669
1670 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1671 {
1672         return parse_cmd_option(opt, val, options, td);
1673 }
1674
1675 void fio_fill_default_options(struct thread_data *td)
1676 {
1677         fill_default_options(td, options);
1678 }
1679
1680 int fio_show_option_help(const char *opt)
1681 {
1682         return show_cmd_help(options, opt);
1683 }
1684
1685 static void __options_mem(struct thread_data *td, int alloc)
1686 {
1687         struct thread_options *o = &td->o;
1688         struct fio_option *opt;
1689         char **ptr;
1690         int i;
1691
1692         for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1693                 if (opt->type != FIO_OPT_STR_STORE)
1694                         continue;
1695
1696                 ptr = (void *) o + opt->off1;
1697                 if (*ptr) {
1698                         if (alloc)
1699                                 *ptr = strdup(*ptr);
1700                         else {
1701                                 free(*ptr);
1702                                 *ptr = NULL;
1703                         }
1704                 }
1705         }
1706 }
1707
1708 /*
1709  * dupe FIO_OPT_STR_STORE options
1710  */
1711 void options_mem_dupe(struct thread_data *td)
1712 {
1713         __options_mem(td, 1);
1714 }
1715
1716 void options_mem_free(struct thread_data fio_unused *td)
1717 {
1718 #if 0
1719         __options_mem(td, 0);
1720 #endif
1721 }