]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_ceph_new: Handle the special case of UTIME_NOW
authorAnoop C S <anoopcs@samba.org>
Sat, 14 Jun 2025 09:02:28 +0000 (14:32 +0530)
committerRalph Boehme <slow@samba.org>
Mon, 30 Jun 2025 14:16:52 +0000 (14:16 +0000)
As per utimensat(2)[1]:
. . .
If the tv_nsec field of one of the timespec structures has the special
value UTIME_NOW, then the corresponding file timestamp is set to the
current time.
. . .

Instead of utimes() or futimes() we make use of ceph_ll_setattr() with
appropriate mask to update timsestamps. It is also important to note
that ceph_ll_setattr() does not handle timestamps in pairs of timespec
structs. This had a shortcoming that the special consideration for the
magic value UTIME_NOW was left unattended resulting in epoch timestamps.
Therefore we reset those timestamps where UTIME_NOW is set in tv_nsec
with the current time.

[1] https://www.man7.org/linux/man-pages/man2/utimensat.2.html

Signed-off-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Mon Jun 30 14:16:52 UTC 2025 on atb-devel-224

source3/modules/vfs_ceph_new.c

index 04694d56bafbd4d7aa31361f660dcc889023dbe8..caafdad12afc15c8f3f6d33ef96b492e97b54ad0 100644 (file)
@@ -1031,23 +1031,37 @@ static int vfs_ceph_ll_fchmod(struct vfs_handle_struct *handle,
                                          cfh->uperm);
 }
 
-static void vfs_ceph_fill_statx_mask_from_ft(const struct smb_file_time *ft,
+static void vfs_ceph_fill_statx_mask_from_ft(struct smb_file_time *ft,
                                             struct ceph_statx *stx,
                                             int *mask)
 {
+       struct timespec time_now = timespec_current();
+
        if (!is_omit_timespec(&ft->atime)) {
+               if (ft->atime.tv_nsec == UTIME_NOW) {
+                       ft->atime = time_now;
+               }
                stx->stx_atime = ft->atime;
                *mask |= CEPH_SETATTR_ATIME;
        }
        if (!is_omit_timespec(&ft->mtime)) {
+               if (ft->mtime.tv_nsec == UTIME_NOW) {
+                       ft->mtime = time_now;
+               }
                stx->stx_mtime = ft->mtime;
                *mask |= CEPH_SETATTR_MTIME;
        }
        if (!is_omit_timespec(&ft->ctime)) {
+               if (ft->ctime.tv_nsec == UTIME_NOW) {
+                       ft->ctime = time_now;
+               }
                stx->stx_ctime = ft->ctime;
                *mask |= CEPH_SETATTR_CTIME;
        }
        if (!is_omit_timespec(&ft->create_time)) {
+               if (ft->create_time.tv_nsec == UTIME_NOW) {
+                       ft->create_time = time_now;
+               }
                stx->stx_btime = ft->create_time;
                *mask |= CEPH_SETATTR_BTIME;
        }
@@ -1055,7 +1069,7 @@ static void vfs_ceph_fill_statx_mask_from_ft(const struct smb_file_time *ft,
 
 static int vfs_ceph_ll_utimes(struct vfs_handle_struct *handle,
                              const struct vfs_ceph_iref *iref,
-                             const struct smb_file_time *ft)
+                             struct smb_file_time *ft)
 {
        struct ceph_statx stx = {0};
        struct UserPerm *uperm = NULL;
@@ -1094,7 +1108,7 @@ static int vfs_ceph_ll_utimes(struct vfs_handle_struct *handle,
 
 static int vfs_ceph_ll_futimes(struct vfs_handle_struct *handle,
                               const struct vfs_ceph_fh *cfh,
-                              const struct smb_file_time *ft)
+                              struct smb_file_time *ft)
 {
        struct ceph_statx stx = {0};
        int mask = 0;