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