From: Rishabh Dave Date: Mon, 10 Nov 2025 13:34:26 +0000 (+0530) Subject: pybind/cephfs: add python bindings for chownat() X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=50f1291be791e986fdbce4de8c982fc5bc5557b9;p=ceph.git pybind/cephfs: add python bindings for chownat() Signed-off-by: Rishabh Dave --- diff --git a/src/pybind/cephfs/c_cephfs.pxd b/src/pybind/cephfs/c_cephfs.pxd index dd92eb3ee65e..45bd814aa041 100644 --- a/src/pybind/cephfs/c_cephfs.pxd +++ b/src/pybind/cephfs/c_cephfs.pxd @@ -187,6 +187,9 @@ cdef extern from "cephfs/libcephfs.h" nogil: int ceph_chown(ceph_mount_info *cmount, const char *path, int uid, int gid) int ceph_lchown(ceph_mount_info *cmount, const char *path, int uid, int gid) int ceph_fchown(ceph_mount_info *cmount, int fd, int uid, int gid) + int ceph_chownat(ceph_mount_info *cmount, int fd, const char *relpath, + int uid, int gid, int flags) + int64_t ceph_lseek(ceph_mount_info *cmount, int fd, int64_t offset, int whence) void ceph_buffer_free(char *buf) mode_t ceph_umask(ceph_mount_info *cmount, mode_t mode) diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 33c90d2d8a17..1a13e64432d3 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -1406,6 +1406,41 @@ cdef class LibCephFS(object): if ret < 0: raise make_ex(ret, "error in fchown") + def chownat(self, fd, relpath, uid, gid, flags): + """ + Change directory ownership + + :param fd: the file descriptor + :param relpath: the path of the directory to change, relative to fd + :param uid: the uid to set + :param gid: the gid to set + :param flags: int value that can be used to set AT_* modifier flags + (AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH) + """ + self.require_state("mounted") + + if not isinstance(uid, int): + raise TypeError('"uid" must be an int') + if not isinstance(gid, int): + raise TypeError('"gid" must be an int') + if not isinstance(flags, int): + raise TypeError('"flags" must be an int') + + relpath = cstr(relpath, 'relpath') + cdef: + int _fd = fd + char* _relpath = relpath + # Avoid "OverflowError: can't convert negative value to uid_t." + uid_t _uid = uid if uid >= 0 else -1 + # Avoid "OverflowError: can't convert negative value to gid_t." + gid_t _gid = gid if gid >= 0 else -1 + int _flags = flags + + with nogil: + ret = ceph_chownat(self.cluster, _fd, _relpath, _uid, _gid, _flags) + if ret < 0: + raise make_ex(ret, f"error in chownat {relpath.decode('utf-8')}") + def mkdirs(self, path, mode): """ Create multiple directories at once. diff --git a/src/pybind/cephfs/mock_cephfs.pxi b/src/pybind/cephfs/mock_cephfs.pxi index 766a7d1c75b0..65234685cdb7 100644 --- a/src/pybind/cephfs/mock_cephfs.pxi +++ b/src/pybind/cephfs/mock_cephfs.pxi @@ -272,12 +272,17 @@ cdef nogil: pass int ceph_fchown(ceph_mount_info *cmount, int fd, int uid, int gid): pass + int ceph_chownat(ceph_mount_info *cmount, int fd, const char *relpath, + int uid, int gid, int flags): + pass + int64_t ceph_lseek(ceph_mount_info *cmount, int fd, int64_t offset, int whence): pass void ceph_buffer_free(char *buf): pass mode_t ceph_umask(ceph_mount_info *cmount, mode_t mode): pass + int ceph_utime(ceph_mount_info *cmount, const char *path, utimbuf *buf): pass int ceph_futime(ceph_mount_info *cmount, int fd, utimbuf *buf):