blob: 15f2e06e62926a9b2353ad14353827577318be72 [file] [log] [blame]
Jens Axboee1f36502006-10-27 10:54:08 +02001#ifndef FIO_PARSE_H
2#define FIO_PARSE_H
3
Jens Axboe9f988e22010-03-04 10:42:38 +01004#include "flist.h"
5
Jens Axboee1f36502006-10-27 10:54:08 +02006/*
7 * Option types
8 */
9enum fio_opt_type {
Jens Axboe07b32322010-03-05 09:48:44 +010010 FIO_OPT_INVALID = 0,
11 FIO_OPT_STR,
Jens Axboe5f6ddf12010-03-09 20:40:44 +010012 FIO_OPT_STR_MULTI,
Jens Axboee1f36502006-10-27 10:54:08 +020013 FIO_OPT_STR_VAL,
14 FIO_OPT_STR_VAL_TIME,
15 FIO_OPT_STR_STORE,
16 FIO_OPT_RANGE,
17 FIO_OPT_INT,
Jens Axboe13335dd2007-01-10 13:14:02 +010018 FIO_OPT_BOOL,
Yu-ju Hong83349192011-08-13 00:53:44 +020019 FIO_OPT_FLOAT_LIST,
Jens Axboee1f36502006-10-27 10:54:08 +020020 FIO_OPT_STR_SET,
Jens Axboe15ca1502008-04-07 09:26:02 +020021 FIO_OPT_DEPRECATED,
Jens Axboee1f36502006-10-27 10:54:08 +020022};
23
24/*
Jens Axboeb1ec1da2007-02-23 10:29:16 +010025 * Match a possible value string with the integer option.
26 */
27struct value_pair {
28 const char *ival; /* string option */
29 unsigned int oval; /* output value */
Jens Axboe78372132007-03-14 13:24:07 +010030 const char *help; /* help text for sub option */
Daniel Gollubebadc0c2014-02-12 08:24:57 -070031 int orval; /* OR value */
Jens Axboec44b1ff2011-08-30 20:43:53 -060032 void *cb; /* sub-option callback */
Jens Axboeb1ec1da2007-02-23 10:29:16 +010033};
34
Zhang, Yanminc06c78c2010-03-03 08:26:30 +010035#define OPT_LEN_MAX 4096
Jens Axboe3ae4f4a2012-09-20 13:46:15 +020036#define PARSE_MAX_VP 24
Jens Axboeb1ec1da2007-02-23 10:29:16 +010037
38/*
Jens Axboee1f36502006-10-27 10:54:08 +020039 * Option define
40 */
41struct fio_option {
Jens Axboeee738492007-01-10 11:23:16 +010042 const char *name; /* option name */
Jens Axboee8b0e952012-03-19 14:37:08 +010043 const char *lname; /* long option name */
Jens Axboe03b74b32007-01-11 11:04:31 +010044 const char *alias; /* possible old allowed name */
Jens Axboeee738492007-01-10 11:23:16 +010045 enum fio_opt_type type; /* option type */
46 unsigned int off1; /* potential parameters */
Jens Axboee1f36502006-10-27 10:54:08 +020047 unsigned int off2;
Jens Axboef90eff52006-11-06 11:08:21 +010048 unsigned int off3;
49 unsigned int off4;
Shaohua Li6eaf09d2012-09-14 08:49:43 +020050 unsigned int off5;
51 unsigned int off6;
Jens Axboeee738492007-01-10 11:23:16 +010052 unsigned int maxval; /* max and min value */
Jens Axboe63f29372007-01-10 13:20:09 +010053 int minval;
Yu-ju Hong83349192011-08-13 00:53:44 +020054 double maxfp; /* max and min floating value */
55 double minfp;
Jens Axboe20eb06b2012-03-16 19:57:23 +010056 unsigned int interval; /* client hint for suitable interval */
Yu-ju Hong83349192011-08-13 00:53:44 +020057 unsigned int maxlen; /* max length */
Jens Axboe76a43db2007-01-11 13:24:44 +010058 int neg; /* negate value stored */
Jens Axboe3b8b7132008-06-10 19:46:23 +020059 int prio;
Jens Axboeee738492007-01-10 11:23:16 +010060 void *cb; /* callback */
61 const char *help; /* help text for option */
62 const char *def; /* default setting */
Jens Axboef5b6bb82010-03-05 10:09:59 +010063 struct value_pair posval[PARSE_MAX_VP];/* possible values */
Jens Axboeafdf9352007-07-31 16:14:34 +020064 const char *parent; /* parent option */
Jens Axboed71c1542012-03-16 20:16:59 +010065 int hide; /* hide if parent isn't set */
Jens Axboea4ed77f2012-03-20 10:19:44 +010066 int hide_on_set; /* hide on set, not on unset */
Jens Axboe90265352012-03-19 20:29:44 +010067 const char *inverse; /* if set, apply opposite action to this option */
68 struct fio_option *inv_opt; /* cached lookup */
Jens Axboe70a4c0c2009-07-01 09:24:05 +020069 int (*verify)(struct fio_option *, void *);
Jens Axboe07b32322010-03-05 09:48:44 +010070 const char *prof_name; /* only valid for specific profile */
Jens Axboe7b504ed2014-02-11 14:19:38 -070071 void *prof_opts;
Jens Axboee8b0e952012-03-19 14:37:08 +010072 unsigned int category; /* what type of option */
73 unsigned int group; /* who to group with */
Jens Axboe90265352012-03-19 20:29:44 +010074 void *gui_data;
Jens Axboe0de5b262014-02-21 15:26:01 -080075 int is_seconds; /* time value with seconds base */
Stephen M. Cameron79dc9142014-11-10 20:31:26 -070076 int is_time; /* time based value */
Jens Axboeef7035a2014-06-18 15:30:09 -070077 int no_warn_def;
Jens Axboee1f36502006-10-27 10:54:08 +020078};
79
80typedef int (str_cb_fn)(void *, char *);
81
Jens Axboe292cc472013-11-26 20:39:35 -070082extern int parse_option(char *, const char *, struct fio_option *, struct fio_option **, void *, int);
Jens Axboe3b8b7132008-06-10 19:46:23 +020083extern void sort_options(char **, struct fio_option *, int);
Jens Axboe07b32322010-03-05 09:48:44 +010084extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, void *);
85extern int show_cmd_help(struct fio_option *, const char *);
Jens Axboeee738492007-01-10 11:23:16 +010086extern void fill_default_options(void *, struct fio_option *);
Jens Axboe9f988e22010-03-04 10:42:38 +010087extern void option_init(struct fio_option *);
Jens Axboe13335dd2007-01-10 13:14:02 +010088extern void options_init(struct fio_option *);
Jens Axboe7e356b22011-10-14 10:55:16 +020089extern void options_free(struct fio_option *, void *);
Jens Axboee1f36502006-10-27 10:54:08 +020090
91extern void strip_blank_front(char **);
92extern void strip_blank_end(char *);
Stephen M. Cameron79dc9142014-11-10 20:31:26 -070093extern int str_to_decimal(const char *, long long *, int, void *, int, int);
Jens Axboe9af4a242012-03-16 10:13:49 +010094extern int check_str_bytes(const char *p, long long *val, void *data);
Jens Axboe0de5b262014-02-21 15:26:01 -080095extern int check_str_time(const char *p, long long *val, int);
Stephen M. Cameron79dc9142014-11-10 20:31:26 -070096extern int str_to_float(const char *str, double *val, int is_time);
Jens Axboee1f36502006-10-27 10:54:08 +020097
Jens Axboe786715e2014-12-05 09:35:40 -070098extern int string_distance(const char *s1, const char *s2);
99
Jens Axboee1f36502006-10-27 10:54:08 +0200100/*
101 * Handlers for the options
102 */
Jens Axboeb4692822006-10-27 13:43:22 +0200103typedef int (fio_opt_str_fn)(void *, const char *);
Jens Axboe63f29372007-01-10 13:20:09 +0100104typedef int (fio_opt_str_val_fn)(void *, long long *);
105typedef int (fio_opt_int_fn)(void *, int *);
Jens Axboee1f36502006-10-27 10:54:08 +0200106typedef int (fio_opt_str_set_fn)(void *);
107
Daniel Gollub3b5dac62014-02-12 19:25:42 +0100108#define __td_var(start, offset) ((char *) start + (offset))
Jens Axboef0fdbca2014-02-11 15:44:50 -0700109
110struct thread_options;
111static inline void *td_var(struct thread_options *to, struct fio_option *o,
112 unsigned int offset)
113{
114 if (o->prof_opts)
115 return __td_var(o->prof_opts, offset);
116
117 return __td_var(to, offset);
118}
Jens Axboee1f36502006-10-27 10:54:08 +0200119
Jens Axboe7bb59102011-07-12 19:47:03 +0200120static inline int parse_is_percent(unsigned long long val)
121{
122 return val <= -1ULL && val >= (-1ULL - 100ULL);
123}
124
Jens Axboee1f36502006-10-27 10:54:08 +0200125#endif