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