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