]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/config: Add methods to return the default value of a config option
authorSridhar Seshasayee <sseshasa@redhat.com>
Wed, 30 Jun 2021 09:22:50 +0000 (14:52 +0530)
committerSridhar Seshasayee <sseshasa@redhat.com>
Tue, 3 Aug 2021 05:54:36 +0000 (11:24 +0530)
Add wrapper method "get_val_default()" to the ConfigProxy class that takes
the config option key to search. This method in-turn calls another method
with the same name added to md_config_t class that does the actual work of
searching for the config option. If the option is valid, _get_val_default()
is used to get the default value. Otherwise, the wrapper method returns
std::nullopt.

Fixes: https://tracker.ceph.com/issues/51464
Signed-off-by: Sridhar Seshasayee <sseshasa@redhat.com>
(cherry picked from commit 9438e5a4b6b16e7ca3276c94c05ec73541690c10)

src/common/config.cc
src/common/config.h
src/common/config_proxy.h

index 4916858676675c3122323e7e3091f034999bcfe9..e15c99e7d09e67fed19cfc1e3ed9b3f6b640473b 100644 (file)
@@ -1029,6 +1029,16 @@ void md_config_t::get_config_bl(
   }
 }
 
+std::optional<std::string> md_config_t::get_val_default(std::string_view key)
+{
+  std::string val;
+  const Option *opt = find_option(key);
+  if (opt && (conf_stringify(_get_val_default(*opt), &val) == 0)) {
+    return std::make_optional(std::move(val));
+  }
+  return std::nullopt;
+}
+
 int md_config_t::get_val(const ConfigValues& values,
                         const std::string_view key, char **buf, int len) const
 {
index ef7d5b34fdc6b3f19dd82c913d766620a6cdc14b..989f5029e1270493ddf680d372d35219cac53185 100644 (file)
@@ -191,6 +191,9 @@ public:
   /// get encoded map<string,string> of compiled-in defaults
   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_view key, char **buf, int len) const;
index cb30a2d7f1fa26ed54486561ac92550e94695327..e43a7c6dd67c8ddd13a750824c8acf5f623849fe 100644 (file)
@@ -344,6 +344,9 @@ public:
   const std::string& get_conf_path() const {
     return config.get_conf_path();
   }
+  std::optional<std::string> get_val_default(std::string_view key) {
+    return config.get_val_default(key);
+  }
 };
 
 }