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