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

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