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