Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1 | #ifndef FIO_PARSE_H |
| 2 | #define FIO_PARSE_H |
| 3 | |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 4 | #include "flist.h" |
| 5 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 6 | /* |
| 7 | * Option types |
| 8 | */ |
| 9 | enum fio_opt_type { |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 10 | FIO_OPT_INVALID = 0, |
| 11 | FIO_OPT_STR, |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 12 | FIO_OPT_STR_MULTI, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 13 | FIO_OPT_STR_VAL, |
| 14 | FIO_OPT_STR_VAL_TIME, |
| 15 | FIO_OPT_STR_STORE, |
| 16 | FIO_OPT_RANGE, |
| 17 | FIO_OPT_INT, |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 18 | FIO_OPT_BOOL, |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 19 | FIO_OPT_FLOAT_LIST, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 20 | FIO_OPT_STR_SET, |
Jens Axboe | 15ca150 | 2008-04-07 09:26:02 +0200 | [diff] [blame] | 21 | FIO_OPT_DEPRECATED, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | /* |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 25 | * Match a possible value string with the integer option. |
| 26 | */ |
| 27 | struct value_pair { |
| 28 | const char *ival; /* string option */ |
| 29 | unsigned int oval; /* output value */ |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 30 | const char *help; /* help text for sub option */ |
Daniel Gollub | ebadc0c | 2014-02-12 08:24:57 -0700 | [diff] [blame] | 31 | int orval; /* OR value */ |
Jens Axboe | c44b1ff | 2011-08-30 20:43:53 -0600 | [diff] [blame] | 32 | void *cb; /* sub-option callback */ |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 33 | }; |
| 34 | |
Zhang, Yanmin | c06c78c | 2010-03-03 08:26:30 +0100 | [diff] [blame] | 35 | #define OPT_LEN_MAX 4096 |
Jens Axboe | 3ae4f4a | 2012-09-20 13:46:15 +0200 | [diff] [blame] | 36 | #define PARSE_MAX_VP 24 |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 37 | |
| 38 | /* |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 39 | * Option define |
| 40 | */ |
| 41 | struct fio_option { |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 42 | const char *name; /* option name */ |
Jens Axboe | e8b0e95 | 2012-03-19 14:37:08 +0100 | [diff] [blame] | 43 | const char *lname; /* long option name */ |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 44 | const char *alias; /* possible old allowed name */ |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 45 | enum fio_opt_type type; /* option type */ |
| 46 | unsigned int off1; /* potential parameters */ |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 47 | unsigned int off2; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 48 | unsigned int off3; |
| 49 | unsigned int off4; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 50 | unsigned int off5; |
| 51 | unsigned int off6; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 52 | unsigned int maxval; /* max and min value */ |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 53 | int minval; |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 54 | double maxfp; /* max and min floating value */ |
| 55 | double minfp; |
Jens Axboe | 20eb06b | 2012-03-16 19:57:23 +0100 | [diff] [blame] | 56 | unsigned int interval; /* client hint for suitable interval */ |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 57 | unsigned int maxlen; /* max length */ |
Jens Axboe | 76a43db | 2007-01-11 13:24:44 +0100 | [diff] [blame] | 58 | int neg; /* negate value stored */ |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 59 | int prio; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 60 | void *cb; /* callback */ |
| 61 | const char *help; /* help text for option */ |
| 62 | const char *def; /* default setting */ |
Jens Axboe | f5b6bb8 | 2010-03-05 10:09:59 +0100 | [diff] [blame] | 63 | struct value_pair posval[PARSE_MAX_VP];/* possible values */ |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 64 | const char *parent; /* parent option */ |
Jens Axboe | d71c154 | 2012-03-16 20:16:59 +0100 | [diff] [blame] | 65 | int hide; /* hide if parent isn't set */ |
Jens Axboe | a4ed77f | 2012-03-20 10:19:44 +0100 | [diff] [blame] | 66 | int hide_on_set; /* hide on set, not on unset */ |
Jens Axboe | 9026535 | 2012-03-19 20:29:44 +0100 | [diff] [blame] | 67 | const char *inverse; /* if set, apply opposite action to this option */ |
| 68 | struct fio_option *inv_opt; /* cached lookup */ |
Jens Axboe | 70a4c0c | 2009-07-01 09:24:05 +0200 | [diff] [blame] | 69 | int (*verify)(struct fio_option *, void *); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 70 | const char *prof_name; /* only valid for specific profile */ |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 71 | void *prof_opts; |
Jens Axboe | e8b0e95 | 2012-03-19 14:37:08 +0100 | [diff] [blame] | 72 | unsigned int category; /* what type of option */ |
| 73 | unsigned int group; /* who to group with */ |
Jens Axboe | 9026535 | 2012-03-19 20:29:44 +0100 | [diff] [blame] | 74 | void *gui_data; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | typedef int (str_cb_fn)(void *, char *); |
| 78 | |
Jens Axboe | 292cc47 | 2013-11-26 20:39:35 -0700 | [diff] [blame] | 79 | extern int parse_option(char *, const char *, struct fio_option *, struct fio_option **, void *, int); |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 80 | extern void sort_options(char **, struct fio_option *, int); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 81 | extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, void *); |
| 82 | extern int show_cmd_help(struct fio_option *, const char *); |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 83 | extern void fill_default_options(void *, struct fio_option *); |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 84 | extern void option_init(struct fio_option *); |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 85 | extern void options_init(struct fio_option *); |
Jens Axboe | 7e356b2 | 2011-10-14 10:55:16 +0200 | [diff] [blame] | 86 | extern void options_free(struct fio_option *, void *); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 87 | |
| 88 | extern void strip_blank_front(char **); |
| 89 | extern void strip_blank_end(char *); |
Jens Axboe | 6925dd3 | 2011-09-07 22:10:11 +0200 | [diff] [blame] | 90 | extern int str_to_decimal(const char *, long long *, int, void *); |
Jens Axboe | 9af4a24 | 2012-03-16 10:13:49 +0100 | [diff] [blame] | 91 | extern int check_str_bytes(const char *p, long long *val, void *data); |
Jens Axboe | 0646490 | 2013-04-24 20:38:54 -0600 | [diff] [blame] | 92 | extern int check_str_time(const char *p, long long *val); |
Jens Axboe | e25839d | 2012-11-06 10:49:42 +0100 | [diff] [blame] | 93 | extern int str_to_float(const char *str, double *val); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * Handlers for the options |
| 97 | */ |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 98 | typedef int (fio_opt_str_fn)(void *, const char *); |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 99 | typedef int (fio_opt_str_val_fn)(void *, long long *); |
| 100 | typedef int (fio_opt_int_fn)(void *, int *); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 101 | typedef int (fio_opt_str_set_fn)(void *); |
| 102 | |
Daniel Gollub | 3b5dac6 | 2014-02-12 19:25:42 +0100 | [diff] [blame] | 103 | #define __td_var(start, offset) ((char *) start + (offset)) |
Jens Axboe | f0fdbca | 2014-02-11 15:44:50 -0700 | [diff] [blame] | 104 | |
| 105 | struct thread_options; |
| 106 | static inline void *td_var(struct thread_options *to, struct fio_option *o, |
| 107 | unsigned int offset) |
| 108 | { |
| 109 | if (o->prof_opts) |
| 110 | return __td_var(o->prof_opts, offset); |
| 111 | |
| 112 | return __td_var(to, offset); |
| 113 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 114 | |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 115 | static inline int parse_is_percent(unsigned long long val) |
| 116 | { |
| 117 | return val <= -1ULL && val >= (-1ULL - 100ULL); |
| 118 | } |
| 119 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 120 | #endif |