[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230907-ctime-fixes-v1-2-3b74c970d934@kernel.org>
Date: Thu, 07 Sep 2023 12:33:48 -0400
From: Jeff Layton <jlayton@...nel.org>
To: Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>
Cc: linux-mm@...ck.org, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, Jeff Layton <jlayton@...nel.org>,
kernel test robot <oliver.sang@...el.com>
Subject: [PATCH 2/2] fs: don't update the atime if existing atime is newer
than "now"
It's possible for the atime to be updated with a fine-grained timestamp
and then later get an update that uses a coarse-grained timestamp which
makes the atime appear to go backward.
Fix this by only updating the atime if "now" is later than the current
value.
Reported-by: kernel test robot <oliver.sang@...el.com>
Closes: https://lore.kernel.org/oe-lkp/202309071017.a64aca5e-oliver.sang@intel.com
Signed-off-by: Jeff Layton <jlayton@...nel.org>
---
fs/inode.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/inode.c b/fs/inode.c
index 54237f4242ff..cf4726b7f4b5 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1905,7 +1905,7 @@ int inode_update_timestamps(struct inode *inode, int flags)
}
if (flags & S_ATIME) {
- if (!timespec64_equal(&now, &inode->i_atime)) {
+ if (timespec64_compare(&inode->i_atime, &now) < 0) {
inode->i_atime = now;
updated |= S_ATIME;
}
@@ -1991,7 +1991,7 @@ bool atime_needs_update(const struct path *path, struct inode *inode)
if (!relatime_need_update(mnt, inode, now))
return false;
- if (timespec64_equal(&inode->i_atime, &now))
+ if (timespec64_compare(&inode->i_atime, &now) >= 0)
return false;
return true;
--
2.41.0
Powered by blists - more mailing lists