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