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 FIO_HAVE_SOLARISAIO
1304                           { .ival = "solarisaio",
1305                             .help = "Solaris native asynchronous IO",
1306                           },
1307 #endif
1308 #ifdef FIO_HAVE_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 FIO_HAVE_E4_ENG
1359                           { .ival = "e4defrag",
1360                             .help = "ext4 defrag engine",
1361                           },
1362 #endif
1363 #ifdef FIO_HAVE_FALLOC_ENG
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 FIO_HAVE_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 FIO_HAVE_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  /* FIO_HAVE_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                 .category = FIO_OPT_C_IO,
2197                 .group  = FIO_OPT_G_VERIFY,
2198         },
2199 #ifdef FIO_HAVE_TRIM
2200         {
2201                 .name   = "trim_percentage",
2202                 .lname  = "Trim percentage",
2203                 .type   = FIO_OPT_INT,
2204                 .off1   = td_var_offset(trim_percentage),
2205                 .minval = 0,
2206                 .maxval = 100,
2207                 .help   = "Number of verify blocks to discard/trim",
2208                 .parent = "verify",
2209                 .def    = "0",
2210                 .interval = 1,
2211                 .hide   = 1,
2212                 .category = FIO_OPT_C_IO,
2213                 .group  = FIO_OPT_G_TRIM,
2214         },
2215         {
2216                 .name   = "trim_verify_zero",
2217                 .lname  = "Verify trim zero",
2218                 .type   = FIO_OPT_BOOL,
2219                 .help   = "Verify that trim/discarded blocks are returned as zeroes",
2220                 .off1   = td_var_offset(trim_zero),
2221                 .parent = "trim_percentage",
2222                 .hide   = 1,
2223                 .def    = "1",
2224                 .category = FIO_OPT_C_IO,
2225                 .group  = FIO_OPT_G_TRIM,
2226         },
2227         {
2228                 .name   = "trim_backlog",
2229                 .lname  = "Trim backlog",
2230                 .type   = FIO_OPT_STR_VAL,
2231                 .off1   = td_var_offset(trim_backlog),
2232                 .help   = "Trim after this number of blocks are written",
2233                 .parent = "trim_percentage",
2234                 .hide   = 1,
2235                 .interval = 1,
2236                 .category = FIO_OPT_C_IO,
2237                 .group  = FIO_OPT_G_TRIM,
2238         },
2239         {
2240                 .name   = "trim_backlog_batch",
2241                 .lname  = "Trim backlog batch",
2242                 .type   = FIO_OPT_INT,
2243                 .off1   = td_var_offset(trim_batch),
2244                 .help   = "Trim this number of IO blocks",
2245                 .parent = "trim_percentage",
2246                 .hide   = 1,
2247                 .interval = 1,
2248                 .category = FIO_OPT_C_IO,
2249                 .group  = FIO_OPT_G_TRIM,
2250         },
2251 #endif
2252         {
2253                 .name   = "write_iolog",
2254                 .lname  = "Write I/O log",
2255                 .type   = FIO_OPT_STR_STORE,
2256                 .off1   = td_var_offset(write_iolog_file),
2257                 .help   = "Store IO pattern to file",
2258                 .category = FIO_OPT_C_IO,
2259                 .group  = FIO_OPT_G_IOLOG,
2260         },
2261         {
2262                 .name   = "read_iolog",
2263                 .lname  = "Read I/O log",
2264                 .type   = FIO_OPT_STR_STORE,
2265                 .off1   = td_var_offset(read_iolog_file),
2266                 .help   = "Playback IO pattern from file",
2267                 .category = FIO_OPT_C_IO,
2268                 .group  = FIO_OPT_G_IOLOG,
2269         },
2270         {
2271                 .name   = "replay_no_stall",
2272                 .lname  = "Don't stall on replay",
2273                 .type   = FIO_OPT_BOOL,
2274                 .off1   = td_var_offset(no_stall),
2275                 .def    = "0",
2276                 .parent = "read_iolog",
2277                 .hide   = 1,
2278                 .help   = "Playback IO pattern file as fast as possible without stalls",
2279                 .category = FIO_OPT_C_IO,
2280                 .group  = FIO_OPT_G_IOLOG,
2281         },
2282         {
2283                 .name   = "replay_redirect",
2284                 .lname  = "Redirect device for replay",
2285                 .type   = FIO_OPT_STR_STORE,
2286                 .off1   = td_var_offset(replay_redirect),
2287                 .parent = "read_iolog",
2288                 .hide   = 1,
2289                 .help   = "Replay all I/O onto this device, regardless of trace device",
2290                 .category = FIO_OPT_C_IO,
2291                 .group  = FIO_OPT_G_IOLOG,
2292         },
2293         {
2294                 .name   = "exec_prerun",
2295                 .lname  = "Pre-execute runnable",
2296                 .type   = FIO_OPT_STR_STORE,
2297                 .off1   = td_var_offset(exec_prerun),
2298                 .help   = "Execute this file prior to running job",
2299                 .category = FIO_OPT_C_GENERAL,
2300                 .group  = FIO_OPT_G_INVALID,
2301         },
2302         {
2303                 .name   = "exec_postrun",
2304                 .lname  = "Post-execute runnable",
2305                 .type   = FIO_OPT_STR_STORE,
2306                 .off1   = td_var_offset(exec_postrun),
2307                 .help   = "Execute this file after running job",
2308                 .category = FIO_OPT_C_GENERAL,
2309                 .group  = FIO_OPT_G_INVALID,
2310         },
2311 #ifdef FIO_HAVE_IOSCHED_SWITCH
2312         {
2313                 .name   = "ioscheduler",
2314                 .lname  = "I/O scheduler",
2315                 .type   = FIO_OPT_STR_STORE,
2316                 .off1   = td_var_offset(ioscheduler),
2317                 .help   = "Use this IO scheduler on the backing device",
2318                 .category = FIO_OPT_C_FILE,
2319                 .group  = FIO_OPT_G_INVALID,
2320         },
2321 #endif
2322         {
2323                 .name   = "zonesize",
2324                 .lname  = "Zone size",
2325                 .type   = FIO_OPT_STR_VAL,
2326                 .off1   = td_var_offset(zone_size),
2327                 .help   = "Amount of data to read per zone",
2328                 .def    = "0",
2329                 .interval = 1024 * 1024,
2330                 .category = FIO_OPT_C_IO,
2331                 .group  = FIO_OPT_G_ZONE,
2332         },
2333         {
2334                 .name   = "zonerange",
2335                 .lname  = "Zone range",
2336                 .type   = FIO_OPT_STR_VAL,
2337                 .off1   = td_var_offset(zone_range),
2338                 .help   = "Give size of an IO zone",
2339                 .def    = "0",
2340                 .interval = 1024 * 1024,
2341                 .category = FIO_OPT_C_IO,
2342                 .group  = FIO_OPT_G_ZONE,
2343         },
2344         {
2345                 .name   = "zoneskip",
2346                 .lname  = "Zone skip",
2347                 .type   = FIO_OPT_STR_VAL,
2348                 .off1   = td_var_offset(zone_skip),
2349                 .help   = "Space between IO zones",
2350                 .def    = "0",
2351                 .interval = 1024 * 1024,
2352                 .category = FIO_OPT_C_IO,
2353                 .group  = FIO_OPT_G_ZONE,
2354         },
2355         {
2356                 .name   = "lockmem",
2357                 .lname  = "Lock memory",
2358                 .type   = FIO_OPT_STR_VAL,
2359                 .off1   = td_var_offset(lockmem),
2360                 .help   = "Lock down this amount of memory",
2361                 .def    = "0",
2362                 .interval = 1024 * 1024,
2363                 .category = FIO_OPT_C_GENERAL,
2364                 .group  = FIO_OPT_G_INVALID,
2365         },
2366         {
2367                 .name   = "rwmixread",
2368                 .lname  = "Read/write mix read",
2369                 .type   = FIO_OPT_INT,
2370                 .cb     = str_rwmix_read_cb,
2371                 .maxval = 100,
2372                 .help   = "Percentage of mixed workload that is reads",
2373                 .def    = "50",
2374                 .interval = 5,
2375                 .inverse = "rwmixwrite",
2376                 .category = FIO_OPT_C_IO,
2377                 .group  = FIO_OPT_G_RWMIX,
2378         },
2379         {
2380                 .name   = "rwmixwrite",
2381                 .lname  = "Read/write mix write",
2382                 .type   = FIO_OPT_INT,
2383                 .cb     = str_rwmix_write_cb,
2384                 .maxval = 100,
2385                 .help   = "Percentage of mixed workload that is writes",
2386                 .def    = "50",
2387                 .interval = 5,
2388                 .inverse = "rwmixread",
2389                 .category = FIO_OPT_C_IO,
2390                 .group  = FIO_OPT_G_RWMIX,
2391         },
2392         {
2393                 .name   = "rwmixcycle",
2394                 .lname  = "Read/write mix cycle",
2395                 .type   = FIO_OPT_DEPRECATED,
2396                 .category = FIO_OPT_C_IO,
2397                 .group  = FIO_OPT_G_RWMIX,
2398         },
2399         {
2400                 .name   = "nice",
2401                 .lname  = "Nice",
2402                 .type   = FIO_OPT_INT,
2403                 .off1   = td_var_offset(nice),
2404                 .help   = "Set job CPU nice value",
2405                 .minval = -19,
2406                 .maxval = 20,
2407                 .def    = "0",
2408                 .interval = 1,
2409                 .category = FIO_OPT_C_GENERAL,
2410                 .group  = FIO_OPT_G_CRED,
2411         },
2412 #ifdef FIO_HAVE_IOPRIO
2413         {
2414                 .name   = "prio",
2415                 .lname  = "I/O nice priority",
2416                 .type   = FIO_OPT_INT,
2417                 .off1   = td_var_offset(ioprio),
2418                 .help   = "Set job IO priority value",
2419                 .minval = 0,
2420                 .maxval = 7,
2421                 .interval = 1,
2422                 .category = FIO_OPT_C_GENERAL,
2423                 .group  = FIO_OPT_G_CRED,
2424         },
2425         {
2426                 .name   = "prioclass",
2427                 .lname  = "I/O nice priority class",
2428                 .type   = FIO_OPT_INT,
2429                 .off1   = td_var_offset(ioprio_class),
2430                 .help   = "Set job IO priority class",
2431                 .minval = 0,
2432                 .maxval = 3,
2433                 .interval = 1,
2434                 .category = FIO_OPT_C_GENERAL,
2435                 .group  = FIO_OPT_G_CRED,
2436         },
2437 #endif
2438         {
2439                 .name   = "thinktime",
2440                 .lname  = "Thinktime",
2441                 .type   = FIO_OPT_INT,
2442                 .off1   = td_var_offset(thinktime),
2443                 .help   = "Idle time between IO buffers (usec)",
2444                 .def    = "0",
2445                 .category = FIO_OPT_C_IO,
2446                 .group  = FIO_OPT_G_THINKTIME,
2447         },
2448         {
2449                 .name   = "thinktime_spin",
2450                 .lname  = "Thinktime spin",
2451                 .type   = FIO_OPT_INT,
2452                 .off1   = td_var_offset(thinktime_spin),
2453                 .help   = "Start think time by spinning this amount (usec)",
2454                 .def    = "0",
2455                 .parent = "thinktime",
2456                 .hide   = 1,
2457                 .category = FIO_OPT_C_IO,
2458                 .group  = FIO_OPT_G_THINKTIME,
2459         },
2460         {
2461                 .name   = "thinktime_blocks",
2462                 .lname  = "Thinktime blocks",
2463                 .type   = FIO_OPT_INT,
2464                 .off1   = td_var_offset(thinktime_blocks),
2465                 .help   = "IO buffer period between 'thinktime'",
2466                 .def    = "1",
2467                 .parent = "thinktime",
2468                 .hide   = 1,
2469                 .category = FIO_OPT_C_IO,
2470                 .group  = FIO_OPT_G_THINKTIME,
2471         },
2472         {
2473                 .name   = "rate",
2474                 .lname  = "I/O rate",
2475                 .type   = FIO_OPT_INT,
2476                 .off1   = td_var_offset(rate[DDIR_READ]),
2477                 .off2   = td_var_offset(rate[DDIR_WRITE]),
2478                 .off3   = td_var_offset(rate[DDIR_TRIM]),
2479                 .help   = "Set bandwidth rate",
2480                 .category = FIO_OPT_C_IO,
2481                 .group  = FIO_OPT_G_RATE,
2482         },
2483         {
2484                 .name   = "ratemin",
2485                 .lname  = "I/O min rate",
2486                 .type   = FIO_OPT_INT,
2487                 .off1   = td_var_offset(ratemin[DDIR_READ]),
2488                 .off2   = td_var_offset(ratemin[DDIR_WRITE]),
2489                 .off3   = td_var_offset(ratemin[DDIR_TRIM]),
2490                 .help   = "Job must meet this rate or it will be shutdown",
2491                 .parent = "rate",
2492                 .hide   = 1,
2493                 .category = FIO_OPT_C_IO,
2494                 .group  = FIO_OPT_G_RATE,
2495         },
2496         {
2497                 .name   = "rate_iops",
2498                 .lname  = "I/O rate IOPS",
2499                 .type   = FIO_OPT_INT,
2500                 .off1   = td_var_offset(rate_iops[DDIR_READ]),
2501                 .off2   = td_var_offset(rate_iops[DDIR_WRITE]),
2502                 .off3   = td_var_offset(rate_iops[DDIR_TRIM]),
2503                 .help   = "Limit IO used to this number of IO operations/sec",
2504                 .hide   = 1,
2505                 .category = FIO_OPT_C_IO,
2506                 .group  = FIO_OPT_G_RATE,
2507         },
2508         {
2509                 .name   = "rate_iops_min",
2510                 .lname  = "I/O min rate IOPS",
2511                 .type   = FIO_OPT_INT,
2512                 .off1   = td_var_offset(rate_iops_min[DDIR_READ]),
2513                 .off2   = td_var_offset(rate_iops_min[DDIR_WRITE]),
2514                 .off3   = td_var_offset(rate_iops_min[DDIR_TRIM]),
2515                 .help   = "Job must meet this rate or it will be shut down",
2516                 .parent = "rate_iops",
2517                 .hide   = 1,
2518                 .category = FIO_OPT_C_IO,
2519                 .group  = FIO_OPT_G_RATE,
2520         },
2521         {
2522                 .name   = "ratecycle",
2523                 .lname  = "I/O rate cycle",
2524                 .type   = FIO_OPT_INT,
2525                 .off1   = td_var_offset(ratecycle),
2526                 .help   = "Window average for rate limits (msec)",
2527                 .def    = "1000",
2528                 .parent = "rate",
2529                 .hide   = 1,
2530                 .category = FIO_OPT_C_IO,
2531                 .group  = FIO_OPT_G_RATE,
2532         },
2533         {
2534                 .name   = "max_latency",
2535                 .type   = FIO_OPT_INT,
2536                 .off1   = td_var_offset(max_latency),
2537                 .help   = "Maximum tolerated IO latency (usec)",
2538                 .category = FIO_OPT_C_IO,
2539                 .group = FIO_OPT_G_RATE,
2540         },
2541         {
2542                 .name   = "invalidate",
2543                 .lname  = "Cache invalidate",
2544                 .type   = FIO_OPT_BOOL,
2545                 .off1   = td_var_offset(invalidate_cache),
2546                 .help   = "Invalidate buffer/page cache prior to running job",
2547                 .def    = "1",
2548                 .category = FIO_OPT_C_IO,
2549                 .group  = FIO_OPT_G_IO_TYPE,
2550         },
2551         {
2552                 .name   = "sync",
2553                 .lname  = "Synchronous I/O",
2554                 .type   = FIO_OPT_BOOL,
2555                 .off1   = td_var_offset(sync_io),
2556                 .help   = "Use O_SYNC for buffered writes",
2557                 .def    = "0",
2558                 .parent = "buffered",
2559                 .hide   = 1,
2560                 .category = FIO_OPT_C_IO,
2561                 .group  = FIO_OPT_G_IO_TYPE,
2562         },
2563         {
2564                 .name   = "create_serialize",
2565                 .lname  = "Create serialize",
2566                 .type   = FIO_OPT_BOOL,
2567                 .off1   = td_var_offset(create_serialize),
2568                 .help   = "Serialize creating of job files",
2569                 .def    = "1",
2570                 .category = FIO_OPT_C_FILE,
2571                 .group  = FIO_OPT_G_INVALID,
2572         },
2573         {
2574                 .name   = "create_fsync",
2575                 .lname  = "Create fsync",
2576                 .type   = FIO_OPT_BOOL,
2577                 .off1   = td_var_offset(create_fsync),
2578                 .help   = "fsync file after creation",
2579                 .def    = "1",
2580                 .category = FIO_OPT_C_FILE,
2581                 .group  = FIO_OPT_G_INVALID,
2582         },
2583         {
2584                 .name   = "create_on_open",
2585                 .lname  = "Create on open",
2586                 .type   = FIO_OPT_BOOL,
2587                 .off1   = td_var_offset(create_on_open),
2588                 .help   = "Create files when they are opened for IO",
2589                 .def    = "0",
2590                 .category = FIO_OPT_C_FILE,
2591                 .group  = FIO_OPT_G_INVALID,
2592         },
2593         {
2594                 .name   = "create_only",
2595                 .type   = FIO_OPT_BOOL,
2596                 .off1   = td_var_offset(create_only),
2597                 .help   = "Only perform file creation phase",
2598                 .category = FIO_OPT_C_FILE,
2599                 .def    = "0",
2600         },
2601         {
2602                 .name   = "pre_read",
2603                 .lname  = "Pre-read files",
2604                 .type   = FIO_OPT_BOOL,
2605                 .off1   = td_var_offset(pre_read),
2606                 .help   = "Pre-read files before starting official testing",
2607                 .def    = "0",
2608                 .category = FIO_OPT_C_FILE,
2609                 .group  = FIO_OPT_G_INVALID,
2610         },
2611 #ifdef FIO_HAVE_CPU_AFFINITY
2612         {
2613                 .name   = "cpumask",
2614                 .lname  = "CPU mask",
2615                 .type   = FIO_OPT_INT,
2616                 .cb     = str_cpumask_cb,
2617                 .help   = "CPU affinity mask",
2618                 .category = FIO_OPT_C_GENERAL,
2619                 .group  = FIO_OPT_G_CRED,
2620         },
2621         {
2622                 .name   = "cpus_allowed",
2623                 .lname  = "CPUs allowed",
2624                 .type   = FIO_OPT_STR,
2625                 .cb     = str_cpus_allowed_cb,
2626                 .help   = "Set CPUs allowed",
2627                 .category = FIO_OPT_C_GENERAL,
2628                 .group  = FIO_OPT_G_CRED,
2629         },
2630 #endif
2631 #ifdef CONFIG_LIBNUMA
2632         {
2633                 .name   = "numa_cpu_nodes",
2634                 .type   = FIO_OPT_STR,
2635                 .cb     = str_numa_cpunodes_cb,
2636                 .help   = "NUMA CPU nodes bind",
2637         },
2638         {
2639                 .name   = "numa_mem_policy",
2640                 .type   = FIO_OPT_STR,
2641                 .cb     = str_numa_mpol_cb,
2642                 .help   = "NUMA memory policy setup",
2643         },
2644 #endif
2645         {
2646                 .name   = "end_fsync",
2647                 .lname  = "End fsync",
2648                 .type   = FIO_OPT_BOOL,
2649                 .off1   = td_var_offset(end_fsync),
2650                 .help   = "Include fsync at the end of job",
2651                 .def    = "0",
2652                 .category = FIO_OPT_C_FILE,
2653                 .group  = FIO_OPT_G_INVALID,
2654         },
2655         {
2656                 .name   = "fsync_on_close",
2657                 .lname  = "Fsync on close",
2658                 .type   = FIO_OPT_BOOL,
2659                 .off1   = td_var_offset(fsync_on_close),
2660                 .help   = "fsync files on close",
2661                 .def    = "0",
2662                 .category = FIO_OPT_C_FILE,
2663                 .group  = FIO_OPT_G_INVALID,
2664         },
2665         {
2666                 .name   = "unlink",
2667                 .lname  = "Unlink file",
2668                 .type   = FIO_OPT_BOOL,
2669                 .off1   = td_var_offset(unlink),
2670                 .help   = "Unlink created files after job has completed",
2671                 .def    = "0",
2672                 .category = FIO_OPT_C_FILE,
2673                 .group  = FIO_OPT_G_INVALID,
2674         },
2675         {
2676                 .name   = "exitall",
2677                 .lname  = "Exit-all on terminate",
2678                 .type   = FIO_OPT_STR_SET,
2679                 .cb     = str_exitall_cb,
2680                 .help   = "Terminate all jobs when one exits",
2681                 .category = FIO_OPT_C_GENERAL,
2682                 .group  = FIO_OPT_G_PROCESS,
2683         },
2684         {
2685                 .name   = "stonewall",
2686                 .lname  = "Wait for previous",
2687                 .alias  = "wait_for_previous",
2688                 .type   = FIO_OPT_STR_SET,
2689                 .off1   = td_var_offset(stonewall),
2690                 .help   = "Insert a hard barrier between this job and previous",
2691                 .category = FIO_OPT_C_GENERAL,
2692                 .group  = FIO_OPT_G_PROCESS,
2693         },
2694         {
2695                 .name   = "new_group",
2696                 .lname  = "New group",
2697                 .type   = FIO_OPT_STR_SET,
2698                 .off1   = td_var_offset(new_group),
2699                 .help   = "Mark the start of a new group (for reporting)",
2700                 .category = FIO_OPT_C_GENERAL,
2701                 .group  = FIO_OPT_G_PROCESS,
2702         },
2703         {
2704                 .name   = "thread",
2705                 .lname  = "Thread",
2706                 .type   = FIO_OPT_STR_SET,
2707                 .off1   = td_var_offset(use_thread),
2708                 .help   = "Use threads instead of processes",
2709                 .category = FIO_OPT_C_GENERAL,
2710                 .group  = FIO_OPT_G_PROCESS,
2711         },
2712         {
2713                 .name   = "write_bw_log",
2714                 .lname  = "Write bandwidth log",
2715                 .type   = FIO_OPT_STR_STORE,
2716                 .off1   = td_var_offset(bw_log_file),
2717                 .help   = "Write log of bandwidth during run",
2718                 .category = FIO_OPT_C_LOG,
2719                 .group  = FIO_OPT_G_INVALID,
2720         },
2721         {
2722                 .name   = "write_lat_log",
2723                 .lname  = "Write latency log",
2724                 .type   = FIO_OPT_STR_STORE,
2725                 .off1   = td_var_offset(lat_log_file),
2726                 .help   = "Write log of latency during run",
2727                 .category = FIO_OPT_C_LOG,
2728                 .group  = FIO_OPT_G_INVALID,
2729         },
2730         {
2731                 .name   = "write_iops_log",
2732                 .lname  = "Write IOPS log",
2733                 .type   = FIO_OPT_STR,
2734                 .off1   = td_var_offset(iops_log_file),
2735                 .help   = "Write log of IOPS during run",
2736                 .category = FIO_OPT_C_LOG,
2737                 .group  = FIO_OPT_G_INVALID,
2738         },
2739         {
2740                 .name   = "log_avg_msec",
2741                 .lname  = "Log averaging (msec)",
2742                 .type   = FIO_OPT_INT,
2743                 .off1   = td_var_offset(log_avg_msec),
2744                 .help   = "Average bw/iops/lat logs over this period of time",
2745                 .def    = "0",
2746                 .category = FIO_OPT_C_LOG,
2747                 .group  = FIO_OPT_G_INVALID,
2748         },
2749         {
2750                 .name   = "bwavgtime",
2751                 .lname  = "Bandwidth average time",
2752                 .type   = FIO_OPT_INT,
2753                 .off1   = td_var_offset(bw_avg_time),
2754                 .help   = "Time window over which to calculate bandwidth"
2755                           " (msec)",
2756                 .def    = "500",
2757                 .parent = "write_bw_log",
2758                 .hide   = 1,
2759                 .interval = 100,
2760                 .category = FIO_OPT_C_LOG,
2761                 .group  = FIO_OPT_G_INVALID,
2762         },
2763         {
2764                 .name   = "iopsavgtime",
2765                 .lname  = "IOPS average time",
2766                 .type   = FIO_OPT_INT,
2767                 .off1   = td_var_offset(iops_avg_time),
2768                 .help   = "Time window over which to calculate IOPS (msec)",
2769                 .def    = "500",
2770                 .parent = "write_iops_log",
2771                 .hide   = 1,
2772                 .interval = 100,
2773                 .category = FIO_OPT_C_LOG,
2774                 .group  = FIO_OPT_G_INVALID,
2775         },
2776         {
2777                 .name   = "group_reporting",
2778                 .lname  = "Group reporting",
2779                 .type   = FIO_OPT_BOOL,
2780                 .off1   = td_var_offset(group_reporting),
2781                 .help   = "Do reporting on a per-group basis",
2782                 .def    = "1",
2783                 .category = FIO_OPT_C_STAT,
2784                 .group  = FIO_OPT_G_INVALID,
2785         },
2786         {
2787                 .name   = "zero_buffers",
2788                 .lname  = "Zero I/O buffers",
2789                 .type   = FIO_OPT_STR_SET,
2790                 .off1   = td_var_offset(zero_buffers),
2791                 .help   = "Init IO buffers to all zeroes",
2792                 .category = FIO_OPT_C_IO,
2793                 .group  = FIO_OPT_G_IO_BUF,
2794         },
2795         {
2796                 .name   = "refill_buffers",
2797                 .lname  = "Refill I/O buffers",
2798                 .type   = FIO_OPT_STR_SET,
2799                 .off1   = td_var_offset(refill_buffers),
2800                 .help   = "Refill IO buffers on every IO submit",
2801                 .category = FIO_OPT_C_IO,
2802                 .group  = FIO_OPT_G_IO_BUF,
2803         },
2804         {
2805                 .name   = "scramble_buffers",
2806                 .lname  = "Scramble I/O buffers",
2807                 .type   = FIO_OPT_BOOL,
2808                 .off1   = td_var_offset(scramble_buffers),
2809                 .help   = "Slightly scramble buffers on every IO submit",
2810                 .def    = "1",
2811                 .category = FIO_OPT_C_IO,
2812                 .group  = FIO_OPT_G_IO_BUF,
2813         },
2814         {
2815                 .name   = "buffer_compress_percentage",
2816                 .lname  = "Buffer compression percentage",
2817                 .type   = FIO_OPT_INT,
2818                 .off1   = td_var_offset(compress_percentage),
2819                 .maxval = 100,
2820                 .minval = 1,
2821                 .help   = "How compressible the buffer is (approximately)",
2822                 .interval = 5,
2823                 .category = FIO_OPT_C_IO,
2824                 .group  = FIO_OPT_G_IO_BUF,
2825         },
2826         {
2827                 .name   = "buffer_compress_chunk",
2828                 .lname  = "Buffer compression chunk size",
2829                 .type   = FIO_OPT_INT,
2830                 .off1   = td_var_offset(compress_chunk),
2831                 .parent = "buffer_compress_percentage",
2832                 .hide   = 1,
2833                 .help   = "Size of compressible region in buffer",
2834                 .interval = 256,
2835                 .category = FIO_OPT_C_IO,
2836                 .group  = FIO_OPT_G_IO_BUF,
2837         },
2838         {
2839                 .name   = "clat_percentiles",
2840                 .lname  = "Completion latency percentiles",
2841                 .type   = FIO_OPT_BOOL,
2842                 .off1   = td_var_offset(clat_percentiles),
2843                 .help   = "Enable the reporting of completion latency percentiles",
2844                 .def    = "1",
2845                 .category = FIO_OPT_C_STAT,
2846                 .group  = FIO_OPT_G_INVALID,
2847         },
2848         {
2849                 .name   = "percentile_list",
2850                 .lname  = "Completion latency percentile list",
2851                 .type   = FIO_OPT_FLOAT_LIST,
2852                 .off1   = td_var_offset(percentile_list),
2853                 .off2   = td_var_offset(overwrite_plist),
2854                 .help   = "Specify a custom list of percentiles to report",
2855                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2856                 .minfp  = 0.0,
2857                 .maxfp  = 100.0,
2858                 .category = FIO_OPT_C_STAT,
2859                 .group  = FIO_OPT_G_INVALID,
2860         },
2861
2862 #ifdef FIO_HAVE_DISK_UTIL
2863         {
2864                 .name   = "disk_util",
2865                 .lname  = "Disk utilization",
2866                 .type   = FIO_OPT_BOOL,
2867                 .off1   = td_var_offset(do_disk_util),
2868                 .help   = "Log disk utilization statistics",
2869                 .def    = "1",
2870                 .category = FIO_OPT_C_STAT,
2871                 .group  = FIO_OPT_G_INVALID,
2872         },
2873 #endif
2874         {
2875                 .name   = "gtod_reduce",
2876                 .lname  = "Reduce gettimeofday() calls",
2877                 .type   = FIO_OPT_BOOL,
2878                 .help   = "Greatly reduce number of gettimeofday() calls",
2879                 .cb     = str_gtod_reduce_cb,
2880                 .def    = "0",
2881                 .hide_on_set = 1,
2882                 .category = FIO_OPT_C_STAT,
2883                 .group  = FIO_OPT_G_INVALID,
2884         },
2885         {
2886                 .name   = "disable_lat",
2887                 .lname  = "Disable all latency stats",
2888                 .type   = FIO_OPT_BOOL,
2889                 .off1   = td_var_offset(disable_lat),
2890                 .help   = "Disable latency numbers",
2891                 .parent = "gtod_reduce",
2892                 .hide   = 1,
2893                 .def    = "0",
2894                 .category = FIO_OPT_C_STAT,
2895                 .group  = FIO_OPT_G_INVALID,
2896         },
2897         {
2898                 .name   = "disable_clat",
2899                 .lname  = "Disable completion latency stats",
2900                 .type   = FIO_OPT_BOOL,
2901                 .off1   = td_var_offset(disable_clat),
2902                 .help   = "Disable completion latency numbers",
2903                 .parent = "gtod_reduce",
2904                 .hide   = 1,
2905                 .def    = "0",
2906                 .category = FIO_OPT_C_STAT,
2907                 .group  = FIO_OPT_G_INVALID,
2908         },
2909         {
2910                 .name   = "disable_slat",
2911                 .lname  = "Disable submission latency stats",
2912                 .type   = FIO_OPT_BOOL,
2913                 .off1   = td_var_offset(disable_slat),
2914                 .help   = "Disable submission latency numbers",
2915                 .parent = "gtod_reduce",
2916                 .hide   = 1,
2917                 .def    = "0",
2918                 .category = FIO_OPT_C_STAT,
2919                 .group  = FIO_OPT_G_INVALID,
2920         },
2921         {
2922                 .name   = "disable_bw_measurement",
2923                 .lname  = "Disable bandwidth stats",
2924                 .type   = FIO_OPT_BOOL,
2925                 .off1   = td_var_offset(disable_bw),
2926                 .help   = "Disable bandwidth logging",
2927                 .parent = "gtod_reduce",
2928                 .hide   = 1,
2929                 .def    = "0",
2930                 .category = FIO_OPT_C_STAT,
2931                 .group  = FIO_OPT_G_INVALID,
2932         },
2933         {
2934                 .name   = "gtod_cpu",
2935                 .lname  = "Dedicated gettimeofday() CPU",
2936                 .type   = FIO_OPT_INT,
2937                 .cb     = str_gtod_cpu_cb,
2938                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
2939                 .verify = gtod_cpu_verify,
2940                 .category = FIO_OPT_C_GENERAL,
2941                 .group  = FIO_OPT_G_CLOCK,
2942         },
2943         {
2944                 .name   = "continue_on_error",
2945                 .lname  = "Continue on error",
2946                 .type   = FIO_OPT_STR,
2947                 .off1   = td_var_offset(continue_on_error),
2948                 .help   = "Continue on non-fatal errors during IO",
2949                 .def    = "none",
2950                 .category = FIO_OPT_C_GENERAL,
2951                 .group  = FIO_OPT_G_ERR,
2952                 .posval = {
2953                           { .ival = "none",
2954                             .oval = ERROR_TYPE_NONE,
2955                             .help = "Exit when an error is encountered",
2956                           },
2957                           { .ival = "read",
2958                             .oval = ERROR_TYPE_READ,
2959                             .help = "Continue on read errors only",
2960                           },
2961                           { .ival = "write",
2962                             .oval = ERROR_TYPE_WRITE,
2963                             .help = "Continue on write errors only",
2964                           },
2965                           { .ival = "io",
2966                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2967                             .help = "Continue on any IO errors",
2968                           },
2969                           { .ival = "verify",
2970                             .oval = ERROR_TYPE_VERIFY,
2971                             .help = "Continue on verify errors only",
2972                           },
2973                           { .ival = "all",
2974                             .oval = ERROR_TYPE_ANY,
2975                             .help = "Continue on all io and verify errors",
2976                           },
2977                           { .ival = "0",
2978                             .oval = ERROR_TYPE_NONE,
2979                             .help = "Alias for 'none'",
2980                           },
2981                           { .ival = "1",
2982                             .oval = ERROR_TYPE_ANY,
2983                             .help = "Alias for 'all'",
2984                           },
2985                 },
2986         },
2987         {
2988                 .name   = "ignore_error",
2989                 .type   = FIO_OPT_STR,
2990                 .cb     = str_ignore_error_cb,
2991                 .help   = "Set a specific list of errors to ignore",
2992                 .parent = "rw",
2993                 .category = FIO_OPT_C_GENERAL,
2994                 .group  = FIO_OPT_G_ERR,
2995         },
2996         {
2997                 .name   = "error_dump",
2998                 .type   = FIO_OPT_BOOL,
2999                 .off1   = td_var_offset(error_dump),
3000                 .def    = "0",
3001                 .help   = "Dump info on each error",
3002                 .category = FIO_OPT_C_GENERAL,
3003                 .group  = FIO_OPT_G_ERR,
3004         },
3005         {
3006                 .name   = "profile",
3007                 .lname  = "Profile",
3008                 .type   = FIO_OPT_STR_STORE,
3009                 .off1   = td_var_offset(profile),
3010                 .help   = "Select a specific builtin performance test",
3011                 .category = FIO_OPT_C_PROFILE,
3012                 .group  = FIO_OPT_G_INVALID,
3013         },
3014         {
3015                 .name   = "cgroup",
3016                 .lname  = "Cgroup",
3017                 .type   = FIO_OPT_STR_STORE,
3018                 .off1   = td_var_offset(cgroup),
3019                 .help   = "Add job to cgroup of this name",
3020                 .category = FIO_OPT_C_GENERAL,
3021                 .group  = FIO_OPT_G_CGROUP,
3022         },
3023         {
3024                 .name   = "cgroup_nodelete",
3025                 .lname  = "Cgroup no-delete",
3026                 .type   = FIO_OPT_BOOL,
3027                 .off1   = td_var_offset(cgroup_nodelete),
3028                 .help   = "Do not delete cgroups after job completion",
3029                 .def    = "0",
3030                 .parent = "cgroup",
3031                 .category = FIO_OPT_C_GENERAL,
3032                 .group  = FIO_OPT_G_CGROUP,
3033         },
3034         {
3035                 .name   = "cgroup_weight",
3036                 .lname  = "Cgroup weight",
3037                 .type   = FIO_OPT_INT,
3038                 .off1   = td_var_offset(cgroup_weight),
3039                 .help   = "Use given weight for cgroup",
3040                 .minval = 100,
3041                 .maxval = 1000,
3042                 .parent = "cgroup",
3043                 .category = FIO_OPT_C_GENERAL,
3044                 .group  = FIO_OPT_G_CGROUP,
3045         },
3046         {
3047                 .name   = "uid",
3048                 .lname  = "User ID",
3049                 .type   = FIO_OPT_INT,
3050                 .off1   = td_var_offset(uid),
3051                 .help   = "Run job with this user ID",
3052                 .category = FIO_OPT_C_GENERAL,
3053                 .group  = FIO_OPT_G_CRED,
3054         },
3055         {
3056                 .name   = "gid",
3057                 .lname  = "Group ID",
3058                 .type   = FIO_OPT_INT,
3059                 .off1   = td_var_offset(gid),
3060                 .help   = "Run job with this group ID",
3061                 .category = FIO_OPT_C_GENERAL,
3062                 .group  = FIO_OPT_G_CRED,
3063         },
3064         {
3065                 .name   = "kb_base",
3066                 .lname  = "KB Base",
3067                 .type   = FIO_OPT_INT,
3068                 .off1   = td_var_offset(kb_base),
3069                 .verify = kb_base_verify,
3070                 .prio   = 1,
3071                 .def    = "1024",
3072                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
3073                 .category = FIO_OPT_C_GENERAL,
3074                 .group  = FIO_OPT_G_INVALID,
3075         },
3076         {
3077                 .name   = "hugepage-size",
3078                 .lname  = "Hugepage size",
3079                 .type   = FIO_OPT_INT,
3080                 .off1   = td_var_offset(hugepage_size),
3081                 .help   = "When using hugepages, specify size of each page",
3082                 .def    = __fio_stringify(FIO_HUGE_PAGE),
3083                 .interval = 1024 * 1024,
3084                 .category = FIO_OPT_C_GENERAL,
3085                 .group  = FIO_OPT_G_INVALID,
3086         },
3087         {
3088                 .name   = "flow_id",
3089                 .lname  = "I/O flow ID",
3090                 .type   = FIO_OPT_INT,
3091                 .off1   = td_var_offset(flow_id),
3092                 .help   = "The flow index ID to use",
3093                 .def    = "0",
3094                 .category = FIO_OPT_C_IO,
3095                 .group  = FIO_OPT_G_IO_FLOW,
3096         },
3097         {
3098                 .name   = "flow",
3099                 .lname  = "I/O flow weight",
3100                 .type   = FIO_OPT_INT,
3101                 .off1   = td_var_offset(flow),
3102                 .help   = "Weight for flow control of this job",
3103                 .parent = "flow_id",
3104                 .hide   = 1,
3105                 .def    = "0",
3106                 .category = FIO_OPT_C_IO,
3107                 .group  = FIO_OPT_G_IO_FLOW,
3108         },
3109         {
3110                 .name   = "flow_watermark",
3111                 .lname  = "I/O flow watermark",
3112                 .type   = FIO_OPT_INT,
3113                 .off1   = td_var_offset(flow_watermark),
3114                 .help   = "High watermark for flow control. This option"
3115                         " should be set to the same value for all threads"
3116                         " with non-zero flow.",
3117                 .parent = "flow_id",
3118                 .hide   = 1,
3119                 .def    = "1024",
3120                 .category = FIO_OPT_C_IO,
3121                 .group  = FIO_OPT_G_IO_FLOW,
3122         },
3123         {
3124                 .name   = "flow_sleep",
3125                 .lname  = "I/O flow sleep",
3126                 .type   = FIO_OPT_INT,
3127                 .off1   = td_var_offset(flow_sleep),
3128                 .help   = "How many microseconds to sleep after being held"
3129                         " back by the flow control mechanism",
3130                 .parent = "flow_id",
3131                 .hide   = 1,
3132                 .def    = "0",
3133                 .category = FIO_OPT_C_IO,
3134                 .group  = FIO_OPT_G_IO_FLOW,
3135         },
3136         {
3137                 .name = NULL,
3138         },
3139 };
3140
3141 static void add_to_lopt(struct option *lopt, struct fio_option *o,
3142                         const char *name, int val)
3143 {
3144         lopt->name = (char *) name;
3145         lopt->val = val;
3146         if (o->type == FIO_OPT_STR_SET)
3147                 lopt->has_arg = no_argument;
3148         else
3149                 lopt->has_arg = required_argument;
3150 }
3151
3152 static void options_to_lopts(struct fio_option *opts,
3153                               struct option *long_options,
3154                               int i, int option_type)
3155 {
3156         struct fio_option *o = &opts[0];
3157         while (o->name) {
3158                 add_to_lopt(&long_options[i], o, o->name, option_type);
3159                 if (o->alias) {
3160                         i++;
3161                         add_to_lopt(&long_options[i], o, o->alias, option_type);
3162                 }
3163
3164                 i++;
3165                 o++;
3166                 assert(i < FIO_NR_OPTIONS);
3167         }
3168 }
3169
3170 void fio_options_set_ioengine_opts(struct option *long_options,
3171                                    struct thread_data *td)
3172 {
3173         unsigned int i;
3174
3175         i = 0;
3176         while (long_options[i].name) {
3177                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
3178                         memset(&long_options[i], 0, sizeof(*long_options));
3179                         break;
3180                 }
3181                 i++;
3182         }
3183
3184         /*
3185          * Just clear out the prior ioengine options.
3186          */
3187         if (!td || !td->eo)
3188                 return;
3189
3190         options_to_lopts(td->io_ops->options, long_options, i,
3191                          FIO_GETOPT_IOENGINE);
3192 }
3193
3194 void fio_options_dup_and_init(struct option *long_options)
3195 {
3196         unsigned int i;
3197
3198         options_init(fio_options);
3199
3200         i = 0;
3201         while (long_options[i].name)
3202                 i++;
3203
3204         options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
3205 }
3206
3207 struct fio_keyword {
3208         const char *word;
3209         const char *desc;
3210         char *replace;
3211 };
3212
3213 static struct fio_keyword fio_keywords[] = {
3214         {
3215                 .word   = "$pagesize",
3216                 .desc   = "Page size in the system",
3217         },
3218         {
3219                 .word   = "$mb_memory",
3220                 .desc   = "Megabytes of memory online",
3221         },
3222         {
3223                 .word   = "$ncpus",
3224                 .desc   = "Number of CPUs online in the system",
3225         },
3226         {
3227                 .word   = NULL,
3228         },
3229 };
3230
3231 void fio_keywords_init(void)
3232 {
3233         unsigned long long mb_memory;
3234         char buf[128];
3235         long l;
3236
3237         sprintf(buf, "%lu", (unsigned long) page_size);
3238         fio_keywords[0].replace = strdup(buf);
3239
3240         mb_memory = os_phys_mem() / (1024 * 1024);
3241         sprintf(buf, "%llu", mb_memory);
3242         fio_keywords[1].replace = strdup(buf);
3243
3244         l = cpus_online();
3245         sprintf(buf, "%lu", l);
3246         fio_keywords[2].replace = strdup(buf);
3247 }
3248
3249 #define BC_APP          "bc"
3250
3251 static char *bc_calc(char *str)
3252 {
3253         char buf[128], *tmp;
3254         FILE *f;
3255         int ret;
3256
3257         /*
3258          * No math, just return string
3259          */
3260         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
3261              !strchr(str, '/')) || strchr(str, '\''))
3262                 return str;
3263
3264         /*
3265          * Split option from value, we only need to calculate the value
3266          */
3267         tmp = strchr(str, '=');
3268         if (!tmp)
3269                 return str;
3270
3271         tmp++;
3272
3273         /*
3274          * Prevent buffer overflows; such a case isn't reasonable anyway
3275          */
3276         if (strlen(str) >= 128 || strlen(tmp) > 100)
3277                 return str;
3278
3279         sprintf(buf, "which %s > /dev/null", BC_APP);
3280         if (system(buf)) {
3281                 log_err("fio: bc is needed for performing math\n");
3282                 return NULL;
3283         }
3284
3285         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
3286         f = popen(buf, "r");
3287         if (!f)
3288                 return NULL;
3289
3290         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
3291         if (ret <= 0)
3292                 return NULL;
3293
3294         pclose(f);
3295         buf[(tmp - str) + ret - 1] = '\0';
3296         memcpy(buf, str, tmp - str);
3297         free(str);
3298         return strdup(buf);
3299 }
3300
3301 /*
3302  * Return a copy of the input string with substrings of the form ${VARNAME}
3303  * substituted with the value of the environment variable VARNAME.  The
3304  * substitution always occurs, even if VARNAME is empty or the corresponding
3305  * environment variable undefined.
3306  */
3307 static char *option_dup_subs(const char *opt)
3308 {
3309         char out[OPT_LEN_MAX+1];
3310         char in[OPT_LEN_MAX+1];
3311         char *outptr = out;
3312         char *inptr = in;
3313         char *ch1, *ch2, *env;
3314         ssize_t nchr = OPT_LEN_MAX;
3315         size_t envlen;
3316
3317         if (strlen(opt) + 1 > OPT_LEN_MAX) {
3318                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
3319                 return NULL;
3320         }
3321
3322         in[OPT_LEN_MAX] = '\0';
3323         strncpy(in, opt, OPT_LEN_MAX);
3324
3325         while (*inptr && nchr > 0) {
3326                 if (inptr[0] == '$' && inptr[1] == '{') {
3327                         ch2 = strchr(inptr, '}');
3328                         if (ch2 && inptr+1 < ch2) {
3329                                 ch1 = inptr+2;
3330                                 inptr = ch2+1;
3331                                 *ch2 = '\0';
3332
3333                                 env = getenv(ch1);
3334                                 if (env) {
3335                                         envlen = strlen(env);
3336                                         if (envlen <= nchr) {
3337                                                 memcpy(outptr, env, envlen);
3338                                                 outptr += envlen;
3339                                                 nchr -= envlen;
3340                                         }
3341                                 }
3342
3343                                 continue;
3344                         }
3345                 }
3346
3347                 *outptr++ = *inptr++;
3348                 --nchr;
3349         }
3350
3351         *outptr = '\0';
3352         return strdup(out);
3353 }
3354
3355 /*
3356  * Look for reserved variable names and replace them with real values
3357  */
3358 static char *fio_keyword_replace(char *opt)
3359 {
3360         char *s;
3361         int i;
3362         int docalc = 0;
3363
3364         for (i = 0; fio_keywords[i].word != NULL; i++) {
3365                 struct fio_keyword *kw = &fio_keywords[i];
3366
3367                 while ((s = strstr(opt, kw->word)) != NULL) {
3368                         char *new = malloc(strlen(opt) + 1);
3369                         char *o_org = opt;
3370                         int olen = s - opt;
3371                         int len;
3372
3373                         /*
3374                          * Copy part of the string before the keyword and
3375                          * sprintf() the replacement after it.
3376                          */
3377                         memcpy(new, opt, olen);
3378                         len = sprintf(new + olen, "%s", kw->replace);
3379
3380                         /*
3381                          * If there's more in the original string, copy that
3382                          * in too
3383                          */
3384                         opt += strlen(kw->word) + olen;
3385                         if (strlen(opt))
3386                                 memcpy(new + olen + len, opt, opt - o_org - 1);
3387
3388                         /*
3389                          * replace opt and free the old opt
3390                          */
3391                         opt = new;
3392                         free(o_org);
3393
3394                         docalc = 1;
3395                 }
3396         }
3397
3398         /*
3399          * Check for potential math and invoke bc, if possible
3400          */
3401         if (docalc)
3402                 opt = bc_calc(opt);
3403
3404         return opt;
3405 }
3406
3407 static char **dup_and_sub_options(char **opts, int num_opts)
3408 {
3409         int i;
3410         char **opts_copy = malloc(num_opts * sizeof(*opts));
3411         for (i = 0; i < num_opts; i++) {
3412                 opts_copy[i] = option_dup_subs(opts[i]);
3413                 if (!opts_copy[i])
3414                         continue;
3415                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
3416         }
3417         return opts_copy;
3418 }
3419
3420 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
3421 {
3422         int i, ret, unknown;
3423         char **opts_copy;
3424
3425         sort_options(opts, fio_options, num_opts);
3426         opts_copy = dup_and_sub_options(opts, num_opts);
3427
3428         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
3429                 struct fio_option *o;
3430                 int newret = parse_option(opts_copy[i], opts[i], fio_options,
3431                                                 &o, td);
3432
3433                 if (opts_copy[i]) {
3434                         if (newret && !o) {
3435                                 unknown++;
3436                                 continue;
3437                         }
3438                         free(opts_copy[i]);
3439                         opts_copy[i] = NULL;
3440                 }
3441
3442                 ret |= newret;
3443         }
3444
3445         if (unknown) {
3446                 ret |= ioengine_load(td);
3447                 if (td->eo) {
3448                         sort_options(opts_copy, td->io_ops->options, num_opts);
3449                         opts = opts_copy;
3450                 }
3451                 for (i = 0; i < num_opts; i++) {
3452                         struct fio_option *o = NULL;
3453                         int newret = 1;
3454                         if (!opts_copy[i])
3455                                 continue;
3456
3457                         if (td->eo)
3458                                 newret = parse_option(opts_copy[i], opts[i],
3459                                                       td->io_ops->options, &o,
3460                                                       td->eo);
3461
3462                         ret |= newret;
3463                         if (!o)
3464                                 log_err("Bad option <%s>\n", opts[i]);
3465
3466                         free(opts_copy[i]);
3467                         opts_copy[i] = NULL;
3468                 }
3469         }
3470
3471         free(opts_copy);
3472         return ret;
3473 }
3474
3475 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
3476 {
3477         return parse_cmd_option(opt, val, fio_options, td);
3478 }
3479
3480 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
3481                                 char *val)
3482 {
3483         return parse_cmd_option(opt, val, td->io_ops->options, td);
3484 }
3485
3486 void fio_fill_default_options(struct thread_data *td)
3487 {
3488         fill_default_options(td, fio_options);
3489 }
3490
3491 int fio_show_option_help(const char *opt)
3492 {
3493         return show_cmd_help(fio_options, opt);
3494 }
3495
3496 void options_mem_dupe(void *data, struct fio_option *options)
3497 {
3498         struct fio_option *o;
3499         char **ptr;
3500
3501         for (o = &options[0]; o->name; o++) {
3502                 if (o->type != FIO_OPT_STR_STORE)
3503                         continue;
3504
3505                 ptr = td_var(data, o->off1);
3506                 if (*ptr)
3507                         *ptr = strdup(*ptr);
3508         }
3509 }
3510
3511 /*
3512  * dupe FIO_OPT_STR_STORE options
3513  */
3514 void fio_options_mem_dupe(struct thread_data *td)
3515 {
3516         options_mem_dupe(&td->o, fio_options);
3517
3518         if (td->eo && td->io_ops) {
3519                 void *oldeo = td->eo;
3520
3521                 td->eo = malloc(td->io_ops->option_struct_size);
3522                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
3523                 options_mem_dupe(td->eo, td->io_ops->options);
3524         }
3525 }
3526
3527 unsigned int fio_get_kb_base(void *data)
3528 {
3529         struct thread_options *o = data;
3530         unsigned int kb_base = 0;
3531
3532         if (o)
3533                 kb_base = o->kb_base;
3534         if (!kb_base)
3535                 kb_base = 1024;
3536
3537         return kb_base;
3538 }
3539
3540 int add_option(struct fio_option *o)
3541 {
3542         struct fio_option *__o;
3543         int opt_index = 0;
3544
3545         __o = fio_options;
3546         while (__o->name) {
3547                 opt_index++;
3548                 __o++;
3549         }
3550
3551         memcpy(&fio_options[opt_index], o, sizeof(*o));
3552         return 0;
3553 }
3554
3555 void invalidate_profile_options(const char *prof_name)
3556 {
3557         struct fio_option *o;
3558
3559         o = fio_options;
3560         while (o->name) {
3561                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
3562                         o->type = FIO_OPT_INVALID;
3563                         o->prof_name = NULL;
3564                 }
3565                 o++;
3566         }
3567 }
3568
3569 void add_opt_posval(const char *optname, const char *ival, const char *help)
3570 {
3571         struct fio_option *o;
3572         unsigned int i;
3573
3574         o = find_option(fio_options, optname);
3575         if (!o)
3576                 return;
3577
3578         for (i = 0; i < PARSE_MAX_VP; i++) {
3579                 if (o->posval[i].ival)
3580                         continue;
3581
3582                 o->posval[i].ival = ival;
3583                 o->posval[i].help = help;
3584                 break;
3585         }
3586 }
3587
3588 void del_opt_posval(const char *optname, const char *ival)
3589 {
3590         struct fio_option *o;
3591         unsigned int i;
3592
3593         o = find_option(fio_options, optname);
3594         if (!o)
3595                 return;
3596
3597         for (i = 0; i < PARSE_MAX_VP; i++) {
3598                 if (!o->posval[i].ival)
3599                         continue;
3600                 if (strcmp(o->posval[i].ival, ival))
3601                         continue;
3602
3603                 o->posval[i].ival = NULL;
3604                 o->posval[i].help = NULL;
3605         }
3606 }
3607
3608 void fio_options_free(struct thread_data *td)
3609 {
3610         options_free(fio_options, td);
3611         if (td->eo && td->io_ops && td->io_ops->options) {
3612                 options_free(td->io_ops->options, td->eo);
3613                 free(td->eo);
3614                 td->eo = NULL;
3615         }
3616 }
3617
3618 struct fio_option *fio_option_find(const char *name)
3619 {
3620         return find_option(fio_options, name);
3621 }
3622