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