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