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