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,
{
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)
{
* 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
*/
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