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 */ |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 31 | int or; /* 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; |
| 52 | void *roff1, *roff2, *roff3, *roff4, *roff5, *roff6; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 53 | unsigned int maxval; /* max and min value */ |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 54 | int minval; |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 55 | double maxfp; /* max and min floating value */ |
| 56 | double minfp; |
Jens Axboe | 20eb06b | 2012-03-16 19:57:23 +0100 | [diff] [blame] | 57 | unsigned int interval; /* client hint for suitable interval */ |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 58 | unsigned int maxlen; /* max length */ |
Jens Axboe | 76a43db | 2007-01-11 13:24:44 +0100 | [diff] [blame] | 59 | int neg; /* negate value stored */ |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 60 | int prio; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 61 | void *cb; /* callback */ |
| 62 | const char *help; /* help text for option */ |
| 63 | const char *def; /* default setting */ |
Jens Axboe | f5b6bb8 | 2010-03-05 10:09:59 +0100 | [diff] [blame] | 64 | struct value_pair posval[PARSE_MAX_VP];/* possible values */ |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 65 | const char *parent; /* parent option */ |
Jens Axboe | d71c154 | 2012-03-16 20:16:59 +0100 | [diff] [blame] | 66 | int hide; /* hide if parent isn't set */ |
Jens Axboe | a4ed77f | 2012-03-20 10:19:44 +0100 | [diff] [blame] | 67 | int hide_on_set; /* hide on set, not on unset */ |
Jens Axboe | 9026535 | 2012-03-19 20:29:44 +0100 | [diff] [blame] | 68 | const char *inverse; /* if set, apply opposite action to this option */ |
| 69 | struct fio_option *inv_opt; /* cached lookup */ |
Jens Axboe | 70a4c0c | 2009-07-01 09:24:05 +0200 | [diff] [blame] | 70 | int (*verify)(struct fio_option *, void *); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 71 | const char *prof_name; /* only valid for specific profile */ |
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 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 79 | extern int parse_option(char *, const char *, struct fio_option *, struct fio_option **, void *); |
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 | |
| 103 | #define td_var(start, offset) ((void *) start + (offset)) |
| 104 | |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 105 | static inline int parse_is_percent(unsigned long long val) |
| 106 | { |
| 107 | return val <= -1ULL && val >= (-1ULL - 100ULL); |
| 108 | } |
| 109 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 110 | #endif |