Fix inverted logic in gtod_reduce()
[fio.git] / parse.h
1 #ifndef FIO_PARSE_H
2 #define FIO_PARSE_H
3
4 #include "flist.h"
5
6 /*
7  * Option types
8  */
9 enum fio_opt_type {
10         FIO_OPT_INVALID = 0,
11         FIO_OPT_STR,
12         FIO_OPT_STR_MULTI,
13         FIO_OPT_STR_VAL,
14         FIO_OPT_STR_VAL_TIME,
15         FIO_OPT_STR_STORE,
16         FIO_OPT_RANGE,
17         FIO_OPT_INT,
18         FIO_OPT_BOOL,
19         FIO_OPT_FLOAT_LIST,
20         FIO_OPT_STR_SET,
21         FIO_OPT_DEPRECATED,
22 };
23
24 /*
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 */
30         const char *help;               /* help text for sub option */
31         int orval;                      /* OR value */
32         void *cb;                       /* sub-option callback */
33 };
34
35 #define OPT_LEN_MAX     4096
36 #define PARSE_MAX_VP    24
37
38 /*
39  * Option define
40  */
41 struct fio_option {
42         const char *name;               /* option name */
43         const char *lname;              /* long option name */
44         const char *alias;              /* possible old allowed name */
45         enum fio_opt_type type;         /* option type */
46         unsigned int off1;              /* potential parameters */
47         unsigned int off2;
48         unsigned int off3;
49         unsigned int off4;
50         unsigned int off5;
51         unsigned int off6;
52         unsigned int maxval;            /* max and min value */
53         int minval;
54         double maxfp;                   /* max and min floating value */
55         double minfp;
56         unsigned int interval;          /* client hint for suitable interval */
57         unsigned int maxlen;            /* max length */
58         int neg;                        /* negate value stored */
59         int prio;
60         void *cb;                       /* callback */
61         const char *help;               /* help text for option */
62         const char *def;                /* default setting */
63         struct value_pair posval[PARSE_MAX_VP];/* possible values */
64         const char *parent;             /* parent option */
65         int hide;                       /* hide if parent isn't set */
66         int hide_on_set;                /* hide on set, not on unset */
67         const char *inverse;            /* if set, apply opposite action to this option */
68         struct fio_option *inv_opt;     /* cached lookup */
69         int (*verify)(struct fio_option *, void *);
70         const char *prof_name;          /* only valid for specific profile */
71         void *prof_opts;
72         unsigned int category;          /* what type of option */
73         unsigned int group;             /* who to group with */
74         void *gui_data;
75 };
76
77 typedef int (str_cb_fn)(void *, char *);
78
79 extern int parse_option(char *, const char *, struct fio_option *, struct fio_option **, void *, int);
80 extern void sort_options(char **, struct fio_option *, int);
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 *);
83 extern void fill_default_options(void *, struct fio_option *);
84 extern void option_init(struct fio_option *);
85 extern void options_init(struct fio_option *);
86 extern void options_free(struct fio_option *, void *);
87
88 extern void strip_blank_front(char **);
89 extern void strip_blank_end(char *);
90 extern int str_to_decimal(const char *, long long *, int, void *);
91 extern int check_str_bytes(const char *p, long long *val, void *data);
92 extern int check_str_time(const char *p, long long *val);
93 extern int str_to_float(const char *str, double *val);
94
95 /*
96  * Handlers for the options
97  */
98 typedef int (fio_opt_str_fn)(void *, const char *);
99 typedef int (fio_opt_str_val_fn)(void *, long long *);
100 typedef int (fio_opt_int_fn)(void *, int *);
101 typedef int (fio_opt_str_set_fn)(void *);
102
103 #define __td_var(start, offset) ((char *) start + (offset))
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 }
114
115 static inline int parse_is_percent(unsigned long long val)
116 {
117         return val <= -1ULL && val >= (-1ULL - 100ULL);
118 }
119
120 #endif