]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/config.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / common / config.h
index 527f6904e967cbc1b5ea235a93fc59b81259bfe6..bafac663127370237224176a15fd9e9bfdab75cc 100644 (file)
@@ -16,6 +16,7 @@
 #define CEPH_CONFIG_H
 
 #include <map>
+#include <variant>
 #include <boost/container/small_vector.hpp>
 #include "common/ConfUtils.h"
 #include "common/code_environment.h"
@@ -24,8 +25,7 @@
 #include "common/subsys_types.h"
 #include "common/config_tracker.h"
 #include "common/config_values.h"
-
-class CephContext;
+#include "include/common_fwd.h"
 
 enum {
   CONF_DEFAULT,
@@ -70,14 +70,14 @@ extern const char *ceph_conf_level_name(int level);
  */
 struct md_config_t {
 public:
-  typedef boost::variant<int64_t ConfigValues::*,
-                         uint64_t ConfigValues::*,
-                         std::string ConfigValues::*,
-                         double ConfigValues::*,
-                         bool ConfigValues::*,
-                         entity_addr_t ConfigValues::*,
-                        entity_addrvec_t ConfigValues::*,
-                         uuid_d ConfigValues::*> member_ptr_t;
+  typedef std::variant<int64_t ConfigValues::*,
+                       uint64_t ConfigValues::*,
+                       std::string ConfigValues::*,
+                       double ConfigValues::*,
+                       bool ConfigValues::*,
+                       entity_addr_t ConfigValues::*,
+                       entity_addrvec_t ConfigValues::*,
+                       uuid_d ConfigValues::*> member_ptr_t;
 
   // For use when intercepting configuration updates
   typedef std::function<bool(
@@ -89,33 +89,28 @@ public:
   /*
    * Mapping from legacy config option names to class members
    */
-  std::map<std::string, member_ptr_t> legacy_values;
+  std::map<std::string_view, member_ptr_t> legacy_values;
 
   /**
    * The configuration schema, in the form of Option objects describing
    * possible settings.
    */
-  std::map<std::string, const Option&> schema;
+  std::map<std::string_view, const Option&> schema;
 
   /// values from mon that we failed to set
   std::map<std::string,std::string> ignored_mon_values;
 
   /// original raw values saved that may need to re-expand at certain time
-  mutable std::map<std::string, std::string> may_reexpand_meta;
+  mutable std::vector<std::string> may_reexpand_meta;
 
   /// encoded, cached copy of of values + ignored_mon_values
-  bufferlist values_bl;
+  ceph::bufferlist values_bl;
 
   /// version for values_bl; increments each time there is a change
   uint64_t values_bl_version = 0;
 
   /// encoded copy of defaults (map<string,string>)
-  bufferlist defaults_bl;
-
-  typedef enum {
-    OPT_INT, OPT_LONGLONG, OPT_STR, OPT_DOUBLE, OPT_FLOAT, OPT_BOOL,
-    OPT_ADDR, OPT_ADDRVEC, OPT_U32, OPT_U64, OPT_UUID
-  } opt_type_t;
+  ceph::bufferlist defaults_bl;
 
   // Create a new md_config_t structure.
   explicit md_config_t(ConfigValues& values,
@@ -127,7 +122,10 @@ public:
   int parse_config_files(ConfigValues& values, const ConfigTracker& tracker,
                         const char *conf_files,
                         std::ostream *warnings, int flags);
-
+  int parse_buffer(ConfigValues& values, const ConfigTracker& tracker,
+                  const char* buf, size_t len,
+                  std::ostream *warnings);
+  void update_legacy_vals(ConfigValues& values);
   // Absorb config settings from the environment
   void parse_env(unsigned entity_type,
                 ConfigValues& values, const ConfigTracker& tracker,
@@ -140,25 +138,25 @@ public:
   // do any commands we got from argv (--show-config, --show-config-val)
   void do_argv_commands(const ConfigValues& values) const;
 
-  bool _internal_field(const string& k);
+  bool _internal_field(const std::string& k);
 
   void set_safe_to_start_threads();
   void _clear_safe_to_start_threads();  // this is only used by the unit test
 
   /// Look up an option in the schema
-  const Option *find_option(const string& name) const;
+  const Option *find_option(const std::string_view name) const;
 
   /// Set a default value
   void set_val_default(ConfigValues& values,
                       const ConfigTracker& tracker,
-                      const std::string& key, const std::string &val);
+                      const std::string_view key, const std::string &val);
 
   /// Set a values from mon
   int set_mon_vals(CephContext *cct,
-      ConfigValues& values,
-      const ConfigTracker& tracker,
-      const map<std::string,std::string>& kv,
-      config_callback config_cb);
+                  ConfigValues& values,
+                  const ConfigTracker& tracker,
+                  const std::map<std::string,std::string, std::less<>>& kv,
+                  config_callback config_cb);
 
   // Called by the Ceph daemons to make configuration changes at runtime
   int injectargs(ConfigValues& values,
@@ -169,51 +167,52 @@ public:
   // Set a configuration value, or crash
   // Metavariables will be expanded.
   void set_val_or_die(ConfigValues& values, const ConfigTracker& tracker,
-                     const std::string &key, const std::string &val);
+                     const std::string_view key, const std::string &val);
 
   // Set a configuration value.
   // Metavariables will be expanded.
   int set_val(ConfigValues& values, const ConfigTracker& tracker,
-             const std::string &key, const char *val,
+             const std::string_view key, const char *val,
               std::stringstream *err_ss=nullptr);
   int set_val(ConfigValues& values, const ConfigTracker& tracker,
-             const std::string &key, const string& s,
+             const std::string_view key, const std::string& s,
               std::stringstream *err_ss=nullptr) {
     return set_val(values, tracker, key, s.c_str(), err_ss);
   }
 
   /// clear override value
-  int rm_val(ConfigValues& values, const std::string& key);
+  int rm_val(ConfigValues& values, const std::string_view key);
 
   /// get encoded map<string,map<int32_t,string>> of entire config
   void get_config_bl(const ConfigValues& values,
                     uint64_t have_version,
-                    bufferlist *bl,
+                    ceph::buffer::list *bl,
                     uint64_t *got_version);
 
   /// get encoded map<string,string> of compiled-in defaults
-  void get_defaults_bl(const ConfigValues& values, bufferlist *bl);
+  void get_defaults_bl(const ConfigValues& values, ceph::buffer::list *bl);
+
+  /// Get the default value of a configuration option
+  std::optional<std::string> get_val_default(std::string_view key);
 
   // Get a configuration value.
   // No metavariables will be returned (they will have already been expanded)
-  int get_val(const ConfigValues& values, const std::string &key, char **buf, int len) const;
-  int get_val(const ConfigValues& values, const std::string &key, std::string *val) const;
-  Option::value_t get_val_generic(const ConfigValues& values, const std::string &key) const;
-  template<typename T> const T get_val(const ConfigValues& values, const std::string &key) const;
+  int get_val(const ConfigValues& values, const std::string_view key, char **buf, int len) const;
+  int get_val(const ConfigValues& values, const std::string_view key, std::string *val) const;
+  template<typename T> const T get_val(const ConfigValues& values, const std::string_view key) const;
   template<typename T, typename Callback, typename...Args>
-  auto with_val(const ConfigValues& values, const string& key,
+  auto with_val(const ConfigValues& values, const std::string_view key,
                Callback&& cb, Args&&... args) const ->
     std::result_of_t<Callback(const T&, Args...)> {
     return std::forward<Callback>(cb)(
-      boost::get<T>(this->get_val_generic(values, key)),
+      std::get<T>(this->get_val_generic(values, key)),
       std::forward<Args>(args)...);
   }
 
   void get_all_keys(std::vector<std::string> *keys) const;
 
   // Return a list of all the sections that the current entity is a member of.
-  void get_my_sections(const ConfigValues& values,
-                      std::vector <std::string> &sections) const;
+  std::vector<std::string> get_my_sections(const ConfigValues& values) const;
 
   // Return a list of all sections
   int get_all_sections(std::vector <std::string> &sections) const;
@@ -222,37 +221,39 @@ public:
   // Metavariables will be expanded if emeta is true.
   int get_val_from_conf_file(const ConfigValues& values,
                   const std::vector <std::string> &sections,
-                  std::string const &key, std::string &out, bool emeta) const;
+                  const std::string_view key, std::string &out, bool emeta) const;
 
   /// dump all config values to a stream
   void show_config(const ConfigValues& values, std::ostream& out) const;
   /// dump all config values to a formatter
-  void show_config(const ConfigValues& values, Formatter *f) const;
-  
+  void show_config(const ConfigValues& values, ceph::Formatter *f) const;
+
   /// dump all config settings to a formatter
-  void config_options(Formatter *f) const;
+  void config_options(ceph::Formatter *f) const;
 
   /// dump config diff from default, conf, mon, etc.
   void diff(const ConfigValues& values,
-           Formatter *f,
-           std::string name=string{}) const;
+           ceph::Formatter *f,
+           std::string name = {}) const;
 
   /// print/log warnings/errors from parsing the config
-  void complain_about_parse_errors(CephContext *cct);
+  void complain_about_parse_error(CephContext *cct);
 
 private:
   // we use this to avoid variable expansion loops
-  typedef boost::container::small_vector<pair<const Option*,
-                                             const Option::value_t*>,
+  typedef boost::container::small_vector<std::pair<const Option*,
+                                                  const Option::value_t*>,
                                         4> expand_stack_t;
 
   void validate_schema();
   void validate_default_settings();
 
+  Option::value_t get_val_generic(const ConfigValues& values,
+                                 const std::string_view key) const;
   int _get_val_cstr(const ConfigValues& values,
-                   const std::string &key, char **buf, int len) const;
+                   const std::stringkey, char **buf, int len) const;
   Option::value_t _get_val(const ConfigValues& values,
-                          const std::string &key,
+                          const std::string_view key,
                           expand_stack_t *stack=0,
                           std::ostream *err=0) const;
   Option::value_t _get_val(const ConfigValues& values,
@@ -263,18 +264,15 @@ private:
   Option::value_t _get_val_nometa(const ConfigValues& values,
                                  const Option& o) const;
 
-  int _rm_val(ConfigValues& values, const std::string& key, int level);
+  int _rm_val(ConfigValues& values, const std::string_view key, int level);
 
   void _refresh(ConfigValues& values, const Option& opt);
 
   void _show_config(const ConfigValues& values,
-                   std::ostream *out, Formatter *f) const;
-
-  void _get_my_sections(const ConfigValues& values,
-                       std::vector <std::string> &sections) const;
+                   std::ostream *out, ceph::Formatter *f) const;
 
-  int _get_val_from_conf_file(const std::vector <std::string> &sections,
-                             const std::string &key, std::string &out) const;
+  int _get_val_from_conf_file(const std::vector<std::string> &sections,
+                             const std::string_view key, std::string &out) const;
 
   int parse_option(ConfigValues& values,
                   const ConfigTracker& tracker,
@@ -301,7 +299,6 @@ private:
   void assign_member(member_ptr_t ptr, const Option::value_t &val);
 
 
-  void update_legacy_vals(ConfigValues& values);
   void update_legacy_val(ConfigValues& values,
                         const Option &opt,
                         member_ptr_t member);
@@ -321,15 +318,22 @@ public:  // for global_init
   // for those want to reexpand special meta, e.g, $pid
   bool finalize_reexpand_meta(ConfigValues& values,
                              const ConfigTracker& tracker);
-private:
 
-  /// expand all metavariables in config structure.
-  void expand_all_meta();
+  std::list<std::string> get_conffile_paths(const ConfigValues& values,
+                                           const char *conf_files,
+                                           std::ostream *warnings,
+                                           int flags) const;
 
+  const std::string& get_conf_path() const {
+    return conf_path;
+  }
+private:
+  static std::string get_cluster_name(const char* conffile_path);
   // The configuration file we read, or NULL if we haven't read one.
   ConfFile cf;
+  std::string conf_path;
 public:
-  std::deque<std::string> parse_errors;
+  std::string parse_error;
 private:
 
   // This will be set to true when it is safe to start threads.
@@ -337,12 +341,12 @@ private:
   bool safe_to_start_threads = false;
 
   bool do_show_config = false;
-  string do_show_config_value;
+  std::string do_show_config_value;
 
-  vector<Option> subsys_options;
+  std::vector<Option> subsys_options;
 
 public:
-  string data_dir_option;  ///< data_dir config option, if any
+  std::string data_dir_option;  ///< data_dir config option, if any
 
 public:
   unsigned get_osd_pool_default_min_size(const ConfigValues& values,
@@ -356,11 +360,11 @@ public:
 
 template<typename T>
 const T md_config_t::get_val(const ConfigValues& values,
-                            const std::string &key) const {
-  return boost::get<T>(this->get_val_generic(values, key));
+                            const std::string_view key) const {
+  return std::get<T>(this->get_val_generic(values, key));
 }
 
-inline std::ostream& operator<<(std::ostream& o, const boost::blank& ) {
+inline std::ostream& operator<<(std::ostream& o, const std::monostate&) {
       return o << "INVALID_CONFIG_VALUE";
 }