All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
	qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] virtio-blk: handle blk_getlength() errors
Date: Tue, 8 Aug 2017 22:30:22 +0800	[thread overview]
Message-ID: <20170808143022.GD2454@lemon> (raw)
In-Reply-To: <20170808122251.29815-1-stefanha@redhat.com>

On Tue, 08/08 13:22, Stefan Hajnoczi wrote:
> If blk_getlength() fails in virtio_blk_update_config() consider the disk
> image length to be 0 bytes.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  hw/block/virtio-blk.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index b750bd8b53..a16ac75090 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -730,6 +730,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
>      BlockConf *conf = &s->conf.conf;
>      struct virtio_blk_config blkcfg;
>      uint64_t capacity;
> +    int64_t length;
>      int blk_size = conf->logical_block_size;
>  
>      blk_get_geometry(s->blk, &capacity);
> @@ -752,7 +753,8 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
>       * divided by 512 - instead it is the amount of blk_size blocks
>       * per track (cylinder).
>       */
> -    if (blk_getlength(s->blk) /  conf->heads / conf->secs % blk_size) {
> +    length = blk_getlength(s->blk);
> +    if (length > 0 && length / conf->heads / conf->secs % blk_size) {
>          blkcfg.geometry.sectors = conf->secs & ~s->sector_mask;
>      } else {
>          blkcfg.geometry.sectors = conf->secs;
> -- 
> 2.13.3
> 
> 

Reviewed-by: Fam Zheng <famz@redhat.com>

  reply	other threads:[~2017-08-08 14:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-08 12:22 [Qemu-devel] [PATCH] virtio-blk: handle blk_getlength() errors Stefan Hajnoczi
2017-08-08 14:30 ` Fam Zheng [this message]
2017-08-10 13:38 ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170808143022.GD2454@lemon \
    --to=famz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.