Relocation of a data block group creates ordered extents. They can cause a hang when a process is trying to thaw the filesystem. We should have called sb_start_write(), so the filesystem is not being frozen. Add an ASSERT to check it is protected. Signed-off-by: Naohiro Aota <naohiro.aota@xxxxxxx> --- fs/btrfs/relocation.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index fdc2c4b411f0..5e52cd8d5f23 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3977,6 +3977,16 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start) if (!bg) return -ENOENT; + /* + * Relocation of a data block group creates ordered extents. + * Without sb_start_write(), we can freeze the FS while unfinished + * ordered extents are left. Such ordered extents can cause a + * deadlock e.g, when syncfs() is trying to finish them because + * they never finish as the FS is already frozen. + */ + if (bg->flags & BTRFS_BLOCK_GROUP_DATA) + ASSERT(sb_write_started(fs_info->sb)); + if (btrfs_pinned_by_swapfile(fs_info, bg)) { btrfs_put_block_group(bg); return -ETXTBSY; -- 2.35.1