crush: change find_roots(); add find_takes()

The find_roots() was looking for nodes referenced by 'take', but those
aren't necessarily roots, which is what the callers actually want.

Rename to find_takes() and add a real find_roots().  Not very efficient,
but we don't care.

Signed-off-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Sage Weil 2013-03-22 14:23:37 -07:00
parent 751b4bf89f
commit 683f745c14
2 changed files with 26 additions and 3 deletions

View File

@ -7,7 +7,7 @@
#define dout_subsys ceph_subsys_crush
void CrushWrapper::find_roots(set<int>& roots) const
void CrushWrapper::find_takes(set<int>& roots) const
{
for (unsigned i=0; i<crush->max_rules; i++) {
crush_rule *r = crush->rules[i];
@ -20,6 +20,17 @@ void CrushWrapper::find_roots(set<int>& roots) const
}
}
void CrushWrapper::find_roots(set<int>& roots) const
{
for (int i = 0; i < crush->max_buckets; i++) {
if (!crush->buckets[i])
continue;
crush_bucket *b = crush->buckets[i];
if (!_search_item_exists(b->id))
roots.insert(b->id);
}
}
bool CrushWrapper::subtree_contains(int root, int item) const
{
if (root == item)
@ -86,7 +97,7 @@ int CrushWrapper::remove_item(CephContext *cct, int item)
return ret;
}
bool CrushWrapper::_search_item_exists(int item)
bool CrushWrapper::_search_item_exists(int item) const
{
for (int i = 0; i < crush->max_buckets; i++) {
if (!crush->buckets[i])

View File

@ -230,6 +230,18 @@ public:
}
/**
* find tree nodes referenced by rules by a 'take' command
*
* Note that these may not be parentless roots.
*/
void find_takes(set<int>& roots) const;
/**
* find tree roots
*
* These are parentless nodes in the map.
*/
void find_roots(set<int>& roots) const;
/**
@ -248,7 +260,7 @@ private:
* @param i item
* @return true if present
*/
bool _search_item_exists(int i);
bool _search_item_exists(int i) const;
public:
/**