All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: Peter Feiner <peter@gridcentric.ca>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: Re: [Qemu-devel] [PATCH] block: fix backing file segfault
Date: Thu, 09 Jan 2014 09:01:52 +0800	[thread overview]
Message-ID: <52CDF500.6080901@redhat.com> (raw)
In-Reply-To: <1389210205-10787-1-git-send-email-peter@gridcentric.ca>


Hi Peter,

Thank your for catching this.

On 2014年01月09日 03:43, Peter Feiner wrote:
> When a backing file is opened such that (1) a protocol is directly
> used as the block driver and (2) the block driver has bdrv_file_open,
> bdrv_open_backing_file segfaults. The problem arises because
> bdrv_open_common returns without setting bd->backing_hd->file.
>
> To effect (1), you seem to have to use the -F flag in qemu-img. There
> are several block drivers that satisfy (2), such as "file" and "nbd".
> Here are some concrete examples:
>
>      #!/bin/bash
>
>      echo Test file format
>      ./qemu-img create -f file base.file 1m
>      ./qemu-img create -f qcow2 -F file -o backing_file=base.file\
>          file-overlay.qcow2
>      ./qemu-img convert -O raw file-overlay.qcow2 file-convert.raw
>
>      echo Test nbd format
>      SOCK=$PWD/nbd.sock
>      ./qemu-img create -f raw base.raw 1m
>      ./qemu-nbd -t -k $SOCK base.raw &
>      trap "kill $!" EXIT
>      while ! test -e $SOCK; do sleep 1; done
>      ./qemu-img create -f qcow2 -F nbd -o backing_file=nbd:unix:$SOCK\
>          nbd-overlay.qcow2
>      ./qemu-img convert -O raw nbd-overlay.qcow2 nbd-convert.raw

It would be nice if you can add this as a test case under 
tests/qemu-iotests.

>
> Without this patch, the two qemu-img convert commands segfault.
>
> This is a regression that was introduced in v1.7 by
> dbecebddfa4932d1c83915bcb9b5ba5984eb91be.
>
> Signed-off-by: Peter Feiner <peter@gridcentric.ca>
> ---
>   block.c |    5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/block.c b/block.c
> index 64e7d22..a4a172d 100644
> --- a/block.c
> +++ b/block.c
> @@ -1016,8 +1016,9 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
>           error_free(local_err);
>           return ret;
>       }
> -    pstrcpy(bs->backing_file, sizeof(bs->backing_file),
> -            bs->backing_hd->file->filename);
> +    if (bs->backing_hd->file)
> +        pstrcpy(bs->backing_file, sizeof(bs->backing_file),
> +                bs->backing_hd->file->filename);

Braces are mandatory for if statements (scripts/checkpatch.pl can check 
the coding style for you).

Thanks,
Fam

  reply	other threads:[~2014-01-09  1:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-08 19:43 [Qemu-devel] [PATCH] block: fix backing file segfault Peter Feiner
2014-01-09  1:01 ` Fam Zheng [this message]
2014-01-09 10:59 ` Kevin Wolf
2014-01-10  4:07   ` Peter Feiner
2014-01-10 17:27   ` Max Reitz
2014-01-10 17:55     ` Kevin Wolf
2014-01-10 18:05       ` Max Reitz
2014-01-10 18:26         ` Kevin Wolf
2014-01-10 18:38           ` Max Reitz
2014-01-10 18:55             ` Kevin Wolf
2014-01-10 19:03           ` Peter Feiner
2014-01-10 19:10             ` Kevin Wolf

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=52CDF500.6080901@redhat.com \
    --to=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=peter@gridcentric.ca \
    --cc=qemu-devel@nongnu.org \
    /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.