btrfs: fix ->free_chunk_space math in btrfs_shrink_device
authorJosef Bacik <josef@toxicpanda.com>
Wed, 27 Sep 2023 17:46:59 +0000 (13:46 -0400)
committerDavid Sterba <dsterba@suse.com>
Thu, 12 Oct 2023 14:44:15 +0000 (16:44 +0200)
commite9fd2c05239ae423af45f99e2964ad086f800e33
tree1d71a4880b1afd82e7e4a67b2e40e18e493d33dc
parentefba1454493df546dcee603c4b77db3a230ac054
btrfs: fix ->free_chunk_space math in btrfs_shrink_device

There are two bugs in how we adjust ->free_chunk_space in
btrfs_shrink_device.  First we're removing the entire diff between
new_size and old_size from ->free_chunk_space.  This only works if we're
reducing the free area, which we could potentially not be.  So adjust
the math to only subtract the diff in the free space from
->free_chunk_space.

Additionally in the error case we're unconditionally adding the diff
back into ->free_chunk_space, which we need to only do if this device is
writeable.

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