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