From: Loic Dachary Date: Thu, 16 Oct 2014 00:08:13 +0000 (-0700) Subject: crush: add CrushWrapper::rename_bucket and can_rename_bucket X-Git-Tag: v0.88~64^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=30f3ac3fb62840ae900e6b0be8b46e3eced17757;p=ceph.git crush: add CrushWrapper::rename_bucket and can_rename_bucket Rename a bucket and return -ENOTDIR if trying to rename an item. The behavior is otherwise the same as rename_item and can_rename_item. Signed-off-by: Loic Dachary --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index dbd50d165d5e..8ea936167fc6 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -101,6 +101,33 @@ int CrushWrapper::rename_item(const string& srcname, return set_item_name(oldid, dstname); } +int CrushWrapper::can_rename_bucket(const string& srcname, + const string& dstname, + ostream *ss) const +{ + int ret = can_rename_item(srcname, dstname, ss); + if (ret) + return ret; + int srcid = get_item_id(srcname); + if (srcid >= 0) { + *ss << "srcname = '" << srcname << "' is not a bucket " + << "because its id = " << srcid << " is >= 0"; + return -ENOTDIR; + } + return 0; +} + +int CrushWrapper::rename_bucket(const string& srcname, + const string& dstname, + ostream *ss) +{ + int ret = can_rename_bucket(srcname, dstname, ss); + if (ret < 0) + return ret; + int oldid = get_item_id(srcname); + return set_item_name(oldid, dstname); +} + void CrushWrapper::find_takes(set& roots) const { for (unsigned i=0; imax_rules; i++) { diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 459d761071d6..94bb8eef34a4 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -275,6 +275,13 @@ public: int rename_item(const string& srcname, const string& dstname, ostream *ss); + int can_rename_bucket(const string& srcname, + const string& dstname, + ostream *ss) const; + int rename_bucket(const string& srcname, + const string& dstname, + ostream *ss); + // rule names bool rule_exists(string name) const { build_rmaps();