Received: from eggs.gnu.org ([2001:4830:134:3::10]:44088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vku3L-0001MM-Np for qemu-devel@nongnu.org; Mon, 25 Nov 2013 06:10:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vku3F-0005Bl-NZ for qemu-devel@nongnu.org; Mon, 25 Nov 2013 06:10:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54803) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vku3F-0005Bf-G7 for qemu-devel@nongnu.org; Mon, 25 Nov 2013 06:10:01 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAPBA06C015632 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 25 Nov 2013 06:10:00 -0500 Date: Mon, 25 Nov 2013 12:10:01 +0100 From: Kevin Wolf Message-ID: <20131125111001.GE3009@dhcp-200-207.str.redhat.com> References: <1385097894-1380-1-git-send-email-famz@redhat.com> <1385097894-1380-6-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1385097894-1380-6-git-send-email-famz@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v4 5/7] block: Parse "backing" option to reference existing BDS List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: hbrock@redhat.com, qemu-devel@nongnu.org, rjones@redhat.com, imain@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Am 22.11.2013 um 06:24 hat Fam Zheng geschrieben: > Signed-off-by: Fam Zheng > --- > block.c | 37 ++++++++++++++++++++++++++++++++----- > include/block/block_int.h | 3 +++ > 2 files changed, 35 insertions(+), 5 deletions(-) >=20 > diff --git a/block.c b/block.c > index 3bf4c8a..a5da656 100644 > --- a/block.c > +++ b/block.c > @@ -1166,11 +1166,33 @@ int bdrv_open(BlockDriverState *bs, const char = *filename, QDict *options, > /* If there is a backing file, use it */ > if ((flags & BDRV_O_NO_BACKING) =3D=3D 0) { > QDict *backing_options; > - > - qdict_extract_subqdict(options, &backing_options, "backing."); > - ret =3D bdrv_open_backing_file(bs, backing_options, &local_err= ); > - if (ret < 0) { > - goto close_and_fail; > + const char *backing_bs; > + > + backing_bs =3D qdict_get_try_str(options, "backing"); > + if (backing_bs) { > + bs->backing_hd =3D bdrv_find(backing_bs); > + qdict_del(options, "backing"); > + if (bs->backing_hd) { > + bdrv_ref(bs->backing_hd); > + assert(!bs->backing_blocker); > + error_setg(&bs->backing_blocker, > + "device is used as backing hd of '%s'", > + bs->device_name); > + bdrv_op_block_all(bs->backing_hd, bs->backing_blocker)= ; > + 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 { > + error_setg(errp, "Backing device not found: %s", backi= ng_bs); > + goto close_and_fail; > + } > + } else { > + qdict_extract_subqdict(options, &backing_options, "backing= ."); > + ret =3D bdrv_open_backing_file(bs, backing_options, &local= _err); > + if (ret < 0) { > + goto close_and_fail; > + } > } > } Can we move all of this code into bdrv_open_backing_file()? I think the bdrv_op_block_all() part should apply to all kinds of backing files. Currently you can't issue any monitor commands, so it doesn't matter yet, but Beno=EEt is working on adding per-node names and then we might want this. And consistency never hurts anyway. > @@ -1461,6 +1483,11 @@ void bdrv_close(BlockDriverState *bs) > =20 > if (bs->drv) { > if (bs->backing_hd) { > + if (error_is_set(&bs->backing_blocker)) { Then this one should become unconditional as well, I think. > + bdrv_op_unblock_all(bs->backing_hd, > + bs->backing_blocker); > + error_free(bs->backing_blocker); > + } > bdrv_unref(bs->backing_hd); > bs->backing_hd =3D NULL; > } Kevin