]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: add a command to display allocation group information
authorDarrick J. Wong <djwong@kernel.org>
Thu, 21 Nov 2024 00:24:39 +0000 (16:24 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 24 Dec 2024 02:01:34 +0000 (18:01 -0800)
Add a new 'aginfo' command to xfs_io so that we can display allocation
group geometry.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
io/Makefile
io/aginfo.c [new file with mode: 0644]
io/init.c
io/io.h
man/man8/xfs_io.8

index c33d57f5e10b8fdb422195f9df4680c83753791a..8f835ec71fd768c81f76efd13cb039854271d744 100644 (file)
@@ -9,6 +9,7 @@ LTCOMMAND = xfs_io
 LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh xfs_property
 HFILES = init.h io.h
 CFILES = \
+       aginfo.c \
        attr.c \
        bmap.c \
        bulkstat.c \
diff --git a/io/aginfo.c b/io/aginfo.c
new file mode 100644 (file)
index 0000000..6cbfcb8
--- /dev/null
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021-2024 Oracle.  All rights reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#include "platform_defs.h"
+#include "libxfs.h"
+#include "command.h"
+#include "input.h"
+#include "init.h"
+#include "io.h"
+#include "libfrog/logging.h"
+#include "libfrog/paths.h"
+#include "libfrog/fsgeom.h"
+
+static cmdinfo_t aginfo_cmd;
+
+static int
+report_aginfo(
+       struct xfs_fd           *xfd,
+       xfs_agnumber_t          agno)
+{
+       struct xfs_ag_geometry  ageo = { 0 };
+       int                     ret;
+
+       ret = -xfrog_ag_geometry(xfd->fd, agno, &ageo);
+       if (ret) {
+               xfrog_perror(ret, "aginfo");
+               return 1;
+       }
+
+       printf(_("AG: %u\n"),           ageo.ag_number);
+       printf(_("Blocks: %u\n"),       ageo.ag_length);
+       printf(_("Free Blocks: %u\n"),  ageo.ag_freeblks);
+       printf(_("Inodes: %u\n"),       ageo.ag_icount);
+       printf(_("Free Inodes: %u\n"),  ageo.ag_ifree);
+       printf(_("Sick: 0x%x\n"),       ageo.ag_sick);
+       printf(_("Checked: 0x%x\n"),    ageo.ag_checked);
+       printf(_("Flags: 0x%x\n"),      ageo.ag_flags);
+
+       return 0;
+}
+
+/* Display AG status. */
+static int
+aginfo_f(
+       int                     argc,
+       char                    **argv)
+{
+       struct xfs_fd           xfd = XFS_FD_INIT(file->fd);
+       unsigned long long      x;
+       xfs_agnumber_t          agno = NULLAGNUMBER;
+       int                     c;
+       int                     ret = 0;
+
+       ret = -xfd_prepare_geometry(&xfd);
+       if (ret) {
+               xfrog_perror(ret, "xfd_prepare_geometry");
+               exitcode = 1;
+               return 1;
+       }
+
+       while ((c = getopt(argc, argv, "a:")) != EOF) {
+               switch (c) {
+               case 'a':
+                       errno = 0;
+                       x = strtoll(optarg, NULL, 10);
+                       if (!errno && x >= NULLAGNUMBER)
+                               errno = ERANGE;
+                       if (errno) {
+                               perror("aginfo");
+                               return 1;
+                       }
+                       agno = x;
+                       break;
+               default:
+                       return command_usage(&aginfo_cmd);
+               }
+       }
+
+       if (agno != NULLAGNUMBER) {
+               ret = report_aginfo(&xfd, agno);
+       } else {
+               for (agno = 0; !ret && agno < xfd.fsgeom.agcount; agno++) {
+                       ret = report_aginfo(&xfd, agno);
+               }
+       }
+
+       return ret;
+}
+
+static void
+aginfo_help(void)
+{
+       printf(_(
+"\n"
+"Report allocation group geometry.\n"
+"\n"
+" -a agno  -- Report on the given allocation group.\n"
+"\n"));
+
+}
+
+static cmdinfo_t aginfo_cmd = {
+       .name = "aginfo",
+       .cfunc = aginfo_f,
+       .argmin = 0,
+       .argmax = -1,
+       .args = "[-a agno]",
+       .flags = CMD_NOMAP_OK,
+       .help = aginfo_help,
+};
+
+void
+aginfo_init(void)
+{
+       aginfo_cmd.oneline = _("Get XFS allocation group state.");
+       add_command(&aginfo_cmd);
+}
index 5727f73515a6a24e673c4e860eec945dbc779e4b..4831deae1b268396523dc876fa48e4a5d627de0e 100644 (file)
--- a/io/init.c
+++ b/io/init.c
@@ -44,6 +44,7 @@ init_cvtnum(
 static void
 init_commands(void)
 {
+       aginfo_init();
        attr_init();
        bmap_init();
        bulkstat_init();
diff --git a/io/io.h b/io/io.h
index 4daedac06419aeaf73162ebeff667934bd026329..d99065582057de77f8100002bba270beea72a587 100644 (file)
--- a/io/io.h
+++ b/io/io.h
@@ -155,3 +155,4 @@ extern void         crc32cselftest_init(void);
 extern void            bulkstat_init(void);
 void                   exchangerange_init(void);
 void                   fsprops_init(void);
+void                   aginfo_init(void);
index 4673b071901c285a573f6d029ba051ac7386ff63..31c81efed8f99ba32a586b4a16ebc35241a22ffb 100644 (file)
@@ -1242,6 +1242,18 @@ Dumps a list of pages or ranges of pages that are currently in core,
 for the current memory mapping.
 
 .SH FILESYSTEM COMMANDS
+.TP
+.BI "aginfo [ \-a " agno " ]"
+Show information about or update the state of allocation groups.
+.RE
+.RS 1.0i
+.PD 0
+.TP
+.BI \-a
+Act only on a specific allocation group.
+.PD
+.RE
+
 .TP
 .BI "bulkstat [ \-a " agno " ] [ \-d ] [ \-e " endino " ] [ \-m ] [ \-n " batchsize " ] [ \-q ] [ \-s " startino " ] [ \-v " version" ]
 Display raw stat information about a bunch of inodes in an XFS filesystem.