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

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