]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs.pyx: implement python bindings for fstat
authorRamana Raja <rraja@redhat.com>
Thu, 23 Jun 2016 12:09:32 +0000 (17:39 +0530)
committerRamana Raja <rraja@redhat.com>
Tue, 2 Aug 2016 10:57:57 +0000 (16:27 +0530)
Signed-off-by: Ramana Raja <rraja@redhat.com>
(cherry picked from commit f58403f3d19e22edeb8f91b6f87a0b7947b0ff21)

src/pybind/cephfs/cephfs.pyx
src/test/pybind/test_cephfs.py

index 6d32c40b4486cfd9208bc8985c1a5962977569fa..b27e7976d0f9162d9a47b50e0f4343e3faeb0f36 100644 (file)
@@ -108,6 +108,7 @@ cdef extern from "cephfs/libcephfs.h" nogil:
     int ceph_conf_set(ceph_mount_info *cmount, const char *option, const char *value)
 
     int ceph_mount(ceph_mount_info *cmount, const char *root)
+    int ceph_fstat(ceph_mount_info *cmount, int fd, stat *stbuf)
     int ceph_stat(ceph_mount_info *cmount, const char *path, stat *stbuf)
     int ceph_statfs(ceph_mount_info *cmount, const char *path, statvfs *stbuf)
 
@@ -799,6 +800,29 @@ cdef class LibCephFS(object):
                           st_mtime=datetime.fromtimestamp(statbuf.st_mtime),
                           st_ctime=datetime.fromtimestamp(statbuf.st_ctime))
 
+    def fstat(self, fd):
+        self.require_state("mounted")
+        if not isinstance(fd, int):
+            raise TypeError('fd must be an int')
+
+        cdef:
+            int _fd = fd
+            stat statbuf
+
+        with nogil:
+            ret = ceph_fstat(self.cluster, _fd, &statbuf)
+        if ret < 0:
+            raise make_ex(ret, "error in fsat")
+        return StatResult(st_dev=statbuf.st_dev, st_ino=statbuf.st_ino,
+                          st_mode=statbuf.st_mode, st_nlink=statbuf.st_nlink,
+                          st_uid=statbuf.st_uid, st_gid=statbuf.st_gid,
+                          st_rdev=statbuf.st_rdev, st_size=statbuf.st_size,
+                          st_blksize=statbuf.st_blksize,
+                          st_blocks=statbuf.st_blocks,
+                          st_atime=datetime.fromtimestamp(statbuf.st_atime),
+                          st_mtime=datetime.fromtimestamp(statbuf.st_mtime),
+                          st_ctime=datetime.fromtimestamp(statbuf.st_ctime))
+
     def symlink(self, existing, newname):
         self.require_state("mounted")
         existing = cstr(existing, 'existing')
index 6267b5f34d0f71c8aa0ccbb46e5e09da83b8e01d..41a6ae518e188f01ffbf32b140510338c07459ae 100644 (file)
@@ -40,6 +40,13 @@ def test_conf_get():
 def test_version():
     cephfs.version()
 
+@with_setup(setup_test)
+def test_fstat():
+    fd = cephfs.open('file-1', 'w', 0755)
+    stat = cephfs.fstat(fd)
+    assert(len(stat) == 13)
+    cephfs.close(fd)
+
 @with_setup(setup_test)
 def test_statfs():
     stat = cephfs.statfs('/')