]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: Add group snap rename method
authorVictor Denisov <denisovenator@gmail.com>
Fri, 2 Dec 2016 20:43:42 +0000 (12:43 -0800)
committerJason Dillaman <dillaman@redhat.com>
Sat, 13 Jan 2018 19:00:30 +0000 (14:00 -0500)
Signed-off-by: Victor Denisov <denisovenator@gmail.com>
src/include/rbd/librbd.h
src/include/rbd/librbd.hpp
src/librbd/api/Group.cc
src/librbd/api/Group.h
src/librbd/librbd.cc
src/pybind/rbd/rbd.pyx
src/test/pybind/test_rbd.py
src/tracing/librbd.tp

index 9ab4186e84aefdab5e00b595736516c52c617763..9679db196a65a282234a0135f627b1c9365db133 100644 (file)
@@ -958,6 +958,10 @@ CEPH_RBD_API int rbd_group_snap_create(rados_ioctx_t group_p,
 CEPH_RBD_API int rbd_group_snap_remove(rados_ioctx_t group_p,
                                        const char *group_name,
                                        const char *snap_name);
+CEPH_RBD_API int rbd_group_snap_rename(rados_ioctx_t group_p,
+                                       const char *group_name,
+                                       const char *old_snap_name,
+                                       const char *new_snap_name);
 CEPH_RBD_API int rbd_group_snap_list(rados_ioctx_t group_p,
                                      const char *group_name,
                                      rbd_group_snap_spec_t *snaps,
index a25cba05c00f7fd27b82d6ac05b9ccae5297692f..470217cf73502dad8ebd24f02364a43b2c3076b6 100644 (file)
@@ -231,6 +231,8 @@ public:
                        const char *snap_name);
   int group_snap_remove(IoCtx& io_ctx, const char *group_name,
                        const char *snap_name);
+  int group_snap_rename(IoCtx& group_ioctx, const char *group_name,
+                        const char *old_snap_name, const char *new_snap_name);
   int group_snap_list(IoCtx& group_ioctx, const char *group_name,
                      std::vector<group_snap_spec_t> *snaps);
 
index e50c3e8c0f4021bf1b0306b4ee91dff698cc05fc..07fbd6d403fd6cc4ece830bc858b4d859f0bc4fd 100644 (file)
@@ -904,6 +904,7 @@ int Group<I>::snap_remove(librados::IoCtx& group_ioctx, const char *group_name,
               << dendl;
     return r;
   }
+
   std::vector<cls::rbd::GroupSnapshot> snaps;
   r = group_snap_list(group_ioctx, group_name, &snaps);
   if (r < 0) {
@@ -927,6 +928,50 @@ int Group<I>::snap_remove(librados::IoCtx& group_ioctx, const char *group_name,
   return r;
 }
 
+template <typename I>
+int Group<I>::snap_rename(librados::IoCtx& group_ioctx, const char *group_name,
+                          const char *old_snap_name,
+                          const char *new_snap_name) {
+  CephContext *cct = (CephContext *)group_ioctx.cct();
+
+  std::string group_id;
+  int r = cls_client::dir_get_id(&group_ioctx, RBD_GROUP_DIRECTORY,
+                                 group_name, &group_id);
+  if (r == -ENOENT) {
+    return r;
+  } else if (r < 0) {
+    lderr(cct) << "error reading group id object: " << cpp_strerror(r) << dendl;
+    return r;
+  }
+
+  std::vector<cls::rbd::GroupSnapshot> group_snaps;
+  r = group_snap_list(group_ioctx, group_name, &group_snaps);
+  if (r < 0) {
+    return r;
+  }
+
+  cls::rbd::GroupSnapshot group_snap;
+  for (auto &snap : group_snaps) {
+    if (snap.name == old_snap_name) {
+      group_snap = snap;
+      break;
+    }
+  }
+
+  if (group_snap.id.empty()) {
+    return -ENOENT;
+  }
+
+  std::string group_header_oid = util::group_header_name(group_id);
+  group_snap.name = new_snap_name;
+  r = cls_client::group_snap_set(&group_ioctx, group_header_oid, group_snap);
+  if (r < 0) {
+    return r;
+  }
+
+  return 0;
+}
+
 template <typename I>
 int Group<I>::snap_list(librados::IoCtx& group_ioctx, const char *group_name,
                        std::vector<group_snap_spec_t> *snaps)
index 58f8ad556b62d4963d6a4ed93441593c8dc50db4..bfcfedab8e798f4e4e1c9f7318354267cadf3f24 100644 (file)
@@ -37,11 +37,13 @@ struct Group {
   static int image_get_group(ImageCtxT *ictx, group_spec_t *group_spec);
 
   static int snap_create(librados::IoCtx& group_ioctx,
-                              const char *group_name, const char *snap_name);
+                         const char *group_name, const char *snap_name);
   static int snap_remove(librados::IoCtx& group_ioctx,
-                              const char *group_name, const char *snap_name);
+                         const char *group_name, const char *snap_name);
+  static int snap_rename(librados::IoCtx& group_ioctx, const char *group_name,
+                         const char *old_snap_name, const char *new_snap_name);
   static int snap_list(librados::IoCtx& group_ioctx, const char *group_name,
-                            std::vector<group_snap_spec_t> *snaps);
+                       std::vector<group_snap_spec_t> *snaps);
 
 };
 
index f87763caa5da195695ca696fc64119080d00317d..42def5efd4e5c6eac9b7f7ed1b85d00160fee5b2 100644 (file)
@@ -802,6 +802,20 @@ namespace librbd {
     return r;
   }
 
+  int RBD::group_snap_rename(IoCtx& group_ioctx, const char *group_name,
+                             const char *old_snap_name,
+                             const char *new_snap_name)
+  {
+    TracepointProvider::initialize<tracepoint_traits>(get_cct(group_ioctx));
+    tracepoint(librbd, group_snap_rename_enter,
+               group_ioctx.get_pool_name().c_str(), group_ioctx.get_id(),
+               group_name, old_snap_name, new_snap_name);
+    int r = librbd::api::Group<>::snap_rename(group_ioctx, group_name,
+                                              old_snap_name, new_snap_name);
+    tracepoint(librbd, group_snap_list_exit, r);
+    return r;
+  }
+
 
   RBD::AioCompletion::AioCompletion(void *cb_arg, callback_t complete_cb)
   {
@@ -4605,6 +4619,26 @@ extern "C" int rbd_group_snap_remove(rados_ioctx_t group_p, const char *group_na
   return r;
 }
 
+extern "C" int rbd_group_snap_rename(rados_ioctx_t group_p,
+                                     const char *group_name,
+                                     const char *old_snap_name,
+                                     const char *new_snap_name)
+{
+  librados::IoCtx group_ioctx;
+  librados::IoCtx::from_rados_ioctx_t(group_p, group_ioctx);
+
+  TracepointProvider::initialize<tracepoint_traits>(get_cct(group_ioctx));
+  tracepoint(librbd, group_snap_rename_enter,
+             group_ioctx.get_pool_name().c_str(), group_ioctx.get_id(),
+             group_name, old_snap_name, new_snap_name);
+
+  int r = librbd::api::Group<>::snap_rename(group_ioctx, group_name,
+                                            old_snap_name, new_snap_name);
+
+  tracepoint(librbd, group_snap_list_exit, r);
+  return r;
+}
+
 extern "C" int rbd_group_snap_list(rados_ioctx_t group_p, const char *group_name,
                                   rbd_group_snap_spec_t *snaps, size_t *snaps_size)
 {
index 43569d4abf0aa4fb9dba4f2c9bc65c833eb6c7ff..a81c4e4955d04f5ec1da77aa3253352ec33b279e 100644 (file)
@@ -419,6 +419,10 @@ cdef extern from "rbd/librbd.h" nogil:
     int rbd_group_snap_remove(rados_ioctx_t group_p, const char *group_name,
                               const char *snap_name)
 
+    int rbd_group_snap_rename(rados_ioctx_t group_p, const char *group_name,
+                              const char *old_snap_name,
+                              const char *new_snap_name)
+
     int rbd_group_snap_list(rados_ioctx_t group_p,
                             const char *group_name,
                             rbd_group_snap_spec_t *snaps,
@@ -1645,6 +1649,28 @@ cdef class Group(object):
         if ret != 0:
             raise make_ex(ret, 'error removing group snapshot', group_errno_to_exception)
 
+    def rename_snap(self, old_snap_name, new_snap_name):
+        """
+        Rename group's snapshot.
+
+        :raises: :class:`ObjectNotFound`
+        :raises: :class:`ObjectExists`
+        :raises: :class:`InvalidArgument`
+        :raises: :class:`FunctionNotSupported`
+        """
+
+        old_snap_name = cstr(old_snap_name, 'old_snap_name')
+        new_snap_name = cstr(new_snap_name, 'new_snap_name')
+        cdef:
+            char *_old_snap_name = old_snap_name
+            char *_new_snap_name = new_snap_name
+        with nogil:
+            ret = rbd_group_snap_rename(self._ioctx, self._name, _old_snap_name,
+                                        _new_snap_name)
+        if ret != 0:
+            raise make_ex(ret, 'error removing group snapshot',
+                          group_errno_to_exception)
+
     def list_snaps(self):
         """
         Iterate over the images of a group.
index 9b89327fd6b3e6ecc316e8dc51c50852de0db77e..e376e92a9a2c96cf63fbcb136cdcc101c730f2a9 100644 (file)
@@ -1790,6 +1790,16 @@ class TestGroups(object):
         self.group.remove_snap(snap_name)
         eq([], list(self.group.list_snaps()))
 
+    def test_group_snap_rename(self):
+        global snap_name
+        new_snap_name = "new" + snap_name
+
+        eq([], list(self.group.list_snaps()))
+        self.group.create_snap(snap_name)
+        eq([snap_name], [snap['name'] for snap in self.group.list_snaps()])
+        self.group.rename_snap(snap_name, new_snap_name)
+        eq([new_snap_name], [snap['name'] for snap in self.group.list_snaps()])
+
 @with_setup(create_image, remove_image)
 def test_rename():
     rbd = RBD()
index 0935b7c2b5df7825145e5972be1fff20af74e3c1..c85e6db608e3ee39ca8d729be25750d03d0fa7b4 100644 (file)
@@ -2611,6 +2611,30 @@ TRACEPOINT_EVENT(librbd, group_snap_remove_exit,
     )
 )
 
+TRACEPOINT_EVENT(librbd, group_snap_rename_enter,
+    TP_ARGS(
+        const char*, pool_name,
+        int64_t, id,
+        const char*, group_name,
+        const char*, old_snap_name,
+        const char*, new_snap_name),
+    TP_FIELDS(
+        ctf_string(pool_name, pool_name)
+        ctf_integer(int64_t, id, id)
+        ctf_string(group_name, group_name)
+        ctf_string(old_snap_name, old_snap_name)
+        ctf_string(new_snap_name, new_snap_name)
+    )
+)
+
+TRACEPOINT_EVENT(librbd, group_snap_rename_exit,
+    TP_ARGS(
+           int, retval),
+    TP_FIELDS(
+        ctf_integer(int, retval, retval)
+    )
+)
+
 TRACEPOINT_EVENT(librbd, group_snap_list_enter,
     TP_ARGS(
         const char*, pool_name,