xfs: drain intents when performing online fsck

Provide a way for per-AG scrubs to drain log intent items so that we're
assured that the fs domain (AG, rt) is consistent and nobody else can be
in the middle of a compound update.
xfs: allow queued AG intents to drain before scrubbing

Currently, online scrub isn't sufficiently careful about quiescing
allocation groups before checking them.  While scrub does take the AG
header locks, it doesn't serialize against chains of AG update intents
that are being processed concurrently.  If there's a collision,
cross-referencing between data structures (e.g. rmapbt and refcountbt)
can yield false corruption events; if repair is running, this results in
incorrect repairs.

Fix this by adding to the perag structure the count of active intents
and make scrub wait until there aren't any to continue.  This is a
little stupid since transactions can queue intents without taking buffer
locks, but we'll also wait for those transactions.

XXX: should have instead a per-ag rwsem that gets taken as soon as the
AG[IF] are locked and stays held until the transaction commits or moves
on to the next AG?  would we rather have a six lock so that intents can
take an ix lock, and not have to upgrade to x until we actually want to
make changes to that ag?  is that how those even work??

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
3 files changed