]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/cephfs: add python bindings for chownat()
authorRishabh Dave <ridave@redhat.com>
Mon, 10 Nov 2025 13:34:26 +0000 (19:04 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 16 Apr 2026 12:40:40 +0000 (18:10 +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 dd92eb3ee65e9237d908fb5b76f25fb912b8d828..45bd814aa041efff4ca10a29eabaf47d9cf26829 100644 (file)
@@ -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)
index 33c90d2d8a17bb2cca506d9f74c34e665ae4fb70..1a13e64432d35ab1d347efe97ff919a6bb14dc2f 100644 (file)
@@ -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.
index 766a7d1c75b048f06b765a13a134cc077fe2c763..65234685cdb76d753fe1f8a82abd364beda93cd2 100644 (file)
@@ -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):