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

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