Makefile: use fmt(1) rather than tr(1) on NetBSD/etc
[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->ts_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         {
2359                 .name   = "fsync",
2360                 .lname  = "Fsync",
2361                 .type   = FIO_OPT_INT,
2362                 .off1   = offsetof(struct thread_options, fsync_blocks),
2363                 .help   = "Issue fsync for writes every given number of blocks",
2364                 .def    = "0",
2365                 .interval = 1,
2366                 .category = FIO_OPT_C_FILE,
2367                 .group  = FIO_OPT_G_INVALID,
2368         },
2369         {
2370                 .name   = "fdatasync",
2371                 .lname  = "Fdatasync",
2372                 .type   = FIO_OPT_INT,
2373                 .off1   = offsetof(struct thread_options, fdatasync_blocks),
2374                 .help   = "Issue fdatasync for writes every given number of blocks",
2375                 .def    = "0",
2376                 .interval = 1,
2377                 .category = FIO_OPT_C_FILE,
2378                 .group  = FIO_OPT_G_INVALID,
2379         },
2380         {
2381                 .name   = "write_barrier",
2382                 .lname  = "Write barrier",
2383                 .type   = FIO_OPT_INT,
2384                 .off1   = offsetof(struct thread_options, barrier_blocks),
2385                 .help   = "Make every Nth write a barrier write",
2386                 .def    = "0",
2387                 .interval = 1,
2388                 .category = FIO_OPT_C_IO,
2389                 .group  = FIO_OPT_G_INVALID,
2390         },
2391 #ifdef CONFIG_SYNC_FILE_RANGE
2392         {
2393                 .name   = "sync_file_range",
2394                 .lname  = "Sync file range",
2395                 .posval = {
2396                           { .ival = "wait_before",
2397                             .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
2398                             .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
2399                             .orval  = 1,
2400                           },
2401                           { .ival = "write",
2402                             .oval = SYNC_FILE_RANGE_WRITE,
2403                             .help = "SYNC_FILE_RANGE_WRITE",
2404                             .orval  = 1,
2405                           },
2406                           {
2407                             .ival = "wait_after",
2408                             .oval = SYNC_FILE_RANGE_WAIT_AFTER,
2409                             .help = "SYNC_FILE_RANGE_WAIT_AFTER",
2410                             .orval  = 1,
2411                           },
2412                 },
2413                 .type   = FIO_OPT_STR_MULTI,
2414                 .cb     = str_sfr_cb,
2415                 .off1   = offsetof(struct thread_options, sync_file_range),
2416                 .help   = "Use sync_file_range()",
2417                 .category = FIO_OPT_C_FILE,
2418                 .group  = FIO_OPT_G_INVALID,
2419         },
2420 #else
2421         {
2422                 .name   = "sync_file_range",
2423                 .lname  = "Sync file range",
2424                 .type   = FIO_OPT_UNSUPPORTED,
2425                 .help   = "Your platform does not support sync_file_range",
2426         },
2427 #endif
2428         {
2429                 .name   = "direct",
2430                 .lname  = "Direct I/O",
2431                 .type   = FIO_OPT_BOOL,
2432                 .off1   = offsetof(struct thread_options, odirect),
2433                 .help   = "Use O_DIRECT IO (negates buffered)",
2434                 .def    = "0",
2435                 .inverse = "buffered",
2436                 .category = FIO_OPT_C_IO,
2437                 .group  = FIO_OPT_G_IO_TYPE,
2438         },
2439         {
2440                 .name   = "atomic",
2441                 .lname  = "Atomic I/O",
2442                 .type   = FIO_OPT_BOOL,
2443                 .off1   = offsetof(struct thread_options, oatomic),
2444                 .help   = "Use Atomic IO with O_DIRECT (implies O_DIRECT)",
2445                 .def    = "0",
2446                 .category = FIO_OPT_C_IO,
2447                 .group  = FIO_OPT_G_IO_TYPE,
2448         },
2449         {
2450                 .name   = "buffered",
2451                 .lname  = "Buffered I/O",
2452                 .type   = FIO_OPT_BOOL,
2453                 .off1   = offsetof(struct thread_options, odirect),
2454                 .neg    = 1,
2455                 .help   = "Use buffered IO (negates direct)",
2456                 .def    = "1",
2457                 .inverse = "direct",
2458                 .category = FIO_OPT_C_IO,
2459                 .group  = FIO_OPT_G_IO_TYPE,
2460         },
2461         {
2462                 .name   = "overwrite",
2463                 .lname  = "Overwrite",
2464                 .type   = FIO_OPT_BOOL,
2465                 .off1   = offsetof(struct thread_options, overwrite),
2466                 .help   = "When writing, set whether to overwrite current data",
2467                 .def    = "0",
2468                 .category = FIO_OPT_C_FILE,
2469                 .group  = FIO_OPT_G_INVALID,
2470         },
2471         {
2472                 .name   = "loops",
2473                 .lname  = "Loops",
2474                 .type   = FIO_OPT_INT,
2475                 .off1   = offsetof(struct thread_options, loops),
2476                 .help   = "Number of times to run the job",
2477                 .def    = "1",
2478                 .interval = 1,
2479                 .category = FIO_OPT_C_GENERAL,
2480                 .group  = FIO_OPT_G_RUNTIME,
2481         },
2482         {
2483                 .name   = "numjobs",
2484                 .lname  = "Number of jobs",
2485                 .type   = FIO_OPT_INT,
2486                 .off1   = offsetof(struct thread_options, numjobs),
2487                 .help   = "Duplicate this job this many times",
2488                 .def    = "1",
2489                 .interval = 1,
2490                 .category = FIO_OPT_C_GENERAL,
2491                 .group  = FIO_OPT_G_RUNTIME,
2492         },
2493         {
2494                 .name   = "startdelay",
2495                 .lname  = "Start delay",
2496                 .type   = FIO_OPT_STR_VAL_TIME,
2497                 .off1   = offsetof(struct thread_options, start_delay),
2498                 .off2   = offsetof(struct thread_options, start_delay_high),
2499                 .help   = "Only start job when this period has passed",
2500                 .def    = "0",
2501                 .is_seconds = 1,
2502                 .is_time = 1,
2503                 .category = FIO_OPT_C_GENERAL,
2504                 .group  = FIO_OPT_G_RUNTIME,
2505         },
2506         {
2507                 .name   = "runtime",
2508                 .lname  = "Runtime",
2509                 .alias  = "timeout",
2510                 .type   = FIO_OPT_STR_VAL_TIME,
2511                 .off1   = offsetof(struct thread_options, timeout),
2512                 .help   = "Stop workload when this amount of time has passed",
2513                 .def    = "0",
2514                 .is_seconds = 1,
2515                 .is_time = 1,
2516                 .category = FIO_OPT_C_GENERAL,
2517                 .group  = FIO_OPT_G_RUNTIME,
2518         },
2519         {
2520                 .name   = "time_based",
2521                 .lname  = "Time based",
2522                 .type   = FIO_OPT_STR_SET,
2523                 .off1   = offsetof(struct thread_options, time_based),
2524                 .help   = "Keep running until runtime/timeout is met",
2525                 .category = FIO_OPT_C_GENERAL,
2526                 .group  = FIO_OPT_G_RUNTIME,
2527         },
2528         {
2529                 .name   = "verify_only",
2530                 .lname  = "Verify only",
2531                 .type   = FIO_OPT_STR_SET,
2532                 .off1   = offsetof(struct thread_options, verify_only),
2533                 .help   = "Verifies previously written data is still valid",
2534                 .category = FIO_OPT_C_GENERAL,
2535                 .group  = FIO_OPT_G_RUNTIME,
2536         },
2537         {
2538                 .name   = "ramp_time",
2539                 .lname  = "Ramp time",
2540                 .type   = FIO_OPT_STR_VAL_TIME,
2541                 .off1   = offsetof(struct thread_options, ramp_time),
2542                 .help   = "Ramp up time before measuring performance",
2543                 .is_seconds = 1,
2544                 .is_time = 1,
2545                 .category = FIO_OPT_C_GENERAL,
2546                 .group  = FIO_OPT_G_RUNTIME,
2547         },
2548         {
2549                 .name   = "clocksource",
2550                 .lname  = "Clock source",
2551                 .type   = FIO_OPT_STR,
2552                 .cb     = fio_clock_source_cb,
2553                 .off1   = offsetof(struct thread_options, clocksource),
2554                 .help   = "What type of timing source to use",
2555                 .category = FIO_OPT_C_GENERAL,
2556                 .group  = FIO_OPT_G_CLOCK,
2557                 .posval = {
2558 #ifdef CONFIG_GETTIMEOFDAY
2559                           { .ival = "gettimeofday",
2560                             .oval = CS_GTOD,
2561                             .help = "Use gettimeofday(2) for timing",
2562                           },
2563 #endif
2564 #ifdef CONFIG_CLOCK_GETTIME
2565                           { .ival = "clock_gettime",
2566                             .oval = CS_CGETTIME,
2567                             .help = "Use clock_gettime(2) for timing",
2568                           },
2569 #endif
2570 #ifdef ARCH_HAVE_CPU_CLOCK
2571                           { .ival = "cpu",
2572                             .oval = CS_CPUCLOCK,
2573                             .help = "Use CPU private clock",
2574                           },
2575 #endif
2576                 },
2577         },
2578         {
2579                 .name   = "mem",
2580                 .alias  = "iomem",
2581                 .lname  = "I/O Memory",
2582                 .type   = FIO_OPT_STR,
2583                 .cb     = str_mem_cb,
2584                 .off1   = offsetof(struct thread_options, mem_type),
2585                 .help   = "Backing type for IO buffers",
2586                 .def    = "malloc",
2587                 .category = FIO_OPT_C_IO,
2588                 .group  = FIO_OPT_G_INVALID,
2589                 .posval = {
2590                           { .ival = "malloc",
2591                             .oval = MEM_MALLOC,
2592                             .help = "Use malloc(3) for IO buffers",
2593                           },
2594 #ifndef CONFIG_NO_SHM
2595                           { .ival = "shm",
2596                             .oval = MEM_SHM,
2597                             .help = "Use shared memory segments for IO buffers",
2598                           },
2599 #ifdef FIO_HAVE_HUGETLB
2600                           { .ival = "shmhuge",
2601                             .oval = MEM_SHMHUGE,
2602                             .help = "Like shm, but use huge pages",
2603                           },
2604 #endif
2605 #endif
2606                           { .ival = "mmap",
2607                             .oval = MEM_MMAP,
2608                             .help = "Use mmap(2) (file or anon) for IO buffers",
2609                           },
2610                           { .ival = "mmapshared",
2611                             .oval = MEM_MMAPSHARED,
2612                             .help = "Like mmap, but use the shared flag",
2613                           },
2614 #ifdef FIO_HAVE_HUGETLB
2615                           { .ival = "mmaphuge",
2616                             .oval = MEM_MMAPHUGE,
2617                             .help = "Like mmap, but use huge pages",
2618                           },
2619 #endif
2620 #ifdef CONFIG_CUDA
2621                           { .ival = "cudamalloc",
2622                             .oval = MEM_CUDA_MALLOC,
2623                             .help = "Allocate GPU device memory for GPUDirect RDMA",
2624                           },
2625 #endif
2626                   },
2627         },
2628         {
2629                 .name   = "iomem_align",
2630                 .alias  = "mem_align",
2631                 .lname  = "I/O memory alignment",
2632                 .type   = FIO_OPT_INT,
2633                 .off1   = offsetof(struct thread_options, mem_align),
2634                 .minval = 0,
2635                 .help   = "IO memory buffer offset alignment",
2636                 .def    = "0",
2637                 .parent = "iomem",
2638                 .hide   = 1,
2639                 .category = FIO_OPT_C_IO,
2640                 .group  = FIO_OPT_G_INVALID,
2641         },
2642         {
2643                 .name   = "verify",
2644                 .lname  = "Verify",
2645                 .type   = FIO_OPT_STR,
2646                 .off1   = offsetof(struct thread_options, verify),
2647                 .help   = "Verify data written",
2648                 .def    = "0",
2649                 .category = FIO_OPT_C_IO,
2650                 .group  = FIO_OPT_G_VERIFY,
2651                 .posval = {
2652                           { .ival = "0",
2653                             .oval = VERIFY_NONE,
2654                             .help = "Don't do IO verification",
2655                           },
2656                           { .ival = "md5",
2657                             .oval = VERIFY_MD5,
2658                             .help = "Use md5 checksums for verification",
2659                           },
2660                           { .ival = "crc64",
2661                             .oval = VERIFY_CRC64,
2662                             .help = "Use crc64 checksums for verification",
2663                           },
2664                           { .ival = "crc32",
2665                             .oval = VERIFY_CRC32,
2666                             .help = "Use crc32 checksums for verification",
2667                           },
2668                           { .ival = "crc32c-intel",
2669                             .oval = VERIFY_CRC32C,
2670                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
2671                           },
2672                           { .ival = "crc32c",
2673                             .oval = VERIFY_CRC32C,
2674                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
2675                           },
2676                           { .ival = "crc16",
2677                             .oval = VERIFY_CRC16,
2678                             .help = "Use crc16 checksums for verification",
2679                           },
2680                           { .ival = "crc7",
2681                             .oval = VERIFY_CRC7,
2682                             .help = "Use crc7 checksums for verification",
2683                           },
2684                           { .ival = "sha1",
2685                             .oval = VERIFY_SHA1,
2686                             .help = "Use sha1 checksums for verification",
2687                           },
2688                           { .ival = "sha256",
2689                             .oval = VERIFY_SHA256,
2690                             .help = "Use sha256 checksums for verification",
2691                           },
2692                           { .ival = "sha512",
2693                             .oval = VERIFY_SHA512,
2694                             .help = "Use sha512 checksums for verification",
2695                           },
2696                           { .ival = "sha3-224",
2697                             .oval = VERIFY_SHA3_224,
2698                             .help = "Use sha3-224 checksums for verification",
2699                           },
2700                           { .ival = "sha3-256",
2701                             .oval = VERIFY_SHA3_256,
2702                             .help = "Use sha3-256 checksums for verification",
2703                           },
2704                           { .ival = "sha3-384",
2705                             .oval = VERIFY_SHA3_384,
2706                             .help = "Use sha3-384 checksums for verification",
2707                           },
2708                           { .ival = "sha3-512",
2709                             .oval = VERIFY_SHA3_512,
2710                             .help = "Use sha3-512 checksums for verification",
2711                           },
2712                           { .ival = "xxhash",
2713                             .oval = VERIFY_XXHASH,
2714                             .help = "Use xxhash checksums for verification",
2715                           },
2716                           /* Meta information was included into verify_header,
2717                            * 'meta' verification is implied by default. */
2718                           { .ival = "meta",
2719                             .oval = VERIFY_HDR_ONLY,
2720                             .help = "Use io information for verification. "
2721                                     "Now is implied by default, thus option is obsolete, "
2722                                     "don't use it",
2723                           },
2724                           { .ival = "pattern",
2725                             .oval = VERIFY_PATTERN_NO_HDR,
2726                             .help = "Verify strict pattern",
2727                           },
2728                           {
2729                             .ival = "null",
2730                             .oval = VERIFY_NULL,
2731                             .help = "Pretend to verify",
2732                           },
2733                 },
2734         },
2735         {
2736                 .name   = "do_verify",
2737                 .lname  = "Perform verify step",
2738                 .type   = FIO_OPT_BOOL,
2739                 .off1   = offsetof(struct thread_options, do_verify),
2740                 .help   = "Run verification stage after write",
2741                 .def    = "1",
2742                 .parent = "verify",
2743                 .hide   = 1,
2744                 .category = FIO_OPT_C_IO,
2745                 .group  = FIO_OPT_G_VERIFY,
2746         },
2747         {
2748                 .name   = "verifysort",
2749                 .lname  = "Verify sort",
2750                 .type   = FIO_OPT_BOOL,
2751                 .off1   = offsetof(struct thread_options, verifysort),
2752                 .help   = "Sort written verify blocks for read back",
2753                 .def    = "1",
2754                 .parent = "verify",
2755                 .hide   = 1,
2756                 .category = FIO_OPT_C_IO,
2757                 .group  = FIO_OPT_G_VERIFY,
2758         },
2759         {
2760                 .name   = "verifysort_nr",
2761                 .lname  = "Verify Sort Nr",
2762                 .type   = FIO_OPT_INT,
2763                 .off1   = offsetof(struct thread_options, verifysort_nr),
2764                 .help   = "Pre-load and sort verify blocks for a read workload",
2765                 .minval = 0,
2766                 .maxval = 131072,
2767                 .def    = "1024",
2768                 .parent = "verify",
2769                 .category = FIO_OPT_C_IO,
2770                 .group  = FIO_OPT_G_VERIFY,
2771         },
2772         {
2773                 .name   = "verify_interval",
2774                 .lname  = "Verify interval",
2775                 .type   = FIO_OPT_INT,
2776                 .off1   = offsetof(struct thread_options, verify_interval),
2777                 .minval = 2 * sizeof(struct verify_header),
2778                 .help   = "Store verify buffer header every N bytes",
2779                 .parent = "verify",
2780                 .hide   = 1,
2781                 .interval = 2 * sizeof(struct verify_header),
2782                 .category = FIO_OPT_C_IO,
2783                 .group  = FIO_OPT_G_VERIFY,
2784         },
2785         {
2786                 .name   = "verify_offset",
2787                 .lname  = "Verify offset",
2788                 .type   = FIO_OPT_INT,
2789                 .help   = "Offset verify header location by N bytes",
2790                 .off1   = offsetof(struct thread_options, verify_offset),
2791                 .minval = sizeof(struct verify_header),
2792                 .parent = "verify",
2793                 .hide   = 1,
2794                 .category = FIO_OPT_C_IO,
2795                 .group  = FIO_OPT_G_VERIFY,
2796         },
2797         {
2798                 .name   = "verify_pattern",
2799                 .lname  = "Verify pattern",
2800                 .type   = FIO_OPT_STR,
2801                 .cb     = str_verify_pattern_cb,
2802                 .off1   = offsetof(struct thread_options, verify_pattern),
2803                 .help   = "Fill pattern for IO buffers",
2804                 .parent = "verify",
2805                 .hide   = 1,
2806                 .category = FIO_OPT_C_IO,
2807                 .group  = FIO_OPT_G_VERIFY,
2808         },
2809         {
2810                 .name   = "verify_fatal",
2811                 .lname  = "Verify fatal",
2812                 .type   = FIO_OPT_BOOL,
2813                 .off1   = offsetof(struct thread_options, verify_fatal),
2814                 .def    = "0",
2815                 .help   = "Exit on a single verify failure, don't continue",
2816                 .parent = "verify",
2817                 .hide   = 1,
2818                 .category = FIO_OPT_C_IO,
2819                 .group  = FIO_OPT_G_VERIFY,
2820         },
2821         {
2822                 .name   = "verify_dump",
2823                 .lname  = "Verify dump",
2824                 .type   = FIO_OPT_BOOL,
2825                 .off1   = offsetof(struct thread_options, verify_dump),
2826                 .def    = "0",
2827                 .help   = "Dump contents of good and bad blocks on failure",
2828                 .parent = "verify",
2829                 .hide   = 1,
2830                 .category = FIO_OPT_C_IO,
2831                 .group  = FIO_OPT_G_VERIFY,
2832         },
2833         {
2834                 .name   = "verify_async",
2835                 .lname  = "Verify asynchronously",
2836                 .type   = FIO_OPT_INT,
2837                 .off1   = offsetof(struct thread_options, verify_async),
2838                 .def    = "0",
2839                 .help   = "Number of async verifier threads to use",
2840                 .parent = "verify",
2841                 .hide   = 1,
2842                 .category = FIO_OPT_C_IO,
2843                 .group  = FIO_OPT_G_VERIFY,
2844         },
2845         {
2846                 .name   = "verify_backlog",
2847                 .lname  = "Verify backlog",
2848                 .type   = FIO_OPT_STR_VAL,
2849                 .off1   = offsetof(struct thread_options, verify_backlog),
2850                 .help   = "Verify after this number of blocks are written",
2851                 .parent = "verify",
2852                 .hide   = 1,
2853                 .category = FIO_OPT_C_IO,
2854                 .group  = FIO_OPT_G_VERIFY,
2855         },
2856         {
2857                 .name   = "verify_backlog_batch",
2858                 .lname  = "Verify backlog batch",
2859                 .type   = FIO_OPT_INT,
2860                 .off1   = offsetof(struct thread_options, verify_batch),
2861                 .help   = "Verify this number of IO blocks",
2862                 .parent = "verify",
2863                 .hide   = 1,
2864                 .category = FIO_OPT_C_IO,
2865                 .group  = FIO_OPT_G_VERIFY,
2866         },
2867 #ifdef FIO_HAVE_CPU_AFFINITY
2868         {
2869                 .name   = "verify_async_cpus",
2870                 .lname  = "Async verify CPUs",
2871                 .type   = FIO_OPT_STR,
2872                 .cb     = str_verify_cpus_allowed_cb,
2873                 .off1   = offsetof(struct thread_options, verify_cpumask),
2874                 .help   = "Set CPUs allowed for async verify threads",
2875                 .parent = "verify_async",
2876                 .hide   = 1,
2877                 .category = FIO_OPT_C_IO,
2878                 .group  = FIO_OPT_G_VERIFY,
2879         },
2880 #else
2881         {
2882                 .name   = "verify_async_cpus",
2883                 .lname  = "Async verify CPUs",
2884                 .type   = FIO_OPT_UNSUPPORTED,
2885                 .help   = "Your platform does not support CPU affinities",
2886         },
2887 #endif
2888         {
2889                 .name   = "experimental_verify",
2890                 .lname  = "Experimental Verify",
2891                 .off1   = offsetof(struct thread_options, experimental_verify),
2892                 .type   = FIO_OPT_BOOL,
2893                 .help   = "Enable experimental verification",
2894                 .parent = "verify",
2895                 .category = FIO_OPT_C_IO,
2896                 .group  = FIO_OPT_G_VERIFY,
2897         },
2898         {
2899                 .name   = "verify_state_load",
2900                 .lname  = "Load verify state",
2901                 .off1   = offsetof(struct thread_options, verify_state),
2902                 .type   = FIO_OPT_BOOL,
2903                 .help   = "Load verify termination state",
2904                 .parent = "verify",
2905                 .category = FIO_OPT_C_IO,
2906                 .group  = FIO_OPT_G_VERIFY,
2907         },
2908         {
2909                 .name   = "verify_state_save",
2910                 .lname  = "Save verify state",
2911                 .off1   = offsetof(struct thread_options, verify_state_save),
2912                 .type   = FIO_OPT_BOOL,
2913                 .def    = "1",
2914                 .help   = "Save verify state on termination",
2915                 .parent = "verify",
2916                 .category = FIO_OPT_C_IO,
2917                 .group  = FIO_OPT_G_VERIFY,
2918         },
2919 #ifdef FIO_HAVE_TRIM
2920         {
2921                 .name   = "trim_percentage",
2922                 .lname  = "Trim percentage",
2923                 .type   = FIO_OPT_INT,
2924                 .off1   = offsetof(struct thread_options, trim_percentage),
2925                 .minval = 0,
2926                 .maxval = 100,
2927                 .help   = "Number of verify blocks to trim (i.e., discard)",
2928                 .parent = "verify",
2929                 .def    = "0",
2930                 .interval = 1,
2931                 .hide   = 1,
2932                 .category = FIO_OPT_C_IO,
2933                 .group  = FIO_OPT_G_TRIM,
2934         },
2935         {
2936                 .name   = "trim_verify_zero",
2937                 .lname  = "Verify trim zero",
2938                 .type   = FIO_OPT_BOOL,
2939                 .help   = "Verify that trimmed (i.e., discarded) blocks are returned as zeroes",
2940                 .off1   = offsetof(struct thread_options, trim_zero),
2941                 .parent = "trim_percentage",
2942                 .hide   = 1,
2943                 .def    = "1",
2944                 .category = FIO_OPT_C_IO,
2945                 .group  = FIO_OPT_G_TRIM,
2946         },
2947         {
2948                 .name   = "trim_backlog",
2949                 .lname  = "Trim backlog",
2950                 .type   = FIO_OPT_STR_VAL,
2951                 .off1   = offsetof(struct thread_options, trim_backlog),
2952                 .help   = "Trim after this number of blocks are written",
2953                 .parent = "trim_percentage",
2954                 .hide   = 1,
2955                 .interval = 1,
2956                 .category = FIO_OPT_C_IO,
2957                 .group  = FIO_OPT_G_TRIM,
2958         },
2959         {
2960                 .name   = "trim_backlog_batch",
2961                 .lname  = "Trim backlog batch",
2962                 .type   = FIO_OPT_INT,
2963                 .off1   = offsetof(struct thread_options, trim_batch),
2964                 .help   = "Trim this number of IO blocks",
2965                 .parent = "trim_percentage",
2966                 .hide   = 1,
2967                 .interval = 1,
2968                 .category = FIO_OPT_C_IO,
2969                 .group  = FIO_OPT_G_TRIM,
2970         },
2971 #else
2972         {
2973                 .name   = "trim_percentage",
2974                 .lname  = "Trim percentage",
2975                 .type   = FIO_OPT_UNSUPPORTED,
2976                 .help   = "Fio does not support TRIM on your platform",
2977         },
2978         {
2979                 .name   = "trim_verify_zero",
2980                 .lname  = "Verify trim zero",
2981                 .type   = FIO_OPT_UNSUPPORTED,
2982                 .help   = "Fio does not support TRIM on your platform",
2983         },
2984         {
2985                 .name   = "trim_backlog",
2986                 .lname  = "Trim backlog",
2987                 .type   = FIO_OPT_UNSUPPORTED,
2988                 .help   = "Fio does not support TRIM on your platform",
2989         },
2990         {
2991                 .name   = "trim_backlog_batch",
2992                 .lname  = "Trim backlog batch",
2993                 .type   = FIO_OPT_UNSUPPORTED,
2994                 .help   = "Fio does not support TRIM on your platform",
2995         },
2996 #endif
2997         {
2998                 .name   = "write_iolog",
2999                 .lname  = "Write I/O log",
3000                 .type   = FIO_OPT_STR_STORE,
3001                 .off1   = offsetof(struct thread_options, write_iolog_file),
3002                 .help   = "Store IO pattern to file",
3003                 .category = FIO_OPT_C_IO,
3004                 .group  = FIO_OPT_G_IOLOG,
3005         },
3006         {
3007                 .name   = "read_iolog",
3008                 .lname  = "Read I/O log",
3009                 .type   = FIO_OPT_STR_STORE,
3010                 .off1   = offsetof(struct thread_options, read_iolog_file),
3011                 .help   = "Playback IO pattern from file",
3012                 .category = FIO_OPT_C_IO,
3013                 .group  = FIO_OPT_G_IOLOG,
3014         },
3015         {
3016                 .name   = "replay_no_stall",
3017                 .lname  = "Don't stall on replay",
3018                 .type   = FIO_OPT_BOOL,
3019                 .off1   = offsetof(struct thread_options, no_stall),
3020                 .def    = "0",
3021                 .parent = "read_iolog",
3022                 .hide   = 1,
3023                 .help   = "Playback IO pattern file as fast as possible without stalls",
3024                 .category = FIO_OPT_C_IO,
3025                 .group  = FIO_OPT_G_IOLOG,
3026         },
3027         {
3028                 .name   = "replay_redirect",
3029                 .lname  = "Redirect device for replay",
3030                 .type   = FIO_OPT_STR_STORE,
3031                 .off1   = offsetof(struct thread_options, replay_redirect),
3032                 .parent = "read_iolog",
3033                 .hide   = 1,
3034                 .help   = "Replay all I/O onto this device, regardless of trace device",
3035                 .category = FIO_OPT_C_IO,
3036                 .group  = FIO_OPT_G_IOLOG,
3037         },
3038         {
3039                 .name   = "replay_scale",
3040                 .lname  = "Replace offset scale factor",
3041                 .type   = FIO_OPT_INT,
3042                 .off1   = offsetof(struct thread_options, replay_scale),
3043                 .parent = "read_iolog",
3044                 .def    = "1",
3045                 .help   = "Align offsets to this blocksize",
3046                 .category = FIO_OPT_C_IO,
3047                 .group  = FIO_OPT_G_IOLOG,
3048         },
3049         {
3050                 .name   = "replay_align",
3051                 .lname  = "Replace alignment",
3052                 .type   = FIO_OPT_INT,
3053                 .off1   = offsetof(struct thread_options, replay_align),
3054                 .parent = "read_iolog",
3055                 .help   = "Scale offset down by this factor",
3056                 .category = FIO_OPT_C_IO,
3057                 .group  = FIO_OPT_G_IOLOG,
3058                 .pow2   = 1,
3059         },
3060         {
3061                 .name   = "exec_prerun",
3062                 .lname  = "Pre-execute runnable",
3063                 .type   = FIO_OPT_STR_STORE,
3064                 .off1   = offsetof(struct thread_options, exec_prerun),
3065                 .help   = "Execute this file prior to running job",
3066                 .category = FIO_OPT_C_GENERAL,
3067                 .group  = FIO_OPT_G_INVALID,
3068         },
3069         {
3070                 .name   = "exec_postrun",
3071                 .lname  = "Post-execute runnable",
3072                 .type   = FIO_OPT_STR_STORE,
3073                 .off1   = offsetof(struct thread_options, exec_postrun),
3074                 .help   = "Execute this file after running job",
3075                 .category = FIO_OPT_C_GENERAL,
3076                 .group  = FIO_OPT_G_INVALID,
3077         },
3078 #ifdef FIO_HAVE_IOSCHED_SWITCH
3079         {
3080                 .name   = "ioscheduler",
3081                 .lname  = "I/O scheduler",
3082                 .type   = FIO_OPT_STR_STORE,
3083                 .off1   = offsetof(struct thread_options, ioscheduler),
3084                 .help   = "Use this IO scheduler on the backing device",
3085                 .category = FIO_OPT_C_FILE,
3086                 .group  = FIO_OPT_G_INVALID,
3087         },
3088 #else
3089         {
3090                 .name   = "ioscheduler",
3091                 .lname  = "I/O scheduler",
3092                 .type   = FIO_OPT_UNSUPPORTED,
3093                 .help   = "Your platform does not support IO scheduler switching",
3094         },
3095 #endif
3096         {
3097                 .name   = "zonesize",
3098                 .lname  = "Zone size",
3099                 .type   = FIO_OPT_STR_VAL,
3100                 .off1   = offsetof(struct thread_options, zone_size),
3101                 .help   = "Amount of data to read per zone",
3102                 .def    = "0",
3103                 .interval = 1024 * 1024,
3104                 .category = FIO_OPT_C_IO,
3105                 .group  = FIO_OPT_G_ZONE,
3106         },
3107         {
3108                 .name   = "zonerange",
3109                 .lname  = "Zone range",
3110                 .type   = FIO_OPT_STR_VAL,
3111                 .off1   = offsetof(struct thread_options, zone_range),
3112                 .help   = "Give size of an IO zone",
3113                 .def    = "0",
3114                 .interval = 1024 * 1024,
3115                 .category = FIO_OPT_C_IO,
3116                 .group  = FIO_OPT_G_ZONE,
3117         },
3118         {
3119                 .name   = "zoneskip",
3120                 .lname  = "Zone skip",
3121                 .type   = FIO_OPT_STR_VAL,
3122                 .off1   = offsetof(struct thread_options, zone_skip),
3123                 .help   = "Space between IO zones",
3124                 .def    = "0",
3125                 .interval = 1024 * 1024,
3126                 .category = FIO_OPT_C_IO,
3127                 .group  = FIO_OPT_G_ZONE,
3128         },
3129         {
3130                 .name   = "lockmem",
3131                 .lname  = "Lock memory",
3132                 .type   = FIO_OPT_STR_VAL,
3133                 .off1   = offsetof(struct thread_options, lockmem),
3134                 .help   = "Lock down this amount of memory (per worker)",
3135                 .def    = "0",
3136                 .interval = 1024 * 1024,
3137                 .category = FIO_OPT_C_GENERAL,
3138                 .group  = FIO_OPT_G_INVALID,
3139         },
3140         {
3141                 .name   = "rwmixread",
3142                 .lname  = "Read/write mix read",
3143                 .type   = FIO_OPT_INT,
3144                 .cb     = str_rwmix_read_cb,
3145                 .off1   = offsetof(struct thread_options, rwmix[DDIR_READ]),
3146                 .maxval = 100,
3147                 .help   = "Percentage of mixed workload that is reads",
3148                 .def    = "50",
3149                 .interval = 5,
3150                 .inverse = "rwmixwrite",
3151                 .category = FIO_OPT_C_IO,
3152                 .group  = FIO_OPT_G_RWMIX,
3153         },
3154         {
3155                 .name   = "rwmixwrite",
3156                 .lname  = "Read/write mix write",
3157                 .type   = FIO_OPT_INT,
3158                 .cb     = str_rwmix_write_cb,
3159                 .off1   = offsetof(struct thread_options, rwmix[DDIR_WRITE]),
3160                 .maxval = 100,
3161                 .help   = "Percentage of mixed workload that is writes",
3162                 .def    = "50",
3163                 .interval = 5,
3164                 .inverse = "rwmixread",
3165                 .category = FIO_OPT_C_IO,
3166                 .group  = FIO_OPT_G_RWMIX,
3167         },
3168         {
3169                 .name   = "rwmixcycle",
3170                 .lname  = "Read/write mix cycle",
3171                 .type   = FIO_OPT_DEPRECATED,
3172                 .category = FIO_OPT_C_IO,
3173                 .group  = FIO_OPT_G_RWMIX,
3174         },
3175         {
3176                 .name   = "nice",
3177                 .lname  = "Nice",
3178                 .type   = FIO_OPT_INT,
3179                 .off1   = offsetof(struct thread_options, nice),
3180                 .help   = "Set job CPU nice value",
3181                 .minval = -19,
3182                 .maxval = 20,
3183                 .def    = "0",
3184                 .interval = 1,
3185                 .category = FIO_OPT_C_GENERAL,
3186                 .group  = FIO_OPT_G_CRED,
3187         },
3188 #ifdef FIO_HAVE_IOPRIO
3189         {
3190                 .name   = "prio",
3191                 .lname  = "I/O nice priority",
3192                 .type   = FIO_OPT_INT,
3193                 .off1   = offsetof(struct thread_options, ioprio),
3194                 .help   = "Set job IO priority value",
3195                 .minval = IOPRIO_MIN_PRIO,
3196                 .maxval = IOPRIO_MAX_PRIO,
3197                 .interval = 1,
3198                 .category = FIO_OPT_C_GENERAL,
3199                 .group  = FIO_OPT_G_CRED,
3200         },
3201 #else
3202         {
3203                 .name   = "prio",
3204                 .lname  = "I/O nice priority",
3205                 .type   = FIO_OPT_UNSUPPORTED,
3206                 .help   = "Your platform does not support IO priorities",
3207         },
3208 #endif
3209 #ifdef FIO_HAVE_IOPRIO_CLASS
3210 #ifndef FIO_HAVE_IOPRIO
3211 #error "FIO_HAVE_IOPRIO_CLASS requires FIO_HAVE_IOPRIO"
3212 #endif
3213         {
3214                 .name   = "prioclass",
3215                 .lname  = "I/O nice priority class",
3216                 .type   = FIO_OPT_INT,
3217                 .off1   = offsetof(struct thread_options, ioprio_class),
3218                 .help   = "Set job IO priority class",
3219                 .minval = IOPRIO_MIN_PRIO_CLASS,
3220                 .maxval = IOPRIO_MAX_PRIO_CLASS,
3221                 .interval = 1,
3222                 .category = FIO_OPT_C_GENERAL,
3223                 .group  = FIO_OPT_G_CRED,
3224         },
3225 #else
3226         {
3227                 .name   = "prioclass",
3228                 .lname  = "I/O nice priority class",
3229                 .type   = FIO_OPT_UNSUPPORTED,
3230                 .help   = "Your platform does not support IO priority classes",
3231         },
3232 #endif
3233         {
3234                 .name   = "thinktime",
3235                 .lname  = "Thinktime",
3236                 .type   = FIO_OPT_INT,
3237                 .off1   = offsetof(struct thread_options, thinktime),
3238                 .help   = "Idle time between IO buffers (usec)",
3239                 .def    = "0",
3240                 .is_time = 1,
3241                 .category = FIO_OPT_C_IO,
3242                 .group  = FIO_OPT_G_THINKTIME,
3243         },
3244         {
3245                 .name   = "thinktime_spin",
3246                 .lname  = "Thinktime spin",
3247                 .type   = FIO_OPT_INT,
3248                 .off1   = offsetof(struct thread_options, thinktime_spin),
3249                 .help   = "Start think time by spinning this amount (usec)",
3250                 .def    = "0",
3251                 .is_time = 1,
3252                 .parent = "thinktime",
3253                 .hide   = 1,
3254                 .category = FIO_OPT_C_IO,
3255                 .group  = FIO_OPT_G_THINKTIME,
3256         },
3257         {
3258                 .name   = "thinktime_blocks",
3259                 .lname  = "Thinktime blocks",
3260                 .type   = FIO_OPT_INT,
3261                 .off1   = offsetof(struct thread_options, thinktime_blocks),
3262                 .help   = "IO buffer period between 'thinktime'",
3263                 .def    = "1",
3264                 .parent = "thinktime",
3265                 .hide   = 1,
3266                 .category = FIO_OPT_C_IO,
3267                 .group  = FIO_OPT_G_THINKTIME,
3268         },
3269         {
3270                 .name   = "rate",
3271                 .lname  = "I/O rate",
3272                 .type   = FIO_OPT_INT,
3273                 .off1   = offsetof(struct thread_options, rate[DDIR_READ]),
3274                 .off2   = offsetof(struct thread_options, rate[DDIR_WRITE]),
3275                 .off3   = offsetof(struct thread_options, rate[DDIR_TRIM]),
3276                 .help   = "Set bandwidth rate",
3277                 .category = FIO_OPT_C_IO,
3278                 .group  = FIO_OPT_G_RATE,
3279         },
3280         {
3281                 .name   = "rate_min",
3282                 .alias  = "ratemin",
3283                 .lname  = "I/O min rate",
3284                 .type   = FIO_OPT_INT,
3285                 .off1   = offsetof(struct thread_options, ratemin[DDIR_READ]),
3286                 .off2   = offsetof(struct thread_options, ratemin[DDIR_WRITE]),
3287                 .off3   = offsetof(struct thread_options, ratemin[DDIR_TRIM]),
3288                 .help   = "Job must meet this rate or it will be shutdown",
3289                 .parent = "rate",
3290                 .hide   = 1,
3291                 .category = FIO_OPT_C_IO,
3292                 .group  = FIO_OPT_G_RATE,
3293         },
3294         {
3295                 .name   = "rate_iops",
3296                 .lname  = "I/O rate IOPS",
3297                 .type   = FIO_OPT_INT,
3298                 .off1   = offsetof(struct thread_options, rate_iops[DDIR_READ]),
3299                 .off2   = offsetof(struct thread_options, rate_iops[DDIR_WRITE]),
3300                 .off3   = offsetof(struct thread_options, rate_iops[DDIR_TRIM]),
3301                 .help   = "Limit IO used to this number of IO operations/sec",
3302                 .hide   = 1,
3303                 .category = FIO_OPT_C_IO,
3304                 .group  = FIO_OPT_G_RATE,
3305         },
3306         {
3307                 .name   = "rate_iops_min",
3308                 .lname  = "I/O min rate IOPS",
3309                 .type   = FIO_OPT_INT,
3310                 .off1   = offsetof(struct thread_options, rate_iops_min[DDIR_READ]),
3311                 .off2   = offsetof(struct thread_options, rate_iops_min[DDIR_WRITE]),
3312                 .off3   = offsetof(struct thread_options, rate_iops_min[DDIR_TRIM]),
3313                 .help   = "Job must meet this rate or it will be shut down",
3314                 .parent = "rate_iops",
3315                 .hide   = 1,
3316                 .category = FIO_OPT_C_IO,
3317                 .group  = FIO_OPT_G_RATE,
3318         },
3319         {
3320                 .name   = "rate_process",
3321                 .lname  = "Rate Process",
3322                 .type   = FIO_OPT_STR,
3323                 .off1   = offsetof(struct thread_options, rate_process),
3324                 .help   = "What process controls how rated IO is managed",
3325                 .def    = "linear",
3326                 .category = FIO_OPT_C_IO,
3327                 .group  = FIO_OPT_G_RATE,
3328                 .posval = {
3329                           { .ival = "linear",
3330                             .oval = RATE_PROCESS_LINEAR,
3331                             .help = "Linear rate of IO",
3332                           },
3333                           {
3334                             .ival = "poisson",
3335                             .oval = RATE_PROCESS_POISSON,
3336                             .help = "Rate follows Poisson process",
3337                           },
3338                 },
3339                 .parent = "rate",
3340         },
3341         {
3342                 .name   = "rate_cycle",
3343                 .alias  = "ratecycle",
3344                 .lname  = "I/O rate cycle",
3345                 .type   = FIO_OPT_INT,
3346                 .off1   = offsetof(struct thread_options, ratecycle),
3347                 .help   = "Window average for rate limits (msec)",
3348                 .def    = "1000",
3349                 .parent = "rate",
3350                 .hide   = 1,
3351                 .category = FIO_OPT_C_IO,
3352                 .group  = FIO_OPT_G_RATE,
3353         },
3354         {
3355                 .name   = "max_latency",
3356                 .lname  = "Max Latency",
3357                 .type   = FIO_OPT_INT,
3358                 .off1   = offsetof(struct thread_options, max_latency),
3359                 .help   = "Maximum tolerated IO latency (usec)",
3360                 .is_time = 1,
3361                 .category = FIO_OPT_C_IO,
3362                 .group = FIO_OPT_G_LATPROF,
3363         },
3364         {
3365                 .name   = "latency_target",
3366                 .lname  = "Latency Target (usec)",
3367                 .type   = FIO_OPT_STR_VAL_TIME,
3368                 .off1   = offsetof(struct thread_options, latency_target),
3369                 .help   = "Ramp to max queue depth supporting this latency",
3370                 .is_time = 1,
3371                 .category = FIO_OPT_C_IO,
3372                 .group  = FIO_OPT_G_LATPROF,
3373         },
3374         {
3375                 .name   = "latency_window",
3376                 .lname  = "Latency Window (usec)",
3377                 .type   = FIO_OPT_STR_VAL_TIME,
3378                 .off1   = offsetof(struct thread_options, latency_window),
3379                 .help   = "Time to sustain latency_target",
3380                 .is_time = 1,
3381                 .category = FIO_OPT_C_IO,
3382                 .group  = FIO_OPT_G_LATPROF,
3383         },
3384         {
3385                 .name   = "latency_percentile",
3386                 .lname  = "Latency Percentile",
3387                 .type   = FIO_OPT_FLOAT_LIST,
3388                 .off1   = offsetof(struct thread_options, latency_percentile),
3389                 .help   = "Percentile of IOs must be below latency_target",
3390                 .def    = "100",
3391                 .maxlen = 1,
3392                 .minfp  = 0.0,
3393                 .maxfp  = 100.0,
3394                 .category = FIO_OPT_C_IO,
3395                 .group  = FIO_OPT_G_LATPROF,
3396         },
3397         {
3398                 .name   = "invalidate",
3399                 .lname  = "Cache invalidate",
3400                 .type   = FIO_OPT_BOOL,
3401                 .off1   = offsetof(struct thread_options, invalidate_cache),
3402                 .help   = "Invalidate buffer/page cache prior to running job",
3403                 .def    = "1",
3404                 .category = FIO_OPT_C_IO,
3405                 .group  = FIO_OPT_G_IO_TYPE,
3406         },
3407         {
3408                 .name   = "sync",
3409                 .lname  = "Synchronous I/O",
3410                 .type   = FIO_OPT_BOOL,
3411                 .off1   = offsetof(struct thread_options, sync_io),
3412                 .help   = "Use O_SYNC for buffered writes",
3413                 .def    = "0",
3414                 .parent = "buffered",
3415                 .hide   = 1,
3416                 .category = FIO_OPT_C_IO,
3417                 .group  = FIO_OPT_G_IO_TYPE,
3418         },
3419 #ifdef FIO_HAVE_WRITE_HINT
3420         {
3421                 .name   = "write_hint",
3422                 .lname  = "Write hint",
3423                 .type   = FIO_OPT_STR,
3424                 .off1   = offsetof(struct thread_options, write_hint),
3425                 .help   = "Set expected write life time",
3426                 .category = FIO_OPT_C_ENGINE,
3427                 .group  = FIO_OPT_G_INVALID,
3428                 .posval = {
3429                           { .ival = "none",
3430                             .oval = RWH_WRITE_LIFE_NONE,
3431                           },
3432                           { .ival = "short",
3433                             .oval = RWH_WRITE_LIFE_SHORT,
3434                           },
3435                           { .ival = "medium",
3436                             .oval = RWH_WRITE_LIFE_MEDIUM,
3437                           },
3438                           { .ival = "long",
3439                             .oval = RWH_WRITE_LIFE_LONG,
3440                           },
3441                           { .ival = "extreme",
3442                             .oval = RWH_WRITE_LIFE_EXTREME,
3443                           },
3444                 },
3445         },
3446 #endif
3447         {
3448                 .name   = "create_serialize",
3449                 .lname  = "Create serialize",
3450                 .type   = FIO_OPT_BOOL,
3451                 .off1   = offsetof(struct thread_options, create_serialize),
3452                 .help   = "Serialize creation of job files",
3453                 .def    = "1",
3454                 .category = FIO_OPT_C_FILE,
3455                 .group  = FIO_OPT_G_INVALID,
3456         },
3457         {
3458                 .name   = "create_fsync",
3459                 .lname  = "Create fsync",
3460                 .type   = FIO_OPT_BOOL,
3461                 .off1   = offsetof(struct thread_options, create_fsync),
3462                 .help   = "fsync file after creation",
3463                 .def    = "1",
3464                 .category = FIO_OPT_C_FILE,
3465                 .group  = FIO_OPT_G_INVALID,
3466         },
3467         {
3468                 .name   = "create_on_open",
3469                 .lname  = "Create on open",
3470                 .type   = FIO_OPT_BOOL,
3471                 .off1   = offsetof(struct thread_options, create_on_open),
3472                 .help   = "Create files when they are opened for IO",
3473                 .def    = "0",
3474                 .category = FIO_OPT_C_FILE,
3475                 .group  = FIO_OPT_G_INVALID,
3476         },
3477         {
3478                 .name   = "create_only",
3479                 .lname  = "Create Only",
3480                 .type   = FIO_OPT_BOOL,
3481                 .off1   = offsetof(struct thread_options, create_only),
3482                 .help   = "Only perform file creation phase",
3483                 .category = FIO_OPT_C_FILE,
3484                 .def    = "0",
3485         },
3486         {
3487                 .name   = "allow_file_create",
3488                 .lname  = "Allow file create",
3489                 .type   = FIO_OPT_BOOL,
3490                 .off1   = offsetof(struct thread_options, allow_create),
3491                 .help   = "Permit fio to create files, if they don't exist",
3492                 .def    = "1",
3493                 .category = FIO_OPT_C_FILE,
3494                 .group  = FIO_OPT_G_FILENAME,
3495         },
3496         {
3497                 .name   = "allow_mounted_write",
3498                 .lname  = "Allow mounted write",
3499                 .type   = FIO_OPT_BOOL,
3500                 .off1   = offsetof(struct thread_options, allow_mounted_write),
3501                 .help   = "Allow writes to a mounted partition",
3502                 .def    = "0",
3503                 .category = FIO_OPT_C_FILE,
3504                 .group  = FIO_OPT_G_FILENAME,
3505         },
3506         {
3507                 .name   = "pre_read",
3508                 .lname  = "Pre-read files",
3509                 .type   = FIO_OPT_BOOL,
3510                 .off1   = offsetof(struct thread_options, pre_read),
3511                 .help   = "Pre-read files before starting official testing",
3512                 .def    = "0",
3513                 .category = FIO_OPT_C_FILE,
3514                 .group  = FIO_OPT_G_INVALID,
3515         },
3516 #ifdef FIO_HAVE_CPU_AFFINITY
3517         {
3518                 .name   = "cpumask",
3519                 .lname  = "CPU mask",
3520                 .type   = FIO_OPT_INT,
3521                 .cb     = str_cpumask_cb,
3522                 .off1   = offsetof(struct thread_options, cpumask),
3523                 .help   = "CPU affinity mask",
3524                 .category = FIO_OPT_C_GENERAL,
3525                 .group  = FIO_OPT_G_CRED,
3526         },
3527         {
3528                 .name   = "cpus_allowed",
3529                 .lname  = "CPUs allowed",
3530                 .type   = FIO_OPT_STR,
3531                 .cb     = str_cpus_allowed_cb,
3532                 .off1   = offsetof(struct thread_options, cpumask),
3533                 .help   = "Set CPUs allowed",
3534                 .category = FIO_OPT_C_GENERAL,
3535                 .group  = FIO_OPT_G_CRED,
3536         },
3537         {
3538                 .name   = "cpus_allowed_policy",
3539                 .lname  = "CPUs allowed distribution policy",
3540                 .type   = FIO_OPT_STR,
3541                 .off1   = offsetof(struct thread_options, cpus_allowed_policy),
3542                 .help   = "Distribution policy for cpus_allowed",
3543                 .parent = "cpus_allowed",
3544                 .prio   = 1,
3545                 .posval = {
3546                           { .ival = "shared",
3547                             .oval = FIO_CPUS_SHARED,
3548                             .help = "Mask shared between threads",
3549                           },
3550                           { .ival = "split",
3551                             .oval = FIO_CPUS_SPLIT,
3552                             .help = "Mask split between threads",
3553                           },
3554                 },
3555                 .category = FIO_OPT_C_GENERAL,
3556                 .group  = FIO_OPT_G_CRED,
3557         },
3558 #else
3559         {
3560                 .name   = "cpumask",
3561                 .lname  = "CPU mask",
3562                 .type   = FIO_OPT_UNSUPPORTED,
3563                 .help   = "Your platform does not support CPU affinities",
3564         },
3565         {
3566                 .name   = "cpus_allowed",
3567                 .lname  = "CPUs allowed",
3568                 .type   = FIO_OPT_UNSUPPORTED,
3569                 .help   = "Your platform does not support CPU affinities",
3570         },
3571         {
3572                 .name   = "cpus_allowed_policy",
3573                 .lname  = "CPUs allowed distribution policy",
3574                 .type   = FIO_OPT_UNSUPPORTED,
3575                 .help   = "Your platform does not support CPU affinities",
3576         },
3577 #endif
3578 #ifdef CONFIG_LIBNUMA
3579         {
3580                 .name   = "numa_cpu_nodes",
3581                 .lname  = "NUMA CPU Nodes",
3582                 .type   = FIO_OPT_STR,
3583                 .cb     = str_numa_cpunodes_cb,
3584                 .off1   = offsetof(struct thread_options, numa_cpunodes),
3585                 .help   = "NUMA CPU nodes bind",
3586                 .category = FIO_OPT_C_GENERAL,
3587                 .group  = FIO_OPT_G_INVALID,
3588         },
3589         {
3590                 .name   = "numa_mem_policy",
3591                 .lname  = "NUMA Memory Policy",
3592                 .type   = FIO_OPT_STR,
3593                 .cb     = str_numa_mpol_cb,
3594                 .off1   = offsetof(struct thread_options, numa_memnodes),
3595                 .help   = "NUMA memory policy setup",
3596                 .category = FIO_OPT_C_GENERAL,
3597                 .group  = FIO_OPT_G_INVALID,
3598         },
3599 #else
3600         {
3601                 .name   = "numa_cpu_nodes",
3602                 .lname  = "NUMA CPU Nodes",
3603                 .type   = FIO_OPT_UNSUPPORTED,
3604                 .help   = "Build fio with libnuma-dev(el) to enable this option",
3605         },
3606         {
3607                 .name   = "numa_mem_policy",
3608                 .lname  = "NUMA Memory Policy",
3609                 .type   = FIO_OPT_UNSUPPORTED,
3610                 .help   = "Build fio with libnuma-dev(el) to enable this option",
3611         },
3612 #endif
3613 #ifdef CONFIG_CUDA
3614         {
3615                 .name   = "gpu_dev_id",
3616                 .lname  = "GPU device ID",
3617                 .type   = FIO_OPT_INT,
3618                 .off1   = offsetof(struct thread_options, gpu_dev_id),
3619                 .help   = "Set GPU device ID for GPUDirect RDMA",
3620                 .def    = "0",
3621                 .category = FIO_OPT_C_GENERAL,
3622                 .group  = FIO_OPT_G_INVALID,
3623         },
3624 #endif
3625         {
3626                 .name   = "end_fsync",
3627                 .lname  = "End fsync",
3628                 .type   = FIO_OPT_BOOL,
3629                 .off1   = offsetof(struct thread_options, end_fsync),
3630                 .help   = "Include fsync at the end of job",
3631                 .def    = "0",
3632                 .category = FIO_OPT_C_FILE,
3633                 .group  = FIO_OPT_G_INVALID,
3634         },
3635         {
3636                 .name   = "fsync_on_close",
3637                 .lname  = "Fsync on close",
3638                 .type   = FIO_OPT_BOOL,
3639                 .off1   = offsetof(struct thread_options, fsync_on_close),
3640                 .help   = "fsync files on close",
3641                 .def    = "0",
3642                 .category = FIO_OPT_C_FILE,
3643                 .group  = FIO_OPT_G_INVALID,
3644         },
3645         {
3646                 .name   = "unlink",
3647                 .lname  = "Unlink file",
3648                 .type   = FIO_OPT_BOOL,
3649                 .off1   = offsetof(struct thread_options, unlink),
3650                 .help   = "Unlink created files after job has completed",
3651                 .def    = "0",
3652                 .category = FIO_OPT_C_FILE,
3653                 .group  = FIO_OPT_G_INVALID,
3654         },
3655         {
3656                 .name   = "unlink_each_loop",
3657                 .lname  = "Unlink file after each loop of a job",
3658                 .type   = FIO_OPT_BOOL,
3659                 .off1   = offsetof(struct thread_options, unlink_each_loop),
3660                 .help   = "Unlink created files after each loop in a job has completed",
3661                 .def    = "0",
3662                 .category = FIO_OPT_C_FILE,
3663                 .group  = FIO_OPT_G_INVALID,
3664         },
3665         {
3666                 .name   = "exitall",
3667                 .lname  = "Exit-all on terminate",
3668                 .type   = FIO_OPT_STR_SET,
3669                 .cb     = str_exitall_cb,
3670                 .help   = "Terminate all jobs when one exits",
3671                 .category = FIO_OPT_C_GENERAL,
3672                 .group  = FIO_OPT_G_PROCESS,
3673         },
3674         {
3675                 .name   = "exitall_on_error",
3676                 .lname  = "Exit-all on terminate in error",
3677                 .type   = FIO_OPT_STR_SET,
3678                 .off1   = offsetof(struct thread_options, exitall_error),
3679                 .help   = "Terminate all jobs when one exits in error",
3680                 .category = FIO_OPT_C_GENERAL,
3681                 .group  = FIO_OPT_G_PROCESS,
3682         },
3683         {
3684                 .name   = "stonewall",
3685                 .lname  = "Wait for previous",
3686                 .alias  = "wait_for_previous",
3687                 .type   = FIO_OPT_STR_SET,
3688                 .off1   = offsetof(struct thread_options, stonewall),
3689                 .help   = "Insert a hard barrier between this job and previous",
3690                 .category = FIO_OPT_C_GENERAL,
3691                 .group  = FIO_OPT_G_PROCESS,
3692         },
3693         {
3694                 .name   = "new_group",
3695                 .lname  = "New group",
3696                 .type   = FIO_OPT_STR_SET,
3697                 .off1   = offsetof(struct thread_options, new_group),
3698                 .help   = "Mark the start of a new group (for reporting)",
3699                 .category = FIO_OPT_C_GENERAL,
3700                 .group  = FIO_OPT_G_PROCESS,
3701         },
3702         {
3703                 .name   = "thread",
3704                 .lname  = "Thread",
3705                 .type   = FIO_OPT_STR_SET,
3706                 .off1   = offsetof(struct thread_options, use_thread),
3707                 .help   = "Use threads instead of processes",
3708 #ifdef CONFIG_NO_SHM
3709                 .def    = "1",
3710                 .no_warn_def = 1,
3711 #endif
3712                 .category = FIO_OPT_C_GENERAL,
3713                 .group  = FIO_OPT_G_PROCESS,
3714         },
3715         {
3716                 .name   = "per_job_logs",
3717                 .lname  = "Per Job Logs",
3718                 .type   = FIO_OPT_BOOL,
3719                 .off1   = offsetof(struct thread_options, per_job_logs),
3720                 .help   = "Include job number in generated log files or not",
3721                 .def    = "1",
3722                 .category = FIO_OPT_C_LOG,
3723                 .group  = FIO_OPT_G_INVALID,
3724         },
3725         {
3726                 .name   = "write_bw_log",
3727                 .lname  = "Write bandwidth log",
3728                 .type   = FIO_OPT_STR,
3729                 .off1   = offsetof(struct thread_options, bw_log_file),
3730                 .cb     = str_write_bw_log_cb,
3731                 .help   = "Write log of bandwidth during run",
3732                 .category = FIO_OPT_C_LOG,
3733                 .group  = FIO_OPT_G_INVALID,
3734         },
3735         {
3736                 .name   = "write_lat_log",
3737                 .lname  = "Write latency log",
3738                 .type   = FIO_OPT_STR,
3739                 .off1   = offsetof(struct thread_options, lat_log_file),
3740                 .cb     = str_write_lat_log_cb,
3741                 .help   = "Write log of latency during run",
3742                 .category = FIO_OPT_C_LOG,
3743                 .group  = FIO_OPT_G_INVALID,
3744         },
3745         {
3746                 .name   = "write_iops_log",
3747                 .lname  = "Write IOPS log",
3748                 .type   = FIO_OPT_STR,
3749                 .off1   = offsetof(struct thread_options, iops_log_file),
3750                 .cb     = str_write_iops_log_cb,
3751                 .help   = "Write log of IOPS during run",
3752                 .category = FIO_OPT_C_LOG,
3753                 .group  = FIO_OPT_G_INVALID,
3754         },
3755         {
3756                 .name   = "log_avg_msec",
3757                 .lname  = "Log averaging (msec)",
3758                 .type   = FIO_OPT_INT,
3759                 .off1   = offsetof(struct thread_options, log_avg_msec),
3760                 .help   = "Average bw/iops/lat logs over this period of time",
3761                 .def    = "0",
3762                 .category = FIO_OPT_C_LOG,
3763                 .group  = FIO_OPT_G_INVALID,
3764         },
3765         {
3766                 .name   = "log_hist_msec",
3767                 .lname  = "Log histograms (msec)",
3768                 .type   = FIO_OPT_INT,
3769                 .off1   = offsetof(struct thread_options, log_hist_msec),
3770                 .help   = "Dump completion latency histograms at frequency of this time value",
3771                 .def    = "0",
3772                 .category = FIO_OPT_C_LOG,
3773                 .group  = FIO_OPT_G_INVALID,
3774         },
3775         {
3776                 .name   = "log_hist_coarseness",
3777                 .lname  = "Histogram logs coarseness",
3778                 .type   = FIO_OPT_INT,
3779                 .off1   = offsetof(struct thread_options, log_hist_coarseness),
3780                 .help   = "Integer in range [0,6]. Higher coarseness outputs"
3781                         " fewer histogram bins per sample. The number of bins for"
3782                         " these are [1216, 608, 304, 152, 76, 38, 19] respectively.",
3783                 .def    = "0",
3784                 .category = FIO_OPT_C_LOG,
3785                 .group  = FIO_OPT_G_INVALID,
3786         },
3787         {
3788                 .name   = "write_hist_log",
3789                 .lname  = "Write latency histogram logs",
3790                 .type   = FIO_OPT_STR,
3791                 .off1   = offsetof(struct thread_options, hist_log_file),
3792                 .cb     = str_write_hist_log_cb,
3793                 .help   = "Write log of latency histograms during run",
3794                 .category = FIO_OPT_C_LOG,
3795                 .group  = FIO_OPT_G_INVALID,
3796         },
3797         {
3798                 .name   = "log_max_value",
3799                 .lname  = "Log maximum instead of average",
3800                 .type   = FIO_OPT_BOOL,
3801                 .off1   = offsetof(struct thread_options, log_max),
3802                 .help   = "Log max sample in a window instead of average",
3803                 .def    = "0",
3804                 .category = FIO_OPT_C_LOG,
3805                 .group  = FIO_OPT_G_INVALID,
3806         },
3807         {
3808                 .name   = "log_offset",
3809                 .lname  = "Log offset of IO",
3810                 .type   = FIO_OPT_BOOL,
3811                 .off1   = offsetof(struct thread_options, log_offset),
3812                 .help   = "Include offset of IO for each log entry",
3813                 .def    = "0",
3814                 .category = FIO_OPT_C_LOG,
3815                 .group  = FIO_OPT_G_INVALID,
3816         },
3817 #ifdef CONFIG_ZLIB
3818         {
3819                 .name   = "log_compression",
3820                 .lname  = "Log compression",
3821                 .type   = FIO_OPT_INT,
3822                 .off1   = offsetof(struct thread_options, log_gz),
3823                 .help   = "Log in compressed chunks of this size",
3824                 .minval = 1024ULL,
3825                 .maxval = 512 * 1024 * 1024ULL,
3826                 .category = FIO_OPT_C_LOG,
3827                 .group  = FIO_OPT_G_INVALID,
3828         },
3829 #ifdef FIO_HAVE_CPU_AFFINITY
3830         {
3831                 .name   = "log_compression_cpus",
3832                 .lname  = "Log Compression CPUs",
3833                 .type   = FIO_OPT_STR,
3834                 .cb     = str_log_cpus_allowed_cb,
3835                 .off1   = offsetof(struct thread_options, log_gz_cpumask),
3836                 .parent = "log_compression",
3837                 .help   = "Limit log compression to these CPUs",
3838                 .category = FIO_OPT_C_LOG,
3839                 .group  = FIO_OPT_G_INVALID,
3840         },
3841 #else
3842         {
3843                 .name   = "log_compression_cpus",
3844                 .lname  = "Log Compression CPUs",
3845                 .type   = FIO_OPT_UNSUPPORTED,
3846                 .help   = "Your platform does not support CPU affinities",
3847         },
3848 #endif
3849         {
3850                 .name   = "log_store_compressed",
3851                 .lname  = "Log store compressed",
3852                 .type   = FIO_OPT_BOOL,
3853                 .off1   = offsetof(struct thread_options, log_gz_store),
3854                 .help   = "Store logs in a compressed format",
3855                 .category = FIO_OPT_C_LOG,
3856                 .group  = FIO_OPT_G_INVALID,
3857         },
3858 #else
3859         {
3860                 .name   = "log_compression",
3861                 .lname  = "Log compression",
3862                 .type   = FIO_OPT_UNSUPPORTED,
3863                 .help   = "Install libz-dev(el) to get compression support",
3864         },
3865         {
3866                 .name   = "log_store_compressed",
3867                 .lname  = "Log store compressed",
3868                 .type   = FIO_OPT_UNSUPPORTED,
3869                 .help   = "Install libz-dev(el) to get compression support",
3870         },
3871 #endif
3872         {
3873                 .name = "log_unix_epoch",
3874                 .lname = "Log epoch unix",
3875                 .type = FIO_OPT_BOOL,
3876                 .off1 = offsetof(struct thread_options, log_unix_epoch),
3877                 .help = "Use Unix time in log files",
3878                 .category = FIO_OPT_C_LOG,
3879                 .group = FIO_OPT_G_INVALID,
3880         },
3881         {
3882                 .name   = "block_error_percentiles",
3883                 .lname  = "Block error percentiles",
3884                 .type   = FIO_OPT_BOOL,
3885                 .off1   = offsetof(struct thread_options, block_error_hist),
3886                 .help   = "Record trim block errors and make a histogram",
3887                 .def    = "0",
3888                 .category = FIO_OPT_C_LOG,
3889                 .group  = FIO_OPT_G_INVALID,
3890         },
3891         {
3892                 .name   = "bwavgtime",
3893                 .lname  = "Bandwidth average time",
3894                 .type   = FIO_OPT_INT,
3895                 .off1   = offsetof(struct thread_options, bw_avg_time),
3896                 .help   = "Time window over which to calculate bandwidth"
3897                           " (msec)",
3898                 .def    = "500",
3899                 .parent = "write_bw_log",
3900                 .hide   = 1,
3901                 .interval = 100,
3902                 .category = FIO_OPT_C_LOG,
3903                 .group  = FIO_OPT_G_INVALID,
3904         },
3905         {
3906                 .name   = "iopsavgtime",
3907                 .lname  = "IOPS average time",
3908                 .type   = FIO_OPT_INT,
3909                 .off1   = offsetof(struct thread_options, iops_avg_time),
3910                 .help   = "Time window over which to calculate IOPS (msec)",
3911                 .def    = "500",
3912                 .parent = "write_iops_log",
3913                 .hide   = 1,
3914                 .interval = 100,
3915                 .category = FIO_OPT_C_LOG,
3916                 .group  = FIO_OPT_G_INVALID,
3917         },
3918         {
3919                 .name   = "group_reporting",
3920                 .lname  = "Group reporting",
3921                 .type   = FIO_OPT_STR_SET,
3922                 .off1   = offsetof(struct thread_options, group_reporting),
3923                 .help   = "Do reporting on a per-group basis",
3924                 .category = FIO_OPT_C_STAT,
3925                 .group  = FIO_OPT_G_INVALID,
3926         },
3927         {
3928                 .name   = "stats",
3929                 .lname  = "Stats",
3930                 .type   = FIO_OPT_BOOL,
3931                 .off1   = offsetof(struct thread_options, stats),
3932                 .help   = "Enable collection of stats",
3933                 .def    = "1",
3934                 .category = FIO_OPT_C_STAT,
3935                 .group  = FIO_OPT_G_INVALID,
3936         },
3937         {
3938                 .name   = "zero_buffers",
3939                 .lname  = "Zero I/O buffers",
3940                 .type   = FIO_OPT_STR_SET,
3941                 .off1   = offsetof(struct thread_options, zero_buffers),
3942                 .help   = "Init IO buffers to all zeroes",
3943                 .category = FIO_OPT_C_IO,
3944                 .group  = FIO_OPT_G_IO_BUF,
3945         },
3946         {
3947                 .name   = "refill_buffers",
3948                 .lname  = "Refill I/O buffers",
3949                 .type   = FIO_OPT_STR_SET,
3950                 .off1   = offsetof(struct thread_options, refill_buffers),
3951                 .help   = "Refill IO buffers on every IO submit",
3952                 .category = FIO_OPT_C_IO,
3953                 .group  = FIO_OPT_G_IO_BUF,
3954         },
3955         {
3956                 .name   = "scramble_buffers",
3957                 .lname  = "Scramble I/O buffers",
3958                 .type   = FIO_OPT_BOOL,
3959                 .off1   = offsetof(struct thread_options, scramble_buffers),
3960                 .help   = "Slightly scramble buffers on every IO submit",
3961                 .def    = "1",
3962                 .category = FIO_OPT_C_IO,
3963                 .group  = FIO_OPT_G_IO_BUF,
3964         },
3965         {
3966                 .name   = "buffer_pattern",
3967                 .lname  = "Buffer pattern",
3968                 .type   = FIO_OPT_STR,
3969                 .cb     = str_buffer_pattern_cb,
3970                 .off1   = offsetof(struct thread_options, buffer_pattern),
3971                 .help   = "Fill pattern for IO buffers",
3972                 .category = FIO_OPT_C_IO,
3973                 .group  = FIO_OPT_G_IO_BUF,
3974         },
3975         {
3976                 .name   = "buffer_compress_percentage",
3977                 .lname  = "Buffer compression percentage",
3978                 .type   = FIO_OPT_INT,
3979                 .cb     = str_buffer_compress_cb,
3980                 .off1   = offsetof(struct thread_options, compress_percentage),
3981                 .maxval = 100,
3982                 .minval = 0,
3983                 .help   = "How compressible the buffer is (approximately)",
3984                 .interval = 5,
3985                 .category = FIO_OPT_C_IO,
3986                 .group  = FIO_OPT_G_IO_BUF,
3987         },
3988         {
3989                 .name   = "buffer_compress_chunk",
3990                 .lname  = "Buffer compression chunk size",
3991                 .type   = FIO_OPT_INT,
3992                 .off1   = offsetof(struct thread_options, compress_chunk),
3993                 .parent = "buffer_compress_percentage",
3994                 .hide   = 1,
3995                 .help   = "Size of compressible region in buffer",
3996                 .interval = 256,
3997                 .category = FIO_OPT_C_IO,
3998                 .group  = FIO_OPT_G_IO_BUF,
3999         },
4000         {
4001                 .name   = "dedupe_percentage",
4002                 .lname  = "Dedupe percentage",
4003                 .type   = FIO_OPT_INT,
4004                 .cb     = str_dedupe_cb,
4005                 .off1   = offsetof(struct thread_options, dedupe_percentage),
4006                 .maxval = 100,
4007                 .minval = 0,
4008                 .help   = "Percentage of buffers that are dedupable",
4009                 .interval = 1,
4010                 .category = FIO_OPT_C_IO,
4011                 .group  = FIO_OPT_G_IO_BUF,
4012         },
4013         {
4014                 .name   = "clat_percentiles",
4015                 .lname  = "Completion latency percentiles",
4016                 .type   = FIO_OPT_BOOL,
4017                 .off1   = offsetof(struct thread_options, clat_percentiles),
4018                 .help   = "Enable the reporting of completion latency percentiles",
4019                 .def    = "1",
4020                 .category = FIO_OPT_C_STAT,
4021                 .group  = FIO_OPT_G_INVALID,
4022         },
4023         {
4024                 .name   = "percentile_list",
4025                 .lname  = "Percentile list",
4026                 .type   = FIO_OPT_FLOAT_LIST,
4027                 .off1   = offsetof(struct thread_options, percentile_list),
4028                 .off2   = offsetof(struct thread_options, percentile_precision),
4029                 .help   = "Specify a custom list of percentiles to report for "
4030                           "completion latency and block errors",
4031                 .def    = "1:5:10:20:30:40:50:60:70:80:90:95:99:99.5:99.9:99.95:99.99",
4032                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
4033                 .minfp  = 0.0,
4034                 .maxfp  = 100.0,
4035                 .category = FIO_OPT_C_STAT,
4036                 .group  = FIO_OPT_G_INVALID,
4037         },
4038
4039 #ifdef FIO_HAVE_DISK_UTIL
4040         {
4041                 .name   = "disk_util",
4042                 .lname  = "Disk utilization",
4043                 .type   = FIO_OPT_BOOL,
4044                 .off1   = offsetof(struct thread_options, do_disk_util),
4045                 .help   = "Log disk utilization statistics",
4046                 .def    = "1",
4047                 .category = FIO_OPT_C_STAT,
4048                 .group  = FIO_OPT_G_INVALID,
4049         },
4050 #else
4051         {
4052                 .name   = "disk_util",
4053                 .lname  = "Disk utilization",
4054                 .type   = FIO_OPT_UNSUPPORTED,
4055                 .help   = "Your platform does not support disk utilization",
4056         },
4057 #endif
4058         {
4059                 .name   = "gtod_reduce",
4060                 .lname  = "Reduce gettimeofday() calls",
4061                 .type   = FIO_OPT_BOOL,
4062                 .help   = "Greatly reduce number of gettimeofday() calls",
4063                 .cb     = str_gtod_reduce_cb,
4064                 .def    = "0",
4065                 .hide_on_set = 1,
4066                 .category = FIO_OPT_C_STAT,
4067                 .group  = FIO_OPT_G_INVALID,
4068         },
4069         {
4070                 .name   = "disable_lat",
4071                 .lname  = "Disable all latency stats",
4072                 .type   = FIO_OPT_BOOL,
4073                 .off1   = offsetof(struct thread_options, disable_lat),
4074                 .help   = "Disable latency numbers",
4075                 .parent = "gtod_reduce",
4076                 .hide   = 1,
4077                 .def    = "0",
4078                 .category = FIO_OPT_C_STAT,
4079                 .group  = FIO_OPT_G_INVALID,
4080         },
4081         {
4082                 .name   = "disable_clat",
4083                 .lname  = "Disable completion latency stats",
4084                 .type   = FIO_OPT_BOOL,
4085                 .off1   = offsetof(struct thread_options, disable_clat),
4086                 .help   = "Disable completion latency numbers",
4087                 .parent = "gtod_reduce",
4088                 .hide   = 1,
4089                 .def    = "0",
4090                 .category = FIO_OPT_C_STAT,
4091                 .group  = FIO_OPT_G_INVALID,
4092         },
4093         {
4094                 .name   = "disable_slat",
4095                 .lname  = "Disable submission latency stats",
4096                 .type   = FIO_OPT_BOOL,
4097                 .off1   = offsetof(struct thread_options, disable_slat),
4098                 .help   = "Disable submission latency numbers",
4099                 .parent = "gtod_reduce",
4100                 .hide   = 1,
4101                 .def    = "0",
4102                 .category = FIO_OPT_C_STAT,
4103                 .group  = FIO_OPT_G_INVALID,
4104         },
4105         {
4106                 .name   = "disable_bw_measurement",
4107                 .alias  = "disable_bw",
4108                 .lname  = "Disable bandwidth stats",
4109                 .type   = FIO_OPT_BOOL,
4110                 .off1   = offsetof(struct thread_options, disable_bw),
4111                 .help   = "Disable bandwidth logging",
4112                 .parent = "gtod_reduce",
4113                 .hide   = 1,
4114                 .def    = "0",
4115                 .category = FIO_OPT_C_STAT,
4116                 .group  = FIO_OPT_G_INVALID,
4117         },
4118         {
4119                 .name   = "gtod_cpu",
4120                 .lname  = "Dedicated gettimeofday() CPU",
4121                 .type   = FIO_OPT_INT,
4122                 .off1   = offsetof(struct thread_options, gtod_cpu),
4123                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
4124                 .verify = gtod_cpu_verify,
4125                 .category = FIO_OPT_C_GENERAL,
4126                 .group  = FIO_OPT_G_CLOCK,
4127         },
4128         {
4129                 .name   = "unified_rw_reporting",
4130                 .lname  = "Unified RW Reporting",
4131                 .type   = FIO_OPT_BOOL,
4132                 .off1   = offsetof(struct thread_options, unified_rw_rep),
4133                 .help   = "Unify reporting across data direction",
4134                 .def    = "0",
4135                 .category = FIO_OPT_C_GENERAL,
4136                 .group  = FIO_OPT_G_INVALID,
4137         },
4138         {
4139                 .name   = "continue_on_error",
4140                 .lname  = "Continue on error",
4141                 .type   = FIO_OPT_STR,
4142                 .off1   = offsetof(struct thread_options, continue_on_error),
4143                 .help   = "Continue on non-fatal errors during IO",
4144                 .def    = "none",
4145                 .category = FIO_OPT_C_GENERAL,
4146                 .group  = FIO_OPT_G_ERR,
4147                 .posval = {
4148                           { .ival = "none",
4149                             .oval = ERROR_TYPE_NONE,
4150                             .help = "Exit when an error is encountered",
4151                           },
4152                           { .ival = "read",
4153                             .oval = ERROR_TYPE_READ,
4154                             .help = "Continue on read errors only",
4155                           },
4156                           { .ival = "write",
4157                             .oval = ERROR_TYPE_WRITE,
4158                             .help = "Continue on write errors only",
4159                           },
4160                           { .ival = "io",
4161                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
4162                             .help = "Continue on any IO errors",
4163                           },
4164                           { .ival = "verify",
4165                             .oval = ERROR_TYPE_VERIFY,
4166                             .help = "Continue on verify errors only",
4167                           },
4168                           { .ival = "all",
4169                             .oval = ERROR_TYPE_ANY,
4170                             .help = "Continue on all io and verify errors",
4171                           },
4172                           { .ival = "0",
4173                             .oval = ERROR_TYPE_NONE,
4174                             .help = "Alias for 'none'",
4175                           },
4176                           { .ival = "1",
4177                             .oval = ERROR_TYPE_ANY,
4178                             .help = "Alias for 'all'",
4179                           },
4180                 },
4181         },
4182         {
4183                 .name   = "ignore_error",
4184                 .lname  = "Ignore Error",
4185                 .type   = FIO_OPT_STR,
4186                 .cb     = str_ignore_error_cb,
4187                 .off1   = offsetof(struct thread_options, ignore_error_nr),
4188                 .help   = "Set a specific list of errors to ignore",
4189                 .parent = "rw",
4190                 .category = FIO_OPT_C_GENERAL,
4191                 .group  = FIO_OPT_G_ERR,
4192         },
4193         {
4194                 .name   = "error_dump",
4195                 .lname  = "Error Dump",
4196                 .type   = FIO_OPT_BOOL,
4197                 .off1   = offsetof(struct thread_options, error_dump),
4198                 .def    = "0",
4199                 .help   = "Dump info on each error",
4200                 .category = FIO_OPT_C_GENERAL,
4201                 .group  = FIO_OPT_G_ERR,
4202         },
4203         {
4204                 .name   = "profile",
4205                 .lname  = "Profile",
4206                 .type   = FIO_OPT_STR_STORE,
4207                 .off1   = offsetof(struct thread_options, profile),
4208                 .help   = "Select a specific builtin performance test",
4209                 .category = FIO_OPT_C_PROFILE,
4210                 .group  = FIO_OPT_G_INVALID,
4211         },
4212         {
4213                 .name   = "cgroup",
4214                 .lname  = "Cgroup",
4215                 .type   = FIO_OPT_STR_STORE,
4216                 .off1   = offsetof(struct thread_options, cgroup),
4217                 .help   = "Add job to cgroup of this name",
4218                 .category = FIO_OPT_C_GENERAL,
4219                 .group  = FIO_OPT_G_CGROUP,
4220         },
4221         {
4222                 .name   = "cgroup_nodelete",
4223                 .lname  = "Cgroup no-delete",
4224                 .type   = FIO_OPT_BOOL,
4225                 .off1   = offsetof(struct thread_options, cgroup_nodelete),
4226                 .help   = "Do not delete cgroups after job completion",
4227                 .def    = "0",
4228                 .parent = "cgroup",
4229                 .category = FIO_OPT_C_GENERAL,
4230                 .group  = FIO_OPT_G_CGROUP,
4231         },
4232         {
4233                 .name   = "cgroup_weight",
4234                 .lname  = "Cgroup weight",
4235                 .type   = FIO_OPT_INT,
4236                 .off1   = offsetof(struct thread_options, cgroup_weight),
4237                 .help   = "Use given weight for cgroup",
4238                 .minval = 100,
4239                 .maxval = 1000,
4240                 .parent = "cgroup",
4241                 .category = FIO_OPT_C_GENERAL,
4242                 .group  = FIO_OPT_G_CGROUP,
4243         },
4244         {
4245                 .name   = "uid",
4246                 .lname  = "User ID",
4247                 .type   = FIO_OPT_INT,
4248                 .off1   = offsetof(struct thread_options, uid),
4249                 .help   = "Run job with this user ID",
4250                 .category = FIO_OPT_C_GENERAL,
4251                 .group  = FIO_OPT_G_CRED,
4252         },
4253         {
4254                 .name   = "gid",
4255                 .lname  = "Group ID",
4256                 .type   = FIO_OPT_INT,
4257                 .off1   = offsetof(struct thread_options, gid),
4258                 .help   = "Run job with this group ID",
4259                 .category = FIO_OPT_C_GENERAL,
4260                 .group  = FIO_OPT_G_CRED,
4261         },
4262         {
4263                 .name   = "kb_base",
4264                 .lname  = "KB Base",
4265                 .type   = FIO_OPT_INT,
4266                 .off1   = offsetof(struct thread_options, kb_base),
4267                 .prio   = 1,
4268                 .def    = "1024",
4269                 .posval = {
4270                           { .ival = "1024",
4271                             .oval = 1024,
4272                             .help = "Inputs invert IEC and SI prefixes (for compatibility); outputs prefer binary",
4273                           },
4274                           { .ival = "1000",
4275                             .oval = 1000,
4276                             .help = "Inputs use IEC and SI prefixes; outputs prefer SI",
4277                           },
4278                 },
4279                 .help   = "Unit prefix interpretation for quantities of data (IEC and SI)",
4280                 .category = FIO_OPT_C_GENERAL,
4281                 .group  = FIO_OPT_G_INVALID,
4282         },
4283         {
4284                 .name   = "unit_base",
4285                 .lname  = "Unit for quantities of data (Bits or Bytes)",
4286                 .type   = FIO_OPT_INT,
4287                 .off1   = offsetof(struct thread_options, unit_base),
4288                 .prio   = 1,
4289                 .posval = {
4290                           { .ival = "0",
4291                             .oval = 0,
4292                             .help = "Auto-detect",
4293                           },
4294                           { .ival = "8",
4295                             .oval = 8,
4296                             .help = "Normal (byte based)",
4297                           },
4298                           { .ival = "1",
4299                             .oval = 1,
4300                             .help = "Bit based",
4301                           },
4302                 },
4303                 .help   = "Bit multiple of result summary data (8 for byte, 1 for bit)",
4304                 .category = FIO_OPT_C_GENERAL,
4305                 .group  = FIO_OPT_G_INVALID,
4306         },
4307         {
4308                 .name   = "hugepage-size",
4309                 .lname  = "Hugepage size",
4310                 .type   = FIO_OPT_INT,
4311                 .off1   = offsetof(struct thread_options, hugepage_size),
4312                 .help   = "When using hugepages, specify size of each page",
4313                 .def    = __fio_stringify(FIO_HUGE_PAGE),
4314                 .interval = 1024 * 1024,
4315                 .category = FIO_OPT_C_GENERAL,
4316                 .group  = FIO_OPT_G_INVALID,
4317         },
4318         {
4319                 .name   = "flow_id",
4320                 .lname  = "I/O flow ID",
4321                 .type   = FIO_OPT_INT,
4322                 .off1   = offsetof(struct thread_options, flow_id),
4323                 .help   = "The flow index ID to use",
4324                 .def    = "0",
4325                 .category = FIO_OPT_C_IO,
4326                 .group  = FIO_OPT_G_IO_FLOW,
4327         },
4328         {
4329                 .name   = "flow",
4330                 .lname  = "I/O flow weight",
4331                 .type   = FIO_OPT_INT,
4332                 .off1   = offsetof(struct thread_options, flow),
4333                 .help   = "Weight for flow control of this job",
4334                 .parent = "flow_id",
4335                 .hide   = 1,
4336                 .def    = "0",
4337                 .category = FIO_OPT_C_IO,
4338                 .group  = FIO_OPT_G_IO_FLOW,
4339         },
4340         {
4341                 .name   = "flow_watermark",
4342                 .lname  = "I/O flow watermark",
4343                 .type   = FIO_OPT_INT,
4344                 .off1   = offsetof(struct thread_options, flow_watermark),
4345                 .help   = "High watermark for flow control. This option"
4346                         " should be set to the same value for all threads"
4347                         " with non-zero flow.",
4348                 .parent = "flow_id",
4349                 .hide   = 1,
4350                 .def    = "1024",
4351                 .category = FIO_OPT_C_IO,
4352                 .group  = FIO_OPT_G_IO_FLOW,
4353         },
4354         {
4355                 .name   = "flow_sleep",
4356                 .lname  = "I/O flow sleep",
4357                 .type   = FIO_OPT_INT,
4358                 .off1   = offsetof(struct thread_options, flow_sleep),
4359                 .help   = "How many microseconds to sleep after being held"
4360                         " back by the flow control mechanism",
4361                 .parent = "flow_id",
4362                 .hide   = 1,
4363                 .def    = "0",
4364                 .category = FIO_OPT_C_IO,
4365                 .group  = FIO_OPT_G_IO_FLOW,
4366         },
4367         {
4368                 .name   = "skip_bad",
4369                 .lname  = "Skip operations against bad blocks",
4370                 .type   = FIO_OPT_BOOL,
4371                 .off1   = offsetof(struct thread_options, skip_bad),
4372                 .help   = "Skip operations against known bad blocks.",
4373                 .hide   = 1,
4374                 .def    = "0",
4375                 .category = FIO_OPT_C_IO,
4376                 .group  = FIO_OPT_G_MTD,
4377         },
4378         {
4379                 .name   = "steadystate",
4380                 .lname  = "Steady state threshold",
4381                 .alias  = "ss",
4382                 .type   = FIO_OPT_STR,
4383                 .off1   = offsetof(struct thread_options, ss_state),
4384                 .cb     = str_steadystate_cb,
4385                 .help   = "Define the criterion and limit to judge when a job has reached steady state",
4386                 .def    = "iops_slope:0.01%",
4387                 .posval = {
4388                           { .ival = "iops",
4389                             .oval = FIO_SS_IOPS,
4390                             .help = "maximum mean deviation of IOPS measurements",
4391                           },
4392                           { .ival = "iops_slope",
4393                             .oval = FIO_SS_IOPS_SLOPE,
4394                             .help = "slope calculated from IOPS measurements",
4395                           },
4396                           { .ival = "bw",
4397                             .oval = FIO_SS_BW,
4398                             .help = "maximum mean deviation of bandwidth measurements",
4399                           },
4400                           {
4401                             .ival = "bw_slope",
4402                             .oval = FIO_SS_BW_SLOPE,
4403                             .help = "slope calculated from bandwidth measurements",
4404                           },
4405                 },
4406                 .category = FIO_OPT_C_GENERAL,
4407                 .group  = FIO_OPT_G_RUNTIME,
4408         },
4409         {
4410                 .name   = "steadystate_duration",
4411                 .lname  = "Steady state duration",
4412                 .alias  = "ss_dur",
4413                 .parent = "steadystate",
4414                 .type   = FIO_OPT_STR_VAL_TIME,
4415                 .off1   = offsetof(struct thread_options, ss_dur),
4416                 .help   = "Stop workload upon attaining steady state for specified duration",
4417                 .def    = "0",
4418                 .is_seconds = 1,
4419                 .is_time = 1,
4420                 .category = FIO_OPT_C_GENERAL,
4421                 .group  = FIO_OPT_G_RUNTIME,
4422         },
4423         {
4424                 .name   = "steadystate_ramp_time",
4425                 .lname  = "Steady state ramp time",
4426                 .alias  = "ss_ramp",
4427                 .parent = "steadystate",
4428                 .type   = FIO_OPT_STR_VAL_TIME,
4429                 .off1   = offsetof(struct thread_options, ss_ramp_time),
4430                 .help   = "Delay before initiation of data collection for steady state job termination testing",
4431                 .def    = "0",
4432                 .is_seconds = 1,
4433                 .is_time = 1,
4434                 .category = FIO_OPT_C_GENERAL,
4435                 .group  = FIO_OPT_G_RUNTIME,
4436         },
4437         {
4438                 .name = NULL,
4439         },
4440 };
4441
4442 static void add_to_lopt(struct option *lopt, struct fio_option *o,
4443                         const char *name, int val)
4444 {
4445         lopt->name = (char *) name;
4446         lopt->val = val;
4447         if (o->type == FIO_OPT_STR_SET)
4448                 lopt->has_arg = optional_argument;
4449         else
4450                 lopt->has_arg = required_argument;
4451 }
4452
4453 static void options_to_lopts(struct fio_option *opts,
4454                               struct option *long_options,
4455                               int i, int option_type)
4456 {
4457         struct fio_option *o = &opts[0];
4458         while (o->name) {
4459                 add_to_lopt(&long_options[i], o, o->name, option_type);
4460                 if (o->alias) {
4461                         i++;
4462                         add_to_lopt(&long_options[i], o, o->alias, option_type);
4463                 }
4464
4465                 i++;
4466                 o++;
4467                 assert(i < FIO_NR_OPTIONS);
4468         }
4469 }
4470
4471 void fio_options_set_ioengine_opts(struct option *long_options,
4472                                    struct thread_data *td)
4473 {
4474         unsigned int i;
4475
4476         i = 0;
4477         while (long_options[i].name) {
4478                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
4479                         memset(&long_options[i], 0, sizeof(*long_options));
4480                         break;
4481                 }
4482                 i++;
4483         }
4484
4485         /*
4486          * Just clear out the prior ioengine options.
4487          */
4488         if (!td || !td->eo)
4489                 return;
4490
4491         options_to_lopts(td->io_ops->options, long_options, i,
4492                          FIO_GETOPT_IOENGINE);
4493 }
4494
4495 void fio_options_dup_and_init(struct option *long_options)
4496 {
4497         unsigned int i;
4498
4499         options_init(fio_options);
4500
4501         i = 0;
4502         while (long_options[i].name)
4503                 i++;
4504
4505         options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
4506 }
4507
4508 struct fio_keyword {
4509         const char *word;
4510         const char *desc;
4511         char *replace;
4512 };
4513
4514 static struct fio_keyword fio_keywords[] = {
4515         {
4516                 .word   = "$pagesize",
4517                 .desc   = "Page size in the system",
4518         },
4519         {
4520                 .word   = "$mb_memory",
4521                 .desc   = "Megabytes of memory online",
4522         },
4523         {
4524                 .word   = "$ncpus",
4525                 .desc   = "Number of CPUs online in the system",
4526         },
4527         {
4528                 .word   = NULL,
4529         },
4530 };
4531
4532 void fio_keywords_exit(void)
4533 {
4534         struct fio_keyword *kw;
4535
4536         kw = &fio_keywords[0];
4537         while (kw->word) {
4538                 free(kw->replace);
4539                 kw->replace = NULL;
4540                 kw++;
4541         }
4542 }
4543
4544 void fio_keywords_init(void)
4545 {
4546         unsigned long long mb_memory;
4547         char buf[128];
4548         long l;
4549
4550         sprintf(buf, "%lu", (unsigned long) page_size);
4551         fio_keywords[0].replace = strdup(buf);
4552
4553         mb_memory = os_phys_mem() / (1024 * 1024);
4554         sprintf(buf, "%llu", mb_memory);
4555         fio_keywords[1].replace = strdup(buf);
4556
4557         l = cpus_online();
4558         sprintf(buf, "%lu", l);
4559         fio_keywords[2].replace = strdup(buf);
4560 }
4561
4562 #define BC_APP          "bc"
4563
4564 static char *bc_calc(char *str)
4565 {
4566         char buf[128], *tmp;
4567         FILE *f;
4568         int ret;
4569
4570         /*
4571          * No math, just return string
4572          */
4573         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
4574              !strchr(str, '/')) || strchr(str, '\''))
4575                 return str;
4576
4577         /*
4578          * Split option from value, we only need to calculate the value
4579          */
4580         tmp = strchr(str, '=');
4581         if (!tmp)
4582                 return str;
4583
4584         tmp++;
4585
4586         /*
4587          * Prevent buffer overflows; such a case isn't reasonable anyway
4588          */
4589         if (strlen(str) >= 128 || strlen(tmp) > 100)
4590                 return str;
4591
4592         sprintf(buf, "which %s > /dev/null", BC_APP);
4593         if (system(buf)) {
4594                 log_err("fio: bc is needed for performing math\n");
4595                 return NULL;
4596         }
4597
4598         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
4599         f = popen(buf, "r");
4600         if (!f)
4601                 return NULL;
4602
4603         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
4604         if (ret <= 0) {
4605                 pclose(f);
4606                 return NULL;
4607         }
4608
4609         pclose(f);
4610         buf[(tmp - str) + ret - 1] = '\0';
4611         memcpy(buf, str, tmp - str);
4612         free(str);
4613         return strdup(buf);
4614 }
4615
4616 /*
4617  * Return a copy of the input string with substrings of the form ${VARNAME}
4618  * substituted with the value of the environment variable VARNAME.  The
4619  * substitution always occurs, even if VARNAME is empty or the corresponding
4620  * environment variable undefined.
4621  */
4622 static char *option_dup_subs(const char *opt)
4623 {
4624         char out[OPT_LEN_MAX+1];
4625         char in[OPT_LEN_MAX+1];
4626         char *outptr = out;
4627         char *inptr = in;
4628         char *ch1, *ch2, *env;
4629         ssize_t nchr = OPT_LEN_MAX;
4630         size_t envlen;
4631
4632         if (strlen(opt) + 1 > OPT_LEN_MAX) {
4633                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
4634                 return NULL;
4635         }
4636
4637         in[OPT_LEN_MAX] = '\0';
4638         strncpy(in, opt, OPT_LEN_MAX);
4639
4640         while (*inptr && nchr > 0) {
4641                 if (inptr[0] == '$' && inptr[1] == '{') {
4642                         ch2 = strchr(inptr, '}');
4643                         if (ch2 && inptr+1 < ch2) {
4644                                 ch1 = inptr+2;
4645                                 inptr = ch2+1;
4646                                 *ch2 = '\0';
4647
4648                                 env = getenv(ch1);
4649                                 if (env) {
4650                                         envlen = strlen(env);
4651                                         if (envlen <= nchr) {
4652                                                 memcpy(outptr, env, envlen);
4653                                                 outptr += envlen;
4654                                                 nchr -= envlen;
4655                                         }
4656                                 }
4657
4658                                 continue;
4659                         }
4660                 }
4661
4662                 *outptr++ = *inptr++;
4663                 --nchr;
4664         }
4665
4666         *outptr = '\0';
4667         return strdup(out);
4668 }
4669
4670 /*
4671  * Look for reserved variable names and replace them with real values
4672  */
4673 static char *fio_keyword_replace(char *opt)
4674 {
4675         char *s;
4676         int i;
4677         int docalc = 0;
4678
4679         for (i = 0; fio_keywords[i].word != NULL; i++) {
4680                 struct fio_keyword *kw = &fio_keywords[i];
4681
4682                 while ((s = strstr(opt, kw->word)) != NULL) {
4683                         char *new = malloc(strlen(opt) + 1);
4684                         char *o_org = opt;
4685                         int olen = s - opt;
4686                         int len;
4687
4688                         /*
4689                          * Copy part of the string before the keyword and
4690                          * sprintf() the replacement after it.
4691                          */
4692                         memcpy(new, opt, olen);
4693                         len = sprintf(new + olen, "%s", kw->replace);
4694
4695                         /*
4696                          * If there's more in the original string, copy that
4697                          * in too
4698                          */
4699                         opt += strlen(kw->word) + olen;
4700                         if (strlen(opt))
4701                                 memcpy(new + olen + len, opt, opt - o_org - 1);
4702
4703                         /*
4704                          * replace opt and free the old opt
4705                          */
4706                         opt = new;
4707                         free(o_org);
4708
4709                         docalc = 1;
4710                 }
4711         }
4712
4713         /*
4714          * Check for potential math and invoke bc, if possible
4715          */
4716         if (docalc)
4717                 opt = bc_calc(opt);
4718
4719         return opt;
4720 }
4721
4722 static char **dup_and_sub_options(char **opts, int num_opts)
4723 {
4724         int i;
4725         char **opts_copy = malloc(num_opts * sizeof(*opts));
4726         for (i = 0; i < num_opts; i++) {
4727                 opts_copy[i] = option_dup_subs(opts[i]);
4728                 if (!opts_copy[i])
4729                         continue;
4730                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
4731         }
4732         return opts_copy;
4733 }
4734
4735 static void show_closest_option(const char *opt)
4736 {
4737         int best_option, best_distance;
4738         int i, distance;
4739         char *name;
4740
4741         if (!strlen(opt))
4742                 return;
4743
4744         name = strdup(opt);
4745         i = 0;
4746         while (name[i] != '\0' && name[i] != '=')
4747                 i++;
4748         name[i] = '\0';
4749
4750         best_option = -1;
4751         best_distance = INT_MAX;
4752         i = 0;
4753         while (fio_options[i].name) {
4754                 distance = string_distance(name, fio_options[i].name);
4755                 if (distance < best_distance) {
4756                         best_distance = distance;
4757                         best_option = i;
4758                 }
4759                 i++;
4760         }
4761
4762         if (best_option != -1 && string_distance_ok(name, best_distance) &&
4763             fio_options[best_option].type != FIO_OPT_UNSUPPORTED)
4764                 log_err("Did you mean %s?\n", fio_options[best_option].name);
4765
4766         free(name);
4767 }
4768
4769 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
4770 {
4771         int i, ret, unknown;
4772         char **opts_copy;
4773
4774         sort_options(opts, fio_options, num_opts);
4775         opts_copy = dup_and_sub_options(opts, num_opts);
4776
4777         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
4778                 struct fio_option *o;
4779                 int newret = parse_option(opts_copy[i], opts[i], fio_options,
4780                                                 &o, &td->o, &td->opt_list);
4781
4782                 if (!newret && o)
4783                         fio_option_mark_set(&td->o, o);
4784
4785                 if (opts_copy[i]) {
4786                         if (newret && !o) {
4787                                 unknown++;
4788                                 continue;
4789                         }
4790                         free(opts_copy[i]);
4791                         opts_copy[i] = NULL;
4792                 }
4793
4794                 ret |= newret;
4795         }
4796
4797         if (unknown) {
4798                 ret |= ioengine_load(td);
4799                 if (td->eo) {
4800                         sort_options(opts_copy, td->io_ops->options, num_opts);
4801                         opts = opts_copy;
4802                 }
4803                 for (i = 0; i < num_opts; i++) {
4804                         struct fio_option *o = NULL;
4805                         int newret = 1;
4806
4807                         if (!opts_copy[i])
4808                                 continue;
4809
4810                         if (td->eo)
4811                                 newret = parse_option(opts_copy[i], opts[i],
4812                                                       td->io_ops->options, &o,
4813                                                       td->eo, &td->opt_list);
4814
4815                         ret |= newret;
4816                         if (!o) {
4817                                 log_err("Bad option <%s>\n", opts[i]);
4818                                 show_closest_option(opts[i]);
4819                         }
4820                         free(opts_copy[i]);
4821                         opts_copy[i] = NULL;
4822                 }
4823         }
4824
4825         free(opts_copy);
4826         return ret;
4827 }
4828
4829 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
4830 {
4831         int ret;
4832
4833         ret = parse_cmd_option(opt, val, fio_options, &td->o, &td->opt_list);
4834         if (!ret) {
4835                 struct fio_option *o;
4836
4837                 o = find_option(fio_options, opt);
4838                 if (o)
4839                         fio_option_mark_set(&td->o, o);
4840         }
4841
4842         return ret;
4843 }
4844
4845 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
4846                                 char *val)
4847 {
4848         return parse_cmd_option(opt, val, td->io_ops->options, td->eo,
4849                                         &td->opt_list);
4850 }
4851
4852 void fio_fill_default_options(struct thread_data *td)
4853 {
4854         td->o.magic = OPT_MAGIC;
4855         fill_default_options(&td->o, fio_options);
4856 }
4857
4858 int fio_show_option_help(const char *opt)
4859 {
4860         return show_cmd_help(fio_options, opt);
4861 }
4862
4863 /*
4864  * dupe FIO_OPT_STR_STORE options
4865  */
4866 void fio_options_mem_dupe(struct thread_data *td)
4867 {
4868         options_mem_dupe(fio_options, &td->o);
4869
4870         if (td->eo && td->io_ops) {
4871                 void *oldeo = td->eo;
4872
4873                 td->eo = malloc(td->io_ops->option_struct_size);
4874                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
4875                 options_mem_dupe(td->io_ops->options, td->eo);
4876         }
4877 }
4878
4879 unsigned int fio_get_kb_base(void *data)
4880 {
4881         struct thread_data *td = cb_data_to_td(data);
4882         struct thread_options *o = &td->o;
4883         unsigned int kb_base = 0;
4884
4885         /*
4886          * This is a hack... For private options, *data is not holding
4887          * a pointer to the thread_options, but to private data. This means
4888          * we can't safely dereference it, but magic is first so mem wise
4889          * it is valid. But this also means that if the job first sets
4890          * kb_base and expects that to be honored by private options,
4891          * it will be disappointed. We will return the global default
4892          * for this.
4893          */
4894         if (o && o->magic == OPT_MAGIC)
4895                 kb_base = o->kb_base;
4896         if (!kb_base)
4897                 kb_base = 1024;
4898
4899         return kb_base;
4900 }
4901
4902 int add_option(struct fio_option *o)
4903 {
4904         struct fio_option *__o;
4905         int opt_index = 0;
4906
4907         __o = fio_options;
4908         while (__o->name) {
4909                 opt_index++;
4910                 __o++;
4911         }
4912
4913         if (opt_index + 1 == FIO_MAX_OPTS) {
4914                 log_err("fio: FIO_MAX_OPTS is too small\n");
4915                 return 1;
4916         }
4917
4918         memcpy(&fio_options[opt_index], o, sizeof(*o));
4919         fio_options[opt_index + 1].name = NULL;
4920         return 0;
4921 }
4922
4923 void invalidate_profile_options(const char *prof_name)
4924 {
4925         struct fio_option *o;
4926
4927         o = fio_options;
4928         while (o->name) {
4929                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
4930                         o->type = FIO_OPT_INVALID;
4931                         o->prof_name = NULL;
4932                 }
4933                 o++;
4934         }
4935 }
4936
4937 void add_opt_posval(const char *optname, const char *ival, const char *help)
4938 {
4939         struct fio_option *o;
4940         unsigned int i;
4941
4942         o = find_option(fio_options, optname);
4943         if (!o)
4944                 return;
4945
4946         for (i = 0; i < PARSE_MAX_VP; i++) {
4947                 if (o->posval[i].ival)
4948                         continue;
4949
4950                 o->posval[i].ival = ival;
4951                 o->posval[i].help = help;
4952                 break;
4953         }
4954 }
4955
4956 void del_opt_posval(const char *optname, const char *ival)
4957 {
4958         struct fio_option *o;
4959         unsigned int i;
4960
4961         o = find_option(fio_options, optname);
4962         if (!o)
4963                 return;
4964
4965         for (i = 0; i < PARSE_MAX_VP; i++) {
4966                 if (!o->posval[i].ival)
4967                         continue;
4968                 if (strcmp(o->posval[i].ival, ival))
4969                         continue;
4970
4971                 o->posval[i].ival = NULL;
4972                 o->posval[i].help = NULL;
4973         }
4974 }
4975
4976 void fio_options_free(struct thread_data *td)
4977 {
4978         options_free(fio_options, &td->o);
4979         if (td->eo && td->io_ops && td->io_ops->options) {
4980                 options_free(td->io_ops->options, td->eo);
4981                 free(td->eo);
4982                 td->eo = NULL;
4983         }
4984 }
4985
4986 struct fio_option *fio_option_find(const char *name)
4987 {
4988         return find_option(fio_options, name);
4989 }
4990
4991 static struct fio_option *find_next_opt(struct thread_options *o,
4992                                         struct fio_option *from,
4993                                         unsigned int off1)
4994 {
4995         struct fio_option *opt;
4996
4997         if (!from)
4998                 from = &fio_options[0];
4999         else
5000                 from++;
5001
5002         opt = NULL;
5003         do {
5004                 if (off1 == from->off1) {
5005                         opt = from;
5006                         break;
5007                 }
5008                 from++;
5009         } while (from->name);
5010
5011         return opt;
5012 }
5013
5014 static int opt_is_set(struct thread_options *o, struct fio_option *opt)
5015 {
5016         unsigned int opt_off, index, offset;
5017
5018         opt_off = opt - &fio_options[0];
5019         index = opt_off / (8 * sizeof(uint64_t));
5020         offset = opt_off & ((8 * sizeof(uint64_t)) - 1);
5021         return (o->set_options[index] & ((uint64_t)1 << offset)) != 0;
5022 }
5023
5024 bool __fio_option_is_set(struct thread_options *o, unsigned int off1)
5025 {
5026         struct fio_option *opt, *next;
5027
5028         next = NULL;
5029         while ((opt = find_next_opt(o, next, off1)) != NULL) {
5030                 if (opt_is_set(o, opt))
5031                         return true;
5032
5033                 next = opt;
5034         }
5035
5036         return false;
5037 }
5038
5039 void fio_option_mark_set(struct thread_options *o, struct fio_option *opt)
5040 {
5041         unsigned int opt_off, index, offset;
5042
5043         opt_off = opt - &fio_options[0];
5044         index = opt_off / (8 * sizeof(uint64_t));
5045         offset = opt_off & ((8 * sizeof(uint64_t)) - 1);
5046         o->set_options[index] |= (uint64_t)1 << offset;
5047 }