]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/cephfs: add python binding for ceph_do_snap_md_op()
authorRishabh Dave <ridave@redhat.com>
Wed, 1 Apr 2026 12:31:56 +0000 (18:01 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 18 Jun 2026 06:27:45 +0000 (11:57 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/pybind/cephfs/c_cephfs.pxd
src/pybind/cephfs/cephfs.pyx
src/pybind/cephfs/mock_cephfs.pxi

index 9d5b93c04937d5f805908f442b0e8d48d829731c..56f1d7d1899405a15585374af6fa0f94a67937f5 100644 (file)
@@ -148,10 +148,15 @@ cdef extern from "cephfs/libcephfs.h" nogil:
 
     int ceph_mkdir(ceph_mount_info *cmount, const char *path, mode_t mode)
     int ceph_mkdirat(ceph_mount_info *cmount, int dirfd, const char *relpath, mode_t mode)
+
     int ceph_mksnap(ceph_mount_info *cmount, const char *path, const char *name, mode_t mode, snap_metadata *snap_metadata, size_t nr_snap_metadata)
     int ceph_rmsnap(ceph_mount_info *cmount, const char *path, const char *name)
     int ceph_get_snap_info(ceph_mount_info *cmount, const char *path, snap_info *snap_info)
     void ceph_free_snap_info_buffer(snap_info *snap_info)
+    int ceph_do_snap_md_op(ceph_mount_info *cmount, const char *path,
+                           const char *md_key, const char *md_val,
+                           const unsigned int op_flag)
+
     int ceph_mkdirs(ceph_mount_info *cmount, const char *path, mode_t mode)
     int ceph_closedir(ceph_mount_info *cmount, ceph_dir_result *dirp)
     int ceph_opendir(ceph_mount_info *cmount, const char *name, ceph_dir_result **dirpp)
index 650beacb9754330335c055b50926e465773516cc..6e0264fc17c8f5684098c308e95ef62f6588b161 100644 (file)
@@ -72,6 +72,20 @@ CEPH_SETATTR_BTIME = 0x200
 
 CEPH_NOSNAP = -2
 
+
+# XXX: DON'T FORGET to update values in src/include/cephfs/snap_types.h, if you
+# make any changes below.
+#
+# NOTE: Regretfully re-defined here to avoid all the compiler/path black magic
+# required to pass the "docs" CI job. Compiling via 'cdef extern' works locally
+# but fails in the isolated ReadTheDocs build environment due to missing directory
+# hierarchies.
+cpdef enum:
+    CEPH_SNAP_MD_OP_CREATE = (1 << 0)
+    CEPH_SNAP_MD_OP_EXCL   = (1 << 1)
+    CEPH_SNAP_MD_OP_REMOVE = (1 << 2)
+
+
 # XXX: errno definitions, hard-coded numbers here are errnos defined by Linux
 # that are used for the Ceph on-the-wire status codes.
 EBLOCKLISTED = ceph_to_hostos_errno(108)
@@ -1255,6 +1269,41 @@ cdef class LibCephFS(object):
             ceph_free_snap_info_buffer(&info)
         return {'id': info.id, 'metadata': md}
 
+    def do_snap_md_op(self, snap_path, md_key, md_val, op_flag):
+        '''
+        Create, update or remove a key-value pair from snapshot metadata.
+
+        :param snap_path: snapshot path
+        :param md_key: key for the key-value pair
+        :param md_val: value for the key-value pair
+        :param op_flag: flag indicating the op to be performed. it can be
+                        create, update or remove.
+
+        :raises: :class: `TypeError`
+        :raises: :class: `Error`
+
+        :returns: 0 on success
+        '''
+        self.require_state('mounted')
+
+        snap_path = cstr(snap_path, 'snap_path')
+        md_key = cstr(md_key, 'md_key')
+        md_val = cstr(md_val, 'md_val')
+
+        if not isinstance(op_flag, int):
+            raise TypeError('"op_flag" must be an int')
+
+        cdef:
+            char* _snap_path = snap_path
+            char* _md_key = md_key
+            char* _md_val = md_val
+            int _op_flag = op_flag
+
+        with nogil:
+            ret = ceph_do_snap_md_op(self.cluster, _snap_path, _md_key, _md_val, _op_flag)
+        if ret < 0:
+            raise make_ex(ret, 'snap_md_op')
+
     def chmod(self, path, mode) -> None:
         """
         Change directory mode.
index 9c2b0f2e0bd8d65ec8434494f7090344cecf9334..bd3e54e040ef69febe00ea2e75705ea2edfd19d4 100644 (file)
@@ -207,6 +207,7 @@ cdef nogil:
         pass
     int ceph_mkdirat(ceph_mount_info *cmount, int dirfd, const char *relpath, mode_t mode):
         pass
+
     int ceph_mksnap(ceph_mount_info *cmount, const char *path, const char *name, mode_t mode, snap_metadata *snap_metadata, size_t nr_snap_metadata):
         pass
     int ceph_rmsnap(ceph_mount_info *cmount, const char *path, const char *name):
@@ -215,6 +216,11 @@ cdef nogil:
         pass
     void ceph_free_snap_info_buffer(snap_info *snap_info):
         pass
+    int ceph_do_snap_md_op(ceph_mount_info* cmount, const char* path,
+                           const char* md_key, const char* md_val,
+                           const unsigned int op_flag):
+        pass
+
     int ceph_mkdirs(ceph_mount_info *cmount, const char *path, mode_t mode):
         pass
     int ceph_closedir(ceph_mount_info *cmount, ceph_dir_result *dirp):