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