diff options
author | Sage Weil <sage@inktank.com> | 2013-01-27 19:40:42 -0800 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-01-28 17:13:59 -0800 |
commit | 75f6ba56e1862900eede1ef81425ef36789390c0 (patch) | |
tree | e921360f3742cc432b953266006f862366fb83a6 | |
parent | fa421cf5f52ca16fa1328dbea2f4bda85c56cd3f (diff) | |
download | ceph-75f6ba56e1862900eede1ef81425ef36789390c0.tar.gz |
crush: implement get_children(), get_immediate_parent_id()
Signed-off-by: Sage Weil <sage@inktank.com>
-rw-r--r-- | src/crush/CrushWrapper.cc | 37 | ||||
-rw-r--r-- | src/crush/CrushWrapper.h | 8 |
2 files changed, 41 insertions, 4 deletions
diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 3bae96c8689..45e4fb53de6 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -202,6 +202,23 @@ map<int, string> CrushWrapper::get_parent_hierarchy(int id) return parent_hierarchy; } +int CrushWrapper::get_children(int id, list<int> *children) +{ + // leaf? + if (id >= 0) { + return 0; + } + + crush_bucket *b = get_bucket(id); + if (!b) { + return -ENOENT; + } + + for (unsigned n=0; n<b->size; n++) { + children->push_back(b->items[n]); + } + return b->size; +} int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string name, @@ -426,24 +443,36 @@ pair<string,string> CrushWrapper::get_immediate_parent(int id) { pair <string, string> loc; - for (int bidx = 0; bidx < crush->max_buckets; bidx++) { crush_bucket *b = crush->buckets[bidx]; if (b == 0) continue; for (unsigned i = 0; i < b->size; i++) - if (b->items[i] == id){ + if (b->items[i] == id) { string parent_id = name_map[b->id]; string parent_bucket_type = type_map[b->type]; loc = make_pair(parent_bucket_type, parent_id); } } - return loc; } - +int CrushWrapper::get_immediate_parent_id(int id, int *parent) +{ + for (int bidx = 0; bidx < crush->max_buckets; bidx++) { + crush_bucket *b = crush->buckets[bidx]; + if (b == 0) + continue; + for (unsigned i = 0; i < b->size; i++) { + if (b->items[i] == id) { + *parent = b->id; + return 0; + } + } + } + return -ENOENT; +} void CrushWrapper::reweight(CephContext *cct) { diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 56bcb598ff3..7def6e4ab34 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -284,6 +284,7 @@ public: * returns the (type, name) of the parent bucket of id */ pair<string,string> get_immediate_parent(int id); + int get_immediate_parent_id(int id, int *parent); /** * get the fully qualified location of a device by successively finding @@ -302,6 +303,13 @@ public: */ map<int, string> get_parent_hierarchy(int id); + /** + * enumerate immediate children of given node + * + * @param id parent bucket or device id + * @return number of items, or error + */ + int get_children(int id, list<int> *children); /** * insert an item into the map at a specific position |