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