From: Rishabh Dave Date: Wed, 1 Apr 2026 12:31:56 +0000 (+0530) Subject: pybind/cephfs: add python binding for ceph_do_snap_md_op() X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8d5cf70ba6affe5fcb921509befc59c990c5a3bf;p=ceph.git pybind/cephfs: add python binding for ceph_do_snap_md_op() Signed-off-by: Rishabh Dave --- diff --git a/src/pybind/cephfs/c_cephfs.pxd b/src/pybind/cephfs/c_cephfs.pxd index 9d5b93c0493..56f1d7d1899 100644 --- a/src/pybind/cephfs/c_cephfs.pxd +++ b/src/pybind/cephfs/c_cephfs.pxd @@ -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) diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 650beacb975..6e0264fc17c 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -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. diff --git a/src/pybind/cephfs/mock_cephfs.pxi b/src/pybind/cephfs/mock_cephfs.pxi index 9c2b0f2e0bd..bd3e54e040e 100644 --- a/src/pybind/cephfs/mock_cephfs.pxi +++ b/src/pybind/cephfs/mock_cephfs.pxi @@ -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):