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