From: Jeff Layton Date: Tue, 14 Nov 2023 09:39:12 +0000 (+0100) Subject: xfs: convert to ctime accessor functions X-Git-Tag: v6.6.0~61 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6cfd0b487e7608eb63688ed6918c3f69526cb9f1;p=thirdparty%2Fxfsprogs-dev.git xfs: convert to ctime accessor functions 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 Reviewed-by: Jan Kara Message-Id: <20230705190309.579783-80-jlayton@kernel.org> Signed-off-by: Christian Brauner Signed-off-by: Carlos Maiolino --- diff --git a/include/xfs_inode.h b/include/xfs_inode.h index 069fcf362..aefad99dc 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 cbcaadbcf..fccab4193 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 c4f81e5d1..ca8e82376 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; }