]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Linux 6.7 compat: zfs_setattr fix atime update
authorRob N <robn@despairlabs.com>
Tue, 16 Jan 2024 22:01:17 +0000 (09:01 +1100)
committerGitHub <noreply@github.com>
Tue, 16 Jan 2024 22:01:17 +0000 (14:01 -0800)
In db4fc559c I messed up and changed this bit of code to set the inode
atime to an uninitialised value, when actually it was just supposed to
loading the atime from the inode to be stored in the SA. This changes it
to what it should have been.

Ensure times change by the right amount Previously, we only checked
if the times changed at all, which missed a bug where the atime was
being set to an undefined value.

Now ensure the times change by two seconds (or thereabouts), ensuring
we catch cases where we set the time to something bonkers

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Sponsored-by: https://despairlabs.com/sponsor/
Closes #15762
Closes #15773

module/os/linux/zfs/zfs_vnops_os.c
tests/zfs-tests/cmd/ctime.c

index 2a766a585b708487301e73ac52f34d2e3f83f5b5..b7b89b8afc564319df68abb558c9109da9321b11 100644 (file)
@@ -2439,9 +2439,8 @@ top:
 
        if ((mask & ATTR_ATIME) || zp->z_atime_dirty) {
                zp->z_atime_dirty = B_FALSE;
-               inode_timespec_t tmp_atime;
+               inode_timespec_t tmp_atime = zpl_inode_get_atime(ip);
                ZFS_TIME_ENCODE(&tmp_atime, atime);
-               zpl_inode_set_atime_to_ts(ZTOI(zp), tmp_atime);
                SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL,
                    &atime, sizeof (atime));
        }
index 0f5d81aea6136cece6e0d32d3f681e759397d96d..5ff1cea8a869842c300144814fd18d9d59743084 100644 (file)
@@ -362,12 +362,20 @@ main(void)
                        return (1);
                }
 
-               if (t1 == t2) {
-                       (void) fprintf(stderr, "%s: t1(%ld) == t2(%ld)\n",
+
+               /*
+                * Ideally, time change would be exactly two seconds, but allow
+                * a little slack in case of scheduling delays or similar.
+                */
+               long delta = (long)t2 - (long)t1;
+               if (delta < 2 || delta > 4) {
+                       (void) fprintf(stderr,
+                           "%s: BAD time change: t1(%ld), t2(%ld)\n",
                            timetest_table[i].name, (long)t1, (long)t2);
                        return (1);
                } else {
-                       (void) fprintf(stderr, "%s: t1(%ld) != t2(%ld)\n",
+                       (void) fprintf(stderr,
+                           "%s: good time change: t1(%ld), t2(%ld)\n",
                            timetest_table[i].name, (long)t1, (long)t2);
                }
        }