]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: scrub the realtime group superblock
authorDarrick J. Wong <djwong@kernel.org>
Mon, 23 Sep 2024 20:41:36 +0000 (13:41 -0700)
committerChristoph Hellwig <hch@lst.de>
Wed, 9 Oct 2024 13:55:41 +0000 (15:55 +0200)
Enable scrubbing of realtime group superblocks.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/Makefile
fs/xfs/libxfs/xfs_fs.h
fs/xfs/scrub/common.h
fs/xfs/scrub/health.c
fs/xfs/scrub/rgsuper.c [new file with mode: 0644]
fs/xfs/scrub/scrub.c
fs/xfs/scrub/scrub.h
fs/xfs/scrub/stats.c
fs/xfs/scrub/trace.h

index 6814debac299294058444b0b50e7ed2c9ec77acb..ed9b0dabc1f11d49e4d82d879de227e24aa36024 100644 (file)
@@ -191,6 +191,7 @@ xfs-y                               += $(addprefix scrub/, \
 xfs-$(CONFIG_XFS_ONLINE_SCRUB_STATS) += scrub/stats.o
 
 xfs-$(CONFIG_XFS_RT)           += $(addprefix scrub/, \
+                                  rgsuper.o \
                                   rtbitmap.o \
                                   rtsummary.o \
                                   )
index a40ae45066258b277916b8376d5f0b2a2a6f5dfe..e5cf94de1651b38a642aea053f6cb8b19977904f 100644 (file)
@@ -737,9 +737,10 @@ struct xfs_scrub_metadata {
 #define XFS_SCRUB_TYPE_HEALTHY 27      /* everything checked out ok */
 #define XFS_SCRUB_TYPE_DIRTREE 28      /* directory tree structure */
 #define XFS_SCRUB_TYPE_METAPATH        29      /* metadata directory tree paths */
+#define XFS_SCRUB_TYPE_RGSUPER 30      /* realtime superblock */
 
 /* Number of scrub subcommands. */
-#define XFS_SCRUB_TYPE_NR      30
+#define XFS_SCRUB_TYPE_NR      31
 
 /*
  * This special type code only applies to the vectored scrub implementation.
index 672ed48d4a9fc36e3c71097876a3e928fbd85607..9ff3cafd867962755b97742a766be53109c7aaef 100644 (file)
@@ -79,9 +79,11 @@ int xchk_setup_metapath(struct xfs_scrub *sc);
 #ifdef CONFIG_XFS_RT
 int xchk_setup_rtbitmap(struct xfs_scrub *sc);
 int xchk_setup_rtsummary(struct xfs_scrub *sc);
+int xchk_setup_rgsuperblock(struct xfs_scrub *sc);
 #else
 # define xchk_setup_rtbitmap           xchk_setup_nothing
 # define xchk_setup_rtsummary          xchk_setup_nothing
+# define xchk_setup_rgsuperblock       xchk_setup_nothing
 #endif
 #ifdef CONFIG_XFS_QUOTA
 int xchk_ino_dqattach(struct xfs_scrub *sc);
index 525f9c85ec83e5c210187e62b9e3d6ab8c26d4ac..bb4a52d4917b1718a000efcd75f3369c71f832c7 100644 (file)
@@ -111,6 +111,7 @@ static const struct xchk_health_map type_to_health_flag[XFS_SCRUB_TYPE_NR] = {
        [XFS_SCRUB_TYPE_NLINKS]         = { XHG_FS,  XFS_SICK_FS_NLINKS },
        [XFS_SCRUB_TYPE_DIRTREE]        = { XHG_INO, XFS_SICK_INO_DIRTREE },
        [XFS_SCRUB_TYPE_METAPATH]       = { XHG_FS,  XFS_SICK_FS_METAPATH },
+       [XFS_SCRUB_TYPE_RGSUPER]        = { XHG_RTGROUP, XFS_SICK_RG_SUPER },
 };
 
 /* Return the health status mask for this scrub type. */
diff --git a/fs/xfs/scrub/rgsuper.c b/fs/xfs/scrub/rgsuper.c
new file mode 100644 (file)
index 0000000..00dfe04
--- /dev/null
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022-2024 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#include "xfs.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_rtgroup.h"
+#include "scrub/scrub.h"
+#include "scrub/common.h"
+
+/* Set us up with a transaction and an empty context. */
+int
+xchk_setup_rgsuperblock(
+       struct xfs_scrub        *sc)
+{
+       return xchk_trans_alloc(sc, 0);
+}
+
+/* Cross-reference with the other rt metadata. */
+STATIC void
+xchk_rgsuperblock_xref(
+       struct xfs_scrub        *sc)
+{
+       if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
+               return;
+
+       xchk_xref_is_used_rt_space(sc, xfs_rgbno_to_rtb(sc->sr.rtg, 0), 1);
+}
+
+int
+xchk_rgsuperblock(
+       struct xfs_scrub        *sc)
+{
+       xfs_rgnumber_t          rgno = sc->sm->sm_agno;
+       int                     error;
+
+       /*
+        * Only rtgroup 0 has a superblock.  We may someday want to use higher
+        * rgno for other functions, similar to what we do with the primary
+        * super scrub function.
+        */
+       if (rgno != 0)
+               return -ENOENT;
+
+       /*
+        * Grab an active reference to the rtgroup structure.  If we can't get
+        * it, we're racing with something that's tearing down the group, so
+        * signal that the group no longer exists.  Take the rtbitmap in shared
+        * mode so that the group can't change while we're doing things.
+        */
+       error = xchk_rtgroup_init_existing(sc, rgno, &sc->sr);
+       if (!xchk_xref_process_error(sc, 0, 0, &error))
+               return error;
+
+       xchk_rtgroup_lock(&sc->sr, XFS_RTGLOCK_BITMAP_SHARED);
+
+       /*
+        * Since we already validated the rt superblock at mount time, we don't
+        * need to check its contents again.  All we need is to cross-reference.
+        */
+       xchk_rgsuperblock_xref(sc);
+       return 0;
+}
index 910825d4b61a294a0092e2cb56e6355636f8e0d6..fc8476c522746ee984962ef0ce0d27d06209edc2 100644 (file)
@@ -451,6 +451,13 @@ static const struct xchk_meta_ops meta_scrub_ops[] = {
                .has    = xfs_has_metadir,
                .repair = xrep_metapath,
        },
+       [XFS_SCRUB_TYPE_RGSUPER] = {    /* realtime group superblock */
+               .type   = ST_RTGROUP,
+               .setup  = xchk_setup_rgsuperblock,
+               .scrub  = xchk_rgsuperblock,
+               .has    = xfs_has_rtsb,
+               .repair = xrep_notsupported,
+       },
 };
 
 static int
index f73c6d0d90a11ab2d13873d2ae3f1688093a8a62..a7fda3e2b013776459cb4efe1c5ac1345148f2a2 100644 (file)
@@ -273,9 +273,11 @@ int xchk_metapath(struct xfs_scrub *sc);
 #ifdef CONFIG_XFS_RT
 int xchk_rtbitmap(struct xfs_scrub *sc);
 int xchk_rtsummary(struct xfs_scrub *sc);
+int xchk_rgsuperblock(struct xfs_scrub *sc);
 #else
 # define xchk_rtbitmap         xchk_nothing
 # define xchk_rtsummary                xchk_nothing
+# define xchk_rgsuperblock     xchk_nothing
 #endif
 #ifdef CONFIG_XFS_QUOTA
 int xchk_quota(struct xfs_scrub *sc);
index edcd02dc2e62c0dd465fe94095bbc0e9f2d26f96..a476c7b2ab75973ba5bd6754bebd7f493181ecf7 100644 (file)
@@ -81,6 +81,7 @@ static const char *name_map[XFS_SCRUB_TYPE_NR] = {
        [XFS_SCRUB_TYPE_NLINKS]         = "nlinks",
        [XFS_SCRUB_TYPE_DIRTREE]        = "dirtree",
        [XFS_SCRUB_TYPE_METAPATH]       = "metapath",
+       [XFS_SCRUB_TYPE_RGSUPER]        = "rgsuper",
 };
 
 /* Format the scrub stats into a text buffer, similar to pcp style. */
index b6c8d0944fa453a2751b9568aab101063221c0c5..9b38f5ad1eaf07bcd619c1dca22425a099a360d3 100644 (file)
@@ -71,6 +71,7 @@ TRACE_DEFINE_ENUM(XFS_SCRUB_TYPE_HEALTHY);
 TRACE_DEFINE_ENUM(XFS_SCRUB_TYPE_DIRTREE);
 TRACE_DEFINE_ENUM(XFS_SCRUB_TYPE_BARRIER);
 TRACE_DEFINE_ENUM(XFS_SCRUB_TYPE_METAPATH);
+TRACE_DEFINE_ENUM(XFS_SCRUB_TYPE_RGSUPER);
 
 #define XFS_SCRUB_TYPE_STRINGS \
        { XFS_SCRUB_TYPE_PROBE,         "probe" }, \
@@ -103,7 +104,8 @@ TRACE_DEFINE_ENUM(XFS_SCRUB_TYPE_METAPATH);
        { XFS_SCRUB_TYPE_HEALTHY,       "healthy" }, \
        { XFS_SCRUB_TYPE_DIRTREE,       "dirtree" }, \
        { XFS_SCRUB_TYPE_BARRIER,       "barrier" }, \
-       { XFS_SCRUB_TYPE_METAPATH,      "metapath" }
+       { XFS_SCRUB_TYPE_METAPATH,      "metapath" }, \
+       { XFS_SCRUB_TYPE_RGSUPER,       "rgsuper" }
 
 #define XFS_SCRUB_FLAG_STRINGS \
        { XFS_SCRUB_IFLAG_REPAIR,               "repair" }, \