Add support for preadv2/pwritev2
[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 <assert.h>
7 #include <libgen.h>
8 #include <fcntl.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <netinet/in.h>
12
13 #include "fio.h"
14 #include "verify.h"
15 #include "parse.h"
16 #include "lib/fls.h"
17 #include "lib/pattern.h"
18 #include "options.h"
19 #include "optgroup.h"
20
21 char client_sockaddr_str[INET6_ADDRSTRLEN] = { 0 };
22
23 /*
24  * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
25  */
26 static char *get_opt_postfix(const char *str)
27 {
28         char *p = strstr(str, ":");
29
30         if (!p)
31                 return NULL;
32
33         p++;
34         strip_blank_front(&p);
35         strip_blank_end(p);
36         return strdup(p);
37 }
38
39 static int bs_cmp(const void *p1, const void *p2)
40 {
41         const struct bssplit *bsp1 = p1;
42         const struct bssplit *bsp2 = p2;
43
44         return (int) bsp1->perc - (int) bsp2->perc;
45 }
46
47 static int bssplit_ddir(struct thread_options *o, int ddir, char *str)
48 {
49         struct bssplit *bssplit;
50         unsigned int i, perc, perc_missing;
51         unsigned int max_bs, min_bs;
52         long long val;
53         char *fname;
54
55         o->bssplit_nr[ddir] = 4;
56         bssplit = malloc(4 * sizeof(struct bssplit));
57
58         i = 0;
59         max_bs = 0;
60         min_bs = -1;
61         while ((fname = strsep(&str, ":")) != NULL) {
62                 char *perc_str;
63
64                 if (!strlen(fname))
65                         break;
66
67                 /*
68                  * grow struct buffer, if needed
69                  */
70                 if (i == o->bssplit_nr[ddir]) {
71                         o->bssplit_nr[ddir] <<= 1;
72                         bssplit = realloc(bssplit, o->bssplit_nr[ddir]
73                                                   * sizeof(struct bssplit));
74                 }
75
76                 perc_str = strstr(fname, "/");
77                 if (perc_str) {
78                         *perc_str = '\0';
79                         perc_str++;
80                         perc = atoi(perc_str);
81                         if (perc > 100)
82                                 perc = 100;
83                         else if (!perc)
84                                 perc = -1U;
85                 } else
86                         perc = -1U;
87
88                 if (str_to_decimal(fname, &val, 1, o, 0, 0)) {
89                         log_err("fio: bssplit conversion failed\n");
90                         free(bssplit);
91                         return 1;
92                 }
93
94                 if (val > max_bs)
95                         max_bs = val;
96                 if (val < min_bs)
97                         min_bs = val;
98
99                 bssplit[i].bs = val;
100                 bssplit[i].perc = perc;
101                 i++;
102         }
103
104         o->bssplit_nr[ddir] = i;
105
106         /*
107          * Now check if the percentages add up, and how much is missing
108          */
109         perc = perc_missing = 0;
110         for (i = 0; i < o->bssplit_nr[ddir]; i++) {
111                 struct bssplit *bsp = &bssplit[i];
112
113                 if (bsp->perc == -1U)
114                         perc_missing++;
115                 else
116                         perc += bsp->perc;
117         }
118
119         if (perc > 100 && perc_missing > 1) {
120                 log_err("fio: bssplit percentages add to more than 100%%\n");
121                 free(bssplit);
122                 return 1;
123         }
124
125         /*
126          * If values didn't have a percentage set, divide the remains between
127          * them.
128          */
129         if (perc_missing) {
130                 if (perc_missing == 1 && o->bssplit_nr[ddir] == 1)
131                         perc = 100;
132                 for (i = 0; i < o->bssplit_nr[ddir]; i++) {
133                         struct bssplit *bsp = &bssplit[i];
134
135                         if (bsp->perc == -1U)
136                                 bsp->perc = (100 - perc) / perc_missing;
137                 }
138         }
139
140         o->min_bs[ddir] = min_bs;
141         o->max_bs[ddir] = max_bs;
142
143         /*
144          * now sort based on percentages, for ease of lookup
145          */
146         qsort(bssplit, o->bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
147         o->bssplit[ddir] = bssplit;
148         return 0;
149 }
150
151 static int str_bssplit_cb(void *data, const char *input)
152 {
153         struct thread_data *td = data;
154         char *str, *p, *odir, *ddir;
155         int ret = 0;
156
157         if (parse_dryrun())
158                 return 0;
159
160         p = str = strdup(input);
161
162         strip_blank_front(&str);
163         strip_blank_end(str);
164
165         odir = strchr(str, ',');
166         if (odir) {
167                 ddir = strchr(odir + 1, ',');
168                 if (ddir) {
169                         ret = bssplit_ddir(&td->o, DDIR_TRIM, ddir + 1);
170                         if (!ret)
171                                 *ddir = '\0';
172                 } else {
173                         char *op;
174
175                         op = strdup(odir + 1);
176                         ret = bssplit_ddir(&td->o, DDIR_TRIM, op);
177
178                         free(op);
179                 }
180                 if (!ret)
181                         ret = bssplit_ddir(&td->o, DDIR_WRITE, odir + 1);
182                 if (!ret) {
183                         *odir = '\0';
184                         ret = bssplit_ddir(&td->o, DDIR_READ, str);
185                 }
186         } else {
187                 char *op;
188
189                 op = strdup(str);
190                 ret = bssplit_ddir(&td->o, DDIR_WRITE, op);
191                 free(op);
192
193                 if (!ret) {
194                         op = strdup(str);
195                         ret = bssplit_ddir(&td->o, DDIR_TRIM, op);
196                         free(op);
197                 }
198                 if (!ret)
199                         ret = bssplit_ddir(&td->o, DDIR_READ, str);
200         }
201
202         free(p);
203         return ret;
204 }
205
206 static int str2error(char *str)
207 {
208         const char *err[] = { "EPERM", "ENOENT", "ESRCH", "EINTR", "EIO",
209                             "ENXIO", "E2BIG", "ENOEXEC", "EBADF",
210                             "ECHILD", "EAGAIN", "ENOMEM", "EACCES",
211                             "EFAULT", "ENOTBLK", "EBUSY", "EEXIST",
212                             "EXDEV", "ENODEV", "ENOTDIR", "EISDIR",
213                             "EINVAL", "ENFILE", "EMFILE", "ENOTTY",
214                             "ETXTBSY","EFBIG", "ENOSPC", "ESPIPE",
215                             "EROFS","EMLINK", "EPIPE", "EDOM", "ERANGE" };
216         int i = 0, num = sizeof(err) / sizeof(void *);
217
218         while (i < num) {
219                 if (!strcmp(err[i], str))
220                         return i + 1;
221                 i++;
222         }
223         return 0;
224 }
225
226 static int ignore_error_type(struct thread_data *td, int etype, char *str)
227 {
228         unsigned int i;
229         int *error;
230         char *fname;
231
232         if (etype >= ERROR_TYPE_CNT) {
233                 log_err("Illegal error type\n");
234                 return 1;
235         }
236
237         td->o.ignore_error_nr[etype] = 4;
238         error = malloc(4 * sizeof(struct bssplit));
239
240         i = 0;
241         while ((fname = strsep(&str, ":")) != NULL) {
242
243                 if (!strlen(fname))
244                         break;
245
246                 /*
247                  * grow struct buffer, if needed
248                  */
249                 if (i == td->o.ignore_error_nr[etype]) {
250                         td->o.ignore_error_nr[etype] <<= 1;
251                         error = realloc(error, td->o.ignore_error_nr[etype]
252                                                   * sizeof(int));
253                 }
254                 if (fname[0] == 'E') {
255                         error[i] = str2error(fname);
256                 } else {
257                         error[i] = atoi(fname);
258                         if (error[i] < 0)
259                                 error[i] = -error[i];
260                 }
261                 if (!error[i]) {
262                         log_err("Unknown error %s, please use number value \n",
263                                   fname);
264                         free(error);
265                         return 1;
266                 }
267                 i++;
268         }
269         if (i) {
270                 td->o.continue_on_error |= 1 << etype;
271                 td->o.ignore_error_nr[etype] = i;
272                 td->o.ignore_error[etype] = error;
273         } else
274                 free(error);
275
276         return 0;
277
278 }
279
280 static int str_ignore_error_cb(void *data, const char *input)
281 {
282         struct thread_data *td = data;
283         char *str, *p, *n;
284         int type = 0, ret = 1;
285
286         if (parse_dryrun())
287                 return 0;
288
289         p = str = strdup(input);
290
291         strip_blank_front(&str);
292         strip_blank_end(str);
293
294         while (p) {
295                 n = strchr(p, ',');
296                 if (n)
297                         *n++ = '\0';
298                 ret = ignore_error_type(td, type, p);
299                 if (ret)
300                         break;
301                 p = n;
302                 type++;
303         }
304         free(str);
305         return ret;
306 }
307
308 static int str_rw_cb(void *data, const char *str)
309 {
310         struct thread_data *td = data;
311         struct thread_options *o = &td->o;
312         char *nr;
313
314         if (parse_dryrun())
315                 return 0;
316
317         o->ddir_seq_nr = 1;
318         o->ddir_seq_add = 0;
319
320         nr = get_opt_postfix(str);
321         if (!nr)
322                 return 0;
323
324         if (td_random(td))
325                 o->ddir_seq_nr = atoi(nr);
326         else {
327                 long long val;
328
329                 if (str_to_decimal(nr, &val, 1, o, 0, 0)) {
330                         log_err("fio: rw postfix parsing failed\n");
331                         free(nr);
332                         return 1;
333                 }
334
335                 o->ddir_seq_add = val;
336         }
337
338         free(nr);
339         return 0;
340 }
341
342 static int str_mem_cb(void *data, const char *mem)
343 {
344         struct thread_data *td = data;
345
346         if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP ||
347             td->o.mem_type == MEM_MMAPSHARED)
348                 td->o.mmapfile = get_opt_postfix(mem);
349
350         return 0;
351 }
352
353 static int fio_clock_source_cb(void *data, const char *str)
354 {
355         struct thread_data *td = data;
356
357         fio_clock_source = td->o.clocksource;
358         fio_clock_source_set = 1;
359         fio_clock_init();
360         return 0;
361 }
362
363 static int str_rwmix_read_cb(void *data, unsigned long long *val)
364 {
365         struct thread_data *td = data;
366
367         td->o.rwmix[DDIR_READ] = *val;
368         td->o.rwmix[DDIR_WRITE] = 100 - *val;
369         return 0;
370 }
371
372 static int str_rwmix_write_cb(void *data, unsigned long long *val)
373 {
374         struct thread_data *td = data;
375
376         td->o.rwmix[DDIR_WRITE] = *val;
377         td->o.rwmix[DDIR_READ] = 100 - *val;
378         return 0;
379 }
380
381 static int str_exitall_cb(void)
382 {
383         exitall_on_terminate = 1;
384         return 0;
385 }
386
387 #ifdef FIO_HAVE_CPU_AFFINITY
388 int fio_cpus_split(os_cpu_mask_t *mask, unsigned int cpu_index)
389 {
390         unsigned int i, index, cpus_in_mask;
391         const long max_cpu = cpus_online();
392
393         cpus_in_mask = fio_cpu_count(mask);
394         cpu_index = cpu_index % cpus_in_mask;
395
396         index = 0;
397         for (i = 0; i < max_cpu; i++) {
398                 if (!fio_cpu_isset(mask, i))
399                         continue;
400
401                 if (cpu_index != index)
402                         fio_cpu_clear(mask, i);
403
404                 index++;
405         }
406
407         return fio_cpu_count(mask);
408 }
409
410 static int str_cpumask_cb(void *data, unsigned long long *val)
411 {
412         struct thread_data *td = data;
413         unsigned int i;
414         long max_cpu;
415         int ret;
416
417         if (parse_dryrun())
418                 return 0;
419
420         ret = fio_cpuset_init(&td->o.cpumask);
421         if (ret < 0) {
422                 log_err("fio: cpuset_init failed\n");
423                 td_verror(td, ret, "fio_cpuset_init");
424                 return 1;
425         }
426
427         max_cpu = cpus_online();
428
429         for (i = 0; i < sizeof(int) * 8; i++) {
430                 if ((1 << i) & *val) {
431                         if (i >= max_cpu) {
432                                 log_err("fio: CPU %d too large (max=%ld)\n", i,
433                                                                 max_cpu - 1);
434                                 return 1;
435                         }
436                         dprint(FD_PARSE, "set cpu allowed %d\n", i);
437                         fio_cpu_set(&td->o.cpumask, i);
438                 }
439         }
440
441         return 0;
442 }
443
444 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
445                             const char *input)
446 {
447         char *cpu, *str, *p;
448         long max_cpu;
449         int ret = 0;
450
451         ret = fio_cpuset_init(mask);
452         if (ret < 0) {
453                 log_err("fio: cpuset_init failed\n");
454                 td_verror(td, ret, "fio_cpuset_init");
455                 return 1;
456         }
457
458         p = str = strdup(input);
459
460         strip_blank_front(&str);
461         strip_blank_end(str);
462
463         max_cpu = cpus_online();
464
465         while ((cpu = strsep(&str, ",")) != NULL) {
466                 char *str2, *cpu2;
467                 int icpu, icpu2;
468
469                 if (!strlen(cpu))
470                         break;
471
472                 str2 = cpu;
473                 icpu2 = -1;
474                 while ((cpu2 = strsep(&str2, "-")) != NULL) {
475                         if (!strlen(cpu2))
476                                 break;
477
478                         icpu2 = atoi(cpu2);
479                 }
480
481                 icpu = atoi(cpu);
482                 if (icpu2 == -1)
483                         icpu2 = icpu;
484                 while (icpu <= icpu2) {
485                         if (icpu >= FIO_MAX_CPUS) {
486                                 log_err("fio: your OS only supports up to"
487                                         " %d CPUs\n", (int) FIO_MAX_CPUS);
488                                 ret = 1;
489                                 break;
490                         }
491                         if (icpu >= max_cpu) {
492                                 log_err("fio: CPU %d too large (max=%ld)\n",
493                                                         icpu, max_cpu - 1);
494                                 ret = 1;
495                                 break;
496                         }
497
498                         dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
499                         fio_cpu_set(mask, icpu);
500                         icpu++;
501                 }
502                 if (ret)
503                         break;
504         }
505
506         free(p);
507         return ret;
508 }
509
510 static int str_cpus_allowed_cb(void *data, const char *input)
511 {
512         struct thread_data *td = data;
513
514         if (parse_dryrun())
515                 return 0;
516
517         return set_cpus_allowed(td, &td->o.cpumask, input);
518 }
519
520 static int str_verify_cpus_allowed_cb(void *data, const char *input)
521 {
522         struct thread_data *td = data;
523
524         if (parse_dryrun())
525                 return 0;
526
527         return set_cpus_allowed(td, &td->o.verify_cpumask, input);
528 }
529
530 #ifdef CONFIG_ZLIB
531 static int str_log_cpus_allowed_cb(void *data, const char *input)
532 {
533         struct thread_data *td = data;
534
535         if (parse_dryrun())
536                 return 0;
537
538         return set_cpus_allowed(td, &td->o.log_gz_cpumask, input);
539 }
540 #endif /* CONFIG_ZLIB */
541
542 #endif /* FIO_HAVE_CPU_AFFINITY */
543
544 #ifdef CONFIG_LIBNUMA
545 static int str_numa_cpunodes_cb(void *data, char *input)
546 {
547         struct thread_data *td = data;
548         struct bitmask *verify_bitmask;
549
550         if (parse_dryrun())
551                 return 0;
552
553         /* numa_parse_nodestring() parses a character string list
554          * of nodes into a bit mask. The bit mask is allocated by
555          * numa_allocate_nodemask(), so it should be freed by
556          * numa_free_nodemask().
557          */
558         verify_bitmask = numa_parse_nodestring(input);
559         if (verify_bitmask == NULL) {
560                 log_err("fio: numa_parse_nodestring failed\n");
561                 td_verror(td, 1, "str_numa_cpunodes_cb");
562                 return 1;
563         }
564         numa_free_nodemask(verify_bitmask);
565
566         td->o.numa_cpunodes = strdup(input);
567         return 0;
568 }
569
570 static int str_numa_mpol_cb(void *data, char *input)
571 {
572         struct thread_data *td = data;
573         const char * const policy_types[] =
574                 { "default", "prefer", "bind", "interleave", "local", NULL };
575         int i;
576         char *nodelist;
577         struct bitmask *verify_bitmask;
578
579         if (parse_dryrun())
580                 return 0;
581
582         nodelist = strchr(input, ':');
583         if (nodelist) {
584                 /* NUL-terminate mode */
585                 *nodelist++ = '\0';
586         }
587
588         for (i = 0; i <= MPOL_LOCAL; i++) {
589                 if (!strcmp(input, policy_types[i])) {
590                         td->o.numa_mem_mode = i;
591                         break;
592                 }
593         }
594         if (i > MPOL_LOCAL) {
595                 log_err("fio: memory policy should be: default, prefer, bind, interleave, local\n");
596                 goto out;
597         }
598
599         switch (td->o.numa_mem_mode) {
600         case MPOL_PREFERRED:
601                 /*
602                  * Insist on a nodelist of one node only
603                  */
604                 if (nodelist) {
605                         char *rest = nodelist;
606                         while (isdigit(*rest))
607                                 rest++;
608                         if (*rest) {
609                                 log_err("fio: one node only for \'prefer\'\n");
610                                 goto out;
611                         }
612                 } else {
613                         log_err("fio: one node is needed for \'prefer\'\n");
614                         goto out;
615                 }
616                 break;
617         case MPOL_INTERLEAVE:
618                 /*
619                  * Default to online nodes with memory if no nodelist
620                  */
621                 if (!nodelist)
622                         nodelist = strdup("all");
623                 break;
624         case MPOL_LOCAL:
625         case MPOL_DEFAULT:
626                 /*
627                  * Don't allow a nodelist
628                  */
629                 if (nodelist) {
630                         log_err("fio: NO nodelist for \'local\'\n");
631                         goto out;
632                 }
633                 break;
634         case MPOL_BIND:
635                 /*
636                  * Insist on a nodelist
637                  */
638                 if (!nodelist) {
639                         log_err("fio: a nodelist is needed for \'bind\'\n");
640                         goto out;
641                 }
642                 break;
643         }
644
645
646         /* numa_parse_nodestring() parses a character string list
647          * of nodes into a bit mask. The bit mask is allocated by
648          * numa_allocate_nodemask(), so it should be freed by
649          * numa_free_nodemask().
650          */
651         switch (td->o.numa_mem_mode) {
652         case MPOL_PREFERRED:
653                 td->o.numa_mem_prefer_node = atoi(nodelist);
654                 break;
655         case MPOL_INTERLEAVE:
656         case MPOL_BIND:
657                 verify_bitmask = numa_parse_nodestring(nodelist);
658                 if (verify_bitmask == NULL) {
659                         log_err("fio: numa_parse_nodestring failed\n");
660                         td_verror(td, 1, "str_numa_memnodes_cb");
661                         return 1;
662                 }
663                 td->o.numa_memnodes = strdup(nodelist);
664                 numa_free_nodemask(verify_bitmask);
665
666                 break;
667         case MPOL_LOCAL:
668         case MPOL_DEFAULT:
669         default:
670                 break;
671         }
672
673         return 0;
674 out:
675         return 1;
676 }
677 #endif
678
679 static int str_fst_cb(void *data, const char *str)
680 {
681         struct thread_data *td = data;
682         char *nr = get_opt_postfix(str);
683
684         td->file_service_nr = 1;
685         if (nr) {
686                 td->file_service_nr = atoi(nr);
687                 free(nr);
688         }
689
690         return 0;
691 }
692
693 #ifdef CONFIG_SYNC_FILE_RANGE
694 static int str_sfr_cb(void *data, const char *str)
695 {
696         struct thread_data *td = data;
697         char *nr = get_opt_postfix(str);
698
699         td->sync_file_range_nr = 1;
700         if (nr) {
701                 td->sync_file_range_nr = atoi(nr);
702                 free(nr);
703         }
704
705         return 0;
706 }
707 #endif
708
709 static int str_random_distribution_cb(void *data, const char *str)
710 {
711         struct thread_data *td = data;
712         double val;
713         char *nr;
714
715         if (parse_dryrun())
716                 return 0;
717
718         if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
719                 val = FIO_DEF_ZIPF;
720         else if (td->o.random_distribution == FIO_RAND_DIST_PARETO)
721                 val = FIO_DEF_PARETO;
722         else if (td->o.random_distribution == FIO_RAND_DIST_GAUSS)
723                 val = 0.0;
724         else
725                 return 0;
726
727         nr = get_opt_postfix(str);
728         if (nr && !str_to_float(nr, &val, 0)) {
729                 log_err("fio: random postfix parsing failed\n");
730                 free(nr);
731                 return 1;
732         }
733
734         free(nr);
735
736         if (td->o.random_distribution == FIO_RAND_DIST_ZIPF) {
737                 if (val == 1.00) {
738                         log_err("fio: zipf theta must different than 1.0\n");
739                         return 1;
740                 }
741                 td->o.zipf_theta.u.f = val;
742         } else if (td->o.random_distribution == FIO_RAND_DIST_PARETO) {
743                 if (val <= 0.00 || val >= 1.00) {
744                         log_err("fio: pareto input out of range (0 < input < 1.0)\n");
745                         return 1;
746                 }
747                 td->o.pareto_h.u.f = val;
748         } else {
749                 if (val <= 0.00 || val >= 100.0) {
750                         log_err("fio: normal deviation out of range (0 < input < 100.0)\n");
751                         return 1;
752                 }
753                 td->o.gauss_dev.u.f = val;
754         }
755
756         return 0;
757 }
758
759 /*
760  * Return next name in the string. Files are separated with ':'. If the ':'
761  * is escaped with a '\', then that ':' is part of the filename and does not
762  * indicate a new file.
763  */
764 static char *get_next_name(char **ptr)
765 {
766         char *str = *ptr;
767         char *p, *start;
768
769         if (!str || !strlen(str))
770                 return NULL;
771
772         start = str;
773         do {
774                 /*
775                  * No colon, we are done
776                  */
777                 p = strchr(str, ':');
778                 if (!p) {
779                         *ptr = NULL;
780                         break;
781                 }
782
783                 /*
784                  * We got a colon, but it's the first character. Skip and
785                  * continue
786                  */
787                 if (p == start) {
788                         str = ++start;
789                         continue;
790                 }
791
792                 if (*(p - 1) != '\\') {
793                         *p = '\0';
794                         *ptr = p + 1;
795                         break;
796                 }
797
798                 memmove(p - 1, p, strlen(p) + 1);
799                 str = p;
800         } while (1);
801
802         return start;
803 }
804
805
806 static int get_max_name_idx(char *input)
807 {
808         unsigned int cur_idx;
809         char *str, *p;
810
811         p = str = strdup(input);
812         for (cur_idx = 0; ; cur_idx++)
813                 if (get_next_name(&str) == NULL)
814                         break;
815
816         free(p);
817         return cur_idx;
818 }
819
820 /*
821  * Returns the directory at the index, indexes > entires will be
822  * assigned via modulo division of the index
823  */
824 int set_name_idx(char *target, size_t tlen, char *input, int index)
825 {
826         unsigned int cur_idx;
827         int len;
828         char *fname, *str, *p;
829
830         p = str = strdup(input);
831
832         index %= get_max_name_idx(input);
833         for (cur_idx = 0; cur_idx <= index; cur_idx++)
834                 fname = get_next_name(&str);
835
836         if (client_sockaddr_str[0]) {
837                 len = snprintf(target, tlen, "%s/%s.", fname,
838                                 client_sockaddr_str);
839         } else
840                 len = snprintf(target, tlen, "%s/", fname);
841
842         target[tlen - 1] = '\0';
843         free(p);
844
845         return len;
846 }
847
848 static int str_filename_cb(void *data, const char *input)
849 {
850         struct thread_data *td = data;
851         char *fname, *str, *p;
852
853         p = str = strdup(input);
854
855         strip_blank_front(&str);
856         strip_blank_end(str);
857
858         if (!td->files_index)
859                 td->o.nr_files = 0;
860
861         while ((fname = get_next_name(&str)) != NULL) {
862                 if (!strlen(fname))
863                         break;
864                 add_file(td, fname, 0, 1);
865         }
866
867         free(p);
868         return 0;
869 }
870
871 static int str_directory_cb(void *data, const char fio_unused *unused)
872 {
873         struct thread_data *td = data;
874         struct stat sb;
875         char *dirname, *str, *p;
876         int ret = 0;
877
878         if (parse_dryrun())
879                 return 0;
880
881         p = str = strdup(td->o.directory);
882         while ((dirname = get_next_name(&str)) != NULL) {
883                 if (lstat(dirname, &sb) < 0) {
884                         ret = errno;
885
886                         log_err("fio: %s is not a directory\n", dirname);
887                         td_verror(td, ret, "lstat");
888                         goto out;
889                 }
890                 if (!S_ISDIR(sb.st_mode)) {
891                         log_err("fio: %s is not a directory\n", dirname);
892                         ret = 1;
893                         goto out;
894                 }
895         }
896
897 out:
898         free(p);
899         return ret;
900 }
901
902 static int str_opendir_cb(void *data, const char fio_unused *str)
903 {
904         struct thread_data *td = data;
905
906         if (parse_dryrun())
907                 return 0;
908
909         if (!td->files_index)
910                 td->o.nr_files = 0;
911
912         return add_dir_files(td, td->o.opendir);
913 }
914
915 static int str_buffer_pattern_cb(void *data, const char *input)
916 {
917         struct thread_data *td = data;
918         int ret;
919
920         /* FIXME: for now buffer pattern does not support formats */
921         ret = parse_and_fill_pattern(input, strlen(input), td->o.buffer_pattern,
922                                      MAX_PATTERN_SIZE, NULL, 0, NULL, NULL);
923         if (ret < 0)
924                 return 1;
925
926         assert(ret != 0);
927         td->o.buffer_pattern_bytes = ret;
928         if (!td->o.compress_percentage)
929                 td->o.refill_buffers = 0;
930         td->o.scramble_buffers = 0;
931         td->o.zero_buffers = 0;
932
933         return 0;
934 }
935
936 static int str_buffer_compress_cb(void *data, unsigned long long *il)
937 {
938         struct thread_data *td = data;
939
940         td->flags |= TD_F_COMPRESS;
941         td->o.compress_percentage = *il;
942         return 0;
943 }
944
945 static int str_dedupe_cb(void *data, unsigned long long *il)
946 {
947         struct thread_data *td = data;
948
949         td->flags |= TD_F_COMPRESS;
950         td->o.dedupe_percentage = *il;
951         td->o.refill_buffers = 1;
952         return 0;
953 }
954
955 static int str_verify_pattern_cb(void *data, const char *input)
956 {
957         struct pattern_fmt_desc fmt_desc[] = {
958                 {
959                         .fmt   = "%o",
960                         .len   = FIELD_SIZE(struct io_u *, offset),
961                         .paste = paste_blockoff
962                 }
963         };
964         struct thread_data *td = data;
965         int ret;
966
967         td->o.verify_fmt_sz = ARRAY_SIZE(td->o.verify_fmt);
968         ret = parse_and_fill_pattern(input, strlen(input), td->o.verify_pattern,
969                         MAX_PATTERN_SIZE, fmt_desc, sizeof(fmt_desc),
970                         td->o.verify_fmt, &td->o.verify_fmt_sz);
971         if (ret < 0)
972                 return 1;
973
974         assert(ret != 0);
975         td->o.verify_pattern_bytes = ret;
976         /*
977          * VERIFY_* could already be set
978          */
979         if (!fio_option_is_set(&td->o, verify))
980                 td->o.verify = VERIFY_PATTERN;
981
982         return 0;
983 }
984
985 static int str_gtod_reduce_cb(void *data, int *il)
986 {
987         struct thread_data *td = data;
988         int val = *il;
989
990         td->o.disable_lat = !!val;
991         td->o.disable_clat = !!val;
992         td->o.disable_slat = !!val;
993         td->o.disable_bw = !!val;
994         td->o.clat_percentiles = !val;
995         if (val)
996                 td->tv_cache_mask = 63;
997
998         return 0;
999 }
1000
1001 static int str_size_cb(void *data, unsigned long long *__val)
1002 {
1003         struct thread_data *td = data;
1004         unsigned long long v = *__val;
1005
1006         if (parse_is_percent(v)) {
1007                 td->o.size = 0;
1008                 td->o.size_percent = -1ULL - v;
1009         } else
1010                 td->o.size = v;
1011
1012         return 0;
1013 }
1014
1015 static int rw_verify(struct fio_option *o, void *data)
1016 {
1017         struct thread_data *td = data;
1018
1019         if (read_only && td_write(td)) {
1020                 log_err("fio: job <%s> has write bit set, but fio is in"
1021                         " read-only mode\n", td->o.name);
1022                 return 1;
1023         }
1024
1025         return 0;
1026 }
1027
1028 static int gtod_cpu_verify(struct fio_option *o, void *data)
1029 {
1030 #ifndef FIO_HAVE_CPU_AFFINITY
1031         struct thread_data *td = data;
1032
1033         if (td->o.gtod_cpu) {
1034                 log_err("fio: platform must support CPU affinity for"
1035                         "gettimeofday() offloading\n");
1036                 return 1;
1037         }
1038 #endif
1039
1040         return 0;
1041 }
1042
1043 /*
1044  * Map of job/command line options
1045  */
1046 struct fio_option fio_options[FIO_MAX_OPTS] = {
1047         {
1048                 .name   = "description",
1049                 .lname  = "Description of job",
1050                 .type   = FIO_OPT_STR_STORE,
1051                 .off1   = td_var_offset(description),
1052                 .help   = "Text job description",
1053                 .category = FIO_OPT_C_GENERAL,
1054                 .group  = FIO_OPT_G_DESC,
1055         },
1056         {
1057                 .name   = "name",
1058                 .lname  = "Job name",
1059                 .type   = FIO_OPT_STR_STORE,
1060                 .off1   = td_var_offset(name),
1061                 .help   = "Name of this job",
1062                 .category = FIO_OPT_C_GENERAL,
1063                 .group  = FIO_OPT_G_DESC,
1064         },
1065         {
1066                 .name   = "wait_for",
1067                 .lname  = "Waitee name",
1068                 .type   = FIO_OPT_STR_STORE,
1069                 .off1   = td_var_offset(wait_for),
1070                 .help   = "Name of the job this one wants to wait for before starting",
1071                 .category = FIO_OPT_C_GENERAL,
1072                 .group  = FIO_OPT_G_DESC,
1073         },
1074         {
1075                 .name   = "filename",
1076                 .lname  = "Filename(s)",
1077                 .type   = FIO_OPT_STR_STORE,
1078                 .off1   = td_var_offset(filename),
1079                 .cb     = str_filename_cb,
1080                 .prio   = -1, /* must come after "directory" */
1081                 .help   = "File(s) to use for the workload",
1082                 .category = FIO_OPT_C_FILE,
1083                 .group  = FIO_OPT_G_FILENAME,
1084         },
1085         {
1086                 .name   = "directory",
1087                 .lname  = "Directory",
1088                 .type   = FIO_OPT_STR_STORE,
1089                 .off1   = td_var_offset(directory),
1090                 .cb     = str_directory_cb,
1091                 .help   = "Directory to store files in",
1092                 .category = FIO_OPT_C_FILE,
1093                 .group  = FIO_OPT_G_FILENAME,
1094         },
1095         {
1096                 .name   = "filename_format",
1097                 .type   = FIO_OPT_STR_STORE,
1098                 .off1   = td_var_offset(filename_format),
1099                 .prio   = -1, /* must come after "directory" */
1100                 .help   = "Override default $jobname.$jobnum.$filenum naming",
1101                 .def    = "$jobname.$jobnum.$filenum",
1102                 .category = FIO_OPT_C_FILE,
1103                 .group  = FIO_OPT_G_FILENAME,
1104         },
1105         {
1106                 .name   = "lockfile",
1107                 .lname  = "Lockfile",
1108                 .type   = FIO_OPT_STR,
1109                 .off1   = td_var_offset(file_lock_mode),
1110                 .help   = "Lock file when doing IO to it",
1111                 .prio   = 1,
1112                 .parent = "filename",
1113                 .hide   = 0,
1114                 .def    = "none",
1115                 .category = FIO_OPT_C_FILE,
1116                 .group  = FIO_OPT_G_FILENAME,
1117                 .posval = {
1118                           { .ival = "none",
1119                             .oval = FILE_LOCK_NONE,
1120                             .help = "No file locking",
1121                           },
1122                           { .ival = "exclusive",
1123                             .oval = FILE_LOCK_EXCLUSIVE,
1124                             .help = "Exclusive file lock",
1125                           },
1126                           {
1127                             .ival = "readwrite",
1128                             .oval = FILE_LOCK_READWRITE,
1129                             .help = "Read vs write lock",
1130                           },
1131                 },
1132         },
1133         {
1134                 .name   = "opendir",
1135                 .lname  = "Open directory",
1136                 .type   = FIO_OPT_STR_STORE,
1137                 .off1   = td_var_offset(opendir),
1138                 .cb     = str_opendir_cb,
1139                 .help   = "Recursively add files from this directory and down",
1140                 .category = FIO_OPT_C_FILE,
1141                 .group  = FIO_OPT_G_FILENAME,
1142         },
1143         {
1144                 .name   = "rw",
1145                 .lname  = "Read/write",
1146                 .alias  = "readwrite",
1147                 .type   = FIO_OPT_STR,
1148                 .cb     = str_rw_cb,
1149                 .off1   = td_var_offset(td_ddir),
1150                 .help   = "IO direction",
1151                 .def    = "read",
1152                 .verify = rw_verify,
1153                 .category = FIO_OPT_C_IO,
1154                 .group  = FIO_OPT_G_IO_BASIC,
1155                 .posval = {
1156                           { .ival = "read",
1157                             .oval = TD_DDIR_READ,
1158                             .help = "Sequential read",
1159                           },
1160                           { .ival = "write",
1161                             .oval = TD_DDIR_WRITE,
1162                             .help = "Sequential write",
1163                           },
1164                           { .ival = "trim",
1165                             .oval = TD_DDIR_TRIM,
1166                             .help = "Sequential trim",
1167                           },
1168                           { .ival = "randread",
1169                             .oval = TD_DDIR_RANDREAD,
1170                             .help = "Random read",
1171                           },
1172                           { .ival = "randwrite",
1173                             .oval = TD_DDIR_RANDWRITE,
1174                             .help = "Random write",
1175                           },
1176                           { .ival = "randtrim",
1177                             .oval = TD_DDIR_RANDTRIM,
1178                             .help = "Random trim",
1179                           },
1180                           { .ival = "rw",
1181                             .oval = TD_DDIR_RW,
1182                             .help = "Sequential read and write mix",
1183                           },
1184                           { .ival = "readwrite",
1185                             .oval = TD_DDIR_RW,
1186                             .help = "Sequential read and write mix",
1187                           },
1188                           { .ival = "randrw",
1189                             .oval = TD_DDIR_RANDRW,
1190                             .help = "Random read and write mix"
1191                           },
1192                           { .ival = "trimwrite",
1193                             .oval = TD_DDIR_TRIMWRITE,
1194                             .help = "Trim and write mix, trims preceding writes"
1195                           },
1196                 },
1197         },
1198         {
1199                 .name   = "rw_sequencer",
1200                 .lname  = "RW Sequencer",
1201                 .type   = FIO_OPT_STR,
1202                 .off1   = td_var_offset(rw_seq),
1203                 .help   = "IO offset generator modifier",
1204                 .def    = "sequential",
1205                 .category = FIO_OPT_C_IO,
1206                 .group  = FIO_OPT_G_IO_BASIC,
1207                 .posval = {
1208                           { .ival = "sequential",
1209                             .oval = RW_SEQ_SEQ,
1210                             .help = "Generate sequential offsets",
1211                           },
1212                           { .ival = "identical",
1213                             .oval = RW_SEQ_IDENT,
1214                             .help = "Generate identical offsets",
1215                           },
1216                 },
1217         },
1218
1219         {
1220                 .name   = "ioengine",
1221                 .lname  = "IO Engine",
1222                 .type   = FIO_OPT_STR_STORE,
1223                 .off1   = td_var_offset(ioengine),
1224                 .help   = "IO engine to use",
1225                 .def    = FIO_PREFERRED_ENGINE,
1226                 .category = FIO_OPT_C_IO,
1227                 .group  = FIO_OPT_G_IO_BASIC,
1228                 .posval = {
1229                           { .ival = "sync",
1230                             .help = "Use read/write",
1231                           },
1232                           { .ival = "psync",
1233                             .help = "Use pread/pwrite",
1234                           },
1235                           { .ival = "vsync",
1236                             .help = "Use readv/writev",
1237                           },
1238 #ifdef CONFIG_PWRITEV
1239                           { .ival = "pvsync",
1240                             .help = "Use preadv/pwritev",
1241                           },
1242 #endif
1243 #ifdef CONFIG_PWRITEV
1244                           { .ival = "pvsync2",
1245                             .help = "Use preadv2/pwritev2",
1246                           },
1247 #endif
1248 #ifdef CONFIG_LIBAIO
1249                           { .ival = "libaio",
1250                             .help = "Linux native asynchronous IO",
1251                           },
1252 #endif
1253 #ifdef CONFIG_POSIXAIO
1254                           { .ival = "posixaio",
1255                             .help = "POSIX asynchronous IO",
1256                           },
1257 #endif
1258 #ifdef CONFIG_SOLARISAIO
1259                           { .ival = "solarisaio",
1260                             .help = "Solaris native asynchronous IO",
1261                           },
1262 #endif
1263 #ifdef CONFIG_WINDOWSAIO
1264                           { .ival = "windowsaio",
1265                             .help = "Windows native asynchronous IO"
1266                           },
1267 #endif
1268 #ifdef CONFIG_RBD
1269                           { .ival = "rbd",
1270                             .help = "Rados Block Device asynchronous IO"
1271                           },
1272 #endif
1273                           { .ival = "mmap",
1274                             .help = "Memory mapped IO"
1275                           },
1276 #ifdef CONFIG_LINUX_SPLICE
1277                           { .ival = "splice",
1278                             .help = "splice/vmsplice based IO",
1279                           },
1280                           { .ival = "netsplice",
1281                             .help = "splice/vmsplice to/from the network",
1282                           },
1283 #endif
1284 #ifdef FIO_HAVE_SGIO
1285                           { .ival = "sg",
1286                             .help = "SCSI generic v3 IO",
1287                           },
1288 #endif
1289                           { .ival = "null",
1290                             .help = "Testing engine (no data transfer)",
1291                           },
1292                           { .ival = "net",
1293                             .help = "Network IO",
1294                           },
1295                           { .ival = "cpuio",
1296                             .help = "CPU cycle burner engine",
1297                           },
1298 #ifdef CONFIG_GUASI
1299                           { .ival = "guasi",
1300                             .help = "GUASI IO engine",
1301                           },
1302 #endif
1303 #ifdef FIO_HAVE_BINJECT
1304                           { .ival = "binject",
1305                             .help = "binject direct inject block engine",
1306                           },
1307 #endif
1308 #ifdef CONFIG_RDMA
1309                           { .ival = "rdma",
1310                             .help = "RDMA IO engine",
1311                           },
1312 #endif
1313 #ifdef CONFIG_FUSION_AW
1314                           { .ival = "fusion-aw-sync",
1315                             .help = "Fusion-io atomic write engine",
1316                           },
1317 #endif
1318 #ifdef CONFIG_LINUX_EXT4_MOVE_EXTENT
1319                           { .ival = "e4defrag",
1320                             .help = "ext4 defrag engine",
1321                           },
1322 #endif
1323 #ifdef CONFIG_LINUX_FALLOCATE
1324                           { .ival = "falloc",
1325                             .help = "fallocate() file based engine",
1326                           },
1327 #endif
1328 #ifdef CONFIG_GFAPI
1329                           { .ival = "gfapi",
1330                             .help = "Glusterfs libgfapi(sync) based engine"
1331                           },
1332                           { .ival = "gfapi_async",
1333                             .help = "Glusterfs libgfapi(async) based engine"
1334                           },
1335 #endif
1336 #ifdef CONFIG_LIBHDFS
1337                           { .ival = "libhdfs",
1338                             .help = "Hadoop Distributed Filesystem (HDFS) engine"
1339                           },
1340 #endif
1341                           { .ival = "external",
1342                             .help = "Load external engine (append name)",
1343                           },
1344                 },
1345         },
1346         {
1347                 .name   = "iodepth",
1348                 .lname  = "IO Depth",
1349                 .type   = FIO_OPT_INT,
1350                 .off1   = td_var_offset(iodepth),
1351                 .help   = "Number of IO buffers to keep in flight",
1352                 .minval = 1,
1353                 .interval = 1,
1354                 .def    = "1",
1355                 .category = FIO_OPT_C_IO,
1356                 .group  = FIO_OPT_G_IO_BASIC,
1357         },
1358         {
1359                 .name   = "iodepth_batch",
1360                 .lname  = "IO Depth batch",
1361                 .alias  = "iodepth_batch_submit",
1362                 .type   = FIO_OPT_INT,
1363                 .off1   = td_var_offset(iodepth_batch),
1364                 .help   = "Number of IO buffers to submit in one go",
1365                 .parent = "iodepth",
1366                 .hide   = 1,
1367                 .minval = 1,
1368                 .interval = 1,
1369                 .def    = "1",
1370                 .category = FIO_OPT_C_IO,
1371                 .group  = FIO_OPT_G_IO_BASIC,
1372         },
1373         {
1374                 .name   = "iodepth_batch_complete_min",
1375                 .lname  = "Min IO depth batch complete",
1376                 .alias  = "iodepth_batch_complete",
1377                 .type   = FIO_OPT_INT,
1378                 .off1   = td_var_offset(iodepth_batch_complete_min),
1379                 .help   = "Min number of IO buffers to retrieve in one go",
1380                 .parent = "iodepth",
1381                 .hide   = 1,
1382                 .minval = 0,
1383                 .interval = 1,
1384                 .def    = "1",
1385                 .category = FIO_OPT_C_IO,
1386                 .group  = FIO_OPT_G_IO_BASIC,
1387         },
1388         {
1389                 .name   = "iodepth_batch_complete_max",
1390                 .lname  = "Max IO depth batch complete",
1391                 .type   = FIO_OPT_INT,
1392                 .off1   = td_var_offset(iodepth_batch_complete_max),
1393                 .help   = "Max number of IO buffers to retrieve in one go",
1394                 .parent = "iodepth",
1395                 .hide   = 1,
1396                 .minval = 0,
1397                 .interval = 1,
1398                 .category = FIO_OPT_C_IO,
1399                 .group  = FIO_OPT_G_IO_BASIC,
1400         },
1401         {
1402                 .name   = "iodepth_low",
1403                 .lname  = "IO Depth batch low",
1404                 .type   = FIO_OPT_INT,
1405                 .off1   = td_var_offset(iodepth_low),
1406                 .help   = "Low water mark for queuing depth",
1407                 .parent = "iodepth",
1408                 .hide   = 1,
1409                 .interval = 1,
1410                 .category = FIO_OPT_C_IO,
1411                 .group  = FIO_OPT_G_IO_BASIC,
1412         },
1413         {
1414                 .name   = "io_submit_mode",
1415                 .lname  = "IO submit mode",
1416                 .type   = FIO_OPT_STR,
1417                 .off1   = td_var_offset(io_submit_mode),
1418                 .help   = "How IO submissions and completions are done",
1419                 .def    = "inline",
1420                 .category = FIO_OPT_C_IO,
1421                 .group  = FIO_OPT_G_IO_BASIC,
1422                 .posval = {
1423                           { .ival = "inline",
1424                             .oval = IO_MODE_INLINE,
1425                             .help = "Submit and complete IO inline",
1426                           },
1427                           { .ival = "offload",
1428                             .oval = IO_MODE_OFFLOAD,
1429                             .help = "Offload submit and complete to threads",
1430                           },
1431                 },
1432         },
1433         {
1434                 .name   = "size",
1435                 .lname  = "Size",
1436                 .type   = FIO_OPT_STR_VAL,
1437                 .cb     = str_size_cb,
1438                 .off1   = td_var_offset(size),
1439                 .help   = "Total size of device or files",
1440                 .interval = 1024 * 1024,
1441                 .category = FIO_OPT_C_IO,
1442                 .group  = FIO_OPT_G_INVALID,
1443         },
1444         {
1445                 .name   = "io_size",
1446                 .alias  = "io_limit",
1447                 .lname  = "IO Size",
1448                 .type   = FIO_OPT_STR_VAL,
1449                 .off1   = td_var_offset(io_limit),
1450                 .interval = 1024 * 1024,
1451                 .category = FIO_OPT_C_IO,
1452                 .group  = FIO_OPT_G_INVALID,
1453         },
1454         {
1455                 .name   = "fill_device",
1456                 .lname  = "Fill device",
1457                 .alias  = "fill_fs",
1458                 .type   = FIO_OPT_BOOL,
1459                 .off1   = td_var_offset(fill_device),
1460                 .help   = "Write until an ENOSPC error occurs",
1461                 .def    = "0",
1462                 .category = FIO_OPT_C_FILE,
1463                 .group  = FIO_OPT_G_INVALID,
1464         },
1465         {
1466                 .name   = "filesize",
1467                 .lname  = "File size",
1468                 .type   = FIO_OPT_STR_VAL,
1469                 .off1   = td_var_offset(file_size_low),
1470                 .off2   = td_var_offset(file_size_high),
1471                 .minval = 1,
1472                 .help   = "Size of individual files",
1473                 .interval = 1024 * 1024,
1474                 .category = FIO_OPT_C_FILE,
1475                 .group  = FIO_OPT_G_INVALID,
1476         },
1477         {
1478                 .name   = "file_append",
1479                 .lname  = "File append",
1480                 .type   = FIO_OPT_BOOL,
1481                 .off1   = td_var_offset(file_append),
1482                 .help   = "IO will start at the end of the file(s)",
1483                 .def    = "0",
1484                 .category = FIO_OPT_C_FILE,
1485                 .group  = FIO_OPT_G_INVALID,
1486         },
1487         {
1488                 .name   = "offset",
1489                 .lname  = "IO offset",
1490                 .alias  = "fileoffset",
1491                 .type   = FIO_OPT_STR_VAL,
1492                 .off1   = td_var_offset(start_offset),
1493                 .help   = "Start IO from this offset",
1494                 .def    = "0",
1495                 .interval = 1024 * 1024,
1496                 .category = FIO_OPT_C_IO,
1497                 .group  = FIO_OPT_G_INVALID,
1498         },
1499         {
1500                 .name   = "offset_increment",
1501                 .lname  = "IO offset increment",
1502                 .type   = FIO_OPT_STR_VAL,
1503                 .off1   = td_var_offset(offset_increment),
1504                 .help   = "What is the increment from one offset to the next",
1505                 .parent = "offset",
1506                 .hide   = 1,
1507                 .def    = "0",
1508                 .interval = 1024 * 1024,
1509                 .category = FIO_OPT_C_IO,
1510                 .group  = FIO_OPT_G_INVALID,
1511         },
1512         {
1513                 .name   = "number_ios",
1514                 .lname  = "Number of IOs to perform",
1515                 .type   = FIO_OPT_STR_VAL,
1516                 .off1   = td_var_offset(number_ios),
1517                 .help   = "Force job completion after this number of IOs",
1518                 .def    = "0",
1519                 .category = FIO_OPT_C_IO,
1520                 .group  = FIO_OPT_G_INVALID,
1521         },
1522         {
1523                 .name   = "bs",
1524                 .lname  = "Block size",
1525                 .alias  = "blocksize",
1526                 .type   = FIO_OPT_INT,
1527                 .off1   = td_var_offset(bs[DDIR_READ]),
1528                 .off2   = td_var_offset(bs[DDIR_WRITE]),
1529                 .off3   = td_var_offset(bs[DDIR_TRIM]),
1530                 .minval = 1,
1531                 .help   = "Block size unit",
1532                 .def    = "4k",
1533                 .parent = "rw",
1534                 .hide   = 1,
1535                 .interval = 512,
1536                 .category = FIO_OPT_C_IO,
1537                 .group  = FIO_OPT_G_INVALID,
1538         },
1539         {
1540                 .name   = "ba",
1541                 .lname  = "Block size align",
1542                 .alias  = "blockalign",
1543                 .type   = FIO_OPT_INT,
1544                 .off1   = td_var_offset(ba[DDIR_READ]),
1545                 .off2   = td_var_offset(ba[DDIR_WRITE]),
1546                 .off3   = td_var_offset(ba[DDIR_TRIM]),
1547                 .minval = 1,
1548                 .help   = "IO block offset alignment",
1549                 .parent = "rw",
1550                 .hide   = 1,
1551                 .interval = 512,
1552                 .category = FIO_OPT_C_IO,
1553                 .group  = FIO_OPT_G_INVALID,
1554         },
1555         {
1556                 .name   = "bsrange",
1557                 .lname  = "Block size range",
1558                 .alias  = "blocksize_range",
1559                 .type   = FIO_OPT_RANGE,
1560                 .off1   = td_var_offset(min_bs[DDIR_READ]),
1561                 .off2   = td_var_offset(max_bs[DDIR_READ]),
1562                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
1563                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
1564                 .off5   = td_var_offset(min_bs[DDIR_TRIM]),
1565                 .off6   = td_var_offset(max_bs[DDIR_TRIM]),
1566                 .minval = 1,
1567                 .help   = "Set block size range (in more detail than bs)",
1568                 .parent = "rw",
1569                 .hide   = 1,
1570                 .interval = 4096,
1571                 .category = FIO_OPT_C_IO,
1572                 .group  = FIO_OPT_G_INVALID,
1573         },
1574         {
1575                 .name   = "bssplit",
1576                 .lname  = "Block size split",
1577                 .type   = FIO_OPT_STR,
1578                 .cb     = str_bssplit_cb,
1579                 .off1   = td_var_offset(bssplit),
1580                 .help   = "Set a specific mix of block sizes",
1581                 .parent = "rw",
1582                 .hide   = 1,
1583                 .category = FIO_OPT_C_IO,
1584                 .group  = FIO_OPT_G_INVALID,
1585         },
1586         {
1587                 .name   = "bs_unaligned",
1588                 .lname  = "Block size unaligned",
1589                 .alias  = "blocksize_unaligned",
1590                 .type   = FIO_OPT_STR_SET,
1591                 .off1   = td_var_offset(bs_unaligned),
1592                 .help   = "Don't sector align IO buffer sizes",
1593                 .parent = "rw",
1594                 .hide   = 1,
1595                 .category = FIO_OPT_C_IO,
1596                 .group  = FIO_OPT_G_INVALID,
1597         },
1598         {
1599                 .name   = "bs_is_seq_rand",
1600                 .lname  = "Block size division is seq/random (not read/write)",
1601                 .type   = FIO_OPT_BOOL,
1602                 .off1   = td_var_offset(bs_is_seq_rand),
1603                 .help   = "Consider any blocksize setting to be sequential,random",
1604                 .def    = "0",
1605                 .parent = "blocksize",
1606                 .category = FIO_OPT_C_IO,
1607                 .group  = FIO_OPT_G_INVALID,
1608         },
1609         {
1610                 .name   = "randrepeat",
1611                 .lname  = "Random repeatable",
1612                 .type   = FIO_OPT_BOOL,
1613                 .off1   = td_var_offset(rand_repeatable),
1614                 .help   = "Use repeatable random IO pattern",
1615                 .def    = "1",
1616                 .parent = "rw",
1617                 .hide   = 1,
1618                 .category = FIO_OPT_C_IO,
1619                 .group  = FIO_OPT_G_RANDOM,
1620         },
1621         {
1622                 .name   = "randseed",
1623                 .lname  = "The random generator seed",
1624                 .type   = FIO_OPT_STR_VAL,
1625                 .off1   = td_var_offset(rand_seed),
1626                 .help   = "Set the random generator seed value",
1627                 .def    = "0x89",
1628                 .parent = "rw",
1629                 .category = FIO_OPT_C_IO,
1630                 .group  = FIO_OPT_G_RANDOM,
1631         },
1632         {
1633                 .name   = "use_os_rand",
1634                 .lname  = "Use OS random",
1635                 .type   = FIO_OPT_DEPRECATED,
1636                 .off1   = td_var_offset(dep_use_os_rand),
1637                 .category = FIO_OPT_C_IO,
1638                 .group  = FIO_OPT_G_RANDOM,
1639         },
1640         {
1641                 .name   = "norandommap",
1642                 .lname  = "No randommap",
1643                 .type   = FIO_OPT_STR_SET,
1644                 .off1   = td_var_offset(norandommap),
1645                 .help   = "Accept potential duplicate random blocks",
1646                 .parent = "rw",
1647                 .hide   = 1,
1648                 .hide_on_set = 1,
1649                 .category = FIO_OPT_C_IO,
1650                 .group  = FIO_OPT_G_RANDOM,
1651         },
1652         {
1653                 .name   = "softrandommap",
1654                 .lname  = "Soft randommap",
1655                 .type   = FIO_OPT_BOOL,
1656                 .off1   = td_var_offset(softrandommap),
1657                 .help   = "Set norandommap if randommap allocation fails",
1658                 .parent = "norandommap",
1659                 .hide   = 1,
1660                 .def    = "0",
1661                 .category = FIO_OPT_C_IO,
1662                 .group  = FIO_OPT_G_RANDOM,
1663         },
1664         {
1665                 .name   = "random_generator",
1666                 .type   = FIO_OPT_STR,
1667                 .off1   = td_var_offset(random_generator),
1668                 .help   = "Type of random number generator to use",
1669                 .def    = "tausworthe",
1670                 .posval = {
1671                           { .ival = "tausworthe",
1672                             .oval = FIO_RAND_GEN_TAUSWORTHE,
1673                             .help = "Strong Tausworthe generator",
1674                           },
1675                           { .ival = "lfsr",
1676                             .oval = FIO_RAND_GEN_LFSR,
1677                             .help = "Variable length LFSR",
1678                           },
1679                           {
1680                             .ival = "tausworthe64",
1681                             .oval = FIO_RAND_GEN_TAUSWORTHE64,
1682                             .help = "64-bit Tausworthe variant",
1683                           },
1684                 },
1685                 .category = FIO_OPT_C_IO,
1686                 .group  = FIO_OPT_G_RANDOM,
1687         },
1688         {
1689                 .name   = "random_distribution",
1690                 .type   = FIO_OPT_STR,
1691                 .off1   = td_var_offset(random_distribution),
1692                 .cb     = str_random_distribution_cb,
1693                 .help   = "Random offset distribution generator",
1694                 .def    = "random",
1695                 .posval = {
1696                           { .ival = "random",
1697                             .oval = FIO_RAND_DIST_RANDOM,
1698                             .help = "Completely random",
1699                           },
1700                           { .ival = "zipf",
1701                             .oval = FIO_RAND_DIST_ZIPF,
1702                             .help = "Zipf distribution",
1703                           },
1704                           { .ival = "pareto",
1705                             .oval = FIO_RAND_DIST_PARETO,
1706                             .help = "Pareto distribution",
1707                           },
1708                           { .ival = "normal",
1709                             .oval = FIO_RAND_DIST_GAUSS,
1710                             .help = "Normal (gaussian) distribution",
1711                           },
1712                 },
1713                 .category = FIO_OPT_C_IO,
1714                 .group  = FIO_OPT_G_RANDOM,
1715         },
1716         {
1717                 .name   = "percentage_random",
1718                 .lname  = "Percentage Random",
1719                 .type   = FIO_OPT_INT,
1720                 .off1   = td_var_offset(perc_rand[DDIR_READ]),
1721                 .off2   = td_var_offset(perc_rand[DDIR_WRITE]),
1722                 .off3   = td_var_offset(perc_rand[DDIR_TRIM]),
1723                 .maxval = 100,
1724                 .help   = "Percentage of seq/random mix that should be random",
1725                 .def    = "100,100,100",
1726                 .interval = 5,
1727                 .inverse = "percentage_sequential",
1728                 .category = FIO_OPT_C_IO,
1729                 .group  = FIO_OPT_G_RANDOM,
1730         },
1731         {
1732                 .name   = "percentage_sequential",
1733                 .lname  = "Percentage Sequential",
1734                 .type   = FIO_OPT_DEPRECATED,
1735                 .category = FIO_OPT_C_IO,
1736                 .group  = FIO_OPT_G_RANDOM,
1737         },
1738         {
1739                 .name   = "allrandrepeat",
1740                 .type   = FIO_OPT_BOOL,
1741                 .off1   = td_var_offset(allrand_repeatable),
1742                 .help   = "Use repeatable random numbers for everything",
1743                 .def    = "0",
1744                 .category = FIO_OPT_C_IO,
1745                 .group  = FIO_OPT_G_RANDOM,
1746         },
1747         {
1748                 .name   = "nrfiles",
1749                 .lname  = "Number of files",
1750                 .alias  = "nr_files",
1751                 .type   = FIO_OPT_INT,
1752                 .off1   = td_var_offset(nr_files),
1753                 .help   = "Split job workload between this number of files",
1754                 .def    = "1",
1755                 .interval = 1,
1756                 .category = FIO_OPT_C_FILE,
1757                 .group  = FIO_OPT_G_INVALID,
1758         },
1759         {
1760                 .name   = "openfiles",
1761                 .lname  = "Number of open files",
1762                 .type   = FIO_OPT_INT,
1763                 .off1   = td_var_offset(open_files),
1764                 .help   = "Number of files to keep open at the same time",
1765                 .category = FIO_OPT_C_FILE,
1766                 .group  = FIO_OPT_G_INVALID,
1767         },
1768         {
1769                 .name   = "file_service_type",
1770                 .lname  = "File service type",
1771                 .type   = FIO_OPT_STR,
1772                 .cb     = str_fst_cb,
1773                 .off1   = td_var_offset(file_service_type),
1774                 .help   = "How to select which file to service next",
1775                 .def    = "roundrobin",
1776                 .category = FIO_OPT_C_FILE,
1777                 .group  = FIO_OPT_G_INVALID,
1778                 .posval = {
1779                           { .ival = "random",
1780                             .oval = FIO_FSERVICE_RANDOM,
1781                             .help = "Choose a file at random",
1782                           },
1783                           { .ival = "roundrobin",
1784                             .oval = FIO_FSERVICE_RR,
1785                             .help = "Round robin select files",
1786                           },
1787                           { .ival = "sequential",
1788                             .oval = FIO_FSERVICE_SEQ,
1789                             .help = "Finish one file before moving to the next",
1790                           },
1791                 },
1792                 .parent = "nrfiles",
1793                 .hide   = 1,
1794         },
1795 #ifdef CONFIG_POSIX_FALLOCATE
1796         {
1797                 .name   = "fallocate",
1798                 .lname  = "Fallocate",
1799                 .type   = FIO_OPT_STR,
1800                 .off1   = td_var_offset(fallocate_mode),
1801                 .help   = "Whether pre-allocation is performed when laying out files",
1802                 .def    = "posix",
1803                 .category = FIO_OPT_C_FILE,
1804                 .group  = FIO_OPT_G_INVALID,
1805                 .posval = {
1806                           { .ival = "none",
1807                             .oval = FIO_FALLOCATE_NONE,
1808                             .help = "Do not pre-allocate space",
1809                           },
1810                           { .ival = "posix",
1811                             .oval = FIO_FALLOCATE_POSIX,
1812                             .help = "Use posix_fallocate()",
1813                           },
1814 #ifdef CONFIG_LINUX_FALLOCATE
1815                           { .ival = "keep",
1816                             .oval = FIO_FALLOCATE_KEEP_SIZE,
1817                             .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1818                           },
1819 #endif
1820                           /* Compatibility with former boolean values */
1821                           { .ival = "0",
1822                             .oval = FIO_FALLOCATE_NONE,
1823                             .help = "Alias for 'none'",
1824                           },
1825                           { .ival = "1",
1826                             .oval = FIO_FALLOCATE_POSIX,
1827                             .help = "Alias for 'posix'",
1828                           },
1829                 },
1830         },
1831 #endif  /* CONFIG_POSIX_FALLOCATE */
1832         {
1833                 .name   = "fadvise_hint",
1834                 .lname  = "Fadvise hint",
1835                 .type   = FIO_OPT_BOOL,
1836                 .off1   = td_var_offset(fadvise_hint),
1837                 .help   = "Use fadvise() to advise the kernel on IO pattern",
1838                 .def    = "1",
1839                 .category = FIO_OPT_C_FILE,
1840                 .group  = FIO_OPT_G_INVALID,
1841         },
1842 #ifdef FIO_HAVE_STREAMID
1843         {
1844                 .name   = "fadvise_stream",
1845                 .lname  = "Fadvise stream",
1846                 .type   = FIO_OPT_INT,
1847                 .off1   = td_var_offset(fadvise_stream),
1848                 .help   = "Use fadvise() to set stream ID",
1849                 .category = FIO_OPT_C_FILE,
1850                 .group  = FIO_OPT_G_INVALID,
1851         },
1852 #endif
1853         {
1854                 .name   = "fsync",
1855                 .lname  = "Fsync",
1856                 .type   = FIO_OPT_INT,
1857                 .off1   = td_var_offset(fsync_blocks),
1858                 .help   = "Issue fsync for writes every given number of blocks",
1859                 .def    = "0",
1860                 .interval = 1,
1861                 .category = FIO_OPT_C_FILE,
1862                 .group  = FIO_OPT_G_INVALID,
1863         },
1864         {
1865                 .name   = "fdatasync",
1866                 .lname  = "Fdatasync",
1867                 .type   = FIO_OPT_INT,
1868                 .off1   = td_var_offset(fdatasync_blocks),
1869                 .help   = "Issue fdatasync for writes every given number of blocks",
1870                 .def    = "0",
1871                 .interval = 1,
1872                 .category = FIO_OPT_C_FILE,
1873                 .group  = FIO_OPT_G_INVALID,
1874         },
1875         {
1876                 .name   = "write_barrier",
1877                 .lname  = "Write barrier",
1878                 .type   = FIO_OPT_INT,
1879                 .off1   = td_var_offset(barrier_blocks),
1880                 .help   = "Make every Nth write a barrier write",
1881                 .def    = "0",
1882                 .interval = 1,
1883                 .category = FIO_OPT_C_IO,
1884                 .group  = FIO_OPT_G_INVALID,
1885         },
1886 #ifdef CONFIG_SYNC_FILE_RANGE
1887         {
1888                 .name   = "sync_file_range",
1889                 .lname  = "Sync file range",
1890                 .posval = {
1891                           { .ival = "wait_before",
1892                             .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1893                             .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1894                             .orval  = 1,
1895                           },
1896                           { .ival = "write",
1897                             .oval = SYNC_FILE_RANGE_WRITE,
1898                             .help = "SYNC_FILE_RANGE_WRITE",
1899                             .orval  = 1,
1900                           },
1901                           {
1902                             .ival = "wait_after",
1903                             .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1904                             .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1905                             .orval  = 1,
1906                           },
1907                 },
1908                 .type   = FIO_OPT_STR_MULTI,
1909                 .cb     = str_sfr_cb,
1910                 .off1   = td_var_offset(sync_file_range),
1911                 .help   = "Use sync_file_range()",
1912                 .category = FIO_OPT_C_FILE,
1913                 .group  = FIO_OPT_G_INVALID,
1914         },
1915 #endif
1916         {
1917                 .name   = "direct",
1918                 .lname  = "Direct I/O",
1919                 .type   = FIO_OPT_BOOL,
1920                 .off1   = td_var_offset(odirect),
1921                 .help   = "Use O_DIRECT IO (negates buffered)",
1922                 .def    = "0",
1923                 .inverse = "buffered",
1924                 .category = FIO_OPT_C_IO,
1925                 .group  = FIO_OPT_G_IO_TYPE,
1926         },
1927         {
1928                 .name   = "atomic",
1929                 .lname  = "Atomic I/O",
1930                 .type   = FIO_OPT_BOOL,
1931                 .off1   = td_var_offset(oatomic),
1932                 .help   = "Use Atomic IO with O_DIRECT (implies O_DIRECT)",
1933                 .def    = "0",
1934                 .category = FIO_OPT_C_IO,
1935                 .group  = FIO_OPT_G_IO_TYPE,
1936         },
1937         {
1938                 .name   = "buffered",
1939                 .lname  = "Buffered I/O",
1940                 .type   = FIO_OPT_BOOL,
1941                 .off1   = td_var_offset(odirect),
1942                 .neg    = 1,
1943                 .help   = "Use buffered IO (negates direct)",
1944                 .def    = "1",
1945                 .inverse = "direct",
1946                 .category = FIO_OPT_C_IO,
1947                 .group  = FIO_OPT_G_IO_TYPE,
1948         },
1949         {
1950                 .name   = "overwrite",
1951                 .lname  = "Overwrite",
1952                 .type   = FIO_OPT_BOOL,
1953                 .off1   = td_var_offset(overwrite),
1954                 .help   = "When writing, set whether to overwrite current data",
1955                 .def    = "0",
1956                 .category = FIO_OPT_C_FILE,
1957                 .group  = FIO_OPT_G_INVALID,
1958         },
1959         {
1960                 .name   = "loops",
1961                 .lname  = "Loops",
1962                 .type   = FIO_OPT_INT,
1963                 .off1   = td_var_offset(loops),
1964                 .help   = "Number of times to run the job",
1965                 .def    = "1",
1966                 .interval = 1,
1967                 .category = FIO_OPT_C_GENERAL,
1968                 .group  = FIO_OPT_G_RUNTIME,
1969         },
1970         {
1971                 .name   = "numjobs",
1972                 .lname  = "Number of jobs",
1973                 .type   = FIO_OPT_INT,
1974                 .off1   = td_var_offset(numjobs),
1975                 .help   = "Duplicate this job this many times",
1976                 .def    = "1",
1977                 .interval = 1,
1978                 .category = FIO_OPT_C_GENERAL,
1979                 .group  = FIO_OPT_G_RUNTIME,
1980         },
1981         {
1982                 .name   = "startdelay",
1983                 .lname  = "Start delay",
1984                 .type   = FIO_OPT_STR_VAL_TIME,
1985                 .off1   = td_var_offset(start_delay),
1986                 .off2   = td_var_offset(start_delay_high),
1987                 .help   = "Only start job when this period has passed",
1988                 .def    = "0",
1989                 .is_seconds = 1,
1990                 .is_time = 1,
1991                 .category = FIO_OPT_C_GENERAL,
1992                 .group  = FIO_OPT_G_RUNTIME,
1993         },
1994         {
1995                 .name   = "runtime",
1996                 .lname  = "Runtime",
1997                 .alias  = "timeout",
1998                 .type   = FIO_OPT_STR_VAL_TIME,
1999                 .off1   = td_var_offset(timeout),
2000                 .help   = "Stop workload when this amount of time has passed",
2001                 .def    = "0",
2002                 .is_seconds = 1,
2003                 .is_time = 1,
2004                 .category = FIO_OPT_C_GENERAL,
2005                 .group  = FIO_OPT_G_RUNTIME,
2006         },
2007         {
2008                 .name   = "time_based",
2009                 .lname  = "Time based",
2010                 .type   = FIO_OPT_STR_SET,
2011                 .off1   = td_var_offset(time_based),
2012                 .help   = "Keep running until runtime/timeout is met",
2013                 .category = FIO_OPT_C_GENERAL,
2014                 .group  = FIO_OPT_G_RUNTIME,
2015         },
2016         {
2017                 .name   = "verify_only",
2018                 .lname  = "Verify only",
2019                 .type   = FIO_OPT_STR_SET,
2020                 .off1   = td_var_offset(verify_only),
2021                 .help   = "Verifies previously written data is still valid",
2022                 .category = FIO_OPT_C_GENERAL,
2023                 .group  = FIO_OPT_G_RUNTIME,
2024         },
2025         {
2026                 .name   = "ramp_time",
2027                 .lname  = "Ramp time",
2028                 .type   = FIO_OPT_STR_VAL_TIME,
2029                 .off1   = td_var_offset(ramp_time),
2030                 .help   = "Ramp up time before measuring performance",
2031                 .is_seconds = 1,
2032                 .is_time = 1,
2033                 .category = FIO_OPT_C_GENERAL,
2034                 .group  = FIO_OPT_G_RUNTIME,
2035         },
2036         {
2037                 .name   = "clocksource",
2038                 .lname  = "Clock source",
2039                 .type   = FIO_OPT_STR,
2040                 .cb     = fio_clock_source_cb,
2041                 .off1   = td_var_offset(clocksource),
2042                 .help   = "What type of timing source to use",
2043                 .category = FIO_OPT_C_GENERAL,
2044                 .group  = FIO_OPT_G_CLOCK,
2045                 .posval = {
2046 #ifdef CONFIG_GETTIMEOFDAY
2047                           { .ival = "gettimeofday",
2048                             .oval = CS_GTOD,
2049                             .help = "Use gettimeofday(2) for timing",
2050                           },
2051 #endif
2052 #ifdef CONFIG_CLOCK_GETTIME
2053                           { .ival = "clock_gettime",
2054                             .oval = CS_CGETTIME,
2055                             .help = "Use clock_gettime(2) for timing",
2056                           },
2057 #endif
2058 #ifdef ARCH_HAVE_CPU_CLOCK
2059                           { .ival = "cpu",
2060                             .oval = CS_CPUCLOCK,
2061                             .help = "Use CPU private clock",
2062                           },
2063 #endif
2064                 },
2065         },
2066         {
2067                 .name   = "mem",
2068                 .alias  = "iomem",
2069                 .lname  = "I/O Memory",
2070                 .type   = FIO_OPT_STR,
2071                 .cb     = str_mem_cb,
2072                 .off1   = td_var_offset(mem_type),
2073                 .help   = "Backing type for IO buffers",
2074                 .def    = "malloc",
2075                 .category = FIO_OPT_C_IO,
2076                 .group  = FIO_OPT_G_INVALID,
2077                 .posval = {
2078                           { .ival = "malloc",
2079                             .oval = MEM_MALLOC,
2080                             .help = "Use malloc(3) for IO buffers",
2081                           },
2082 #ifndef CONFIG_NO_SHM
2083                           { .ival = "shm",
2084                             .oval = MEM_SHM,
2085                             .help = "Use shared memory segments for IO buffers",
2086                           },
2087 #ifdef FIO_HAVE_HUGETLB
2088                           { .ival = "shmhuge",
2089                             .oval = MEM_SHMHUGE,
2090                             .help = "Like shm, but use huge pages",
2091                           },
2092 #endif
2093 #endif
2094                           { .ival = "mmap",
2095                             .oval = MEM_MMAP,
2096                             .help = "Use mmap(2) (file or anon) for IO buffers",
2097                           },
2098                           { .ival = "mmapshared",
2099                             .oval = MEM_MMAPSHARED,
2100                             .help = "Like mmap, but use the shared flag",
2101                           },
2102 #ifdef FIO_HAVE_HUGETLB
2103                           { .ival = "mmaphuge",
2104                             .oval = MEM_MMAPHUGE,
2105                             .help = "Like mmap, but use huge pages",
2106                           },
2107 #endif
2108                   },
2109         },
2110         {
2111                 .name   = "iomem_align",
2112                 .alias  = "mem_align",
2113                 .lname  = "I/O memory alignment",
2114                 .type   = FIO_OPT_INT,
2115                 .off1   = td_var_offset(mem_align),
2116                 .minval = 0,
2117                 .help   = "IO memory buffer offset alignment",
2118                 .def    = "0",
2119                 .parent = "iomem",
2120                 .hide   = 1,
2121                 .category = FIO_OPT_C_IO,
2122                 .group  = FIO_OPT_G_INVALID,
2123         },
2124         {
2125                 .name   = "verify",
2126                 .lname  = "Verify",
2127                 .type   = FIO_OPT_STR,
2128                 .off1   = td_var_offset(verify),
2129                 .help   = "Verify data written",
2130                 .def    = "0",
2131                 .category = FIO_OPT_C_IO,
2132                 .group  = FIO_OPT_G_VERIFY,
2133                 .posval = {
2134                           { .ival = "0",
2135                             .oval = VERIFY_NONE,
2136                             .help = "Don't do IO verification",
2137                           },
2138                           { .ival = "md5",
2139                             .oval = VERIFY_MD5,
2140                             .help = "Use md5 checksums for verification",
2141                           },
2142                           { .ival = "crc64",
2143                             .oval = VERIFY_CRC64,
2144                             .help = "Use crc64 checksums for verification",
2145                           },
2146                           { .ival = "crc32",
2147                             .oval = VERIFY_CRC32,
2148                             .help = "Use crc32 checksums for verification",
2149                           },
2150                           { .ival = "crc32c-intel",
2151                             .oval = VERIFY_CRC32C,
2152                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
2153                           },
2154                           { .ival = "crc32c",
2155                             .oval = VERIFY_CRC32C,
2156                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
2157                           },
2158                           { .ival = "crc16",
2159                             .oval = VERIFY_CRC16,
2160                             .help = "Use crc16 checksums for verification",
2161                           },
2162                           { .ival = "crc7",
2163                             .oval = VERIFY_CRC7,
2164                             .help = "Use crc7 checksums for verification",
2165                           },
2166                           { .ival = "sha1",
2167                             .oval = VERIFY_SHA1,
2168                             .help = "Use sha1 checksums for verification",
2169                           },
2170                           { .ival = "sha256",
2171                             .oval = VERIFY_SHA256,
2172                             .help = "Use sha256 checksums for verification",
2173                           },
2174                           { .ival = "sha512",
2175                             .oval = VERIFY_SHA512,
2176                             .help = "Use sha512 checksums for verification",
2177                           },
2178                           { .ival = "xxhash",
2179                             .oval = VERIFY_XXHASH,
2180                             .help = "Use xxhash checksums for verification",
2181                           },
2182                           /* Meta information was included into verify_header,
2183                            * 'meta' verification is implied by default. */
2184                           { .ival = "meta",
2185                             .oval = VERIFY_HDR_ONLY,
2186                             .help = "Use io information for verification. "
2187                                     "Now is implied by default, thus option is obsolete, "
2188                                     "don't use it",
2189                           },
2190                           { .ival = "pattern",
2191                             .oval = VERIFY_PATTERN_NO_HDR,
2192                             .help = "Verify strict pattern",
2193                           },
2194                           {
2195                             .ival = "null",
2196                             .oval = VERIFY_NULL,
2197                             .help = "Pretend to verify",
2198                           },
2199                 },
2200         },
2201         {
2202                 .name   = "do_verify",
2203                 .lname  = "Perform verify step",
2204                 .type   = FIO_OPT_BOOL,
2205                 .off1   = td_var_offset(do_verify),
2206                 .help   = "Run verification stage after write",
2207                 .def    = "1",
2208                 .parent = "verify",
2209                 .hide   = 1,
2210                 .category = FIO_OPT_C_IO,
2211                 .group  = FIO_OPT_G_VERIFY,
2212         },
2213         {
2214                 .name   = "verifysort",
2215                 .lname  = "Verify sort",
2216                 .type   = FIO_OPT_BOOL,
2217                 .off1   = td_var_offset(verifysort),
2218                 .help   = "Sort written verify blocks for read back",
2219                 .def    = "1",
2220                 .parent = "verify",
2221                 .hide   = 1,
2222                 .category = FIO_OPT_C_IO,
2223                 .group  = FIO_OPT_G_VERIFY,
2224         },
2225         {
2226                 .name   = "verifysort_nr",
2227                 .type   = FIO_OPT_INT,
2228                 .off1   = td_var_offset(verifysort_nr),
2229                 .help   = "Pre-load and sort verify blocks for a read workload",
2230                 .minval = 0,
2231                 .maxval = 131072,
2232                 .def    = "1024",
2233                 .parent = "verify",
2234                 .category = FIO_OPT_C_IO,
2235                 .group  = FIO_OPT_G_VERIFY,
2236         },
2237         {
2238                 .name   = "verify_interval",
2239                 .lname  = "Verify interval",
2240                 .type   = FIO_OPT_INT,
2241                 .off1   = td_var_offset(verify_interval),
2242                 .minval = 2 * sizeof(struct verify_header),
2243                 .help   = "Store verify buffer header every N bytes",
2244                 .parent = "verify",
2245                 .hide   = 1,
2246                 .interval = 2 * sizeof(struct verify_header),
2247                 .category = FIO_OPT_C_IO,
2248                 .group  = FIO_OPT_G_VERIFY,
2249         },
2250         {
2251                 .name   = "verify_offset",
2252                 .lname  = "Verify offset",
2253                 .type   = FIO_OPT_INT,
2254                 .help   = "Offset verify header location by N bytes",
2255                 .off1   = td_var_offset(verify_offset),
2256                 .minval = sizeof(struct verify_header),
2257                 .parent = "verify",
2258                 .hide   = 1,
2259                 .category = FIO_OPT_C_IO,
2260                 .group  = FIO_OPT_G_VERIFY,
2261         },
2262         {
2263                 .name   = "verify_pattern",
2264                 .lname  = "Verify pattern",
2265                 .type   = FIO_OPT_STR,
2266                 .cb     = str_verify_pattern_cb,
2267                 .off1   = td_var_offset(verify_pattern),
2268                 .help   = "Fill pattern for IO buffers",
2269                 .parent = "verify",
2270                 .hide   = 1,
2271                 .category = FIO_OPT_C_IO,
2272                 .group  = FIO_OPT_G_VERIFY,
2273         },
2274         {
2275                 .name   = "verify_fatal",
2276                 .lname  = "Verify fatal",
2277                 .type   = FIO_OPT_BOOL,
2278                 .off1   = td_var_offset(verify_fatal),
2279                 .def    = "0",
2280                 .help   = "Exit on a single verify failure, don't continue",
2281                 .parent = "verify",
2282                 .hide   = 1,
2283                 .category = FIO_OPT_C_IO,
2284                 .group  = FIO_OPT_G_VERIFY,
2285         },
2286         {
2287                 .name   = "verify_dump",
2288                 .lname  = "Verify dump",
2289                 .type   = FIO_OPT_BOOL,
2290                 .off1   = td_var_offset(verify_dump),
2291                 .def    = "0",
2292                 .help   = "Dump contents of good and bad blocks on failure",
2293                 .parent = "verify",
2294                 .hide   = 1,
2295                 .category = FIO_OPT_C_IO,
2296                 .group  = FIO_OPT_G_VERIFY,
2297         },
2298         {
2299                 .name   = "verify_async",
2300                 .lname  = "Verify asynchronously",
2301                 .type   = FIO_OPT_INT,
2302                 .off1   = td_var_offset(verify_async),
2303                 .def    = "0",
2304                 .help   = "Number of async verifier threads to use",
2305                 .parent = "verify",
2306                 .hide   = 1,
2307                 .category = FIO_OPT_C_IO,
2308                 .group  = FIO_OPT_G_VERIFY,
2309         },
2310         {
2311                 .name   = "verify_backlog",
2312                 .lname  = "Verify backlog",
2313                 .type   = FIO_OPT_STR_VAL,
2314                 .off1   = td_var_offset(verify_backlog),
2315                 .help   = "Verify after this number of blocks are written",
2316                 .parent = "verify",
2317                 .hide   = 1,
2318                 .category = FIO_OPT_C_IO,
2319                 .group  = FIO_OPT_G_VERIFY,
2320         },
2321         {
2322                 .name   = "verify_backlog_batch",
2323                 .lname  = "Verify backlog batch",
2324                 .type   = FIO_OPT_INT,
2325                 .off1   = td_var_offset(verify_batch),
2326                 .help   = "Verify this number of IO blocks",
2327                 .parent = "verify",
2328                 .hide   = 1,
2329                 .category = FIO_OPT_C_IO,
2330                 .group  = FIO_OPT_G_VERIFY,
2331         },
2332 #ifdef FIO_HAVE_CPU_AFFINITY
2333         {
2334                 .name   = "verify_async_cpus",
2335                 .lname  = "Async verify CPUs",
2336                 .type   = FIO_OPT_STR,
2337                 .cb     = str_verify_cpus_allowed_cb,
2338                 .off1   = td_var_offset(verify_cpumask),
2339                 .help   = "Set CPUs allowed for async verify threads",
2340                 .parent = "verify_async",
2341                 .hide   = 1,
2342                 .category = FIO_OPT_C_IO,
2343                 .group  = FIO_OPT_G_VERIFY,
2344         },
2345 #endif
2346         {
2347                 .name   = "experimental_verify",
2348                 .off1   = td_var_offset(experimental_verify),
2349                 .type   = FIO_OPT_BOOL,
2350                 .help   = "Enable experimental verification",
2351                 .parent = "verify",
2352                 .category = FIO_OPT_C_IO,
2353                 .group  = FIO_OPT_G_VERIFY,
2354         },
2355         {
2356                 .name   = "verify_state_load",
2357                 .lname  = "Load verify state",
2358                 .off1   = td_var_offset(verify_state),
2359                 .type   = FIO_OPT_BOOL,
2360                 .help   = "Load verify termination state",
2361                 .parent = "verify",
2362                 .category = FIO_OPT_C_IO,
2363                 .group  = FIO_OPT_G_VERIFY,
2364         },
2365         {
2366                 .name   = "verify_state_save",
2367                 .lname  = "Save verify state",
2368                 .off1   = td_var_offset(verify_state_save),
2369                 .type   = FIO_OPT_BOOL,
2370                 .def    = "1",
2371                 .help   = "Save verify state on termination",
2372                 .parent = "verify",
2373                 .category = FIO_OPT_C_IO,
2374                 .group  = FIO_OPT_G_VERIFY,
2375         },
2376 #ifdef FIO_HAVE_TRIM
2377         {
2378                 .name   = "trim_percentage",
2379                 .lname  = "Trim percentage",
2380                 .type   = FIO_OPT_INT,
2381                 .off1   = td_var_offset(trim_percentage),
2382                 .minval = 0,
2383                 .maxval = 100,
2384                 .help   = "Number of verify blocks to discard/trim",
2385                 .parent = "verify",
2386                 .def    = "0",
2387                 .interval = 1,
2388                 .hide   = 1,
2389                 .category = FIO_OPT_C_IO,
2390                 .group  = FIO_OPT_G_TRIM,
2391         },
2392         {
2393                 .name   = "trim_verify_zero",
2394                 .lname  = "Verify trim zero",
2395                 .type   = FIO_OPT_BOOL,
2396                 .help   = "Verify that trim/discarded blocks are returned as zeroes",
2397                 .off1   = td_var_offset(trim_zero),
2398                 .parent = "trim_percentage",
2399                 .hide   = 1,
2400                 .def    = "1",
2401                 .category = FIO_OPT_C_IO,
2402                 .group  = FIO_OPT_G_TRIM,
2403         },
2404         {
2405                 .name   = "trim_backlog",
2406                 .lname  = "Trim backlog",
2407                 .type   = FIO_OPT_STR_VAL,
2408                 .off1   = td_var_offset(trim_backlog),
2409                 .help   = "Trim after this number of blocks are written",
2410                 .parent = "trim_percentage",
2411                 .hide   = 1,
2412                 .interval = 1,
2413                 .category = FIO_OPT_C_IO,
2414                 .group  = FIO_OPT_G_TRIM,
2415         },
2416         {
2417                 .name   = "trim_backlog_batch",
2418                 .lname  = "Trim backlog batch",
2419                 .type   = FIO_OPT_INT,
2420                 .off1   = td_var_offset(trim_batch),
2421                 .help   = "Trim this number of IO blocks",
2422                 .parent = "trim_percentage",
2423                 .hide   = 1,
2424                 .interval = 1,
2425                 .category = FIO_OPT_C_IO,
2426                 .group  = FIO_OPT_G_TRIM,
2427         },
2428 #endif
2429         {
2430                 .name   = "write_iolog",
2431                 .lname  = "Write I/O log",
2432                 .type   = FIO_OPT_STR_STORE,
2433                 .off1   = td_var_offset(write_iolog_file),
2434                 .help   = "Store IO pattern to file",
2435                 .category = FIO_OPT_C_IO,
2436                 .group  = FIO_OPT_G_IOLOG,
2437         },
2438         {
2439                 .name   = "read_iolog",
2440                 .lname  = "Read I/O log",
2441                 .type   = FIO_OPT_STR_STORE,
2442                 .off1   = td_var_offset(read_iolog_file),
2443                 .help   = "Playback IO pattern from file",
2444                 .category = FIO_OPT_C_IO,
2445                 .group  = FIO_OPT_G_IOLOG,
2446         },
2447         {
2448                 .name   = "replay_no_stall",
2449                 .lname  = "Don't stall on replay",
2450                 .type   = FIO_OPT_BOOL,
2451                 .off1   = td_var_offset(no_stall),
2452                 .def    = "0",
2453                 .parent = "read_iolog",
2454                 .hide   = 1,
2455                 .help   = "Playback IO pattern file as fast as possible without stalls",
2456                 .category = FIO_OPT_C_IO,
2457                 .group  = FIO_OPT_G_IOLOG,
2458         },
2459         {
2460                 .name   = "replay_redirect",
2461                 .lname  = "Redirect device for replay",
2462                 .type   = FIO_OPT_STR_STORE,
2463                 .off1   = td_var_offset(replay_redirect),
2464                 .parent = "read_iolog",
2465                 .hide   = 1,
2466                 .help   = "Replay all I/O onto this device, regardless of trace device",
2467                 .category = FIO_OPT_C_IO,
2468                 .group  = FIO_OPT_G_IOLOG,
2469         },
2470         {
2471                 .name   = "replay_scale",
2472                 .lname  = "Replace offset scale factor",
2473                 .type   = FIO_OPT_INT,
2474                 .off1   = td_var_offset(replay_scale),
2475                 .parent = "read_iolog",
2476                 .def    = "1",
2477                 .help   = "Align offsets to this blocksize",
2478                 .category = FIO_OPT_C_IO,
2479                 .group  = FIO_OPT_G_IOLOG,
2480         },
2481         {
2482                 .name   = "replay_align",
2483                 .lname  = "Replace alignment",
2484                 .type   = FIO_OPT_INT,
2485                 .off1   = td_var_offset(replay_align),
2486                 .parent = "read_iolog",
2487                 .help   = "Scale offset down by this factor",
2488                 .category = FIO_OPT_C_IO,
2489                 .group  = FIO_OPT_G_IOLOG,
2490                 .pow2   = 1,
2491         },
2492         {
2493                 .name   = "exec_prerun",
2494                 .lname  = "Pre-execute runnable",
2495                 .type   = FIO_OPT_STR_STORE,
2496                 .off1   = td_var_offset(exec_prerun),
2497                 .help   = "Execute this file prior to running job",
2498                 .category = FIO_OPT_C_GENERAL,
2499                 .group  = FIO_OPT_G_INVALID,
2500         },
2501         {
2502                 .name   = "exec_postrun",
2503                 .lname  = "Post-execute runnable",
2504                 .type   = FIO_OPT_STR_STORE,
2505                 .off1   = td_var_offset(exec_postrun),
2506                 .help   = "Execute this file after running job",
2507                 .category = FIO_OPT_C_GENERAL,
2508                 .group  = FIO_OPT_G_INVALID,
2509         },
2510 #ifdef FIO_HAVE_IOSCHED_SWITCH
2511         {
2512                 .name   = "ioscheduler",
2513                 .lname  = "I/O scheduler",
2514                 .type   = FIO_OPT_STR_STORE,
2515                 .off1   = td_var_offset(ioscheduler),
2516                 .help   = "Use this IO scheduler on the backing device",
2517                 .category = FIO_OPT_C_FILE,
2518                 .group  = FIO_OPT_G_INVALID,
2519         },
2520 #endif
2521         {
2522                 .name   = "zonesize",
2523                 .lname  = "Zone size",
2524                 .type   = FIO_OPT_STR_VAL,
2525                 .off1   = td_var_offset(zone_size),
2526                 .help   = "Amount of data to read per zone",
2527                 .def    = "0",
2528                 .interval = 1024 * 1024,
2529                 .category = FIO_OPT_C_IO,
2530                 .group  = FIO_OPT_G_ZONE,
2531         },
2532         {
2533                 .name   = "zonerange",
2534                 .lname  = "Zone range",
2535                 .type   = FIO_OPT_STR_VAL,
2536                 .off1   = td_var_offset(zone_range),
2537                 .help   = "Give size of an IO zone",
2538                 .def    = "0",
2539                 .interval = 1024 * 1024,
2540                 .category = FIO_OPT_C_IO,
2541                 .group  = FIO_OPT_G_ZONE,
2542         },
2543         {
2544                 .name   = "zoneskip",
2545                 .lname  = "Zone skip",
2546                 .type   = FIO_OPT_STR_VAL,
2547                 .off1   = td_var_offset(zone_skip),
2548                 .help   = "Space between IO zones",
2549                 .def    = "0",
2550                 .interval = 1024 * 1024,
2551                 .category = FIO_OPT_C_IO,
2552                 .group  = FIO_OPT_G_ZONE,
2553         },
2554         {
2555                 .name   = "lockmem",
2556                 .lname  = "Lock memory",
2557                 .type   = FIO_OPT_STR_VAL,
2558                 .off1   = td_var_offset(lockmem),
2559                 .help   = "Lock down this amount of memory (per worker)",
2560                 .def    = "0",
2561                 .interval = 1024 * 1024,
2562                 .category = FIO_OPT_C_GENERAL,
2563                 .group  = FIO_OPT_G_INVALID,
2564         },
2565         {
2566                 .name   = "rwmixread",
2567                 .lname  = "Read/write mix read",
2568                 .type   = FIO_OPT_INT,
2569                 .cb     = str_rwmix_read_cb,
2570                 .off1   = td_var_offset(rwmix[DDIR_READ]),
2571                 .maxval = 100,
2572                 .help   = "Percentage of mixed workload that is reads",
2573                 .def    = "50",
2574                 .interval = 5,
2575                 .inverse = "rwmixwrite",
2576                 .category = FIO_OPT_C_IO,
2577                 .group  = FIO_OPT_G_RWMIX,
2578         },
2579         {
2580                 .name   = "rwmixwrite",
2581                 .lname  = "Read/write mix write",
2582                 .type   = FIO_OPT_INT,
2583                 .cb     = str_rwmix_write_cb,
2584                 .off1   = td_var_offset(rwmix[DDIR_WRITE]),
2585                 .maxval = 100,
2586                 .help   = "Percentage of mixed workload that is writes",
2587                 .def    = "50",
2588                 .interval = 5,
2589                 .inverse = "rwmixread",
2590                 .category = FIO_OPT_C_IO,
2591                 .group  = FIO_OPT_G_RWMIX,
2592         },
2593         {
2594                 .name   = "rwmixcycle",
2595                 .lname  = "Read/write mix cycle",
2596                 .type   = FIO_OPT_DEPRECATED,
2597                 .category = FIO_OPT_C_IO,
2598                 .group  = FIO_OPT_G_RWMIX,
2599         },
2600         {
2601                 .name   = "nice",
2602                 .lname  = "Nice",
2603                 .type   = FIO_OPT_INT,
2604                 .off1   = td_var_offset(nice),
2605                 .help   = "Set job CPU nice value",
2606                 .minval = -19,
2607                 .maxval = 20,
2608                 .def    = "0",
2609                 .interval = 1,
2610                 .category = FIO_OPT_C_GENERAL,
2611                 .group  = FIO_OPT_G_CRED,
2612         },
2613 #ifdef FIO_HAVE_IOPRIO
2614         {
2615                 .name   = "prio",
2616                 .lname  = "I/O nice priority",
2617                 .type   = FIO_OPT_INT,
2618                 .off1   = td_var_offset(ioprio),
2619                 .help   = "Set job IO priority value",
2620                 .minval = 0,
2621                 .maxval = 7,
2622                 .interval = 1,
2623                 .category = FIO_OPT_C_GENERAL,
2624                 .group  = FIO_OPT_G_CRED,
2625         },
2626         {
2627                 .name   = "prioclass",
2628                 .lname  = "I/O nice priority class",
2629                 .type   = FIO_OPT_INT,
2630                 .off1   = td_var_offset(ioprio_class),
2631                 .help   = "Set job IO priority class",
2632                 .minval = 0,
2633                 .maxval = 3,
2634                 .interval = 1,
2635                 .category = FIO_OPT_C_GENERAL,
2636                 .group  = FIO_OPT_G_CRED,
2637         },
2638 #endif
2639         {
2640                 .name   = "thinktime",
2641                 .lname  = "Thinktime",
2642                 .type   = FIO_OPT_INT,
2643                 .off1   = td_var_offset(thinktime),
2644                 .help   = "Idle time between IO buffers (usec)",
2645                 .def    = "0",
2646                 .is_time = 1,
2647                 .category = FIO_OPT_C_IO,
2648                 .group  = FIO_OPT_G_THINKTIME,
2649         },
2650         {
2651                 .name   = "thinktime_spin",
2652                 .lname  = "Thinktime spin",
2653                 .type   = FIO_OPT_INT,
2654                 .off1   = td_var_offset(thinktime_spin),
2655                 .help   = "Start think time by spinning this amount (usec)",
2656                 .def    = "0",
2657                 .is_time = 1,
2658                 .parent = "thinktime",
2659                 .hide   = 1,
2660                 .category = FIO_OPT_C_IO,
2661                 .group  = FIO_OPT_G_THINKTIME,
2662         },
2663         {
2664                 .name   = "thinktime_blocks",
2665                 .lname  = "Thinktime blocks",
2666                 .type   = FIO_OPT_INT,
2667                 .off1   = td_var_offset(thinktime_blocks),
2668                 .help   = "IO buffer period between 'thinktime'",
2669                 .def    = "1",
2670                 .parent = "thinktime",
2671                 .hide   = 1,
2672                 .category = FIO_OPT_C_IO,
2673                 .group  = FIO_OPT_G_THINKTIME,
2674         },
2675         {
2676                 .name   = "rate",
2677                 .lname  = "I/O rate",
2678                 .type   = FIO_OPT_INT,
2679                 .off1   = td_var_offset(rate[DDIR_READ]),
2680                 .off2   = td_var_offset(rate[DDIR_WRITE]),
2681                 .off3   = td_var_offset(rate[DDIR_TRIM]),
2682                 .help   = "Set bandwidth rate",
2683                 .category = FIO_OPT_C_IO,
2684                 .group  = FIO_OPT_G_RATE,
2685         },
2686         {
2687                 .name   = "rate_min",
2688                 .alias  = "ratemin",
2689                 .lname  = "I/O min rate",
2690                 .type   = FIO_OPT_INT,
2691                 .off1   = td_var_offset(ratemin[DDIR_READ]),
2692                 .off2   = td_var_offset(ratemin[DDIR_WRITE]),
2693                 .off3   = td_var_offset(ratemin[DDIR_TRIM]),
2694                 .help   = "Job must meet this rate or it will be shutdown",
2695                 .parent = "rate",
2696                 .hide   = 1,
2697                 .category = FIO_OPT_C_IO,
2698                 .group  = FIO_OPT_G_RATE,
2699         },
2700         {
2701                 .name   = "rate_iops",
2702                 .lname  = "I/O rate IOPS",
2703                 .type   = FIO_OPT_INT,
2704                 .off1   = td_var_offset(rate_iops[DDIR_READ]),
2705                 .off2   = td_var_offset(rate_iops[DDIR_WRITE]),
2706                 .off3   = td_var_offset(rate_iops[DDIR_TRIM]),
2707                 .help   = "Limit IO used to this number of IO operations/sec",
2708                 .hide   = 1,
2709                 .category = FIO_OPT_C_IO,
2710                 .group  = FIO_OPT_G_RATE,
2711         },
2712         {
2713                 .name   = "rate_iops_min",
2714                 .lname  = "I/O min rate IOPS",
2715                 .type   = FIO_OPT_INT,
2716                 .off1   = td_var_offset(rate_iops_min[DDIR_READ]),
2717                 .off2   = td_var_offset(rate_iops_min[DDIR_WRITE]),
2718                 .off3   = td_var_offset(rate_iops_min[DDIR_TRIM]),
2719                 .help   = "Job must meet this rate or it will be shut down",
2720                 .parent = "rate_iops",
2721                 .hide   = 1,
2722                 .category = FIO_OPT_C_IO,
2723                 .group  = FIO_OPT_G_RATE,
2724         },
2725         {
2726                 .name   = "rate_process",
2727                 .lname  = "Rate Process",
2728                 .type   = FIO_OPT_STR,
2729                 .off1   = td_var_offset(rate_process),
2730                 .help   = "What process controls how rated IO is managed",
2731                 .def    = "linear",
2732                 .category = FIO_OPT_C_IO,
2733                 .group  = FIO_OPT_G_RATE,
2734                 .posval = {
2735                           { .ival = "linear",
2736                             .oval = RATE_PROCESS_LINEAR,
2737                             .help = "Linear rate of IO",
2738                           },
2739                           {
2740                             .ival = "poisson",
2741                             .oval = RATE_PROCESS_POISSON,
2742                             .help = "Rate follows Poisson process",
2743                           },
2744                 },
2745                 .parent = "rate",
2746         },
2747         {
2748                 .name   = "rate_cycle",
2749                 .alias  = "ratecycle",
2750                 .lname  = "I/O rate cycle",
2751                 .type   = FIO_OPT_INT,
2752                 .off1   = td_var_offset(ratecycle),
2753                 .help   = "Window average for rate limits (msec)",
2754                 .def    = "1000",
2755                 .parent = "rate",
2756                 .hide   = 1,
2757                 .category = FIO_OPT_C_IO,
2758                 .group  = FIO_OPT_G_RATE,
2759         },
2760         {
2761                 .name   = "max_latency",
2762                 .type   = FIO_OPT_INT,
2763                 .off1   = td_var_offset(max_latency),
2764                 .help   = "Maximum tolerated IO latency (usec)",
2765                 .is_time = 1,
2766                 .category = FIO_OPT_C_IO,
2767                 .group = FIO_OPT_G_LATPROF,
2768         },
2769         {
2770                 .name   = "latency_target",
2771                 .lname  = "Latency Target (usec)",
2772                 .type   = FIO_OPT_STR_VAL_TIME,
2773                 .off1   = td_var_offset(latency_target),
2774                 .help   = "Ramp to max queue depth supporting this latency",
2775                 .is_time = 1,
2776                 .category = FIO_OPT_C_IO,
2777                 .group  = FIO_OPT_G_LATPROF,
2778         },
2779         {
2780                 .name   = "latency_window",
2781                 .lname  = "Latency Window (usec)",
2782                 .type   = FIO_OPT_STR_VAL_TIME,
2783                 .off1   = td_var_offset(latency_window),
2784                 .help   = "Time to sustain latency_target",
2785                 .is_time = 1,
2786                 .category = FIO_OPT_C_IO,
2787                 .group  = FIO_OPT_G_LATPROF,
2788         },
2789         {
2790                 .name   = "latency_percentile",
2791                 .lname  = "Latency Percentile",
2792                 .type   = FIO_OPT_FLOAT_LIST,
2793                 .off1   = td_var_offset(latency_percentile),
2794                 .help   = "Percentile of IOs must be below latency_target",
2795                 .def    = "100",
2796                 .maxlen = 1,
2797                 .minfp  = 0.0,
2798                 .maxfp  = 100.0,
2799                 .category = FIO_OPT_C_IO,
2800                 .group  = FIO_OPT_G_LATPROF,
2801         },
2802         {
2803                 .name   = "invalidate",
2804                 .lname  = "Cache invalidate",
2805                 .type   = FIO_OPT_BOOL,
2806                 .off1   = td_var_offset(invalidate_cache),
2807                 .help   = "Invalidate buffer/page cache prior to running job",
2808                 .def    = "1",
2809                 .category = FIO_OPT_C_IO,
2810                 .group  = FIO_OPT_G_IO_TYPE,
2811         },
2812         {
2813                 .name   = "sync",
2814                 .lname  = "Synchronous I/O",
2815                 .type   = FIO_OPT_BOOL,
2816                 .off1   = td_var_offset(sync_io),
2817                 .help   = "Use O_SYNC for buffered writes",
2818                 .def    = "0",
2819                 .parent = "buffered",
2820                 .hide   = 1,
2821                 .category = FIO_OPT_C_IO,
2822                 .group  = FIO_OPT_G_IO_TYPE,
2823         },
2824         {
2825                 .name   = "create_serialize",
2826                 .lname  = "Create serialize",
2827                 .type   = FIO_OPT_BOOL,
2828                 .off1   = td_var_offset(create_serialize),
2829                 .help   = "Serialize creating of job files",
2830                 .def    = "1",
2831                 .category = FIO_OPT_C_FILE,
2832                 .group  = FIO_OPT_G_INVALID,
2833         },
2834         {
2835                 .name   = "create_fsync",
2836                 .lname  = "Create fsync",
2837                 .type   = FIO_OPT_BOOL,
2838                 .off1   = td_var_offset(create_fsync),
2839                 .help   = "fsync file after creation",
2840                 .def    = "1",
2841                 .category = FIO_OPT_C_FILE,
2842                 .group  = FIO_OPT_G_INVALID,
2843         },
2844         {
2845                 .name   = "create_on_open",
2846                 .lname  = "Create on open",
2847                 .type   = FIO_OPT_BOOL,
2848                 .off1   = td_var_offset(create_on_open),
2849                 .help   = "Create files when they are opened for IO",
2850                 .def    = "0",
2851                 .category = FIO_OPT_C_FILE,
2852                 .group  = FIO_OPT_G_INVALID,
2853         },
2854         {
2855                 .name   = "create_only",
2856                 .type   = FIO_OPT_BOOL,
2857                 .off1   = td_var_offset(create_only),
2858                 .help   = "Only perform file creation phase",
2859                 .category = FIO_OPT_C_FILE,
2860                 .def    = "0",
2861         },
2862         {
2863                 .name   = "allow_file_create",
2864                 .lname  = "Allow file create",
2865                 .type   = FIO_OPT_BOOL,
2866                 .off1   = td_var_offset(allow_create),
2867                 .help   = "Permit fio to create files, if they don't exist",
2868                 .def    = "1",
2869                 .category = FIO_OPT_C_FILE,
2870                 .group  = FIO_OPT_G_FILENAME,
2871         },
2872         {
2873                 .name   = "allow_mounted_write",
2874                 .lname  = "Allow mounted write",
2875                 .type   = FIO_OPT_BOOL,
2876                 .off1   = td_var_offset(allow_mounted_write),
2877                 .help   = "Allow writes to a mounted partition",
2878                 .def    = "0",
2879                 .category = FIO_OPT_C_FILE,
2880                 .group  = FIO_OPT_G_FILENAME,
2881         },
2882         {
2883                 .name   = "pre_read",
2884                 .lname  = "Pre-read files",
2885                 .type   = FIO_OPT_BOOL,
2886                 .off1   = td_var_offset(pre_read),
2887                 .help   = "Pre-read files before starting official testing",
2888                 .def    = "0",
2889                 .category = FIO_OPT_C_FILE,
2890                 .group  = FIO_OPT_G_INVALID,
2891         },
2892 #ifdef FIO_HAVE_CPU_AFFINITY
2893         {
2894                 .name   = "cpumask",
2895                 .lname  = "CPU mask",
2896                 .type   = FIO_OPT_INT,
2897                 .cb     = str_cpumask_cb,
2898                 .off1   = td_var_offset(cpumask),
2899                 .help   = "CPU affinity mask",
2900                 .category = FIO_OPT_C_GENERAL,
2901                 .group  = FIO_OPT_G_CRED,
2902         },
2903         {
2904                 .name   = "cpus_allowed",
2905                 .lname  = "CPUs allowed",
2906                 .type   = FIO_OPT_STR,
2907                 .cb     = str_cpus_allowed_cb,
2908                 .off1   = td_var_offset(cpumask),
2909                 .help   = "Set CPUs allowed",
2910                 .category = FIO_OPT_C_GENERAL,
2911                 .group  = FIO_OPT_G_CRED,
2912         },
2913         {
2914                 .name   = "cpus_allowed_policy",
2915                 .lname  = "CPUs allowed distribution policy",
2916                 .type   = FIO_OPT_STR,
2917                 .off1   = td_var_offset(cpus_allowed_policy),
2918                 .help   = "Distribution policy for cpus_allowed",
2919                 .parent = "cpus_allowed",
2920                 .prio   = 1,
2921                 .posval = {
2922                           { .ival = "shared",
2923                             .oval = FIO_CPUS_SHARED,
2924                             .help = "Mask shared between threads",
2925                           },
2926                           { .ival = "split",
2927                             .oval = FIO_CPUS_SPLIT,
2928                             .help = "Mask split between threads",
2929                           },
2930                 },
2931                 .category = FIO_OPT_C_GENERAL,
2932                 .group  = FIO_OPT_G_CRED,
2933         },
2934 #endif
2935 #ifdef CONFIG_LIBNUMA
2936         {
2937                 .name   = "numa_cpu_nodes",
2938                 .type   = FIO_OPT_STR,
2939                 .cb     = str_numa_cpunodes_cb,
2940                 .off1   = td_var_offset(numa_cpunodes),
2941                 .help   = "NUMA CPU nodes bind",
2942                 .category = FIO_OPT_C_GENERAL,
2943                 .group  = FIO_OPT_G_INVALID,
2944         },
2945         {
2946                 .name   = "numa_mem_policy",
2947                 .type   = FIO_OPT_STR,
2948                 .cb     = str_numa_mpol_cb,
2949                 .off1   = td_var_offset(numa_memnodes),
2950                 .help   = "NUMA memory policy setup",
2951                 .category = FIO_OPT_C_GENERAL,
2952                 .group  = FIO_OPT_G_INVALID,
2953         },
2954 #endif
2955         {
2956                 .name   = "end_fsync",
2957                 .lname  = "End fsync",
2958                 .type   = FIO_OPT_BOOL,
2959                 .off1   = td_var_offset(end_fsync),
2960                 .help   = "Include fsync at the end of job",
2961                 .def    = "0",
2962                 .category = FIO_OPT_C_FILE,
2963                 .group  = FIO_OPT_G_INVALID,
2964         },
2965         {
2966                 .name   = "fsync_on_close",
2967                 .lname  = "Fsync on close",
2968                 .type   = FIO_OPT_BOOL,
2969                 .off1   = td_var_offset(fsync_on_close),
2970                 .help   = "fsync files on close",
2971                 .def    = "0",
2972                 .category = FIO_OPT_C_FILE,
2973                 .group  = FIO_OPT_G_INVALID,
2974         },
2975         {
2976                 .name   = "unlink",
2977                 .lname  = "Unlink file",
2978                 .type   = FIO_OPT_BOOL,
2979                 .off1   = td_var_offset(unlink),
2980                 .help   = "Unlink created files after job has completed",
2981                 .def    = "0",
2982                 .category = FIO_OPT_C_FILE,
2983                 .group  = FIO_OPT_G_INVALID,
2984         },
2985         {
2986                 .name   = "exitall",
2987                 .lname  = "Exit-all on terminate",
2988                 .type   = FIO_OPT_STR_SET,
2989                 .cb     = str_exitall_cb,
2990                 .help   = "Terminate all jobs when one exits",
2991                 .category = FIO_OPT_C_GENERAL,
2992                 .group  = FIO_OPT_G_PROCESS,
2993         },
2994         {
2995                 .name   = "exitall_on_error",
2996                 .lname  = "Exit-all on terminate in error",
2997                 .type   = FIO_OPT_BOOL,
2998                 .off1   = td_var_offset(unlink),
2999                 .help   = "Terminate all jobs when one exits in error",
3000                 .category = FIO_OPT_C_GENERAL,
3001                 .group  = FIO_OPT_G_PROCESS,
3002         },
3003         {
3004                 .name   = "stonewall",
3005                 .lname  = "Wait for previous",
3006                 .alias  = "wait_for_previous",
3007                 .type   = FIO_OPT_STR_SET,
3008                 .off1   = td_var_offset(stonewall),
3009                 .help   = "Insert a hard barrier between this job and previous",
3010                 .category = FIO_OPT_C_GENERAL,
3011                 .group  = FIO_OPT_G_PROCESS,
3012         },
3013         {
3014                 .name   = "new_group",
3015                 .lname  = "New group",
3016                 .type   = FIO_OPT_STR_SET,
3017                 .off1   = td_var_offset(new_group),
3018                 .help   = "Mark the start of a new group (for reporting)",
3019                 .category = FIO_OPT_C_GENERAL,
3020                 .group  = FIO_OPT_G_PROCESS,
3021         },
3022         {
3023                 .name   = "thread",
3024                 .lname  = "Thread",
3025                 .type   = FIO_OPT_STR_SET,
3026                 .off1   = td_var_offset(use_thread),
3027                 .help   = "Use threads instead of processes",
3028 #ifdef CONFIG_NO_SHM
3029                 .def    = "1",
3030                 .no_warn_def = 1,
3031 #endif
3032                 .category = FIO_OPT_C_GENERAL,
3033                 .group  = FIO_OPT_G_PROCESS,
3034         },
3035         {
3036                 .name   = "per_job_logs",
3037                 .type   = FIO_OPT_BOOL,
3038                 .off1   = td_var_offset(per_job_logs),
3039                 .help   = "Include job number in generated log files or not",
3040                 .def    = "1",
3041                 .category = FIO_OPT_C_LOG,
3042                 .group  = FIO_OPT_G_INVALID,
3043         },
3044         {
3045                 .name   = "write_bw_log",
3046                 .lname  = "Write bandwidth log",
3047                 .type   = FIO_OPT_STR_STORE,
3048                 .off1   = td_var_offset(bw_log_file),
3049                 .help   = "Write log of bandwidth during run",
3050                 .category = FIO_OPT_C_LOG,
3051                 .group  = FIO_OPT_G_INVALID,
3052         },
3053         {
3054                 .name   = "write_lat_log",
3055                 .lname  = "Write latency log",
3056                 .type   = FIO_OPT_STR_STORE,
3057                 .off1   = td_var_offset(lat_log_file),
3058                 .help   = "Write log of latency during run",
3059                 .category = FIO_OPT_C_LOG,
3060                 .group  = FIO_OPT_G_INVALID,
3061         },
3062         {
3063                 .name   = "write_iops_log",
3064                 .lname  = "Write IOPS log",
3065                 .type   = FIO_OPT_STR_STORE,
3066                 .off1   = td_var_offset(iops_log_file),
3067                 .help   = "Write log of IOPS during run",
3068                 .category = FIO_OPT_C_LOG,
3069                 .group  = FIO_OPT_G_INVALID,
3070         },
3071         {
3072                 .name   = "log_avg_msec",
3073                 .lname  = "Log averaging (msec)",
3074                 .type   = FIO_OPT_INT,
3075                 .off1   = td_var_offset(log_avg_msec),
3076                 .help   = "Average bw/iops/lat logs over this period of time",
3077                 .def    = "0",
3078                 .category = FIO_OPT_C_LOG,
3079                 .group  = FIO_OPT_G_INVALID,
3080         },
3081         {
3082                 .name   = "log_max_value",
3083                 .lname  = "Log maximum instead of average",
3084                 .type   = FIO_OPT_BOOL,
3085                 .off1   = td_var_offset(log_max),
3086                 .help   = "Log max sample in a window instead of average",
3087                 .def    = "0",
3088                 .category = FIO_OPT_C_LOG,
3089                 .group  = FIO_OPT_G_INVALID,
3090         },
3091         {
3092                 .name   = "log_offset",
3093                 .lname  = "Log offset of IO",
3094                 .type   = FIO_OPT_BOOL,
3095                 .off1   = td_var_offset(log_offset),
3096                 .help   = "Include offset of IO for each log entry",
3097                 .def    = "0",
3098                 .category = FIO_OPT_C_LOG,
3099                 .group  = FIO_OPT_G_INVALID,
3100         },
3101 #ifdef CONFIG_ZLIB
3102         {
3103                 .name   = "log_compression",
3104                 .lname  = "Log compression",
3105                 .type   = FIO_OPT_INT,
3106                 .off1   = td_var_offset(log_gz),
3107                 .help   = "Log in compressed chunks of this size",
3108                 .minval = 1024ULL,
3109                 .maxval = 512 * 1024 * 1024ULL,
3110                 .category = FIO_OPT_C_LOG,
3111                 .group  = FIO_OPT_G_INVALID,
3112         },
3113 #ifdef FIO_HAVE_CPU_AFFINITY
3114         {
3115                 .name   = "log_compression_cpus",
3116                 .lname  = "Log Compression CPUs",
3117                 .type   = FIO_OPT_STR,
3118                 .cb     = str_log_cpus_allowed_cb,
3119                 .off1   = td_var_offset(log_gz_cpumask),
3120                 .parent = "log_compression",
3121                 .help   = "Limit log compression to these CPUs",
3122                 .category = FIO_OPT_C_LOG,
3123                 .group  = FIO_OPT_G_INVALID,
3124         },
3125 #endif
3126         {
3127                 .name   = "log_store_compressed",
3128                 .lname  = "Log store compressed",
3129                 .type   = FIO_OPT_BOOL,
3130                 .off1   = td_var_offset(log_gz_store),
3131                 .help   = "Store logs in a compressed format",
3132                 .category = FIO_OPT_C_LOG,
3133                 .group  = FIO_OPT_G_INVALID,
3134         },
3135 #endif
3136         {
3137                 .name   = "block_error_percentiles",
3138                 .lname  = "Block error percentiles",
3139                 .type   = FIO_OPT_BOOL,
3140                 .off1   = td_var_offset(block_error_hist),
3141                 .help   = "Record trim block errors and make a histogram",
3142                 .def    = "0",
3143                 .category = FIO_OPT_C_LOG,
3144                 .group  = FIO_OPT_G_INVALID,
3145         },
3146         {
3147                 .name   = "bwavgtime",
3148                 .lname  = "Bandwidth average time",
3149                 .type   = FIO_OPT_INT,
3150                 .off1   = td_var_offset(bw_avg_time),
3151                 .help   = "Time window over which to calculate bandwidth"
3152                           " (msec)",
3153                 .def    = "500",
3154                 .parent = "write_bw_log",
3155                 .hide   = 1,
3156                 .interval = 100,
3157                 .category = FIO_OPT_C_LOG,
3158                 .group  = FIO_OPT_G_INVALID,
3159         },
3160         {
3161                 .name   = "iopsavgtime",
3162                 .lname  = "IOPS average time",
3163                 .type   = FIO_OPT_INT,
3164                 .off1   = td_var_offset(iops_avg_time),
3165                 .help   = "Time window over which to calculate IOPS (msec)",
3166                 .def    = "500",
3167                 .parent = "write_iops_log",
3168                 .hide   = 1,
3169                 .interval = 100,
3170                 .category = FIO_OPT_C_LOG,
3171                 .group  = FIO_OPT_G_INVALID,
3172         },
3173         {
3174                 .name   = "group_reporting",
3175                 .lname  = "Group reporting",
3176                 .type   = FIO_OPT_STR_SET,
3177                 .off1   = td_var_offset(group_reporting),
3178                 .help   = "Do reporting on a per-group basis",
3179                 .category = FIO_OPT_C_STAT,
3180                 .group  = FIO_OPT_G_INVALID,
3181         },
3182         {
3183                 .name   = "zero_buffers",
3184                 .lname  = "Zero I/O buffers",
3185                 .type   = FIO_OPT_STR_SET,
3186                 .off1   = td_var_offset(zero_buffers),
3187                 .help   = "Init IO buffers to all zeroes",
3188                 .category = FIO_OPT_C_IO,
3189                 .group  = FIO_OPT_G_IO_BUF,
3190         },
3191         {
3192                 .name   = "refill_buffers",
3193                 .lname  = "Refill I/O buffers",
3194                 .type   = FIO_OPT_STR_SET,
3195                 .off1   = td_var_offset(refill_buffers),
3196                 .help   = "Refill IO buffers on every IO submit",
3197                 .category = FIO_OPT_C_IO,
3198                 .group  = FIO_OPT_G_IO_BUF,
3199         },
3200         {
3201                 .name   = "scramble_buffers",
3202                 .lname  = "Scramble I/O buffers",
3203                 .type   = FIO_OPT_BOOL,
3204                 .off1   = td_var_offset(scramble_buffers),
3205                 .help   = "Slightly scramble buffers on every IO submit",
3206                 .def    = "1",
3207                 .category = FIO_OPT_C_IO,
3208                 .group  = FIO_OPT_G_IO_BUF,
3209         },
3210         {
3211                 .name   = "buffer_pattern",
3212                 .lname  = "Buffer pattern",
3213                 .type   = FIO_OPT_STR,
3214                 .cb     = str_buffer_pattern_cb,
3215                 .off1   = td_var_offset(buffer_pattern),
3216                 .help   = "Fill pattern for IO buffers",
3217                 .category = FIO_OPT_C_IO,
3218                 .group  = FIO_OPT_G_IO_BUF,
3219         },
3220         {
3221                 .name   = "buffer_compress_percentage",
3222                 .lname  = "Buffer compression percentage",
3223                 .type   = FIO_OPT_INT,
3224                 .cb     = str_buffer_compress_cb,
3225                 .off1   = td_var_offset(compress_percentage),
3226                 .maxval = 100,
3227                 .minval = 0,
3228                 .help   = "How compressible the buffer is (approximately)",
3229                 .interval = 5,
3230                 .category = FIO_OPT_C_IO,
3231                 .group  = FIO_OPT_G_IO_BUF,
3232         },
3233         {
3234                 .name   = "buffer_compress_chunk",
3235                 .lname  = "Buffer compression chunk size",
3236                 .type   = FIO_OPT_INT,
3237                 .off1   = td_var_offset(compress_chunk),
3238                 .parent = "buffer_compress_percentage",
3239                 .hide   = 1,
3240                 .help   = "Size of compressible region in buffer",
3241                 .interval = 256,
3242                 .category = FIO_OPT_C_IO,
3243                 .group  = FIO_OPT_G_IO_BUF,
3244         },
3245         {
3246                 .name   = "dedupe_percentage",
3247                 .lname  = "Dedupe percentage",
3248                 .type   = FIO_OPT_INT,
3249                 .cb     = str_dedupe_cb,
3250                 .off1   = td_var_offset(dedupe_percentage),
3251                 .maxval = 100,
3252                 .minval = 0,
3253                 .help   = "Percentage of buffers that are dedupable",
3254                 .interval = 1,
3255                 .category = FIO_OPT_C_IO,
3256                 .group  = FIO_OPT_G_IO_BUF,
3257         },
3258         {
3259                 .name   = "clat_percentiles",
3260                 .lname  = "Completion latency percentiles",
3261                 .type   = FIO_OPT_BOOL,
3262                 .off1   = td_var_offset(clat_percentiles),
3263                 .help   = "Enable the reporting of completion latency percentiles",
3264                 .def    = "1",
3265                 .category = FIO_OPT_C_STAT,
3266                 .group  = FIO_OPT_G_INVALID,
3267         },
3268         {
3269                 .name   = "percentile_list",
3270                 .lname  = "Percentile list",
3271                 .type   = FIO_OPT_FLOAT_LIST,
3272                 .off1   = td_var_offset(percentile_list),
3273                 .off2   = td_var_offset(percentile_precision),
3274                 .help   = "Specify a custom list of percentiles to report for "
3275                           "completion latency and block errors",
3276                 .def    = "1:5:10:20:30:40:50:60:70:80:90:95:99:99.5:99.9:99.95:99.99",
3277                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
3278                 .minfp  = 0.0,
3279                 .maxfp  = 100.0,
3280                 .category = FIO_OPT_C_STAT,
3281                 .group  = FIO_OPT_G_INVALID,
3282         },
3283
3284 #ifdef FIO_HAVE_DISK_UTIL
3285         {
3286                 .name   = "disk_util",
3287                 .lname  = "Disk utilization",
3288                 .type   = FIO_OPT_BOOL,
3289                 .off1   = td_var_offset(do_disk_util),
3290                 .help   = "Log disk utilization statistics",
3291                 .def    = "1",
3292                 .category = FIO_OPT_C_STAT,
3293                 .group  = FIO_OPT_G_INVALID,
3294         },
3295 #endif
3296         {
3297                 .name   = "gtod_reduce",
3298                 .lname  = "Reduce gettimeofday() calls",
3299                 .type   = FIO_OPT_BOOL,
3300                 .help   = "Greatly reduce number of gettimeofday() calls",
3301                 .cb     = str_gtod_reduce_cb,
3302                 .def    = "0",
3303                 .hide_on_set = 1,
3304                 .category = FIO_OPT_C_STAT,
3305                 .group  = FIO_OPT_G_INVALID,
3306         },
3307         {
3308                 .name   = "disable_lat",
3309                 .lname  = "Disable all latency stats",
3310                 .type   = FIO_OPT_BOOL,
3311                 .off1   = td_var_offset(disable_lat),
3312                 .help   = "Disable latency numbers",
3313                 .parent = "gtod_reduce",
3314                 .hide   = 1,
3315                 .def    = "0",
3316                 .category = FIO_OPT_C_STAT,
3317                 .group  = FIO_OPT_G_INVALID,
3318         },
3319         {
3320                 .name   = "disable_clat",
3321                 .lname  = "Disable completion latency stats",
3322                 .type   = FIO_OPT_BOOL,
3323                 .off1   = td_var_offset(disable_clat),
3324                 .help   = "Disable completion latency numbers",
3325                 .parent = "gtod_reduce",
3326                 .hide   = 1,
3327                 .def    = "0",
3328                 .category = FIO_OPT_C_STAT,
3329                 .group  = FIO_OPT_G_INVALID,
3330         },
3331         {
3332                 .name   = "disable_slat",
3333                 .lname  = "Disable submission latency stats",
3334                 .type   = FIO_OPT_BOOL,
3335                 .off1   = td_var_offset(disable_slat),
3336                 .help   = "Disable submission latency numbers",
3337                 .parent = "gtod_reduce",
3338                 .hide   = 1,
3339                 .def    = "0",
3340                 .category = FIO_OPT_C_STAT,
3341                 .group  = FIO_OPT_G_INVALID,
3342         },
3343         {
3344                 .name   = "disable_bw_measurement",
3345                 .lname  = "Disable bandwidth stats",
3346                 .type   = FIO_OPT_BOOL,
3347                 .off1   = td_var_offset(disable_bw),
3348                 .help   = "Disable bandwidth logging",
3349                 .parent = "gtod_reduce",
3350                 .hide   = 1,
3351                 .def    = "0",
3352                 .category = FIO_OPT_C_STAT,
3353                 .group  = FIO_OPT_G_INVALID,
3354         },
3355         {
3356                 .name   = "gtod_cpu",
3357                 .lname  = "Dedicated gettimeofday() CPU",
3358                 .type   = FIO_OPT_INT,
3359                 .off1   = td_var_offset(gtod_cpu),
3360                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
3361                 .verify = gtod_cpu_verify,
3362                 .category = FIO_OPT_C_GENERAL,
3363                 .group  = FIO_OPT_G_CLOCK,
3364         },
3365         {
3366                 .name   = "unified_rw_reporting",
3367                 .type   = FIO_OPT_BOOL,
3368                 .off1   = td_var_offset(unified_rw_rep),
3369                 .help   = "Unify reporting across data direction",
3370                 .def    = "0",
3371                 .category = FIO_OPT_C_GENERAL,
3372                 .group  = FIO_OPT_G_INVALID,
3373         },
3374         {
3375                 .name   = "continue_on_error",
3376                 .lname  = "Continue on error",
3377                 .type   = FIO_OPT_STR,
3378                 .off1   = td_var_offset(continue_on_error),
3379                 .help   = "Continue on non-fatal errors during IO",
3380                 .def    = "none",
3381                 .category = FIO_OPT_C_GENERAL,
3382                 .group  = FIO_OPT_G_ERR,
3383                 .posval = {
3384                           { .ival = "none",
3385                             .oval = ERROR_TYPE_NONE,
3386                             .help = "Exit when an error is encountered",
3387                           },
3388                           { .ival = "read",
3389                             .oval = ERROR_TYPE_READ,
3390                             .help = "Continue on read errors only",
3391                           },
3392                           { .ival = "write",
3393                             .oval = ERROR_TYPE_WRITE,
3394                             .help = "Continue on write errors only",
3395                           },
3396                           { .ival = "io",
3397                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
3398                             .help = "Continue on any IO errors",
3399                           },
3400                           { .ival = "verify",
3401                             .oval = ERROR_TYPE_VERIFY,
3402                             .help = "Continue on verify errors only",
3403                           },
3404                           { .ival = "all",
3405                             .oval = ERROR_TYPE_ANY,
3406                             .help = "Continue on all io and verify errors",
3407                           },
3408                           { .ival = "0",
3409                             .oval = ERROR_TYPE_NONE,
3410                             .help = "Alias for 'none'",
3411                           },
3412                           { .ival = "1",
3413                             .oval = ERROR_TYPE_ANY,
3414                             .help = "Alias for 'all'",
3415                           },
3416                 },
3417         },
3418         {
3419                 .name   = "ignore_error",
3420                 .type   = FIO_OPT_STR,
3421                 .cb     = str_ignore_error_cb,
3422                 .off1   = td_var_offset(ignore_error_nr),
3423                 .help   = "Set a specific list of errors to ignore",
3424                 .parent = "rw",
3425                 .category = FIO_OPT_C_GENERAL,
3426                 .group  = FIO_OPT_G_ERR,
3427         },
3428         {
3429                 .name   = "error_dump",
3430                 .type   = FIO_OPT_BOOL,
3431                 .off1   = td_var_offset(error_dump),
3432                 .def    = "0",
3433                 .help   = "Dump info on each error",
3434                 .category = FIO_OPT_C_GENERAL,
3435                 .group  = FIO_OPT_G_ERR,
3436         },
3437         {
3438                 .name   = "profile",
3439                 .lname  = "Profile",
3440                 .type   = FIO_OPT_STR_STORE,
3441                 .off1   = td_var_offset(profile),
3442                 .help   = "Select a specific builtin performance test",
3443                 .category = FIO_OPT_C_PROFILE,
3444                 .group  = FIO_OPT_G_INVALID,
3445         },
3446         {
3447                 .name   = "cgroup",
3448                 .lname  = "Cgroup",
3449                 .type   = FIO_OPT_STR_STORE,
3450                 .off1   = td_var_offset(cgroup),
3451                 .help   = "Add job to cgroup of this name",
3452                 .category = FIO_OPT_C_GENERAL,
3453                 .group  = FIO_OPT_G_CGROUP,
3454         },
3455         {
3456                 .name   = "cgroup_nodelete",
3457                 .lname  = "Cgroup no-delete",
3458                 .type   = FIO_OPT_BOOL,
3459                 .off1   = td_var_offset(cgroup_nodelete),
3460                 .help   = "Do not delete cgroups after job completion",
3461                 .def    = "0",
3462                 .parent = "cgroup",
3463                 .category = FIO_OPT_C_GENERAL,
3464                 .group  = FIO_OPT_G_CGROUP,
3465         },
3466         {
3467                 .name   = "cgroup_weight",
3468                 .lname  = "Cgroup weight",
3469                 .type   = FIO_OPT_INT,
3470                 .off1   = td_var_offset(cgroup_weight),
3471                 .help   = "Use given weight for cgroup",
3472                 .minval = 100,
3473                 .maxval = 1000,
3474                 .parent = "cgroup",
3475                 .category = FIO_OPT_C_GENERAL,
3476                 .group  = FIO_OPT_G_CGROUP,
3477         },
3478         {
3479                 .name   = "uid",
3480                 .lname  = "User ID",
3481                 .type   = FIO_OPT_INT,
3482                 .off1   = td_var_offset(uid),
3483                 .help   = "Run job with this user ID",
3484                 .category = FIO_OPT_C_GENERAL,
3485                 .group  = FIO_OPT_G_CRED,
3486         },
3487         {
3488                 .name   = "gid",
3489                 .lname  = "Group ID",
3490                 .type   = FIO_OPT_INT,
3491                 .off1   = td_var_offset(gid),
3492                 .help   = "Run job with this group ID",
3493                 .category = FIO_OPT_C_GENERAL,
3494                 .group  = FIO_OPT_G_CRED,
3495         },
3496         {
3497                 .name   = "kb_base",
3498                 .lname  = "KB Base",
3499                 .type   = FIO_OPT_INT,
3500                 .off1   = td_var_offset(kb_base),
3501                 .prio   = 1,
3502                 .def    = "1024",
3503                 .posval = {
3504                           { .ival = "1024",
3505                             .oval = 1024,
3506                             .help = "Use 1024 as the K base",
3507                           },
3508                           { .ival = "1000",
3509                             .oval = 1000,
3510                             .help = "Use 1000 as the K base",
3511                           },
3512                 },
3513                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
3514                 .category = FIO_OPT_C_GENERAL,
3515                 .group  = FIO_OPT_G_INVALID,
3516         },
3517         {
3518                 .name   = "unit_base",
3519                 .lname  = "Base unit for reporting (Bits or Bytes)",
3520                 .type   = FIO_OPT_INT,
3521                 .off1   = td_var_offset(unit_base),
3522                 .prio   = 1,
3523                 .posval = {
3524                           { .ival = "0",
3525                             .oval = 0,
3526                             .help = "Auto-detect",
3527                           },
3528                           { .ival = "8",
3529                             .oval = 8,
3530                             .help = "Normal (byte based)",
3531                           },
3532                           { .ival = "1",
3533                             .oval = 1,
3534                             .help = "Bit based",
3535                           },
3536                 },
3537                 .help   = "Bit multiple of result summary data (8 for byte, 1 for bit)",
3538                 .category = FIO_OPT_C_GENERAL,
3539                 .group  = FIO_OPT_G_INVALID,
3540         },
3541         {
3542                 .name   = "hugepage-size",
3543                 .lname  = "Hugepage size",
3544                 .type   = FIO_OPT_INT,
3545                 .off1   = td_var_offset(hugepage_size),
3546                 .help   = "When using hugepages, specify size of each page",
3547                 .def    = __fio_stringify(FIO_HUGE_PAGE),
3548                 .interval = 1024 * 1024,
3549                 .category = FIO_OPT_C_GENERAL,
3550                 .group  = FIO_OPT_G_INVALID,
3551         },
3552         {
3553                 .name   = "flow_id",
3554                 .lname  = "I/O flow ID",
3555                 .type   = FIO_OPT_INT,
3556                 .off1   = td_var_offset(flow_id),
3557                 .help   = "The flow index ID to use",
3558                 .def    = "0",
3559                 .category = FIO_OPT_C_IO,
3560                 .group  = FIO_OPT_G_IO_FLOW,
3561         },
3562         {
3563                 .name   = "flow",
3564                 .lname  = "I/O flow weight",
3565                 .type   = FIO_OPT_INT,
3566                 .off1   = td_var_offset(flow),
3567                 .help   = "Weight for flow control of this job",
3568                 .parent = "flow_id",
3569                 .hide   = 1,
3570                 .def    = "0",
3571                 .category = FIO_OPT_C_IO,
3572                 .group  = FIO_OPT_G_IO_FLOW,
3573         },
3574         {
3575                 .name   = "flow_watermark",
3576                 .lname  = "I/O flow watermark",
3577                 .type   = FIO_OPT_INT,
3578                 .off1   = td_var_offset(flow_watermark),
3579                 .help   = "High watermark for flow control. This option"
3580                         " should be set to the same value for all threads"
3581                         " with non-zero flow.",
3582                 .parent = "flow_id",
3583                 .hide   = 1,
3584                 .def    = "1024",
3585                 .category = FIO_OPT_C_IO,
3586                 .group  = FIO_OPT_G_IO_FLOW,
3587         },
3588         {
3589                 .name   = "flow_sleep",
3590                 .lname  = "I/O flow sleep",
3591                 .type   = FIO_OPT_INT,
3592                 .off1   = td_var_offset(flow_sleep),
3593                 .help   = "How many microseconds to sleep after being held"
3594                         " back by the flow control mechanism",
3595                 .parent = "flow_id",
3596                 .hide   = 1,
3597                 .def    = "0",
3598                 .category = FIO_OPT_C_IO,
3599                 .group  = FIO_OPT_G_IO_FLOW,
3600         },
3601         {
3602                 .name   = "skip_bad",
3603                 .lname  = "Skip operations against bad blocks",
3604                 .type   = FIO_OPT_BOOL,
3605                 .off1   = td_var_offset(skip_bad),
3606                 .help   = "Skip operations against known bad blocks.",
3607                 .hide   = 1,
3608                 .def    = "0",
3609                 .category = FIO_OPT_C_IO,
3610                 .group  = FIO_OPT_G_MTD,
3611         },
3612         {
3613                 .name = NULL,
3614         },
3615 };
3616
3617 static void add_to_lopt(struct option *lopt, struct fio_option *o,
3618                         const char *name, int val)
3619 {
3620         lopt->name = (char *) name;
3621         lopt->val = val;
3622         if (o->type == FIO_OPT_STR_SET)
3623                 lopt->has_arg = optional_argument;
3624         else
3625                 lopt->has_arg = required_argument;
3626 }
3627
3628 static void options_to_lopts(struct fio_option *opts,
3629                               struct option *long_options,
3630                               int i, int option_type)
3631 {
3632         struct fio_option *o = &opts[0];
3633         while (o->name) {
3634                 add_to_lopt(&long_options[i], o, o->name, option_type);
3635                 if (o->alias) {
3636                         i++;
3637                         add_to_lopt(&long_options[i], o, o->alias, option_type);
3638                 }
3639
3640                 i++;
3641                 o++;
3642                 assert(i < FIO_NR_OPTIONS);
3643         }
3644 }
3645
3646 void fio_options_set_ioengine_opts(struct option *long_options,
3647                                    struct thread_data *td)
3648 {
3649         unsigned int i;
3650
3651         i = 0;
3652         while (long_options[i].name) {
3653                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
3654                         memset(&long_options[i], 0, sizeof(*long_options));
3655                         break;
3656                 }
3657                 i++;
3658         }
3659
3660         /*
3661          * Just clear out the prior ioengine options.
3662          */
3663         if (!td || !td->eo)
3664                 return;
3665
3666         options_to_lopts(td->io_ops->options, long_options, i,
3667                          FIO_GETOPT_IOENGINE);
3668 }
3669
3670 void fio_options_dup_and_init(struct option *long_options)
3671 {
3672         unsigned int i;
3673
3674         options_init(fio_options);
3675
3676         i = 0;
3677         while (long_options[i].name)
3678                 i++;
3679
3680         options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
3681 }
3682
3683 struct fio_keyword {
3684         const char *word;
3685         const char *desc;
3686         char *replace;
3687 };
3688
3689 static struct fio_keyword fio_keywords[] = {
3690         {
3691                 .word   = "$pagesize",
3692                 .desc   = "Page size in the system",
3693         },
3694         {
3695                 .word   = "$mb_memory",
3696                 .desc   = "Megabytes of memory online",
3697         },
3698         {
3699                 .word   = "$ncpus",
3700                 .desc   = "Number of CPUs online in the system",
3701         },
3702         {
3703                 .word   = NULL,
3704         },
3705 };
3706
3707 void fio_keywords_exit(void)
3708 {
3709         struct fio_keyword *kw;
3710
3711         kw = &fio_keywords[0];
3712         while (kw->word) {
3713                 free(kw->replace);
3714                 kw->replace = NULL;
3715                 kw++;
3716         }
3717 }
3718
3719 void fio_keywords_init(void)
3720 {
3721         unsigned long long mb_memory;
3722         char buf[128];
3723         long l;
3724
3725         sprintf(buf, "%lu", (unsigned long) page_size);
3726         fio_keywords[0].replace = strdup(buf);
3727
3728         mb_memory = os_phys_mem() / (1024 * 1024);
3729         sprintf(buf, "%llu", mb_memory);
3730         fio_keywords[1].replace = strdup(buf);
3731
3732         l = cpus_online();
3733         sprintf(buf, "%lu", l);
3734         fio_keywords[2].replace = strdup(buf);
3735 }
3736
3737 #define BC_APP          "bc"
3738
3739 static char *bc_calc(char *str)
3740 {
3741         char buf[128], *tmp;
3742         FILE *f;
3743         int ret;
3744
3745         /*
3746          * No math, just return string
3747          */
3748         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
3749              !strchr(str, '/')) || strchr(str, '\''))
3750                 return str;
3751
3752         /*
3753          * Split option from value, we only need to calculate the value
3754          */
3755         tmp = strchr(str, '=');
3756         if (!tmp)
3757                 return str;
3758
3759         tmp++;
3760
3761         /*
3762          * Prevent buffer overflows; such a case isn't reasonable anyway
3763          */
3764         if (strlen(str) >= 128 || strlen(tmp) > 100)
3765                 return str;
3766
3767         sprintf(buf, "which %s > /dev/null", BC_APP);
3768         if (system(buf)) {
3769                 log_err("fio: bc is needed for performing math\n");
3770                 return NULL;
3771         }
3772
3773         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
3774         f = popen(buf, "r");
3775         if (!f)
3776                 return NULL;
3777
3778         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
3779         if (ret <= 0) {
3780                 pclose(f);
3781                 return NULL;
3782         }
3783
3784         pclose(f);
3785         buf[(tmp - str) + ret - 1] = '\0';
3786         memcpy(buf, str, tmp - str);
3787         free(str);
3788         return strdup(buf);
3789 }
3790
3791 /*
3792  * Return a copy of the input string with substrings of the form ${VARNAME}
3793  * substituted with the value of the environment variable VARNAME.  The
3794  * substitution always occurs, even if VARNAME is empty or the corresponding
3795  * environment variable undefined.
3796  */
3797 static char *option_dup_subs(const char *opt)
3798 {
3799         char out[OPT_LEN_MAX+1];
3800         char in[OPT_LEN_MAX+1];
3801         char *outptr = out;
3802         char *inptr = in;
3803         char *ch1, *ch2, *env;
3804         ssize_t nchr = OPT_LEN_MAX;
3805         size_t envlen;
3806
3807         if (strlen(opt) + 1 > OPT_LEN_MAX) {
3808                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
3809                 return NULL;
3810         }
3811
3812         in[OPT_LEN_MAX] = '\0';
3813         strncpy(in, opt, OPT_LEN_MAX);
3814
3815         while (*inptr && nchr > 0) {
3816                 if (inptr[0] == '$' && inptr[1] == '{') {
3817                         ch2 = strchr(inptr, '}');
3818                         if (ch2 && inptr+1 < ch2) {
3819                                 ch1 = inptr+2;
3820                                 inptr = ch2+1;
3821                                 *ch2 = '\0';
3822
3823                                 env = getenv(ch1);
3824                                 if (env) {
3825                                         envlen = strlen(env);
3826                                         if (envlen <= nchr) {
3827                                                 memcpy(outptr, env, envlen);
3828                                                 outptr += envlen;
3829                                                 nchr -= envlen;
3830                                         }
3831                                 }
3832
3833                                 continue;
3834                         }
3835                 }
3836
3837                 *outptr++ = *inptr++;
3838                 --nchr;
3839         }
3840
3841         *outptr = '\0';
3842         return strdup(out);
3843 }
3844
3845 /*
3846  * Look for reserved variable names and replace them with real values
3847  */
3848 static char *fio_keyword_replace(char *opt)
3849 {
3850         char *s;
3851         int i;
3852         int docalc = 0;
3853
3854         for (i = 0; fio_keywords[i].word != NULL; i++) {
3855                 struct fio_keyword *kw = &fio_keywords[i];
3856
3857                 while ((s = strstr(opt, kw->word)) != NULL) {
3858                         char *new = malloc(strlen(opt) + 1);
3859                         char *o_org = opt;
3860                         int olen = s - opt;
3861                         int len;
3862
3863                         /*
3864                          * Copy part of the string before the keyword and
3865                          * sprintf() the replacement after it.
3866                          */
3867                         memcpy(new, opt, olen);
3868                         len = sprintf(new + olen, "%s", kw->replace);
3869
3870                         /*
3871                          * If there's more in the original string, copy that
3872                          * in too
3873                          */
3874                         opt += strlen(kw->word) + olen;
3875                         if (strlen(opt))
3876                                 memcpy(new + olen + len, opt, opt - o_org - 1);
3877
3878                         /*
3879                          * replace opt and free the old opt
3880                          */
3881                         opt = new;
3882                         free(o_org);
3883
3884                         docalc = 1;
3885                 }
3886         }
3887
3888         /*
3889          * Check for potential math and invoke bc, if possible
3890          */
3891         if (docalc)
3892                 opt = bc_calc(opt);
3893
3894         return opt;
3895 }
3896
3897 static char **dup_and_sub_options(char **opts, int num_opts)
3898 {
3899         int i;
3900         char **opts_copy = malloc(num_opts * sizeof(*opts));
3901         for (i = 0; i < num_opts; i++) {
3902                 opts_copy[i] = option_dup_subs(opts[i]);
3903                 if (!opts_copy[i])
3904                         continue;
3905                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
3906         }
3907         return opts_copy;
3908 }
3909
3910 static void show_closest_option(const char *opt)
3911 {
3912         int best_option, best_distance;
3913         int i, distance;
3914         char *name;
3915
3916         if (!strlen(opt))
3917                 return;
3918
3919         name = strdup(opt);
3920         i = 0;
3921         while (name[i] != '\0' && name[i] != '=')
3922                 i++;
3923         name[i] = '\0';
3924
3925         best_option = -1;
3926         best_distance = INT_MAX;
3927         i = 0;
3928         while (fio_options[i].name) {
3929                 distance = string_distance(name, fio_options[i].name);
3930                 if (distance < best_distance) {
3931                         best_distance = distance;
3932                         best_option = i;
3933                 }
3934                 i++;
3935         }
3936
3937         if (best_option != -1 && string_distance_ok(name, best_distance))
3938                 log_err("Did you mean %s?\n", fio_options[best_option].name);
3939
3940         free(name);
3941 }
3942
3943 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
3944 {
3945         int i, ret, unknown;
3946         char **opts_copy;
3947
3948         sort_options(opts, fio_options, num_opts);
3949         opts_copy = dup_and_sub_options(opts, num_opts);
3950
3951         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
3952                 struct fio_option *o;
3953                 int newret = parse_option(opts_copy[i], opts[i], fio_options,
3954                                                 &o, td, &td->opt_list);
3955
3956                 if (!newret && o)
3957                         fio_option_mark_set(&td->o, o);
3958
3959                 if (opts_copy[i]) {
3960                         if (newret && !o) {
3961                                 unknown++;
3962                                 continue;
3963                         }
3964                         free(opts_copy[i]);
3965                         opts_copy[i] = NULL;
3966                 }
3967
3968                 ret |= newret;
3969         }
3970
3971         if (unknown) {
3972                 ret |= ioengine_load(td);
3973                 if (td->eo) {
3974                         sort_options(opts_copy, td->io_ops->options, num_opts);
3975                         opts = opts_copy;
3976                 }
3977                 for (i = 0; i < num_opts; i++) {
3978                         struct fio_option *o = NULL;
3979                         int newret = 1;
3980
3981                         if (!opts_copy[i])
3982                                 continue;
3983
3984                         if (td->eo)
3985                                 newret = parse_option(opts_copy[i], opts[i],
3986                                                       td->io_ops->options, &o,
3987                                                       td->eo, &td->opt_list);
3988
3989                         ret |= newret;
3990                         if (!o) {
3991                                 log_err("Bad option <%s>\n", opts[i]);
3992                                 show_closest_option(opts[i]);
3993                         }
3994                         free(opts_copy[i]);
3995                         opts_copy[i] = NULL;
3996                 }
3997         }
3998
3999         free(opts_copy);
4000         return ret;
4001 }
4002
4003 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
4004 {
4005         int ret;
4006
4007         ret = parse_cmd_option(opt, val, fio_options, td, &td->opt_list);
4008         if (!ret) {
4009                 struct fio_option *o;
4010
4011                 o = find_option(fio_options, opt);
4012                 if (o)
4013                         fio_option_mark_set(&td->o, o);
4014         }
4015
4016         return ret;
4017 }
4018
4019 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
4020                                 char *val)
4021 {
4022         return parse_cmd_option(opt, val, td->io_ops->options, td->eo,
4023                                         &td->opt_list);
4024 }
4025
4026 void fio_fill_default_options(struct thread_data *td)
4027 {
4028         td->o.magic = OPT_MAGIC;
4029         fill_default_options(td, fio_options);
4030 }
4031
4032 int fio_show_option_help(const char *opt)
4033 {
4034         return show_cmd_help(fio_options, opt);
4035 }
4036
4037 void options_mem_dupe(void *data, struct fio_option *options)
4038 {
4039         struct fio_option *o;
4040         char **ptr;
4041
4042         for (o = &options[0]; o->name; o++) {
4043                 if (o->type != FIO_OPT_STR_STORE)
4044                         continue;
4045
4046                 ptr = td_var(data, o, o->off1);
4047                 if (*ptr)
4048                         *ptr = strdup(*ptr);
4049         }
4050 }
4051
4052 /*
4053  * dupe FIO_OPT_STR_STORE options
4054  */
4055 void fio_options_mem_dupe(struct thread_data *td)
4056 {
4057         options_mem_dupe(&td->o, fio_options);
4058
4059         if (td->eo && td->io_ops) {
4060                 void *oldeo = td->eo;
4061
4062                 td->eo = malloc(td->io_ops->option_struct_size);
4063                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
4064                 options_mem_dupe(td->eo, td->io_ops->options);
4065         }
4066 }
4067
4068 unsigned int fio_get_kb_base(void *data)
4069 {
4070         struct thread_options *o = data;
4071         unsigned int kb_base = 0;
4072
4073         /*
4074          * This is a hack... For private options, *data is not holding
4075          * a pointer to the thread_options, but to private data. This means
4076          * we can't safely dereference it, but magic is first so mem wise
4077          * it is valid. But this also means that if the job first sets
4078          * kb_base and expects that to be honored by private options,
4079          * it will be disappointed. We will return the global default
4080          * for this.
4081          */
4082         if (o && o->magic == OPT_MAGIC)
4083                 kb_base = o->kb_base;
4084         if (!kb_base)
4085                 kb_base = 1024;
4086
4087         return kb_base;
4088 }
4089
4090 int add_option(struct fio_option *o)
4091 {
4092         struct fio_option *__o;
4093         int opt_index = 0;
4094
4095         __o = fio_options;
4096         while (__o->name) {
4097                 opt_index++;
4098                 __o++;
4099         }
4100
4101         if (opt_index + 1 == FIO_MAX_OPTS) {
4102                 log_err("fio: FIO_MAX_OPTS is too small\n");
4103                 return 1;
4104         }
4105
4106         memcpy(&fio_options[opt_index], o, sizeof(*o));
4107         fio_options[opt_index + 1].name = NULL;
4108         return 0;
4109 }
4110
4111 void invalidate_profile_options(const char *prof_name)
4112 {
4113         struct fio_option *o;
4114
4115         o = fio_options;
4116         while (o->name) {
4117                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
4118                         o->type = FIO_OPT_INVALID;
4119                         o->prof_name = NULL;
4120                 }
4121                 o++;
4122         }
4123 }
4124
4125 void add_opt_posval(const char *optname, const char *ival, const char *help)
4126 {
4127         struct fio_option *o;
4128         unsigned int i;
4129
4130         o = find_option(fio_options, optname);
4131         if (!o)
4132                 return;
4133
4134         for (i = 0; i < PARSE_MAX_VP; i++) {
4135                 if (o->posval[i].ival)
4136                         continue;
4137
4138                 o->posval[i].ival = ival;
4139                 o->posval[i].help = help;
4140                 break;
4141         }
4142 }
4143
4144 void del_opt_posval(const char *optname, const char *ival)
4145 {
4146         struct fio_option *o;
4147         unsigned int i;
4148
4149         o = find_option(fio_options, optname);
4150         if (!o)
4151                 return;
4152
4153         for (i = 0; i < PARSE_MAX_VP; i++) {
4154                 if (!o->posval[i].ival)
4155                         continue;
4156                 if (strcmp(o->posval[i].ival, ival))
4157                         continue;
4158
4159                 o->posval[i].ival = NULL;
4160                 o->posval[i].help = NULL;
4161         }
4162 }
4163
4164 void fio_options_free(struct thread_data *td)
4165 {
4166         options_free(fio_options, td);
4167         if (td->eo && td->io_ops && td->io_ops->options) {
4168                 options_free(td->io_ops->options, td->eo);
4169                 free(td->eo);
4170                 td->eo = NULL;
4171         }
4172 }
4173
4174 struct fio_option *fio_option_find(const char *name)
4175 {
4176         return find_option(fio_options, name);
4177 }
4178
4179 static struct fio_option *find_next_opt(struct thread_options *o,
4180                                         struct fio_option *from,
4181                                         unsigned int off1)
4182 {
4183         struct fio_option *opt;
4184
4185         if (!from)
4186                 from = &fio_options[0];
4187         else
4188                 from++;
4189
4190         opt = NULL;
4191         do {
4192                 if (off1 == from->off1) {
4193                         opt = from;
4194                         break;
4195                 }
4196                 from++;
4197         } while (from->name);
4198
4199         return opt;
4200 }
4201
4202 static int opt_is_set(struct thread_options *o, struct fio_option *opt)
4203 {
4204         unsigned int opt_off, index, offset;
4205
4206         opt_off = opt - &fio_options[0];
4207         index = opt_off / (8 * sizeof(uint64_t));
4208         offset = opt_off & ((8 * sizeof(uint64_t)) - 1);
4209         return (o->set_options[index] & ((uint64_t)1 << offset)) != 0;
4210 }
4211
4212 bool __fio_option_is_set(struct thread_options *o, unsigned int off1)
4213 {
4214         struct fio_option *opt, *next;
4215
4216         next = NULL;
4217         while ((opt = find_next_opt(o, next, off1)) != NULL) {
4218                 if (opt_is_set(o, opt))
4219                         return true;
4220
4221                 next = opt;
4222         }
4223
4224         return false;
4225 }
4226
4227 void fio_option_mark_set(struct thread_options *o, struct fio_option *opt)
4228 {
4229         unsigned int opt_off, index, offset;
4230
4231         opt_off = opt - &fio_options[0];
4232         index = opt_off / (8 * sizeof(uint64_t));
4233         offset = opt_off & ((8 * sizeof(uint64_t)) - 1);
4234         o->set_options[index] |= (uint64_t)1 << offset;
4235 }