From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzQy6-00051K-Ji for qemu-devel@nongnu.org; Wed, 17 Jul 2013 08:36:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzQy1-0002z6-FI for qemu-devel@nongnu.org; Wed, 17 Jul 2013 08:36:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23266) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzQy1-0002z0-5C for qemu-devel@nongnu.org; Wed, 17 Jul 2013 08:36:25 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6HCaO3a020509 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 17 Jul 2013 08:36:24 -0400 Message-ID: <51E68FBC.10200@redhat.com> Date: Wed, 17 Jul 2013 14:36:12 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1374054136-28741-1-git-send-email-famz@redhat.com> <1374054136-28741-11-git-send-email-famz@redhat.com> In-Reply-To: <1374054136-28741-11-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 10/11] block: add option 'backing' to -drive options List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, hbrock@redhat.com, qemu-devel@nongnu.org, rjones@redhat.com, imain@redhat.com, stefanha@redhat.com Il 17/07/2013 11:42, Fam Zheng ha scritto: > This option allows overriding backing hd of drive. If the target drive > exists, it's referenced as the backing file and refcount incremented. > > Example: > qemu-system-x86_64 -drive \ > file.filename=foo.qcow2,if=none,id=foo \ > -drive file=bar.qcow2,backing=foo I guess this is where we need the soft reference. This has a _lot_ of potential for misuse, I think Kevin bashed me and Federico very heavily when we tried to do something similar. block/backup.c is the right place where we can override the backing hd of the drive. Perhaps we can add a way to open a file with BDRV_O_NO_BACKING from the command line. Paolo > Signed-off-by: Fam Zheng > --- > block.c | 30 ++++++++++++++++++++++++------ > 1 file changed, 24 insertions(+), 6 deletions(-) > > diff --git a/block.c b/block.c > index 147a448..31fab07 100644 > --- a/block.c > +++ b/block.c > @@ -1083,12 +1083,30 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, > > /* If there is a backing file, use it */ > if ((flags & BDRV_O_NO_BACKING) == 0) { > - QDict *backing_options; > - > - extract_subqdict(options, &backing_options, "backing."); > - ret = bdrv_open_backing_file(bs, backing_options); > - if (ret < 0) { > - goto close_and_fail; > + const char *backing_drive; > + backing_drive = qdict_get_try_str(options, "backing"); > + if (backing_drive) { > + bs->backing_hd = bdrv_find(backing_drive); > + if (bs->backing_hd) { > + bdrv_ref(bs->backing_hd, false); > + pstrcpy(bs->backing_file, sizeof(bs->backing_file), > + bs->backing_hd->filename); > + pstrcpy(bs->backing_format, sizeof(bs->backing_format), > + bs->backing_hd->drv->format_name); > + } else { > + qerror_report(ERROR_CLASS_DEVICE_NOT_FOUND, > + "Can't find drive with name %s\n", backing_drive); > + ret = -EINVAL; > + goto close_and_fail; > + } > + qdict_del(options, "backing"); > + } else { > + QDict *backing_options; > + extract_subqdict(options, &backing_options, "backing."); > + ret = bdrv_open_backing_file(bs, backing_options); > + if (ret < 0) { > + goto close_and_fail; > + } > } > } > >