aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorNikolay Borisov <nborisov@suse.com>2017-07-21 04:28:24 -0400
committerDavid Sterba <dsterba@suse.com>2017-07-24 10:05:00 -0400
commit0e4324a4c36b3eb5cd1f71cbbc38d888f919ebfc (patch)
treeda38571564787f0e289ca307712f99fb7671c933 /fs
parent17024ad0a0fdfcfe53043afb969b813d3e020c21 (diff)
btrfs: round down size diff when shrinking/growing device
Further testing showed that the fix introduced in 7dfb8be11b5d ("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: 7dfb8be11b5d ("btrfs: Round down values which are written for total_bytes_size") Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/volumes.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index c95f018d4a1e..b3c30719bf5d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2702,7 +2702,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
2702 2702
2703 mutex_lock(&fs_info->chunk_mutex); 2703 mutex_lock(&fs_info->chunk_mutex);
2704 old_total = btrfs_super_total_bytes(super_copy); 2704 old_total = btrfs_super_total_bytes(super_copy);
2705 diff = new_size - device->total_bytes; 2705 diff = round_down(new_size - device->total_bytes, fs_info->sectorsize);
2706 2706
2707 if (new_size <= device->total_bytes || 2707 if (new_size <= device->total_bytes ||
2708 device->is_tgtdev_for_dev_replace) { 2708 device->is_tgtdev_for_dev_replace) {
@@ -4406,7 +4406,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
4406 u64 diff; 4406 u64 diff;
4407 4407
4408 new_size = round_down(new_size, fs_info->sectorsize); 4408 new_size = round_down(new_size, fs_info->sectorsize);
4409 diff = old_size - new_size; 4409 diff = round_down(old_size - new_size, fs_info->sectorsize);
4410 4410
4411 if (device->is_tgtdev_for_dev_replace) 4411 if (device->is_tgtdev_for_dev_replace)
4412 return -EINVAL; 4412 return -EINVAL;