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