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