From: Sage Weil Date: Wed, 20 Mar 2013 14:59:03 +0000 (-0700) Subject: crush: add link_bucket() X-Git-Tag: v0.62~177^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a54a41173d1de3113560fd4309f75577df0f9def;p=ceph.git crush: add link_bucket() Allow an existing bucket to get linked from a new position in the tree. Signed-off-by: Sage Weil --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 02f361e8b05..766fad6e0af 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -349,6 +349,26 @@ int CrushWrapper::move_bucket(CephContext *cct, int id, const map return insert_item(cct, id, bucket_weight / (float)0x10000, id_name, loc); } +int CrushWrapper::link_bucket(CephContext *cct, int id, const map& 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& loc) // typename -> bucketname { diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 2b745479951..6a12d95ff16 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -352,6 +352,20 @@ public: */ int move_bucket(CephContext *cct, int id, const map& 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& loc); + /** * add or update an item's position in the map *