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