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