]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs: chown function
authorJos Collin <jcollin@redhat.com>
Sun, 27 Oct 2019 08:29:00 +0000 (13:59 +0530)
committerJos Collin <jcollin@redhat.com>
Tue, 19 Nov 2019 15:58:24 +0000 (21:28 +0530)
Fixes: https://tracker.ceph.com/issues/40959
Signed-off-by: Jos Collin <jcollin@redhat.com>
(cherry picked from commit 4ad415866b33e4f69ee04866aa0de99b75c4e992)

src/pybind/cephfs/cephfs.pyx

index def4069b90ff164c3e3ed68f74f35adb78a22835..851f07b372e571f9a41f843cf880fe762e16fcce 100644 (file)
@@ -156,6 +156,7 @@ cdef extern from "cephfs/libcephfs.h" nogil:
     int ceph_fsync(ceph_mount_info *cmount, int fd, int syncdataonly)
     int ceph_conf_parse_argv(ceph_mount_info *cmount, int argc, const char **argv)
     int ceph_chmod(ceph_mount_info *cmount, const char *path, mode_t mode)
+    int ceph_chown(ceph_mount_info *cmount, const char *path, int uid, int gid)
     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)
@@ -840,6 +841,29 @@ cdef class LibCephFS(object):
         if ret < 0:
             raise make_ex(ret, "error in chmod {}".format(path.decode('utf-8')))
 
+    def chown(self, path, int uid, int gid):
+        """
+        Change directory ownership
+        :param path: the path of the directory to change.
+        :param uid: the uid to set
+        :param gid: the gid to set
+        """
+        self.require_state("mounted")
+        path = cstr(path, 'path')
+        if not isinstance(uid, int):
+            raise TypeError('uid must be an int')
+        elif not isinstance(gid, int):
+            raise TypeError('gid must be an int')
+
+        cdef:
+            char* _path = path
+            int _uid = uid
+            int _gid = gid
+        with nogil:
+            ret = ceph_chown(self.cluster, _path, _uid, _gid)
+        if ret < 0:
+            raise make_ex(ret, "error in chown {}".format(path.decode('utf-8')))
+
     def mkdirs(self, path, mode):
         """
         Create multiple directories at once.