diff options
author | Yuri Weinstein <yuri.weinstein@gmail.com> | 2017-06-14 22:11:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-14 22:11:58 +0200 |
commit | 3ace41f8d218b23c40cb871e229f08e5db8d5f68 (patch) | |
tree | fd5c13265b81ded2f9cb6f7cd2399f12710bef35 /src/crush | |
parent | Merge pull request #15535 from gregsfortytwo/wip-jumbo-ping (diff) | |
parent | mon/OSDMonitor: wildcard support for osd down/out/in/remove commands (diff) | |
download | ceph-3ace41f8d218b23c40cb871e229f08e5db8d5f68.tar.xz ceph-3ace41f8d218b23c40cb871e229f08e5db8d5f68.zip |
Merge pull request #15381 from xiexingguo/wip-noout-osdlist
mon/OSDMonitor: batch OSDs nodown/noout support
Reviewed-by: Josh Durgin <jdurgin@redhat.com>
Reviewed-by: Sage Weil <sage@redhat.com>
Reviewed-by: Piotr Dałek <piotr.dalek@corp.ovh.com>
Diffstat (limited to 'src/crush')
-rw-r--r-- | src/crush/CrushWrapper.cc | 58 | ||||
-rw-r--r-- | src/crush/CrushWrapper.h | 9 |
2 files changed, 67 insertions, 0 deletions
diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 1e84904ba4f..0def97e1b37 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -677,6 +677,64 @@ int CrushWrapper::get_children(int id, list<int> *children) return b->size; } +int CrushWrapper::_get_leaves(int id, list<int> *leaves) +{ + assert(leaves); + + // Already leaf? + if (id >= 0) { + leaves->push_back(id); + return 0; + } + + crush_bucket *b = get_bucket(id); + if (IS_ERR(b)) { + return -ENOENT; + } + + for (unsigned n = 0; n < b->size; n++) { + if (b->items[n] >= 0) { + leaves->push_back(b->items[n]); + } else { + // is a bucket, do recursive call + int r = _get_leaves(b->items[n], leaves); + if (r < 0) { + return r; + } + } + } + + return 0; // all is well +} + +int CrushWrapper::get_leaves(const string &name, set<int> *leaves) +{ + assert(leaves); + leaves->clear(); + + if (!name_exists(name)) { + return -ENOENT; + } + + int id = get_item_id(name); + if (id >= 0) { + // already leaf + leaves->insert(id); + return 0; + } + + list<int> unordered; + int r = _get_leaves(id, &unordered); + if (r < 0) { + return r; + } + + for (auto &p : unordered) { + leaves->insert(p); + } + + return 0; +} int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string name, const map<string,string>& loc) // typename -> bucketname diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 0e48b8c8f66..b4a3bc19ca7 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -637,6 +637,15 @@ public: int get_children(int id, list<int> *children); /** + * enumerate leaves(devices) of given node + * + * @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 + + /** * insert an item into the map at a specific position * * Add an item as a specific location of the hierarchy. |