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