]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon/ConfigMap: use ValueSource type for generate_entity_map()
authorSage Weil <sage@newdream.net>
Tue, 16 Nov 2021 21:04:01 +0000 (16:04 -0500)
committerMatan Breizman <mbreizma@redhat.com>
Mon, 16 Oct 2023 12:18:07 +0000 (12:18 +0000)
Changes from original commit:
- switch to unordered map
- use nullptr instead of 0

Signed-off-by: Sage Weil <sage@newdream.net>
Signed-off-by: Matan Breizman <mbreizma@redhat.com>
(cherry picked from commit e36da92118eac4d2af11d8a8a1795e7b08d08874)

src/mgr/ActivePyModules.cc
src/mon/ConfigMap.cc
src/mon/ConfigMap.h
src/mon/ConfigMonitor.cc

index 45038e734afcf90c15c0e54e01757ddb4aeef7b7..701b41bef8e1ce099ae9fe73f1da73c86d5b38df 100644 (file)
@@ -1198,13 +1198,11 @@ PyObject *ActivePyModules::get_foreign_config(
                 << " class " << device_class << dendl;
       }
 
-      std::map<std::string,pair<std::string,const MaskedOption*>> src;
       config = config_map.generate_entity_map(
        entity,
        crush_location,
        osdmap.crush.get(),
-       device_class,
-       &src);
+       device_class);
     });
 
   // get a single value
index 7a639947bdef393230577f1a0ad0001902e27630..dff1a94c1e6fc3e300eb1cc62695c16c6d9d1582 100644 (file)
@@ -136,7 +136,7 @@ ConfigMap::generate_entity_map(
   const map<std::string,std::string>& crush_location,
   const CrushWrapper *crush,
   const std::string& device_class,
-  std::map<std::string,pair<std::string,const MaskedOption*>> *src)
+  std::unordered_map<std::string, ValueSource> *src)
 {
   // global, then by type, then by name prefix component(s), then name.
   // name prefix components are .-separated,
@@ -185,7 +185,7 @@ ConfigMap::generate_entity_map(
       }
       out[i.first] = o.raw_value;
       if (src) {
-       (*src)[i.first] = make_pair(s.first, &o);
+       (*src).emplace(i.first, ConfigMap::ValueSource(s.first, &o));
       }
       prev = &o;
     }
index 34af942a61e05d3336a4d714d1a558d4baea9833..bf2bd97c0ba38f9533841c26b5788a448f9cc7e4 100644 (file)
@@ -99,6 +99,14 @@ struct Section {
 };
 
 struct ConfigMap {
+  struct ValueSource {
+    std::string section;
+    const MaskedOption *option = nullptr;
+    ValueSource() {}
+    ValueSource(const std::string& s, const MaskedOption *o)
+      : section(s), option(o) {}
+  };
+
   Section global;
   std::map<std::string,Section, std::less<>> by_type;
   std::map<std::string,Section, std::less<>> by_id;
@@ -125,12 +133,13 @@ struct ConfigMap {
     stray_options.clear();
   }
   void dump(ceph::Formatter *f) const;
+
   std::map<std::string,std::string,std::less<>> generate_entity_map(
     const EntityName& name,
     const std::map<std::string,std::string>& crush_location,
     const CrushWrapper *crush,
     const std::string& device_class,
-    std::map<std::string,std::pair<std::string,const MaskedOption*>> *src=0);
+    std::unordered_map<std::string,ValueSource> *src = nullptr);
 
   void parse_key(
     const std::string& key,
index 7f52b9d7ef73df091228382b2ab9dea81b48ef62..a5f61cbea529219f7f82f4e9ddc5831f4c88e2fa 100644 (file)
@@ -314,7 +314,7 @@ bool ConfigMonitor::preprocess_command(MonOpRequestRef op)
               << " class " << device_class << dendl;
     }
 
-    std::map<std::string,pair<std::string,const MaskedOption*>> src;
+    std::unordered_map<std::string,ConfigMap::ValueSource> src;
     auto config = config_map.generate_entity_map(
       entity,
       crush_location,
@@ -378,20 +378,20 @@ bool ConfigMonitor::preprocess_command(MonOpRequestRef op)
          continue;
        }
        if (!f) {
-         tbl << q->second.first;
-         tbl << q->second.second->mask.to_str();
-         tbl << Option::level_to_str(q->second.second->opt->level);
+         tbl << q->second.section;
+         tbl << q->second.option->mask.to_str();
+         tbl << Option::level_to_str(q->second.option->opt->level);
          tbl << p->first;
          tbl << p->second;
-         tbl << (q->second.second->opt->can_update_at_runtime() ? "" : "*");
+         tbl << (q->second.option->opt->can_update_at_runtime() ? "" : "*");
          tbl << TextTable::endrow;
        } else {
          f->open_object_section(p->first.c_str());
          f->dump_string("value", p->second);
-         f->dump_string("section", q->second.first);
-         f->dump_object("mask", q->second.second->mask);
+         f->dump_string("section", q->second.section);
+         f->dump_object("mask", q->second.option->mask);
          f->dump_bool("can_update_at_runtime",
-                      q->second.second->opt->can_update_at_runtime());
+                      q->second.option->opt->can_update_at_runtime());
          f->close_section();
        }
       }