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