]> git.hungrycats.org Git - linux/commit
btrfs: scrub: fix lost wakeup and hang when cancelling a scrub that is finishing
authorFilipe Manana <fdmanana@suse.com>
Fri, 16 Oct 2026 16:14:49 +0000 (17:14 +0100)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 5 Nov 2026 04:21:56 +0000 (23:21 -0500)
commit7b52839468ace45f625ae99b1982e1df2de4e357
treec0c603e2c98c26109d74529a752ba7537336287a
parent7984b9666bd2f091fc293aeae6af3caa3db47116
btrfs: scrub: fix lost wakeup and hang when cancelling a scrub that is finishing

When scrub finishes, it does a wakeup on the fs_info->scrub_pause_wait
wait queue and then sets dev->scrub_sctx to NULL. On the other hand the
scrub cancel code (btrfs_scrub_cancel_dev()) waits on that wait queue
for dev->scrub_sctx to be NULL. So this means if btrfs_scrub_cancel_dev()
is called right when scrub is finishing and sees the wakeup before the
NULL is assigned to dev->scrub_sctx by btrfs_scrub_dev(), it hangs.

Fix this by doing the wakeup in btrfs_scrub_dev() after setting
dev->scrub_sctx to NULL.

Fixes: a2de733c78fa ("btrfs: scrub")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
(cherry picked from btrfs for-next commit f64d1d4ceeb7ea9879eeaa4b92ccaa60a24d7cdf)
fs/btrfs/scrub.c