btrfs: zoned: mark relocation as writing
authorNaohiro Aota <naohiro.aota@wdc.com>
Thu, 10 Feb 2022 05:59:05 +0000 (14:59 +0900)
committerDavid Sterba <dsterba@suse.com>
Tue, 15 Feb 2022 15:55:43 +0000 (16:55 +0100)
commitf927ff1abd001387784416b44a494517b1e08ca5
treeea271067c7e2e3c0f0f50c5d3a54eb94ac87b9dd
parentd5f9e56c77d13dbac05a82929dc222d0f454d6aa
btrfs: zoned: mark relocation as writing

There is a hung_task issue with running generic/068 on an SMR
device. The hang occurs while a process is trying to thaw the
filesystem. The process is trying to take sb->s_umount to thaw the
FS. The lock is held by fsstress, which calls btrfs_sync_fs() and is
waiting for an ordered extent to finish. However, as the FS is frozen,
the ordered extent never finish.

Having an ordered extent while the FS is frozen is the root cause of
the hang. The ordered extent is initiated from btrfs_relocate_chunk()
which is called from btrfs_reclaim_bgs_work().

This commit add sb_*_write() around btrfs_relocate_chunk() call
site. For the usual "btrfs balance" command, we already call it with
mnt_want_file() in btrfs_ioctl_balance().

Additionally, add an ASSERT in btrfs_relocate_chunk() to check it is
properly called.

Fixes: 18bb8bbf13c1 ("btrfs: zoned: automatically reclaim zones")
CC: stable@vger.kernel.org # 5.13+
Link: https://github.com/naota/linux/issues/56
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/volumes.c