blob: 81ddd2390ca5459b85714c74d014716109e1005d [file] [log] [blame]
Jens Axboe214e1ec2007-03-15 10:48:13 +01001#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"
Jens Axboe90059d62007-07-30 09:33:12 +020011#include "fls.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010012
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010013#define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
Jens Axboe214e1ec2007-03-15 10:48:13 +010014
15/*
16 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
17 */
18static char *get_opt_postfix(const char *str)
19{
20 char *p = strstr(str, ":");
21
22 if (!p)
23 return NULL;
24
25 p++;
26 strip_blank_front(&p);
27 strip_blank_end(p);
28 return strdup(p);
29}
30
Jens Axboe211097b2007-03-22 18:56:45 +010031static int str_rw_cb(void *data, const char *str)
32{
33 struct thread_data *td = data;
34 char *nr = get_opt_postfix(str);
35
Jens Axboefafdba32007-03-26 10:09:12 +020036 td->o.ddir_nr = 1;
Jens Axboe211097b2007-03-22 18:56:45 +010037 if (nr)
38 td->o.ddir_nr = atoi(nr);
39
Jens Axboe211097b2007-03-22 18:56:45 +010040 return 0;
41}
42
Jens Axboe214e1ec2007-03-15 10:48:13 +010043static int str_mem_cb(void *data, const char *mem)
44{
45 struct thread_data *td = data;
46
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010047 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
Jens Axboe214e1ec2007-03-15 10:48:13 +010048 td->mmapfile = get_opt_postfix(mem);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010049 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboe214e1ec2007-03-15 10:48:13 +010050 log_err("fio: mmaphuge:/path/to/file\n");
51 return 1;
52 }
53 }
54
55 return 0;
56}
57
58static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
59{
60 mlock_size = *val;
61 return 0;
62}
63
64#ifdef FIO_HAVE_IOPRIO
65static int str_prioclass_cb(void *data, unsigned int *val)
66{
67 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +020068 unsigned short mask;
69
70 /*
71 * mask off old class bits, str_prio_cb() may have set a default class
72 */
73 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
74 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +010075
76 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
77 return 0;
78}
79
80static int str_prio_cb(void *data, unsigned int *val)
81{
82 struct thread_data *td = data;
83
84 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +020085
86 /*
87 * If no class is set, assume BE
88 */
89 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
90 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
91
Jens Axboe214e1ec2007-03-15 10:48:13 +010092 return 0;
93}
94#endif
95
96static int str_exitall_cb(void)
97{
98 exitall_on_terminate = 1;
99 return 0;
100}
101
Jens Axboe214e1ec2007-03-15 10:48:13 +0100102#ifdef FIO_HAVE_CPU_AFFINITY
Jens Axboe214e1ec2007-03-15 10:48:13 +0100103static int str_cpumask_cb(void *data, unsigned int *val)
104{
105 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200106 unsigned int i;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100107
Jens Axboed2e268b2007-06-15 10:33:49 +0200108 CPU_ZERO(&td->o.cpumask);
109
110 for (i = 0; i < sizeof(int) * 8; i++)
111 if ((1 << i) & *val)
112 CPU_SET(*val, &td->o.cpumask);
113
Jens Axboe375b2692007-05-22 09:13:02 +0200114 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100115 return 0;
116}
117
Jens Axboed2e268b2007-06-15 10:33:49 +0200118static int str_cpus_allowed_cb(void *data, const char *input)
119{
120 struct thread_data *td = data;
121 char *cpu, *str, *p;
122
123 CPU_ZERO(&td->o.cpumask);
124
125 p = str = strdup(input);
126
127 strip_blank_front(&str);
128 strip_blank_end(str);
129
130 while ((cpu = strsep(&str, ",")) != NULL) {
131 if (!strlen(cpu))
132 break;
133 CPU_SET(atoi(cpu), &td->o.cpumask);
134 }
135
136 free(p);
137 td->o.cpumask_set = 1;
138 exit(0);
139 return 0;
140}
141#endif
142
Jens Axboe214e1ec2007-03-15 10:48:13 +0100143static int str_fst_cb(void *data, const char *str)
144{
145 struct thread_data *td = data;
146 char *nr = get_opt_postfix(str);
147
148 td->file_service_nr = 1;
149 if (nr)
150 td->file_service_nr = atoi(nr);
151
152 return 0;
153}
154
155static int str_filename_cb(void *data, const char *input)
156{
157 struct thread_data *td = data;
158 char *fname, *str, *p;
159
160 p = str = strdup(input);
161
162 strip_blank_front(&str);
163 strip_blank_end(str);
164
165 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100166 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100167
168 while ((fname = strsep(&str, ":")) != NULL) {
169 if (!strlen(fname))
170 break;
171 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100172 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100173 }
174
175 free(p);
176 return 0;
177}
178
179static int str_directory_cb(void *data, const char fio_unused *str)
180{
181 struct thread_data *td = data;
182 struct stat sb;
183
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100184 if (lstat(td->o.directory, &sb) < 0) {
185 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100186 td_verror(td, errno, "lstat");
187 return 1;
188 }
189 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100190 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100191 return 1;
192 }
193
194 return 0;
195}
196
197static int str_opendir_cb(void *data, const char fio_unused *str)
198{
199 struct thread_data *td = data;
200
201 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100202 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100203
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100204 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100205}
206
Jens Axboea59e1702007-07-30 08:53:27 +0200207static int str_verify_offset_cb(void *data, unsigned int *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200208{
209 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200210
Shawn Lewis546a9142007-07-28 21:11:37 +0200211 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200212 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200213 return 1;
214 }
Jens Axboea59e1702007-07-30 08:53:27 +0200215
216 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200217 return 0;
218}
219
Jens Axboe90059d62007-07-30 09:33:12 +0200220static int str_verify_pattern_cb(void *data, unsigned int *off)
221{
222 struct thread_data *td = data;
223 unsigned int msb;
224
225 msb = fls(*off);
226 if (msb <= 8)
227 td->o.verify_pattern_bytes = 1;
228 else if (msb <= 16)
229 td->o.verify_pattern_bytes = 2;
230 else if (msb <= 24)
231 td->o.verify_pattern_bytes = 3;
232 else
233 td->o.verify_pattern_bytes = 4;
234
235 td->o.verify_pattern = *off;
236 return 0;
237}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100238
239#define __stringify_1(x) #x
240#define __stringify(x) __stringify_1(x)
241
242/*
243 * Map of job/command line options
244 */
245static struct fio_option options[] = {
246 {
247 .name = "description",
248 .type = FIO_OPT_STR_STORE,
249 .off1 = td_var_offset(description),
250 .help = "Text job description",
251 },
252 {
253 .name = "name",
254 .type = FIO_OPT_STR_STORE,
255 .off1 = td_var_offset(name),
256 .help = "Name of this job",
257 },
258 {
259 .name = "directory",
260 .type = FIO_OPT_STR_STORE,
261 .off1 = td_var_offset(directory),
262 .cb = str_directory_cb,
263 .help = "Directory to store files in",
264 },
265 {
266 .name = "filename",
267 .type = FIO_OPT_STR_STORE,
268 .off1 = td_var_offset(filename),
269 .cb = str_filename_cb,
270 .help = "File(s) to use for the workload",
271 },
272 {
273 .name = "opendir",
274 .type = FIO_OPT_STR_STORE,
275 .off1 = td_var_offset(opendir),
276 .cb = str_opendir_cb,
277 .help = "Recursively add files from this directory and down",
278 },
279 {
280 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100281 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100282 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +0100283 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100284 .off1 = td_var_offset(td_ddir),
285 .help = "IO direction",
286 .def = "read",
287 .posval = {
288 { .ival = "read",
289 .oval = TD_DDIR_READ,
290 .help = "Sequential read",
291 },
292 { .ival = "write",
293 .oval = TD_DDIR_WRITE,
294 .help = "Sequential write",
295 },
296 { .ival = "randread",
297 .oval = TD_DDIR_RANDREAD,
298 .help = "Random read",
299 },
300 { .ival = "randwrite",
301 .oval = TD_DDIR_RANDWRITE,
302 .help = "Random write",
303 },
304 { .ival = "rw",
305 .oval = TD_DDIR_RW,
306 .help = "Sequential read and write mix",
307 },
308 { .ival = "randrw",
309 .oval = TD_DDIR_RANDRW,
310 .help = "Random read and write mix"
311 },
312 },
313 },
314 {
315 .name = "ioengine",
316 .type = FIO_OPT_STR_STORE,
317 .off1 = td_var_offset(ioengine),
318 .help = "IO engine to use",
319 .def = "sync",
320 .posval = {
321 { .ival = "sync",
322 .help = "Use read/write",
323 },
324#ifdef FIO_HAVE_LIBAIO
325 { .ival = "libaio",
326 .help = "Linux native asynchronous IO",
327 },
328#endif
329#ifdef FIO_HAVE_POSIXAIO
330 { .ival = "posixaio",
331 .help = "POSIX asynchronous IO",
332 },
333#endif
334 { .ival = "mmap",
335 .help = "Memory mapped IO",
336 },
337#ifdef FIO_HAVE_SPLICE
338 { .ival = "splice",
339 .help = "splice/vmsplice based IO",
340 },
Jens Axboe9cce02e2007-06-22 15:42:21 +0200341 { .ival = "netsplice",
342 .help = "splice/vmsplice to/from the network",
343 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100344#endif
345#ifdef FIO_HAVE_SGIO
346 { .ival = "sg",
347 .help = "SCSI generic v3 IO",
348 },
349#endif
350 { .ival = "null",
351 .help = "Testing engine (no data transfer)",
352 },
353 { .ival = "net",
354 .help = "Network IO",
355 },
356#ifdef FIO_HAVE_SYSLET
357 { .ival = "syslet-rw",
358 .help = "syslet enabled async pread/pwrite IO",
359 },
360#endif
361 { .ival = "cpuio",
362 .help = "CPU cycler burner engine",
363 },
Jens Axboeb8c82a42007-03-21 08:48:26 +0100364#ifdef FIO_HAVE_GUASI
365 { .ival = "guasi",
366 .help = "GUASI IO engine",
367 },
368#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100369 { .ival = "external",
370 .help = "Load external engine (append name)",
371 },
372 },
373 },
374 {
375 .name = "iodepth",
376 .type = FIO_OPT_INT,
377 .off1 = td_var_offset(iodepth),
378 .help = "Amount of IO buffers to keep in flight",
379 .def = "1",
380 },
381 {
382 .name = "iodepth_batch",
383 .type = FIO_OPT_INT,
384 .off1 = td_var_offset(iodepth_batch),
385 .help = "Number of IO to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +0200386 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100387 },
388 {
389 .name = "iodepth_low",
390 .type = FIO_OPT_INT,
391 .off1 = td_var_offset(iodepth_low),
392 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +0200393 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100394 },
395 {
396 .name = "size",
397 .type = FIO_OPT_STR_VAL,
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100398 .off1 = td_var_offset(size),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200399 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100400 .help = "Total size of device or files",
401 },
402 {
403 .name = "filesize",
404 .type = FIO_OPT_STR_VAL,
405 .off1 = td_var_offset(file_size_low),
406 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200407 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100408 .help = "Size of individual files",
409 },
410 {
Jens Axboe67a10002007-07-31 23:12:16 +0200411 .name = "offset",
412 .alias = "fileoffset",
413 .type = FIO_OPT_STR_VAL,
414 .off1 = td_var_offset(start_offset),
415 .help = "Start IO from this offset",
416 .def = "0",
417 },
418 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100419 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100420 .alias = "blocksize",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100421 .type = FIO_OPT_STR_VAL_INT,
422 .off1 = td_var_offset(bs[DDIR_READ]),
423 .off2 = td_var_offset(bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200424 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100425 .help = "Block size unit",
426 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +0200427 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100428 },
429 {
430 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100431 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100432 .type = FIO_OPT_RANGE,
433 .off1 = td_var_offset(min_bs[DDIR_READ]),
434 .off2 = td_var_offset(max_bs[DDIR_READ]),
435 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
436 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200437 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100438 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +0200439 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100440 },
441 {
442 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100443 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100444 .type = FIO_OPT_STR_SET,
445 .off1 = td_var_offset(bs_unaligned),
446 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +0200447 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100448 },
449 {
450 .name = "randrepeat",
451 .type = FIO_OPT_BOOL,
452 .off1 = td_var_offset(rand_repeatable),
453 .help = "Use repeatable random IO pattern",
454 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +0200455 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100456 },
457 {
458 .name = "norandommap",
459 .type = FIO_OPT_STR_SET,
460 .off1 = td_var_offset(norandommap),
461 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +0200462 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100463 },
464 {
465 .name = "nrfiles",
466 .type = FIO_OPT_INT,
467 .off1 = td_var_offset(nr_files),
468 .help = "Split job workload between this number of files",
469 .def = "1",
470 },
471 {
472 .name = "openfiles",
473 .type = FIO_OPT_INT,
474 .off1 = td_var_offset(open_files),
475 .help = "Number of files to keep open at the same time",
476 },
477 {
478 .name = "file_service_type",
479 .type = FIO_OPT_STR,
480 .cb = str_fst_cb,
481 .off1 = td_var_offset(file_service_type),
482 .help = "How to select which file to service next",
483 .def = "roundrobin",
484 .posval = {
485 { .ival = "random",
486 .oval = FIO_FSERVICE_RANDOM,
487 .help = "Choose a file at random",
488 },
489 { .ival = "roundrobin",
490 .oval = FIO_FSERVICE_RR,
491 .help = "Round robin select files",
492 },
493 },
Jens Axboe67a10002007-07-31 23:12:16 +0200494 .parent = "nrfiles",
495 },
496 {
497 .name = "fadvise_hint",
498 .type = FIO_OPT_BOOL,
499 .off1 = td_var_offset(fadvise_hint),
500 .help = "Use fadvise() to advise the kernel on IO pattern",
501 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100502 },
503 {
504 .name = "fsync",
505 .type = FIO_OPT_INT,
506 .off1 = td_var_offset(fsync_blocks),
507 .help = "Issue fsync for writes every given number of blocks",
508 .def = "0",
509 },
510 {
511 .name = "direct",
512 .type = FIO_OPT_BOOL,
513 .off1 = td_var_offset(odirect),
514 .help = "Use O_DIRECT IO (negates buffered)",
515 .def = "0",
516 },
517 {
518 .name = "buffered",
519 .type = FIO_OPT_BOOL,
520 .off1 = td_var_offset(odirect),
521 .neg = 1,
522 .help = "Use buffered IO (negates direct)",
523 .def = "1",
524 },
525 {
526 .name = "overwrite",
527 .type = FIO_OPT_BOOL,
528 .off1 = td_var_offset(overwrite),
529 .help = "When writing, set whether to overwrite current data",
530 .def = "0",
531 },
532 {
533 .name = "loops",
534 .type = FIO_OPT_INT,
535 .off1 = td_var_offset(loops),
536 .help = "Number of times to run the job",
537 .def = "1",
538 },
539 {
540 .name = "numjobs",
541 .type = FIO_OPT_INT,
542 .off1 = td_var_offset(numjobs),
543 .help = "Duplicate this job this many times",
544 .def = "1",
545 },
546 {
547 .name = "startdelay",
548 .type = FIO_OPT_INT,
549 .off1 = td_var_offset(start_delay),
550 .help = "Only start job when this period has passed",
551 .def = "0",
552 },
553 {
554 .name = "runtime",
555 .alias = "timeout",
556 .type = FIO_OPT_STR_VAL_TIME,
557 .off1 = td_var_offset(timeout),
558 .help = "Stop workload when this amount of time has passed",
559 .def = "0",
560 },
561 {
Jens Axboecf4464c2007-04-17 20:14:42 +0200562 .name = "time_based",
563 .type = FIO_OPT_STR_SET,
564 .off1 = td_var_offset(time_based),
565 .help = "Keep running until runtime/timeout is met",
566 },
567 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100568 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100569 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100570 .type = FIO_OPT_STR,
571 .cb = str_mem_cb,
572 .off1 = td_var_offset(mem_type),
573 .help = "Backing type for IO buffers",
574 .def = "malloc",
575 .posval = {
576 { .ival = "malloc",
577 .oval = MEM_MALLOC,
578 .help = "Use malloc(3) for IO buffers",
579 },
Jens Axboeb370e462007-03-19 10:51:49 +0100580 { .ival = "shm",
581 .oval = MEM_SHM,
582 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100583 },
584#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +0100585 { .ival = "shmhuge",
586 .oval = MEM_SHMHUGE,
587 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100588 },
589#endif
Jens Axboeb370e462007-03-19 10:51:49 +0100590 { .ival = "mmap",
591 .oval = MEM_MMAP,
592 .help = "Use mmap(2) (file or anon) for IO buffers",
593 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +0100594#ifdef FIO_HAVE_HUGETLB
595 { .ival = "mmaphuge",
596 .oval = MEM_MMAPHUGE,
597 .help = "Like mmap, but use huge pages",
598 },
599#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100600 },
601 },
602 {
603 .name = "verify",
604 .type = FIO_OPT_STR,
605 .off1 = td_var_offset(verify),
606 .help = "Verify data written",
607 .def = "0",
608 .posval = {
609 { .ival = "0",
610 .oval = VERIFY_NONE,
611 .help = "Don't do IO verification",
612 },
Jens Axboefcca4b52007-07-27 15:42:00 +0200613 { .ival = "md5",
614 .oval = VERIFY_MD5,
615 .help = "Use md5 checksums for verification",
616 },
Jens Axboed77a7af2007-07-27 15:35:06 +0200617 { .ival = "crc64",
618 .oval = VERIFY_CRC64,
619 .help = "Use crc64 checksums for verification",
620 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100621 { .ival = "crc32",
622 .oval = VERIFY_CRC32,
623 .help = "Use crc32 checksums for verification",
624 },
Jens Axboe969f7ed2007-07-27 09:07:17 +0200625 { .ival = "crc16",
626 .oval = VERIFY_CRC16,
627 .help = "Use crc16 checksums for verification",
628 },
Jens Axboe1e154bd2007-07-27 09:52:40 +0200629 { .ival = "crc7",
630 .oval = VERIFY_CRC7,
631 .help = "Use crc7 checksums for verification",
632 },
Jens Axboecd14cc12007-07-30 10:59:33 +0200633 { .ival = "sha256",
634 .oval = VERIFY_SHA256,
635 .help = "Use sha256 checksums for verification",
636 },
637 { .ival = "sha512",
638 .oval = VERIFY_SHA512,
639 .help = "Use sha512 checksums for verification",
640 },
Jens Axboe36690c92007-03-26 10:23:34 +0200641 {
642 .ival = "null",
643 .oval = VERIFY_NULL,
644 .help = "Pretend to verify",
645 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100646 },
647 },
648 {
Jens Axboe160b9662007-03-27 10:59:49 +0200649 .name = "verifysort",
650 .type = FIO_OPT_BOOL,
651 .off1 = td_var_offset(verifysort),
652 .help = "Sort written verify blocks for read back",
653 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +0200654 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +0200655 },
656 {
Jens Axboea59e1702007-07-30 08:53:27 +0200657 .name = "verify_interval",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +0200658 .type = FIO_OPT_STR_VAL_INT,
Jens Axboea59e1702007-07-30 08:53:27 +0200659 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +0200660 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +0200661 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +0200662 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +0200663 },
664 {
Jens Axboea59e1702007-07-30 08:53:27 +0200665 .name = "verify_offset",
Shawn Lewis546a9142007-07-28 21:11:37 +0200666 .type = FIO_OPT_STR_VAL_INT,
Jens Axboea59e1702007-07-30 08:53:27 +0200667 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +0200668 .def = "0",
Jens Axboea59e1702007-07-30 08:53:27 +0200669 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +0200670 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +0200671 },
672 {
Jens Axboe90059d62007-07-30 09:33:12 +0200673 .name = "verify_pattern",
674 .type = FIO_OPT_INT,
675 .cb = str_verify_pattern_cb,
Jens Axboe90059d62007-07-30 09:33:12 +0200676 .help = "Fill pattern for IO buffers",
Jens Axboeafdf9352007-07-31 16:14:34 +0200677 .parent = "verify",
Jens Axboe90059d62007-07-30 09:33:12 +0200678 },
679 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100680 .name = "write_iolog",
681 .type = FIO_OPT_STR_STORE,
682 .off1 = td_var_offset(write_iolog_file),
683 .help = "Store IO pattern to file",
684 },
685 {
686 .name = "read_iolog",
687 .type = FIO_OPT_STR_STORE,
688 .off1 = td_var_offset(read_iolog_file),
689 .help = "Playback IO pattern from file",
690 },
691 {
692 .name = "exec_prerun",
693 .type = FIO_OPT_STR_STORE,
694 .off1 = td_var_offset(exec_prerun),
695 .help = "Execute this file prior to running job",
696 },
697 {
698 .name = "exec_postrun",
699 .type = FIO_OPT_STR_STORE,
700 .off1 = td_var_offset(exec_postrun),
701 .help = "Execute this file after running job",
702 },
703#ifdef FIO_HAVE_IOSCHED_SWITCH
704 {
705 .name = "ioscheduler",
706 .type = FIO_OPT_STR_STORE,
707 .off1 = td_var_offset(ioscheduler),
708 .help = "Use this IO scheduler on the backing device",
709 },
710#endif
711 {
712 .name = "zonesize",
713 .type = FIO_OPT_STR_VAL,
714 .off1 = td_var_offset(zone_size),
715 .help = "Give size of an IO zone",
716 .def = "0",
717 },
718 {
719 .name = "zoneskip",
720 .type = FIO_OPT_STR_VAL,
721 .off1 = td_var_offset(zone_skip),
722 .help = "Space between IO zones",
723 .def = "0",
724 },
725 {
726 .name = "lockmem",
727 .type = FIO_OPT_STR_VAL,
728 .cb = str_lockmem_cb,
729 .help = "Lock down this amount of memory",
730 .def = "0",
731 },
732 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100733 .name = "rwmixread",
734 .type = FIO_OPT_INT,
Jens Axboee47f7992007-03-21 14:05:39 +0100735 .off1 = td_var_offset(rwmix[DDIR_READ]),
Jens Axboe214e1ec2007-03-15 10:48:13 +0100736 .maxval = 100,
737 .help = "Percentage of mixed workload that is reads",
738 .def = "50",
739 },
740 {
741 .name = "rwmixwrite",
742 .type = FIO_OPT_INT,
Jens Axboee47f7992007-03-21 14:05:39 +0100743 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
Jens Axboe214e1ec2007-03-15 10:48:13 +0100744 .maxval = 100,
745 .help = "Percentage of mixed workload that is writes",
746 .def = "50",
747 },
748 {
Jens Axboeafdf9352007-07-31 16:14:34 +0200749 .name = "rwmixcycle",
750 .type = FIO_OPT_INT,
751 .off1 = td_var_offset(rwmixcycle),
752 .help = "Cycle period for mixed read/write workloads (msec)",
753 .def = "500",
754 .parent = "rwmixread",
755 },
756 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100757 .name = "nice",
758 .type = FIO_OPT_INT,
759 .off1 = td_var_offset(nice),
760 .help = "Set job CPU nice value",
761 .minval = -19,
762 .maxval = 20,
763 .def = "0",
764 },
765#ifdef FIO_HAVE_IOPRIO
766 {
767 .name = "prio",
768 .type = FIO_OPT_INT,
769 .cb = str_prio_cb,
770 .help = "Set job IO priority value",
771 .minval = 0,
772 .maxval = 7,
773 },
774 {
775 .name = "prioclass",
776 .type = FIO_OPT_INT,
777 .cb = str_prioclass_cb,
778 .help = "Set job IO priority class",
779 .minval = 0,
780 .maxval = 3,
781 },
782#endif
783 {
784 .name = "thinktime",
785 .type = FIO_OPT_INT,
786 .off1 = td_var_offset(thinktime),
787 .help = "Idle time between IO buffers (usec)",
788 .def = "0",
789 },
790 {
791 .name = "thinktime_spin",
792 .type = FIO_OPT_INT,
793 .off1 = td_var_offset(thinktime_spin),
794 .help = "Start think time by spinning this amount (usec)",
795 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +0200796 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100797 },
798 {
799 .name = "thinktime_blocks",
800 .type = FIO_OPT_INT,
801 .off1 = td_var_offset(thinktime_blocks),
802 .help = "IO buffer period between 'thinktime'",
803 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +0200804 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100805 },
806 {
807 .name = "rate",
808 .type = FIO_OPT_INT,
809 .off1 = td_var_offset(rate),
810 .help = "Set bandwidth rate",
811 },
812 {
813 .name = "ratemin",
814 .type = FIO_OPT_INT,
815 .off1 = td_var_offset(ratemin),
Jens Axboe4e991c22007-03-15 11:41:11 +0100816 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +0200817 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +0100818 },
819 {
820 .name = "rate_iops",
821 .type = FIO_OPT_INT,
822 .off1 = td_var_offset(rate_iops),
823 .help = "Limit IO used to this number of IO operations/sec",
824 },
825 {
826 .name = "rate_iops_min",
827 .type = FIO_OPT_INT,
828 .off1 = td_var_offset(rate_iops_min),
829 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +0200830 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100831 },
832 {
833 .name = "ratecycle",
834 .type = FIO_OPT_INT,
835 .off1 = td_var_offset(ratecycle),
836 .help = "Window average for rate limits (msec)",
837 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +0200838 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100839 },
840 {
841 .name = "invalidate",
842 .type = FIO_OPT_BOOL,
843 .off1 = td_var_offset(invalidate_cache),
844 .help = "Invalidate buffer/page cache prior to running job",
845 .def = "1",
846 },
847 {
848 .name = "sync",
849 .type = FIO_OPT_BOOL,
850 .off1 = td_var_offset(sync_io),
851 .help = "Use O_SYNC for buffered writes",
852 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +0200853 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100854 },
855 {
856 .name = "bwavgtime",
857 .type = FIO_OPT_INT,
858 .off1 = td_var_offset(bw_avg_time),
859 .help = "Time window over which to calculate bandwidth (msec)",
860 .def = "500",
861 },
862 {
863 .name = "create_serialize",
864 .type = FIO_OPT_BOOL,
865 .off1 = td_var_offset(create_serialize),
866 .help = "Serialize creating of job files",
867 .def = "1",
868 },
869 {
870 .name = "create_fsync",
871 .type = FIO_OPT_BOOL,
872 .off1 = td_var_offset(create_fsync),
873 .help = "Fsync file after creation",
874 .def = "1",
875 },
876 {
877 .name = "cpuload",
878 .type = FIO_OPT_INT,
879 .off1 = td_var_offset(cpuload),
880 .help = "Use this percentage of CPU",
881 },
882 {
883 .name = "cpuchunks",
884 .type = FIO_OPT_INT,
885 .off1 = td_var_offset(cpucycle),
886 .help = "Length of the CPU burn cycles (usecs)",
887 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +0200888 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100889 },
890#ifdef FIO_HAVE_CPU_AFFINITY
891 {
892 .name = "cpumask",
893 .type = FIO_OPT_INT,
894 .cb = str_cpumask_cb,
895 .help = "CPU affinity mask",
896 },
Jens Axboed2e268b2007-06-15 10:33:49 +0200897 {
898 .name = "cpus_allowed",
899 .type = FIO_OPT_STR,
900 .cb = str_cpus_allowed_cb,
901 .help = "Set CPUs allowed",
902 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100903#endif
904 {
905 .name = "end_fsync",
906 .type = FIO_OPT_BOOL,
907 .off1 = td_var_offset(end_fsync),
908 .help = "Include fsync at the end of job",
909 .def = "0",
910 },
911 {
912 .name = "fsync_on_close",
913 .type = FIO_OPT_BOOL,
914 .off1 = td_var_offset(fsync_on_close),
915 .help = "fsync files on close",
916 .def = "0",
917 },
918 {
919 .name = "unlink",
920 .type = FIO_OPT_BOOL,
921 .off1 = td_var_offset(unlink),
922 .help = "Unlink created files after job has completed",
923 .def = "0",
924 },
925 {
926 .name = "exitall",
927 .type = FIO_OPT_STR_SET,
928 .cb = str_exitall_cb,
929 .help = "Terminate all jobs when one exits",
930 },
931 {
932 .name = "stonewall",
933 .type = FIO_OPT_STR_SET,
934 .off1 = td_var_offset(stonewall),
935 .help = "Insert a hard barrier between this job and previous",
936 },
937 {
Jens Axboeb3d62a72007-03-20 14:23:26 +0100938 .name = "new_group",
939 .type = FIO_OPT_STR_SET,
940 .off1 = td_var_offset(new_group),
941 .help = "Mark the start of a new group (for reporting)",
942 },
943 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100944 .name = "thread",
945 .type = FIO_OPT_STR_SET,
946 .off1 = td_var_offset(use_thread),
947 .help = "Use threads instead of forks",
948 },
949 {
950 .name = "write_bw_log",
951 .type = FIO_OPT_STR_SET,
952 .off1 = td_var_offset(write_bw_log),
953 .help = "Write log of bandwidth during run",
954 },
955 {
956 .name = "write_lat_log",
957 .type = FIO_OPT_STR_SET,
958 .off1 = td_var_offset(write_lat_log),
959 .help = "Write log of latency during run",
960 },
961 {
962 .name = "hugepage-size",
963 .type = FIO_OPT_STR_VAL,
964 .off1 = td_var_offset(hugepage_size),
965 .help = "When using hugepages, specify size of each page",
966 .def = __stringify(FIO_HUGE_PAGE),
967 },
968 {
969 .name = "group_reporting",
970 .type = FIO_OPT_STR_SET,
971 .off1 = td_var_offset(group_reporting),
972 .help = "Do reporting on a per-group basis",
973 },
974 {
Jens Axboee9459e52007-04-17 15:46:32 +0200975 .name = "zero_buffers",
976 .type = FIO_OPT_STR_SET,
977 .off1 = td_var_offset(zero_buffers),
978 .help = "Init IO buffers to all zeroes",
979 },
Jens Axboe0a839f32007-04-26 09:02:34 +0200980#ifdef FIO_HAVE_DISK_UTIL
981 {
982 .name = "disk_util",
983 .type = FIO_OPT_BOOL,
984 .off1 = td_var_offset(do_disk_util),
985 .help = "Log disk utilization stats",
986 .def = "1",
987 },
988#endif
Jens Axboee9459e52007-04-17 15:46:32 +0200989 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100990 .name = NULL,
991 },
992};
993
994void fio_options_dup_and_init(struct option *long_options)
995{
996 struct fio_option *o;
997 unsigned int i;
998
999 options_init(options);
1000
1001 i = 0;
1002 while (long_options[i].name)
1003 i++;
1004
1005 o = &options[0];
1006 while (o->name) {
1007 long_options[i].name = o->name;
1008 long_options[i].val = FIO_GETOPT_JOB;
1009 if (o->type == FIO_OPT_STR_SET)
1010 long_options[i].has_arg = no_argument;
1011 else
1012 long_options[i].has_arg = required_argument;
1013
1014 i++;
1015 o++;
1016 assert(i < FIO_NR_OPTIONS);
1017 }
1018}
1019
1020int fio_option_parse(struct thread_data *td, const char *opt)
1021{
1022 return parse_option(opt, options, td);
1023}
1024
1025int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1026{
1027 return parse_cmd_option(opt, val, options, td);
1028}
1029
1030void fio_fill_default_options(struct thread_data *td)
1031{
1032 fill_default_options(td, options);
1033}
1034
1035int fio_show_option_help(const char *opt)
1036{
1037 return show_cmd_help(options, opt);
1038}
Jens Axboed23bb322007-03-23 15:57:56 +01001039
1040static void __options_mem(struct thread_data *td, int alloc)
1041{
1042 struct thread_options *o = &td->o;
1043 struct fio_option *opt;
1044 char **ptr;
1045 int i;
1046
1047 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1048 if (opt->type != FIO_OPT_STR_STORE)
1049 continue;
1050
1051 ptr = (void *) o + opt->off1;
1052 if (*ptr) {
1053 if (alloc)
1054 *ptr = strdup(*ptr);
1055 else {
1056 free(*ptr);
1057 *ptr = NULL;
1058 }
1059 }
1060 }
1061}
1062
1063/*
1064 * dupe FIO_OPT_STR_STORE options
1065 */
1066void options_mem_dupe(struct thread_data *td)
1067{
1068 __options_mem(td, 1);
1069}
1070
Jens Axboe22d66212007-03-27 20:06:25 +02001071void options_mem_free(struct thread_data fio_unused *td)
Jens Axboed23bb322007-03-23 15:57:56 +01001072{
Jens Axboe22d66212007-03-27 20:06:25 +02001073#if 0
Jens Axboed23bb322007-03-23 15:57:56 +01001074 __options_mem(td, 0);
Jens Axboe22d66212007-03-27 20:06:25 +02001075#endif
Jens Axboed23bb322007-03-23 15:57:56 +01001076}