* [PATCHSET v23.1 0/2] xfs: enhance fs summary counter scrubber
@ 2022-10-02 18:20 Darrick J. Wong
2022-10-02 18:20 ` [PATCH 1/2] xfs: skip fscounters comparisons when the scan is incomplete Darrick J. Wong
2022-10-02 18:20 ` [PATCH 2/2] xfs: online checking of the free rt extent count Darrick J. Wong
0 siblings, 2 replies; 6+ messages in thread
From: Darrick J. Wong @ 2022-10-02 18:20 UTC (permalink / raw)
To: djwong; +Cc: linux-xfs
Hi all,
This series makes two changes to the fs summary counter scrubber: first,
we should mark the scrub incomplete when we can't read the AG headers.
Second, it fixes a functionality gap where we don't actually check the
free rt extent count.
If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy!
Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=scrub-fscounters-enhancements
---
fs/xfs/scrub/fscounters.c | 107 ++++++++++++++++++++++++++++++++++++++++++++-
fs/xfs/scrub/scrub.h | 8 ---
2 files changed, 104 insertions(+), 11 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] xfs: skip fscounters comparisons when the scan is incomplete
2022-10-02 18:20 [PATCHSET v23.1 0/2] xfs: enhance fs summary counter scrubber Darrick J. Wong
@ 2022-10-02 18:20 ` Darrick J. Wong
2022-10-14 3:51 ` Dave Chinner
2022-10-02 18:20 ` [PATCH 2/2] xfs: online checking of the free rt extent count Darrick J. Wong
1 sibling, 1 reply; 6+ messages in thread
From: Darrick J. Wong @ 2022-10-02 18:20 UTC (permalink / raw)
To: djwong; +Cc: linux-xfs
From: Darrick J. Wong <djwong@kernel.org>
If any part of the per-AG summary counter scan loop aborts without
collecting all of the data we need, the scrubber's observation data will
be invalid. Set the incomplete flag so that we abort the scrub without
reporting false corruptions. Document the data dependency here too.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
fs/xfs/scrub/fscounters.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/fs/xfs/scrub/fscounters.c b/fs/xfs/scrub/fscounters.c
index 3c66523ec212..c869b537fe34 100644
--- a/fs/xfs/scrub/fscounters.c
+++ b/fs/xfs/scrub/fscounters.c
@@ -145,6 +145,18 @@ xchk_setup_fscounters(
return xchk_trans_alloc(sc, 0);
}
+/*
+ * Part 1: Collecting filesystem summary counts. For each AG, we add its
+ * summary counts (total inodes, free inodes, free data blocks) to an incore
+ * copy of the overall filesystem summary counts.
+ *
+ * To avoid false corruption reports in part 2, any failure in this part must
+ * set the INCOMPLETE flag even when a negative errno is returned. This care
+ * must be taken with certain errno values (i.e. EFSBADCRC, EFSCORRUPTED,
+ * ECANCELED) that are absorbed into a scrub state flag update by
+ * xchk_*_process_error.
+ */
+
/* Count free space btree blocks manually for pre-lazysbcount filesystems. */
static int
xchk_fscount_btreeblks(
@@ -232,8 +244,10 @@ xchk_fscount_aggregate_agcounts(
}
if (pag)
xfs_perag_put(pag);
- if (error)
+ if (error) {
+ xchk_set_incomplete(sc);
return error;
+ }
/*
* The global incore space reservation is taken from the incore
@@ -274,6 +288,11 @@ xchk_fscount_aggregate_agcounts(
return 0;
}
+/*
+ * Part 2: Comparing filesystem summary counters. All we have to do here is
+ * sum the percpu counters and compare them to what we've observed.
+ */
+
/*
* Is the @counter reasonably close to the @expected value?
*
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] xfs: online checking of the free rt extent count
2022-10-02 18:20 [PATCHSET v23.1 0/2] xfs: enhance fs summary counter scrubber Darrick J. Wong
2022-10-02 18:20 ` [PATCH 1/2] xfs: skip fscounters comparisons when the scan is incomplete Darrick J. Wong
@ 2022-10-02 18:20 ` Darrick J. Wong
2022-10-14 3:56 ` Dave Chinner
1 sibling, 1 reply; 6+ messages in thread
From: Darrick J. Wong @ 2022-10-02 18:20 UTC (permalink / raw)
To: djwong; +Cc: linux-xfs
From: Darrick J. Wong <djwong@kernel.org>
Teach the summary count checker to count the number of free realtime
extents and compare that to the superblock copy.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
fs/xfs/scrub/fscounters.c | 86 ++++++++++++++++++++++++++++++++++++++++++++-
fs/xfs/scrub/scrub.h | 8 ----
2 files changed, 84 insertions(+), 10 deletions(-)
diff --git a/fs/xfs/scrub/fscounters.c b/fs/xfs/scrub/fscounters.c
index c869b537fe34..2eea6a517b79 100644
--- a/fs/xfs/scrub/fscounters.c
+++ b/fs/xfs/scrub/fscounters.c
@@ -14,6 +14,8 @@
#include "xfs_health.h"
#include "xfs_btree.h"
#include "xfs_ag.h"
+#include "xfs_rtalloc.h"
+#include "xfs_inode.h"
#include "scrub/scrub.h"
#include "scrub/common.h"
#include "scrub/trace.h"
@@ -43,6 +45,16 @@
* our tolerance for mismatch between expected and actual counter values.
*/
+struct xchk_fscounters {
+ struct xfs_scrub *sc;
+ uint64_t icount;
+ uint64_t ifree;
+ uint64_t fdblocks;
+ uint64_t frextents;
+ unsigned long long icount_min;
+ unsigned long long icount_max;
+};
+
/*
* Since the expected value computation is lockless but only browses incore
* values, the percpu counters should be fairly close to each other. However,
@@ -127,6 +139,7 @@ xchk_setup_fscounters(
if (!sc->buf)
return -ENOMEM;
fsc = sc->buf;
+ fsc->sc = sc;
xfs_icount_range(sc->mp, &fsc->icount_min, &fsc->icount_max);
@@ -288,6 +301,59 @@ xchk_fscount_aggregate_agcounts(
return 0;
}
+#ifdef CONFIG_XFS_RT
+static inline int
+xchk_fscount_add_frextent(
+ struct xfs_mount *mp,
+ struct xfs_trans *tp,
+ const struct xfs_rtalloc_rec *rec,
+ void *priv)
+{
+ struct xchk_fscounters *fsc = priv;
+ int error = 0;
+
+ fsc->frextents += rec->ar_extcount;
+
+ xchk_should_terminate(fsc->sc, &error);
+ return error;
+}
+
+/* Calculate the number of free realtime extents from the realtime bitmap. */
+STATIC int
+xchk_fscount_count_frextents(
+ struct xfs_scrub *sc,
+ struct xchk_fscounters *fsc)
+{
+ struct xfs_mount *mp = sc->mp;
+ int error;
+
+ fsc->frextents = 0;
+ if (!xfs_has_realtime(mp))
+ return 0;
+
+ xfs_ilock(sc->mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
+ error = xfs_rtalloc_query_all(sc->mp, sc->tp,
+ xchk_fscount_add_frextent, fsc);
+ if (error) {
+ xchk_set_incomplete(sc);
+ goto out_unlock;
+ }
+
+out_unlock:
+ xfs_iunlock(sc->mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
+ return error;
+}
+#else
+STATIC int
+xchk_fscount_count_frextents(
+ struct xfs_scrub *sc,
+ struct xchk_fscounters *fsc)
+{
+ fsc->frextents = 0;
+ return 0;
+}
+#endif /* CONFIG_XFS_RT */
+
/*
* Part 2: Comparing filesystem summary counters. All we have to do here is
* sum the percpu counters and compare them to what we've observed.
@@ -359,16 +425,17 @@ xchk_fscounters(
{
struct xfs_mount *mp = sc->mp;
struct xchk_fscounters *fsc = sc->buf;
- int64_t icount, ifree, fdblocks;
+ int64_t icount, ifree, fdblocks, frextents;
int error;
/* Snapshot the percpu counters. */
icount = percpu_counter_sum(&mp->m_icount);
ifree = percpu_counter_sum(&mp->m_ifree);
fdblocks = percpu_counter_sum(&mp->m_fdblocks);
+ frextents = percpu_counter_sum(&mp->m_frextents);
/* No negative values, please! */
- if (icount < 0 || ifree < 0 || fdblocks < 0)
+ if (icount < 0 || ifree < 0 || fdblocks < 0 || frextents < 0)
xchk_set_corrupt(sc);
/* See if icount is obviously wrong. */
@@ -379,6 +446,10 @@ xchk_fscounters(
if (fdblocks > mp->m_sb.sb_dblocks)
xchk_set_corrupt(sc);
+ /* See if frextents is obviously wrong. */
+ if (frextents > mp->m_sb.sb_rextents)
+ xchk_set_corrupt(sc);
+
/*
* If ifree exceeds icount by more than the minimum variance then
* something's probably wrong with the counters.
@@ -393,6 +464,13 @@ xchk_fscounters(
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_INCOMPLETE)
return 0;
+ /* Count the free extents counter for rt volumes. */
+ error = xchk_fscount_count_frextents(sc, fsc);
+ if (!xchk_process_error(sc, 0, XFS_SB_BLOCK(mp), &error))
+ return error;
+ if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_INCOMPLETE)
+ return 0;
+
/* Compare the in-core counters with whatever we counted. */
if (!xchk_fscount_within_range(sc, icount, &mp->m_icount, fsc->icount))
xchk_set_corrupt(sc);
@@ -404,5 +482,9 @@ xchk_fscounters(
fsc->fdblocks))
xchk_set_corrupt(sc);
+ if (!xchk_fscount_within_range(sc, frextents, &mp->m_frextents,
+ fsc->frextents))
+ xchk_set_corrupt(sc);
+
return 0;
}
diff --git a/fs/xfs/scrub/scrub.h b/fs/xfs/scrub/scrub.h
index 92b383061e88..85c055c2ddc5 100644
--- a/fs/xfs/scrub/scrub.h
+++ b/fs/xfs/scrub/scrub.h
@@ -173,12 +173,4 @@ void xchk_xref_is_used_rt_space(struct xfs_scrub *sc, xfs_rtblock_t rtbno,
# define xchk_xref_is_used_rt_space(sc, rtbno, len) do { } while (0)
#endif
-struct xchk_fscounters {
- uint64_t icount;
- uint64_t ifree;
- uint64_t fdblocks;
- unsigned long long icount_min;
- unsigned long long icount_max;
-};
-
#endif /* __XFS_SCRUB_SCRUB_H__ */
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] xfs: skip fscounters comparisons when the scan is incomplete
2022-10-02 18:20 ` [PATCH 1/2] xfs: skip fscounters comparisons when the scan is incomplete Darrick J. Wong
@ 2022-10-14 3:51 ` Dave Chinner
0 siblings, 0 replies; 6+ messages in thread
From: Dave Chinner @ 2022-10-14 3:51 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-xfs
On Sun, Oct 02, 2022 at 11:20:05AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> If any part of the per-AG summary counter scan loop aborts without
> collecting all of the data we need, the scrubber's observation data will
> be invalid. Set the incomplete flag so that we abort the scrub without
> reporting false corruptions. Document the data dependency here too.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
> fs/xfs/scrub/fscounters.c | 21 ++++++++++++++++++++-
> 1 file changed, 20 insertions(+), 1 deletion(-)
Looks good. Added comments are nice :)
Reviewed-by: Dave Chinner <dchinner@redhat.com>
--
Dave Chinner
david@fromorbit.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] xfs: online checking of the free rt extent count
2022-10-02 18:20 ` [PATCH 2/2] xfs: online checking of the free rt extent count Darrick J. Wong
@ 2022-10-14 3:56 ` Dave Chinner
2022-10-14 21:46 ` Darrick J. Wong
0 siblings, 1 reply; 6+ messages in thread
From: Dave Chinner @ 2022-10-14 3:56 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-xfs
On Sun, Oct 02, 2022 at 11:20:05AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> Teach the summary count checker to count the number of free realtime
> extents and compare that to the superblock copy.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
> fs/xfs/scrub/fscounters.c | 86 ++++++++++++++++++++++++++++++++++++++++++++-
> fs/xfs/scrub/scrub.h | 8 ----
> 2 files changed, 84 insertions(+), 10 deletions(-)
.....
> @@ -288,6 +301,59 @@ xchk_fscount_aggregate_agcounts(
> return 0;
> }
>
> +#ifdef CONFIG_XFS_RT
> +static inline int
> +xchk_fscount_add_frextent(
> + struct xfs_mount *mp,
> + struct xfs_trans *tp,
> + const struct xfs_rtalloc_rec *rec,
> + void *priv)
This is a callback function, so it shouldn't be declared as
"inline"....
With that fixed,
Reviewed-by: Dave Chinner <dchinner@redhat.com>
--
Dave Chinner
david@fromorbit.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] xfs: online checking of the free rt extent count
2022-10-14 3:56 ` Dave Chinner
@ 2022-10-14 21:46 ` Darrick J. Wong
0 siblings, 0 replies; 6+ messages in thread
From: Darrick J. Wong @ 2022-10-14 21:46 UTC (permalink / raw)
To: Dave Chinner; +Cc: linux-xfs
On Fri, Oct 14, 2022 at 02:56:34PM +1100, Dave Chinner wrote:
> On Sun, Oct 02, 2022 at 11:20:05AM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> >
> > Teach the summary count checker to count the number of free realtime
> > extents and compare that to the superblock copy.
> >
> > Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> > ---
> > fs/xfs/scrub/fscounters.c | 86 ++++++++++++++++++++++++++++++++++++++++++++-
> > fs/xfs/scrub/scrub.h | 8 ----
> > 2 files changed, 84 insertions(+), 10 deletions(-)
>
> .....
> > @@ -288,6 +301,59 @@ xchk_fscount_aggregate_agcounts(
> > return 0;
> > }
> >
> > +#ifdef CONFIG_XFS_RT
> > +static inline int
> > +xchk_fscount_add_frextent(
> > + struct xfs_mount *mp,
> > + struct xfs_trans *tp,
> > + const struct xfs_rtalloc_rec *rec,
> > + void *priv)
>
> This is a callback function, so it shouldn't be declared as
> "inline"....
Ok done.
--D
> With that fixed,
>
> Reviewed-by: Dave Chinner <dchinner@redhat.com>
>
> --
> Dave Chinner
> david@fromorbit.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-10-14 21:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-02 18:20 [PATCHSET v23.1 0/2] xfs: enhance fs summary counter scrubber Darrick J. Wong
2022-10-02 18:20 ` [PATCH 1/2] xfs: skip fscounters comparisons when the scan is incomplete Darrick J. Wong
2022-10-14 3:51 ` Dave Chinner
2022-10-02 18:20 ` [PATCH 2/2] xfs: online checking of the free rt extent count Darrick J. Wong
2022-10-14 3:56 ` Dave Chinner
2022-10-14 21:46 ` Darrick J. Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).