Signed-off-by: Sage Weil <sage@redhat.com>
return -ENOENT;
}
+int CrushWrapper::get_parent_of_type(int item, int type) const
+{
+ do {
+ int r = get_immediate_parent_id(item, &item);
+ if (r < 0) {
+ return 0;
+ }
+ } while (get_bucket_type(item) != type);
+ return item;
+}
+
bool CrushWrapper::class_is_in_use(int class_id)
{
for (auto &i : class_bucket)
pair<string,string> get_immediate_parent(int id, int *ret = NULL);
int get_immediate_parent_id(int id, int *parent) const;
+ /**
+ * return ancestor of the given type, or 0 if none
+ * (parent is always a bucket and thus <0)
+ */
+ int get_parent_of_type(int id, int type) const;
+
/**
* get the fully qualified location of a device by successively finding
* parents beginning at ID and ending at highest type number specified in