mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 11:06:41 -05:00
fs: refactor file timestamp update logic
Currently the two high-level APIs use two helper functions to implement almost all of the logic. Refactor the two helpers and the common logic into a new file_update_time_flags routine that gets the iocb flags or 0 in case of file_update_time passed so that the entire logic is contained in a single function and can be easily understood and modified. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://patch.msgid.link/20251120064859.2911749-2-hch@lst.de Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
committed by
Christian Brauner
parent
54ca9e913e
commit
3cd9a42f1b
54
fs/inode.c
54
fs/inode.c
@@ -2310,10 +2310,12 @@ struct timespec64 current_time(struct inode *inode)
|
||||
}
|
||||
EXPORT_SYMBOL(current_time);
|
||||
|
||||
static int inode_needs_update_time(struct inode *inode)
|
||||
static int file_update_time_flags(struct file *file, unsigned int flags)
|
||||
{
|
||||
struct inode *inode = file_inode(file);
|
||||
struct timespec64 now, ts;
|
||||
int sync_it = 0;
|
||||
int sync_mode = 0;
|
||||
int ret = 0;
|
||||
|
||||
/* First try to exhaust all avenues to not sync */
|
||||
if (IS_NOCMTIME(inode))
|
||||
@@ -2323,29 +2325,23 @@ static int inode_needs_update_time(struct inode *inode)
|
||||
|
||||
ts = inode_get_mtime(inode);
|
||||
if (!timespec64_equal(&ts, &now))
|
||||
sync_it |= S_MTIME;
|
||||
|
||||
sync_mode |= S_MTIME;
|
||||
ts = inode_get_ctime(inode);
|
||||
if (!timespec64_equal(&ts, &now))
|
||||
sync_it |= S_CTIME;
|
||||
|
||||
sync_mode |= S_CTIME;
|
||||
if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode))
|
||||
sync_it |= S_VERSION;
|
||||
sync_mode |= S_VERSION;
|
||||
|
||||
return sync_it;
|
||||
}
|
||||
if (!sync_mode)
|
||||
return 0;
|
||||
|
||||
static int __file_update_time(struct file *file, int sync_mode)
|
||||
{
|
||||
int ret = 0;
|
||||
struct inode *inode = file_inode(file);
|
||||
|
||||
/* try to update time settings */
|
||||
if (!mnt_get_write_access_file(file)) {
|
||||
ret = inode_update_time(inode, sync_mode);
|
||||
mnt_put_write_access_file(file);
|
||||
}
|
||||
if (flags & IOCB_NOWAIT)
|
||||
return -EAGAIN;
|
||||
|
||||
if (mnt_get_write_access_file(file))
|
||||
return 0;
|
||||
ret = inode_update_time(inode, sync_mode);
|
||||
mnt_put_write_access_file(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -2365,14 +2361,7 @@ static int __file_update_time(struct file *file, int sync_mode)
|
||||
*/
|
||||
int file_update_time(struct file *file)
|
||||
{
|
||||
int ret;
|
||||
struct inode *inode = file_inode(file);
|
||||
|
||||
ret = inode_needs_update_time(inode);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
|
||||
return __file_update_time(file, ret);
|
||||
return file_update_time_flags(file, 0);
|
||||
}
|
||||
EXPORT_SYMBOL(file_update_time);
|
||||
|
||||
@@ -2394,7 +2383,6 @@ EXPORT_SYMBOL(file_update_time);
|
||||
static int file_modified_flags(struct file *file, int flags)
|
||||
{
|
||||
int ret;
|
||||
struct inode *inode = file_inode(file);
|
||||
|
||||
/*
|
||||
* Clear the security bits if the process is not being run by root.
|
||||
@@ -2403,17 +2391,9 @@ static int file_modified_flags(struct file *file, int flags)
|
||||
ret = file_remove_privs_flags(file, flags);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (unlikely(file->f_mode & FMODE_NOCMTIME))
|
||||
return 0;
|
||||
|
||||
ret = inode_needs_update_time(inode);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
if (flags & IOCB_NOWAIT)
|
||||
return -EAGAIN;
|
||||
|
||||
return __file_update_time(file, ret);
|
||||
return file_update_time_flags(file, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user