blob: 82e3e279dfe342f66ea98098604655630568a703 [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
Kenneth Watersdf9cf922009-10-15 07:08:48 +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 Axboe182ec6e2008-11-14 13:06:06 +0100206 if (nr) {
Jens Axboe5736c102010-07-20 12:03:25 -0600207 td->o.ddir_seq_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100208 free(nr);
209 }
Jens Axboe211097b2007-03-22 18:56:45 +0100210
Jens Axboe211097b2007-03-22 18:56:45 +0100211 return 0;
212}
213
Jens Axboe214e1ec2007-03-15 10:48:13 +0100214static int str_mem_cb(void *data, const char *mem)
215{
216 struct thread_data *td = data;
217
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100218 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100219 td->mmapfile = get_opt_postfix(mem);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100220 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100221 log_err("fio: mmaphuge:/path/to/file\n");
222 return 1;
223 }
224 }
225
226 return 0;
227}
228
Jens Axboe5d7c5d32010-06-21 15:08:17 +0200229static int str_verify_cb(void *data, const char *mem)
230{
231 struct thread_data *td = data;
232
233 if (td->o.verify != VERIFY_CRC32C_INTEL)
234 return 0;
235
236 if (!crc32c_intel_works()) {
237 log_info("fio: System does not support hw accelerated crc32c. Falling back to sw crc32c.\n");
238 td->o.verify = VERIFY_CRC32C;
239 }
240
241 return 0;
242}
243
Jens Axboec223da82010-03-24 13:23:53 +0100244static int fio_clock_source_cb(void *data, const char *str)
245{
246 struct thread_data *td = data;
247
248 fio_clock_source = td->o.clocksource;
249 fio_time_init();
250 return 0;
251}
252
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400253static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100254{
255 mlock_size = *val;
256 return 0;
257}
258
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400259static int str_rwmix_read_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200260{
261 struct thread_data *td = data;
262
263 td->o.rwmix[DDIR_READ] = *val;
264 td->o.rwmix[DDIR_WRITE] = 100 - *val;
265 return 0;
266}
267
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400268static int str_rwmix_write_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200269{
270 struct thread_data *td = data;
271
272 td->o.rwmix[DDIR_WRITE] = *val;
273 td->o.rwmix[DDIR_READ] = 100 - *val;
274 return 0;
275}
276
Jens Axboe214e1ec2007-03-15 10:48:13 +0100277#ifdef FIO_HAVE_IOPRIO
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400278static int str_prioclass_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100279{
280 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200281 unsigned short mask;
282
283 /*
284 * mask off old class bits, str_prio_cb() may have set a default class
285 */
286 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
287 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100288
289 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
Jens Axboeac684782007-11-08 08:29:07 +0100290 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100291 return 0;
292}
293
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400294static int str_prio_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100295{
296 struct thread_data *td = data;
297
298 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200299
300 /*
301 * If no class is set, assume BE
302 */
303 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
304 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
305
Jens Axboeac684782007-11-08 08:29:07 +0100306 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100307 return 0;
308}
309#endif
310
311static int str_exitall_cb(void)
312{
313 exitall_on_terminate = 1;
314 return 0;
315}
316
Jens Axboe214e1ec2007-03-15 10:48:13 +0100317#ifdef FIO_HAVE_CPU_AFFINITY
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400318static int str_cpumask_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100319{
320 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200321 unsigned int i;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100322 long max_cpu;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100323 int ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100324
Jens Axboed2ce18b2008-12-12 20:51:40 +0100325 ret = fio_cpuset_init(&td->o.cpumask);
326 if (ret < 0) {
327 log_err("fio: cpuset_init failed\n");
328 td_verror(td, ret, "fio_cpuset_init");
329 return 1;
330 }
331
Jens Axboec00a2282011-07-08 20:56:06 +0200332 max_cpu = cpus_online();
Jens Axboed2e268b2007-06-15 10:33:49 +0200333
Jens Axboe62a72732008-12-08 11:37:01 +0100334 for (i = 0; i < sizeof(int) * 8; i++) {
335 if ((1 << i) & *val) {
Jens Axboeb03daaf2008-12-08 20:31:43 +0100336 if (i > max_cpu) {
337 log_err("fio: CPU %d too large (max=%ld)\n", i,
338 max_cpu);
339 return 1;
340 }
Jens Axboe62a72732008-12-08 11:37:01 +0100341 dprint(FD_PARSE, "set cpu allowed %d\n", i);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100342 fio_cpu_set(&td->o.cpumask, i);
Jens Axboe62a72732008-12-08 11:37:01 +0100343 }
344 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200345
Jens Axboe375b2692007-05-22 09:13:02 +0200346 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100347 return 0;
348}
349
Jens Axboee8462bd2009-07-06 12:59:04 +0200350static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
351 const char *input)
Jens Axboed2e268b2007-06-15 10:33:49 +0200352{
Jens Axboed2e268b2007-06-15 10:33:49 +0200353 char *cpu, *str, *p;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100354 long max_cpu;
Jens Axboe19608d62008-12-08 15:03:12 +0100355 int ret = 0;
Jens Axboed2e268b2007-06-15 10:33:49 +0200356
Jens Axboee8462bd2009-07-06 12:59:04 +0200357 ret = fio_cpuset_init(mask);
Jens Axboed2ce18b2008-12-12 20:51:40 +0100358 if (ret < 0) {
359 log_err("fio: cpuset_init failed\n");
360 td_verror(td, ret, "fio_cpuset_init");
361 return 1;
362 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200363
364 p = str = strdup(input);
365
366 strip_blank_front(&str);
367 strip_blank_end(str);
368
Jens Axboec00a2282011-07-08 20:56:06 +0200369 max_cpu = cpus_online();
Jens Axboeb03daaf2008-12-08 20:31:43 +0100370
Jens Axboed2e268b2007-06-15 10:33:49 +0200371 while ((cpu = strsep(&str, ",")) != NULL) {
Jens Axboe62a72732008-12-08 11:37:01 +0100372 char *str2, *cpu2;
373 int icpu, icpu2;
374
Jens Axboed2e268b2007-06-15 10:33:49 +0200375 if (!strlen(cpu))
376 break;
Jens Axboe62a72732008-12-08 11:37:01 +0100377
378 str2 = cpu;
379 icpu2 = -1;
380 while ((cpu2 = strsep(&str2, "-")) != NULL) {
381 if (!strlen(cpu2))
382 break;
383
384 icpu2 = atoi(cpu2);
385 }
386
387 icpu = atoi(cpu);
388 if (icpu2 == -1)
389 icpu2 = icpu;
390 while (icpu <= icpu2) {
Jens Axboe6d459ee2008-12-12 20:02:58 +0100391 if (icpu >= FIO_MAX_CPUS) {
Jens Axboe19608d62008-12-08 15:03:12 +0100392 log_err("fio: your OS only supports up to"
Jens Axboe6d459ee2008-12-12 20:02:58 +0100393 " %d CPUs\n", (int) FIO_MAX_CPUS);
Jens Axboe19608d62008-12-08 15:03:12 +0100394 ret = 1;
395 break;
396 }
Jens Axboeb03daaf2008-12-08 20:31:43 +0100397 if (icpu > max_cpu) {
398 log_err("fio: CPU %d too large (max=%ld)\n",
399 icpu, max_cpu);
400 ret = 1;
401 break;
402 }
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200403
Jens Axboe62a72732008-12-08 11:37:01 +0100404 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
Jens Axboee8462bd2009-07-06 12:59:04 +0200405 fio_cpu_set(mask, icpu);
Jens Axboe62a72732008-12-08 11:37:01 +0100406 icpu++;
407 }
Jens Axboe19608d62008-12-08 15:03:12 +0100408 if (ret)
409 break;
Jens Axboed2e268b2007-06-15 10:33:49 +0200410 }
411
412 free(p);
Jens Axboe19608d62008-12-08 15:03:12 +0100413 if (!ret)
414 td->o.cpumask_set = 1;
415 return ret;
Jens Axboed2e268b2007-06-15 10:33:49 +0200416}
Jens Axboee8462bd2009-07-06 12:59:04 +0200417
418static int str_cpus_allowed_cb(void *data, const char *input)
419{
420 struct thread_data *td = data;
421 int ret;
422
423 ret = set_cpus_allowed(td, &td->o.cpumask, input);
424 if (!ret)
425 td->o.cpumask_set = 1;
426
427 return ret;
428}
429
430static int str_verify_cpus_allowed_cb(void *data, const char *input)
431{
432 struct thread_data *td = data;
433 int ret;
434
435 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
436 if (!ret)
437 td->o.verify_cpumask_set = 1;
438
439 return ret;
440}
Jens Axboed2e268b2007-06-15 10:33:49 +0200441#endif
442
Jens Axboe0d29de82010-09-01 13:54:15 +0200443#ifdef FIO_HAVE_TRIM
444static int str_verify_trim_cb(void *data, unsigned long long *val)
445{
446 struct thread_data *td = data;
447
448 td->o.trim_percentage = *val;
449 return 0;
450}
451#endif
452
Jens Axboe214e1ec2007-03-15 10:48:13 +0100453static int str_fst_cb(void *data, const char *str)
454{
455 struct thread_data *td = data;
456 char *nr = get_opt_postfix(str);
457
458 td->file_service_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100459 if (nr) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100460 td->file_service_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100461 free(nr);
462 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100463
464 return 0;
465}
466
Jens Axboe3ae06372010-03-19 19:17:15 +0100467#ifdef FIO_HAVE_SYNC_FILE_RANGE
Jens Axboe44f29692010-03-09 20:09:44 +0100468static int str_sfr_cb(void *data, const char *str)
469{
470 struct thread_data *td = data;
471 char *nr = get_opt_postfix(str);
472
473 td->sync_file_range_nr = 1;
474 if (nr) {
475 td->sync_file_range_nr = atoi(nr);
476 free(nr);
477 }
478
479 return 0;
480}
Jens Axboe3ae06372010-03-19 19:17:15 +0100481#endif
Jens Axboe44f29692010-03-09 20:09:44 +0100482
Jens Axboe921c7662008-03-26 09:17:55 +0100483static int check_dir(struct thread_data *td, char *fname)
484{
Jens Axboe3f0ca9b2011-05-24 21:36:24 +0200485#if 0
Jens Axboe921c7662008-03-26 09:17:55 +0100486 char file[PATH_MAX], *dir;
Jens Axboebc838912008-04-07 09:00:54 +0200487 int elen = 0;
Jens Axboe921c7662008-03-26 09:17:55 +0100488
Jens Axboebc838912008-04-07 09:00:54 +0200489 if (td->o.directory) {
490 strcpy(file, td->o.directory);
Jens Axboefcef0b32008-05-26 14:53:24 +0200491 strcat(file, "/");
Jens Axboebc838912008-04-07 09:00:54 +0200492 elen = strlen(file);
493 }
494
Jens Axboefcef0b32008-05-26 14:53:24 +0200495 sprintf(file + elen, "%s", fname);
Jens Axboe921c7662008-03-26 09:17:55 +0100496 dir = dirname(file);
497
Jens Axboefcef0b32008-05-26 14:53:24 +0200498 {
499 struct stat sb;
500 /*
501 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
502 * yet, so we can't do this check right here...
503 */
Jens Axboe921c7662008-03-26 09:17:55 +0100504 if (lstat(dir, &sb) < 0) {
505 int ret = errno;
506
507 log_err("fio: %s is not a directory\n", dir);
508 td_verror(td, ret, "lstat");
509 return 1;
510 }
511
512 if (!S_ISDIR(sb.st_mode)) {
513 log_err("fio: %s is not a directory\n", dir);
514 return 1;
515 }
Jens Axboefcef0b32008-05-26 14:53:24 +0200516 }
517#endif
Jens Axboe921c7662008-03-26 09:17:55 +0100518
519 return 0;
520}
521
Jens Axboe8e827d32009-08-04 09:51:48 +0200522/*
523 * Return next file in the string. Files are separated with ':'. If the ':'
524 * is escaped with a '\', then that ':' is part of the filename and does not
525 * indicate a new file.
526 */
527static char *get_next_file_name(char **ptr)
528{
529 char *str = *ptr;
530 char *p, *start;
531
532 if (!str || !strlen(str))
533 return NULL;
534
535 start = str;
536 do {
537 /*
538 * No colon, we are done
539 */
540 p = strchr(str, ':');
541 if (!p) {
542 *ptr = NULL;
543 break;
544 }
545
546 /*
547 * We got a colon, but it's the first character. Skip and
548 * continue
549 */
550 if (p == start) {
551 str = ++start;
552 continue;
553 }
554
555 if (*(p - 1) != '\\') {
556 *p = '\0';
557 *ptr = p + 1;
558 break;
559 }
560
561 memmove(p - 1, p, strlen(p) + 1);
562 str = p;
563 } while (1);
564
565 return start;
566}
567
Jens Axboe214e1ec2007-03-15 10:48:13 +0100568static int str_filename_cb(void *data, const char *input)
569{
570 struct thread_data *td = data;
571 char *fname, *str, *p;
572
573 p = str = strdup(input);
574
575 strip_blank_front(&str);
576 strip_blank_end(str);
577
578 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100579 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100580
Jens Axboe8e827d32009-08-04 09:51:48 +0200581 while ((fname = get_next_file_name(&str)) != NULL) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100582 if (!strlen(fname))
583 break;
Jens Axboe921c7662008-03-26 09:17:55 +0100584 if (check_dir(td, fname)) {
585 free(p);
586 return 1;
587 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100588 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100589 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100590 }
591
592 free(p);
593 return 0;
594}
595
596static int str_directory_cb(void *data, const char fio_unused *str)
597{
598 struct thread_data *td = data;
599 struct stat sb;
600
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100601 if (lstat(td->o.directory, &sb) < 0) {
Jens Axboe921c7662008-03-26 09:17:55 +0100602 int ret = errno;
603
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100604 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe921c7662008-03-26 09:17:55 +0100605 td_verror(td, ret, "lstat");
Jens Axboe214e1ec2007-03-15 10:48:13 +0100606 return 1;
607 }
608 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100609 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100610 return 1;
611 }
612
613 return 0;
614}
615
616static int str_opendir_cb(void *data, const char fio_unused *str)
617{
618 struct thread_data *td = data;
619
620 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100621 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100622
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100623 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100624}
625
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400626static int str_verify_offset_cb(void *data, unsigned long long *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200627{
628 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200629
Shawn Lewis546a9142007-07-28 21:11:37 +0200630 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200631 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200632 return 1;
633 }
Jens Axboea59e1702007-07-30 08:53:27 +0200634
635 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200636 return 0;
637}
638
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100639static int str_verify_pattern_cb(void *data, const char *input)
Jens Axboe90059d62007-07-30 09:33:12 +0200640{
641 struct thread_data *td = data;
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100642 long off;
643 int i = 0, j = 0, len, k, base = 10;
644 char* loc1, * loc2;
Jens Axboe90059d62007-07-30 09:33:12 +0200645
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100646 loc1 = strstr(input, "0x");
647 loc2 = strstr(input, "0X");
648 if (loc1 || loc2)
649 base = 16;
650 off = strtol(input, NULL, base);
651 if (off != LONG_MAX || errno != ERANGE) {
652 while (off) {
653 td->o.verify_pattern[i] = off & 0xff;
654 off >>= 8;
655 i++;
656 }
657 } else {
658 len = strlen(input);
659 k = len - 1;
660 if (base == 16) {
661 if (loc1)
662 j = loc1 - input + 2;
663 else
664 j = loc2 - input + 2;
665 } else
666 return 1;
667 if (len - j < MAX_PATTERN_SIZE * 2) {
668 while (k >= j) {
669 off = converthexchartoint(input[k--]);
670 if (k >= j)
671 off += (converthexchartoint(input[k--])
672 * 16);
673 td->o.verify_pattern[i++] = (char) off;
674 }
675 }
676 }
677 td->o.verify_pattern_bytes = i;
Jens Axboe92bf48d2011-01-14 21:20:42 +0100678 /*
679 * VERIFY_META could already be set
680 */
681 if (td->o.verify == VERIFY_NONE)
682 td->o.verify = VERIFY_PATTERN;
Jens Axboe90059d62007-07-30 09:33:12 +0200683 return 0;
684}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100685
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100686static int str_lockfile_cb(void *data, const char *str)
687{
688 struct thread_data *td = data;
689 char *nr = get_opt_postfix(str);
690
691 td->o.lockfile_batch = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100692 if (nr) {
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100693 td->o.lockfile_batch = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100694 free(nr);
695 }
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100696
697 return 0;
698}
699
Jens Axboee3cedca2008-11-19 19:57:52 +0100700static int str_write_bw_log_cb(void *data, const char *str)
701{
702 struct thread_data *td = data;
703
704 if (str)
705 td->o.bw_log_file = strdup(str);
706
707 td->o.write_bw_log = 1;
708 return 0;
709}
710
711static int str_write_lat_log_cb(void *data, const char *str)
712{
713 struct thread_data *td = data;
714
715 if (str)
716 td->o.lat_log_file = strdup(str);
717
718 td->o.write_lat_log = 1;
719 return 0;
720}
721
Jens Axboe993bf482008-11-14 13:04:53 +0100722static int str_gtod_reduce_cb(void *data, int *il)
723{
724 struct thread_data *td = data;
725 int val = *il;
726
Jens Axboe02af0982010-06-24 09:59:34 +0200727 td->o.disable_lat = !!val;
Jens Axboe993bf482008-11-14 13:04:53 +0100728 td->o.disable_clat = !!val;
729 td->o.disable_slat = !!val;
730 td->o.disable_bw = !!val;
731 if (val)
732 td->tv_cache_mask = 63;
733
734 return 0;
735}
736
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400737static int str_gtod_cpu_cb(void *data, long long *il)
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100738{
739 struct thread_data *td = data;
740 int val = *il;
741
742 td->o.gtod_cpu = val;
743 td->o.gtod_offload = 1;
744 return 0;
745}
746
Jens Axboe7bb59102011-07-12 19:47:03 +0200747static int str_size_cb(void *data, unsigned long long *__val)
748{
749 struct thread_data *td = data;
750 unsigned long long v = *__val;
751
752 if (parse_is_percent(v)) {
753 td->o.size = 0;
754 td->o.size_percent = -1ULL - v;
755 } else
756 td->o.size = v;
757
758 return 0;
759}
760
Jens Axboe896cac22009-07-01 10:38:35 +0200761static int rw_verify(struct fio_option *o, void *data)
762{
763 struct thread_data *td = data;
764
765 if (read_only && td_write(td)) {
766 log_err("fio: job <%s> has write bit set, but fio is in"
767 " read-only mode\n", td->o.name);
768 return 1;
769 }
770
771 return 0;
772}
773
Jens Axboe276ca4f2009-07-01 10:43:05 +0200774static int gtod_cpu_verify(struct fio_option *o, void *data)
Jens Axboe29d43ff2009-07-01 10:42:18 +0200775{
Jens Axboe276ca4f2009-07-01 10:43:05 +0200776#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboe29d43ff2009-07-01 10:42:18 +0200777 struct thread_data *td = data;
778
Jens Axboe29d43ff2009-07-01 10:42:18 +0200779 if (td->o.gtod_cpu) {
780 log_err("fio: platform must support CPU affinity for"
781 "gettimeofday() offloading\n");
782 return 1;
783 }
784#endif
785
786 return 0;
787}
788
Jens Axboe90fef2d2009-07-17 22:33:32 +0200789static int kb_base_verify(struct fio_option *o, void *data)
790{
791 struct thread_data *td = data;
792
793 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
794 log_err("fio: kb_base set to nonsensical value: %u\n",
795 td->o.kb_base);
796 return 1;
797 }
798
799 return 0;
800}
801
Jens Axboe214e1ec2007-03-15 10:48:13 +0100802#define __stringify_1(x) #x
803#define __stringify(x) __stringify_1(x)
804
805/*
806 * Map of job/command line options
807 */
Jens Axboe07b32322010-03-05 09:48:44 +0100808static struct fio_option options[FIO_MAX_OPTS] = {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100809 {
810 .name = "description",
811 .type = FIO_OPT_STR_STORE,
812 .off1 = td_var_offset(description),
813 .help = "Text job description",
814 },
815 {
816 .name = "name",
817 .type = FIO_OPT_STR_STORE,
818 .off1 = td_var_offset(name),
819 .help = "Name of this job",
820 },
821 {
822 .name = "directory",
823 .type = FIO_OPT_STR_STORE,
824 .off1 = td_var_offset(directory),
825 .cb = str_directory_cb,
826 .help = "Directory to store files in",
827 },
828 {
829 .name = "filename",
830 .type = FIO_OPT_STR_STORE,
831 .off1 = td_var_offset(filename),
832 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +0200833 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +0100834 .help = "File(s) to use for the workload",
835 },
836 {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200837 .name = "kb_base",
838 .type = FIO_OPT_INT,
839 .off1 = td_var_offset(kb_base),
Jens Axboe90fef2d2009-07-17 22:33:32 +0200840 .verify = kb_base_verify,
Jens Axboea639f0b2009-07-18 08:25:35 +0200841 .prio = 1,
Jens Axboe90fef2d2009-07-17 22:33:32 +0200842 .def = "1024",
Jens Axboea639f0b2009-07-18 08:25:35 +0200843 .help = "How many bytes per KB for reporting (1000 or 1024)",
Jens Axboe90fef2d2009-07-17 22:33:32 +0200844 },
845 {
Jens Axboe29c13492008-03-01 19:25:20 +0100846 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100847 .type = FIO_OPT_STR,
848 .cb = str_lockfile_cb,
849 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +0100850 .help = "Lock file when doing IO to it",
851 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100852 .def = "none",
853 .posval = {
854 { .ival = "none",
855 .oval = FILE_LOCK_NONE,
856 .help = "No file locking",
857 },
858 { .ival = "exclusive",
859 .oval = FILE_LOCK_EXCLUSIVE,
860 .help = "Exclusive file lock",
861 },
862 {
863 .ival = "readwrite",
864 .oval = FILE_LOCK_READWRITE,
865 .help = "Read vs write lock",
866 },
867 },
Jens Axboe29c13492008-03-01 19:25:20 +0100868 },
869 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100870 .name = "opendir",
871 .type = FIO_OPT_STR_STORE,
872 .off1 = td_var_offset(opendir),
873 .cb = str_opendir_cb,
874 .help = "Recursively add files from this directory and down",
875 },
876 {
877 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100878 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100879 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +0100880 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100881 .off1 = td_var_offset(td_ddir),
882 .help = "IO direction",
883 .def = "read",
Jens Axboe896cac22009-07-01 10:38:35 +0200884 .verify = rw_verify,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100885 .posval = {
886 { .ival = "read",
887 .oval = TD_DDIR_READ,
888 .help = "Sequential read",
889 },
890 { .ival = "write",
891 .oval = TD_DDIR_WRITE,
892 .help = "Sequential write",
893 },
894 { .ival = "randread",
895 .oval = TD_DDIR_RANDREAD,
896 .help = "Random read",
897 },
898 { .ival = "randwrite",
899 .oval = TD_DDIR_RANDWRITE,
900 .help = "Random write",
901 },
902 { .ival = "rw",
903 .oval = TD_DDIR_RW,
904 .help = "Sequential read and write mix",
905 },
906 { .ival = "randrw",
907 .oval = TD_DDIR_RANDRW,
908 .help = "Random read and write mix"
909 },
910 },
911 },
912 {
Jens Axboe38dad622010-07-20 14:46:00 -0600913 .name = "rw_sequencer",
914 .type = FIO_OPT_STR,
915 .off1 = td_var_offset(rw_seq),
916 .help = "IO offset generator modifier",
917 .def = "sequential",
918 .posval = {
919 { .ival = "sequential",
920 .oval = RW_SEQ_SEQ,
921 .help = "Generate sequential offsets",
922 },
923 { .ival = "identical",
924 .oval = RW_SEQ_IDENT,
925 .help = "Generate identical offsets",
926 },
927 },
928 },
929
930 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100931 .name = "ioengine",
932 .type = FIO_OPT_STR_STORE,
933 .off1 = td_var_offset(ioengine),
934 .help = "IO engine to use",
Jens Axboe58483fa2011-01-19 11:09:58 -0700935 .def = FIO_PREFERRED_ENGINE,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100936 .posval = {
937 { .ival = "sync",
938 .help = "Use read/write",
939 },
gurudas paia31041e2007-10-23 15:12:30 +0200940 { .ival = "psync",
941 .help = "Use pread/pwrite",
942 },
Jens Axboe1d2af022008-02-04 10:59:07 +0100943 { .ival = "vsync",
Bruce Cran03e20d62011-01-02 20:14:54 +0100944 .help = "Use readv/writev",
Jens Axboe1d2af022008-02-04 10:59:07 +0100945 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100946#ifdef FIO_HAVE_LIBAIO
947 { .ival = "libaio",
948 .help = "Linux native asynchronous IO",
949 },
950#endif
951#ifdef FIO_HAVE_POSIXAIO
952 { .ival = "posixaio",
953 .help = "POSIX asynchronous IO",
954 },
955#endif
Jens Axboe417f0062008-06-02 11:59:30 +0200956#ifdef FIO_HAVE_SOLARISAIO
957 { .ival = "solarisaio",
958 .help = "Solaris native asynchronous IO",
959 },
960#endif
Bruce Cran03e20d62011-01-02 20:14:54 +0100961#ifdef FIO_HAVE_WINDOWSAIO
962 { .ival = "windowsaio",
Jens Axboe3be80072011-01-19 11:07:28 -0700963 .help = "Windows native asynchronous IO"
Bruce Cran03e20d62011-01-02 20:14:54 +0100964 },
Jens Axboe3be80072011-01-19 11:07:28 -0700965#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100966 { .ival = "mmap",
Bruce Cran03e20d62011-01-02 20:14:54 +0100967 .help = "Memory mapped IO"
Jens Axboe214e1ec2007-03-15 10:48:13 +0100968 },
969#ifdef FIO_HAVE_SPLICE
970 { .ival = "splice",
971 .help = "splice/vmsplice based IO",
972 },
Jens Axboe9cce02e2007-06-22 15:42:21 +0200973 { .ival = "netsplice",
974 .help = "splice/vmsplice to/from the network",
975 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100976#endif
977#ifdef FIO_HAVE_SGIO
978 { .ival = "sg",
979 .help = "SCSI generic v3 IO",
980 },
981#endif
982 { .ival = "null",
983 .help = "Testing engine (no data transfer)",
984 },
985 { .ival = "net",
986 .help = "Network IO",
987 },
988#ifdef FIO_HAVE_SYSLET
989 { .ival = "syslet-rw",
990 .help = "syslet enabled async pread/pwrite IO",
991 },
992#endif
993 { .ival = "cpuio",
Bruce Cran03e20d62011-01-02 20:14:54 +0100994 .help = "CPU cycle burner engine",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100995 },
Jens Axboeb8c82a42007-03-21 08:48:26 +0100996#ifdef FIO_HAVE_GUASI
997 { .ival = "guasi",
998 .help = "GUASI IO engine",
999 },
1000#endif
Jens Axboe79a43182010-09-07 13:28:58 +02001001#ifdef FIO_HAVE_BINJECT
1002 { .ival = "binject",
1003 .help = "binject direct inject block engine",
1004 },
1005#endif
ren yufei21b8aee2011-08-01 10:01:57 +02001006#ifdef FIO_HAVE_RDMA
1007 { .ival = "rdma",
1008 .help = "RDMA IO engine",
1009 },
1010#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001011 { .ival = "external",
1012 .help = "Load external engine (append name)",
1013 },
1014 },
1015 },
1016 {
1017 .name = "iodepth",
1018 .type = FIO_OPT_INT,
1019 .off1 = td_var_offset(iodepth),
Bruce Cran03e20d62011-01-02 20:14:54 +01001020 .help = "Number of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +01001021 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001022 .def = "1",
1023 },
1024 {
1025 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +02001026 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001027 .type = FIO_OPT_INT,
1028 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +01001029 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +02001030 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +01001031 .minval = 1,
1032 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001033 },
1034 {
Jens Axboe49504212008-06-05 09:03:30 +02001035 .name = "iodepth_batch_complete",
1036 .type = FIO_OPT_INT,
1037 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +01001038 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +02001039 .parent = "iodepth",
1040 .minval = 0,
1041 .def = "1",
1042 },
1043 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001044 .name = "iodepth_low",
1045 .type = FIO_OPT_INT,
1046 .off1 = td_var_offset(iodepth_low),
1047 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +02001048 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001049 },
1050 {
1051 .name = "size",
1052 .type = FIO_OPT_STR_VAL,
Jens Axboe7bb59102011-07-12 19:47:03 +02001053 .cb = str_size_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001054 .help = "Total size of device or files",
1055 },
1056 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001057 .name = "fill_device",
Jens Axboe74586c12011-01-20 10:16:03 -07001058 .alias = "fill_fs",
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001059 .type = FIO_OPT_BOOL,
1060 .off1 = td_var_offset(fill_device),
1061 .help = "Write until an ENOSPC error occurs",
1062 .def = "0",
1063 },
1064 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001065 .name = "filesize",
1066 .type = FIO_OPT_STR_VAL,
1067 .off1 = td_var_offset(file_size_low),
1068 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001069 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001070 .help = "Size of individual files",
1071 },
1072 {
Jens Axboe67a10002007-07-31 23:12:16 +02001073 .name = "offset",
1074 .alias = "fileoffset",
1075 .type = FIO_OPT_STR_VAL,
1076 .off1 = td_var_offset(start_offset),
1077 .help = "Start IO from this offset",
1078 .def = "0",
1079 },
1080 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001081 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001082 .alias = "blocksize",
Jens Axboee01b22b2009-06-09 15:43:25 +02001083 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001084 .off1 = td_var_offset(bs[DDIR_READ]),
1085 .off2 = td_var_offset(bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001086 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001087 .help = "Block size unit",
1088 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +02001089 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001090 },
1091 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001092 .name = "ba",
1093 .alias = "blockalign",
Jens Axboee01b22b2009-06-09 15:43:25 +02001094 .type = FIO_OPT_INT,
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001095 .off1 = td_var_offset(ba[DDIR_READ]),
1096 .off2 = td_var_offset(ba[DDIR_WRITE]),
1097 .minval = 1,
1098 .help = "IO block offset alignment",
1099 .parent = "rw",
1100 },
1101 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001102 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001103 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001104 .type = FIO_OPT_RANGE,
1105 .off1 = td_var_offset(min_bs[DDIR_READ]),
1106 .off2 = td_var_offset(max_bs[DDIR_READ]),
1107 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1108 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001109 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001110 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +02001111 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001112 },
1113 {
Jens Axboe564ca972007-12-14 12:21:19 +01001114 .name = "bssplit",
1115 .type = FIO_OPT_STR,
1116 .cb = str_bssplit_cb,
1117 .help = "Set a specific mix of block sizes",
1118 .parent = "rw",
1119 },
1120 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001121 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001122 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001123 .type = FIO_OPT_STR_SET,
1124 .off1 = td_var_offset(bs_unaligned),
1125 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +02001126 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001127 },
1128 {
1129 .name = "randrepeat",
1130 .type = FIO_OPT_BOOL,
1131 .off1 = td_var_offset(rand_repeatable),
1132 .help = "Use repeatable random IO pattern",
1133 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +02001134 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001135 },
1136 {
Jens Axboe2615cc42011-03-28 09:35:09 +02001137 .name = "use_os_rand",
1138 .type = FIO_OPT_BOOL,
1139 .off1 = td_var_offset(use_os_rand),
1140 .help = "Set to use OS random generator",
1141 .def = "0",
1142 .parent = "rw",
1143 },
1144 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001145 .name = "norandommap",
1146 .type = FIO_OPT_STR_SET,
1147 .off1 = td_var_offset(norandommap),
1148 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +02001149 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001150 },
1151 {
Jens Axboe2b386d22008-03-26 10:32:57 +01001152 .name = "softrandommap",
1153 .type = FIO_OPT_BOOL,
1154 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001155 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +01001156 .parent = "norandommap",
1157 .def = "0",
1158 },
1159 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001160 .name = "nrfiles",
Jens Axboed7c8be02010-11-25 08:21:39 +01001161 .alias = "nr_files",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001162 .type = FIO_OPT_INT,
1163 .off1 = td_var_offset(nr_files),
1164 .help = "Split job workload between this number of files",
1165 .def = "1",
1166 },
1167 {
1168 .name = "openfiles",
1169 .type = FIO_OPT_INT,
1170 .off1 = td_var_offset(open_files),
1171 .help = "Number of files to keep open at the same time",
1172 },
1173 {
1174 .name = "file_service_type",
1175 .type = FIO_OPT_STR,
1176 .cb = str_fst_cb,
1177 .off1 = td_var_offset(file_service_type),
1178 .help = "How to select which file to service next",
1179 .def = "roundrobin",
1180 .posval = {
1181 { .ival = "random",
1182 .oval = FIO_FSERVICE_RANDOM,
1183 .help = "Choose a file at random",
1184 },
1185 { .ival = "roundrobin",
1186 .oval = FIO_FSERVICE_RR,
1187 .help = "Round robin select files",
1188 },
Jens Axboea086c252009-03-04 08:27:37 +01001189 { .ival = "sequential",
1190 .oval = FIO_FSERVICE_SEQ,
1191 .help = "Finish one file before moving to the next",
1192 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001193 },
Jens Axboe67a10002007-07-31 23:12:16 +02001194 .parent = "nrfiles",
1195 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001196#ifdef FIO_HAVE_FALLOCATE
1197 {
1198 .name = "fallocate",
Eric Gourioua596f042011-06-17 09:11:45 +02001199 .type = FIO_OPT_STR,
1200 .off1 = td_var_offset(fallocate_mode),
1201 .help = "Whether pre-allocation is performed when laying out files",
1202 .def = "posix",
1203 .posval = {
1204 { .ival = "none",
1205 .oval = FIO_FALLOCATE_NONE,
1206 .help = "Do not pre-allocate space",
1207 },
1208 { .ival = "posix",
1209 .oval = FIO_FALLOCATE_POSIX,
1210 .help = "Use posix_fallocate()",
1211 },
1212#ifdef FIO_HAVE_LINUX_FALLOCATE
1213 { .ival = "keep",
1214 .oval = FIO_FALLOCATE_KEEP_SIZE,
1215 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1216 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001217#endif
Eric Gourioua596f042011-06-17 09:11:45 +02001218 /* Compatibility with former boolean values */
1219 { .ival = "0",
1220 .oval = FIO_FALLOCATE_NONE,
1221 .help = "Alias for 'none'",
1222 },
1223 { .ival = "1",
1224 .oval = FIO_FALLOCATE_POSIX,
1225 .help = "Alias for 'posix'",
1226 },
1227 },
1228 },
1229#endif /* FIO_HAVE_FALLOCATE */
Jens Axboe67a10002007-07-31 23:12:16 +02001230 {
1231 .name = "fadvise_hint",
1232 .type = FIO_OPT_BOOL,
1233 .off1 = td_var_offset(fadvise_hint),
1234 .help = "Use fadvise() to advise the kernel on IO pattern",
1235 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001236 },
1237 {
1238 .name = "fsync",
1239 .type = FIO_OPT_INT,
1240 .off1 = td_var_offset(fsync_blocks),
1241 .help = "Issue fsync for writes every given number of blocks",
1242 .def = "0",
1243 },
1244 {
Jens Axboe5f9099e2009-06-16 22:40:26 +02001245 .name = "fdatasync",
1246 .type = FIO_OPT_INT,
1247 .off1 = td_var_offset(fdatasync_blocks),
1248 .help = "Issue fdatasync for writes every given number of blocks",
1249 .def = "0",
1250 },
Jens Axboe1ef2b6b2010-10-08 15:07:01 +02001251 {
1252 .name = "write_barrier",
1253 .type = FIO_OPT_INT,
1254 .off1 = td_var_offset(barrier_blocks),
1255 .help = "Make every Nth write a barrier write",
1256 .def = "0",
1257 },
Jens Axboe44f29692010-03-09 20:09:44 +01001258#ifdef FIO_HAVE_SYNC_FILE_RANGE
1259 {
1260 .name = "sync_file_range",
1261 .posval = {
1262 { .ival = "wait_before",
1263 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1264 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001265 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001266 },
1267 { .ival = "write",
1268 .oval = SYNC_FILE_RANGE_WRITE,
1269 .help = "SYNC_FILE_RANGE_WRITE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001270 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001271 },
1272 {
1273 .ival = "wait_after",
1274 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1275 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
Jens Axboe3843deb2010-03-09 20:41:15 +01001276 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001277 },
1278 },
Jens Axboe3843deb2010-03-09 20:41:15 +01001279 .type = FIO_OPT_STR_MULTI,
Jens Axboe44f29692010-03-09 20:09:44 +01001280 .cb = str_sfr_cb,
1281 .off1 = td_var_offset(sync_file_range),
1282 .help = "Use sync_file_range()",
1283 },
1284#endif
Jens Axboe5f9099e2009-06-16 22:40:26 +02001285 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001286 .name = "direct",
1287 .type = FIO_OPT_BOOL,
1288 .off1 = td_var_offset(odirect),
1289 .help = "Use O_DIRECT IO (negates buffered)",
1290 .def = "0",
1291 },
1292 {
1293 .name = "buffered",
1294 .type = FIO_OPT_BOOL,
1295 .off1 = td_var_offset(odirect),
1296 .neg = 1,
1297 .help = "Use buffered IO (negates direct)",
1298 .def = "1",
1299 },
1300 {
1301 .name = "overwrite",
1302 .type = FIO_OPT_BOOL,
1303 .off1 = td_var_offset(overwrite),
1304 .help = "When writing, set whether to overwrite current data",
1305 .def = "0",
1306 },
1307 {
1308 .name = "loops",
1309 .type = FIO_OPT_INT,
1310 .off1 = td_var_offset(loops),
1311 .help = "Number of times to run the job",
1312 .def = "1",
1313 },
1314 {
1315 .name = "numjobs",
1316 .type = FIO_OPT_INT,
1317 .off1 = td_var_offset(numjobs),
1318 .help = "Duplicate this job this many times",
1319 .def = "1",
1320 },
1321 {
1322 .name = "startdelay",
Jens Axboea5737c92010-06-29 10:40:30 +02001323 .type = FIO_OPT_STR_VAL_TIME,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001324 .off1 = td_var_offset(start_delay),
1325 .help = "Only start job when this period has passed",
1326 .def = "0",
1327 },
1328 {
1329 .name = "runtime",
1330 .alias = "timeout",
1331 .type = FIO_OPT_STR_VAL_TIME,
1332 .off1 = td_var_offset(timeout),
1333 .help = "Stop workload when this amount of time has passed",
1334 .def = "0",
1335 },
1336 {
Jens Axboecf4464c2007-04-17 20:14:42 +02001337 .name = "time_based",
1338 .type = FIO_OPT_STR_SET,
1339 .off1 = td_var_offset(time_based),
1340 .help = "Keep running until runtime/timeout is met",
1341 },
1342 {
Jens Axboe721938a2008-09-10 09:46:16 +02001343 .name = "ramp_time",
1344 .type = FIO_OPT_STR_VAL_TIME,
1345 .off1 = td_var_offset(ramp_time),
1346 .help = "Ramp up time before measuring performance",
1347 },
1348 {
Jens Axboec223da82010-03-24 13:23:53 +01001349 .name = "clocksource",
1350 .type = FIO_OPT_STR,
1351 .cb = fio_clock_source_cb,
1352 .off1 = td_var_offset(clocksource),
1353 .help = "What type of timing source to use",
Jens Axboec223da82010-03-24 13:23:53 +01001354 .posval = {
1355 { .ival = "gettimeofday",
1356 .oval = CS_GTOD,
1357 .help = "Use gettimeofday(2) for timing",
1358 },
1359 { .ival = "clock_gettime",
1360 .oval = CS_CGETTIME,
1361 .help = "Use clock_gettime(2) for timing",
1362 },
1363#ifdef ARCH_HAVE_CPU_CLOCK
1364 { .ival = "cpu",
1365 .oval = CS_CPUCLOCK,
1366 .help = "Use CPU private clock",
1367 },
1368#endif
1369 },
1370 },
1371 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001372 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001373 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001374 .type = FIO_OPT_STR,
1375 .cb = str_mem_cb,
1376 .off1 = td_var_offset(mem_type),
1377 .help = "Backing type for IO buffers",
1378 .def = "malloc",
1379 .posval = {
1380 { .ival = "malloc",
1381 .oval = MEM_MALLOC,
1382 .help = "Use malloc(3) for IO buffers",
1383 },
Jens Axboeb370e462007-03-19 10:51:49 +01001384 { .ival = "shm",
1385 .oval = MEM_SHM,
1386 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001387 },
1388#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001389 { .ival = "shmhuge",
1390 .oval = MEM_SHMHUGE,
1391 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001392 },
1393#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001394 { .ival = "mmap",
1395 .oval = MEM_MMAP,
1396 .help = "Use mmap(2) (file or anon) for IO buffers",
1397 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001398#ifdef FIO_HAVE_HUGETLB
1399 { .ival = "mmaphuge",
1400 .oval = MEM_MMAPHUGE,
1401 .help = "Like mmap, but use huge pages",
1402 },
1403#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001404 },
1405 },
1406 {
Jens Axboed529ee12009-07-01 10:33:03 +02001407 .name = "iomem_align",
1408 .alias = "mem_align",
1409 .type = FIO_OPT_INT,
1410 .off1 = td_var_offset(mem_align),
1411 .minval = 0,
1412 .help = "IO memory buffer offset alignment",
1413 .def = "0",
1414 .parent = "iomem",
1415 },
1416 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001417 .name = "verify",
1418 .type = FIO_OPT_STR,
1419 .off1 = td_var_offset(verify),
1420 .help = "Verify data written",
Jens Axboe5d7c5d32010-06-21 15:08:17 +02001421 .cb = str_verify_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001422 .def = "0",
1423 .posval = {
1424 { .ival = "0",
1425 .oval = VERIFY_NONE,
1426 .help = "Don't do IO verification",
1427 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001428 { .ival = "md5",
1429 .oval = VERIFY_MD5,
1430 .help = "Use md5 checksums for verification",
1431 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001432 { .ival = "crc64",
1433 .oval = VERIFY_CRC64,
1434 .help = "Use crc64 checksums for verification",
1435 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001436 { .ival = "crc32",
1437 .oval = VERIFY_CRC32,
1438 .help = "Use crc32 checksums for verification",
1439 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001440 { .ival = "crc32c-intel",
1441 .oval = VERIFY_CRC32C_INTEL,
1442 .help = "Use hw crc32c checksums for verification",
1443 },
Jens Axboebac39e02008-06-11 20:46:19 +02001444 { .ival = "crc32c",
1445 .oval = VERIFY_CRC32C,
1446 .help = "Use crc32c checksums for verification",
1447 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001448 { .ival = "crc16",
1449 .oval = VERIFY_CRC16,
1450 .help = "Use crc16 checksums for verification",
1451 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001452 { .ival = "crc7",
1453 .oval = VERIFY_CRC7,
1454 .help = "Use crc7 checksums for verification",
1455 },
Jens Axboe7c353ce2009-08-09 22:40:33 +02001456 { .ival = "sha1",
1457 .oval = VERIFY_SHA1,
1458 .help = "Use sha1 checksums for verification",
1459 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001460 { .ival = "sha256",
1461 .oval = VERIFY_SHA256,
1462 .help = "Use sha256 checksums for verification",
1463 },
1464 { .ival = "sha512",
1465 .oval = VERIFY_SHA512,
1466 .help = "Use sha512 checksums for verification",
1467 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001468 { .ival = "meta",
1469 .oval = VERIFY_META,
1470 .help = "Use io information",
1471 },
Jens Axboe36690c92007-03-26 10:23:34 +02001472 {
1473 .ival = "null",
1474 .oval = VERIFY_NULL,
1475 .help = "Pretend to verify",
1476 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001477 },
1478 },
1479 {
Jens Axboe005c5652007-08-02 22:21:36 +02001480 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001481 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001482 .off1 = td_var_offset(do_verify),
1483 .help = "Run verification stage after write",
1484 .def = "1",
1485 .parent = "verify",
1486 },
1487 {
Jens Axboe160b9662007-03-27 10:59:49 +02001488 .name = "verifysort",
1489 .type = FIO_OPT_BOOL,
1490 .off1 = td_var_offset(verifysort),
1491 .help = "Sort written verify blocks for read back",
1492 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001493 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001494 },
1495 {
Jens Axboea59e1702007-07-30 08:53:27 +02001496 .name = "verify_interval",
Jens Axboee01b22b2009-06-09 15:43:25 +02001497 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001498 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001499 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001500 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001501 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001502 },
1503 {
Jens Axboea59e1702007-07-30 08:53:27 +02001504 .name = "verify_offset",
Jens Axboee01b22b2009-06-09 15:43:25 +02001505 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001506 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001507 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001508 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001509 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001510 },
1511 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001512 .name = "verify_pattern",
Radha Ramachandran0e92f872009-10-27 20:14:27 +01001513 .type = FIO_OPT_STR,
Shawn Lewise28218f2008-01-16 11:01:33 +01001514 .cb = str_verify_pattern_cb,
1515 .help = "Fill pattern for IO buffers",
1516 .parent = "verify",
1517 },
1518 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001519 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001520 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001521 .off1 = td_var_offset(verify_fatal),
1522 .def = "0",
1523 .help = "Exit on a single verify failure, don't continue",
1524 .parent = "verify",
1525 },
1526 {
Jens Axboeb463e932011-01-12 09:03:23 +01001527 .name = "verify_dump",
1528 .type = FIO_OPT_BOOL,
1529 .off1 = td_var_offset(verify_dump),
1530 .def = "1",
1531 .help = "Dump contents of good and bad blocks on failure",
1532 .parent = "verify",
1533 },
1534 {
Jens Axboee8462bd2009-07-06 12:59:04 +02001535 .name = "verify_async",
1536 .type = FIO_OPT_INT,
1537 .off1 = td_var_offset(verify_async),
1538 .def = "0",
1539 .help = "Number of async verifier threads to use",
1540 .parent = "verify",
1541 },
Jens Axboe9e144182010-06-15 14:25:36 +02001542 {
1543 .name = "verify_backlog",
1544 .type = FIO_OPT_STR_VAL,
1545 .off1 = td_var_offset(verify_backlog),
1546 .help = "Verify after this number of blocks are written",
1547 .parent = "verify",
1548 },
1549 {
1550 .name = "verify_backlog_batch",
1551 .type = FIO_OPT_INT,
1552 .off1 = td_var_offset(verify_batch),
1553 .help = "Verify this number of IO blocks",
Jens Axboe0d29de82010-09-01 13:54:15 +02001554 .parent = "verify",
Jens Axboe9e144182010-06-15 14:25:36 +02001555 },
Jens Axboee8462bd2009-07-06 12:59:04 +02001556#ifdef FIO_HAVE_CPU_AFFINITY
1557 {
1558 .name = "verify_async_cpus",
1559 .type = FIO_OPT_STR,
1560 .cb = str_verify_cpus_allowed_cb,
1561 .help = "Set CPUs allowed for async verify threads",
1562 .parent = "verify_async",
1563 },
1564#endif
Jens Axboe0d29de82010-09-01 13:54:15 +02001565#ifdef FIO_HAVE_TRIM
1566 {
1567 .name = "trim_percentage",
1568 .type = FIO_OPT_INT,
1569 .cb = str_verify_trim_cb,
1570 .maxval = 100,
1571 .help = "Number of verify blocks to discard/trim",
1572 .parent = "verify",
1573 .def = "0",
1574 },
1575 {
1576 .name = "trim_verify_zero",
1577 .type = FIO_OPT_INT,
1578 .help = "Verify that trim/discarded blocks are returned as zeroes",
1579 .off1 = td_var_offset(trim_zero),
1580 .parent = "trim_percentage",
1581 .def = "1",
1582 },
1583 {
1584 .name = "trim_backlog",
1585 .type = FIO_OPT_STR_VAL,
1586 .off1 = td_var_offset(trim_backlog),
1587 .help = "Trim after this number of blocks are written",
1588 .parent = "trim_percentage",
1589 },
1590 {
1591 .name = "trim_backlog_batch",
1592 .type = FIO_OPT_INT,
1593 .off1 = td_var_offset(trim_batch),
1594 .help = "Trim this number of IO blocks",
1595 .parent = "trim_percentage",
1596 },
1597#endif
Jens Axboee8462bd2009-07-06 12:59:04 +02001598 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001599 .name = "write_iolog",
1600 .type = FIO_OPT_STR_STORE,
1601 .off1 = td_var_offset(write_iolog_file),
1602 .help = "Store IO pattern to file",
1603 },
1604 {
1605 .name = "read_iolog",
1606 .type = FIO_OPT_STR_STORE,
1607 .off1 = td_var_offset(read_iolog_file),
1608 .help = "Playback IO pattern from file",
1609 },
1610 {
David Nellans64bbb862010-08-24 22:13:30 +02001611 .name = "replay_no_stall",
1612 .type = FIO_OPT_INT,
1613 .off1 = td_var_offset(no_stall),
1614 .def = "0",
Jens Axboe87e7a972010-08-25 09:01:25 +02001615 .parent = "read_iolog",
David Nellans64bbb862010-08-24 22:13:30 +02001616 .help = "Playback IO pattern file as fast as possible without stalls",
1617 },
1618 {
David Nellansd1c46c02010-08-31 21:20:47 +02001619 .name = "replay_redirect",
1620 .type = FIO_OPT_STR_STORE,
1621 .off1 = td_var_offset(replay_redirect),
1622 .parent = "read_iolog",
1623 .help = "Replay all I/O onto this device, regardless of trace device",
1624 },
1625 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001626 .name = "exec_prerun",
1627 .type = FIO_OPT_STR_STORE,
1628 .off1 = td_var_offset(exec_prerun),
1629 .help = "Execute this file prior to running job",
1630 },
1631 {
1632 .name = "exec_postrun",
1633 .type = FIO_OPT_STR_STORE,
1634 .off1 = td_var_offset(exec_postrun),
1635 .help = "Execute this file after running job",
1636 },
1637#ifdef FIO_HAVE_IOSCHED_SWITCH
1638 {
1639 .name = "ioscheduler",
1640 .type = FIO_OPT_STR_STORE,
1641 .off1 = td_var_offset(ioscheduler),
1642 .help = "Use this IO scheduler on the backing device",
1643 },
1644#endif
1645 {
1646 .name = "zonesize",
1647 .type = FIO_OPT_STR_VAL,
1648 .off1 = td_var_offset(zone_size),
1649 .help = "Give size of an IO zone",
1650 .def = "0",
1651 },
1652 {
1653 .name = "zoneskip",
1654 .type = FIO_OPT_STR_VAL,
1655 .off1 = td_var_offset(zone_skip),
1656 .help = "Space between IO zones",
1657 .def = "0",
1658 },
1659 {
1660 .name = "lockmem",
1661 .type = FIO_OPT_STR_VAL,
1662 .cb = str_lockmem_cb,
1663 .help = "Lock down this amount of memory",
1664 .def = "0",
1665 },
1666 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001667 .name = "rwmixread",
1668 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001669 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001670 .maxval = 100,
1671 .help = "Percentage of mixed workload that is reads",
1672 .def = "50",
1673 },
1674 {
1675 .name = "rwmixwrite",
1676 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001677 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001678 .maxval = 100,
1679 .help = "Percentage of mixed workload that is writes",
1680 .def = "50",
1681 },
1682 {
Jens Axboeafdf9352007-07-31 16:14:34 +02001683 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02001684 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02001685 },
1686 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001687 .name = "nice",
1688 .type = FIO_OPT_INT,
1689 .off1 = td_var_offset(nice),
1690 .help = "Set job CPU nice value",
1691 .minval = -19,
1692 .maxval = 20,
1693 .def = "0",
1694 },
1695#ifdef FIO_HAVE_IOPRIO
1696 {
1697 .name = "prio",
1698 .type = FIO_OPT_INT,
1699 .cb = str_prio_cb,
1700 .help = "Set job IO priority value",
1701 .minval = 0,
1702 .maxval = 7,
1703 },
1704 {
1705 .name = "prioclass",
1706 .type = FIO_OPT_INT,
1707 .cb = str_prioclass_cb,
1708 .help = "Set job IO priority class",
1709 .minval = 0,
1710 .maxval = 3,
1711 },
1712#endif
1713 {
1714 .name = "thinktime",
1715 .type = FIO_OPT_INT,
1716 .off1 = td_var_offset(thinktime),
1717 .help = "Idle time between IO buffers (usec)",
1718 .def = "0",
1719 },
1720 {
1721 .name = "thinktime_spin",
1722 .type = FIO_OPT_INT,
1723 .off1 = td_var_offset(thinktime_spin),
1724 .help = "Start think time by spinning this amount (usec)",
1725 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02001726 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001727 },
1728 {
1729 .name = "thinktime_blocks",
1730 .type = FIO_OPT_INT,
1731 .off1 = td_var_offset(thinktime_blocks),
1732 .help = "IO buffer period between 'thinktime'",
1733 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02001734 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001735 },
1736 {
1737 .name = "rate",
Jens Axboee01b22b2009-06-09 15:43:25 +02001738 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001739 .off1 = td_var_offset(rate[0]),
1740 .off2 = td_var_offset(rate[1]),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001741 .help = "Set bandwidth rate",
1742 },
1743 {
1744 .name = "ratemin",
Jens Axboee01b22b2009-06-09 15:43:25 +02001745 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001746 .off1 = td_var_offset(ratemin[0]),
1747 .off2 = td_var_offset(ratemin[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001748 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001749 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01001750 },
1751 {
1752 .name = "rate_iops",
Jens Axboee01b22b2009-06-09 15:43:25 +02001753 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001754 .off1 = td_var_offset(rate_iops[0]),
1755 .off2 = td_var_offset(rate_iops[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001756 .help = "Limit IO used to this number of IO operations/sec",
1757 },
1758 {
1759 .name = "rate_iops_min",
Jens Axboee01b22b2009-06-09 15:43:25 +02001760 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001761 .off1 = td_var_offset(rate_iops_min[0]),
1762 .off2 = td_var_offset(rate_iops_min[1]),
Bruce Cran03e20d62011-01-02 20:14:54 +01001763 .help = "Job must meet this rate or it will be shut down",
Jens Axboeafdf9352007-07-31 16:14:34 +02001764 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001765 },
1766 {
1767 .name = "ratecycle",
1768 .type = FIO_OPT_INT,
1769 .off1 = td_var_offset(ratecycle),
1770 .help = "Window average for rate limits (msec)",
1771 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02001772 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001773 },
1774 {
1775 .name = "invalidate",
1776 .type = FIO_OPT_BOOL,
1777 .off1 = td_var_offset(invalidate_cache),
1778 .help = "Invalidate buffer/page cache prior to running job",
1779 .def = "1",
1780 },
1781 {
1782 .name = "sync",
1783 .type = FIO_OPT_BOOL,
1784 .off1 = td_var_offset(sync_io),
1785 .help = "Use O_SYNC for buffered writes",
1786 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02001787 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001788 },
1789 {
1790 .name = "bwavgtime",
1791 .type = FIO_OPT_INT,
1792 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001793 .help = "Time window over which to calculate bandwidth"
1794 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001795 .def = "500",
1796 },
1797 {
1798 .name = "create_serialize",
1799 .type = FIO_OPT_BOOL,
1800 .off1 = td_var_offset(create_serialize),
1801 .help = "Serialize creating of job files",
1802 .def = "1",
1803 },
1804 {
1805 .name = "create_fsync",
1806 .type = FIO_OPT_BOOL,
1807 .off1 = td_var_offset(create_fsync),
Bruce Cran03e20d62011-01-02 20:14:54 +01001808 .help = "fsync file after creation",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001809 .def = "1",
1810 },
1811 {
Jens Axboe814452b2009-03-04 12:53:13 +01001812 .name = "create_on_open",
1813 .type = FIO_OPT_BOOL,
1814 .off1 = td_var_offset(create_on_open),
1815 .help = "Create files when they are opened for IO",
1816 .def = "0",
1817 },
Jens Axboe0b9d69e2009-09-11 22:29:54 +02001818 {
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001819 .name = "pre_read",
1820 .type = FIO_OPT_BOOL,
1821 .off1 = td_var_offset(pre_read),
Bruce Cran03e20d62011-01-02 20:14:54 +01001822 .help = "Pre-read files before starting official testing",
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001823 .def = "0",
1824 },
Jens Axboe814452b2009-03-04 12:53:13 +01001825 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001826 .name = "cpuload",
1827 .type = FIO_OPT_INT,
1828 .off1 = td_var_offset(cpuload),
1829 .help = "Use this percentage of CPU",
1830 },
1831 {
1832 .name = "cpuchunks",
1833 .type = FIO_OPT_INT,
1834 .off1 = td_var_offset(cpucycle),
1835 .help = "Length of the CPU burn cycles (usecs)",
1836 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02001837 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001838 },
1839#ifdef FIO_HAVE_CPU_AFFINITY
1840 {
1841 .name = "cpumask",
1842 .type = FIO_OPT_INT,
1843 .cb = str_cpumask_cb,
1844 .help = "CPU affinity mask",
1845 },
Jens Axboed2e268b2007-06-15 10:33:49 +02001846 {
1847 .name = "cpus_allowed",
1848 .type = FIO_OPT_STR,
1849 .cb = str_cpus_allowed_cb,
1850 .help = "Set CPUs allowed",
1851 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001852#endif
1853 {
1854 .name = "end_fsync",
1855 .type = FIO_OPT_BOOL,
1856 .off1 = td_var_offset(end_fsync),
1857 .help = "Include fsync at the end of job",
1858 .def = "0",
1859 },
1860 {
1861 .name = "fsync_on_close",
1862 .type = FIO_OPT_BOOL,
1863 .off1 = td_var_offset(fsync_on_close),
1864 .help = "fsync files on close",
1865 .def = "0",
1866 },
1867 {
1868 .name = "unlink",
1869 .type = FIO_OPT_BOOL,
1870 .off1 = td_var_offset(unlink),
1871 .help = "Unlink created files after job has completed",
1872 .def = "0",
1873 },
1874 {
1875 .name = "exitall",
1876 .type = FIO_OPT_STR_SET,
1877 .cb = str_exitall_cb,
1878 .help = "Terminate all jobs when one exits",
1879 },
1880 {
1881 .name = "stonewall",
Jens Axboed3923652011-08-03 12:38:39 +02001882 .alias = "wait_for_previous",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001883 .type = FIO_OPT_STR_SET,
1884 .off1 = td_var_offset(stonewall),
1885 .help = "Insert a hard barrier between this job and previous",
1886 },
1887 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01001888 .name = "new_group",
1889 .type = FIO_OPT_STR_SET,
1890 .off1 = td_var_offset(new_group),
1891 .help = "Mark the start of a new group (for reporting)",
1892 },
1893 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001894 .name = "thread",
1895 .type = FIO_OPT_STR_SET,
1896 .off1 = td_var_offset(use_thread),
1897 .help = "Use threads instead of forks",
1898 },
1899 {
1900 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001901 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001902 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001903 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001904 .help = "Write log of bandwidth during run",
1905 },
1906 {
1907 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001908 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001909 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001910 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001911 .help = "Write log of latency during run",
1912 },
1913 {
1914 .name = "hugepage-size",
Jens Axboee01b22b2009-06-09 15:43:25 +02001915 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001916 .off1 = td_var_offset(hugepage_size),
1917 .help = "When using hugepages, specify size of each page",
1918 .def = __stringify(FIO_HUGE_PAGE),
1919 },
1920 {
1921 .name = "group_reporting",
1922 .type = FIO_OPT_STR_SET,
1923 .off1 = td_var_offset(group_reporting),
1924 .help = "Do reporting on a per-group basis",
1925 },
1926 {
Jens Axboee9459e52007-04-17 15:46:32 +02001927 .name = "zero_buffers",
1928 .type = FIO_OPT_STR_SET,
1929 .off1 = td_var_offset(zero_buffers),
1930 .help = "Init IO buffers to all zeroes",
1931 },
Jens Axboe5973caf2008-05-21 19:52:35 +02001932 {
1933 .name = "refill_buffers",
1934 .type = FIO_OPT_STR_SET,
1935 .off1 = td_var_offset(refill_buffers),
1936 .help = "Refill IO buffers on every IO submit",
1937 },
Jens Axboe0a839f32007-04-26 09:02:34 +02001938#ifdef FIO_HAVE_DISK_UTIL
1939 {
1940 .name = "disk_util",
1941 .type = FIO_OPT_BOOL,
1942 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001943 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02001944 .def = "1",
1945 },
1946#endif
Jens Axboee9459e52007-04-17 15:46:32 +02001947 {
Jens Axboe993bf482008-11-14 13:04:53 +01001948 .name = "gtod_reduce",
1949 .type = FIO_OPT_BOOL,
1950 .help = "Greatly reduce number of gettimeofday() calls",
1951 .cb = str_gtod_reduce_cb,
1952 .def = "0",
1953 },
1954 {
Jens Axboe02af0982010-06-24 09:59:34 +02001955 .name = "disable_lat",
1956 .type = FIO_OPT_BOOL,
1957 .off1 = td_var_offset(disable_lat),
1958 .help = "Disable latency numbers",
1959 .parent = "gtod_reduce",
1960 .def = "0",
1961 },
1962 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02001963 .name = "disable_clat",
1964 .type = FIO_OPT_BOOL,
1965 .off1 = td_var_offset(disable_clat),
1966 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001967 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001968 .def = "0",
1969 },
1970 {
1971 .name = "disable_slat",
1972 .type = FIO_OPT_BOOL,
1973 .off1 = td_var_offset(disable_slat),
Bruce Cran03e20d62011-01-02 20:14:54 +01001974 .help = "Disable submission latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001975 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001976 .def = "0",
1977 },
1978 {
1979 .name = "disable_bw_measurement",
1980 .type = FIO_OPT_BOOL,
1981 .off1 = td_var_offset(disable_bw),
1982 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01001983 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001984 .def = "0",
1985 },
1986 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001987 .name = "gtod_cpu",
1988 .type = FIO_OPT_INT,
1989 .cb = str_gtod_cpu_cb,
Bruce Cran03e20d62011-01-02 20:14:54 +01001990 .help = "Set up dedicated gettimeofday() thread on this CPU",
Jens Axboe29d43ff2009-07-01 10:42:18 +02001991 .verify = gtod_cpu_verify,
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001992 },
1993 {
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001994 .name = "continue_on_error",
1995 .type = FIO_OPT_BOOL,
1996 .off1 = td_var_offset(continue_on_error),
Bruce Cran03e20d62011-01-02 20:14:54 +01001997 .help = "Continue on non-fatal errors during IO",
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001998 .def = "0",
1999 },
2000 {
Jens Axboe9ac8a792009-11-13 21:23:07 +01002001 .name = "profile",
Jens Axboe79d16312010-03-04 12:43:20 +01002002 .type = FIO_OPT_STR_STORE,
Jens Axboe9ac8a792009-11-13 21:23:07 +01002003 .off1 = td_var_offset(profile),
Jens Axboe9ac8a792009-11-13 21:23:07 +01002004 .help = "Select a specific builtin performance test",
2005 },
2006 {
Jens Axboea696fa22009-12-04 10:05:02 +01002007 .name = "cgroup",
2008 .type = FIO_OPT_STR_STORE,
2009 .off1 = td_var_offset(cgroup),
2010 .help = "Add job to cgroup of this name",
2011 },
2012 {
2013 .name = "cgroup_weight",
2014 .type = FIO_OPT_INT,
2015 .off1 = td_var_offset(cgroup_weight),
2016 .help = "Use given weight for cgroup",
2017 .minval = 100,
2018 .maxval = 1000,
Jens Axboea696fa22009-12-04 10:05:02 +01002019 },
2020 {
Vivek Goyal7de87092010-03-31 22:55:15 +02002021 .name = "cgroup_nodelete",
2022 .type = FIO_OPT_BOOL,
2023 .off1 = td_var_offset(cgroup_nodelete),
2024 .help = "Do not delete cgroups after job completion",
2025 .def = "0",
2026 },
2027 {
Jens Axboee0b0d892009-12-08 10:10:14 +01002028 .name = "uid",
2029 .type = FIO_OPT_INT,
2030 .off1 = td_var_offset(uid),
2031 .help = "Run job with this user ID",
2032 },
2033 {
2034 .name = "gid",
2035 .type = FIO_OPT_INT,
2036 .off1 = td_var_offset(gid),
2037 .help = "Run job with this group ID",
2038 },
2039 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002040 .name = NULL,
2041 },
2042};
2043
Jens Axboe17af15d2010-04-13 10:38:16 +02002044static void add_to_lopt(struct option *lopt, struct fio_option *o,
2045 const char *name)
Jens Axboe9f817362010-03-04 14:38:10 +01002046{
Jens Axboe17af15d2010-04-13 10:38:16 +02002047 lopt->name = (char *) name;
Jens Axboe9f817362010-03-04 14:38:10 +01002048 lopt->val = FIO_GETOPT_JOB;
2049 if (o->type == FIO_OPT_STR_SET)
2050 lopt->has_arg = no_argument;
2051 else
2052 lopt->has_arg = required_argument;
2053}
2054
Jens Axboe214e1ec2007-03-15 10:48:13 +01002055void fio_options_dup_and_init(struct option *long_options)
2056{
2057 struct fio_option *o;
2058 unsigned int i;
2059
2060 options_init(options);
2061
2062 i = 0;
2063 while (long_options[i].name)
2064 i++;
2065
2066 o = &options[0];
2067 while (o->name) {
Jens Axboe17af15d2010-04-13 10:38:16 +02002068 add_to_lopt(&long_options[i], o, o->name);
2069 if (o->alias) {
2070 i++;
2071 add_to_lopt(&long_options[i], o, o->alias);
2072 }
Jens Axboe214e1ec2007-03-15 10:48:13 +01002073
2074 i++;
2075 o++;
2076 assert(i < FIO_NR_OPTIONS);
2077 }
2078}
2079
Jens Axboe74929ac2009-08-05 11:42:37 +02002080struct fio_keyword {
2081 const char *word;
2082 const char *desc;
2083 char *replace;
2084};
2085
2086static struct fio_keyword fio_keywords[] = {
2087 {
2088 .word = "$pagesize",
2089 .desc = "Page size in the system",
2090 },
2091 {
2092 .word = "$mb_memory",
2093 .desc = "Megabytes of memory online",
2094 },
2095 {
2096 .word = "$ncpus",
2097 .desc = "Number of CPUs online in the system",
2098 },
2099 {
2100 .word = NULL,
2101 },
2102};
2103
2104void fio_keywords_init(void)
2105{
Jens Axboe3b2e1462009-12-15 08:58:10 +01002106 unsigned long long mb_memory;
Jens Axboe74929ac2009-08-05 11:42:37 +02002107 char buf[128];
2108 long l;
2109
2110 sprintf(buf, "%lu", page_size);
2111 fio_keywords[0].replace = strdup(buf);
2112
Jens Axboe8eb016d2011-07-11 10:24:20 +02002113 mb_memory = os_phys_mem() / (1024 * 1024);
Jens Axboe3b2e1462009-12-15 08:58:10 +01002114 sprintf(buf, "%llu", mb_memory);
Jens Axboe74929ac2009-08-05 11:42:37 +02002115 fio_keywords[1].replace = strdup(buf);
2116
Jens Axboec00a2282011-07-08 20:56:06 +02002117 l = cpus_online();
Jens Axboe74929ac2009-08-05 11:42:37 +02002118 sprintf(buf, "%lu", l);
2119 fio_keywords[2].replace = strdup(buf);
2120}
2121
Jens Axboe892a6ff2009-11-13 12:19:49 +01002122#define BC_APP "bc"
2123
2124static char *bc_calc(char *str)
2125{
2126 char *buf, *tmp, opt[80];
2127 FILE *f;
2128 int ret;
2129
2130 /*
2131 * No math, just return string
2132 */
2133 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2134 !strchr(str, '/'))
2135 return str;
2136
2137 /*
2138 * Split option from value, we only need to calculate the value
2139 */
2140 tmp = strchr(str, '=');
2141 if (!tmp)
2142 return str;
2143
2144 tmp++;
Jens Axboe9ac8a792009-11-13 21:23:07 +01002145 memset(opt, 0, sizeof(opt));
Jens Axboe892a6ff2009-11-13 12:19:49 +01002146 strncpy(opt, str, tmp - str);
2147
2148 buf = malloc(128);
2149
2150 sprintf(buf, "which %s > /dev/null", BC_APP);
2151 if (system(buf)) {
2152 log_err("fio: bc is needed for performing math\n");
2153 free(buf);
2154 return NULL;
2155 }
2156
2157 sprintf(buf, "echo %s | %s", tmp, BC_APP);
2158 f = popen(buf, "r");
2159 if (!f) {
2160 free(buf);
2161 return NULL;
2162 }
2163
2164 ret = fread(buf, 1, 128, f);
2165 if (ret <= 0) {
2166 free(buf);
2167 return NULL;
2168 }
2169
2170 buf[ret - 1] = '\0';
2171 strcat(opt, buf);
2172 strcpy(buf, opt);
2173 pclose(f);
2174 free(str);
2175 return buf;
2176}
2177
Jens Axboe74929ac2009-08-05 11:42:37 +02002178/*
2179 * Look for reserved variable names and replace them with real values
2180 */
2181static char *fio_keyword_replace(char *opt)
2182{
2183 char *s;
2184 int i;
2185
2186 for (i = 0; fio_keywords[i].word != NULL; i++) {
2187 struct fio_keyword *kw = &fio_keywords[i];
2188
2189 while ((s = strstr(opt, kw->word)) != NULL) {
2190 char *new = malloc(strlen(opt) + 1);
2191 char *o_org = opt;
2192 int olen = s - opt;
2193 int len;
2194
2195 /*
2196 * Copy part of the string before the keyword and
2197 * sprintf() the replacement after it.
2198 */
2199 memcpy(new, opt, olen);
2200 len = sprintf(new + olen, "%s", kw->replace);
2201
2202 /*
2203 * If there's more in the original string, copy that
2204 * in too
2205 */
2206 opt += strlen(kw->word) + olen;
2207 if (strlen(opt))
2208 memcpy(new + olen + len, opt, opt - o_org - 1);
2209
2210 /*
2211 * replace opt and free the old opt
2212 */
2213 opt = new;
Jens Axboe9ac8a792009-11-13 21:23:07 +01002214 //free(o_org);
Jens Axboe7a958bd2009-11-13 12:33:54 +01002215
2216 /*
2217 * Check for potential math and invoke bc, if possible
2218 */
2219 opt = bc_calc(opt);
Jens Axboe74929ac2009-08-05 11:42:37 +02002220 }
2221 }
2222
Jens Axboe7a958bd2009-11-13 12:33:54 +01002223 return opt;
Jens Axboe74929ac2009-08-05 11:42:37 +02002224}
2225
Jens Axboe3b8b7132008-06-10 19:46:23 +02002226int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01002227{
Jens Axboe3b8b7132008-06-10 19:46:23 +02002228 int i, ret;
2229
2230 sort_options(opts, options, num_opts);
2231
Jens Axboe74929ac2009-08-05 11:42:37 +02002232 for (ret = 0, i = 0; i < num_opts; i++) {
2233 opts[i] = fio_keyword_replace(opts[i]);
Jens Axboe07b32322010-03-05 09:48:44 +01002234 ret |= parse_option(opts[i], options, td);
Jens Axboe74929ac2009-08-05 11:42:37 +02002235 }
Jens Axboe3b8b7132008-06-10 19:46:23 +02002236
2237 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01002238}
2239
2240int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2241{
Jens Axboe07b32322010-03-05 09:48:44 +01002242 return parse_cmd_option(opt, val, options, td);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002243}
2244
2245void fio_fill_default_options(struct thread_data *td)
2246{
2247 fill_default_options(td, options);
2248}
2249
2250int fio_show_option_help(const char *opt)
2251{
Jens Axboe07b32322010-03-05 09:48:44 +01002252 return show_cmd_help(options, opt);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002253}
Jens Axboed23bb322007-03-23 15:57:56 +01002254
2255static void __options_mem(struct thread_data *td, int alloc)
2256{
2257 struct thread_options *o = &td->o;
2258 struct fio_option *opt;
2259 char **ptr;
2260 int i;
2261
2262 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2263 if (opt->type != FIO_OPT_STR_STORE)
2264 continue;
2265
2266 ptr = (void *) o + opt->off1;
2267 if (*ptr) {
2268 if (alloc)
2269 *ptr = strdup(*ptr);
2270 else {
2271 free(*ptr);
2272 *ptr = NULL;
2273 }
2274 }
2275 }
2276}
2277
2278/*
2279 * dupe FIO_OPT_STR_STORE options
2280 */
2281void options_mem_dupe(struct thread_data *td)
2282{
2283 __options_mem(td, 1);
2284}
2285
Jens Axboe22d66212007-03-27 20:06:25 +02002286void options_mem_free(struct thread_data fio_unused *td)
Jens Axboed23bb322007-03-23 15:57:56 +01002287{
Jens Axboe22d66212007-03-27 20:06:25 +02002288#if 0
Jens Axboed23bb322007-03-23 15:57:56 +01002289 __options_mem(td, 0);
Jens Axboe22d66212007-03-27 20:06:25 +02002290#endif
Jens Axboed23bb322007-03-23 15:57:56 +01002291}
Jens Axboed6978a32009-07-18 21:04:09 +02002292
2293unsigned int fio_get_kb_base(void *data)
2294{
2295 struct thread_data *td = data;
2296 unsigned int kb_base = 0;
2297
2298 if (td)
2299 kb_base = td->o.kb_base;
2300 if (!kb_base)
2301 kb_base = 1024;
2302
2303 return kb_base;
2304}
Jens Axboe9f988e22010-03-04 10:42:38 +01002305
Jens Axboe07b32322010-03-05 09:48:44 +01002306int add_option(struct fio_option *o)
Jens Axboe9f988e22010-03-04 10:42:38 +01002307{
Jens Axboe07b32322010-03-05 09:48:44 +01002308 struct fio_option *__o;
2309 int opt_index = 0;
2310
2311 __o = options;
2312 while (__o->name) {
2313 opt_index++;
2314 __o++;
2315 }
2316
2317 memcpy(&options[opt_index], o, sizeof(*o));
2318 return 0;
Jens Axboe9f988e22010-03-04 10:42:38 +01002319}
Jens Axboee2de69d2010-03-04 14:05:48 +01002320
Jens Axboe07b32322010-03-05 09:48:44 +01002321void invalidate_profile_options(const char *prof_name)
Jens Axboee2de69d2010-03-04 14:05:48 +01002322{
Jens Axboe07b32322010-03-05 09:48:44 +01002323 struct fio_option *o;
Jens Axboee2de69d2010-03-04 14:05:48 +01002324
Jens Axboe07b32322010-03-05 09:48:44 +01002325 o = options;
2326 while (o->name) {
2327 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2328 o->type = FIO_OPT_INVALID;
2329 o->prof_name = NULL;
2330 }
2331 o++;
Jens Axboee2de69d2010-03-04 14:05:48 +01002332 }
2333}
Jens Axboef5b6bb82010-03-05 10:09:59 +01002334
2335void add_opt_posval(const char *optname, const char *ival, const char *help)
2336{
2337 struct fio_option *o;
2338 unsigned int i;
2339
2340 o = find_option(options, optname);
2341 if (!o)
2342 return;
2343
2344 for (i = 0; i < PARSE_MAX_VP; i++) {
2345 if (o->posval[i].ival)
2346 continue;
2347
2348 o->posval[i].ival = ival;
2349 o->posval[i].help = help;
2350 break;
2351 }
2352}
2353
2354void del_opt_posval(const char *optname, const char *ival)
2355{
2356 struct fio_option *o;
2357 unsigned int i;
2358
2359 o = find_option(options, optname);
2360 if (!o)
2361 return;
2362
2363 for (i = 0; i < PARSE_MAX_VP; i++) {
2364 if (!o->posval[i].ival)
2365 continue;
2366 if (strcmp(o->posval[i].ival, ival))
2367 continue;
2368
2369 o->posval[i].ival = NULL;
2370 o->posval[i].help = NULL;
2371 }
2372}