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