[PATCH 04/11] fs: delay the actual timestamp updates in inode_update_timestamps

Christoph Hellwig <[email protected]>
Newsgroups dev.linux.lists.gfs2,org.infradead.lists.linux-mtd,org.kernel.vger.io-uring,org.kernel.vger.linux-btrfs,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-nfs,org.kernel.vger.linux-unionfs,org.kernel.vger.linux-xfs
Message-ID <[email protected]>
Perform the actual updates of the inode timestamp at the very end of
inode_update_timestamps after finishing all checks.  This prepares for
adding non-blocking timestamp updates where we might bail out instead of
performing this updates if the update would block.

Signed-off-by: Christoph Hellwig <[email protected]>
---
 fs/inode.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index 876641a6e478..19f50bdb6f7d 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2109,10 +2109,8 @@ int inode_update_timestamps(struct inode *inode, int flags)
 		now = inode_set_ctime_current(inode);
 		if (!timespec64_equal(&now, &ctime))
 			updated |= S_CTIME;
-		if (!timespec64_equal(&now, &mtime)) {
-			inode_set_mtime_to_ts(inode, now);
+		if (!timespec64_equal(&now, &mtime))
 			updated |= S_MTIME;
-		}
 		if (IS_I_VERSION(inode) && inode_maybe_inc_iversion(inode, updated))
 			updated |= S_VERSION;
 	} else {
@@ -2122,11 +2120,14 @@ int inode_update_timestamps(struct inode *inode, int flags)
 	if (flags & S_ATIME) {
 		struct timespec64 atime = inode_get_atime(inode);
 
-		if (!timespec64_equal(&now, &atime)) {
-			inode_set_atime_to_ts(inode, now);
+		if (!timespec64_equal(&now, &atime))
 			updated |= S_ATIME;
-		}
 	}
+
+	if (updated & S_MTIME)
+		inode_set_mtime_to_ts(inode, now);
+	if (updated & S_ATIME)
+		inode_set_atime_to_ts(inode, now);
 	return updated;
 }
 EXPORT_SYMBOL(inode_update_timestamps);
-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.