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