server: don't make SO_REUSEPORT errors fatal
[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_LIBAIO
1244                           { .ival = "libaio",
1245                             .help = "Linux native asynchronous IO",
1246                           },
1247 #endif
1248 #ifdef CONFIG_POSIXAIO
1249                           { .ival = "posixaio",
1250                             .help = "POSIX asynchronous IO",
1251                           },
1252 #endif
1253 #ifdef CONFIG_SOLARISAIO
1254                           { .ival = "solarisaio",
1255                             .help = "Solaris native asynchronous IO",
1256                           },
1257 #endif
1258 #ifdef CONFIG_WINDOWSAIO
1259                           { .ival = "windowsaio",
1260                             .help = "Windows native asynchronous IO"
1261                           },
1262 #endif
1263 #ifdef CONFIG_RBD
1264                           { .ival = "rbd",
1265                             .help = "Rados Block Device asynchronous IO"
1266                           },
1267 #endif
1268                           { .ival = "mmap",
1269                             .help = "Memory mapped IO"
1270                           },
1271 #ifdef CONFIG_LINUX_SPLICE
1272                           { .ival = "splice",
1273                             .help = "splice/vmsplice based IO",
1274                           },
1275                           { .ival = "netsplice",
1276                             .help = "splice/vmsplice to/from the network",
1277                           },
1278 #endif
1279 #ifdef FIO_HAVE_SGIO
1280                           { .ival = "sg",
1281                             .help = "SCSI generic v3 IO",
1282                           },
1283 #endif
1284                           { .ival = "null",
1285                             .help = "Testing engine (no data transfer)",
1286                           },
1287                           { .ival = "net",
1288                             .help = "Network IO",
1289                           },
1290                           { .ival = "cpuio",
1291                             .help = "CPU cycle burner engine",
1292                           },
1293 #ifdef CONFIG_GUASI
1294                           { .ival = "guasi",
1295                             .help = "GUASI IO engine",
1296                           },
1297 #endif
1298 #ifdef FIO_HAVE_BINJECT
1299                           { .ival = "binject",
1300                             .help = "binject direct inject block engine",
1301                           },
1302 #endif
1303 #ifdef CONFIG_RDMA
1304                           { .ival = "rdma",
1305                             .help = "RDMA IO engine",
1306                           },
1307 #endif
1308 #ifdef CONFIG_FUSION_AW
1309                           { .ival = "fusion-aw-sync",
1310                             .help = "Fusion-io atomic write engine",
1311                           },
1312 #endif
1313 #ifdef CONFIG_LINUX_EXT4_MOVE_EXTENT
1314                           { .ival = "e4defrag",
1315                             .help = "ext4 defrag engine",
1316                           },
1317 #endif
1318 #ifdef CONFIG_LINUX_FALLOCATE
1319                           { .ival = "falloc",
1320                             .help = "fallocate() file based engine",
1321                           },
1322 #endif
1323 #ifdef CONFIG_GFAPI
1324                           { .ival = "gfapi",
1325                             .help = "Glusterfs libgfapi(sync) based engine"
1326                           },
1327                           { .ival = "gfapi_async",
1328                             .help = "Glusterfs libgfapi(async) based engine"
1329                           },
1330 #endif
1331 #ifdef CONFIG_LIBHDFS
1332                           { .ival = "libhdfs",
1333                             .help = "Hadoop Distributed Filesystem (HDFS) engine"
1334                           },
1335 #endif
1336                           { .ival = "external",
1337                             .help = "Load external engine (append name)",
1338                           },
1339                 },
1340         },
1341         {
1342                 .name   = "iodepth",
1343                 .lname  = "IO Depth",
1344                 .type   = FIO_OPT_INT,
1345                 .off1   = td_var_offset(iodepth),
1346                 .help   = "Number of IO buffers to keep in flight",
1347                 .minval = 1,
1348                 .interval = 1,
1349                 .def    = "1",
1350                 .category = FIO_OPT_C_IO,
1351                 .group  = FIO_OPT_G_IO_BASIC,
1352         },
1353         {
1354                 .name   = "iodepth_batch",
1355                 .lname  = "IO Depth batch",
1356                 .alias  = "iodepth_batch_submit",
1357                 .type   = FIO_OPT_INT,
1358                 .off1   = td_var_offset(iodepth_batch),
1359                 .help   = "Number of IO buffers to submit in one go",
1360                 .parent = "iodepth",
1361                 .hide   = 1,
1362                 .minval = 1,
1363                 .interval = 1,
1364                 .def    = "1",
1365                 .category = FIO_OPT_C_IO,
1366                 .group  = FIO_OPT_G_IO_BASIC,
1367         },
1368         {
1369                 .name   = "iodepth_batch_complete_min",
1370                 .lname  = "Min IO depth batch complete",
1371                 .alias  = "iodepth_batch_complete",
1372                 .type   = FIO_OPT_INT,
1373                 .off1   = td_var_offset(iodepth_batch_complete_min),
1374                 .help   = "Min number of IO buffers to retrieve in one go",
1375                 .parent = "iodepth",
1376                 .hide   = 1,
1377                 .minval = 0,
1378                 .interval = 1,
1379                 .def    = "1",
1380                 .category = FIO_OPT_C_IO,
1381                 .group  = FIO_OPT_G_IO_BASIC,
1382         },
1383         {
1384                 .name   = "iodepth_batch_complete_max",
1385                 .lname  = "Max IO depth batch complete",
1386                 .type   = FIO_OPT_INT,
1387                 .off1   = td_var_offset(iodepth_batch_complete_max),
1388                 .help   = "Max number of IO buffers to retrieve in one go",
1389                 .parent = "iodepth",
1390                 .hide   = 1,
1391                 .minval = 0,
1392                 .interval = 1,
1393                 .category = FIO_OPT_C_IO,
1394                 .group  = FIO_OPT_G_IO_BASIC,
1395         },
1396         {
1397                 .name   = "iodepth_low",
1398                 .lname  = "IO Depth batch low",
1399                 .type   = FIO_OPT_INT,
1400                 .off1   = td_var_offset(iodepth_low),
1401                 .help   = "Low water mark for queuing depth",
1402                 .parent = "iodepth",
1403                 .hide   = 1,
1404                 .interval = 1,
1405                 .category = FIO_OPT_C_IO,
1406                 .group  = FIO_OPT_G_IO_BASIC,
1407         },
1408         {
1409                 .name   = "io_submit_mode",
1410                 .lname  = "IO submit mode",
1411                 .type   = FIO_OPT_STR,
1412                 .off1   = td_var_offset(io_submit_mode),
1413                 .help   = "How IO submissions and completions are done",
1414                 .def    = "inline",
1415                 .category = FIO_OPT_C_IO,
1416                 .group  = FIO_OPT_G_IO_BASIC,
1417                 .posval = {
1418                           { .ival = "inline",
1419                             .oval = IO_MODE_INLINE,
1420                             .help = "Submit and complete IO inline",
1421                           },
1422                           { .ival = "offload",
1423                             .oval = IO_MODE_OFFLOAD,
1424                             .help = "Offload submit and complete to threads",
1425                           },
1426                 },
1427         },
1428         {
1429                 .name   = "size",
1430                 .lname  = "Size",
1431                 .type   = FIO_OPT_STR_VAL,
1432                 .cb     = str_size_cb,
1433                 .off1   = td_var_offset(size),
1434                 .help   = "Total size of device or files",
1435                 .interval = 1024 * 1024,
1436                 .category = FIO_OPT_C_IO,
1437                 .group  = FIO_OPT_G_INVALID,
1438         },
1439         {
1440                 .name   = "io_size",
1441                 .alias  = "io_limit",
1442                 .lname  = "IO Size",
1443                 .type   = FIO_OPT_STR_VAL,
1444                 .off1   = td_var_offset(io_limit),
1445                 .interval = 1024 * 1024,
1446                 .category = FIO_OPT_C_IO,
1447                 .group  = FIO_OPT_G_INVALID,
1448         },
1449         {
1450                 .name   = "fill_device",
1451                 .lname  = "Fill device",
1452                 .alias  = "fill_fs",
1453                 .type   = FIO_OPT_BOOL,
1454                 .off1   = td_var_offset(fill_device),
1455                 .help   = "Write until an ENOSPC error occurs",
1456                 .def    = "0",
1457                 .category = FIO_OPT_C_FILE,
1458                 .group  = FIO_OPT_G_INVALID,
1459         },
1460         {
1461                 .name   = "filesize",
1462                 .lname  = "File size",
1463                 .type   = FIO_OPT_STR_VAL,
1464                 .off1   = td_var_offset(file_size_low),
1465                 .off2   = td_var_offset(file_size_high),
1466                 .minval = 1,
1467                 .help   = "Size of individual files",
1468                 .interval = 1024 * 1024,
1469                 .category = FIO_OPT_C_FILE,
1470                 .group  = FIO_OPT_G_INVALID,
1471         },
1472         {
1473                 .name   = "file_append",
1474                 .lname  = "File append",
1475                 .type   = FIO_OPT_BOOL,
1476                 .off1   = td_var_offset(file_append),
1477                 .help   = "IO will start at the end of the file(s)",
1478                 .def    = "0",
1479                 .category = FIO_OPT_C_FILE,
1480                 .group  = FIO_OPT_G_INVALID,
1481         },
1482         {
1483                 .name   = "offset",
1484                 .lname  = "IO offset",
1485                 .alias  = "fileoffset",
1486                 .type   = FIO_OPT_STR_VAL,
1487                 .off1   = td_var_offset(start_offset),
1488                 .help   = "Start IO from this offset",
1489                 .def    = "0",
1490                 .interval = 1024 * 1024,
1491                 .category = FIO_OPT_C_IO,
1492                 .group  = FIO_OPT_G_INVALID,
1493         },
1494         {
1495                 .name   = "offset_increment",
1496                 .lname  = "IO offset increment",
1497                 .type   = FIO_OPT_STR_VAL,
1498                 .off1   = td_var_offset(offset_increment),
1499                 .help   = "What is the increment from one offset to the next",
1500                 .parent = "offset",
1501                 .hide   = 1,
1502                 .def    = "0",
1503                 .interval = 1024 * 1024,
1504                 .category = FIO_OPT_C_IO,
1505                 .group  = FIO_OPT_G_INVALID,
1506         },
1507         {
1508                 .name   = "number_ios",
1509                 .lname  = "Number of IOs to perform",
1510                 .type   = FIO_OPT_STR_VAL,
1511                 .off1   = td_var_offset(number_ios),
1512                 .help   = "Force job completion after this number of IOs",
1513                 .def    = "0",
1514                 .category = FIO_OPT_C_IO,
1515                 .group  = FIO_OPT_G_INVALID,
1516         },
1517         {
1518                 .name   = "bs",
1519                 .lname  = "Block size",
1520                 .alias  = "blocksize",
1521                 .type   = FIO_OPT_INT,
1522                 .off1   = td_var_offset(bs[DDIR_READ]),
1523                 .off2   = td_var_offset(bs[DDIR_WRITE]),
1524                 .off3   = td_var_offset(bs[DDIR_TRIM]),
1525                 .minval = 1,
1526                 .help   = "Block size unit",
1527                 .def    = "4k",
1528                 .parent = "rw",
1529                 .hide   = 1,
1530                 .interval = 512,
1531                 .category = FIO_OPT_C_IO,
1532                 .group  = FIO_OPT_G_INVALID,
1533         },
1534         {
1535                 .name   = "ba",
1536                 .lname  = "Block size align",
1537                 .alias  = "blockalign",
1538                 .type   = FIO_OPT_INT,
1539                 .off1   = td_var_offset(ba[DDIR_READ]),
1540                 .off2   = td_var_offset(ba[DDIR_WRITE]),
1541                 .off3   = td_var_offset(ba[DDIR_TRIM]),
1542                 .minval = 1,
1543                 .help   = "IO block offset alignment",
1544                 .parent = "rw",
1545                 .hide   = 1,
1546                 .interval = 512,
1547                 .category = FIO_OPT_C_IO,
1548                 .group  = FIO_OPT_G_INVALID,
1549         },
1550         {
1551                 .name   = "bsrange",
1552                 .lname  = "Block size range",
1553                 .alias  = "blocksize_range",
1554                 .type   = FIO_OPT_RANGE,
1555                 .off1   = td_var_offset(min_bs[DDIR_READ]),
1556                 .off2   = td_var_offset(max_bs[DDIR_READ]),
1557                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
1558                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
1559                 .off5   = td_var_offset(min_bs[DDIR_TRIM]),
1560                 .off6   = td_var_offset(max_bs[DDIR_TRIM]),
1561                 .minval = 1,
1562                 .help   = "Set block size range (in more detail than bs)",
1563                 .parent = "rw",
1564                 .hide   = 1,
1565                 .interval = 4096,
1566                 .category = FIO_OPT_C_IO,
1567                 .group  = FIO_OPT_G_INVALID,
1568         },
1569         {
1570                 .name   = "bssplit",
1571                 .lname  = "Block size split",
1572                 .type   = FIO_OPT_STR,
1573                 .cb     = str_bssplit_cb,
1574                 .off1   = td_var_offset(bssplit),
1575                 .help   = "Set a specific mix of block sizes",
1576                 .parent = "rw",
1577                 .hide   = 1,
1578                 .category = FIO_OPT_C_IO,
1579                 .group  = FIO_OPT_G_INVALID,
1580         },
1581         {
1582                 .name   = "bs_unaligned",
1583                 .lname  = "Block size unaligned",
1584                 .alias  = "blocksize_unaligned",
1585                 .type   = FIO_OPT_STR_SET,
1586                 .off1   = td_var_offset(bs_unaligned),
1587                 .help   = "Don't sector align IO buffer sizes",
1588                 .parent = "rw",
1589                 .hide   = 1,
1590                 .category = FIO_OPT_C_IO,
1591                 .group  = FIO_OPT_G_INVALID,
1592         },
1593         {
1594                 .name   = "bs_is_seq_rand",
1595                 .lname  = "Block size division is seq/random (not read/write)",
1596                 .type   = FIO_OPT_BOOL,
1597                 .off1   = td_var_offset(bs_is_seq_rand),
1598                 .help   = "Consider any blocksize setting to be sequential,random",
1599                 .def    = "0",
1600                 .parent = "blocksize",
1601                 .category = FIO_OPT_C_IO,
1602                 .group  = FIO_OPT_G_INVALID,
1603         },
1604         {
1605                 .name   = "randrepeat",
1606                 .lname  = "Random repeatable",
1607                 .type   = FIO_OPT_BOOL,
1608                 .off1   = td_var_offset(rand_repeatable),
1609                 .help   = "Use repeatable random IO pattern",
1610                 .def    = "1",
1611                 .parent = "rw",
1612                 .hide   = 1,
1613                 .category = FIO_OPT_C_IO,
1614                 .group  = FIO_OPT_G_RANDOM,
1615         },
1616         {
1617                 .name   = "randseed",
1618                 .lname  = "The random generator seed",
1619                 .type   = FIO_OPT_STR_VAL,
1620                 .off1   = td_var_offset(rand_seed),
1621                 .help   = "Set the random generator seed value",
1622                 .def    = "0x89",
1623                 .parent = "rw",
1624                 .category = FIO_OPT_C_IO,
1625                 .group  = FIO_OPT_G_RANDOM,
1626         },
1627         {
1628                 .name   = "use_os_rand",
1629                 .lname  = "Use OS random",
1630                 .type   = FIO_OPT_DEPRECATED,
1631                 .off1   = td_var_offset(dep_use_os_rand),
1632                 .category = FIO_OPT_C_IO,
1633                 .group  = FIO_OPT_G_RANDOM,
1634         },
1635         {
1636                 .name   = "norandommap",
1637                 .lname  = "No randommap",
1638                 .type   = FIO_OPT_STR_SET,
1639                 .off1   = td_var_offset(norandommap),
1640                 .help   = "Accept potential duplicate random blocks",
1641                 .parent = "rw",
1642                 .hide   = 1,
1643                 .hide_on_set = 1,
1644                 .category = FIO_OPT_C_IO,
1645                 .group  = FIO_OPT_G_RANDOM,
1646         },
1647         {
1648                 .name   = "softrandommap",
1649                 .lname  = "Soft randommap",
1650                 .type   = FIO_OPT_BOOL,
1651                 .off1   = td_var_offset(softrandommap),
1652                 .help   = "Set norandommap if randommap allocation fails",
1653                 .parent = "norandommap",
1654                 .hide   = 1,
1655                 .def    = "0",
1656                 .category = FIO_OPT_C_IO,
1657                 .group  = FIO_OPT_G_RANDOM,
1658         },
1659         {
1660                 .name   = "random_generator",
1661                 .type   = FIO_OPT_STR,
1662                 .off1   = td_var_offset(random_generator),
1663                 .help   = "Type of random number generator to use",
1664                 .def    = "tausworthe",
1665                 .posval = {
1666                           { .ival = "tausworthe",
1667                             .oval = FIO_RAND_GEN_TAUSWORTHE,
1668                             .help = "Strong Tausworthe generator",
1669                           },
1670                           { .ival = "lfsr",
1671                             .oval = FIO_RAND_GEN_LFSR,
1672                             .help = "Variable length LFSR",
1673                           },
1674                           {
1675                             .ival = "tausworthe64",
1676                             .oval = FIO_RAND_GEN_TAUSWORTHE64,
1677                             .help = "64-bit Tausworthe variant",
1678                           },
1679                 },
1680                 .category = FIO_OPT_C_IO,
1681                 .group  = FIO_OPT_G_RANDOM,
1682         },
1683         {
1684                 .name   = "random_distribution",
1685                 .type   = FIO_OPT_STR,
1686                 .off1   = td_var_offset(random_distribution),
1687                 .cb     = str_random_distribution_cb,
1688                 .help   = "Random offset distribution generator",
1689                 .def    = "random",
1690                 .posval = {
1691                           { .ival = "random",
1692                             .oval = FIO_RAND_DIST_RANDOM,
1693                             .help = "Completely random",
1694                           },
1695                           { .ival = "zipf",
1696                             .oval = FIO_RAND_DIST_ZIPF,
1697                             .help = "Zipf distribution",
1698                           },
1699                           { .ival = "pareto",
1700                             .oval = FIO_RAND_DIST_PARETO,
1701                             .help = "Pareto distribution",
1702                           },
1703                           { .ival = "normal",
1704                             .oval = FIO_RAND_DIST_GAUSS,
1705                             .help = "Normal (gaussian) distribution",
1706                           },
1707                 },
1708                 .category = FIO_OPT_C_IO,
1709                 .group  = FIO_OPT_G_RANDOM,
1710         },
1711         {
1712                 .name   = "percentage_random",
1713                 .lname  = "Percentage Random",
1714                 .type   = FIO_OPT_INT,
1715                 .off1   = td_var_offset(perc_rand[DDIR_READ]),
1716                 .off2   = td_var_offset(perc_rand[DDIR_WRITE]),
1717                 .off3   = td_var_offset(perc_rand[DDIR_TRIM]),
1718                 .maxval = 100,
1719                 .help   = "Percentage of seq/random mix that should be random",
1720                 .def    = "100,100,100",
1721                 .interval = 5,
1722                 .inverse = "percentage_sequential",
1723                 .category = FIO_OPT_C_IO,
1724                 .group  = FIO_OPT_G_RANDOM,
1725         },
1726         {
1727                 .name   = "percentage_sequential",
1728                 .lname  = "Percentage Sequential",
1729                 .type   = FIO_OPT_DEPRECATED,
1730                 .category = FIO_OPT_C_IO,
1731                 .group  = FIO_OPT_G_RANDOM,
1732         },
1733         {
1734                 .name   = "allrandrepeat",
1735                 .type   = FIO_OPT_BOOL,
1736                 .off1   = td_var_offset(allrand_repeatable),
1737                 .help   = "Use repeatable random numbers for everything",
1738                 .def    = "0",
1739                 .category = FIO_OPT_C_IO,
1740                 .group  = FIO_OPT_G_RANDOM,
1741         },
1742         {
1743                 .name   = "nrfiles",
1744                 .lname  = "Number of files",
1745                 .alias  = "nr_files",
1746                 .type   = FIO_OPT_INT,
1747                 .off1   = td_var_offset(nr_files),
1748                 .help   = "Split job workload between this number of files",
1749                 .def    = "1",
1750                 .interval = 1,
1751                 .category = FIO_OPT_C_FILE,
1752                 .group  = FIO_OPT_G_INVALID,
1753         },
1754         {
1755                 .name   = "openfiles",
1756                 .lname  = "Number of open files",
1757                 .type   = FIO_OPT_INT,
1758                 .off1   = td_var_offset(open_files),
1759                 .help   = "Number of files to keep open at the same time",
1760                 .category = FIO_OPT_C_FILE,
1761                 .group  = FIO_OPT_G_INVALID,
1762         },
1763         {
1764                 .name   = "file_service_type",
1765                 .lname  = "File service type",
1766                 .type   = FIO_OPT_STR,
1767                 .cb     = str_fst_cb,
1768                 .off1   = td_var_offset(file_service_type),
1769                 .help   = "How to select which file to service next",
1770                 .def    = "roundrobin",
1771                 .category = FIO_OPT_C_FILE,
1772                 .group  = FIO_OPT_G_INVALID,
1773                 .posval = {
1774                           { .ival = "random",
1775                             .oval = FIO_FSERVICE_RANDOM,
1776                             .help = "Choose a file at random",
1777                           },
1778                           { .ival = "roundrobin",
1779                             .oval = FIO_FSERVICE_RR,
1780                             .help = "Round robin select files",
1781                           },
1782                           { .ival = "sequential",
1783                             .oval = FIO_FSERVICE_SEQ,
1784                             .help = "Finish one file before moving to the next",
1785                           },
1786                 },
1787                 .parent = "nrfiles",
1788                 .hide   = 1,
1789         },
1790 #ifdef CONFIG_POSIX_FALLOCATE
1791         {
1792                 .name   = "fallocate",
1793                 .lname  = "Fallocate",
1794                 .type   = FIO_OPT_STR,
1795                 .off1   = td_var_offset(fallocate_mode),
1796                 .help   = "Whether pre-allocation is performed when laying out files",
1797                 .def    = "posix",
1798                 .category = FIO_OPT_C_FILE,
1799                 .group  = FIO_OPT_G_INVALID,
1800                 .posval = {
1801                           { .ival = "none",
1802                             .oval = FIO_FALLOCATE_NONE,
1803                             .help = "Do not pre-allocate space",
1804                           },
1805                           { .ival = "posix",
1806                             .oval = FIO_FALLOCATE_POSIX,
1807                             .help = "Use posix_fallocate()",
1808                           },
1809 #ifdef CONFIG_LINUX_FALLOCATE
1810                           { .ival = "keep",
1811                             .oval = FIO_FALLOCATE_KEEP_SIZE,
1812                             .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1813                           },
1814 #endif
1815                           /* Compatibility with former boolean values */
1816                           { .ival = "0",
1817                             .oval = FIO_FALLOCATE_NONE,
1818                             .help = "Alias for 'none'",
1819                           },
1820                           { .ival = "1",
1821                             .oval = FIO_FALLOCATE_POSIX,
1822                             .help = "Alias for 'posix'",
1823                           },
1824                 },
1825         },
1826 #endif  /* CONFIG_POSIX_FALLOCATE */
1827         {
1828                 .name   = "fadvise_hint",
1829                 .lname  = "Fadvise hint",
1830                 .type   = FIO_OPT_BOOL,
1831                 .off1   = td_var_offset(fadvise_hint),
1832                 .help   = "Use fadvise() to advise the kernel on IO pattern",
1833                 .def    = "1",
1834                 .category = FIO_OPT_C_FILE,
1835                 .group  = FIO_OPT_G_INVALID,
1836         },
1837 #ifdef FIO_HAVE_STREAMID
1838         {
1839                 .name   = "fadvise_stream",
1840                 .lname  = "Fadvise stream",
1841                 .type   = FIO_OPT_INT,
1842                 .off1   = td_var_offset(fadvise_stream),
1843                 .help   = "Use fadvise() to set stream ID",
1844                 .category = FIO_OPT_C_FILE,
1845                 .group  = FIO_OPT_G_INVALID,
1846         },
1847 #endif
1848         {
1849                 .name   = "fsync",
1850                 .lname  = "Fsync",
1851                 .type   = FIO_OPT_INT,
1852                 .off1   = td_var_offset(fsync_blocks),
1853                 .help   = "Issue fsync for writes every given number of blocks",
1854                 .def    = "0",
1855                 .interval = 1,
1856                 .category = FIO_OPT_C_FILE,
1857                 .group  = FIO_OPT_G_INVALID,
1858         },
1859         {
1860                 .name   = "fdatasync",
1861                 .lname  = "Fdatasync",
1862                 .type   = FIO_OPT_INT,
1863                 .off1   = td_var_offset(fdatasync_blocks),
1864                 .help   = "Issue fdatasync for writes every given number of blocks",
1865                 .def    = "0",
1866                 .interval = 1,
1867                 .category = FIO_OPT_C_FILE,
1868                 .group  = FIO_OPT_G_INVALID,
1869         },
1870         {
1871                 .name   = "write_barrier",
1872                 .lname  = "Write barrier",
1873                 .type   = FIO_OPT_INT,
1874                 .off1   = td_var_offset(barrier_blocks),
1875                 .help   = "Make every Nth write a barrier write",
1876                 .def    = "0",
1877                 .interval = 1,
1878                 .category = FIO_OPT_C_IO,
1879                 .group  = FIO_OPT_G_INVALID,
1880         },
1881 #ifdef CONFIG_SYNC_FILE_RANGE
1882         {
1883                 .name   = "sync_file_range",
1884                 .lname  = "Sync file range",
1885                 .posval = {
1886                           { .ival = "wait_before",
1887                             .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1888                             .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1889                             .orval  = 1,
1890                           },
1891                           { .ival = "write",
1892                             .oval = SYNC_FILE_RANGE_WRITE,
1893                             .help = "SYNC_FILE_RANGE_WRITE",
1894                             .orval  = 1,
1895                           },
1896                           {
1897                             .ival = "wait_after",
1898                             .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1899                             .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1900                             .orval  = 1,
1901                           },
1902                 },
1903                 .type   = FIO_OPT_STR_MULTI,
1904                 .cb     = str_sfr_cb,
1905                 .off1   = td_var_offset(sync_file_range),
1906                 .help   = "Use sync_file_range()",
1907                 .category = FIO_OPT_C_FILE,
1908                 .group  = FIO_OPT_G_INVALID,
1909         },
1910 #endif
1911         {
1912                 .name   = "direct",
1913                 .lname  = "Direct I/O",
1914                 .type   = FIO_OPT_BOOL,
1915                 .off1   = td_var_offset(odirect),
1916                 .help   = "Use O_DIRECT IO (negates buffered)",
1917                 .def    = "0",
1918                 .inverse = "buffered",
1919                 .category = FIO_OPT_C_IO,
1920                 .group  = FIO_OPT_G_IO_TYPE,
1921         },
1922         {
1923                 .name   = "atomic",
1924                 .lname  = "Atomic I/O",
1925                 .type   = FIO_OPT_BOOL,
1926                 .off1   = td_var_offset(oatomic),
1927                 .help   = "Use Atomic IO with O_DIRECT (implies O_DIRECT)",
1928                 .def    = "0",
1929                 .category = FIO_OPT_C_IO,
1930                 .group  = FIO_OPT_G_IO_TYPE,
1931         },
1932         {
1933                 .name   = "buffered",
1934                 .lname  = "Buffered I/O",
1935                 .type   = FIO_OPT_BOOL,
1936                 .off1   = td_var_offset(odirect),
1937                 .neg    = 1,
1938                 .help   = "Use buffered IO (negates direct)",
1939                 .def    = "1",
1940                 .inverse = "direct",
1941                 .category = FIO_OPT_C_IO,
1942                 .group  = FIO_OPT_G_IO_TYPE,
1943         },
1944         {
1945                 .name   = "overwrite",
1946                 .lname  = "Overwrite",
1947                 .type   = FIO_OPT_BOOL,
1948                 .off1   = td_var_offset(overwrite),
1949                 .help   = "When writing, set whether to overwrite current data",
1950                 .def    = "0",
1951                 .category = FIO_OPT_C_FILE,
1952                 .group  = FIO_OPT_G_INVALID,
1953         },
1954         {
1955                 .name   = "loops",
1956                 .lname  = "Loops",
1957                 .type   = FIO_OPT_INT,
1958                 .off1   = td_var_offset(loops),
1959                 .help   = "Number of times to run the job",
1960                 .def    = "1",
1961                 .interval = 1,
1962                 .category = FIO_OPT_C_GENERAL,
1963                 .group  = FIO_OPT_G_RUNTIME,
1964         },
1965         {
1966                 .name   = "numjobs",
1967                 .lname  = "Number of jobs",
1968                 .type   = FIO_OPT_INT,
1969                 .off1   = td_var_offset(numjobs),
1970                 .help   = "Duplicate this job this many times",
1971                 .def    = "1",
1972                 .interval = 1,
1973                 .category = FIO_OPT_C_GENERAL,
1974                 .group  = FIO_OPT_G_RUNTIME,
1975         },
1976         {
1977                 .name   = "startdelay",
1978                 .lname  = "Start delay",
1979                 .type   = FIO_OPT_STR_VAL_TIME,
1980                 .off1   = td_var_offset(start_delay),
1981                 .off2   = td_var_offset(start_delay_high),
1982                 .help   = "Only start job when this period has passed",
1983                 .def    = "0",
1984                 .is_seconds = 1,
1985                 .is_time = 1,
1986                 .category = FIO_OPT_C_GENERAL,
1987                 .group  = FIO_OPT_G_RUNTIME,
1988         },
1989         {
1990                 .name   = "runtime",
1991                 .lname  = "Runtime",
1992                 .alias  = "timeout",
1993                 .type   = FIO_OPT_STR_VAL_TIME,
1994                 .off1   = td_var_offset(timeout),
1995                 .help   = "Stop workload when this amount of time has passed",
1996                 .def    = "0",
1997                 .is_seconds = 1,
1998                 .is_time = 1,
1999                 .category = FIO_OPT_C_GENERAL,
2000                 .group  = FIO_OPT_G_RUNTIME,
2001         },
2002         {
2003                 .name   = "time_based",
2004                 .lname  = "Time based",
2005                 .type   = FIO_OPT_STR_SET,
2006                 .off1   = td_var_offset(time_based),
2007                 .help   = "Keep running until runtime/timeout is met",
2008                 .category = FIO_OPT_C_GENERAL,
2009                 .group  = FIO_OPT_G_RUNTIME,
2010         },
2011         {
2012                 .name   = "verify_only",
2013                 .lname  = "Verify only",
2014                 .type   = FIO_OPT_STR_SET,
2015                 .off1   = td_var_offset(verify_only),
2016                 .help   = "Verifies previously written data is still valid",
2017                 .category = FIO_OPT_C_GENERAL,
2018                 .group  = FIO_OPT_G_RUNTIME,
2019         },
2020         {
2021                 .name   = "ramp_time",
2022                 .lname  = "Ramp time",
2023                 .type   = FIO_OPT_STR_VAL_TIME,
2024                 .off1   = td_var_offset(ramp_time),
2025                 .help   = "Ramp up time before measuring performance",
2026                 .is_seconds = 1,
2027                 .is_time = 1,
2028                 .category = FIO_OPT_C_GENERAL,
2029                 .group  = FIO_OPT_G_RUNTIME,
2030         },
2031         {
2032                 .name   = "clocksource",
2033                 .lname  = "Clock source",
2034                 .type   = FIO_OPT_STR,
2035                 .cb     = fio_clock_source_cb,
2036                 .off1   = td_var_offset(clocksource),
2037                 .help   = "What type of timing source to use",
2038                 .category = FIO_OPT_C_GENERAL,
2039                 .group  = FIO_OPT_G_CLOCK,
2040                 .posval = {
2041 #ifdef CONFIG_GETTIMEOFDAY
2042                           { .ival = "gettimeofday",
2043                             .oval = CS_GTOD,
2044                             .help = "Use gettimeofday(2) for timing",
2045                           },
2046 #endif
2047 #ifdef CONFIG_CLOCK_GETTIME
2048                           { .ival = "clock_gettime",
2049                             .oval = CS_CGETTIME,
2050                             .help = "Use clock_gettime(2) for timing",
2051                           },
2052 #endif
2053 #ifdef ARCH_HAVE_CPU_CLOCK
2054                           { .ival = "cpu",
2055                             .oval = CS_CPUCLOCK,
2056                             .help = "Use CPU private clock",
2057                           },
2058 #endif
2059                 },
2060         },
2061         {
2062                 .name   = "mem",
2063                 .alias  = "iomem",
2064                 .lname  = "I/O Memory",
2065                 .type   = FIO_OPT_STR,
2066                 .cb     = str_mem_cb,
2067                 .off1   = td_var_offset(mem_type),
2068                 .help   = "Backing type for IO buffers",
2069                 .def    = "malloc",
2070                 .category = FIO_OPT_C_IO,
2071                 .group  = FIO_OPT_G_INVALID,
2072                 .posval = {
2073                           { .ival = "malloc",
2074                             .oval = MEM_MALLOC,
2075                             .help = "Use malloc(3) for IO buffers",
2076                           },
2077 #ifndef CONFIG_NO_SHM
2078                           { .ival = "shm",
2079                             .oval = MEM_SHM,
2080                             .help = "Use shared memory segments for IO buffers",
2081                           },
2082 #ifdef FIO_HAVE_HUGETLB
2083                           { .ival = "shmhuge",
2084                             .oval = MEM_SHMHUGE,
2085                             .help = "Like shm, but use huge pages",
2086                           },
2087 #endif
2088 #endif
2089                           { .ival = "mmap",
2090                             .oval = MEM_MMAP,
2091                             .help = "Use mmap(2) (file or anon) for IO buffers",
2092                           },
2093                           { .ival = "mmapshared",
2094                             .oval = MEM_MMAPSHARED,
2095                             .help = "Like mmap, but use the shared flag",
2096                           },
2097 #ifdef FIO_HAVE_HUGETLB
2098                           { .ival = "mmaphuge",
2099                             .oval = MEM_MMAPHUGE,
2100                             .help = "Like mmap, but use huge pages",
2101                           },
2102 #endif
2103                   },
2104         },
2105         {
2106                 .name   = "iomem_align",
2107                 .alias  = "mem_align",
2108                 .lname  = "I/O memory alignment",
2109                 .type   = FIO_OPT_INT,
2110                 .off1   = td_var_offset(mem_align),
2111                 .minval = 0,
2112                 .help   = "IO memory buffer offset alignment",
2113                 .def    = "0",
2114                 .parent = "iomem",
2115                 .hide   = 1,
2116                 .category = FIO_OPT_C_IO,
2117                 .group  = FIO_OPT_G_INVALID,
2118         },
2119         {
2120                 .name   = "verify",
2121                 .lname  = "Verify",
2122                 .type   = FIO_OPT_STR,
2123                 .off1   = td_var_offset(verify),
2124                 .help   = "Verify data written",
2125                 .def    = "0",
2126                 .category = FIO_OPT_C_IO,
2127                 .group  = FIO_OPT_G_VERIFY,
2128                 .posval = {
2129                           { .ival = "0",
2130                             .oval = VERIFY_NONE,
2131                             .help = "Don't do IO verification",
2132                           },
2133                           { .ival = "md5",
2134                             .oval = VERIFY_MD5,
2135                             .help = "Use md5 checksums for verification",
2136                           },
2137                           { .ival = "crc64",
2138                             .oval = VERIFY_CRC64,
2139                             .help = "Use crc64 checksums for verification",
2140                           },
2141                           { .ival = "crc32",
2142                             .oval = VERIFY_CRC32,
2143                             .help = "Use crc32 checksums for verification",
2144                           },
2145                           { .ival = "crc32c-intel",
2146                             .oval = VERIFY_CRC32C,
2147                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
2148                           },
2149                           { .ival = "crc32c",
2150                             .oval = VERIFY_CRC32C,
2151                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
2152                           },
2153                           { .ival = "crc16",
2154                             .oval = VERIFY_CRC16,
2155                             .help = "Use crc16 checksums for verification",
2156                           },
2157                           { .ival = "crc7",
2158                             .oval = VERIFY_CRC7,
2159                             .help = "Use crc7 checksums for verification",
2160                           },
2161                           { .ival = "sha1",
2162                             .oval = VERIFY_SHA1,
2163                             .help = "Use sha1 checksums for verification",
2164                           },
2165                           { .ival = "sha256",
2166                             .oval = VERIFY_SHA256,
2167                             .help = "Use sha256 checksums for verification",
2168                           },
2169                           { .ival = "sha512",
2170                             .oval = VERIFY_SHA512,
2171                             .help = "Use sha512 checksums for verification",
2172                           },
2173                           { .ival = "xxhash",
2174                             .oval = VERIFY_XXHASH,
2175                             .help = "Use xxhash checksums for verification",
2176                           },
2177                           /* Meta information was included into verify_header,
2178                            * 'meta' verification is implied by default. */
2179                           { .ival = "meta",
2180                             .oval = VERIFY_HDR_ONLY,
2181                             .help = "Use io information for verification. "
2182                                     "Now is implied by default, thus option is obsolete, "
2183                                     "don't use it",
2184                           },
2185                           { .ival = "pattern",
2186                             .oval = VERIFY_PATTERN_NO_HDR,
2187                             .help = "Verify strict pattern",
2188                           },
2189                           {
2190                             .ival = "null",
2191                             .oval = VERIFY_NULL,
2192                             .help = "Pretend to verify",
2193                           },
2194                 },
2195         },
2196         {
2197                 .name   = "do_verify",
2198                 .lname  = "Perform verify step",
2199                 .type   = FIO_OPT_BOOL,
2200                 .off1   = td_var_offset(do_verify),
2201                 .help   = "Run verification stage after write",
2202                 .def    = "1",
2203                 .parent = "verify",
2204                 .hide   = 1,
2205                 .category = FIO_OPT_C_IO,
2206                 .group  = FIO_OPT_G_VERIFY,
2207         },
2208         {
2209                 .name   = "verifysort",
2210                 .lname  = "Verify sort",
2211                 .type   = FIO_OPT_BOOL,
2212                 .off1   = td_var_offset(verifysort),
2213                 .help   = "Sort written verify blocks for read back",
2214                 .def    = "1",
2215                 .parent = "verify",
2216                 .hide   = 1,
2217                 .category = FIO_OPT_C_IO,
2218                 .group  = FIO_OPT_G_VERIFY,
2219         },
2220         {
2221                 .name   = "verifysort_nr",
2222                 .type   = FIO_OPT_INT,
2223                 .off1   = td_var_offset(verifysort_nr),
2224                 .help   = "Pre-load and sort verify blocks for a read workload",
2225                 .minval = 0,
2226                 .maxval = 131072,
2227                 .def    = "1024",
2228                 .parent = "verify",
2229                 .category = FIO_OPT_C_IO,
2230                 .group  = FIO_OPT_G_VERIFY,
2231         },
2232         {
2233                 .name   = "verify_interval",
2234                 .lname  = "Verify interval",
2235                 .type   = FIO_OPT_INT,
2236                 .off1   = td_var_offset(verify_interval),
2237                 .minval = 2 * sizeof(struct verify_header),
2238                 .help   = "Store verify buffer header every N bytes",
2239                 .parent = "verify",
2240                 .hide   = 1,
2241                 .interval = 2 * sizeof(struct verify_header),
2242                 .category = FIO_OPT_C_IO,
2243                 .group  = FIO_OPT_G_VERIFY,
2244         },
2245         {
2246                 .name   = "verify_offset",
2247                 .lname  = "Verify offset",
2248                 .type   = FIO_OPT_INT,
2249                 .help   = "Offset verify header location by N bytes",
2250                 .off1   = td_var_offset(verify_offset),
2251                 .minval = sizeof(struct verify_header),
2252                 .parent = "verify",
2253                 .hide   = 1,
2254                 .category = FIO_OPT_C_IO,
2255                 .group  = FIO_OPT_G_VERIFY,
2256         },
2257         {
2258                 .name   = "verify_pattern",
2259                 .lname  = "Verify pattern",
2260                 .type   = FIO_OPT_STR,
2261                 .cb     = str_verify_pattern_cb,
2262                 .off1   = td_var_offset(verify_pattern),
2263                 .help   = "Fill pattern for IO buffers",
2264                 .parent = "verify",
2265                 .hide   = 1,
2266                 .category = FIO_OPT_C_IO,
2267                 .group  = FIO_OPT_G_VERIFY,
2268         },
2269         {
2270                 .name   = "verify_fatal",
2271                 .lname  = "Verify fatal",
2272                 .type   = FIO_OPT_BOOL,
2273                 .off1   = td_var_offset(verify_fatal),
2274                 .def    = "0",
2275                 .help   = "Exit on a single verify failure, don't continue",
2276                 .parent = "verify",
2277                 .hide   = 1,
2278                 .category = FIO_OPT_C_IO,
2279                 .group  = FIO_OPT_G_VERIFY,
2280         },
2281         {
2282                 .name   = "verify_dump",
2283                 .lname  = "Verify dump",
2284                 .type   = FIO_OPT_BOOL,
2285                 .off1   = td_var_offset(verify_dump),
2286                 .def    = "0",
2287                 .help   = "Dump contents of good and bad blocks on failure",
2288                 .parent = "verify",
2289                 .hide   = 1,
2290                 .category = FIO_OPT_C_IO,
2291                 .group  = FIO_OPT_G_VERIFY,
2292         },
2293         {
2294                 .name   = "verify_async",
2295                 .lname  = "Verify asynchronously",
2296                 .type   = FIO_OPT_INT,
2297                 .off1   = td_var_offset(verify_async),
2298                 .def    = "0",
2299                 .help   = "Number of async verifier threads to use",
2300                 .parent = "verify",
2301                 .hide   = 1,
2302                 .category = FIO_OPT_C_IO,
2303                 .group  = FIO_OPT_G_VERIFY,
2304         },
2305         {
2306                 .name   = "verify_backlog",
2307                 .lname  = "Verify backlog",
2308                 .type   = FIO_OPT_STR_VAL,
2309                 .off1   = td_var_offset(verify_backlog),
2310                 .help   = "Verify after this number of blocks are written",
2311                 .parent = "verify",
2312                 .hide   = 1,
2313                 .category = FIO_OPT_C_IO,
2314                 .group  = FIO_OPT_G_VERIFY,
2315         },
2316         {
2317                 .name   = "verify_backlog_batch",
2318                 .lname  = "Verify backlog batch",
2319                 .type   = FIO_OPT_INT,
2320                 .off1   = td_var_offset(verify_batch),
2321                 .help   = "Verify this number of IO blocks",
2322                 .parent = "verify",
2323                 .hide   = 1,
2324                 .category = FIO_OPT_C_IO,
2325                 .group  = FIO_OPT_G_VERIFY,
2326         },
2327 #ifdef FIO_HAVE_CPU_AFFINITY
2328         {
2329                 .name   = "verify_async_cpus",
2330                 .lname  = "Async verify CPUs",
2331                 .type   = FIO_OPT_STR,
2332                 .cb     = str_verify_cpus_allowed_cb,
2333                 .off1   = td_var_offset(verify_cpumask),
2334                 .help   = "Set CPUs allowed for async verify threads",
2335                 .parent = "verify_async",
2336                 .hide   = 1,
2337                 .category = FIO_OPT_C_IO,
2338                 .group  = FIO_OPT_G_VERIFY,
2339         },
2340 #endif
2341         {
2342                 .name   = "experimental_verify",
2343                 .off1   = td_var_offset(experimental_verify),
2344                 .type   = FIO_OPT_BOOL,
2345                 .help   = "Enable experimental verification",
2346                 .parent = "verify",
2347                 .category = FIO_OPT_C_IO,
2348                 .group  = FIO_OPT_G_VERIFY,
2349         },
2350         {
2351                 .name   = "verify_state_load",
2352                 .lname  = "Load verify state",
2353                 .off1   = td_var_offset(verify_state),
2354                 .type   = FIO_OPT_BOOL,
2355                 .help   = "Load verify termination state",
2356                 .parent = "verify",
2357                 .category = FIO_OPT_C_IO,
2358                 .group  = FIO_OPT_G_VERIFY,
2359         },
2360         {
2361                 .name   = "verify_state_save",
2362                 .lname  = "Save verify state",
2363                 .off1   = td_var_offset(verify_state_save),
2364                 .type   = FIO_OPT_BOOL,
2365                 .def    = "1",
2366                 .help   = "Save verify state on termination",
2367                 .parent = "verify",
2368                 .category = FIO_OPT_C_IO,
2369                 .group  = FIO_OPT_G_VERIFY,
2370         },
2371 #ifdef FIO_HAVE_TRIM
2372         {
2373                 .name   = "trim_percentage",
2374                 .lname  = "Trim percentage",
2375                 .type   = FIO_OPT_INT,
2376                 .off1   = td_var_offset(trim_percentage),
2377                 .minval = 0,
2378                 .maxval = 100,
2379                 .help   = "Number of verify blocks to discard/trim",
2380                 .parent = "verify",
2381                 .def    = "0",
2382                 .interval = 1,
2383                 .hide   = 1,
2384                 .category = FIO_OPT_C_IO,
2385                 .group  = FIO_OPT_G_TRIM,
2386         },
2387         {
2388                 .name   = "trim_verify_zero",
2389                 .lname  = "Verify trim zero",
2390                 .type   = FIO_OPT_BOOL,
2391                 .help   = "Verify that trim/discarded blocks are returned as zeroes",
2392                 .off1   = td_var_offset(trim_zero),
2393                 .parent = "trim_percentage",
2394                 .hide   = 1,
2395                 .def    = "1",
2396                 .category = FIO_OPT_C_IO,
2397                 .group  = FIO_OPT_G_TRIM,
2398         },
2399         {
2400                 .name   = "trim_backlog",
2401                 .lname  = "Trim backlog",
2402                 .type   = FIO_OPT_STR_VAL,
2403                 .off1   = td_var_offset(trim_backlog),
2404                 .help   = "Trim after this number of blocks are written",
2405                 .parent = "trim_percentage",
2406                 .hide   = 1,
2407                 .interval = 1,
2408                 .category = FIO_OPT_C_IO,
2409                 .group  = FIO_OPT_G_TRIM,
2410         },
2411         {
2412                 .name   = "trim_backlog_batch",
2413                 .lname  = "Trim backlog batch",
2414                 .type   = FIO_OPT_INT,
2415                 .off1   = td_var_offset(trim_batch),
2416                 .help   = "Trim this number of IO blocks",
2417                 .parent = "trim_percentage",
2418                 .hide   = 1,
2419                 .interval = 1,
2420                 .category = FIO_OPT_C_IO,
2421                 .group  = FIO_OPT_G_TRIM,
2422         },
2423 #endif
2424         {
2425                 .name   = "write_iolog",
2426                 .lname  = "Write I/O log",
2427                 .type   = FIO_OPT_STR_STORE,
2428                 .off1   = td_var_offset(write_iolog_file),
2429                 .help   = "Store IO pattern to file",
2430                 .category = FIO_OPT_C_IO,
2431                 .group  = FIO_OPT_G_IOLOG,
2432         },
2433         {
2434                 .name   = "read_iolog",
2435                 .lname  = "Read I/O log",
2436                 .type   = FIO_OPT_STR_STORE,
2437                 .off1   = td_var_offset(read_iolog_file),
2438                 .help   = "Playback IO pattern from file",
2439                 .category = FIO_OPT_C_IO,
2440                 .group  = FIO_OPT_G_IOLOG,
2441         },
2442         {
2443                 .name   = "replay_no_stall",
2444                 .lname  = "Don't stall on replay",
2445                 .type   = FIO_OPT_BOOL,
2446                 .off1   = td_var_offset(no_stall),
2447                 .def    = "0",
2448                 .parent = "read_iolog",
2449                 .hide   = 1,
2450                 .help   = "Playback IO pattern file as fast as possible without stalls",
2451                 .category = FIO_OPT_C_IO,
2452                 .group  = FIO_OPT_G_IOLOG,
2453         },
2454         {
2455                 .name   = "replay_redirect",
2456                 .lname  = "Redirect device for replay",
2457                 .type   = FIO_OPT_STR_STORE,
2458                 .off1   = td_var_offset(replay_redirect),
2459                 .parent = "read_iolog",
2460                 .hide   = 1,
2461                 .help   = "Replay all I/O onto this device, regardless of trace device",
2462                 .category = FIO_OPT_C_IO,
2463                 .group  = FIO_OPT_G_IOLOG,
2464         },
2465         {
2466                 .name   = "replay_scale",
2467                 .lname  = "Replace offset scale factor",
2468                 .type   = FIO_OPT_INT,
2469                 .off1   = td_var_offset(replay_scale),
2470                 .parent = "read_iolog",
2471                 .def    = "1",
2472                 .help   = "Align offsets to this blocksize",
2473                 .category = FIO_OPT_C_IO,
2474                 .group  = FIO_OPT_G_IOLOG,
2475         },
2476         {
2477                 .name   = "replay_align",
2478                 .lname  = "Replace alignment",
2479                 .type   = FIO_OPT_INT,
2480                 .off1   = td_var_offset(replay_align),
2481                 .parent = "read_iolog",
2482                 .help   = "Scale offset down by this factor",
2483                 .category = FIO_OPT_C_IO,
2484                 .group  = FIO_OPT_G_IOLOG,
2485                 .pow2   = 1,
2486         },
2487         {
2488                 .name   = "exec_prerun",
2489                 .lname  = "Pre-execute runnable",
2490                 .type   = FIO_OPT_STR_STORE,
2491                 .off1   = td_var_offset(exec_prerun),
2492                 .help   = "Execute this file prior to running job",
2493                 .category = FIO_OPT_C_GENERAL,
2494                 .group  = FIO_OPT_G_INVALID,
2495         },
2496         {
2497                 .name   = "exec_postrun",
2498                 .lname  = "Post-execute runnable",
2499                 .type   = FIO_OPT_STR_STORE,
2500                 .off1   = td_var_offset(exec_postrun),
2501                 .help   = "Execute this file after running job",
2502                 .category = FIO_OPT_C_GENERAL,
2503                 .group  = FIO_OPT_G_INVALID,
2504         },
2505 #ifdef FIO_HAVE_IOSCHED_SWITCH
2506         {
2507                 .name   = "ioscheduler",
2508                 .lname  = "I/O scheduler",
2509                 .type   = FIO_OPT_STR_STORE,
2510                 .off1   = td_var_offset(ioscheduler),
2511                 .help   = "Use this IO scheduler on the backing device",
2512                 .category = FIO_OPT_C_FILE,
2513                 .group  = FIO_OPT_G_INVALID,
2514         },
2515 #endif
2516         {
2517                 .name   = "zonesize",
2518                 .lname  = "Zone size",
2519                 .type   = FIO_OPT_STR_VAL,
2520                 .off1   = td_var_offset(zone_size),
2521                 .help   = "Amount of data to read per zone",
2522                 .def    = "0",
2523                 .interval = 1024 * 1024,
2524                 .category = FIO_OPT_C_IO,
2525                 .group  = FIO_OPT_G_ZONE,
2526         },
2527         {
2528                 .name   = "zonerange",
2529                 .lname  = "Zone range",
2530                 .type   = FIO_OPT_STR_VAL,
2531                 .off1   = td_var_offset(zone_range),
2532                 .help   = "Give size of an IO zone",
2533                 .def    = "0",
2534                 .interval = 1024 * 1024,
2535                 .category = FIO_OPT_C_IO,
2536                 .group  = FIO_OPT_G_ZONE,
2537         },
2538         {
2539                 .name   = "zoneskip",
2540                 .lname  = "Zone skip",
2541                 .type   = FIO_OPT_STR_VAL,
2542                 .off1   = td_var_offset(zone_skip),
2543                 .help   = "Space between IO zones",
2544                 .def    = "0",
2545                 .interval = 1024 * 1024,
2546                 .category = FIO_OPT_C_IO,
2547                 .group  = FIO_OPT_G_ZONE,
2548         },
2549         {
2550                 .name   = "lockmem",
2551                 .lname  = "Lock memory",
2552                 .type   = FIO_OPT_STR_VAL,
2553                 .off1   = td_var_offset(lockmem),
2554                 .help   = "Lock down this amount of memory (per worker)",
2555                 .def    = "0",
2556                 .interval = 1024 * 1024,
2557                 .category = FIO_OPT_C_GENERAL,
2558                 .group  = FIO_OPT_G_INVALID,
2559         },
2560         {
2561                 .name   = "rwmixread",
2562                 .lname  = "Read/write mix read",
2563                 .type   = FIO_OPT_INT,
2564                 .cb     = str_rwmix_read_cb,
2565                 .off1   = td_var_offset(rwmix[DDIR_READ]),
2566                 .maxval = 100,
2567                 .help   = "Percentage of mixed workload that is reads",
2568                 .def    = "50",
2569                 .interval = 5,
2570                 .inverse = "rwmixwrite",
2571                 .category = FIO_OPT_C_IO,
2572                 .group  = FIO_OPT_G_RWMIX,
2573         },
2574         {
2575                 .name   = "rwmixwrite",
2576                 .lname  = "Read/write mix write",
2577                 .type   = FIO_OPT_INT,
2578                 .cb     = str_rwmix_write_cb,
2579                 .off1   = td_var_offset(rwmix[DDIR_WRITE]),
2580                 .maxval = 100,
2581                 .help   = "Percentage of mixed workload that is writes",
2582                 .def    = "50",
2583                 .interval = 5,
2584                 .inverse = "rwmixread",
2585                 .category = FIO_OPT_C_IO,
2586                 .group  = FIO_OPT_G_RWMIX,
2587         },
2588         {
2589                 .name   = "rwmixcycle",
2590                 .lname  = "Read/write mix cycle",
2591                 .type   = FIO_OPT_DEPRECATED,
2592                 .category = FIO_OPT_C_IO,
2593                 .group  = FIO_OPT_G_RWMIX,
2594         },
2595         {
2596                 .name   = "nice",
2597                 .lname  = "Nice",
2598                 .type   = FIO_OPT_INT,
2599                 .off1   = td_var_offset(nice),
2600                 .help   = "Set job CPU nice value",
2601                 .minval = -19,
2602                 .maxval = 20,
2603                 .def    = "0",
2604                 .interval = 1,
2605                 .category = FIO_OPT_C_GENERAL,
2606                 .group  = FIO_OPT_G_CRED,
2607         },
2608 #ifdef FIO_HAVE_IOPRIO
2609         {
2610                 .name   = "prio",
2611                 .lname  = "I/O nice priority",
2612                 .type   = FIO_OPT_INT,
2613                 .off1   = td_var_offset(ioprio),
2614                 .help   = "Set job IO priority value",
2615                 .minval = 0,
2616                 .maxval = 7,
2617                 .interval = 1,
2618                 .category = FIO_OPT_C_GENERAL,
2619                 .group  = FIO_OPT_G_CRED,
2620         },
2621         {
2622                 .name   = "prioclass",
2623                 .lname  = "I/O nice priority class",
2624                 .type   = FIO_OPT_INT,
2625                 .off1   = td_var_offset(ioprio_class),
2626                 .help   = "Set job IO priority class",
2627                 .minval = 0,
2628                 .maxval = 3,
2629                 .interval = 1,
2630                 .category = FIO_OPT_C_GENERAL,
2631                 .group  = FIO_OPT_G_CRED,
2632         },
2633 #endif
2634         {
2635                 .name   = "thinktime",
2636                 .lname  = "Thinktime",
2637                 .type   = FIO_OPT_INT,
2638                 .off1   = td_var_offset(thinktime),
2639                 .help   = "Idle time between IO buffers (usec)",
2640                 .def    = "0",
2641                 .is_time = 1,
2642                 .category = FIO_OPT_C_IO,
2643                 .group  = FIO_OPT_G_THINKTIME,
2644         },
2645         {
2646                 .name   = "thinktime_spin",
2647                 .lname  = "Thinktime spin",
2648                 .type   = FIO_OPT_INT,
2649                 .off1   = td_var_offset(thinktime_spin),
2650                 .help   = "Start think time by spinning this amount (usec)",
2651                 .def    = "0",
2652                 .is_time = 1,
2653                 .parent = "thinktime",
2654                 .hide   = 1,
2655                 .category = FIO_OPT_C_IO,
2656                 .group  = FIO_OPT_G_THINKTIME,
2657         },
2658         {
2659                 .name   = "thinktime_blocks",
2660                 .lname  = "Thinktime blocks",
2661                 .type   = FIO_OPT_INT,
2662                 .off1   = td_var_offset(thinktime_blocks),
2663                 .help   = "IO buffer period between 'thinktime'",
2664                 .def    = "1",
2665                 .parent = "thinktime",
2666                 .hide   = 1,
2667                 .category = FIO_OPT_C_IO,
2668                 .group  = FIO_OPT_G_THINKTIME,
2669         },
2670         {
2671                 .name   = "rate",
2672                 .lname  = "I/O rate",
2673                 .type   = FIO_OPT_INT,
2674                 .off1   = td_var_offset(rate[DDIR_READ]),
2675                 .off2   = td_var_offset(rate[DDIR_WRITE]),
2676                 .off3   = td_var_offset(rate[DDIR_TRIM]),
2677                 .help   = "Set bandwidth rate",
2678                 .category = FIO_OPT_C_IO,
2679                 .group  = FIO_OPT_G_RATE,
2680         },
2681         {
2682                 .name   = "rate_min",
2683                 .alias  = "ratemin",
2684                 .lname  = "I/O min rate",
2685                 .type   = FIO_OPT_INT,
2686                 .off1   = td_var_offset(ratemin[DDIR_READ]),
2687                 .off2   = td_var_offset(ratemin[DDIR_WRITE]),
2688                 .off3   = td_var_offset(ratemin[DDIR_TRIM]),
2689                 .help   = "Job must meet this rate or it will be shutdown",
2690                 .parent = "rate",
2691                 .hide   = 1,
2692                 .category = FIO_OPT_C_IO,
2693                 .group  = FIO_OPT_G_RATE,
2694         },
2695         {
2696                 .name   = "rate_iops",
2697                 .lname  = "I/O rate IOPS",
2698                 .type   = FIO_OPT_INT,
2699                 .off1   = td_var_offset(rate_iops[DDIR_READ]),
2700                 .off2   = td_var_offset(rate_iops[DDIR_WRITE]),
2701                 .off3   = td_var_offset(rate_iops[DDIR_TRIM]),
2702                 .help   = "Limit IO used to this number of IO operations/sec",
2703                 .hide   = 1,
2704                 .category = FIO_OPT_C_IO,
2705                 .group  = FIO_OPT_G_RATE,
2706         },
2707         {
2708                 .name   = "rate_iops_min",
2709                 .lname  = "I/O min rate IOPS",
2710                 .type   = FIO_OPT_INT,
2711                 .off1   = td_var_offset(rate_iops_min[DDIR_READ]),
2712                 .off2   = td_var_offset(rate_iops_min[DDIR_WRITE]),
2713                 .off3   = td_var_offset(rate_iops_min[DDIR_TRIM]),
2714                 .help   = "Job must meet this rate or it will be shut down",
2715                 .parent = "rate_iops",
2716                 .hide   = 1,
2717                 .category = FIO_OPT_C_IO,
2718                 .group  = FIO_OPT_G_RATE,
2719         },
2720         {
2721                 .name   = "rate_process",
2722                 .lname  = "Rate Process",
2723                 .type   = FIO_OPT_STR,
2724                 .off1   = td_var_offset(rate_process),
2725                 .help   = "What process controls how rated IO is managed",
2726                 .def    = "linear",
2727                 .category = FIO_OPT_C_IO,
2728                 .group  = FIO_OPT_G_RATE,
2729                 .posval = {
2730                           { .ival = "linear",
2731                             .oval = RATE_PROCESS_LINEAR,
2732                             .help = "Linear rate of IO",
2733                           },
2734                           {
2735                             .ival = "poisson",
2736                             .oval = RATE_PROCESS_POISSON,
2737                             .help = "Rate follows Poisson process",
2738                           },
2739                 },
2740                 .parent = "rate",
2741         },
2742         {
2743                 .name   = "rate_cycle",
2744                 .alias  = "ratecycle",
2745                 .lname  = "I/O rate cycle",
2746                 .type   = FIO_OPT_INT,
2747                 .off1   = td_var_offset(ratecycle),
2748                 .help   = "Window average for rate limits (msec)",
2749                 .def    = "1000",
2750                 .parent = "rate",
2751                 .hide   = 1,
2752                 .category = FIO_OPT_C_IO,
2753                 .group  = FIO_OPT_G_RATE,
2754         },
2755         {
2756                 .name   = "max_latency",
2757                 .type   = FIO_OPT_INT,
2758                 .off1   = td_var_offset(max_latency),
2759                 .help   = "Maximum tolerated IO latency (usec)",
2760                 .is_time = 1,
2761                 .category = FIO_OPT_C_IO,
2762                 .group = FIO_OPT_G_LATPROF,
2763         },
2764         {
2765                 .name   = "latency_target",
2766                 .lname  = "Latency Target (usec)",
2767                 .type   = FIO_OPT_STR_VAL_TIME,
2768                 .off1   = td_var_offset(latency_target),
2769                 .help   = "Ramp to max queue depth supporting this latency",
2770                 .is_time = 1,
2771                 .category = FIO_OPT_C_IO,
2772                 .group  = FIO_OPT_G_LATPROF,
2773         },
2774         {
2775                 .name   = "latency_window",
2776                 .lname  = "Latency Window (usec)",
2777                 .type   = FIO_OPT_STR_VAL_TIME,
2778                 .off1   = td_var_offset(latency_window),
2779                 .help   = "Time to sustain latency_target",
2780                 .is_time = 1,
2781                 .category = FIO_OPT_C_IO,
2782                 .group  = FIO_OPT_G_LATPROF,
2783         },
2784         {
2785                 .name   = "latency_percentile",
2786                 .lname  = "Latency Percentile",
2787                 .type   = FIO_OPT_FLOAT_LIST,
2788                 .off1   = td_var_offset(latency_percentile),
2789                 .help   = "Percentile of IOs must be below latency_target",
2790                 .def    = "100",
2791                 .maxlen = 1,
2792                 .minfp  = 0.0,
2793                 .maxfp  = 100.0,
2794                 .category = FIO_OPT_C_IO,
2795                 .group  = FIO_OPT_G_LATPROF,
2796         },
2797         {
2798                 .name   = "invalidate",
2799                 .lname  = "Cache invalidate",
2800                 .type   = FIO_OPT_BOOL,
2801                 .off1   = td_var_offset(invalidate_cache),
2802                 .help   = "Invalidate buffer/page cache prior to running job",
2803                 .def    = "1",
2804                 .category = FIO_OPT_C_IO,
2805                 .group  = FIO_OPT_G_IO_TYPE,
2806         },
2807         {
2808                 .name   = "sync",
2809                 .lname  = "Synchronous I/O",
2810                 .type   = FIO_OPT_BOOL,
2811                 .off1   = td_var_offset(sync_io),
2812                 .help   = "Use O_SYNC for buffered writes",
2813                 .def    = "0",
2814                 .parent = "buffered",
2815                 .hide   = 1,
2816                 .category = FIO_OPT_C_IO,
2817                 .group  = FIO_OPT_G_IO_TYPE,
2818         },
2819         {
2820                 .name   = "create_serialize",
2821                 .lname  = "Create serialize",
2822                 .type   = FIO_OPT_BOOL,
2823                 .off1   = td_var_offset(create_serialize),
2824                 .help   = "Serialize creating of job files",
2825                 .def    = "1",
2826                 .category = FIO_OPT_C_FILE,
2827                 .group  = FIO_OPT_G_INVALID,
2828         },
2829         {
2830                 .name   = "create_fsync",
2831                 .lname  = "Create fsync",
2832                 .type   = FIO_OPT_BOOL,
2833                 .off1   = td_var_offset(create_fsync),
2834                 .help   = "fsync file after creation",
2835                 .def    = "1",
2836                 .category = FIO_OPT_C_FILE,
2837                 .group  = FIO_OPT_G_INVALID,
2838         },
2839         {
2840                 .name   = "create_on_open",
2841                 .lname  = "Create on open",
2842                 .type   = FIO_OPT_BOOL,
2843                 .off1   = td_var_offset(create_on_open),
2844                 .help   = "Create files when they are opened for IO",
2845                 .def    = "0",
2846                 .category = FIO_OPT_C_FILE,
2847                 .group  = FIO_OPT_G_INVALID,
2848         },
2849         {
2850                 .name   = "create_only",
2851                 .type   = FIO_OPT_BOOL,
2852                 .off1   = td_var_offset(create_only),
2853                 .help   = "Only perform file creation phase",
2854                 .category = FIO_OPT_C_FILE,
2855                 .def    = "0",
2856         },
2857         {
2858                 .name   = "allow_file_create",
2859                 .lname  = "Allow file create",
2860                 .type   = FIO_OPT_BOOL,
2861                 .off1   = td_var_offset(allow_create),
2862                 .help   = "Permit fio to create files, if they don't exist",
2863                 .def    = "1",
2864                 .category = FIO_OPT_C_FILE,
2865                 .group  = FIO_OPT_G_FILENAME,
2866         },
2867         {
2868                 .name   = "allow_mounted_write",
2869                 .lname  = "Allow mounted write",
2870                 .type   = FIO_OPT_BOOL,
2871                 .off1   = td_var_offset(allow_mounted_write),
2872                 .help   = "Allow writes to a mounted partition",
2873                 .def    = "0",
2874                 .category = FIO_OPT_C_FILE,
2875                 .group  = FIO_OPT_G_FILENAME,
2876         },
2877         {
2878                 .name   = "pre_read",
2879                 .lname  = "Pre-read files",
2880                 .type   = FIO_OPT_BOOL,
2881                 .off1   = td_var_offset(pre_read),
2882                 .help   = "Pre-read files before starting official testing",
2883                 .def    = "0",
2884                 .category = FIO_OPT_C_FILE,
2885                 .group  = FIO_OPT_G_INVALID,
2886         },
2887 #ifdef FIO_HAVE_CPU_AFFINITY
2888         {
2889                 .name   = "cpumask",
2890                 .lname  = "CPU mask",
2891                 .type   = FIO_OPT_INT,
2892                 .cb     = str_cpumask_cb,
2893                 .off1   = td_var_offset(cpumask),
2894                 .help   = "CPU affinity mask",
2895                 .category = FIO_OPT_C_GENERAL,
2896                 .group  = FIO_OPT_G_CRED,
2897         },
2898         {
2899                 .name   = "cpus_allowed",
2900                 .lname  = "CPUs allowed",
2901                 .type   = FIO_OPT_STR,
2902                 .cb     = str_cpus_allowed_cb,
2903                 .off1   = td_var_offset(cpumask),
2904                 .help   = "Set CPUs allowed",
2905                 .category = FIO_OPT_C_GENERAL,
2906                 .group  = FIO_OPT_G_CRED,
2907         },
2908         {
2909                 .name   = "cpus_allowed_policy",
2910                 .lname  = "CPUs allowed distribution policy",
2911                 .type   = FIO_OPT_STR,
2912                 .off1   = td_var_offset(cpus_allowed_policy),
2913                 .help   = "Distribution policy for cpus_allowed",
2914                 .parent = "cpus_allowed",
2915                 .prio   = 1,
2916                 .posval = {
2917                           { .ival = "shared",
2918                             .oval = FIO_CPUS_SHARED,
2919                             .help = "Mask shared between threads",
2920                           },
2921                           { .ival = "split",
2922                             .oval = FIO_CPUS_SPLIT,
2923                             .help = "Mask split between threads",
2924                           },
2925                 },
2926                 .category = FIO_OPT_C_GENERAL,
2927                 .group  = FIO_OPT_G_CRED,
2928         },
2929 #endif
2930 #ifdef CONFIG_LIBNUMA
2931         {
2932                 .name   = "numa_cpu_nodes",
2933                 .type   = FIO_OPT_STR,
2934                 .cb     = str_numa_cpunodes_cb,
2935                 .off1   = td_var_offset(numa_cpunodes),
2936                 .help   = "NUMA CPU nodes bind",
2937                 .category = FIO_OPT_C_GENERAL,
2938                 .group  = FIO_OPT_G_INVALID,
2939         },
2940         {
2941                 .name   = "numa_mem_policy",
2942                 .type   = FIO_OPT_STR,
2943                 .cb     = str_numa_mpol_cb,
2944                 .off1   = td_var_offset(numa_memnodes),
2945                 .help   = "NUMA memory policy setup",
2946                 .category = FIO_OPT_C_GENERAL,
2947                 .group  = FIO_OPT_G_INVALID,
2948         },
2949 #endif
2950         {
2951                 .name   = "end_fsync",
2952                 .lname  = "End fsync",
2953                 .type   = FIO_OPT_BOOL,
2954                 .off1   = td_var_offset(end_fsync),
2955                 .help   = "Include fsync at the end of job",
2956                 .def    = "0",
2957                 .category = FIO_OPT_C_FILE,
2958                 .group  = FIO_OPT_G_INVALID,
2959         },
2960         {
2961                 .name   = "fsync_on_close",
2962                 .lname  = "Fsync on close",
2963                 .type   = FIO_OPT_BOOL,
2964                 .off1   = td_var_offset(fsync_on_close),
2965                 .help   = "fsync files on close",
2966                 .def    = "0",
2967                 .category = FIO_OPT_C_FILE,
2968                 .group  = FIO_OPT_G_INVALID,
2969         },
2970         {
2971                 .name   = "unlink",
2972                 .lname  = "Unlink file",
2973                 .type   = FIO_OPT_BOOL,
2974                 .off1   = td_var_offset(unlink),
2975                 .help   = "Unlink created files after job has completed",
2976                 .def    = "0",
2977                 .category = FIO_OPT_C_FILE,
2978                 .group  = FIO_OPT_G_INVALID,
2979         },
2980         {
2981                 .name   = "exitall",
2982                 .lname  = "Exit-all on terminate",
2983                 .type   = FIO_OPT_STR_SET,
2984                 .cb     = str_exitall_cb,
2985                 .help   = "Terminate all jobs when one exits",
2986                 .category = FIO_OPT_C_GENERAL,
2987                 .group  = FIO_OPT_G_PROCESS,
2988         },
2989         {
2990                 .name   = "exitall_on_error",
2991                 .lname  = "Exit-all on terminate in error",
2992                 .type   = FIO_OPT_BOOL,
2993                 .off1   = td_var_offset(unlink),
2994                 .help   = "Terminate all jobs when one exits in error",
2995                 .category = FIO_OPT_C_GENERAL,
2996                 .group  = FIO_OPT_G_PROCESS,
2997         },
2998         {
2999                 .name   = "stonewall",
3000                 .lname  = "Wait for previous",
3001                 .alias  = "wait_for_previous",
3002                 .type   = FIO_OPT_STR_SET,
3003                 .off1   = td_var_offset(stonewall),
3004                 .help   = "Insert a hard barrier between this job and previous",
3005                 .category = FIO_OPT_C_GENERAL,
3006                 .group  = FIO_OPT_G_PROCESS,
3007         },
3008         {
3009                 .name   = "new_group",
3010                 .lname  = "New group",
3011                 .type   = FIO_OPT_STR_SET,
3012                 .off1   = td_var_offset(new_group),
3013                 .help   = "Mark the start of a new group (for reporting)",
3014                 .category = FIO_OPT_C_GENERAL,
3015                 .group  = FIO_OPT_G_PROCESS,
3016         },
3017         {
3018                 .name   = "thread",
3019                 .lname  = "Thread",
3020                 .type   = FIO_OPT_STR_SET,
3021                 .off1   = td_var_offset(use_thread),
3022                 .help   = "Use threads instead of processes",
3023 #ifdef CONFIG_NO_SHM
3024                 .def    = "1",
3025                 .no_warn_def = 1,
3026 #endif
3027                 .category = FIO_OPT_C_GENERAL,
3028                 .group  = FIO_OPT_G_PROCESS,
3029         },
3030         {
3031                 .name   = "per_job_logs",
3032                 .type   = FIO_OPT_BOOL,
3033                 .off1   = td_var_offset(per_job_logs),
3034                 .help   = "Include job number in generated log files or not",
3035                 .def    = "1",
3036                 .category = FIO_OPT_C_LOG,
3037                 .group  = FIO_OPT_G_INVALID,
3038         },
3039         {
3040                 .name   = "write_bw_log",
3041                 .lname  = "Write bandwidth log",
3042                 .type   = FIO_OPT_STR_STORE,
3043                 .off1   = td_var_offset(bw_log_file),
3044                 .help   = "Write log of bandwidth during run",
3045                 .category = FIO_OPT_C_LOG,
3046                 .group  = FIO_OPT_G_INVALID,
3047         },
3048         {
3049                 .name   = "write_lat_log",
3050                 .lname  = "Write latency log",
3051                 .type   = FIO_OPT_STR_STORE,
3052                 .off1   = td_var_offset(lat_log_file),
3053                 .help   = "Write log of latency during run",
3054                 .category = FIO_OPT_C_LOG,
3055                 .group  = FIO_OPT_G_INVALID,
3056         },
3057         {
3058                 .name   = "write_iops_log",
3059                 .lname  = "Write IOPS log",
3060                 .type   = FIO_OPT_STR_STORE,
3061                 .off1   = td_var_offset(iops_log_file),
3062                 .help   = "Write log of IOPS during run",
3063                 .category = FIO_OPT_C_LOG,
3064                 .group  = FIO_OPT_G_INVALID,
3065         },
3066         {
3067                 .name   = "log_avg_msec",
3068                 .lname  = "Log averaging (msec)",
3069                 .type   = FIO_OPT_INT,
3070                 .off1   = td_var_offset(log_avg_msec),
3071                 .help   = "Average bw/iops/lat logs over this period of time",
3072                 .def    = "0",
3073                 .category = FIO_OPT_C_LOG,
3074                 .group  = FIO_OPT_G_INVALID,
3075         },
3076         {
3077                 .name   = "log_max_value",
3078                 .lname  = "Log maximum instead of average",
3079                 .type   = FIO_OPT_BOOL,
3080                 .off1   = td_var_offset(log_max),
3081                 .help   = "Log max sample in a window instead of average",
3082                 .def    = "0",
3083                 .category = FIO_OPT_C_LOG,
3084                 .group  = FIO_OPT_G_INVALID,
3085         },
3086         {
3087                 .name   = "log_offset",
3088                 .lname  = "Log offset of IO",
3089                 .type   = FIO_OPT_BOOL,
3090                 .off1   = td_var_offset(log_offset),
3091                 .help   = "Include offset of IO for each log entry",
3092                 .def    = "0",
3093                 .category = FIO_OPT_C_LOG,
3094                 .group  = FIO_OPT_G_INVALID,
3095         },
3096 #ifdef CONFIG_ZLIB
3097         {
3098                 .name   = "log_compression",
3099                 .lname  = "Log compression",
3100                 .type   = FIO_OPT_INT,
3101                 .off1   = td_var_offset(log_gz),
3102                 .help   = "Log in compressed chunks of this size",
3103                 .minval = 1024ULL,
3104                 .maxval = 512 * 1024 * 1024ULL,
3105                 .category = FIO_OPT_C_LOG,
3106                 .group  = FIO_OPT_G_INVALID,
3107         },
3108 #ifdef FIO_HAVE_CPU_AFFINITY
3109         {
3110                 .name   = "log_compression_cpus",
3111                 .lname  = "Log Compression CPUs",
3112                 .type   = FIO_OPT_STR,
3113                 .cb     = str_log_cpus_allowed_cb,
3114                 .off1   = td_var_offset(log_gz_cpumask),
3115                 .parent = "log_compression",
3116                 .help   = "Limit log compression to these CPUs",
3117                 .category = FIO_OPT_C_LOG,
3118                 .group  = FIO_OPT_G_INVALID,
3119         },
3120 #endif
3121         {
3122                 .name   = "log_store_compressed",
3123                 .lname  = "Log store compressed",
3124                 .type   = FIO_OPT_BOOL,
3125                 .off1   = td_var_offset(log_gz_store),
3126                 .help   = "Store logs in a compressed format",
3127                 .category = FIO_OPT_C_LOG,
3128                 .group  = FIO_OPT_G_INVALID,
3129         },
3130 #endif
3131         {
3132                 .name   = "block_error_percentiles",
3133                 .lname  = "Block error percentiles",
3134                 .type   = FIO_OPT_BOOL,
3135                 .off1   = td_var_offset(block_error_hist),
3136                 .help   = "Record trim block errors and make a histogram",
3137                 .def    = "0",
3138                 .category = FIO_OPT_C_LOG,
3139                 .group  = FIO_OPT_G_INVALID,
3140         },
3141         {
3142                 .name   = "bwavgtime",
3143                 .lname  = "Bandwidth average time",
3144                 .type   = FIO_OPT_INT,
3145                 .off1   = td_var_offset(bw_avg_time),
3146                 .help   = "Time window over which to calculate bandwidth"
3147                           " (msec)",
3148                 .def    = "500",
3149                 .parent = "write_bw_log",
3150                 .hide   = 1,
3151                 .interval = 100,
3152                 .category = FIO_OPT_C_LOG,
3153                 .group  = FIO_OPT_G_INVALID,
3154         },
3155         {
3156                 .name   = "iopsavgtime",
3157                 .lname  = "IOPS average time",
3158                 .type   = FIO_OPT_INT,
3159                 .off1   = td_var_offset(iops_avg_time),
3160                 .help   = "Time window over which to calculate IOPS (msec)",
3161                 .def    = "500",
3162                 .parent = "write_iops_log",
3163                 .hide   = 1,
3164                 .interval = 100,
3165                 .category = FIO_OPT_C_LOG,
3166                 .group  = FIO_OPT_G_INVALID,
3167         },
3168         {
3169                 .name   = "group_reporting",
3170                 .lname  = "Group reporting",
3171                 .type   = FIO_OPT_STR_SET,
3172                 .off1   = td_var_offset(group_reporting),
3173                 .help   = "Do reporting on a per-group basis",
3174                 .category = FIO_OPT_C_STAT,
3175                 .group  = FIO_OPT_G_INVALID,
3176         },
3177         {
3178                 .name   = "zero_buffers",
3179                 .lname  = "Zero I/O buffers",
3180                 .type   = FIO_OPT_STR_SET,
3181                 .off1   = td_var_offset(zero_buffers),
3182                 .help   = "Init IO buffers to all zeroes",
3183                 .category = FIO_OPT_C_IO,
3184                 .group  = FIO_OPT_G_IO_BUF,
3185         },
3186         {
3187                 .name   = "refill_buffers",
3188                 .lname  = "Refill I/O buffers",
3189                 .type   = FIO_OPT_STR_SET,
3190                 .off1   = td_var_offset(refill_buffers),
3191                 .help   = "Refill IO buffers on every IO submit",
3192                 .category = FIO_OPT_C_IO,
3193                 .group  = FIO_OPT_G_IO_BUF,
3194         },
3195         {
3196                 .name   = "scramble_buffers",
3197                 .lname  = "Scramble I/O buffers",
3198                 .type   = FIO_OPT_BOOL,
3199                 .off1   = td_var_offset(scramble_buffers),
3200                 .help   = "Slightly scramble buffers on every IO submit",
3201                 .def    = "1",
3202                 .category = FIO_OPT_C_IO,
3203                 .group  = FIO_OPT_G_IO_BUF,
3204         },
3205         {
3206                 .name   = "buffer_pattern",
3207                 .lname  = "Buffer pattern",
3208                 .type   = FIO_OPT_STR,
3209                 .cb     = str_buffer_pattern_cb,
3210                 .off1   = td_var_offset(buffer_pattern),
3211                 .help   = "Fill pattern for IO buffers",
3212                 .category = FIO_OPT_C_IO,
3213                 .group  = FIO_OPT_G_IO_BUF,
3214         },
3215         {
3216                 .name   = "buffer_compress_percentage",
3217                 .lname  = "Buffer compression percentage",
3218                 .type   = FIO_OPT_INT,
3219                 .cb     = str_buffer_compress_cb,
3220                 .off1   = td_var_offset(compress_percentage),
3221                 .maxval = 100,
3222                 .minval = 0,
3223                 .help   = "How compressible the buffer is (approximately)",
3224                 .interval = 5,
3225                 .category = FIO_OPT_C_IO,
3226                 .group  = FIO_OPT_G_IO_BUF,
3227         },
3228         {
3229                 .name   = "buffer_compress_chunk",
3230                 .lname  = "Buffer compression chunk size",
3231                 .type   = FIO_OPT_INT,
3232                 .off1   = td_var_offset(compress_chunk),
3233                 .parent = "buffer_compress_percentage",
3234                 .hide   = 1,
3235                 .help   = "Size of compressible region in buffer",
3236                 .interval = 256,
3237                 .category = FIO_OPT_C_IO,
3238                 .group  = FIO_OPT_G_IO_BUF,
3239         },
3240         {
3241                 .name   = "dedupe_percentage",
3242                 .lname  = "Dedupe percentage",
3243                 .type   = FIO_OPT_INT,
3244                 .cb     = str_dedupe_cb,
3245                 .off1   = td_var_offset(dedupe_percentage),
3246                 .maxval = 100,
3247                 .minval = 0,
3248                 .help   = "Percentage of buffers that are dedupable",
3249                 .interval = 1,
3250                 .category = FIO_OPT_C_IO,
3251                 .group  = FIO_OPT_G_IO_BUF,
3252         },
3253         {
3254                 .name   = "clat_percentiles",
3255                 .lname  = "Completion latency percentiles",
3256                 .type   = FIO_OPT_BOOL,
3257                 .off1   = td_var_offset(clat_percentiles),
3258                 .help   = "Enable the reporting of completion latency percentiles",
3259                 .def    = "1",
3260                 .category = FIO_OPT_C_STAT,
3261                 .group  = FIO_OPT_G_INVALID,
3262         },
3263         {
3264                 .name   = "percentile_list",
3265                 .lname  = "Percentile list",
3266                 .type   = FIO_OPT_FLOAT_LIST,
3267                 .off1   = td_var_offset(percentile_list),
3268                 .off2   = td_var_offset(percentile_precision),
3269                 .help   = "Specify a custom list of percentiles to report for "
3270                           "completion latency and block errors",
3271                 .def    = "1:5:10:20:30:40:50:60:70:80:90:95:99:99.5:99.9:99.95:99.99",
3272                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
3273                 .minfp  = 0.0,
3274                 .maxfp  = 100.0,
3275                 .category = FIO_OPT_C_STAT,
3276                 .group  = FIO_OPT_G_INVALID,
3277         },
3278
3279 #ifdef FIO_HAVE_DISK_UTIL
3280         {
3281                 .name   = "disk_util",
3282                 .lname  = "Disk utilization",
3283                 .type   = FIO_OPT_BOOL,
3284                 .off1   = td_var_offset(do_disk_util),
3285                 .help   = "Log disk utilization statistics",
3286                 .def    = "1",
3287                 .category = FIO_OPT_C_STAT,
3288                 .group  = FIO_OPT_G_INVALID,
3289         },
3290 #endif
3291         {
3292                 .name   = "gtod_reduce",
3293                 .lname  = "Reduce gettimeofday() calls",
3294                 .type   = FIO_OPT_BOOL,
3295                 .help   = "Greatly reduce number of gettimeofday() calls",
3296                 .cb     = str_gtod_reduce_cb,
3297                 .def    = "0",
3298                 .hide_on_set = 1,
3299                 .category = FIO_OPT_C_STAT,
3300                 .group  = FIO_OPT_G_INVALID,
3301         },
3302         {
3303                 .name   = "disable_lat",
3304                 .lname  = "Disable all latency stats",
3305                 .type   = FIO_OPT_BOOL,
3306                 .off1   = td_var_offset(disable_lat),
3307                 .help   = "Disable latency numbers",
3308                 .parent = "gtod_reduce",
3309                 .hide   = 1,
3310                 .def    = "0",
3311                 .category = FIO_OPT_C_STAT,
3312                 .group  = FIO_OPT_G_INVALID,
3313         },
3314         {
3315                 .name   = "disable_clat",
3316                 .lname  = "Disable completion latency stats",
3317                 .type   = FIO_OPT_BOOL,
3318                 .off1   = td_var_offset(disable_clat),
3319                 .help   = "Disable completion latency numbers",
3320                 .parent = "gtod_reduce",
3321                 .hide   = 1,
3322                 .def    = "0",
3323                 .category = FIO_OPT_C_STAT,
3324                 .group  = FIO_OPT_G_INVALID,
3325         },
3326         {
3327                 .name   = "disable_slat",
3328                 .lname  = "Disable submission latency stats",
3329                 .type   = FIO_OPT_BOOL,
3330                 .off1   = td_var_offset(disable_slat),
3331                 .help   = "Disable submission latency numbers",
3332                 .parent = "gtod_reduce",
3333                 .hide   = 1,
3334                 .def    = "0",
3335                 .category = FIO_OPT_C_STAT,
3336                 .group  = FIO_OPT_G_INVALID,
3337         },
3338         {
3339                 .name   = "disable_bw_measurement",
3340                 .lname  = "Disable bandwidth stats",
3341                 .type   = FIO_OPT_BOOL,
3342                 .off1   = td_var_offset(disable_bw),
3343                 .help   = "Disable bandwidth logging",
3344                 .parent = "gtod_reduce",
3345                 .hide   = 1,
3346                 .def    = "0",
3347                 .category = FIO_OPT_C_STAT,
3348                 .group  = FIO_OPT_G_INVALID,
3349         },
3350         {
3351                 .name   = "gtod_cpu",
3352                 .lname  = "Dedicated gettimeofday() CPU",
3353                 .type   = FIO_OPT_INT,
3354                 .off1   = td_var_offset(gtod_cpu),
3355                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
3356                 .verify = gtod_cpu_verify,
3357                 .category = FIO_OPT_C_GENERAL,
3358                 .group  = FIO_OPT_G_CLOCK,
3359         },
3360         {
3361                 .name   = "unified_rw_reporting",
3362                 .type   = FIO_OPT_BOOL,
3363                 .off1   = td_var_offset(unified_rw_rep),
3364                 .help   = "Unify reporting across data direction",
3365                 .def    = "0",
3366                 .category = FIO_OPT_C_GENERAL,
3367                 .group  = FIO_OPT_G_INVALID,
3368         },
3369         {
3370                 .name   = "continue_on_error",
3371                 .lname  = "Continue on error",
3372                 .type   = FIO_OPT_STR,
3373                 .off1   = td_var_offset(continue_on_error),
3374                 .help   = "Continue on non-fatal errors during IO",
3375                 .def    = "none",
3376                 .category = FIO_OPT_C_GENERAL,
3377                 .group  = FIO_OPT_G_ERR,
3378                 .posval = {
3379                           { .ival = "none",
3380                             .oval = ERROR_TYPE_NONE,
3381                             .help = "Exit when an error is encountered",
3382                           },
3383                           { .ival = "read",
3384                             .oval = ERROR_TYPE_READ,
3385                             .help = "Continue on read errors only",
3386                           },
3387                           { .ival = "write",
3388                             .oval = ERROR_TYPE_WRITE,
3389                             .help = "Continue on write errors only",
3390                           },
3391                           { .ival = "io",
3392                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
3393                             .help = "Continue on any IO errors",
3394                           },
3395                           { .ival = "verify",
3396                             .oval = ERROR_TYPE_VERIFY,
3397                             .help = "Continue on verify errors only",
3398                           },
3399                           { .ival = "all",
3400                             .oval = ERROR_TYPE_ANY,
3401                             .help = "Continue on all io and verify errors",
3402                           },
3403                           { .ival = "0",
3404                             .oval = ERROR_TYPE_NONE,
3405                             .help = "Alias for 'none'",
3406                           },
3407                           { .ival = "1",
3408                             .oval = ERROR_TYPE_ANY,
3409                             .help = "Alias for 'all'",
3410                           },
3411                 },
3412         },
3413         {
3414                 .name   = "ignore_error",
3415                 .type   = FIO_OPT_STR,
3416                 .cb     = str_ignore_error_cb,
3417                 .off1   = td_var_offset(ignore_error_nr),
3418                 .help   = "Set a specific list of errors to ignore",
3419                 .parent = "rw",
3420                 .category = FIO_OPT_C_GENERAL,
3421                 .group  = FIO_OPT_G_ERR,
3422         },
3423         {
3424                 .name   = "error_dump",
3425                 .type   = FIO_OPT_BOOL,
3426                 .off1   = td_var_offset(error_dump),
3427                 .def    = "0",
3428                 .help   = "Dump info on each error",
3429                 .category = FIO_OPT_C_GENERAL,
3430                 .group  = FIO_OPT_G_ERR,
3431         },
3432         {
3433                 .name   = "profile",
3434                 .lname  = "Profile",
3435                 .type   = FIO_OPT_STR_STORE,
3436                 .off1   = td_var_offset(profile),
3437                 .help   = "Select a specific builtin performance test",
3438                 .category = FIO_OPT_C_PROFILE,
3439                 .group  = FIO_OPT_G_INVALID,
3440         },
3441         {
3442                 .name   = "cgroup",
3443                 .lname  = "Cgroup",
3444                 .type   = FIO_OPT_STR_STORE,
3445                 .off1   = td_var_offset(cgroup),
3446                 .help   = "Add job to cgroup of this name",
3447                 .category = FIO_OPT_C_GENERAL,
3448                 .group  = FIO_OPT_G_CGROUP,
3449         },
3450         {
3451                 .name   = "cgroup_nodelete",
3452                 .lname  = "Cgroup no-delete",
3453                 .type   = FIO_OPT_BOOL,
3454                 .off1   = td_var_offset(cgroup_nodelete),
3455                 .help   = "Do not delete cgroups after job completion",
3456                 .def    = "0",
3457                 .parent = "cgroup",
3458                 .category = FIO_OPT_C_GENERAL,
3459                 .group  = FIO_OPT_G_CGROUP,
3460         },
3461         {
3462                 .name   = "cgroup_weight",
3463                 .lname  = "Cgroup weight",
3464                 .type   = FIO_OPT_INT,
3465                 .off1   = td_var_offset(cgroup_weight),
3466                 .help   = "Use given weight for cgroup",
3467                 .minval = 100,
3468                 .maxval = 1000,
3469                 .parent = "cgroup",
3470                 .category = FIO_OPT_C_GENERAL,
3471                 .group  = FIO_OPT_G_CGROUP,
3472         },
3473         {
3474                 .name   = "uid",
3475                 .lname  = "User ID",
3476                 .type   = FIO_OPT_INT,
3477                 .off1   = td_var_offset(uid),
3478                 .help   = "Run job with this user ID",
3479                 .category = FIO_OPT_C_GENERAL,
3480                 .group  = FIO_OPT_G_CRED,
3481         },
3482         {
3483                 .name   = "gid",
3484                 .lname  = "Group ID",
3485                 .type   = FIO_OPT_INT,
3486                 .off1   = td_var_offset(gid),
3487                 .help   = "Run job with this group ID",
3488                 .category = FIO_OPT_C_GENERAL,
3489                 .group  = FIO_OPT_G_CRED,
3490         },
3491         {
3492                 .name   = "kb_base",
3493                 .lname  = "KB Base",
3494                 .type   = FIO_OPT_INT,
3495                 .off1   = td_var_offset(kb_base),
3496                 .prio   = 1,
3497                 .def    = "1024",
3498                 .posval = {
3499                           { .ival = "1024",
3500                             .oval = 1024,
3501                             .help = "Use 1024 as the K base",
3502                           },
3503                           { .ival = "1000",
3504                             .oval = 1000,
3505                             .help = "Use 1000 as the K base",
3506                           },
3507                 },
3508                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
3509                 .category = FIO_OPT_C_GENERAL,
3510                 .group  = FIO_OPT_G_INVALID,
3511         },
3512         {
3513                 .name   = "unit_base",
3514                 .lname  = "Base unit for reporting (Bits or Bytes)",
3515                 .type   = FIO_OPT_INT,
3516                 .off1   = td_var_offset(unit_base),
3517                 .prio   = 1,
3518                 .posval = {
3519                           { .ival = "0",
3520                             .oval = 0,
3521                             .help = "Auto-detect",
3522                           },
3523                           { .ival = "8",
3524                             .oval = 8,
3525                             .help = "Normal (byte based)",
3526                           },
3527                           { .ival = "1",
3528                             .oval = 1,
3529                             .help = "Bit based",
3530                           },
3531                 },
3532                 .help   = "Bit multiple of result summary data (8 for byte, 1 for bit)",
3533                 .category = FIO_OPT_C_GENERAL,
3534                 .group  = FIO_OPT_G_INVALID,
3535         },
3536         {
3537                 .name   = "hugepage-size",
3538                 .lname  = "Hugepage size",
3539                 .type   = FIO_OPT_INT,
3540                 .off1   = td_var_offset(hugepage_size),
3541                 .help   = "When using hugepages, specify size of each page",
3542                 .def    = __fio_stringify(FIO_HUGE_PAGE),
3543                 .interval = 1024 * 1024,
3544                 .category = FIO_OPT_C_GENERAL,
3545                 .group  = FIO_OPT_G_INVALID,
3546         },
3547         {
3548                 .name   = "flow_id",
3549                 .lname  = "I/O flow ID",
3550                 .type   = FIO_OPT_INT,
3551                 .off1   = td_var_offset(flow_id),
3552                 .help   = "The flow index ID to use",
3553                 .def    = "0",
3554                 .category = FIO_OPT_C_IO,
3555                 .group  = FIO_OPT_G_IO_FLOW,
3556         },
3557         {
3558                 .name   = "flow",
3559                 .lname  = "I/O flow weight",
3560                 .type   = FIO_OPT_INT,
3561                 .off1   = td_var_offset(flow),
3562                 .help   = "Weight for flow control of this job",
3563                 .parent = "flow_id",
3564                 .hide   = 1,
3565                 .def    = "0",
3566                 .category = FIO_OPT_C_IO,
3567                 .group  = FIO_OPT_G_IO_FLOW,
3568         },
3569         {
3570                 .name   = "flow_watermark",
3571                 .lname  = "I/O flow watermark",
3572                 .type   = FIO_OPT_INT,
3573                 .off1   = td_var_offset(flow_watermark),
3574                 .help   = "High watermark for flow control. This option"
3575                         " should be set to the same value for all threads"
3576                         " with non-zero flow.",
3577                 .parent = "flow_id",
3578                 .hide   = 1,
3579                 .def    = "1024",
3580                 .category = FIO_OPT_C_IO,
3581                 .group  = FIO_OPT_G_IO_FLOW,
3582         },
3583         {
3584                 .name   = "flow_sleep",
3585                 .lname  = "I/O flow sleep",
3586                 .type   = FIO_OPT_INT,
3587                 .off1   = td_var_offset(flow_sleep),
3588                 .help   = "How many microseconds to sleep after being held"
3589                         " back by the flow control mechanism",
3590                 .parent = "flow_id",
3591                 .hide   = 1,
3592                 .def    = "0",
3593                 .category = FIO_OPT_C_IO,
3594                 .group  = FIO_OPT_G_IO_FLOW,
3595         },
3596         {
3597                 .name   = "skip_bad",
3598                 .lname  = "Skip operations against bad blocks",
3599                 .type   = FIO_OPT_BOOL,
3600                 .off1   = td_var_offset(skip_bad),
3601                 .help   = "Skip operations against known bad blocks.",
3602                 .hide   = 1,
3603                 .def    = "0",
3604                 .category = FIO_OPT_C_IO,
3605                 .group  = FIO_OPT_G_MTD,
3606         },
3607         {
3608                 .name = NULL,
3609         },
3610 };
3611
3612 static void add_to_lopt(struct option *lopt, struct fio_option *o,
3613                         const char *name, int val)
3614 {
3615         lopt->name = (char *) name;
3616         lopt->val = val;
3617         if (o->type == FIO_OPT_STR_SET)
3618                 lopt->has_arg = optional_argument;
3619         else
3620                 lopt->has_arg = required_argument;
3621 }
3622
3623 static void options_to_lopts(struct fio_option *opts,
3624                               struct option *long_options,
3625                               int i, int option_type)
3626 {
3627         struct fio_option *o = &opts[0];
3628         while (o->name) {
3629                 add_to_lopt(&long_options[i], o, o->name, option_type);
3630                 if (o->alias) {
3631                         i++;
3632                         add_to_lopt(&long_options[i], o, o->alias, option_type);
3633                 }
3634
3635                 i++;
3636                 o++;
3637                 assert(i < FIO_NR_OPTIONS);
3638         }
3639 }
3640
3641 void fio_options_set_ioengine_opts(struct option *long_options,
3642                                    struct thread_data *td)
3643 {
3644         unsigned int i;
3645
3646         i = 0;
3647         while (long_options[i].name) {
3648                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
3649                         memset(&long_options[i], 0, sizeof(*long_options));
3650                         break;
3651                 }
3652                 i++;
3653         }
3654
3655         /*
3656          * Just clear out the prior ioengine options.
3657          */
3658         if (!td || !td->eo)
3659                 return;
3660
3661         options_to_lopts(td->io_ops->options, long_options, i,
3662                          FIO_GETOPT_IOENGINE);
3663 }
3664
3665 void fio_options_dup_and_init(struct option *long_options)
3666 {
3667         unsigned int i;
3668
3669         options_init(fio_options);
3670
3671         i = 0;
3672         while (long_options[i].name)
3673                 i++;
3674
3675         options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
3676 }
3677
3678 struct fio_keyword {
3679         const char *word;
3680         const char *desc;
3681         char *replace;
3682 };
3683
3684 static struct fio_keyword fio_keywords[] = {
3685         {
3686                 .word   = "$pagesize",
3687                 .desc   = "Page size in the system",
3688         },
3689         {
3690                 .word   = "$mb_memory",
3691                 .desc   = "Megabytes of memory online",
3692         },
3693         {
3694                 .word   = "$ncpus",
3695                 .desc   = "Number of CPUs online in the system",
3696         },
3697         {
3698                 .word   = NULL,
3699         },
3700 };
3701
3702 void fio_keywords_exit(void)
3703 {
3704         struct fio_keyword *kw;
3705
3706         kw = &fio_keywords[0];
3707         while (kw->word) {
3708                 free(kw->replace);
3709                 kw->replace = NULL;
3710                 kw++;
3711         }
3712 }
3713
3714 void fio_keywords_init(void)
3715 {
3716         unsigned long long mb_memory;
3717         char buf[128];
3718         long l;
3719
3720         sprintf(buf, "%lu", (unsigned long) page_size);
3721         fio_keywords[0].replace = strdup(buf);
3722
3723         mb_memory = os_phys_mem() / (1024 * 1024);
3724         sprintf(buf, "%llu", mb_memory);
3725         fio_keywords[1].replace = strdup(buf);
3726
3727         l = cpus_online();
3728         sprintf(buf, "%lu", l);
3729         fio_keywords[2].replace = strdup(buf);
3730 }
3731
3732 #define BC_APP          "bc"
3733
3734 static char *bc_calc(char *str)
3735 {
3736         char buf[128], *tmp;
3737         FILE *f;
3738         int ret;
3739
3740         /*
3741          * No math, just return string
3742          */
3743         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
3744              !strchr(str, '/')) || strchr(str, '\''))
3745                 return str;
3746
3747         /*
3748          * Split option from value, we only need to calculate the value
3749          */
3750         tmp = strchr(str, '=');
3751         if (!tmp)
3752                 return str;
3753
3754         tmp++;
3755
3756         /*
3757          * Prevent buffer overflows; such a case isn't reasonable anyway
3758          */
3759         if (strlen(str) >= 128 || strlen(tmp) > 100)
3760                 return str;
3761
3762         sprintf(buf, "which %s > /dev/null", BC_APP);
3763         if (system(buf)) {
3764                 log_err("fio: bc is needed for performing math\n");
3765                 return NULL;
3766         }
3767
3768         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
3769         f = popen(buf, "r");
3770         if (!f)
3771                 return NULL;
3772
3773         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
3774         if (ret <= 0) {
3775                 pclose(f);
3776                 return NULL;
3777         }
3778
3779         pclose(f);
3780         buf[(tmp - str) + ret - 1] = '\0';
3781         memcpy(buf, str, tmp - str);
3782         free(str);
3783         return strdup(buf);
3784 }
3785
3786 /*
3787  * Return a copy of the input string with substrings of the form ${VARNAME}
3788  * substituted with the value of the environment variable VARNAME.  The
3789  * substitution always occurs, even if VARNAME is empty or the corresponding
3790  * environment variable undefined.
3791  */
3792 static char *option_dup_subs(const char *opt)
3793 {
3794         char out[OPT_LEN_MAX+1];
3795         char in[OPT_LEN_MAX+1];
3796         char *outptr = out;
3797         char *inptr = in;
3798         char *ch1, *ch2, *env;
3799         ssize_t nchr = OPT_LEN_MAX;
3800         size_t envlen;
3801
3802         if (strlen(opt) + 1 > OPT_LEN_MAX) {
3803                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
3804                 return NULL;
3805         }
3806
3807         in[OPT_LEN_MAX] = '\0';
3808         strncpy(in, opt, OPT_LEN_MAX);
3809
3810         while (*inptr && nchr > 0) {
3811                 if (inptr[0] == '$' && inptr[1] == '{') {
3812                         ch2 = strchr(inptr, '}');
3813                         if (ch2 && inptr+1 < ch2) {
3814                                 ch1 = inptr+2;
3815                                 inptr = ch2+1;
3816                                 *ch2 = '\0';
3817
3818                                 env = getenv(ch1);
3819                                 if (env) {
3820                                         envlen = strlen(env);
3821                                         if (envlen <= nchr) {
3822                                                 memcpy(outptr, env, envlen);
3823                                                 outptr += envlen;
3824                                                 nchr -= envlen;
3825                                         }
3826                                 }
3827
3828                                 continue;
3829                         }
3830                 }
3831
3832                 *outptr++ = *inptr++;
3833                 --nchr;
3834         }
3835
3836         *outptr = '\0';
3837         return strdup(out);
3838 }
3839
3840 /*
3841  * Look for reserved variable names and replace them with real values
3842  */
3843 static char *fio_keyword_replace(char *opt)
3844 {
3845         char *s;
3846         int i;
3847         int docalc = 0;
3848
3849         for (i = 0; fio_keywords[i].word != NULL; i++) {
3850                 struct fio_keyword *kw = &fio_keywords[i];
3851
3852                 while ((s = strstr(opt, kw->word)) != NULL) {
3853                         char *new = malloc(strlen(opt) + 1);
3854                         char *o_org = opt;
3855                         int olen = s - opt;
3856                         int len;
3857
3858                         /*
3859                          * Copy part of the string before the keyword and
3860                          * sprintf() the replacement after it.
3861                          */
3862                         memcpy(new, opt, olen);
3863                         len = sprintf(new + olen, "%s", kw->replace);
3864
3865                         /*
3866                          * If there's more in the original string, copy that
3867                          * in too
3868                          */
3869                         opt += strlen(kw->word) + olen;
3870                         if (strlen(opt))
3871                                 memcpy(new + olen + len, opt, opt - o_org - 1);
3872
3873                         /*
3874                          * replace opt and free the old opt
3875                          */
3876                         opt = new;
3877                         free(o_org);
3878
3879                         docalc = 1;
3880                 }
3881         }
3882
3883         /*
3884          * Check for potential math and invoke bc, if possible
3885          */
3886         if (docalc)
3887                 opt = bc_calc(opt);
3888
3889         return opt;
3890 }
3891
3892 static char **dup_and_sub_options(char **opts, int num_opts)
3893 {
3894         int i;
3895         char **opts_copy = malloc(num_opts * sizeof(*opts));
3896         for (i = 0; i < num_opts; i++) {
3897                 opts_copy[i] = option_dup_subs(opts[i]);
3898                 if (!opts_copy[i])
3899                         continue;
3900                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
3901         }
3902         return opts_copy;
3903 }
3904
3905 static void show_closest_option(const char *opt)
3906 {
3907         int best_option, best_distance;
3908         int i, distance;
3909         char *name;
3910
3911         if (!strlen(opt))
3912                 return;
3913
3914         name = strdup(opt);
3915         i = 0;
3916         while (name[i] != '\0' && name[i] != '=')
3917                 i++;
3918         name[i] = '\0';
3919
3920         best_option = -1;
3921         best_distance = INT_MAX;
3922         i = 0;
3923         while (fio_options[i].name) {
3924                 distance = string_distance(name, fio_options[i].name);
3925                 if (distance < best_distance) {
3926                         best_distance = distance;
3927                         best_option = i;
3928                 }
3929                 i++;
3930         }
3931
3932         if (best_option != -1 && string_distance_ok(name, best_distance))
3933                 log_err("Did you mean %s?\n", fio_options[best_option].name);
3934
3935         free(name);
3936 }
3937
3938 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
3939 {
3940         int i, ret, unknown;
3941         char **opts_copy;
3942
3943         sort_options(opts, fio_options, num_opts);
3944         opts_copy = dup_and_sub_options(opts, num_opts);
3945
3946         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
3947                 struct fio_option *o;
3948                 int newret = parse_option(opts_copy[i], opts[i], fio_options,
3949                                                 &o, td, &td->opt_list);
3950
3951                 if (!newret && o)
3952                         fio_option_mark_set(&td->o, o);
3953
3954                 if (opts_copy[i]) {
3955                         if (newret && !o) {
3956                                 unknown++;
3957                                 continue;
3958                         }
3959                         free(opts_copy[i]);
3960                         opts_copy[i] = NULL;
3961                 }
3962
3963                 ret |= newret;
3964         }
3965
3966         if (unknown) {
3967                 ret |= ioengine_load(td);
3968                 if (td->eo) {
3969                         sort_options(opts_copy, td->io_ops->options, num_opts);
3970                         opts = opts_copy;
3971                 }
3972                 for (i = 0; i < num_opts; i++) {
3973                         struct fio_option *o = NULL;
3974                         int newret = 1;
3975
3976                         if (!opts_copy[i])
3977                                 continue;
3978
3979                         if (td->eo)
3980                                 newret = parse_option(opts_copy[i], opts[i],
3981                                                       td->io_ops->options, &o,
3982                                                       td->eo, &td->opt_list);
3983
3984                         ret |= newret;
3985                         if (!o) {
3986                                 log_err("Bad option <%s>\n", opts[i]);
3987                                 show_closest_option(opts[i]);
3988                         }
3989                         free(opts_copy[i]);
3990                         opts_copy[i] = NULL;
3991                 }
3992         }
3993
3994         free(opts_copy);
3995         return ret;
3996 }
3997
3998 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
3999 {
4000         int ret;
4001
4002         ret = parse_cmd_option(opt, val, fio_options, td, &td->opt_list);
4003         if (!ret) {
4004                 struct fio_option *o;
4005
4006                 o = find_option(fio_options, opt);
4007                 if (o)
4008                         fio_option_mark_set(&td->o, o);
4009         }
4010
4011         return ret;
4012 }
4013
4014 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
4015                                 char *val)
4016 {
4017         return parse_cmd_option(opt, val, td->io_ops->options, td->eo,
4018                                         &td->opt_list);
4019 }
4020
4021 void fio_fill_default_options(struct thread_data *td)
4022 {
4023         td->o.magic = OPT_MAGIC;
4024         fill_default_options(td, fio_options);
4025 }
4026
4027 int fio_show_option_help(const char *opt)
4028 {
4029         return show_cmd_help(fio_options, opt);
4030 }
4031
4032 void options_mem_dupe(void *data, struct fio_option *options)
4033 {
4034         struct fio_option *o;
4035         char **ptr;
4036
4037         for (o = &options[0]; o->name; o++) {
4038                 if (o->type != FIO_OPT_STR_STORE)
4039                         continue;
4040
4041                 ptr = td_var(data, o, o->off1);
4042                 if (*ptr)
4043                         *ptr = strdup(*ptr);
4044         }
4045 }
4046
4047 /*
4048  * dupe FIO_OPT_STR_STORE options
4049  */
4050 void fio_options_mem_dupe(struct thread_data *td)
4051 {
4052         options_mem_dupe(&td->o, fio_options);
4053
4054         if (td->eo && td->io_ops) {
4055                 void *oldeo = td->eo;
4056
4057                 td->eo = malloc(td->io_ops->option_struct_size);
4058                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
4059                 options_mem_dupe(td->eo, td->io_ops->options);
4060         }
4061 }
4062
4063 unsigned int fio_get_kb_base(void *data)
4064 {
4065         struct thread_options *o = data;
4066         unsigned int kb_base = 0;
4067
4068         /*
4069          * This is a hack... For private options, *data is not holding
4070          * a pointer to the thread_options, but to private data. This means
4071          * we can't safely dereference it, but magic is first so mem wise
4072          * it is valid. But this also means that if the job first sets
4073          * kb_base and expects that to be honored by private options,
4074          * it will be disappointed. We will return the global default
4075          * for this.
4076          */
4077         if (o && o->magic == OPT_MAGIC)
4078                 kb_base = o->kb_base;
4079         if (!kb_base)
4080                 kb_base = 1024;
4081
4082         return kb_base;
4083 }
4084
4085 int add_option(struct fio_option *o)
4086 {
4087         struct fio_option *__o;
4088         int opt_index = 0;
4089
4090         __o = fio_options;
4091         while (__o->name) {
4092                 opt_index++;
4093                 __o++;
4094         }
4095
4096         if (opt_index + 1 == FIO_MAX_OPTS) {
4097                 log_err("fio: FIO_MAX_OPTS is too small\n");
4098                 return 1;
4099         }
4100
4101         memcpy(&fio_options[opt_index], o, sizeof(*o));
4102         fio_options[opt_index + 1].name = NULL;
4103         return 0;
4104 }
4105
4106 void invalidate_profile_options(const char *prof_name)
4107 {
4108         struct fio_option *o;
4109
4110         o = fio_options;
4111         while (o->name) {
4112                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
4113                         o->type = FIO_OPT_INVALID;
4114                         o->prof_name = NULL;
4115                 }
4116                 o++;
4117         }
4118 }
4119
4120 void add_opt_posval(const char *optname, const char *ival, const char *help)
4121 {
4122         struct fio_option *o;
4123         unsigned int i;
4124
4125         o = find_option(fio_options, optname);
4126         if (!o)
4127                 return;
4128
4129         for (i = 0; i < PARSE_MAX_VP; i++) {
4130                 if (o->posval[i].ival)
4131                         continue;
4132
4133                 o->posval[i].ival = ival;
4134                 o->posval[i].help = help;
4135                 break;
4136         }
4137 }
4138
4139 void del_opt_posval(const char *optname, const char *ival)
4140 {
4141         struct fio_option *o;
4142         unsigned int i;
4143
4144         o = find_option(fio_options, optname);
4145         if (!o)
4146                 return;
4147
4148         for (i = 0; i < PARSE_MAX_VP; i++) {
4149                 if (!o->posval[i].ival)
4150                         continue;
4151                 if (strcmp(o->posval[i].ival, ival))
4152                         continue;
4153
4154                 o->posval[i].ival = NULL;
4155                 o->posval[i].help = NULL;
4156         }
4157 }
4158
4159 void fio_options_free(struct thread_data *td)
4160 {
4161         options_free(fio_options, td);
4162         if (td->eo && td->io_ops && td->io_ops->options) {
4163                 options_free(td->io_ops->options, td->eo);
4164                 free(td->eo);
4165                 td->eo = NULL;
4166         }
4167 }
4168
4169 struct fio_option *fio_option_find(const char *name)
4170 {
4171         return find_option(fio_options, name);
4172 }
4173
4174 static struct fio_option *find_next_opt(struct thread_options *o,
4175                                         struct fio_option *from,
4176                                         unsigned int off1)
4177 {
4178         struct fio_option *opt;
4179
4180         if (!from)
4181                 from = &fio_options[0];
4182         else
4183                 from++;
4184
4185         opt = NULL;
4186         do {
4187                 if (off1 == from->off1) {
4188                         opt = from;
4189                         break;
4190                 }
4191                 from++;
4192         } while (from->name);
4193
4194         return opt;
4195 }
4196
4197 static int opt_is_set(struct thread_options *o, struct fio_option *opt)
4198 {
4199         unsigned int opt_off, index, offset;
4200
4201         opt_off = opt - &fio_options[0];
4202         index = opt_off / (8 * sizeof(uint64_t));
4203         offset = opt_off & ((8 * sizeof(uint64_t)) - 1);
4204         return (o->set_options[index] & ((uint64_t)1 << offset)) != 0;
4205 }
4206
4207 bool __fio_option_is_set(struct thread_options *o, unsigned int off1)
4208 {
4209         struct fio_option *opt, *next;
4210
4211         next = NULL;
4212         while ((opt = find_next_opt(o, next, off1)) != NULL) {
4213                 if (opt_is_set(o, opt))
4214                         return true;
4215
4216                 next = opt;
4217         }
4218
4219         return false;
4220 }
4221
4222 void fio_option_mark_set(struct thread_options *o, struct fio_option *opt)
4223 {
4224         unsigned int opt_off, index, offset;
4225
4226         opt_off = opt - &fio_options[0];
4227         index = opt_off / (8 * sizeof(uint64_t));
4228         offset = opt_off & ((8 * sizeof(uint64_t)) - 1);
4229         o->set_options[index] |= (uint64_t)1 << offset;
4230 }