]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: add CrushWrapper::rename_bucket and can_rename_bucket
authorLoic Dachary <loic-201408@dachary.org>
Thu, 16 Oct 2014 00:08:13 +0000 (17:08 -0700)
committerLoic Dachary <loic-201408@dachary.org>
Thu, 16 Oct 2014 00:13:59 +0000 (17:13 -0700)
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 <loic-201408@dachary.org>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index dbd50d165d5ee8fccef6bb09e7fe4f935cb0d02c..8ea936167fc647cf8160d4cb8ffccf00c44a5afc 100644 (file)
@@ -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<int>& roots) const
 {
   for (unsigned i=0; i<crush->max_rules; i++) {
index 459d761071d65b1e72fb2421734b680585abeaf8..94bb8eef34a44b2bc4802359173886c8cc3fcdce 100644 (file)
@@ -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();