From nobody Sun Feb 8 19:55:35 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 1488901952479614.3864222701203; Tue, 7 Mar 2017 07:52:32 -0800 (PST) Received: from localhost ([::1]:51307 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHPa-0002rO-7b for importer@patchew.org; Tue, 07 Mar 2017 10:52:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEn-0002HU-Sa for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEj-0002ll-TR for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49002) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEg-0002h4-Dl; Tue, 07 Mar 2017 10:41:14 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 80ADA8046F; Tue, 7 Mar 2017 15:41:14 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v27FeuUd032123; Tue, 7 Mar 2017 10:41:12 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:34 +0100 Message-Id: <1488901251-16214-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1488901251-16214-1-git-send-email-kwolf@redhat.com> References: <1488901251-16214-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 07 Mar 2017 15:41:14 +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 10/27] block: Fix error handling in bdrv_replace_in_backing_chain() 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" When adding an Error parameter, bdrv_replace_in_backing_chain() would become nothing more than a wrapper around change_parent_backing_link(). So make the latter public, renamed as bdrv_replace_node(), and remove bdrv_replace_in_backing_chain(). Most of the callers just remove a node from the graph that they just inserted, so they can use &error_abort, but completion of a mirror job with 'replaces' set can actually fail. Signed-off-by: Kevin Wolf Reviewed-by: Fam Zheng Reviewed-by: Eric Blake --- block.c | 25 ++++++------------------- block/mirror.c | 15 +++++++++------ blockdev.c | 2 +- include/block/block.h | 4 ++-- include/block/block_int.h | 4 ++-- 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/block.c b/block.c index a310132..dd9ded8 100644 --- a/block.c +++ b/block.c @@ -2932,8 +2932,8 @@ static bool should_update_child(BdrvChild *c, BlockDr= iverState *to) return true; } =20 -static void change_parent_backing_link(BlockDriverState *from, - BlockDriverState *to, Error **errp) +void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, + Error **errp) { BdrvChild *c, *next; GSList *list =3D NULL, *p; @@ -2941,6 +2941,9 @@ static void change_parent_backing_link(BlockDriverSta= te *from, uint64_t perm =3D 0, shared =3D BLK_PERM_ALL; int ret; =20 + assert(!atomic_read(&from->in_flight)); + assert(!atomic_read(&to->in_flight)); + /* Make sure that @from doesn't go away until we have successfully att= ached * all of its parents to @to. */ bdrv_ref(from); @@ -3003,16 +3006,13 @@ void bdrv_append(BlockDriverState *bs_new, BlockDri= verState *bs_top, { Error *local_err =3D NULL; =20 - assert(!atomic_read(&bs_top->in_flight)); - assert(!atomic_read(&bs_new->in_flight)); - bdrv_set_backing_hd(bs_new, bs_top, &local_err); if (local_err) { error_propagate(errp, local_err); goto out; } =20 - change_parent_backing_link(bs_top, bs_new, &local_err); + bdrv_replace_node(bs_top, bs_new, &local_err); if (local_err) { error_propagate(errp, local_err); bdrv_set_backing_hd(bs_new, NULL, &error_abort); @@ -3025,19 +3025,6 @@ out: bdrv_unref(bs_new); } =20 -void bdrv_replace_in_backing_chain(BlockDriverState *old, BlockDriverState= *new) -{ - assert(!bdrv_requests_pending(old)); - assert(!bdrv_requests_pending(new)); - - bdrv_ref(old); - - /* FIXME Proper error handling */ - change_parent_backing_link(old, new, &error_abort); - - bdrv_unref(old); -} - static void bdrv_delete(BlockDriverState *bs) { assert(!bs->job); diff --git a/block/mirror.c b/block/mirror.c index f24dc51..a5d30ee 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -550,8 +550,12 @@ static void mirror_exit(BlockJob *job, void *opaque) /* The mirror job has no requests in flight any more, but we need = to * drain potential other users of the BDS before changing the grap= h. */ bdrv_drained_begin(target_bs); - bdrv_replace_in_backing_chain(to_replace, target_bs); + bdrv_replace_node(to_replace, target_bs, &local_err); bdrv_drained_end(target_bs); + if (local_err) { + error_report_err(local_err); + data->ret =3D -EPERM; + } } if (s->to_replace) { bdrv_op_unblock_all(s->to_replace, s->replace_blocker); @@ -570,12 +574,11 @@ static void mirror_exit(BlockJob *job, void *opaque) * block the removal. */ block_job_remove_all_bdrv(job); bdrv_child_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL); - bdrv_replace_in_backing_chain(mirror_top_bs, backing_bs(mirror_top_bs)= ); + bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abo= rt); =20 /* We just changed the BDS the job BB refers to (with either or both o= f the - * bdrv_replace_in_backing_chain() calls), so switch the BB back so the - * cleanup does the right thing. We don't need any permissions any more - * now. */ + * bdrv_replace_node() calls), so switch the BB back so the cleanup do= es + * the right thing. We don't need any permissions any more now. */ blk_remove_bs(job->blk); blk_set_perm(job->blk, 0, BLK_PERM_ALL, &error_abort); blk_insert_bs(job->blk, mirror_top_bs, &error_abort); @@ -1234,7 +1237,7 @@ fail: } =20 bdrv_child_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL); - bdrv_replace_in_backing_chain(mirror_top_bs, backing_bs(mirror_top_bs)= ); + bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abo= rt); } =20 void mirror_start(const char *job_id, BlockDriverState *bs, diff --git a/blockdev.c b/blockdev.c index af67ce4..f1f49bd 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1806,7 +1806,7 @@ static void external_snapshot_abort(BlkActionState *c= ommon) DO_UPCAST(ExternalSnapshotState, common, comm= on); if (state->new_bs) { if (state->overlay_appended) { - bdrv_replace_in_backing_chain(state->new_bs, state->old_bs); + bdrv_replace_node(state->new_bs, state->old_bs, &error_abort); } } } diff --git a/include/block/block.h b/include/block/block.h index c7c4a3a..5149260 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -238,8 +238,8 @@ int bdrv_create_file(const char *filename, QemuOpts *op= ts, Error **errp); BlockDriverState *bdrv_new(void); void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, Error **errp); -void bdrv_replace_in_backing_chain(BlockDriverState *old, - BlockDriverState *new); +void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, + Error **errp); =20 int bdrv_parse_cache_mode(const char *mode, int *flags, bool *writethrough= ); int bdrv_parse_discard_flags(const char *mode, int *flags); diff --git a/include/block/block_int.h b/include/block/block_int.h index fc83f7f..6c699ac 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -441,8 +441,8 @@ typedef struct BdrvAioNotifier { } BdrvAioNotifier; =20 struct BdrvChildRole { - /* If true, bdrv_replace_in_backing_chain() doesn't change the node th= is - * BdrvChild points to. */ + /* If true, bdrv_replace_node() doesn't change the node this BdrvChild + * points to. */ bool stay_at_node; =20 void (*inherit_options)(int *child_flags, QDict *child_options, --=20 1.8.3.1