Blame SOURCES/xfsprogs-5.10.0-xfs-redefine-xfs_timestamp_t.patch

f49185
From a252aadfc977473e0851acf0d529c930c6e8e181 Mon Sep 17 00:00:00 2001
f49185
From: "Darrick J. Wong" <darrick.wong@oracle.com>
f49185
Date: Tue, 10 Nov 2020 16:29:40 -0500
f49185
Subject: [PATCH] xfs: redefine xfs_timestamp_t
f49185
f49185
Source kernel commit: 5a0bb066f60fa02f453d7721844eae59f505c06e
f49185
f49185
Redefine xfs_timestamp_t as a __be64 typedef in preparation for the
f49185
bigtime functionality.  Preserve the legacy structure format so that we
f49185
can let the compiler take care of masking and shifting.
f49185
f49185
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
f49185
Reviewed-by: Christoph Hellwig <hch@lst.de>
f49185
Reviewed-by: Gao Xiang <hsiangkao@redhat.com>
f49185
Reviewed-by: Dave Chinner <dchinner@redhat.com>
f49185
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
f49185
---
f49185
f49185
diff --git a/db/field.c b/db/field.c
f49185
index 66fa37e..4a45c66 100644
f49185
--- a/db/field.c
f49185
+++ b/db/field.c
f49185
@@ -350,7 +350,7 @@ const ftattr_t	ftattrtab[] = {
f49185
 	{ FLDT_TIME, "time", fp_time, NULL, SI(bitsz(int32_t)), FTARG_SIGNED,
f49185
 	  NULL, NULL },
f49185
 	{ FLDT_TIMESTAMP, "timestamp", NULL, (char *)timestamp_flds,
f49185
-	  SI(bitsz(xfs_timestamp_t)), 0, NULL, timestamp_flds },
f49185
+	  SI(bitsz(struct xfs_legacy_timestamp)), 0, NULL, timestamp_flds },
f49185
 	{ FLDT_UINT1, "uint1", fp_num, "%u", SI(1), 0, NULL, NULL },
f49185
 	{ FLDT_UINT16D, "uint16d", fp_num, "%u", SI(bitsz(uint16_t)), 0, NULL,
f49185
 	  NULL },
f49185
diff --git a/db/inode.c b/db/inode.c
f49185
index 697f7fe..b308538 100644
f49185
--- a/db/inode.c
f49185
+++ b/db/inode.c
f49185
@@ -176,7 +176,7 @@ const field_t	inode_v3_flds[] = {
f49185
 };
f49185
 
f49185
 
f49185
-#define	TOFF(f)	bitize(offsetof(xfs_timestamp_t, t_ ## f))
f49185
+#define	TOFF(f)	bitize(offsetof(struct xfs_legacy_timestamp, t_ ## f))
f49185
 const field_t	timestamp_flds[] = {
f49185
 	{ "sec", FLDT_TIME, OI(TOFF(sec)), C1, 0, TYP_NONE },
f49185
 	{ "nsec", FLDT_NSEC, OI(TOFF(nsec)), C1, 0, TYP_NONE },
f49185
diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h
f49185
index 8858341..371f5cd 100644
f49185
--- a/libxfs/xfs_format.h
f49185
+++ b/libxfs/xfs_format.h
f49185
@@ -847,12 +847,16 @@ typedef struct xfs_agfl {
f49185
  * seconds and nanoseconds; time zero is the Unix epoch, Jan  1 00:00:00 UTC
f49185
  * 1970, which means that the timestamp epoch is the same as the Unix epoch.
f49185
  * Therefore, the ondisk min and max defined here can be used directly to
f49185
- * constrain the incore timestamps on a Unix system.
f49185
+ * constrain the incore timestamps on a Unix system.  Note that we actually
f49185
+ * encode a __be64 value on disk.
f49185
  */
f49185
-typedef struct xfs_timestamp {
f49185
+typedef __be64 xfs_timestamp_t;
f49185
+
f49185
+/* Legacy timestamp encoding format. */
f49185
+struct xfs_legacy_timestamp {
f49185
 	__be32		t_sec;		/* timestamp seconds */
f49185
 	__be32		t_nsec;		/* timestamp nanoseconds */
f49185
-} xfs_timestamp_t;
f49185
+};
f49185
 
f49185
 /*
f49185
  * Smallest possible ondisk seconds value with traditional timestamps.  This
f49185
diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c
f49185
index f80ce10..d8831a1 100644
f49185
--- a/libxfs/xfs_inode_buf.c
f49185
+++ b/libxfs/xfs_inode_buf.c
f49185
@@ -195,6 +195,21 @@ xfs_imap_to_bp(
f49185
 	return 0;
f49185
 }
f49185
 
f49185
+/* Convert an ondisk timestamp to an incore timestamp. */
f49185
+struct timespec64
f49185
+xfs_inode_from_disk_ts(
f49185
+	const xfs_timestamp_t		ts)
f49185
+{
f49185
+	struct timespec64		tv;
f49185
+	struct xfs_legacy_timestamp	*lts;
f49185
+
f49185
+	lts = (struct xfs_legacy_timestamp *)&ts;
f49185
+	tv.tv_sec = (int)be32_to_cpu(lts->t_sec);
f49185
+	tv.tv_nsec = (int)be32_to_cpu(lts->t_nsec);
f49185
+
f49185
+	return tv;
f49185
+}
f49185
+
f49185
 void
f49185
 xfs_inode_from_disk(
f49185
 	struct xfs_inode	*ip,
f49185
@@ -231,12 +246,10 @@ xfs_inode_from_disk(
f49185
 	 * a time before epoch is converted to a time long after epoch
f49185
 	 * on 64 bit systems.
f49185
 	 */
f49185
-	inode->i_atime.tv_sec = (int)be32_to_cpu(from->di_atime.t_sec);
f49185
-	inode->i_atime.tv_nsec = (int)be32_to_cpu(from->di_atime.t_nsec);
f49185
-	inode->i_mtime.tv_sec = (int)be32_to_cpu(from->di_mtime.t_sec);
f49185
-	inode->i_mtime.tv_nsec = (int)be32_to_cpu(from->di_mtime.t_nsec);
f49185
-	inode->i_ctime.tv_sec = (int)be32_to_cpu(from->di_ctime.t_sec);
f49185
-	inode->i_ctime.tv_nsec = (int)be32_to_cpu(from->di_ctime.t_nsec);
f49185
+	inode->i_atime = xfs_inode_from_disk_ts(from->di_atime);
f49185
+	inode->i_mtime = xfs_inode_from_disk_ts(from->di_mtime);
f49185
+	inode->i_ctime = xfs_inode_from_disk_ts(from->di_ctime);
f49185
+
f49185
 	inode->i_generation = be32_to_cpu(from->di_gen);
f49185
 	inode->i_mode = be16_to_cpu(from->di_mode);
f49185
 
f49185
@@ -254,13 +267,27 @@ xfs_inode_from_disk(
f49185
 	if (to->di_version == 3) {
f49185
 		inode_set_iversion_queried(inode,
f49185
 					   be64_to_cpu(from->di_changecount));
f49185
-		to->di_crtime.tv_sec = be32_to_cpu(from->di_crtime.t_sec);
f49185
-		to->di_crtime.tv_nsec = be32_to_cpu(from->di_crtime.t_nsec);
f49185
+		to->di_crtime = xfs_inode_from_disk_ts(from->di_crtime);
f49185
 		to->di_flags2 = be64_to_cpu(from->di_flags2);
f49185
 		to->di_cowextsize = be32_to_cpu(from->di_cowextsize);
f49185
 	}
f49185
 }
f49185
 
f49185
+/* Convert an incore timestamp to an ondisk timestamp. */
f49185
+static inline xfs_timestamp_t
f49185
+xfs_inode_to_disk_ts(
f49185
+	const struct timespec64		tv)
f49185
+{
f49185
+	struct xfs_legacy_timestamp	*lts;
f49185
+	xfs_timestamp_t			ts;
f49185
+
f49185
+	lts = (struct xfs_legacy_timestamp *)&ts;
f49185
+	lts->t_sec = cpu_to_be32(tv.tv_sec);
f49185
+	lts->t_nsec = cpu_to_be32(tv.tv_nsec);
f49185
+
f49185
+	return ts;
f49185
+}
f49185
+
f49185
 void
f49185
 xfs_inode_to_disk(
f49185
 	struct xfs_inode	*ip,
f49185
@@ -281,12 +308,9 @@ xfs_inode_to_disk(
f49185
 	to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
f49185
 
f49185
 	memset(to->di_pad, 0, sizeof(to->di_pad));
f49185
-	to->di_atime.t_sec = cpu_to_be32(inode->i_atime.tv_sec);
f49185
-	to->di_atime.t_nsec = cpu_to_be32(inode->i_atime.tv_nsec);
f49185
-	to->di_mtime.t_sec = cpu_to_be32(inode->i_mtime.tv_sec);
f49185
-	to->di_mtime.t_nsec = cpu_to_be32(inode->i_mtime.tv_nsec);
f49185
-	to->di_ctime.t_sec = cpu_to_be32(inode->i_ctime.tv_sec);
f49185
-	to->di_ctime.t_nsec = cpu_to_be32(inode->i_ctime.tv_nsec);
f49185
+	to->di_atime = xfs_inode_to_disk_ts(inode->i_atime);
f49185
+	to->di_mtime = xfs_inode_to_disk_ts(inode->i_mtime);
f49185
+	to->di_ctime = xfs_inode_to_disk_ts(inode->i_ctime);
f49185
 	to->di_nlink = cpu_to_be32(inode->i_nlink);
f49185
 	to->di_gen = cpu_to_be32(inode->i_generation);
f49185
 	to->di_mode = cpu_to_be16(inode->i_mode);
f49185
@@ -304,8 +328,7 @@ xfs_inode_to_disk(
f49185
 
f49185
 	if (from->di_version == 3) {
f49185
 		to->di_changecount = cpu_to_be64(inode_peek_iversion(inode));
f49185
-		to->di_crtime.t_sec = cpu_to_be32(from->di_crtime.tv_sec);
f49185
-		to->di_crtime.t_nsec = cpu_to_be32(from->di_crtime.tv_nsec);
f49185
+		to->di_crtime = xfs_inode_to_disk_ts(from->di_crtime);
f49185
 		to->di_flags2 = cpu_to_be64(from->di_flags2);
f49185
 		to->di_cowextsize = cpu_to_be32(from->di_cowextsize);
f49185
 		to->di_ino = cpu_to_be64(ip->i_ino);
f49185
diff --git a/libxfs/xfs_inode_buf.h b/libxfs/xfs_inode_buf.h
f49185
index 0343368..6147f42 100644
f49185
--- a/libxfs/xfs_inode_buf.h
f49185
+++ b/libxfs/xfs_inode_buf.h
f49185
@@ -76,4 +76,6 @@ xfs_failaddr_t xfs_inode_validate_cowextsize(struct xfs_mount *mp,
f49185
 		uint32_t cowextsize, uint16_t mode, uint16_t flags,
f49185
 		uint64_t flags2);
f49185
 
f49185
+struct timespec64 xfs_inode_from_disk_ts(const xfs_timestamp_t ts);
f49185
+
f49185
 #endif	/* __XFS_INODE_BUF_H__ */
f49185
diff --git a/repair/dinode.c b/repair/dinode.c
f49185
index 8fa5f88..0c40f2a 100644
f49185
--- a/repair/dinode.c
f49185
+++ b/repair/dinode.c
f49185
@@ -2213,9 +2213,12 @@ static void
f49185
 check_nsec(
f49185
 	const char		*name,
f49185
 	xfs_ino_t		lino,
f49185
-	struct xfs_timestamp	*t,
f49185
+	xfs_timestamp_t		*ts,
f49185
 	int			*dirty)
f49185
 {
f49185
+	struct xfs_legacy_timestamp *t;
f49185
+
f49185
+	t = (struct xfs_legacy_timestamp *)ts;
f49185
 	if (be32_to_cpu(t->t_nsec) < NSEC_PER_SEC)
f49185
 		return;
f49185