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