1e1f365035a952233463d85d659bd960ba78f012eJens Axboe#ifndef FIO_PARSE_H 2e1f365035a952233463d85d659bd960ba78f012eJens Axboe#define FIO_PARSE_H 3e1f365035a952233463d85d659bd960ba78f012eJens Axboe 4eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes#include <inttypes.h> 59f988e2ebb3bff7087cc9681a54bd7f0d0e42140Jens Axboe#include "flist.h" 69f988e2ebb3bff7087cc9681a54bd7f0d0e42140Jens Axboe 7e1f365035a952233463d85d659bd960ba78f012eJens Axboe/* 8e1f365035a952233463d85d659bd960ba78f012eJens Axboe * Option types 9e1f365035a952233463d85d659bd960ba78f012eJens Axboe */ 10e1f365035a952233463d85d659bd960ba78f012eJens Axboeenum fio_opt_type { 1107b3232de97ac32a873f0b5d17c8f49c18ed3ae7Jens Axboe FIO_OPT_INVALID = 0, 1207b3232de97ac32a873f0b5d17c8f49c18ed3ae7Jens Axboe FIO_OPT_STR, 135f6ddf1e568d5014925a98da316d92f9e6e03eb4Jens Axboe FIO_OPT_STR_MULTI, 14e1f365035a952233463d85d659bd960ba78f012eJens Axboe FIO_OPT_STR_VAL, 15e1f365035a952233463d85d659bd960ba78f012eJens Axboe FIO_OPT_STR_VAL_TIME, 16e1f365035a952233463d85d659bd960ba78f012eJens Axboe FIO_OPT_STR_STORE, 17e1f365035a952233463d85d659bd960ba78f012eJens Axboe FIO_OPT_RANGE, 18e1f365035a952233463d85d659bd960ba78f012eJens Axboe FIO_OPT_INT, 1913335ddb0e304efa0fc96593dd1fd995ec6f68d7Jens Axboe FIO_OPT_BOOL, 20833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong FIO_OPT_FLOAT_LIST, 21e1f365035a952233463d85d659bd960ba78f012eJens Axboe FIO_OPT_STR_SET, 2215ca150e8dbfd68aa5beb479fcb3f07447417a04Jens Axboe FIO_OPT_DEPRECATED, 23eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes FIO_OPT_UNSUPPORTED, 24e1f365035a952233463d85d659bd960ba78f012eJens Axboe}; 25e1f365035a952233463d85d659bd960ba78f012eJens Axboe 26e1f365035a952233463d85d659bd960ba78f012eJens Axboe/* 27b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe * Match a possible value string with the integer option. 28b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe */ 29b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboestruct value_pair { 30b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe const char *ival; /* string option */ 31b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe unsigned int oval; /* output value */ 327837213b66e20a8d91e7069f5823852f42c41440Jens Axboe const char *help; /* help text for sub option */ 33ebadc0ce34c11b3e0130d5602b18f4ed0e638386Daniel Gollub int orval; /* OR value */ 34c44b1ff54402c589e8f07436ec56efb4f8b1ac23Jens Axboe void *cb; /* sub-option callback */ 35b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe}; 36b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe 37c06c78c04c415bcb33350e8e56b924b75b4e93aaZhang, Yanmin#define OPT_LEN_MAX 4096 383ae4f4af272a54045cba9c650411353c92ec768dJens Axboe#define PARSE_MAX_VP 24 39b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe 40b1ec1da670aab645e32303ea5ffaa1e5ca336936Jens Axboe/* 41e1f365035a952233463d85d659bd960ba78f012eJens Axboe * Option define 42e1f365035a952233463d85d659bd960ba78f012eJens Axboe */ 43e1f365035a952233463d85d659bd960ba78f012eJens Axboestruct fio_option { 44ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe const char *name; /* option name */ 45e8b0e958cd219cabb1154e2b06036863a7d6dbd7Jens Axboe const char *lname; /* long option name */ 4603b74b3ec5268e731ed7fcaef31c8c0655acd530Jens Axboe const char *alias; /* possible old allowed name */ 47ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe enum fio_opt_type type; /* option type */ 48ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe unsigned int off1; /* potential parameters */ 49e1f365035a952233463d85d659bd960ba78f012eJens Axboe unsigned int off2; 50f90eff5a414f6e8c16a51c3a7d9b5e077ab49aacJens Axboe unsigned int off3; 51f90eff5a414f6e8c16a51c3a7d9b5e077ab49aacJens Axboe unsigned int off4; 526eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li unsigned int off5; 536eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li unsigned int off6; 54ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe unsigned int maxval; /* max and min value */ 5563f29372bc1bd69b66816c96d88b9c0bd8f3d8b9Jens Axboe int minval; 56833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong double maxfp; /* max and min floating value */ 57833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong double minfp; 5820eb06bd2aef37fa8dd314a110bb81c733115e15Jens Axboe unsigned int interval; /* client hint for suitable interval */ 59833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong unsigned int maxlen; /* max length */ 6076a43db448f9fd5e9f1397428a433466d98e0d5dJens Axboe int neg; /* negate value stored */ 613b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboe int prio; 62ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe void *cb; /* callback */ 63ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe const char *help; /* help text for option */ 64ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboe const char *def; /* default setting */ 65f5b6bb85364fcb8b2ac8d922ca65afd9dfabc9bbJens Axboe struct value_pair posval[PARSE_MAX_VP];/* possible values */ 66afdf935261b23cdf08214e708133318548ddf2c4Jens Axboe const char *parent; /* parent option */ 67d71c154c8b20a7ddca645d9854e640563f1b79c7Jens Axboe int hide; /* hide if parent isn't set */ 68a4ed77fe07de1ca78cd44a6378dc20a2cd1ce7adJens Axboe int hide_on_set; /* hide on set, not on unset */ 6990265353af8dbf1c43804996909777d4c1a5998eJens Axboe const char *inverse; /* if set, apply opposite action to this option */ 7090265353af8dbf1c43804996909777d4c1a5998eJens Axboe struct fio_option *inv_opt; /* cached lookup */ 7170a4c0c8417bba7c2e1e9a384b9acf226f5b9782Jens Axboe int (*verify)(struct fio_option *, void *); 7207b3232de97ac32a873f0b5d17c8f49c18ed3ae7Jens Axboe const char *prof_name; /* only valid for specific profile */ 737b504eddc4b039f2db3a0626bd08f880c5f4de27Jens Axboe void *prof_opts; 74eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes uint64_t category; /* what type of option */ 75eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes uint64_t group; /* who to group with */ 7690265353af8dbf1c43804996909777d4c1a5998eJens Axboe void *gui_data; 770de5b26f6e177aacac0683306c47e0cbaf58b0b6Jens Axboe int is_seconds; /* time value with seconds base */ 7879dc914fcf76e8f6c8f8e20dc75bd424cc833d27Stephen M. Cameron int is_time; /* time based value */ 79ef7035a9b2c7af1e745b7cd2448685527ef7eeb0Jens Axboe int no_warn_def; 80eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int pow2; /* must be a power-of-2 */ 81e1f365035a952233463d85d659bd960ba78f012eJens Axboe}; 82e1f365035a952233463d85d659bd960ba78f012eJens Axboe 83eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesextern int parse_option(char *, const char *, struct fio_option *, struct fio_option **, void *, struct flist_head *); 843b8b7135602a4d3a7132fee10da9c1203ab643adJens Axboeextern void sort_options(char **, struct fio_option *, int); 85eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesextern int parse_cmd_option(const char *t, const char *l, struct fio_option *, void *, struct flist_head *); 8607b3232de97ac32a873f0b5d17c8f49c18ed3ae7Jens Axboeextern int show_cmd_help(struct fio_option *, const char *); 87ee738499877bb1ee913e839cb4a8d4edad2d52adJens Axboeextern void fill_default_options(void *, struct fio_option *); 8813335ddb0e304efa0fc96593dd1fd995ec6f68d7Jens Axboeextern void options_init(struct fio_option *); 89eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesextern void options_mem_dupe(struct fio_option *, void *); 907e356b2dee2e86f3684424fc6e903f1ef9f00ef4Jens Axboeextern void options_free(struct fio_option *, void *); 91e1f365035a952233463d85d659bd960ba78f012eJens Axboe 92e1f365035a952233463d85d659bd960ba78f012eJens Axboeextern void strip_blank_front(char **); 93e1f365035a952233463d85d659bd960ba78f012eJens Axboeextern void strip_blank_end(char *); 9479dc914fcf76e8f6c8f8e20dc75bd424cc833d27Stephen M. Cameronextern int str_to_decimal(const char *, long long *, int, void *, int, int); 959af4a24408ea7d4cea084a4fe214b81145cc36acJens Axboeextern int check_str_bytes(const char *p, long long *val, void *data); 960de5b26f6e177aacac0683306c47e0cbaf58b0b6Jens Axboeextern int check_str_time(const char *p, long long *val, int); 9779dc914fcf76e8f6c8f8e20dc75bd424cc833d27Stephen M. Cameronextern int str_to_float(const char *str, double *val, int is_time); 98e1f365035a952233463d85d659bd960ba78f012eJens Axboe 99786715eaa81c267b4a372e22f028e7a5543e5698Jens Axboeextern int string_distance(const char *s1, const char *s2); 100eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesextern int string_distance_ok(const char *s1, int dist); 101786715eaa81c267b4a372e22f028e7a5543e5698Jens Axboe 102e1f365035a952233463d85d659bd960ba78f012eJens Axboe/* 103e1f365035a952233463d85d659bd960ba78f012eJens Axboe * Handlers for the options 104e1f365035a952233463d85d659bd960ba78f012eJens Axboe */ 105b46928282e0a890f49250e79b81af773a2b7108fJens Axboetypedef int (fio_opt_str_fn)(void *, const char *); 10663f29372bc1bd69b66816c96d88b9c0bd8f3d8b9Jens Axboetypedef int (fio_opt_str_val_fn)(void *, long long *); 10763f29372bc1bd69b66816c96d88b9c0bd8f3d8b9Jens Axboetypedef int (fio_opt_int_fn)(void *, int *); 108f0fdbcafc3a62b84250e5ccdcaec47e3ffa93a00Jens Axboe 109f0fdbcafc3a62b84250e5ccdcaec47e3ffa93a00Jens Axboestruct thread_options; 110eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic inline void *td_var(void *to, struct fio_option *o, unsigned int offset) 111f0fdbcafc3a62b84250e5ccdcaec47e3ffa93a00Jens Axboe{ 112eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes void *ret; 113eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 114f0fdbcafc3a62b84250e5ccdcaec47e3ffa93a00Jens Axboe if (o->prof_opts) 115eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ret = o->prof_opts; 116eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else 117eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ret = to; 118f0fdbcafc3a62b84250e5ccdcaec47e3ffa93a00Jens Axboe 119eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return (char *) ret + offset; 120f0fdbcafc3a62b84250e5ccdcaec47e3ffa93a00Jens Axboe} 121e1f365035a952233463d85d659bd960ba78f012eJens Axboe 1227bb591020669b7266c57108f2a68b48a03ae72eeJens Axboestatic inline int parse_is_percent(unsigned long long val) 1237bb591020669b7266c57108f2a68b48a03ae72eeJens Axboe{ 1247bb591020669b7266c57108f2a68b48a03ae72eeJens Axboe return val <= -1ULL && val >= (-1ULL - 100ULL); 1257bb591020669b7266c57108f2a68b48a03ae72eeJens Axboe} 1267bb591020669b7266c57108f2a68b48a03ae72eeJens Axboe 127eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstruct print_option { 128eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct flist_head list; 129eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes char *name; 130eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes char *value; 131eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes}; 132eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 133e1f365035a952233463d85d659bd960ba78f012eJens Axboe#endif 134