virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio_blk: fix incorrect message when disk is resized
@ 2017-07-26 14:32 Stefan Hajnoczi
  2017-08-04  9:37 ` Stefan Hajnoczi
       [not found] ` <20170804093754.GA9867@stefanha-x1.localdomain>
  0 siblings, 2 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2017-07-26 14:32 UTC (permalink / raw)
  To: linux-kernel; +Cc: virtualization, Stefan Hajnoczi, Michael S. Tsirkin

The message printed on disk resize is incorrect.  The following is
printed when resizing to 2 GiB:

  $ truncate -s 1G test.img
  $ qemu -device virtio-blk-pci,logical_block_size=4096,...
  (qemu) block_resize drive1 2G

  virtio_blk virtio0: new size: 4194304 4096-byte logical blocks (17.2 GB/16.0 GiB)

The virtio_blk capacity config field is in 512-byte sector units
regardless of logical_block_size as per the VIRTIO specification.
Therefore the message should read:

  virtio_blk virtio0: new size: 524288 4096-byte logical blocks (2.15 GB/2.0 GiB)

Note that this only affects the printed message.  Thankfully the actual
block device has the correct size because the block layer expects
capacity in sectors.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 drivers/block/virtio_blk.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 4e02aa5fdac0..69a2d1748743 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -381,6 +381,7 @@ static void virtblk_config_changed_work(struct work_struct *work)
 	struct request_queue *q = vblk->disk->queue;
 	char cap_str_2[10], cap_str_10[10];
 	char *envp[] = { "RESIZE=1", NULL };
+	unsigned long long nblocks;
 	u64 capacity;
 
 	/* Host must always specify the capacity. */
@@ -393,16 +394,19 @@ static void virtblk_config_changed_work(struct work_struct *work)
 		capacity = (sector_t)-1;
 	}
 
-	string_get_size(capacity, queue_logical_block_size(q),
+	nblocks = DIV_ROUND_UP_ULL(capacity, queue_logical_block_size(q) >> 9);
+
+	string_get_size(nblocks, queue_logical_block_size(q),
 			STRING_UNITS_2, cap_str_2, sizeof(cap_str_2));
-	string_get_size(capacity, queue_logical_block_size(q),
+	string_get_size(nblocks, queue_logical_block_size(q),
 			STRING_UNITS_10, cap_str_10, sizeof(cap_str_10));
 
 	dev_notice(&vdev->dev,
-		  "new size: %llu %d-byte logical blocks (%s/%s)\n",
-		  (unsigned long long)capacity,
-		  queue_logical_block_size(q),
-		  cap_str_10, cap_str_2);
+		   "new size: %llu %d-byte logical blocks (%s/%s)\n",
+		   nblocks,
+		   queue_logical_block_size(q),
+		   cap_str_10,
+		   cap_str_2);
 
 	set_capacity(vblk->disk, capacity);
 	revalidate_disk(vblk->disk);
-- 
2.13.3

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

* Re: [PATCH] virtio_blk: fix incorrect message when disk is resized
  2017-07-26 14:32 [PATCH] virtio_blk: fix incorrect message when disk is resized Stefan Hajnoczi
@ 2017-08-04  9:37 ` Stefan Hajnoczi
       [not found] ` <20170804093754.GA9867@stefanha-x1.localdomain>
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2017-08-04  9:37 UTC (permalink / raw)
  To: linux-kernel; +Cc: virtualization, Michael S. Tsirkin


[-- Attachment #1.1: Type: text/plain, Size: 2558 bytes --]

On Wed, Jul 26, 2017 at 03:32:23PM +0100, Stefan Hajnoczi wrote:
> The message printed on disk resize is incorrect.  The following is
> printed when resizing to 2 GiB:
> 
>   $ truncate -s 1G test.img
>   $ qemu -device virtio-blk-pci,logical_block_size=4096,...
>   (qemu) block_resize drive1 2G
> 
>   virtio_blk virtio0: new size: 4194304 4096-byte logical blocks (17.2 GB/16.0 GiB)
> 
> The virtio_blk capacity config field is in 512-byte sector units
> regardless of logical_block_size as per the VIRTIO specification.
> Therefore the message should read:
> 
>   virtio_blk virtio0: new size: 524288 4096-byte logical blocks (2.15 GB/2.0 GiB)
> 
> Note that this only affects the printed message.  Thankfully the actual
> block device has the correct size because the block layer expects
> capacity in sectors.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  drivers/block/virtio_blk.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)

Ping?

> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 4e02aa5fdac0..69a2d1748743 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -381,6 +381,7 @@ static void virtblk_config_changed_work(struct work_struct *work)
>  	struct request_queue *q = vblk->disk->queue;
>  	char cap_str_2[10], cap_str_10[10];
>  	char *envp[] = { "RESIZE=1", NULL };
> +	unsigned long long nblocks;
>  	u64 capacity;
>  
>  	/* Host must always specify the capacity. */
> @@ -393,16 +394,19 @@ static void virtblk_config_changed_work(struct work_struct *work)
>  		capacity = (sector_t)-1;
>  	}
>  
> -	string_get_size(capacity, queue_logical_block_size(q),
> +	nblocks = DIV_ROUND_UP_ULL(capacity, queue_logical_block_size(q) >> 9);
> +
> +	string_get_size(nblocks, queue_logical_block_size(q),
>  			STRING_UNITS_2, cap_str_2, sizeof(cap_str_2));
> -	string_get_size(capacity, queue_logical_block_size(q),
> +	string_get_size(nblocks, queue_logical_block_size(q),
>  			STRING_UNITS_10, cap_str_10, sizeof(cap_str_10));
>  
>  	dev_notice(&vdev->dev,
> -		  "new size: %llu %d-byte logical blocks (%s/%s)\n",
> -		  (unsigned long long)capacity,
> -		  queue_logical_block_size(q),
> -		  cap_str_10, cap_str_2);
> +		   "new size: %llu %d-byte logical blocks (%s/%s)\n",
> +		   nblocks,
> +		   queue_logical_block_size(q),
> +		   cap_str_10,
> +		   cap_str_2);
>  
>  	set_capacity(vblk->disk, capacity);
>  	revalidate_disk(vblk->disk);
> -- 
> 2.13.3
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

[-- Attachment #2: Type: text/plain, Size: 183 bytes --]

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH] virtio_blk: fix incorrect message when disk is resized
       [not found] ` <20170804093754.GA9867@stefanha-x1.localdomain>
@ 2017-08-04 13:24   ` Michael S. Tsirkin
  0 siblings, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2017-08-04 13:24 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: linux-kernel, virtualization

On Fri, Aug 04, 2017 at 10:37:54AM +0100, Stefan Hajnoczi wrote:
> On Wed, Jul 26, 2017 at 03:32:23PM +0100, Stefan Hajnoczi wrote:
> > The message printed on disk resize is incorrect.  The following is
> > printed when resizing to 2 GiB:
> > 
> >   $ truncate -s 1G test.img
> >   $ qemu -device virtio-blk-pci,logical_block_size=4096,...
> >   (qemu) block_resize drive1 2G
> > 
> >   virtio_blk virtio0: new size: 4194304 4096-byte logical blocks (17.2 GB/16.0 GiB)
> > 
> > The virtio_blk capacity config field is in 512-byte sector units
> > regardless of logical_block_size as per the VIRTIO specification.
> > Therefore the message should read:
> > 
> >   virtio_blk virtio0: new size: 524288 4096-byte logical blocks (2.15 GB/2.0 GiB)
> > 
> > Note that this only affects the printed message.  Thankfully the actual
> > block device has the correct size because the block layer expects
> > capacity in sectors.
> > 
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> >  drivers/block/virtio_blk.c | 16 ++++++++++------
> >  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> Ping?

Oops - I thought I sent it up. Will do.

> > diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> > index 4e02aa5fdac0..69a2d1748743 100644
> > --- a/drivers/block/virtio_blk.c
> > +++ b/drivers/block/virtio_blk.c
> > @@ -381,6 +381,7 @@ static void virtblk_config_changed_work(struct work_struct *work)
> >  	struct request_queue *q = vblk->disk->queue;
> >  	char cap_str_2[10], cap_str_10[10];
> >  	char *envp[] = { "RESIZE=1", NULL };
> > +	unsigned long long nblocks;
> >  	u64 capacity;
> >  
> >  	/* Host must always specify the capacity. */
> > @@ -393,16 +394,19 @@ static void virtblk_config_changed_work(struct work_struct *work)
> >  		capacity = (sector_t)-1;
> >  	}
> >  
> > -	string_get_size(capacity, queue_logical_block_size(q),
> > +	nblocks = DIV_ROUND_UP_ULL(capacity, queue_logical_block_size(q) >> 9);
> > +
> > +	string_get_size(nblocks, queue_logical_block_size(q),
> >  			STRING_UNITS_2, cap_str_2, sizeof(cap_str_2));
> > -	string_get_size(capacity, queue_logical_block_size(q),
> > +	string_get_size(nblocks, queue_logical_block_size(q),
> >  			STRING_UNITS_10, cap_str_10, sizeof(cap_str_10));
> >  
> >  	dev_notice(&vdev->dev,
> > -		  "new size: %llu %d-byte logical blocks (%s/%s)\n",
> > -		  (unsigned long long)capacity,
> > -		  queue_logical_block_size(q),
> > -		  cap_str_10, cap_str_2);
> > +		   "new size: %llu %d-byte logical blocks (%s/%s)\n",
> > +		   nblocks,
> > +		   queue_logical_block_size(q),
> > +		   cap_str_10,
> > +		   cap_str_2);
> >  
> >  	set_capacity(vblk->disk, capacity);
> >  	revalidate_disk(vblk->disk);
> > -- 
> > 2.13.3
> > 

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-26 14:32 [PATCH] virtio_blk: fix incorrect message when disk is resized Stefan Hajnoczi
2017-08-04  9:37 ` Stefan Hajnoczi
     [not found] ` <20170804093754.GA9867@stefanha-x1.localdomain>
2017-08-04 13:24   ` Michael S. Tsirkin

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).