blob: dacfb73808f48c9868c2ba5a41937935454181c2 [file] [log] [blame]
Jens Axboe214e1ec2007-03-15 10:48:13 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <ctype.h>
5#include <string.h>
Jens Axboe214e1ec2007-03-15 10:48:13 +01006#include <assert.h>
Jens Axboe921c7662008-03-26 09:17:55 +01007#include <libgen.h>
Jens Axboe5921e802008-05-30 15:02:38 +02008#include <fcntl.h>
9#include <sys/types.h>
10#include <sys/stat.h>
Jens Axboe214e1ec2007-03-15 10:48:13 +010011
12#include "fio.h"
Jens Axboe4f5af7b2009-06-03 08:45:40 +020013#include "verify.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010014#include "parse.h"
Jens Axboeeef32352008-06-02 13:31:26 +020015#include "lib/fls.h"
Jens Axboe9f988e22010-03-04 10:42:38 +010016#include "options.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010017
Jens Axboe5d7c5d32010-06-21 15:08:17 +020018#include "crc/crc32c.h"
19
Jens Axboe214e1ec2007-03-15 10:48:13 +010020/*
21 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
22 */
23static char *get_opt_postfix(const char *str)
24{
25 char *p = strstr(str, ":");
26
27 if (!p)
28 return NULL;
29
30 p++;
31 strip_blank_front(&p);
32 strip_blank_end(p);
33 return strdup(p);
34}
35
Radha Ramachandran0e92f872009-10-27 20:14:27 +010036static int converthexchartoint(char a)
37{
38 int base;
39
40 switch(a) {
41 case '0'...'9':
42 base = '0';
43 break;
44 case 'A'...'F':
45 base = 'A' - 10;
46 break;
47 case 'a'...'f':
48 base = 'a' - 10;
49 break;
50 default:
51 base = 0;
52 }
53 return (a - base);
54}
55
Jens Axboe564ca972007-12-14 12:21:19 +010056static int bs_cmp(const void *p1, const void *p2)
57{
58 const struct bssplit *bsp1 = p1;
59 const struct bssplit *bsp2 = p2;
60
61 return bsp1->perc < bsp2->perc;
62}
63
Jens Axboe720e84a2009-04-21 08:29:55 +020064static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
Jens Axboe564ca972007-12-14 12:21:19 +010065{
Jens Axboe720e84a2009-04-21 08:29:55 +020066 struct bssplit *bssplit;
Jens Axboe564ca972007-12-14 12:21:19 +010067 unsigned int i, perc, perc_missing;
68 unsigned int max_bs, min_bs;
69 long long val;
Jens Axboe720e84a2009-04-21 08:29:55 +020070 char *fname;
Jens Axboe564ca972007-12-14 12:21:19 +010071
Jens Axboe720e84a2009-04-21 08:29:55 +020072 td->o.bssplit_nr[ddir] = 4;
73 bssplit = malloc(4 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010074
75 i = 0;
76 max_bs = 0;
77 min_bs = -1;
78 while ((fname = strsep(&str, ":")) != NULL) {
79 char *perc_str;
80
81 if (!strlen(fname))
82 break;
83
84 /*
85 * grow struct buffer, if needed
86 */
Jens Axboe720e84a2009-04-21 08:29:55 +020087 if (i == td->o.bssplit_nr[ddir]) {
88 td->o.bssplit_nr[ddir] <<= 1;
89 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
Jens Axboe5ec10ea2008-03-06 15:42:00 +010090 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010091 }
92
93 perc_str = strstr(fname, "/");
94 if (perc_str) {
95 *perc_str = '\0';
96 perc_str++;
97 perc = atoi(perc_str);
98 if (perc > 100)
99 perc = 100;
100 else if (!perc)
101 perc = -1;
102 } else
103 perc = -1;
104
Jens Axboe6925dd32011-09-07 22:10:11 +0200105 if (str_to_decimal(fname, &val, 1, td)) {
Jens Axboe564ca972007-12-14 12:21:19 +0100106 log_err("fio: bssplit conversion failed\n");
107 free(td->o.bssplit);
108 return 1;
109 }
110
111 if (val > max_bs)
112 max_bs = val;
113 if (val < min_bs)
114 min_bs = val;
115
Jens Axboe720e84a2009-04-21 08:29:55 +0200116 bssplit[i].bs = val;
117 bssplit[i].perc = perc;
Jens Axboe564ca972007-12-14 12:21:19 +0100118 i++;
119 }
120
Jens Axboe720e84a2009-04-21 08:29:55 +0200121 td->o.bssplit_nr[ddir] = i;
Jens Axboe564ca972007-12-14 12:21:19 +0100122
123 /*
124 * Now check if the percentages add up, and how much is missing
125 */
126 perc = perc_missing = 0;
Jens Axboe720e84a2009-04-21 08:29:55 +0200127 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
128 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100129
130 if (bsp->perc == (unsigned char) -1)
131 perc_missing++;
132 else
133 perc += bsp->perc;
134 }
135
136 if (perc > 100) {
137 log_err("fio: bssplit percentages add to more than 100%%\n");
Jens Axboe720e84a2009-04-21 08:29:55 +0200138 free(bssplit);
Jens Axboe564ca972007-12-14 12:21:19 +0100139 return 1;
140 }
141 /*
142 * If values didn't have a percentage set, divide the remains between
143 * them.
144 */
145 if (perc_missing) {
Jens Axboe720e84a2009-04-21 08:29:55 +0200146 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
147 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100148
149 if (bsp->perc == (unsigned char) -1)
150 bsp->perc = (100 - perc) / perc_missing;
151 }
152 }
153
Jens Axboe720e84a2009-04-21 08:29:55 +0200154 td->o.min_bs[ddir] = min_bs;
155 td->o.max_bs[ddir] = max_bs;
Jens Axboe564ca972007-12-14 12:21:19 +0100156
157 /*
158 * now sort based on percentages, for ease of lookup
159 */
Jens Axboe720e84a2009-04-21 08:29:55 +0200160 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 td->o.bssplit[ddir] = bssplit;
162 return 0;
163
164}
165
166static int str_bssplit_cb(void *data, const char *input)
167{
168 struct thread_data *td = data;
169 char *str, *p, *odir;
170 int ret = 0;
171
172 p = str = strdup(input);
173
174 strip_blank_front(&str);
175 strip_blank_end(str);
176
177 odir = strchr(str, ',');
178 if (odir) {
179 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
180 if (!ret) {
181 *odir = '\0';
182 ret = bssplit_ddir(td, DDIR_READ, str);
183 }
184 } else {
185 char *op;
186
187 op = strdup(str);
188
189 ret = bssplit_ddir(td, DDIR_READ, str);
190 if (!ret)
191 ret = bssplit_ddir(td, DDIR_WRITE, op);
192
193 free(op);
194 }
Jens Axboe564ca972007-12-14 12:21:19 +0100195
196 free(p);
Jens Axboe720e84a2009-04-21 08:29:55 +0200197 return ret;
Jens Axboe564ca972007-12-14 12:21:19 +0100198}
199
Jens Axboe211097b2007-03-22 18:56:45 +0100200static int str_rw_cb(void *data, const char *str)
201{
202 struct thread_data *td = data;
203 char *nr = get_opt_postfix(str);
204
Jens Axboe5736c102010-07-20 12:03:25 -0600205 td->o.ddir_seq_nr = 1;
Jens Axboe059b0802011-08-25 09:09:37 +0200206 td->o.ddir_seq_add = 0;
207
208 if (!nr)
209 return 0;
210
211 if (td_random(td))
Jens Axboe5736c102010-07-20 12:03:25 -0600212 td->o.ddir_seq_nr = atoi(nr);
Jens Axboe059b0802011-08-25 09:09:37 +0200213 else {
214 long long val;
215
Jens Axboe6925dd32011-09-07 22:10:11 +0200216 if (str_to_decimal(nr, &val, 1, td)) {
Jens Axboe059b0802011-08-25 09:09:37 +0200217 log_err("fio: rw postfix parsing failed\n");
218 free(nr);
219 return 1;
220 }
221
222 td->o.ddir_seq_add = val;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100223 }
Jens Axboe211097b2007-03-22 18:56:45 +0100224
Jens Axboe059b0802011-08-25 09:09:37 +0200225 free(nr);
Jens Axboe211097b2007-03-22 18:56:45 +0100226 return 0;
227}
228
Jens Axboec44b1ff2011-08-30 20:43:53 -0600229#ifdef FIO_HAVE_LIBAIO
230static int str_libaio_cb(void *data, const char *str)
231{
232 struct thread_data *td = data;
233
234 if (!strcmp(str, "userspace_reap")) {
235 td->o.userspace_libaio_reap = 1;
236 return 0;
237 }
238
239 log_err("fio: bad libaio sub-option: %s\n", str);
240 return 1;
241}
242#endif
243
Jens Axboe214e1ec2007-03-15 10:48:13 +0100244static int str_mem_cb(void *data, const char *mem)
245{
246 struct thread_data *td = data;
247
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100248 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100249 td->mmapfile = get_opt_postfix(mem);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100250 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100251 log_err("fio: mmaphuge:/path/to/file\n");
252 return 1;
253 }
254 }
255
256 return 0;
257}
258
Jens Axboe5d7c5d32010-06-21 15:08:17 +0200259static int str_verify_cb(void *data, const char *mem)
260{
261 struct thread_data *td = data;
262
263 if (td->o.verify != VERIFY_CRC32C_INTEL)
264 return 0;
265
266 if (!crc32c_intel_works()) {
267 log_info("fio: System does not support hw accelerated crc32c. Falling back to sw crc32c.\n");
268 td->o.verify = VERIFY_CRC32C;
269 }
270
271 return 0;
272}
273
Jens Axboec223da82010-03-24 13:23:53 +0100274static int fio_clock_source_cb(void *data, const char *str)
275{
276 struct thread_data *td = data;
277
278 fio_clock_source = td->o.clocksource;
279 fio_time_init();
280 return 0;
281}
282
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400283static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100284{
285 mlock_size = *val;
286 return 0;
287}
288
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400289static int str_rwmix_read_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200290{
291 struct thread_data *td = data;
292
293 td->o.rwmix[DDIR_READ] = *val;
294 td->o.rwmix[DDIR_WRITE] = 100 - *val;
295 return 0;
296}
297
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400298static int str_rwmix_write_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200299{
300 struct thread_data *td = data;
301
302 td->o.rwmix[DDIR_WRITE] = *val;
303 td->o.rwmix[DDIR_READ] = 100 - *val;
304 return 0;
305}
306
Jens Axboe214e1ec2007-03-15 10:48:13 +0100307#ifdef FIO_HAVE_IOPRIO
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400308static int str_prioclass_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100309{
310 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200311 unsigned short mask;
312
313 /*
314 * mask off old class bits, str_prio_cb() may have set a default class
315 */
316 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
317 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100318
319 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
Jens Axboeac684782007-11-08 08:29:07 +0100320 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100321 return 0;
322}
323
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400324static int str_prio_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100325{
326 struct thread_data *td = data;
327
328 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200329
330 /*
331 * If no class is set, assume BE
332 */
333 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
334 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
335
Jens Axboeac684782007-11-08 08:29:07 +0100336 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100337 return 0;
338}
339#endif
340
341static int str_exitall_cb(void)
342{
343 exitall_on_terminate = 1;
344 return 0;
345}
346
Jens Axboe214e1ec2007-03-15 10:48:13 +0100347#ifdef FIO_HAVE_CPU_AFFINITY
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400348static int str_cpumask_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100349{
350 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200351 unsigned int i;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100352 long max_cpu;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100353 int ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100354
Jens Axboed2ce18b2008-12-12 20:51:40 +0100355 ret = fio_cpuset_init(&td->o.cpumask);
356 if (ret < 0) {
357 log_err("fio: cpuset_init failed\n");
358 td_verror(td, ret, "fio_cpuset_init");
359 return 1;
360 }
361
Jens Axboec00a2282011-07-08 20:56:06 +0200362 max_cpu = cpus_online();
Jens Axboed2e268b2007-06-15 10:33:49 +0200363
Jens Axboe62a72732008-12-08 11:37:01 +0100364 for (i = 0; i < sizeof(int) * 8; i++) {
365 if ((1 << i) & *val) {
Jens Axboeb03daaf2008-12-08 20:31:43 +0100366 if (i > max_cpu) {
367 log_err("fio: CPU %d too large (max=%ld)\n", i,
368 max_cpu);
369 return 1;
370 }
Jens Axboe62a72732008-12-08 11:37:01 +0100371 dprint(FD_PARSE, "set cpu allowed %d\n", i);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100372 fio_cpu_set(&td->o.cpumask, i);
Jens Axboe62a72732008-12-08 11:37:01 +0100373 }
374 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200375
Jens Axboe375b2692007-05-22 09:13:02 +0200376 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100377 return 0;
378}
379
Jens Axboee8462bd2009-07-06 12:59:04 +0200380static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
381 const char *input)
Jens Axboed2e268b2007-06-15 10:33:49 +0200382{
Jens Axboed2e268b2007-06-15 10:33:49 +0200383 char *cpu, *str, *p;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100384 long max_cpu;
Jens Axboe19608d62008-12-08 15:03:12 +0100385 int ret = 0;
Jens Axboed2e268b2007-06-15 10:33:49 +0200386
Jens Axboee8462bd2009-07-06 12:59:04 +0200387 ret = fio_cpuset_init(mask);
Jens Axboed2ce18b2008-12-12 20:51:40 +0100388 if (ret < 0) {
389 log_err("fio: cpuset_init failed\n");
390 td_verror(td, ret, "fio_cpuset_init");
391 return 1;
392 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200393
394 p = str = strdup(input);
395
396 strip_blank_front(&str);
397 strip_blank_end(str);
398
Jens Axboec00a2282011-07-08 20:56:06 +0200399 max_cpu = cpus_online();
Jens Axboeb03daaf2008-12-08 20:31:43 +0100400
Jens Axboed2e268b2007-06-15 10:33:49 +0200401 while ((cpu = strsep(&str, ",")) != NULL) {
Jens Axboe62a72732008-12-08 11:37:01 +0100402 char *str2, *cpu2;
403 int icpu, icpu2;
404
Jens Axboed2e268b2007-06-15 10:33:49 +0200405 if (!strlen(cpu))
406 break;
Jens Axboe62a72732008-12-08 11:37:01 +0100407
408 str2 = cpu;
409 icpu2 = -1;
410 while ((cpu2 = strsep(&str2, "-")) != NULL) {
411 if (!strlen(cpu2))
412 break;
413
414 icpu2 = atoi(cpu2);
415 }
416
417 icpu = atoi(cpu);
418 if (icpu2 == -1)
419 icpu2 = icpu;
420 while (icpu <= icpu2) {
Jens Axboe6d459ee2008-12-12 20:02:58 +0100421 if (icpu >= FIO_MAX_CPUS) {
Jens Axboe19608d62008-12-08 15:03:12 +0100422 log_err("fio: your OS only supports up to"
Jens Axboe6d459ee2008-12-12 20:02:58 +0100423 " %d CPUs\n", (int) FIO_MAX_CPUS);
Jens Axboe19608d62008-12-08 15:03:12 +0100424 ret = 1;
425 break;
426 }
Jens Axboeb03daaf2008-12-08 20:31:43 +0100427 if (icpu > max_cpu) {
428 log_err("fio: CPU %d too large (max=%ld)\n",
429 icpu, max_cpu);
430 ret = 1;
431 break;
432 }
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200433
Jens Axboe62a72732008-12-08 11:37:01 +0100434 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
Jens Axboee8462bd2009-07-06 12:59:04 +0200435 fio_cpu_set(mask, icpu);
Jens Axboe62a72732008-12-08 11:37:01 +0100436 icpu++;
437 }
Jens Axboe19608d62008-12-08 15:03:12 +0100438 if (ret)
439 break;
Jens Axboed2e268b2007-06-15 10:33:49 +0200440 }
441
442 free(p);
Jens Axboe19608d62008-12-08 15:03:12 +0100443 if (!ret)
444 td->o.cpumask_set = 1;
445 return ret;
Jens Axboed2e268b2007-06-15 10:33:49 +0200446}
Jens Axboee8462bd2009-07-06 12:59:04 +0200447
448static int str_cpus_allowed_cb(void *data, const char *input)
449{
450 struct thread_data *td = data;
451 int ret;
452
453 ret = set_cpus_allowed(td, &td->o.cpumask, input);
454 if (!ret)
455 td->o.cpumask_set = 1;
456
457 return ret;
458}
459
460static int str_verify_cpus_allowed_cb(void *data, const char *input)
461{
462 struct thread_data *td = data;
463 int ret;
464
465 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
466 if (!ret)
467 td->o.verify_cpumask_set = 1;
468
469 return ret;
470}
Jens Axboed2e268b2007-06-15 10:33:49 +0200471#endif
472
Jens Axboe0d29de82010-09-01 13:54:15 +0200473#ifdef FIO_HAVE_TRIM
474static int str_verify_trim_cb(void *data, unsigned long long *val)
475{
476 struct thread_data *td = data;
477
478 td->o.trim_percentage = *val;
479 return 0;
480}
481#endif
482
Jens Axboe214e1ec2007-03-15 10:48:13 +0100483static int str_fst_cb(void *data, const char *str)
484{
485 struct thread_data *td = data;
486 char *nr = get_opt_postfix(str);
487
488 td->file_service_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100489 if (nr) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100490 td->file_service_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100491 free(nr);
492 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100493
494 return 0;
495}
496
Jens Axboe3ae06372010-03-19 19:17:15 +0100497#ifdef FIO_HAVE_SYNC_FILE_RANGE
Jens Axboe44f29692010-03-09 20:09:44 +0100498static int str_sfr_cb(void *data, const char *str)
499{
500 struct thread_data *td = data;
501 char *nr = get_opt_postfix(str);
502
503 td->sync_file_range_nr = 1;
504 if (nr) {
505 td->sync_file_range_nr = atoi(nr);
506 free(nr);
507 }
508
509 return 0;
510}
Jens Axboe3ae06372010-03-19 19:17:15 +0100511#endif
Jens Axboe44f29692010-03-09 20:09:44 +0100512
Jens Axboe921c7662008-03-26 09:17:55 +0100513static int check_dir(struct thread_data *td, char *fname)
514{
Jens Axboe3f0ca9b2011-05-24 21:36:24 +0200515#if 0
Jens Axboe921c7662008-03-26 09:17:55 +0100516 char file[PATH_MAX], *dir;
Jens Axboebc838912008-04-07 09:00:54 +0200517 int elen = 0;
Jens Axboe921c7662008-03-26 09:17:55 +0100518
Jens Axboebc838912008-04-07 09:00:54 +0200519 if (td->o.directory) {
520 strcpy(file, td->o.directory);
Jens Axboefcef0b32008-05-26 14:53:24 +0200521 strcat(file, "/");
Jens Axboebc838912008-04-07 09:00:54 +0200522 elen = strlen(file);
523 }
524
Jens Axboefcef0b32008-05-26 14:53:24 +0200525 sprintf(file + elen, "%s", fname);
Jens Axboe921c7662008-03-26 09:17:55 +0100526 dir = dirname(file);
527
Jens Axboefcef0b32008-05-26 14:53:24 +0200528 {
529 struct stat sb;
530 /*
531 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
532 * yet, so we can't do this check right here...
533 */
Jens Axboe921c7662008-03-26 09:17:55 +0100534 if (lstat(dir, &sb) < 0) {
535 int ret = errno;
536
537 log_err("fio: %s is not a directory\n", dir);
538 td_verror(td, ret, "lstat");
539 return 1;
540 }
541
542 if (!S_ISDIR(sb.st_mode)) {
543 log_err("fio: %s is not a directory\n", dir);
544 return 1;
545 }
Jens Axboefcef0b32008-05-26 14:53:24 +0200546 }
547#endif
Jens Axboe921c7662008-03-26 09:17:55 +0100548
549 return 0;
550}
551
Jens Axboe8e827d32009-08-04 09:51:48 +0200552/*
553 * Return next file in the string. Files are separated with ':'. If the ':'
554 * is escaped with a '\', then that ':' is part of the filename and does not
555 * indicate a new file.
556 */
557static char *get_next_file_name(char **ptr)
558{
559 char *str = *ptr;
560 char *p, *start;
561
562 if (!str || !strlen(str))
563 return NULL;
564
565 start = str;
566 do {
567 /*
568 * No colon, we are done
569 */
570 p = strchr(str, ':');
571 if (!p) {
572 *ptr = NULL;
573 break;
574 }
575
576 /*
577 * We got a colon, but it's the first character. Skip and
578 * continue
579 */
580 if (p == start) {
581 str = ++start;
582 continue;
583 }
584
585 if (*(p - 1) != '\\') {
586 *p = '\0';
587 *ptr = p + 1;
588 break;
589 }
590
591 memmove(p - 1, p, strlen(p) + 1);
592 str = p;
593 } while (1);
594
595 return start;
596}
597
Jens Axboe0fd666b2011-10-06 20:08:53 +0200598static int str_hostname_cb(void *data, const char *input)
599{
600 struct thread_data *td = data;
601
602 td->o.filename = strdup(input);
603 return 0;
604}
605
Jens Axboe214e1ec2007-03-15 10:48:13 +0100606static int str_filename_cb(void *data, const char *input)
607{
608 struct thread_data *td = data;
609 char *fname, *str, *p;
610
611 p = str = strdup(input);
612
613 strip_blank_front(&str);
614 strip_blank_end(str);
615
616 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100617 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100618
Jens Axboe8e827d32009-08-04 09:51:48 +0200619 while ((fname = get_next_file_name(&str)) != NULL) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100620 if (!strlen(fname))
621 break;
Jens Axboe921c7662008-03-26 09:17:55 +0100622 if (check_dir(td, fname)) {
623 free(p);
624 return 1;
625 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100626 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100627 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100628 }
629
630 free(p);
631 return 0;
632}
633
634static int str_directory_cb(void *data, const char fio_unused *str)
635{
636 struct thread_data *td = data;
637 struct stat sb;
638
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100639 if (lstat(td->o.directory, &sb) < 0) {
Jens Axboe921c7662008-03-26 09:17:55 +0100640 int ret = errno;
641
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100642 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe921c7662008-03-26 09:17:55 +0100643 td_verror(td, ret, "lstat");
Jens Axboe214e1ec2007-03-15 10:48:13 +0100644 return 1;
645 }
646 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100647 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100648 return 1;
649 }
650
651 return 0;
652}
653
654static int str_opendir_cb(void *data, const char fio_unused *str)
655{
656 struct thread_data *td = data;
657
658 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100659 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100660
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100661 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100662}
663
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400664static int str_verify_offset_cb(void *data, unsigned long long *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200665{
666 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200667
Shawn Lewis546a9142007-07-28 21:11:37 +0200668 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200669 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200670 return 1;
671 }
Jens Axboea59e1702007-07-30 08:53:27 +0200672
673 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200674 return 0;
675}
676
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100677static int str_verify_pattern_cb(void *data, const char *input)
Jens Axboe90059d62007-07-30 09:33:12 +0200678{
679 struct thread_data *td = data;
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100680 long off;
681 int i = 0, j = 0, len, k, base = 10;
682 char* loc1, * loc2;
Jens Axboe90059d62007-07-30 09:33:12 +0200683
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100684 loc1 = strstr(input, "0x");
685 loc2 = strstr(input, "0X");
686 if (loc1 || loc2)
687 base = 16;
688 off = strtol(input, NULL, base);
689 if (off != LONG_MAX || errno != ERANGE) {
690 while (off) {
691 td->o.verify_pattern[i] = off & 0xff;
692 off >>= 8;
693 i++;
694 }
695 } else {
696 len = strlen(input);
697 k = len - 1;
698 if (base == 16) {
699 if (loc1)
700 j = loc1 - input + 2;
701 else
702 j = loc2 - input + 2;
703 } else
704 return 1;
705 if (len - j < MAX_PATTERN_SIZE * 2) {
706 while (k >= j) {
707 off = converthexchartoint(input[k--]);
708 if (k >= j)
709 off += (converthexchartoint(input[k--])
710 * 16);
711 td->o.verify_pattern[i++] = (char) off;
712 }
713 }
714 }
715 td->o.verify_pattern_bytes = i;
Jens Axboe92bf48d2011-01-14 21:20:42 +0100716 /*
717 * VERIFY_META could already be set
718 */
719 if (td->o.verify == VERIFY_NONE)
720 td->o.verify = VERIFY_PATTERN;
Jens Axboe90059d62007-07-30 09:33:12 +0200721 return 0;
722}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100723
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100724static int str_lockfile_cb(void *data, const char *str)
725{
726 struct thread_data *td = data;
727 char *nr = get_opt_postfix(str);
728
729 td->o.lockfile_batch = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100730 if (nr) {
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100731 td->o.lockfile_batch = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100732 free(nr);
733 }
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100734
735 return 0;
736}
737
Jens Axboee3cedca2008-11-19 19:57:52 +0100738static int str_write_bw_log_cb(void *data, const char *str)
739{
740 struct thread_data *td = data;
741
742 if (str)
743 td->o.bw_log_file = strdup(str);
744
745 td->o.write_bw_log = 1;
746 return 0;
747}
748
749static int str_write_lat_log_cb(void *data, const char *str)
750{
751 struct thread_data *td = data;
752
753 if (str)
754 td->o.lat_log_file = strdup(str);
755
756 td->o.write_lat_log = 1;
757 return 0;
758}
759
Jens Axboec8eeb9d2011-10-05 14:02:22 +0200760static int str_write_iops_log_cb(void *data, const char *str)
761{
762 struct thread_data *td = data;
763
764 if (str)
765 td->o.iops_log_file = strdup(str);
766
767 td->o.write_iops_log = 1;
768 return 0;
769}
770
Jens Axboe993bf482008-11-14 13:04:53 +0100771static int str_gtod_reduce_cb(void *data, int *il)
772{
773 struct thread_data *td = data;
774 int val = *il;
775
Jens Axboe02af0982010-06-24 09:59:34 +0200776 td->o.disable_lat = !!val;
Jens Axboe993bf482008-11-14 13:04:53 +0100777 td->o.disable_clat = !!val;
778 td->o.disable_slat = !!val;
779 td->o.disable_bw = !!val;
780 if (val)
781 td->tv_cache_mask = 63;
782
783 return 0;
784}
785
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400786static int str_gtod_cpu_cb(void *data, long long *il)
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100787{
788 struct thread_data *td = data;
789 int val = *il;
790
791 td->o.gtod_cpu = val;
792 td->o.gtod_offload = 1;
793 return 0;
794}
795
Jens Axboe7bb59102011-07-12 19:47:03 +0200796static int str_size_cb(void *data, unsigned long long *__val)
797{
798 struct thread_data *td = data;
799 unsigned long long v = *__val;
800
801 if (parse_is_percent(v)) {
802 td->o.size = 0;
803 td->o.size_percent = -1ULL - v;
804 } else
805 td->o.size = v;
806
807 return 0;
808}
809
Jens Axboe896cac22009-07-01 10:38:35 +0200810static int rw_verify(struct fio_option *o, void *data)
811{
812 struct thread_data *td = data;
813
814 if (read_only && td_write(td)) {
815 log_err("fio: job <%s> has write bit set, but fio is in"
816 " read-only mode\n", td->o.name);
817 return 1;
818 }
819
820 return 0;
821}
822
Jens Axboe276ca4f2009-07-01 10:43:05 +0200823static int gtod_cpu_verify(struct fio_option *o, void *data)
Jens Axboe29d43ff2009-07-01 10:42:18 +0200824{
Jens Axboe276ca4f2009-07-01 10:43:05 +0200825#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboe29d43ff2009-07-01 10:42:18 +0200826 struct thread_data *td = data;
827
Jens Axboe29d43ff2009-07-01 10:42:18 +0200828 if (td->o.gtod_cpu) {
829 log_err("fio: platform must support CPU affinity for"
830 "gettimeofday() offloading\n");
831 return 1;
832 }
833#endif
834
835 return 0;
836}
837
Jens Axboe90fef2d2009-07-17 22:33:32 +0200838static int kb_base_verify(struct fio_option *o, void *data)
839{
840 struct thread_data *td = data;
841
842 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
843 log_err("fio: kb_base set to nonsensical value: %u\n",
844 td->o.kb_base);
845 return 1;
846 }
847
848 return 0;
849}
850
Jens Axboe214e1ec2007-03-15 10:48:13 +0100851/*
852 * Map of job/command line options
853 */
Jens Axboe07b32322010-03-05 09:48:44 +0100854static struct fio_option options[FIO_MAX_OPTS] = {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100855 {
856 .name = "description",
857 .type = FIO_OPT_STR_STORE,
858 .off1 = td_var_offset(description),
859 .help = "Text job description",
860 },
861 {
862 .name = "name",
863 .type = FIO_OPT_STR_STORE,
864 .off1 = td_var_offset(name),
865 .help = "Name of this job",
866 },
867 {
868 .name = "directory",
869 .type = FIO_OPT_STR_STORE,
870 .off1 = td_var_offset(directory),
871 .cb = str_directory_cb,
872 .help = "Directory to store files in",
873 },
874 {
875 .name = "filename",
876 .type = FIO_OPT_STR_STORE,
877 .off1 = td_var_offset(filename),
878 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +0200879 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +0100880 .help = "File(s) to use for the workload",
881 },
882 {
Jens Axboe0fd666b2011-10-06 20:08:53 +0200883 .name = "hostname",
884 .type = FIO_OPT_STR_STORE,
885 .cb = str_hostname_cb,
886 .help = "Hostname for net IO engine",
887 },
888 {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200889 .name = "kb_base",
890 .type = FIO_OPT_INT,
891 .off1 = td_var_offset(kb_base),
Jens Axboe90fef2d2009-07-17 22:33:32 +0200892 .verify = kb_base_verify,
Jens Axboea639f0b2009-07-18 08:25:35 +0200893 .prio = 1,
Jens Axboe90fef2d2009-07-17 22:33:32 +0200894 .def = "1024",
Jens Axboea639f0b2009-07-18 08:25:35 +0200895 .help = "How many bytes per KB for reporting (1000 or 1024)",
Jens Axboe90fef2d2009-07-17 22:33:32 +0200896 },
897 {
Jens Axboe29c13492008-03-01 19:25:20 +0100898 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100899 .type = FIO_OPT_STR,
900 .cb = str_lockfile_cb,
901 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +0100902 .help = "Lock file when doing IO to it",
903 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100904 .def = "none",
905 .posval = {
906 { .ival = "none",
907 .oval = FILE_LOCK_NONE,
908 .help = "No file locking",
909 },
910 { .ival = "exclusive",
911 .oval = FILE_LOCK_EXCLUSIVE,
912 .help = "Exclusive file lock",
913 },
914 {
915 .ival = "readwrite",
916 .oval = FILE_LOCK_READWRITE,
917 .help = "Read vs write lock",
918 },
919 },
Jens Axboe29c13492008-03-01 19:25:20 +0100920 },
921 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100922 .name = "opendir",
923 .type = FIO_OPT_STR_STORE,
924 .off1 = td_var_offset(opendir),
925 .cb = str_opendir_cb,
926 .help = "Recursively add files from this directory and down",
927 },
928 {
929 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100930 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100931 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +0100932 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100933 .off1 = td_var_offset(td_ddir),
934 .help = "IO direction",
935 .def = "read",
Jens Axboe896cac22009-07-01 10:38:35 +0200936 .verify = rw_verify,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100937 .posval = {
938 { .ival = "read",
939 .oval = TD_DDIR_READ,
940 .help = "Sequential read",
941 },
942 { .ival = "write",
943 .oval = TD_DDIR_WRITE,
944 .help = "Sequential write",
945 },
946 { .ival = "randread",
947 .oval = TD_DDIR_RANDREAD,
948 .help = "Random read",
949 },
950 { .ival = "randwrite",
951 .oval = TD_DDIR_RANDWRITE,
952 .help = "Random write",
953 },
954 { .ival = "rw",
955 .oval = TD_DDIR_RW,
956 .help = "Sequential read and write mix",
957 },
958 { .ival = "randrw",
959 .oval = TD_DDIR_RANDRW,
960 .help = "Random read and write mix"
961 },
962 },
963 },
964 {
Jens Axboe38dad622010-07-20 14:46:00 -0600965 .name = "rw_sequencer",
966 .type = FIO_OPT_STR,
967 .off1 = td_var_offset(rw_seq),
968 .help = "IO offset generator modifier",
969 .def = "sequential",
970 .posval = {
971 { .ival = "sequential",
972 .oval = RW_SEQ_SEQ,
973 .help = "Generate sequential offsets",
974 },
975 { .ival = "identical",
976 .oval = RW_SEQ_IDENT,
977 .help = "Generate identical offsets",
978 },
979 },
980 },
981
982 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100983 .name = "ioengine",
984 .type = FIO_OPT_STR_STORE,
985 .off1 = td_var_offset(ioengine),
986 .help = "IO engine to use",
Jens Axboe58483fa2011-01-19 11:09:58 -0700987 .def = FIO_PREFERRED_ENGINE,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100988 .posval = {
989 { .ival = "sync",
990 .help = "Use read/write",
991 },
gurudas paia31041e2007-10-23 15:12:30 +0200992 { .ival = "psync",
993 .help = "Use pread/pwrite",
994 },
Jens Axboe1d2af022008-02-04 10:59:07 +0100995 { .ival = "vsync",
Bruce Cran03e20d62011-01-02 20:14:54 +0100996 .help = "Use readv/writev",
Jens Axboe1d2af022008-02-04 10:59:07 +0100997 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100998#ifdef FIO_HAVE_LIBAIO
999 { .ival = "libaio",
1000 .help = "Linux native asynchronous IO",
Jens Axboec44b1ff2011-08-30 20:43:53 -06001001 .cb = str_libaio_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001002 },
1003#endif
1004#ifdef FIO_HAVE_POSIXAIO
1005 { .ival = "posixaio",
1006 .help = "POSIX asynchronous IO",
1007 },
1008#endif
Jens Axboe417f0062008-06-02 11:59:30 +02001009#ifdef FIO_HAVE_SOLARISAIO
1010 { .ival = "solarisaio",
1011 .help = "Solaris native asynchronous IO",
1012 },
1013#endif
Bruce Cran03e20d62011-01-02 20:14:54 +01001014#ifdef FIO_HAVE_WINDOWSAIO
1015 { .ival = "windowsaio",
Jens Axboe3be80072011-01-19 11:07:28 -07001016 .help = "Windows native asynchronous IO"
Bruce Cran03e20d62011-01-02 20:14:54 +01001017 },
Jens Axboe3be80072011-01-19 11:07:28 -07001018#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001019 { .ival = "mmap",
Bruce Cran03e20d62011-01-02 20:14:54 +01001020 .help = "Memory mapped IO"
Jens Axboe214e1ec2007-03-15 10:48:13 +01001021 },
1022#ifdef FIO_HAVE_SPLICE
1023 { .ival = "splice",
1024 .help = "splice/vmsplice based IO",
1025 },
Jens Axboe9cce02e2007-06-22 15:42:21 +02001026 { .ival = "netsplice",
1027 .help = "splice/vmsplice to/from the network",
1028 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001029#endif
1030#ifdef FIO_HAVE_SGIO
1031 { .ival = "sg",
1032 .help = "SCSI generic v3 IO",
1033 },
1034#endif
1035 { .ival = "null",
1036 .help = "Testing engine (no data transfer)",
1037 },
1038 { .ival = "net",
1039 .help = "Network IO",
1040 },
1041#ifdef FIO_HAVE_SYSLET
1042 { .ival = "syslet-rw",
1043 .help = "syslet enabled async pread/pwrite IO",
1044 },
1045#endif
1046 { .ival = "cpuio",
Bruce Cran03e20d62011-01-02 20:14:54 +01001047 .help = "CPU cycle burner engine",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001048 },
Jens Axboeb8c82a42007-03-21 08:48:26 +01001049#ifdef FIO_HAVE_GUASI
1050 { .ival = "guasi",
1051 .help = "GUASI IO engine",
1052 },
1053#endif
Jens Axboe79a43182010-09-07 13:28:58 +02001054#ifdef FIO_HAVE_BINJECT
1055 { .ival = "binject",
1056 .help = "binject direct inject block engine",
1057 },
1058#endif
ren yufei21b8aee2011-08-01 10:01:57 +02001059#ifdef FIO_HAVE_RDMA
1060 { .ival = "rdma",
1061 .help = "RDMA IO engine",
1062 },
1063#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001064 { .ival = "external",
1065 .help = "Load external engine (append name)",
1066 },
1067 },
1068 },
1069 {
1070 .name = "iodepth",
1071 .type = FIO_OPT_INT,
1072 .off1 = td_var_offset(iodepth),
Bruce Cran03e20d62011-01-02 20:14:54 +01001073 .help = "Number of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +01001074 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001075 .def = "1",
1076 },
1077 {
1078 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +02001079 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001080 .type = FIO_OPT_INT,
1081 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +01001082 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +02001083 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +01001084 .minval = 1,
1085 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001086 },
1087 {
Jens Axboe49504212008-06-05 09:03:30 +02001088 .name = "iodepth_batch_complete",
1089 .type = FIO_OPT_INT,
1090 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +01001091 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +02001092 .parent = "iodepth",
1093 .minval = 0,
1094 .def = "1",
1095 },
1096 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001097 .name = "iodepth_low",
1098 .type = FIO_OPT_INT,
1099 .off1 = td_var_offset(iodepth_low),
1100 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +02001101 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001102 },
1103 {
1104 .name = "size",
1105 .type = FIO_OPT_STR_VAL,
Jens Axboe7bb59102011-07-12 19:47:03 +02001106 .cb = str_size_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001107 .help = "Total size of device or files",
1108 },
1109 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001110 .name = "fill_device",
Jens Axboe74586c12011-01-20 10:16:03 -07001111 .alias = "fill_fs",
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001112 .type = FIO_OPT_BOOL,
1113 .off1 = td_var_offset(fill_device),
1114 .help = "Write until an ENOSPC error occurs",
1115 .def = "0",
1116 },
1117 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001118 .name = "filesize",
1119 .type = FIO_OPT_STR_VAL,
1120 .off1 = td_var_offset(file_size_low),
1121 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001122 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001123 .help = "Size of individual files",
1124 },
1125 {
Jens Axboe67a10002007-07-31 23:12:16 +02001126 .name = "offset",
1127 .alias = "fileoffset",
1128 .type = FIO_OPT_STR_VAL,
1129 .off1 = td_var_offset(start_offset),
1130 .help = "Start IO from this offset",
1131 .def = "0",
1132 },
1133 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001134 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001135 .alias = "blocksize",
Jens Axboee01b22b2009-06-09 15:43:25 +02001136 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001137 .off1 = td_var_offset(bs[DDIR_READ]),
1138 .off2 = td_var_offset(bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001139 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001140 .help = "Block size unit",
1141 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +02001142 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001143 },
1144 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001145 .name = "ba",
1146 .alias = "blockalign",
Jens Axboee01b22b2009-06-09 15:43:25 +02001147 .type = FIO_OPT_INT,
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001148 .off1 = td_var_offset(ba[DDIR_READ]),
1149 .off2 = td_var_offset(ba[DDIR_WRITE]),
1150 .minval = 1,
1151 .help = "IO block offset alignment",
1152 .parent = "rw",
1153 },
1154 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001155 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001156 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001157 .type = FIO_OPT_RANGE,
1158 .off1 = td_var_offset(min_bs[DDIR_READ]),
1159 .off2 = td_var_offset(max_bs[DDIR_READ]),
1160 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1161 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001162 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001163 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +02001164 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001165 },
1166 {
Jens Axboe564ca972007-12-14 12:21:19 +01001167 .name = "bssplit",
1168 .type = FIO_OPT_STR,
1169 .cb = str_bssplit_cb,
1170 .help = "Set a specific mix of block sizes",
1171 .parent = "rw",
1172 },
1173 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001174 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001175 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001176 .type = FIO_OPT_STR_SET,
1177 .off1 = td_var_offset(bs_unaligned),
1178 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +02001179 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001180 },
1181 {
1182 .name = "randrepeat",
1183 .type = FIO_OPT_BOOL,
1184 .off1 = td_var_offset(rand_repeatable),
1185 .help = "Use repeatable random IO pattern",
1186 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +02001187 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001188 },
1189 {
Jens Axboe2615cc42011-03-28 09:35:09 +02001190 .name = "use_os_rand",
1191 .type = FIO_OPT_BOOL,
1192 .off1 = td_var_offset(use_os_rand),
1193 .help = "Set to use OS random generator",
1194 .def = "0",
1195 .parent = "rw",
1196 },
1197 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001198 .name = "norandommap",
1199 .type = FIO_OPT_STR_SET,
1200 .off1 = td_var_offset(norandommap),
1201 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +02001202 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001203 },
1204 {
Jens Axboe2b386d22008-03-26 10:32:57 +01001205 .name = "softrandommap",
1206 .type = FIO_OPT_BOOL,
1207 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001208 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +01001209 .parent = "norandommap",
1210 .def = "0",
1211 },
1212 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001213 .name = "nrfiles",
Jens Axboed7c8be02010-11-25 08:21:39 +01001214 .alias = "nr_files",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001215 .type = FIO_OPT_INT,
1216 .off1 = td_var_offset(nr_files),
1217 .help = "Split job workload between this number of files",
1218 .def = "1",
1219 },
1220 {
1221 .name = "openfiles",
1222 .type = FIO_OPT_INT,
1223 .off1 = td_var_offset(open_files),
1224 .help = "Number of files to keep open at the same time",
1225 },
1226 {
1227 .name = "file_service_type",
1228 .type = FIO_OPT_STR,
1229 .cb = str_fst_cb,
1230 .off1 = td_var_offset(file_service_type),
1231 .help = "How to select which file to service next",
1232 .def = "roundrobin",
1233 .posval = {
1234 { .ival = "random",
1235 .oval = FIO_FSERVICE_RANDOM,
1236 .help = "Choose a file at random",
1237 },
1238 { .ival = "roundrobin",
1239 .oval = FIO_FSERVICE_RR,
1240 .help = "Round robin select files",
1241 },
Jens Axboea086c252009-03-04 08:27:37 +01001242 { .ival = "sequential",
1243 .oval = FIO_FSERVICE_SEQ,
1244 .help = "Finish one file before moving to the next",
1245 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001246 },
Jens Axboe67a10002007-07-31 23:12:16 +02001247 .parent = "nrfiles",
1248 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001249#ifdef FIO_HAVE_FALLOCATE
1250 {
1251 .name = "fallocate",
Eric Gourioua596f042011-06-17 09:11:45 +02001252 .type = FIO_OPT_STR,
1253 .off1 = td_var_offset(fallocate_mode),
1254 .help = "Whether pre-allocation is performed when laying out files",
1255 .def = "posix",
1256 .posval = {
1257 { .ival = "none",
1258 .oval = FIO_FALLOCATE_NONE,
1259 .help = "Do not pre-allocate space",
1260 },
1261 { .ival = "posix",
1262 .oval = FIO_FALLOCATE_POSIX,
1263 .help = "Use posix_fallocate()",
1264 },
1265#ifdef FIO_HAVE_LINUX_FALLOCATE
1266 { .ival = "keep",
1267 .oval = FIO_FALLOCATE_KEEP_SIZE,
1268 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1269 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001270#endif
Eric Gourioua596f042011-06-17 09:11:45 +02001271 /* Compatibility with former boolean values */
1272 { .ival = "0",
1273 .oval = FIO_FALLOCATE_NONE,
1274 .help = "Alias for 'none'",
1275 },
1276 { .ival = "1",
1277 .oval = FIO_FALLOCATE_POSIX,
1278 .help = "Alias for 'posix'",
1279 },
1280 },
1281 },
1282#endif /* FIO_HAVE_FALLOCATE */
Jens Axboe67a10002007-07-31 23:12:16 +02001283 {
1284 .name = "fadvise_hint",
1285 .type = FIO_OPT_BOOL,
1286 .off1 = td_var_offset(fadvise_hint),
1287 .help = "Use fadvise() to advise the kernel on IO pattern",
1288 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001289 },
1290 {
1291 .name = "fsync",
1292 .type = FIO_OPT_INT,
1293 .off1 = td_var_offset(fsync_blocks),
1294 .help = "Issue fsync for writes every given number of blocks",
1295 .def = "0",
1296 },
1297 {
Jens Axboe5f9099e2009-06-16 22:40:26 +02001298 .name = "fdatasync",
1299 .type = FIO_OPT_INT,
1300 .off1 = td_var_offset(fdatasync_blocks),
1301 .help = "Issue fdatasync for writes every given number of blocks",
1302 .def = "0",
1303 },
Jens Axboe1ef2b6b2010-10-08 15:07:01 +02001304 {
1305 .name = "write_barrier",
1306 .type = FIO_OPT_INT,
1307 .off1 = td_var_offset(barrier_blocks),
1308 .help = "Make every Nth write a barrier write",
1309 .def = "0",
1310 },
Jens Axboe44f29692010-03-09 20:09:44 +01001311#ifdef FIO_HAVE_SYNC_FILE_RANGE
1312 {
1313 .name = "sync_file_range",
1314 .posval = {
1315 { .ival = "wait_before",
1316 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1317 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001318 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001319 },
1320 { .ival = "write",
1321 .oval = SYNC_FILE_RANGE_WRITE,
1322 .help = "SYNC_FILE_RANGE_WRITE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001323 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001324 },
1325 {
1326 .ival = "wait_after",
1327 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1328 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
Jens Axboe3843deb2010-03-09 20:41:15 +01001329 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001330 },
1331 },
Jens Axboe3843deb2010-03-09 20:41:15 +01001332 .type = FIO_OPT_STR_MULTI,
Jens Axboe44f29692010-03-09 20:09:44 +01001333 .cb = str_sfr_cb,
1334 .off1 = td_var_offset(sync_file_range),
1335 .help = "Use sync_file_range()",
1336 },
1337#endif
Jens Axboe5f9099e2009-06-16 22:40:26 +02001338 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001339 .name = "direct",
1340 .type = FIO_OPT_BOOL,
1341 .off1 = td_var_offset(odirect),
1342 .help = "Use O_DIRECT IO (negates buffered)",
1343 .def = "0",
1344 },
1345 {
1346 .name = "buffered",
1347 .type = FIO_OPT_BOOL,
1348 .off1 = td_var_offset(odirect),
1349 .neg = 1,
1350 .help = "Use buffered IO (negates direct)",
1351 .def = "1",
1352 },
1353 {
1354 .name = "overwrite",
1355 .type = FIO_OPT_BOOL,
1356 .off1 = td_var_offset(overwrite),
1357 .help = "When writing, set whether to overwrite current data",
1358 .def = "0",
1359 },
1360 {
1361 .name = "loops",
1362 .type = FIO_OPT_INT,
1363 .off1 = td_var_offset(loops),
1364 .help = "Number of times to run the job",
1365 .def = "1",
1366 },
1367 {
1368 .name = "numjobs",
1369 .type = FIO_OPT_INT,
1370 .off1 = td_var_offset(numjobs),
1371 .help = "Duplicate this job this many times",
1372 .def = "1",
1373 },
1374 {
1375 .name = "startdelay",
Jens Axboea5737c92010-06-29 10:40:30 +02001376 .type = FIO_OPT_STR_VAL_TIME,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001377 .off1 = td_var_offset(start_delay),
1378 .help = "Only start job when this period has passed",
1379 .def = "0",
1380 },
1381 {
1382 .name = "runtime",
1383 .alias = "timeout",
1384 .type = FIO_OPT_STR_VAL_TIME,
1385 .off1 = td_var_offset(timeout),
1386 .help = "Stop workload when this amount of time has passed",
1387 .def = "0",
1388 },
1389 {
Jens Axboecf4464c2007-04-17 20:14:42 +02001390 .name = "time_based",
1391 .type = FIO_OPT_STR_SET,
1392 .off1 = td_var_offset(time_based),
1393 .help = "Keep running until runtime/timeout is met",
1394 },
1395 {
Jens Axboe721938a2008-09-10 09:46:16 +02001396 .name = "ramp_time",
1397 .type = FIO_OPT_STR_VAL_TIME,
1398 .off1 = td_var_offset(ramp_time),
1399 .help = "Ramp up time before measuring performance",
1400 },
1401 {
Jens Axboec223da82010-03-24 13:23:53 +01001402 .name = "clocksource",
1403 .type = FIO_OPT_STR,
1404 .cb = fio_clock_source_cb,
1405 .off1 = td_var_offset(clocksource),
1406 .help = "What type of timing source to use",
Jens Axboec223da82010-03-24 13:23:53 +01001407 .posval = {
1408 { .ival = "gettimeofday",
1409 .oval = CS_GTOD,
1410 .help = "Use gettimeofday(2) for timing",
1411 },
1412 { .ival = "clock_gettime",
1413 .oval = CS_CGETTIME,
1414 .help = "Use clock_gettime(2) for timing",
1415 },
1416#ifdef ARCH_HAVE_CPU_CLOCK
1417 { .ival = "cpu",
1418 .oval = CS_CPUCLOCK,
1419 .help = "Use CPU private clock",
1420 },
1421#endif
1422 },
1423 },
1424 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001425 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001426 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001427 .type = FIO_OPT_STR,
1428 .cb = str_mem_cb,
1429 .off1 = td_var_offset(mem_type),
1430 .help = "Backing type for IO buffers",
1431 .def = "malloc",
1432 .posval = {
1433 { .ival = "malloc",
1434 .oval = MEM_MALLOC,
1435 .help = "Use malloc(3) for IO buffers",
1436 },
Jens Axboeb370e462007-03-19 10:51:49 +01001437 { .ival = "shm",
1438 .oval = MEM_SHM,
1439 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001440 },
1441#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001442 { .ival = "shmhuge",
1443 .oval = MEM_SHMHUGE,
1444 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001445 },
1446#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001447 { .ival = "mmap",
1448 .oval = MEM_MMAP,
1449 .help = "Use mmap(2) (file or anon) for IO buffers",
1450 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001451#ifdef FIO_HAVE_HUGETLB
1452 { .ival = "mmaphuge",
1453 .oval = MEM_MMAPHUGE,
1454 .help = "Like mmap, but use huge pages",
1455 },
1456#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001457 },
1458 },
1459 {
Jens Axboed529ee12009-07-01 10:33:03 +02001460 .name = "iomem_align",
1461 .alias = "mem_align",
1462 .type = FIO_OPT_INT,
1463 .off1 = td_var_offset(mem_align),
1464 .minval = 0,
1465 .help = "IO memory buffer offset alignment",
1466 .def = "0",
1467 .parent = "iomem",
1468 },
1469 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001470 .name = "verify",
1471 .type = FIO_OPT_STR,
1472 .off1 = td_var_offset(verify),
1473 .help = "Verify data written",
Jens Axboe5d7c5d32010-06-21 15:08:17 +02001474 .cb = str_verify_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001475 .def = "0",
1476 .posval = {
1477 { .ival = "0",
1478 .oval = VERIFY_NONE,
1479 .help = "Don't do IO verification",
1480 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001481 { .ival = "md5",
1482 .oval = VERIFY_MD5,
1483 .help = "Use md5 checksums for verification",
1484 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001485 { .ival = "crc64",
1486 .oval = VERIFY_CRC64,
1487 .help = "Use crc64 checksums for verification",
1488 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001489 { .ival = "crc32",
1490 .oval = VERIFY_CRC32,
1491 .help = "Use crc32 checksums for verification",
1492 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001493 { .ival = "crc32c-intel",
1494 .oval = VERIFY_CRC32C_INTEL,
1495 .help = "Use hw crc32c checksums for verification",
1496 },
Jens Axboebac39e02008-06-11 20:46:19 +02001497 { .ival = "crc32c",
1498 .oval = VERIFY_CRC32C,
1499 .help = "Use crc32c checksums for verification",
1500 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001501 { .ival = "crc16",
1502 .oval = VERIFY_CRC16,
1503 .help = "Use crc16 checksums for verification",
1504 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001505 { .ival = "crc7",
1506 .oval = VERIFY_CRC7,
1507 .help = "Use crc7 checksums for verification",
1508 },
Jens Axboe7c353ce2009-08-09 22:40:33 +02001509 { .ival = "sha1",
1510 .oval = VERIFY_SHA1,
1511 .help = "Use sha1 checksums for verification",
1512 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001513 { .ival = "sha256",
1514 .oval = VERIFY_SHA256,
1515 .help = "Use sha256 checksums for verification",
1516 },
1517 { .ival = "sha512",
1518 .oval = VERIFY_SHA512,
1519 .help = "Use sha512 checksums for verification",
1520 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001521 { .ival = "meta",
1522 .oval = VERIFY_META,
1523 .help = "Use io information",
1524 },
Jens Axboe36690c92007-03-26 10:23:34 +02001525 {
1526 .ival = "null",
1527 .oval = VERIFY_NULL,
1528 .help = "Pretend to verify",
1529 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001530 },
1531 },
1532 {
Jens Axboe005c5652007-08-02 22:21:36 +02001533 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001534 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001535 .off1 = td_var_offset(do_verify),
1536 .help = "Run verification stage after write",
1537 .def = "1",
1538 .parent = "verify",
1539 },
1540 {
Jens Axboe160b9662007-03-27 10:59:49 +02001541 .name = "verifysort",
1542 .type = FIO_OPT_BOOL,
1543 .off1 = td_var_offset(verifysort),
1544 .help = "Sort written verify blocks for read back",
1545 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001546 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001547 },
1548 {
Jens Axboea59e1702007-07-30 08:53:27 +02001549 .name = "verify_interval",
Jens Axboee01b22b2009-06-09 15:43:25 +02001550 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001551 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001552 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001553 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001554 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001555 },
1556 {
Jens Axboea59e1702007-07-30 08:53:27 +02001557 .name = "verify_offset",
Jens Axboee01b22b2009-06-09 15:43:25 +02001558 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001559 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001560 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001561 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001562 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001563 },
1564 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001565 .name = "verify_pattern",
Radha Ramachandran0e92f872009-10-27 20:14:27 +01001566 .type = FIO_OPT_STR,
Shawn Lewise28218f2008-01-16 11:01:33 +01001567 .cb = str_verify_pattern_cb,
1568 .help = "Fill pattern for IO buffers",
1569 .parent = "verify",
1570 },
1571 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001572 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001573 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001574 .off1 = td_var_offset(verify_fatal),
1575 .def = "0",
1576 .help = "Exit on a single verify failure, don't continue",
1577 .parent = "verify",
1578 },
1579 {
Jens Axboeb463e932011-01-12 09:03:23 +01001580 .name = "verify_dump",
1581 .type = FIO_OPT_BOOL,
1582 .off1 = td_var_offset(verify_dump),
1583 .def = "1",
1584 .help = "Dump contents of good and bad blocks on failure",
1585 .parent = "verify",
1586 },
1587 {
Jens Axboee8462bd2009-07-06 12:59:04 +02001588 .name = "verify_async",
1589 .type = FIO_OPT_INT,
1590 .off1 = td_var_offset(verify_async),
1591 .def = "0",
1592 .help = "Number of async verifier threads to use",
1593 .parent = "verify",
1594 },
Jens Axboe9e144182010-06-15 14:25:36 +02001595 {
1596 .name = "verify_backlog",
1597 .type = FIO_OPT_STR_VAL,
1598 .off1 = td_var_offset(verify_backlog),
1599 .help = "Verify after this number of blocks are written",
1600 .parent = "verify",
1601 },
1602 {
1603 .name = "verify_backlog_batch",
1604 .type = FIO_OPT_INT,
1605 .off1 = td_var_offset(verify_batch),
1606 .help = "Verify this number of IO blocks",
Jens Axboe0d29de82010-09-01 13:54:15 +02001607 .parent = "verify",
Jens Axboe9e144182010-06-15 14:25:36 +02001608 },
Jens Axboee8462bd2009-07-06 12:59:04 +02001609#ifdef FIO_HAVE_CPU_AFFINITY
1610 {
1611 .name = "verify_async_cpus",
1612 .type = FIO_OPT_STR,
1613 .cb = str_verify_cpus_allowed_cb,
1614 .help = "Set CPUs allowed for async verify threads",
1615 .parent = "verify_async",
1616 },
1617#endif
Jens Axboe0d29de82010-09-01 13:54:15 +02001618#ifdef FIO_HAVE_TRIM
1619 {
1620 .name = "trim_percentage",
1621 .type = FIO_OPT_INT,
1622 .cb = str_verify_trim_cb,
1623 .maxval = 100,
1624 .help = "Number of verify blocks to discard/trim",
1625 .parent = "verify",
1626 .def = "0",
1627 },
1628 {
1629 .name = "trim_verify_zero",
1630 .type = FIO_OPT_INT,
1631 .help = "Verify that trim/discarded blocks are returned as zeroes",
1632 .off1 = td_var_offset(trim_zero),
1633 .parent = "trim_percentage",
1634 .def = "1",
1635 },
1636 {
1637 .name = "trim_backlog",
1638 .type = FIO_OPT_STR_VAL,
1639 .off1 = td_var_offset(trim_backlog),
1640 .help = "Trim after this number of blocks are written",
1641 .parent = "trim_percentage",
1642 },
1643 {
1644 .name = "trim_backlog_batch",
1645 .type = FIO_OPT_INT,
1646 .off1 = td_var_offset(trim_batch),
1647 .help = "Trim this number of IO blocks",
1648 .parent = "trim_percentage",
1649 },
1650#endif
Jens Axboee8462bd2009-07-06 12:59:04 +02001651 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001652 .name = "write_iolog",
1653 .type = FIO_OPT_STR_STORE,
1654 .off1 = td_var_offset(write_iolog_file),
1655 .help = "Store IO pattern to file",
1656 },
1657 {
1658 .name = "read_iolog",
1659 .type = FIO_OPT_STR_STORE,
1660 .off1 = td_var_offset(read_iolog_file),
1661 .help = "Playback IO pattern from file",
1662 },
1663 {
David Nellans64bbb862010-08-24 22:13:30 +02001664 .name = "replay_no_stall",
1665 .type = FIO_OPT_INT,
1666 .off1 = td_var_offset(no_stall),
1667 .def = "0",
Jens Axboe87e7a972010-08-25 09:01:25 +02001668 .parent = "read_iolog",
David Nellans64bbb862010-08-24 22:13:30 +02001669 .help = "Playback IO pattern file as fast as possible without stalls",
1670 },
1671 {
David Nellansd1c46c02010-08-31 21:20:47 +02001672 .name = "replay_redirect",
1673 .type = FIO_OPT_STR_STORE,
1674 .off1 = td_var_offset(replay_redirect),
1675 .parent = "read_iolog",
1676 .help = "Replay all I/O onto this device, regardless of trace device",
1677 },
1678 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001679 .name = "exec_prerun",
1680 .type = FIO_OPT_STR_STORE,
1681 .off1 = td_var_offset(exec_prerun),
1682 .help = "Execute this file prior to running job",
1683 },
1684 {
1685 .name = "exec_postrun",
1686 .type = FIO_OPT_STR_STORE,
1687 .off1 = td_var_offset(exec_postrun),
1688 .help = "Execute this file after running job",
1689 },
1690#ifdef FIO_HAVE_IOSCHED_SWITCH
1691 {
1692 .name = "ioscheduler",
1693 .type = FIO_OPT_STR_STORE,
1694 .off1 = td_var_offset(ioscheduler),
1695 .help = "Use this IO scheduler on the backing device",
1696 },
1697#endif
1698 {
1699 .name = "zonesize",
1700 .type = FIO_OPT_STR_VAL,
1701 .off1 = td_var_offset(zone_size),
1702 .help = "Give size of an IO zone",
1703 .def = "0",
1704 },
1705 {
1706 .name = "zoneskip",
1707 .type = FIO_OPT_STR_VAL,
1708 .off1 = td_var_offset(zone_skip),
1709 .help = "Space between IO zones",
1710 .def = "0",
1711 },
1712 {
1713 .name = "lockmem",
1714 .type = FIO_OPT_STR_VAL,
1715 .cb = str_lockmem_cb,
1716 .help = "Lock down this amount of memory",
1717 .def = "0",
1718 },
1719 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001720 .name = "rwmixread",
1721 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001722 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001723 .maxval = 100,
1724 .help = "Percentage of mixed workload that is reads",
1725 .def = "50",
1726 },
1727 {
1728 .name = "rwmixwrite",
1729 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001730 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001731 .maxval = 100,
1732 .help = "Percentage of mixed workload that is writes",
1733 .def = "50",
1734 },
1735 {
Jens Axboeafdf9352007-07-31 16:14:34 +02001736 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02001737 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02001738 },
1739 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001740 .name = "nice",
1741 .type = FIO_OPT_INT,
1742 .off1 = td_var_offset(nice),
1743 .help = "Set job CPU nice value",
1744 .minval = -19,
1745 .maxval = 20,
1746 .def = "0",
1747 },
1748#ifdef FIO_HAVE_IOPRIO
1749 {
1750 .name = "prio",
1751 .type = FIO_OPT_INT,
1752 .cb = str_prio_cb,
1753 .help = "Set job IO priority value",
1754 .minval = 0,
1755 .maxval = 7,
1756 },
1757 {
1758 .name = "prioclass",
1759 .type = FIO_OPT_INT,
1760 .cb = str_prioclass_cb,
1761 .help = "Set job IO priority class",
1762 .minval = 0,
1763 .maxval = 3,
1764 },
1765#endif
1766 {
1767 .name = "thinktime",
1768 .type = FIO_OPT_INT,
1769 .off1 = td_var_offset(thinktime),
1770 .help = "Idle time between IO buffers (usec)",
1771 .def = "0",
1772 },
1773 {
1774 .name = "thinktime_spin",
1775 .type = FIO_OPT_INT,
1776 .off1 = td_var_offset(thinktime_spin),
1777 .help = "Start think time by spinning this amount (usec)",
1778 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02001779 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001780 },
1781 {
1782 .name = "thinktime_blocks",
1783 .type = FIO_OPT_INT,
1784 .off1 = td_var_offset(thinktime_blocks),
1785 .help = "IO buffer period between 'thinktime'",
1786 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02001787 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001788 },
1789 {
1790 .name = "rate",
Jens Axboee01b22b2009-06-09 15:43:25 +02001791 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001792 .off1 = td_var_offset(rate[0]),
1793 .off2 = td_var_offset(rate[1]),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001794 .help = "Set bandwidth rate",
1795 },
1796 {
1797 .name = "ratemin",
Jens Axboee01b22b2009-06-09 15:43:25 +02001798 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001799 .off1 = td_var_offset(ratemin[0]),
1800 .off2 = td_var_offset(ratemin[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001801 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001802 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01001803 },
1804 {
1805 .name = "rate_iops",
Jens Axboee01b22b2009-06-09 15:43:25 +02001806 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001807 .off1 = td_var_offset(rate_iops[0]),
1808 .off2 = td_var_offset(rate_iops[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001809 .help = "Limit IO used to this number of IO operations/sec",
1810 },
1811 {
1812 .name = "rate_iops_min",
Jens Axboee01b22b2009-06-09 15:43:25 +02001813 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001814 .off1 = td_var_offset(rate_iops_min[0]),
1815 .off2 = td_var_offset(rate_iops_min[1]),
Bruce Cran03e20d62011-01-02 20:14:54 +01001816 .help = "Job must meet this rate or it will be shut down",
Jens Axboeafdf9352007-07-31 16:14:34 +02001817 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001818 },
1819 {
1820 .name = "ratecycle",
1821 .type = FIO_OPT_INT,
1822 .off1 = td_var_offset(ratecycle),
1823 .help = "Window average for rate limits (msec)",
1824 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02001825 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001826 },
1827 {
1828 .name = "invalidate",
1829 .type = FIO_OPT_BOOL,
1830 .off1 = td_var_offset(invalidate_cache),
1831 .help = "Invalidate buffer/page cache prior to running job",
1832 .def = "1",
1833 },
1834 {
1835 .name = "sync",
1836 .type = FIO_OPT_BOOL,
1837 .off1 = td_var_offset(sync_io),
1838 .help = "Use O_SYNC for buffered writes",
1839 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02001840 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001841 },
1842 {
1843 .name = "bwavgtime",
1844 .type = FIO_OPT_INT,
1845 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001846 .help = "Time window over which to calculate bandwidth"
1847 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001848 .def = "500",
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001849 .parent = "write_bw_log",
1850 },
1851 {
1852 .name = "iopsavgtime",
1853 .type = FIO_OPT_INT,
1854 .off1 = td_var_offset(iops_avg_time),
1855 .help = "Time window over which to calculate IOPS (msec)",
1856 .def = "500",
1857 .parent = "write_iops_log",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001858 },
1859 {
1860 .name = "create_serialize",
1861 .type = FIO_OPT_BOOL,
1862 .off1 = td_var_offset(create_serialize),
1863 .help = "Serialize creating of job files",
1864 .def = "1",
1865 },
1866 {
1867 .name = "create_fsync",
1868 .type = FIO_OPT_BOOL,
1869 .off1 = td_var_offset(create_fsync),
Bruce Cran03e20d62011-01-02 20:14:54 +01001870 .help = "fsync file after creation",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001871 .def = "1",
1872 },
1873 {
Jens Axboe814452b2009-03-04 12:53:13 +01001874 .name = "create_on_open",
1875 .type = FIO_OPT_BOOL,
1876 .off1 = td_var_offset(create_on_open),
1877 .help = "Create files when they are opened for IO",
1878 .def = "0",
1879 },
Jens Axboe0b9d69e2009-09-11 22:29:54 +02001880 {
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001881 .name = "pre_read",
1882 .type = FIO_OPT_BOOL,
1883 .off1 = td_var_offset(pre_read),
Bruce Cran03e20d62011-01-02 20:14:54 +01001884 .help = "Pre-read files before starting official testing",
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001885 .def = "0",
1886 },
Jens Axboe814452b2009-03-04 12:53:13 +01001887 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001888 .name = "cpuload",
1889 .type = FIO_OPT_INT,
1890 .off1 = td_var_offset(cpuload),
1891 .help = "Use this percentage of CPU",
1892 },
1893 {
1894 .name = "cpuchunks",
1895 .type = FIO_OPT_INT,
1896 .off1 = td_var_offset(cpucycle),
1897 .help = "Length of the CPU burn cycles (usecs)",
1898 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02001899 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001900 },
1901#ifdef FIO_HAVE_CPU_AFFINITY
1902 {
1903 .name = "cpumask",
1904 .type = FIO_OPT_INT,
1905 .cb = str_cpumask_cb,
1906 .help = "CPU affinity mask",
1907 },
Jens Axboed2e268b2007-06-15 10:33:49 +02001908 {
1909 .name = "cpus_allowed",
1910 .type = FIO_OPT_STR,
1911 .cb = str_cpus_allowed_cb,
1912 .help = "Set CPUs allowed",
1913 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001914#endif
1915 {
1916 .name = "end_fsync",
1917 .type = FIO_OPT_BOOL,
1918 .off1 = td_var_offset(end_fsync),
1919 .help = "Include fsync at the end of job",
1920 .def = "0",
1921 },
1922 {
1923 .name = "fsync_on_close",
1924 .type = FIO_OPT_BOOL,
1925 .off1 = td_var_offset(fsync_on_close),
1926 .help = "fsync files on close",
1927 .def = "0",
1928 },
1929 {
1930 .name = "unlink",
1931 .type = FIO_OPT_BOOL,
1932 .off1 = td_var_offset(unlink),
1933 .help = "Unlink created files after job has completed",
1934 .def = "0",
1935 },
1936 {
1937 .name = "exitall",
1938 .type = FIO_OPT_STR_SET,
1939 .cb = str_exitall_cb,
1940 .help = "Terminate all jobs when one exits",
1941 },
1942 {
1943 .name = "stonewall",
Jens Axboed3923652011-08-03 12:38:39 +02001944 .alias = "wait_for_previous",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001945 .type = FIO_OPT_STR_SET,
1946 .off1 = td_var_offset(stonewall),
1947 .help = "Insert a hard barrier between this job and previous",
1948 },
1949 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01001950 .name = "new_group",
1951 .type = FIO_OPT_STR_SET,
1952 .off1 = td_var_offset(new_group),
1953 .help = "Mark the start of a new group (for reporting)",
1954 },
1955 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001956 .name = "thread",
1957 .type = FIO_OPT_STR_SET,
1958 .off1 = td_var_offset(use_thread),
1959 .help = "Use threads instead of forks",
1960 },
1961 {
1962 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001963 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001964 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001965 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001966 .help = "Write log of bandwidth during run",
1967 },
1968 {
1969 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001970 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001971 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001972 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001973 .help = "Write log of latency during run",
1974 },
1975 {
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001976 .name = "write_iops_log",
1977 .type = FIO_OPT_STR,
1978 .off1 = td_var_offset(write_iops_log),
1979 .cb = str_write_iops_log_cb,
1980 .help = "Write log of IOPS during run",
1981 },
1982 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001983 .name = "hugepage-size",
Jens Axboee01b22b2009-06-09 15:43:25 +02001984 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001985 .off1 = td_var_offset(hugepage_size),
1986 .help = "When using hugepages, specify size of each page",
Jens Axboe81179ee2011-10-04 12:42:06 +02001987 .def = __fio_stringify(FIO_HUGE_PAGE),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001988 },
1989 {
1990 .name = "group_reporting",
1991 .type = FIO_OPT_STR_SET,
1992 .off1 = td_var_offset(group_reporting),
1993 .help = "Do reporting on a per-group basis",
1994 },
1995 {
Jens Axboee9459e52007-04-17 15:46:32 +02001996 .name = "zero_buffers",
1997 .type = FIO_OPT_STR_SET,
1998 .off1 = td_var_offset(zero_buffers),
1999 .help = "Init IO buffers to all zeroes",
2000 },
Jens Axboe5973caf2008-05-21 19:52:35 +02002001 {
2002 .name = "refill_buffers",
2003 .type = FIO_OPT_STR_SET,
2004 .off1 = td_var_offset(refill_buffers),
2005 .help = "Refill IO buffers on every IO submit",
2006 },
Yu-ju Hong83349192011-08-13 00:53:44 +02002007 {
Jens Axboefd684182011-09-19 09:24:44 +02002008 .name = "scramble_buffers",
2009 .type = FIO_OPT_BOOL,
2010 .off1 = td_var_offset(scramble_buffers),
2011 .help = "Slightly scramble buffers on every IO submit",
2012 .def = "1",
2013 },
2014 {
Yu-ju Hong83349192011-08-13 00:53:44 +02002015 .name = "clat_percentiles",
2016 .type = FIO_OPT_BOOL,
2017 .off1 = td_var_offset(clat_percentiles),
2018 .help = "Enable the reporting of completion latency percentiles",
Jens Axboe467b35e2011-10-13 08:53:24 +02002019 .def = "1",
Yu-ju Hong83349192011-08-13 00:53:44 +02002020 },
2021 {
2022 .name = "percentile_list",
2023 .type = FIO_OPT_FLOAT_LIST,
2024 .off1 = td_var_offset(percentile_list),
2025 .off2 = td_var_offset(overwrite_plist),
2026 .help = "Specify a custom list of percentiles to report",
2027 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2028 .minfp = 0.0,
2029 .maxfp = 100.0,
2030 },
2031
Jens Axboe0a839f32007-04-26 09:02:34 +02002032#ifdef FIO_HAVE_DISK_UTIL
2033 {
2034 .name = "disk_util",
2035 .type = FIO_OPT_BOOL,
2036 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02002037 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02002038 .def = "1",
2039 },
2040#endif
Jens Axboee9459e52007-04-17 15:46:32 +02002041 {
Jens Axboe993bf482008-11-14 13:04:53 +01002042 .name = "gtod_reduce",
2043 .type = FIO_OPT_BOOL,
2044 .help = "Greatly reduce number of gettimeofday() calls",
2045 .cb = str_gtod_reduce_cb,
2046 .def = "0",
2047 },
2048 {
Jens Axboe02af0982010-06-24 09:59:34 +02002049 .name = "disable_lat",
2050 .type = FIO_OPT_BOOL,
2051 .off1 = td_var_offset(disable_lat),
2052 .help = "Disable latency numbers",
2053 .parent = "gtod_reduce",
2054 .def = "0",
2055 },
2056 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02002057 .name = "disable_clat",
2058 .type = FIO_OPT_BOOL,
2059 .off1 = td_var_offset(disable_clat),
2060 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002061 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002062 .def = "0",
2063 },
2064 {
2065 .name = "disable_slat",
2066 .type = FIO_OPT_BOOL,
2067 .off1 = td_var_offset(disable_slat),
Bruce Cran03e20d62011-01-02 20:14:54 +01002068 .help = "Disable submission latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002069 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002070 .def = "0",
2071 },
2072 {
2073 .name = "disable_bw_measurement",
2074 .type = FIO_OPT_BOOL,
2075 .off1 = td_var_offset(disable_bw),
2076 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01002077 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002078 .def = "0",
2079 },
2080 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002081 .name = "gtod_cpu",
2082 .type = FIO_OPT_INT,
2083 .cb = str_gtod_cpu_cb,
Bruce Cran03e20d62011-01-02 20:14:54 +01002084 .help = "Set up dedicated gettimeofday() thread on this CPU",
Jens Axboe29d43ff2009-07-01 10:42:18 +02002085 .verify = gtod_cpu_verify,
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002086 },
2087 {
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002088 .name = "continue_on_error",
2089 .type = FIO_OPT_BOOL,
2090 .off1 = td_var_offset(continue_on_error),
Bruce Cran03e20d62011-01-02 20:14:54 +01002091 .help = "Continue on non-fatal errors during IO",
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002092 .def = "0",
2093 },
2094 {
Jens Axboe9ac8a792009-11-13 21:23:07 +01002095 .name = "profile",
Jens Axboe79d16312010-03-04 12:43:20 +01002096 .type = FIO_OPT_STR_STORE,
Jens Axboe9ac8a792009-11-13 21:23:07 +01002097 .off1 = td_var_offset(profile),
Jens Axboe9ac8a792009-11-13 21:23:07 +01002098 .help = "Select a specific builtin performance test",
2099 },
2100 {
Jens Axboea696fa22009-12-04 10:05:02 +01002101 .name = "cgroup",
2102 .type = FIO_OPT_STR_STORE,
2103 .off1 = td_var_offset(cgroup),
2104 .help = "Add job to cgroup of this name",
2105 },
2106 {
2107 .name = "cgroup_weight",
2108 .type = FIO_OPT_INT,
2109 .off1 = td_var_offset(cgroup_weight),
2110 .help = "Use given weight for cgroup",
2111 .minval = 100,
2112 .maxval = 1000,
Jens Axboea696fa22009-12-04 10:05:02 +01002113 },
2114 {
Vivek Goyal7de87092010-03-31 22:55:15 +02002115 .name = "cgroup_nodelete",
2116 .type = FIO_OPT_BOOL,
2117 .off1 = td_var_offset(cgroup_nodelete),
2118 .help = "Do not delete cgroups after job completion",
2119 .def = "0",
2120 },
2121 {
Jens Axboee0b0d892009-12-08 10:10:14 +01002122 .name = "uid",
2123 .type = FIO_OPT_INT,
2124 .off1 = td_var_offset(uid),
2125 .help = "Run job with this user ID",
2126 },
2127 {
2128 .name = "gid",
2129 .type = FIO_OPT_INT,
2130 .off1 = td_var_offset(gid),
2131 .help = "Run job with this group ID",
2132 },
2133 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002134 .name = NULL,
2135 },
2136};
2137
Jens Axboe17af15d2010-04-13 10:38:16 +02002138static void add_to_lopt(struct option *lopt, struct fio_option *o,
2139 const char *name)
Jens Axboe9f817362010-03-04 14:38:10 +01002140{
Jens Axboe17af15d2010-04-13 10:38:16 +02002141 lopt->name = (char *) name;
Jens Axboe9f817362010-03-04 14:38:10 +01002142 lopt->val = FIO_GETOPT_JOB;
2143 if (o->type == FIO_OPT_STR_SET)
2144 lopt->has_arg = no_argument;
2145 else
2146 lopt->has_arg = required_argument;
2147}
2148
Jens Axboe214e1ec2007-03-15 10:48:13 +01002149void fio_options_dup_and_init(struct option *long_options)
2150{
2151 struct fio_option *o;
2152 unsigned int i;
2153
2154 options_init(options);
2155
2156 i = 0;
2157 while (long_options[i].name)
2158 i++;
2159
2160 o = &options[0];
2161 while (o->name) {
Jens Axboe17af15d2010-04-13 10:38:16 +02002162 add_to_lopt(&long_options[i], o, o->name);
2163 if (o->alias) {
2164 i++;
2165 add_to_lopt(&long_options[i], o, o->alias);
2166 }
Jens Axboe214e1ec2007-03-15 10:48:13 +01002167
2168 i++;
2169 o++;
2170 assert(i < FIO_NR_OPTIONS);
2171 }
2172}
2173
Jens Axboe74929ac2009-08-05 11:42:37 +02002174struct fio_keyword {
2175 const char *word;
2176 const char *desc;
2177 char *replace;
2178};
2179
2180static struct fio_keyword fio_keywords[] = {
2181 {
2182 .word = "$pagesize",
2183 .desc = "Page size in the system",
2184 },
2185 {
2186 .word = "$mb_memory",
2187 .desc = "Megabytes of memory online",
2188 },
2189 {
2190 .word = "$ncpus",
2191 .desc = "Number of CPUs online in the system",
2192 },
2193 {
2194 .word = NULL,
2195 },
2196};
2197
2198void fio_keywords_init(void)
2199{
Jens Axboe3b2e1462009-12-15 08:58:10 +01002200 unsigned long long mb_memory;
Jens Axboe74929ac2009-08-05 11:42:37 +02002201 char buf[128];
2202 long l;
2203
2204 sprintf(buf, "%lu", page_size);
2205 fio_keywords[0].replace = strdup(buf);
2206
Jens Axboe8eb016d2011-07-11 10:24:20 +02002207 mb_memory = os_phys_mem() / (1024 * 1024);
Jens Axboe3b2e1462009-12-15 08:58:10 +01002208 sprintf(buf, "%llu", mb_memory);
Jens Axboe74929ac2009-08-05 11:42:37 +02002209 fio_keywords[1].replace = strdup(buf);
2210
Jens Axboec00a2282011-07-08 20:56:06 +02002211 l = cpus_online();
Jens Axboe74929ac2009-08-05 11:42:37 +02002212 sprintf(buf, "%lu", l);
2213 fio_keywords[2].replace = strdup(buf);
2214}
2215
Jens Axboe892a6ff2009-11-13 12:19:49 +01002216#define BC_APP "bc"
2217
2218static char *bc_calc(char *str)
2219{
2220 char *buf, *tmp, opt[80];
2221 FILE *f;
2222 int ret;
2223
2224 /*
2225 * No math, just return string
2226 */
2227 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2228 !strchr(str, '/'))
2229 return str;
2230
2231 /*
2232 * Split option from value, we only need to calculate the value
2233 */
2234 tmp = strchr(str, '=');
2235 if (!tmp)
2236 return str;
2237
2238 tmp++;
Jens Axboe9ac8a792009-11-13 21:23:07 +01002239 memset(opt, 0, sizeof(opt));
Jens Axboe892a6ff2009-11-13 12:19:49 +01002240 strncpy(opt, str, tmp - str);
2241
2242 buf = malloc(128);
2243
2244 sprintf(buf, "which %s > /dev/null", BC_APP);
2245 if (system(buf)) {
2246 log_err("fio: bc is needed for performing math\n");
2247 free(buf);
2248 return NULL;
2249 }
2250
2251 sprintf(buf, "echo %s | %s", tmp, BC_APP);
2252 f = popen(buf, "r");
2253 if (!f) {
2254 free(buf);
2255 return NULL;
2256 }
2257
2258 ret = fread(buf, 1, 128, f);
2259 if (ret <= 0) {
2260 free(buf);
2261 return NULL;
2262 }
2263
2264 buf[ret - 1] = '\0';
2265 strcat(opt, buf);
2266 strcpy(buf, opt);
2267 pclose(f);
2268 free(str);
2269 return buf;
2270}
2271
Jens Axboe74929ac2009-08-05 11:42:37 +02002272/*
2273 * Look for reserved variable names and replace them with real values
2274 */
2275static char *fio_keyword_replace(char *opt)
2276{
2277 char *s;
2278 int i;
2279
2280 for (i = 0; fio_keywords[i].word != NULL; i++) {
2281 struct fio_keyword *kw = &fio_keywords[i];
2282
2283 while ((s = strstr(opt, kw->word)) != NULL) {
2284 char *new = malloc(strlen(opt) + 1);
2285 char *o_org = opt;
2286 int olen = s - opt;
2287 int len;
2288
2289 /*
2290 * Copy part of the string before the keyword and
2291 * sprintf() the replacement after it.
2292 */
2293 memcpy(new, opt, olen);
2294 len = sprintf(new + olen, "%s", kw->replace);
2295
2296 /*
2297 * If there's more in the original string, copy that
2298 * in too
2299 */
2300 opt += strlen(kw->word) + olen;
2301 if (strlen(opt))
2302 memcpy(new + olen + len, opt, opt - o_org - 1);
2303
2304 /*
2305 * replace opt and free the old opt
2306 */
2307 opt = new;
Jens Axboe9ac8a792009-11-13 21:23:07 +01002308 //free(o_org);
Jens Axboe7a958bd2009-11-13 12:33:54 +01002309
2310 /*
2311 * Check for potential math and invoke bc, if possible
2312 */
2313 opt = bc_calc(opt);
Jens Axboe74929ac2009-08-05 11:42:37 +02002314 }
2315 }
2316
Jens Axboe7a958bd2009-11-13 12:33:54 +01002317 return opt;
Jens Axboe74929ac2009-08-05 11:42:37 +02002318}
2319
Jens Axboe3b8b7132008-06-10 19:46:23 +02002320int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01002321{
Jens Axboe3b8b7132008-06-10 19:46:23 +02002322 int i, ret;
2323
2324 sort_options(opts, options, num_opts);
2325
Jens Axboe74929ac2009-08-05 11:42:37 +02002326 for (ret = 0, i = 0; i < num_opts; i++) {
2327 opts[i] = fio_keyword_replace(opts[i]);
Jens Axboe07b32322010-03-05 09:48:44 +01002328 ret |= parse_option(opts[i], options, td);
Jens Axboe74929ac2009-08-05 11:42:37 +02002329 }
Jens Axboe3b8b7132008-06-10 19:46:23 +02002330
2331 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01002332}
2333
2334int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2335{
Jens Axboe07b32322010-03-05 09:48:44 +01002336 return parse_cmd_option(opt, val, options, td);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002337}
2338
2339void fio_fill_default_options(struct thread_data *td)
2340{
2341 fill_default_options(td, options);
2342}
2343
2344int fio_show_option_help(const char *opt)
2345{
Jens Axboe07b32322010-03-05 09:48:44 +01002346 return show_cmd_help(options, opt);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002347}
Jens Axboed23bb322007-03-23 15:57:56 +01002348
2349static void __options_mem(struct thread_data *td, int alloc)
2350{
2351 struct thread_options *o = &td->o;
2352 struct fio_option *opt;
2353 char **ptr;
2354 int i;
2355
2356 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2357 if (opt->type != FIO_OPT_STR_STORE)
2358 continue;
2359
2360 ptr = (void *) o + opt->off1;
2361 if (*ptr) {
2362 if (alloc)
2363 *ptr = strdup(*ptr);
2364 else {
2365 free(*ptr);
2366 *ptr = NULL;
2367 }
2368 }
2369 }
2370}
2371
2372/*
2373 * dupe FIO_OPT_STR_STORE options
2374 */
2375void options_mem_dupe(struct thread_data *td)
2376{
2377 __options_mem(td, 1);
2378}
2379
Jens Axboe22d66212007-03-27 20:06:25 +02002380void options_mem_free(struct thread_data fio_unused *td)
Jens Axboed23bb322007-03-23 15:57:56 +01002381{
Jens Axboe22d66212007-03-27 20:06:25 +02002382#if 0
Jens Axboed23bb322007-03-23 15:57:56 +01002383 __options_mem(td, 0);
Jens Axboe22d66212007-03-27 20:06:25 +02002384#endif
Jens Axboed23bb322007-03-23 15:57:56 +01002385}
Jens Axboed6978a32009-07-18 21:04:09 +02002386
2387unsigned int fio_get_kb_base(void *data)
2388{
2389 struct thread_data *td = data;
2390 unsigned int kb_base = 0;
2391
2392 if (td)
2393 kb_base = td->o.kb_base;
2394 if (!kb_base)
2395 kb_base = 1024;
2396
2397 return kb_base;
2398}
Jens Axboe9f988e22010-03-04 10:42:38 +01002399
Jens Axboe07b32322010-03-05 09:48:44 +01002400int add_option(struct fio_option *o)
Jens Axboe9f988e22010-03-04 10:42:38 +01002401{
Jens Axboe07b32322010-03-05 09:48:44 +01002402 struct fio_option *__o;
2403 int opt_index = 0;
2404
2405 __o = options;
2406 while (__o->name) {
2407 opt_index++;
2408 __o++;
2409 }
2410
2411 memcpy(&options[opt_index], o, sizeof(*o));
2412 return 0;
Jens Axboe9f988e22010-03-04 10:42:38 +01002413}
Jens Axboee2de69d2010-03-04 14:05:48 +01002414
Jens Axboe07b32322010-03-05 09:48:44 +01002415void invalidate_profile_options(const char *prof_name)
Jens Axboee2de69d2010-03-04 14:05:48 +01002416{
Jens Axboe07b32322010-03-05 09:48:44 +01002417 struct fio_option *o;
Jens Axboee2de69d2010-03-04 14:05:48 +01002418
Jens Axboe07b32322010-03-05 09:48:44 +01002419 o = options;
2420 while (o->name) {
2421 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2422 o->type = FIO_OPT_INVALID;
2423 o->prof_name = NULL;
2424 }
2425 o++;
Jens Axboee2de69d2010-03-04 14:05:48 +01002426 }
2427}
Jens Axboef5b6bb82010-03-05 10:09:59 +01002428
2429void add_opt_posval(const char *optname, const char *ival, const char *help)
2430{
2431 struct fio_option *o;
2432 unsigned int i;
2433
2434 o = find_option(options, optname);
2435 if (!o)
2436 return;
2437
2438 for (i = 0; i < PARSE_MAX_VP; i++) {
2439 if (o->posval[i].ival)
2440 continue;
2441
2442 o->posval[i].ival = ival;
2443 o->posval[i].help = help;
2444 break;
2445 }
2446}
2447
2448void del_opt_posval(const char *optname, const char *ival)
2449{
2450 struct fio_option *o;
2451 unsigned int i;
2452
2453 o = find_option(options, optname);
2454 if (!o)
2455 return;
2456
2457 for (i = 0; i < PARSE_MAX_VP; i++) {
2458 if (!o->posval[i].ival)
2459 continue;
2460 if (strcmp(o->posval[i].ival, ival))
2461 continue;
2462
2463 o->posval[i].ival = NULL;
2464 o->posval[i].help = NULL;
2465 }
2466}