]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: hide internal logger configuration strings from clients 43578/head
authorRonen Friedman <rfriedma@redhat.com>
Sun, 17 Oct 2021 06:21:16 +0000 (06:21 +0000)
committerRonen Friedman <rfriedma@redhat.com>
Thu, 11 Nov 2021 08:58:35 +0000 (08:58 +0000)
Replace the common pattern used by clients of the logger, of:
- creating multiple "one element maps" for all config options;
- passing them, untouched, to the logger's update config.
with one that hides the configuration handling details from
the users.

Note: a followup PR, bypassing the strmaps construction altogether,
should be considered.

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
13 files changed:
src/common/LogClient.cc
src/common/LogClient.h
src/common/str_list.cc
src/common/str_map.cc
src/include/str_map.h
src/mds/MDSRank.cc
src/mgr/ActivePyModules.cc
src/mgr/DaemonState.h
src/mgr/MgrStandby.cc
src/mon/Monitor.cc
src/osd/OSD.cc
src/rgw/rgw_kms.cc
src/rgw/rgw_kms.h

index 5082d45fac5108f33358dce4acfff16746166349..1ba363da790e1e629e4f65d382a4209db355e866 100644 (file)
@@ -27,80 +27,6 @@ using std::ostream;
 using std::ostringstream;
 using std::string;
 
-int parse_log_client_options(CephContext *cct,
-                            map<string,string> &log_to_monitors,
-                            map<string,string> &log_to_syslog,
-                            map<string,string> &log_channels,
-                            map<string,string> &log_prios,
-                            map<string,string> &log_to_graylog,
-                            map<string,string> &log_to_graylog_host,
-                            map<string,string> &log_to_graylog_port,
-                            uuid_d &fsid,
-                            string &host)
-{
-  ostringstream oss;
-
-  int r = get_conf_str_map_helper(
-    cct->_conf.get_val<string>("clog_to_monitors"), oss,
-    &log_to_monitors, CLOG_CONFIG_DEFAULT_KEY);
-  if (r < 0) {
-    lderr(cct) << __func__ << " error parsing 'clog_to_monitors'" << dendl;
-    return r;
-  }
-
-  r = get_conf_str_map_helper(
-    cct->_conf.get_val<string>("clog_to_syslog"), oss,
-                              &log_to_syslog, CLOG_CONFIG_DEFAULT_KEY);
-  if (r < 0) {
-    lderr(cct) << __func__ << " error parsing 'clog_to_syslog'" << dendl;
-    return r;
-  }
-
-  r = get_conf_str_map_helper(
-    cct->_conf.get_val<string>("clog_to_syslog_facility"), oss,
-    &log_channels, CLOG_CONFIG_DEFAULT_KEY);
-  if (r < 0) {
-    lderr(cct) << __func__ << " error parsing 'clog_to_syslog_facility'" << dendl;
-    return r;
-  }
-
-  r = get_conf_str_map_helper(
-    cct->_conf.get_val<string>("clog_to_syslog_level"), oss,
-    &log_prios, CLOG_CONFIG_DEFAULT_KEY);
-  if (r < 0) {
-    lderr(cct) << __func__ << " error parsing 'clog_to_syslog_level'" << dendl;
-    return r;
-  }
-
-  r = get_conf_str_map_helper(
-    cct->_conf.get_val<string>("clog_to_graylog"), oss,
-    &log_to_graylog, CLOG_CONFIG_DEFAULT_KEY);
-  if (r < 0) {
-    lderr(cct) << __func__ << " error parsing 'clog_to_graylog'" << dendl;
-    return r;
-  }
-
-  r = get_conf_str_map_helper(
-    cct->_conf.get_val<string>("clog_to_graylog_host"), oss,
-    &log_to_graylog_host, CLOG_CONFIG_DEFAULT_KEY);
-  if (r < 0) {
-    lderr(cct) << __func__ << " error parsing 'clog_to_graylog_host'" << dendl;
-    return r;
-  }
-
-  r = get_conf_str_map_helper(
-    cct->_conf.get_val<string>("clog_to_graylog_port"), oss,
-    &log_to_graylog_port, CLOG_CONFIG_DEFAULT_KEY);
-  if (r < 0) {
-    lderr(cct) << __func__ << " error parsing 'clog_to_graylog_port'" << dendl;
-    return r;
-  }
-
-  fsid = cct->_conf.get_val<uuid_d>("fsid");
-  host = cct->_conf->host;
-  return 0;
-}
-
 #undef dout_prefix
 #define dout_prefix _prefix(_dout, this)
 static ostream& _prefix(std::ostream *_dout, LogClient *logc) {
@@ -141,41 +67,23 @@ void LogChannel::set_log_to_monitors(bool v)
   }
 }
 
-void LogChannel::update_config(map<string,string> &log_to_monitors,
-                              map<string,string> &log_to_syslog,
-                              map<string,string> &log_channels,
-                              map<string,string> &log_prios,
-                              map<string,string> &log_to_graylog,
-                              map<string,string> &log_to_graylog_host,
-                              map<string,string> &log_to_graylog_port,
-                              uuid_d &fsid,
-                              string &host)
+void LogChannel::update_config(const clog_targets_conf_t& conf_strings)
 {
-  ldout(cct, 20) << __func__ << " log_to_monitors " << log_to_monitors
-                << " log_to_syslog " << log_to_syslog
-                << " log_channels " << log_channels
-                << " log_prios " << log_prios
+  ldout(cct, 20) << __func__ << " log_to_monitors " << conf_strings.log_to_monitors
+                << " log_to_syslog " << conf_strings.log_to_syslog
+                << " log_channels " << conf_strings.log_channels
+                << " log_prios " << conf_strings.log_prios
                 << dendl;
-  bool to_monitors = (get_str_map_key(log_to_monitors, log_channel,
-                                      &CLOG_CONFIG_DEFAULT_KEY) == "true");
-  bool to_syslog = (get_str_map_key(log_to_syslog, log_channel,
-                                    &CLOG_CONFIG_DEFAULT_KEY) == "true");
-  string syslog_facility = get_str_map_key(log_channels, log_channel,
-                                          &CLOG_CONFIG_DEFAULT_KEY);
-  string prio = get_str_map_key(log_prios, log_channel,
-                               &CLOG_CONFIG_DEFAULT_KEY);
-  bool to_graylog = (get_str_map_key(log_to_graylog, log_channel,
-                                    &CLOG_CONFIG_DEFAULT_KEY) == "true");
-  string graylog_host = get_str_map_key(log_to_graylog_host, log_channel,
-                                      &CLOG_CONFIG_DEFAULT_KEY);
-  string graylog_port_str = get_str_map_key(log_to_graylog_port, log_channel,
-                                           &CLOG_CONFIG_DEFAULT_KEY);
-  int graylog_port = atoi(graylog_port_str.c_str());
+
+  bool to_monitors = (conf_strings.log_to_monitors == "true");
+  bool to_syslog = (conf_strings.log_to_syslog == "true");
+  bool to_graylog = (conf_strings.log_to_graylog == "true");
+  auto graylog_port = atoi(conf_strings.log_to_graylog_port.c_str());
 
   set_log_to_monitors(to_monitors);
   set_log_to_syslog(to_syslog);
-  set_syslog_facility(syslog_facility);
-  set_log_prio(prio);
+  set_syslog_facility(conf_strings.log_channels);
+  set_log_prio(conf_strings.log_prios);
 
   if (to_graylog && !graylog) { /* should but isn't */
     graylog = std::make_shared<ceph::logging::Graylog>("clog");
@@ -184,25 +92,63 @@ void LogChannel::update_config(map<string,string> &log_to_monitors,
   }
 
   if (to_graylog && graylog) {
-    graylog->set_fsid(fsid);
-    graylog->set_hostname(host);
+    graylog->set_fsid(conf_strings.fsid);
+    graylog->set_hostname(conf_strings.host);
   }
 
-  if (graylog && (!graylog_host.empty()) && (graylog_port != 0)) {
-    graylog->set_destination(graylog_host, graylog_port);
+  if (graylog && !conf_strings.log_to_graylog_host.empty() && (graylog_port != 0)) {
+    graylog->set_destination(conf_strings.log_to_graylog_host, graylog_port);
   }
 
   ldout(cct, 10) << __func__
                 << " to_monitors: " << (to_monitors ? "true" : "false")
                 << " to_syslog: " << (to_syslog ? "true" : "false")
-                << " syslog_facility: " << syslog_facility
-                << " prio: " << prio
+                << " syslog_facility: " << conf_strings.log_channels
+                << " prio: " << conf_strings.log_prios
                 << " to_graylog: " << (to_graylog ? "true" : "false")
-                << " graylog_host: " << graylog_host
+                << " graylog_host: " << conf_strings.log_to_graylog_host
                 << " graylog_port: " << graylog_port
                 << ")" << dendl;
 }
 
+clog_targets_conf_t LogChannel::parse_client_options(CephContext* conf_cct)
+{
+  auto parsed_options = parse_log_client_options(conf_cct);
+  update_config(parsed_options);
+  return parsed_options;
+}
+
+clog_targets_conf_t LogChannel::parse_log_client_options(CephContext* cct)
+{
+  clog_targets_conf_t targets;
+
+  targets.log_to_monitors =
+    get_value_via_strmap(cct->_conf.get_val<string>("clog_to_monitors"),
+                         log_channel, CLOG_CONFIG_DEFAULT_KEY);
+  targets.log_to_syslog =
+    get_value_via_strmap(cct->_conf.get_val<string>("clog_to_syslog"),
+                         log_channel, CLOG_CONFIG_DEFAULT_KEY);
+  targets.log_channels =
+    get_value_via_strmap(cct->_conf.get_val<string>("clog_to_syslog_facility"),
+                         log_channel, CLOG_CONFIG_DEFAULT_KEY);
+  targets.log_prios =
+    get_value_via_strmap(cct->_conf.get_val<string>("clog_to_syslog_level"),
+                         log_channel, CLOG_CONFIG_DEFAULT_KEY);
+  targets.log_to_graylog =
+    get_value_via_strmap(cct->_conf.get_val<string>("clog_to_graylog"),
+                         log_channel, CLOG_CONFIG_DEFAULT_KEY);
+  targets.log_to_graylog_host =
+    get_value_via_strmap(cct->_conf.get_val<string>("clog_to_graylog_host"),
+                         log_channel, CLOG_CONFIG_DEFAULT_KEY);
+  targets.log_to_graylog_port =
+    get_value_via_strmap(cct->_conf.get_val<string>("clog_to_graylog_port"),
+                         log_channel, CLOG_CONFIG_DEFAULT_KEY);
+
+  targets.fsid = cct->_conf.get_val<uuid_d>("fsid");
+  targets.host = cct->_conf->host;
+  return targets;
+}
+
 void LogChannel::do_log(clog_type prio, std::stringstream& ss)
 {
   while (!ss.eof()) {
index c20fde4f157d67b6d34681742e099680d68940b3..688b2a57bbe26ac857db5f4e23f818c1b650f144 100644 (file)
@@ -39,16 +39,17 @@ namespace logging {
 }
 }
 
-int parse_log_client_options(CephContext *cct,
-                            std::map<std::string,std::string> &log_to_monitors,
-                            std::map<std::string,std::string> &log_to_syslog,
-                            std::map<std::string,std::string> &log_channels,
-                            std::map<std::string,std::string> &log_prios,
-                            std::map<std::string,std::string> &log_to_graylog,
-                            std::map<std::string,std::string> &log_to_graylog_host,
-                            std::map<std::string,std::string> &log_to_graylog_port,
-                            uuid_d &fsid,
-                            std::string &host);
+struct clog_targets_conf_t {
+  std::string log_to_monitors;
+  std::string log_to_syslog;
+  std::string log_channels;
+  std::string log_prios;
+  std::string log_to_graylog;
+  std::string log_to_graylog_host;
+  std::string log_to_graylog_port;
+  uuid_d fsid; // only 16B. Simpler as a copy.
+  std::string host;
+};
 
 /** Manage where we output to and at which priority
  *
@@ -153,19 +154,13 @@ public:
   typedef std::shared_ptr<LogChannel> Ref;
 
   /**
-   * update config values from parsed k/v std::map for each config option
+   * Query the configuration database in conf_cct for configuration
+   * parameters. Pick out the relevant values based on our channel name.
+   * Update the logger configuration based on these values.
    *
-   * Pick out the relevant value based on our channel.
+   * Return a collection of configuration strings.
    */
-  void update_config(std::map<std::string,std::string> &log_to_monitors,
-                    std::map<std::string,std::string> &log_to_syslog,
-                    std::map<std::string,std::string> &log_channels,
-                    std::map<std::string,std::string> &log_prios,
-                    std::map<std::string,std::string> &log_to_graylog,
-                    std::map<std::string,std::string> &log_to_graylog_host,
-                    std::map<std::string,std::string> &log_to_graylog_port,
-                    uuid_d &fsid,
-                    std::string &host);
+  clog_targets_conf_t parse_client_options(CephContext* conf_cct);
 
   void do_log(clog_type prio, std::stringstream& ss);
   void do_log(clog_type prio, const std::string& s);
@@ -181,6 +176,12 @@ private:
   bool log_to_monitors;
   std::shared_ptr<ceph::logging::Graylog> graylog;
 
+  /**
+   * update config values from parsed k/v std::map for each config option
+   */
+  void update_config(const clog_targets_conf_t& conf_strings);
+
+  clog_targets_conf_t parse_log_client_options(CephContext* conf_cct);
 };
 
 typedef LogChannel::Ref LogChannelRef;
index e2284e1e19989de7df88ea0aaf7887d6dba89ce3..09e00b6702013fa466c0f5c35b5d58a4af6980ca 100644 (file)
@@ -57,6 +57,8 @@ void get_str_vec(const string& str, vector<string>& str_vec)
 vector<string> get_str_vec(const string& str, const char *delims)
 {
   vector<string> result;
-  get_str_vec(str, delims, result);
+  for_each_substr(str, delims, [&result] (auto token) {
+      result.emplace_back(token.begin(), token.end());
+    });
   return result;
 }
index 947ad21a4b2de192c3fbbdc00b25ff124b57dccb..2ce9b541c213546801a6c6666bf02eb854539f5e 100644 (file)
@@ -26,7 +26,7 @@ using namespace std;
 int get_json_str_map(
     const string &str,
     ostream &ss,
-    map<string,string> *str_map,
+    str_map_t *str_map,
     bool fallback_to_plain)
 {
   json_spirit::mValue json;
@@ -69,31 +69,54 @@ string trim(const string& str) {
 
 int get_str_map(
     const string &str,
-    map<string,string> *str_map,
+    str_map_t* str_map,
     const char *delims)
 {
-  list<string> pairs;
-  get_str_list(str, delims, pairs);
-  for (list<string>::iterator i = pairs.begin(); i != pairs.end(); ++i) {
-    size_t equal = i->find('=');
+  auto pairs = get_str_list(str, delims);
+  for (const auto& pr : pairs) {
+    size_t equal = pr.find('=');
     if (equal == string::npos)
-      (*str_map)[*i] = string();
+      (*str_map)[pr] = string();
     else {
-      const string key = trim(i->substr(0, equal));
+      const string key = trim(pr.substr(0, equal));
       equal++;
-      const string value = trim(i->substr(equal));
+      const string value = trim(pr.substr(equal));
       (*str_map)[key] = value;
     }
   }
   return 0;
 }
 
+str_map_t get_str_map(
+  const string& str,
+  const char* delim)
+{
+  auto pairs = get_str_list(str, delim);
+  str_map_t str_map;
+
+  for (const auto& pr : pairs) {
+    auto equal = pr.find('=');
+
+    // is the format 'K=V' or just 'K'?
+    if (equal == std::string::npos) {
+      str_map[pr] = std::string{};
+    } else {
+      const string key = trim(pr.substr(0, equal));
+      equal++;
+      const string value = trim(pr.substr(equal));
+      str_map[key] = value;
+    }
+  }
+
+  return str_map;
+}
+
 string get_str_map_value(
-    const map<string,string> &str_map,
+    const str_map_t &str_map,
     const string &key,
     const string *def_val)
 {
-  map<string,string>::const_iterator p = str_map.find(key);
+  auto p = str_map.find(key);
 
   // key exists in str_map
   if (p != str_map.end()) {
@@ -105,7 +128,7 @@ string get_str_map_value(
   }
 
   // key DNE in str_map and def_val was specified
-  if (def_val != NULL)
+  if (def_val != nullptr)
     return *def_val;
 
   // key DNE in str_map, no def_val was specified
@@ -113,15 +136,15 @@ string get_str_map_value(
 }
 
 string get_str_map_key(
-    const map<string,string> &str_map,
+    const str_map_t &str_map,
     const string &key,
     const string *fallback_key)
 {
-  map<string,string>::const_iterator p = str_map.find(key);
+  auto p = str_map.find(key);
   if (p != str_map.end())
     return p->second;
 
-  if (fallback_key != NULL) {
+  if (fallback_key != nullptr) {
     p = str_map.find(*fallback_key);
     if (p != str_map.end())
       return p->second;
@@ -138,22 +161,62 @@ string get_str_map_key(
 int get_conf_str_map_helper(
     const string &str,
     ostringstream &oss,
-    map<string,string> *m,
-    const string &def_key)
+    str_map_t* str_map,
+    const string &default_key)
 {
-  int r = get_str_map(str, m);
+  get_str_map(str, str_map);
 
-  if (r < 0) {
-    return r;
-  }
-
-  if (r >= 0 && m->size() == 1) {
-    map<string,string>::iterator p = m->begin();
+  if (str_map->size() == 1) {
+    auto p = str_map->begin();
     if (p->second.empty()) {
       string s = p->first;
-      m->erase(s);
-      (*m)[def_key] = s;
+      str_map->erase(s);
+      (*str_map)[default_key] = s;
     }
   }
-  return r;
+  return 0;
+}
+
+std::string get_value_via_strmap(
+  const string& conf_string,
+  std::string_view default_key)
+{
+  auto mp = get_str_map(conf_string);
+  if (mp.size() != 1) {
+    return "";
+  }
+
+  // if the one-elem "map" is of the form { 'value' : '' }
+  // replace it with { 'default_key' : 'value' }
+  const auto& [k, v] = *(mp.begin());
+  if (v.empty()) {
+    return k;
+  }
+  return v;
+}
+
+std::string get_value_via_strmap(
+  const string& conf_string,
+  const string& key,
+  std::string_view default_key)
+{
+  auto mp = get_str_map(conf_string);
+  if (mp.size() != 1) {
+    return std::string{};
+  }
+
+  // if the one-elem "map" is of the form { 'value' : '' }
+  // replace it with { 'default_key' : 'value' }
+  const auto& [k, v] = *(mp.begin());
+  if (v.empty()) {
+    return k;
+  }
+  if (k == key) {
+    return k;
+  }
+  if (k == default_key) {
+    return v;
+  }
+
+  return string{};
 }
index 6a0370d1299cb6782d222d916e41bf073d88306e..f8bef05790217a800d2c7c84929b31c33b976f0c 100644 (file)
@@ -23,6 +23,8 @@
 #include <string>
 #include <sstream>
 
+using str_map_t = std::map<std::string,std::string>;
+
 /**
  * Parse **str** and set **str_map** with the key/value pairs read
  * from it. The format of **str** is either a well formed JSON object
  * @param [in] fallback_to_plain attempt parsing as plain-text if json fails
  * @return **0** on success or a -EINVAL on error.
  */
-extern int get_json_str_map(
+int get_json_str_map(
     const std::string &str,
     std::ostream &ss,
-    std::map<std::string,std::string> *str_map,
+    str_map_t* str_map,
     bool fallback_to_plain = true);
 
 /**
@@ -89,11 +91,16 @@ extern int get_json_str_map(
  * @param [out] str_map key/value pairs parsed from str
  * @return **0**
  */
-extern int get_str_map(
+int get_str_map(
     const std::string &str,
-    std::map<std::string,std::string> *str_map,
+    str_map_t* str_map,
     const char *delims = CONST_DELIMS);
 
+// an alternate form (as we never fail):
+str_map_t get_str_map(
+    const std::string& str,
+    const char* delim = CONST_DELIMS);
+
 /**
  * Returns the value of **key** in **str_map** if available.
  *
@@ -106,10 +113,10 @@ extern int get_str_map(
  * @param[in] key The key to search for in the map
  * @param[in] def_val The value to return in case **key** is not present
  */
-extern std::string get_str_map_value(
-    const std::map<std::string,std::string> &str_map,
+std::string get_str_map_value(
+    const str_map_t& str_map,
     const std::string &key,
-    const std::string *def_val = NULL);
+    const std::string *def_val = nullptr);
 
 /**
  * Returns the value of **key** in **str_map** if available.
@@ -127,11 +134,10 @@ extern std::string get_str_map_value(
  * @param[in] def_key Key to fallback to if **key** is not present
  *                    in **str_map**
  */
-extern std::string get_str_map_key(
-    const std::map<std::string,std::string> &str_map,
+std::string get_str_map_key(
+    const str_map_t& str_map,
     const std::string &key,
-    const std::string *fallback_key = NULL);
-
+    const std::string *fallback_key = nullptr);
 
 // This function's only purpose is to check whether a given map has only
 // ONE key with an empty value (which would mean that 'get_str_map()' read
@@ -142,7 +148,16 @@ extern std::string get_str_map_key(
 int get_conf_str_map_helper(
     const std::string &str,
     std::ostringstream &oss,
-    std::map<std::string,std::string> *m,
-    const std::string &def_key);
+    str_map_t* str_map,
+    const std::string &default_key);
+
+std::string get_value_via_strmap(
+  const std::string& conf_string,
+  std::string_view default_key);
+
+std::string get_value_via_strmap(
+  const std::string& conf_string,
+  const std::string& key,
+  std::string_view default_key);
 
 #endif
index 186b528010e790cb712ad78ef416dd9c5ee02ab9..489e6f0f70c9b9d89df64aa076da4fe46c700576 100644 (file)
@@ -3267,25 +3267,8 @@ void MDSRank::dump_clientreplay_status(Formatter *f) const
 
 void MDSRankDispatcher::update_log_config()
 {
-  map<string,string> log_to_monitors;
-  map<string,string> log_to_syslog;
-  map<string,string> log_channel;
-  map<string,string> log_prio;
-  map<string,string> log_to_graylog;
-  map<string,string> log_to_graylog_host;
-  map<string,string> log_to_graylog_port;
-  uuid_d fsid;
-  string host;
-
-  if (parse_log_client_options(g_ceph_context, log_to_monitors, log_to_syslog,
-                              log_channel, log_prio, log_to_graylog,
-                              log_to_graylog_host, log_to_graylog_port,
-                              fsid, host) == 0)
-    clog->update_config(log_to_monitors, log_to_syslog,
-                       log_channel, log_prio, log_to_graylog,
-                       log_to_graylog_host, log_to_graylog_port,
-                       fsid, host);
-  dout(10) << __func__ << " log_to_monitors " << log_to_monitors << dendl;
+  auto parsed_options = clog->parse_client_options(g_ceph_context);
+  dout(10) << __func__ << " log_to_monitors " << parsed_options.log_to_monitors << dendl;
 }
 
 void MDSRank::create_logger()
index 27b1baf8d1edbad1d4749cd955b5cd5817505a13..249cb73c9e49bf8f644d704fc32b0bdfd138ac0b 100644 (file)
@@ -1422,23 +1422,7 @@ void ActivePyModules::cluster_log(const std::string &channel, clog_type prio,
   std::lock_guard l(lock);
 
   auto cl = monc.get_log_client()->create_channel(channel);
-  map<string,string> log_to_monitors;
-  map<string,string> log_to_syslog;
-  map<string,string> log_channel;
-  map<string,string> log_prio;
-  map<string,string> log_to_graylog;
-  map<string,string> log_to_graylog_host;
-  map<string,string> log_to_graylog_port;
-  uuid_d fsid;
-  string host;
-  if (parse_log_client_options(g_ceph_context, log_to_monitors, log_to_syslog,
-                              log_channel, log_prio, log_to_graylog,
-                              log_to_graylog_host, log_to_graylog_port,
-                              fsid, host) == 0)
-    cl->update_config(log_to_monitors, log_to_syslog,
-                     log_channel, log_prio, log_to_graylog,
-                     log_to_graylog_host, log_to_graylog_port,
-                     fsid, host);
+  cl->parse_client_options(g_ceph_context);
   cl->do_log(prio, message);
 }
 
index 8e72cff04192f49e398fe9be4512f77e315fdbe5..d5866299b1470b89300d328669cb3758ec0b6bd5 100644 (file)
@@ -169,8 +169,8 @@ class DaemonState
     metadata = m;
     auto p = m.find("device_ids");
     if (p != m.end()) {
-      std::map<std::string,std::string> devs, paths; // devname -> id or path
-      get_str_map(p->second, &devs, ",; ");
+      std::map<std::string,std::string> paths; // devname -> id or path
+      auto devs = get_str_map(p->second, ",; ");
       auto q = m.find("device_paths");
       if (q != m.end()) {
        get_str_map(q->second, &paths, ",; ");
index f3d1b38770acaaaedc2bb2a83ad104ef91002f46..96c18892d0a3d1f1c2690095e510ed86b3b593d5 100644 (file)
@@ -375,29 +375,8 @@ void MgrStandby::respawn()
 
 void MgrStandby::_update_log_config()
 {
-  map<string,string> log_to_monitors;
-  map<string,string> log_to_syslog;
-  map<string,string> log_channel;
-  map<string,string> log_prio;
-  map<string,string> log_to_graylog;
-  map<string,string> log_to_graylog_host;
-  map<string,string> log_to_graylog_port;
-  uuid_d fsid;
-  string host;
-
-  if (parse_log_client_options(cct, log_to_monitors, log_to_syslog,
-                              log_channel, log_prio, log_to_graylog,
-                              log_to_graylog_host, log_to_graylog_port,
-                              fsid, host) == 0) {
-    clog->update_config(log_to_monitors, log_to_syslog,
-                       log_channel, log_prio, log_to_graylog,
-                       log_to_graylog_host, log_to_graylog_port,
-                       fsid, host);
-    audit_clog->update_config(log_to_monitors, log_to_syslog,
-                             log_channel, log_prio, log_to_graylog,
-                             log_to_graylog_host, log_to_graylog_port,
-                             fsid, host);
-  }
+  clog->parse_client_options(cct);
+  audit_clog->parse_client_options(cct);
 }
 
 void MgrStandby::handle_mgr_map(ref_t<MMgrMap> mmap)
index be3d05623a1d892925cb3b8d3f72c36e80cbe5c0..6b86a802ad6b6e93c3d13c34db54a11b418fa908 100644 (file)
@@ -674,31 +674,8 @@ void Monitor::handle_conf_change(const ConfigProxy& conf,
 
 void Monitor::update_log_clients()
 {
-  map<string,string> log_to_monitors;
-  map<string,string> log_to_syslog;
-  map<string,string> log_channel;
-  map<string,string> log_prio;
-  map<string,string> log_to_graylog;
-  map<string,string> log_to_graylog_host;
-  map<string,string> log_to_graylog_port;
-  uuid_d fsid;
-  string host;
-
-  if (parse_log_client_options(g_ceph_context, log_to_monitors, log_to_syslog,
-                              log_channel, log_prio, log_to_graylog,
-                              log_to_graylog_host, log_to_graylog_port,
-                              fsid, host))
-    return;
-
-  clog->update_config(log_to_monitors, log_to_syslog,
-                     log_channel, log_prio, log_to_graylog,
-                     log_to_graylog_host, log_to_graylog_port,
-                     fsid, host);
-
-  audit_clog->update_config(log_to_monitors, log_to_syslog,
-                           log_channel, log_prio, log_to_graylog,
-                           log_to_graylog_host, log_to_graylog_port,
-                           fsid, host);
+  clog->parse_client_options(g_ceph_context);
+  audit_clog->parse_client_options(g_ceph_context);
 }
 
 int Monitor::sanitize_options()
@@ -6643,7 +6620,7 @@ void Monitor::do_stretch_mode_election_work()
   dout(20) << "prior dead_mon_buckets: " << old_dead_buckets
           << "; down_mon_buckets: " << down_mon_buckets
           << "; up_mon_buckets: " << up_mon_buckets << dendl;
-  for (auto di : down_mon_buckets) {
+  for (const auto& di : down_mon_buckets) {
     if (!up_mon_buckets.count(di.first)) {
       dead_mon_buckets[di.first] = di.second;
     }
index ca1dc472b2197a53d96a9cabaa76c519eda3dc8d..0b2718b98d7847eecc8ccbfb086a06274c257bc2 100644 (file)
@@ -10124,25 +10124,8 @@ int OSD::mon_cmd_set_config(const std::string &key, const std::string &val)
 
 void OSD::update_log_config()
 {
-  map<string,string> log_to_monitors;
-  map<string,string> log_to_syslog;
-  map<string,string> log_channel;
-  map<string,string> log_prio;
-  map<string,string> log_to_graylog;
-  map<string,string> log_to_graylog_host;
-  map<string,string> log_to_graylog_port;
-  uuid_d fsid;
-  string host;
-
-  if (parse_log_client_options(cct, log_to_monitors, log_to_syslog,
-                              log_channel, log_prio, log_to_graylog,
-                              log_to_graylog_host, log_to_graylog_port,
-                              fsid, host) == 0)
-    clog->update_config(log_to_monitors, log_to_syslog,
-                       log_channel, log_prio, log_to_graylog,
-                       log_to_graylog_host, log_to_graylog_port,
-                       fsid, host);
-  derr << "log_to_monitors " << log_to_monitors << dendl;
+  auto parsed_options = clog->parse_client_options(cct);
+  derr << "log_to_monitors " << parsed_options.log_to_monitors << dendl;
 }
 
 void OSD::check_config()
index fb6e897c756617dd163c4521fa40c562bc28e0b6..0113b6c0b44d37dbc2e1826cbcd9fde409c07281 100644 (file)
@@ -733,14 +733,6 @@ public:
   }
 };
 
-
-static map<string,string> get_str_map(const string &str) {
-  map<string,string> m;
-  get_str_map(str, &m, ";, \t");
-  return m;
-}
-
-
 static int get_actual_key_from_conf(const DoutPrefixProvider* dpp,
                                     CephContext *cct,
                                     std::string_view key_id,
index 58f2d8728438ad58381c27dc202d99f43223ca9e..cd64794f122d83991a64910f5d1ca69c069ccf14 100644 (file)
@@ -8,6 +8,8 @@
 #ifndef CEPH_RGW_KMS_H
 #define CEPH_RGW_KMS_H
 
+#include <string>
+
 static const std::string RGW_SSE_KMS_BACKEND_TESTING = "testing";
 static const std::string RGW_SSE_KMS_BACKEND_BARBICAN = "barbican";
 static const std::string RGW_SSE_KMS_BACKEND_VAULT = "vault";