btrfs: increase ->free_chunk_space in btrfs_grow_device
authorJosef Bacik <josef@toxicpanda.com>
Wed, 27 Sep 2023 17:47:00 +0000 (13:47 -0400)
committerDavid Sterba <dsterba@suse.com>
Thu, 12 Oct 2023 14:44:16 +0000 (16:44 +0200)
commit6f2d3c01960a68bfdfae14a8dc54dd7904ab61ed
tree5c860506c1535b078d9cea1dc79024d0f2e3e4a7
parente9fd2c05239ae423af45f99e2964ad086f800e33
btrfs: increase ->free_chunk_space in btrfs_grow_device

My overcommit patch exposed a bug with btrfs/177 [1].  The problem here is
that when we grow the device we're not adding to ->free_chunk_space, so
subsequent allocations can cause ->free_chunk_space to wrap, which
causes problems in can_overcommit because we add this to ->total_bytes,
which causes the counter to wrap and gives us an unexpected ENOSPC.

Fix this by properly updating ->free_chunk_space with the new available
space in btrfs_grow_device.

[1] First version of the fix:
    https://lore.kernel.org/linux-btrfs/b97e47ce0ce1d41d221878de7d6090b90aa7a597.1695065233.git.josef@toxicpanda.com/

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c