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