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