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