]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: add more constness to CrushWrapper 17360/head
authorKefu Chai <kchai@redhat.com>
Wed, 30 Aug 2017 07:28:49 +0000 (15:28 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 30 Aug 2017 07:31:56 +0000 (15:31 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index 4a73b6feba24228afbfc648175658f7605075df2..e1b0723a11768ac561f96d4e73658a387505f348 100644 (file)
@@ -591,7 +591,7 @@ int CrushWrapper::remove_item_under(
 }
 
 int CrushWrapper::get_common_ancestor_distance(CephContext *cct, int id,
-                              const std::multimap<string,string>& loc)
+                              const std::multimap<string,string>& loc) const
 {
   ldout(cct, 5) << __func__ << " " << id << " " << loc << dendl;
   if (!item_exists(id))
@@ -704,7 +704,7 @@ bool CrushWrapper::check_item_loc(CephContext *cct, int item, const map<string,s
   return false;
 }
 
-map<string, string> CrushWrapper::get_full_location(int id)
+map<string, string> CrushWrapper::get_full_location(int id) const
 {
   vector<pair<string, string> > full_location_ordered;
   map<string,string> full_location;
@@ -718,7 +718,7 @@ map<string, string> CrushWrapper::get_full_location(int id)
   return full_location;
 }
 
-int CrushWrapper::get_full_location_ordered(int id, vector<pair<string, string> >& path)
+int CrushWrapper::get_full_location_ordered(int id, vector<pair<string, string> >& path) const
 {
   if (!item_exists(id))
     return -ENOENT;
@@ -734,7 +734,7 @@ int CrushWrapper::get_full_location_ordered(int id, vector<pair<string, string>
   return 0;
 }
 
-string CrushWrapper::get_full_location_ordered_string(int id)
+string CrushWrapper::get_full_location_ordered_string(int id) const
 {
   vector<pair<string, string> > full_location_ordered;
   string full_location;
@@ -749,7 +749,7 @@ string CrushWrapper::get_full_location_ordered_string(int id)
   return full_location;
 }
 
-map<int, string> CrushWrapper::get_parent_hierarchy(int id)
+map<int, string> CrushWrapper::get_parent_hierarchy(int id) const
 {
   map<int,string> parent_hierarchy;
   pair<string, string> parent_coord = get_immediate_parent(id);
@@ -784,14 +784,14 @@ map<int, string> CrushWrapper::get_parent_hierarchy(int id)
   return parent_hierarchy;
 }
 
-int CrushWrapper::get_children(int id, list<int> *children)
+int CrushWrapper::get_children(int id, list<int> *children) const
 {
   // leaf?
   if (id >= 0) {
     return 0;
   }
 
-  crush_bucket *b = get_bucket(id);
+  auto *b = get_bucket(id);
   if (IS_ERR(b)) {
     return -ENOENT;
   }
@@ -802,7 +802,7 @@ int CrushWrapper::get_children(int id, list<int> *children)
   return b->size;
 }
 
-int CrushWrapper::_get_leaves(int id, list<int> *leaves)
+int CrushWrapper::_get_leaves(int id, list<int> *leaves) const
 {
   assert(leaves);
 
@@ -812,7 +812,7 @@ int CrushWrapper::_get_leaves(int id, list<int> *leaves)
     return 0;
   }
 
-  crush_bucket *b = get_bucket(id);
+  auto b = get_bucket(id);
   if (IS_ERR(b)) {
     return -ENOENT;
   }
@@ -832,7 +832,7 @@ int CrushWrapper::_get_leaves(int id, list<int> *leaves)
   return 0; // all is well
 }
 
-int CrushWrapper::get_leaves(const string &name, set<int> *leaves)
+int CrushWrapper::get_leaves(const string &name, set<int> *leaves) const
 {
   assert(leaves);
   leaves->clear();
@@ -1332,7 +1332,7 @@ bool CrushWrapper::check_item_present(int id) const
 }
 
 
-pair<string,string> CrushWrapper::get_immediate_parent(int id, int *_ret)
+pair<string,string> CrushWrapper::get_immediate_parent(int id, int *_ret) const
 {
 
   for (int bidx = 0; bidx < crush->max_buckets; bidx++) {
@@ -1343,8 +1343,8 @@ pair<string,string> CrushWrapper::get_immediate_parent(int id, int *_ret)
       continue;
     for (unsigned i = 0; i < b->size; i++)
       if (b->items[i] == id) {
-        string parent_id = name_map[b->id];
-        string parent_bucket_type = type_map[b->type];
+        string parent_id = name_map.at(b->id);
+        string parent_bucket_type = type_map.at(b->type);
         if (_ret)
           *_ret = 0;
         return make_pair(parent_bucket_type, parent_id);
index 3737d57300230404dd6b086861a2d10fd28c5941..cefcd8fee17f3e584bd1d5c3793715afad6eeb0b 100644 (file)
@@ -664,7 +664,7 @@ public:
    *
    * FIXME: ambiguous for items that occur multiple times in the map
    */
-  pair<string,string> get_immediate_parent(int id, int *ret = NULL);
+  pair<string,string> get_immediate_parent(int id, int *ret = NULL) const;
 
   int get_immediate_parent_id(int id, int *parent) const;
 
@@ -683,7 +683,7 @@ public:
    * returns the location in the form of (type=foo) where type is a type of bucket
    * specified in the CRUSH map and foo is a name specified in the CRUSH map
    */
-  map<string, string> get_full_location(int id);
+  map<string, string> get_full_location(int id) const;
 
   /*
    * identical to get_full_location(int id) although it returns the type/name
@@ -691,7 +691,7 @@ public:
    *
    * returns -ENOENT if id is not found.
    */
-  int get_full_location_ordered(int id, vector<pair<string, string> >& path);
+  int get_full_location_ordered(int id, vector<pair<string, string> >& path) const;
 
   /*
    * identical to get_full_location_ordered(int id, vector<pair<string, string> >& path),
@@ -700,13 +700,13 @@ public:
    *
    * returns the location in descending hierarchy as a string.
    */
-  string get_full_location_ordered_string(int id);
+  string get_full_location_ordered_string(int id) const;
 
   /**
    * returns (type_id, type) of all parent buckets between id and
    * default, can be used to check for anomolous CRUSH maps
    */
-  map<int, string> get_parent_hierarchy(int id);
+  map<int, string> get_parent_hierarchy(int id) const;
 
   /**
    * enumerate immediate children of given node
@@ -714,7 +714,7 @@ public:
    * @param id parent bucket or device id
    * @return number of items, or error
    */
-  int get_children(int id, list<int> *children);
+  int get_children(int id, list<int> *children) const;
 
   /**
     * enumerate leaves(devices) of given node
@@ -722,9 +722,12 @@ public:
     * @param name parent bucket name
     * @return 0 on success or a negative errno on error.
     */
-  int get_leaves(const string &name, set<int> *leaves);
-  int _get_leaves(int id, list<int> *leaves); // worker
+  int get_leaves(const string &name, set<int> *leaves) const;
 
+private:
+  int _get_leaves(int id, list<int> *leaves) const; // worker
+
+public:
   /**
    * insert an item into the map at a specific position
    *
@@ -868,7 +871,7 @@ public:
    * @param loc a set of key=value pairs describing a location in the hierarchy
    */
   int get_common_ancestor_distance(CephContext *cct, int id,
-                                  const std::multimap<string,string>& loc);
+                                  const std::multimap<string,string>& loc) const;
 
   /**
    * parse a set of key/value pairs out of a string vector