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