From 07a09009e996b5bef35f0a248420ed6d34bae777 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Thu, 15 Aug 2024 11:57:34 -0700 Subject: [PATCH] xfs: allow queued realtime intents to drain before scrubbing Source kernel commit: 77b81645574605ea0c0199ec32fc4a9cdc87bc53 When a writer thread executes a chain of log intent items for the realtime volume, the ILOCKs taken during each step are for each rt metadata file, not the entire rt volume itself. Although scrub takes all rt metadata ILOCKs, this isn't sufficient to guard against scrub checking the rt volume while that writer thread is in the middle of finishing a chain because there's no higher level locking primitive guarding the realtime volume. When there's a collision, cross-referencing between data structures (e.g. rtrmapbt and rtrefcountbt) yields false corruption events; if repair is running, this results in incorrect repairs, which is catastrophic. Fix this by adding to the mount structure the same drain that we use to protect scrub against concurrent AG updates, but this time for the realtime volume. [Contains a few cleanups from hch] Cc: Christoph Hellwig Signed-off-by: Darrick J. Wong Signed-off-by: Christoph Hellwig --- libxfs/xfs_rtgroup.c | 5 +++++ libxfs/xfs_rtgroup.h | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/libxfs/xfs_rtgroup.c b/libxfs/xfs_rtgroup.c index b16e1467a..5b24e0614 100644 --- a/libxfs/xfs_rtgroup.c +++ b/libxfs/xfs_rtgroup.c @@ -142,6 +142,7 @@ xfs_rtgroup_alloc( /* Place kernel structure only init below this point. */ spin_lock_init(&rtg->rtg_state_lock); init_waitqueue_head(&rtg->rtg_active_wq); + xfs_defer_drain_init(&rtg->rtg_intents_drain); #endif /* __KERNEL__ */ /* Active ref owned by mount indicates rtgroup is online. */ @@ -169,6 +170,10 @@ xfs_rtgroup_free( XFS_IS_CORRUPT(mp, atomic_read(&rtg->rtg_ref) != 0); +#ifdef __KERNEL__ + xfs_defer_drain_free(&rtg->rtg_intents_drain); +#endif + /* drop the mount's active reference */ xfs_rtgroup_rele(rtg); XFS_IS_CORRUPT(mp, atomic_read(&rtg->rtg_active_ref) != 0); diff --git a/libxfs/xfs_rtgroup.h b/libxfs/xfs_rtgroup.h index c2addd4e1..aad16b0ec 100644 --- a/libxfs/xfs_rtgroup.h +++ b/libxfs/xfs_rtgroup.h @@ -56,6 +56,15 @@ struct xfs_rtgroup { #ifdef __KERNEL__ /* -- kernel only structures below this line -- */ spinlock_t rtg_state_lock; + + /* + * We use xfs_drain to track the number of deferred log intent items + * that have been queued (but not yet processed) so that waiters (e.g. + * scrub) will not lock resources when other threads are in the middle + * of processing a chain of intent items only to find momentary + * inconsistencies. + */ + struct xfs_defer_drain rtg_intents_drain; #endif /* __KERNEL__ */ }; -- 2.50.1