]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: improve constness of CrushWrapper methods
authorLoic Dachary <loic-201408@dachary.org>
Thu, 16 Oct 2014 00:02:58 +0000 (17:02 -0700)
committerSage Weil <sage@redhat.com>
Fri, 13 Feb 2015 16:32:00 +0000 (08:32 -0800)
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 <loic-201408@dachary.org>
(cherry picked from commit 236895eea65f8706baa5fdef96fb00ad5b82218c)

src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index 2ed3935e52d9f4e3e527a9217d1a412b77f66023..805a0c6cb4a99ba251636a8e2808989881b94630 100644 (file)
@@ -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;
 
index 135de32729dce1233d7c543715c8350bc8e34b8e..9fac2fe443ab64f170dff92e43be16842dcb2ee1 100644 (file)
@@ -59,16 +59,16 @@ public:
 private:
   struct crush_map *crush;
   /* reverse maps */
-  bool have_rmaps;
-  std::map<string, int> type_rmap, name_rmap, rule_name_rmap;
-  void build_rmaps() {
+  mutable bool have_rmaps;
+  mutable std::map<string, int> 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<int, string> &f, std::map<string, int> &r) {
+  void build_rmap(const map<int, string> &f, std::map<string, int> &r) const {
     r.clear();
     for (std::map<int, string>::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<string,string> &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 ***/