Blame SOURCES/xfsprogs-5.10.0-xfs_db-refactor-timestamp-printing.patch

0bf83d
From 300422226c423222e78d82d54b09d0ae27c7d4af Mon Sep 17 00:00:00 2001
0bf83d
From: "Darrick J. Wong" <darrick.wong@oracle.com>
0bf83d
Date: Fri, 20 Nov 2020 17:03:27 -0500
0bf83d
Subject: [PATCH] xfs_db: refactor timestamp printing
0bf83d
0bf83d
Introduce type-specific printing functions to xfs_db to print an
0bf83d
xfs_timestamp instead of open-coding the timestamp decoding.  This is
0bf83d
needed to stay ahead of changes that we're going to make to
0bf83d
xfs_timestamp_t in the following patches.
0bf83d
0bf83d
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
0bf83d
Reviewed-by: Christoph Hellwig <hch@lst.de>
0bf83d
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
0bf83d
---
0bf83d
0bf83d
diff --git a/db/field.c b/db/field.c
0bf83d
index 4a45c66..a187a72 100644
0bf83d
--- a/db/field.c
0bf83d
+++ b/db/field.c
0bf83d
@@ -334,8 +334,8 @@ const ftattr_t	ftattrtab[] = {
0bf83d
 	  FTARG_SIGNED, NULL, NULL },
0bf83d
 	{ FLDT_INT8D, "int8d", fp_num, "%d", SI(bitsz(int8_t)), FTARG_SIGNED,
0bf83d
 	  NULL, NULL },
0bf83d
-	{ FLDT_NSEC, "nsec", fp_num, "%09d", SI(bitsz(int32_t)), FTARG_SIGNED,
0bf83d
-	  NULL, NULL },
0bf83d
+	{ FLDT_NSEC, "nsec", fp_nsec, NULL, SI(bitsz(xfs_timestamp_t)),
0bf83d
+	  FTARG_SIGNED, NULL, NULL },
0bf83d
 	{ FLDT_QCNT, "qcnt", fp_num, "%llu", SI(bitsz(xfs_qcnt_t)), 0, NULL,
0bf83d
 	  NULL },
0bf83d
 	{ FLDT_QWARNCNT, "qwarncnt", fp_num, "%u", SI(bitsz(xfs_qwarncnt_t)), 0,
0bf83d
@@ -347,10 +347,10 @@ const ftattr_t	ftattrtab[] = {
0bf83d
 	{ FLDT_SYMLINK_CRC, "symlink", NULL, (char *)symlink_crc_flds,
0bf83d
 	  symlink_size, FTARG_SIZE, NULL, symlink_crc_flds },
0bf83d
 
0bf83d
-	{ FLDT_TIME, "time", fp_time, NULL, SI(bitsz(int32_t)), FTARG_SIGNED,
0bf83d
-	  NULL, NULL },
0bf83d
+	{ FLDT_TIME, "time", fp_time, NULL, SI(bitsz(xfs_timestamp_t)),
0bf83d
+	  FTARG_SIGNED, NULL, NULL },
0bf83d
 	{ FLDT_TIMESTAMP, "timestamp", NULL, (char *)timestamp_flds,
0bf83d
-	  SI(bitsz(struct xfs_legacy_timestamp)), 0, NULL, timestamp_flds },
0bf83d
+	  SI(bitsz(xfs_timestamp_t)), 0, NULL, timestamp_flds },
0bf83d
 	{ FLDT_UINT1, "uint1", fp_num, "%u", SI(1), 0, NULL, NULL },
0bf83d
 	{ FLDT_UINT16D, "uint16d", fp_num, "%u", SI(bitsz(uint16_t)), 0, NULL,
0bf83d
 	  NULL },
0bf83d
diff --git a/db/fprint.c b/db/fprint.c
0bf83d
index c9d07e1..6e72bf0 100644
0bf83d
--- a/db/fprint.c
0bf83d
+++ b/db/fprint.c
0bf83d
@@ -112,22 +112,21 @@ fp_sarray(
0bf83d
 	return 1;
0bf83d
 }
0bf83d
 
0bf83d
-/*ARGSUSED*/
0bf83d
 int
0bf83d
 fp_time(
0bf83d
-	void	*obj,
0bf83d
-	int	bit,
0bf83d
-	int	count,
0bf83d
-	char	*fmtstr,
0bf83d
-	int	size,
0bf83d
-	int	arg,
0bf83d
-	int	base,
0bf83d
-	int	array)
0bf83d
+	void			*obj,
0bf83d
+	int			bit,
0bf83d
+	int			count,
0bf83d
+	char			*fmtstr,
0bf83d
+	int			size,
0bf83d
+	int			arg,
0bf83d
+	int			base,
0bf83d
+	int			array)
0bf83d
 {
0bf83d
-	int	bitpos;
0bf83d
-	char	*c;
0bf83d
-	int	i;
0bf83d
-	time_t  t;
0bf83d
+	struct timespec64	tv;
0bf83d
+	xfs_timestamp_t		*ts;
0bf83d
+	int			bitpos;
0bf83d
+	int			i;
0bf83d
 
0bf83d
 	ASSERT(bitoffs(bit) == 0);
0bf83d
 	for (i = 0, bitpos = bit;
0bf83d
@@ -135,10 +134,46 @@ fp_time(
0bf83d
 	     i++, bitpos += size) {
0bf83d
 		if (array)
0bf83d
 			dbprintf("%d:", i + base);
0bf83d
-		t = (time_t)getbitval((char *)obj + byteize(bitpos), 0,
0bf83d
-				sizeof(int32_t) * 8, BVSIGNED);
0bf83d
-		c = ctime(&t);
0bf83d
-		dbprintf("%24.24s", c);
0bf83d
+
0bf83d
+		ts = obj + byteize(bitpos);
0bf83d
+		tv = libxfs_inode_from_disk_ts(obj, *ts);
0bf83d
+
0bf83d
+		dbprintf("%24.24s", tv.tv_sec);
0bf83d
+
0bf83d
+		if (i < count - 1)
0bf83d
+			dbprintf(" ");
0bf83d
+	}
0bf83d
+	return 1;
0bf83d
+}
0bf83d
+
0bf83d
+int
0bf83d
+fp_nsec(
0bf83d
+	void			*obj,
0bf83d
+	int			bit,
0bf83d
+	int			count,
0bf83d
+	char			*fmtstr,
0bf83d
+	int			size,
0bf83d
+	int			arg,
0bf83d
+	int			base,
0bf83d
+	int			array)
0bf83d
+{
0bf83d
+	struct timespec64	tv;
0bf83d
+	xfs_timestamp_t		*ts;
0bf83d
+	int			bitpos;
0bf83d
+	int			i;
0bf83d
+
0bf83d
+	ASSERT(bitoffs(bit) == 0);
0bf83d
+	for (i = 0, bitpos = bit;
0bf83d
+	     i < count && !seenint();
0bf83d
+	     i++, bitpos += size) {
0bf83d
+		if (array)
0bf83d
+			dbprintf("%d:", i + base);
0bf83d
+
0bf83d
+		ts = obj + byteize(bitpos);
0bf83d
+		tv = libxfs_inode_from_disk_ts(obj, *ts);
0bf83d
+
0bf83d
+		dbprintf("%u", tv.tv_nsec);
0bf83d
+
0bf83d
 		if (i < count - 1)
0bf83d
 			dbprintf(" ");
0bf83d
 	}
0bf83d
diff --git a/db/fprint.h b/db/fprint.h
0bf83d
index c958dca..bfeed15 100644
0bf83d
--- a/db/fprint.h
0bf83d
+++ b/db/fprint.h
0bf83d
@@ -15,6 +15,8 @@ extern int	fp_sarray(void *obj, int bit, int count, char *fmtstr, int size,
0bf83d
 			  int arg, int base, int array);
0bf83d
 extern int	fp_time(void *obj, int bit, int count, char *fmtstr, int size,
0bf83d
 			int arg, int base, int array);
0bf83d
+extern int	fp_nsec(void *obj, int bit, int count, char *fmtstr, int size,
0bf83d
+			int arg, int base, int array);
0bf83d
 extern int	fp_uuid(void *obj, int bit, int count, char *fmtstr, int size,
0bf83d
 			int arg, int base, int array);
0bf83d
 extern int	fp_crc(void *obj, int bit, int count, char *fmtstr, int size,
0bf83d
diff --git a/db/inode.c b/db/inode.c
0bf83d
index b308538..bbfee74 100644
0bf83d
--- a/db/inode.c
0bf83d
+++ b/db/inode.c
0bf83d
@@ -176,10 +176,9 @@ const field_t	inode_v3_flds[] = {
0bf83d
 };
0bf83d
 
0bf83d
 
0bf83d
-#define	TOFF(f)	bitize(offsetof(struct xfs_legacy_timestamp, t_ ## f))
0bf83d
 const field_t	timestamp_flds[] = {
0bf83d
-	{ "sec", FLDT_TIME, OI(TOFF(sec)), C1, 0, TYP_NONE },
0bf83d
-	{ "nsec", FLDT_NSEC, OI(TOFF(nsec)), C1, 0, TYP_NONE },
0bf83d
+	{ "sec", FLDT_TIME, OI(0), C1, 0, TYP_NONE },
0bf83d
+	{ "nsec", FLDT_NSEC, OI(0), C1, 0, TYP_NONE },
0bf83d
 	{ NULL }
0bf83d
 };
0bf83d
 
0bf83d
diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
0bf83d
index f4f7626..00f367e 100644
0bf83d
--- a/libxfs/libxfs_api_defs.h
0bf83d
+++ b/libxfs/libxfs_api_defs.h
0bf83d
@@ -89,6 +89,7 @@
0bf83d
 #define xfs_da_get_buf			libxfs_da_get_buf
0bf83d
 
0bf83d
 #define xfs_inode_from_disk		libxfs_inode_from_disk
0bf83d
+#define xfs_inode_from_disk_ts		libxfs_inode_from_disk_ts
0bf83d
 #define xfs_inode_to_disk		libxfs_inode_to_disk
0bf83d
 #define xfs_dinode_calc_crc		libxfs_dinode_calc_crc
0bf83d
 #define xfs_idata_realloc		libxfs_idata_realloc