Commit 928066e6 authored by Josef Bacik's avatar Josef Bacik Committed by Greg Kroah-Hartman

btrfs: fix deadlock when writing out space cache

[ Upstream commit b77000ed ]

If we fail to prepare our pages for whatever reason (out of memory in
our case) we need to make sure to drop the block_group->data_rwsem,
otherwise hilarity ensues.
Signed-off-by: default avatarJosef Bacik <>
Reviewed-by: default avatarOmar Sandoval <>
Reviewed-by: default avatarLiu Bo <>
Reviewed-by: default avatarDavid Sterba <>
[ add label and use existing unlocking code ]
Signed-off-by: default avatarDavid Sterba <>
Signed-off-by: default avatarSasha Levin <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent 84121127
......@@ -1264,7 +1264,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
/* Lock all pages first so we can lock the extent safely. */
ret = io_ctl_prepare_pages(io_ctl, inode, 0);
if (ret)
goto out;
goto out_unlock;
lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1,
......@@ -1358,6 +1358,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
cleanup_write_cache_enospc(inode, io_ctl, &cached_state);
if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment