Blame SOURCES/xfsprogs-5.10.0-xfs_db-report-bigtime-format-timestamps.patch

0bf83d
From 344f38a9e5d0f938dae337c8c769853e6368d480 Mon Sep 17 00:00:00 2001
0bf83d
From: "Darrick J. Wong" <darrick.wong@oracle.com>
0bf83d
Date: Fri, 20 Nov 2020 17:03:28 -0500
0bf83d
Subject: [PATCH] xfs_db: report bigtime format timestamps
0bf83d
0bf83d
Report the large format timestamps in a human-readable manner if it is
0bf83d
possible to do so without loss of information.
0bf83d
0bf83d
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
0bf83d
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
0bf83d
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
0bf83d
---
0bf83d
0bf83d
diff --git a/db/fprint.c b/db/fprint.c
0bf83d
index 72ed55f..65accfd 100644
0bf83d
--- a/db/fprint.c
0bf83d
+++ b/db/fprint.c
0bf83d
@@ -112,6 +112,35 @@ fp_sarray(
0bf83d
 	return 1;
0bf83d
 }
0bf83d
 
0bf83d
+static void
0bf83d
+fp_time64(
0bf83d
+	time64_t		sec)
0bf83d
+{
0bf83d
+	time_t			tt = sec;
0bf83d
+	time64_t		tt_sec = tt;
0bf83d
+	char			*c;
0bf83d
+
0bf83d
+	/*
0bf83d
+	 * Stupid time_t shenanigans -- POSIX.1-2017 only requires that this
0bf83d
+	 * type represent a time in seconds.  Since we have no idea if our
0bf83d
+	 * time64_t filesystem timestamps can actually be represented by the C
0bf83d
+	 * library, we resort to converting the input value from time64_t to
0bf83d
+	 * time_t and back to time64_t to check for information loss.  If so,
0bf83d
+	 * we print the raw value; otherwise we print a human-readable value.
0bf83d
+	 */
0bf83d
+	if (tt_sec != sec)
0bf83d
+		goto raw;
0bf83d
+
0bf83d
+	c = ctime(&tt;;
0bf83d
+	if (!c)
0bf83d
+		goto raw;
0bf83d
+
0bf83d
+	dbprintf("%24.24s", c);
0bf83d
+	return;
0bf83d
+raw:
0bf83d
+	dbprintf("%lld", sec);
0bf83d
+}
0bf83d
+
0bf83d
 int
0bf83d
 fp_time(
0bf83d
 	void			*obj,
0bf83d
@@ -138,7 +167,7 @@ fp_time(
0bf83d
 		ts = obj + byteize(bitpos);
0bf83d
 		tv = libxfs_inode_from_disk_ts(obj, *ts);
0bf83d
 
0bf83d
-		dbprintf("%24.24s", tv.tv_sec);
0bf83d
+		fp_time64(tv.tv_sec);
0bf83d
 
0bf83d
 		if (i < count - 1)
0bf83d
 			dbprintf(" ");
0bf83d
@@ -191,7 +220,8 @@ fp_qtimer(
0bf83d
 	int			base,
0bf83d
 	int			array)
0bf83d
 {
0bf83d
-	uint32_t		sec;
0bf83d
+	struct xfs_disk_dquot	*ddq = obj;
0bf83d
+	time64_t		sec;
0bf83d
 	__be32			*t;
0bf83d
 	int			bitpos;
0bf83d
 	int			i;
0bf83d
@@ -204,9 +234,16 @@ fp_qtimer(
0bf83d
 			dbprintf("%d:", i + base);
0bf83d
 
0bf83d
 		t = obj + byteize(bitpos);
0bf83d
-		sec = be32_to_cpu(*t);
0bf83d
+		sec = libxfs_dquot_from_disk_ts(ddq, *t);
0bf83d
 
0bf83d
-		dbprintf("%u", sec);
0bf83d
+		/*
0bf83d
+		 * Display the raw value if it's the default grace expiration
0bf83d
+		 * period (root dquot) or if the quota has not expired.
0bf83d
+		 */
0bf83d
+		if (ddq->d_id == 0 || sec == 0)
0bf83d
+			dbprintf("%lld", sec);
0bf83d
+		else
0bf83d
+			fp_time64(sec);
0bf83d
 
0bf83d
 		if (i < count - 1)
0bf83d
 			dbprintf(" ");
0bf83d
diff --git a/db/inode.c b/db/inode.c
0bf83d
index bbfee74..37c7dc0 100644
0bf83d
--- a/db/inode.c
0bf83d
+++ b/db/inode.c
0bf83d
@@ -172,10 +172,12 @@ const field_t	inode_v3_flds[] = {
0bf83d
 	{ "cowextsz", FLDT_UINT1,
0bf83d
 	  OI(COFF(flags2) + bitsz(uint64_t) - XFS_DIFLAG2_COWEXTSIZE_BIT-1), C1,
0bf83d
 	  0, TYP_NONE },
0bf83d
+	{ "bigtime", FLDT_UINT1,
0bf83d
+	  OI(COFF(flags2) + bitsz(uint64_t) - XFS_DIFLAG2_BIGTIME_BIT - 1), C1,
0bf83d
+	  0, TYP_NONE },
0bf83d
 	{ NULL }
0bf83d
 };
0bf83d
 
0bf83d
-
0bf83d
 const field_t	timestamp_flds[] = {
0bf83d
 	{ "sec", FLDT_TIME, OI(0), C1, 0, TYP_NONE },
0bf83d
 	{ "nsec", FLDT_NSEC, OI(0), C1, 0, TYP_NONE },
0bf83d
diff --git a/db/sb.c b/db/sb.c
0bf83d
index d63fc71..109fdc3 100644
0bf83d
--- a/db/sb.c
0bf83d
+++ b/db/sb.c
0bf83d
@@ -689,6 +689,8 @@ version_string(
0bf83d
 		strcat(s, ",REFLINK");
0bf83d
 	if (xfs_sb_version_hasinobtcounts(sbp))
0bf83d
 		strcat(s, ",INOBTCNT");
0bf83d
+	if (xfs_sb_version_hasbigtime(sbp))
0bf83d
+		strcat(s, ",BIGTIME");
0bf83d
 	return s;
0bf83d
 }
0bf83d