From: Kefu Chai Date: Fri, 22 Mar 2019 04:03:29 +0000 (+0800) Subject: mon: let ConfigMap::generate_entity_map() return the map X-Git-Tag: v15.0.0~115^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ccb4978e43fa736767f27a948f62683b4b4e0b68;p=ceph.git mon: let ConfigMap::generate_entity_map() return the map C++17 enforces copy elision, so no need to pass the output parameter by reference/pointer anymore. also, it would be easier if we change the output's type by putting something like auto output = config.generate_entity_map(...) Signed-off-by: Kefu Chai --- diff --git a/src/mon/ConfigMap.cc b/src/mon/ConfigMap.cc index 89be317697b33..c09f73dfa3eaa 100644 --- a/src/mon/ConfigMap.cc +++ b/src/mon/ConfigMap.cc @@ -101,12 +101,12 @@ void ConfigMap::dump(Formatter *f) const f->close_section(); } -void ConfigMap::generate_entity_map( +std::map +ConfigMap::generate_entity_map( const EntityName& name, const map& crush_location, const CrushWrapper *crush, const std::string& device_class, - std::map *out, std::map> *src) { // global, then by type, then by full name. @@ -119,6 +119,7 @@ void ConfigMap::generate_entity_map( if (q != by_id.end()) { sections.push_back(make_pair(name.to_str(), &q->second)); } + std::map> out; MaskedOption *prev = nullptr; for (auto s : sections) { for (auto& i : s.second->options) { @@ -142,13 +143,14 @@ void ConfigMap::generate_entity_map( prev->get_precision(crush) < o.get_precision(crush)) { continue; } - (*out)[i.first] = o.raw_value; + out[i.first] = o.raw_value; if (src) { (*src)[i.first] = make_pair(s.first, &o); } prev = &o; } } + return out; } bool ConfigMap::parse_mask( diff --git a/src/mon/ConfigMap.h b/src/mon/ConfigMap.h index 220715256fd50..4b061fa4b86a3 100644 --- a/src/mon/ConfigMap.h +++ b/src/mon/ConfigMap.h @@ -120,12 +120,11 @@ struct ConfigMap { by_id.clear(); } void dump(Formatter *f) const; - void generate_entity_map( + std::map generate_entity_map( const EntityName& name, const map& crush_location, const CrushWrapper *crush, const std::string& device_class, - std::map *out, std::map> *src=0); static bool parse_mask( diff --git a/src/mon/ConfigMonitor.cc b/src/mon/ConfigMonitor.cc index 3e08b8a49f0ca..2f519def0ed2c 100644 --- a/src/mon/ConfigMonitor.cc +++ b/src/mon/ConfigMonitor.cc @@ -276,14 +276,13 @@ bool ConfigMonitor::preprocess_command(MonOpRequestRef op) << " class " << device_class << dendl; } - std::map config; std::map> src; - config_map.generate_entity_map( + auto config = config_map.generate_entity_map( entity, crush_location, mon->osdmon()->osdmap.crush.get(), device_class, - &config, &src); + &src); if (cmd_getval(g_ceph_context, cmdmap, "key", name)) { // get a single value @@ -419,13 +418,11 @@ void ConfigMonitor::handle_get_config(MonOpRequestRef op) const OSDMap& osdmap = mon->osdmon()->osdmap; map crush_location; osdmap.crush->get_full_location(m->host, &crush_location); - map out; - config_map.generate_entity_map( + auto out = config_map.generate_entity_map( m->name, crush_location, osdmap.crush.get(), - m->device_class, - &out); + m->device_class); dout(20) << " config is " << out << dendl; m->get_connection()->send_message(new MConfig(out)); } @@ -770,13 +767,11 @@ void ConfigMonitor::load_config() const OSDMap& osdmap = mon->osdmon()->osdmap; map crush_location; osdmap.crush->get_full_location(g_conf()->host, &crush_location); - map out; - config_map.generate_entity_map( + auto out = config_map.generate_entity_map( g_conf()->name, crush_location, osdmap.crush.get(), - string(), // no device class - &out); + string{}); // no device class g_conf().set_mon_vals(g_ceph_context, out, nullptr); } } @@ -832,13 +827,11 @@ bool ConfigMonitor::refresh_config(MonSession *s) dout(20) << __func__ << " " << s->entity_name << " crush " << crush_location << " device_class " << device_class << dendl; - map out; - config_map.generate_entity_map( + auto out = config_map.generate_entity_map( s->entity_name, crush_location, osdmap.crush.get(), - device_class, - &out); + device_class); if (out == s->last_config && s->any_config) { dout(20) << __func__ << " no change, " << out << dendl; @@ -846,7 +839,7 @@ bool ConfigMonitor::refresh_config(MonSession *s) } dout(20) << __func__ << " " << out << dendl; - s->last_config = out; + s->last_config = std::move(out); s->any_config = true; return true; }