Skip to content

Commit 2d72003

Browse files
Christoph Hellwigbrauner
authored andcommitted
fs: refactor file_update_time_flags
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>
1 parent 85c871a commit 2d72003

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

fs/inode.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,31 +2378,30 @@ struct timespec64 current_time(struct inode *inode)
23782378
}
23792379
EXPORT_SYMBOL(current_time);
23802380

2381+
static inline bool need_cmtime_update(struct inode *inode)
2382+
{
2383+
struct timespec64 now = current_time(inode), ts;
2384+
2385+
ts = inode_get_mtime(inode);
2386+
if (!timespec64_equal(&ts, &now))
2387+
return true;
2388+
ts = inode_get_ctime(inode);
2389+
if (!timespec64_equal(&ts, &now))
2390+
return true;
2391+
return IS_I_VERSION(inode) && inode_iversion_need_inc(inode);
2392+
}
2393+
23812394
static int file_update_time_flags(struct file *file, unsigned int flags)
23822395
{
23832396
struct inode *inode = file_inode(file);
2384-
struct timespec64 now, ts;
2385-
bool need_update = false;
2386-
int ret = 0;
2397+
int ret;
23872398

23882399
/* First try to exhaust all avenues to not sync */
23892400
if (IS_NOCMTIME(inode))
23902401
return 0;
23912402
if (unlikely(file->f_mode & FMODE_NOCMTIME))
23922403
return 0;
2393-
2394-
now = current_time(inode);
2395-
2396-
ts = inode_get_mtime(inode);
2397-
if (!timespec64_equal(&ts, &now))
2398-
need_update = true;
2399-
ts = inode_get_ctime(inode);
2400-
if (!timespec64_equal(&ts, &now))
2401-
need_update = true;
2402-
if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode))
2403-
need_update = true;
2404-
2405-
if (!need_update)
2404+
if (!need_cmtime_update(inode))
24062405
return 0;
24072406

24082407
flags &= IOCB_NOWAIT;

0 commit comments

Comments
 (0)