]> 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>
Mon, 18 Jul 2016 10:06:40 +0000 (15:36 +0530)
Signed-off-by: Ramana Raja <rraja@redhat.com>
src/pybind/cephfs/cephfs.pyx
src/test/pybind/test_cephfs.py

index b2232d329f6fb26bf6d666a80367d3cf683df757..ac17ada1a14c2735656e9da762e33259a953c44b 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)
 
@@ -800,6 +801,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 607e9de6853c5494ff71cb9b67d23d9e27fee04c..34a5d63184aaff70f8af8bf694e296b7fd219833 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('/')