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