Skip to content

Commit

Permalink
Btrfs: fix mutex unlock without prior lock on space cache truncation
Browse files Browse the repository at this point in the history
If the call to btrfs_truncate_inode_items() failed and we don't have a block
group, we were unlocking the cache_write_mutex without having locked it (we
do it only if we have a block group).

Fixes: 1bbc621 ("Btrfs: allow block group cache writeout
                      outside critical section in commit")

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
  • Loading branch information
Filipe Manana authored and Chris Mason committed Jun 3, 2015
1 parent 816fceb commit 35c7664
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions fs/btrfs/free-space-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,15 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root,
{
int ret = 0;
struct btrfs_path *path = btrfs_alloc_path();
bool locked = false;

if (!path) {
ret = -ENOMEM;
goto fail;
}

if (block_group) {
locked = true;
mutex_lock(&trans->transaction->cache_write_mutex);
if (!list_empty(&block_group->io_list)) {
list_del_init(&block_group->io_list);
Expand Down Expand Up @@ -269,18 +271,14 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root,
*/
ret = btrfs_truncate_inode_items(trans, root, inode,
0, BTRFS_EXTENT_DATA_KEY);
if (ret) {
mutex_unlock(&trans->transaction->cache_write_mutex);
btrfs_abort_transaction(trans, root, ret);
return ret;
}
if (ret)
goto fail;

ret = btrfs_update_inode(trans, root, inode);

if (block_group)
mutex_unlock(&trans->transaction->cache_write_mutex);

fail:
if (locked)
mutex_unlock(&trans->transaction->cache_write_mutex);
if (ret)
btrfs_abort_transaction(trans, root, ret);

Expand Down

0 comments on commit 35c7664

Please sign in to comment.