iolog: switch to list based scheme
[fio.git] / parse.h
... / ...
CommitLineData
1#ifndef FIO_PARSE_H
2#define FIO_PARSE_H
3
4#include <inttypes.h>
5#include "flist.h"
6
7/*
8 * Option types
9 */
10enum fio_opt_type {
11 FIO_OPT_INVALID = 0,
12 FIO_OPT_STR,
13 FIO_OPT_STR_MULTI,
14 FIO_OPT_STR_VAL,
15 FIO_OPT_STR_VAL_TIME,
16 FIO_OPT_STR_STORE,
17 FIO_OPT_RANGE,
18 FIO_OPT_INT,
19 FIO_OPT_BOOL,
20 FIO_OPT_FLOAT_LIST,
21 FIO_OPT_STR_SET,
22 FIO_OPT_DEPRECATED,
23};
24
25/*
26 * Match a possible value string with the integer option.
27 */
28struct value_pair {
29 const char *ival; /* string option */
30 unsigned int oval; /* output value */
31 const char *help; /* help text for sub option */
32 int orval; /* OR value */
33 void *cb; /* sub-option callback */
34};
35
36#define OPT_LEN_MAX 4096
37#define PARSE_MAX_VP 24
38
39/*
40 * Option define
41 */
42struct fio_option {
43 const char *name; /* option name */
44 const char *lname; /* long option name */
45 const char *alias; /* possible old allowed name */
46 enum fio_opt_type type; /* option type */
47 unsigned int off1; /* potential parameters */
48 unsigned int off2;
49 unsigned int off3;
50 unsigned int off4;
51 unsigned int off5;
52 unsigned int off6;
53 unsigned int maxval; /* max and min value */
54 int minval;
55 double maxfp; /* max and min floating value */
56 double minfp;
57 unsigned int interval; /* client hint for suitable interval */
58 unsigned int maxlen; /* max length */
59 int neg; /* negate value stored */
60 int prio;
61 void *cb; /* callback */
62 const char *help; /* help text for option */
63 const char *def; /* default setting */
64 struct value_pair posval[PARSE_MAX_VP];/* possible values */
65 const char *parent; /* parent option */
66 int hide; /* hide if parent isn't set */
67 int hide_on_set; /* hide on set, not on unset */
68 const char *inverse; /* if set, apply opposite action to this option */
69 struct fio_option *inv_opt; /* cached lookup */
70 int (*verify)(struct fio_option *, void *);
71 const char *prof_name; /* only valid for specific profile */
72 void *prof_opts;
73 uint64_t category; /* what type of option */
74 uint64_t group; /* who to group with */
75 void *gui_data;
76 int is_seconds; /* time value with seconds base */
77 int is_time; /* time based value */
78 int no_warn_def;
79 int pow2; /* must be a power-of-2 */
80};
81
82typedef int (str_cb_fn)(void *, char *);
83
84extern int parse_option(char *, const char *, struct fio_option *, struct fio_option **, void *, struct flist_head *);
85extern void sort_options(char **, struct fio_option *, int);
86extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, void *, struct flist_head *);
87extern int show_cmd_help(struct fio_option *, const char *);
88extern void fill_default_options(void *, struct fio_option *);
89extern void option_init(struct fio_option *);
90extern void options_init(struct fio_option *);
91extern void options_free(struct fio_option *, void *);
92
93extern void strip_blank_front(char **);
94extern void strip_blank_end(char *);
95extern int str_to_decimal(const char *, long long *, int, void *, int, int);
96extern int check_str_bytes(const char *p, long long *val, void *data);
97extern int check_str_time(const char *p, long long *val, int);
98extern int str_to_float(const char *str, double *val, int is_time);
99
100extern int string_distance(const char *s1, const char *s2);
101extern int string_distance_ok(const char *s1, int dist);
102
103/*
104 * Handlers for the options
105 */
106typedef int (fio_opt_str_fn)(void *, const char *);
107typedef int (fio_opt_str_val_fn)(void *, long long *);
108typedef int (fio_opt_int_fn)(void *, int *);
109typedef int (fio_opt_str_set_fn)(void *);
110
111#define __td_var(start, offset) ((char *) start + (offset))
112
113struct thread_options;
114static inline void *td_var(struct thread_options *to, struct fio_option *o,
115 unsigned int offset)
116{
117 if (o->prof_opts)
118 return __td_var(o->prof_opts, offset);
119
120 return __td_var(to, offset);
121}
122
123static inline int parse_is_percent(unsigned long long val)
124{
125 return val <= -1ULL && val >= (-1ULL - 100ULL);
126}
127
128struct print_option {
129 struct flist_head list;
130 char *name;
131 char *value;
132};
133
134#endif