blob: c5a74171ae94e70cb45339b1b22fbd387579ccf5 [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 */
Jens Axboe5f6ddf12010-03-09 20:40:44 +010031 int or; /* OR value */
Jens Axboeb1ec1da2007-02-23 10:29:16 +010032};
33
Zhang, Yanminc06c78c2010-03-03 08:26:30 +010034#define OPT_LEN_MAX 4096
Jens Axboeb1ec1da2007-02-23 10:29:16 +010035#define PARSE_MAX_VP 16
36
37/*
Jens Axboee1f36502006-10-27 10:54:08 +020038 * Option define
39 */
40struct fio_option {
Jens Axboeee738492007-01-10 11:23:16 +010041 const char *name; /* option name */
Jens Axboe03b74b32007-01-11 11:04:31 +010042 const char *alias; /* possible old allowed name */
Jens Axboeee738492007-01-10 11:23:16 +010043 enum fio_opt_type type; /* option type */
44 unsigned int off1; /* potential parameters */
Jens Axboee1f36502006-10-27 10:54:08 +020045 unsigned int off2;
Jens Axboef90eff52006-11-06 11:08:21 +010046 unsigned int off3;
47 unsigned int off4;
Jens Axboe02c6aad2010-03-04 13:49:11 +010048 void *roff1, *roff2, *roff3, *roff4;
Jens Axboeee738492007-01-10 11:23:16 +010049 unsigned int maxval; /* max and min value */
Jens Axboe63f29372007-01-10 13:20:09 +010050 int minval;
Yu-ju Hong83349192011-08-13 00:53:44 +020051 double maxfp; /* max and min floating value */
52 double minfp;
53 unsigned int maxlen; /* max length */
Jens Axboe76a43db2007-01-11 13:24:44 +010054 int neg; /* negate value stored */
Jens Axboe3b8b7132008-06-10 19:46:23 +020055 int prio;
Jens Axboeee738492007-01-10 11:23:16 +010056 void *cb; /* callback */
57 const char *help; /* help text for option */
58 const char *def; /* default setting */
Jens Axboef5b6bb82010-03-05 10:09:59 +010059 struct value_pair posval[PARSE_MAX_VP];/* possible values */
Jens Axboeafdf9352007-07-31 16:14:34 +020060 const char *parent; /* parent option */
Jens Axboe70a4c0c2009-07-01 09:24:05 +020061 int (*verify)(struct fio_option *, void *);
Jens Axboe07b32322010-03-05 09:48:44 +010062 const char *prof_name; /* only valid for specific profile */
Jens Axboee1f36502006-10-27 10:54:08 +020063};
64
65typedef int (str_cb_fn)(void *, char *);
66
Jens Axboe07b32322010-03-05 09:48:44 +010067extern int parse_option(const char *, struct fio_option *, void *);
Jens Axboe3b8b7132008-06-10 19:46:23 +020068extern void sort_options(char **, struct fio_option *, int);
Jens Axboe07b32322010-03-05 09:48:44 +010069extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, void *);
70extern int show_cmd_help(struct fio_option *, const char *);
Jens Axboeee738492007-01-10 11:23:16 +010071extern void fill_default_options(void *, struct fio_option *);
Jens Axboe9f988e22010-03-04 10:42:38 +010072extern void option_init(struct fio_option *);
Jens Axboe13335dd2007-01-10 13:14:02 +010073extern void options_init(struct fio_option *);
Jens Axboee1f36502006-10-27 10:54:08 +020074
75extern void strip_blank_front(char **);
76extern void strip_blank_end(char *);
Jens Axboed6978a32009-07-18 21:04:09 +020077extern int str_to_decimal(const char *, long long *, int, void *);
Jens Axboee1f36502006-10-27 10:54:08 +020078
79/*
80 * Handlers for the options
81 */
Jens Axboeb4692822006-10-27 13:43:22 +020082typedef int (fio_opt_str_fn)(void *, const char *);
Jens Axboe63f29372007-01-10 13:20:09 +010083typedef int (fio_opt_str_val_fn)(void *, long long *);
84typedef int (fio_opt_int_fn)(void *, int *);
Jens Axboee1f36502006-10-27 10:54:08 +020085typedef int (fio_opt_str_set_fn)(void *);
86
87#define td_var(start, offset) ((void *) start + (offset))
88
Jens Axboe0e9f7fa2007-03-01 14:05:30 +010089#ifndef min
90#define min(a, b) ((a) < (b) ? (a) : (b))
91#endif
92#ifndef max
93#define max(a, b) ((a) > (b) ? (a) : (b))
94#endif
95
Jens Axboe7bb59102011-07-12 19:47:03 +020096static inline int parse_is_percent(unsigned long long val)
97{
98 return val <= -1ULL && val >= (-1ULL - 100ULL);
99}
100
Jens Axboee1f36502006-10-27 10:54:08 +0200101#endif