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