diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index c9f69bd78d4..8d33839bbb7 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -65,7 +65,7 @@ int CrushWrapper::remove_item(CephContext *cct, int item) return ret; } -bool CrushWrapper::check_item_loc(CephContext *cct, int item, map& loc, +bool CrushWrapper::check_item_loc(CephContext *cct, int item, const map& loc, int *weight) { ldout(cct, 5) << "check_item_loc item " << item << " loc " << loc << dendl; @@ -76,20 +76,21 @@ bool CrushWrapper::check_item_loc(CephContext *cct, int item, map continue; // ignore types that aren't specified in loc - if (loc.count(p->second) == 0) { + map::const_iterator q = loc.find(p->second); + if (q == loc.end()) { ldout(cct, 2) << "warning: did not specify location for '" << p->second << "' level (levels are " << type_map << ")" << dendl; continue; } - if (!name_exists(loc[p->second].c_str())) { - ldout(cct, 5) << "check_item_loc bucket " << loc[p->second] << " dne" << dendl; + if (!name_exists(q->second)) { + ldout(cct, 5) << "check_item_loc bucket " << q->second << " dne" << dendl; return false; } - int id = get_item_id(loc[p->second].c_str()); + int id = get_item_id(q->second); if (id >= 0) { - ldout(cct, 5) << "check_item_loc requested " << loc[p->second] << " for type " << p->second + ldout(cct, 5) << "check_item_loc requested " << q->second << " for type " << p->second << " is a device, not bucket" << dendl; return false; } @@ -185,7 +186,7 @@ map CrushWrapper::get_parent_hierarchy(int id) int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string name, - map& loc) // typename -> bucketname + const map& loc) // typename -> bucketname { ldout(cct, 5) << "insert_item item " << item << " weight " << weight @@ -207,22 +208,23 @@ int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string n continue; // skip types that are unspecified - if (loc.count(p->second) == 0) { + map::const_iterator q = loc.find(p->second); + if (q == loc.end()) { ldout(cct, 2) << "warning: did not specify location for '" << p->second << "' level (levels are " << type_map << ")" << dendl; continue; } - if (!name_exists(loc[p->second].c_str())) { - ldout(cct, 5) << "insert_item creating bucket " << loc[p->second] << dendl; + if (!name_exists(q->second)) { + ldout(cct, 5) << "insert_item creating bucket " << q->second << dendl; int empty = 0; cur = add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, p->first, 1, &cur, &empty); - set_item_name(cur, loc[p->second].c_str()); + set_item_name(cur, q->second); continue; } // add to an existing bucket - int id = get_item_id(loc[p->second].c_str()); + int id = get_item_id(q->second); if (!bucket_exists(id)) { ldout(cct, 1) << "insert_item doesn't have bucket " << id << dendl; return -EINVAL; @@ -258,7 +260,7 @@ int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string n return -EINVAL; } -int CrushWrapper::move_bucket(CephContext *cct, int id, map& loc) +int CrushWrapper::move_bucket(CephContext *cct, int id, const map& loc) { // sorry this only works for buckets if (id >= 0) @@ -283,7 +285,7 @@ int CrushWrapper::move_bucket(CephContext *cct, int id, map& loc) } int CrushWrapper::create_or_move_item(CephContext *cct, int item, float weight, string name, - map& loc) // typename -> bucketname + const map& loc) // typename -> bucketname { int ret = 0; int old_iweight; @@ -305,7 +307,7 @@ int CrushWrapper::create_or_move_item(CephContext *cct, int item, float weight, } int CrushWrapper::update_item(CephContext *cct, int item, float weight, string name, - map& loc) // typename -> bucketname + const map& loc) // typename -> bucketname { ldout(cct, 5) << "update_item item " << item << " weight " << weight << " name " << name << " loc " << loc << dendl; diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 5531ece0719..e8120931103 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -228,8 +228,8 @@ public: * @param weight optional pointer to weight of item at that location * @return true if item is at specified location */ - bool check_item_loc(CephContext *cct, int item, map& loc, int *iweight); - bool check_item_loc(CephContext *cct, int item, map& loc, float *weight) { + bool check_item_loc(CephContext *cct, int item, const map& loc, int *iweight); + bool check_item_loc(CephContext *cct, int item, const map& loc, float *weight) { int iweight; bool ret = check_item_loc(cct, item, loc, &iweight); if (weight) @@ -291,7 +291,7 @@ public: * @param loc location (map of type to bucket names) * @return 0 for success, negative on error */ - int insert_item(CephContext *cct, int id, float weight, string name, map& loc); + int insert_item(CephContext *cct, int id, float weight, string name, const map& loc); /** * move a bucket in the hierarchy to the given location @@ -304,7 +304,7 @@ public: * @param loc location (map of type to bucket names) * @return 0 for success, negative on error */ - int move_bucket(CephContext *cct, int id, map& loc); + int move_bucket(CephContext *cct, int id, const map& loc); /** * add or update an item's position in the map @@ -319,7 +319,7 @@ public: * @param loc location (map of type to bucket names) * @return 0 for no change, 1 for successful change, negative on error */ - int update_item(CephContext *cct, int id, float weight, string name, map& loc); + int update_item(CephContext *cct, int id, float weight, string name, const map& loc); /** * create or move an item, but do not adjust its weight if it already exists @@ -332,7 +332,7 @@ public: * @return 0 for no change, 1 for successful change, negative on error */ int create_or_move_item(CephContext *cct, int item, float weight, string name, - map& loc); + const map& loc); /** * remove an item from the map