[v2,66/92] overlayfs: convert to ctime accessor functions

Message ID 20230705190309.579783-64-jlayton@kernel.org
State New
Headers
Series [v2,01/92] ibmvmc: update ctime in conjunction with mtime on write |

Commit Message

Jeff Layton July 5, 2023, 7:01 p.m. UTC
  In later patches, we're going to change how the inode's ctime field is
used. Switch to using accessor functions instead of raw accesses of
inode->i_ctime.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/overlayfs/file.c | 7 +++++--
 fs/overlayfs/util.c | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)
  

Comments

Jan Kara July 6, 2023, 1:58 p.m. UTC | #1
On Wed 05-07-23 15:01:31, Jeff Layton wrote:
> In later patches, we're going to change how the inode's ctime field is
> used. Switch to using accessor functions instead of raw accesses of
> inode->i_ctime.
> 
> Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
...
> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
> index 21245b00722a..7acd3e3fe790 100644
> --- a/fs/overlayfs/file.c
> +++ b/fs/overlayfs/file.c
...
> @@ -249,10 +250,12 @@ static void ovl_file_accessed(struct file *file)
>  	if (!upperinode)
>  		return;
>  
> +	ctime = inode_get_ctime(inode);
> +	uctime = inode_get_ctime(upperinode);
>  	if ((!timespec64_equal(&inode->i_mtime, &upperinode->i_mtime) ||
> -	     !timespec64_equal(&inode->i_ctime, &upperinode->i_ctime))) {
> +	     !timespec64_equal(&ctime, &uctime))) {
>  		inode->i_mtime = upperinode->i_mtime;
> -		inode->i_ctime = upperinode->i_ctime;
> +		inode_set_ctime_to_ts(inode, inode_get_ctime(upperinode));

I think you can use uctime here instead of inode_get_ctime(upperinode)?
Otherwise the patch looks good. Feel free to add:

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

								Honza
  
Jeff Layton July 6, 2023, 2:01 p.m. UTC | #2
On Thu, 2023-07-06 at 15:58 +0200, Jan Kara wrote:
> On Wed 05-07-23 15:01:31, Jeff Layton wrote:
> > In later patches, we're going to change how the inode's ctime field is
> > used. Switch to using accessor functions instead of raw accesses of
> > inode->i_ctime.
> > 
> > Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> > Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ...
> > diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
> > index 21245b00722a..7acd3e3fe790 100644
> > --- a/fs/overlayfs/file.c
> > +++ b/fs/overlayfs/file.c
> ...
> > @@ -249,10 +250,12 @@ static void ovl_file_accessed(struct file *file)
> >  	if (!upperinode)
> >  		return;
> >  
> > +	ctime = inode_get_ctime(inode);
> > +	uctime = inode_get_ctime(upperinode);
> >  	if ((!timespec64_equal(&inode->i_mtime, &upperinode->i_mtime) ||
> > -	     !timespec64_equal(&inode->i_ctime, &upperinode->i_ctime))) {
> > +	     !timespec64_equal(&ctime, &uctime))) {
> >  		inode->i_mtime = upperinode->i_mtime;
> > -		inode->i_ctime = upperinode->i_ctime;
> > +		inode_set_ctime_to_ts(inode, inode_get_ctime(upperinode));
> 
> I think you can use uctime here instead of inode_get_ctime(upperinode)?
> Otherwise the patch looks good. Feel free to add:
> 
> Reviewed-by: Jan Kara <jack@suse.cz>
> 

Thanks, fixed in tree.
  

Patch

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 21245b00722a..7acd3e3fe790 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -239,6 +239,7 @@  static loff_t ovl_llseek(struct file *file, loff_t offset, int whence)
 static void ovl_file_accessed(struct file *file)
 {
 	struct inode *inode, *upperinode;
+	struct timespec64 ctime, uctime;
 
 	if (file->f_flags & O_NOATIME)
 		return;
@@ -249,10 +250,12 @@  static void ovl_file_accessed(struct file *file)
 	if (!upperinode)
 		return;
 
+	ctime = inode_get_ctime(inode);
+	uctime = inode_get_ctime(upperinode);
 	if ((!timespec64_equal(&inode->i_mtime, &upperinode->i_mtime) ||
-	     !timespec64_equal(&inode->i_ctime, &upperinode->i_ctime))) {
+	     !timespec64_equal(&ctime, &uctime))) {
 		inode->i_mtime = upperinode->i_mtime;
-		inode->i_ctime = upperinode->i_ctime;
+		inode_set_ctime_to_ts(inode, inode_get_ctime(upperinode));
 	}
 
 	touch_atime(&file->f_path);
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index 7ef9e13c404a..c210b5d496a8 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -1202,6 +1202,6 @@  void ovl_copyattr(struct inode *inode)
 	inode->i_mode = realinode->i_mode;
 	inode->i_atime = realinode->i_atime;
 	inode->i_mtime = realinode->i_mtime;
-	inode->i_ctime = realinode->i_ctime;
+	inode_set_ctime_to_ts(inode, inode_get_ctime(realinode));
 	i_size_write(inode, i_size_read(realinode));
 }