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