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 | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 43 | const char *alias; /* possible old allowed name */ |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 44 | enum fio_opt_type type; /* option type */ |
| 45 | unsigned int off1; /* potential parameters */ |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 46 | unsigned int off2; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 47 | unsigned int off3; |
| 48 | unsigned int off4; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 49 | unsigned int off5; |
| 50 | unsigned int off6; |
| 51 | void *roff1, *roff2, *roff3, *roff4, *roff5, *roff6; |
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; |
| 56 | unsigned int maxlen; /* max length */ |
Jens Axboe | 76a43db | 2007-01-11 13:24:44 +0100 | [diff] [blame] | 57 | int neg; /* negate value stored */ |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 58 | int prio; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 59 | void *cb; /* callback */ |
| 60 | const char *help; /* help text for option */ |
| 61 | const char *def; /* default setting */ |
Jens Axboe | f5b6bb8 | 2010-03-05 10:09:59 +0100 | [diff] [blame] | 62 | struct value_pair posval[PARSE_MAX_VP];/* possible values */ |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 63 | const char *parent; /* parent option */ |
Jens Axboe | 70a4c0c | 2009-07-01 09:24:05 +0200 | [diff] [blame] | 64 | int (*verify)(struct fio_option *, void *); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 65 | const char *prof_name; /* only valid for specific profile */ |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | typedef int (str_cb_fn)(void *, char *); |
| 69 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 70 | 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] | 71 | extern void sort_options(char **, struct fio_option *, int); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 72 | extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, void *); |
| 73 | extern int show_cmd_help(struct fio_option *, const char *); |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 74 | extern void fill_default_options(void *, struct fio_option *); |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 75 | extern void option_init(struct fio_option *); |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 76 | extern void options_init(struct fio_option *); |
Jens Axboe | 7e356b2 | 2011-10-14 10:55:16 +0200 | [diff] [blame] | 77 | extern void options_free(struct fio_option *, void *); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 78 | |
| 79 | extern void strip_blank_front(char **); |
| 80 | extern void strip_blank_end(char *); |
Jens Axboe | 6925dd3 | 2011-09-07 22:10:11 +0200 | [diff] [blame] | 81 | extern int str_to_decimal(const char *, long long *, int, void *); |
Jens Axboe | e25839d | 2012-11-06 10:49:42 +0100 | [diff] [blame] | 82 | extern int str_to_float(const char *str, double *val); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * Handlers for the options |
| 86 | */ |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 87 | typedef int (fio_opt_str_fn)(void *, const char *); |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 88 | typedef int (fio_opt_str_val_fn)(void *, long long *); |
| 89 | typedef int (fio_opt_int_fn)(void *, int *); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 90 | typedef int (fio_opt_str_set_fn)(void *); |
| 91 | |
| 92 | #define td_var(start, offset) ((void *) start + (offset)) |
| 93 | |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 94 | static inline int parse_is_percent(unsigned long long val) |
| 95 | { |
| 96 | return val <= -1ULL && val >= (-1ULL - 100ULL); |
| 97 | } |
| 98 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 99 | #endif |