From 1d5f37e8605fc7247a38d96e0e978f14bbabff6c Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Wed, 22 Oct 2025 19:27:44 +0530 Subject: [PATCH] pybind/cephfs: add python bindings for fdopendir() Signed-off-by: Rishabh Dave --- src/pybind/cephfs/c_cephfs.pxd | 1 + src/pybind/cephfs/cephfs.pyx | 17 +++++++++++++++++ src/pybind/cephfs/mock_cephfs.pxi | 2 ++ 3 files changed, 20 insertions(+) diff --git a/src/pybind/cephfs/c_cephfs.pxd b/src/pybind/cephfs/c_cephfs.pxd index 141ad718667..29cec2676c6 100644 --- a/src/pybind/cephfs/c_cephfs.pxd +++ b/src/pybind/cephfs/c_cephfs.pxd @@ -124,6 +124,7 @@ cdef extern from "cephfs/libcephfs.h" nogil: int ceph_mkdirs(ceph_mount_info *cmount, const char *path, mode_t mode) int ceph_closedir(ceph_mount_info *cmount, ceph_dir_result *dirp) int ceph_opendir(ceph_mount_info *cmount, const char *name, ceph_dir_result **dirpp) + int ceph_fdopendir(ceph_mount_info *cmount, int dirfd, ceph_dir_result** dirpp) void ceph_rewinddir(ceph_mount_info *cmount, ceph_dir_result *dirp) int64_t ceph_telldir(ceph_mount_info *cmount, ceph_dir_result *dirp) void ceph_seekdir(ceph_mount_info *cmount, ceph_dir_result *dirp, int64_t offset) diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 8f34788dc1d..a6f48682a22 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -1034,6 +1034,23 @@ cdef class LibCephFS(object): d.handle = handle return d + def fdopendir(self, dirfd): + self.require_state("mounted") + + cdef: + int dirfd_ = dirfd + ceph_dir_result* handle + + with nogil: + ret = ceph_fdopendir(self.cluster, dirfd_, &handle) + if ret < 0: + raise make_ex(ret, f'error in fdopendir when it was called for fd "{dirfd_}"') + + d = DirResult() + d.lib = self + d.handle = handle + return d + def readdir(self, DirResult handle) -> Optional[DirEntry]: """ Get the next entry in an open directory. diff --git a/src/pybind/cephfs/mock_cephfs.pxi b/src/pybind/cephfs/mock_cephfs.pxi index fcda27bbc35..ef4a0c5e17d 100644 --- a/src/pybind/cephfs/mock_cephfs.pxi +++ b/src/pybind/cephfs/mock_cephfs.pxi @@ -179,6 +179,8 @@ cdef nogil: pass int ceph_opendir(ceph_mount_info *cmount, const char *name, ceph_dir_result **dirpp): pass + int ceph_fdopendir(ceph_mount_info *cmount, int dirfd, ceph_dir_result** dirpp): + pass void ceph_rewinddir(ceph_mount_info *cmount, ceph_dir_result *dirp): pass int64_t ceph_telldir(ceph_mount_info *cmount, ceph_dir_result *dirp): -- 2.39.5