From: Rishabh Dave Date: Mon, 10 Nov 2025 13:36:10 +0000 (+0530) Subject: pybind/cephfs: add python bindings for utimensat() X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ff010ad8d1eccf4d03adc616c12a26bb8132efbc;p=ceph.git pybind/cephfs: add python bindings for utimensat() Signed-off-by: Rishabh Dave --- diff --git a/src/pybind/cephfs/c_cephfs.pxd b/src/pybind/cephfs/c_cephfs.pxd index 45bd814aa041..9d5b93c04937 100644 --- a/src/pybind/cephfs/c_cephfs.pxd +++ b/src/pybind/cephfs/c_cephfs.pxd @@ -193,12 +193,16 @@ cdef extern from "cephfs/libcephfs.h" nogil: 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) + int ceph_utime(ceph_mount_info *cmount, const char *path, utimbuf *buf) int ceph_futime(ceph_mount_info *cmount, int fd, utimbuf *buf) int ceph_utimes(ceph_mount_info *cmount, const char *path, timeval times[2]) int ceph_lutimes(ceph_mount_info *cmount, const char *path, timeval times[2]) int ceph_futimes(ceph_mount_info *cmount, int fd, timeval times[2]) int ceph_futimens(ceph_mount_info *cmount, int fd, timespec times[2]) + int ceph_utimensat(ceph_mount_info* cmount, int fd, const char* relpath, + timespec* times, int flags) + int ceph_get_file_replication(ceph_mount_info *cmount, int fh) int ceph_get_path_replication(ceph_mount_info *cmount, const char *path) int ceph_get_pool_id(ceph_mount_info *cmount, const char *pool_name) diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 1a13e64432d3..a8652072d6bf 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -2840,6 +2840,46 @@ cdef class LibCephFS(object): if ret < 0: raise make_ex(ret, "error in futimens") + def utimensat(self, fd, relpath, times, flags): + """ + Set access and modification time for a file pointer by descriptor + + :param fd: file descriptor of the open file + :param relpath: path relative to file descriptor + :param times: if times is not None, it must be a tuple (atime, mtime) + :param flags: int value that can be used to set AT_* modifier flags + (AT_SYMLINK_NOFOLLOW) + """ + self.require_state("mounted") + + if not isinstance(fd, int): + raise TypeError('"fd" must be an int') + if not isinstance(flags, int): + raise TypeError('"flags" must be an int') + + if not isinstance(times, tuple): + raise TypeError('times must be a tuple') + if not isinstance(times[0], (int, float)): + raise TypeError('atime must be an int or a float') + if not isinstance(times[1], (int, float)): + raise TypeError('mtime must be an int or a float') + + ac_time = float(times[0]) + mod_time = float(times[1]) + + relpath = cstr(relpath, 'relpath') + cdef: + int _fd = fd + char* _relpath = relpath + timespec* _times = [to_timespec(ac_time), to_timespec(mod_time)] + int _flags = flags + + with nogil: + ret = ceph_utimensat(self.cluster, _fd, _relpath, _times, _flags) + + if ret < 0: + raise make_ex(ret, "error in utimensat") + def get_file_replication(self, fd): """ Get the file replication information from an open file descriptor. diff --git a/src/pybind/cephfs/mock_cephfs.pxi b/src/pybind/cephfs/mock_cephfs.pxi index 65234685cdb7..9c2b0f2e0bd8 100644 --- a/src/pybind/cephfs/mock_cephfs.pxi +++ b/src/pybind/cephfs/mock_cephfs.pxi @@ -295,6 +295,10 @@ cdef nogil: pass int ceph_futimens(ceph_mount_info *cmount, int fd, timespec times[2]): pass + int ceph_utimensat(ceph_mount_info* cmount, int fd, const char* relpath, + timespec* times, int flags): + pass + int ceph_get_file_replication(ceph_mount_info *cmount, int fh): pass int ceph_get_path_replication(ceph_mount_info *cmount, const char *path):