blob: 84bf5ac345ccdda9d1ccf7f66d7a90beb57b0c94 [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;
Jens Axboe0dc1bc02011-10-13 08:55:29 +0200780 td->o.clat_percentiles = !val;
Jens Axboe993bf482008-11-14 13:04:53 +0100781 if (val)
782 td->tv_cache_mask = 63;
783
784 return 0;
785}
786
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400787static int str_gtod_cpu_cb(void *data, long long *il)
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100788{
789 struct thread_data *td = data;
790 int val = *il;
791
792 td->o.gtod_cpu = val;
793 td->o.gtod_offload = 1;
794 return 0;
795}
796
Jens Axboe7bb59102011-07-12 19:47:03 +0200797static int str_size_cb(void *data, unsigned long long *__val)
798{
799 struct thread_data *td = data;
800 unsigned long long v = *__val;
801
802 if (parse_is_percent(v)) {
803 td->o.size = 0;
804 td->o.size_percent = -1ULL - v;
805 } else
806 td->o.size = v;
807
808 return 0;
809}
810
Jens Axboe896cac22009-07-01 10:38:35 +0200811static int rw_verify(struct fio_option *o, void *data)
812{
813 struct thread_data *td = data;
814
815 if (read_only && td_write(td)) {
816 log_err("fio: job <%s> has write bit set, but fio is in"
817 " read-only mode\n", td->o.name);
818 return 1;
819 }
820
821 return 0;
822}
823
Jens Axboe276ca4f2009-07-01 10:43:05 +0200824static int gtod_cpu_verify(struct fio_option *o, void *data)
Jens Axboe29d43ff2009-07-01 10:42:18 +0200825{
Jens Axboe276ca4f2009-07-01 10:43:05 +0200826#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboe29d43ff2009-07-01 10:42:18 +0200827 struct thread_data *td = data;
828
Jens Axboe29d43ff2009-07-01 10:42:18 +0200829 if (td->o.gtod_cpu) {
830 log_err("fio: platform must support CPU affinity for"
831 "gettimeofday() offloading\n");
832 return 1;
833 }
834#endif
835
836 return 0;
837}
838
Jens Axboe90fef2d2009-07-17 22:33:32 +0200839static int kb_base_verify(struct fio_option *o, void *data)
840{
841 struct thread_data *td = data;
842
843 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
844 log_err("fio: kb_base set to nonsensical value: %u\n",
845 td->o.kb_base);
846 return 1;
847 }
848
849 return 0;
850}
851
Jens Axboe214e1ec2007-03-15 10:48:13 +0100852/*
853 * Map of job/command line options
854 */
Jens Axboe07b32322010-03-05 09:48:44 +0100855static struct fio_option options[FIO_MAX_OPTS] = {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100856 {
857 .name = "description",
858 .type = FIO_OPT_STR_STORE,
859 .off1 = td_var_offset(description),
860 .help = "Text job description",
861 },
862 {
863 .name = "name",
864 .type = FIO_OPT_STR_STORE,
865 .off1 = td_var_offset(name),
866 .help = "Name of this job",
867 },
868 {
869 .name = "directory",
870 .type = FIO_OPT_STR_STORE,
871 .off1 = td_var_offset(directory),
872 .cb = str_directory_cb,
873 .help = "Directory to store files in",
874 },
875 {
876 .name = "filename",
877 .type = FIO_OPT_STR_STORE,
878 .off1 = td_var_offset(filename),
879 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +0200880 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +0100881 .help = "File(s) to use for the workload",
882 },
883 {
Jens Axboe0fd666b2011-10-06 20:08:53 +0200884 .name = "hostname",
885 .type = FIO_OPT_STR_STORE,
886 .cb = str_hostname_cb,
887 .help = "Hostname for net IO engine",
888 },
889 {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200890 .name = "kb_base",
891 .type = FIO_OPT_INT,
892 .off1 = td_var_offset(kb_base),
Jens Axboe90fef2d2009-07-17 22:33:32 +0200893 .verify = kb_base_verify,
Jens Axboea639f0b2009-07-18 08:25:35 +0200894 .prio = 1,
Jens Axboe90fef2d2009-07-17 22:33:32 +0200895 .def = "1024",
Jens Axboea639f0b2009-07-18 08:25:35 +0200896 .help = "How many bytes per KB for reporting (1000 or 1024)",
Jens Axboe90fef2d2009-07-17 22:33:32 +0200897 },
898 {
Jens Axboe29c13492008-03-01 19:25:20 +0100899 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100900 .type = FIO_OPT_STR,
901 .cb = str_lockfile_cb,
902 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +0100903 .help = "Lock file when doing IO to it",
904 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100905 .def = "none",
906 .posval = {
907 { .ival = "none",
908 .oval = FILE_LOCK_NONE,
909 .help = "No file locking",
910 },
911 { .ival = "exclusive",
912 .oval = FILE_LOCK_EXCLUSIVE,
913 .help = "Exclusive file lock",
914 },
915 {
916 .ival = "readwrite",
917 .oval = FILE_LOCK_READWRITE,
918 .help = "Read vs write lock",
919 },
920 },
Jens Axboe29c13492008-03-01 19:25:20 +0100921 },
922 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100923 .name = "opendir",
924 .type = FIO_OPT_STR_STORE,
925 .off1 = td_var_offset(opendir),
926 .cb = str_opendir_cb,
927 .help = "Recursively add files from this directory and down",
928 },
929 {
930 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100931 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100932 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +0100933 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100934 .off1 = td_var_offset(td_ddir),
935 .help = "IO direction",
936 .def = "read",
Jens Axboe896cac22009-07-01 10:38:35 +0200937 .verify = rw_verify,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100938 .posval = {
939 { .ival = "read",
940 .oval = TD_DDIR_READ,
941 .help = "Sequential read",
942 },
943 { .ival = "write",
944 .oval = TD_DDIR_WRITE,
945 .help = "Sequential write",
946 },
947 { .ival = "randread",
948 .oval = TD_DDIR_RANDREAD,
949 .help = "Random read",
950 },
951 { .ival = "randwrite",
952 .oval = TD_DDIR_RANDWRITE,
953 .help = "Random write",
954 },
955 { .ival = "rw",
956 .oval = TD_DDIR_RW,
957 .help = "Sequential read and write mix",
958 },
959 { .ival = "randrw",
960 .oval = TD_DDIR_RANDRW,
961 .help = "Random read and write mix"
962 },
963 },
964 },
965 {
Jens Axboe38dad622010-07-20 14:46:00 -0600966 .name = "rw_sequencer",
967 .type = FIO_OPT_STR,
968 .off1 = td_var_offset(rw_seq),
969 .help = "IO offset generator modifier",
970 .def = "sequential",
971 .posval = {
972 { .ival = "sequential",
973 .oval = RW_SEQ_SEQ,
974 .help = "Generate sequential offsets",
975 },
976 { .ival = "identical",
977 .oval = RW_SEQ_IDENT,
978 .help = "Generate identical offsets",
979 },
980 },
981 },
982
983 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100984 .name = "ioengine",
985 .type = FIO_OPT_STR_STORE,
986 .off1 = td_var_offset(ioengine),
987 .help = "IO engine to use",
Jens Axboe58483fa2011-01-19 11:09:58 -0700988 .def = FIO_PREFERRED_ENGINE,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100989 .posval = {
990 { .ival = "sync",
991 .help = "Use read/write",
992 },
gurudas paia31041e2007-10-23 15:12:30 +0200993 { .ival = "psync",
994 .help = "Use pread/pwrite",
995 },
Jens Axboe1d2af022008-02-04 10:59:07 +0100996 { .ival = "vsync",
Bruce Cran03e20d62011-01-02 20:14:54 +0100997 .help = "Use readv/writev",
Jens Axboe1d2af022008-02-04 10:59:07 +0100998 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100999#ifdef FIO_HAVE_LIBAIO
1000 { .ival = "libaio",
1001 .help = "Linux native asynchronous IO",
Jens Axboec44b1ff2011-08-30 20:43:53 -06001002 .cb = str_libaio_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001003 },
1004#endif
1005#ifdef FIO_HAVE_POSIXAIO
1006 { .ival = "posixaio",
1007 .help = "POSIX asynchronous IO",
1008 },
1009#endif
Jens Axboe417f0062008-06-02 11:59:30 +02001010#ifdef FIO_HAVE_SOLARISAIO
1011 { .ival = "solarisaio",
1012 .help = "Solaris native asynchronous IO",
1013 },
1014#endif
Bruce Cran03e20d62011-01-02 20:14:54 +01001015#ifdef FIO_HAVE_WINDOWSAIO
1016 { .ival = "windowsaio",
Jens Axboe3be80072011-01-19 11:07:28 -07001017 .help = "Windows native asynchronous IO"
Bruce Cran03e20d62011-01-02 20:14:54 +01001018 },
Jens Axboe3be80072011-01-19 11:07:28 -07001019#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001020 { .ival = "mmap",
Bruce Cran03e20d62011-01-02 20:14:54 +01001021 .help = "Memory mapped IO"
Jens Axboe214e1ec2007-03-15 10:48:13 +01001022 },
1023#ifdef FIO_HAVE_SPLICE
1024 { .ival = "splice",
1025 .help = "splice/vmsplice based IO",
1026 },
Jens Axboe9cce02e2007-06-22 15:42:21 +02001027 { .ival = "netsplice",
1028 .help = "splice/vmsplice to/from the network",
1029 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001030#endif
1031#ifdef FIO_HAVE_SGIO
1032 { .ival = "sg",
1033 .help = "SCSI generic v3 IO",
1034 },
1035#endif
1036 { .ival = "null",
1037 .help = "Testing engine (no data transfer)",
1038 },
1039 { .ival = "net",
1040 .help = "Network IO",
1041 },
1042#ifdef FIO_HAVE_SYSLET
1043 { .ival = "syslet-rw",
1044 .help = "syslet enabled async pread/pwrite IO",
1045 },
1046#endif
1047 { .ival = "cpuio",
Bruce Cran03e20d62011-01-02 20:14:54 +01001048 .help = "CPU cycle burner engine",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001049 },
Jens Axboeb8c82a42007-03-21 08:48:26 +01001050#ifdef FIO_HAVE_GUASI
1051 { .ival = "guasi",
1052 .help = "GUASI IO engine",
1053 },
1054#endif
Jens Axboe79a43182010-09-07 13:28:58 +02001055#ifdef FIO_HAVE_BINJECT
1056 { .ival = "binject",
1057 .help = "binject direct inject block engine",
1058 },
1059#endif
ren yufei21b8aee2011-08-01 10:01:57 +02001060#ifdef FIO_HAVE_RDMA
1061 { .ival = "rdma",
1062 .help = "RDMA IO engine",
1063 },
1064#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001065 { .ival = "external",
1066 .help = "Load external engine (append name)",
1067 },
1068 },
1069 },
1070 {
1071 .name = "iodepth",
1072 .type = FIO_OPT_INT,
1073 .off1 = td_var_offset(iodepth),
Bruce Cran03e20d62011-01-02 20:14:54 +01001074 .help = "Number of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +01001075 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001076 .def = "1",
1077 },
1078 {
1079 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +02001080 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001081 .type = FIO_OPT_INT,
1082 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +01001083 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +02001084 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +01001085 .minval = 1,
1086 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001087 },
1088 {
Jens Axboe49504212008-06-05 09:03:30 +02001089 .name = "iodepth_batch_complete",
1090 .type = FIO_OPT_INT,
1091 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +01001092 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +02001093 .parent = "iodepth",
1094 .minval = 0,
1095 .def = "1",
1096 },
1097 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001098 .name = "iodepth_low",
1099 .type = FIO_OPT_INT,
1100 .off1 = td_var_offset(iodepth_low),
1101 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +02001102 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001103 },
1104 {
1105 .name = "size",
1106 .type = FIO_OPT_STR_VAL,
Jens Axboe7bb59102011-07-12 19:47:03 +02001107 .cb = str_size_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001108 .help = "Total size of device or files",
1109 },
1110 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001111 .name = "fill_device",
Jens Axboe74586c12011-01-20 10:16:03 -07001112 .alias = "fill_fs",
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001113 .type = FIO_OPT_BOOL,
1114 .off1 = td_var_offset(fill_device),
1115 .help = "Write until an ENOSPC error occurs",
1116 .def = "0",
1117 },
1118 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001119 .name = "filesize",
1120 .type = FIO_OPT_STR_VAL,
1121 .off1 = td_var_offset(file_size_low),
1122 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001123 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001124 .help = "Size of individual files",
1125 },
1126 {
Jens Axboe67a10002007-07-31 23:12:16 +02001127 .name = "offset",
1128 .alias = "fileoffset",
1129 .type = FIO_OPT_STR_VAL,
1130 .off1 = td_var_offset(start_offset),
1131 .help = "Start IO from this offset",
1132 .def = "0",
1133 },
1134 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001135 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001136 .alias = "blocksize",
Jens Axboee01b22b2009-06-09 15:43:25 +02001137 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001138 .off1 = td_var_offset(bs[DDIR_READ]),
1139 .off2 = td_var_offset(bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001140 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001141 .help = "Block size unit",
1142 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +02001143 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001144 },
1145 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001146 .name = "ba",
1147 .alias = "blockalign",
Jens Axboee01b22b2009-06-09 15:43:25 +02001148 .type = FIO_OPT_INT,
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001149 .off1 = td_var_offset(ba[DDIR_READ]),
1150 .off2 = td_var_offset(ba[DDIR_WRITE]),
1151 .minval = 1,
1152 .help = "IO block offset alignment",
1153 .parent = "rw",
1154 },
1155 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001156 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001157 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001158 .type = FIO_OPT_RANGE,
1159 .off1 = td_var_offset(min_bs[DDIR_READ]),
1160 .off2 = td_var_offset(max_bs[DDIR_READ]),
1161 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1162 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001163 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001164 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +02001165 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001166 },
1167 {
Jens Axboe564ca972007-12-14 12:21:19 +01001168 .name = "bssplit",
1169 .type = FIO_OPT_STR,
1170 .cb = str_bssplit_cb,
1171 .help = "Set a specific mix of block sizes",
1172 .parent = "rw",
1173 },
1174 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001175 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001176 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001177 .type = FIO_OPT_STR_SET,
1178 .off1 = td_var_offset(bs_unaligned),
1179 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +02001180 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001181 },
1182 {
1183 .name = "randrepeat",
1184 .type = FIO_OPT_BOOL,
1185 .off1 = td_var_offset(rand_repeatable),
1186 .help = "Use repeatable random IO pattern",
1187 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +02001188 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001189 },
1190 {
Jens Axboe2615cc42011-03-28 09:35:09 +02001191 .name = "use_os_rand",
1192 .type = FIO_OPT_BOOL,
1193 .off1 = td_var_offset(use_os_rand),
1194 .help = "Set to use OS random generator",
1195 .def = "0",
1196 .parent = "rw",
1197 },
1198 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001199 .name = "norandommap",
1200 .type = FIO_OPT_STR_SET,
1201 .off1 = td_var_offset(norandommap),
1202 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +02001203 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001204 },
1205 {
Jens Axboe2b386d22008-03-26 10:32:57 +01001206 .name = "softrandommap",
1207 .type = FIO_OPT_BOOL,
1208 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001209 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +01001210 .parent = "norandommap",
1211 .def = "0",
1212 },
1213 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001214 .name = "nrfiles",
Jens Axboed7c8be02010-11-25 08:21:39 +01001215 .alias = "nr_files",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001216 .type = FIO_OPT_INT,
1217 .off1 = td_var_offset(nr_files),
1218 .help = "Split job workload between this number of files",
1219 .def = "1",
1220 },
1221 {
1222 .name = "openfiles",
1223 .type = FIO_OPT_INT,
1224 .off1 = td_var_offset(open_files),
1225 .help = "Number of files to keep open at the same time",
1226 },
1227 {
1228 .name = "file_service_type",
1229 .type = FIO_OPT_STR,
1230 .cb = str_fst_cb,
1231 .off1 = td_var_offset(file_service_type),
1232 .help = "How to select which file to service next",
1233 .def = "roundrobin",
1234 .posval = {
1235 { .ival = "random",
1236 .oval = FIO_FSERVICE_RANDOM,
1237 .help = "Choose a file at random",
1238 },
1239 { .ival = "roundrobin",
1240 .oval = FIO_FSERVICE_RR,
1241 .help = "Round robin select files",
1242 },
Jens Axboea086c252009-03-04 08:27:37 +01001243 { .ival = "sequential",
1244 .oval = FIO_FSERVICE_SEQ,
1245 .help = "Finish one file before moving to the next",
1246 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001247 },
Jens Axboe67a10002007-07-31 23:12:16 +02001248 .parent = "nrfiles",
1249 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001250#ifdef FIO_HAVE_FALLOCATE
1251 {
1252 .name = "fallocate",
Eric Gourioua596f042011-06-17 09:11:45 +02001253 .type = FIO_OPT_STR,
1254 .off1 = td_var_offset(fallocate_mode),
1255 .help = "Whether pre-allocation is performed when laying out files",
1256 .def = "posix",
1257 .posval = {
1258 { .ival = "none",
1259 .oval = FIO_FALLOCATE_NONE,
1260 .help = "Do not pre-allocate space",
1261 },
1262 { .ival = "posix",
1263 .oval = FIO_FALLOCATE_POSIX,
1264 .help = "Use posix_fallocate()",
1265 },
1266#ifdef FIO_HAVE_LINUX_FALLOCATE
1267 { .ival = "keep",
1268 .oval = FIO_FALLOCATE_KEEP_SIZE,
1269 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1270 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001271#endif
Eric Gourioua596f042011-06-17 09:11:45 +02001272 /* Compatibility with former boolean values */
1273 { .ival = "0",
1274 .oval = FIO_FALLOCATE_NONE,
1275 .help = "Alias for 'none'",
1276 },
1277 { .ival = "1",
1278 .oval = FIO_FALLOCATE_POSIX,
1279 .help = "Alias for 'posix'",
1280 },
1281 },
1282 },
1283#endif /* FIO_HAVE_FALLOCATE */
Jens Axboe67a10002007-07-31 23:12:16 +02001284 {
1285 .name = "fadvise_hint",
1286 .type = FIO_OPT_BOOL,
1287 .off1 = td_var_offset(fadvise_hint),
1288 .help = "Use fadvise() to advise the kernel on IO pattern",
1289 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001290 },
1291 {
1292 .name = "fsync",
1293 .type = FIO_OPT_INT,
1294 .off1 = td_var_offset(fsync_blocks),
1295 .help = "Issue fsync for writes every given number of blocks",
1296 .def = "0",
1297 },
1298 {
Jens Axboe5f9099e2009-06-16 22:40:26 +02001299 .name = "fdatasync",
1300 .type = FIO_OPT_INT,
1301 .off1 = td_var_offset(fdatasync_blocks),
1302 .help = "Issue fdatasync for writes every given number of blocks",
1303 .def = "0",
1304 },
Jens Axboe1ef2b6b2010-10-08 15:07:01 +02001305 {
1306 .name = "write_barrier",
1307 .type = FIO_OPT_INT,
1308 .off1 = td_var_offset(barrier_blocks),
1309 .help = "Make every Nth write a barrier write",
1310 .def = "0",
1311 },
Jens Axboe44f29692010-03-09 20:09:44 +01001312#ifdef FIO_HAVE_SYNC_FILE_RANGE
1313 {
1314 .name = "sync_file_range",
1315 .posval = {
1316 { .ival = "wait_before",
1317 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1318 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001319 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001320 },
1321 { .ival = "write",
1322 .oval = SYNC_FILE_RANGE_WRITE,
1323 .help = "SYNC_FILE_RANGE_WRITE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001324 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001325 },
1326 {
1327 .ival = "wait_after",
1328 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1329 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
Jens Axboe3843deb2010-03-09 20:41:15 +01001330 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001331 },
1332 },
Jens Axboe3843deb2010-03-09 20:41:15 +01001333 .type = FIO_OPT_STR_MULTI,
Jens Axboe44f29692010-03-09 20:09:44 +01001334 .cb = str_sfr_cb,
1335 .off1 = td_var_offset(sync_file_range),
1336 .help = "Use sync_file_range()",
1337 },
1338#endif
Jens Axboe5f9099e2009-06-16 22:40:26 +02001339 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001340 .name = "direct",
1341 .type = FIO_OPT_BOOL,
1342 .off1 = td_var_offset(odirect),
1343 .help = "Use O_DIRECT IO (negates buffered)",
1344 .def = "0",
1345 },
1346 {
1347 .name = "buffered",
1348 .type = FIO_OPT_BOOL,
1349 .off1 = td_var_offset(odirect),
1350 .neg = 1,
1351 .help = "Use buffered IO (negates direct)",
1352 .def = "1",
1353 },
1354 {
1355 .name = "overwrite",
1356 .type = FIO_OPT_BOOL,
1357 .off1 = td_var_offset(overwrite),
1358 .help = "When writing, set whether to overwrite current data",
1359 .def = "0",
1360 },
1361 {
1362 .name = "loops",
1363 .type = FIO_OPT_INT,
1364 .off1 = td_var_offset(loops),
1365 .help = "Number of times to run the job",
1366 .def = "1",
1367 },
1368 {
1369 .name = "numjobs",
1370 .type = FIO_OPT_INT,
1371 .off1 = td_var_offset(numjobs),
1372 .help = "Duplicate this job this many times",
1373 .def = "1",
1374 },
1375 {
1376 .name = "startdelay",
Jens Axboea5737c92010-06-29 10:40:30 +02001377 .type = FIO_OPT_STR_VAL_TIME,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001378 .off1 = td_var_offset(start_delay),
1379 .help = "Only start job when this period has passed",
1380 .def = "0",
1381 },
1382 {
1383 .name = "runtime",
1384 .alias = "timeout",
1385 .type = FIO_OPT_STR_VAL_TIME,
1386 .off1 = td_var_offset(timeout),
1387 .help = "Stop workload when this amount of time has passed",
1388 .def = "0",
1389 },
1390 {
Jens Axboecf4464c2007-04-17 20:14:42 +02001391 .name = "time_based",
1392 .type = FIO_OPT_STR_SET,
1393 .off1 = td_var_offset(time_based),
1394 .help = "Keep running until runtime/timeout is met",
1395 },
1396 {
Jens Axboe721938a2008-09-10 09:46:16 +02001397 .name = "ramp_time",
1398 .type = FIO_OPT_STR_VAL_TIME,
1399 .off1 = td_var_offset(ramp_time),
1400 .help = "Ramp up time before measuring performance",
1401 },
1402 {
Jens Axboec223da82010-03-24 13:23:53 +01001403 .name = "clocksource",
1404 .type = FIO_OPT_STR,
1405 .cb = fio_clock_source_cb,
1406 .off1 = td_var_offset(clocksource),
1407 .help = "What type of timing source to use",
Jens Axboec223da82010-03-24 13:23:53 +01001408 .posval = {
1409 { .ival = "gettimeofday",
1410 .oval = CS_GTOD,
1411 .help = "Use gettimeofday(2) for timing",
1412 },
1413 { .ival = "clock_gettime",
1414 .oval = CS_CGETTIME,
1415 .help = "Use clock_gettime(2) for timing",
1416 },
1417#ifdef ARCH_HAVE_CPU_CLOCK
1418 { .ival = "cpu",
1419 .oval = CS_CPUCLOCK,
1420 .help = "Use CPU private clock",
1421 },
1422#endif
1423 },
1424 },
1425 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001426 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001427 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001428 .type = FIO_OPT_STR,
1429 .cb = str_mem_cb,
1430 .off1 = td_var_offset(mem_type),
1431 .help = "Backing type for IO buffers",
1432 .def = "malloc",
1433 .posval = {
1434 { .ival = "malloc",
1435 .oval = MEM_MALLOC,
1436 .help = "Use malloc(3) for IO buffers",
1437 },
Jens Axboeb370e462007-03-19 10:51:49 +01001438 { .ival = "shm",
1439 .oval = MEM_SHM,
1440 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001441 },
1442#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001443 { .ival = "shmhuge",
1444 .oval = MEM_SHMHUGE,
1445 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001446 },
1447#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001448 { .ival = "mmap",
1449 .oval = MEM_MMAP,
1450 .help = "Use mmap(2) (file or anon) for IO buffers",
1451 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001452#ifdef FIO_HAVE_HUGETLB
1453 { .ival = "mmaphuge",
1454 .oval = MEM_MMAPHUGE,
1455 .help = "Like mmap, but use huge pages",
1456 },
1457#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001458 },
1459 },
1460 {
Jens Axboed529ee12009-07-01 10:33:03 +02001461 .name = "iomem_align",
1462 .alias = "mem_align",
1463 .type = FIO_OPT_INT,
1464 .off1 = td_var_offset(mem_align),
1465 .minval = 0,
1466 .help = "IO memory buffer offset alignment",
1467 .def = "0",
1468 .parent = "iomem",
1469 },
1470 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001471 .name = "verify",
1472 .type = FIO_OPT_STR,
1473 .off1 = td_var_offset(verify),
1474 .help = "Verify data written",
Jens Axboe5d7c5d32010-06-21 15:08:17 +02001475 .cb = str_verify_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001476 .def = "0",
1477 .posval = {
1478 { .ival = "0",
1479 .oval = VERIFY_NONE,
1480 .help = "Don't do IO verification",
1481 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001482 { .ival = "md5",
1483 .oval = VERIFY_MD5,
1484 .help = "Use md5 checksums for verification",
1485 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001486 { .ival = "crc64",
1487 .oval = VERIFY_CRC64,
1488 .help = "Use crc64 checksums for verification",
1489 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001490 { .ival = "crc32",
1491 .oval = VERIFY_CRC32,
1492 .help = "Use crc32 checksums for verification",
1493 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001494 { .ival = "crc32c-intel",
1495 .oval = VERIFY_CRC32C_INTEL,
1496 .help = "Use hw crc32c checksums for verification",
1497 },
Jens Axboebac39e02008-06-11 20:46:19 +02001498 { .ival = "crc32c",
1499 .oval = VERIFY_CRC32C,
1500 .help = "Use crc32c checksums for verification",
1501 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001502 { .ival = "crc16",
1503 .oval = VERIFY_CRC16,
1504 .help = "Use crc16 checksums for verification",
1505 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001506 { .ival = "crc7",
1507 .oval = VERIFY_CRC7,
1508 .help = "Use crc7 checksums for verification",
1509 },
Jens Axboe7c353ce2009-08-09 22:40:33 +02001510 { .ival = "sha1",
1511 .oval = VERIFY_SHA1,
1512 .help = "Use sha1 checksums for verification",
1513 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001514 { .ival = "sha256",
1515 .oval = VERIFY_SHA256,
1516 .help = "Use sha256 checksums for verification",
1517 },
1518 { .ival = "sha512",
1519 .oval = VERIFY_SHA512,
1520 .help = "Use sha512 checksums for verification",
1521 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001522 { .ival = "meta",
1523 .oval = VERIFY_META,
1524 .help = "Use io information",
1525 },
Jens Axboe36690c92007-03-26 10:23:34 +02001526 {
1527 .ival = "null",
1528 .oval = VERIFY_NULL,
1529 .help = "Pretend to verify",
1530 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001531 },
1532 },
1533 {
Jens Axboe005c5652007-08-02 22:21:36 +02001534 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001535 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001536 .off1 = td_var_offset(do_verify),
1537 .help = "Run verification stage after write",
1538 .def = "1",
1539 .parent = "verify",
1540 },
1541 {
Jens Axboe160b9662007-03-27 10:59:49 +02001542 .name = "verifysort",
1543 .type = FIO_OPT_BOOL,
1544 .off1 = td_var_offset(verifysort),
1545 .help = "Sort written verify blocks for read back",
1546 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001547 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001548 },
1549 {
Jens Axboea59e1702007-07-30 08:53:27 +02001550 .name = "verify_interval",
Jens Axboee01b22b2009-06-09 15:43:25 +02001551 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001552 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001553 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001554 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001555 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001556 },
1557 {
Jens Axboea59e1702007-07-30 08:53:27 +02001558 .name = "verify_offset",
Jens Axboee01b22b2009-06-09 15:43:25 +02001559 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001560 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001561 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001562 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001563 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001564 },
1565 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001566 .name = "verify_pattern",
Radha Ramachandran0e92f872009-10-27 20:14:27 +01001567 .type = FIO_OPT_STR,
Shawn Lewise28218f2008-01-16 11:01:33 +01001568 .cb = str_verify_pattern_cb,
1569 .help = "Fill pattern for IO buffers",
1570 .parent = "verify",
1571 },
1572 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001573 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001574 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001575 .off1 = td_var_offset(verify_fatal),
1576 .def = "0",
1577 .help = "Exit on a single verify failure, don't continue",
1578 .parent = "verify",
1579 },
1580 {
Jens Axboeb463e932011-01-12 09:03:23 +01001581 .name = "verify_dump",
1582 .type = FIO_OPT_BOOL,
1583 .off1 = td_var_offset(verify_dump),
Jens Axboeef71e312011-10-25 22:43:36 +02001584 .def = "0",
Jens Axboeb463e932011-01-12 09:03:23 +01001585 .help = "Dump contents of good and bad blocks on failure",
1586 .parent = "verify",
1587 },
1588 {
Jens Axboee8462bd2009-07-06 12:59:04 +02001589 .name = "verify_async",
1590 .type = FIO_OPT_INT,
1591 .off1 = td_var_offset(verify_async),
1592 .def = "0",
1593 .help = "Number of async verifier threads to use",
1594 .parent = "verify",
1595 },
Jens Axboe9e144182010-06-15 14:25:36 +02001596 {
1597 .name = "verify_backlog",
1598 .type = FIO_OPT_STR_VAL,
1599 .off1 = td_var_offset(verify_backlog),
1600 .help = "Verify after this number of blocks are written",
1601 .parent = "verify",
1602 },
1603 {
1604 .name = "verify_backlog_batch",
1605 .type = FIO_OPT_INT,
1606 .off1 = td_var_offset(verify_batch),
1607 .help = "Verify this number of IO blocks",
Jens Axboe0d29de82010-09-01 13:54:15 +02001608 .parent = "verify",
Jens Axboe9e144182010-06-15 14:25:36 +02001609 },
Jens Axboee8462bd2009-07-06 12:59:04 +02001610#ifdef FIO_HAVE_CPU_AFFINITY
1611 {
1612 .name = "verify_async_cpus",
1613 .type = FIO_OPT_STR,
1614 .cb = str_verify_cpus_allowed_cb,
1615 .help = "Set CPUs allowed for async verify threads",
1616 .parent = "verify_async",
1617 },
1618#endif
Jens Axboe0d29de82010-09-01 13:54:15 +02001619#ifdef FIO_HAVE_TRIM
1620 {
1621 .name = "trim_percentage",
1622 .type = FIO_OPT_INT,
1623 .cb = str_verify_trim_cb,
1624 .maxval = 100,
1625 .help = "Number of verify blocks to discard/trim",
1626 .parent = "verify",
1627 .def = "0",
1628 },
1629 {
1630 .name = "trim_verify_zero",
1631 .type = FIO_OPT_INT,
1632 .help = "Verify that trim/discarded blocks are returned as zeroes",
1633 .off1 = td_var_offset(trim_zero),
1634 .parent = "trim_percentage",
1635 .def = "1",
1636 },
1637 {
1638 .name = "trim_backlog",
1639 .type = FIO_OPT_STR_VAL,
1640 .off1 = td_var_offset(trim_backlog),
1641 .help = "Trim after this number of blocks are written",
1642 .parent = "trim_percentage",
1643 },
1644 {
1645 .name = "trim_backlog_batch",
1646 .type = FIO_OPT_INT,
1647 .off1 = td_var_offset(trim_batch),
1648 .help = "Trim this number of IO blocks",
1649 .parent = "trim_percentage",
1650 },
1651#endif
Jens Axboee8462bd2009-07-06 12:59:04 +02001652 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001653 .name = "write_iolog",
1654 .type = FIO_OPT_STR_STORE,
1655 .off1 = td_var_offset(write_iolog_file),
1656 .help = "Store IO pattern to file",
1657 },
1658 {
1659 .name = "read_iolog",
1660 .type = FIO_OPT_STR_STORE,
1661 .off1 = td_var_offset(read_iolog_file),
1662 .help = "Playback IO pattern from file",
1663 },
1664 {
David Nellans64bbb862010-08-24 22:13:30 +02001665 .name = "replay_no_stall",
1666 .type = FIO_OPT_INT,
1667 .off1 = td_var_offset(no_stall),
1668 .def = "0",
Jens Axboe87e7a972010-08-25 09:01:25 +02001669 .parent = "read_iolog",
David Nellans64bbb862010-08-24 22:13:30 +02001670 .help = "Playback IO pattern file as fast as possible without stalls",
1671 },
1672 {
David Nellansd1c46c02010-08-31 21:20:47 +02001673 .name = "replay_redirect",
1674 .type = FIO_OPT_STR_STORE,
1675 .off1 = td_var_offset(replay_redirect),
1676 .parent = "read_iolog",
1677 .help = "Replay all I/O onto this device, regardless of trace device",
1678 },
1679 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001680 .name = "exec_prerun",
1681 .type = FIO_OPT_STR_STORE,
1682 .off1 = td_var_offset(exec_prerun),
1683 .help = "Execute this file prior to running job",
1684 },
1685 {
1686 .name = "exec_postrun",
1687 .type = FIO_OPT_STR_STORE,
1688 .off1 = td_var_offset(exec_postrun),
1689 .help = "Execute this file after running job",
1690 },
1691#ifdef FIO_HAVE_IOSCHED_SWITCH
1692 {
1693 .name = "ioscheduler",
1694 .type = FIO_OPT_STR_STORE,
1695 .off1 = td_var_offset(ioscheduler),
1696 .help = "Use this IO scheduler on the backing device",
1697 },
1698#endif
1699 {
1700 .name = "zonesize",
1701 .type = FIO_OPT_STR_VAL,
1702 .off1 = td_var_offset(zone_size),
1703 .help = "Give size of an IO zone",
1704 .def = "0",
1705 },
1706 {
1707 .name = "zoneskip",
1708 .type = FIO_OPT_STR_VAL,
1709 .off1 = td_var_offset(zone_skip),
1710 .help = "Space between IO zones",
1711 .def = "0",
1712 },
1713 {
1714 .name = "lockmem",
1715 .type = FIO_OPT_STR_VAL,
1716 .cb = str_lockmem_cb,
1717 .help = "Lock down this amount of memory",
1718 .def = "0",
1719 },
1720 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001721 .name = "rwmixread",
1722 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001723 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001724 .maxval = 100,
1725 .help = "Percentage of mixed workload that is reads",
1726 .def = "50",
1727 },
1728 {
1729 .name = "rwmixwrite",
1730 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001731 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001732 .maxval = 100,
1733 .help = "Percentage of mixed workload that is writes",
1734 .def = "50",
1735 },
1736 {
Jens Axboeafdf9352007-07-31 16:14:34 +02001737 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02001738 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02001739 },
1740 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001741 .name = "nice",
1742 .type = FIO_OPT_INT,
1743 .off1 = td_var_offset(nice),
1744 .help = "Set job CPU nice value",
1745 .minval = -19,
1746 .maxval = 20,
1747 .def = "0",
1748 },
1749#ifdef FIO_HAVE_IOPRIO
1750 {
1751 .name = "prio",
1752 .type = FIO_OPT_INT,
1753 .cb = str_prio_cb,
1754 .help = "Set job IO priority value",
1755 .minval = 0,
1756 .maxval = 7,
1757 },
1758 {
1759 .name = "prioclass",
1760 .type = FIO_OPT_INT,
1761 .cb = str_prioclass_cb,
1762 .help = "Set job IO priority class",
1763 .minval = 0,
1764 .maxval = 3,
1765 },
1766#endif
1767 {
1768 .name = "thinktime",
1769 .type = FIO_OPT_INT,
1770 .off1 = td_var_offset(thinktime),
1771 .help = "Idle time between IO buffers (usec)",
1772 .def = "0",
1773 },
1774 {
1775 .name = "thinktime_spin",
1776 .type = FIO_OPT_INT,
1777 .off1 = td_var_offset(thinktime_spin),
1778 .help = "Start think time by spinning this amount (usec)",
1779 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02001780 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001781 },
1782 {
1783 .name = "thinktime_blocks",
1784 .type = FIO_OPT_INT,
1785 .off1 = td_var_offset(thinktime_blocks),
1786 .help = "IO buffer period between 'thinktime'",
1787 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02001788 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001789 },
1790 {
1791 .name = "rate",
Jens Axboee01b22b2009-06-09 15:43:25 +02001792 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001793 .off1 = td_var_offset(rate[0]),
1794 .off2 = td_var_offset(rate[1]),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001795 .help = "Set bandwidth rate",
1796 },
1797 {
1798 .name = "ratemin",
Jens Axboee01b22b2009-06-09 15:43:25 +02001799 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001800 .off1 = td_var_offset(ratemin[0]),
1801 .off2 = td_var_offset(ratemin[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001802 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001803 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01001804 },
1805 {
1806 .name = "rate_iops",
Jens Axboee01b22b2009-06-09 15:43:25 +02001807 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001808 .off1 = td_var_offset(rate_iops[0]),
1809 .off2 = td_var_offset(rate_iops[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001810 .help = "Limit IO used to this number of IO operations/sec",
1811 },
1812 {
1813 .name = "rate_iops_min",
Jens Axboee01b22b2009-06-09 15:43:25 +02001814 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001815 .off1 = td_var_offset(rate_iops_min[0]),
1816 .off2 = td_var_offset(rate_iops_min[1]),
Bruce Cran03e20d62011-01-02 20:14:54 +01001817 .help = "Job must meet this rate or it will be shut down",
Jens Axboeafdf9352007-07-31 16:14:34 +02001818 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001819 },
1820 {
1821 .name = "ratecycle",
1822 .type = FIO_OPT_INT,
1823 .off1 = td_var_offset(ratecycle),
1824 .help = "Window average for rate limits (msec)",
1825 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02001826 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001827 },
1828 {
1829 .name = "invalidate",
1830 .type = FIO_OPT_BOOL,
1831 .off1 = td_var_offset(invalidate_cache),
1832 .help = "Invalidate buffer/page cache prior to running job",
1833 .def = "1",
1834 },
1835 {
1836 .name = "sync",
1837 .type = FIO_OPT_BOOL,
1838 .off1 = td_var_offset(sync_io),
1839 .help = "Use O_SYNC for buffered writes",
1840 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02001841 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001842 },
1843 {
1844 .name = "bwavgtime",
1845 .type = FIO_OPT_INT,
1846 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001847 .help = "Time window over which to calculate bandwidth"
1848 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001849 .def = "500",
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001850 .parent = "write_bw_log",
1851 },
1852 {
1853 .name = "iopsavgtime",
1854 .type = FIO_OPT_INT,
1855 .off1 = td_var_offset(iops_avg_time),
1856 .help = "Time window over which to calculate IOPS (msec)",
1857 .def = "500",
1858 .parent = "write_iops_log",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001859 },
1860 {
1861 .name = "create_serialize",
1862 .type = FIO_OPT_BOOL,
1863 .off1 = td_var_offset(create_serialize),
1864 .help = "Serialize creating of job files",
1865 .def = "1",
1866 },
1867 {
1868 .name = "create_fsync",
1869 .type = FIO_OPT_BOOL,
1870 .off1 = td_var_offset(create_fsync),
Bruce Cran03e20d62011-01-02 20:14:54 +01001871 .help = "fsync file after creation",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001872 .def = "1",
1873 },
1874 {
Jens Axboe814452b2009-03-04 12:53:13 +01001875 .name = "create_on_open",
1876 .type = FIO_OPT_BOOL,
1877 .off1 = td_var_offset(create_on_open),
1878 .help = "Create files when they are opened for IO",
1879 .def = "0",
1880 },
Jens Axboe0b9d69e2009-09-11 22:29:54 +02001881 {
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001882 .name = "pre_read",
1883 .type = FIO_OPT_BOOL,
1884 .off1 = td_var_offset(pre_read),
Bruce Cran03e20d62011-01-02 20:14:54 +01001885 .help = "Pre-read files before starting official testing",
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001886 .def = "0",
1887 },
Jens Axboe814452b2009-03-04 12:53:13 +01001888 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001889 .name = "cpuload",
1890 .type = FIO_OPT_INT,
1891 .off1 = td_var_offset(cpuload),
1892 .help = "Use this percentage of CPU",
1893 },
1894 {
1895 .name = "cpuchunks",
1896 .type = FIO_OPT_INT,
1897 .off1 = td_var_offset(cpucycle),
1898 .help = "Length of the CPU burn cycles (usecs)",
1899 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02001900 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001901 },
1902#ifdef FIO_HAVE_CPU_AFFINITY
1903 {
1904 .name = "cpumask",
1905 .type = FIO_OPT_INT,
1906 .cb = str_cpumask_cb,
1907 .help = "CPU affinity mask",
1908 },
Jens Axboed2e268b2007-06-15 10:33:49 +02001909 {
1910 .name = "cpus_allowed",
1911 .type = FIO_OPT_STR,
1912 .cb = str_cpus_allowed_cb,
1913 .help = "Set CPUs allowed",
1914 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001915#endif
1916 {
1917 .name = "end_fsync",
1918 .type = FIO_OPT_BOOL,
1919 .off1 = td_var_offset(end_fsync),
1920 .help = "Include fsync at the end of job",
1921 .def = "0",
1922 },
1923 {
1924 .name = "fsync_on_close",
1925 .type = FIO_OPT_BOOL,
1926 .off1 = td_var_offset(fsync_on_close),
1927 .help = "fsync files on close",
1928 .def = "0",
1929 },
1930 {
1931 .name = "unlink",
1932 .type = FIO_OPT_BOOL,
1933 .off1 = td_var_offset(unlink),
1934 .help = "Unlink created files after job has completed",
1935 .def = "0",
1936 },
1937 {
1938 .name = "exitall",
1939 .type = FIO_OPT_STR_SET,
1940 .cb = str_exitall_cb,
1941 .help = "Terminate all jobs when one exits",
1942 },
1943 {
1944 .name = "stonewall",
Jens Axboed3923652011-08-03 12:38:39 +02001945 .alias = "wait_for_previous",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001946 .type = FIO_OPT_STR_SET,
1947 .off1 = td_var_offset(stonewall),
1948 .help = "Insert a hard barrier between this job and previous",
1949 },
1950 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01001951 .name = "new_group",
1952 .type = FIO_OPT_STR_SET,
1953 .off1 = td_var_offset(new_group),
1954 .help = "Mark the start of a new group (for reporting)",
1955 },
1956 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001957 .name = "thread",
1958 .type = FIO_OPT_STR_SET,
1959 .off1 = td_var_offset(use_thread),
1960 .help = "Use threads instead of forks",
1961 },
1962 {
1963 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001964 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001965 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001966 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001967 .help = "Write log of bandwidth during run",
1968 },
1969 {
1970 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001971 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001972 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001973 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001974 .help = "Write log of latency during run",
1975 },
1976 {
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001977 .name = "write_iops_log",
1978 .type = FIO_OPT_STR,
1979 .off1 = td_var_offset(write_iops_log),
1980 .cb = str_write_iops_log_cb,
1981 .help = "Write log of IOPS during run",
1982 },
1983 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001984 .name = "hugepage-size",
Jens Axboee01b22b2009-06-09 15:43:25 +02001985 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001986 .off1 = td_var_offset(hugepage_size),
1987 .help = "When using hugepages, specify size of each page",
Jens Axboe81179ee2011-10-04 12:42:06 +02001988 .def = __fio_stringify(FIO_HUGE_PAGE),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001989 },
1990 {
1991 .name = "group_reporting",
1992 .type = FIO_OPT_STR_SET,
1993 .off1 = td_var_offset(group_reporting),
1994 .help = "Do reporting on a per-group basis",
1995 },
1996 {
Jens Axboee9459e52007-04-17 15:46:32 +02001997 .name = "zero_buffers",
1998 .type = FIO_OPT_STR_SET,
1999 .off1 = td_var_offset(zero_buffers),
2000 .help = "Init IO buffers to all zeroes",
2001 },
Jens Axboe5973caf2008-05-21 19:52:35 +02002002 {
2003 .name = "refill_buffers",
2004 .type = FIO_OPT_STR_SET,
2005 .off1 = td_var_offset(refill_buffers),
2006 .help = "Refill IO buffers on every IO submit",
2007 },
Yu-ju Hong83349192011-08-13 00:53:44 +02002008 {
Jens Axboefd684182011-09-19 09:24:44 +02002009 .name = "scramble_buffers",
2010 .type = FIO_OPT_BOOL,
2011 .off1 = td_var_offset(scramble_buffers),
2012 .help = "Slightly scramble buffers on every IO submit",
2013 .def = "1",
2014 },
2015 {
Yu-ju Hong83349192011-08-13 00:53:44 +02002016 .name = "clat_percentiles",
2017 .type = FIO_OPT_BOOL,
2018 .off1 = td_var_offset(clat_percentiles),
2019 .help = "Enable the reporting of completion latency percentiles",
Jens Axboe467b35e2011-10-13 08:53:24 +02002020 .def = "1",
Yu-ju Hong83349192011-08-13 00:53:44 +02002021 },
2022 {
2023 .name = "percentile_list",
2024 .type = FIO_OPT_FLOAT_LIST,
2025 .off1 = td_var_offset(percentile_list),
2026 .off2 = td_var_offset(overwrite_plist),
2027 .help = "Specify a custom list of percentiles to report",
2028 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2029 .minfp = 0.0,
2030 .maxfp = 100.0,
2031 },
2032
Jens Axboe0a839f32007-04-26 09:02:34 +02002033#ifdef FIO_HAVE_DISK_UTIL
2034 {
2035 .name = "disk_util",
2036 .type = FIO_OPT_BOOL,
2037 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02002038 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02002039 .def = "1",
2040 },
2041#endif
Jens Axboee9459e52007-04-17 15:46:32 +02002042 {
Jens Axboe993bf482008-11-14 13:04:53 +01002043 .name = "gtod_reduce",
2044 .type = FIO_OPT_BOOL,
2045 .help = "Greatly reduce number of gettimeofday() calls",
2046 .cb = str_gtod_reduce_cb,
2047 .def = "0",
2048 },
2049 {
Jens Axboe02af0982010-06-24 09:59:34 +02002050 .name = "disable_lat",
2051 .type = FIO_OPT_BOOL,
2052 .off1 = td_var_offset(disable_lat),
2053 .help = "Disable latency numbers",
2054 .parent = "gtod_reduce",
2055 .def = "0",
2056 },
2057 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02002058 .name = "disable_clat",
2059 .type = FIO_OPT_BOOL,
2060 .off1 = td_var_offset(disable_clat),
2061 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002062 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002063 .def = "0",
2064 },
2065 {
2066 .name = "disable_slat",
2067 .type = FIO_OPT_BOOL,
2068 .off1 = td_var_offset(disable_slat),
Bruce Cran03e20d62011-01-02 20:14:54 +01002069 .help = "Disable submission latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002070 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002071 .def = "0",
2072 },
2073 {
2074 .name = "disable_bw_measurement",
2075 .type = FIO_OPT_BOOL,
2076 .off1 = td_var_offset(disable_bw),
2077 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01002078 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002079 .def = "0",
2080 },
2081 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002082 .name = "gtod_cpu",
2083 .type = FIO_OPT_INT,
2084 .cb = str_gtod_cpu_cb,
Bruce Cran03e20d62011-01-02 20:14:54 +01002085 .help = "Set up dedicated gettimeofday() thread on this CPU",
Jens Axboe29d43ff2009-07-01 10:42:18 +02002086 .verify = gtod_cpu_verify,
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002087 },
2088 {
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002089 .name = "continue_on_error",
2090 .type = FIO_OPT_BOOL,
2091 .off1 = td_var_offset(continue_on_error),
Bruce Cran03e20d62011-01-02 20:14:54 +01002092 .help = "Continue on non-fatal errors during IO",
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002093 .def = "0",
2094 },
2095 {
Jens Axboe9ac8a792009-11-13 21:23:07 +01002096 .name = "profile",
Jens Axboe79d16312010-03-04 12:43:20 +01002097 .type = FIO_OPT_STR_STORE,
Jens Axboe9ac8a792009-11-13 21:23:07 +01002098 .off1 = td_var_offset(profile),
Jens Axboe9ac8a792009-11-13 21:23:07 +01002099 .help = "Select a specific builtin performance test",
2100 },
2101 {
Jens Axboea696fa22009-12-04 10:05:02 +01002102 .name = "cgroup",
2103 .type = FIO_OPT_STR_STORE,
2104 .off1 = td_var_offset(cgroup),
2105 .help = "Add job to cgroup of this name",
2106 },
2107 {
2108 .name = "cgroup_weight",
2109 .type = FIO_OPT_INT,
2110 .off1 = td_var_offset(cgroup_weight),
2111 .help = "Use given weight for cgroup",
2112 .minval = 100,
2113 .maxval = 1000,
Jens Axboea696fa22009-12-04 10:05:02 +01002114 },
2115 {
Vivek Goyal7de87092010-03-31 22:55:15 +02002116 .name = "cgroup_nodelete",
2117 .type = FIO_OPT_BOOL,
2118 .off1 = td_var_offset(cgroup_nodelete),
2119 .help = "Do not delete cgroups after job completion",
2120 .def = "0",
2121 },
2122 {
Jens Axboee0b0d892009-12-08 10:10:14 +01002123 .name = "uid",
2124 .type = FIO_OPT_INT,
2125 .off1 = td_var_offset(uid),
2126 .help = "Run job with this user ID",
2127 },
2128 {
2129 .name = "gid",
2130 .type = FIO_OPT_INT,
2131 .off1 = td_var_offset(gid),
2132 .help = "Run job with this group ID",
2133 },
2134 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002135 .name = NULL,
2136 },
2137};
2138
Jens Axboe17af15d2010-04-13 10:38:16 +02002139static void add_to_lopt(struct option *lopt, struct fio_option *o,
2140 const char *name)
Jens Axboe9f817362010-03-04 14:38:10 +01002141{
Jens Axboe17af15d2010-04-13 10:38:16 +02002142 lopt->name = (char *) name;
Jens Axboe9f817362010-03-04 14:38:10 +01002143 lopt->val = FIO_GETOPT_JOB;
2144 if (o->type == FIO_OPT_STR_SET)
2145 lopt->has_arg = no_argument;
2146 else
2147 lopt->has_arg = required_argument;
2148}
2149
Jens Axboe214e1ec2007-03-15 10:48:13 +01002150void fio_options_dup_and_init(struct option *long_options)
2151{
2152 struct fio_option *o;
2153 unsigned int i;
2154
2155 options_init(options);
2156
2157 i = 0;
2158 while (long_options[i].name)
2159 i++;
2160
2161 o = &options[0];
2162 while (o->name) {
Jens Axboe17af15d2010-04-13 10:38:16 +02002163 add_to_lopt(&long_options[i], o, o->name);
2164 if (o->alias) {
2165 i++;
2166 add_to_lopt(&long_options[i], o, o->alias);
2167 }
Jens Axboe214e1ec2007-03-15 10:48:13 +01002168
2169 i++;
2170 o++;
2171 assert(i < FIO_NR_OPTIONS);
2172 }
2173}
2174
Jens Axboe74929ac2009-08-05 11:42:37 +02002175struct fio_keyword {
2176 const char *word;
2177 const char *desc;
2178 char *replace;
2179};
2180
2181static struct fio_keyword fio_keywords[] = {
2182 {
2183 .word = "$pagesize",
2184 .desc = "Page size in the system",
2185 },
2186 {
2187 .word = "$mb_memory",
2188 .desc = "Megabytes of memory online",
2189 },
2190 {
2191 .word = "$ncpus",
2192 .desc = "Number of CPUs online in the system",
2193 },
2194 {
2195 .word = NULL,
2196 },
2197};
2198
2199void fio_keywords_init(void)
2200{
Jens Axboe3b2e1462009-12-15 08:58:10 +01002201 unsigned long long mb_memory;
Jens Axboe74929ac2009-08-05 11:42:37 +02002202 char buf[128];
2203 long l;
2204
2205 sprintf(buf, "%lu", page_size);
2206 fio_keywords[0].replace = strdup(buf);
2207
Jens Axboe8eb016d2011-07-11 10:24:20 +02002208 mb_memory = os_phys_mem() / (1024 * 1024);
Jens Axboe3b2e1462009-12-15 08:58:10 +01002209 sprintf(buf, "%llu", mb_memory);
Jens Axboe74929ac2009-08-05 11:42:37 +02002210 fio_keywords[1].replace = strdup(buf);
2211
Jens Axboec00a2282011-07-08 20:56:06 +02002212 l = cpus_online();
Jens Axboe74929ac2009-08-05 11:42:37 +02002213 sprintf(buf, "%lu", l);
2214 fio_keywords[2].replace = strdup(buf);
2215}
2216
Jens Axboe892a6ff2009-11-13 12:19:49 +01002217#define BC_APP "bc"
2218
2219static char *bc_calc(char *str)
2220{
Steven Langd0c814e2011-10-28 08:37:13 +02002221 char buf[128], *tmp;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002222 FILE *f;
2223 int ret;
2224
2225 /*
2226 * No math, just return string
2227 */
Steven Langd0c814e2011-10-28 08:37:13 +02002228 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2229 !strchr(str, '/')) || strchr(str, '\''))
Jens Axboe892a6ff2009-11-13 12:19:49 +01002230 return str;
2231
2232 /*
2233 * Split option from value, we only need to calculate the value
2234 */
2235 tmp = strchr(str, '=');
2236 if (!tmp)
2237 return str;
2238
2239 tmp++;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002240
Steven Langd0c814e2011-10-28 08:37:13 +02002241 /*
2242 * Prevent buffer overflows; such a case isn't reasonable anyway
2243 */
2244 if (strlen(str) >= 128 || strlen(tmp) > 100)
2245 return str;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002246
2247 sprintf(buf, "which %s > /dev/null", BC_APP);
2248 if (system(buf)) {
2249 log_err("fio: bc is needed for performing math\n");
Jens Axboe892a6ff2009-11-13 12:19:49 +01002250 return NULL;
2251 }
2252
Steven Langd0c814e2011-10-28 08:37:13 +02002253 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002254 f = popen(buf, "r");
2255 if (!f) {
Jens Axboe892a6ff2009-11-13 12:19:49 +01002256 return NULL;
2257 }
2258
Steven Langd0c814e2011-10-28 08:37:13 +02002259 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002260 if (ret <= 0) {
Jens Axboe892a6ff2009-11-13 12:19:49 +01002261 return NULL;
2262 }
2263
Jens Axboe892a6ff2009-11-13 12:19:49 +01002264 pclose(f);
Steven Langd0c814e2011-10-28 08:37:13 +02002265 buf[(tmp - str) + ret - 1] = '\0';
2266 memcpy(buf, str, tmp - str);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002267 free(str);
Steven Langd0c814e2011-10-28 08:37:13 +02002268 return strdup(buf);
2269}
2270
2271/*
2272 * Return a copy of the input string with substrings of the form ${VARNAME}
2273 * substituted with the value of the environment variable VARNAME. The
2274 * substitution always occurs, even if VARNAME is empty or the corresponding
2275 * environment variable undefined.
2276 */
2277static char *option_dup_subs(const char *opt)
2278{
2279 char out[OPT_LEN_MAX+1];
2280 char in[OPT_LEN_MAX+1];
2281 char *outptr = out;
2282 char *inptr = in;
2283 char *ch1, *ch2, *env;
2284 ssize_t nchr = OPT_LEN_MAX;
2285 size_t envlen;
2286
2287 if (strlen(opt) + 1 > OPT_LEN_MAX) {
2288 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2289 return NULL;
2290 }
2291
2292 in[OPT_LEN_MAX] = '\0';
2293 strncpy(in, opt, OPT_LEN_MAX);
2294
2295 while (*inptr && nchr > 0) {
2296 if (inptr[0] == '$' && inptr[1] == '{') {
2297 ch2 = strchr(inptr, '}');
2298 if (ch2 && inptr+1 < ch2) {
2299 ch1 = inptr+2;
2300 inptr = ch2+1;
2301 *ch2 = '\0';
2302
2303 env = getenv(ch1);
2304 if (env) {
2305 envlen = strlen(env);
2306 if (envlen <= nchr) {
2307 memcpy(outptr, env, envlen);
2308 outptr += envlen;
2309 nchr -= envlen;
2310 }
2311 }
2312
2313 continue;
2314 }
2315 }
2316
2317 *outptr++ = *inptr++;
2318 --nchr;
2319 }
2320
2321 *outptr = '\0';
2322 return strdup(out);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002323}
2324
Jens Axboe74929ac2009-08-05 11:42:37 +02002325/*
2326 * Look for reserved variable names and replace them with real values
2327 */
2328static char *fio_keyword_replace(char *opt)
2329{
2330 char *s;
2331 int i;
Steven Langd0c814e2011-10-28 08:37:13 +02002332 int docalc = 0;
Jens Axboe74929ac2009-08-05 11:42:37 +02002333
2334 for (i = 0; fio_keywords[i].word != NULL; i++) {
2335 struct fio_keyword *kw = &fio_keywords[i];
2336
2337 while ((s = strstr(opt, kw->word)) != NULL) {
2338 char *new = malloc(strlen(opt) + 1);
2339 char *o_org = opt;
2340 int olen = s - opt;
2341 int len;
2342
2343 /*
2344 * Copy part of the string before the keyword and
2345 * sprintf() the replacement after it.
2346 */
2347 memcpy(new, opt, olen);
2348 len = sprintf(new + olen, "%s", kw->replace);
2349
2350 /*
2351 * If there's more in the original string, copy that
2352 * in too
2353 */
2354 opt += strlen(kw->word) + olen;
2355 if (strlen(opt))
2356 memcpy(new + olen + len, opt, opt - o_org - 1);
2357
2358 /*
2359 * replace opt and free the old opt
2360 */
2361 opt = new;
Steven Langd0c814e2011-10-28 08:37:13 +02002362 free(o_org);
Jens Axboe7a958bd2009-11-13 12:33:54 +01002363
Steven Langd0c814e2011-10-28 08:37:13 +02002364 docalc = 1;
Jens Axboe74929ac2009-08-05 11:42:37 +02002365 }
2366 }
2367
Steven Langd0c814e2011-10-28 08:37:13 +02002368 /*
2369 * Check for potential math and invoke bc, if possible
2370 */
2371 if (docalc)
2372 opt = bc_calc(opt);
2373
Jens Axboe7a958bd2009-11-13 12:33:54 +01002374 return opt;
Jens Axboe74929ac2009-08-05 11:42:37 +02002375}
2376
Steven Langd0c814e2011-10-28 08:37:13 +02002377static char **dup_and_sub_options(char **opts, int num_opts)
2378{
2379 int i;
2380 char **opts_copy = malloc(num_opts * sizeof(*opts));
2381 for (i = 0; i < num_opts; i++) {
2382 opts_copy[i] = option_dup_subs(opts[i]);
2383 if (!opts_copy[i])
2384 continue;
2385 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2386 }
2387 return opts_copy;
2388}
2389
Jens Axboe3b8b7132008-06-10 19:46:23 +02002390int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01002391{
Jens Axboe3b8b7132008-06-10 19:46:23 +02002392 int i, ret;
Steven Langd0c814e2011-10-28 08:37:13 +02002393 char **opts_copy;
Jens Axboe3b8b7132008-06-10 19:46:23 +02002394
2395 sort_options(opts, options, num_opts);
Steven Langd0c814e2011-10-28 08:37:13 +02002396 opts_copy = dup_and_sub_options(opts, num_opts);
Jens Axboe3b8b7132008-06-10 19:46:23 +02002397
Jens Axboe74929ac2009-08-05 11:42:37 +02002398 for (ret = 0, i = 0; i < num_opts; i++) {
Steven Langd0c814e2011-10-28 08:37:13 +02002399 ret |= parse_option(opts_copy[i], opts[i], options, td);
2400
2401 if (opts_copy[i])
2402 free(opts_copy[i]);
2403 opts_copy[i] = NULL;
Jens Axboe74929ac2009-08-05 11:42:37 +02002404 }
Jens Axboe3b8b7132008-06-10 19:46:23 +02002405
Steven Langd0c814e2011-10-28 08:37:13 +02002406 free(opts_copy);
Jens Axboe3b8b7132008-06-10 19:46:23 +02002407 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01002408}
2409
2410int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2411{
Jens Axboe07b32322010-03-05 09:48:44 +01002412 return parse_cmd_option(opt, val, options, td);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002413}
2414
2415void fio_fill_default_options(struct thread_data *td)
2416{
2417 fill_default_options(td, options);
2418}
2419
2420int fio_show_option_help(const char *opt)
2421{
Jens Axboe07b32322010-03-05 09:48:44 +01002422 return show_cmd_help(options, opt);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002423}
Jens Axboed23bb322007-03-23 15:57:56 +01002424
Jens Axboe7e356b22011-10-14 10:55:16 +02002425/*
2426 * dupe FIO_OPT_STR_STORE options
2427 */
2428void options_mem_dupe(struct thread_data *td)
Jens Axboed23bb322007-03-23 15:57:56 +01002429{
2430 struct thread_options *o = &td->o;
2431 struct fio_option *opt;
2432 char **ptr;
2433 int i;
2434
2435 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2436 if (opt->type != FIO_OPT_STR_STORE)
2437 continue;
2438
2439 ptr = (void *) o + opt->off1;
Jens Axboe7e356b22011-10-14 10:55:16 +02002440 if (!*ptr)
2441 ptr = td_var(o, opt->off1);
2442 if (*ptr)
2443 *ptr = strdup(*ptr);
Jens Axboed23bb322007-03-23 15:57:56 +01002444 }
2445}
2446
Jens Axboed6978a32009-07-18 21:04:09 +02002447unsigned int fio_get_kb_base(void *data)
2448{
2449 struct thread_data *td = data;
2450 unsigned int kb_base = 0;
2451
2452 if (td)
2453 kb_base = td->o.kb_base;
2454 if (!kb_base)
2455 kb_base = 1024;
2456
2457 return kb_base;
2458}
Jens Axboe9f988e22010-03-04 10:42:38 +01002459
Jens Axboe07b32322010-03-05 09:48:44 +01002460int add_option(struct fio_option *o)
Jens Axboe9f988e22010-03-04 10:42:38 +01002461{
Jens Axboe07b32322010-03-05 09:48:44 +01002462 struct fio_option *__o;
2463 int opt_index = 0;
2464
2465 __o = options;
2466 while (__o->name) {
2467 opt_index++;
2468 __o++;
2469 }
2470
2471 memcpy(&options[opt_index], o, sizeof(*o));
2472 return 0;
Jens Axboe9f988e22010-03-04 10:42:38 +01002473}
Jens Axboee2de69d2010-03-04 14:05:48 +01002474
Jens Axboe07b32322010-03-05 09:48:44 +01002475void invalidate_profile_options(const char *prof_name)
Jens Axboee2de69d2010-03-04 14:05:48 +01002476{
Jens Axboe07b32322010-03-05 09:48:44 +01002477 struct fio_option *o;
Jens Axboee2de69d2010-03-04 14:05:48 +01002478
Jens Axboe07b32322010-03-05 09:48:44 +01002479 o = options;
2480 while (o->name) {
2481 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2482 o->type = FIO_OPT_INVALID;
2483 o->prof_name = NULL;
2484 }
2485 o++;
Jens Axboee2de69d2010-03-04 14:05:48 +01002486 }
2487}
Jens Axboef5b6bb82010-03-05 10:09:59 +01002488
2489void add_opt_posval(const char *optname, const char *ival, const char *help)
2490{
2491 struct fio_option *o;
2492 unsigned int i;
2493
2494 o = find_option(options, optname);
2495 if (!o)
2496 return;
2497
2498 for (i = 0; i < PARSE_MAX_VP; i++) {
2499 if (o->posval[i].ival)
2500 continue;
2501
2502 o->posval[i].ival = ival;
2503 o->posval[i].help = help;
2504 break;
2505 }
2506}
2507
2508void del_opt_posval(const char *optname, const char *ival)
2509{
2510 struct fio_option *o;
2511 unsigned int i;
2512
2513 o = find_option(options, optname);
2514 if (!o)
2515 return;
2516
2517 for (i = 0; i < PARSE_MAX_VP; i++) {
2518 if (!o->posval[i].ival)
2519 continue;
2520 if (strcmp(o->posval[i].ival, ival))
2521 continue;
2522
2523 o->posval[i].ival = NULL;
2524 o->posval[i].help = NULL;
2525 }
2526}
Jens Axboe7e356b22011-10-14 10:55:16 +02002527
2528void fio_options_free(struct thread_data *td)
2529{
2530 options_free(options, td);
2531}