Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 1 | /* |
| 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 Carroll | 88b5a39 | 2008-10-07 11:25:20 +0200 | [diff] [blame] | 11 | #include <stdlib.h> |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 12 | #include <math.h> |
Bruce Cran | ab9461e | 2013-02-02 14:31:24 +0000 | [diff] [blame] | 13 | #include <float.h> |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 14 | |
| 15 | #include "parse.h" |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 16 | #include "debug.h" |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 17 | #include "options.h" |
Jens Axboe | e25839d | 2012-11-06 10:49:42 +0100 | [diff] [blame] | 18 | #include "minmax.h" |
Vincent Kang Fu | fd112d3 | 2013-02-02 09:28:55 +0100 | [diff] [blame] | 19 | #include "lib/ieee754.h" |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 20 | |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 21 | #ifdef CONFIG_ARITHMETIC |
| 22 | #include "y.tab.h" |
| 23 | #endif |
| 24 | |
Jens Axboe | 9af4a24 | 2012-03-16 10:13:49 +0100 | [diff] [blame] | 25 | static struct fio_option *__fio_options; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 26 | |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 27 | static 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 Axboe | ce952ab | 2011-08-31 14:29:22 -0600 | [diff] [blame] | 35 | static void posval_sort(struct fio_option *o, struct value_pair *vpmap) |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 36 | { |
| 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 Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 53 | static void show_option_range(struct fio_option *o, |
| 54 | int (*logger)(const char *format, ...)) |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 55 | { |
Jens Axboe | 3c037bc | 2013-04-10 11:21:33 +0200 | [diff] [blame] | 56 | if (o->type == FIO_OPT_FLOAT_LIST) { |
Bruce Cran | ab9461e | 2013-02-02 14:31:24 +0000 | [diff] [blame] | 57 | if (o->minfp == DBL_MIN && o->maxfp == DBL_MAX) |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 58 | return; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 59 | |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 60 | logger("%20s: min=%f", "range", o->minfp); |
Bruce Cran | ab9461e | 2013-02-02 14:31:24 +0000 | [diff] [blame] | 61 | if (o->maxfp != DBL_MAX) |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 62 | logger(", max=%f", o->maxfp); |
| 63 | logger("\n"); |
Jens Axboe | 3c037bc | 2013-04-10 11:21:33 +0200 | [diff] [blame] | 64 | } else if (!o->posval[0].ival) { |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 65 | if (!o->minval && !o->maxval) |
| 66 | return; |
| 67 | |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 68 | logger("%20s: min=%d", "range", o->minval); |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 69 | if (o->maxval) |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 70 | logger(", max=%d", o->maxval); |
| 71 | logger("\n"); |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 72 | } |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static void show_option_values(struct fio_option *o) |
| 76 | { |
Jens Axboe | a3073f4 | 2010-03-05 10:06:15 +0100 | [diff] [blame] | 77 | int i; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 78 | |
Jens Axboe | a3073f4 | 2010-03-05 10:06:15 +0100 | [diff] [blame] | 79 | for (i = 0; i < PARSE_MAX_VP; i++) { |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 80 | const struct value_pair *vp = &o->posval[i]; |
| 81 | |
| 82 | if (!vp->ival) |
Jens Axboe | a3073f4 | 2010-03-05 10:06:15 +0100 | [diff] [blame] | 83 | continue; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 84 | |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 85 | log_info("%20s: %-10s", i == 0 ? "valid values" : "", vp->ival); |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 86 | if (vp->help) |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 87 | log_info(" %s", vp->help); |
| 88 | log_info("\n"); |
Jens Axboe | a3073f4 | 2010-03-05 10:06:15 +0100 | [diff] [blame] | 89 | } |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 90 | |
| 91 | if (i) |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 92 | log_info("\n"); |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 95 | static void show_option_help(struct fio_option *o, int is_err) |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 96 | { |
| 97 | const char *typehelp[] = { |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 98 | "invalid", |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 99 | "string (opt=bla)", |
Jens Axboe | ae3fb6f | 2010-09-14 13:10:35 +0200 | [diff] [blame] | 100 | "string (opt=bla)", |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 101 | "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 Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 107 | "list of floating point values separated by ':' (opt=5.9:7.8)", |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 108 | "no argument (opt)", |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 109 | "deprecated", |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 110 | }; |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 111 | int (*logger)(const char *format, ...); |
| 112 | |
| 113 | if (is_err) |
| 114 | logger = log_err; |
| 115 | else |
| 116 | logger = log_info; |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 117 | |
| 118 | if (o->alias) |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 119 | logger("%20s: %s\n", "alias", o->alias); |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 120 | |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 121 | logger("%20s: %s\n", "type", typehelp[o->type]); |
| 122 | logger("%20s: %s\n", "default", o->def ? o->def : "no default"); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 123 | if (o->prof_name) |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 124 | logger("%20s: only for profile '%s'\n", "valid", o->prof_name); |
| 125 | show_option_range(o, logger); |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 126 | show_option_values(o); |
| 127 | } |
| 128 | |
Jens Axboe | 0de5b26 | 2014-02-21 15:26:01 -0800 | [diff] [blame] | 129 | static unsigned long long get_mult_time(const char *str, int len, |
| 130 | int is_seconds) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 131 | { |
Christian Ehrhardt | 74454ce | 2014-02-20 14:20:01 +0100 | [diff] [blame] | 132 | const char *p = str; |
| 133 | char *c; |
Jens Axboe | e466826 | 2014-02-21 11:50:09 -0800 | [diff] [blame] | 134 | unsigned long long mult = 1; |
Christian Ehrhardt | 74454ce | 2014-02-20 14:20:01 +0100 | [diff] [blame] | 135 | |
| 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 Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 143 | } |
Christian Ehrhardt | 74454ce | 2014-02-20 14:20:01 +0100 | [diff] [blame] | 144 | |
Jens Axboe | 0de5b26 | 2014-02-21 15:26:01 -0800 | [diff] [blame] | 145 | if (!isalpha((int) *p)) { |
| 146 | if (is_seconds) |
| 147 | return 1000000UL; |
| 148 | else |
| 149 | return 1; |
| 150 | } |
Christian Ehrhardt | 74454ce | 2014-02-20 14:20:01 +0100 | [diff] [blame] | 151 | |
| 152 | c = strdup(p); |
| 153 | for (int i = 0; i < strlen(c); i++) |
| 154 | c[i] = tolower(c[i]); |
| 155 | |
Jens Axboe | e466826 | 2014-02-21 11:50:09 -0800 | [diff] [blame] | 156 | if (!strncmp("us", c, 2) || !strncmp("usec", c, 4)) |
Christian Ehrhardt | 74454ce | 2014-02-20 14:20:01 +0100 | [diff] [blame] | 157 | mult = 1; |
Jens Axboe | e466826 | 2014-02-21 11:50:09 -0800 | [diff] [blame] | 158 | else if (!strncmp("ms", c, 2) || !strncmp("msec", c, 4)) |
Christian Ehrhardt | 74454ce | 2014-02-20 14:20:01 +0100 | [diff] [blame] | 159 | mult = 1000; |
Jens Axboe | e466826 | 2014-02-21 11:50:09 -0800 | [diff] [blame] | 160 | else if (!strcmp("s", c)) |
| 161 | mult = 1000000; |
Christian Ehrhardt | 74454ce | 2014-02-20 14:20:01 +0100 | [diff] [blame] | 162 | else if (!strcmp("m", c)) |
Jens Axboe | e466826 | 2014-02-21 11:50:09 -0800 | [diff] [blame] | 163 | mult = 60 * 1000000UL; |
Christian Ehrhardt | 74454ce | 2014-02-20 14:20:01 +0100 | [diff] [blame] | 164 | else if (!strcmp("h", c)) |
Jens Axboe | e466826 | 2014-02-21 11:50:09 -0800 | [diff] [blame] | 165 | mult = 60 * 60 * 1000000UL; |
Christian Ehrhardt | 74454ce | 2014-02-20 14:20:01 +0100 | [diff] [blame] | 166 | else if (!strcmp("d", c)) |
Jens Axboe | e466826 | 2014-02-21 11:50:09 -0800 | [diff] [blame] | 167 | mult = 24 * 60 * 60 * 1000000UL; |
Christian Ehrhardt | 74454ce | 2014-02-20 14:20:01 +0100 | [diff] [blame] | 168 | |
| 169 | free(c); |
| 170 | return mult; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Jens Axboe | a03fb65 | 2013-03-29 12:20:51 -0600 | [diff] [blame] | 173 | static 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 Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 186 | static unsigned long long __get_mult_bytes(const char *p, void *data, |
| 187 | int *percent) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 188 | { |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 189 | unsigned int kb_base = fio_get_kb_base(data); |
Jens Axboe | a639f0b | 2009-07-18 08:25:35 +0200 | [diff] [blame] | 190 | unsigned long long ret = 1; |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 191 | unsigned int i, pow = 0, mult = kb_base; |
| 192 | char *c; |
Jens Axboe | a639f0b | 2009-07-18 08:25:35 +0200 | [diff] [blame] | 193 | |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 194 | if (!p) |
| 195 | return 1; |
Jens Axboe | a639f0b | 2009-07-18 08:25:35 +0200 | [diff] [blame] | 196 | |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 197 | c = strdup(p); |
| 198 | |
Jens Axboe | a03fb65 | 2013-03-29 12:20:51 -0600 | [diff] [blame] | 199 | for (i = 0; i < strlen(c); i++) { |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 200 | c[i] = tolower(c[i]); |
Jens Axboe | a03fb65 | 2013-03-29 12:20:51 -0600 | [diff] [blame] | 201 | if (is_separator(c[i])) { |
| 202 | c[i] = '\0'; |
| 203 | break; |
| 204 | } |
| 205 | } |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 206 | |
Jens Axboe | a04f158 | 2012-03-07 10:53:29 +0100 | [diff] [blame] | 207 | if (!strncmp("pib", c, 3)) { |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 208 | pow = 5; |
| 209 | mult = 1000; |
Jens Axboe | a04f158 | 2012-03-07 10:53:29 +0100 | [diff] [blame] | 210 | } else if (!strncmp("tib", c, 3)) { |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 211 | pow = 4; |
| 212 | mult = 1000; |
Jens Axboe | a04f158 | 2012-03-07 10:53:29 +0100 | [diff] [blame] | 213 | } else if (!strncmp("gib", c, 3)) { |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 214 | pow = 3; |
| 215 | mult = 1000; |
Jens Axboe | a04f158 | 2012-03-07 10:53:29 +0100 | [diff] [blame] | 216 | } else if (!strncmp("mib", c, 3)) { |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 217 | pow = 2; |
| 218 | mult = 1000; |
Jens Axboe | a04f158 | 2012-03-07 10:53:29 +0100 | [diff] [blame] | 219 | } else if (!strncmp("kib", c, 3)) { |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 220 | pow = 1; |
| 221 | mult = 1000; |
Jens Axboe | a04f158 | 2012-03-07 10:53:29 +0100 | [diff] [blame] | 222 | } else if (!strncmp("p", c, 1) || !strncmp("pb", c, 2)) |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 223 | pow = 5; |
Jens Axboe | a04f158 | 2012-03-07 10:53:29 +0100 | [diff] [blame] | 224 | else if (!strncmp("t", c, 1) || !strncmp("tb", c, 2)) |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 225 | pow = 4; |
Jens Axboe | a04f158 | 2012-03-07 10:53:29 +0100 | [diff] [blame] | 226 | else if (!strncmp("g", c, 1) || !strncmp("gb", c, 2)) |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 227 | pow = 3; |
Jens Axboe | a04f158 | 2012-03-07 10:53:29 +0100 | [diff] [blame] | 228 | else if (!strncmp("m", c, 1) || !strncmp("mb", c, 2)) |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 229 | pow = 2; |
Jens Axboe | a04f158 | 2012-03-07 10:53:29 +0100 | [diff] [blame] | 230 | else if (!strncmp("k", c, 1) || !strncmp("kb", c, 2)) |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 231 | pow = 1; |
Jens Axboe | a04f158 | 2012-03-07 10:53:29 +0100 | [diff] [blame] | 232 | else if (!strncmp("%", c, 1)) { |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 233 | *percent = 1; |
Jens Axboe | e721c57 | 2012-02-09 20:55:29 +0100 | [diff] [blame] | 234 | free(c); |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 235 | return ret; |
| 236 | } |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 237 | |
| 238 | while (pow--) |
| 239 | ret *= (unsigned long long) mult; |
| 240 | |
| 241 | free(c); |
Jens Axboe | a639f0b | 2009-07-18 08:25:35 +0200 | [diff] [blame] | 242 | return ret; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 245 | static unsigned long long get_mult_bytes(const char *str, int len, void *data, |
Jens Axboe | 6925dd3 | 2011-09-07 22:10:11 +0200 | [diff] [blame] | 246 | int *percent) |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 247 | { |
Jens Axboe | 55ed963 | 2011-03-27 20:55:09 +0200 | [diff] [blame] | 248 | const char *p = str; |
Jens Axboe | ba4ddd6 | 2011-09-07 22:11:00 +0200 | [diff] [blame] | 249 | int digit_seen = 0; |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 250 | |
Jens Axboe | 1d1c187 | 2010-07-29 10:50:05 +0200 | [diff] [blame] | 251 | if (len < 2) |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 252 | return __get_mult_bytes(str, data, percent); |
Jens Axboe | 1d1c187 | 2010-07-29 10:50:05 +0200 | [diff] [blame] | 253 | |
Steven Lang | d0c814e | 2011-10-28 08:37:13 +0200 | [diff] [blame] | 254 | /* |
| 255 | * Go forward until we hit a non-digit, or +/- sign |
| 256 | */ |
Jens Axboe | 55ed963 | 2011-03-27 20:55:09 +0200 | [diff] [blame] | 257 | while ((p - str) <= len) { |
Jens Axboe | ba4ddd6 | 2011-09-07 22:11:00 +0200 | [diff] [blame] | 258 | if (!isdigit((int) *p) && |
| 259 | (((*p != '+') && (*p != '-')) || digit_seen)) |
Jens Axboe | 55ed963 | 2011-03-27 20:55:09 +0200 | [diff] [blame] | 260 | break; |
Jens Axboe | 3c703d1 | 2011-09-21 09:27:24 +0200 | [diff] [blame] | 261 | digit_seen |= isdigit((int) *p); |
Jens Axboe | 55ed963 | 2011-03-27 20:55:09 +0200 | [diff] [blame] | 262 | p++; |
| 263 | } |
| 264 | |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 265 | if (!isalpha((int) *p) && (*p != '%')) |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 266 | p = NULL; |
| 267 | |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 268 | return __get_mult_bytes(p, data, percent); |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 269 | } |
| 270 | |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 271 | extern int evaluate_arithmetic_expression(const char *buffer, long long *ival, |
Stephen M. Cameron | 64c9d60 | 2014-09-30 10:32:28 -0500 | [diff] [blame] | 272 | double *dval, double implied_units); |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 273 | |
Stephen M. Cameron | 21bda79 | 2014-09-30 08:29:33 -0500 | [diff] [blame] | 274 | #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 | */ |
Stephen M. Cameron | 64c9d60 | 2014-09-30 10:32:28 -0500 | [diff] [blame] | 281 | static void verify_exp_parser_float(const char *str, double implied_units) |
Stephen M. Cameron | 21bda79 | 2014-09-30 08:29:33 -0500 | [diff] [blame] | 282 | { |
| 283 | long long ival; |
| 284 | double dval, tmpval; |
| 285 | |
| 286 | if (sscanf(str, "%lf", &tmpval) != 1) |
| 287 | return; |
| 288 | |
Stephen M. Cameron | 64c9d60 | 2014-09-30 10:32:28 -0500 | [diff] [blame] | 289 | if (evaluate_arithmetic_expression(str, &ival, &dval, implied_units) != 0) { |
Stephen M. Cameron | 21bda79 | 2014-09-30 08:29:33 -0500 | [diff] [blame] | 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 | |
| 299 | static 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; |
Stephen M. Cameron | 64c9d60 | 2014-09-30 10:32:28 -0500 | [diff] [blame] | 304 | double implied_units = 1.0; |
Stephen M. Cameron | 21bda79 | 2014-09-30 08:29:33 -0500 | [diff] [blame] | 305 | |
Stephen M. Cameron | 64c9d60 | 2014-09-30 10:32:28 -0500 | [diff] [blame] | 306 | if (is_seconds) |
| 307 | implied_units = 1000000.0; |
| 308 | |
| 309 | rc = evaluate_arithmetic_expression(str, &ival, &dval, implied_units); |
Stephen M. Cameron | 21bda79 | 2014-09-30 08:29:33 -0500 | [diff] [blame] | 310 | if (!rc) { |
| 311 | if (ival != val) |
| 312 | log_info("Arithmetic failed on '%s', expected %lld, got %lld\n", |
| 313 | str, val, ival); |
| 314 | } else { |
| 315 | log_info("Arithmetic failed on '%s'\n", str); |
| 316 | } |
| 317 | } |
| 318 | #endif |
| 319 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 320 | /* |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 321 | * Convert string into a floating number. Return 1 for success and 0 otherwise. |
| 322 | */ |
Jens Axboe | e25839d | 2012-11-06 10:49:42 +0100 | [diff] [blame] | 323 | int str_to_float(const char *str, double *val) |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 324 | { |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 325 | #ifdef CONFIG_ARITHMETIC |
| 326 | int rc; |
| 327 | long long ival; |
| 328 | double dval; |
| 329 | |
| 330 | if (str[0] == '(') { |
Stephen M. Cameron | 64c9d60 | 2014-09-30 10:32:28 -0500 | [diff] [blame] | 331 | rc = evaluate_arithmetic_expression(str, &ival, &dval, 1.0); |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 332 | if (!rc) { |
| 333 | *val = dval; |
| 334 | return 1; |
| 335 | } |
Stephen M. Cameron | 21bda79 | 2014-09-30 08:29:33 -0500 | [diff] [blame] | 336 | } else { |
Stephen M. Cameron | 64c9d60 | 2014-09-30 10:32:28 -0500 | [diff] [blame] | 337 | verify_exp_parser_float(str, 1.0); |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 338 | } |
| 339 | #endif |
| 340 | return 1 == sscanf(str, "%lf", val); |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /* |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 344 | * convert string into decimal value, noting any size suffix |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 345 | */ |
Jens Axboe | 0de5b26 | 2014-02-21 15:26:01 -0800 | [diff] [blame] | 346 | int str_to_decimal(const char *str, long long *val, int kilo, void *data, |
| 347 | int is_seconds) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 348 | { |
Jens Axboe | b347f9d | 2009-03-09 14:15:21 +0100 | [diff] [blame] | 349 | int len, base; |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 350 | int rc = 1; |
| 351 | #ifdef CONFIG_ARITHMETIC |
| 352 | long long ival; |
| 353 | double dval; |
Stephen M. Cameron | 64c9d60 | 2014-09-30 10:32:28 -0500 | [diff] [blame] | 354 | double implied_units = 1.0; |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 355 | #endif |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 356 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 357 | len = strlen(str); |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 358 | if (!len) |
| 359 | return 1; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 360 | |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 361 | #ifdef CONFIG_ARITHMETIC |
Stephen M. Cameron | 64c9d60 | 2014-09-30 10:32:28 -0500 | [diff] [blame] | 362 | if (is_seconds) |
| 363 | implied_units = 1000000.0; |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 364 | if (str[0] == '(') |
Stephen M. Cameron | 64c9d60 | 2014-09-30 10:32:28 -0500 | [diff] [blame] | 365 | rc = evaluate_arithmetic_expression(str, &ival, &dval, implied_units); |
Stephen M. Cameron | c3805eb | 2014-09-29 12:15:35 -0600 | [diff] [blame] | 366 | if (str[0] == '(' && !rc) { |
| 367 | if (!kilo && is_seconds) |
| 368 | *val = ival / 1000000LL; |
| 369 | else |
| 370 | *val = ival; |
| 371 | } |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 372 | #endif |
Jens Axboe | b347f9d | 2009-03-09 14:15:21 +0100 | [diff] [blame] | 373 | |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 374 | if (rc == 1) { |
| 375 | if (strstr(str, "0x") || strstr(str, "0X")) |
| 376 | base = 16; |
| 377 | else |
| 378 | base = 10; |
| 379 | |
| 380 | *val = strtoll(str, NULL, base); |
| 381 | if (*val == LONG_MAX && errno == ERANGE) |
| 382 | return 1; |
| 383 | } |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 384 | |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 385 | if (kilo) { |
| 386 | unsigned long long mult; |
| 387 | int perc = 0; |
| 388 | |
Jens Axboe | 6925dd3 | 2011-09-07 22:10:11 +0200 | [diff] [blame] | 389 | mult = get_mult_bytes(str, len, data, &perc); |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 390 | if (perc) |
| 391 | *val = -1ULL - *val; |
| 392 | else |
| 393 | *val *= mult; |
| 394 | } else |
Jens Axboe | 0de5b26 | 2014-02-21 15:26:01 -0800 | [diff] [blame] | 395 | *val *= get_mult_time(str, len, is_seconds); |
Stephen M. Cameron | 21bda79 | 2014-09-30 08:29:33 -0500 | [diff] [blame] | 396 | #ifdef CONFIG_ARITHMETIC |
| 397 | verify_exp_parser_decimal(str, *val, kilo, is_seconds); |
| 398 | #endif |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | |
Jens Axboe | 9af4a24 | 2012-03-16 10:13:49 +0100 | [diff] [blame] | 402 | int check_str_bytes(const char *p, long long *val, void *data) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 403 | { |
Jens Axboe | 0de5b26 | 2014-02-21 15:26:01 -0800 | [diff] [blame] | 404 | return str_to_decimal(p, val, 1, data, 0); |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 405 | } |
| 406 | |
Jens Axboe | 0de5b26 | 2014-02-21 15:26:01 -0800 | [diff] [blame] | 407 | int check_str_time(const char *p, long long *val, int is_seconds) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 408 | { |
Jens Axboe | 0de5b26 | 2014-02-21 15:26:01 -0800 | [diff] [blame] | 409 | return str_to_decimal(p, val, 0, NULL, is_seconds); |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | void strip_blank_front(char **p) |
| 413 | { |
| 414 | char *s = *p; |
| 415 | |
Jens Axboe | 4c8e964 | 2011-10-15 14:37:38 +0200 | [diff] [blame] | 416 | if (!strlen(s)) |
| 417 | return; |
Jens Axboe | 76cd937 | 2011-07-08 21:14:57 +0200 | [diff] [blame] | 418 | while (isspace((int) *s)) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 419 | s++; |
Jens Axboe | 4d651da | 2007-03-28 19:34:53 +0200 | [diff] [blame] | 420 | |
| 421 | *p = s; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | void strip_blank_end(char *p) |
| 425 | { |
Jens Axboe | 853ee7f | 2009-03-06 20:29:29 +0100 | [diff] [blame] | 426 | char *start = p, *s; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 427 | |
Jens Axboe | 4c8e964 | 2011-10-15 14:37:38 +0200 | [diff] [blame] | 428 | if (!strlen(p)) |
| 429 | return; |
| 430 | |
Jens Axboe | 523bfad | 2007-04-04 11:04:06 +0200 | [diff] [blame] | 431 | s = strchr(p, ';'); |
| 432 | if (s) |
| 433 | *s = '\0'; |
| 434 | s = strchr(p, '#'); |
| 435 | if (s) |
| 436 | *s = '\0'; |
| 437 | if (s) |
| 438 | p = s; |
| 439 | |
Jens Axboe | 7f7e6e5 | 2007-07-19 14:50:05 +0200 | [diff] [blame] | 440 | s = p + strlen(p); |
Jens Axboe | 76cd937 | 2011-07-08 21:14:57 +0200 | [diff] [blame] | 441 | while ((isspace((int) *s) || iscntrl((int) *s)) && (s > start)) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 442 | s--; |
| 443 | |
| 444 | *(s + 1) = '\0'; |
| 445 | } |
| 446 | |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 447 | static int check_range_bytes(const char *str, long *val, void *data) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 448 | { |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 449 | long long __val; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 450 | |
Jens Axboe | 0de5b26 | 2014-02-21 15:26:01 -0800 | [diff] [blame] | 451 | if (!str_to_decimal(str, &__val, 1, data, 0)) { |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 452 | *val = __val; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 453 | return 0; |
| 454 | } |
| 455 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 456 | return 1; |
| 457 | } |
| 458 | |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 459 | static int check_int(const char *p, int *val) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 460 | { |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 461 | if (!strlen(p)) |
| 462 | return 1; |
Jens Axboe | d78ee46 | 2007-08-10 14:03:20 +0200 | [diff] [blame] | 463 | if (strstr(p, "0x") || strstr(p, "0X")) { |
Jens Axboe | a61bdfd | 2007-07-30 09:07:04 +0200 | [diff] [blame] | 464 | if (sscanf(p, "%x", val) == 1) |
| 465 | return 0; |
| 466 | } else { |
| 467 | if (sscanf(p, "%u", val) == 1) |
| 468 | return 0; |
| 469 | } |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 470 | |
| 471 | return 1; |
| 472 | } |
| 473 | |
Jens Axboe | 8adb452 | 2014-09-23 10:38:54 -0600 | [diff] [blame] | 474 | static size_t opt_len(const char *str) |
Jens Axboe | 808def7 | 2010-07-14 16:27:02 -0600 | [diff] [blame] | 475 | { |
| 476 | char *postfix; |
| 477 | |
| 478 | postfix = strchr(str, ':'); |
| 479 | if (!postfix) |
| 480 | return strlen(str); |
| 481 | |
| 482 | return (int)(postfix - str); |
| 483 | } |
| 484 | |
Jens Axboe | 119cd93 | 2012-12-06 17:34:57 +0100 | [diff] [blame] | 485 | static int str_match_len(const struct value_pair *vp, const char *str) |
| 486 | { |
| 487 | return max(strlen(vp->ival), opt_len(str)); |
| 488 | } |
| 489 | |
Jens Axboe | f0fdbca | 2014-02-11 15:44:50 -0700 | [diff] [blame] | 490 | #define val_store(ptr, val, off, or, data, o) \ |
| 491 | do { \ |
| 492 | ptr = td_var((data), (o), (off)); \ |
| 493 | if ((or)) \ |
| 494 | *ptr |= (val); \ |
| 495 | else \ |
| 496 | *ptr = (val); \ |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 497 | } while (0) |
| 498 | |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 499 | static int __handle_option(struct fio_option *o, const char *ptr, void *data, |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 500 | int first, int more, int curr) |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 501 | { |
Erwan Velu | 2fdbefd | 2013-07-22 23:48:48 +0200 | [diff] [blame] | 502 | int il=0, *ilp; |
Vincent Kang Fu | fd112d3 | 2013-02-02 09:28:55 +0100 | [diff] [blame] | 503 | fio_fp64_t *flp; |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 504 | long long ull, *ullp; |
| 505 | long ul1, ul2; |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 506 | double uf; |
Jens Axboe | bfe1d59 | 2012-11-29 21:33:03 +0100 | [diff] [blame] | 507 | char **cp = NULL; |
Jens Axboe | e42b01e | 2011-05-05 12:05:10 -0600 | [diff] [blame] | 508 | int ret = 0, is_time = 0; |
Jens Axboe | c44b1ff | 2011-08-30 20:43:53 -0600 | [diff] [blame] | 509 | const struct value_pair *vp; |
| 510 | struct value_pair posval[PARSE_MAX_VP]; |
| 511 | int i, all_skipped = 1; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 512 | |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 513 | dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name, |
| 514 | o->type, ptr); |
| 515 | |
Jens Axboe | e3cedca | 2008-11-19 19:57:52 +0100 | [diff] [blame] | 516 | if (!ptr && o->type != FIO_OPT_STR_SET && o->type != FIO_OPT_STR) { |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 517 | log_err("Option %s requires an argument\n", o->name); |
Jens Axboe | 08e26e3 | 2006-11-21 13:15:10 +0100 | [diff] [blame] | 518 | return 1; |
| 519 | } |
| 520 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 521 | switch (o->type) { |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 522 | case FIO_OPT_STR: |
| 523 | case FIO_OPT_STR_MULTI: { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 524 | fio_opt_str_fn *fn = o->cb; |
| 525 | |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 526 | posval_sort(o, posval); |
| 527 | |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 528 | ret = 1; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 529 | for (i = 0; i < PARSE_MAX_VP; i++) { |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 530 | vp = &posval[i]; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 531 | if (!vp->ival || vp->ival[0] == '\0') |
Jens Axboe | a3073f4 | 2010-03-05 10:06:15 +0100 | [diff] [blame] | 532 | continue; |
Jens Axboe | ae2ddba | 2010-03-10 12:49:03 +0100 | [diff] [blame] | 533 | all_skipped = 0; |
Jens Axboe | 119cd93 | 2012-12-06 17:34:57 +0100 | [diff] [blame] | 534 | if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) { |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 535 | ret = 0; |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 536 | if (o->off1) |
Daniel Gollub | ebadc0c | 2014-02-12 08:24:57 -0700 | [diff] [blame] | 537 | val_store(ilp, vp->oval, o->off1, vp->orval, data, o); |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 538 | continue; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
Jens Axboe | ae2ddba | 2010-03-10 12:49:03 +0100 | [diff] [blame] | 542 | if (ret && !all_skipped) |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 543 | show_option_values(o); |
| 544 | else if (fn) |
| 545 | ret = fn(data, ptr); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 546 | break; |
| 547 | } |
Jens Axboe | e42b01e | 2011-05-05 12:05:10 -0600 | [diff] [blame] | 548 | case FIO_OPT_STR_VAL_TIME: |
| 549 | is_time = 1; |
Jens Axboe | f7fa265 | 2009-03-09 14:20:20 +0100 | [diff] [blame] | 550 | case FIO_OPT_INT: |
Jens Axboe | e42b01e | 2011-05-05 12:05:10 -0600 | [diff] [blame] | 551 | case FIO_OPT_STR_VAL: { |
| 552 | fio_opt_str_val_fn *fn = o->cb; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 553 | char tmp[128], *p; |
| 554 | |
| 555 | strncpy(tmp, ptr, sizeof(tmp) - 1); |
| 556 | p = strchr(tmp, ','); |
| 557 | if (p) |
| 558 | *p = '\0'; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 559 | |
Jens Axboe | e42b01e | 2011-05-05 12:05:10 -0600 | [diff] [blame] | 560 | if (is_time) |
Jens Axboe | 0de5b26 | 2014-02-21 15:26:01 -0800 | [diff] [blame] | 561 | ret = check_str_time(tmp, &ull, o->is_seconds); |
Jens Axboe | e42b01e | 2011-05-05 12:05:10 -0600 | [diff] [blame] | 562 | else |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 563 | ret = check_str_bytes(tmp, &ull, data); |
Jens Axboe | e42b01e | 2011-05-05 12:05:10 -0600 | [diff] [blame] | 564 | |
Jens Axboe | ae3fcb5 | 2013-04-25 10:06:32 -0600 | [diff] [blame] | 565 | dprint(FD_PARSE, " ret=%d, out=%llu\n", ret, ull); |
| 566 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 567 | if (ret) |
| 568 | break; |
| 569 | |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 570 | if (o->maxval && ull > o->maxval) { |
Jens Axboe | d4fc2f0 | 2012-09-24 14:32:26 +0200 | [diff] [blame] | 571 | log_err("max value out of range: %llu" |
| 572 | " (%u max)\n", ull, o->maxval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 573 | return 1; |
| 574 | } |
| 575 | if (o->minval && ull < o->minval) { |
Jens Axboe | d4fc2f0 | 2012-09-24 14:32:26 +0200 | [diff] [blame] | 576 | log_err("min value out of range: %llu" |
| 577 | " (%u min)\n", ull, o->minval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 578 | return 1; |
| 579 | } |
Jens Axboe | d926d53 | 2013-04-09 21:02:15 +0200 | [diff] [blame] | 580 | if (o->posval[0].ival) { |
| 581 | posval_sort(o, posval); |
| 582 | |
| 583 | ret = 1; |
| 584 | for (i = 0; i < PARSE_MAX_VP; i++) { |
| 585 | vp = &posval[i]; |
| 586 | if (!vp->ival || vp->ival[0] == '\0') |
| 587 | continue; |
| 588 | if (vp->oval == ull) { |
| 589 | ret = 0; |
| 590 | break; |
| 591 | } |
| 592 | } |
| 593 | if (ret) { |
Jens Axboe | 128e4ca | 2013-04-10 11:06:34 +0200 | [diff] [blame] | 594 | log_err("fio: value %llu not allowed:\n", ull); |
| 595 | show_option_values(o); |
Jens Axboe | d926d53 | 2013-04-09 21:02:15 +0200 | [diff] [blame] | 596 | return 1; |
| 597 | } |
| 598 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 599 | |
| 600 | if (fn) |
| 601 | ret = fn(data, &ull); |
| 602 | else { |
Jens Axboe | e01b22b | 2009-06-09 15:43:25 +0200 | [diff] [blame] | 603 | if (o->type == FIO_OPT_INT) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 604 | if (first) |
| 605 | val_store(ilp, ull, o->off1, 0, data, o); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 606 | if (curr == 1) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 607 | if (o->off2) |
| 608 | val_store(ilp, ull, o->off2, 0, data, o); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 609 | } |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 610 | if (curr == 2) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 611 | if (o->off3) |
| 612 | val_store(ilp, ull, o->off3, 0, data, o); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 613 | } |
| 614 | if (!more) { |
| 615 | if (curr < 1) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 616 | if (o->off2) |
| 617 | val_store(ilp, ull, o->off2, 0, data, o); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 618 | } |
| 619 | if (curr < 2) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 620 | if (o->off3) |
| 621 | val_store(ilp, ull, o->off3, 0, data, o); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 622 | } |
| 623 | } |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 624 | } else { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 625 | if (first) |
| 626 | val_store(ullp, ull, o->off1, 0, data, o); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 627 | if (!more) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 628 | if (o->off2) |
| 629 | val_store(ullp, ull, o->off2, 0, data, o); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 630 | } |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 631 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 632 | } |
| 633 | break; |
| 634 | } |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 635 | case FIO_OPT_FLOAT_LIST: { |
Jens Axboe | eef0244 | 2013-02-06 08:51:57 +0100 | [diff] [blame] | 636 | char *cp2; |
| 637 | |
Vincent Kang Fu | 435d195 | 2013-02-06 08:43:40 +0100 | [diff] [blame] | 638 | if (first) { |
| 639 | /* |
| 640 | ** Initialize precision to 0 and zero out list |
| 641 | ** in case specified list is shorter than default |
| 642 | */ |
Jens Axboe | 3e260a4 | 2013-12-09 12:38:53 -0700 | [diff] [blame] | 643 | if (o->off2) { |
| 644 | ul2 = 0; |
Jens Axboe | f0fdbca | 2014-02-11 15:44:50 -0700 | [diff] [blame] | 645 | ilp = td_var(data, o, o->off2); |
Jens Axboe | 3e260a4 | 2013-12-09 12:38:53 -0700 | [diff] [blame] | 646 | *ilp = ul2; |
| 647 | } |
Vincent Kang Fu | 435d195 | 2013-02-06 08:43:40 +0100 | [diff] [blame] | 648 | |
Jens Axboe | f0fdbca | 2014-02-11 15:44:50 -0700 | [diff] [blame] | 649 | flp = td_var(data, o, o->off1); |
Vincent Kang Fu | 435d195 | 2013-02-06 08:43:40 +0100 | [diff] [blame] | 650 | for(i = 0; i < o->maxlen; i++) |
| 651 | flp[i].u.f = 0.0; |
| 652 | } |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 653 | if (curr >= o->maxlen) { |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 654 | log_err("the list exceeding max length %d\n", |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 655 | o->maxlen); |
| 656 | return 1; |
| 657 | } |
Jens Axboe | 3c3ed07 | 2012-03-27 09:12:39 +0200 | [diff] [blame] | 658 | if (!str_to_float(ptr, &uf)) { |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 659 | log_err("not a floating point value: %s\n", ptr); |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 660 | return 1; |
| 661 | } |
Jens Axboe | 2665069 | 2013-02-02 09:56:23 +0100 | [diff] [blame] | 662 | if (uf > o->maxfp) { |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 663 | log_err("value out of range: %f" |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 664 | " (range max: %f)\n", uf, o->maxfp); |
| 665 | return 1; |
| 666 | } |
Jens Axboe | 2665069 | 2013-02-02 09:56:23 +0100 | [diff] [blame] | 667 | if (uf < o->minfp) { |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 668 | log_err("value out of range: %f" |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 669 | " (range min: %f)\n", uf, o->minfp); |
| 670 | return 1; |
| 671 | } |
| 672 | |
Jens Axboe | f0fdbca | 2014-02-11 15:44:50 -0700 | [diff] [blame] | 673 | flp = td_var(data, o, o->off1); |
Vincent Kang Fu | fd112d3 | 2013-02-02 09:28:55 +0100 | [diff] [blame] | 674 | flp[curr].u.f = uf; |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 675 | |
Jens Axboe | ae3fcb5 | 2013-04-25 10:06:32 -0600 | [diff] [blame] | 676 | dprint(FD_PARSE, " out=%f\n", uf); |
| 677 | |
Vincent Kang Fu | 435d195 | 2013-02-06 08:43:40 +0100 | [diff] [blame] | 678 | /* |
| 679 | ** Calculate precision for output by counting |
| 680 | ** number of digits after period. Find first |
| 681 | ** period in entire remaining list each time |
| 682 | */ |
| 683 | cp2 = strchr(ptr, '.'); |
| 684 | if (cp2 != NULL) { |
Jens Axboe | eef0244 | 2013-02-06 08:51:57 +0100 | [diff] [blame] | 685 | int len = 0; |
Vincent Kang Fu | 435d195 | 2013-02-06 08:43:40 +0100 | [diff] [blame] | 686 | |
| 687 | while (*++cp2 != '\0' && *cp2 >= '0' && *cp2 <= '9') |
| 688 | len++; |
| 689 | |
Jens Axboe | 3e260a4 | 2013-12-09 12:38:53 -0700 | [diff] [blame] | 690 | if (o->off2) { |
Jens Axboe | f0fdbca | 2014-02-11 15:44:50 -0700 | [diff] [blame] | 691 | ilp = td_var(data, o, o->off2); |
Jens Axboe | 3e260a4 | 2013-12-09 12:38:53 -0700 | [diff] [blame] | 692 | if (len > *ilp) |
| 693 | *ilp = len; |
| 694 | } |
Vincent Kang Fu | 435d195 | 2013-02-06 08:43:40 +0100 | [diff] [blame] | 695 | } |
| 696 | |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 697 | break; |
| 698 | } |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 699 | case FIO_OPT_STR_STORE: { |
| 700 | fio_opt_str_fn *fn = o->cb; |
| 701 | |
Jens Axboe | f75c69a | 2014-04-03 08:18:07 -0600 | [diff] [blame] | 702 | if (!strlen(ptr)) |
| 703 | return 1; |
| 704 | |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 705 | if (o->off1) { |
Jens Axboe | f0fdbca | 2014-02-11 15:44:50 -0700 | [diff] [blame] | 706 | cp = td_var(data, o, o->off1); |
Steven Lang | 184b409 | 2011-11-16 10:33:51 +0100 | [diff] [blame] | 707 | *cp = strdup(ptr); |
Jens Axboe | 1c964ce | 2011-08-31 16:45:03 -0600 | [diff] [blame] | 708 | } |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 709 | |
Steven Lang | 184b409 | 2011-11-16 10:33:51 +0100 | [diff] [blame] | 710 | if (fn) |
| 711 | ret = fn(data, ptr); |
| 712 | else if (o->posval[0].ival) { |
| 713 | posval_sort(o, posval); |
Jens Axboe | c44b1ff | 2011-08-30 20:43:53 -0600 | [diff] [blame] | 714 | |
Steven Lang | 184b409 | 2011-11-16 10:33:51 +0100 | [diff] [blame] | 715 | ret = 1; |
| 716 | for (i = 0; i < PARSE_MAX_VP; i++) { |
| 717 | vp = &posval[i]; |
Jens Axboe | ab50817 | 2014-04-14 13:16:10 -0600 | [diff] [blame] | 718 | if (!vp->ival || vp->ival[0] == '\0' || !cp) |
Steven Lang | 184b409 | 2011-11-16 10:33:51 +0100 | [diff] [blame] | 719 | continue; |
| 720 | all_skipped = 0; |
Jens Axboe | 119cd93 | 2012-12-06 17:34:57 +0100 | [diff] [blame] | 721 | if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) { |
Steven Lang | 184b409 | 2011-11-16 10:33:51 +0100 | [diff] [blame] | 722 | char *rest; |
| 723 | |
| 724 | ret = 0; |
| 725 | if (vp->cb) |
| 726 | fn = vp->cb; |
| 727 | rest = strstr(*cp ?: ptr, ":"); |
| 728 | if (rest) { |
| 729 | if (*cp) |
| 730 | *rest = '\0'; |
| 731 | ptr = rest + 1; |
| 732 | } else |
| 733 | ptr = NULL; |
| 734 | break; |
| 735 | } |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 736 | } |
| 737 | } |
Jens Axboe | c44b1ff | 2011-08-30 20:43:53 -0600 | [diff] [blame] | 738 | |
Steven Lang | 184b409 | 2011-11-16 10:33:51 +0100 | [diff] [blame] | 739 | if (!all_skipped) { |
| 740 | if (ret && !*cp) |
| 741 | show_option_values(o); |
| 742 | else if (ret && *cp) |
| 743 | ret = 0; |
| 744 | else if (fn && ptr) |
| 745 | ret = fn(data, ptr); |
| 746 | } |
Jens Axboe | c44b1ff | 2011-08-30 20:43:53 -0600 | [diff] [blame] | 747 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 748 | break; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 749 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 750 | case FIO_OPT_RANGE: { |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 751 | char tmp[128]; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 752 | char *p1, *p2; |
| 753 | |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 754 | strncpy(tmp, ptr, sizeof(tmp) - 1); |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 755 | |
Dave Engberg | 31d23f4 | 2011-07-23 21:07:13 +0200 | [diff] [blame] | 756 | /* Handle bsrange with separate read,write values: */ |
| 757 | p1 = strchr(tmp, ','); |
| 758 | if (p1) |
| 759 | *p1 = '\0'; |
| 760 | |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 761 | p1 = strchr(tmp, '-'); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 762 | if (!p1) { |
Jens Axboe | 0c9baf9 | 2007-01-11 15:59:26 +0100 | [diff] [blame] | 763 | p1 = strchr(tmp, ':'); |
| 764 | if (!p1) { |
| 765 | ret = 1; |
| 766 | break; |
| 767 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | p2 = p1 + 1; |
| 771 | *p1 = '\0'; |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 772 | p1 = tmp; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 773 | |
| 774 | ret = 1; |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 775 | if (!check_range_bytes(p1, &ul1, data) && |
| 776 | !check_range_bytes(p2, &ul2, data)) { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 777 | ret = 0; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 778 | if (ul1 > ul2) { |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 779 | unsigned long foo = ul1; |
| 780 | |
| 781 | ul1 = ul2; |
| 782 | ul2 = foo; |
| 783 | } |
| 784 | |
| 785 | if (first) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 786 | val_store(ilp, ul1, o->off1, 0, data, o); |
| 787 | val_store(ilp, ul2, o->off2, 0, data, o); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 788 | } |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 789 | if (curr == 1) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 790 | if (o->off3 && o->off4) { |
| 791 | val_store(ilp, ul1, o->off3, 0, data, o); |
| 792 | val_store(ilp, ul2, o->off4, 0, data, o); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | if (curr == 2) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 796 | if (o->off5 && o->off6) { |
| 797 | val_store(ilp, ul1, o->off5, 0, data, o); |
| 798 | val_store(ilp, ul2, o->off6, 0, data, o); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | if (!more) { |
| 802 | if (curr < 1) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 803 | if (o->off3 && o->off4) { |
| 804 | val_store(ilp, ul1, o->off3, 0, data, o); |
| 805 | val_store(ilp, ul2, o->off4, 0, data, o); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | if (curr < 2) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 809 | if (o->off5 && o->off6) { |
| 810 | val_store(ilp, ul1, o->off5, 0, data, o); |
| 811 | val_store(ilp, ul2, o->off6, 0, data, o); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 812 | } |
| 813 | } |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 817 | break; |
| 818 | } |
Jens Axboe | 74ba180 | 2011-07-15 09:09:15 +0200 | [diff] [blame] | 819 | case FIO_OPT_BOOL: |
| 820 | case FIO_OPT_STR_SET: { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 821 | fio_opt_int_fn *fn = o->cb; |
| 822 | |
Jens Axboe | 74ba180 | 2011-07-15 09:09:15 +0200 | [diff] [blame] | 823 | if (ptr) |
| 824 | ret = check_int(ptr, &il); |
| 825 | else if (o->type == FIO_OPT_BOOL) |
| 826 | ret = 1; |
| 827 | else |
| 828 | il = 1; |
| 829 | |
Jens Axboe | ae3fcb5 | 2013-04-25 10:06:32 -0600 | [diff] [blame] | 830 | dprint(FD_PARSE, " ret=%d, out=%d\n", ret, il); |
| 831 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 832 | if (ret) |
| 833 | break; |
| 834 | |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 835 | if (o->maxval && il > (int) o->maxval) { |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 836 | log_err("max value out of range: %d (%d max)\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 837 | il, o->maxval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 838 | return 1; |
| 839 | } |
| 840 | if (o->minval && il < o->minval) { |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 841 | log_err("min value out of range: %d (%d min)\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 842 | il, o->minval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 843 | return 1; |
| 844 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 845 | |
Jens Axboe | 76a43db | 2007-01-11 13:24:44 +0100 | [diff] [blame] | 846 | if (o->neg) |
| 847 | il = !il; |
| 848 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 849 | if (fn) |
| 850 | ret = fn(data, &il); |
| 851 | else { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 852 | if (first) |
| 853 | val_store(ilp, il, o->off1, 0, data, o); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 854 | if (!more) { |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 855 | if (o->off2) |
| 856 | val_store(ilp, il, o->off2, 0, data, o); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 857 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 858 | } |
| 859 | break; |
| 860 | } |
Jens Axboe | 15ca150 | 2008-04-07 09:26:02 +0200 | [diff] [blame] | 861 | case FIO_OPT_DEPRECATED: |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 862 | log_info("Option %s is deprecated\n", o->name); |
Jens Axboe | d947227 | 2013-07-25 10:20:45 -0600 | [diff] [blame] | 863 | ret = 1; |
Jens Axboe | 15ca150 | 2008-04-07 09:26:02 +0200 | [diff] [blame] | 864 | break; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 865 | default: |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 866 | log_err("Bad option type %u\n", o->type); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 867 | ret = 1; |
| 868 | } |
| 869 | |
Jens Axboe | 70a4c0c | 2009-07-01 09:24:05 +0200 | [diff] [blame] | 870 | if (ret) |
| 871 | return ret; |
| 872 | |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 873 | if (o->verify) { |
Jens Axboe | 70a4c0c | 2009-07-01 09:24:05 +0200 | [diff] [blame] | 874 | ret = o->verify(o, data); |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 875 | if (ret) { |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 876 | log_err("Correct format for offending option\n"); |
| 877 | log_err("%20s: %s\n", o->name, o->help); |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 878 | show_option_help(o, 1); |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 879 | } |
| 880 | } |
Jens Axboe | 70a4c0c | 2009-07-01 09:24:05 +0200 | [diff] [blame] | 881 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 882 | return ret; |
| 883 | } |
| 884 | |
Jens Axboe | 7c8f1a5 | 2009-06-09 12:28:57 +0200 | [diff] [blame] | 885 | static int handle_option(struct fio_option *o, const char *__ptr, void *data) |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 886 | { |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 887 | char *o_ptr, *ptr, *ptr2; |
| 888 | int ret, done; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 889 | |
Jens Axboe | 7c8f1a5 | 2009-06-09 12:28:57 +0200 | [diff] [blame] | 890 | dprint(FD_PARSE, "handle_option=%s, ptr=%s\n", o->name, __ptr); |
| 891 | |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 892 | o_ptr = ptr = NULL; |
Jens Axboe | 7c8f1a5 | 2009-06-09 12:28:57 +0200 | [diff] [blame] | 893 | if (__ptr) |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 894 | o_ptr = ptr = strdup(__ptr); |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 895 | |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 896 | /* |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 897 | * See if we have another set of parameters, hidden after a comma. |
| 898 | * Do this before parsing this round, to check if we should |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 899 | * copy set 1 options to set 2. |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 900 | */ |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 901 | done = 0; |
| 902 | ret = 1; |
| 903 | do { |
| 904 | int __ret; |
| 905 | |
| 906 | ptr2 = NULL; |
| 907 | if (ptr && |
| 908 | (o->type != FIO_OPT_STR_STORE) && |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 909 | (o->type != FIO_OPT_STR) && |
| 910 | (o->type != FIO_OPT_FLOAT_LIST)) { |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 911 | ptr2 = strchr(ptr, ','); |
| 912 | if (ptr2 && *(ptr2 + 1) == '\0') |
| 913 | *ptr2 = '\0'; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 914 | if (o->type != FIO_OPT_STR_MULTI && o->type != FIO_OPT_RANGE) { |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 915 | if (!ptr2) |
| 916 | ptr2 = strchr(ptr, ':'); |
| 917 | if (!ptr2) |
| 918 | ptr2 = strchr(ptr, '-'); |
| 919 | } |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 920 | } else if (ptr && o->type == FIO_OPT_FLOAT_LIST) { |
| 921 | ptr2 = strchr(ptr, ':'); |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | /* |
| 925 | * Don't return early if parsing the first option fails - if |
| 926 | * we are doing multiple arguments, we can allow the first one |
| 927 | * being empty. |
| 928 | */ |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 929 | __ret = __handle_option(o, ptr, data, !done, !!ptr2, done); |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 930 | if (ret) |
| 931 | ret = __ret; |
| 932 | |
Jens Axboe | 0c9baf9 | 2007-01-11 15:59:26 +0100 | [diff] [blame] | 933 | if (!ptr2) |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 934 | break; |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 935 | |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 936 | ptr = ptr2 + 1; |
| 937 | done++; |
| 938 | } while (1); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 939 | |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 940 | if (o_ptr) |
| 941 | free(o_ptr); |
| 942 | return ret; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 943 | } |
| 944 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 945 | static struct fio_option *get_option(char *opt, |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 946 | struct fio_option *options, char **post) |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 947 | { |
| 948 | struct fio_option *o; |
| 949 | char *ret; |
| 950 | |
| 951 | ret = strchr(opt, '='); |
| 952 | if (ret) { |
| 953 | *post = ret; |
| 954 | *ret = '\0'; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 955 | ret = opt; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 956 | (*post)++; |
Jens Axboe | 43c129b | 2008-12-08 14:06:42 +0100 | [diff] [blame] | 957 | strip_blank_end(ret); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 958 | o = find_option(options, ret); |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 959 | } else { |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 960 | o = find_option(options, opt); |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 961 | *post = NULL; |
| 962 | } |
| 963 | |
| 964 | return o; |
| 965 | } |
| 966 | |
| 967 | static int opt_cmp(const void *p1, const void *p2) |
| 968 | { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 969 | struct fio_option *o; |
| 970 | char *s, *foo; |
Jens Axboe | 8cdabc1 | 2008-11-19 12:31:43 +0100 | [diff] [blame] | 971 | int prio1, prio2; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 972 | |
Jens Axboe | 8cdabc1 | 2008-11-19 12:31:43 +0100 | [diff] [blame] | 973 | prio1 = prio2 = 0; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 974 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 975 | if (*(char **)p1) { |
| 976 | s = strdup(*((char **) p1)); |
Jens Axboe | 9af4a24 | 2012-03-16 10:13:49 +0100 | [diff] [blame] | 977 | o = get_option(s, __fio_options, &foo); |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 978 | if (o) |
| 979 | prio1 = o->prio; |
| 980 | free(s); |
| 981 | } |
| 982 | if (*(char **)p2) { |
| 983 | s = strdup(*((char **) p2)); |
Jens Axboe | 9af4a24 | 2012-03-16 10:13:49 +0100 | [diff] [blame] | 984 | o = get_option(s, __fio_options, &foo); |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 985 | if (o) |
| 986 | prio2 = o->prio; |
| 987 | free(s); |
| 988 | } |
| 989 | |
Jens Axboe | 8cdabc1 | 2008-11-19 12:31:43 +0100 | [diff] [blame] | 990 | return prio2 - prio1; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | void sort_options(char **opts, struct fio_option *options, int num_opts) |
| 994 | { |
Jens Axboe | 9af4a24 | 2012-03-16 10:13:49 +0100 | [diff] [blame] | 995 | __fio_options = options; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 996 | qsort(opts, num_opts, sizeof(char *), opt_cmp); |
Jens Axboe | 9af4a24 | 2012-03-16 10:13:49 +0100 | [diff] [blame] | 997 | __fio_options = NULL; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 998 | } |
| 999 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1000 | int parse_cmd_option(const char *opt, const char *val, |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 1001 | struct fio_option *options, void *data) |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1002 | { |
| 1003 | struct fio_option *o; |
| 1004 | |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 1005 | o = find_option(options, opt); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1006 | if (!o) { |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 1007 | log_err("Bad option <%s>\n", opt); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1008 | return 1; |
| 1009 | } |
| 1010 | |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 1011 | if (!handle_option(o, val, data)) |
| 1012 | return 0; |
| 1013 | |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 1014 | log_err("fio: failed parsing %s=%s\n", opt, val); |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 1015 | return 1; |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1016 | } |
| 1017 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1018 | int parse_option(char *opt, const char *input, |
Jens Axboe | 292cc47 | 2013-11-26 20:39:35 -0700 | [diff] [blame] | 1019 | struct fio_option *options, struct fio_option **o, void *data, |
| 1020 | int dump_cmdline) |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1021 | { |
Steven Lang | d0c814e | 2011-10-28 08:37:13 +0200 | [diff] [blame] | 1022 | char *post; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1023 | |
Steven Lang | d0c814e | 2011-10-28 08:37:13 +0200 | [diff] [blame] | 1024 | if (!opt) { |
| 1025 | log_err("fio: failed parsing %s\n", input); |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1026 | *o = NULL; |
Jens Axboe | 38789b5 | 2010-03-03 09:23:20 +0100 | [diff] [blame] | 1027 | return 1; |
Steven Lang | d0c814e | 2011-10-28 08:37:13 +0200 | [diff] [blame] | 1028 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1029 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1030 | *o = get_option(opt, options, &post); |
| 1031 | if (!*o) { |
| 1032 | if (post) { |
| 1033 | int len = strlen(opt); |
| 1034 | if (opt + len + 1 != post) |
| 1035 | memmove(opt + len + 1, post, strlen(post)); |
| 1036 | opt[len] = '='; |
| 1037 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1038 | return 1; |
| 1039 | } |
| 1040 | |
Jens Axboe | 292cc47 | 2013-11-26 20:39:35 -0700 | [diff] [blame] | 1041 | if (handle_option(*o, post, data)) { |
| 1042 | log_err("fio: failed parsing %s\n", input); |
| 1043 | return 1; |
| 1044 | } |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 1045 | |
Jens Axboe | 292cc47 | 2013-11-26 20:39:35 -0700 | [diff] [blame] | 1046 | if (dump_cmdline) { |
| 1047 | const char *delim; |
| 1048 | |
| 1049 | if (!strcmp("description", (*o)->name)) |
| 1050 | delim = "\""; |
| 1051 | else |
| 1052 | delim = ""; |
| 1053 | |
| 1054 | log_info("--%s%s", (*o)->name, post ? "" : " "); |
| 1055 | if (post) |
| 1056 | log_info("=%s%s%s ", delim, post, delim); |
| 1057 | } |
| 1058 | |
| 1059 | return 0; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1060 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 1061 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 1062 | /* |
| 1063 | * Option match, levenshtein distance. Handy for not quite remembering what |
| 1064 | * the option name is. |
| 1065 | */ |
| 1066 | static int string_distance(const char *s1, const char *s2) |
| 1067 | { |
| 1068 | unsigned int s1_len = strlen(s1); |
| 1069 | unsigned int s2_len = strlen(s2); |
| 1070 | unsigned int *p, *q, *r; |
| 1071 | unsigned int i, j; |
| 1072 | |
| 1073 | p = malloc(sizeof(unsigned int) * (s2_len + 1)); |
| 1074 | q = malloc(sizeof(unsigned int) * (s2_len + 1)); |
| 1075 | |
| 1076 | p[0] = 0; |
| 1077 | for (i = 1; i <= s2_len; i++) |
| 1078 | p[i] = p[i - 1] + 1; |
| 1079 | |
| 1080 | for (i = 1; i <= s1_len; i++) { |
| 1081 | q[0] = p[0] + 1; |
| 1082 | for (j = 1; j <= s2_len; j++) { |
| 1083 | unsigned int sub = p[j - 1]; |
| 1084 | |
| 1085 | if (s1[i - 1] != s2[j - 1]) |
| 1086 | sub++; |
| 1087 | |
| 1088 | q[j] = min(p[j] + 1, min(q[j - 1] + 1, sub)); |
| 1089 | } |
| 1090 | r = p; |
| 1091 | p = q; |
| 1092 | q = r; |
| 1093 | } |
| 1094 | |
| 1095 | i = p[s2_len]; |
| 1096 | free(p); |
| 1097 | free(q); |
| 1098 | return i; |
| 1099 | } |
| 1100 | |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 1101 | static struct fio_option *find_child(struct fio_option *options, |
| 1102 | struct fio_option *o) |
| 1103 | { |
| 1104 | struct fio_option *__o; |
| 1105 | |
Jens Axboe | fdf2874 | 2007-07-31 23:06:09 +0200 | [diff] [blame] | 1106 | for (__o = options + 1; __o->name; __o++) |
| 1107 | if (__o->parent && !strcmp(__o->parent, o->name)) |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 1108 | return __o; |
| 1109 | |
| 1110 | return NULL; |
| 1111 | } |
| 1112 | |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 1113 | static void __print_option(struct fio_option *o, struct fio_option *org, |
| 1114 | int level) |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 1115 | { |
| 1116 | char name[256], *p; |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 1117 | int depth; |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 1118 | |
| 1119 | if (!o) |
| 1120 | return; |
Jens Axboe | ef9aff5 | 2007-07-31 22:56:53 +0200 | [diff] [blame] | 1121 | if (!org) |
| 1122 | org = o; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1123 | |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 1124 | p = name; |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 1125 | depth = level; |
| 1126 | while (depth--) |
| 1127 | p += sprintf(p, "%s", " "); |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 1128 | |
| 1129 | sprintf(p, "%s", o->name); |
| 1130 | |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 1131 | log_info("%-24s: %s\n", name, o->help); |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | static void print_option(struct fio_option *o) |
| 1135 | { |
| 1136 | struct fio_option *parent; |
| 1137 | struct fio_option *__o; |
| 1138 | unsigned int printed; |
| 1139 | unsigned int level; |
| 1140 | |
| 1141 | __print_option(o, NULL, 0); |
| 1142 | parent = o; |
| 1143 | level = 0; |
| 1144 | do { |
| 1145 | level++; |
| 1146 | printed = 0; |
| 1147 | |
| 1148 | while ((__o = find_child(o, parent)) != NULL) { |
| 1149 | __print_option(__o, o, level); |
| 1150 | o = __o; |
| 1151 | printed++; |
| 1152 | } |
| 1153 | |
| 1154 | parent = o; |
| 1155 | } while (printed); |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 1156 | } |
| 1157 | |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 1158 | int show_cmd_help(struct fio_option *options, const char *name) |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 1159 | { |
| 1160 | struct fio_option *o, *closest; |
Jens Axboe | d091d09 | 2010-04-01 19:56:23 +0200 | [diff] [blame] | 1161 | unsigned int best_dist = -1U; |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 1162 | int found = 0; |
Jens Axboe | 320beef | 2007-03-01 10:44:12 +0100 | [diff] [blame] | 1163 | int show_all = 0; |
| 1164 | |
| 1165 | if (!name || !strcmp(name, "all")) |
| 1166 | show_all = 1; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 1167 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 1168 | closest = NULL; |
| 1169 | best_dist = -1; |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 1170 | for (o = &options[0]; o->name; o++) { |
Jens Axboe | 320beef | 2007-03-01 10:44:12 +0100 | [diff] [blame] | 1171 | int match = 0; |
| 1172 | |
Jens Axboe | 15ca150 | 2008-04-07 09:26:02 +0200 | [diff] [blame] | 1173 | if (o->type == FIO_OPT_DEPRECATED) |
| 1174 | continue; |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 1175 | if (!exec_profile && o->prof_name) |
| 1176 | continue; |
Jens Axboe | 4ac23d2 | 2013-05-23 21:14:03 +0200 | [diff] [blame] | 1177 | if (exec_profile && !(o->prof_name && !strcmp(exec_profile, o->prof_name))) |
| 1178 | continue; |
Jens Axboe | 15ca150 | 2008-04-07 09:26:02 +0200 | [diff] [blame] | 1179 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 1180 | if (name) { |
Jens Axboe | 7f9348f | 2007-03-15 14:09:28 +0100 | [diff] [blame] | 1181 | if (!strcmp(name, o->name) || |
| 1182 | (o->alias && !strcmp(name, o->alias))) |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 1183 | match = 1; |
| 1184 | else { |
| 1185 | unsigned int dist; |
| 1186 | |
| 1187 | dist = string_distance(name, o->name); |
| 1188 | if (dist < best_dist) { |
| 1189 | best_dist = dist; |
| 1190 | closest = o; |
| 1191 | } |
| 1192 | } |
| 1193 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 1194 | |
| 1195 | if (show_all || match) { |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 1196 | found = 1; |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 1197 | if (match) |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 1198 | log_info("%20s: %s\n", o->name, o->help); |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 1199 | if (show_all) { |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 1200 | if (!o->parent) |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 1201 | print_option(o); |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 1202 | continue; |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 1203 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 1204 | } |
| 1205 | |
Jens Axboe | 70df2f1 | 2007-01-11 14:04:47 +0100 | [diff] [blame] | 1206 | if (!match) |
| 1207 | continue; |
| 1208 | |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 1209 | show_option_help(o, 0); |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 1210 | } |
| 1211 | |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 1212 | if (found) |
| 1213 | return 0; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 1214 | |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 1215 | log_err("No such command: %s", name); |
Jens Axboe | d091d09 | 2010-04-01 19:56:23 +0200 | [diff] [blame] | 1216 | |
| 1217 | /* |
| 1218 | * Only print an appropriately close option, one where the edit |
| 1219 | * distance isn't too big. Otherwise we get crazy matches. |
| 1220 | */ |
| 1221 | if (closest && best_dist < 3) { |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 1222 | log_info(" - showing closest match\n"); |
| 1223 | log_info("%20s: %s\n", closest->name, closest->help); |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 1224 | show_option_help(closest, 0); |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 1225 | } else |
Jens Axboe | 28d7c36 | 2011-10-05 20:30:24 +0200 | [diff] [blame] | 1226 | log_info("\n"); |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 1227 | |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 1228 | return 1; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 1229 | } |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1230 | |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 1231 | /* |
| 1232 | * Handle parsing of default parameters. |
| 1233 | */ |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1234 | void fill_default_options(void *data, struct fio_option *options) |
| 1235 | { |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 1236 | struct fio_option *o; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1237 | |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 1238 | dprint(FD_PARSE, "filling default options\n"); |
| 1239 | |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 1240 | for (o = &options[0]; o->name; o++) |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1241 | if (o->def) |
| 1242 | handle_option(o, o->def, data); |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1243 | } |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 1244 | |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 1245 | void option_init(struct fio_option *o) |
| 1246 | { |
| 1247 | if (o->type == FIO_OPT_DEPRECATED) |
| 1248 | return; |
| 1249 | if (o->type == FIO_OPT_BOOL) { |
| 1250 | o->minval = 0; |
| 1251 | o->maxval = 1; |
| 1252 | } |
Jens Axboe | d4fc2f0 | 2012-09-24 14:32:26 +0200 | [diff] [blame] | 1253 | if (o->type == FIO_OPT_INT) { |
| 1254 | if (!o->maxval) |
| 1255 | o->maxval = UINT_MAX; |
| 1256 | } |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 1257 | if (o->type == FIO_OPT_FLOAT_LIST) { |
Bruce Cran | ab9461e | 2013-02-02 14:31:24 +0000 | [diff] [blame] | 1258 | o->minfp = DBL_MIN; |
| 1259 | o->maxfp = DBL_MAX; |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 1260 | } |
Jens Axboe | ef7035a | 2014-06-18 15:30:09 -0700 | [diff] [blame] | 1261 | if (o->type == FIO_OPT_STR_SET && o->def && !o->no_warn_def) { |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 1262 | log_err("Option %s: string set option with" |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 1263 | " default will always be true\n", o->name); |
| 1264 | } |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 1265 | if (!o->cb && !o->off1) |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 1266 | log_err("Option %s: neither cb nor offset given\n", o->name); |
Jens Axboe | 2275474 | 2013-04-10 13:05:23 +0200 | [diff] [blame] | 1267 | if (!o->category) { |
Jens Axboe | cca5b5b | 2013-04-10 19:35:25 +0200 | [diff] [blame] | 1268 | log_info("Option %s: no category defined. Setting to misc\n", o->name); |
Jens Axboe | 2275474 | 2013-04-10 13:05:23 +0200 | [diff] [blame] | 1269 | o->category = FIO_OPT_C_GENERAL; |
Jens Axboe | ffd7821 | 2013-04-10 13:07:43 +0200 | [diff] [blame] | 1270 | o->group = FIO_OPT_G_INVALID; |
Jens Axboe | 2275474 | 2013-04-10 13:05:23 +0200 | [diff] [blame] | 1271 | } |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 1272 | if (o->type == FIO_OPT_STR || o->type == FIO_OPT_STR_STORE || |
| 1273 | o->type == FIO_OPT_STR_MULTI) |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 1274 | return; |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 1275 | if (o->cb && (o->off1 || o->off2 || o->off3 || o->off4)) |
Jens Axboe | 06b0be6 | 2011-10-04 10:31:10 +0200 | [diff] [blame] | 1276 | log_err("Option %s: both cb and offset given\n", o->name); |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 1277 | } |
| 1278 | |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 1279 | /* |
| 1280 | * Sanitize the options structure. For now it just sets min/max for bool |
Jens Axboe | 5b0a888 | 2007-01-11 14:40:27 +0100 | [diff] [blame] | 1281 | * values and whether both callback and offsets are given. |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 1282 | */ |
| 1283 | void options_init(struct fio_option *options) |
| 1284 | { |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 1285 | struct fio_option *o; |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 1286 | |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 1287 | dprint(FD_PARSE, "init options\n"); |
| 1288 | |
Jens Axboe | 9026535 | 2012-03-19 20:29:44 +0100 | [diff] [blame] | 1289 | for (o = &options[0]; o->name; o++) { |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 1290 | option_init(o); |
Jens Axboe | 9026535 | 2012-03-19 20:29:44 +0100 | [diff] [blame] | 1291 | if (o->inverse) |
| 1292 | o->inv_opt = find_option(options, o->inverse); |
| 1293 | } |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 1294 | } |
Jens Axboe | 7e356b2 | 2011-10-14 10:55:16 +0200 | [diff] [blame] | 1295 | |
| 1296 | void options_free(struct fio_option *options, void *data) |
| 1297 | { |
| 1298 | struct fio_option *o; |
| 1299 | char **ptr; |
| 1300 | |
| 1301 | dprint(FD_PARSE, "free options\n"); |
| 1302 | |
| 1303 | for (o = &options[0]; o->name; o++) { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1304 | if (o->type != FIO_OPT_STR_STORE || !o->off1) |
Jens Axboe | 7e356b2 | 2011-10-14 10:55:16 +0200 | [diff] [blame] | 1305 | continue; |
| 1306 | |
Jens Axboe | f0fdbca | 2014-02-11 15:44:50 -0700 | [diff] [blame] | 1307 | ptr = td_var(data, o, o->off1); |
Jens Axboe | 7e356b2 | 2011-10-14 10:55:16 +0200 | [diff] [blame] | 1308 | if (*ptr) { |
| 1309 | free(*ptr); |
| 1310 | *ptr = NULL; |
| 1311 | } |
| 1312 | } |
| 1313 | } |