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