[PATCH 01/26] libxfs: create a real struct timespec64

Darrick J. Wong
2020-10-26T23:34:19Z

From: Darrick J. Wong <darrick.wong@oracle.com>

Create a real struct timespec64 that supports 64-bit seconds counts.
The C library struct timespec doesn't support this on 32-bit
architectures and we cannot lose the upper bits in the incore inode.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
---
include/libxfs.h | 1 -
include/xfs_fs_compat.h | 8 ++++++++
include/xfs_inode.h | 22 +++++++++++-----------
libxfs/libxfs_priv.h | 2 --
4 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/include/libxfs.h b/include/libxfs.h
index b9370139becc..2667d3b77084 100644
--- a/include/libxfs.h
+++ b/include/libxfs.h
@@ -41,7 +41,6 @@ struct iomap;
#define __round_mask(x, y) ((__typeof__(x))((y)-1))
#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
#define unlikely(x) (x)
-#define timespec64 timespec

/*
* This mirrors the kernel include for xfs_buf.h - it's implicitly included in
diff --git a/include/xfs_fs_compat.h b/include/xfs_fs_compat.h
index 154a802d9aed..d0ffc9775875 100644
--- a/include/xfs_fs_compat.h
+++ b/include/xfs_fs_compat.h
@@ -85,4 +85,12 @@ struct xfs_extent_data {
#define XFS_IOC_CLONE_RANGE _IOW (0x94, 13, struct xfs_clone_args)
#define XFS_IOC_FILE_EXTENT_SAME _IOWR(0x94, 54, struct xfs_extent_data)

+/* 64-bit seconds counter that works independently of the C library time_t. */
+typedef long long int time64_t;
+
+struct timespec64 {
+ time64_t tv_sec; /* seconds */
+ long tv_nsec; /* nanoseconds */
+};
+
#endif /* __XFS_FS_COMPAT_H__ */
diff --git a/include/xfs_inode.h b/include/xfs_inode.h
index 588d8c7258f4..12676cb30bf2 100644
--- a/include/xfs_inode.h
+++ b/include/xfs_inode.h
@@ -31,17 +31,17 @@ struct xfs_inode_log_item;
* metadata.
*/
struct inode {
- mode_t i_mode;
- uint32_t i_uid;
- uint32_t i_gid;
- uint32_t i_nlink;
- xfs_dev_t i_rdev; /* This actually holds xfs_dev_t */
- unsigned long i_state; /* Not actually used in userspace */
- uint32_t i_generation;
- uint64_t i_version;
- struct timespec i_atime;
- struct timespec i_mtime;
- struct timespec i_ctime;
+ mode_t i_mode;
+ uint32_t i_uid;
+ uint32_t i_gid;
+ uint32_t i_nlink;
+ xfs_dev_t i_rdev; /* This actually holds xfs_dev_t */
+ unsigned long i_state; /* Not actually used in userspace */
+ uint32_t i_generation;
+ uint64_t i_version;
+ struct timespec64 i_atime;
+ struct timespec64 i_mtime;
+ struct timespec64 i_ctime;
};

static inline uint32_t i_uid_read(struct inode *inode)
diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index bd724c32c263..e92269f0bdae 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -64,8 +64,6 @@ extern kmem_zone_t *xfs_buf_zone;
extern kmem_zone_t *xfs_inode_zone;
extern kmem_zone_t *xfs_trans_zone;

-#define timespec64 timespec
-
/* fake up iomap, (not) used in xfs_bmap.[ch] */
#define IOMAP_F_SHARED 0x04
#define xfs_bmbt_to_iomap(a, b, c, d) ((void) 0)