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