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 | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 36 | #define PARSE_MAX_VP 16 |
| 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; |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 49 | void *roff1, *roff2, *roff3, *roff4; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 50 | unsigned int maxval; /* max and min value */ |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 51 | int minval; |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 52 | double maxfp; /* max and min floating value */ |
| 53 | double minfp; |
| 54 | unsigned int maxlen; /* max length */ |
Jens Axboe | 76a43db | 2007-01-11 13:24:44 +0100 | [diff] [blame] | 55 | int neg; /* negate value stored */ |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 56 | int prio; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 57 | void *cb; /* callback */ |
| 58 | const char *help; /* help text for option */ |
| 59 | const char *def; /* default setting */ |
Jens Axboe | f5b6bb8 | 2010-03-05 10:09:59 +0100 | [diff] [blame] | 60 | struct value_pair posval[PARSE_MAX_VP];/* possible values */ |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 61 | const char *parent; /* parent option */ |
Jens Axboe | 70a4c0c | 2009-07-01 09:24:05 +0200 | [diff] [blame] | 62 | int (*verify)(struct fio_option *, void *); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 63 | const char *prof_name; /* only valid for specific profile */ |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | typedef int (str_cb_fn)(void *, char *); |
| 67 | |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 68 | extern int parse_option(const char *, struct fio_option *, void *); |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 69 | extern void sort_options(char **, struct fio_option *, int); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 70 | extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, void *); |
| 71 | extern int show_cmd_help(struct fio_option *, const char *); |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 72 | extern void fill_default_options(void *, struct fio_option *); |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 73 | extern void option_init(struct fio_option *); |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 74 | extern void options_init(struct fio_option *); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 75 | |
| 76 | extern void strip_blank_front(char **); |
| 77 | extern void strip_blank_end(char *); |
Jens Axboe | f20485a | 2011-09-07 21:21:07 +0200 | [diff] [blame^] | 78 | extern int str_to_decimal(const char *, long long *, int, int, void *); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * Handlers for the options |
| 82 | */ |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 83 | typedef int (fio_opt_str_fn)(void *, const char *); |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 84 | typedef int (fio_opt_str_val_fn)(void *, long long *); |
| 85 | typedef int (fio_opt_int_fn)(void *, int *); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 86 | typedef int (fio_opt_str_set_fn)(void *); |
| 87 | |
| 88 | #define td_var(start, offset) ((void *) start + (offset)) |
| 89 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 90 | #ifndef min |
| 91 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
| 92 | #endif |
| 93 | #ifndef max |
| 94 | #define max(a, b) ((a) > (b) ? (a) : (b)) |
| 95 | #endif |
| 96 | |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 97 | static inline int parse_is_percent(unsigned long long val) |
| 98 | { |
| 99 | return val <= -1ULL && val >= (-1ULL - 100ULL); |
| 100 | } |
| 101 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 102 | #endif |