Fix bug with random IO and network connections
[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>
6#include <getopt.h>
7#include <assert.h>
8
9#include "fio.h"
10#include "parse.h"
11
2dc1bbeb 12#define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
214e1eca
JA
13
14/*
15 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
16 */
17static char *get_opt_postfix(const char *str)
18{
19 char *p = strstr(str, ":");
20
21 if (!p)
22 return NULL;
23
24 p++;
25 strip_blank_front(&p);
26 strip_blank_end(p);
27 return strdup(p);
28}
29
211097b2
JA
30static int str_rw_cb(void *data, const char *str)
31{
32 struct thread_data *td = data;
33 char *nr = get_opt_postfix(str);
34
fafdba3c 35 td->o.ddir_nr = 1;
211097b2
JA
36 if (nr)
37 td->o.ddir_nr = atoi(nr);
38
211097b2
JA
39 return 0;
40}
41
214e1eca
JA
42static int str_mem_cb(void *data, const char *mem)
43{
44 struct thread_data *td = data;
45
2dc1bbeb 46 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
214e1eca 47 td->mmapfile = get_opt_postfix(mem);
2dc1bbeb 48 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
214e1eca
JA
49 log_err("fio: mmaphuge:/path/to/file\n");
50 return 1;
51 }
52 }
53
54 return 0;
55}
56
57static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
58{
59 mlock_size = *val;
60 return 0;
61}
62
63#ifdef FIO_HAVE_IOPRIO
64static int str_prioclass_cb(void *data, unsigned int *val)
65{
66 struct thread_data *td = data;
6cefbe33
JA
67 unsigned short mask;
68
69 /*
70 * mask off old class bits, str_prio_cb() may have set a default class
71 */
72 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
73 td->ioprio &= mask;
214e1eca
JA
74
75 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
76 return 0;
77}
78
79static int str_prio_cb(void *data, unsigned int *val)
80{
81 struct thread_data *td = data;
82
83 td->ioprio |= *val;
6cefbe33
JA
84
85 /*
86 * If no class is set, assume BE
87 */
88 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
89 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
90
214e1eca
JA
91 return 0;
92}
93#endif
94
95static int str_exitall_cb(void)
96{
97 exitall_on_terminate = 1;
98 return 0;
99}
100
101static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
102{
103#ifdef FIO_HAVE_CPU_AFFINITY
104 unsigned int i;
105
106 CPU_ZERO(&cpumask);
107
108 for (i = 0; i < sizeof(int) * 8; i++) {
109 if ((1 << i) & cpu)
110 CPU_SET(i, &cpumask);
111 }
112#endif
113}
114
115static int str_cpumask_cb(void *data, unsigned int *val)
116{
117 struct thread_data *td = data;
118
2dc1bbeb 119 fill_cpu_mask(td->o.cpumask, *val);
375b2695 120 td->o.cpumask_set = 1;
214e1eca
JA
121 return 0;
122}
123
124static int str_fst_cb(void *data, const char *str)
125{
126 struct thread_data *td = data;
127 char *nr = get_opt_postfix(str);
128
129 td->file_service_nr = 1;
130 if (nr)
131 td->file_service_nr = atoi(nr);
132
133 return 0;
134}
135
136static int str_filename_cb(void *data, const char *input)
137{
138 struct thread_data *td = data;
139 char *fname, *str, *p;
140
141 p = str = strdup(input);
142
143 strip_blank_front(&str);
144 strip_blank_end(str);
145
146 if (!td->files_index)
2dc1bbeb 147 td->o.nr_files = 0;
214e1eca
JA
148
149 while ((fname = strsep(&str, ":")) != NULL) {
150 if (!strlen(fname))
151 break;
152 add_file(td, fname);
2dc1bbeb 153 td->o.nr_files++;
214e1eca
JA
154 }
155
156 free(p);
157 return 0;
158}
159
160static int str_directory_cb(void *data, const char fio_unused *str)
161{
162 struct thread_data *td = data;
163 struct stat sb;
164
2dc1bbeb
JA
165 if (lstat(td->o.directory, &sb) < 0) {
166 log_err("fio: %s is not a directory\n", td->o.directory);
214e1eca
JA
167 td_verror(td, errno, "lstat");
168 return 1;
169 }
170 if (!S_ISDIR(sb.st_mode)) {
2dc1bbeb 171 log_err("fio: %s is not a directory\n", td->o.directory);
214e1eca
JA
172 return 1;
173 }
174
175 return 0;
176}
177
178static int str_opendir_cb(void *data, const char fio_unused *str)
179{
180 struct thread_data *td = data;
181
182 if (!td->files_index)
2dc1bbeb 183 td->o.nr_files = 0;
214e1eca 184
2dc1bbeb 185 return add_dir_files(td, td->o.opendir);
214e1eca
JA
186}
187
188
189#define __stringify_1(x) #x
190#define __stringify(x) __stringify_1(x)
191
192/*
193 * Map of job/command line options
194 */
195static struct fio_option options[] = {
196 {
197 .name = "description",
198 .type = FIO_OPT_STR_STORE,
199 .off1 = td_var_offset(description),
200 .help = "Text job description",
201 },
202 {
203 .name = "name",
204 .type = FIO_OPT_STR_STORE,
205 .off1 = td_var_offset(name),
206 .help = "Name of this job",
207 },
208 {
209 .name = "directory",
210 .type = FIO_OPT_STR_STORE,
211 .off1 = td_var_offset(directory),
212 .cb = str_directory_cb,
213 .help = "Directory to store files in",
214 },
215 {
216 .name = "filename",
217 .type = FIO_OPT_STR_STORE,
218 .off1 = td_var_offset(filename),
219 .cb = str_filename_cb,
220 .help = "File(s) to use for the workload",
221 },
222 {
223 .name = "opendir",
224 .type = FIO_OPT_STR_STORE,
225 .off1 = td_var_offset(opendir),
226 .cb = str_opendir_cb,
227 .help = "Recursively add files from this directory and down",
228 },
229 {
230 .name = "rw",
d3aad8f2 231 .alias = "readwrite",
214e1eca 232 .type = FIO_OPT_STR,
211097b2 233 .cb = str_rw_cb,
214e1eca
JA
234 .off1 = td_var_offset(td_ddir),
235 .help = "IO direction",
236 .def = "read",
237 .posval = {
238 { .ival = "read",
239 .oval = TD_DDIR_READ,
240 .help = "Sequential read",
241 },
242 { .ival = "write",
243 .oval = TD_DDIR_WRITE,
244 .help = "Sequential write",
245 },
246 { .ival = "randread",
247 .oval = TD_DDIR_RANDREAD,
248 .help = "Random read",
249 },
250 { .ival = "randwrite",
251 .oval = TD_DDIR_RANDWRITE,
252 .help = "Random write",
253 },
254 { .ival = "rw",
255 .oval = TD_DDIR_RW,
256 .help = "Sequential read and write mix",
257 },
258 { .ival = "randrw",
259 .oval = TD_DDIR_RANDRW,
260 .help = "Random read and write mix"
261 },
262 },
263 },
d2f3ac35
JA
264 {
265 .name = "fadvise_hint",
266 .type = FIO_OPT_BOOL,
267 .off1 = td_var_offset(fadvise_hint),
268 .help = "Use fadvise() to advise the kernel on IO pattern",
269 .def = "1",
270 },
214e1eca
JA
271 {
272 .name = "ioengine",
273 .type = FIO_OPT_STR_STORE,
274 .off1 = td_var_offset(ioengine),
275 .help = "IO engine to use",
276 .def = "sync",
277 .posval = {
278 { .ival = "sync",
279 .help = "Use read/write",
280 },
281#ifdef FIO_HAVE_LIBAIO
282 { .ival = "libaio",
283 .help = "Linux native asynchronous IO",
284 },
285#endif
286#ifdef FIO_HAVE_POSIXAIO
287 { .ival = "posixaio",
288 .help = "POSIX asynchronous IO",
289 },
290#endif
291 { .ival = "mmap",
292 .help = "Memory mapped IO",
293 },
294#ifdef FIO_HAVE_SPLICE
295 { .ival = "splice",
296 .help = "splice/vmsplice based IO",
297 },
298#endif
299#ifdef FIO_HAVE_SGIO
300 { .ival = "sg",
301 .help = "SCSI generic v3 IO",
302 },
303#endif
304 { .ival = "null",
305 .help = "Testing engine (no data transfer)",
306 },
307 { .ival = "net",
308 .help = "Network IO",
309 },
310#ifdef FIO_HAVE_SYSLET
311 { .ival = "syslet-rw",
312 .help = "syslet enabled async pread/pwrite IO",
313 },
314#endif
315 { .ival = "cpuio",
316 .help = "CPU cycler burner engine",
317 },
b8c82a46
JA
318#ifdef FIO_HAVE_GUASI
319 { .ival = "guasi",
320 .help = "GUASI IO engine",
321 },
322#endif
214e1eca
JA
323 { .ival = "external",
324 .help = "Load external engine (append name)",
325 },
326 },
327 },
328 {
329 .name = "iodepth",
330 .type = FIO_OPT_INT,
331 .off1 = td_var_offset(iodepth),
332 .help = "Amount of IO buffers to keep in flight",
333 .def = "1",
334 },
335 {
336 .name = "iodepth_batch",
337 .type = FIO_OPT_INT,
338 .off1 = td_var_offset(iodepth_batch),
339 .help = "Number of IO to submit in one go",
340 },
341 {
342 .name = "iodepth_low",
343 .type = FIO_OPT_INT,
344 .off1 = td_var_offset(iodepth_low),
345 .help = "Low water mark for queuing depth",
346 },
347 {
348 .name = "size",
349 .type = FIO_OPT_STR_VAL,
2dc1bbeb 350 .off1 = td_var_offset(size),
214e1eca
JA
351 .help = "Total size of device or files",
352 },
353 {
354 .name = "filesize",
355 .type = FIO_OPT_STR_VAL,
356 .off1 = td_var_offset(file_size_low),
357 .off2 = td_var_offset(file_size_high),
358 .help = "Size of individual files",
359 },
360 {
361 .name = "bs",
d3aad8f2 362 .alias = "blocksize",
214e1eca
JA
363 .type = FIO_OPT_STR_VAL_INT,
364 .off1 = td_var_offset(bs[DDIR_READ]),
365 .off2 = td_var_offset(bs[DDIR_WRITE]),
366 .help = "Block size unit",
367 .def = "4k",
368 },
369 {
370 .name = "bsrange",
d3aad8f2 371 .alias = "blocksize_range",
214e1eca
JA
372 .type = FIO_OPT_RANGE,
373 .off1 = td_var_offset(min_bs[DDIR_READ]),
374 .off2 = td_var_offset(max_bs[DDIR_READ]),
375 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
376 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
377 .help = "Set block size range (in more detail than bs)",
378 },
379 {
380 .name = "bs_unaligned",
d3aad8f2 381 .alias = "blocksize_unaligned",
214e1eca
JA
382 .type = FIO_OPT_STR_SET,
383 .off1 = td_var_offset(bs_unaligned),
384 .help = "Don't sector align IO buffer sizes",
385 },
386 {
387 .name = "offset",
388 .type = FIO_OPT_STR_VAL,
389 .off1 = td_var_offset(start_offset),
390 .help = "Start IO from this offset",
391 .def = "0",
392 },
393 {
394 .name = "randrepeat",
395 .type = FIO_OPT_BOOL,
396 .off1 = td_var_offset(rand_repeatable),
397 .help = "Use repeatable random IO pattern",
398 .def = "1",
399 },
400 {
401 .name = "norandommap",
402 .type = FIO_OPT_STR_SET,
403 .off1 = td_var_offset(norandommap),
404 .help = "Accept potential duplicate random blocks",
405 },
406 {
407 .name = "nrfiles",
408 .type = FIO_OPT_INT,
409 .off1 = td_var_offset(nr_files),
410 .help = "Split job workload between this number of files",
411 .def = "1",
412 },
413 {
414 .name = "openfiles",
415 .type = FIO_OPT_INT,
416 .off1 = td_var_offset(open_files),
417 .help = "Number of files to keep open at the same time",
418 },
419 {
420 .name = "file_service_type",
421 .type = FIO_OPT_STR,
422 .cb = str_fst_cb,
423 .off1 = td_var_offset(file_service_type),
424 .help = "How to select which file to service next",
425 .def = "roundrobin",
426 .posval = {
427 { .ival = "random",
428 .oval = FIO_FSERVICE_RANDOM,
429 .help = "Choose a file at random",
430 },
431 { .ival = "roundrobin",
432 .oval = FIO_FSERVICE_RR,
433 .help = "Round robin select files",
434 },
435 },
436 },
437 {
438 .name = "fsync",
439 .type = FIO_OPT_INT,
440 .off1 = td_var_offset(fsync_blocks),
441 .help = "Issue fsync for writes every given number of blocks",
442 .def = "0",
443 },
444 {
445 .name = "direct",
446 .type = FIO_OPT_BOOL,
447 .off1 = td_var_offset(odirect),
448 .help = "Use O_DIRECT IO (negates buffered)",
449 .def = "0",
450 },
451 {
452 .name = "buffered",
453 .type = FIO_OPT_BOOL,
454 .off1 = td_var_offset(odirect),
455 .neg = 1,
456 .help = "Use buffered IO (negates direct)",
457 .def = "1",
458 },
459 {
460 .name = "overwrite",
461 .type = FIO_OPT_BOOL,
462 .off1 = td_var_offset(overwrite),
463 .help = "When writing, set whether to overwrite current data",
464 .def = "0",
465 },
466 {
467 .name = "loops",
468 .type = FIO_OPT_INT,
469 .off1 = td_var_offset(loops),
470 .help = "Number of times to run the job",
471 .def = "1",
472 },
473 {
474 .name = "numjobs",
475 .type = FIO_OPT_INT,
476 .off1 = td_var_offset(numjobs),
477 .help = "Duplicate this job this many times",
478 .def = "1",
479 },
480 {
481 .name = "startdelay",
482 .type = FIO_OPT_INT,
483 .off1 = td_var_offset(start_delay),
484 .help = "Only start job when this period has passed",
485 .def = "0",
486 },
487 {
488 .name = "runtime",
489 .alias = "timeout",
490 .type = FIO_OPT_STR_VAL_TIME,
491 .off1 = td_var_offset(timeout),
492 .help = "Stop workload when this amount of time has passed",
493 .def = "0",
494 },
cf4464ca
JA
495 {
496 .name = "time_based",
497 .type = FIO_OPT_STR_SET,
498 .off1 = td_var_offset(time_based),
499 .help = "Keep running until runtime/timeout is met",
500 },
214e1eca
JA
501 {
502 .name = "mem",
d3aad8f2 503 .alias = "iomem",
214e1eca
JA
504 .type = FIO_OPT_STR,
505 .cb = str_mem_cb,
506 .off1 = td_var_offset(mem_type),
507 .help = "Backing type for IO buffers",
508 .def = "malloc",
509 .posval = {
510 { .ival = "malloc",
511 .oval = MEM_MALLOC,
512 .help = "Use malloc(3) for IO buffers",
513 },
37c8cdfe
JA
514 { .ival = "shm",
515 .oval = MEM_SHM,
516 .help = "Use shared memory segments for IO buffers",
517 },
214e1eca
JA
518#ifdef FIO_HAVE_HUGETLB
519 { .ival = "shmhuge",
520 .oval = MEM_SHMHUGE,
521 .help = "Like shm, but use huge pages",
522 },
b370e46a 523#endif
37c8cdfe
JA
524 { .ival = "mmap",
525 .oval = MEM_MMAP,
526 .help = "Use mmap(2) (file or anon) for IO buffers",
527 },
214e1eca
JA
528#ifdef FIO_HAVE_HUGETLB
529 { .ival = "mmaphuge",
530 .oval = MEM_MMAPHUGE,
531 .help = "Like mmap, but use huge pages",
532 },
533#endif
534 },
535 },
536 {
537 .name = "verify",
538 .type = FIO_OPT_STR,
539 .off1 = td_var_offset(verify),
540 .help = "Verify data written",
541 .def = "0",
542 .posval = {
543 { .ival = "0",
544 .oval = VERIFY_NONE,
545 .help = "Don't do IO verification",
546 },
547 { .ival = "crc32",
548 .oval = VERIFY_CRC32,
549 .help = "Use crc32 checksums for verification",
550 },
551 { .ival = "md5",
552 .oval = VERIFY_MD5,
553 .help = "Use md5 checksums for verification",
554 },
36690c9b
JA
555 {
556 .ival = "null",
557 .oval = VERIFY_NULL,
558 .help = "Pretend to verify",
559 },
214e1eca
JA
560 },
561 },
160b966d
JA
562 {
563 .name = "verifysort",
564 .type = FIO_OPT_BOOL,
565 .off1 = td_var_offset(verifysort),
566 .help = "Sort written verify blocks for read back",
567 .def = "1",
568 },
214e1eca
JA
569 {
570 .name = "write_iolog",
571 .type = FIO_OPT_STR_STORE,
572 .off1 = td_var_offset(write_iolog_file),
573 .help = "Store IO pattern to file",
574 },
575 {
576 .name = "read_iolog",
577 .type = FIO_OPT_STR_STORE,
578 .off1 = td_var_offset(read_iolog_file),
579 .help = "Playback IO pattern from file",
580 },
581 {
582 .name = "exec_prerun",
583 .type = FIO_OPT_STR_STORE,
584 .off1 = td_var_offset(exec_prerun),
585 .help = "Execute this file prior to running job",
586 },
587 {
588 .name = "exec_postrun",
589 .type = FIO_OPT_STR_STORE,
590 .off1 = td_var_offset(exec_postrun),
591 .help = "Execute this file after running job",
592 },
593#ifdef FIO_HAVE_IOSCHED_SWITCH
594 {
595 .name = "ioscheduler",
596 .type = FIO_OPT_STR_STORE,
597 .off1 = td_var_offset(ioscheduler),
598 .help = "Use this IO scheduler on the backing device",
599 },
600#endif
601 {
602 .name = "zonesize",
603 .type = FIO_OPT_STR_VAL,
604 .off1 = td_var_offset(zone_size),
605 .help = "Give size of an IO zone",
606 .def = "0",
607 },
608 {
609 .name = "zoneskip",
610 .type = FIO_OPT_STR_VAL,
611 .off1 = td_var_offset(zone_skip),
612 .help = "Space between IO zones",
613 .def = "0",
614 },
615 {
616 .name = "lockmem",
617 .type = FIO_OPT_STR_VAL,
618 .cb = str_lockmem_cb,
619 .help = "Lock down this amount of memory",
620 .def = "0",
621 },
622 {
623 .name = "rwmixcycle",
624 .type = FIO_OPT_INT,
625 .off1 = td_var_offset(rwmixcycle),
626 .help = "Cycle period for mixed read/write workloads (msec)",
627 .def = "500",
628 },
629 {
630 .name = "rwmixread",
631 .type = FIO_OPT_INT,
e47f799f 632 .off1 = td_var_offset(rwmix[DDIR_READ]),
214e1eca
JA
633 .maxval = 100,
634 .help = "Percentage of mixed workload that is reads",
635 .def = "50",
636 },
637 {
638 .name = "rwmixwrite",
639 .type = FIO_OPT_INT,
e47f799f 640 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
214e1eca
JA
641 .maxval = 100,
642 .help = "Percentage of mixed workload that is writes",
643 .def = "50",
644 },
645 {
646 .name = "nice",
647 .type = FIO_OPT_INT,
648 .off1 = td_var_offset(nice),
649 .help = "Set job CPU nice value",
650 .minval = -19,
651 .maxval = 20,
652 .def = "0",
653 },
654#ifdef FIO_HAVE_IOPRIO
655 {
656 .name = "prio",
657 .type = FIO_OPT_INT,
658 .cb = str_prio_cb,
659 .help = "Set job IO priority value",
660 .minval = 0,
661 .maxval = 7,
662 },
663 {
664 .name = "prioclass",
665 .type = FIO_OPT_INT,
666 .cb = str_prioclass_cb,
667 .help = "Set job IO priority class",
668 .minval = 0,
669 .maxval = 3,
670 },
671#endif
672 {
673 .name = "thinktime",
674 .type = FIO_OPT_INT,
675 .off1 = td_var_offset(thinktime),
676 .help = "Idle time between IO buffers (usec)",
677 .def = "0",
678 },
679 {
680 .name = "thinktime_spin",
681 .type = FIO_OPT_INT,
682 .off1 = td_var_offset(thinktime_spin),
683 .help = "Start think time by spinning this amount (usec)",
684 .def = "0",
685 },
686 {
687 .name = "thinktime_blocks",
688 .type = FIO_OPT_INT,
689 .off1 = td_var_offset(thinktime_blocks),
690 .help = "IO buffer period between 'thinktime'",
691 .def = "1",
692 },
693 {
694 .name = "rate",
695 .type = FIO_OPT_INT,
696 .off1 = td_var_offset(rate),
697 .help = "Set bandwidth rate",
698 },
699 {
700 .name = "ratemin",
701 .type = FIO_OPT_INT,
702 .off1 = td_var_offset(ratemin),
4e991c23
JA
703 .help = "Job must meet this rate or it will be shutdown",
704 },
705 {
706 .name = "rate_iops",
707 .type = FIO_OPT_INT,
708 .off1 = td_var_offset(rate_iops),
709 .help = "Limit IO used to this number of IO operations/sec",
710 },
711 {
712 .name = "rate_iops_min",
713 .type = FIO_OPT_INT,
714 .off1 = td_var_offset(rate_iops_min),
715 .help = "Job must meet this rate or it will be shutdown",
214e1eca
JA
716 },
717 {
718 .name = "ratecycle",
719 .type = FIO_OPT_INT,
720 .off1 = td_var_offset(ratecycle),
721 .help = "Window average for rate limits (msec)",
722 .def = "1000",
723 },
724 {
725 .name = "invalidate",
726 .type = FIO_OPT_BOOL,
727 .off1 = td_var_offset(invalidate_cache),
728 .help = "Invalidate buffer/page cache prior to running job",
729 .def = "1",
730 },
731 {
732 .name = "sync",
733 .type = FIO_OPT_BOOL,
734 .off1 = td_var_offset(sync_io),
735 .help = "Use O_SYNC for buffered writes",
736 .def = "0",
737 },
738 {
739 .name = "bwavgtime",
740 .type = FIO_OPT_INT,
741 .off1 = td_var_offset(bw_avg_time),
742 .help = "Time window over which to calculate bandwidth (msec)",
743 .def = "500",
744 },
745 {
746 .name = "create_serialize",
747 .type = FIO_OPT_BOOL,
748 .off1 = td_var_offset(create_serialize),
749 .help = "Serialize creating of job files",
750 .def = "1",
751 },
752 {
753 .name = "create_fsync",
754 .type = FIO_OPT_BOOL,
755 .off1 = td_var_offset(create_fsync),
756 .help = "Fsync file after creation",
757 .def = "1",
758 },
759 {
760 .name = "cpuload",
761 .type = FIO_OPT_INT,
762 .off1 = td_var_offset(cpuload),
763 .help = "Use this percentage of CPU",
764 },
765 {
766 .name = "cpuchunks",
767 .type = FIO_OPT_INT,
768 .off1 = td_var_offset(cpucycle),
769 .help = "Length of the CPU burn cycles (usecs)",
770 .def = "50000",
771 },
772#ifdef FIO_HAVE_CPU_AFFINITY
773 {
774 .name = "cpumask",
775 .type = FIO_OPT_INT,
776 .cb = str_cpumask_cb,
777 .help = "CPU affinity mask",
778 },
779#endif
780 {
781 .name = "end_fsync",
782 .type = FIO_OPT_BOOL,
783 .off1 = td_var_offset(end_fsync),
784 .help = "Include fsync at the end of job",
785 .def = "0",
786 },
787 {
788 .name = "fsync_on_close",
789 .type = FIO_OPT_BOOL,
790 .off1 = td_var_offset(fsync_on_close),
791 .help = "fsync files on close",
792 .def = "0",
793 },
794 {
795 .name = "unlink",
796 .type = FIO_OPT_BOOL,
797 .off1 = td_var_offset(unlink),
798 .help = "Unlink created files after job has completed",
799 .def = "0",
800 },
801 {
802 .name = "exitall",
803 .type = FIO_OPT_STR_SET,
804 .cb = str_exitall_cb,
805 .help = "Terminate all jobs when one exits",
806 },
807 {
808 .name = "stonewall",
809 .type = FIO_OPT_STR_SET,
810 .off1 = td_var_offset(stonewall),
811 .help = "Insert a hard barrier between this job and previous",
812 },
b3d62a75
JA
813 {
814 .name = "new_group",
815 .type = FIO_OPT_STR_SET,
816 .off1 = td_var_offset(new_group),
817 .help = "Mark the start of a new group (for reporting)",
818 },
214e1eca
JA
819 {
820 .name = "thread",
821 .type = FIO_OPT_STR_SET,
822 .off1 = td_var_offset(use_thread),
823 .help = "Use threads instead of forks",
824 },
825 {
826 .name = "write_bw_log",
827 .type = FIO_OPT_STR_SET,
828 .off1 = td_var_offset(write_bw_log),
829 .help = "Write log of bandwidth during run",
830 },
831 {
832 .name = "write_lat_log",
833 .type = FIO_OPT_STR_SET,
834 .off1 = td_var_offset(write_lat_log),
835 .help = "Write log of latency during run",
836 },
837 {
838 .name = "hugepage-size",
839 .type = FIO_OPT_STR_VAL,
840 .off1 = td_var_offset(hugepage_size),
841 .help = "When using hugepages, specify size of each page",
842 .def = __stringify(FIO_HUGE_PAGE),
843 },
844 {
845 .name = "group_reporting",
846 .type = FIO_OPT_STR_SET,
847 .off1 = td_var_offset(group_reporting),
848 .help = "Do reporting on a per-group basis",
849 },
e9459e5a
JA
850 {
851 .name = "zero_buffers",
852 .type = FIO_OPT_STR_SET,
853 .off1 = td_var_offset(zero_buffers),
854 .help = "Init IO buffers to all zeroes",
855 },
0a839f30
JA
856#ifdef FIO_HAVE_DISK_UTIL
857 {
858 .name = "disk_util",
859 .type = FIO_OPT_BOOL,
860 .off1 = td_var_offset(do_disk_util),
861 .help = "Log disk utilization stats",
862 .def = "1",
863 },
864#endif
214e1eca
JA
865 {
866 .name = NULL,
867 },
868};
869
870void fio_options_dup_and_init(struct option *long_options)
871{
872 struct fio_option *o;
873 unsigned int i;
874
875 options_init(options);
876
877 i = 0;
878 while (long_options[i].name)
879 i++;
880
881 o = &options[0];
882 while (o->name) {
883 long_options[i].name = o->name;
884 long_options[i].val = FIO_GETOPT_JOB;
885 if (o->type == FIO_OPT_STR_SET)
886 long_options[i].has_arg = no_argument;
887 else
888 long_options[i].has_arg = required_argument;
889
890 i++;
891 o++;
892 assert(i < FIO_NR_OPTIONS);
893 }
894}
895
896int fio_option_parse(struct thread_data *td, const char *opt)
897{
898 return parse_option(opt, options, td);
899}
900
901int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
902{
903 return parse_cmd_option(opt, val, options, td);
904}
905
906void fio_fill_default_options(struct thread_data *td)
907{
908 fill_default_options(td, options);
909}
910
911int fio_show_option_help(const char *opt)
912{
913 return show_cmd_help(options, opt);
914}
d23bb327
JA
915
916static void __options_mem(struct thread_data *td, int alloc)
917{
918 struct thread_options *o = &td->o;
919 struct fio_option *opt;
920 char **ptr;
921 int i;
922
923 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
924 if (opt->type != FIO_OPT_STR_STORE)
925 continue;
926
927 ptr = (void *) o + opt->off1;
928 if (*ptr) {
929 if (alloc)
930 *ptr = strdup(*ptr);
931 else {
932 free(*ptr);
933 *ptr = NULL;
934 }
935 }
936 }
937}
938
939/*
940 * dupe FIO_OPT_STR_STORE options
941 */
942void options_mem_dupe(struct thread_data *td)
943{
944 __options_mem(td, 1);
945}
946
22d66213 947void options_mem_free(struct thread_data fio_unused *td)
d23bb327 948{
22d66213 949#if 0
d23bb327 950 __options_mem(td, 0);
22d66213 951#endif
d23bb327 952}