Skip to content

Commit 0e4324a

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: round down size diff when shrinking/growing device
Further testing showed that the fix introduced in 7dfb8be ("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: 7dfb8be ("btrfs: Round down values which are written for total_bytes_size") Signed-off-by: Nikolay Borisov <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 17024ad commit 0e4324a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/btrfs/volumes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
27022702

27032703
mutex_lock(&fs_info->chunk_mutex);
27042704
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);
27062706

27072707
if (new_size <= device->total_bytes ||
27082708
device->is_tgtdev_for_dev_replace) {
@@ -4406,7 +4406,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
44064406
u64 diff;
44074407

44084408
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);
44104410

44114411
if (device->is_tgtdev_for_dev_replace)
44124412
return -EINVAL;

0 commit comments

Comments
 (0)