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