X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Fcommon%2Fconfig.h;h=1e573f5e11b28832ee77b3cb3b1fb5cd29a1d573;hb=c07f9fc5a4f48397831383549fb0482b93480643;hp=0d32fb3b90c5beb578eccff625e58e60c68e413e;hpb=9439ae556f035e65c9c107ae13ddd09457dbbecd;p=ceph.git diff --git a/ceph/src/common/config.h b/ceph/src/common/config.h index 0d32fb3b9..1e573f5e1 100644 --- a/ceph/src/common/config.h +++ b/ceph/src/common/config.h @@ -17,9 +17,11 @@ #include "common/ConfUtils.h" #include "common/entity_name.h" +#include "common/code_environment.h" #include "common/Mutex.h" #include "log/SubsystemMap.h" #include "common/config_obs.h" +#include "common/options.h" #define OSD_REP_PRIMARY 0 #define OSD_REP_SPLAY 1 @@ -64,6 +66,14 @@ extern const char *CEPH_CONF_FILE_DEFAULT; */ struct md_config_t { public: + typedef boost::variant member_ptr_t; + /* Maps configuration options to the observer listening for them. */ typedef std::multimap obs_map_t; @@ -71,83 +81,29 @@ public: * apply_changes */ typedef std::set < std::string > changed_set_t; - struct invalid_config_value_t { }; - typedef boost::variant config_value_t; - typedef boost::variant member_ptr_t; + /* + * Mapping from legacy config option names to class members + */ + std::map legacy_values; + + /** + * The configuration schema, in the form of Option objects describing + * possible settings. + */ + std::map schema; + + /** + * The current values of all settings described by the schema + */ + std::map values; typedef enum { OPT_INT, OPT_LONGLONG, OPT_STR, OPT_DOUBLE, OPT_FLOAT, OPT_BOOL, OPT_ADDR, OPT_U32, OPT_U64, OPT_UUID } opt_type_t; - typedef std::function validator_t; - - class config_option { - public: - const char *name; - opt_type_t type; - md_config_t::member_ptr_t md_member_ptr; - bool safe; // promise to access it only via md_config_t::get_val - validator_t validator; - private: - template struct get_typed_pointer_visitor : public boost::static_visitor { - md_config_t const *conf; - explicit get_typed_pointer_visitor(md_config_t const *conf_) : conf(conf_) { } - template, int>::type = 0> - T const *operator()(const U md_config_t::* member_ptr) { - return &(conf->*member_ptr); - } - template::value, int>::type = 0> - T const *operator()(const U md_config_t::* member_ptr) { - return nullptr; - } - }; - public: - // is it OK to alter the value when threads are running? - bool is_safe() const; - // Given a configuration, return a pointer to this option inside - // that configuration. - template void conf_ptr(T const *&ptr, md_config_t const *conf) const { - get_typed_pointer_visitor gtpv(conf); - ptr = boost::apply_visitor(gtpv, md_member_ptr); - } - template void conf_ptr(T *&ptr, md_config_t *conf) const { - get_typed_pointer_visitor gtpv(conf); - ptr = const_cast(boost::apply_visitor(gtpv, md_member_ptr)); - } - template T const *conf_ptr(md_config_t const *conf) const { - get_typed_pointer_visitor gtpv(conf); - return boost::apply_visitor(gtpv, md_member_ptr); - } - template T *conf_ptr(md_config_t *conf) const { - get_typed_pointer_visitor gtpv(conf); - return const_cast(boost::apply_visitor(gtpv, md_member_ptr)); - } - }; - // Create a new md_config_t structure. - md_config_t(); + md_config_t(bool is_daemon=false); ~md_config_t(); // Adds a new observer to this configuration. You can do this at any time, @@ -188,21 +144,24 @@ public: // Set a configuration value, or crash // Metavariables will be expanded. - void set_val_or_die(const char *key, const char *val); + void set_val_or_die(const std::string &key, const std::string &val, + bool meta=true); // Set a configuration value. // Metavariables will be expanded. - int set_val(const char *key, const char *val, bool meta=true); - int set_val(const char *key, const string& s, bool meta=true) { - return set_val(key, s.c_str(), meta); + int set_val(const std::string &key, const char *val, bool meta=true, + std::stringstream *err_ss=nullptr); + int set_val(const std::string &key, const string& s, bool meta=true, + std::stringstream *err_ss=nullptr) { + return set_val(key, s.c_str(), meta, err_ss); } // Get a configuration value. // No metavariables will be returned (they will have already been expanded) - int get_val(const char *key, char **buf, int len) const; - int _get_val(const char *key, char **buf, int len) const; - config_value_t get_val_generic(const char *key) const; - template T get_val(const char *key) const; + int get_val(const std::string &key, char **buf, int len) const; + int _get_val(const std::string &key, char **buf, int len) const; + Option::value_t get_val_generic(const std::string &key) const; + template T get_val(const std::string &key) const; void get_all_keys(std::vector *keys) const; @@ -215,7 +174,7 @@ public: // Get a value from the configuration file that we read earlier. // Metavariables will be expanded if emeta is true. int get_val_from_conf_file(const std::vector §ions, - const char *key, std::string &out, bool emeta) const; + std::string const &key, std::string &out, bool emeta) const; /// dump all config values to a stream void show_config(std::ostream& out); @@ -236,16 +195,17 @@ public: void complain_about_parse_errors(CephContext *cct); private: + void validate_schema(); void validate_default_settings(); - int _get_val(const char *key, std::string *value) const; - config_value_t _get_val(const char *key) const; + int _get_val(const std::string &key, std::string *value) const; + Option::value_t _get_val(const std::string &key) const; void _show_config(std::ostream *out, Formatter *f); void _get_my_sections(std::vector §ions) const; int _get_val_from_conf_file(const std::vector §ions, - const char *key, std::string &out, bool emeta) const; + const std::string &key, std::string &out, bool emeta) const; int parse_option(std::vector& args, std::vector::iterator& i, @@ -255,9 +215,15 @@ private: int parse_config_files_impl(const std::list &conf_files, std::ostream *warnings); - int set_val_impl(const std::string &val, config_option const *opt, + int set_val_impl(const std::string &val, const Option &opt, std::string *error_message); - int set_val_raw(const char *val, config_option const *opt); + + template + void assign_member(member_ptr_t ptr, const Option::value_t &val); + + + void update_legacy_val(const Option &opt, + md_config_t::member_ptr_t member); void init_subsys(); @@ -276,8 +242,8 @@ public: // for global_init } private: bool expand_meta(std::string &val, - config_option const *opt, - std::list stack, + const Option *opt, + std::list stack, std::ostream *oss) const; /// expand all metavariables in config structure. @@ -301,29 +267,28 @@ public: /// cluster name string cluster; -#define OPTION_OPT_INT(name) const int name; -#define OPTION_OPT_LONGLONG(name) const long long name; -#define OPTION_OPT_STR(name) const std::string name; -#define OPTION_OPT_DOUBLE(name) const double name; -#define OPTION_OPT_FLOAT(name) const float name; -#define OPTION_OPT_BOOL(name) const bool name; -#define OPTION_OPT_ADDR(name) const entity_addr_t name; -#define OPTION_OPT_U32(name) const uint32_t name; -#define OPTION_OPT_U64(name) const uint64_t name; -#define OPTION_OPT_UUID(name) const uuid_d name; -#define OPTION(name, ty, init) \ +// This macro block defines C members of the md_config_t struct +// corresponding to the definitions in legacy_config_opts.h. +// These C members are consumed by code that was written before +// the new options.cc infrastructure: all newer code should +// be consume options via explicit get() rather than C members. +#define OPTION_OPT_INT(name) int64_t name; +#define OPTION_OPT_LONGLONG(name) int64_t name; +#define OPTION_OPT_STR(name) std::string name; +#define OPTION_OPT_DOUBLE(name) double name; +#define OPTION_OPT_FLOAT(name) double name; +#define OPTION_OPT_BOOL(name) bool name; +#define OPTION_OPT_ADDR(name) entity_addr_t name; +#define OPTION_OPT_U32(name) uint64_t name; +#define OPTION_OPT_U64(name) uint64_t name; +#define OPTION_OPT_UUID(name) uuid_d name; +#define OPTION(name, ty) \ public: \ - OPTION_##ty(name) \ - struct option_##name##_t; -#define OPTION_VALIDATOR(name) -#define SAFE_OPTION(name, ty, init) \ + OPTION_##ty(name) +#define SAFE_OPTION(name, ty) \ protected: \ - OPTION_##ty(name) \ - public: \ - struct option_##name##_t; -#define SUBSYS(name, log, gather) -#define DEFAULT_SUBSYS(log, gather) -#include "common/config_opts.h" + OPTION_##ty(name) +#include "common/legacy_config_opts.h" #undef OPTION_OPT_INT #undef OPTION_OPT_LONGLONG #undef OPTION_OPT_STR @@ -335,11 +300,9 @@ public: #undef OPTION_OPT_U64 #undef OPTION_OPT_UUID #undef OPTION -#undef OPTION_VALIDATOR #undef SAFE_OPTION -#undef SUBSYS -#undef DEFAULT_SUBSYS +public: unsigned get_osd_pool_default_min_size() const { return osd_pool_default_min_size ? MIN(osd_pool_default_min_size, osd_pool_default_size) : @@ -353,11 +316,6 @@ public: mutable Mutex lock; friend class test_md_config_t; -protected: - // Tests and possibly users expect options to appear in the output - // of ceph-conf in the same order as declared in config_opts.h - std::shared_ptr> config_options; - config_option const *find_config_option(const std::string& normalized_key) const; }; template @@ -374,35 +332,26 @@ struct get_typed_value_visitor : public boost::static_visitor { } }; -template T md_config_t::get_val(const char *key) const { - config_value_t generic_val = this->get_val_generic(key); +template T md_config_t::get_val(const std::string &key) const { + Option::value_t generic_val = this->get_val_generic(key); get_typed_value_visitor gtv; return boost::apply_visitor(gtv, generic_val); } -inline std::ostream& operator<<(std::ostream& o, const md_config_t::invalid_config_value_t& ) { +inline std::ostream& operator<<(std::ostream& o, const boost::blank& ) { return o << "INVALID_CONFIG_VALUE"; } int ceph_resolve_file_search(const std::string& filename_list, std::string& result); -typedef md_config_t::config_option config_option; - - enum config_subsys_id { ceph_subsys_, // default -#define OPTION(a,b,c) -#define OPTION_VALIDATOR(name) -#define SAFE_OPTION(a,b,c) #define SUBSYS(name, log, gather) \ ceph_subsys_##name, #define DEFAULT_SUBSYS(log, gather) -#include "common/config_opts.h" +#include "common/subsys.h" #undef SUBSYS -#undef OPTION -#undef OPTION_VALIDATOR -#undef SAFE_OPTION #undef DEFAULT_SUBSYS ceph_subsys_max };