2 * This file contains the ini and command liner parser main.
12 #include "compiler/compiler.h"
19 #include "lib/ieee754.h"
22 #ifdef CONFIG_ARITHMETIC
26 static const char *opt_type_names[] = {
42 "OPT_SOFT_DEPRECATED",
46 static const struct fio_option *__fio_options;
48 static int vp_cmp(const void *p1, const void *p2)
50 const struct value_pair *vp1 = p1;
51 const struct value_pair *vp2 = p2;
53 return strlen(vp2->ival) - strlen(vp1->ival);
56 static void posval_sort(const struct fio_option *o, struct value_pair *vpmap)
58 const struct value_pair *vp;
61 memset(vpmap, 0, PARSE_MAX_VP * sizeof(struct value_pair));
63 for (entries = 0; entries < PARSE_MAX_VP; entries++) {
64 vp = &o->posval[entries];
65 if (!vp->ival || vp->ival[0] == '\0')
68 memcpy(&vpmap[entries], vp, sizeof(*vp));
71 qsort(vpmap, entries, sizeof(struct value_pair), vp_cmp);
74 static void show_option_range(const struct fio_option *o,
75 ssize_t (*logger)(const char *format, ...))
77 if (o->type == FIO_OPT_FLOAT_LIST) {
79 if (!o->minfp && !o->maxfp)
82 logger("%20s: ", "range");
83 if (o->minfp != DBL_MIN) {
84 logger("min=%f", o->minfp);
87 if (o->maxfp != DBL_MAX)
88 logger("%smax=%f", sep, o->maxfp);
90 } else if (!o->posval[0].ival) {
91 if (!o->minval && !o->maxval)
94 logger("%20s: min=%d", "range", o->minval);
96 logger(", max=%d", o->maxval);
101 static void show_option_values(const struct fio_option *o)
105 for (i = 0; i < PARSE_MAX_VP; i++) {
106 const struct value_pair *vp = &o->posval[i];
111 log_info("%20s: %-10s", i == 0 ? "valid values" : "", vp->ival);
113 log_info(" %s", vp->help);
121 static void show_option_help(const struct fio_option *o, int is_err)
123 const char *typehelp[] = {
124 [FIO_OPT_INVALID] = "invalid",
125 [FIO_OPT_STR] = "string (opt=bla)",
126 [FIO_OPT_STR_ULL] = "string (opt=bla)",
127 [FIO_OPT_STR_MULTI] = "string with possible k/m/g postfix (opt=4k)",
128 [FIO_OPT_STR_VAL] = "string (opt=bla)",
129 [FIO_OPT_STR_VAL_TIME] = "string with time postfix (opt=10s)",
130 [FIO_OPT_STR_STORE] = "string (opt=bla)",
131 [FIO_OPT_RANGE] = "one to three ranges (opt=1k-4k[,4k-8k[,1k-8k]])",
132 [FIO_OPT_INT] = "integer value (opt=100)",
133 [FIO_OPT_ULL] = "integer value (opt=100)",
134 [FIO_OPT_BOOL] = "boolean value (opt=1)",
135 [FIO_OPT_FLOAT_LIST] = "list of floating point values separated by ':' (opt=5.9:7.8)",
136 [FIO_OPT_STR_SET] = "empty or boolean value ([0|1])",
137 [FIO_OPT_DEPRECATED] = "deprecated",
138 [FIO_OPT_SOFT_DEPRECATED] = "deprecated",
139 [FIO_OPT_UNSUPPORTED] = "unsupported",
141 ssize_t (*logger)(const char *format, ...);
149 logger("%20s: %s\n", "alias", o->alias);
151 logger("%20s: %s\n", "type", typehelp[o->type]);
152 logger("%20s: %s\n", "default", o->def ? o->def : "no default");
154 logger("%20s: only for profile '%s'\n", "valid", o->prof_name);
155 show_option_range(o, logger);
156 show_option_values(o);
159 static unsigned long long get_mult_time(const char *str, int len,
164 unsigned long long mult = 1;
168 * Go forward until we hit a non-digit, or +/- sign
170 while ((p - str) <= len) {
171 if (!isdigit((int) *p) && (*p != '+') && (*p != '-'))
176 if (!isalpha((int) *p)) {
184 for (i = 0; i < strlen(c); i++)
185 c[i] = tolower((unsigned char)c[i]);
187 if (!strncmp("us", c, 2) || !strncmp("usec", c, 4))
189 else if (!strncmp("ms", c, 2) || !strncmp("msec", c, 4))
191 else if (!strcmp("s", c))
193 else if (!strcmp("m", c))
194 mult = 60 * 1000000UL;
195 else if (!strcmp("h", c))
196 mult = 60 * 60 * 1000000UL;
197 else if (!strcmp("d", c))
198 mult = 24 * 60 * 60 * 1000000ULL;
204 static int is_separator(char c)
217 static unsigned long long __get_mult_bytes(const char *p, void *data,
220 unsigned int kb_base = fio_get_kb_base(data);
221 unsigned long long ret = 1;
222 unsigned int i, pow = 0, mult = kb_base;
230 for (i = 0; i < strlen(c); i++) {
231 c[i] = tolower((unsigned char)c[i]);
232 if (is_separator(c[i])) {
238 /* If kb_base is 1000, use true units.
239 * If kb_base is 1024, use opposite units.
241 if (!strncmp("pib", c, 3)) {
245 else if (kb_base == 1024)
247 } else if (!strncmp("tib", c, 3)) {
251 else if (kb_base == 1024)
253 } else if (!strncmp("gib", c, 3)) {
257 else if (kb_base == 1024)
259 } else if (!strncmp("mib", c, 3)) {
263 else if (kb_base == 1024)
265 } else if (!strncmp("kib", c, 3)) {
269 else if (kb_base == 1024)
271 } else if (!strncmp("p", c, 1) || !strncmp("pb", c, 2)) {
273 } else if (!strncmp("t", c, 1) || !strncmp("tb", c, 2)) {
275 } else if (!strncmp("g", c, 1) || !strncmp("gb", c, 2)) {
277 } else if (!strncmp("m", c, 1) || !strncmp("mb", c, 2)) {
279 } else if (!strncmp("k", c, 1) || !strncmp("kb", c, 2)) {
281 } else if (!strncmp("%", c, 1)) {
288 ret *= (unsigned long long) mult;
294 static unsigned long long get_mult_bytes(const char *str, int len, void *data,
301 return __get_mult_bytes(str, data, percent);
304 * Go forward until we hit a non-digit, or +/- sign
306 while ((p - str) <= len) {
307 if (!isdigit((int) *p) &&
308 (((*p != '+') && (*p != '-')) || digit_seen))
310 digit_seen |= isdigit((int) *p);
314 if (!isalpha((int) *p) && (*p != '%'))
317 return __get_mult_bytes(p, data, percent);
320 extern int evaluate_arithmetic_expression(const char *buffer, long long *ival,
321 double *dval, double implied_units,
325 * Convert string into a floating number. Return 1 for success and 0 otherwise.
327 int str_to_float(const char *str, double *val, int is_time)
329 #ifdef CONFIG_ARITHMETIC
335 rc = evaluate_arithmetic_expression(str, &ival, &dval, 1.0, is_time);
342 return 1 == sscanf(str, "%lf", val);
346 * convert string into decimal value, noting any size suffix
348 int str_to_decimal(const char *str, long long *val, int kilo, void *data,
349 int is_seconds, int is_time)
353 #ifdef CONFIG_ARITHMETIC
356 double implied_units = 1.0;
363 #ifdef CONFIG_ARITHMETIC
365 implied_units = 1000000.0;
367 rc = evaluate_arithmetic_expression(str, &ival, &dval, implied_units, is_time);
368 if (str[0] == '(' && !rc) {
369 if (!kilo && is_seconds)
370 *val = ival / 1000000LL;
379 if (strstr(str, "0x") || strstr(str, "0X"))
384 *val = strtoll(str, &endptr, base);
385 if (*val == 0 && endptr == str)
387 if (*val == LONG_MAX && errno == ERANGE)
392 unsigned long long mult;
395 mult = get_mult_bytes(str, len, data, &perc);
401 *val *= get_mult_time(str, len, is_seconds);
406 int check_str_bytes(const char *p, long long *val, void *data)
408 return str_to_decimal(p, val, 1, data, 0, 0);
411 int check_str_time(const char *p, long long *val, int is_seconds)
413 return str_to_decimal(p, val, 0, NULL, is_seconds, 1);
416 void strip_blank_front(char **p)
422 while (isspace((int) *s))
428 void strip_blank_end(char *p)
445 while ((isspace((int) *s) || iscntrl((int) *s)) && (s > start))
451 static int check_range_bytes(const char *str, long long *val, void *data)
455 if (!str_to_decimal(str, &__val, 1, data, 0, 0)) {
463 static int check_int(const char *p, int *val)
467 if (strstr(p, "0x") || strstr(p, "0X")) {
468 if (sscanf(p, "%x", val) == 1)
471 if (sscanf(p, "%u", val) == 1)
478 static size_t opt_len(const char *str)
480 char delimiter[] = {',', ':'};
483 size_t candidate_len;
485 size_t prefix_len = strlen(str);
486 for (i = 0; i < FIO_ARRAY_SIZE(delimiter); i++) {
487 postfix = strchr(str, delimiter[i]);
488 candidate_len = (size_t)(postfix - str);
489 if (postfix && candidate_len < prefix_len)
490 prefix_len = candidate_len;
496 static int str_match_len(const struct value_pair *vp, const char *str)
498 return max(strlen(vp->ival), opt_len(str));
501 #define val_store(ptr, val, off, or, data, o) \
503 ptr = td_var((data), (o), (off)); \
510 static const char *opt_type_name(const struct fio_option *o)
512 compiletime_assert(FIO_ARRAY_SIZE(opt_type_names) - 1 == FIO_OPT_UNSUPPORTED,
513 "opt_type_names[] index");
515 if (o->type <= FIO_OPT_UNSUPPORTED)
516 return opt_type_names[o->type];
518 return "OPT_UNKNOWN?";
521 static bool val_too_large(const struct fio_option *o, unsigned long long val,
529 return (int) val > (int) o->maxval;
530 return (unsigned int) val > o->maxval;
533 return val > o->maxval;
536 static bool val_too_small(const struct fio_option *o, unsigned long long val,
543 return (int) val < o->minval;
545 return val < o->minval;
548 static int __handle_option(const struct fio_option *o, const char *ptr,
549 void *data, int first, int more, int curr)
553 long long ull, *ullp;
555 long long ull1, ull2;
558 int ret = 0, is_time = 0;
559 const struct value_pair *vp;
560 struct value_pair posval[PARSE_MAX_VP];
561 int i, all_skipped = 1;
563 dprint(FD_PARSE, "__handle_option=%s, type=%s, ptr=%s\n", o->name,
564 opt_type_name(o), ptr);
566 if (!ptr && o->type != FIO_OPT_STR_SET && o->type != FIO_OPT_STR) {
567 log_err("Option %s requires an argument\n", o->name);
573 case FIO_OPT_STR_ULL:
574 case FIO_OPT_STR_MULTI: {
575 fio_opt_str_fn *fn = o->cb;
577 posval_sort(o, posval);
580 for (i = 0; i < PARSE_MAX_VP; i++) {
582 if (!vp->ival || vp->ival[0] == '\0')
587 if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) {
591 if (o->type == FIO_OPT_STR_ULL)
592 val_store(ullp, vp->oval, o->off1, vp->orval, data, o);
594 val_store(ilp, vp->oval, o->off1, vp->orval, data, o);
599 if (ret && !all_skipped)
600 show_option_values(o);
605 case FIO_OPT_STR_VAL_TIME:
610 case FIO_OPT_STR_VAL:
611 case FIO_OPT_STR_VAL_ZONE:
613 fio_opt_str_val_fn *fn = o->cb;
615 size_t len = strlen(ptr);
617 if (len > 0 && ptr[len - 1] == 'z') {
618 if (o->type == FIO_OPT_STR_VAL_ZONE) {
620 unsigned long long val;
623 val = strtoul(ptr, &ep, 10);
624 if (errno == 0 && ep != ptr && *ep == 'z') {
625 ull = ZONE_BASE_VAL + (uint32_t)val;
627 goto store_option_value;
629 log_err("%s: unexpected zone value '%s'\n",
634 log_err("%s: 'z' suffix isn't applicable\n",
640 if (!is_time && o->is_time)
641 is_time = o->is_time;
643 snprintf(tmp, sizeof(tmp), "%s", ptr);
644 p = strchr(tmp, ',');
649 ret = check_str_time(tmp, &ull, o->is_seconds);
651 ret = check_str_bytes(tmp, &ull, data);
653 dprint(FD_PARSE, " ret=%d, out=%llu\n", ret, ull);
657 if (o->pow2 && !is_power_of_2(ull)) {
658 log_err("%s: must be a power-of-2\n", o->name);
662 if (val_too_large(o, ull, o->type == FIO_OPT_INT)) {
663 log_err("%s: max value out of range: %llu"
664 " (%llu max)\n", o->name, ull, o->maxval);
667 if (val_too_small(o, ull, o->type == FIO_OPT_INT)) {
668 log_err("%s: min value out of range: %lld"
669 " (%d min)\n", o->name, ull, o->minval);
672 if (o->posval[0].ival) {
673 posval_sort(o, posval);
676 for (i = 0; i < PARSE_MAX_VP; i++) {
678 if (!vp->ival || vp->ival[0] == '\0')
680 if (vp->oval == ull) {
686 log_err("fio: value %llu not allowed:\n", ull);
687 show_option_values(o);
694 ret = fn(data, &ull);
696 if (o->type == FIO_OPT_INT) {
698 val_store(ilp, ull, o->off1, 0, data, o);
701 val_store(ilp, ull, o->off2, 0, data, o);
705 val_store(ilp, ull, o->off3, 0, data, o);
710 val_store(ilp, ull, o->off2, 0, data, o);
714 val_store(ilp, ull, o->off3, 0, data, o);
717 } else if (o->type == FIO_OPT_ULL) {
719 val_store(ullp, ull, o->off1, 0, data, o);
722 val_store(ullp, ull, o->off2, 0, data, o);
726 val_store(ullp, ull, o->off3, 0, data, o);
731 val_store(ullp, ull, o->off2, 0, data, o);
735 val_store(ullp, ull, o->off3, 0, data, o);
740 val_store(ullp, ull, o->off1, 0, data, o);
743 val_store(ullp, ull, o->off2, 0, data, o);
749 case FIO_OPT_FLOAT_LIST: {
754 ** Initialize precision to 0 and zero out list
755 ** in case specified list is shorter than default
759 ilp = td_var(data, o, o->off2);
763 flp = td_var(data, o, o->off1);
764 for(i = 0; i < o->maxlen; i++)
767 if (curr >= o->maxlen) {
768 log_err("the list exceeding max length %d\n",
772 if (!str_to_float(ptr, &uf, 0)) { /* this breaks if we ever have lists of times */
773 log_err("not a floating point value: %s\n", ptr);
776 if (o->minfp || o->maxfp) {
778 log_err("value out of range: %f"
779 " (range max: %f)\n", uf, o->maxfp);
783 log_err("value out of range: %f"
784 " (range min: %f)\n", uf, o->minfp);
789 flp = td_var(data, o, o->off1);
792 dprint(FD_PARSE, " out=%f\n", uf);
795 ** Calculate precision for output by counting
796 ** number of digits after period. Find first
797 ** period in entire remaining list each time
799 cp2 = strchr(ptr, '.');
803 while (*++cp2 != '\0' && *cp2 >= '0' && *cp2 <= '9')
807 ilp = td_var(data, o, o->off2);
815 case FIO_OPT_STR_STORE: {
816 fio_opt_str_fn *fn = o->cb;
822 cp = td_var(data, o, o->off1);
826 if (strlen(ptr) > o->maxlen - 1) {
827 log_err("value exceeds max length of %d\n",
835 else if (o->posval[0].ival) {
836 posval_sort(o, posval);
839 for (i = 0; i < PARSE_MAX_VP; i++) {
841 if (!vp->ival || vp->ival[0] == '\0' || !cp)
844 if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) {
850 rest = strstr(*cp ?: ptr, ":");
864 show_option_values(o);
873 case FIO_OPT_RANGE: {
877 snprintf(tmp, sizeof(tmp), "%s", ptr);
879 /* Handle bsrange with separate read,write values: */
880 p1 = strchr(tmp, ',');
884 p1 = strchr(tmp, '-');
886 p1 = strchr(tmp, ':');
898 if (!check_range_bytes(p1, &ull1, data) &&
899 !check_range_bytes(p2, &ull2, data)) {
902 unsigned long long foo = ull1;
909 val_store(ullp, ull1, o->off1, 0, data, o);
910 val_store(ullp, ull2, o->off2, 0, data, o);
913 if (o->off3 && o->off4) {
914 val_store(ullp, ull1, o->off3, 0, data, o);
915 val_store(ullp, ull2, o->off4, 0, data, o);
919 if (o->off5 && o->off6) {
920 val_store(ullp, ull1, o->off5, 0, data, o);
921 val_store(ullp, ull2, o->off6, 0, data, o);
926 if (o->off3 && o->off4) {
927 val_store(ullp, ull1, o->off3, 0, data, o);
928 val_store(ullp, ull2, o->off4, 0, data, o);
932 if (o->off5 && o->off6) {
933 val_store(ullp, ull1, o->off5, 0, data, o);
934 val_store(ullp, ull2, o->off6, 0, data, o);
943 case FIO_OPT_STR_SET: {
944 fio_opt_int_fn *fn = o->cb;
947 ret = check_int(ptr, &il);
948 else if (o->type == FIO_OPT_BOOL)
953 dprint(FD_PARSE, " ret=%d, out=%d\n", ret, il);
958 if (o->maxval && il > (int) o->maxval) {
959 log_err("max value out of range: %d (%llu max)\n",
963 if (o->minval && il < o->minval) {
964 log_err("min value out of range: %d (%d min)\n",
976 val_store(ilp, il, o->off1, 0, data, o);
979 val_store(ilp, il, o->off2, 0, data, o);
984 case FIO_OPT_DEPRECATED:
987 case FIO_OPT_SOFT_DEPRECATED:
988 log_info("Option %s is deprecated\n", o->name);
991 log_err("Bad option type %u\n", o->type);
999 ret = o->verify(o, data);
1001 log_err("Correct format for offending option\n");
1002 log_err("%20s: %s\n", o->name, o->help);
1003 show_option_help(o, 1);
1010 static int handle_option(const struct fio_option *o, const char *__ptr,
1013 char *o_ptr, *ptr, *ptr2;
1016 dprint(FD_PARSE, "handle_option=%s, ptr=%s\n", o->name, __ptr);
1020 o_ptr = ptr = strdup(__ptr);
1023 * See if we have another set of parameters, hidden after a comma.
1024 * Do this before parsing this round, to check if we should
1025 * copy set 1 options to set 2.
1034 (o->type != FIO_OPT_STR_STORE) &&
1035 (o->type != FIO_OPT_STR) &&
1036 (o->type != FIO_OPT_STR_ULL) &&
1037 (o->type != FIO_OPT_FLOAT_LIST)) {
1038 ptr2 = strchr(ptr, ',');
1039 if (ptr2 && *(ptr2 + 1) == '\0')
1041 if (o->type != FIO_OPT_STR_MULTI && o->type != FIO_OPT_RANGE) {
1043 ptr2 = strchr(ptr, ':');
1045 ptr2 = strchr(ptr, '-');
1047 } else if (ptr && o->type == FIO_OPT_FLOAT_LIST) {
1048 ptr2 = strchr(ptr, ':');
1052 * Don't return early if parsing the first option fails - if
1053 * we are doing multiple arguments, we can allow the first one
1056 __ret = __handle_option(o, ptr, data, !done, !!ptr2, done);
1072 struct fio_option *find_option(struct fio_option *options, const char *opt)
1074 struct fio_option *o;
1076 for (o = &options[0]; o->name; o++) {
1077 if (!o_match(o, opt))
1079 if (o->type == FIO_OPT_UNSUPPORTED) {
1080 log_err("Option <%s>: %s\n", o->name, o->help);
1090 const struct fio_option *
1091 find_option_c(const struct fio_option *options, const char *opt)
1093 const struct fio_option *o;
1095 for (o = &options[0]; o->name; o++) {
1096 if (!o_match(o, opt))
1098 if (o->type == FIO_OPT_UNSUPPORTED) {
1099 log_err("Option <%s>: %s\n", o->name, o->help);
1109 static const struct fio_option *
1110 get_option(char *opt, const struct fio_option *options, char **post)
1112 const struct fio_option *o;
1115 ret = strchr(opt, '=');
1121 strip_blank_end(ret);
1122 o = find_option_c(options, ret);
1124 o = find_option_c(options, opt);
1131 static int opt_cmp(const void *p1, const void *p2)
1133 const struct fio_option *o;
1140 s = strdup(*((char **) p1));
1141 o = get_option(s, __fio_options, &foo);
1147 s = strdup(*((char **) p2));
1148 o = get_option(s, __fio_options, &foo);
1154 return prio2 - prio1;
1157 void sort_options(char **opts, const struct fio_option *options, int num_opts)
1159 __fio_options = options;
1160 qsort(opts, num_opts, sizeof(char *), opt_cmp);
1161 __fio_options = NULL;
1164 static void add_to_dump_list(const struct fio_option *o,
1165 struct flist_head *dump_list, const char *post)
1167 struct print_option *p;
1172 p = malloc(sizeof(*p));
1173 p->name = strdup(o->name);
1175 p->value = strdup(post);
1179 flist_add_tail(&p->list, dump_list);
1182 int parse_cmd_option(const char *opt, const char *val,
1183 const struct fio_option *options, void *data,
1184 struct flist_head *dump_list)
1186 const struct fio_option *o;
1188 o = find_option_c(options, opt);
1190 log_err("Bad option <%s>\n", opt);
1194 if (handle_option(o, val, data)) {
1195 log_err("fio: failed parsing %s=%s\n", opt, val);
1199 add_to_dump_list(o, dump_list, val);
1203 int parse_option(char *opt, const char *input, const struct fio_option *options,
1204 const struct fio_option **o, void *data,
1205 struct flist_head *dump_list)
1210 log_err("fio: failed parsing %s\n", input);
1215 *o = get_option(opt, options, &post);
1218 int len = strlen(opt);
1219 if (opt + len + 1 != post)
1220 memmove(opt + len + 1, post, strlen(post));
1226 if (handle_option(*o, post, data)) {
1227 log_err("fio: failed parsing %s\n", input);
1231 add_to_dump_list(*o, dump_list, post);
1236 * Option match, levenshtein distance. Handy for not quite remembering what
1237 * the option name is.
1239 int string_distance(const char *s1, const char *s2)
1241 unsigned int s1_len = strlen(s1);
1242 unsigned int s2_len = strlen(s2);
1243 unsigned int *p, *q, *r;
1246 p = malloc(sizeof(unsigned int) * (s2_len + 1));
1247 q = malloc(sizeof(unsigned int) * (s2_len + 1));
1250 for (i = 1; i <= s2_len; i++)
1251 p[i] = p[i - 1] + 1;
1253 for (i = 1; i <= s1_len; i++) {
1255 for (j = 1; j <= s2_len; j++) {
1256 unsigned int sub = p[j - 1];
1259 if (s1[i - 1] != s2[j - 1])
1262 pmin = min(q[j - 1] + 1, sub);
1263 q[j] = min(p[j] + 1, pmin);
1277 * Make a guess of whether the distance from 's1' is significant enough
1278 * to warrant printing the guess. We set this to a 1/2 match.
1280 int string_distance_ok(const char *opt, int distance)
1285 len = (len + 1) / 2;
1286 return distance <= len;
1289 static const struct fio_option *find_child(const struct fio_option *options,
1290 const struct fio_option *o)
1292 const struct fio_option *__o;
1294 for (__o = options + 1; __o->name; __o++)
1295 if (__o->parent && !strcmp(__o->parent, o->name))
1301 static void __print_option(const struct fio_option *o,
1302 const struct fio_option *org,
1314 p += sprintf(p, "%s", " ");
1316 sprintf(p, "%s", o->name);
1318 log_info("%-24s: %s\n", name, o->help);
1321 static void print_option(const struct fio_option *o)
1323 const struct fio_option *parent;
1324 const struct fio_option *__o;
1325 unsigned int printed;
1328 __print_option(o, NULL, 0);
1335 while ((__o = find_child(o, parent)) != NULL) {
1336 __print_option(__o, o, level);
1345 int show_cmd_help(const struct fio_option *options, const char *name)
1347 const struct fio_option *o, *closest;
1348 unsigned int best_dist = -1U;
1352 if (!name || !strcmp(name, "all"))
1357 for (o = &options[0]; o->name; o++) {
1360 if (o->type == FIO_OPT_DEPRECATED ||
1361 o->type == FIO_OPT_SOFT_DEPRECATED)
1363 if (!exec_profile && o->prof_name)
1365 if (exec_profile && !(o->prof_name && !strcmp(exec_profile, o->prof_name)))
1369 if (!strcmp(name, o->name) ||
1370 (o->alias && !strcmp(name, o->alias)))
1375 dist = string_distance(name, o->name);
1376 if (dist < best_dist) {
1383 if (show_all || match) {
1386 log_info("%20s: %s\n", o->name, o->help);
1397 show_option_help(o, 0);
1403 log_err("No such command: %s", name);
1406 * Only print an appropriately close option, one where the edit
1407 * distance isn't too big. Otherwise we get crazy matches.
1409 if (closest && best_dist < 3) {
1410 log_info(" - showing closest match\n");
1411 log_info("%20s: %s\n", closest->name, closest->help);
1412 show_option_help(closest, 0);
1420 * Handle parsing of default parameters.
1422 void fill_default_options(void *data, const struct fio_option *options)
1424 const struct fio_option *o;
1426 dprint(FD_PARSE, "filling default options\n");
1428 for (o = &options[0]; o->name; o++)
1430 handle_option(o, o->def, data);
1433 static void option_init(struct fio_option *o)
1435 if (o->type == FIO_OPT_DEPRECATED || o->type == FIO_OPT_UNSUPPORTED ||
1436 o->type == FIO_OPT_SOFT_DEPRECATED)
1438 if (o->name && !o->lname)
1439 log_err("Option %s: missing long option name\n", o->name);
1440 if (o->type == FIO_OPT_BOOL) {
1444 if (o->type == FIO_OPT_INT) {
1446 o->maxval = UINT_MAX;
1448 if (o->type == FIO_OPT_ULL) {
1450 o->maxval = ULLONG_MAX;
1452 if (o->type == FIO_OPT_STR_SET && o->def && !o->no_warn_def) {
1453 log_err("Option %s: string set option with"
1454 " default will always be true\n", o->name);
1456 if (!o->cb && !o->off1)
1457 log_err("Option %s: neither cb nor offset given\n", o->name);
1459 log_info("Option %s: no category defined. Setting to misc\n", o->name);
1460 o->category = FIO_OPT_C_GENERAL;
1461 o->group = FIO_OPT_G_INVALID;
1466 * Sanitize the options structure. For now it just sets min/max for bool
1467 * values and whether both callback and offsets are given.
1469 void options_init(struct fio_option *options)
1471 struct fio_option *o;
1473 dprint(FD_PARSE, "init options\n");
1475 for (o = &options[0]; o->name; o++) {
1478 o->inv_opt = find_option(options, o->inverse);
1482 void options_mem_dupe(const struct fio_option *options, void *data)
1484 const struct fio_option *o;
1487 dprint(FD_PARSE, "dup options\n");
1489 for (o = &options[0]; o->name; o++) {
1490 if (o->type != FIO_OPT_STR_STORE)
1493 ptr = td_var(data, o, o->off1);
1495 *ptr = strdup(*ptr);
1499 void options_free(const struct fio_option *options, void *data)
1501 const struct fio_option *o;
1504 dprint(FD_PARSE, "free options\n");
1506 for (o = &options[0]; o->name; o++) {
1507 if (o->type != FIO_OPT_STR_STORE || !o->off1 || o->no_free)
1510 ptr = td_var(data, o, o->off1);