From nobody Sun Apr 13 03:40:52 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 1488315304802841.5423454405787; Tue, 28 Feb 2017 12:55:04 -0800 (PST) Received: from localhost ([::1]:36842 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cionW-0003xm-G5 for importer@patchew.org; Tue, 28 Feb 2017 15:55:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cioXP-0006sD-9Y for qemu-devel@nongnu.org; Tue, 28 Feb 2017 15:38:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cioXN-0008Eo-Uk for qemu-devel@nongnu.org; Tue, 28 Feb 2017 15:38:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52794) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cioXJ-0008Ap-Iy; Tue, 28 Feb 2017 15:38:17 -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 B7EA4C054C46; Tue, 28 Feb 2017 20:38:17 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-177.ams2.redhat.com [10.36.116.177]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SKapFk021888; Tue, 28 Feb 2017 15:38:16 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 28 Feb 2017 21:36:44 +0100 Message-Id: <1488314205-16264-46-git-send-email-kwolf@redhat.com> In-Reply-To: <1488314205-16264-1-git-send-email-kwolf@redhat.com> References: <1488314205-16264-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.32]); Tue, 28 Feb 2017 20:38:17 +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] [PULL 45/46] block: Add Error parameter to bdrv_set_backing_hd() 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, qemu-devel@nongnu.org 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" Not all callers of bdrv_set_backing_hd() know for sure that attaching the backing file will be allowed by the permission system. Return the error from the function rather than aborting. Signed-off-by: Kevin Wolf Acked-by: Fam Zheng Reviewed-by: Max Reitz --- block.c | 30 +++++++++++++++++++++++------- block/commit.c | 14 +++++++------- block/mirror.c | 7 ++++++- block/stream.c | 9 ++++++++- block/vvfat.c | 2 +- include/block/block.h | 3 ++- 6 files changed, 47 insertions(+), 18 deletions(-) diff --git a/block.c b/block.c index 74ac7dc..6440b61 100644 --- a/block.c +++ b/block.c @@ -1883,7 +1883,8 @@ static void bdrv_parent_cb_resize(BlockDriverState *b= s) * Sets the backing file link of a BDS. A new reference is created; callers * which don't need their own reference any more must call bdrv_unref(). */ -void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_h= d) +void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_h= d, + Error **errp) { if (backing_hd) { bdrv_ref(backing_hd); @@ -1897,9 +1898,12 @@ void bdrv_set_backing_hd(BlockDriverState *bs, Block= DriverState *backing_hd) bs->backing =3D NULL; goto out; } - /* FIXME Error handling */ + bs->backing =3D bdrv_attach_child(bs, backing_hd, "backing", &child_ba= cking, - &error_abort); + errp); + if (!bs->backing) { + bdrv_unref(backing_hd); + } =20 out: bdrv_refresh_limits(bs, NULL); @@ -1983,8 +1987,12 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDi= ct *parent_options, =20 /* Hook up the backing file link; drop our reference, bs owns the * backing_hd reference now */ - bdrv_set_backing_hd(bs, backing_hd); + bdrv_set_backing_hd(bs, backing_hd, &local_err); bdrv_unref(backing_hd); + if (local_err) { + ret =3D -EINVAL; + goto free_exit; + } =20 qdict_del(parent_options, bdref_key); =20 @@ -2818,7 +2826,7 @@ static void bdrv_close(BlockDriverState *bs) bs->drv->bdrv_close(bs); bs->drv =3D NULL; =20 - bdrv_set_backing_hd(bs, NULL); + bdrv_set_backing_hd(bs, NULL, &error_abort); =20 if (bs->file !=3D NULL) { bdrv_unref_child(bs, bs->file); @@ -2927,7 +2935,8 @@ void bdrv_append(BlockDriverState *bs_new, BlockDrive= rState *bs_top) bdrv_ref(bs_top); =20 change_parent_backing_link(bs_top, bs_new); - bdrv_set_backing_hd(bs_new, bs_top); + /* FIXME Error handling */ + bdrv_set_backing_hd(bs_new, bs_top, &error_abort); bdrv_unref(bs_top); =20 /* bs_new is now referenced by its new parents, we don't need the @@ -3075,6 +3084,7 @@ int bdrv_drop_intermediate(BlockDriverState *active, = BlockDriverState *top, BlockDriverState *base, const char *backing_fil= e_str) { BlockDriverState *new_top_bs =3D NULL; + Error *local_err =3D NULL; int ret =3D -EIO; =20 if (!top->drv || !base->drv) { @@ -3107,7 +3117,13 @@ int bdrv_drop_intermediate(BlockDriverState *active,= BlockDriverState *top, if (ret) { goto exit; } - bdrv_set_backing_hd(new_top_bs, base); + + bdrv_set_backing_hd(new_top_bs, base, &local_err); + if (local_err) { + ret =3D -EPERM; + error_report_err(local_err); + goto exit; + } =20 ret =3D 0; exit: diff --git a/block/commit.c b/block/commit.c index 1e0f531..22a0a4d 100644 --- a/block/commit.c +++ b/block/commit.c @@ -121,7 +121,7 @@ static void commit_complete(BlockJob *job, void *opaque) * filter driver from the backing chain. Do this as the final step so = that * the 'consistent read' permission can be granted. */ if (remove_commit_top_bs) { - bdrv_set_backing_hd(overlay_bs, top); + bdrv_set_backing_hd(overlay_bs, top, &error_abort); } } =20 @@ -316,8 +316,8 @@ void commit_start(const char *job_id, BlockDriverState = *bs, goto fail; } =20 - bdrv_set_backing_hd(commit_top_bs, top); - bdrv_set_backing_hd(overlay_bs, commit_top_bs); + bdrv_set_backing_hd(commit_top_bs, top, &error_abort); + bdrv_set_backing_hd(overlay_bs, commit_top_bs, &error_abort); =20 s->commit_top_bs =3D commit_top_bs; bdrv_unref(commit_top_bs); @@ -390,7 +390,7 @@ fail: blk_unref(s->top); } if (commit_top_bs) { - bdrv_set_backing_hd(overlay_bs, top); + bdrv_set_backing_hd(overlay_bs, top, &error_abort); } block_job_unref(&s->common); } @@ -451,8 +451,8 @@ int bdrv_commit(BlockDriverState *bs) goto ro_cleanup; } =20 - bdrv_set_backing_hd(commit_top_bs, backing_file_bs); - bdrv_set_backing_hd(bs, commit_top_bs); + bdrv_set_backing_hd(commit_top_bs, backing_file_bs, &error_abort); + bdrv_set_backing_hd(bs, commit_top_bs, &error_abort); =20 ret =3D blk_insert_bs(backing, backing_file_bs, &local_err); if (ret < 0) { @@ -532,7 +532,7 @@ ro_cleanup: =20 blk_unref(backing); if (backing_file_bs) { - bdrv_set_backing_hd(bs, backing_file_bs); + bdrv_set_backing_hd(bs, backing_file_bs, &error_abort); } bdrv_unref(commit_top_bs); blk_unref(src); diff --git a/block/mirror.c b/block/mirror.c index 869212d..8497e0d 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -503,6 +503,7 @@ static void mirror_exit(BlockJob *job, void *opaque) BlockDriverState *src =3D s->source; BlockDriverState *target_bs =3D blk_bs(s->target); BlockDriverState *mirror_top_bs =3D s->mirror_top_bs; + Error *local_err =3D NULL; =20 /* Make sure that the source BDS doesn't go away before we called * block_job_completed(). */ @@ -516,7 +517,11 @@ static void mirror_exit(BlockJob *job, void *opaque) if (s->backing_mode =3D=3D MIRROR_SOURCE_BACKING_CHAIN) { BlockDriverState *backing =3D s->is_none_mode ? src : s->base; if (backing_bs(target_bs) !=3D backing) { - bdrv_set_backing_hd(target_bs, backing); + bdrv_set_backing_hd(target_bs, backing, &local_err); + if (local_err) { + error_report_err(local_err); + data->ret =3D -EPERM; + } } } =20 diff --git a/block/stream.c b/block/stream.c index b9c2f43..0113710 100644 --- a/block/stream.c +++ b/block/stream.c @@ -68,6 +68,7 @@ static void stream_complete(BlockJob *job, void *opaque) StreamCompleteData *data =3D opaque; BlockDriverState *bs =3D blk_bs(job->blk); BlockDriverState *base =3D s->base; + Error *local_err =3D NULL; =20 if (!block_job_is_cancelled(&s->common) && data->reached_end && data->ret =3D=3D 0) { @@ -79,9 +80,15 @@ static void stream_complete(BlockJob *job, void *opaque) } } data->ret =3D bdrv_change_backing_file(bs, base_id, base_fmt); - bdrv_set_backing_hd(bs, base); + bdrv_set_backing_hd(bs, base, &local_err); + if (local_err) { + error_report_err(local_err); + data->ret =3D -EPERM; + goto out; + } } =20 +out: /* Reopen the image back in read-only mode if necessary */ if (s->bs_flags !=3D bdrv_get_flags(bs)) { /* Give up write permissions before making it read-only */ diff --git a/block/vvfat.c b/block/vvfat.c index 72b482c..aa61c32 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3041,7 +3041,7 @@ static int enable_write_target(BlockDriverState *bs, = Error **errp) &error_abort); *(void**) backing->opaque =3D s; =20 - bdrv_set_backing_hd(s->bs, backing); + bdrv_set_backing_hd(s->bs, backing, &error_abort); bdrv_unref(backing); =20 return 0; diff --git a/include/block/block.h b/include/block/block.h index 07f7561..eac2861 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -247,7 +247,8 @@ BdrvChild *bdrv_open_child(const char *filename, BlockDriverState* parent, const BdrvChildRole *child_role, bool allow_none, Error **errp); -void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_h= d); +void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_h= d, + Error **errp); int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, const char *bdref_key, Error **errp); BlockDriverState *bdrv_open(const char *filename, const char *reference, --=20 1.8.3.1