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