Skip to content

Commit 3f64c71

Browse files
author
Darrick J. Wong
committed
xfs: clean up scrub context if scrub setup returns -EDEADLOCK
It has been a longstanding convention that online scrub and repair functions can return -EDEADLOCK to signal that they weren't able to obtain some necessary resource. When this happens, the scrub framework is supposed to release all resources attached to the scrub context, set the TRY_HARDER flag in the scrub context flags, and try again. In this context, individual scrub functions are supposed to take all the resources they (incorrectly) speculated were not necessary. We're about to make it so that the functions that lock and wait for a filesystem AG can also return EDEADLOCK to signal that we need to try again with the drain waiters enabled. Therefore, refactor xfs_scrub_metadata to support this behavior for ->setup() functions. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent d5c8813 commit 3f64c71

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

fs/xfs/scrub/scrub.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,23 +491,16 @@ xfs_scrub_metadata(
491491

492492
/* Set up for the operation. */
493493
error = sc->ops->setup(sc);
494+
if (error == -EDEADLOCK && !(sc->flags & XCHK_TRY_HARDER))
495+
goto try_harder;
494496
if (error)
495497
goto out_teardown;
496498

497499
/* Scrub for errors. */
498500
error = sc->ops->scrub(sc);
499-
if (!(sc->flags & XCHK_TRY_HARDER) && error == -EDEADLOCK) {
500-
/*
501-
* Scrubbers return -EDEADLOCK to mean 'try harder'.
502-
* Tear down everything we hold, then set up again with
503-
* preparation for worst-case scenarios.
504-
*/
505-
error = xchk_teardown(sc, 0);
506-
if (error)
507-
goto out_sc;
508-
sc->flags |= XCHK_TRY_HARDER;
509-
goto retry_op;
510-
} else if (error || (sm->sm_flags & XFS_SCRUB_OFLAG_INCOMPLETE))
501+
if (error == -EDEADLOCK && !(sc->flags & XCHK_TRY_HARDER))
502+
goto try_harder;
503+
if (error || (sm->sm_flags & XFS_SCRUB_OFLAG_INCOMPLETE))
511504
goto out_teardown;
512505

513506
xchk_update_health(sc);
@@ -565,4 +558,15 @@ xfs_scrub_metadata(
565558
error = 0;
566559
}
567560
return error;
561+
try_harder:
562+
/*
563+
* Scrubbers return -EDEADLOCK to mean 'try harder'. Tear down
564+
* everything we hold, then set up again with preparation for
565+
* worst-case scenarios.
566+
*/
567+
error = xchk_teardown(sc, 0);
568+
if (error)
569+
goto out_sc;
570+
sc->flags |= XCHK_TRY_HARDER;
571+
goto retry_op;
568572
}

0 commit comments

Comments
 (0)