Blame SOURCES/xfsprogs-5.10.0-xfs_db-support-printing-time-limits.patch

0bf83d
From 4893718570dac172f639cc5e8687e782c4f759ee 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: support printing time limits
0bf83d
0bf83d
Support printing the minimum and maxium timestamp limits on this
0bf83d
filesystem.
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/Makefile b/db/Makefile
0bf83d
index 8fecfc1..68ab659 100644
0bf83d
--- a/db/Makefile
0bf83d
+++ b/db/Makefile
0bf83d
@@ -14,7 +14,7 @@ HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \
0bf83d
 	io.h logformat.h malloc.h metadump.h output.h print.h quit.h sb.h \
0bf83d
 	sig.h strvec.h text.h type.h write.h attrset.h symlink.h fsmap.h \
0bf83d
 	fuzz.h
0bf83d
-CFILES = $(HFILES:.h=.c) btdump.c info.c
0bf83d
+CFILES = $(HFILES:.h=.c) btdump.c info.c timelimit.c
0bf83d
 LSRCFILES = xfs_admin.sh xfs_ncheck.sh xfs_metadump.sh
0bf83d
 
0bf83d
 LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
0bf83d
diff --git a/db/command.c b/db/command.c
0bf83d
index c7c5234..73b06a7 100644
0bf83d
--- a/db/command.c
0bf83d
+++ b/db/command.c
0bf83d
@@ -139,4 +139,5 @@ init_commands(void)
0bf83d
 	write_init();
0bf83d
 	dquot_init();
0bf83d
 	fuzz_init();
0bf83d
+	timelimit_init();
0bf83d
 }
0bf83d
diff --git a/db/command.h b/db/command.h
0bf83d
index eacfd46..1a9b4d2 100644
0bf83d
--- a/db/command.h
0bf83d
+++ b/db/command.h
0bf83d
@@ -30,3 +30,4 @@ extern void		init_commands(void);
0bf83d
 
0bf83d
 extern void		btdump_init(void);
0bf83d
 extern void		info_init(void);
0bf83d
+extern void		timelimit_init(void);
0bf83d
diff --git a/db/timelimit.c b/db/timelimit.c
0bf83d
new file mode 100644
0bf83d
index 0000000..53a0a39
0bf83d
--- /dev/null
0bf83d
+++ b/db/timelimit.c
0bf83d
@@ -0,0 +1,160 @@
0bf83d
+// SPDX-License-Identifier: GPL-2.0-or-later
0bf83d
+/*
0bf83d
+ * Copyright (C) 2020 Oracle.  All Rights Reserved.
0bf83d
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
0bf83d
+ */
0bf83d
+#include "libxfs.h"
0bf83d
+#include "command.h"
0bf83d
+#include "output.h"
0bf83d
+#include "init.h"
0bf83d
+
0bf83d
+enum show_what {
0bf83d
+	SHOW_AUTO,
0bf83d
+	SHOW_CLASSIC,
0bf83d
+	SHOW_BIGTIME,
0bf83d
+};
0bf83d
+
0bf83d
+
0bf83d
+enum print_how {
0bf83d
+	PRINT_RAW,
0bf83d
+	PRINT_PRETTY,
0bf83d
+	PRINT_COMPACT,
0bf83d
+};
0bf83d
+
0bf83d
+static void
0bf83d
+show_limit(
0bf83d
+	const char	*tag,
0bf83d
+	int64_t		limit,
0bf83d
+	enum print_how	how)
0bf83d
+{
0bf83d
+	if (how == PRINT_COMPACT) {
0bf83d
+		dbprintf("%" PRId64 " ", limit);
0bf83d
+		return;
0bf83d
+	}
0bf83d
+
0bf83d
+	if (how == PRINT_PRETTY && limit <= LONG_MAX && limit >= LONG_MIN) {
0bf83d
+		time_t	tt = limit;
0bf83d
+		char	*c;
0bf83d
+
0bf83d
+		c = ctime(&tt;;
0bf83d
+		if (c) {
0bf83d
+			dbprintf("%s = %24.24s\n", tag, c);
0bf83d
+			return;
0bf83d
+		}
0bf83d
+	}
0bf83d
+
0bf83d
+	dbprintf("%s = %" PRId64 "\n", tag, limit);
0bf83d
+}
0bf83d
+
0bf83d
+static void
0bf83d
+show_limits(
0bf83d
+	enum show_what	whatkind,
0bf83d
+	enum print_how	how)
0bf83d
+{
0bf83d
+	enum print_how	grace_how = how;
0bf83d
+
0bf83d
+	switch (whatkind) {
0bf83d
+	case SHOW_AUTO:
0bf83d
+		/* should never get here */
0bf83d
+		break;
0bf83d
+	case SHOW_CLASSIC:
0bf83d
+		show_limit("time.min", XFS_LEGACY_TIME_MIN, how);
0bf83d
+		show_limit("time.max", XFS_LEGACY_TIME_MAX, how);
0bf83d
+		show_limit("dqtimer.min", XFS_DQ_LEGACY_EXPIRY_MIN, how);
0bf83d
+		show_limit("dqtimer.max", XFS_DQ_LEGACY_EXPIRY_MAX, how);
0bf83d
+		break;
0bf83d
+	case SHOW_BIGTIME:
0bf83d
+		show_limit("time.min",
0bf83d
+				xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MIN), how);
0bf83d
+		show_limit("time.max",
0bf83d
+				xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MAX), how);
0bf83d
+		show_limit("dqtimer.min",
0bf83d
+				xfs_dq_bigtime_to_unix(XFS_DQ_BIGTIME_EXPIRY_MIN),
0bf83d
+				how);
0bf83d
+		show_limit("dqtimer.max",
0bf83d
+				xfs_dq_bigtime_to_unix(XFS_DQ_BIGTIME_EXPIRY_MAX),
0bf83d
+				how);
0bf83d
+		break;
0bf83d
+	}
0bf83d
+
0bf83d
+	/* grace periods are always integers */
0bf83d
+	if (grace_how != PRINT_COMPACT)
0bf83d
+		grace_how = PRINT_RAW;
0bf83d
+	show_limit("dqgrace.min", XFS_DQ_GRACE_MIN, grace_how);
0bf83d
+	show_limit("dqgrace.min", XFS_DQ_GRACE_MAX, grace_how);
0bf83d
+
0bf83d
+	if (how == PRINT_COMPACT)
0bf83d
+		dbprintf("\n");
0bf83d
+}
0bf83d
+
0bf83d
+static int
0bf83d
+timelimit_f(
0bf83d
+	int		argc,
0bf83d
+	char		**argv)
0bf83d
+{
0bf83d
+	enum show_what	whatkind = SHOW_AUTO;
0bf83d
+	enum print_how	how = PRINT_RAW;
0bf83d
+	int		i;
0bf83d
+
0bf83d
+	for (i = 1; i < argc; i++) {
0bf83d
+		if (!strcmp("--classic", argv[i]))
0bf83d
+			whatkind = SHOW_CLASSIC;
0bf83d
+		else if (!strcmp("--bigtime", argv[i]))
0bf83d
+			whatkind = SHOW_BIGTIME;
0bf83d
+		else if (!strcmp("--pretty", argv[i]))
0bf83d
+			how = PRINT_PRETTY;
0bf83d
+		else if (!strcmp("--compact", argv[i]))
0bf83d
+			how = PRINT_COMPACT;
0bf83d
+		else {
0bf83d
+			dbprintf(_("%s: bad option for timelimit command\n"),
0bf83d
+					argv[i]);
0bf83d
+			return 1;
0bf83d
+		}
0bf83d
+	}
0bf83d
+
0bf83d
+	if (whatkind == SHOW_AUTO) {
0bf83d
+		if (xfs_sb_version_hasbigtime(&mp->m_sb))
0bf83d
+			whatkind = SHOW_BIGTIME;
0bf83d
+		else
0bf83d
+			whatkind = SHOW_CLASSIC;
0bf83d
+	}
0bf83d
+
0bf83d
+	show_limits(whatkind, how);
0bf83d
+	return 0;
0bf83d
+}
0bf83d
+
0bf83d
+static void
0bf83d
+timelimit_help(void)
0bf83d
+{
0bf83d
+	dbprintf(_(
0bf83d
+"\n"
0bf83d
+" Print the minimum and maximum supported values for inode timestamps,\n"
0bf83d
+" disk quota expiration timers, and disk quota grace periods supported\n"
0bf83d
+" by this filesystem.\n"
0bf83d
+"\n"
0bf83d
+" Options:\n"
0bf83d
+"   --classic -- Force printing of the classic time limits.\n"
0bf83d
+"   --bigtime -- Force printing of the bigtime limits.\n"
0bf83d
+"   --pretty  -- Pretty-print the time limits.\n"
0bf83d
+"   --compact -- Print the limits in a single line.\n"
0bf83d
+"\n"
0bf83d
+));
0bf83d
+
0bf83d
+}
0bf83d
+
0bf83d
+static const cmdinfo_t	timelimit_cmd = {
0bf83d
+	.name		= "timelimit",
0bf83d
+	.cfunc		= timelimit_f,
0bf83d
+	.argmin		= 0,
0bf83d
+	.argmax		= -1,
0bf83d
+	.canpush	= 0,
0bf83d
+	.args		= N_("[--classic|--bigtime] [--pretty]"),
0bf83d
+	.oneline	= N_("display timestamp limits"),
0bf83d
+	.help		= timelimit_help,
0bf83d
+};
0bf83d
+
0bf83d
+void
0bf83d
+timelimit_init(void)
0bf83d
+{
0bf83d
+	add_command(&timelimit_cmd);
0bf83d
+}
0bf83d
diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8
0bf83d
index a1ee351..f46e936 100644
0bf83d
--- a/man/man8/xfs_db.8
0bf83d
+++ b/man/man8/xfs_db.8
0bf83d
@@ -785,6 +785,29 @@ The possible data types are:
0bf83d
 .BR rtsummary ", " sb ", " symlink " and " text .
0bf83d
 See the TYPES section below for more information on these data types.
0bf83d
 .TP
0bf83d
+.BI "timelimit [" OPTIONS ]
0bf83d
+Print the minimum and maximum supported values for inode timestamps,
0bf83d
+quota expiration timers, and quota grace periods supported by this
0bf83d
+filesystem.
0bf83d
+Options include:
0bf83d
+.RS 1.0i
0bf83d
+.TP 0.4i
0bf83d
+.B \--bigtime
0bf83d
+Print the time limits of an XFS filesystem with the
0bf83d
+.B bigtime
0bf83d
+feature enabled.
0bf83d
+.TP 0.4i
0bf83d
+.B \--classic
0bf83d
+Print the time limits of a classic XFS filesystem.
0bf83d
+.TP 0.4i
0bf83d
+.B \--compact
0bf83d
+Print all limits as raw values on a single line.
0bf83d
+.TP 0.4i
0bf83d
+.B \--pretty
0bf83d
+Print the timestamps in the current locale's date and time format instead of
0bf83d
+raw seconds since the Unix epoch.
0bf83d
+.RE
0bf83d
+.TP
0bf83d
 .BI "uuid [" uuid " | " generate " | " rewrite " | " restore ]
0bf83d
 Set the filesystem universally unique identifier (UUID).
0bf83d
 The filesystem UUID can be used by