From nobody Sun Feb 8 21:33:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14876909137970.8598785403138436; Tue, 21 Feb 2017 07:28:33 -0800 (PST) Received: from localhost ([::1]:46333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgCMi-00021w-80 for importer@patchew.org; Tue, 21 Feb 2017 10:28:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgBuK-00086J-Lo for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgBuJ-0007lz-GT for qemu-devel@nongnu.org; Tue, 21 Feb 2017 09:59:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34076) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgBuG-0007jm-UJ; Tue, 21 Feb 2017 09:59:09 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A3A9C04B320; Tue, 21 Feb 2017 14:59:09 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LEwucp030565; Tue, 21 Feb 2017 09:59:07 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Feb 2017 15:58:03 +0100 Message-Id: <1487689130-30373-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1487689130-30373-1-git-send-email-kwolf@redhat.com> References: <1487689130-30373-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Feb 2017 14:59:09 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 07/54] block: Use BlockBackend for image probing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jcody@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This fixes the use of a parent-less BdrvChild in bdrv_open_inherit() by converting it into a BlockBackend. Which is exactly what it should be, image probing is an external, standalone user of a node. The requests can't be considered to originate from the format driver node because that one isn't even opened yet. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index e9d90aa..0f17576 100644 --- a/block.c +++ b/block.c @@ -588,21 +588,20 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int b= uf_size, return drv; } =20 -static int find_image_format(BdrvChild *file, const char *filename, +static int find_image_format(BlockBackend *file, const char *filename, BlockDriver **pdrv, Error **errp) { - BlockDriverState *bs =3D file->bs; BlockDriver *drv; uint8_t buf[BLOCK_PROBE_BUF_SIZE]; int ret =3D 0; =20 /* Return the raw BlockDriver * to scsi-generic devices or empty drive= s */ - if (bdrv_is_sg(bs) || !bdrv_is_inserted(bs) || bdrv_getlength(bs) =3D= =3D 0) { + if (blk_is_sg(file) || !blk_is_inserted(file) || blk_getlength(file) = =3D=3D 0) { *pdrv =3D &bdrv_raw; return ret; } =20 - ret =3D bdrv_pread(file, 0, buf, sizeof(buf)); + ret =3D blk_pread(file, 0, buf, sizeof(buf)); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read image for determining= its " "format"); @@ -974,7 +973,7 @@ QemuOptsList bdrv_runtime_opts =3D { * * Removes all processed options from *options. */ -static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file, +static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file, QDict *options, Error **errp) { int ret, open_flags; @@ -1005,7 +1004,7 @@ static int bdrv_open_common(BlockDriverState *bs, Bdr= vChild *file, assert(drv !=3D NULL); =20 if (file !=3D NULL) { - filename =3D file->bs->filename; + filename =3D blk_bs(file)->filename; } else { filename =3D qdict_get_try_str(options, "filename"); } @@ -1707,7 +1706,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, Error **errp) { int ret; - BdrvChild *file =3D NULL; + BlockBackend *file =3D NULL; BlockDriverState *bs; BlockDriver *drv =3D NULL; const char *drvname; @@ -1805,19 +1804,24 @@ static BlockDriverState *bdrv_open_inherit(const ch= ar *filename, qdict_del(options, "backing"); } =20 - /* Open image file without format layer. This BdrvChild is only used f= or + /* Open image file without format layer. This BlockBackend is only use= d for * probing, the block drivers will do their own bdrv_open_child() for = the * same BDS, which is why we put the node name back into options. */ if ((flags & BDRV_O_PROTOCOL) =3D=3D 0) { - /* FIXME Shouldn't attach a child to a node that isn't opened yet.= */ - file =3D bdrv_open_child(filename, options, "file", bs, - &child_file, true, &local_err); + BlockDriverState *file_bs; + + file_bs =3D bdrv_open_child_bs(filename, options, "file", bs, + &child_file, true, &local_err); if (local_err) { goto fail; } - if (file !=3D NULL) { + if (file_bs !=3D NULL) { + file =3D blk_new(); + blk_insert_bs(file, file_bs); + bdrv_unref(file_bs); + qdict_put(options, "file", - qstring_from_str(bdrv_get_node_name(file->bs))); + qstring_from_str(bdrv_get_node_name(file_bs))); } } =20 @@ -1859,7 +1863,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, } =20 if (file) { - bdrv_unref_child(bs, file); + blk_unref(file); file =3D NULL; } =20 @@ -1922,7 +1926,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, =20 fail: if (file !=3D NULL) { - bdrv_unref_child(bs, file); + blk_unref(file); } if (bs->file !=3D NULL) { bdrv_unref_child(bs, bs->file); --=20 1.8.3.1