blob: 3a5fbcc4bff557da86edc54f08a8a2abd8b20f07 [file] [log] [blame]
Jens Axboecb2c86f2006-10-26 13:48:34 +02001/*
2 * This file contains the ini and command liner parser main.
3 */
4#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7#include <ctype.h>
8#include <string.h>
9#include <errno.h>
10#include <limits.h>
Aaron Carroll88b5a392008-10-07 11:25:20 +020011#include <stdlib.h>
Yu-ju Hong83349192011-08-13 00:53:44 +020012#include <math.h>
Bruce Cranab9461e2013-02-02 14:31:24 +000013#include <float.h>
Jens Axboecb2c86f2006-10-26 13:48:34 +020014
15#include "parse.h"
Jens Axboea3d741f2008-02-27 18:32:33 +010016#include "debug.h"
Jens Axboe9f988e22010-03-04 10:42:38 +010017#include "options.h"
Jens Axboee25839d2012-11-06 10:49:42 +010018#include "minmax.h"
Vincent Kang Fufd112d32013-02-02 09:28:55 +010019#include "lib/ieee754.h"
Jens Axboecb2c86f2006-10-26 13:48:34 +020020
Stephen M. Cameron88b635b2014-09-29 12:10:49 -060021#ifdef CONFIG_ARITHMETIC
22#include "y.tab.h"
23#endif
24
Jens Axboe9af4a242012-03-16 10:13:49 +010025static struct fio_option *__fio_options;
Jens Axboe3b8b7132008-06-10 19:46:23 +020026
Jens Axboef0857372007-03-19 13:15:23 +010027static int vp_cmp(const void *p1, const void *p2)
28{
29 const struct value_pair *vp1 = p1;
30 const struct value_pair *vp2 = p2;
31
32 return strlen(vp2->ival) - strlen(vp1->ival);
33}
34
Jens Axboece952ab2011-08-31 14:29:22 -060035static void posval_sort(struct fio_option *o, struct value_pair *vpmap)
Jens Axboef0857372007-03-19 13:15:23 +010036{
37 const struct value_pair *vp;
38 int entries;
39
40 memset(vpmap, 0, PARSE_MAX_VP * sizeof(struct value_pair));
41
42 for (entries = 0; entries < PARSE_MAX_VP; entries++) {
43 vp = &o->posval[entries];
44 if (!vp->ival || vp->ival[0] == '\0')
45 break;
46
47 memcpy(&vpmap[entries], vp, sizeof(*vp));
48 }
49
50 qsort(vpmap, entries, sizeof(struct value_pair), vp_cmp);
51}
52
Jens Axboe06b0be62011-10-04 10:31:10 +020053static void show_option_range(struct fio_option *o,
54 int (*logger)(const char *format, ...))
Jens Axboeb1ec1da2007-02-23 10:29:16 +010055{
Jens Axboe3c037bc2013-04-10 11:21:33 +020056 if (o->type == FIO_OPT_FLOAT_LIST) {
Bruce Cranab9461e2013-02-02 14:31:24 +000057 if (o->minfp == DBL_MIN && o->maxfp == DBL_MAX)
Yu-ju Hong83349192011-08-13 00:53:44 +020058 return;
Jens Axboeb1ec1da2007-02-23 10:29:16 +010059
Jens Axboe06b0be62011-10-04 10:31:10 +020060 logger("%20s: min=%f", "range", o->minfp);
Bruce Cranab9461e2013-02-02 14:31:24 +000061 if (o->maxfp != DBL_MAX)
Jens Axboe06b0be62011-10-04 10:31:10 +020062 logger(", max=%f", o->maxfp);
63 logger("\n");
Jens Axboe3c037bc2013-04-10 11:21:33 +020064 } else if (!o->posval[0].ival) {
Yu-ju Hong83349192011-08-13 00:53:44 +020065 if (!o->minval && !o->maxval)
66 return;
67
Jens Axboe06b0be62011-10-04 10:31:10 +020068 logger("%20s: min=%d", "range", o->minval);
Yu-ju Hong83349192011-08-13 00:53:44 +020069 if (o->maxval)
Jens Axboe06b0be62011-10-04 10:31:10 +020070 logger(", max=%d", o->maxval);
71 logger("\n");
Yu-ju Hong83349192011-08-13 00:53:44 +020072 }
Jens Axboeb1ec1da2007-02-23 10:29:16 +010073}
74
75static void show_option_values(struct fio_option *o)
76{
Jens Axboea3073f42010-03-05 10:06:15 +010077 int i;
Jens Axboeb1ec1da2007-02-23 10:29:16 +010078
Jens Axboea3073f42010-03-05 10:06:15 +010079 for (i = 0; i < PARSE_MAX_VP; i++) {
Jens Axboe78372132007-03-14 13:24:07 +010080 const struct value_pair *vp = &o->posval[i];
81
82 if (!vp->ival)
Jens Axboea3073f42010-03-05 10:06:15 +010083 continue;
Jens Axboeb1ec1da2007-02-23 10:29:16 +010084
Jens Axboe06b0be62011-10-04 10:31:10 +020085 log_info("%20s: %-10s", i == 0 ? "valid values" : "", vp->ival);
Jens Axboe78372132007-03-14 13:24:07 +010086 if (vp->help)
Jens Axboe06b0be62011-10-04 10:31:10 +020087 log_info(" %s", vp->help);
88 log_info("\n");
Jens Axboea3073f42010-03-05 10:06:15 +010089 }
Jens Axboeb1ec1da2007-02-23 10:29:16 +010090
91 if (i)
Jens Axboe06b0be62011-10-04 10:31:10 +020092 log_info("\n");
Jens Axboeb1ec1da2007-02-23 10:29:16 +010093}
94
Jens Axboe06b0be62011-10-04 10:31:10 +020095static void show_option_help(struct fio_option *o, int is_err)
Jens Axboed447a8c2009-07-17 22:26:15 +020096{
97 const char *typehelp[] = {
Jens Axboe07b32322010-03-05 09:48:44 +010098 "invalid",
Jens Axboed447a8c2009-07-17 22:26:15 +020099 "string (opt=bla)",
Jens Axboeae3fb6f2010-09-14 13:10:35 +0200100 "string (opt=bla)",
Jens Axboed447a8c2009-07-17 22:26:15 +0200101 "string with possible k/m/g postfix (opt=4k)",
102 "string with time postfix (opt=10s)",
103 "string (opt=bla)",
104 "string with dual range (opt=1k-4k,4k-8k)",
105 "integer value (opt=100)",
106 "boolean value (opt=1)",
Yu-ju Hong83349192011-08-13 00:53:44 +0200107 "list of floating point values separated by ':' (opt=5.9:7.8)",
Jens Axboed447a8c2009-07-17 22:26:15 +0200108 "no argument (opt)",
Jens Axboe07b32322010-03-05 09:48:44 +0100109 "deprecated",
Jens Axboed447a8c2009-07-17 22:26:15 +0200110 };
Jens Axboe06b0be62011-10-04 10:31:10 +0200111 int (*logger)(const char *format, ...);
112
113 if (is_err)
114 logger = log_err;
115 else
116 logger = log_info;
Jens Axboed447a8c2009-07-17 22:26:15 +0200117
118 if (o->alias)
Jens Axboe06b0be62011-10-04 10:31:10 +0200119 logger("%20s: %s\n", "alias", o->alias);
Jens Axboed447a8c2009-07-17 22:26:15 +0200120
Jens Axboe06b0be62011-10-04 10:31:10 +0200121 logger("%20s: %s\n", "type", typehelp[o->type]);
122 logger("%20s: %s\n", "default", o->def ? o->def : "no default");
Jens Axboe07b32322010-03-05 09:48:44 +0100123 if (o->prof_name)
Jens Axboe06b0be62011-10-04 10:31:10 +0200124 logger("%20s: only for profile '%s'\n", "valid", o->prof_name);
125 show_option_range(o, logger);
Jens Axboed447a8c2009-07-17 22:26:15 +0200126 show_option_values(o);
127}
128
Jens Axboe0de5b262014-02-21 15:26:01 -0800129static unsigned long long get_mult_time(const char *str, int len,
130 int is_seconds)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200131{
Christian Ehrhardt74454ce2014-02-20 14:20:01 +0100132 const char *p = str;
133 char *c;
Jens Axboee4668262014-02-21 11:50:09 -0800134 unsigned long long mult = 1;
Christian Ehrhardt74454ce2014-02-20 14:20:01 +0100135
136 /*
137 * Go forward until we hit a non-digit, or +/- sign
138 */
139 while ((p - str) <= len) {
140 if (!isdigit((int) *p) && (*p != '+') && (*p != '-'))
141 break;
142 p++;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200143 }
Christian Ehrhardt74454ce2014-02-20 14:20:01 +0100144
Jens Axboe0de5b262014-02-21 15:26:01 -0800145 if (!isalpha((int) *p)) {
146 if (is_seconds)
147 return 1000000UL;
148 else
149 return 1;
150 }
Christian Ehrhardt74454ce2014-02-20 14:20:01 +0100151
152 c = strdup(p);
153 for (int i = 0; i < strlen(c); i++)
154 c[i] = tolower(c[i]);
155
Jens Axboee4668262014-02-21 11:50:09 -0800156 if (!strncmp("us", c, 2) || !strncmp("usec", c, 4))
Christian Ehrhardt74454ce2014-02-20 14:20:01 +0100157 mult = 1;
Jens Axboee4668262014-02-21 11:50:09 -0800158 else if (!strncmp("ms", c, 2) || !strncmp("msec", c, 4))
Christian Ehrhardt74454ce2014-02-20 14:20:01 +0100159 mult = 1000;
Jens Axboee4668262014-02-21 11:50:09 -0800160 else if (!strcmp("s", c))
161 mult = 1000000;
Christian Ehrhardt74454ce2014-02-20 14:20:01 +0100162 else if (!strcmp("m", c))
Jens Axboee4668262014-02-21 11:50:09 -0800163 mult = 60 * 1000000UL;
Christian Ehrhardt74454ce2014-02-20 14:20:01 +0100164 else if (!strcmp("h", c))
Jens Axboee4668262014-02-21 11:50:09 -0800165 mult = 60 * 60 * 1000000UL;
Christian Ehrhardt74454ce2014-02-20 14:20:01 +0100166 else if (!strcmp("d", c))
Jens Axboee4668262014-02-21 11:50:09 -0800167 mult = 24 * 60 * 60 * 1000000UL;
Christian Ehrhardt74454ce2014-02-20 14:20:01 +0100168
169 free(c);
170 return mult;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200171}
172
Jens Axboea03fb652013-03-29 12:20:51 -0600173static int is_separator(char c)
174{
175 switch (c) {
176 case ':':
177 case '-':
178 case ',':
179 case '/':
180 return 1;
181 default:
182 return 0;
183 }
184}
185
Jens Axboe7bb59102011-07-12 19:47:03 +0200186static unsigned long long __get_mult_bytes(const char *p, void *data,
187 int *percent)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200188{
Jens Axboed6978a32009-07-18 21:04:09 +0200189 unsigned int kb_base = fio_get_kb_base(data);
Jens Axboea639f0b2009-07-18 08:25:35 +0200190 unsigned long long ret = 1;
Jens Axboe57fc29f2010-06-23 22:24:07 +0200191 unsigned int i, pow = 0, mult = kb_base;
192 char *c;
Jens Axboea639f0b2009-07-18 08:25:35 +0200193
Jens Axboe57fc29f2010-06-23 22:24:07 +0200194 if (!p)
195 return 1;
Jens Axboea639f0b2009-07-18 08:25:35 +0200196
Jens Axboe57fc29f2010-06-23 22:24:07 +0200197 c = strdup(p);
198
Jens Axboea03fb652013-03-29 12:20:51 -0600199 for (i = 0; i < strlen(c); i++) {
Jens Axboe57fc29f2010-06-23 22:24:07 +0200200 c[i] = tolower(c[i]);
Jens Axboea03fb652013-03-29 12:20:51 -0600201 if (is_separator(c[i])) {
202 c[i] = '\0';
203 break;
204 }
205 }
Jens Axboe57fc29f2010-06-23 22:24:07 +0200206
Jens Axboea04f1582012-03-07 10:53:29 +0100207 if (!strncmp("pib", c, 3)) {
Jens Axboe57fc29f2010-06-23 22:24:07 +0200208 pow = 5;
209 mult = 1000;
Jens Axboea04f1582012-03-07 10:53:29 +0100210 } else if (!strncmp("tib", c, 3)) {
Jens Axboe57fc29f2010-06-23 22:24:07 +0200211 pow = 4;
212 mult = 1000;
Jens Axboea04f1582012-03-07 10:53:29 +0100213 } else if (!strncmp("gib", c, 3)) {
Jens Axboe57fc29f2010-06-23 22:24:07 +0200214 pow = 3;
215 mult = 1000;
Jens Axboea04f1582012-03-07 10:53:29 +0100216 } else if (!strncmp("mib", c, 3)) {
Jens Axboe57fc29f2010-06-23 22:24:07 +0200217 pow = 2;
218 mult = 1000;
Jens Axboea04f1582012-03-07 10:53:29 +0100219 } else if (!strncmp("kib", c, 3)) {
Jens Axboe57fc29f2010-06-23 22:24:07 +0200220 pow = 1;
221 mult = 1000;
Jens Axboea04f1582012-03-07 10:53:29 +0100222 } else if (!strncmp("p", c, 1) || !strncmp("pb", c, 2))
Jens Axboe57fc29f2010-06-23 22:24:07 +0200223 pow = 5;
Jens Axboea04f1582012-03-07 10:53:29 +0100224 else if (!strncmp("t", c, 1) || !strncmp("tb", c, 2))
Jens Axboe57fc29f2010-06-23 22:24:07 +0200225 pow = 4;
Jens Axboea04f1582012-03-07 10:53:29 +0100226 else if (!strncmp("g", c, 1) || !strncmp("gb", c, 2))
Jens Axboe57fc29f2010-06-23 22:24:07 +0200227 pow = 3;
Jens Axboea04f1582012-03-07 10:53:29 +0100228 else if (!strncmp("m", c, 1) || !strncmp("mb", c, 2))
Jens Axboe57fc29f2010-06-23 22:24:07 +0200229 pow = 2;
Jens Axboea04f1582012-03-07 10:53:29 +0100230 else if (!strncmp("k", c, 1) || !strncmp("kb", c, 2))
Jens Axboe57fc29f2010-06-23 22:24:07 +0200231 pow = 1;
Jens Axboea04f1582012-03-07 10:53:29 +0100232 else if (!strncmp("%", c, 1)) {
Jens Axboe7bb59102011-07-12 19:47:03 +0200233 *percent = 1;
Jens Axboee721c572012-02-09 20:55:29 +0100234 free(c);
Jens Axboe7bb59102011-07-12 19:47:03 +0200235 return ret;
236 }
Jens Axboe57fc29f2010-06-23 22:24:07 +0200237
238 while (pow--)
239 ret *= (unsigned long long) mult;
240
241 free(c);
Jens Axboea639f0b2009-07-18 08:25:35 +0200242 return ret;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200243}
244
Jens Axboe7bb59102011-07-12 19:47:03 +0200245static unsigned long long get_mult_bytes(const char *str, int len, void *data,
Jens Axboe6925dd32011-09-07 22:10:11 +0200246 int *percent)
Jens Axboe57fc29f2010-06-23 22:24:07 +0200247{
Jens Axboe55ed9632011-03-27 20:55:09 +0200248 const char *p = str;
Jens Axboeba4ddd62011-09-07 22:11:00 +0200249 int digit_seen = 0;
Jens Axboe57fc29f2010-06-23 22:24:07 +0200250
Jens Axboe1d1c1872010-07-29 10:50:05 +0200251 if (len < 2)
Jens Axboe7bb59102011-07-12 19:47:03 +0200252 return __get_mult_bytes(str, data, percent);
Jens Axboe1d1c1872010-07-29 10:50:05 +0200253
Steven Langd0c814e2011-10-28 08:37:13 +0200254 /*
255 * Go forward until we hit a non-digit, or +/- sign
256 */
Jens Axboe55ed9632011-03-27 20:55:09 +0200257 while ((p - str) <= len) {
Jens Axboeba4ddd62011-09-07 22:11:00 +0200258 if (!isdigit((int) *p) &&
259 (((*p != '+') && (*p != '-')) || digit_seen))
Jens Axboe55ed9632011-03-27 20:55:09 +0200260 break;
Jens Axboe3c703d12011-09-21 09:27:24 +0200261 digit_seen |= isdigit((int) *p);
Jens Axboe55ed9632011-03-27 20:55:09 +0200262 p++;
263 }
264
Jens Axboe7bb59102011-07-12 19:47:03 +0200265 if (!isalpha((int) *p) && (*p != '%'))
Jens Axboe57fc29f2010-06-23 22:24:07 +0200266 p = NULL;
267
Jens Axboe7bb59102011-07-12 19:47:03 +0200268 return __get_mult_bytes(p, data, percent);
Jens Axboe57fc29f2010-06-23 22:24:07 +0200269}
270
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600271extern int evaluate_arithmetic_expression(const char *buffer, long long *ival,
272 double *dval);
273
Stephen M. Cameron21bda792014-09-30 08:29:33 -0500274#ifdef CONFIG_ARITHMETIC
275/*
276 * These two verification functions are just to gain confidence that
277 * the arithmetic processing code is always getting the same answer as the
278 * original number parsing code. Once sufficiently sure that the arithmetic
279 * code is always getting the right answers, these can be removed.
280 */
281static void verify_exp_parser_float(const char *str)
282{
283 long long ival;
284 double dval, tmpval;
285
286 if (sscanf(str, "%lf", &tmpval) != 1)
287 return;
288
289 if (evaluate_arithmetic_expression(str, &ival, &dval) != 0) {
290 log_info("Arithmetic failed on '%s'\n", str);
291 return;
292 }
293 if (dval != tmpval) {
294 log_info("Arithmetic failed on: '%s' got %lf, expected %lf\n",
295 str, dval, tmpval);
296 }
297}
298
299static void verify_exp_parser_decimal(const char *str, long long val, int kilo, int is_seconds)
300{
301 int rc;
302 long long ival;
303 double dval;
304
305 rc = evaluate_arithmetic_expression(str, &ival, &dval);
306 if (!rc) {
307 if (ival != val)
308 log_info("Arithmetic failed on '%s', expected %lld, got %lld\n",
309 str, val, ival);
310 } else {
311 log_info("Arithmetic failed on '%s'\n", str);
312 }
313}
314#endif
315
Jens Axboecb2c86f2006-10-26 13:48:34 +0200316/*
Yu-ju Hong83349192011-08-13 00:53:44 +0200317 * Convert string into a floating number. Return 1 for success and 0 otherwise.
318 */
Jens Axboee25839d2012-11-06 10:49:42 +0100319int str_to_float(const char *str, double *val)
Yu-ju Hong83349192011-08-13 00:53:44 +0200320{
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600321#ifdef CONFIG_ARITHMETIC
322 int rc;
323 long long ival;
324 double dval;
325
326 if (str[0] == '(') {
327 rc = evaluate_arithmetic_expression(str, &ival, &dval);
328 if (!rc) {
329 *val = dval;
330 return 1;
331 }
Stephen M. Cameron21bda792014-09-30 08:29:33 -0500332 } else {
333 verify_exp_parser_float(str);
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600334 }
335#endif
336 return 1 == sscanf(str, "%lf", val);
Yu-ju Hong83349192011-08-13 00:53:44 +0200337}
338
339/*
Jens Axboee1f36502006-10-27 10:54:08 +0200340 * convert string into decimal value, noting any size suffix
Jens Axboecb2c86f2006-10-26 13:48:34 +0200341 */
Jens Axboe0de5b262014-02-21 15:26:01 -0800342int str_to_decimal(const char *str, long long *val, int kilo, void *data,
343 int is_seconds)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200344{
Jens Axboeb347f9d2009-03-09 14:15:21 +0100345 int len, base;
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600346 int rc = 1;
347#ifdef CONFIG_ARITHMETIC
348 long long ival;
349 double dval;
350#endif
Jens Axboecb2c86f2006-10-26 13:48:34 +0200351
Jens Axboecb2c86f2006-10-26 13:48:34 +0200352 len = strlen(str);
Jens Axboef90eff52006-11-06 11:08:21 +0100353 if (!len)
354 return 1;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200355
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600356#ifdef CONFIG_ARITHMETIC
357 if (str[0] == '(')
358 rc = evaluate_arithmetic_expression(str, &ival, &dval);
Stephen M. Cameronc3805eb2014-09-29 12:15:35 -0600359 if (str[0] == '(' && !rc) {
360 if (!kilo && is_seconds)
361 *val = ival / 1000000LL;
362 else
363 *val = ival;
364 }
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600365#endif
Jens Axboeb347f9d2009-03-09 14:15:21 +0100366
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600367 if (rc == 1) {
368 if (strstr(str, "0x") || strstr(str, "0X"))
369 base = 16;
370 else
371 base = 10;
372
373 *val = strtoll(str, NULL, base);
374 if (*val == LONG_MAX && errno == ERANGE)
375 return 1;
376 }
Jens Axboecb2c86f2006-10-26 13:48:34 +0200377
Jens Axboe7bb59102011-07-12 19:47:03 +0200378 if (kilo) {
379 unsigned long long mult;
380 int perc = 0;
381
Jens Axboe6925dd32011-09-07 22:10:11 +0200382 mult = get_mult_bytes(str, len, data, &perc);
Jens Axboe7bb59102011-07-12 19:47:03 +0200383 if (perc)
384 *val = -1ULL - *val;
385 else
386 *val *= mult;
387 } else
Jens Axboe0de5b262014-02-21 15:26:01 -0800388 *val *= get_mult_time(str, len, is_seconds);
Stephen M. Cameron21bda792014-09-30 08:29:33 -0500389#ifdef CONFIG_ARITHMETIC
390 verify_exp_parser_decimal(str, *val, kilo, is_seconds);
391#endif
Jens Axboecb2c86f2006-10-26 13:48:34 +0200392 return 0;
393}
394
Jens Axboe9af4a242012-03-16 10:13:49 +0100395int check_str_bytes(const char *p, long long *val, void *data)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200396{
Jens Axboe0de5b262014-02-21 15:26:01 -0800397 return str_to_decimal(p, val, 1, data, 0);
Jens Axboecb2c86f2006-10-26 13:48:34 +0200398}
399
Jens Axboe0de5b262014-02-21 15:26:01 -0800400int check_str_time(const char *p, long long *val, int is_seconds)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200401{
Jens Axboe0de5b262014-02-21 15:26:01 -0800402 return str_to_decimal(p, val, 0, NULL, is_seconds);
Jens Axboecb2c86f2006-10-26 13:48:34 +0200403}
404
405void strip_blank_front(char **p)
406{
407 char *s = *p;
408
Jens Axboe4c8e9642011-10-15 14:37:38 +0200409 if (!strlen(s))
410 return;
Jens Axboe76cd9372011-07-08 21:14:57 +0200411 while (isspace((int) *s))
Jens Axboecb2c86f2006-10-26 13:48:34 +0200412 s++;
Jens Axboe4d651da2007-03-28 19:34:53 +0200413
414 *p = s;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200415}
416
417void strip_blank_end(char *p)
418{
Jens Axboe853ee7f2009-03-06 20:29:29 +0100419 char *start = p, *s;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200420
Jens Axboe4c8e9642011-10-15 14:37:38 +0200421 if (!strlen(p))
422 return;
423
Jens Axboe523bfad2007-04-04 11:04:06 +0200424 s = strchr(p, ';');
425 if (s)
426 *s = '\0';
427 s = strchr(p, '#');
428 if (s)
429 *s = '\0';
430 if (s)
431 p = s;
432
Jens Axboe7f7e6e52007-07-19 14:50:05 +0200433 s = p + strlen(p);
Jens Axboe76cd9372011-07-08 21:14:57 +0200434 while ((isspace((int) *s) || iscntrl((int) *s)) && (s > start))
Jens Axboecb2c86f2006-10-26 13:48:34 +0200435 s--;
436
437 *(s + 1) = '\0';
438}
439
Jens Axboed6978a32009-07-18 21:04:09 +0200440static int check_range_bytes(const char *str, long *val, void *data)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200441{
Jens Axboe57fc29f2010-06-23 22:24:07 +0200442 long long __val;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200443
Jens Axboe0de5b262014-02-21 15:26:01 -0800444 if (!str_to_decimal(str, &__val, 1, data, 0)) {
Jens Axboe57fc29f2010-06-23 22:24:07 +0200445 *val = __val;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200446 return 0;
447 }
448
Jens Axboecb2c86f2006-10-26 13:48:34 +0200449 return 1;
450}
451
Jens Axboe63f29372007-01-10 13:20:09 +0100452static int check_int(const char *p, int *val)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200453{
Jens Axboe787f7e92006-11-06 13:26:29 +0100454 if (!strlen(p))
455 return 1;
Jens Axboed78ee462007-08-10 14:03:20 +0200456 if (strstr(p, "0x") || strstr(p, "0X")) {
Jens Axboea61bdfd2007-07-30 09:07:04 +0200457 if (sscanf(p, "%x", val) == 1)
458 return 0;
459 } else {
460 if (sscanf(p, "%u", val) == 1)
461 return 0;
462 }
Jens Axboecb2c86f2006-10-26 13:48:34 +0200463
464 return 1;
465}
466
Jens Axboe8adb4522014-09-23 10:38:54 -0600467static size_t opt_len(const char *str)
Jens Axboe808def72010-07-14 16:27:02 -0600468{
469 char *postfix;
470
471 postfix = strchr(str, ':');
472 if (!postfix)
473 return strlen(str);
474
475 return (int)(postfix - str);
476}
477
Jens Axboe119cd932012-12-06 17:34:57 +0100478static int str_match_len(const struct value_pair *vp, const char *str)
479{
480 return max(strlen(vp->ival), opt_len(str));
481}
482
Jens Axboef0fdbca2014-02-11 15:44:50 -0700483#define val_store(ptr, val, off, or, data, o) \
484 do { \
485 ptr = td_var((data), (o), (off)); \
486 if ((or)) \
487 *ptr |= (val); \
488 else \
489 *ptr = (val); \
Jens Axboe17abbe82006-11-06 11:23:10 +0100490 } while (0)
491
Jens Axboef90eff52006-11-06 11:08:21 +0100492static int __handle_option(struct fio_option *o, const char *ptr, void *data,
Yu-ju Hong83349192011-08-13 00:53:44 +0200493 int first, int more, int curr)
Jens Axboee1f36502006-10-27 10:54:08 +0200494{
Erwan Velu2fdbefd2013-07-22 23:48:48 +0200495 int il=0, *ilp;
Vincent Kang Fufd112d32013-02-02 09:28:55 +0100496 fio_fp64_t *flp;
Jens Axboe63f29372007-01-10 13:20:09 +0100497 long long ull, *ullp;
498 long ul1, ul2;
Yu-ju Hong83349192011-08-13 00:53:44 +0200499 double uf;
Jens Axboebfe1d592012-11-29 21:33:03 +0100500 char **cp = NULL;
Jens Axboee42b01e2011-05-05 12:05:10 -0600501 int ret = 0, is_time = 0;
Jens Axboec44b1ff2011-08-30 20:43:53 -0600502 const struct value_pair *vp;
503 struct value_pair posval[PARSE_MAX_VP];
504 int i, all_skipped = 1;
Jens Axboee1f36502006-10-27 10:54:08 +0200505
Jens Axboea3d741f2008-02-27 18:32:33 +0100506 dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name,
507 o->type, ptr);
508
Jens Axboee3cedca2008-11-19 19:57:52 +0100509 if (!ptr && o->type != FIO_OPT_STR_SET && o->type != FIO_OPT_STR) {
Jens Axboe28d7c362011-10-05 20:30:24 +0200510 log_err("Option %s requires an argument\n", o->name);
Jens Axboe08e26e32006-11-21 13:15:10 +0100511 return 1;
512 }
513
Jens Axboee1f36502006-10-27 10:54:08 +0200514 switch (o->type) {
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100515 case FIO_OPT_STR:
516 case FIO_OPT_STR_MULTI: {
Jens Axboee1f36502006-10-27 10:54:08 +0200517 fio_opt_str_fn *fn = o->cb;
518
Jens Axboef0857372007-03-19 13:15:23 +0100519 posval_sort(o, posval);
520
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100521 ret = 1;
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100522 for (i = 0; i < PARSE_MAX_VP; i++) {
Jens Axboef0857372007-03-19 13:15:23 +0100523 vp = &posval[i];
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100524 if (!vp->ival || vp->ival[0] == '\0')
Jens Axboea3073f42010-03-05 10:06:15 +0100525 continue;
Jens Axboeae2ddba2010-03-10 12:49:03 +0100526 all_skipped = 0;
Jens Axboe119cd932012-12-06 17:34:57 +0100527 if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) {
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100528 ret = 0;
Jens Axboe7b504ed2014-02-11 14:19:38 -0700529 if (o->off1)
Daniel Gollubebadc0c2014-02-12 08:24:57 -0700530 val_store(ilp, vp->oval, o->off1, vp->orval, data, o);
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100531 continue;
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100532 }
533 }
534
Jens Axboeae2ddba2010-03-10 12:49:03 +0100535 if (ret && !all_skipped)
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100536 show_option_values(o);
537 else if (fn)
538 ret = fn(data, ptr);
Jens Axboee1f36502006-10-27 10:54:08 +0200539 break;
540 }
Jens Axboee42b01e2011-05-05 12:05:10 -0600541 case FIO_OPT_STR_VAL_TIME:
542 is_time = 1;
Jens Axboef7fa2652009-03-09 14:20:20 +0100543 case FIO_OPT_INT:
Jens Axboee42b01e2011-05-05 12:05:10 -0600544 case FIO_OPT_STR_VAL: {
545 fio_opt_str_val_fn *fn = o->cb;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200546 char tmp[128], *p;
547
548 strncpy(tmp, ptr, sizeof(tmp) - 1);
549 p = strchr(tmp, ',');
550 if (p)
551 *p = '\0';
Jens Axboee1f36502006-10-27 10:54:08 +0200552
Jens Axboee42b01e2011-05-05 12:05:10 -0600553 if (is_time)
Jens Axboe0de5b262014-02-21 15:26:01 -0800554 ret = check_str_time(tmp, &ull, o->is_seconds);
Jens Axboee42b01e2011-05-05 12:05:10 -0600555 else
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200556 ret = check_str_bytes(tmp, &ull, data);
Jens Axboee42b01e2011-05-05 12:05:10 -0600557
Jens Axboeae3fcb52013-04-25 10:06:32 -0600558 dprint(FD_PARSE, " ret=%d, out=%llu\n", ret, ull);
559
Jens Axboee1f36502006-10-27 10:54:08 +0200560 if (ret)
561 break;
562
Jens Axboedb8e0162007-01-10 13:41:26 +0100563 if (o->maxval && ull > o->maxval) {
Jens Axboed4fc2f02012-09-24 14:32:26 +0200564 log_err("max value out of range: %llu"
565 " (%u max)\n", ull, o->maxval);
Jens Axboedb8e0162007-01-10 13:41:26 +0100566 return 1;
567 }
568 if (o->minval && ull < o->minval) {
Jens Axboed4fc2f02012-09-24 14:32:26 +0200569 log_err("min value out of range: %llu"
570 " (%u min)\n", ull, o->minval);
Jens Axboedb8e0162007-01-10 13:41:26 +0100571 return 1;
572 }
Jens Axboed926d532013-04-09 21:02:15 +0200573 if (o->posval[0].ival) {
574 posval_sort(o, posval);
575
576 ret = 1;
577 for (i = 0; i < PARSE_MAX_VP; i++) {
578 vp = &posval[i];
579 if (!vp->ival || vp->ival[0] == '\0')
580 continue;
581 if (vp->oval == ull) {
582 ret = 0;
583 break;
584 }
585 }
586 if (ret) {
Jens Axboe128e4ca2013-04-10 11:06:34 +0200587 log_err("fio: value %llu not allowed:\n", ull);
588 show_option_values(o);
Jens Axboed926d532013-04-09 21:02:15 +0200589 return 1;
590 }
591 }
Jens Axboee1f36502006-10-27 10:54:08 +0200592
593 if (fn)
594 ret = fn(data, &ull);
595 else {
Jens Axboee01b22b2009-06-09 15:43:25 +0200596 if (o->type == FIO_OPT_INT) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700597 if (first)
598 val_store(ilp, ull, o->off1, 0, data, o);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200599 if (curr == 1) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700600 if (o->off2)
601 val_store(ilp, ull, o->off2, 0, data, o);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100602 }
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200603 if (curr == 2) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700604 if (o->off3)
605 val_store(ilp, ull, o->off3, 0, data, o);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200606 }
607 if (!more) {
608 if (curr < 1) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700609 if (o->off2)
610 val_store(ilp, ull, o->off2, 0, data, o);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200611 }
612 if (curr < 2) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700613 if (o->off3)
614 val_store(ilp, ull, o->off3, 0, data, o);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200615 }
616 }
Jens Axboe75e6f362006-11-03 08:17:09 +0100617 } else {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700618 if (first)
619 val_store(ullp, ull, o->off1, 0, data, o);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100620 if (!more) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700621 if (o->off2)
622 val_store(ullp, ull, o->off2, 0, data, o);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100623 }
Jens Axboe75e6f362006-11-03 08:17:09 +0100624 }
Jens Axboee1f36502006-10-27 10:54:08 +0200625 }
626 break;
627 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200628 case FIO_OPT_FLOAT_LIST: {
Jens Axboeeef02442013-02-06 08:51:57 +0100629 char *cp2;
630
Vincent Kang Fu435d1952013-02-06 08:43:40 +0100631 if (first) {
632 /*
633 ** Initialize precision to 0 and zero out list
634 ** in case specified list is shorter than default
635 */
Jens Axboe3e260a42013-12-09 12:38:53 -0700636 if (o->off2) {
637 ul2 = 0;
Jens Axboef0fdbca2014-02-11 15:44:50 -0700638 ilp = td_var(data, o, o->off2);
Jens Axboe3e260a42013-12-09 12:38:53 -0700639 *ilp = ul2;
640 }
Vincent Kang Fu435d1952013-02-06 08:43:40 +0100641
Jens Axboef0fdbca2014-02-11 15:44:50 -0700642 flp = td_var(data, o, o->off1);
Vincent Kang Fu435d1952013-02-06 08:43:40 +0100643 for(i = 0; i < o->maxlen; i++)
644 flp[i].u.f = 0.0;
645 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200646 if (curr >= o->maxlen) {
Jens Axboe28d7c362011-10-05 20:30:24 +0200647 log_err("the list exceeding max length %d\n",
Yu-ju Hong83349192011-08-13 00:53:44 +0200648 o->maxlen);
649 return 1;
650 }
Jens Axboe3c3ed072012-03-27 09:12:39 +0200651 if (!str_to_float(ptr, &uf)) {
Jens Axboe28d7c362011-10-05 20:30:24 +0200652 log_err("not a floating point value: %s\n", ptr);
Yu-ju Hong83349192011-08-13 00:53:44 +0200653 return 1;
654 }
Jens Axboe26650692013-02-02 09:56:23 +0100655 if (uf > o->maxfp) {
Jens Axboe28d7c362011-10-05 20:30:24 +0200656 log_err("value out of range: %f"
Yu-ju Hong83349192011-08-13 00:53:44 +0200657 " (range max: %f)\n", uf, o->maxfp);
658 return 1;
659 }
Jens Axboe26650692013-02-02 09:56:23 +0100660 if (uf < o->minfp) {
Jens Axboe28d7c362011-10-05 20:30:24 +0200661 log_err("value out of range: %f"
Yu-ju Hong83349192011-08-13 00:53:44 +0200662 " (range min: %f)\n", uf, o->minfp);
663 return 1;
664 }
665
Jens Axboef0fdbca2014-02-11 15:44:50 -0700666 flp = td_var(data, o, o->off1);
Vincent Kang Fufd112d32013-02-02 09:28:55 +0100667 flp[curr].u.f = uf;
Yu-ju Hong83349192011-08-13 00:53:44 +0200668
Jens Axboeae3fcb52013-04-25 10:06:32 -0600669 dprint(FD_PARSE, " out=%f\n", uf);
670
Vincent Kang Fu435d1952013-02-06 08:43:40 +0100671 /*
672 ** Calculate precision for output by counting
673 ** number of digits after period. Find first
674 ** period in entire remaining list each time
675 */
676 cp2 = strchr(ptr, '.');
677 if (cp2 != NULL) {
Jens Axboeeef02442013-02-06 08:51:57 +0100678 int len = 0;
Vincent Kang Fu435d1952013-02-06 08:43:40 +0100679
680 while (*++cp2 != '\0' && *cp2 >= '0' && *cp2 <= '9')
681 len++;
682
Jens Axboe3e260a42013-12-09 12:38:53 -0700683 if (o->off2) {
Jens Axboef0fdbca2014-02-11 15:44:50 -0700684 ilp = td_var(data, o, o->off2);
Jens Axboe3e260a42013-12-09 12:38:53 -0700685 if (len > *ilp)
686 *ilp = len;
687 }
Vincent Kang Fu435d1952013-02-06 08:43:40 +0100688 }
689
Yu-ju Hong83349192011-08-13 00:53:44 +0200690 break;
691 }
Jens Axboeaf52b342007-03-13 10:07:47 +0100692 case FIO_OPT_STR_STORE: {
693 fio_opt_str_fn *fn = o->cb;
694
Jens Axboef75c69a2014-04-03 08:18:07 -0600695 if (!strlen(ptr))
696 return 1;
697
Jens Axboe7b504ed2014-02-11 14:19:38 -0700698 if (o->off1) {
Jens Axboef0fdbca2014-02-11 15:44:50 -0700699 cp = td_var(data, o, o->off1);
Steven Lang184b4092011-11-16 10:33:51 +0100700 *cp = strdup(ptr);
Jens Axboe1c964ce2011-08-31 16:45:03 -0600701 }
Jens Axboe02c6aad2010-03-04 13:49:11 +0100702
Steven Lang184b4092011-11-16 10:33:51 +0100703 if (fn)
704 ret = fn(data, ptr);
705 else if (o->posval[0].ival) {
706 posval_sort(o, posval);
Jens Axboec44b1ff2011-08-30 20:43:53 -0600707
Steven Lang184b4092011-11-16 10:33:51 +0100708 ret = 1;
709 for (i = 0; i < PARSE_MAX_VP; i++) {
710 vp = &posval[i];
Jens Axboeab508172014-04-14 13:16:10 -0600711 if (!vp->ival || vp->ival[0] == '\0' || !cp)
Steven Lang184b4092011-11-16 10:33:51 +0100712 continue;
713 all_skipped = 0;
Jens Axboe119cd932012-12-06 17:34:57 +0100714 if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) {
Steven Lang184b4092011-11-16 10:33:51 +0100715 char *rest;
716
717 ret = 0;
718 if (vp->cb)
719 fn = vp->cb;
720 rest = strstr(*cp ?: ptr, ":");
721 if (rest) {
722 if (*cp)
723 *rest = '\0';
724 ptr = rest + 1;
725 } else
726 ptr = NULL;
727 break;
728 }
Jens Axboeaf52b342007-03-13 10:07:47 +0100729 }
730 }
Jens Axboec44b1ff2011-08-30 20:43:53 -0600731
Steven Lang184b4092011-11-16 10:33:51 +0100732 if (!all_skipped) {
733 if (ret && !*cp)
734 show_option_values(o);
735 else if (ret && *cp)
736 ret = 0;
737 else if (fn && ptr)
738 ret = fn(data, ptr);
739 }
Jens Axboec44b1ff2011-08-30 20:43:53 -0600740
Jens Axboee1f36502006-10-27 10:54:08 +0200741 break;
Jens Axboeaf52b342007-03-13 10:07:47 +0100742 }
Jens Axboee1f36502006-10-27 10:54:08 +0200743 case FIO_OPT_RANGE: {
Jens Axboeb765a372006-10-27 15:00:16 +0200744 char tmp[128];
Jens Axboee1f36502006-10-27 10:54:08 +0200745 char *p1, *p2;
746
Jens Axboe0bbab0e2006-11-02 09:18:36 +0100747 strncpy(tmp, ptr, sizeof(tmp) - 1);
Jens Axboeb765a372006-10-27 15:00:16 +0200748
Dave Engberg31d23f42011-07-23 21:07:13 +0200749 /* Handle bsrange with separate read,write values: */
750 p1 = strchr(tmp, ',');
751 if (p1)
752 *p1 = '\0';
753
Jens Axboeb765a372006-10-27 15:00:16 +0200754 p1 = strchr(tmp, '-');
Jens Axboee1f36502006-10-27 10:54:08 +0200755 if (!p1) {
Jens Axboe0c9baf92007-01-11 15:59:26 +0100756 p1 = strchr(tmp, ':');
757 if (!p1) {
758 ret = 1;
759 break;
760 }
Jens Axboee1f36502006-10-27 10:54:08 +0200761 }
762
763 p2 = p1 + 1;
764 *p1 = '\0';
Jens Axboeb765a372006-10-27 15:00:16 +0200765 p1 = tmp;
Jens Axboee1f36502006-10-27 10:54:08 +0200766
767 ret = 1;
Jens Axboed6978a32009-07-18 21:04:09 +0200768 if (!check_range_bytes(p1, &ul1, data) &&
769 !check_range_bytes(p2, &ul2, data)) {
Jens Axboee1f36502006-10-27 10:54:08 +0200770 ret = 0;
Jens Axboee1f36502006-10-27 10:54:08 +0200771 if (ul1 > ul2) {
Jens Axboef90eff52006-11-06 11:08:21 +0100772 unsigned long foo = ul1;
773
774 ul1 = ul2;
775 ul2 = foo;
776 }
777
778 if (first) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700779 val_store(ilp, ul1, o->off1, 0, data, o);
780 val_store(ilp, ul2, o->off2, 0, data, o);
Jens Axboee1f36502006-10-27 10:54:08 +0200781 }
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200782 if (curr == 1) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700783 if (o->off3 && o->off4) {
784 val_store(ilp, ul1, o->off3, 0, data, o);
785 val_store(ilp, ul2, o->off4, 0, data, o);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200786 }
787 }
788 if (curr == 2) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700789 if (o->off5 && o->off6) {
790 val_store(ilp, ul1, o->off5, 0, data, o);
791 val_store(ilp, ul2, o->off6, 0, data, o);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200792 }
793 }
794 if (!more) {
795 if (curr < 1) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700796 if (o->off3 && o->off4) {
797 val_store(ilp, ul1, o->off3, 0, data, o);
798 val_store(ilp, ul2, o->off4, 0, data, o);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200799 }
800 }
801 if (curr < 2) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700802 if (o->off5 && o->off6) {
803 val_store(ilp, ul1, o->off5, 0, data, o);
804 val_store(ilp, ul2, o->off6, 0, data, o);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200805 }
806 }
Jens Axboe17abbe82006-11-06 11:23:10 +0100807 }
808 }
809
Jens Axboee1f36502006-10-27 10:54:08 +0200810 break;
811 }
Jens Axboe74ba1802011-07-15 09:09:15 +0200812 case FIO_OPT_BOOL:
813 case FIO_OPT_STR_SET: {
Jens Axboee1f36502006-10-27 10:54:08 +0200814 fio_opt_int_fn *fn = o->cb;
815
Jens Axboe74ba1802011-07-15 09:09:15 +0200816 if (ptr)
817 ret = check_int(ptr, &il);
818 else if (o->type == FIO_OPT_BOOL)
819 ret = 1;
820 else
821 il = 1;
822
Jens Axboeae3fcb52013-04-25 10:06:32 -0600823 dprint(FD_PARSE, " ret=%d, out=%d\n", ret, il);
824
Jens Axboee1f36502006-10-27 10:54:08 +0200825 if (ret)
826 break;
827
Jens Axboedb8e0162007-01-10 13:41:26 +0100828 if (o->maxval && il > (int) o->maxval) {
Jens Axboe28d7c362011-10-05 20:30:24 +0200829 log_err("max value out of range: %d (%d max)\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100830 il, o->maxval);
Jens Axboedb8e0162007-01-10 13:41:26 +0100831 return 1;
832 }
833 if (o->minval && il < o->minval) {
Jens Axboe28d7c362011-10-05 20:30:24 +0200834 log_err("min value out of range: %d (%d min)\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100835 il, o->minval);
Jens Axboedb8e0162007-01-10 13:41:26 +0100836 return 1;
837 }
Jens Axboee1f36502006-10-27 10:54:08 +0200838
Jens Axboe76a43db2007-01-11 13:24:44 +0100839 if (o->neg)
840 il = !il;
841
Jens Axboee1f36502006-10-27 10:54:08 +0200842 if (fn)
843 ret = fn(data, &il);
844 else {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700845 if (first)
846 val_store(ilp, il, o->off1, 0, data, o);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100847 if (!more) {
Jens Axboe7b504ed2014-02-11 14:19:38 -0700848 if (o->off2)
849 val_store(ilp, il, o->off2, 0, data, o);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100850 }
Jens Axboee1f36502006-10-27 10:54:08 +0200851 }
852 break;
853 }
Jens Axboe15ca1502008-04-07 09:26:02 +0200854 case FIO_OPT_DEPRECATED:
Jens Axboe06b0be62011-10-04 10:31:10 +0200855 log_info("Option %s is deprecated\n", o->name);
Jens Axboed9472272013-07-25 10:20:45 -0600856 ret = 1;
Jens Axboe15ca1502008-04-07 09:26:02 +0200857 break;
Jens Axboee1f36502006-10-27 10:54:08 +0200858 default:
Jens Axboe06b0be62011-10-04 10:31:10 +0200859 log_err("Bad option type %u\n", o->type);
Jens Axboee1f36502006-10-27 10:54:08 +0200860 ret = 1;
861 }
862
Jens Axboe70a4c0c2009-07-01 09:24:05 +0200863 if (ret)
864 return ret;
865
Jens Axboed447a8c2009-07-17 22:26:15 +0200866 if (o->verify) {
Jens Axboe70a4c0c2009-07-01 09:24:05 +0200867 ret = o->verify(o, data);
Jens Axboed447a8c2009-07-17 22:26:15 +0200868 if (ret) {
Jens Axboe28d7c362011-10-05 20:30:24 +0200869 log_err("Correct format for offending option\n");
870 log_err("%20s: %s\n", o->name, o->help);
Jens Axboe06b0be62011-10-04 10:31:10 +0200871 show_option_help(o, 1);
Jens Axboed447a8c2009-07-17 22:26:15 +0200872 }
873 }
Jens Axboe70a4c0c2009-07-01 09:24:05 +0200874
Jens Axboee1f36502006-10-27 10:54:08 +0200875 return ret;
876}
877
Jens Axboe7c8f1a52009-06-09 12:28:57 +0200878static int handle_option(struct fio_option *o, const char *__ptr, void *data)
Jens Axboef90eff52006-11-06 11:08:21 +0100879{
Jens Axboeb62bdf22010-03-10 12:36:17 +0100880 char *o_ptr, *ptr, *ptr2;
881 int ret, done;
Jens Axboef90eff52006-11-06 11:08:21 +0100882
Jens Axboe7c8f1a52009-06-09 12:28:57 +0200883 dprint(FD_PARSE, "handle_option=%s, ptr=%s\n", o->name, __ptr);
884
Jens Axboeb62bdf22010-03-10 12:36:17 +0100885 o_ptr = ptr = NULL;
Jens Axboe7c8f1a52009-06-09 12:28:57 +0200886 if (__ptr)
Jens Axboeb62bdf22010-03-10 12:36:17 +0100887 o_ptr = ptr = strdup(__ptr);
Jens Axboea3d741f2008-02-27 18:32:33 +0100888
Jens Axboef90eff52006-11-06 11:08:21 +0100889 /*
Jens Axboeb62bdf22010-03-10 12:36:17 +0100890 * See if we have another set of parameters, hidden after a comma.
891 * Do this before parsing this round, to check if we should
Jens Axboe787f7e92006-11-06 13:26:29 +0100892 * copy set 1 options to set 2.
Jens Axboef90eff52006-11-06 11:08:21 +0100893 */
Jens Axboeb62bdf22010-03-10 12:36:17 +0100894 done = 0;
895 ret = 1;
896 do {
897 int __ret;
898
899 ptr2 = NULL;
900 if (ptr &&
901 (o->type != FIO_OPT_STR_STORE) &&
Yu-ju Hong83349192011-08-13 00:53:44 +0200902 (o->type != FIO_OPT_STR) &&
903 (o->type != FIO_OPT_FLOAT_LIST)) {
Jens Axboeb62bdf22010-03-10 12:36:17 +0100904 ptr2 = strchr(ptr, ',');
905 if (ptr2 && *(ptr2 + 1) == '\0')
906 *ptr2 = '\0';
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200907 if (o->type != FIO_OPT_STR_MULTI && o->type != FIO_OPT_RANGE) {
Jens Axboeb62bdf22010-03-10 12:36:17 +0100908 if (!ptr2)
909 ptr2 = strchr(ptr, ':');
910 if (!ptr2)
911 ptr2 = strchr(ptr, '-');
912 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200913 } else if (ptr && o->type == FIO_OPT_FLOAT_LIST) {
914 ptr2 = strchr(ptr, ':');
Jens Axboeb62bdf22010-03-10 12:36:17 +0100915 }
916
917 /*
918 * Don't return early if parsing the first option fails - if
919 * we are doing multiple arguments, we can allow the first one
920 * being empty.
921 */
Yu-ju Hong83349192011-08-13 00:53:44 +0200922 __ret = __handle_option(o, ptr, data, !done, !!ptr2, done);
Jens Axboeb62bdf22010-03-10 12:36:17 +0100923 if (ret)
924 ret = __ret;
925
Jens Axboe0c9baf92007-01-11 15:59:26 +0100926 if (!ptr2)
Jens Axboeb62bdf22010-03-10 12:36:17 +0100927 break;
Jens Axboe787f7e92006-11-06 13:26:29 +0100928
Jens Axboeb62bdf22010-03-10 12:36:17 +0100929 ptr = ptr2 + 1;
930 done++;
931 } while (1);
Jens Axboe787f7e92006-11-06 13:26:29 +0100932
Jens Axboeb62bdf22010-03-10 12:36:17 +0100933 if (o_ptr)
934 free(o_ptr);
935 return ret;
Jens Axboef90eff52006-11-06 11:08:21 +0100936}
937
Steven Langde890a12011-11-09 14:03:34 +0100938static struct fio_option *get_option(char *opt,
Jens Axboe07b32322010-03-05 09:48:44 +0100939 struct fio_option *options, char **post)
Jens Axboe3b8b7132008-06-10 19:46:23 +0200940{
941 struct fio_option *o;
942 char *ret;
943
944 ret = strchr(opt, '=');
945 if (ret) {
946 *post = ret;
947 *ret = '\0';
Steven Langde890a12011-11-09 14:03:34 +0100948 ret = opt;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200949 (*post)++;
Jens Axboe43c129b2008-12-08 14:06:42 +0100950 strip_blank_end(ret);
Jens Axboe07b32322010-03-05 09:48:44 +0100951 o = find_option(options, ret);
Jens Axboe3b8b7132008-06-10 19:46:23 +0200952 } else {
Jens Axboe07b32322010-03-05 09:48:44 +0100953 o = find_option(options, opt);
Jens Axboe3b8b7132008-06-10 19:46:23 +0200954 *post = NULL;
955 }
956
957 return o;
958}
959
960static int opt_cmp(const void *p1, const void *p2)
961{
Steven Langde890a12011-11-09 14:03:34 +0100962 struct fio_option *o;
963 char *s, *foo;
Jens Axboe8cdabc12008-11-19 12:31:43 +0100964 int prio1, prio2;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200965
Jens Axboe8cdabc12008-11-19 12:31:43 +0100966 prio1 = prio2 = 0;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200967
Steven Langde890a12011-11-09 14:03:34 +0100968 if (*(char **)p1) {
969 s = strdup(*((char **) p1));
Jens Axboe9af4a242012-03-16 10:13:49 +0100970 o = get_option(s, __fio_options, &foo);
Steven Langde890a12011-11-09 14:03:34 +0100971 if (o)
972 prio1 = o->prio;
973 free(s);
974 }
975 if (*(char **)p2) {
976 s = strdup(*((char **) p2));
Jens Axboe9af4a242012-03-16 10:13:49 +0100977 o = get_option(s, __fio_options, &foo);
Steven Langde890a12011-11-09 14:03:34 +0100978 if (o)
979 prio2 = o->prio;
980 free(s);
981 }
982
Jens Axboe8cdabc12008-11-19 12:31:43 +0100983 return prio2 - prio1;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200984}
985
986void sort_options(char **opts, struct fio_option *options, int num_opts)
987{
Jens Axboe9af4a242012-03-16 10:13:49 +0100988 __fio_options = options;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200989 qsort(opts, num_opts, sizeof(char *), opt_cmp);
Jens Axboe9af4a242012-03-16 10:13:49 +0100990 __fio_options = NULL;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200991}
992
Jens Axboeb4692822006-10-27 13:43:22 +0200993int parse_cmd_option(const char *opt, const char *val,
Jens Axboe07b32322010-03-05 09:48:44 +0100994 struct fio_option *options, void *data)
Jens Axboeb4692822006-10-27 13:43:22 +0200995{
996 struct fio_option *o;
997
Jens Axboe07b32322010-03-05 09:48:44 +0100998 o = find_option(options, opt);
Jens Axboeb4692822006-10-27 13:43:22 +0200999 if (!o) {
Jens Axboe06b0be62011-10-04 10:31:10 +02001000 log_err("Bad option <%s>\n", opt);
Jens Axboeb4692822006-10-27 13:43:22 +02001001 return 1;
1002 }
1003
Jens Axboeb1508cf2006-11-02 09:12:40 +01001004 if (!handle_option(o, val, data))
1005 return 0;
1006
Jens Axboe06b0be62011-10-04 10:31:10 +02001007 log_err("fio: failed parsing %s=%s\n", opt, val);
Jens Axboeb1508cf2006-11-02 09:12:40 +01001008 return 1;
Jens Axboeb4692822006-10-27 13:43:22 +02001009}
1010
Steven Langde890a12011-11-09 14:03:34 +01001011int parse_option(char *opt, const char *input,
Jens Axboe292cc472013-11-26 20:39:35 -07001012 struct fio_option *options, struct fio_option **o, void *data,
1013 int dump_cmdline)
Jens Axboee1f36502006-10-27 10:54:08 +02001014{
Steven Langd0c814e2011-10-28 08:37:13 +02001015 char *post;
Jens Axboee1f36502006-10-27 10:54:08 +02001016
Steven Langd0c814e2011-10-28 08:37:13 +02001017 if (!opt) {
1018 log_err("fio: failed parsing %s\n", input);
Steven Langde890a12011-11-09 14:03:34 +01001019 *o = NULL;
Jens Axboe38789b52010-03-03 09:23:20 +01001020 return 1;
Steven Langd0c814e2011-10-28 08:37:13 +02001021 }
Jens Axboee1f36502006-10-27 10:54:08 +02001022
Steven Langde890a12011-11-09 14:03:34 +01001023 *o = get_option(opt, options, &post);
1024 if (!*o) {
1025 if (post) {
1026 int len = strlen(opt);
1027 if (opt + len + 1 != post)
1028 memmove(opt + len + 1, post, strlen(post));
1029 opt[len] = '=';
1030 }
Jens Axboee1f36502006-10-27 10:54:08 +02001031 return 1;
1032 }
1033
Jens Axboe292cc472013-11-26 20:39:35 -07001034 if (handle_option(*o, post, data)) {
1035 log_err("fio: failed parsing %s\n", input);
1036 return 1;
1037 }
Jens Axboeb1508cf2006-11-02 09:12:40 +01001038
Jens Axboe292cc472013-11-26 20:39:35 -07001039 if (dump_cmdline) {
1040 const char *delim;
1041
1042 if (!strcmp("description", (*o)->name))
1043 delim = "\"";
1044 else
1045 delim = "";
1046
1047 log_info("--%s%s", (*o)->name, post ? "" : " ");
1048 if (post)
1049 log_info("=%s%s%s ", delim, post, delim);
1050 }
1051
1052 return 0;
Jens Axboee1f36502006-10-27 10:54:08 +02001053}
Jens Axboefd28ca42007-01-09 21:20:13 +01001054
Jens Axboe0e9f7fa2007-03-01 14:05:30 +01001055/*
1056 * Option match, levenshtein distance. Handy for not quite remembering what
1057 * the option name is.
1058 */
1059static int string_distance(const char *s1, const char *s2)
1060{
1061 unsigned int s1_len = strlen(s1);
1062 unsigned int s2_len = strlen(s2);
1063 unsigned int *p, *q, *r;
1064 unsigned int i, j;
1065
1066 p = malloc(sizeof(unsigned int) * (s2_len + 1));
1067 q = malloc(sizeof(unsigned int) * (s2_len + 1));
1068
1069 p[0] = 0;
1070 for (i = 1; i <= s2_len; i++)
1071 p[i] = p[i - 1] + 1;
1072
1073 for (i = 1; i <= s1_len; i++) {
1074 q[0] = p[0] + 1;
1075 for (j = 1; j <= s2_len; j++) {
1076 unsigned int sub = p[j - 1];
1077
1078 if (s1[i - 1] != s2[j - 1])
1079 sub++;
1080
1081 q[j] = min(p[j] + 1, min(q[j - 1] + 1, sub));
1082 }
1083 r = p;
1084 p = q;
1085 q = r;
1086 }
1087
1088 i = p[s2_len];
1089 free(p);
1090 free(q);
1091 return i;
1092}
1093
Jens Axboeafdf9352007-07-31 16:14:34 +02001094static struct fio_option *find_child(struct fio_option *options,
1095 struct fio_option *o)
1096{
1097 struct fio_option *__o;
1098
Jens Axboefdf28742007-07-31 23:06:09 +02001099 for (__o = options + 1; __o->name; __o++)
1100 if (__o->parent && !strcmp(__o->parent, o->name))
Jens Axboeafdf9352007-07-31 16:14:34 +02001101 return __o;
1102
1103 return NULL;
1104}
1105
Jens Axboe323d9112008-03-01 15:12:14 +01001106static void __print_option(struct fio_option *o, struct fio_option *org,
1107 int level)
Jens Axboeafdf9352007-07-31 16:14:34 +02001108{
1109 char name[256], *p;
Jens Axboe323d9112008-03-01 15:12:14 +01001110 int depth;
Jens Axboeafdf9352007-07-31 16:14:34 +02001111
1112 if (!o)
1113 return;
Jens Axboeef9aff52007-07-31 22:56:53 +02001114 if (!org)
1115 org = o;
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001116
Jens Axboeafdf9352007-07-31 16:14:34 +02001117 p = name;
Jens Axboe323d9112008-03-01 15:12:14 +01001118 depth = level;
1119 while (depth--)
1120 p += sprintf(p, "%s", " ");
Jens Axboeafdf9352007-07-31 16:14:34 +02001121
1122 sprintf(p, "%s", o->name);
1123
Jens Axboe28d7c362011-10-05 20:30:24 +02001124 log_info("%-24s: %s\n", name, o->help);
Jens Axboe323d9112008-03-01 15:12:14 +01001125}
1126
1127static void print_option(struct fio_option *o)
1128{
1129 struct fio_option *parent;
1130 struct fio_option *__o;
1131 unsigned int printed;
1132 unsigned int level;
1133
1134 __print_option(o, NULL, 0);
1135 parent = o;
1136 level = 0;
1137 do {
1138 level++;
1139 printed = 0;
1140
1141 while ((__o = find_child(o, parent)) != NULL) {
1142 __print_option(__o, o, level);
1143 o = __o;
1144 printed++;
1145 }
1146
1147 parent = o;
1148 } while (printed);
Jens Axboeafdf9352007-07-31 16:14:34 +02001149}
1150
Jens Axboe07b32322010-03-05 09:48:44 +01001151int show_cmd_help(struct fio_option *options, const char *name)
Jens Axboe0e9f7fa2007-03-01 14:05:30 +01001152{
1153 struct fio_option *o, *closest;
Jens Axboed091d092010-04-01 19:56:23 +02001154 unsigned int best_dist = -1U;
Jens Axboe29fc6af2007-01-09 21:22:02 +01001155 int found = 0;
Jens Axboe320beef2007-03-01 10:44:12 +01001156 int show_all = 0;
1157
1158 if (!name || !strcmp(name, "all"))
1159 show_all = 1;
Jens Axboefd28ca42007-01-09 21:20:13 +01001160
Jens Axboe0e9f7fa2007-03-01 14:05:30 +01001161 closest = NULL;
1162 best_dist = -1;
Jens Axboe4945ba12007-01-11 14:36:56 +01001163 for (o = &options[0]; o->name; o++) {
Jens Axboe320beef2007-03-01 10:44:12 +01001164 int match = 0;
1165
Jens Axboe15ca1502008-04-07 09:26:02 +02001166 if (o->type == FIO_OPT_DEPRECATED)
1167 continue;
Jens Axboe07b32322010-03-05 09:48:44 +01001168 if (!exec_profile && o->prof_name)
1169 continue;
Jens Axboe4ac23d22013-05-23 21:14:03 +02001170 if (exec_profile && !(o->prof_name && !strcmp(exec_profile, o->prof_name)))
1171 continue;
Jens Axboe15ca1502008-04-07 09:26:02 +02001172
Jens Axboe0e9f7fa2007-03-01 14:05:30 +01001173 if (name) {
Jens Axboe7f9348f2007-03-15 14:09:28 +01001174 if (!strcmp(name, o->name) ||
1175 (o->alias && !strcmp(name, o->alias)))
Jens Axboe0e9f7fa2007-03-01 14:05:30 +01001176 match = 1;
1177 else {
1178 unsigned int dist;
1179
1180 dist = string_distance(name, o->name);
1181 if (dist < best_dist) {
1182 best_dist = dist;
1183 closest = o;
1184 }
1185 }
1186 }
Jens Axboefd28ca42007-01-09 21:20:13 +01001187
1188 if (show_all || match) {
Jens Axboe29fc6af2007-01-09 21:22:02 +01001189 found = 1;
Jens Axboec167ded2007-03-14 13:02:53 +01001190 if (match)
Jens Axboe28d7c362011-10-05 20:30:24 +02001191 log_info("%20s: %s\n", o->name, o->help);
Jens Axboec167ded2007-03-14 13:02:53 +01001192 if (show_all) {
Jens Axboeafdf9352007-07-31 16:14:34 +02001193 if (!o->parent)
Jens Axboe323d9112008-03-01 15:12:14 +01001194 print_option(o);
Jens Axboe4945ba12007-01-11 14:36:56 +01001195 continue;
Jens Axboec167ded2007-03-14 13:02:53 +01001196 }
Jens Axboefd28ca42007-01-09 21:20:13 +01001197 }
1198
Jens Axboe70df2f12007-01-11 14:04:47 +01001199 if (!match)
1200 continue;
1201
Jens Axboe06b0be62011-10-04 10:31:10 +02001202 show_option_help(o, 0);
Jens Axboefd28ca42007-01-09 21:20:13 +01001203 }
1204
Jens Axboe29fc6af2007-01-09 21:22:02 +01001205 if (found)
1206 return 0;
Jens Axboefd28ca42007-01-09 21:20:13 +01001207
Jens Axboe28d7c362011-10-05 20:30:24 +02001208 log_err("No such command: %s", name);
Jens Axboed091d092010-04-01 19:56:23 +02001209
1210 /*
1211 * Only print an appropriately close option, one where the edit
1212 * distance isn't too big. Otherwise we get crazy matches.
1213 */
1214 if (closest && best_dist < 3) {
Jens Axboe28d7c362011-10-05 20:30:24 +02001215 log_info(" - showing closest match\n");
1216 log_info("%20s: %s\n", closest->name, closest->help);
Jens Axboe06b0be62011-10-04 10:31:10 +02001217 show_option_help(closest, 0);
Jens Axboe0e9f7fa2007-03-01 14:05:30 +01001218 } else
Jens Axboe28d7c362011-10-05 20:30:24 +02001219 log_info("\n");
Jens Axboe0e9f7fa2007-03-01 14:05:30 +01001220
Jens Axboe29fc6af2007-01-09 21:22:02 +01001221 return 1;
Jens Axboefd28ca42007-01-09 21:20:13 +01001222}
Jens Axboeee738492007-01-10 11:23:16 +01001223
Jens Axboe13335dd2007-01-10 13:14:02 +01001224/*
1225 * Handle parsing of default parameters.
1226 */
Jens Axboeee738492007-01-10 11:23:16 +01001227void fill_default_options(void *data, struct fio_option *options)
1228{
Jens Axboe4945ba12007-01-11 14:36:56 +01001229 struct fio_option *o;
Jens Axboeee738492007-01-10 11:23:16 +01001230
Jens Axboea3d741f2008-02-27 18:32:33 +01001231 dprint(FD_PARSE, "filling default options\n");
1232
Jens Axboe4945ba12007-01-11 14:36:56 +01001233 for (o = &options[0]; o->name; o++)
Jens Axboeee738492007-01-10 11:23:16 +01001234 if (o->def)
1235 handle_option(o, o->def, data);
Jens Axboeee738492007-01-10 11:23:16 +01001236}
Jens Axboe13335dd2007-01-10 13:14:02 +01001237
Jens Axboe9f988e22010-03-04 10:42:38 +01001238void option_init(struct fio_option *o)
1239{
1240 if (o->type == FIO_OPT_DEPRECATED)
1241 return;
1242 if (o->type == FIO_OPT_BOOL) {
1243 o->minval = 0;
1244 o->maxval = 1;
1245 }
Jens Axboed4fc2f02012-09-24 14:32:26 +02001246 if (o->type == FIO_OPT_INT) {
1247 if (!o->maxval)
1248 o->maxval = UINT_MAX;
1249 }
Yu-ju Hong83349192011-08-13 00:53:44 +02001250 if (o->type == FIO_OPT_FLOAT_LIST) {
Bruce Cranab9461e2013-02-02 14:31:24 +00001251 o->minfp = DBL_MIN;
1252 o->maxfp = DBL_MAX;
Yu-ju Hong83349192011-08-13 00:53:44 +02001253 }
Jens Axboeef7035a2014-06-18 15:30:09 -07001254 if (o->type == FIO_OPT_STR_SET && o->def && !o->no_warn_def) {
Jens Axboe06b0be62011-10-04 10:31:10 +02001255 log_err("Option %s: string set option with"
Jens Axboe9f988e22010-03-04 10:42:38 +01001256 " default will always be true\n", o->name);
1257 }
Jens Axboe7b504ed2014-02-11 14:19:38 -07001258 if (!o->cb && !o->off1)
Jens Axboe06b0be62011-10-04 10:31:10 +02001259 log_err("Option %s: neither cb nor offset given\n", o->name);
Jens Axboe22754742013-04-10 13:05:23 +02001260 if (!o->category) {
Jens Axboecca5b5b2013-04-10 19:35:25 +02001261 log_info("Option %s: no category defined. Setting to misc\n", o->name);
Jens Axboe22754742013-04-10 13:05:23 +02001262 o->category = FIO_OPT_C_GENERAL;
Jens Axboeffd78212013-04-10 13:07:43 +02001263 o->group = FIO_OPT_G_INVALID;
Jens Axboe22754742013-04-10 13:05:23 +02001264 }
Jens Axboe5f6ddf12010-03-09 20:40:44 +01001265 if (o->type == FIO_OPT_STR || o->type == FIO_OPT_STR_STORE ||
1266 o->type == FIO_OPT_STR_MULTI)
Jens Axboe9f988e22010-03-04 10:42:38 +01001267 return;
Jens Axboe7b504ed2014-02-11 14:19:38 -07001268 if (o->cb && (o->off1 || o->off2 || o->off3 || o->off4))
Jens Axboe06b0be62011-10-04 10:31:10 +02001269 log_err("Option %s: both cb and offset given\n", o->name);
Jens Axboe9f988e22010-03-04 10:42:38 +01001270}
1271
Jens Axboe13335dd2007-01-10 13:14:02 +01001272/*
1273 * Sanitize the options structure. For now it just sets min/max for bool
Jens Axboe5b0a8882007-01-11 14:40:27 +01001274 * values and whether both callback and offsets are given.
Jens Axboe13335dd2007-01-10 13:14:02 +01001275 */
1276void options_init(struct fio_option *options)
1277{
Jens Axboe4945ba12007-01-11 14:36:56 +01001278 struct fio_option *o;
Jens Axboe13335dd2007-01-10 13:14:02 +01001279
Jens Axboea3d741f2008-02-27 18:32:33 +01001280 dprint(FD_PARSE, "init options\n");
1281
Jens Axboe90265352012-03-19 20:29:44 +01001282 for (o = &options[0]; o->name; o++) {
Jens Axboe9f988e22010-03-04 10:42:38 +01001283 option_init(o);
Jens Axboe90265352012-03-19 20:29:44 +01001284 if (o->inverse)
1285 o->inv_opt = find_option(options, o->inverse);
1286 }
Jens Axboe13335dd2007-01-10 13:14:02 +01001287}
Jens Axboe7e356b22011-10-14 10:55:16 +02001288
1289void options_free(struct fio_option *options, void *data)
1290{
1291 struct fio_option *o;
1292 char **ptr;
1293
1294 dprint(FD_PARSE, "free options\n");
1295
1296 for (o = &options[0]; o->name; o++) {
Steven Langde890a12011-11-09 14:03:34 +01001297 if (o->type != FIO_OPT_STR_STORE || !o->off1)
Jens Axboe7e356b22011-10-14 10:55:16 +02001298 continue;
1299
Jens Axboef0fdbca2014-02-11 15:44:50 -07001300 ptr = td_var(data, o, o->off1);
Jens Axboe7e356b22011-10-14 10:55:16 +02001301 if (*ptr) {
1302 free(*ptr);
1303 *ptr = NULL;
1304 }
1305 }
1306}