| 1 | #ifndef FIO_PARSE_H |
| 2 | #define FIO_PARSE_H |
| 3 | |
| 4 | #include <inttypes.h> |
| 5 | #include "flist.h" |
| 6 | |
| 7 | /* |
| 8 | * Option types |
| 9 | */ |
| 10 | enum fio_opt_type { |
| 11 | FIO_OPT_INVALID = 0, |
| 12 | FIO_OPT_STR, |
| 13 | FIO_OPT_STR_ULL, |
| 14 | FIO_OPT_STR_MULTI, |
| 15 | FIO_OPT_STR_VAL, |
| 16 | FIO_OPT_STR_VAL_TIME, |
| 17 | FIO_OPT_STR_STORE, |
| 18 | FIO_OPT_RANGE, |
| 19 | FIO_OPT_INT, |
| 20 | FIO_OPT_ULL, |
| 21 | FIO_OPT_BOOL, |
| 22 | FIO_OPT_FLOAT_LIST, |
| 23 | FIO_OPT_STR_SET, |
| 24 | FIO_OPT_DEPRECATED, |
| 25 | FIO_OPT_SOFT_DEPRECATED, |
| 26 | FIO_OPT_UNSUPPORTED, /* keep this last */ |
| 27 | }; |
| 28 | |
| 29 | /* |
| 30 | * Match a possible value string with the integer option. |
| 31 | */ |
| 32 | struct value_pair { |
| 33 | const char *ival; /* string option */ |
| 34 | unsigned long long oval;/* output value */ |
| 35 | const char *help; /* help text for sub option */ |
| 36 | int orval; /* OR value */ |
| 37 | void *cb; /* sub-option callback */ |
| 38 | }; |
| 39 | |
| 40 | #define OPT_LEN_MAX 8192 |
| 41 | #define PARSE_MAX_VP 32 |
| 42 | |
| 43 | /* |
| 44 | * Option define |
| 45 | */ |
| 46 | struct fio_option { |
| 47 | const char *name; /* option name */ |
| 48 | const char *lname; /* long option name */ |
| 49 | const char *alias; /* possible old allowed name */ |
| 50 | enum fio_opt_type type; /* option type */ |
| 51 | unsigned int off1; /* potential parameters */ |
| 52 | unsigned int off2; |
| 53 | unsigned int off3; |
| 54 | unsigned int off4; |
| 55 | unsigned int off5; |
| 56 | unsigned int off6; |
| 57 | unsigned long long maxval; /* max and min value */ |
| 58 | int minval; |
| 59 | double maxfp; /* max and min floating value */ |
| 60 | double minfp; |
| 61 | unsigned int interval; /* client hint for suitable interval */ |
| 62 | unsigned int maxlen; /* max length */ |
| 63 | int neg; /* negate value stored */ |
| 64 | int prio; |
| 65 | void *cb; /* callback */ |
| 66 | const char *help; /* help text for option */ |
| 67 | const char *def; /* default setting */ |
| 68 | struct value_pair posval[PARSE_MAX_VP];/* possible values */ |
| 69 | const char *parent; /* parent option */ |
| 70 | int hide; /* hide if parent isn't set */ |
| 71 | int hide_on_set; /* hide on set, not on unset */ |
| 72 | const char *inverse; /* if set, apply opposite action to this option */ |
| 73 | struct fio_option *inv_opt; /* cached lookup */ |
| 74 | int (*verify)(const struct fio_option *, void *); |
| 75 | const char *prof_name; /* only valid for specific profile */ |
| 76 | void *prof_opts; |
| 77 | uint64_t category; /* what type of option */ |
| 78 | uint64_t group; /* who to group with */ |
| 79 | void *gui_data; |
| 80 | int is_seconds; /* time value with seconds base */ |
| 81 | int is_time; /* time based value */ |
| 82 | int no_warn_def; |
| 83 | int pow2; /* must be a power-of-2 */ |
| 84 | int no_free; |
| 85 | }; |
| 86 | |
| 87 | extern int parse_option(char *, const char *, const struct fio_option *, |
| 88 | const struct fio_option **, void *, |
| 89 | struct flist_head *); |
| 90 | extern void sort_options(char **, const struct fio_option *, int); |
| 91 | extern int parse_cmd_option(const char *t, const char *l, |
| 92 | const struct fio_option *, void *, |
| 93 | struct flist_head *); |
| 94 | extern int show_cmd_help(const struct fio_option *, const char *); |
| 95 | extern void fill_default_options(void *, const struct fio_option *); |
| 96 | extern void options_init(struct fio_option *); |
| 97 | extern void options_mem_dupe(const struct fio_option *, void *); |
| 98 | extern void options_free(const struct fio_option *, void *); |
| 99 | |
| 100 | extern void strip_blank_front(char **); |
| 101 | extern void strip_blank_end(char *); |
| 102 | extern int str_to_decimal(const char *, long long *, int, void *, int, int); |
| 103 | extern int check_str_bytes(const char *p, long long *val, void *data); |
| 104 | extern int check_str_time(const char *p, long long *val, int); |
| 105 | extern int str_to_float(const char *str, double *val, int is_time); |
| 106 | |
| 107 | extern int string_distance(const char *s1, const char *s2); |
| 108 | extern int string_distance_ok(const char *s1, int dist); |
| 109 | |
| 110 | /* |
| 111 | * Handlers for the options |
| 112 | */ |
| 113 | typedef int (fio_opt_str_fn)(void *, const char *); |
| 114 | typedef int (fio_opt_str_val_fn)(void *, long long *); |
| 115 | typedef int (fio_opt_int_fn)(void *, int *); |
| 116 | |
| 117 | struct thread_options; |
| 118 | static inline void *td_var(void *to, const struct fio_option *o, |
| 119 | unsigned int offset) |
| 120 | { |
| 121 | void *ret; |
| 122 | |
| 123 | if (o->prof_opts) |
| 124 | ret = o->prof_opts; |
| 125 | else |
| 126 | ret = to; |
| 127 | |
| 128 | return ret + offset; |
| 129 | } |
| 130 | |
| 131 | static inline int parse_is_percent(unsigned long long val) |
| 132 | { |
| 133 | return val <= -1ULL && val >= (-1ULL - 100ULL); |
| 134 | } |
| 135 | |
| 136 | struct print_option { |
| 137 | struct flist_head list; |
| 138 | char *name; |
| 139 | char *value; |
| 140 | }; |
| 141 | |
| 142 | #endif |