From: Ramana Raja Date: Thu, 23 Jun 2016 12:09:32 +0000 (+0530) Subject: cephfs.pyx: implement python bindings for fstat X-Git-Tag: v10.2.3~113^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e77684fc68cfd3dfb33a80e7c5604356921a40b0;p=ceph.git cephfs.pyx: implement python bindings for fstat Signed-off-by: Ramana Raja (cherry picked from commit f58403f3d19e22edeb8f91b6f87a0b7947b0ff21) --- diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 6d32c40b4486..b27e7976d0f9 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -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') diff --git a/src/test/pybind/test_cephfs.py b/src/test/pybind/test_cephfs.py index 6267b5f34d0f..41a6ae518e18 100644 --- a/src/test/pybind/test_cephfs.py +++ b/src/test/pybind/test_cephfs.py @@ -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('/')