From nobody Thu Nov 6 19:04:18 2025 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 1488226581670320.3666082907141; Mon, 27 Feb 2017 12:16:21 -0800 (PST) Received: from localhost ([::1]:56533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciRiW-0004Zf-93 for importer@patchew.org; Mon, 27 Feb 2017 15:16:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciRcU-0007bk-Kg for qemu-devel@nongnu.org; Mon, 27 Feb 2017 15:10:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciRcQ-0002su-GM for qemu-devel@nongnu.org; Mon, 27 Feb 2017 15:10:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46386) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciRcL-0002rz-Qg; Mon, 27 Feb 2017 15:09:57 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 128BB83F3F; Mon, 27 Feb 2017 20:09:58 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-148.ams2.redhat.com [10.36.116.148]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RK9n8F003294; Mon, 27 Feb 2017 15:09:55 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 27 Feb 2017 21:09:03 +0100 Message-Id: <1488226184-9044-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1488226184-9044-1-git-send-email-kwolf@redhat.com> References: <1488226184-9044-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 27 Feb 2017 20:09:58 +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 v2 02/43] block: Add Error argument to bdrv_attach_child() 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" It will have to return an error soon, so prepare the callers for it. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 16 +++++++++++++--- block/quorum.c | 9 ++++++++- include/block/block.h | 3 ++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index b663204..65240fa 100644 --- a/block.c +++ b/block.c @@ -1368,7 +1368,8 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *c= hild_bs, BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, const char *child_name, - const BdrvChildRole *child_role) + const BdrvChildRole *child_role, + Error **errp) { BdrvChild *child =3D bdrv_root_attach_child(child_bs, child_name, chil= d_role, parent_bs); @@ -1469,7 +1470,9 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockD= riverState *backing_hd) bs->backing =3D NULL; goto out; } - bs->backing =3D bdrv_attach_child(bs, backing_hd, "backing", &child_ba= cking); + /* FIXME Error handling */ + bs->backing =3D bdrv_attach_child(bs, backing_hd, "backing", &child_ba= cking, + &error_abort); bs->open_flags &=3D ~BDRV_O_NO_BACKING; pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_hd->filena= me); pstrcpy(bs->backing_format, sizeof(bs->backing_format), @@ -1648,6 +1651,7 @@ BdrvChild *bdrv_open_child(const char *filename, const BdrvChildRole *child_role, bool allow_none, Error **errp) { + BdrvChild *c; BlockDriverState *bs; =20 bs =3D bdrv_open_child_bs(filename, options, bdref_key, parent, child_= role, @@ -1656,7 +1660,13 @@ BdrvChild *bdrv_open_child(const char *filename, return NULL; } =20 - return bdrv_attach_child(parent, bs, bdref_key, child_role); + c =3D bdrv_attach_child(parent, bs, bdref_key, child_role, errp); + if (!c) { + bdrv_unref(bs); + return NULL; + } + + return c; } =20 static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs, diff --git a/block/quorum.c b/block/quorum.c index 86e2072..bdbcec6 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1032,10 +1032,17 @@ static void quorum_add_child(BlockDriverState *bs, = BlockDriverState *child_bs, =20 /* We can safely add the child now */ bdrv_ref(child_bs); - child =3D bdrv_attach_child(bs, child_bs, indexstr, &child_format); + + child =3D bdrv_attach_child(bs, child_bs, indexstr, &child_format, err= p); + if (child =3D=3D NULL) { + s->next_child_index--; + bdrv_unref(child_bs); + goto out; + } s->children =3D g_renew(BdrvChild *, s->children, s->num_children + 1); s->children[s->num_children++] =3D child; =20 +out: bdrv_drained_end(bs); } =20 diff --git a/include/block/block.h b/include/block/block.h index f62f38e..ff951ea 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -520,7 +520,8 @@ void bdrv_unref_child(BlockDriverState *parent, BdrvChi= ld *child); BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, const char *child_name, - const BdrvChildRole *child_role); + const BdrvChildRole *child_role, + Error **errp); =20 bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp= ); void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason); --=20 1.8.3.1