From nobody Sun Apr 28 19:36:58 2024 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 148881741537710.059141187655996; Mon, 6 Mar 2017 08:23:35 -0800 (PST) Received: from localhost ([::1]:44785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvQ1-0002Si-QK for importer@patchew.org; Mon, 06 Mar 2017 11:23:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvP1-0002R9-Dw for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckvP0-00017j-Kz for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34614) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckvOx-00015k-Dg; Mon, 06 Mar 2017 11:22:23 -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 98E3961D31; Mon, 6 Mar 2017 16:22:23 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-180.ams2.redhat.com [10.36.116.180]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26GMJmr031063; Mon, 6 Mar 2017 11:22:22 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 6 Mar 2017 17:21:53 +0100 Message-Id: <1488817322-11397-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1488817322-11397-1-git-send-email-kwolf@redhat.com> References: <1488817322-11397-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.39]); Mon, 06 Mar 2017 16:22:23 +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 01/10] commit: Fix error handling 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" Apparently some kind of mismerge happened in commit 8dfba279, which broke the error handling without any real reason by removing the assignment of the return value to ret in a blk_insert_bs() call. Signed-off-by: Kevin Wolf Reviewed-by: Fam Zheng Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- block/commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/commit.c b/block/commit.c index 22a0a4d..e57c1cf 100644 --- a/block/commit.c +++ b/block/commit.c @@ -364,7 +364,7 @@ void commit_start(const char *job_id, BlockDriverState = *bs, =20 /* Required permissions are already taken with block_job_add_bdrv() */ s->top =3D blk_new(0, BLK_PERM_ALL); - blk_insert_bs(s->top, top, errp); + ret =3D blk_insert_bs(s->top, top, errp); if (ret < 0) { goto fail; } --=20 1.8.3.1 From nobody Sun Apr 28 19:36:58 2024 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 1488817414889440.58661159732605; Mon, 6 Mar 2017 08:23:34 -0800 (PST) Received: from localhost ([::1]:44787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvQ3-0002UC-HD for importer@patchew.org; Mon, 06 Mar 2017 11:23:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvP2-0002S3-EF for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckvP1-00018V-Hy for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60734) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckvOz-00016e-8L; Mon, 06 Mar 2017 11:22:25 -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 71CD180F75; Mon, 6 Mar 2017 16:22:25 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-180.ams2.redhat.com [10.36.116.180]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26GMJms031063; Mon, 6 Mar 2017 11:22:23 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 6 Mar 2017 17:21:54 +0100 Message-Id: <1488817322-11397-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1488817322-11397-1-git-send-email-kwolf@redhat.com> References: <1488817322-11397-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, 06 Mar 2017 16:22:25 +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 02/10] mirror: Fix permission problem with 'replaces' 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" The 'replaces' option of drive-mirror can be used to mirror a Quorum node to a new image and then let the target image replace one of the Quorum children. In order for this graph modification to succeed, the mirror job needs to lift its restrictions on the target node first before actually replacing the child. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Fam Zheng --- block/mirror.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 57f26c3..c9185b3 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -509,6 +509,13 @@ static void mirror_exit(BlockJob *job, void *opaque) * block_job_completed(). */ bdrv_ref(src); bdrv_ref(mirror_top_bs); + bdrv_ref(target_bs); + + /* Remove target parent that still uses BLK_PERM_WRITE/RESIZE before + * inserting target_bs at s->to_replace, where we might not be able to= get + * these permissions. */ + blk_unref(s->target); + s->target =3D NULL; =20 /* We don't access the source any more. Dropping any WRITE/RESIZE is * required before it could become a backing file of target_bs. */ @@ -555,8 +562,7 @@ static void mirror_exit(BlockJob *job, void *opaque) aio_context_release(replace_aio_context); } g_free(s->replaces); - blk_unref(s->target); - s->target =3D NULL; + bdrv_unref(target_bs); =20 /* Remove the mirror filter driver from the graph. Before this, get ri= d of * the blockers on the intermediate nodes so that the resulting state = is --=20 1.8.3.1 From nobody Sun Apr 28 19:36:58 2024 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 1488817554585385.17608224140236; Mon, 6 Mar 2017 08:25:54 -0800 (PST) Received: from localhost ([::1]:44802 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvSJ-0004WC-Ap for importer@patchew.org; Mon, 06 Mar 2017 11:25:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvP4-0002U1-FD for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckvP3-0001A0-HR for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43976) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckvP1-00017b-66; Mon, 06 Mar 2017 11:22:27 -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 51635D59BF; Mon, 6 Mar 2017 16:22:27 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-180.ams2.redhat.com [10.36.116.180]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26GMJmt031063; Mon, 6 Mar 2017 11:22:25 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 6 Mar 2017 17:21:55 +0100 Message-Id: <1488817322-11397-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1488817322-11397-1-git-send-email-kwolf@redhat.com> References: <1488817322-11397-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.38]); Mon, 06 Mar 2017 16:22:27 +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 03/10] mirror: Fix permissions for removing mirror_top_bs 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" mirror_top_bs takes write permissions on its backing file, which can make it impossible to attach that backing file node to another parent. However, this is exactly what needs to be done in order to remove mirror_top_bs from the backing chain. So give up the write permission first. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Fam Zheng --- block/mirror.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index c9185b3..001b5f0 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -566,8 +566,10 @@ static void mirror_exit(BlockJob *job, void *opaque) =20 /* Remove the mirror filter driver from the graph. Before this, get ri= d of * the blockers on the intermediate nodes so that the resulting state = is - * valid. */ + * valid. Also give up permissions on mirror_top_bs->backing, which mi= ght + * 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)= ); =20 /* We just changed the BDS the job BB refers to (with either or both o= f the @@ -1234,6 +1236,7 @@ fail: block_job_unref(&s->common); } =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)= ); } =20 --=20 1.8.3.1 From nobody Sun Apr 28 19:36:58 2024 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 1488817683645145.76555055115318; Mon, 6 Mar 2017 08:28:03 -0800 (PST) Received: from localhost ([::1]:44820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvUQ-0006Vb-Ev for importer@patchew.org; Mon, 06 Mar 2017 11:28:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvP8-0002YI-8s for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckvP5-0001At-4A for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44004) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckvP3-00019B-0d; Mon, 06 Mar 2017 11:22:29 -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 34C224E4EE; Mon, 6 Mar 2017 16:22:29 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-180.ams2.redhat.com [10.36.116.180]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26GMJmu031063; Mon, 6 Mar 2017 11:22:27 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 6 Mar 2017 17:21:56 +0100 Message-Id: <1488817322-11397-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1488817322-11397-1-git-send-email-kwolf@redhat.com> References: <1488817322-11397-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.38]); Mon, 06 Mar 2017 16:22:29 +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 04/10] mirror: Fix error path for dirty bitmap creation 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" mirror_top_bs must be removed from the graph again when creating the dirty bitmap fails. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Fam Zheng --- block/mirror.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 001b5f0..f24dc51 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1197,10 +1197,7 @@ static void mirror_start_job(const char *job_id, Blo= ckDriverState *bs, =20 s->dirty_bitmap =3D bdrv_create_dirty_bitmap(bs, granularity, NULL, er= rp); if (!s->dirty_bitmap) { - g_free(s->replaces); - blk_unref(s->target); - block_job_unref(&s->common); - return; + goto fail; } =20 /* Required permissions are already taken with blk_new() */ --=20 1.8.3.1 From nobody Sun Apr 28 19:36:58 2024 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 1488817550362446.73591894474555; Mon, 6 Mar 2017 08:25:50 -0800 (PST) Received: from localhost ([::1]:44801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvSG-0004TR-UP for importer@patchew.org; Mon, 06 Mar 2017 11:25:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvPA-0002ah-B4 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckvP9-0001CO-Er for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34716) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckvP4-0001AP-TB; Mon, 06 Mar 2017 11:22:30 -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 1810561D31; Mon, 6 Mar 2017 16:22:31 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-180.ams2.redhat.com [10.36.116.180]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26GMJmv031063; Mon, 6 Mar 2017 11:22:29 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 6 Mar 2017 17:21:57 +0100 Message-Id: <1488817322-11397-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1488817322-11397-1-git-send-email-kwolf@redhat.com> References: <1488817322-11397-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.39]); Mon, 06 Mar 2017 16:22:31 +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 05/10] block: Fix blockdev-snapshot error handling 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" For blockdev-snapshot, external_snapshot_prepare() accepts an arbitrary node reference at first and only checks later whether it already has a backing file. Between those places, other errors can occur. Therefore checking in external_snapshot_abort() whether state->new_bs has a backing file is not sufficient to tell whether bdrv_append() was already completed or not. Trying to undo the bdrv_append() when it wasn't even executed is wrong. Introduce a new boolean flag in the state to fix this. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Fam Zheng --- blockdev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 8eb4e84..af67ce4 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1614,6 +1614,7 @@ typedef struct ExternalSnapshotState { BlockDriverState *old_bs; BlockDriverState *new_bs; AioContext *aio_context; + bool overlay_appended; } ExternalSnapshotState; =20 static void external_snapshot_prepare(BlkActionState *common, @@ -1780,6 +1781,7 @@ static void external_snapshot_prepare(BlkActionState = *common, error_propagate(errp, local_err); return; } + state->overlay_appended =3D true; } =20 static void external_snapshot_commit(BlkActionState *common) @@ -1803,7 +1805,7 @@ static void external_snapshot_abort(BlkActionState *c= ommon) ExternalSnapshotState *state =3D DO_UPCAST(ExternalSnapshotState, common, comm= on); if (state->new_bs) { - if (state->new_bs->backing) { + if (state->overlay_appended) { bdrv_replace_in_backing_chain(state->new_bs, state->old_bs); } } --=20 1.8.3.1 From nobody Sun Apr 28 19:36:58 2024 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 1488817685508740.2468937400848; Mon, 6 Mar 2017 08:28:05 -0800 (PST) Received: from localhost ([::1]:44819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvUO-0006T4-8O for importer@patchew.org; Mon, 06 Mar 2017 11:28:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvPA-0002as-GR for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckvP9-0001CT-GE for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36314) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckvP6-0001BA-Qh; Mon, 06 Mar 2017 11:22:32 -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 0CE8D8EB56; Mon, 6 Mar 2017 16:22:33 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-180.ams2.redhat.com [10.36.116.180]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26GMJmw031063; Mon, 6 Mar 2017 11:22:31 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 6 Mar 2017 17:21:58 +0100 Message-Id: <1488817322-11397-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1488817322-11397-1-git-send-email-kwolf@redhat.com> References: <1488817322-11397-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.26]); Mon, 06 Mar 2017 16:22:33 +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 06/10] block: Factor out should_update_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" Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- block.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index f293ccb..6dc02b8 100644 --- a/block.c +++ b/block.c @@ -2886,28 +2886,40 @@ void bdrv_close_all(void) assert(QTAILQ_EMPTY(&all_bdrv_states)); } =20 +static bool should_update_child(BdrvChild *c, BlockDriverState *to) +{ + BdrvChild *to_c; + + if (c->role->stay_at_node) { + return false; + } + + if (c->role =3D=3D &child_backing) { + /* If @from is a backing file of @to, ignore the child to avoid + * creating a loop. We only want to change the pointer of other + * parents. */ + QLIST_FOREACH(to_c, &to->children, next) { + if (to_c =3D=3D c) { + break; + } + } + if (to_c) { + return false; + } + } + + return true; +} + static void change_parent_backing_link(BlockDriverState *from, BlockDriverState *to) { - BdrvChild *c, *next, *to_c; + BdrvChild *c, *next; =20 QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { - if (c->role->stay_at_node) { + if (!should_update_child(c, to)) { continue; } - if (c->role =3D=3D &child_backing) { - /* If @from is a backing file of @to, ignore the child to avoid - * creating a loop. We only want to change the pointer of other - * parents. */ - QLIST_FOREACH(to_c, &to->children, next) { - if (to_c =3D=3D c) { - break; - } - } - if (to_c) { - continue; - } - } =20 bdrv_ref(to); /* FIXME Are we sure that bdrv_replace_child() can't run into --=20 1.8.3.1 From nobody Sun Apr 28 19:36:58 2024 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 1488817434928304.21815599718514; Mon, 6 Mar 2017 08:23:54 -0800 (PST) Received: from localhost ([::1]:44791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvQM-0002lJ-Mx for importer@patchew.org; Mon, 06 Mar 2017 11:23:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvPC-0002ck-6v for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckvPB-0001DK-A4 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46974) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckvP8-0001Br-Tj; Mon, 06 Mar 2017 11:22:35 -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 20FAEC057FA5; Mon, 6 Mar 2017 16:22:35 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-180.ams2.redhat.com [10.36.116.180]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26GMJmx031063; Mon, 6 Mar 2017 11:22:33 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 6 Mar 2017 17:21:59 +0100 Message-Id: <1488817322-11397-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1488817322-11397-1-git-send-email-kwolf@redhat.com> References: <1488817322-11397-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]); Mon, 06 Mar 2017 16:22:35 +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/10] block: Factor out bdrv_replace_child_noperm() 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" Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Fam Zheng --- block.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 6dc02b8..d4570c8 100644 --- a/block.c +++ b/block.c @@ -1713,11 +1713,10 @@ void bdrv_format_default_perms(BlockDriverState *bs= , BdrvChild *c, *nshared =3D shared; } =20 -static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs, - bool check_new_perm) +static void bdrv_replace_child_noperm(BdrvChild *child, + BlockDriverState *new_bs) { BlockDriverState *old_bs =3D child->bs; - uint64_t perm, shared_perm; =20 if (old_bs) { if (old_bs->quiesce_counter && child->role->drained_end) { @@ -1727,7 +1726,29 @@ static void bdrv_replace_child(BdrvChild *child, Blo= ckDriverState *new_bs, child->role->detach(child); } QLIST_REMOVE(child, next_parent); + } + + child->bs =3D new_bs; + + if (new_bs) { + QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); + if (new_bs->quiesce_counter && child->role->drained_begin) { + child->role->drained_begin(child); + } + + if (child->role->attach) { + child->role->attach(child); + } + } +} =20 +static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs, + bool check_new_perm) +{ + BlockDriverState *old_bs =3D child->bs; + uint64_t perm, shared_perm; + + if (old_bs) { /* Update permissions for old node. This is guaranteed to succeed * because we're just taking a parent away, so we're loosening * restrictions. */ @@ -1736,23 +1757,14 @@ static void bdrv_replace_child(BdrvChild *child, Bl= ockDriverState *new_bs, bdrv_set_perm(old_bs, perm, shared_perm); } =20 - child->bs =3D new_bs; + bdrv_replace_child_noperm(child, new_bs); =20 if (new_bs) { - QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); - if (new_bs->quiesce_counter && child->role->drained_begin) { - child->role->drained_begin(child); - } - bdrv_get_cumulative_perm(new_bs, &perm, &shared_perm); if (check_new_perm) { bdrv_check_perm(new_bs, perm, shared_perm, &error_abort); } bdrv_set_perm(new_bs, perm, shared_perm); - - if (child->role->attach) { - child->role->attach(child); - } } } =20 --=20 1.8.3.1 From nobody Sun Apr 28 19:36:58 2024 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 1488817791991297.70098832296276; Mon, 6 Mar 2017 08:29:51 -0800 (PST) Received: from localhost ([::1]:44830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvWA-00088t-Ow for importer@patchew.org; Mon, 06 Mar 2017 11:29:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvPE-0002fL-Mj for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckvPD-0001ET-GV for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44086) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckvPA-0001Cm-R8; Mon, 06 Mar 2017 11:22:37 -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 09F064DD62; Mon, 6 Mar 2017 16:22:37 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-180.ams2.redhat.com [10.36.116.180]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26GMJn0031063; Mon, 6 Mar 2017 11:22:35 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 6 Mar 2017 17:22:00 +0100 Message-Id: <1488817322-11397-9-git-send-email-kwolf@redhat.com> In-Reply-To: <1488817322-11397-1-git-send-email-kwolf@redhat.com> References: <1488817322-11397-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.38]); Mon, 06 Mar 2017 16:22:37 +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 08/10] block: Ignore multiple children in bdrv_check_update_perm() 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" change_parent_backing_link() will need to update multiple BdrvChild objects at once. Checking permissions reference by reference doesn't work because permissions need to be consistent only with all parents moved to the new child. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Fam Zheng --- block.c | 35 ++++++++++++++++++++++------------- include/block/block_int.h | 2 +- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index d4570c8..a7b09d3 100644 --- a/block.c +++ b/block.c @@ -1398,7 +1398,8 @@ static int bdrv_fill_options(QDict **options, const c= har *filename, * or bdrv_abort_perm_update(). */ static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms, - uint64_t cumulative_shared_perms, Error **errp) + uint64_t cumulative_shared_perms, + GSList *ignore_children, Error **errp) { BlockDriver *drv =3D bs->drv; BdrvChild *c; @@ -1434,7 +1435,8 @@ static int bdrv_check_perm(BlockDriverState *bs, uint= 64_t cumulative_perms, drv->bdrv_child_perm(bs, c, c->role, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); - ret =3D bdrv_child_check_perm(c, cur_perm, cur_shared, errp); + ret =3D bdrv_child_check_perm(c, cur_perm, cur_shared, ignore_chil= dren, + errp); if (ret < 0) { return ret; } @@ -1554,15 +1556,15 @@ static char *bdrv_perm_names(uint64_t perm) =20 /* * Checks whether a new reference to @bs can be added if the new user requ= ires - * @new_used_perm/@new_shared_perm as its permissions. If @ignore_child is= set, - * this old reference is ignored in the calculations; this allows checking - * permission updates for an existing reference. + * @new_used_perm/@new_shared_perm as its permissions. If @ignore_children= is + * set, the BdrvChild objects in this list are ignored in the calculations; + * this allows checking permission updates for an existing reference. * * Needs to be followed by a call to either bdrv_set_perm() or * bdrv_abort_perm_update(). */ static int bdrv_check_update_perm(BlockDriverState *bs, uint64_t new_used_= perm, uint64_t new_shared_perm, - BdrvChild *ignore_child, Error **errp) + GSList *ignore_children, Error **errp) { BdrvChild *c; uint64_t cumulative_perms =3D new_used_perm; @@ -1572,7 +1574,7 @@ static int bdrv_check_update_perm(BlockDriverState *b= s, uint64_t new_used_perm, assert(new_shared_perm & BLK_PERM_WRITE_UNCHANGED); =20 QLIST_FOREACH(c, &bs->parents, next_parent) { - if (c =3D=3D ignore_child) { + if (g_slist_find(ignore_children, c)) { continue; } =20 @@ -1602,15 +1604,22 @@ static int bdrv_check_update_perm(BlockDriverState = *bs, uint64_t new_used_perm, cumulative_shared_perms &=3D c->shared_perm; } =20 - return bdrv_check_perm(bs, cumulative_perms, cumulative_shared_perms, = errp); + return bdrv_check_perm(bs, cumulative_perms, cumulative_shared_perms, + ignore_children, errp); } =20 /* Needs to be followed by a call to either bdrv_child_set_perm() or * bdrv_child_abort_perm_update(). */ int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared, - Error **errp) + GSList *ignore_children, Error **errp) { - return bdrv_check_update_perm(c->bs, perm, shared, c, errp); + int ret; + + ignore_children =3D g_slist_prepend(g_slist_copy(ignore_children), c); + ret =3D bdrv_check_update_perm(c->bs, perm, shared, ignore_children, e= rrp); + g_slist_free(ignore_children); + + return ret; } =20 void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared) @@ -1635,7 +1644,7 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t pe= rm, uint64_t shared, { int ret; =20 - ret =3D bdrv_child_check_perm(c, perm, shared, errp); + ret =3D bdrv_child_check_perm(c, perm, shared, NULL, errp); if (ret < 0) { bdrv_child_abort_perm_update(c); return ret; @@ -1753,7 +1762,7 @@ static void bdrv_replace_child(BdrvChild *child, Bloc= kDriverState *new_bs, * because we're just taking a parent away, so we're loosening * restrictions. */ bdrv_get_cumulative_perm(old_bs, &perm, &shared_perm); - bdrv_check_perm(old_bs, perm, shared_perm, &error_abort); + bdrv_check_perm(old_bs, perm, shared_perm, NULL, &error_abort); bdrv_set_perm(old_bs, perm, shared_perm); } =20 @@ -1762,7 +1771,7 @@ static void bdrv_replace_child(BdrvChild *child, Bloc= kDriverState *new_bs, if (new_bs) { bdrv_get_cumulative_perm(new_bs, &perm, &shared_perm); if (check_new_perm) { - bdrv_check_perm(new_bs, perm, shared_perm, &error_abort); + bdrv_check_perm(new_bs, perm, shared_perm, NULL, &error_abort); } bdrv_set_perm(new_bs, perm, shared_perm); } diff --git a/include/block/block_int.h b/include/block/block_int.h index a57c0bf..fc83f7f 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -890,7 +890,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *chi= ld_bs, void bdrv_root_unref_child(BdrvChild *child); =20 int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared, - Error **errp); + GSList *ignore_children, Error **errp); void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared); void bdrv_child_abort_perm_update(BdrvChild *c); int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, --=20 1.8.3.1 From nobody Sun Apr 28 19:36:58 2024 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 1488817570322721.0017186872243; Mon, 6 Mar 2017 08:26:10 -0800 (PST) Received: from localhost ([::1]:44811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvSX-0004kU-NH for importer@patchew.org; Mon, 06 Mar 2017 11:26:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvPI-0002ir-C1 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckvPH-0001G2-DE for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44108) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckvPC-0001Do-QE; Mon, 06 Mar 2017 11:22:38 -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 00D8D6AE0; Mon, 6 Mar 2017 16:22:39 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-180.ams2.redhat.com [10.36.116.180]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26GMJn1031063; Mon, 6 Mar 2017 11:22:37 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 6 Mar 2017 17:22:01 +0100 Message-Id: <1488817322-11397-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1488817322-11397-1-git-send-email-kwolf@redhat.com> References: <1488817322-11397-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.38]); Mon, 06 Mar 2017 16:22:39 +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 09/10] block: Handle permission errors in change_parent_backing_link() 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" Instead of just trying to change parents by parent over to reference @to instead of @from, and abort()ing whenever the permissions don't allow this, do proper permission checking beforehand and pass any error to the callers. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Fam Zheng --- block.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index a7b09d3..a310132 100644 --- a/block.c +++ b/block.c @@ -2933,21 +2933,53 @@ static bool should_update_child(BdrvChild *c, Block= DriverState *to) } =20 static void change_parent_backing_link(BlockDriverState *from, - BlockDriverState *to) + BlockDriverState *to, Error **errp) { BdrvChild *c, *next; + GSList *list =3D NULL, *p; + uint64_t old_perm, old_shared; + uint64_t perm =3D 0, shared =3D BLK_PERM_ALL; + int ret; + + /* Make sure that @from doesn't go away until we have successfully att= ached + * all of its parents to @to. */ + bdrv_ref(from); =20 + /* Put all parents into @list and calculate their cumulative permissio= ns */ QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { if (!should_update_child(c, to)) { continue; } + list =3D g_slist_prepend(list, c); + perm |=3D c->perm; + shared &=3D c->shared_perm; + } + + /* Check whether the required permissions can be granted on @to, ignor= ing + * all BdrvChild in @list so that they can't block themselves. */ + ret =3D bdrv_check_update_perm(to, perm, shared, list, errp); + if (ret < 0) { + bdrv_abort_perm_update(to); + goto out; + } + + /* Now actually perform the change. We performed the permission check = for + * all elements of @list at once, so set the permissions all at once a= t the + * very end. */ + for (p =3D list; p !=3D NULL; p =3D p->next) { + c =3D p->data; =20 bdrv_ref(to); - /* FIXME Are we sure that bdrv_replace_child() can't run into - * &error_abort because of permissions? */ - bdrv_replace_child(c, to, true); + bdrv_replace_child_noperm(c, to); bdrv_unref(from); } + + bdrv_get_cumulative_perm(to, &old_perm, &old_shared); + bdrv_set_perm(to, old_perm | perm, old_shared | shared); + +out: + g_slist_free(list); + bdrv_unref(from); } =20 /* @@ -2980,7 +3012,12 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriv= erState *bs_top, goto out; } =20 - change_parent_backing_link(bs_top, bs_new); + change_parent_backing_link(bs_top, bs_new, &local_err); + if (local_err) { + error_propagate(errp, local_err); + bdrv_set_backing_hd(bs_new, NULL, &error_abort); + goto out; + } =20 /* bs_new is now referenced by its new parents, we don't need the * additional reference any more. */ @@ -2995,7 +3032,8 @@ void bdrv_replace_in_backing_chain(BlockDriverState *= old, BlockDriverState *new) =20 bdrv_ref(old); =20 - change_parent_backing_link(old, new); + /* FIXME Proper error handling */ + change_parent_backing_link(old, new, &error_abort); =20 bdrv_unref(old); } --=20 1.8.3.1 From nobody Sun Apr 28 19:36:58 2024 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 1488817696200150.1495311280238; Mon, 6 Mar 2017 08:28:16 -0800 (PST) Received: from localhost ([::1]:44821 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvUa-0006hV-UI for importer@patchew.org; Mon, 06 Mar 2017 11:28:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckvPK-0002kU-GH for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckvPJ-0001Gk-2m for qemu-devel@nongnu.org; Mon, 06 Mar 2017 11:22:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36228) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckvPE-0001Es-Oz; Mon, 06 Mar 2017 11:22:40 -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 EFC803B71B; Mon, 6 Mar 2017 16:22:40 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-180.ams2.redhat.com [10.36.116.180]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26GMJn2031063; Mon, 6 Mar 2017 11:22:39 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 6 Mar 2017 17:22:02 +0100 Message-Id: <1488817322-11397-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1488817322-11397-1-git-send-email-kwolf@redhat.com> References: <1488817322-11397-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.30]); Mon, 06 Mar 2017 16:22:41 +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 10/10] 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, 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" 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: Eric Blake Reviewed-by: Fam Zheng --- 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