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