574916179f04a968b9877df234ebd3a599f84728
[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   = NULL,
935         }
936 };
937
938 struct opt_group *opt_group_cat_from_mask(unsigned int *mask)
939 {
940         return __opt_group_from_mask(fio_opt_cat_groups, mask, FIO_OPT_G_INVALID);
941 }
942
943 /*
944  * Map of job/command line options
945  */
946 struct fio_option fio_options[FIO_MAX_OPTS] = {
947         {
948                 .name   = "description",
949                 .lname  = "Description of job",
950                 .type   = FIO_OPT_STR_STORE,
951                 .off1   = td_var_offset(description),
952                 .help   = "Text job description",
953                 .category = FIO_OPT_C_GENERAL,
954                 .group  = FIO_OPT_G_INVALID,
955         },
956         {
957                 .name   = "name",
958                 .lname  = "Job name",
959                 .type   = FIO_OPT_STR_STORE,
960                 .off1   = td_var_offset(name),
961                 .help   = "Name of this job",
962                 .category = FIO_OPT_C_GENERAL,
963                 .group  = FIO_OPT_G_INVALID,
964         },
965         {
966                 .name   = "kb_base",
967                 .lname  = "KB Base",
968                 .type   = FIO_OPT_INT,
969                 .off1   = td_var_offset(kb_base),
970                 .verify = kb_base_verify,
971                 .prio   = 1,
972                 .def    = "1024",
973                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
974                 .category = FIO_OPT_C_GENERAL,
975                 .group  = FIO_OPT_G_INVALID,
976         },
977         {
978                 .name   = "filename",
979                 .lname  = "Filename(s)",
980                 .type   = FIO_OPT_STR_STORE,
981                 .off1   = td_var_offset(filename),
982                 .cb     = str_filename_cb,
983                 .prio   = -1, /* must come after "directory" */
984                 .help   = "File(s) to use for the workload",
985                 .category = FIO_OPT_C_FILE,
986                 .group  = FIO_OPT_G_INVALID,
987         },
988         {
989                 .name   = "directory",
990                 .lname  = "Directory",
991                 .type   = FIO_OPT_STR_STORE,
992                 .off1   = td_var_offset(directory),
993                 .cb     = str_directory_cb,
994                 .help   = "Directory to store files in",
995                 .category = FIO_OPT_C_FILE,
996                 .group  = FIO_OPT_G_INVALID,
997         },
998         {
999                 .name   = "lockfile",
1000                 .lname  = "Lockfile",
1001                 .type   = FIO_OPT_STR,
1002                 .cb     = str_lockfile_cb,
1003                 .off1   = td_var_offset(file_lock_mode),
1004                 .help   = "Lock file when doing IO to it",
1005                 .parent = "filename",
1006                 .hide   = 0,
1007                 .def    = "none",
1008                 .category = FIO_OPT_C_FILE,
1009                 .group  = FIO_OPT_G_INVALID,
1010                 .posval = {
1011                           { .ival = "none",
1012                             .oval = FILE_LOCK_NONE,
1013                             .help = "No file locking",
1014                           },
1015                           { .ival = "exclusive",
1016                             .oval = FILE_LOCK_EXCLUSIVE,
1017                             .help = "Exclusive file lock",
1018                           },
1019                           {
1020                             .ival = "readwrite",
1021                             .oval = FILE_LOCK_READWRITE,
1022                             .help = "Read vs write lock",
1023                           },
1024                 },
1025         },
1026         {
1027                 .name   = "opendir",
1028                 .lname  = "Open directory",
1029                 .type   = FIO_OPT_STR_STORE,
1030                 .off1   = td_var_offset(opendir),
1031                 .cb     = str_opendir_cb,
1032                 .help   = "Recursively add files from this directory and down",
1033                 .category = FIO_OPT_C_FILE,
1034                 .group  = FIO_OPT_G_INVALID,
1035         },
1036         {
1037                 .name   = "rw",
1038                 .lname  = "Read/write",
1039                 .alias  = "readwrite",
1040                 .type   = FIO_OPT_STR,
1041                 .cb     = str_rw_cb,
1042                 .off1   = td_var_offset(td_ddir),
1043                 .help   = "IO direction",
1044                 .def    = "read",
1045                 .verify = rw_verify,
1046                 .category = FIO_OPT_C_IO,
1047                 .group  = FIO_OPT_G_INVALID,
1048                 .posval = {
1049                           { .ival = "read",
1050                             .oval = TD_DDIR_READ,
1051                             .help = "Sequential read",
1052                           },
1053                           { .ival = "write",
1054                             .oval = TD_DDIR_WRITE,
1055                             .help = "Sequential write",
1056                           },
1057                           { .ival = "randread",
1058                             .oval = TD_DDIR_RANDREAD,
1059                             .help = "Random read",
1060                           },
1061                           { .ival = "randwrite",
1062                             .oval = TD_DDIR_RANDWRITE,
1063                             .help = "Random write",
1064                           },
1065                           { .ival = "rw",
1066                             .oval = TD_DDIR_RW,
1067                             .help = "Sequential read and write mix",
1068                           },
1069                           { .ival = "randrw",
1070                             .oval = TD_DDIR_RANDRW,
1071                             .help = "Random read and write mix"
1072                           },
1073                 },
1074         },
1075         {
1076                 .name   = "rw_sequencer",
1077                 .lname  = "RW Sequencer",
1078                 .type   = FIO_OPT_STR,
1079                 .off1   = td_var_offset(rw_seq),
1080                 .help   = "IO offset generator modifier",
1081                 .def    = "sequential",
1082                 .category = FIO_OPT_C_IO,
1083                 .group  = FIO_OPT_G_INVALID,
1084                 .posval = {
1085                           { .ival = "sequential",
1086                             .oval = RW_SEQ_SEQ,
1087                             .help = "Generate sequential offsets",
1088                           },
1089                           { .ival = "identical",
1090                             .oval = RW_SEQ_IDENT,
1091                             .help = "Generate identical offsets",
1092                           },
1093                 },
1094         },
1095
1096         {
1097                 .name   = "ioengine",
1098                 .lname  = "IO Engine",
1099                 .type   = FIO_OPT_STR_STORE,
1100                 .off1   = td_var_offset(ioengine),
1101                 .help   = "IO engine to use",
1102                 .def    = FIO_PREFERRED_ENGINE,
1103                 .category = FIO_OPT_C_IO,
1104                 .group  = FIO_OPT_G_INVALID,
1105                 .posval = {
1106                           { .ival = "sync",
1107                             .help = "Use read/write",
1108                           },
1109                           { .ival = "psync",
1110                             .help = "Use pread/pwrite",
1111                           },
1112                           { .ival = "vsync",
1113                             .help = "Use readv/writev",
1114                           },
1115 #ifdef FIO_HAVE_LIBAIO
1116                           { .ival = "libaio",
1117                             .help = "Linux native asynchronous IO",
1118                           },
1119 #endif
1120 #ifdef FIO_HAVE_POSIXAIO
1121                           { .ival = "posixaio",
1122                             .help = "POSIX asynchronous IO",
1123                           },
1124 #endif
1125 #ifdef FIO_HAVE_SOLARISAIO
1126                           { .ival = "solarisaio",
1127                             .help = "Solaris native asynchronous IO",
1128                           },
1129 #endif
1130 #ifdef FIO_HAVE_WINDOWSAIO
1131                           { .ival = "windowsaio",
1132                             .help = "Windows native asynchronous IO"
1133                           },
1134 #endif
1135                           { .ival = "mmap",
1136                             .help = "Memory mapped IO"
1137                           },
1138 #ifdef FIO_HAVE_SPLICE
1139                           { .ival = "splice",
1140                             .help = "splice/vmsplice based IO",
1141                           },
1142                           { .ival = "netsplice",
1143                             .help = "splice/vmsplice to/from the network",
1144                           },
1145 #endif
1146 #ifdef FIO_HAVE_SGIO
1147                           { .ival = "sg",
1148                             .help = "SCSI generic v3 IO",
1149                           },
1150 #endif
1151                           { .ival = "null",
1152                             .help = "Testing engine (no data transfer)",
1153                           },
1154                           { .ival = "net",
1155                             .help = "Network IO",
1156                           },
1157 #ifdef FIO_HAVE_SYSLET
1158                           { .ival = "syslet-rw",
1159                             .help = "syslet enabled async pread/pwrite IO",
1160                           },
1161 #endif
1162                           { .ival = "cpuio",
1163                             .help = "CPU cycle burner engine",
1164                           },
1165 #ifdef FIO_HAVE_GUASI
1166                           { .ival = "guasi",
1167                             .help = "GUASI IO engine",
1168                           },
1169 #endif
1170 #ifdef FIO_HAVE_BINJECT
1171                           { .ival = "binject",
1172                             .help = "binject direct inject block engine",
1173                           },
1174 #endif
1175 #ifdef FIO_HAVE_RDMA
1176                           { .ival = "rdma",
1177                             .help = "RDMA IO engine",
1178                           },
1179 #endif
1180                           { .ival = "external",
1181                             .help = "Load external engine (append name)",
1182                           },
1183                 },
1184         },
1185         {
1186                 .name   = "iodepth",
1187                 .lname  = "IO Depth",
1188                 .type   = FIO_OPT_INT,
1189                 .off1   = td_var_offset(iodepth),
1190                 .help   = "Number of IO buffers to keep in flight",
1191                 .minval = 1,
1192                 .interval = 1,
1193                 .def    = "1",
1194                 .category = FIO_OPT_C_IO,
1195                 .group  = FIO_OPT_G_IO_DEPTH,
1196         },
1197         {
1198                 .name   = "iodepth_batch",
1199                 .lname  = "IO Depth batch",
1200                 .alias  = "iodepth_batch_submit",
1201                 .type   = FIO_OPT_INT,
1202                 .off1   = td_var_offset(iodepth_batch),
1203                 .help   = "Number of IO buffers to submit in one go",
1204                 .parent = "iodepth",
1205                 .hide   = 1,
1206                 .minval = 1,
1207                 .interval = 1,
1208                 .def    = "1",
1209                 .category = FIO_OPT_C_IO,
1210                 .group  = FIO_OPT_G_IO_DEPTH,
1211         },
1212         {
1213                 .name   = "iodepth_batch_complete",
1214                 .lname  = "IO Depth batch complete",
1215                 .type   = FIO_OPT_INT,
1216                 .off1   = td_var_offset(iodepth_batch_complete),
1217                 .help   = "Number of IO buffers to retrieve in one go",
1218                 .parent = "iodepth",
1219                 .hide   = 1,
1220                 .minval = 0,
1221                 .interval = 1,
1222                 .def    = "1",
1223                 .category = FIO_OPT_C_IO,
1224                 .group  = FIO_OPT_G_IO_DEPTH,
1225         },
1226         {
1227                 .name   = "iodepth_low",
1228                 .lname  = "IO Depth batch low",
1229                 .type   = FIO_OPT_INT,
1230                 .off1   = td_var_offset(iodepth_low),
1231                 .help   = "Low water mark for queuing depth",
1232                 .parent = "iodepth",
1233                 .hide   = 1,
1234                 .interval = 1,
1235                 .category = FIO_OPT_C_IO,
1236                 .group  = FIO_OPT_G_IO_DEPTH,
1237         },
1238         {
1239                 .name   = "size",
1240                 .lname  = "Size",
1241                 .type   = FIO_OPT_STR_VAL,
1242                 .cb     = str_size_cb,
1243                 .help   = "Total size of device or files",
1244                 .interval = 1024 * 1024,
1245                 .category = FIO_OPT_C_IO,
1246                 .group  = FIO_OPT_G_INVALID,
1247         },
1248         {
1249                 .name   = "fill_device",
1250                 .lname  = "Fill device",
1251                 .alias  = "fill_fs",
1252                 .type   = FIO_OPT_BOOL,
1253                 .off1   = td_var_offset(fill_device),
1254                 .help   = "Write until an ENOSPC error occurs",
1255                 .def    = "0",
1256                 .category = FIO_OPT_C_FILE,
1257                 .group  = FIO_OPT_G_INVALID,
1258         },
1259         {
1260                 .name   = "filesize",
1261                 .lname  = "File size",
1262                 .type   = FIO_OPT_STR_VAL,
1263                 .off1   = td_var_offset(file_size_low),
1264                 .off2   = td_var_offset(file_size_high),
1265                 .minval = 1,
1266                 .help   = "Size of individual files",
1267                 .interval = 1024 * 1024,
1268                 .category = FIO_OPT_C_FILE,
1269                 .group  = FIO_OPT_G_INVALID,
1270         },
1271         {
1272                 .name   = "offset",
1273                 .lname  = "IO offset",
1274                 .alias  = "fileoffset",
1275                 .type   = FIO_OPT_STR_VAL,
1276                 .off1   = td_var_offset(start_offset),
1277                 .help   = "Start IO from this offset",
1278                 .def    = "0",
1279                 .interval = 1024 * 1024,
1280                 .category = FIO_OPT_C_IO,
1281                 .group  = FIO_OPT_G_INVALID,
1282         },
1283         {
1284                 .name   = "offset_increment",
1285                 .lname  = "IO offset increment",
1286                 .type   = FIO_OPT_STR_VAL,
1287                 .off1   = td_var_offset(offset_increment),
1288                 .help   = "What is the increment from one offset to the next",
1289                 .parent = "offset",
1290                 .hide   = 1,
1291                 .def    = "0",
1292                 .interval = 1024 * 1024,
1293                 .category = FIO_OPT_C_IO,
1294                 .group  = FIO_OPT_G_INVALID,
1295         },
1296         {
1297                 .name   = "bs",
1298                 .lname  = "Block size",
1299                 .alias  = "blocksize",
1300                 .type   = FIO_OPT_INT,
1301                 .off1   = td_var_offset(bs[DDIR_READ]),
1302                 .off2   = td_var_offset(bs[DDIR_WRITE]),
1303                 .minval = 1,
1304                 .help   = "Block size unit",
1305                 .def    = "4k",
1306                 .parent = "rw",
1307                 .hide   = 1,
1308                 .interval = 512,
1309                 .category = FIO_OPT_C_IO,
1310                 .group  = FIO_OPT_G_INVALID,
1311         },
1312         {
1313                 .name   = "ba",
1314                 .lname  = "Block size align",
1315                 .alias  = "blockalign",
1316                 .type   = FIO_OPT_INT,
1317                 .off1   = td_var_offset(ba[DDIR_READ]),
1318                 .off2   = td_var_offset(ba[DDIR_WRITE]),
1319                 .minval = 1,
1320                 .help   = "IO block offset alignment",
1321                 .parent = "rw",
1322                 .hide   = 1,
1323                 .interval = 512,
1324                 .category = FIO_OPT_C_IO,
1325                 .group  = FIO_OPT_G_INVALID,
1326         },
1327         {
1328                 .name   = "bsrange",
1329                 .lname  = "Block size range",
1330                 .alias  = "blocksize_range",
1331                 .type   = FIO_OPT_RANGE,
1332                 .off1   = td_var_offset(min_bs[DDIR_READ]),
1333                 .off2   = td_var_offset(max_bs[DDIR_READ]),
1334                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
1335                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
1336                 .minval = 1,
1337                 .help   = "Set block size range (in more detail than bs)",
1338                 .parent = "rw",
1339                 .hide   = 1,
1340                 .interval = 4096,
1341                 .category = FIO_OPT_C_IO,
1342                 .group  = FIO_OPT_G_INVALID,
1343         },
1344         {
1345                 .name   = "bssplit",
1346                 .lname  = "Block size split",
1347                 .type   = FIO_OPT_STR,
1348                 .cb     = str_bssplit_cb,
1349                 .help   = "Set a specific mix of block sizes",
1350                 .parent = "rw",
1351                 .hide   = 1,
1352                 .category = FIO_OPT_C_IO,
1353                 .group  = FIO_OPT_G_INVALID,
1354         },
1355         {
1356                 .name   = "bs_unaligned",
1357                 .lname  = "Block size unaligned",
1358                 .alias  = "blocksize_unaligned",
1359                 .type   = FIO_OPT_STR_SET,
1360                 .off1   = td_var_offset(bs_unaligned),
1361                 .help   = "Don't sector align IO buffer sizes",
1362                 .parent = "rw",
1363                 .hide   = 1,
1364                 .category = FIO_OPT_C_IO,
1365                 .group  = FIO_OPT_G_INVALID,
1366         },
1367         {
1368                 .name   = "randrepeat",
1369                 .lname  = "Random repeatable",
1370                 .type   = FIO_OPT_BOOL,
1371                 .off1   = td_var_offset(rand_repeatable),
1372                 .help   = "Use repeatable random IO pattern",
1373                 .def    = "1",
1374                 .parent = "rw",
1375                 .hide   = 1,
1376                 .category = FIO_OPT_C_IO,
1377                 .group  = FIO_OPT_G_INVALID,
1378         },
1379         {
1380                 .name   = "use_os_rand",
1381                 .lname  = "Use OS random",
1382                 .type   = FIO_OPT_BOOL,
1383                 .off1   = td_var_offset(use_os_rand),
1384                 .help   = "Set to use OS random generator",
1385                 .def    = "0",
1386                 .parent = "rw",
1387                 .hide   = 1,
1388                 .category = FIO_OPT_C_IO,
1389                 .group  = FIO_OPT_G_INVALID,
1390         },
1391         {
1392                 .name   = "norandommap",
1393                 .lname  = "No randommap",
1394                 .type   = FIO_OPT_STR_SET,
1395                 .off1   = td_var_offset(norandommap),
1396                 .help   = "Accept potential duplicate random blocks",
1397                 .parent = "rw",
1398                 .hide   = 1,
1399                 .category = FIO_OPT_C_IO,
1400                 .group  = FIO_OPT_G_INVALID,
1401         },
1402         {
1403                 .name   = "softrandommap",
1404                 .lname  = "Soft randommap",
1405                 .type   = FIO_OPT_BOOL,
1406                 .off1   = td_var_offset(softrandommap),
1407                 .help   = "Set norandommap if randommap allocation fails",
1408                 .parent = "norandommap",
1409                 .hide   = 1,
1410                 .def    = "0",
1411                 .category = FIO_OPT_C_IO,
1412                 .group  = FIO_OPT_G_INVALID,
1413         },
1414         {
1415                 .name   = "nrfiles",
1416                 .lname  = "Number of files",
1417                 .alias  = "nr_files",
1418                 .type   = FIO_OPT_INT,
1419                 .off1   = td_var_offset(nr_files),
1420                 .help   = "Split job workload between this number of files",
1421                 .def    = "1",
1422                 .interval = 1,
1423                 .category = FIO_OPT_C_FILE,
1424                 .group  = FIO_OPT_G_INVALID,
1425         },
1426         {
1427                 .name   = "openfiles",
1428                 .lname  = "Number of open files",
1429                 .type   = FIO_OPT_INT,
1430                 .off1   = td_var_offset(open_files),
1431                 .help   = "Number of files to keep open at the same time",
1432                 .category = FIO_OPT_C_FILE,
1433                 .group  = FIO_OPT_G_INVALID,
1434         },
1435         {
1436                 .name   = "file_service_type",
1437                 .lname  = "File service type",
1438                 .type   = FIO_OPT_STR,
1439                 .cb     = str_fst_cb,
1440                 .off1   = td_var_offset(file_service_type),
1441                 .help   = "How to select which file to service next",
1442                 .def    = "roundrobin",
1443                 .category = FIO_OPT_C_FILE,
1444                 .group  = FIO_OPT_G_INVALID,
1445                 .posval = {
1446                           { .ival = "random",
1447                             .oval = FIO_FSERVICE_RANDOM,
1448                             .help = "Choose a file at random",
1449                           },
1450                           { .ival = "roundrobin",
1451                             .oval = FIO_FSERVICE_RR,
1452                             .help = "Round robin select files",
1453                           },
1454                           { .ival = "sequential",
1455                             .oval = FIO_FSERVICE_SEQ,
1456                             .help = "Finish one file before moving to the next",
1457                           },
1458                 },
1459                 .parent = "nrfiles",
1460                 .hide   = 1,
1461         },
1462 #ifdef FIO_HAVE_FALLOCATE
1463         {
1464                 .name   = "fallocate",
1465                 .lname  = "Fallocate",
1466                 .type   = FIO_OPT_STR,
1467                 .off1   = td_var_offset(fallocate_mode),
1468                 .help   = "Whether pre-allocation is performed when laying out files",
1469                 .def    = "posix",
1470                 .category = FIO_OPT_C_FILE,
1471                 .group  = FIO_OPT_G_INVALID,
1472                 .posval = {
1473                           { .ival = "none",
1474                             .oval = FIO_FALLOCATE_NONE,
1475                             .help = "Do not pre-allocate space",
1476                           },
1477                           { .ival = "posix",
1478                             .oval = FIO_FALLOCATE_POSIX,
1479                             .help = "Use posix_fallocate()",
1480                           },
1481 #ifdef FIO_HAVE_LINUX_FALLOCATE
1482                           { .ival = "keep",
1483                             .oval = FIO_FALLOCATE_KEEP_SIZE,
1484                             .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1485                           },
1486 #endif
1487                           /* Compatibility with former boolean values */
1488                           { .ival = "0",
1489                             .oval = FIO_FALLOCATE_NONE,
1490                             .help = "Alias for 'none'",
1491                           },
1492                           { .ival = "1",
1493                             .oval = FIO_FALLOCATE_POSIX,
1494                             .help = "Alias for 'posix'",
1495                           },
1496                 },
1497         },
1498 #endif  /* FIO_HAVE_FALLOCATE */
1499         {
1500                 .name   = "fadvise_hint",
1501                 .lname  = "Fadvise hint",
1502                 .type   = FIO_OPT_BOOL,
1503                 .off1   = td_var_offset(fadvise_hint),
1504                 .help   = "Use fadvise() to advise the kernel on IO pattern",
1505                 .def    = "1",
1506                 .category = FIO_OPT_C_FILE,
1507                 .group  = FIO_OPT_G_INVALID,
1508         },
1509         {
1510                 .name   = "fsync",
1511                 .lname  = "Fsync",
1512                 .type   = FIO_OPT_INT,
1513                 .off1   = td_var_offset(fsync_blocks),
1514                 .help   = "Issue fsync for writes every given number of blocks",
1515                 .def    = "0",
1516                 .interval = 1,
1517                 .category = FIO_OPT_C_FILE,
1518                 .group  = FIO_OPT_G_INVALID,
1519         },
1520         {
1521                 .name   = "fdatasync",
1522                 .lname  = "Fdatasync",
1523                 .type   = FIO_OPT_INT,
1524                 .off1   = td_var_offset(fdatasync_blocks),
1525                 .help   = "Issue fdatasync for writes every given number of blocks",
1526                 .def    = "0",
1527                 .interval = 1,
1528                 .category = FIO_OPT_C_FILE,
1529                 .group  = FIO_OPT_G_INVALID,
1530         },
1531         {
1532                 .name   = "write_barrier",
1533                 .lname  = "Write barrier",
1534                 .type   = FIO_OPT_INT,
1535                 .off1   = td_var_offset(barrier_blocks),
1536                 .help   = "Make every Nth write a barrier write",
1537                 .def    = "0",
1538                 .interval = 1,
1539                 .category = FIO_OPT_C_IO,
1540                 .group  = FIO_OPT_G_INVALID,
1541         },
1542 #ifdef FIO_HAVE_SYNC_FILE_RANGE
1543         {
1544                 .name   = "sync_file_range",
1545                 .lname  = "Sync file range",
1546                 .posval = {
1547                           { .ival = "wait_before",
1548                             .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1549                             .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1550                             .or   = 1,
1551                           },
1552                           { .ival = "write",
1553                             .oval = SYNC_FILE_RANGE_WRITE,
1554                             .help = "SYNC_FILE_RANGE_WRITE",
1555                             .or   = 1,
1556                           },
1557                           {
1558                             .ival = "wait_after",
1559                             .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1560                             .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1561                             .or   = 1,
1562                           },
1563                 },
1564                 .type   = FIO_OPT_STR_MULTI,
1565                 .cb     = str_sfr_cb,
1566                 .off1   = td_var_offset(sync_file_range),
1567                 .help   = "Use sync_file_range()",
1568                 .category = FIO_OPT_C_FILE,
1569                 .group  = FIO_OPT_G_INVALID,
1570         },
1571 #endif
1572         {
1573                 .name   = "direct",
1574                 .lname  = "Direct I/O",
1575                 .type   = FIO_OPT_BOOL,
1576                 .off1   = td_var_offset(odirect),
1577                 .help   = "Use O_DIRECT IO (negates buffered)",
1578                 .def    = "0",
1579                 .category = FIO_OPT_C_IO,
1580                 .group  = FIO_OPT_G_INVALID,
1581         },
1582         {
1583                 .name   = "buffered",
1584                 .lname  = "Buffered I/O",
1585                 .type   = FIO_OPT_BOOL,
1586                 .off1   = td_var_offset(odirect),
1587                 .neg    = 1,
1588                 .help   = "Use buffered IO (negates direct)",
1589                 .def    = "1",
1590                 .category = FIO_OPT_C_IO,
1591                 .group  = FIO_OPT_G_INVALID,
1592         },
1593         {
1594                 .name   = "overwrite",
1595                 .lname  = "Overwrite",
1596                 .type   = FIO_OPT_BOOL,
1597                 .off1   = td_var_offset(overwrite),
1598                 .help   = "When writing, set whether to overwrite current data",
1599                 .def    = "0",
1600                 .category = FIO_OPT_C_FILE,
1601                 .group  = FIO_OPT_G_INVALID,
1602         },
1603         {
1604                 .name   = "loops",
1605                 .lname  = "Loops",
1606                 .type   = FIO_OPT_INT,
1607                 .off1   = td_var_offset(loops),
1608                 .help   = "Number of times to run the job",
1609                 .def    = "1",
1610                 .interval = 1,
1611                 .category = FIO_OPT_C_GENERAL,
1612                 .group  = FIO_OPT_G_INVALID,
1613         },
1614         {
1615                 .name   = "numjobs",
1616                 .lname  = "Number of jobs",
1617                 .type   = FIO_OPT_INT,
1618                 .off1   = td_var_offset(numjobs),
1619                 .help   = "Duplicate this job this many times",
1620                 .def    = "1",
1621                 .interval = 1,
1622                 .category = FIO_OPT_C_GENERAL,
1623                 .group  = FIO_OPT_G_INVALID,
1624         },
1625         {
1626                 .name   = "startdelay",
1627                 .lname  = "Start delay",
1628                 .type   = FIO_OPT_STR_VAL_TIME,
1629                 .off1   = td_var_offset(start_delay),
1630                 .help   = "Only start job when this period has passed",
1631                 .def    = "0",
1632                 .category = FIO_OPT_C_GENERAL,
1633                 .group  = FIO_OPT_G_INVALID,
1634         },
1635         {
1636                 .name   = "runtime",
1637                 .lname  = "Runtime",
1638                 .alias  = "timeout",
1639                 .type   = FIO_OPT_STR_VAL_TIME,
1640                 .off1   = td_var_offset(timeout),
1641                 .help   = "Stop workload when this amount of time has passed",
1642                 .def    = "0",
1643                 .category = FIO_OPT_C_GENERAL,
1644                 .group  = FIO_OPT_G_INVALID,
1645         },
1646         {
1647                 .name   = "time_based",
1648                 .lname  = "Time based",
1649                 .type   = FIO_OPT_STR_SET,
1650                 .off1   = td_var_offset(time_based),
1651                 .help   = "Keep running until runtime/timeout is met",
1652                 .category = FIO_OPT_C_GENERAL,
1653                 .group  = FIO_OPT_G_INVALID,
1654         },
1655         {
1656                 .name   = "ramp_time",
1657                 .lname  = "Ramp time",
1658                 .type   = FIO_OPT_STR_VAL_TIME,
1659                 .off1   = td_var_offset(ramp_time),
1660                 .help   = "Ramp up time before measuring performance",
1661                 .category = FIO_OPT_C_GENERAL,
1662                 .group  = FIO_OPT_G_INVALID,
1663         },
1664         {
1665                 .name   = "clocksource",
1666                 .lname  = "Clock source",
1667                 .type   = FIO_OPT_STR,
1668                 .cb     = fio_clock_source_cb,
1669                 .off1   = td_var_offset(clocksource),
1670                 .help   = "What type of timing source to use",
1671                 .category = FIO_OPT_C_GENERAL,
1672                 .group  = FIO_OPT_G_INVALID,
1673                 .posval = {
1674                           { .ival = "gettimeofday",
1675                             .oval = CS_GTOD,
1676                             .help = "Use gettimeofday(2) for timing",
1677                           },
1678                           { .ival = "clock_gettime",
1679                             .oval = CS_CGETTIME,
1680                             .help = "Use clock_gettime(2) for timing",
1681                           },
1682 #ifdef ARCH_HAVE_CPU_CLOCK
1683                           { .ival = "cpu",
1684                             .oval = CS_CPUCLOCK,
1685                             .help = "Use CPU private clock",
1686                           },
1687 #endif
1688                 },
1689         },
1690         {
1691                 .name   = "mem",
1692                 .alias  = "iomem",
1693                 .lname  = "I/O Memory",
1694                 .type   = FIO_OPT_STR,
1695                 .cb     = str_mem_cb,
1696                 .off1   = td_var_offset(mem_type),
1697                 .help   = "Backing type for IO buffers",
1698                 .def    = "malloc",
1699                 .category = FIO_OPT_C_IO,
1700                 .group  = FIO_OPT_G_INVALID,
1701                 .posval = {
1702                           { .ival = "malloc",
1703                             .oval = MEM_MALLOC,
1704                             .help = "Use malloc(3) for IO buffers",
1705                           },
1706                           { .ival = "shm",
1707                             .oval = MEM_SHM,
1708                             .help = "Use shared memory segments for IO buffers",
1709                           },
1710 #ifdef FIO_HAVE_HUGETLB
1711                           { .ival = "shmhuge",
1712                             .oval = MEM_SHMHUGE,
1713                             .help = "Like shm, but use huge pages",
1714                           },
1715 #endif
1716                           { .ival = "mmap",
1717                             .oval = MEM_MMAP,
1718                             .help = "Use mmap(2) (file or anon) for IO buffers",
1719                           },
1720 #ifdef FIO_HAVE_HUGETLB
1721                           { .ival = "mmaphuge",
1722                             .oval = MEM_MMAPHUGE,
1723                             .help = "Like mmap, but use huge pages",
1724                           },
1725 #endif
1726                   },
1727         },
1728         {
1729                 .name   = "iomem_align",
1730                 .alias  = "mem_align",
1731                 .lname  = "I/O memory alignment",
1732                 .type   = FIO_OPT_INT,
1733                 .off1   = td_var_offset(mem_align),
1734                 .minval = 0,
1735                 .help   = "IO memory buffer offset alignment",
1736                 .def    = "0",
1737                 .parent = "iomem",
1738                 .hide   = 1,
1739                 .category = FIO_OPT_C_IO,
1740                 .group  = FIO_OPT_G_INVALID,
1741         },
1742         {
1743                 .name   = "verify",
1744                 .lname  = "Verify",
1745                 .type   = FIO_OPT_STR,
1746                 .off1   = td_var_offset(verify),
1747                 .help   = "Verify data written",
1748                 .cb     = str_verify_cb,
1749                 .def    = "0",
1750                 .category = FIO_OPT_C_IO,
1751                 .group  = FIO_OPT_G_INVALID,
1752                 .posval = {
1753                           { .ival = "0",
1754                             .oval = VERIFY_NONE,
1755                             .help = "Don't do IO verification",
1756                           },
1757                           { .ival = "md5",
1758                             .oval = VERIFY_MD5,
1759                             .help = "Use md5 checksums for verification",
1760                           },
1761                           { .ival = "crc64",
1762                             .oval = VERIFY_CRC64,
1763                             .help = "Use crc64 checksums for verification",
1764                           },
1765                           { .ival = "crc32",
1766                             .oval = VERIFY_CRC32,
1767                             .help = "Use crc32 checksums for verification",
1768                           },
1769                           { .ival = "crc32c-intel",
1770                             .oval = VERIFY_CRC32C,
1771                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
1772                           },
1773                           { .ival = "crc32c",
1774                             .oval = VERIFY_CRC32C,
1775                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
1776                           },
1777                           { .ival = "crc16",
1778                             .oval = VERIFY_CRC16,
1779                             .help = "Use crc16 checksums for verification",
1780                           },
1781                           { .ival = "crc7",
1782                             .oval = VERIFY_CRC7,
1783                             .help = "Use crc7 checksums for verification",
1784                           },
1785                           { .ival = "sha1",
1786                             .oval = VERIFY_SHA1,
1787                             .help = "Use sha1 checksums for verification",
1788                           },
1789                           { .ival = "sha256",
1790                             .oval = VERIFY_SHA256,
1791                             .help = "Use sha256 checksums for verification",
1792                           },
1793                           { .ival = "sha512",
1794                             .oval = VERIFY_SHA512,
1795                             .help = "Use sha512 checksums for verification",
1796                           },
1797                           { .ival = "meta",
1798                             .oval = VERIFY_META,
1799                             .help = "Use io information",
1800                           },
1801                           {
1802                             .ival = "null",
1803                             .oval = VERIFY_NULL,
1804                             .help = "Pretend to verify",
1805                           },
1806                 },
1807         },
1808         {
1809                 .name   = "do_verify",
1810                 .lname  = "Perform verify step",
1811                 .type   = FIO_OPT_BOOL,
1812                 .off1   = td_var_offset(do_verify),
1813                 .help   = "Run verification stage after write",
1814                 .def    = "1",
1815                 .parent = "verify",
1816                 .hide   = 1,
1817                 .category = FIO_OPT_C_IO,
1818                 .group  = FIO_OPT_G_VERIFY,
1819         },
1820         {
1821                 .name   = "verifysort",
1822                 .lname  = "Verify sort",
1823                 .type   = FIO_OPT_BOOL,
1824                 .off1   = td_var_offset(verifysort),
1825                 .help   = "Sort written verify blocks for read back",
1826                 .def    = "1",
1827                 .parent = "verify",
1828                 .hide   = 1,
1829                 .category = FIO_OPT_C_IO,
1830                 .group  = FIO_OPT_G_VERIFY,
1831         },
1832         {
1833                 .name   = "verify_interval",
1834                 .lname  = "Verify interval",
1835                 .type   = FIO_OPT_INT,
1836                 .off1   = td_var_offset(verify_interval),
1837                 .minval = 2 * sizeof(struct verify_header),
1838                 .help   = "Store verify buffer header every N bytes",
1839                 .parent = "verify",
1840                 .hide   = 1,
1841                 .interval = 2 * sizeof(struct verify_header),
1842                 .category = FIO_OPT_C_IO,
1843                 .group  = FIO_OPT_G_VERIFY,
1844         },
1845         {
1846                 .name   = "verify_offset",
1847                 .lname  = "Verify offset",
1848                 .type   = FIO_OPT_INT,
1849                 .help   = "Offset verify header location by N bytes",
1850                 .def    = "0",
1851                 .cb     = str_verify_offset_cb,
1852                 .parent = "verify",
1853                 .hide   = 1,
1854                 .category = FIO_OPT_C_IO,
1855                 .group  = FIO_OPT_G_VERIFY,
1856         },
1857         {
1858                 .name   = "verify_pattern",
1859                 .lname  = "Verify pattern",
1860                 .type   = FIO_OPT_STR,
1861                 .cb     = str_verify_pattern_cb,
1862                 .help   = "Fill pattern for IO buffers",
1863                 .parent = "verify",
1864                 .hide   = 1,
1865                 .category = FIO_OPT_C_IO,
1866                 .group  = FIO_OPT_G_VERIFY,
1867         },
1868         {
1869                 .name   = "verify_fatal",
1870                 .lname  = "Verify fatal",
1871                 .type   = FIO_OPT_BOOL,
1872                 .off1   = td_var_offset(verify_fatal),
1873                 .def    = "0",
1874                 .help   = "Exit on a single verify failure, don't continue",
1875                 .parent = "verify",
1876                 .hide   = 1,
1877                 .category = FIO_OPT_C_IO,
1878                 .group  = FIO_OPT_G_VERIFY,
1879         },
1880         {
1881                 .name   = "verify_dump",
1882                 .lname  = "Verify dump",
1883                 .type   = FIO_OPT_BOOL,
1884                 .off1   = td_var_offset(verify_dump),
1885                 .def    = "0",
1886                 .help   = "Dump contents of good and bad blocks on failure",
1887                 .parent = "verify",
1888                 .hide   = 1,
1889                 .category = FIO_OPT_C_IO,
1890                 .group  = FIO_OPT_G_VERIFY,
1891         },
1892         {
1893                 .name   = "verify_async",
1894                 .lname  = "Verify asynchronously",
1895                 .type   = FIO_OPT_INT,
1896                 .off1   = td_var_offset(verify_async),
1897                 .def    = "0",
1898                 .help   = "Number of async verifier threads to use",
1899                 .parent = "verify",
1900                 .hide   = 1,
1901                 .category = FIO_OPT_C_IO,
1902                 .group  = FIO_OPT_G_VERIFY,
1903         },
1904         {
1905                 .name   = "verify_backlog",
1906                 .lname  = "Verify backlog",
1907                 .type   = FIO_OPT_STR_VAL,
1908                 .off1   = td_var_offset(verify_backlog),
1909                 .help   = "Verify after this number of blocks are written",
1910                 .parent = "verify",
1911                 .hide   = 1,
1912                 .category = FIO_OPT_C_IO,
1913                 .group  = FIO_OPT_G_VERIFY,
1914         },
1915         {
1916                 .name   = "verify_backlog_batch",
1917                 .lname  = "Verify backlog batch",
1918                 .type   = FIO_OPT_INT,
1919                 .off1   = td_var_offset(verify_batch),
1920                 .help   = "Verify this number of IO blocks",
1921                 .parent = "verify",
1922                 .hide   = 1,
1923                 .category = FIO_OPT_C_IO,
1924                 .group  = FIO_OPT_G_VERIFY,
1925         },
1926 #ifdef FIO_HAVE_CPU_AFFINITY
1927         {
1928                 .name   = "verify_async_cpus",
1929                 .lname  = "Async verify CPUs",
1930                 .type   = FIO_OPT_STR,
1931                 .cb     = str_verify_cpus_allowed_cb,
1932                 .help   = "Set CPUs allowed for async verify threads",
1933                 .parent = "verify_async",
1934                 .hide   = 1,
1935                 .category = FIO_OPT_C_IO,
1936                 .group  = FIO_OPT_G_VERIFY,
1937         },
1938 #endif
1939 #ifdef FIO_HAVE_TRIM
1940         {
1941                 .name   = "trim_percentage",
1942                 .lname  = "Trim percentage",
1943                 .type   = FIO_OPT_INT,
1944                 .cb     = str_verify_trim_cb,
1945                 .minval = 0,
1946                 .maxval = 100,
1947                 .help   = "Number of verify blocks to discard/trim",
1948                 .parent = "verify",
1949                 .def    = "0",
1950                 .interval = 1,
1951                 .hide   = 1,
1952                 .category = FIO_OPT_C_IO,
1953                 .group  = FIO_OPT_G_TRIM,
1954         },
1955         {
1956                 .name   = "trim_verify_zero",
1957                 .lname  = "Verify trim zero",
1958                 .type   = FIO_OPT_BOOL,
1959                 .help   = "Verify that trim/discarded blocks are returned as zeroes",
1960                 .off1   = td_var_offset(trim_zero),
1961                 .parent = "trim_percentage",
1962                 .hide   = 1,
1963                 .def    = "1",
1964                 .category = FIO_OPT_C_IO,
1965                 .group  = FIO_OPT_G_TRIM,
1966         },
1967         {
1968                 .name   = "trim_backlog",
1969                 .lname  = "Trim backlog",
1970                 .type   = FIO_OPT_STR_VAL,
1971                 .off1   = td_var_offset(trim_backlog),
1972                 .help   = "Trim after this number of blocks are written",
1973                 .parent = "trim_percentage",
1974                 .hide   = 1,
1975                 .interval = 1,
1976                 .category = FIO_OPT_C_IO,
1977                 .group  = FIO_OPT_G_TRIM,
1978         },
1979         {
1980                 .name   = "trim_backlog_batch",
1981                 .lname  = "Trim backlog batch",
1982                 .type   = FIO_OPT_INT,
1983                 .off1   = td_var_offset(trim_batch),
1984                 .help   = "Trim this number of IO blocks",
1985                 .parent = "trim_percentage",
1986                 .hide   = 1,
1987                 .interval = 1,
1988                 .category = FIO_OPT_C_IO,
1989                 .group  = FIO_OPT_G_TRIM,
1990         },
1991 #endif
1992         {
1993                 .name   = "write_iolog",
1994                 .lname  = "Write I/O log",
1995                 .type   = FIO_OPT_STR_STORE,
1996                 .off1   = td_var_offset(write_iolog_file),
1997                 .help   = "Store IO pattern to file",
1998                 .category = FIO_OPT_C_IO,
1999                 .group  = FIO_OPT_G_IOLOG,
2000         },
2001         {
2002                 .name   = "read_iolog",
2003                 .lname  = "Read I/O log",
2004                 .type   = FIO_OPT_STR_STORE,
2005                 .off1   = td_var_offset(read_iolog_file),
2006                 .help   = "Playback IO pattern from file",
2007                 .category = FIO_OPT_C_IO,
2008                 .group  = FIO_OPT_G_IOLOG,
2009         },
2010         {
2011                 .name   = "replay_no_stall",
2012                 .lname  = "Don't stall on replay",
2013                 .type   = FIO_OPT_BOOL,
2014                 .off1   = td_var_offset(no_stall),
2015                 .def    = "0",
2016                 .parent = "read_iolog",
2017                 .hide   = 1,
2018                 .help   = "Playback IO pattern file as fast as possible without stalls",
2019                 .category = FIO_OPT_C_IO,
2020                 .group  = FIO_OPT_G_IOLOG,
2021         },
2022         {
2023                 .name   = "replay_redirect",
2024                 .lname  = "Redirect device for replay",
2025                 .type   = FIO_OPT_STR_STORE,
2026                 .off1   = td_var_offset(replay_redirect),
2027                 .parent = "read_iolog",
2028                 .hide   = 1,
2029                 .help   = "Replay all I/O onto this device, regardless of trace device",
2030                 .category = FIO_OPT_C_IO,
2031                 .group  = FIO_OPT_G_IOLOG,
2032         },
2033         {
2034                 .name   = "exec_prerun",
2035                 .lname  = "Pre-execute runnable",
2036                 .type   = FIO_OPT_STR_STORE,
2037                 .off1   = td_var_offset(exec_prerun),
2038                 .help   = "Execute this file prior to running job",
2039                 .category = FIO_OPT_C_GENERAL,
2040                 .group  = FIO_OPT_G_INVALID,
2041         },
2042         {
2043                 .name   = "exec_postrun",
2044                 .lname  = "Post-execute runnable",
2045                 .type   = FIO_OPT_STR_STORE,
2046                 .off1   = td_var_offset(exec_postrun),
2047                 .help   = "Execute this file after running job",
2048                 .category = FIO_OPT_C_GENERAL,
2049                 .group  = FIO_OPT_G_INVALID,
2050         },
2051 #ifdef FIO_HAVE_IOSCHED_SWITCH
2052         {
2053                 .name   = "ioscheduler",
2054                 .lname  = "I/O scheduler",
2055                 .type   = FIO_OPT_STR_STORE,
2056                 .off1   = td_var_offset(ioscheduler),
2057                 .help   = "Use this IO scheduler on the backing device",
2058                 .category = FIO_OPT_C_FILE,
2059                 .group  = FIO_OPT_G_INVALID,
2060         },
2061 #endif
2062         {
2063                 .name   = "zonesize",
2064                 .lname  = "Zone size",
2065                 .type   = FIO_OPT_STR_VAL,
2066                 .off1   = td_var_offset(zone_size),
2067                 .help   = "Amount of data to read per zone",
2068                 .def    = "0",
2069                 .interval = 1024 * 1024,
2070                 .category = FIO_OPT_C_IO,
2071                 .group  = FIO_OPT_G_ZONE,
2072         },
2073         {
2074                 .name   = "zonerange",
2075                 .lname  = "Zone range",
2076                 .type   = FIO_OPT_STR_VAL,
2077                 .off1   = td_var_offset(zone_range),
2078                 .help   = "Give size of an IO zone",
2079                 .def    = "0",
2080                 .interval = 1024 * 1024,
2081                 .category = FIO_OPT_C_IO,
2082                 .group  = FIO_OPT_G_ZONE,
2083         },
2084         {
2085                 .name   = "zoneskip",
2086                 .lname  = "Zone skip",
2087                 .type   = FIO_OPT_STR_VAL,
2088                 .off1   = td_var_offset(zone_skip),
2089                 .help   = "Space between IO zones",
2090                 .def    = "0",
2091                 .interval = 1024 * 1024,
2092                 .category = FIO_OPT_C_IO,
2093                 .group  = FIO_OPT_G_ZONE,
2094         },
2095         {
2096                 .name   = "lockmem",
2097                 .lname  = "Lock memory",
2098                 .type   = FIO_OPT_STR_VAL,
2099                 .cb     = str_lockmem_cb,
2100                 .help   = "Lock down this amount of memory",
2101                 .def    = "0",
2102                 .interval = 1024 * 1024,
2103                 .category = FIO_OPT_C_GENERAL,
2104                 .group  = FIO_OPT_G_INVALID,
2105         },
2106         {
2107                 .name   = "rwmixread",
2108                 .lname  = "Read/write mix read",
2109                 .type   = FIO_OPT_INT,
2110                 .cb     = str_rwmix_read_cb,
2111                 .maxval = 100,
2112                 .help   = "Percentage of mixed workload that is reads",
2113                 .def    = "50",
2114                 .interval = 5,
2115                 .category = FIO_OPT_C_IO,
2116                 .group  = FIO_OPT_G_RWMIX,
2117         },
2118         {
2119                 .name   = "rwmixwrite",
2120                 .lname  = "Read/write mix write",
2121                 .type   = FIO_OPT_INT,
2122                 .cb     = str_rwmix_write_cb,
2123                 .maxval = 100,
2124                 .help   = "Percentage of mixed workload that is writes",
2125                 .def    = "50",
2126                 .interval = 5,
2127                 .category = FIO_OPT_C_IO,
2128                 .group  = FIO_OPT_G_RWMIX,
2129         },
2130         {
2131                 .name   = "rwmixcycle",
2132                 .lname  = "Read/write mix cycle",
2133                 .type   = FIO_OPT_DEPRECATED,
2134                 .category = FIO_OPT_C_IO,
2135                 .group  = FIO_OPT_G_RWMIX,
2136         },
2137         {
2138                 .name   = "nice",
2139                 .lname  = "Nice",
2140                 .type   = FIO_OPT_INT,
2141                 .off1   = td_var_offset(nice),
2142                 .help   = "Set job CPU nice value",
2143                 .minval = -19,
2144                 .maxval = 20,
2145                 .def    = "0",
2146                 .interval = 1,
2147                 .category = FIO_OPT_C_GENERAL,
2148                 .group  = FIO_OPT_G_INVALID,
2149         },
2150 #ifdef FIO_HAVE_IOPRIO
2151         {
2152                 .name   = "prio",
2153                 .lname  = "I/O nice priority",
2154                 .type   = FIO_OPT_INT,
2155                 .cb     = str_prio_cb,
2156                 .help   = "Set job IO priority value",
2157                 .minval = 0,
2158                 .maxval = 7,
2159                 .interval = 1,
2160                 .category = FIO_OPT_C_GENERAL,
2161                 .group  = FIO_OPT_G_INVALID,
2162         },
2163         {
2164                 .name   = "prioclass",
2165                 .lname  = "I/O nice priority class",
2166                 .type   = FIO_OPT_INT,
2167                 .cb     = str_prioclass_cb,
2168                 .help   = "Set job IO priority class",
2169                 .minval = 0,
2170                 .maxval = 3,
2171                 .interval = 1,
2172                 .category = FIO_OPT_C_GENERAL,
2173                 .group  = FIO_OPT_G_INVALID,
2174         },
2175 #endif
2176         {
2177                 .name   = "thinktime",
2178                 .lname  = "Thinktime",
2179                 .type   = FIO_OPT_INT,
2180                 .off1   = td_var_offset(thinktime),
2181                 .help   = "Idle time between IO buffers (usec)",
2182                 .def    = "0",
2183                 .category = FIO_OPT_C_IO,
2184                 .group  = FIO_OPT_G_INVALID,
2185         },
2186         {
2187                 .name   = "thinktime_spin",
2188                 .lname  = "Thinktime spin",
2189                 .type   = FIO_OPT_INT,
2190                 .off1   = td_var_offset(thinktime_spin),
2191                 .help   = "Start think time by spinning this amount (usec)",
2192                 .def    = "0",
2193                 .parent = "thinktime",
2194                 .hide   = 1,
2195                 .category = FIO_OPT_C_IO,
2196                 .group  = FIO_OPT_G_INVALID,
2197         },
2198         {
2199                 .name   = "thinktime_blocks",
2200                 .lname  = "Thinktime blocks",
2201                 .type   = FIO_OPT_INT,
2202                 .off1   = td_var_offset(thinktime_blocks),
2203                 .help   = "IO buffer period between 'thinktime'",
2204                 .def    = "1",
2205                 .parent = "thinktime",
2206                 .hide   = 1,
2207                 .category = FIO_OPT_C_IO,
2208                 .group  = FIO_OPT_G_INVALID,
2209         },
2210         {
2211                 .name   = "rate",
2212                 .lname  = "I/O rate",
2213                 .type   = FIO_OPT_INT,
2214                 .off1   = td_var_offset(rate[0]),
2215                 .off2   = td_var_offset(rate[1]),
2216                 .help   = "Set bandwidth rate",
2217                 .category = FIO_OPT_C_IO,
2218                 .group  = FIO_OPT_G_RATE,
2219         },
2220         {
2221                 .name   = "ratemin",
2222                 .lname  = "I/O min rate",
2223                 .type   = FIO_OPT_INT,
2224                 .off1   = td_var_offset(ratemin[0]),
2225                 .off2   = td_var_offset(ratemin[1]),
2226                 .help   = "Job must meet this rate or it will be shutdown",
2227                 .parent = "rate",
2228                 .hide   = 1,
2229                 .category = FIO_OPT_C_IO,
2230                 .group  = FIO_OPT_G_RATE,
2231         },
2232         {
2233                 .name   = "rate_iops",
2234                 .lname  = "I/O rate IOPS",
2235                 .type   = FIO_OPT_INT,
2236                 .off1   = td_var_offset(rate_iops[0]),
2237                 .off2   = td_var_offset(rate_iops[1]),
2238                 .help   = "Limit IO used to this number of IO operations/sec",
2239                 .hide   = 1,
2240                 .category = FIO_OPT_C_IO,
2241                 .group  = FIO_OPT_G_RATE,
2242         },
2243         {
2244                 .name   = "rate_iops_min",
2245                 .lname  = "I/O min rate IOPS",
2246                 .type   = FIO_OPT_INT,
2247                 .off1   = td_var_offset(rate_iops_min[0]),
2248                 .off2   = td_var_offset(rate_iops_min[1]),
2249                 .help   = "Job must meet this rate or it will be shut down",
2250                 .parent = "rate_iops",
2251                 .hide   = 1,
2252                 .category = FIO_OPT_C_IO,
2253                 .group  = FIO_OPT_G_RATE,
2254         },
2255         {
2256                 .name   = "ratecycle",
2257                 .lname  = "I/O rate cycle",
2258                 .type   = FIO_OPT_INT,
2259                 .off1   = td_var_offset(ratecycle),
2260                 .help   = "Window average for rate limits (msec)",
2261                 .def    = "1000",
2262                 .parent = "rate",
2263                 .hide   = 1,
2264                 .category = FIO_OPT_C_IO,
2265                 .group  = FIO_OPT_G_RATE,
2266         },
2267         {
2268                 .name   = "invalidate",
2269                 .lname  = "Cache invalidate",
2270                 .type   = FIO_OPT_BOOL,
2271                 .off1   = td_var_offset(invalidate_cache),
2272                 .help   = "Invalidate buffer/page cache prior to running job",
2273                 .def    = "1",
2274                 .category = FIO_OPT_C_IO,
2275                 .group  = FIO_OPT_G_INVALID,
2276         },
2277         {
2278                 .name   = "sync",
2279                 .lname  = "Synchronous I/O",
2280                 .type   = FIO_OPT_BOOL,
2281                 .off1   = td_var_offset(sync_io),
2282                 .help   = "Use O_SYNC for buffered writes",
2283                 .def    = "0",
2284                 .parent = "buffered",
2285                 .hide   = 1,
2286                 .category = FIO_OPT_C_IO,
2287                 .group  = FIO_OPT_G_INVALID,
2288         },
2289         {
2290                 .name   = "bwavgtime",
2291                 .lname  = "Bandwidth average time",
2292                 .type   = FIO_OPT_INT,
2293                 .off1   = td_var_offset(bw_avg_time),
2294                 .help   = "Time window over which to calculate bandwidth"
2295                           " (msec)",
2296                 .def    = "500",
2297                 .parent = "write_bw_log",
2298                 .hide   = 1,
2299                 .interval = 100,
2300                 .category = FIO_OPT_C_LOG,
2301                 .group  = FIO_OPT_G_INVALID,
2302         },
2303         {
2304                 .name   = "iopsavgtime",
2305                 .lname  = "IOPS average time",
2306                 .type   = FIO_OPT_INT,
2307                 .off1   = td_var_offset(iops_avg_time),
2308                 .help   = "Time window over which to calculate IOPS (msec)",
2309                 .def    = "500",
2310                 .parent = "write_iops_log",
2311                 .hide   = 1,
2312                 .interval = 100,
2313                 .category = FIO_OPT_C_LOG,
2314                 .group  = FIO_OPT_G_INVALID,
2315         },
2316         {
2317                 .name   = "create_serialize",
2318                 .lname  = "Create serialize",
2319                 .type   = FIO_OPT_BOOL,
2320                 .off1   = td_var_offset(create_serialize),
2321                 .help   = "Serialize creating of job files",
2322                 .def    = "1",
2323                 .category = FIO_OPT_C_FILE,
2324                 .group  = FIO_OPT_G_INVALID,
2325         },
2326         {
2327                 .name   = "create_fsync",
2328                 .lname  = "Create fsync",
2329                 .type   = FIO_OPT_BOOL,
2330                 .off1   = td_var_offset(create_fsync),
2331                 .help   = "fsync file after creation",
2332                 .def    = "1",
2333                 .category = FIO_OPT_C_FILE,
2334                 .group  = FIO_OPT_G_INVALID,
2335         },
2336         {
2337                 .name   = "create_on_open",
2338                 .lname  = "Create on open",
2339                 .type   = FIO_OPT_BOOL,
2340                 .off1   = td_var_offset(create_on_open),
2341                 .help   = "Create files when they are opened for IO",
2342                 .def    = "0",
2343                 .category = FIO_OPT_C_FILE,
2344                 .group  = FIO_OPT_G_INVALID,
2345         },
2346         {
2347                 .name   = "pre_read",
2348                 .lname  = "Pre-read files",
2349                 .type   = FIO_OPT_BOOL,
2350                 .off1   = td_var_offset(pre_read),
2351                 .help   = "Pre-read files before starting official testing",
2352                 .def    = "0",
2353                 .category = FIO_OPT_C_FILE,
2354                 .group  = FIO_OPT_G_INVALID,
2355         },
2356         {
2357                 .name   = "cpuload",
2358                 .lname  = "CPU load",
2359                 .type   = FIO_OPT_INT,
2360                 .off1   = td_var_offset(cpuload),
2361                 .help   = "Use this percentage of CPU",
2362                 .category = FIO_OPT_C_GENERAL,
2363                 .group  = FIO_OPT_G_INVALID,
2364         },
2365         {
2366                 .name   = "cpuchunks",
2367                 .lname  = "CPU chunk",
2368                 .type   = FIO_OPT_INT,
2369                 .off1   = td_var_offset(cpucycle),
2370                 .help   = "Length of the CPU burn cycles (usecs)",
2371                 .def    = "50000",
2372                 .parent = "cpuload",
2373                 .hide   = 1,
2374                 .category = FIO_OPT_C_GENERAL,
2375                 .group  = FIO_OPT_G_INVALID,
2376         },
2377 #ifdef FIO_HAVE_CPU_AFFINITY
2378         {
2379                 .name   = "cpumask",
2380                 .lname  = "CPU mask",
2381                 .type   = FIO_OPT_INT,
2382                 .cb     = str_cpumask_cb,
2383                 .help   = "CPU affinity mask",
2384                 .category = FIO_OPT_C_GENERAL,
2385                 .group  = FIO_OPT_G_INVALID,
2386         },
2387         {
2388                 .name   = "cpus_allowed",
2389                 .lname  = "CPUs allowed",
2390                 .type   = FIO_OPT_STR,
2391                 .cb     = str_cpus_allowed_cb,
2392                 .help   = "Set CPUs allowed",
2393                 .category = FIO_OPT_C_GENERAL,
2394                 .group  = FIO_OPT_G_INVALID,
2395         },
2396 #endif
2397         {
2398                 .name   = "end_fsync",
2399                 .lname  = "End fsync",
2400                 .type   = FIO_OPT_BOOL,
2401                 .off1   = td_var_offset(end_fsync),
2402                 .help   = "Include fsync at the end of job",
2403                 .def    = "0",
2404                 .category = FIO_OPT_C_FILE,
2405                 .group  = FIO_OPT_G_INVALID,
2406         },
2407         {
2408                 .name   = "fsync_on_close",
2409                 .lname  = "Fsync on close",
2410                 .type   = FIO_OPT_BOOL,
2411                 .off1   = td_var_offset(fsync_on_close),
2412                 .help   = "fsync files on close",
2413                 .def    = "0",
2414                 .category = FIO_OPT_C_FILE,
2415                 .group  = FIO_OPT_G_INVALID,
2416         },
2417         {
2418                 .name   = "unlink",
2419                 .lname  = "Unlink file",
2420                 .type   = FIO_OPT_BOOL,
2421                 .off1   = td_var_offset(unlink),
2422                 .help   = "Unlink created files after job has completed",
2423                 .def    = "0",
2424                 .category = FIO_OPT_C_FILE,
2425                 .group  = FIO_OPT_G_INVALID,
2426         },
2427         {
2428                 .name   = "exitall",
2429                 .lname  = "Exit-all on terminate",
2430                 .type   = FIO_OPT_STR_SET,
2431                 .cb     = str_exitall_cb,
2432                 .help   = "Terminate all jobs when one exits",
2433                 .category = FIO_OPT_C_GENERAL,
2434                 .group  = FIO_OPT_G_INVALID,
2435         },
2436         {
2437                 .name   = "stonewall",
2438                 .lname  = "Wait for previous",
2439                 .alias  = "wait_for_previous",
2440                 .type   = FIO_OPT_STR_SET,
2441                 .off1   = td_var_offset(stonewall),
2442                 .help   = "Insert a hard barrier between this job and previous",
2443                 .category = FIO_OPT_C_GENERAL,
2444                 .group  = FIO_OPT_G_INVALID,
2445         },
2446         {
2447                 .name   = "new_group",
2448                 .lname  = "New group",
2449                 .type   = FIO_OPT_STR_SET,
2450                 .off1   = td_var_offset(new_group),
2451                 .help   = "Mark the start of a new group (for reporting)",
2452                 .category = FIO_OPT_C_GENERAL,
2453                 .group  = FIO_OPT_G_INVALID,
2454         },
2455         {
2456                 .name   = "thread",
2457                 .lname  = "Thread",
2458                 .type   = FIO_OPT_STR_SET,
2459                 .off1   = td_var_offset(use_thread),
2460                 .help   = "Use threads instead of processes",
2461                 .category = FIO_OPT_C_GENERAL,
2462                 .group  = FIO_OPT_G_INVALID,
2463         },
2464         {
2465                 .name   = "write_bw_log",
2466                 .lname  = "Write bandwidth log",
2467                 .type   = FIO_OPT_STR,
2468                 .off1   = td_var_offset(write_bw_log),
2469                 .cb     = str_write_bw_log_cb,
2470                 .help   = "Write log of bandwidth during run",
2471                 .category = FIO_OPT_C_LOG,
2472                 .group  = FIO_OPT_G_INVALID,
2473         },
2474         {
2475                 .name   = "write_lat_log",
2476                 .lname  = "Write latency log",
2477                 .type   = FIO_OPT_STR,
2478                 .off1   = td_var_offset(write_lat_log),
2479                 .cb     = str_write_lat_log_cb,
2480                 .help   = "Write log of latency during run",
2481                 .category = FIO_OPT_C_LOG,
2482                 .group  = FIO_OPT_G_INVALID,
2483         },
2484         {
2485                 .name   = "write_iops_log",
2486                 .lname  = "Write IOPS log",
2487                 .type   = FIO_OPT_STR,
2488                 .off1   = td_var_offset(write_iops_log),
2489                 .cb     = str_write_iops_log_cb,
2490                 .help   = "Write log of IOPS during run",
2491                 .category = FIO_OPT_C_LOG,
2492                 .group  = FIO_OPT_G_INVALID,
2493         },
2494         {
2495                 .name   = "log_avg_msec",
2496                 .lname  = "Log averaging (msec)",
2497                 .type   = FIO_OPT_INT,
2498                 .off1   = td_var_offset(log_avg_msec),
2499                 .help   = "Average bw/iops/lat logs over this period of time",
2500                 .def    = "0",
2501                 .category = FIO_OPT_C_LOG,
2502                 .group  = FIO_OPT_G_INVALID,
2503         },
2504         {
2505                 .name   = "hugepage-size",
2506                 .lname  = "Hugepage size",
2507                 .type   = FIO_OPT_INT,
2508                 .off1   = td_var_offset(hugepage_size),
2509                 .help   = "When using hugepages, specify size of each page",
2510                 .def    = __fio_stringify(FIO_HUGE_PAGE),
2511                 .interval = 1024 * 1024,
2512                 .category = FIO_OPT_C_GENERAL,
2513                 .group  = FIO_OPT_G_INVALID,
2514         },
2515         {
2516                 .name   = "group_reporting",
2517                 .lname  = "Group reporting",
2518                 .type   = FIO_OPT_BOOL,
2519                 .off1   = td_var_offset(group_reporting),
2520                 .help   = "Do reporting on a per-group basis",
2521                 .def    = "1",
2522                 .category = FIO_OPT_C_GENERAL,
2523                 .group  = FIO_OPT_G_INVALID,
2524         },
2525         {
2526                 .name   = "zero_buffers",
2527                 .lname  = "Zero I/O buffers",
2528                 .type   = FIO_OPT_STR_SET,
2529                 .off1   = td_var_offset(zero_buffers),
2530                 .help   = "Init IO buffers to all zeroes",
2531                 .category = FIO_OPT_C_IO,
2532                 .group  = FIO_OPT_G_INVALID,
2533         },
2534         {
2535                 .name   = "refill_buffers",
2536                 .lname  = "Refill I/O buffers",
2537                 .type   = FIO_OPT_STR_SET,
2538                 .off1   = td_var_offset(refill_buffers),
2539                 .help   = "Refill IO buffers on every IO submit",
2540                 .category = FIO_OPT_C_IO,
2541                 .group  = FIO_OPT_G_INVALID,
2542         },
2543         {
2544                 .name   = "scramble_buffers",
2545                 .lname  = "Scramble I/O buffers",
2546                 .type   = FIO_OPT_BOOL,
2547                 .off1   = td_var_offset(scramble_buffers),
2548                 .help   = "Slightly scramble buffers on every IO submit",
2549                 .def    = "1",
2550                 .category = FIO_OPT_C_IO,
2551                 .group  = FIO_OPT_G_INVALID,
2552         },
2553         {
2554                 .name   = "buffer_compress_percentage",
2555                 .lname  = "Buffer compression percentage",
2556                 .type   = FIO_OPT_INT,
2557                 .off1   = td_var_offset(compress_percentage),
2558                 .maxval = 100,
2559                 .minval = 1,
2560                 .help   = "How compressible the buffer is (approximately)",
2561                 .interval = 5,
2562                 .category = FIO_OPT_C_IO,
2563                 .group  = FIO_OPT_G_INVALID,
2564         },
2565         {
2566                 .name   = "buffer_compress_chunk",
2567                 .lname  = "Buffer compression chunk size",
2568                 .type   = FIO_OPT_INT,
2569                 .off1   = td_var_offset(compress_chunk),
2570                 .parent = "buffer_compress_percentage",
2571                 .hide   = 1,
2572                 .help   = "Size of compressible region in buffer",
2573                 .interval = 256,
2574                 .category = FIO_OPT_C_IO,
2575                 .group  = FIO_OPT_G_INVALID,
2576         },
2577         {
2578                 .name   = "clat_percentiles",
2579                 .lname  = "Completion latency percentiles",
2580                 .type   = FIO_OPT_BOOL,
2581                 .off1   = td_var_offset(clat_percentiles),
2582                 .help   = "Enable the reporting of completion latency percentiles",
2583                 .def    = "1",
2584                 .category = FIO_OPT_C_STAT,
2585                 .group  = FIO_OPT_G_INVALID,
2586         },
2587         {
2588                 .name   = "percentile_list",
2589                 .lname  = "Completion latency percentile list",
2590                 .type   = FIO_OPT_FLOAT_LIST,
2591                 .off1   = td_var_offset(percentile_list),
2592                 .off2   = td_var_offset(overwrite_plist),
2593                 .help   = "Specify a custom list of percentiles to report",
2594                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2595                 .minfp  = 0.0,
2596                 .maxfp  = 100.0,
2597                 .category = FIO_OPT_C_STAT,
2598                 .group  = FIO_OPT_G_INVALID,
2599         },
2600
2601 #ifdef FIO_HAVE_DISK_UTIL
2602         {
2603                 .name   = "disk_util",
2604                 .lname  = "Disk utilization",
2605                 .type   = FIO_OPT_BOOL,
2606                 .off1   = td_var_offset(do_disk_util),
2607                 .help   = "Log disk utilization statistics",
2608                 .def    = "1",
2609                 .category = FIO_OPT_C_STAT,
2610                 .group  = FIO_OPT_G_INVALID,
2611         },
2612 #endif
2613         {
2614                 .name   = "gtod_reduce",
2615                 .lname  = "Reduce gettimeofday() calls",
2616                 .type   = FIO_OPT_BOOL,
2617                 .help   = "Greatly reduce number of gettimeofday() calls",
2618                 .cb     = str_gtod_reduce_cb,
2619                 .def    = "0",
2620                 .category = FIO_OPT_C_STAT,
2621                 .group  = FIO_OPT_G_INVALID,
2622         },
2623         {
2624                 .name   = "disable_lat",
2625                 .lname  = "Disable all latency stats",
2626                 .type   = FIO_OPT_BOOL,
2627                 .off1   = td_var_offset(disable_lat),
2628                 .help   = "Disable latency numbers",
2629                 .parent = "gtod_reduce",
2630                 .hide   = 1,
2631                 .def    = "0",
2632                 .category = FIO_OPT_C_STAT,
2633                 .group  = FIO_OPT_G_INVALID,
2634         },
2635         {
2636                 .name   = "disable_clat",
2637                 .lname  = "Disable completion latency stats",
2638                 .type   = FIO_OPT_BOOL,
2639                 .off1   = td_var_offset(disable_clat),
2640                 .help   = "Disable completion latency numbers",
2641                 .parent = "gtod_reduce",
2642                 .hide   = 1,
2643                 .def    = "0",
2644                 .category = FIO_OPT_C_STAT,
2645                 .group  = FIO_OPT_G_INVALID,
2646         },
2647         {
2648                 .name   = "disable_slat",
2649                 .lname  = "Disable submission latency stats",
2650                 .type   = FIO_OPT_BOOL,
2651                 .off1   = td_var_offset(disable_slat),
2652                 .help   = "Disable submission latency numbers",
2653                 .parent = "gtod_reduce",
2654                 .hide   = 1,
2655                 .def    = "0",
2656                 .category = FIO_OPT_C_STAT,
2657                 .group  = FIO_OPT_G_INVALID,
2658         },
2659         {
2660                 .name   = "disable_bw_measurement",
2661                 .lname  = "Disable bandwidth stats",
2662                 .type   = FIO_OPT_BOOL,
2663                 .off1   = td_var_offset(disable_bw),
2664                 .help   = "Disable bandwidth logging",
2665                 .parent = "gtod_reduce",
2666                 .hide   = 1,
2667                 .def    = "0",
2668                 .category = FIO_OPT_C_STAT,
2669                 .group  = FIO_OPT_G_INVALID,
2670         },
2671         {
2672                 .name   = "gtod_cpu",
2673                 .lname  = "Dedicated gettimeofday() CPU",
2674                 .type   = FIO_OPT_INT,
2675                 .cb     = str_gtod_cpu_cb,
2676                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
2677                 .verify = gtod_cpu_verify,
2678                 .category = FIO_OPT_C_GENERAL,
2679                 .group  = FIO_OPT_G_INVALID,
2680         },
2681         {
2682                 .name   = "continue_on_error",
2683                 .lname  = "Continue on error",
2684                 .type   = FIO_OPT_STR,
2685                 .off1   = td_var_offset(continue_on_error),
2686                 .help   = "Continue on non-fatal errors during IO",
2687                 .def    = "none",
2688                 .category = FIO_OPT_C_GENERAL,
2689                 .group  = FIO_OPT_G_INVALID,
2690                 .posval = {
2691                           { .ival = "none",
2692                             .oval = ERROR_TYPE_NONE,
2693                             .help = "Exit when an error is encountered",
2694                           },
2695                           { .ival = "read",
2696                             .oval = ERROR_TYPE_READ,
2697                             .help = "Continue on read errors only",
2698                           },
2699                           { .ival = "write",
2700                             .oval = ERROR_TYPE_WRITE,
2701                             .help = "Continue on write errors only",
2702                           },
2703                           { .ival = "io",
2704                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2705                             .help = "Continue on any IO errors",
2706                           },
2707                           { .ival = "verify",
2708                             .oval = ERROR_TYPE_VERIFY,
2709                             .help = "Continue on verify errors only",
2710                           },
2711                           { .ival = "all",
2712                             .oval = ERROR_TYPE_ANY,
2713                             .help = "Continue on all io and verify errors",
2714                           },
2715                           { .ival = "0",
2716                             .oval = ERROR_TYPE_NONE,
2717                             .help = "Alias for 'none'",
2718                           },
2719                           { .ival = "1",
2720                             .oval = ERROR_TYPE_ANY,
2721                             .help = "Alias for 'all'",
2722                           },
2723                 },
2724         },
2725         {
2726                 .name   = "profile",
2727                 .lname  = "Profile",
2728                 .type   = FIO_OPT_STR_STORE,
2729                 .off1   = td_var_offset(profile),
2730                 .help   = "Select a specific builtin performance test",
2731                 .category = FIO_OPT_C_GENERAL,
2732                 .group  = FIO_OPT_G_INVALID,
2733         },
2734         {
2735                 .name   = "cgroup",
2736                 .lname  = "Cgroup",
2737                 .type   = FIO_OPT_STR_STORE,
2738                 .off1   = td_var_offset(cgroup),
2739                 .help   = "Add job to cgroup of this name",
2740                 .category = FIO_OPT_C_GENERAL,
2741                 .group  = FIO_OPT_G_INVALID,
2742         },
2743         {
2744                 .name   = "cgroup_weight",
2745                 .lname  = "Cgroup weight",
2746                 .type   = FIO_OPT_INT,
2747                 .off1   = td_var_offset(cgroup_weight),
2748                 .help   = "Use given weight for cgroup",
2749                 .minval = 100,
2750                 .maxval = 1000,
2751                 .category = FIO_OPT_C_GENERAL,
2752                 .group  = FIO_OPT_G_INVALID,
2753         },
2754         {
2755                 .name   = "cgroup_nodelete",
2756                 .lname  = "Cgroup no-delete",
2757                 .type   = FIO_OPT_BOOL,
2758                 .off1   = td_var_offset(cgroup_nodelete),
2759                 .help   = "Do not delete cgroups after job completion",
2760                 .def    = "0",
2761                 .category = FIO_OPT_C_GENERAL,
2762                 .group  = FIO_OPT_G_INVALID,
2763         },
2764         {
2765                 .name   = "uid",
2766                 .lname  = "User ID",
2767                 .type   = FIO_OPT_INT,
2768                 .off1   = td_var_offset(uid),
2769                 .help   = "Run job with this user ID",
2770                 .category = FIO_OPT_C_GENERAL,
2771                 .group  = FIO_OPT_G_INVALID,
2772         },
2773         {
2774                 .name   = "gid",
2775                 .lname  = "Group ID",
2776                 .type   = FIO_OPT_INT,
2777                 .off1   = td_var_offset(gid),
2778                 .help   = "Run job with this group ID",
2779                 .category = FIO_OPT_C_GENERAL,
2780                 .group  = FIO_OPT_G_INVALID,
2781         },
2782         {
2783                 .name   = "flow_id",
2784                 .lname  = "I/O flow ID",
2785                 .type   = FIO_OPT_INT,
2786                 .off1   = td_var_offset(flow_id),
2787                 .help   = "The flow index ID to use",
2788                 .def    = "0",
2789                 .category = FIO_OPT_C_IO,
2790                 .group  = FIO_OPT_G_IO_FLOW,
2791         },
2792         {
2793                 .name   = "flow",
2794                 .lname  = "I/O flow weight",
2795                 .type   = FIO_OPT_INT,
2796                 .off1   = td_var_offset(flow),
2797                 .help   = "Weight for flow control of this job",
2798                 .parent = "flow_id",
2799                 .hide   = 1,
2800                 .def    = "0",
2801                 .category = FIO_OPT_C_IO,
2802                 .group  = FIO_OPT_G_IO_FLOW,
2803         },
2804         {
2805                 .name   = "flow_watermark",
2806                 .lname  = "I/O flow watermark",
2807                 .type   = FIO_OPT_INT,
2808                 .off1   = td_var_offset(flow_watermark),
2809                 .help   = "High watermark for flow control. This option"
2810                         " should be set to the same value for all threads"
2811                         " with non-zero flow.",
2812                 .parent = "flow_id",
2813                 .hide   = 1,
2814                 .def    = "1024",
2815                 .category = FIO_OPT_C_IO,
2816                 .group  = FIO_OPT_G_IO_FLOW,
2817         },
2818         {
2819                 .name   = "flow_sleep",
2820                 .lname  = "I/O flow sleep",
2821                 .type   = FIO_OPT_INT,
2822                 .off1   = td_var_offset(flow_sleep),
2823                 .help   = "How many microseconds to sleep after being held"
2824                         " back by the flow control mechanism",
2825                 .parent = "flow_id",
2826                 .hide   = 1,
2827                 .def    = "0",
2828                 .category = FIO_OPT_C_IO,
2829                 .group  = FIO_OPT_G_IO_FLOW,
2830         },
2831         {
2832                 .name = NULL,
2833         },
2834 };
2835
2836 static void add_to_lopt(struct option *lopt, struct fio_option *o,
2837                         const char *name, int val)
2838 {
2839         lopt->name = (char *) name;
2840         lopt->val = val;
2841         if (o->type == FIO_OPT_STR_SET)
2842                 lopt->has_arg = no_argument;
2843         else
2844                 lopt->has_arg = required_argument;
2845 }
2846
2847 static void options_to_lopts(struct fio_option *opts,
2848                               struct option *long_options,
2849                               int i, int option_type)
2850 {
2851         struct fio_option *o = &opts[0];
2852         while (o->name) {
2853                 add_to_lopt(&long_options[i], o, o->name, option_type);
2854                 if (o->alias) {
2855                         i++;
2856                         add_to_lopt(&long_options[i], o, o->alias, option_type);
2857                 }
2858
2859                 i++;
2860                 o++;
2861                 assert(i < FIO_NR_OPTIONS);
2862         }
2863 }
2864
2865 void fio_options_set_ioengine_opts(struct option *long_options,
2866                                    struct thread_data *td)
2867 {
2868         unsigned int i;
2869
2870         i = 0;
2871         while (long_options[i].name) {
2872                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2873                         memset(&long_options[i], 0, sizeof(*long_options));
2874                         break;
2875                 }
2876                 i++;
2877         }
2878
2879         /*
2880          * Just clear out the prior ioengine options.
2881          */
2882         if (!td || !td->eo)
2883                 return;
2884
2885         options_to_lopts(td->io_ops->options, long_options, i,
2886                          FIO_GETOPT_IOENGINE);
2887 }
2888
2889 void fio_options_dup_and_init(struct option *long_options)
2890 {
2891         unsigned int i;
2892
2893         options_init(fio_options);
2894
2895         i = 0;
2896         while (long_options[i].name)
2897                 i++;
2898
2899         options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
2900 }
2901
2902 struct fio_keyword {
2903         const char *word;
2904         const char *desc;
2905         char *replace;
2906 };
2907
2908 static struct fio_keyword fio_keywords[] = {
2909         {
2910                 .word   = "$pagesize",
2911                 .desc   = "Page size in the system",
2912         },
2913         {
2914                 .word   = "$mb_memory",
2915                 .desc   = "Megabytes of memory online",
2916         },
2917         {
2918                 .word   = "$ncpus",
2919                 .desc   = "Number of CPUs online in the system",
2920         },
2921         {
2922                 .word   = NULL,
2923         },
2924 };
2925
2926 void fio_keywords_init(void)
2927 {
2928         unsigned long long mb_memory;
2929         char buf[128];
2930         long l;
2931
2932         sprintf(buf, "%lu", page_size);
2933         fio_keywords[0].replace = strdup(buf);
2934
2935         mb_memory = os_phys_mem() / (1024 * 1024);
2936         sprintf(buf, "%llu", mb_memory);
2937         fio_keywords[1].replace = strdup(buf);
2938
2939         l = cpus_online();
2940         sprintf(buf, "%lu", l);
2941         fio_keywords[2].replace = strdup(buf);
2942 }
2943
2944 #define BC_APP          "bc"
2945
2946 static char *bc_calc(char *str)
2947 {
2948         char buf[128], *tmp;
2949         FILE *f;
2950         int ret;
2951
2952         /*
2953          * No math, just return string
2954          */
2955         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2956              !strchr(str, '/')) || strchr(str, '\''))
2957                 return str;
2958
2959         /*
2960          * Split option from value, we only need to calculate the value
2961          */
2962         tmp = strchr(str, '=');
2963         if (!tmp)
2964                 return str;
2965
2966         tmp++;
2967
2968         /*
2969          * Prevent buffer overflows; such a case isn't reasonable anyway
2970          */
2971         if (strlen(str) >= 128 || strlen(tmp) > 100)
2972                 return str;
2973
2974         sprintf(buf, "which %s > /dev/null", BC_APP);
2975         if (system(buf)) {
2976                 log_err("fio: bc is needed for performing math\n");
2977                 return NULL;
2978         }
2979
2980         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
2981         f = popen(buf, "r");
2982         if (!f) {
2983                 return NULL;
2984         }
2985
2986         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
2987         if (ret <= 0) {
2988                 return NULL;
2989         }
2990
2991         pclose(f);
2992         buf[(tmp - str) + ret - 1] = '\0';
2993         memcpy(buf, str, tmp - str);
2994         free(str);
2995         return strdup(buf);
2996 }
2997
2998 /*
2999  * Return a copy of the input string with substrings of the form ${VARNAME}
3000  * substituted with the value of the environment variable VARNAME.  The
3001  * substitution always occurs, even if VARNAME is empty or the corresponding
3002  * environment variable undefined.
3003  */
3004 static char *option_dup_subs(const char *opt)
3005 {
3006         char out[OPT_LEN_MAX+1];
3007         char in[OPT_LEN_MAX+1];
3008         char *outptr = out;
3009         char *inptr = in;
3010         char *ch1, *ch2, *env;
3011         ssize_t nchr = OPT_LEN_MAX;
3012         size_t envlen;
3013
3014         if (strlen(opt) + 1 > OPT_LEN_MAX) {
3015                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
3016                 return NULL;
3017         }
3018
3019         in[OPT_LEN_MAX] = '\0';
3020         strncpy(in, opt, OPT_LEN_MAX);
3021
3022         while (*inptr && nchr > 0) {
3023                 if (inptr[0] == '$' && inptr[1] == '{') {
3024                         ch2 = strchr(inptr, '}');
3025                         if (ch2 && inptr+1 < ch2) {
3026                                 ch1 = inptr+2;
3027                                 inptr = ch2+1;
3028                                 *ch2 = '\0';
3029
3030                                 env = getenv(ch1);
3031                                 if (env) {
3032                                         envlen = strlen(env);
3033                                         if (envlen <= nchr) {
3034                                                 memcpy(outptr, env, envlen);
3035                                                 outptr += envlen;
3036                                                 nchr -= envlen;
3037                                         }
3038                                 }
3039
3040                                 continue;
3041                         }
3042                 }
3043
3044                 *outptr++ = *inptr++;
3045                 --nchr;
3046         }
3047
3048         *outptr = '\0';
3049         return strdup(out);
3050 }
3051
3052 /*
3053  * Look for reserved variable names and replace them with real values
3054  */
3055 static char *fio_keyword_replace(char *opt)
3056 {
3057         char *s;
3058         int i;
3059         int docalc = 0;
3060
3061         for (i = 0; fio_keywords[i].word != NULL; i++) {
3062                 struct fio_keyword *kw = &fio_keywords[i];
3063
3064                 while ((s = strstr(opt, kw->word)) != NULL) {
3065                         char *new = malloc(strlen(opt) + 1);
3066                         char *o_org = opt;
3067                         int olen = s - opt;
3068                         int len;
3069
3070                         /*
3071                          * Copy part of the string before the keyword and
3072                          * sprintf() the replacement after it.
3073                          */
3074                         memcpy(new, opt, olen);
3075                         len = sprintf(new + olen, "%s", kw->replace);
3076
3077                         /*
3078                          * If there's more in the original string, copy that
3079                          * in too
3080                          */
3081                         opt += strlen(kw->word) + olen;
3082                         if (strlen(opt))
3083                                 memcpy(new + olen + len, opt, opt - o_org - 1);
3084
3085                         /*
3086                          * replace opt and free the old opt
3087                          */
3088                         opt = new;
3089                         free(o_org);
3090
3091                         docalc = 1;
3092                 }
3093         }
3094
3095         /*
3096          * Check for potential math and invoke bc, if possible
3097          */
3098         if (docalc)
3099                 opt = bc_calc(opt);
3100
3101         return opt;
3102 }
3103
3104 static char **dup_and_sub_options(char **opts, int num_opts)
3105 {
3106         int i;
3107         char **opts_copy = malloc(num_opts * sizeof(*opts));
3108         for (i = 0; i < num_opts; i++) {
3109                 opts_copy[i] = option_dup_subs(opts[i]);
3110                 if (!opts_copy[i])
3111                         continue;
3112                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
3113         }
3114         return opts_copy;
3115 }
3116
3117 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
3118 {
3119         int i, ret, unknown;
3120         char **opts_copy;
3121
3122         sort_options(opts, fio_options, num_opts);
3123         opts_copy = dup_and_sub_options(opts, num_opts);
3124
3125         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
3126                 struct fio_option *o;
3127                 int newret = parse_option(opts_copy[i], opts[i], fio_options,
3128                                                 &o, td);
3129
3130                 if (opts_copy[i]) {
3131                         if (newret && !o) {
3132                                 unknown++;
3133                                 continue;
3134                         }
3135                         free(opts_copy[i]);
3136                         opts_copy[i] = NULL;
3137                 }
3138
3139                 ret |= newret;
3140         }
3141
3142         if (unknown) {
3143                 ret |= ioengine_load(td);
3144                 if (td->eo) {
3145                         sort_options(opts_copy, td->io_ops->options, num_opts);
3146                         opts = opts_copy;
3147                 }
3148                 for (i = 0; i < num_opts; i++) {
3149                         struct fio_option *o = NULL;
3150                         int newret = 1;
3151                         if (!opts_copy[i])
3152                                 continue;
3153
3154                         if (td->eo)
3155                                 newret = parse_option(opts_copy[i], opts[i],
3156                                                       td->io_ops->options, &o,
3157                                                       td->eo);
3158
3159                         ret |= newret;
3160                         if (!o)
3161                                 log_err("Bad option <%s>\n", opts[i]);
3162
3163                         free(opts_copy[i]);
3164                         opts_copy[i] = NULL;
3165                 }
3166         }
3167
3168         free(opts_copy);
3169         return ret;
3170 }
3171
3172 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
3173 {
3174         return parse_cmd_option(opt, val, fio_options, td);
3175 }
3176
3177 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
3178                                 char *val)
3179 {
3180         return parse_cmd_option(opt, val, td->io_ops->options, td);
3181 }
3182
3183 void fio_fill_default_options(struct thread_data *td)
3184 {
3185         fill_default_options(td, fio_options);
3186 }
3187
3188 int fio_show_option_help(const char *opt)
3189 {
3190         return show_cmd_help(fio_options, opt);
3191 }
3192
3193 void options_mem_dupe(void *data, struct fio_option *options)
3194 {
3195         struct fio_option *o;
3196         char **ptr;
3197
3198         for (o = &options[0]; o->name; o++) {
3199                 if (o->type != FIO_OPT_STR_STORE)
3200                         continue;
3201
3202                 ptr = td_var(data, o->off1);
3203                 if (*ptr)
3204                         *ptr = strdup(*ptr);
3205         }
3206 }
3207
3208 /*
3209  * dupe FIO_OPT_STR_STORE options
3210  */
3211 void fio_options_mem_dupe(struct thread_data *td)
3212 {
3213         options_mem_dupe(&td->o, fio_options);
3214
3215         if (td->eo && td->io_ops) {
3216                 void *oldeo = td->eo;
3217
3218                 td->eo = malloc(td->io_ops->option_struct_size);
3219                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
3220                 options_mem_dupe(td->eo, td->io_ops->options);
3221         }
3222 }
3223
3224 unsigned int fio_get_kb_base(void *data)
3225 {
3226         struct thread_data *td = data;
3227         unsigned int kb_base = 0;
3228
3229         if (td)
3230                 kb_base = td->o.kb_base;
3231         if (!kb_base)
3232                 kb_base = 1024;
3233
3234         return kb_base;
3235 }
3236
3237 int add_option(struct fio_option *o)
3238 {
3239         struct fio_option *__o;
3240         int opt_index = 0;
3241
3242         __o = fio_options;
3243         while (__o->name) {
3244                 opt_index++;
3245                 __o++;
3246         }
3247
3248         memcpy(&fio_options[opt_index], o, sizeof(*o));
3249         return 0;
3250 }
3251
3252 void invalidate_profile_options(const char *prof_name)
3253 {
3254         struct fio_option *o;
3255
3256         o = fio_options;
3257         while (o->name) {
3258                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
3259                         o->type = FIO_OPT_INVALID;
3260                         o->prof_name = NULL;
3261                 }
3262                 o++;
3263         }
3264 }
3265
3266 void add_opt_posval(const char *optname, const char *ival, const char *help)
3267 {
3268         struct fio_option *o;
3269         unsigned int i;
3270
3271         o = find_option(fio_options, optname);
3272         if (!o)
3273                 return;
3274
3275         for (i = 0; i < PARSE_MAX_VP; i++) {
3276                 if (o->posval[i].ival)
3277                         continue;
3278
3279                 o->posval[i].ival = ival;
3280                 o->posval[i].help = help;
3281                 break;
3282         }
3283 }
3284
3285 void del_opt_posval(const char *optname, const char *ival)
3286 {
3287         struct fio_option *o;
3288         unsigned int i;
3289
3290         o = find_option(fio_options, optname);
3291         if (!o)
3292                 return;
3293
3294         for (i = 0; i < PARSE_MAX_VP; i++) {
3295                 if (!o->posval[i].ival)
3296                         continue;
3297                 if (strcmp(o->posval[i].ival, ival))
3298                         continue;
3299
3300                 o->posval[i].ival = NULL;
3301                 o->posval[i].help = NULL;
3302         }
3303 }
3304
3305 void fio_options_free(struct thread_data *td)
3306 {
3307         options_free(fio_options, td);
3308         if (td->eo && td->io_ops && td->io_ops->options) {
3309                 options_free(td->io_ops->options, td->eo);
3310                 free(td->eo);
3311                 td->eo = NULL;
3312         }
3313 }