]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: implement get_children(), get_immediate_parent_id()
authorSage Weil <sage@inktank.com>
Mon, 28 Jan 2013 03:40:42 +0000 (19:40 -0800)
committerSage Weil <sage@inktank.com>
Tue, 29 Jan 2013 01:13:59 +0000 (17:13 -0800)
Signed-off-by: Sage Weil <sage@inktank.com>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index 3bae96c8689d98ccefb4ca1ff90b02311de6b0fb..45e4fb53de6ddbc5f155daf885d6c6c7bc5115d8 100644 (file)
@@ -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)
 {
index 56bcb598ff3088d12cc92785507ae5849eb198ca..7def6e4ab345548c9f145ed68d2c5d8bac024481 100644 (file)
@@ -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