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