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