]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fs: refactor file_update_time_flags
authorChristoph Hellwig <hch@lst.de>
Thu, 8 Jan 2026 14:19:09 +0000 (15:19 +0100)
committerChristian Brauner <brauner@kernel.org>
Mon, 12 Jan 2026 13:01:33 +0000 (14:01 +0100)
Split all the inode timestamp flags into a helper.  This not only
makes the code a bit more readable, but also optimizes away the
further checks as soon as know we need an update.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://patch.msgid.link/20260108141934.2052404-10-hch@lst.de
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/inode.c

index cd3ca98e8355b5f4371cde54d90b039db28a468f..5913e1993e4aa18dd29685eac73f2dc4aed66f87 100644 (file)
@@ -2378,31 +2378,30 @@ out:
 }
 EXPORT_SYMBOL(current_time);
 
+static inline bool need_cmtime_update(struct inode *inode)
+{
+       struct timespec64 now = current_time(inode), ts;
+
+       ts = inode_get_mtime(inode);
+       if (!timespec64_equal(&ts, &now))
+               return true;
+       ts = inode_get_ctime(inode);
+       if (!timespec64_equal(&ts, &now))
+               return true;
+       return IS_I_VERSION(inode) && inode_iversion_need_inc(inode);
+}
+
 static int file_update_time_flags(struct file *file, unsigned int flags)
 {
        struct inode *inode = file_inode(file);
-       struct timespec64 now, ts;
-       bool need_update = false;
-       int ret = 0;
+       int ret;
 
        /* First try to exhaust all avenues to not sync */
        if (IS_NOCMTIME(inode))
                return 0;
        if (unlikely(file->f_mode & FMODE_NOCMTIME))
                return 0;
-
-       now = current_time(inode);
-
-       ts = inode_get_mtime(inode);
-       if (!timespec64_equal(&ts, &now))
-               need_update = true;
-       ts = inode_get_ctime(inode);
-       if (!timespec64_equal(&ts, &now))
-               need_update = true;
-       if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode))
-               need_update = true;
-
-       if (!need_update)
+       if (!need_cmtime_update(inode))
                return 0;
 
        flags &= IOCB_NOWAIT;