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