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