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