]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/cephfs: add python bindings for utimensat()
authorRishabh Dave <ridave@redhat.com>
Mon, 10 Nov 2025 13:36:10 +0000 (19:06 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 16 Apr 2026 12:40:46 +0000 (18:10 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/pybind/cephfs/c_cephfs.pxd
src/pybind/cephfs/cephfs.pyx
src/pybind/cephfs/mock_cephfs.pxi

index 45bd814aa041efff4ca10a29eabaf47d9cf26829..9d5b93c04937d5f805908f442b0e8d48d829731c 100644 (file)
@@ -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)
index 1a13e64432d35ab1d347efe97ff919a6bb14dc2f..a8652072d6bfe68df1a0ddd4b65c0602c8df1600 100644 (file)
@@ -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.
index 65234685cdb76d753fe1f8a82abd364beda93cd2..9c2b0f2e0bd8d65ec8434494f7090344cecf9334 100644 (file)
@@ -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):