Skip to content

Commit

Permalink
btrfs: free qgroup rsv on io failure
Browse files Browse the repository at this point in the history
commit e28b021 upstream.

If we do a write whose bio suffers an error, we will never reclaim the
qgroup reserved space for it. We allocate the space in the write_iter
codepath, then release the reservation as we allocate the ordered
extent, but we only create a delayed ref if the ordered extent finishes.
If it has an error, we simply leak the rsv. This is apparent in running
any error injecting (dmerror) fstests like btrfs/146 or btrfs/160. Such
tests fail due to dmesg on umount complaining about the leaked qgroup
data space.

When we clean up other aspects of space on failed ordered_extents, also
free the qgroup rsv.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
CC: stable@vger.kernel.org # 5.10+
Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
boryas authored and gregkh committed Sep 19, 2023
1 parent 6fd4d27 commit b5cd2c8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fs/btrfs/inode.c
Expand Up @@ -3359,6 +3359,13 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
btrfs_free_reserved_extent(fs_info,
ordered_extent->disk_bytenr,
ordered_extent->disk_num_bytes, 1);
/*
* Actually free the qgroup rsv which was released when
* the ordered extent was created.
*/
btrfs_qgroup_free_refroot(fs_info, inode->root->root_key.objectid,
ordered_extent->qgroup_rsv,
BTRFS_QGROUP_RSV_DATA);
}
}

Expand Down

0 comments on commit b5cd2c8

Please sign in to comment.