diff mbox series

[2/2] fs: don't update the atime if existing atime is newer than "now"

Message ID 20230907-ctime-fixes-v1-2-3b74c970d934@kernel.org (mailing list archive)
State New
Headers show
Series fs: fixes for multigrain ctime code | expand

Commit Message

Jeffrey Layton Sept. 7, 2023, 4:33 p.m. UTC
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@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202309071017.a64aca5e-oliver.sang@intel.com
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jan Kara Sept. 8, 2023, 12:11 p.m. UTC | #1
On Thu 07-09-23 12:33:48, Jeff Layton wrote:
> 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@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202309071017.a64aca5e-oliver.sang@intel.com
> Signed-off-by: Jeff Layton <jlayton@kernel.org>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  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
>
diff mbox series

Patch

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;