linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: round down size diff when shrinking/growing device
@ 2017-07-21  8:28 Nikolay Borisov
  2017-07-24 13:24 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Nikolay Borisov @ 2017-07-21  8:28 UTC (permalink / raw)
  To: dsterba; +Cc: jeffm, linux-btrfs, Nikolay Borisov

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 substracting/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>
---
 fs/btrfs/volumes.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index fa779875bcfb..774b4168841a 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2701,7 +2701,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
 
 	mutex_lock(&fs_info->chunk_mutex);
 	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 ||
 	    device->is_tgtdev_for_dev_replace) {
@@ -4399,7 +4399,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
 	u64 diff;
 
 	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)
 		return -EINVAL;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] btrfs: round down size diff when shrinking/growing device
  2017-07-21  8:28 [PATCH] btrfs: round down size diff when shrinking/growing device Nikolay Borisov
@ 2017-07-24 13:24 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2017-07-24 13:24 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: dsterba, jeffm, linux-btrfs

On Fri, Jul 21, 2017 at 11:28:24AM +0300, Nikolay Borisov wrote:
> 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 substracting/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>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-24 13:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-21  8:28 [PATCH] btrfs: round down size diff when shrinking/growing device Nikolay Borisov
2017-07-24 13:24 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).