From: Loic Dachary Date: Thu, 16 Oct 2014 00:02:58 +0000 (-0700) Subject: crush: improve constness of CrushWrapper methods X-Git-Tag: v0.80.9~11^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=247afa4efe7d11b5ef06e094680b50ea30d7d5e3;p=ceph.git crush: improve constness of CrushWrapper methods A number of CrushWrapper get methods or predicates were not const because they need to maintain transparently the rmaps. Make the rmaps mutable and update the constness of the methods to match what the caller would expect. Signed-off-by: Loic Dachary (cherry picked from commit 236895eea65f8706baa5fdef96fb00ad5b82218c) --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 2ed3935e52d9..805a0c6cb4a9 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -643,7 +643,7 @@ int CrushWrapper::update_item(CephContext *cct, int item, float weight, string n return ret; } -int CrushWrapper::get_item_weight(int id) +int CrushWrapper::get_item_weight(int id) const { for (int bidx = 0; bidx < crush->max_buckets; bidx++) { crush_bucket *b = crush->buckets[bidx]; @@ -722,7 +722,7 @@ int CrushWrapper::adjust_item_weight_in_loc(CephContext *cct, int id, int weight return changed; } -bool CrushWrapper::check_item_present(int id) +bool CrushWrapper::check_item_present(int id) const { bool found = false; diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 135de32729dc..9fac2fe443ab 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -59,16 +59,16 @@ public: private: struct crush_map *crush; /* reverse maps */ - bool have_rmaps; - std::map type_rmap, name_rmap, rule_name_rmap; - void build_rmaps() { + mutable bool have_rmaps; + mutable std::map type_rmap, name_rmap, rule_name_rmap; + void build_rmaps() const { if (have_rmaps) return; build_rmap(type_map, type_rmap); build_rmap(name_map, name_rmap); build_rmap(rule_name_map, rule_name_rmap); have_rmaps = true; } - void build_rmap(const map &f, std::map &r) { + void build_rmap(const map &f, std::map &r) const { r.clear(); for (std::map::const_iterator p = f.begin(); p != f.end(); ++p) r[p->second] = p->first; @@ -237,7 +237,7 @@ public: int get_num_type_names() const { return type_map.size(); } - int get_type_id(const string& name) { + int get_type_id(const string& name) const { build_rmaps(); if (type_rmap.count(name)) return type_rmap[name]; @@ -256,14 +256,14 @@ public: } // item/bucket names - bool name_exists(const string& name) { + bool name_exists(const string& name) const { build_rmaps(); return name_rmap.count(name); } bool item_exists(int i) { return name_map.count(i); } - int get_item_id(const string& name) { + int get_item_id(const string& name) const { build_rmaps(); if (name_rmap.count(name)) return name_rmap[name]; @@ -285,11 +285,11 @@ public: } // rule names - bool rule_exists(string name) { + bool rule_exists(string name) const { build_rmaps(); return rule_name_rmap.count(name); } - int get_rule_id(string name) { + int get_rule_id(string name) const { build_rmaps(); if (rule_name_rmap.count(name)) return rule_name_rmap[name]; @@ -556,8 +556,8 @@ public: * @param id item id to check * @return weight of item */ - int get_item_weight(int id); - float get_item_weightf(int id) { + int get_item_weight(int id) const; + float get_item_weightf(int id) const { return (float)get_item_weight(id) / (float)0x10000; } int get_item_weight_in_loc(int id, const map &loc); @@ -576,7 +576,7 @@ public: void reweight(CephContext *cct); /// check if item id is present in the map hierarchy - bool check_item_present(int id); + bool check_item_present(int id) const; /*** devices ***/