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