From a412990d594905a414f1c29d583dc2092ac1cbc4 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 30 Aug 2017 15:28:49 +0800 Subject: [PATCH] crush: add more constness to CrushWrapper Signed-off-by: Kefu Chai --- src/crush/CrushWrapper.cc | 26 +++++++++++++------------- src/crush/CrushWrapper.h | 21 ++++++++++++--------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 4a73b6feba242..e1b0723a11768 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -591,7 +591,7 @@ int CrushWrapper::remove_item_under( } int CrushWrapper::get_common_ancestor_distance(CephContext *cct, int id, - const std::multimap& loc) + const std::multimap& 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 CrushWrapper::get_full_location(int id) +map CrushWrapper::get_full_location(int id) const { vector > full_location_ordered; map full_location; @@ -718,7 +718,7 @@ map CrushWrapper::get_full_location(int id) return full_location; } -int CrushWrapper::get_full_location_ordered(int id, vector >& path) +int CrushWrapper::get_full_location_ordered(int id, vector >& path) const { if (!item_exists(id)) return -ENOENT; @@ -734,7 +734,7 @@ int CrushWrapper::get_full_location_ordered(int id, vector return 0; } -string CrushWrapper::get_full_location_ordered_string(int id) +string CrushWrapper::get_full_location_ordered_string(int id) const { vector > full_location_ordered; string full_location; @@ -749,7 +749,7 @@ string CrushWrapper::get_full_location_ordered_string(int id) return full_location; } -map CrushWrapper::get_parent_hierarchy(int id) +map CrushWrapper::get_parent_hierarchy(int id) const { map parent_hierarchy; pair parent_coord = get_immediate_parent(id); @@ -784,14 +784,14 @@ map CrushWrapper::get_parent_hierarchy(int id) return parent_hierarchy; } -int CrushWrapper::get_children(int id, list *children) +int CrushWrapper::get_children(int id, list *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 *children) return b->size; } -int CrushWrapper::_get_leaves(int id, list *leaves) +int CrushWrapper::_get_leaves(int id, list *leaves) const { assert(leaves); @@ -812,7 +812,7 @@ int CrushWrapper::_get_leaves(int id, list *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 *leaves) return 0; // all is well } -int CrushWrapper::get_leaves(const string &name, set *leaves) +int CrushWrapper::get_leaves(const string &name, set *leaves) const { assert(leaves); leaves->clear(); @@ -1332,7 +1332,7 @@ bool CrushWrapper::check_item_present(int id) const } -pair CrushWrapper::get_immediate_parent(int id, int *_ret) +pair CrushWrapper::get_immediate_parent(int id, int *_ret) const { for (int bidx = 0; bidx < crush->max_buckets; bidx++) { @@ -1343,8 +1343,8 @@ pair 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); diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 3737d57300230..cefcd8fee17f3 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -664,7 +664,7 @@ public: * * FIXME: ambiguous for items that occur multiple times in the map */ - pair get_immediate_parent(int id, int *ret = NULL); + pair 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 get_full_location(int id); + map 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 >& path); + int get_full_location_ordered(int id, vector >& path) const; /* * identical to get_full_location_ordered(int id, vector >& 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 get_parent_hierarchy(int id); + map 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 *children); + int get_children(int id, list *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 *leaves); - int _get_leaves(int id, list *leaves); // worker + int get_leaves(const string &name, set *leaves) const; +private: + int _get_leaves(int id, list *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& loc); + const std::multimap& loc) const; /** * parse a set of key/value pairs out of a string vector -- 2.39.5