From: Jeff Layton <jlayton@xxxxxxxxxx> Source kernel commit: a0a415e34b57368acd262e1172720252c028b936 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. Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx> Reviewed-by: Jan Kara <jack@xxxxxxx> Message-Id: <20230705190309.579783-80-jlayton@xxxxxxxxxx> Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx> --- include/xfs_inode.h | 22 +++++++++++++++++++++- libxfs/xfs_inode_buf.c | 5 +++-- libxfs/xfs_trans_inode.c | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/xfs_inode.h b/include/xfs_inode.h index 069fcf362ec..39b1bee8444 100644 --- a/include/xfs_inode.h +++ b/include/xfs_inode.h @@ -43,7 +43,7 @@ struct inode { uint64_t i_version; struct timespec64 i_atime; struct timespec64 i_mtime; - struct timespec64 i_ctime; + struct timespec64 __i_ctime; /* use inode_*_ctime accessors! */ spinlock_t i_lock; }; @@ -69,6 +69,26 @@ static inline void ihold(struct inode *inode) inode->i_count++; } +/* Userspace does not support multigrain timestamps incore. */ +#define I_CTIME_QUERIED (0) + +static inline struct timespec64 inode_get_ctime(const struct inode *inode) +{ + struct timespec64 ctime; + + ctime.tv_sec = inode->__i_ctime.tv_sec; + ctime.tv_nsec = inode->__i_ctime.tv_nsec & ~I_CTIME_QUERIED; + + return ctime; +} + +static inline struct timespec64 inode_set_ctime_to_ts(struct inode *inode, + struct timespec64 ts) +{ + inode->__i_ctime = ts; + return ts; +} + typedef struct xfs_inode { struct cache_node i_node; struct xfs_mount *i_mount; /* fs mount struct ptr */ diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c index cbcaadbcf69..fccab419354 100644 --- a/libxfs/xfs_inode_buf.c +++ b/libxfs/xfs_inode_buf.c @@ -219,7 +219,8 @@ xfs_inode_from_disk( */ inode->i_atime = xfs_inode_from_disk_ts(from, from->di_atime); inode->i_mtime = xfs_inode_from_disk_ts(from, from->di_mtime); - inode->i_ctime = xfs_inode_from_disk_ts(from, from->di_ctime); + inode_set_ctime_to_ts(inode, + xfs_inode_from_disk_ts(from, from->di_ctime)); ip->i_disk_size = be64_to_cpu(from->di_size); ip->i_nblocks = be64_to_cpu(from->di_nblocks); @@ -313,7 +314,7 @@ xfs_inode_to_disk( to->di_atime = xfs_inode_to_disk_ts(ip, inode->i_atime); to->di_mtime = xfs_inode_to_disk_ts(ip, inode->i_mtime); - to->di_ctime = xfs_inode_to_disk_ts(ip, inode->i_ctime); + to->di_ctime = xfs_inode_to_disk_ts(ip, inode_get_ctime(inode)); to->di_nlink = cpu_to_be32(inode->i_nlink); to->di_gen = cpu_to_be32(inode->i_generation); to->di_mode = cpu_to_be16(inode->i_mode); diff --git a/libxfs/xfs_trans_inode.c b/libxfs/xfs_trans_inode.c index c4f81e5d12a..ca8e823762c 100644 --- a/libxfs/xfs_trans_inode.c +++ b/libxfs/xfs_trans_inode.c @@ -64,7 +64,7 @@ xfs_trans_ichgtime( if (flags & XFS_ICHGTIME_MOD) inode->i_mtime = tv; if (flags & XFS_ICHGTIME_CHG) - inode->i_ctime = tv; + inode_set_ctime_to_ts(inode, tv); if (flags & XFS_ICHGTIME_CREATE) ip->i_crtime = tv; }