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