From 30f3ac3fb62840ae900e6b0be8b46e3eced17757 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Wed, 15 Oct 2014 17:08:13 -0700 Subject: [PATCH] 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 --- src/crush/CrushWrapper.cc | 27 +++++++++++++++++++++++++++ src/crush/CrushWrapper.h | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index dbd50d165d5..8ea936167fc 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 459d761071d..94bb8eef34a 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(); -- 2.47.3