gfio: add recently opened files to File menu
[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   = "clat_percentiles",
2134                 .type   = FIO_OPT_BOOL,
2135                 .off1   = td_var_offset(clat_percentiles),
2136                 .help   = "Enable the reporting of completion latency percentiles",
2137                 .def    = "1",
2138                 .category = FIO_OPT_G_STAT,
2139         },
2140         {
2141                 .name   = "percentile_list",
2142                 .type   = FIO_OPT_FLOAT_LIST,
2143                 .off1   = td_var_offset(percentile_list),
2144                 .off2   = td_var_offset(overwrite_plist),
2145                 .help   = "Specify a custom list of percentiles to report",
2146                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2147                 .minfp  = 0.0,
2148                 .maxfp  = 100.0,
2149                 .category = FIO_OPT_G_STAT,
2150         },
2151
2152 #ifdef FIO_HAVE_DISK_UTIL
2153         {
2154                 .name   = "disk_util",
2155                 .type   = FIO_OPT_BOOL,
2156                 .off1   = td_var_offset(do_disk_util),
2157                 .help   = "Log disk utilization statistics",
2158                 .def    = "1",
2159                 .category = FIO_OPT_G_OS | FIO_OPT_G_STAT,
2160         },
2161 #endif
2162         {
2163                 .name   = "gtod_reduce",
2164                 .type   = FIO_OPT_BOOL,
2165                 .help   = "Greatly reduce number of gettimeofday() calls",
2166                 .cb     = str_gtod_reduce_cb,
2167                 .def    = "0",
2168                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2169         },
2170         {
2171                 .name   = "disable_lat",
2172                 .type   = FIO_OPT_BOOL,
2173                 .off1   = td_var_offset(disable_lat),
2174                 .help   = "Disable latency numbers",
2175                 .parent = "gtod_reduce",
2176                 .def    = "0",
2177                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2178         },
2179         {
2180                 .name   = "disable_clat",
2181                 .type   = FIO_OPT_BOOL,
2182                 .off1   = td_var_offset(disable_clat),
2183                 .help   = "Disable completion latency numbers",
2184                 .parent = "gtod_reduce",
2185                 .def    = "0",
2186                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2187         },
2188         {
2189                 .name   = "disable_slat",
2190                 .type   = FIO_OPT_BOOL,
2191                 .off1   = td_var_offset(disable_slat),
2192                 .help   = "Disable submission latency numbers",
2193                 .parent = "gtod_reduce",
2194                 .def    = "0",
2195                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2196         },
2197         {
2198                 .name   = "disable_bw_measurement",
2199                 .type   = FIO_OPT_BOOL,
2200                 .off1   = td_var_offset(disable_bw),
2201                 .help   = "Disable bandwidth logging",
2202                 .parent = "gtod_reduce",
2203                 .def    = "0",
2204                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2205         },
2206         {
2207                 .name   = "gtod_cpu",
2208                 .type   = FIO_OPT_INT,
2209                 .cb     = str_gtod_cpu_cb,
2210                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
2211                 .verify = gtod_cpu_verify,
2212                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2213         },
2214         {
2215                 .name   = "continue_on_error",
2216                 .type   = FIO_OPT_STR,
2217                 .off1   = td_var_offset(continue_on_error),
2218                 .help   = "Continue on non-fatal errors during IO",
2219                 .def    = "none",
2220                 .category = FIO_OPT_G_MISC | FIO_OPT_G_ERR,
2221                 .posval = {
2222                           { .ival = "none",
2223                             .oval = ERROR_TYPE_NONE,
2224                             .help = "Exit when an error is encountered",
2225                           },
2226                           { .ival = "read",
2227                             .oval = ERROR_TYPE_READ,
2228                             .help = "Continue on read errors only",
2229                           },
2230                           { .ival = "write",
2231                             .oval = ERROR_TYPE_WRITE,
2232                             .help = "Continue on write errors only",
2233                           },
2234                           { .ival = "io",
2235                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2236                             .help = "Continue on any IO errors",
2237                           },
2238                           { .ival = "verify",
2239                             .oval = ERROR_TYPE_VERIFY,
2240                             .help = "Continue on verify errors only",
2241                           },
2242                           { .ival = "all",
2243                             .oval = ERROR_TYPE_ANY,
2244                             .help = "Continue on all io and verify errors",
2245                           },
2246                           { .ival = "0",
2247                             .oval = ERROR_TYPE_NONE,
2248                             .help = "Alias for 'none'",
2249                           },
2250                           { .ival = "1",
2251                             .oval = ERROR_TYPE_ANY,
2252                             .help = "Alias for 'all'",
2253                           },
2254                 },
2255         },
2256         {
2257                 .name   = "profile",
2258                 .type   = FIO_OPT_STR_STORE,
2259                 .off1   = td_var_offset(profile),
2260                 .help   = "Select a specific builtin performance test",
2261                 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2262         },
2263         {
2264                 .name   = "cgroup",
2265                 .type   = FIO_OPT_STR_STORE,
2266                 .off1   = td_var_offset(cgroup),
2267                 .help   = "Add job to cgroup of this name",
2268                 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2269         },
2270         {
2271                 .name   = "cgroup_weight",
2272                 .type   = FIO_OPT_INT,
2273                 .off1   = td_var_offset(cgroup_weight),
2274                 .help   = "Use given weight for cgroup",
2275                 .minval = 100,
2276                 .maxval = 1000,
2277                 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2278         },
2279         {
2280                 .name   = "cgroup_nodelete",
2281                 .type   = FIO_OPT_BOOL,
2282                 .off1   = td_var_offset(cgroup_nodelete),
2283                 .help   = "Do not delete cgroups after job completion",
2284                 .def    = "0",
2285                 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2286         },
2287         {
2288                 .name   = "uid",
2289                 .type   = FIO_OPT_INT,
2290                 .off1   = td_var_offset(uid),
2291                 .help   = "Run job with this user ID",
2292                 .category = FIO_OPT_G_OS | FIO_OPT_G_JOB,
2293         },
2294         {
2295                 .name   = "gid",
2296                 .type   = FIO_OPT_INT,
2297                 .off1   = td_var_offset(gid),
2298                 .help   = "Run job with this group ID",
2299                 .category = FIO_OPT_G_OS | FIO_OPT_G_JOB,
2300         },
2301         {
2302                 .name   = "flow_id",
2303                 .type   = FIO_OPT_INT,
2304                 .off1   = td_var_offset(flow_id),
2305                 .help   = "The flow index ID to use",
2306                 .def    = "0",
2307                 .category = FIO_OPT_G_IO,
2308         },
2309         {
2310                 .name   = "flow",
2311                 .type   = FIO_OPT_INT,
2312                 .off1   = td_var_offset(flow),
2313                 .help   = "Weight for flow control of this job",
2314                 .parent = "flow_id",
2315                 .def    = "0",
2316                 .category = FIO_OPT_G_IO,
2317         },
2318         {
2319                 .name   = "flow_watermark",
2320                 .type   = FIO_OPT_INT,
2321                 .off1   = td_var_offset(flow_watermark),
2322                 .help   = "High watermark for flow control. This option"
2323                         " should be set to the same value for all threads"
2324                         " with non-zero flow.",
2325                 .parent = "flow_id",
2326                 .def    = "1024",
2327                 .category = FIO_OPT_G_IO,
2328         },
2329         {
2330                 .name   = "flow_sleep",
2331                 .type   = FIO_OPT_INT,
2332                 .off1   = td_var_offset(flow_sleep),
2333                 .help   = "How many microseconds to sleep after being held"
2334                         " back by the flow control mechanism",
2335                 .parent = "flow_id",
2336                 .def    = "0",
2337                 .category = FIO_OPT_G_IO,
2338         },
2339         {
2340                 .name = NULL,
2341         },
2342 };
2343
2344 static void add_to_lopt(struct option *lopt, struct fio_option *o,
2345                         const char *name, int val)
2346 {
2347         lopt->name = (char *) name;
2348         lopt->val = val;
2349         if (o->type == FIO_OPT_STR_SET)
2350                 lopt->has_arg = no_argument;
2351         else
2352                 lopt->has_arg = required_argument;
2353 }
2354
2355 static void options_to_lopts(struct fio_option *opts,
2356                               struct option *long_options,
2357                               int i, int option_type)
2358 {
2359         struct fio_option *o = &opts[0];
2360         while (o->name) {
2361                 add_to_lopt(&long_options[i], o, o->name, option_type);
2362                 if (o->alias) {
2363                         i++;
2364                         add_to_lopt(&long_options[i], o, o->alias, option_type);
2365                 }
2366
2367                 i++;
2368                 o++;
2369                 assert(i < FIO_NR_OPTIONS);
2370         }
2371 }
2372
2373 void fio_options_set_ioengine_opts(struct option *long_options,
2374                                    struct thread_data *td)
2375 {
2376         unsigned int i;
2377
2378         i = 0;
2379         while (long_options[i].name) {
2380                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2381                         memset(&long_options[i], 0, sizeof(*long_options));
2382                         break;
2383                 }
2384                 i++;
2385         }
2386
2387         /*
2388          * Just clear out the prior ioengine options.
2389          */
2390         if (!td || !td->eo)
2391                 return;
2392
2393         options_to_lopts(td->io_ops->options, long_options, i,
2394                          FIO_GETOPT_IOENGINE);
2395 }
2396
2397 void fio_options_dup_and_init(struct option *long_options)
2398 {
2399         unsigned int i;
2400
2401         options_init(options);
2402
2403         i = 0;
2404         while (long_options[i].name)
2405                 i++;
2406
2407         options_to_lopts(options, long_options, i, FIO_GETOPT_JOB);
2408 }
2409
2410 struct fio_keyword {
2411         const char *word;
2412         const char *desc;
2413         char *replace;
2414 };
2415
2416 static struct fio_keyword fio_keywords[] = {
2417         {
2418                 .word   = "$pagesize",
2419                 .desc   = "Page size in the system",
2420         },
2421         {
2422                 .word   = "$mb_memory",
2423                 .desc   = "Megabytes of memory online",
2424         },
2425         {
2426                 .word   = "$ncpus",
2427                 .desc   = "Number of CPUs online in the system",
2428         },
2429         {
2430                 .word   = NULL,
2431         },
2432 };
2433
2434 void fio_keywords_init(void)
2435 {
2436         unsigned long long mb_memory;
2437         char buf[128];
2438         long l;
2439
2440         sprintf(buf, "%lu", page_size);
2441         fio_keywords[0].replace = strdup(buf);
2442
2443         mb_memory = os_phys_mem() / (1024 * 1024);
2444         sprintf(buf, "%llu", mb_memory);
2445         fio_keywords[1].replace = strdup(buf);
2446
2447         l = cpus_online();
2448         sprintf(buf, "%lu", l);
2449         fio_keywords[2].replace = strdup(buf);
2450 }
2451
2452 #define BC_APP          "bc"
2453
2454 static char *bc_calc(char *str)
2455 {
2456         char buf[128], *tmp;
2457         FILE *f;
2458         int ret;
2459
2460         /*
2461          * No math, just return string
2462          */
2463         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2464              !strchr(str, '/')) || strchr(str, '\''))
2465                 return str;
2466
2467         /*
2468          * Split option from value, we only need to calculate the value
2469          */
2470         tmp = strchr(str, '=');
2471         if (!tmp)
2472                 return str;
2473
2474         tmp++;
2475
2476         /*
2477          * Prevent buffer overflows; such a case isn't reasonable anyway
2478          */
2479         if (strlen(str) >= 128 || strlen(tmp) > 100)
2480                 return str;
2481
2482         sprintf(buf, "which %s > /dev/null", BC_APP);
2483         if (system(buf)) {
2484                 log_err("fio: bc is needed for performing math\n");
2485                 return NULL;
2486         }
2487
2488         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
2489         f = popen(buf, "r");
2490         if (!f) {
2491                 return NULL;
2492         }
2493
2494         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
2495         if (ret <= 0) {
2496                 return NULL;
2497         }
2498
2499         pclose(f);
2500         buf[(tmp - str) + ret - 1] = '\0';
2501         memcpy(buf, str, tmp - str);
2502         free(str);
2503         return strdup(buf);
2504 }
2505
2506 /*
2507  * Return a copy of the input string with substrings of the form ${VARNAME}
2508  * substituted with the value of the environment variable VARNAME.  The
2509  * substitution always occurs, even if VARNAME is empty or the corresponding
2510  * environment variable undefined.
2511  */
2512 static char *option_dup_subs(const char *opt)
2513 {
2514         char out[OPT_LEN_MAX+1];
2515         char in[OPT_LEN_MAX+1];
2516         char *outptr = out;
2517         char *inptr = in;
2518         char *ch1, *ch2, *env;
2519         ssize_t nchr = OPT_LEN_MAX;
2520         size_t envlen;
2521
2522         if (strlen(opt) + 1 > OPT_LEN_MAX) {
2523                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2524                 return NULL;
2525         }
2526
2527         in[OPT_LEN_MAX] = '\0';
2528         strncpy(in, opt, OPT_LEN_MAX);
2529
2530         while (*inptr && nchr > 0) {
2531                 if (inptr[0] == '$' && inptr[1] == '{') {
2532                         ch2 = strchr(inptr, '}');
2533                         if (ch2 && inptr+1 < ch2) {
2534                                 ch1 = inptr+2;
2535                                 inptr = ch2+1;
2536                                 *ch2 = '\0';
2537
2538                                 env = getenv(ch1);
2539                                 if (env) {
2540                                         envlen = strlen(env);
2541                                         if (envlen <= nchr) {
2542                                                 memcpy(outptr, env, envlen);
2543                                                 outptr += envlen;
2544                                                 nchr -= envlen;
2545                                         }
2546                                 }
2547
2548                                 continue;
2549                         }
2550                 }
2551
2552                 *outptr++ = *inptr++;
2553                 --nchr;
2554         }
2555
2556         *outptr = '\0';
2557         return strdup(out);
2558 }
2559
2560 /*
2561  * Look for reserved variable names and replace them with real values
2562  */
2563 static char *fio_keyword_replace(char *opt)
2564 {
2565         char *s;
2566         int i;
2567         int docalc = 0;
2568
2569         for (i = 0; fio_keywords[i].word != NULL; i++) {
2570                 struct fio_keyword *kw = &fio_keywords[i];
2571
2572                 while ((s = strstr(opt, kw->word)) != NULL) {
2573                         char *new = malloc(strlen(opt) + 1);
2574                         char *o_org = opt;
2575                         int olen = s - opt;
2576                         int len;
2577
2578                         /*
2579                          * Copy part of the string before the keyword and
2580                          * sprintf() the replacement after it.
2581                          */
2582                         memcpy(new, opt, olen);
2583                         len = sprintf(new + olen, "%s", kw->replace);
2584
2585                         /*
2586                          * If there's more in the original string, copy that
2587                          * in too
2588                          */
2589                         opt += strlen(kw->word) + olen;
2590                         if (strlen(opt))
2591                                 memcpy(new + olen + len, opt, opt - o_org - 1);
2592
2593                         /*
2594                          * replace opt and free the old opt
2595                          */
2596                         opt = new;
2597                         free(o_org);
2598
2599                         docalc = 1;
2600                 }
2601         }
2602
2603         /*
2604          * Check for potential math and invoke bc, if possible
2605          */
2606         if (docalc)
2607                 opt = bc_calc(opt);
2608
2609         return opt;
2610 }
2611
2612 static char **dup_and_sub_options(char **opts, int num_opts)
2613 {
2614         int i;
2615         char **opts_copy = malloc(num_opts * sizeof(*opts));
2616         for (i = 0; i < num_opts; i++) {
2617                 opts_copy[i] = option_dup_subs(opts[i]);
2618                 if (!opts_copy[i])
2619                         continue;
2620                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2621         }
2622         return opts_copy;
2623 }
2624
2625 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2626 {
2627         int i, ret, unknown;
2628         char **opts_copy;
2629
2630         sort_options(opts, options, num_opts);
2631         opts_copy = dup_and_sub_options(opts, num_opts);
2632
2633         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2634                 struct fio_option *o;
2635                 int newret = parse_option(opts_copy[i], opts[i], options, &o,
2636                                           td);
2637
2638                 if (opts_copy[i]) {
2639                         if (newret && !o) {
2640                                 unknown++;
2641                                 continue;
2642                         }
2643                         free(opts_copy[i]);
2644                         opts_copy[i] = NULL;
2645                 }
2646
2647                 ret |= newret;
2648         }
2649
2650         if (unknown) {
2651                 ret |= ioengine_load(td);
2652                 if (td->eo) {
2653                         sort_options(opts_copy, td->io_ops->options, num_opts);
2654                         opts = opts_copy;
2655                 }
2656                 for (i = 0; i < num_opts; i++) {
2657                         struct fio_option *o = NULL;
2658                         int newret = 1;
2659                         if (!opts_copy[i])
2660                                 continue;
2661
2662                         if (td->eo)
2663                                 newret = parse_option(opts_copy[i], opts[i],
2664                                                       td->io_ops->options, &o,
2665                                                       td->eo);
2666
2667                         ret |= newret;
2668                         if (!o)
2669                                 log_err("Bad option <%s>\n", opts[i]);
2670
2671                         free(opts_copy[i]);
2672                         opts_copy[i] = NULL;
2673                 }
2674         }
2675
2676         free(opts_copy);
2677         return ret;
2678 }
2679
2680 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2681 {
2682         return parse_cmd_option(opt, val, options, td);
2683 }
2684
2685 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2686                                 char *val)
2687 {
2688         return parse_cmd_option(opt, val, td->io_ops->options, td);
2689 }
2690
2691 void fio_fill_default_options(struct thread_data *td)
2692 {
2693         fill_default_options(td, options);
2694 }
2695
2696 int fio_show_option_help(const char *opt)
2697 {
2698         return show_cmd_help(options, opt);
2699 }
2700
2701 void options_mem_dupe(void *data, struct fio_option *options)
2702 {
2703         struct fio_option *o;
2704         char **ptr;
2705
2706         for (o = &options[0]; o->name; o++) {
2707                 if (o->type != FIO_OPT_STR_STORE)
2708                         continue;
2709
2710                 ptr = td_var(data, o->off1);
2711                 if (*ptr)
2712                         *ptr = strdup(*ptr);
2713         }
2714 }
2715
2716 /*
2717  * dupe FIO_OPT_STR_STORE options
2718  */
2719 void fio_options_mem_dupe(struct thread_data *td)
2720 {
2721         options_mem_dupe(&td->o, options);
2722
2723         if (td->eo && td->io_ops) {
2724                 void *oldeo = td->eo;
2725
2726                 td->eo = malloc(td->io_ops->option_struct_size);
2727                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2728                 options_mem_dupe(td->eo, td->io_ops->options);
2729         }
2730 }
2731
2732 unsigned int fio_get_kb_base(void *data)
2733 {
2734         struct thread_data *td = data;
2735         unsigned int kb_base = 0;
2736
2737         if (td)
2738                 kb_base = td->o.kb_base;
2739         if (!kb_base)
2740                 kb_base = 1024;
2741
2742         return kb_base;
2743 }
2744
2745 int add_option(struct fio_option *o)
2746 {
2747         struct fio_option *__o;
2748         int opt_index = 0;
2749
2750         __o = options;
2751         while (__o->name) {
2752                 opt_index++;
2753                 __o++;
2754         }
2755
2756         memcpy(&options[opt_index], o, sizeof(*o));
2757         return 0;
2758 }
2759
2760 void invalidate_profile_options(const char *prof_name)
2761 {
2762         struct fio_option *o;
2763
2764         o = options;
2765         while (o->name) {
2766                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2767                         o->type = FIO_OPT_INVALID;
2768                         o->prof_name = NULL;
2769                 }
2770                 o++;
2771         }
2772 }
2773
2774 void add_opt_posval(const char *optname, const char *ival, const char *help)
2775 {
2776         struct fio_option *o;
2777         unsigned int i;
2778
2779         o = find_option(options, optname);
2780         if (!o)
2781                 return;
2782
2783         for (i = 0; i < PARSE_MAX_VP; i++) {
2784                 if (o->posval[i].ival)
2785                         continue;
2786
2787                 o->posval[i].ival = ival;
2788                 o->posval[i].help = help;
2789                 break;
2790         }
2791 }
2792
2793 void del_opt_posval(const char *optname, const char *ival)
2794 {
2795         struct fio_option *o;
2796         unsigned int i;
2797
2798         o = find_option(options, optname);
2799         if (!o)
2800                 return;
2801
2802         for (i = 0; i < PARSE_MAX_VP; i++) {
2803                 if (!o->posval[i].ival)
2804                         continue;
2805                 if (strcmp(o->posval[i].ival, ival))
2806                         continue;
2807
2808                 o->posval[i].ival = NULL;
2809                 o->posval[i].help = NULL;
2810         }
2811 }
2812
2813 void fio_options_free(struct thread_data *td)
2814 {
2815         options_free(options, td);
2816         if (td->eo && td->io_ops && td->io_ops->options) {
2817                 options_free(td->io_ops->options, td->eo);
2818                 free(td->eo);
2819                 td->eo = NULL;
2820         }
2821 }