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