]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: add link_bucket()
authorSage Weil <sage@inktank.com>
Wed, 20 Mar 2013 14:59:03 +0000 (07:59 -0700)
committerSage Weil <sage@inktank.com>
Fri, 22 Mar 2013 22:15:37 +0000 (15:15 -0700)
Allow an existing bucket to get linked from a new position in the tree.

Signed-off-by: Sage Weil <sage@inktank.com>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index 02f361e8b058fe1460ba7aa8a10031fe5d5e989a..766fad6e0afe32e9dc8a8da6992bc88ee673cd36 100644 (file)
@@ -349,6 +349,26 @@ int CrushWrapper::move_bucket(CephContext *cct, int id, const map<string,string>
   return insert_item(cct, id, bucket_weight / (float)0x10000, id_name, loc);
 }
 
+int CrushWrapper::link_bucket(CephContext *cct, int id, const map<string,string>& loc)
+{
+  // sorry this only works for buckets
+  if (id >= 0)
+    return -EINVAL;
+
+  if (!item_exists(id))
+    return -ENOENT;
+
+  // get the name of the bucket we are trying to move for later
+  string id_name = get_item_name(id);
+
+  // detach the bucket
+  crush_bucket *b = get_bucket(id);
+  unsigned bucket_weight = b->weight;
+
+  // insert the bucket back into the hierarchy
+  return insert_item(cct, id, bucket_weight / (float)0x10000, id_name, loc);
+}
+
 int CrushWrapper::create_or_move_item(CephContext *cct, int item, float weight, string name,
                                      const map<string,string>& loc)  // typename -> bucketname
 {
index 2b745479951635f890b4e7bdcd1a70c15c02e1b3..6a12d95ff16cf21c5adf85ad89dc4ee6df8a410b 100644 (file)
@@ -352,6 +352,20 @@ public:
    */
   int move_bucket(CephContext *cct, int id, const map<string,string>& loc);
 
+  /**
+   * add a link to an existing bucket in the hierarchy to the new location
+   *
+   * This has the same location and ancestor creation behavior as
+   * insert_item(), but will add a new link to the specified existing
+   * bucket.
+   *
+   * @param cct cct
+   * @param id bucket id
+   * @param loc location (map of type to bucket names)
+   * @return 0 for success, negative on error
+   */
+  int link_bucket(CephContext *cct, int id, const map<string,string>& loc);
+
   /**
    * add or update an item's position in the map
    *