]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: add snap_exists method API 32497/head
authorzhengyin <zhengyin@cmss.chinamobile.com>
Tue, 17 Dec 2019 03:03:45 +0000 (11:03 +0800)
committerzhengyin <zhengyin@cmss.chinamobile.com>
Wed, 15 Jan 2020 01:54:22 +0000 (09:54 +0800)
Signed-off-by: Zheng Yin <zhengyin@cmss.chinamobile.com>
src/include/rbd/librbd.h
src/librbd/librbd.cc
src/pybind/rbd/rbd.pyx

index a53e2c448fb78ea9d3af0e3a74610a6f8d96033e..197e8d55d87b347c50d0f6a2d78b60a416495ae5 100644 (file)
@@ -763,6 +763,7 @@ CEPH_RBD_API int rbd_deep_copy_with_progress(rbd_image_t image,
 CEPH_RBD_API int rbd_snap_list(rbd_image_t image, rbd_snap_info_t *snaps,
                                int *max_snaps);
 CEPH_RBD_API void rbd_snap_list_end(rbd_snap_info_t *snaps);
+CEPH_RBD_API int rbd_snap_exists(rbd_image_t image, const char *snapname, bool *exists);
 CEPH_RBD_API int rbd_snap_create(rbd_image_t image, const char *snapname);
 CEPH_RBD_API int rbd_snap_remove(rbd_image_t image, const char *snapname);
 CEPH_RBD_API int rbd_snap_remove2(rbd_image_t image, const char *snap_name,
index 517fa4132dcdcdcb0523a60dc3d334315619a7e4..c0dbd82be2ecd40621ff8baa2b0e5398d19453d3 100644 (file)
@@ -5292,6 +5292,16 @@ extern "C" int rbd_snap_get_limit(rbd_image_t image, uint64_t *limit)
   return r;
 }
 
+extern "C" int rbd_snap_exists(rbd_image_t image, const char *snapname, bool *exists)
+{
+  librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
+  tracepoint(librbd, snap_exists_enter, ictx, ictx->name.c_str(), 
+             ictx->snap_name.c_str(), ictx->read_only, snapname);
+  int r = librbd::api::Snapshot<>::exists(ictx, cls::rbd::UserSnapshotNamespace(), snapname, exists);
+  tracepoint(librbd, snap_exists_exit, r, *exists);
+  return r;
+}
+
 extern "C" int rbd_snap_get_timestamp(rbd_image_t image, uint64_t snap_id, struct timespec *timestamp)
 {
   librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
index 6544bfbdf15bf64a78dca6a51ed78882f72163fe..41534ac440ac32b5d229297704829e2f4015599f 100644 (file)
@@ -502,6 +502,7 @@ cdef extern from "rbd/librbd.h" nogil:
     int rbd_snap_unprotect(rbd_image_t image, const char *snap_name)
     int rbd_snap_is_protected(rbd_image_t image, const char *snap_name,
                               int *is_protected)
+    int rbd_snap_exists(rbd_image_t image, const char *snapname, bint *exists)
     int rbd_snap_get_limit(rbd_image_t image, uint64_t *limit)
     int rbd_snap_set_limit(rbd_image_t image, uint64_t limit)
     int rbd_snap_get_timestamp(rbd_image_t image, uint64_t snap_id, timespec *timestamp)
@@ -3905,6 +3906,24 @@ cdef class Image(object):
             raise make_ex(ret, 'error checking if snapshot %s@%s is protected' % (self.name, name))
         return is_protected == 1
 
+    def snap_exists(self, name):
+        """
+        Find out whether a snapshot is exists.
+
+        :param name: the snapshot to check
+        :type name: str
+        :returns: bool - whether the snapshot is exists
+        """
+        name = cstr(name, 'name')
+        cdef:
+            char *_name = name
+            bint _exists = False
+        with nogil:
+            ret = rbd_snap_exists(self.image, _name, &_exists)
+        if ret != 0:
+            raise make_ex(ret, 'error getting snapshot exists for %s' % self.name)
+        return bool(_exists != 0)
+
     def get_snap_limit(self):
         """
         Get the snapshot limit for an image.