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