From nobody Tue May 7 13:35:19 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 1488901347202428.2429655373803; Tue, 7 Mar 2017 07:42:27 -0800 (PST) Received: from localhost ([::1]:51243 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHFp-0002FN-Rr for importer@patchew.org; Tue, 07 Mar 2017 10:42:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEX-0001yx-Ef for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEW-0002Tt-5L for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50280) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHES-0002O0-0e; Tue, 07 Mar 2017 10:41:00 -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 20FCF811AC; Tue, 7 Mar 2017 15:41:00 +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 v27FeuUU032123; Tue, 7 Mar 2017 10:40:58 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:25 +0100 Message-Id: <1488901251-16214-2-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> MIME-Version: 1.0 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.27]); Tue, 07 Mar 2017 15:41:00 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 01/27] 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, 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-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 Tue May 7 13:35:19 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 1488901348602672.1502992328965; Tue, 7 Mar 2017 07:42:28 -0800 (PST) Received: from localhost ([::1]:51244 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHFp-0002FR-9b for importer@patchew.org; Tue, 07 Mar 2017 10:42:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEX-0001yq-Dg for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEW-0002To-57 for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48020) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHES-0002O5-Ir; Tue, 07 Mar 2017 10:41:00 -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 AB8487E9DD; Tue, 7 Mar 2017 15:41:00 +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 v27FeuUV032123; Tue, 7 Mar 2017 10:40:59 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:26 +0100 Message-Id: <1488901251-16214-3-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.26]); Tue, 07 Mar 2017 15:41:00 +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 02/27] 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, 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" 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: Fam Zheng Reviewed-by: Eric Blake --- 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 Tue May 7 13:35:19 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 1488901485945956.6814788684527; Tue, 7 Mar 2017 07:44:45 -0800 (PST) Received: from localhost ([::1]:51254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHI2-0004VX-KE for importer@patchew.org; Tue, 07 Mar 2017 10:44:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEX-0001yw-EO for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEW-0002Ti-3o for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50308) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHET-0002PK-LK; Tue, 07 Mar 2017 10:41:01 -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 BD46781138; Tue, 7 Mar 2017 15:41:01 +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 v27FeuUW032123; Tue, 7 Mar 2017 10:41:00 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:27 +0100 Message-Id: <1488901251-16214-4-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.27]); Tue, 07 Mar 2017 15:41:01 +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 03/27] 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, 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" 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: Fam Zheng Reviewed-by: Eric Blake --- 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 Tue May 7 13:35:19 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 1488901345467795.1267764772301; Tue, 7 Mar 2017 07:42:25 -0800 (PST) Received: from localhost ([::1]:51242 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHFl-0002Au-S8 for importer@patchew.org; Tue, 07 Mar 2017 10:42:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEa-000225-BG for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEZ-0002Y4-IZ for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48446) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEX-0002U2-Bm; Tue, 07 Mar 2017 10:41:05 -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 EC7DAC00A170; Tue, 7 Mar 2017 15:41:04 +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 v27FeuUX032123; Tue, 7 Mar 2017 10:41:01 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:28 +0100 Message-Id: <1488901251-16214-5-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.32]); Tue, 07 Mar 2017 15:41:05 +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 04/27] 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, 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" mirror_top_bs must be removed from the graph again when creating the dirty bitmap fails. Signed-off-by: Kevin Wolf Reviewed-by: Fam Zheng Reviewed-by: Eric Blake --- 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 Tue May 7 13:35:19 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 1488901486840867.9358565498586; Tue, 7 Mar 2017 07:44:46 -0800 (PST) Received: from localhost ([::1]:51255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHI3-0004Ve-Ft for importer@patchew.org; Tue, 07 Mar 2017 10:44:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEa-000227-Bm for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEZ-0002Xl-H1 for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEX-0002U4-0l; Tue, 07 Mar 2017 10:41:05 -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 261DA64DA8; Tue, 7 Mar 2017 15:41:05 +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 v27FeuUY032123; Tue, 7 Mar 2017 10:41:04 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:29 +0100 Message-Id: <1488901251-16214-6-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.38]); Tue, 07 Mar 2017 15:41:05 +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 05/27] 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, 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" 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: Fam Zheng Reviewed-by: Eric Blake --- 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 Tue May 7 13:35:19 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 1488901641072372.1776017215127; Tue, 7 Mar 2017 07:47:21 -0800 (PST) Received: from localhost ([::1]:51279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHKY-0006ww-KU for importer@patchew.org; Tue, 07 Mar 2017 10:47:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42482) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEg-00029D-L0 for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEf-0002gV-HD for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37360) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEa-0002Xq-4J; Tue, 07 Mar 2017 10:41:08 -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 38EE61555E; Tue, 7 Mar 2017 15:41:07 +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 v27FeuUZ032123; Tue, 7 Mar 2017 10:41:05 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:30 +0100 Message-Id: <1488901251-16214-7-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> MIME-Version: 1.0 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.29]); Tue, 07 Mar 2017 15:41:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 06/27] 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, 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-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf Reviewed-by: Fam Zheng Reviewed-by: Eric Blake 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 Tue May 7 13:35:19 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 148890137577980.12729633523577; Tue, 7 Mar 2017 07:42:55 -0800 (PST) Received: from localhost ([::1]:51247 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHGH-0002p2-EH for importer@patchew.org; Tue, 07 Mar 2017 10:42:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEf-00028K-Vy for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEf-0002g5-6W for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16045) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEZ-0002X3-Ov; Tue, 07 Mar 2017 10:41:07 -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 E39FF4DD62; Tue, 7 Mar 2017 15:41:07 +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 v27FeuUa032123; Tue, 7 Mar 2017 10:41:06 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:31 +0100 Message-Id: <1488901251-16214-8-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.38]); Tue, 07 Mar 2017 15:41:07 +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 07/27] 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, 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" Signed-off-by: Kevin Wolf Reviewed-by: Fam Zheng Reviewed-by: Eric Blake --- 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 Tue May 7 13:35:19 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 1488901637346169.49343872508337; Tue, 7 Mar 2017 07:47:17 -0800 (PST) Received: from localhost ([::1]:51278 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHKT-0006rh-Oa for importer@patchew.org; Tue, 07 Mar 2017 10:47:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEg-00029M-Rv for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEf-0002go-Li for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53946) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEc-0002cl-6q; Tue, 07 Mar 2017 10:41:10 -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 40722624D7; Tue, 7 Mar 2017 15:41:10 +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 v27FeuUb032123; Tue, 7 Mar 2017 10:41:07 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:32 +0100 Message-Id: <1488901251-16214-9-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.39]); Tue, 07 Mar 2017 15:41:10 +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 08/27] 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, 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" 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: Fam Zheng Reviewed-by: Eric Blake --- 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 Tue May 7 13:35:19 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 1488901794013595.712691554871; Tue, 7 Mar 2017 07:49:54 -0800 (PST) Received: from localhost ([::1]:51289 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHN2-0000gH-LH for importer@patchew.org; Tue, 07 Mar 2017 10:49:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEm-0002Fp-Ba for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEh-0002kk-FH for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35362) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEe-0002fF-M4; Tue, 07 Mar 2017 10:41:12 -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 BEC7D81247; Tue, 7 Mar 2017 15:41:12 +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 v27FeuUc032123; Tue, 7 Mar 2017 10:41:10 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:33 +0100 Message-Id: <1488901251-16214-10-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.25]); Tue, 07 Mar 2017 15:41:12 +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 09/27] 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, 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" 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: Fam Zheng Reviewed-by: Eric Blake --- 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 Tue May 7 13:35:19 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 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 From nobody Tue May 7 13:35:19 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 1488901816298975.0262163275024; Tue, 7 Mar 2017 07:50:16 -0800 (PST) Received: from localhost ([::1]:51294 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHNN-0000ur-1c for importer@patchew.org; Tue, 07 Mar 2017 10:50:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEn-0002HR-Rk for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEk-0002lt-2I for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35404) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEh-0002jN-FS; Tue, 07 Mar 2017 10:41:15 -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 95AD081245; Tue, 7 Mar 2017 15:41:15 +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 v27FeuUe032123; Tue, 7 Mar 2017 10:41:13 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:35 +0100 Message-Id: <1488901251-16214-12-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.25]); Tue, 07 Mar 2017 15:41:15 +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 11/27] sheepdog: Defuse time bomb in sd_open() 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, 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" From: Markus Armbruster When qemu_opts_absorb_qdict() fails, sd_open() closes stdin, because sd->fd is still zero. Fortunately, qemu_opts_absorb_qdict() can't fail, because: 1. it only fails when qemu_opt_parse() fails, and 2. the only member of runtime_opts.desc[] is a QEMU_OPT_STRING, and 3. qemu_opt_parse() can't fail for QEMU_OPT_STRING. Defuse this ticking time bomb by jumping behind the file descriptor cleanup on error. Also do that for the error paths where sd->fd is still -1. The file descriptor cleanup happens to do nothing then, but let's not rely on that here. While there, rename label out to err, because it's on the error path, not the normal path out of the function. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/sheepdog.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 7434710..c3ee4ce 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1392,7 +1392,7 @@ static int sd_open(BlockDriverState *bs, QDict *optio= ns, int flags, if (local_err) { error_propagate(errp, local_err); ret =3D -EINVAL; - goto out; + goto err_no_fd; } =20 filename =3D qemu_opt_get(opts, "filename"); @@ -1412,17 +1412,17 @@ static int sd_open(BlockDriverState *bs, QDict *opt= ions, int flags, } if (ret < 0) { error_setg(errp, "Can't parse filename"); - goto out; + goto err_no_fd; } s->fd =3D get_sheep_fd(s, errp); if (s->fd < 0) { ret =3D s->fd; - goto out; + goto err_no_fd; } =20 ret =3D find_vdi_name(s, vdi, snapid, tag, &vid, true, errp); if (ret) { - goto out; + goto err; } =20 /* @@ -1443,7 +1443,7 @@ static int sd_open(BlockDriverState *bs, QDict *optio= ns, int flags, fd =3D connect_to_sdog(s, errp); if (fd < 0) { ret =3D fd; - goto out; + goto err; } =20 buf =3D g_malloc(SD_INODE_SIZE); @@ -1454,7 +1454,7 @@ static int sd_open(BlockDriverState *bs, QDict *optio= ns, int flags, =20 if (ret) { error_setg(errp, "Can't read snapshot inode"); - goto out; + goto err; } =20 memcpy(&s->inode, buf, sizeof(s->inode)); @@ -1466,12 +1466,12 @@ static int sd_open(BlockDriverState *bs, QDict *opt= ions, int flags, qemu_opts_del(opts); g_free(buf); return 0; -out: + +err: aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd, false, NULL, NULL, NULL, NULL); - if (s->fd >=3D 0) { - closesocket(s->fd); - } + closesocket(s->fd); +err_no_fd: qemu_opts_del(opts); g_free(buf); return ret; --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488901977579279.2853357380377; Tue, 7 Mar 2017 07:52:57 -0800 (PST) Received: from localhost ([::1]:51312 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHPw-00037b-71 for importer@patchew.org; Tue, 07 Mar 2017 10:52:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEq-0002K8-Bp for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEp-0002o6-7Z for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29311) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEl-0002mF-PZ; Tue, 07 Mar 2017 10:41:19 -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 DE76180F7C; Tue, 7 Mar 2017 15:41:19 +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 v27FeuUf032123; Tue, 7 Mar 2017 10:41:14 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:36 +0100 Message-Id: <1488901251-16214-13-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.27]); Tue, 07 Mar 2017 15:41:19 +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 12/27] sheepdog: Fix error handling in sd_snapshot_delete() 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" From: Markus Armbruster As a bdrv_snapshot_delete() method, sd_snapshot_delete() must set an error and return negative errno on failure. It sometimes returns -1, and sometimes neglects to set an error. It also prints error messages with error_report(). Fix all that. Moreover, its handling of an attempt to delete a nonexistent snapshot is wrong: it error_report()s and succeeds. Fix it to set an error and return -ENOENT instead. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/sheepdog.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index c3ee4ce..0a0803e 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2405,18 +2405,15 @@ out: =20 #define NR_BATCHED_DISCARD 128 =20 -static bool remove_objects(BDRVSheepdogState *s) +static int remove_objects(BDRVSheepdogState *s, Error **errp) { int fd, i =3D 0, nr_objs =3D 0; - Error *local_err =3D NULL; - int ret =3D 0; - bool result =3D true; + int ret; SheepdogInode *inode =3D &s->inode; =20 - fd =3D connect_to_sdog(s, &local_err); + fd =3D connect_to_sdog(s, errp); if (fd < 0) { - error_report_err(local_err); - return false; + return fd; } =20 nr_objs =3D count_data_objs(inode); @@ -2446,15 +2443,15 @@ static bool remove_objects(BDRVSheepdogState *s) data_vdi_id[start_idx]), false, s->cache_flags); if (ret < 0) { - error_report("failed to discard snapshot inode."); - result =3D false; + error_setg(errp, "Failed to discard snapshot inode"); goto out; } } =20 + ret =3D 0; out: closesocket(fd); - return result; + return ret; } =20 static int sd_snapshot_delete(BlockDriverState *bs, @@ -2464,7 +2461,6 @@ static int sd_snapshot_delete(BlockDriverState *bs, { unsigned long snap_id =3D 0; char snap_tag[SD_MAX_VDI_TAG_LEN]; - Error *local_err =3D NULL; int fd, ret; char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN]; BDRVSheepdogState *s =3D bs->opaque; @@ -2477,8 +2473,9 @@ static int sd_snapshot_delete(BlockDriverState *bs, }; SheepdogVdiRsp *rsp =3D (SheepdogVdiRsp *)&hdr; =20 - if (!remove_objects(s)) { - return -1; + ret =3D remove_objects(s, errp); + if (ret) { + return ret; } =20 memset(buf, 0, sizeof(buf)); @@ -2498,36 +2495,36 @@ static int sd_snapshot_delete(BlockDriverState *bs, pstrcpy(buf + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, snap_tag); } =20 - ret =3D find_vdi_name(s, s->name, snap_id, snap_tag, &vid, true, - &local_err); + ret =3D find_vdi_name(s, s->name, snap_id, snap_tag, &vid, true, errp); if (ret) { return ret; } =20 - fd =3D connect_to_sdog(s, &local_err); + fd =3D connect_to_sdog(s, errp); if (fd < 0) { - error_report_err(local_err); - return -1; + return fd; } =20 ret =3D do_req(fd, s->bs, (SheepdogReq *)&hdr, buf, &wlen, &rlen); closesocket(fd); if (ret) { + error_setg_errno(errp, -ret, "Couldn't send request to server"); return ret; } =20 switch (rsp->result) { case SD_RES_NO_VDI: - error_report("%s was already deleted", s->name); + error_setg(errp, "Can't find the snapshot"); + return -ENOENT; case SD_RES_SUCCESS: break; default: - error_report("%s, %s", sd_strerror(rsp->result), s->name); - return -1; + error_setg(errp, "%s", sd_strerror(rsp->result)); + return -EIO; } =20 - return ret; + return 0; } =20 static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_t= ab) --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488901520705501.3059920061671; Tue, 7 Mar 2017 07:45:20 -0800 (PST) Received: from localhost ([::1]:51259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHIc-000556-EV for importer@patchew.org; Tue, 07 Mar 2017 10:45:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEq-0002Jk-0t for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEp-0002o0-4e for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57824) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEl-0002mD-O9; Tue, 07 Mar 2017 10:41:19 -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 C7157C04B93D; Tue, 7 Mar 2017 15:41:19 +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 v27FeuUg032123; Tue, 7 Mar 2017 10:41:16 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:37 +0100 Message-Id: <1488901251-16214-14-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> MIME-Version: 1.0 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.31]); Tue, 07 Mar 2017 15:41:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 13/27] sheepdog: Fix error handling sd_create() 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-Type: text/plain; charset="utf-8" From: Markus Armbruster As a bdrv_create() method, sd_create() must set an error and return negative errno on failure. It prints the error instead of setting it when connect_to_sdog() fails. Fix that. While there, return the value of connect_to_sdog() like we do elsewhere, instead of -EIO. No functional change, as connect_to_sdog() returns no other error code. Many more suspicious uses of error_report() and error_report_err() remain in other functions. Left for another day. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/sheepdog.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 0a0803e..be3db1f 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1829,14 +1829,12 @@ static int sd_create(const char *filename, QemuOpts= *opts, if (s->inode.block_size_shift =3D=3D 0) { SheepdogVdiReq hdr; SheepdogClusterRsp *rsp =3D (SheepdogClusterRsp *)&hdr; - Error *local_err =3D NULL; int fd; unsigned int wlen =3D 0, rlen =3D 0; =20 - fd =3D connect_to_sdog(s, &local_err); + fd =3D connect_to_sdog(s, errp); if (fd < 0) { - error_report_err(local_err); - ret =3D -EIO; + ret =3D fd; goto out; } =20 --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488901651782510.66030509079894; Tue, 7 Mar 2017 07:47:31 -0800 (PST) Received: from localhost ([::1]:51281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHKi-00073T-8L for importer@patchew.org; Tue, 07 Mar 2017 10:47:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEp-0002Jf-UU for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEp-0002nv-3W for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35752) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEm-0002md-Nz; Tue, 07 Mar 2017 10:41:20 -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 D45157715; Tue, 7 Mar 2017 15:41:20 +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 v27FeuUh032123; Tue, 7 Mar 2017 10:41:20 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:38 +0100 Message-Id: <1488901251-16214-15-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.38]); Tue, 07 Mar 2017 15:41:20 +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 14/27] sheepdog: Mark sd_snapshot_delete() lossage FIXME 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" From: Markus Armbruster sd_snapshot_delete() should delete the snapshot whose ID matches @snapshot_id and whose name matches @name. But that's not what it does. If @snapshot_id is a valid ID, it deletes the snapshot with that ID, else it deletes the snapshot with that name. It doesn't use @name at all. Add suitable FIXME comments, so someone who actually knows Sheepdog can fix it. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/sheepdog.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/sheepdog.c b/block/sheepdog.c index be3db1f..187bcd8 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2457,6 +2457,10 @@ static int sd_snapshot_delete(BlockDriverState *bs, const char *name, Error **errp) { + /* + * FIXME should delete the snapshot matching both @snapshot_id and + * @name, but @name not used here + */ unsigned long snap_id =3D 0; char snap_tag[SD_MAX_VDI_TAG_LEN]; int fd, ret; @@ -2481,6 +2485,11 @@ static int sd_snapshot_delete(BlockDriverState *bs, pstrcpy(buf, SD_MAX_VDI_LEN, s->name); ret =3D qemu_strtoul(snapshot_id, NULL, 10, &snap_id); if (ret || snap_id > UINT32_MAX) { + /* + * FIXME Since qemu_strtoul() returns -EINVAL when + * @snapshot_id is null, @snapshot_id is mandatory. Correct + * would be to require at least one of @snapshot_id and @name. + */ error_setg(errp, "Invalid snapshot ID: %s", snapshot_id ? snapshot_id : ""); return -EINVAL; @@ -2489,6 +2498,7 @@ static int sd_snapshot_delete(BlockDriverState *bs, if (snap_id) { hdr.snapid =3D (uint32_t) snap_id; } else { + /* FIXME I suspect we should use @name here */ pstrcpy(snap_tag, sizeof(snap_tag), snapshot_id); pstrcpy(buf + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, snap_tag); } --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488902118578412.61550344476063; Tue, 7 Mar 2017 07:55:18 -0800 (PST) Received: from localhost ([::1]:51322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHSG-0005Hc-6l for importer@patchew.org; Tue, 07 Mar 2017 10:55:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEs-0002Mq-42 for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEq-0002px-Qz for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57852) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEo-0002nE-2c; Tue, 07 Mar 2017 10:41:22 -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 2B9BCC04B951; Tue, 7 Mar 2017 15:41:22 +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 v27FeuUi032123; Tue, 7 Mar 2017 10:41:21 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:39 +0100 Message-Id: <1488901251-16214-16-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.31]); Tue, 07 Mar 2017 15:41:22 +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 15/27] sheepdog: Fix snapshot ID parsing in _open(), _create, _goto() 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" From: Markus Armbruster sd_parse_uri() and sd_snapshot_goto() screw up error checking after strtoul(), and truncate long tag names silently. Fix by replacing those parts by new sd_parse_snapid_or_tag(), which checks more carefully. sd_snapshot_delete() also parses snapshot IDs, but is currently too broken for me to touch. Mark TODO. Two calls of strtol() without error checking remain in parse_redundancy(). Mark them FIXME. More silent truncation of configuration strings remains elsewhere. Not marked. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/sheepdog.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++------= ---- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 187bcd8..d3d3731 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -914,6 +914,49 @@ static int get_sheep_fd(BDRVSheepdogState *s, Error **= errp) return fd; } =20 +/* + * Parse numeric snapshot ID in @str + * If @str can't be parsed as number, return false. + * Else, if the number is zero or too large, set *@snapid to zero and + * return true. + * Else, set *@snapid to the number and return true. + */ +static bool sd_parse_snapid(const char *str, uint32_t *snapid) +{ + unsigned long ul; + int ret; + + ret =3D qemu_strtoul(str, NULL, 10, &ul); + if (ret =3D=3D -ERANGE) { + ul =3D ret =3D 0; + } + if (ret) { + return false; + } + if (ul > UINT32_MAX) { + ul =3D 0; + } + + *snapid =3D ul; + return true; +} + +static bool sd_parse_snapid_or_tag(const char *str, + uint32_t *snapid, char tag[]) +{ + if (!sd_parse_snapid(str, snapid)) { + *snapid =3D 0; + if (g_strlcpy(tag, str, SD_MAX_VDI_TAG_LEN) >=3D SD_MAX_VDI_TAG_LE= N) { + return false; + } + } else if (!*snapid) { + return false; + } else { + tag[0] =3D 0; + } + return true; +} + static int sd_parse_uri(BDRVSheepdogState *s, const char *filename, char *vdi, uint32_t *snapid, char *tag) { @@ -965,9 +1008,9 @@ static int sd_parse_uri(BDRVSheepdogState *s, const ch= ar *filename, =20 /* snapshot tag */ if (uri->fragment) { - *snapid =3D strtoul(uri->fragment, NULL, 10); - if (*snapid =3D=3D 0) { - pstrcpy(tag, SD_MAX_VDI_TAG_LEN, uri->fragment); + if (!sd_parse_snapid_or_tag(uri->fragment, snapid, tag)) { + ret =3D -EINVAL; + goto out; } } else { *snapid =3D CURRENT_VDI_ID; /* search current vdi */ @@ -1685,6 +1728,7 @@ static int parse_redundancy(BDRVSheepdogState *s, con= st char *opt) } =20 copy =3D strtol(n1, NULL, 10); + /* FIXME fix error checking by switching to qemu_strtol() */ if (copy > SD_MAX_COPIES || copy < 1) { return -EINVAL; } @@ -1699,6 +1743,7 @@ static int parse_redundancy(BDRVSheepdogState *s, con= st char *opt) } =20 parity =3D strtol(n2, NULL, 10); + /* FIXME fix error checking by switching to qemu_strtol() */ if (parity >=3D SD_EC_MAX_STRIP || parity < 1) { return -EINVAL; } @@ -2365,19 +2410,16 @@ static int sd_snapshot_goto(BlockDriverState *bs, c= onst char *snapshot_id) BDRVSheepdogState *old_s; char tag[SD_MAX_VDI_TAG_LEN]; uint32_t snapid =3D 0; - int ret =3D 0; + int ret; + + if (!sd_parse_snapid_or_tag(snapshot_id, &snapid, tag)) { + return -EINVAL; + } =20 old_s =3D g_new(BDRVSheepdogState, 1); =20 memcpy(old_s, s, sizeof(BDRVSheepdogState)); =20 - snapid =3D strtoul(snapshot_id, NULL, 10); - if (snapid) { - tag[0] =3D 0; - } else { - pstrcpy(tag, sizeof(tag), snapshot_id); - } - ret =3D reload_inode(s, snapid, tag); if (ret) { goto out; @@ -2483,6 +2525,7 @@ static int sd_snapshot_delete(BlockDriverState *bs, memset(buf, 0, sizeof(buf)); memset(snap_tag, 0, sizeof(snap_tag)); pstrcpy(buf, SD_MAX_VDI_LEN, s->name); + /* TODO Use sd_parse_snapid() once this mess is cleaned up */ ret =3D qemu_strtoul(snapshot_id, NULL, 10, &snap_id); if (ret || snap_id > UINT32_MAX) { /* @@ -2499,6 +2542,7 @@ static int sd_snapshot_delete(BlockDriverState *bs, hdr.snapid =3D (uint32_t) snap_id; } else { /* FIXME I suspect we should use @name here */ + /* FIXME don't truncate silently */ pstrcpy(snap_tag, sizeof(snap_tag), snapshot_id); pstrcpy(buf + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, snap_tag); } --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 14889021092271023.3028010180041; Tue, 7 Mar 2017 07:55:09 -0800 (PST) Received: from localhost ([::1]:51321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHS5-00059G-0S for importer@patchew.org; Tue, 07 Mar 2017 10:55:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHEx-0002S2-KE for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEr-0002qH-Uy for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36016) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEp-0002oA-So; Tue, 07 Mar 2017 10:41:23 -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 F129020265; Tue, 7 Mar 2017 15:41:22 +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 v27FeuUj032123; Tue, 7 Mar 2017 10:41:22 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:40 +0100 Message-Id: <1488901251-16214-17-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> MIME-Version: 1.0 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.29]); Tue, 07 Mar 2017 15:41:24 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 16/27] sheepdog: Don't truncate long VDI name in _open(), _create() 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-Type: text/plain; charset="utf-8" From: Markus Armbruster sd_parse_uri() truncates long VDI names silently. Reject them instead. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Kevin Wolf --- block/sheepdog.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index d3d3731..fed7264 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -985,7 +985,10 @@ static int sd_parse_uri(BDRVSheepdogState *s, const ch= ar *filename, ret =3D -EINVAL; goto out; } - pstrcpy(vdi, SD_MAX_VDI_LEN, uri->path + 1); + if (g_strlcpy(vdi, uri->path + 1, SD_MAX_VDI_LEN) >=3D SD_MAX_VDI_LEN)= { + ret =3D -EINVAL; + goto out; + } =20 qp =3D query_params_parse(uri->query); if (qp->n > 1 || (s->is_unix && !qp->n) || (!s->is_unix && qp->n)) { --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488901834373719.201667075994; Tue, 7 Mar 2017 07:50:34 -0800 (PST) Received: from localhost ([::1]:51295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHNg-0001C5-OL for importer@patchew.org; Tue, 07 Mar 2017 10:50:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHF0-0002Vf-Vs for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEz-0002u2-Ea for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35802) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEt-0002qa-Cj; Tue, 07 Mar 2017 10:41:27 -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 49A4E4E4D2; Tue, 7 Mar 2017 15:41:26 +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 v27FeuUk032123; Tue, 7 Mar 2017 10:41:23 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:41 +0100 Message-Id: <1488901251-16214-18-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> MIME-Version: 1.0 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.38]); Tue, 07 Mar 2017 15:41:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 17/27] sheepdog: Report errors in pseudo-filename more usefully 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-Type: text/plain; charset="utf-8" From: Markus Armbruster Errors in the pseudo-filename are all reported with the same laconic "Can't parse filename" message. Add real error reporting, such as: $ qemu-system-x86_64 --drive driver=3Dsheepdog,filename=3Dsheepdog:/// qemu-system-x86_64: --drive driver=3Dsheepdog,filename=3Dsheepdog:///: = missing file path in URI $ qemu-system-x86_64 --drive driver=3Dsheepdog,filename=3Dsheepgod:///v= di qemu-system-x86_64: --drive driver=3Dsheepdog,filename=3Dsheepgod:///vd= i: URI scheme must be 'sheepdog', 'sheepdog+tcp', or 'sheepdog+unix' $ qemu-system-x86_64 --drive driver=3Dsheepdog,filename=3Dsheepdog+unix= :///vdi?socke=3Dsheepdog.sock qemu-system-x86_64: --drive driver=3Dsheepdog,filename=3Dsheepdog+unix:= ///vdi?socke=3Dsheepdog.sock: unexpected query parameters The code to translate legacy syntax to URI fails to escape URI meta-characters. The new error messages are misleading then. Replace them by the old "Can't parse filename" message. "Internal error" would be more honest. Anyway, no worse than before. Also add a FIXME comment. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/sheepdog.c | 88 +++++++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 59 insertions(+), 29 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index fed7264..161932d 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -957,16 +957,18 @@ static bool sd_parse_snapid_or_tag(const char *str, return true; } =20 -static int sd_parse_uri(BDRVSheepdogState *s, const char *filename, - char *vdi, uint32_t *snapid, char *tag) +static void sd_parse_uri(BDRVSheepdogState *s, const char *filename, + char *vdi, uint32_t *snapid, char *tag, + Error **errp) { + Error *err =3D NULL; URI *uri; QueryParams *qp =3D NULL; - int ret =3D 0; =20 uri =3D uri_parse(filename); if (!uri) { - return -EINVAL; + error_setg(&err, "invalid URI"); + goto out; } =20 /* transport */ @@ -977,34 +979,46 @@ static int sd_parse_uri(BDRVSheepdogState *s, const c= har *filename, } else if (!strcmp(uri->scheme, "sheepdog+unix")) { s->is_unix =3D true; } else { - ret =3D -EINVAL; + error_setg(&err, "URI scheme must be 'sheepdog', 'sheepdog+tcp'," + " or 'sheepdog+unix'"); goto out; } =20 if (uri->path =3D=3D NULL || !strcmp(uri->path, "/")) { - ret =3D -EINVAL; + error_setg(&err, "missing file path in URI"); goto out; } if (g_strlcpy(vdi, uri->path + 1, SD_MAX_VDI_LEN) >=3D SD_MAX_VDI_LEN)= { - ret =3D -EINVAL; + error_setg(&err, "VDI name is too long"); goto out; } =20 qp =3D query_params_parse(uri->query); - if (qp->n > 1 || (s->is_unix && !qp->n) || (!s->is_unix && qp->n)) { - ret =3D -EINVAL; - goto out; - } =20 if (s->is_unix) { /* sheepdog+unix:///vdiname?socket=3Dpath */ - if (uri->server || uri->port || strcmp(qp->p[0].name, "socket")) { - ret =3D -EINVAL; + if (uri->server || uri->port) { + error_setg(&err, "URI scheme %s doesn't accept a server addres= s", + uri->scheme); + goto out; + } + if (!qp->n) { + error_setg(&err, + "URI scheme %s requires query parameter 'socket'", + uri->scheme); + goto out; + } + if (qp->n !=3D 1 || strcmp(qp->p[0].name, "socket")) { + error_setg(&err, "unexpected query parameters"); goto out; } s->host_spec =3D g_strdup(qp->p[0].value); } else { /* sheepdog[+tcp]://[host:port]/vdiname */ + if (qp->n) { + error_setg(&err, "unexpected query parameters"); + goto out; + } s->host_spec =3D g_strdup_printf("%s:%d", uri->server ?: SD_DEFAUL= T_ADDR, uri->port ?: SD_DEFAULT_PORT); } @@ -1012,7 +1026,8 @@ static int sd_parse_uri(BDRVSheepdogState *s, const c= har *filename, /* snapshot tag */ if (uri->fragment) { if (!sd_parse_snapid_or_tag(uri->fragment, snapid, tag)) { - ret =3D -EINVAL; + error_setg(&err, "'%s' is not a valid snapshot ID", + uri->fragment); goto out; } } else { @@ -1020,11 +1035,11 @@ static int sd_parse_uri(BDRVSheepdogState *s, const= char *filename, } =20 out: + error_propagate(errp, err); if (qp) { query_params_free(qp); } uri_free(uri); - return ret; } =20 /* @@ -1044,12 +1059,14 @@ out: * You can run VMs outside the Sheepdog cluster by specifying * `hostname' and `port' (experimental). */ -static int parse_vdiname(BDRVSheepdogState *s, const char *filename, - char *vdi, uint32_t *snapid, char *tag) +static void parse_vdiname(BDRVSheepdogState *s, const char *filename, + char *vdi, uint32_t *snapid, char *tag, + Error **errp) { + Error *err =3D NULL; char *p, *q, *uri; const char *host_spec, *vdi_spec; - int nr_sep, ret; + int nr_sep; =20 strstart(filename, "sheepdog:", &filename); p =3D q =3D g_strdup(filename); @@ -1084,12 +1101,23 @@ static int parse_vdiname(BDRVSheepdogState *s, cons= t char *filename, =20 uri =3D g_strdup_printf("sheepdog://%s/%s", host_spec, vdi_spec); =20 - ret =3D sd_parse_uri(s, uri, vdi, snapid, tag); + /* + * FIXME We to escape URI meta-characters, e.g. "x?y=3Dz" + * produces "sheepdog://x?y=3Dz". Because of that ... + */ + sd_parse_uri(s, uri, vdi, snapid, tag, &err); + if (err) { + /* + * ... this can fail, but the error message is misleading. + * Replace it by the traditional useless one until the + * escaping is fixed. + */ + error_free(err); + error_setg(errp, "Can't parse filename"); + } =20 g_free(q); g_free(uri); - - return ret; } =20 static int find_vdi_name(BDRVSheepdogState *s, const char *filename, @@ -1452,12 +1480,13 @@ static int sd_open(BlockDriverState *bs, QDict *opt= ions, int flags, memset(tag, 0, sizeof(tag)); =20 if (strstr(filename, "://")) { - ret =3D sd_parse_uri(s, filename, vdi, &snapid, tag); + sd_parse_uri(s, filename, vdi, &snapid, tag, &local_err); } else { - ret =3D parse_vdiname(s, filename, vdi, &snapid, tag); + parse_vdiname(s, filename, vdi, &snapid, tag, &local_err); } - if (ret < 0) { - error_setg(errp, "Can't parse filename"); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; goto err_no_fd; } s->fd =3D get_sheep_fd(s, errp); @@ -1785,6 +1814,7 @@ static int parse_block_size_shift(BDRVSheepdogState *= s, QemuOpts *opt) static int sd_create(const char *filename, QemuOpts *opts, Error **errp) { + Error *err =3D NULL; int ret =3D 0; uint32_t vid =3D 0; char *backing_file =3D NULL; @@ -1799,12 +1829,12 @@ static int sd_create(const char *filename, QemuOpts= *opts, =20 memset(tag, 0, sizeof(tag)); if (strstr(filename, "://")) { - ret =3D sd_parse_uri(s, filename, s->name, &snapid, tag); + sd_parse_uri(s, filename, s->name, &snapid, tag, &err); } else { - ret =3D parse_vdiname(s, filename, s->name, &snapid, tag); + parse_vdiname(s, filename, s->name, &snapid, tag, &err); } - if (ret < 0) { - error_setg(errp, "Can't parse filename"); + if (err) { + error_propagate(errp, err); goto out; } =20 --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488901677216298.20661877159523; Tue, 7 Mar 2017 07:47:57 -0800 (PST) Received: from localhost ([::1]:51283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHL6-0007Ot-MC for importer@patchew.org; Tue, 07 Mar 2017 10:47:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHF0-0002VD-J7 for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEz-0002uH-I2 for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36026) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEr-0002q9-To; Tue, 07 Mar 2017 10:41:26 -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 076E520264; Tue, 7 Mar 2017 15:41:26 +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 v27FeuUl032123; Tue, 7 Mar 2017 10:41:25 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:42 +0100 Message-Id: <1488901251-16214-19-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.29]); Tue, 07 Mar 2017 15:41:26 +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 18/27] sheepdog: Use SocketAddress and socket_connect() 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" From: Markus Armbruster sd_parse_uri() builds a string from host and port parts for inet_connect(). inet_connect() parses it into host, port and options. Whether this gets exactly the same host, port and no options for all inputs is not obvious. Cut out the string middleman and build a SocketAddress for socket_connect() instead. Signed-off-by: Markus Armbruster Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/sheepdog.c | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 161932d..9b1e121 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -374,8 +374,7 @@ struct BDRVSheepdogState { uint32_t cache_flags; bool discard_supported; =20 - char *host_spec; - bool is_unix; + SocketAddress *addr; int fd; =20 CoMutex lock; @@ -532,16 +531,12 @@ static int connect_to_sdog(BDRVSheepdogState *s, Erro= r **errp) { int fd; =20 - if (s->is_unix) { - fd =3D unix_connect(s->host_spec, errp); - } else { - fd =3D inet_connect(s->host_spec, errp); + fd =3D socket_connect(s->addr, errp, NULL, NULL); =20 - if (fd >=3D 0) { - int ret =3D socket_set_nodelay(fd); - if (ret < 0) { - error_report("%s", strerror(errno)); - } + if (s->addr->type =3D=3D SOCKET_ADDRESS_KIND_INET && fd >=3D 0) { + int ret =3D socket_set_nodelay(fd); + if (ret < 0) { + error_report("%s", strerror(errno)); } } =20 @@ -820,8 +815,7 @@ static void coroutine_fn aio_read_response(void *opaque) case AIOCB_DISCARD_OBJ: switch (rsp.result) { case SD_RES_INVALID_PARMS: - error_report("sheep(%s) doesn't support discard command", - s->host_spec); + error_report("server doesn't support discard command"); rsp.result =3D SD_RES_SUCCESS; s->discard_supported =3D false; break; @@ -962,8 +956,10 @@ static void sd_parse_uri(BDRVSheepdogState *s, const c= har *filename, Error **errp) { Error *err =3D NULL; - URI *uri; QueryParams *qp =3D NULL; + SocketAddress *addr =3D NULL; + bool is_unix; + URI *uri; =20 uri =3D uri_parse(filename); if (!uri) { @@ -973,11 +969,11 @@ static void sd_parse_uri(BDRVSheepdogState *s, const = char *filename, =20 /* transport */ if (!strcmp(uri->scheme, "sheepdog")) { - s->is_unix =3D false; + is_unix =3D false; } else if (!strcmp(uri->scheme, "sheepdog+tcp")) { - s->is_unix =3D false; + is_unix =3D false; } else if (!strcmp(uri->scheme, "sheepdog+unix")) { - s->is_unix =3D true; + is_unix =3D true; } else { error_setg(&err, "URI scheme must be 'sheepdog', 'sheepdog+tcp'," " or 'sheepdog+unix'"); @@ -994,8 +990,9 @@ static void sd_parse_uri(BDRVSheepdogState *s, const ch= ar *filename, } =20 qp =3D query_params_parse(uri->query); + addr =3D g_new0(SocketAddress, 1); =20 - if (s->is_unix) { + if (is_unix) { /* sheepdog+unix:///vdiname?socket=3Dpath */ if (uri->server || uri->port) { error_setg(&err, "URI scheme %s doesn't accept a server addres= s", @@ -1012,15 +1009,20 @@ static void sd_parse_uri(BDRVSheepdogState *s, cons= t char *filename, error_setg(&err, "unexpected query parameters"); goto out; } - s->host_spec =3D g_strdup(qp->p[0].value); + addr->type =3D SOCKET_ADDRESS_KIND_UNIX; + addr->u.q_unix.data =3D g_new0(UnixSocketAddress, 1); + addr->u.q_unix.data->path =3D g_strdup(qp->p[0].value); } else { /* sheepdog[+tcp]://[host:port]/vdiname */ if (qp->n) { error_setg(&err, "unexpected query parameters"); goto out; } - s->host_spec =3D g_strdup_printf("%s:%d", uri->server ?: SD_DEFAUL= T_ADDR, - uri->port ?: SD_DEFAULT_PORT); + addr->type =3D SOCKET_ADDRESS_KIND_INET; + addr->u.inet.data =3D g_new0(InetSocketAddress, 1); + addr->u.inet.data->host =3D g_strdup(uri->server ?: SD_DEFAULT_ADD= R); + addr->u.inet.data->port =3D g_strdup_printf("%d", + uri->port ?: SD_DEFAULT_PORT); } =20 /* snapshot tag */ @@ -1035,7 +1037,12 @@ static void sd_parse_uri(BDRVSheepdogState *s, const= char *filename, } =20 out: - error_propagate(errp, err); + if (err) { + error_propagate(errp, err); + qapi_free_SocketAddress(addr); + } else { + s->addr =3D addr; + } if (qp) { query_params_free(qp); } @@ -1998,7 +2005,7 @@ static void sd_close(BlockDriverState *bs) aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd, false, NULL, NULL, NULL, NULL); closesocket(s->fd); - g_free(s->host_spec); + qapi_free_SocketAddress(s->addr); } =20 static int64_t sd_getlength(BlockDriverState *bs) --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488901991255638.8074719402821; Tue, 7 Mar 2017 07:53:11 -0800 (PST) Received: from localhost ([::1]:51313 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHQC-0003LJ-LE for importer@patchew.org; Tue, 07 Mar 2017 10:53:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHF1-0002WG-Hv for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHEz-0002uB-GR for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57920) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEt-0002qn-Ug; Tue, 07 Mar 2017 10:41:28 -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 150DAC04B92D; Tue, 7 Mar 2017 15:41:28 +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 v27FeuUm032123; Tue, 7 Mar 2017 10:41:26 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:43 +0100 Message-Id: <1488901251-16214-20-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.31]); Tue, 07 Mar 2017 15:41:28 +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 19/27] sheepdog: Implement bdrv_parse_filename() 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" From: Markus Armbruster This permits configuration with driver-specific options in addition to pseudo-filename parsed as URI. For instance, --drive driver=3Dsheepdog,host=3Dfido,vdi=3Ddolly instead of --drive driver=3Dsheepdog,file=3Dsheepdog://fido/dolly It's also a first step towards supporting blockdev-add. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/sheepdog.c | 230 +++++++++++++++++++++++++++++++++++++++++----------= ---- 1 file changed, 174 insertions(+), 56 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 9b1e121..89e98ed 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -14,6 +14,8 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qint.h" #include "qemu/uri.h" #include "qemu/error-report.h" #include "qemu/sockets.h" @@ -526,6 +528,25 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheep= dogState *s, QLIST_INSERT_HEAD(&s->inflight_aiocb_head, acb, aiocb_siblings); } =20 +static SocketAddress *sd_socket_address(const char *path, + const char *host, const char *port) +{ + SocketAddress *addr =3D g_new0(SocketAddress, 1); + + if (path) { + addr->type =3D SOCKET_ADDRESS_KIND_UNIX; + addr->u.q_unix.data =3D g_new0(UnixSocketAddress, 1); + addr->u.q_unix.data->path =3D g_strdup(path); + } else { + addr->type =3D SOCKET_ADDRESS_KIND_INET; + addr->u.inet.data =3D g_new0(InetSocketAddress, 1); + addr->u.inet.data->host =3D g_strdup(host ?: SD_DEFAULT_ADDR); + addr->u.inet.data->port =3D g_strdup(port ?: stringify(SD_DEFAULT_= PORT)); + } + + return addr; +} + /* Return -EIO in case of error, file descriptor on success */ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) { @@ -951,17 +972,37 @@ static bool sd_parse_snapid_or_tag(const char *str, return true; } =20 -static void sd_parse_uri(BDRVSheepdogState *s, const char *filename, - char *vdi, uint32_t *snapid, char *tag, +typedef struct { + const char *path; /* non-null iff transport is tcp */ + const char *host; /* valid when transport is tcp */ + int port; /* valid when transport is tcp */ + char vdi[SD_MAX_VDI_LEN]; + char tag[SD_MAX_VDI_TAG_LEN]; + uint32_t snap_id; + /* Remainder is only for sd_config_done() */ + URI *uri; + QueryParams *qp; +} SheepdogConfig; + +static void sd_config_done(SheepdogConfig *cfg) +{ + if (cfg->qp) { + query_params_free(cfg->qp); + } + uri_free(cfg->uri); +} + +static void sd_parse_uri(SheepdogConfig *cfg, const char *filename, Error **errp) { Error *err =3D NULL; QueryParams *qp =3D NULL; - SocketAddress *addr =3D NULL; bool is_unix; URI *uri; =20 - uri =3D uri_parse(filename); + memset(cfg, 0, sizeof(*cfg)); + + cfg->uri =3D uri =3D uri_parse(filename); if (!uri) { error_setg(&err, "invalid URI"); goto out; @@ -984,13 +1025,13 @@ static void sd_parse_uri(BDRVSheepdogState *s, const= char *filename, error_setg(&err, "missing file path in URI"); goto out; } - if (g_strlcpy(vdi, uri->path + 1, SD_MAX_VDI_LEN) >=3D SD_MAX_VDI_LEN)= { + if (g_strlcpy(cfg->vdi, uri->path + 1, SD_MAX_VDI_LEN) + >=3D SD_MAX_VDI_LEN) { error_setg(&err, "VDI name is too long"); goto out; } =20 - qp =3D query_params_parse(uri->query); - addr =3D g_new0(SocketAddress, 1); + cfg->qp =3D qp =3D query_params_parse(uri->query); =20 if (is_unix) { /* sheepdog+unix:///vdiname?socket=3Dpath */ @@ -1009,44 +1050,34 @@ static void sd_parse_uri(BDRVSheepdogState *s, cons= t char *filename, error_setg(&err, "unexpected query parameters"); goto out; } - addr->type =3D SOCKET_ADDRESS_KIND_UNIX; - addr->u.q_unix.data =3D g_new0(UnixSocketAddress, 1); - addr->u.q_unix.data->path =3D g_strdup(qp->p[0].value); + cfg->path =3D qp->p[0].value; } else { /* sheepdog[+tcp]://[host:port]/vdiname */ if (qp->n) { error_setg(&err, "unexpected query parameters"); goto out; } - addr->type =3D SOCKET_ADDRESS_KIND_INET; - addr->u.inet.data =3D g_new0(InetSocketAddress, 1); - addr->u.inet.data->host =3D g_strdup(uri->server ?: SD_DEFAULT_ADD= R); - addr->u.inet.data->port =3D g_strdup_printf("%d", - uri->port ?: SD_DEFAULT_PORT); + cfg->host =3D uri->server; + cfg->port =3D uri->port; } =20 /* snapshot tag */ if (uri->fragment) { - if (!sd_parse_snapid_or_tag(uri->fragment, snapid, tag)) { + if (!sd_parse_snapid_or_tag(uri->fragment, + &cfg->snap_id, cfg->tag)) { error_setg(&err, "'%s' is not a valid snapshot ID", uri->fragment); goto out; } } else { - *snapid =3D CURRENT_VDI_ID; /* search current vdi */ + cfg->snap_id =3D CURRENT_VDI_ID; /* search current vdi */ } =20 out: if (err) { error_propagate(errp, err); - qapi_free_SocketAddress(addr); - } else { - s->addr =3D addr; - } - if (qp) { - query_params_free(qp); + sd_config_done(cfg); } - uri_free(uri); } =20 /* @@ -1066,8 +1097,7 @@ out: * You can run VMs outside the Sheepdog cluster by specifying * `hostname' and `port' (experimental). */ -static void parse_vdiname(BDRVSheepdogState *s, const char *filename, - char *vdi, uint32_t *snapid, char *tag, +static void parse_vdiname(SheepdogConfig *cfg, const char *filename, Error **errp) { Error *err =3D NULL; @@ -1112,7 +1142,7 @@ static void parse_vdiname(BDRVSheepdogState *s, const= char *filename, * FIXME We to escape URI meta-characters, e.g. "x?y=3Dz" * produces "sheepdog://x?y=3Dz". Because of that ... */ - sd_parse_uri(s, uri, vdi, snapid, tag, &err); + sd_parse_uri(cfg, uri, &err); if (err) { /* * ... this can fail, but the error message is misleading. @@ -1127,6 +1157,43 @@ static void parse_vdiname(BDRVSheepdogState *s, cons= t char *filename, g_free(uri); } =20 +static void sd_parse_filename(const char *filename, QDict *options, + Error **errp) +{ + Error *err =3D NULL; + SheepdogConfig cfg; + char buf[32]; + + if (strstr(filename, "://")) { + sd_parse_uri(&cfg, filename, &err); + } else { + parse_vdiname(&cfg, filename, &err); + } + if (err) { + error_propagate(errp, err); + return; + } + + if (cfg.host) { + qdict_set_default_str(options, "host", cfg.host); + } + if (cfg.port) { + snprintf(buf, sizeof(buf), "%d", cfg.port); + qdict_set_default_str(options, "port", buf); + } + if (cfg.path) { + qdict_set_default_str(options, "path", cfg.path); + } + qdict_set_default_str(options, "vdi", cfg.vdi); + qdict_set_default_str(options, "tag", cfg.tag); + if (cfg.snap_id) { + snprintf(buf, sizeof(buf), "%d", cfg.snap_id); + qdict_set_default_str(options, "snap-id", buf); + } + + sd_config_done(&cfg); +} + static int find_vdi_name(BDRVSheepdogState *s, const char *filename, uint32_t snapid, const char *tag, uint32_t *vid, bool lock, Error **errp) @@ -1438,15 +1505,33 @@ static void sd_attach_aio_context(BlockDriverState = *bs, co_read_response, NULL, NULL, s); } =20 -/* TODO Convert to fine grained options */ static QemuOptsList runtime_opts =3D { .name =3D "sheepdog", .head =3D QTAILQ_HEAD_INITIALIZER(runtime_opts.head), .desc =3D { { - .name =3D "filename", + .name =3D "host", + .type =3D QEMU_OPT_STRING, + }, + { + .name =3D "port", + .type =3D QEMU_OPT_STRING, + }, + { + .name =3D "path", + .type =3D QEMU_OPT_STRING, + }, + { + .name =3D "vdi", + .type =3D QEMU_OPT_STRING, + }, + { + .name =3D "snap-id", + .type =3D QEMU_OPT_NUMBER, + }, + { + .name =3D "tag", .type =3D QEMU_OPT_STRING, - .help =3D "URL to the sheepdog image", }, { /* end of list */ } }, @@ -1458,12 +1543,11 @@ static int sd_open(BlockDriverState *bs, QDict *opt= ions, int flags, int ret, fd; uint32_t vid =3D 0; BDRVSheepdogState *s =3D bs->opaque; - char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN]; - uint32_t snapid; + const char *host, *port, *path, *vdi, *snap_id_str, *tag; + uint64_t snap_id; char *buf =3D NULL; QemuOpts *opts; Error *local_err =3D NULL; - const char *filename; =20 s->bs =3D bs; s->aio_context =3D bdrv_get_aio_context(bs); @@ -1476,33 +1560,63 @@ static int sd_open(BlockDriverState *bs, QDict *opt= ions, int flags, goto err_no_fd; } =20 - filename =3D qemu_opt_get(opts, "filename"); + host =3D qemu_opt_get(opts, "host"); + port =3D qemu_opt_get(opts, "port"); + path =3D qemu_opt_get(opts, "path"); + vdi =3D qemu_opt_get(opts, "vdi"); + snap_id_str =3D qemu_opt_get(opts, "snap-id"); + snap_id =3D qemu_opt_get_number(opts, "snap-id", CURRENT_VDI_ID); + tag =3D qemu_opt_get(opts, "tag"); =20 - QLIST_INIT(&s->inflight_aio_head); - QLIST_INIT(&s->failed_aio_head); - QLIST_INIT(&s->inflight_aiocb_head); - s->fd =3D -1; + if ((host || port) && path) { + error_setg(errp, "can't use 'path' together with 'host' or 'port'"= ); + ret =3D -EINVAL; + goto err_no_fd; + } + + if (!vdi) { + error_setg(errp, "parameter 'vdi' is missing"); + ret =3D -EINVAL; + goto err_no_fd; + } + if (strlen(vdi) >=3D SD_MAX_VDI_LEN) { + error_setg(errp, "value of parameter 'vdi' is too long"); + ret =3D -EINVAL; + goto err_no_fd; + } =20 - memset(vdi, 0, sizeof(vdi)); - memset(tag, 0, sizeof(tag)); + if (snap_id > UINT32_MAX) { + snap_id =3D 0; + } + if (snap_id_str && !snap_id) { + error_setg(errp, "'snap-id=3D%s' is not a valid snapshot ID", + snap_id_str); + ret =3D -EINVAL; + goto err_no_fd; + } =20 - if (strstr(filename, "://")) { - sd_parse_uri(s, filename, vdi, &snapid, tag, &local_err); - } else { - parse_vdiname(s, filename, vdi, &snapid, tag, &local_err); + if (!tag) { + tag =3D ""; } - if (local_err) { - error_propagate(errp, local_err); + if (tag && strlen(tag) >=3D SD_MAX_VDI_TAG_LEN) { + error_setg(errp, "value of parameter 'tag' is too long"); ret =3D -EINVAL; goto err_no_fd; } + + s->addr =3D sd_socket_address(path, host, port); + + QLIST_INIT(&s->inflight_aio_head); + QLIST_INIT(&s->failed_aio_head); + QLIST_INIT(&s->inflight_aiocb_head); + s->fd =3D get_sheep_fd(s, errp); if (s->fd < 0) { ret =3D s->fd; goto err_no_fd; } =20 - ret =3D find_vdi_name(s, vdi, snapid, tag, &vid, true, errp); + ret =3D find_vdi_name(s, vdi, (uint32_t)snap_id, tag, &vid, true, errp= ); if (ret) { goto err; } @@ -1517,7 +1631,7 @@ static int sd_open(BlockDriverState *bs, QDict *optio= ns, int flags, } s->discard_supported =3D true; =20 - if (snapid || tag[0] !=3D '\0') { + if (snap_id || tag[0]) { DPRINTF("%" PRIx32 " snapshot inode was open.\n", vid); s->is_snapshot =3D true; } @@ -1827,24 +1941,28 @@ static int sd_create(const char *filename, QemuOpts= *opts, char *backing_file =3D NULL; char *buf =3D NULL; BDRVSheepdogState *s; - char tag[SD_MAX_VDI_TAG_LEN]; - uint32_t snapid; + SheepdogConfig cfg; uint64_t max_vdi_size; bool prealloc =3D false; =20 s =3D g_new0(BDRVSheepdogState, 1); =20 - memset(tag, 0, sizeof(tag)); if (strstr(filename, "://")) { - sd_parse_uri(s, filename, s->name, &snapid, tag, &err); + sd_parse_uri(&cfg, filename, &err); } else { - parse_vdiname(s, filename, s->name, &snapid, tag, &err); + parse_vdiname(&cfg, filename, &err); } if (err) { error_propagate(errp, err); goto out; } =20 + buf =3D cfg.port ? g_strdup_printf("%d", cfg.port) : NULL; + s->addr =3D sd_socket_address(cfg.path, cfg.host, buf); + g_free(buf); + strcpy(s->name, cfg.vdi); + sd_config_done(&cfg); + s->inode.vdi_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_S= IZE, 0), BDRV_SECTOR_SIZE); backing_file =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); @@ -2921,7 +3039,7 @@ static BlockDriver bdrv_sheepdog =3D { .format_name =3D "sheepdog", .protocol_name =3D "sheepdog", .instance_size =3D sizeof(BDRVSheepdogState), - .bdrv_needs_filename =3D true, + .bdrv_parse_filename =3D sd_parse_filename, .bdrv_file_open =3D sd_open, .bdrv_reopen_prepare =3D sd_reopen_prepare, .bdrv_reopen_commit =3D sd_reopen_commit, @@ -2957,7 +3075,7 @@ static BlockDriver bdrv_sheepdog_tcp =3D { .format_name =3D "sheepdog", .protocol_name =3D "sheepdog+tcp", .instance_size =3D sizeof(BDRVSheepdogState), - .bdrv_needs_filename =3D true, + .bdrv_parse_filename =3D sd_parse_filename, .bdrv_file_open =3D sd_open, .bdrv_reopen_prepare =3D sd_reopen_prepare, .bdrv_reopen_commit =3D sd_reopen_commit, @@ -2993,7 +3111,7 @@ static BlockDriver bdrv_sheepdog_unix =3D { .format_name =3D "sheepdog", .protocol_name =3D "sheepdog+unix", .instance_size =3D sizeof(BDRVSheepdogState), - .bdrv_needs_filename =3D true, + .bdrv_parse_filename =3D sd_parse_filename, .bdrv_file_open =3D sd_open, .bdrv_reopen_prepare =3D sd_reopen_prepare, .bdrv_reopen_commit =3D sd_reopen_commit, --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488902259109675.3573311522395; Tue, 7 Mar 2017 07:57:39 -0800 (PST) Received: from localhost ([::1]:51344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHUX-0007MD-9U for importer@patchew.org; Tue, 07 Mar 2017 10:57:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHF1-0002W8-FT for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHF0-0002uq-HY for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54236) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEy-0002sm-Ep; Tue, 07 Mar 2017 10:41:32 -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 85E8F61D33; Tue, 7 Mar 2017 15:41:32 +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 v27FeuUn032123; Tue, 7 Mar 2017 10:41:27 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:44 +0100 Message-Id: <1488901251-16214-21-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.39]); Tue, 07 Mar 2017 15:41:32 +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 20/27] gluster: Drop assumptions on SocketTransport names 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" From: Markus Armbruster qemu_gluster_glfs_init() passes the names of QAPI enumeration type SocketTransport to glfs_set_volfile_server(). Works, because they were chosen to match. But the coupling is artificial. Use the appropriate literal strings instead. Signed-off-by: Markus Armbruster Reviewed-by: Niels de Vos Signed-off-by: Kevin Wolf --- block/gluster.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 56b4abe..7236d59 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -412,8 +412,7 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOpti= onsGluster *gconf, =20 for (server =3D gconf->server; server; server =3D server->next) { if (server->value->type =3D=3D GLUSTER_TRANSPORT_UNIX) { - ret =3D glfs_set_volfile_server(glfs, - GlusterTransport_lookup[server->value->= type], + ret =3D glfs_set_volfile_server(glfs, "unix", server->value->u.q_unix.path, 0); } else { if (parse_uint_full(server->value->u.tcp.port, &port, 10) < 0 = || @@ -423,8 +422,7 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOpti= onsGluster *gconf, errno =3D EINVAL; goto out; } - ret =3D glfs_set_volfile_server(glfs, - GlusterTransport_lookup[server->value->= type], + ret =3D glfs_set_volfile_server(glfs, "tcp", server->value->u.tcp.host, (int)port); } --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488902284504724.224286226285; Tue, 7 Mar 2017 07:58:04 -0800 (PST) Received: from localhost ([::1]:51349 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHUw-0007ju-5l for importer@patchew.org; Tue, 07 Mar 2017 10:58:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHF6-0002bc-Vp for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHF3-0002wU-Mu for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHEy-0002sd-Ak; Tue, 07 Mar 2017 10:41:32 -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 72AAD61D31; Tue, 7 Mar 2017 15:41:32 +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 v27FeuUo032123; Tue, 7 Mar 2017 10:41:31 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:45 +0100 Message-Id: <1488901251-16214-22-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.39]); Tue, 07 Mar 2017 15:41:32 +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 21/27] gluster: Don't duplicate qapi-util.c's qapi_enum_parse() 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" From: Markus Armbruster Signed-off-by: Markus Armbruster Reviewed-by: Niels de Vos Signed-off-by: Kevin Wolf --- block/gluster.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 7236d59..6fbcf9e 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -12,6 +12,7 @@ #include "block/block_int.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" +#include "qapi/util.h" #include "qemu/uri.h" #include "qemu/error-report.h" #include "qemu/cutils.h" @@ -472,23 +473,6 @@ out: return NULL; } =20 -static int qapi_enum_parse(const char *opt) -{ - int i; - - if (!opt) { - return GLUSTER_TRANSPORT__MAX; - } - - for (i =3D 0; i < GLUSTER_TRANSPORT__MAX; i++) { - if (!strcmp(opt, GlusterTransport_lookup[i])) { - return i; - } - } - - return i; -} - /* * Convert the json formatted command line into qapi. */ @@ -546,16 +530,20 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlu= ster *gconf, =20 ptr =3D qemu_opt_get(opts, GLUSTER_OPT_TYPE); gsconf =3D g_new0(GlusterServer, 1); - gsconf->type =3D qapi_enum_parse(ptr); + gsconf->type =3D qapi_enum_parse(GlusterTransport_lookup, ptr, + GLUSTER_TRANSPORT__MAX, + GLUSTER_TRANSPORT__MAX, + &local_err); if (!ptr) { error_setg(&local_err, QERR_MISSING_PARAMETER, GLUSTER_OPT_TYP= E); error_append_hint(&local_err, GERR_INDEX_HINT, i); goto out; =20 } - if (gsconf->type =3D=3D GLUSTER_TRANSPORT__MAX) { - error_setg(&local_err, QERR_INVALID_PARAMETER_VALUE, - GLUSTER_OPT_TYPE, "tcp or unix"); + if (local_err) { + error_append_hint(&local_err, + "Parameter '%s' may be 'tcp' or 'unix'\n", + GLUSTER_OPT_TYPE); error_append_hint(&local_err, GERR_INDEX_HINT, i); goto out; } --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488902218319841.3330768429282; Tue, 7 Mar 2017 07:56:58 -0800 (PST) Received: from localhost ([::1]:51341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHTr-0006mr-1Q for importer@patchew.org; Tue, 07 Mar 2017 10:56:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHF9-0002e5-7m for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHF8-0002z6-AB for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35572) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHF2-0002va-SK; Tue, 07 Mar 2017 10:41:36 -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 0606281247; Tue, 7 Mar 2017 15:41:37 +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 v27FeuUp032123; Tue, 7 Mar 2017 10:41:32 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:46 +0100 Message-Id: <1488901251-16214-23-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.25]); Tue, 07 Mar 2017 15:41: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] [PULL 22/27] gluster: Plug memory leaks in qemu_gluster_parse_json() 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" From: Markus Armbruster To reproduce, run $ valgrind qemu-system-x86_64 --nodefaults -S --drive driver=3Dgluster,= volume=3Dtestvol,path=3D/a/b/c,server.0.type=3Dxxx Signed-off-by: Markus Armbruster Reviewed-by: Niels de Vos Signed-off-by: Kevin Wolf --- block/gluster.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 6fbcf9e..991f18f 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -480,7 +480,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlust= er *gconf, QDict *options, Error **errp) { QemuOpts *opts; - GlusterServer *gsconf; + GlusterServer *gsconf =3D NULL; GlusterServerList *curr =3D NULL; QDict *backing_options =3D NULL; Error *local_err =3D NULL; @@ -529,17 +529,16 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlu= ster *gconf, } =20 ptr =3D qemu_opt_get(opts, GLUSTER_OPT_TYPE); - gsconf =3D g_new0(GlusterServer, 1); - gsconf->type =3D qapi_enum_parse(GlusterTransport_lookup, ptr, - GLUSTER_TRANSPORT__MAX, - GLUSTER_TRANSPORT__MAX, - &local_err); if (!ptr) { error_setg(&local_err, QERR_MISSING_PARAMETER, GLUSTER_OPT_TYP= E); error_append_hint(&local_err, GERR_INDEX_HINT, i); goto out; =20 } + gsconf =3D g_new0(GlusterServer, 1); + gsconf->type =3D qapi_enum_parse(GlusterTransport_lookup, ptr, + GLUSTER_TRANSPORT__MAX, -1, + &local_err); if (local_err) { error_append_hint(&local_err, "Parameter '%s' may be 'tcp' or 'unix'\n", @@ -626,8 +625,10 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlus= ter *gconf, curr->next->value =3D gsconf; curr =3D curr->next; } + gsconf =3D NULL; =20 - qdict_del(backing_options, str); + QDECREF(backing_options); + backing_options =3D NULL; g_free(str); str =3D NULL; } @@ -636,11 +637,10 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlu= ster *gconf, =20 out: error_propagate(errp, local_err); + qapi_free_GlusterServer(gsconf); qemu_opts_del(opts); - if (str) { - qdict_del(backing_options, str); - g_free(str); - } + g_free(str); + QDECREF(backing_options); errno =3D EINVAL; return -errno; } --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488902577001741.0593134578495; Tue, 7 Mar 2017 08:02:57 -0800 (PST) Received: from localhost ([::1]:51386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHZc-0004EU-6y for importer@patchew.org; Tue, 07 Mar 2017 11:02:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHFA-0002fY-ES for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHF9-0002zS-40 for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50732) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHF2-0002vX-RH; Tue, 07 Mar 2017 10:41:37 -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 EAFE680F75; Tue, 7 Mar 2017 15:41:36 +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 v27FeuUq032123; Tue, 7 Mar 2017 10:41:36 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:47 +0100 Message-Id: <1488901251-16214-24-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.27]); Tue, 07 Mar 2017 15:41:36 +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 23/27] qapi-schema: Rename GlusterServer to SocketAddressFlat 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" From: Markus Armbruster As its documentation says, it's not specific to Gluster. Rename it, as I'm going to use it for something else. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/gluster.c | 38 +++++++++++++++++++------------------- qapi-schema.json | 38 ++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 46 +--------------------------------------------- 3 files changed, 58 insertions(+), 64 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 991f18f..64b0217 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -321,7 +321,7 @@ static int parse_volume_options(BlockdevOptionsGluster = *gconf, char *path) static int qemu_gluster_parse_uri(BlockdevOptionsGluster *gconf, const char *filename) { - GlusterServer *gsconf; + SocketAddressFlat *gsconf; URI *uri; QueryParams *qp =3D NULL; bool is_unix =3D false; @@ -332,19 +332,19 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGlus= ter *gconf, return -EINVAL; } =20 - gconf->server =3D g_new0(GlusterServerList, 1); - gconf->server->value =3D gsconf =3D g_new0(GlusterServer, 1); + gconf->server =3D g_new0(SocketAddressFlatList, 1); + gconf->server->value =3D gsconf =3D g_new0(SocketAddressFlat, 1); =20 /* transport */ if (!uri->scheme || !strcmp(uri->scheme, "gluster")) { - gsconf->type =3D GLUSTER_TRANSPORT_TCP; + gsconf->type =3D SOCKET_ADDRESS_FLAT_TYPE_TCP; } else if (!strcmp(uri->scheme, "gluster+tcp")) { - gsconf->type =3D GLUSTER_TRANSPORT_TCP; + gsconf->type =3D SOCKET_ADDRESS_FLAT_TYPE_TCP; } else if (!strcmp(uri->scheme, "gluster+unix")) { - gsconf->type =3D GLUSTER_TRANSPORT_UNIX; + gsconf->type =3D SOCKET_ADDRESS_FLAT_TYPE_UNIX; is_unix =3D true; } else if (!strcmp(uri->scheme, "gluster+rdma")) { - gsconf->type =3D GLUSTER_TRANSPORT_TCP; + gsconf->type =3D SOCKET_ADDRESS_FLAT_TYPE_TCP; error_report("Warning: rdma feature is not supported, falling " "back to tcp"); } else { @@ -396,7 +396,7 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOpti= onsGluster *gconf, struct glfs *glfs; int ret; int old_errno; - GlusterServerList *server; + SocketAddressFlatList *server; unsigned long long port; =20 glfs =3D glfs_find_preopened(gconf->volume); @@ -412,7 +412,7 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOpti= onsGluster *gconf, glfs_set_preopened(gconf->volume, glfs); =20 for (server =3D gconf->server; server; server =3D server->next) { - if (server->value->type =3D=3D GLUSTER_TRANSPORT_UNIX) { + if (server->value->type =3D=3D SOCKET_ADDRESS_FLAT_TYPE_UNIX) { ret =3D glfs_set_volfile_server(glfs, "unix", server->value->u.q_unix.path, 0); } else { @@ -443,7 +443,7 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOpti= onsGluster *gconf, error_setg(errp, "Gluster connection for volume %s, path %s failed" " to connect", gconf->volume, gconf->path); for (server =3D gconf->server; server; server =3D server->next) { - if (server->value->type =3D=3D GLUSTER_TRANSPORT_UNIX) { + if (server->value->type =3D=3D SOCKET_ADDRESS_FLAT_TYPE_UNIX)= { error_append_hint(errp, "hint: failed on socket %s ", server->value->u.q_unix.path); } else { @@ -480,8 +480,8 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlust= er *gconf, QDict *options, Error **errp) { QemuOpts *opts; - GlusterServer *gsconf =3D NULL; - GlusterServerList *curr =3D NULL; + SocketAddressFlat *gsconf =3D NULL; + SocketAddressFlatList *curr =3D NULL; QDict *backing_options =3D NULL; Error *local_err =3D NULL; char *str =3D NULL; @@ -535,9 +535,9 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlust= er *gconf, goto out; =20 } - gsconf =3D g_new0(GlusterServer, 1); - gsconf->type =3D qapi_enum_parse(GlusterTransport_lookup, ptr, - GLUSTER_TRANSPORT__MAX, -1, + gsconf =3D g_new0(SocketAddressFlat, 1); + gsconf->type =3D qapi_enum_parse(SocketAddressFlatType_lookup, ptr, + SOCKET_ADDRESS_FLAT_TYPE__MAX, -1, &local_err); if (local_err) { error_append_hint(&local_err, @@ -548,7 +548,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlust= er *gconf, } qemu_opts_del(opts); =20 - if (gsconf->type =3D=3D GLUSTER_TRANSPORT_TCP) { + if (gsconf->type =3D=3D SOCKET_ADDRESS_FLAT_TYPE_TCP) { /* create opts info from runtime_tcp_opts list */ opts =3D qemu_opts_create(&runtime_tcp_opts, NULL, 0, &error_a= bort); qemu_opts_absorb_qdict(opts, backing_options, &local_err); @@ -617,11 +617,11 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlu= ster *gconf, } =20 if (gconf->server =3D=3D NULL) { - gconf->server =3D g_new0(GlusterServerList, 1); + gconf->server =3D g_new0(SocketAddressFlatList, 1); gconf->server->value =3D gsconf; curr =3D gconf->server; } else { - curr->next =3D g_new0(GlusterServerList, 1); + curr->next =3D g_new0(SocketAddressFlatList, 1); curr->next->value =3D gsconf; curr =3D curr->next; } @@ -637,7 +637,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlust= er *gconf, =20 out: error_propagate(errp, local_err); - qapi_free_GlusterServer(gsconf); + qapi_free_SocketAddressFlat(gsconf); qemu_opts_del(opts); g_free(str); QDECREF(backing_options); diff --git a/qapi-schema.json b/qapi-schema.json index 6febfa7..15a8f7d 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4101,6 +4101,44 @@ 'fd': 'String' } } =20 ## +# @SocketAddressFlatType: +# +# Available SocketAddressFlat types +# +# @tcp: Internet address +# +# @unix: Unix domain socket +# +# Since: 2.9 +## +{ 'enum': 'SocketAddressFlatType', + 'data': [ 'unix', 'tcp' ] } + +## +# @SocketAddressFlat: +# +# Captures the address of a socket +# +# @type: Transport type +# +# This is similar to SocketAddress, only distinction: +# +# 1. SocketAddressFlat is a flat union, SocketAddress is a simple union. +# A flat union is nicer than simple because it avoids nesting +# (i.e. more {}) on the wire. +# +# 2. SocketAddressFlat supports only types 'unix' and 'tcp', because +# that's what its current users need. +# +# Since: 2.9 +## +{ 'union': 'SocketAddressFlat', + 'base': { 'type': 'SocketAddressFlatType' }, + 'discriminator': 'type', + 'data': { 'unix': 'UnixSocketAddress', + 'tcp': 'InetSocketAddress' } } + +## # @getfd: # # Receive a file descriptor via SCM rights and assign it a name diff --git a/qapi/block-core.json b/qapi/block-core.json index bc0ccd6..d63be0a 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2546,50 +2546,6 @@ '*read-pattern': 'QuorumReadPattern' } } =20 ## -# @GlusterTransport: -# -# An enumeration of Gluster transport types -# -# @tcp: TCP - Transmission Control Protocol -# -# @unix: UNIX - Unix domain socket -# -# Since: 2.7 -## -{ 'enum': 'GlusterTransport', - 'data': [ 'unix', 'tcp' ] } - - -## -# @GlusterServer: -# -# Captures the address of a socket -# -# Details for connecting to a gluster server -# -# @type: Transport type used for gluster connection -# -# This is similar to SocketAddress, only distinction: -# -# 1. GlusterServer is a flat union, SocketAddress is a simple union. -# A flat union is nicer than simple because it avoids nesting -# (i.e. more {}) on the wire. -# -# 2. GlusterServer lacks case 'fd', since gluster doesn't let you -# pass in a file descriptor. -# -# GlusterServer is actually not Gluster-specific, its a -# compatibility evolved into an alternate for SocketAddress. -# -# Since: 2.7 -## -{ 'union': 'GlusterServer', - 'base': { 'type': 'GlusterTransport' }, - 'discriminator': 'type', - 'data': { 'unix': 'UnixSocketAddress', - 'tcp': 'InetSocketAddress' } } - -## # @BlockdevOptionsGluster: # # Driver specific block device options for Gluster @@ -2610,7 +2566,7 @@ { 'struct': 'BlockdevOptionsGluster', 'data': { 'volume': 'str', 'path': 'str', - 'server': ['GlusterServer'], + 'server': ['SocketAddressFlat'], '*debug': 'int', '*logfile': 'str' } } =20 --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488902481684433.529254000233; Tue, 7 Mar 2017 08:01:21 -0800 (PST) Received: from localhost ([::1]:51373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHY7-00030O-Ai for importer@patchew.org; Tue, 07 Mar 2017 11:01:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHFA-0002gC-SB for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHF9-0002ze-AU for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35580) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHF3-0002vr-Gn; Tue, 07 Mar 2017 10:41:37 -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 9C90D81226; Tue, 7 Mar 2017 15:41:37 +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 v27FeuUr032123; Tue, 7 Mar 2017 10:41:36 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:48 +0100 Message-Id: <1488901251-16214-25-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.25]); Tue, 07 Mar 2017 15:41: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] [PULL 24/27] qapi-schema: Rename SocketAddressFlat's variant tcp to inet 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" From: Markus Armbruster QAPI type SocketAddressFlat differs from SocketAddress pointlessly: the discriminator value for variant InetSocketAddress is 'tcp' instead of 'inet'. Rename. The type is so far only used by the Gluster block drivers. Take care to keep 'tcp' working in things like -drive's file.server.0.type=3Dtcp. The "gluster+tcp" URI scheme in pseudo-filenames stays the same. blockdev-add changes, but it has changed incompatibly since 2.8 already. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/gluster.c | 59 +++++++++++++++++++++++++++++-----------------------= ---- qapi-schema.json | 8 ++++---- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 64b0217..a577dae 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -152,7 +152,7 @@ static QemuOptsList runtime_type_opts =3D { { .name =3D GLUSTER_OPT_TYPE, .type =3D QEMU_OPT_STRING, - .help =3D "tcp|unix", + .help =3D "inet|unix", }, { /* end of list */ } }, @@ -171,14 +171,14 @@ static QemuOptsList runtime_unix_opts =3D { }, }; =20 -static QemuOptsList runtime_tcp_opts =3D { - .name =3D "gluster_tcp", - .head =3D QTAILQ_HEAD_INITIALIZER(runtime_tcp_opts.head), +static QemuOptsList runtime_inet_opts =3D { + .name =3D "gluster_inet", + .head =3D QTAILQ_HEAD_INITIALIZER(runtime_inet_opts.head), .desc =3D { { .name =3D GLUSTER_OPT_TYPE, .type =3D QEMU_OPT_STRING, - .help =3D "tcp|unix", + .help =3D "inet|unix", }, { .name =3D GLUSTER_OPT_HOST, @@ -337,14 +337,14 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGlus= ter *gconf, =20 /* transport */ if (!uri->scheme || !strcmp(uri->scheme, "gluster")) { - gsconf->type =3D SOCKET_ADDRESS_FLAT_TYPE_TCP; + gsconf->type =3D SOCKET_ADDRESS_FLAT_TYPE_INET; } else if (!strcmp(uri->scheme, "gluster+tcp")) { - gsconf->type =3D SOCKET_ADDRESS_FLAT_TYPE_TCP; + gsconf->type =3D SOCKET_ADDRESS_FLAT_TYPE_INET; } else if (!strcmp(uri->scheme, "gluster+unix")) { gsconf->type =3D SOCKET_ADDRESS_FLAT_TYPE_UNIX; is_unix =3D true; } else if (!strcmp(uri->scheme, "gluster+rdma")) { - gsconf->type =3D SOCKET_ADDRESS_FLAT_TYPE_TCP; + gsconf->type =3D SOCKET_ADDRESS_FLAT_TYPE_INET; error_report("Warning: rdma feature is not supported, falling " "back to tcp"); } else { @@ -374,11 +374,11 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGlus= ter *gconf, } gsconf->u.q_unix.path =3D g_strdup(qp->p[0].value); } else { - gsconf->u.tcp.host =3D g_strdup(uri->server ? uri->server : "local= host"); + gsconf->u.inet.host =3D g_strdup(uri->server ? uri->server : "loca= lhost"); if (uri->port) { - gsconf->u.tcp.port =3D g_strdup_printf("%d", uri->port); + gsconf->u.inet.port =3D g_strdup_printf("%d", uri->port); } else { - gsconf->u.tcp.port =3D g_strdup_printf("%d", GLUSTER_DEFAULT_P= ORT); + gsconf->u.inet.port =3D g_strdup_printf("%d", GLUSTER_DEFAULT_= PORT); } } =20 @@ -416,15 +416,15 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOp= tionsGluster *gconf, ret =3D glfs_set_volfile_server(glfs, "unix", server->value->u.q_unix.path, 0); } else { - if (parse_uint_full(server->value->u.tcp.port, &port, 10) < 0 = || + if (parse_uint_full(server->value->u.inet.port, &port, 10) < 0= || port > 65535) { error_setg(errp, "'%s' is not a valid port number", - server->value->u.tcp.port); + server->value->u.inet.port); errno =3D EINVAL; goto out; } ret =3D glfs_set_volfile_server(glfs, "tcp", - server->value->u.tcp.host, + server->value->u.inet.host, (int)port); } =20 @@ -448,8 +448,8 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOpti= onsGluster *gconf, server->value->u.q_unix.path); } else { error_append_hint(errp, "hint: failed on host %s and port = %s ", - server->value->u.tcp.host, - server->value->u.tcp.port); + server->value->u.inet.host, + server->value->u.inet.port); } } =20 @@ -536,21 +536,24 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlu= ster *gconf, =20 } gsconf =3D g_new0(SocketAddressFlat, 1); + if (!strcmp(ptr, "tcp")) { + ptr =3D "inet"; /* accept legacy "tcp" */ + } gsconf->type =3D qapi_enum_parse(SocketAddressFlatType_lookup, ptr, SOCKET_ADDRESS_FLAT_TYPE__MAX, -1, &local_err); if (local_err) { error_append_hint(&local_err, - "Parameter '%s' may be 'tcp' or 'unix'\n", + "Parameter '%s' may be 'inet' or 'unix'\n", GLUSTER_OPT_TYPE); error_append_hint(&local_err, GERR_INDEX_HINT, i); goto out; } qemu_opts_del(opts); =20 - if (gsconf->type =3D=3D SOCKET_ADDRESS_FLAT_TYPE_TCP) { - /* create opts info from runtime_tcp_opts list */ - opts =3D qemu_opts_create(&runtime_tcp_opts, NULL, 0, &error_a= bort); + if (gsconf->type =3D=3D SOCKET_ADDRESS_FLAT_TYPE_INET) { + /* create opts info from runtime_inet_opts list */ + opts =3D qemu_opts_create(&runtime_inet_opts, NULL, 0, &error_= abort); qemu_opts_absorb_qdict(opts, backing_options, &local_err); if (local_err) { goto out; @@ -563,7 +566,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlust= er *gconf, error_append_hint(&local_err, GERR_INDEX_HINT, i); goto out; } - gsconf->u.tcp.host =3D g_strdup(ptr); + gsconf->u.inet.host =3D g_strdup(ptr); ptr =3D qemu_opt_get(opts, GLUSTER_OPT_PORT); if (!ptr) { error_setg(&local_err, QERR_MISSING_PARAMETER, @@ -571,28 +574,28 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlu= ster *gconf, error_append_hint(&local_err, GERR_INDEX_HINT, i); goto out; } - gsconf->u.tcp.port =3D g_strdup(ptr); + gsconf->u.inet.port =3D g_strdup(ptr); =20 /* defend for unsupported fields in InetSocketAddress, * i.e. @ipv4, @ipv6 and @to */ ptr =3D qemu_opt_get(opts, GLUSTER_OPT_TO); if (ptr) { - gsconf->u.tcp.has_to =3D true; + gsconf->u.inet.has_to =3D true; } ptr =3D qemu_opt_get(opts, GLUSTER_OPT_IPV4); if (ptr) { - gsconf->u.tcp.has_ipv4 =3D true; + gsconf->u.inet.has_ipv4 =3D true; } ptr =3D qemu_opt_get(opts, GLUSTER_OPT_IPV6); if (ptr) { - gsconf->u.tcp.has_ipv6 =3D true; + gsconf->u.inet.has_ipv6 =3D true; } - if (gsconf->u.tcp.has_to) { + if (gsconf->u.inet.has_to) { error_setg(&local_err, "Parameter 'to' not supported"); goto out; } - if (gsconf->u.tcp.has_ipv4 || gsconf->u.tcp.has_ipv6) { + if (gsconf->u.inet.has_ipv4 || gsconf->u.inet.has_ipv6) { error_setg(&local_err, "Parameters 'ipv4/ipv6' not support= ed"); goto out; } @@ -669,7 +672,7 @@ static struct glfs *qemu_gluster_init(BlockdevOptionsGl= uster *gconf, "file.volume=3Dtestvol,file.path=3D/path/a.qc= ow2" "[,file.debug=3D9]" "[,file.logfile=3D/path/filename.log]," - "file.server.0.type=3Dtcp," + "file.server.0.type=3Dinet," "file.server.0.host=3D1.2.3.4," "file.server.0.port=3D24007," "file.server.1.transport=3Dunix," diff --git a/qapi-schema.json b/qapi-schema.json index 15a8f7d..32b4a4b 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4105,14 +4105,14 @@ # # Available SocketAddressFlat types # -# @tcp: Internet address +# @inet: Internet address # # @unix: Unix domain socket # # Since: 2.9 ## { 'enum': 'SocketAddressFlatType', - 'data': [ 'unix', 'tcp' ] } + 'data': [ 'unix', 'inet' ] } =20 ## # @SocketAddressFlat: @@ -4127,7 +4127,7 @@ # A flat union is nicer than simple because it avoids nesting # (i.e. more {}) on the wire. # -# 2. SocketAddressFlat supports only types 'unix' and 'tcp', because +# 2. SocketAddressFlat supports only types 'unix' and 'inet', because # that's what its current users need. # # Since: 2.9 @@ -4136,7 +4136,7 @@ 'base': { 'type': 'SocketAddressFlatType' }, 'discriminator': 'type', 'data': { 'unix': 'UnixSocketAddress', - 'tcp': 'InetSocketAddress' } } + 'inet': 'InetSocketAddress' } } =20 ## # @getfd: --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 148890181635888.31917845477687; Tue, 7 Mar 2017 07:50:16 -0800 (PST) Received: from localhost ([::1]:51293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHNK-0000sf-Tq for importer@patchew.org; Tue, 07 Mar 2017 10:50:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHF9-0002eI-CP for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHF8-0002zE-HS for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHF4-0002wo-Hv; Tue, 07 Mar 2017 10:41:38 -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 AA1C680468; Tue, 7 Mar 2017 15:41:38 +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 v27FeuUs032123; Tue, 7 Mar 2017 10:41:37 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:49 +0100 Message-Id: <1488901251-16214-26-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:38 +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 25/27] sheepdog: Support blockdev-add 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" From: Markus Armbruster Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- qapi/block-core.json | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index d63be0a..9bb7f4a 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2124,6 +2124,7 @@ # @ssh: Since 2.8 # @iscsi: Since 2.9 # @rbd: Since 2.9 +# @sheepdog: Since 2.9 # # Since: 2.0 ## @@ -2132,8 +2133,8 @@ 'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed', - 'quorum', 'raw', 'rbd', 'replication', 'ssh', 'vdi', 'vhdx', '= vmdk', - 'vpc', 'vvfat' ] } + 'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'ssh', + 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } =20 ## # @BlockdevOptionsFile: @@ -2692,6 +2693,26 @@ '*password-secret': 'str' } } =20 ## +# @BlockdevOptionsSheepdog: +# +# Driver specific block device options for sheepdog +# +# @vdi: Virtual disk image name +# @addr: The Sheepdog server to connect to +# @snap-id: Snapshot ID +# @tag: Snapshot tag name +# +# Only one of @snap-id and @tag may be present. +# +# Since: 2.9 +## +{ 'struct': 'BlockdevOptionsSheepdog', + 'data': { 'addr': 'SocketAddressFlat', + 'vdi': 'str', + '*snap-id': 'uint32', + '*tag': 'str' } } + +## # @ReplicationMode: # # An enumeration of replication modes. @@ -2891,7 +2912,7 @@ 'raw': 'BlockdevOptionsRaw', 'rbd': 'BlockdevOptionsRbd', 'replication':'BlockdevOptionsReplication', -# TODO sheepdog: Wait for structured options + 'sheepdog': 'BlockdevOptionsSheepdog', 'ssh': 'BlockdevOptionsSsh', 'vdi': 'BlockdevOptionsGenericFormat', 'vhdx': 'BlockdevOptionsGenericFormat', --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488902422732455.45899805576323; Tue, 7 Mar 2017 08:00:22 -0800 (PST) Received: from localhost ([::1]:51362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHXA-00024g-CL for importer@patchew.org; Tue, 07 Mar 2017 11:00:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHFA-0002eq-2h for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHF9-0002zr-Ec for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36138) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHF6-0002xs-R9; Tue, 07 Mar 2017 10:41:40 -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 E724D1555E; Tue, 7 Mar 2017 15:41:40 +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 v27FeuUt032123; Tue, 7 Mar 2017 10:41:38 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:50 +0100 Message-Id: <1488901251-16214-27-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.29]); Tue, 07 Mar 2017 15:41:40 +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 26/27] block: Don't use error_abort in blk_new_open 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" From: Fam Zheng We have an errp and bdrv_root_attach_child can fail permission check, error_abort is not the best choice here. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/block-backend.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index daa7908..5742c09 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -213,7 +213,12 @@ BlockBackend *blk_new_open(const char *filename, const= char *reference, } =20 blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, - perm, BLK_PERM_ALL, blk, &error_abo= rt); + perm, BLK_PERM_ALL, blk, errp); + if (!blk->root) { + bdrv_unref(bs); + blk_unref(blk); + return NULL; + } =20 return blk; } --=20 1.8.3.1 From nobody Tue May 7 13:35:19 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 1488902361479313.81822291522985; Tue, 7 Mar 2017 07:59:21 -0800 (PST) Received: from localhost ([::1]:51354 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHW9-0000dx-40 for importer@patchew.org; Tue, 07 Mar 2017 10:59:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHFB-0002gI-17 for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHFA-00030P-BB for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:41:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35902) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clHF8-0002yX-1k; Tue, 07 Mar 2017 10:41:42 -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 3383763E2F; Tue, 7 Mar 2017 15:41:42 +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 v27FeuUu032123; Tue, 7 Mar 2017 10:41:41 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 7 Mar 2017 16:40:51 +0100 Message-Id: <1488901251-16214-28-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.38]); Tue, 07 Mar 2017 15:41:42 +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 27/27] commit: Don't use error_abort in commit_start 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" From: Fam Zheng bdrv_set_backing_hd failure needn't be abort. Since we already have error parameter, use it. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/commit.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/block/commit.c b/block/commit.c index e57c1cf..9c41988 100644 --- a/block/commit.c +++ b/block/commit.c @@ -316,8 +316,20 @@ void commit_start(const char *job_id, BlockDriverState= *bs, goto fail; } =20 - bdrv_set_backing_hd(commit_top_bs, top, &error_abort); - bdrv_set_backing_hd(overlay_bs, commit_top_bs, &error_abort); + bdrv_set_backing_hd(commit_top_bs, top, &local_err); + if (local_err) { + bdrv_unref(commit_top_bs); + commit_top_bs =3D NULL; + error_propagate(errp, local_err); + goto fail; + } + bdrv_set_backing_hd(overlay_bs, commit_top_bs, &local_err); + if (local_err) { + bdrv_unref(commit_top_bs); + commit_top_bs =3D NULL; + error_propagate(errp, local_err); + goto fail; + } =20 s->commit_top_bs =3D commit_top_bs; bdrv_unref(commit_top_bs); --=20 1.8.3.1