Commit 0e4324a4 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: round down size diff when shrinking/growing device

Further testing showed that the fix introduced in 7dfb8be1 ("btrfs:
Round down values which are written for total_bytes_size") was
insufficient and it could still lead to discrepancies between the
total_bytes in the super block and the device total bytes. So this patch
also ensures that the difference between old/new sizes when
shrinking/growing is also rounded down. This ensure that we won't be
subtracting/adding a non-sectorsize multiples to the superblock/device
total sizees.

Fixes: 7dfb8be1 ("btrfs: Round down values which are written for total_bytes_size")
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 17024ad0
...@@ -2702,7 +2702,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans, ...@@ -2702,7 +2702,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
mutex_lock(&fs_info->chunk_mutex); mutex_lock(&fs_info->chunk_mutex);
old_total = btrfs_super_total_bytes(super_copy); old_total = btrfs_super_total_bytes(super_copy);
diff = new_size - device->total_bytes; diff = round_down(new_size - device->total_bytes, fs_info->sectorsize);
if (new_size <= device->total_bytes || if (new_size <= device->total_bytes ||
device->is_tgtdev_for_dev_replace) { device->is_tgtdev_for_dev_replace) {
...@@ -4406,7 +4406,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4406,7 +4406,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
u64 diff; u64 diff;
new_size = round_down(new_size, fs_info->sectorsize); new_size = round_down(new_size, fs_info->sectorsize);
diff = old_size - new_size; diff = round_down(old_size - new_size, fs_info->sectorsize);
if (device->is_tgtdev_for_dev_replace) if (device->is_tgtdev_for_dev_replace)
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment