btrfs: scrub: move scrub_setup_ctx allocation out of device_list_mutex
authorDavid Sterba <dsterba@suse.com>
Tue, 4 Dec 2018 15:11:56 +0000 (16:11 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 16 Sep 2019 06:22:07 +0000 (08:22 +0200)
commitff55333f5c525dc7ee7e9f41db1e289bc8cbf04f
tree87b50dccb63c5e3381e19ebd3a1ec827a39be0c4
parent8ba3169dceac319cb12917c66094be4810af4fd9
btrfs: scrub: move scrub_setup_ctx allocation out of device_list_mutex

[ Upstream commit 0e94c4f45d14cf89d1f40c91b0a8517e791672a7 ]

The scrub context is allocated with GFP_KERNEL and called from
btrfs_scrub_dev under the fs_info::device_list_mutex. This is not safe
regarding reclaim that could try to flush filesystem data in order to
get the memory. And the device_list_mutex is held during superblock
commit, so this would cause a lockup.

Move the alocation and initialization before any changes that require
the mutex.

Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/scrub.c