diff options
author | 2023-09-27 13:47:00 -0400 | |
---|---|---|
committer | 2023-10-12 16:44:16 +0200 | |
commit | 6f2d3c01960a68bfdfae14a8dc54dd7904ab61ed (patch) | |
tree | 5c860506c1535b078d9cea1dc79024d0f2e3e4a7 | |
parent | btrfs: fix ->free_chunk_space math in btrfs_shrink_device (diff) | |
download | wireguard-linux-6f2d3c01960a68bfdfae14a8dc54dd7904ab61ed.tar.xz wireguard-linux-6f2d3c01960a68bfdfae14a8dc54dd7904ab61ed.zip |
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>
-rw-r--r-- | fs/btrfs/volumes.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 8355533fd287..790368d4b866 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2812,6 +2812,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans, btrfs_set_super_total_bytes(super_copy, round_down(old_total + diff, fs_info->sectorsize)); device->fs_devices->total_rw_bytes += diff; + atomic64_add(diff, &fs_info->free_chunk_space); btrfs_device_set_total_bytes(device, new_size); btrfs_device_set_disk_total_bytes(device, new_size); |