From nobody Sun May 5 10:37:10 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.zohomail.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 150350640524363.1435178557208; Wed, 23 Aug 2017 09:40:05 -0700 (PDT) Received: from localhost ([::1]:44732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYhI-0005AP-3z for importer@patchew.org; Wed, 23 Aug 2017 12:40:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYbW-0008QR-96 for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkYbV-0005QV-BZ for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47984) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkYbO-0005Oq-Se; Wed, 23 Aug 2017 12:33:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D695B5F7B5; Wed, 23 Aug 2017 16:33:57 +0000 (UTC) Received: from red.redhat.com (ovpn-124-155.rdu2.redhat.com [10.10.124.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F05E614FE; Wed, 23 Aug 2017 16:33:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D695B5F7B5 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 11:33:44 -0500 Message-Id: <20170823163349.11663-2-eblake@redhat.com> In-Reply-To: <20170823163349.11663-1-eblake@redhat.com> References: <20170823163349.11663-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 23 Aug 2017 16:33:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/6] block-backend: Refactor inactivate check 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: Kevin Wolf , Fam Zheng , "open list:Block layer core" , Max Reitz 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 The logic will be fixed (extended), move it to a separate function. Signed-off-by: Fam Zheng Message-Id: <20170823134242.12080-2-famz@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Eric Blake --- block/block-backend.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index e9798e897d..a3984d2bec 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -192,19 +192,28 @@ static void blk_root_activate(BdrvChild *child, Error= **errp) } } -static int blk_root_inactivate(BdrvChild *child) +static bool blk_can_inactivate(BlockBackend *blk) { - BlockBackend *blk =3D child->opaque; - - if (blk->disable_perm) { - return 0; - } - /* Only inactivate BlockBackends for guest devices (which are inactive= at * this point because the VM is stopped) and unattached monitor-owned * BlockBackends. If there is still any other user like a block job, t= hen * we simply can't inactivate the image. */ - if (!blk->dev && !blk_name(blk)[0]) { + if (blk->dev || blk_name(blk)[0]) { + return true; + } + + return false; +} + +static int blk_root_inactivate(BdrvChild *child) +{ + BlockBackend *blk =3D child->opaque; + + if (blk->disable_perm) { + return 0; + } + + if (!blk_can_inactivate(blk)) { return -EPERM; } --=20 2.13.5 From nobody Sun May 5 10:37:10 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.zohomail.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 1503506659870575.3305101485022; Wed, 23 Aug 2017 09:44:19 -0700 (PDT) Received: from localhost ([::1]:44758 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYlO-0001H7-Np for importer@patchew.org; Wed, 23 Aug 2017 12:44:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYbW-0008Qd-Fu for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkYbV-0005Qd-FC for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57608) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkYbQ-0005P4-5B; Wed, 23 Aug 2017 12:34:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B204821C7; Wed, 23 Aug 2017 16:33:59 +0000 (UTC) Received: from red.redhat.com (ovpn-124-155.rdu2.redhat.com [10.10.124.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19B58614FE; Wed, 23 Aug 2017 16:33:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2B204821C7 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 11:33:45 -0500 Message-Id: <20170823163349.11663-3-eblake@redhat.com> In-Reply-To: <20170823163349.11663-1-eblake@redhat.com> References: <20170823163349.11663-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 23 Aug 2017 16:33:59 +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 2/6] block-backend: Allow more "can inactivate" cases 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: Kevin Wolf , Fam Zheng , "open list:Block layer core" , Max Reitz 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 These two conditions corresponds to mirror job's source and target, which need to be allowed as they are part of the non-shared storage migration workflow: failing to inactivate either will result in a failure during migration completion. Signed-off-by: Fam Zheng Message-Id: <20170823134242.12080-3-famz@redhat.com> Reviewed-by: Stefan Hajnoczi [eblake: improve comment grammar] Signed-off-by: Eric Blake --- include/sysemu/block-backend.h | 1 + block/block-backend.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 4a3730596b..aadc733daf 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -241,5 +241,6 @@ void blk_set_io_limits(BlockBackend *blk, ThrottleConfi= g *cfg); void blk_io_limits_disable(BlockBackend *blk); void blk_io_limits_enable(BlockBackend *blk, const char *group); void blk_io_limits_update_group(BlockBackend *blk, const char *group); +void blk_set_force_allow_inactivate(BlockBackend *blk); #endif diff --git a/block/block-backend.c b/block/block-backend.c index a3984d2bec..1031742401 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -70,6 +70,7 @@ struct BlockBackend { int quiesce_counter; VMChangeStateEntry *vmsh; + bool force_allow_inactivate; }; typedef struct BlockBackendAIOCB { @@ -192,17 +193,28 @@ static void blk_root_activate(BdrvChild *child, Error= **errp) } } +void blk_set_force_allow_inactivate(BlockBackend *blk) +{ + blk->force_allow_inactivate =3D true; +} + static bool blk_can_inactivate(BlockBackend *blk) { - /* Only inactivate BlockBackends for guest devices (which are inactive= at - * this point because the VM is stopped) and unattached monitor-owned - * BlockBackends. If there is still any other user like a block job, t= hen - * we simply can't inactivate the image. */ + /* If it is a guest device, inactivate is ok. */ if (blk->dev || blk_name(blk)[0]) { return true; } - return false; + /* Inactivating means no more writes to the image can be done, + * even if those writes would be changes invisible to the + * guest. For block job BBs that satisfy this, we can just allow + * it. This is the case for mirror job source, which is required + * by libvirt non-shared block migration. */ + if (!(blk->perm & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED))) { + return true; + } + + return blk->force_allow_inactivate; } static int blk_root_inactivate(BdrvChild *child) --=20 2.13.5 From nobody Sun May 5 10:37:10 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.zohomail.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 150350655986410.68713284797002; Wed, 23 Aug 2017 09:42:39 -0700 (PDT) Received: from localhost ([::1]:44749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYjm-00088d-J9 for importer@patchew.org; Wed, 23 Aug 2017 12:42:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYbW-0008Qi-I5 for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkYbV-0005Qi-G4 for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkYbR-0005PQ-Mo; Wed, 23 Aug 2017 12:34:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B01D380B29; Wed, 23 Aug 2017 16:34:00 +0000 (UTC) Received: from red.redhat.com (ovpn-124-155.rdu2.redhat.com [10.10.124.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62824614FE; Wed, 23 Aug 2017 16:33:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B01D380B29 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 11:33:46 -0500 Message-Id: <20170823163349.11663-4-eblake@redhat.com> In-Reply-To: <20170823163349.11663-1-eblake@redhat.com> References: <20170823163349.11663-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 23 Aug 2017 16:34: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 3/6] mirror: Mark target BB as "force allow inactivate" 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: Kevin Wolf , Jeff Cody , Fam Zheng , "open list:Block Jobs" , Max Reitz 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 Signed-off-by: Fam Zheng Message-Id: <20170823134242.12080-4-famz@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Eric Blake --- block/mirror.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index c9a6a3ca86..429751b9fe 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1134,6 +1134,7 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, const BlockJobDriver *driver, bool is_none_mode, BlockDriverState *base, bool auto_complete, const char *filter_node_n= ame, + bool is_mirror, Error **errp) { MirrorBlockJob *s; @@ -1222,6 +1223,15 @@ static void mirror_start_job(const char *job_id, Blo= ckDriverState *bs, if (ret < 0) { goto fail; } + if (is_mirror) { + /* XXX: Mirror target could be a NBD server of target QEMU in the = case + * of non-shared block migration. To allow migration completion, we + * have to allow "inactivate" of the target BB. When that happens= , we + * know the job is drained, and the vcpus are stopped, so no write + * operation will be performed. Block layer already has assertions= to + * ensure that. */ + blk_set_force_allow_inactivate(s->target); + } s->replaces =3D g_strdup(replaces); s->on_source_error =3D on_source_error; @@ -1306,7 +1316,7 @@ void mirror_start(const char *job_id, BlockDriverStat= e *bs, speed, granularity, buf_size, backing_mode, on_source_error, on_target_error, unmap, NULL, NULL, &mirror_job_driver, is_none_mode, base, false, - filter_node_name, errp); + filter_node_name, true, errp); } void commit_active_start(const char *job_id, BlockDriverState *bs, @@ -1329,7 +1339,7 @@ void commit_active_start(const char *job_id, BlockDri= verState *bs, MIRROR_LEAVE_BACKING_CHAIN, on_error, on_error, true, cb, opaque, &commit_active_job_driver, false, base, auto_complete, - filter_node_name, &local_err); + filter_node_name, false, &local_err); if (local_err) { error_propagate(errp, local_err); goto error_restore_flags; --=20 2.13.5 From nobody Sun May 5 10:37:10 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.zohomail.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 150350670939833.831988877616936; Wed, 23 Aug 2017 09:45:09 -0700 (PDT) Received: from localhost ([::1]:44766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYmC-0002Ux-6o for importer@patchew.org; Wed, 23 Aug 2017 12:45:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYbZ-0008Ti-Dz for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkYbY-0005Rq-Hu for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60530) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkYbW-0005Qm-5m; Wed, 23 Aug 2017 12:34:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2EDD037E85; Wed, 23 Aug 2017 16:34:05 +0000 (UTC) Received: from red.redhat.com (ovpn-124-155.rdu2.redhat.com [10.10.124.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAF3B614FE; Wed, 23 Aug 2017 16:34:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2EDD037E85 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 11:33:47 -0500 Message-Id: <20170823163349.11663-5-eblake@redhat.com> In-Reply-To: <20170823163349.11663-1-eblake@redhat.com> References: <20170823163349.11663-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 23 Aug 2017 16:34: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 4/6] block: Update open_flags after ->inactivate() callback 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: Kevin Wolf , Fam Zheng , "open list:Block layer core" , Stefan Hajnoczi , Max Reitz 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: Stefan Hajnoczi In the ->inactivate() callbacks, permissions are updated, which typically involves a recursive check of the whole graph. Setting BDRV_O_INACTIVE right before doing that creates a state that bdrv_is_writable() returns false, which causes permission update failure. Reorder them so the flag is updated after calling the function. Note that this doesn't break the assert in bdrv_child_cb_inactivate() because for any specific BDS, we still update its flags first before calling ->inactivate() on it one level deeper in the recursion. Signed-off-by: Stefan Hajnoczi Signed-off-by: Fam Zheng Message-Id: <20170823134242.12080-5-famz@redhat.com> Tested-by: Dr. David Alan Gilbert Signed-off-by: Eric Blake --- block.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 3615a6809e..3308814bba 100644 --- a/block.c +++ b/block.c @@ -4085,21 +4085,20 @@ static int bdrv_inactivate_recurse(BlockDriverState= *bs, } } - if (setting_flag) { + if (setting_flag && !(bs->open_flags & BDRV_O_INACTIVE)) { uint64_t perm, shared_perm; - bs->open_flags |=3D BDRV_O_INACTIVE; - QLIST_FOREACH(parent, &bs->parents, next_parent) { if (parent->role->inactivate) { ret =3D parent->role->inactivate(parent); if (ret < 0) { - bs->open_flags &=3D ~BDRV_O_INACTIVE; return ret; } } } + bs->open_flags |=3D BDRV_O_INACTIVE; + /* Update permissions, they may differ for inactive nodes */ bdrv_get_cumulative_perm(bs, &perm, &shared_perm); bdrv_check_perm(bs, perm, shared_perm, NULL, &error_abort); --=20 2.13.5 From nobody Sun May 5 10:37:10 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.zohomail.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 1503506928215225.7229896370809; Wed, 23 Aug 2017 09:48:48 -0700 (PDT) Received: from localhost ([::1]:44799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYpj-0005X7-06 for importer@patchew.org; Wed, 23 Aug 2017 12:48:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYbf-00005R-MA for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkYbb-0005TC-4a for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60600) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkYbX-0005RI-Gt; Wed, 23 Aug 2017 12:34:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D40C2027B; Wed, 23 Aug 2017 16:34:06 +0000 (UTC) Received: from red.redhat.com (ovpn-124-155.rdu2.redhat.com [10.10.124.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C42C6F122; Wed, 23 Aug 2017 16:34:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7D40C2027B Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 11:33:48 -0500 Message-Id: <20170823163349.11663-6-eblake@redhat.com> In-Reply-To: <20170823163349.11663-1-eblake@redhat.com> References: <20170823163349.11663-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 23 Aug 2017 16:34:06 +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 5/6] qemu-iotests: add 194 non-shared storage migration test 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: Kevin Wolf , "open list:Block layer core" , Stefan Hajnoczi , Max Reitz 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: Stefan Hajnoczi Non-shared storage migration with NBD and drive-mirror is currently not tested by qemu-iotests. This test case covers the basic migration scenario. Signed-off-by: Stefan Hajnoczi Based-on: <20170823134242.12080-1-famz@redhat.com> Message-Id: <20170823140506.28723-1-stefanha@redhat.com> Tested-by: Eric Blake Signed-off-by: Eric Blake --- tests/qemu-iotests/194 | 73 +++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/194.out | 13 ++++++++ tests/qemu-iotests/group | 1 + tests/qemu-iotests/iotests.py | 13 ++++++++ 4 files changed, 100 insertions(+) create mode 100755 tests/qemu-iotests/194 create mode 100644 tests/qemu-iotests/194.out diff --git a/tests/qemu-iotests/194 b/tests/qemu-iotests/194 new file mode 100755 index 0000000000..8028111e21 --- /dev/null +++ b/tests/qemu-iotests/194 @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Creator/Owner: Stefan Hajnoczi +# +# Non-shared storage migration test using NBD server and drive-mirror + +import os +import atexit +import iotests + +iotests.verify_platform(['linux']) + +img_size =3D '1G' +source_img_path =3D os.path.join(iotests.test_dir, 'source.img') +dest_img_path =3D os.path.join(iotests.test_dir, 'dest.img') +iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, source_img_path, img= _size) +iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, dest_img_path, img_s= ize) + +iotests.log('Launching VMs...') +migration_sock_path =3D os.path.join(iotests.test_dir, 'migration.sock') +nbd_sock_path =3D os.path.join(iotests.test_dir, 'nbd.sock') +source_vm =3D iotests.VM('source').add_drive(source_img_path) +dest_vm =3D (iotests.VM('dest').add_drive(dest_img_path) + .add_incoming('unix:{0}'.format(migration_soc= k_path))) +source_vm.launch() +atexit.register(source_vm.shutdown) +dest_vm.launch() +atexit.register(dest_vm.shutdown) + +iotests.log('Launching NBD server on destination...') +iotests.log(dest_vm.qmp('nbd-server-start', addr=3D{'type': 'unix', 'data'= : {'path': nbd_sock_path}})) +iotests.log(dest_vm.qmp('nbd-server-add', device=3D'drive0', writable=3DTr= ue)) + +iotests.log('Starting drive-mirror on source...') +iotests.log(source_vm.qmp( + 'drive-mirror', + device=3D'drive0', + target=3D'nbd+unix:///drive0?socket=3D{0}'.format(nbd_sock_p= ath), + sync=3D'full', + format=3D'raw', # always raw, the server handles the format + mode=3D'existing')) + +iotests.log('Waiting for drive-mirror to complete...') +iotests.log(source_vm.event_wait('BLOCK_JOB_READY'), + filters=3D[iotests.filter_qmp_event]) + +iotests.log('Starting migration...') +source_vm.qmp('migrate-set-capabilities', + capabilities=3D[{'capability': 'events', 'state': True}]) +dest_vm.qmp('migrate-set-capabilities', + capabilities=3D[{'capability': 'events', 'state': True}]) +iotests.log(source_vm.qmp('migrate', uri=3D'unix:{0}'.format(migration_soc= k_path))) + +while True: + event =3D source_vm.event_wait('MIGRATION') + iotests.log(event, filters=3D[iotests.filter_qmp_event]) + if event['data']['status'] in ('completed', 'failed'): + break diff --git a/tests/qemu-iotests/194.out b/tests/qemu-iotests/194.out new file mode 100644 index 0000000000..ae501fecac --- /dev/null +++ b/tests/qemu-iotests/194.out @@ -0,0 +1,13 @@ +Launching VMs... +Launching NBD server on destination... +{u'return': {}} +{u'return': {}} +Starting drive-mirror on source... +{u'return': {}} +Waiting for drive-mirror to complete... +{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'device': u'drive0', u'type': u'mirror', u'speed': 0, u'len': 1073741824, u= 'offset': 1073741824}, u'event': u'BLOCK_JOB_READY'} +Starting migration... +{u'return': {}} +{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'setup'}, u'event': u'MIGRATION'} +{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'active'}, u'event': u'MIGRATION'} +{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'completed'}, u'event': u'MIGRATION'} diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index afbdc427ea..4bd5017008 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -187,3 +187,4 @@ 189 rw auto 190 rw auto quick 192 rw auto quick +194 rw auto migration quick diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 22439c43d3..7233983f3c 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -133,6 +133,14 @@ chown_re =3D re.compile(r"chown [0-9]+:[0-9]+") def filter_chown(msg): return chown_re.sub("chown UID:GID", msg) +def filter_qmp_event(event): + '''Filter a QMP event dict''' + event =3D dict(event) + if 'timestamp' in event: + event['timestamp']['seconds'] =3D 'SECS' + event['timestamp']['microseconds'] =3D 'USECS' + return event + def log(msg, filters=3D[]): for flt in filters: msg =3D flt(msg) @@ -200,6 +208,11 @@ class VM(qtest.QEMUQtestMachine): self._args.append(','.join(opts)) return self + def add_incoming(self, addr): + self._args.append('-incoming') + self._args.append(addr) + return self + def pause_drive(self, drive, event=3DNone): '''Pause drive r/w operations''' if not event: --=20 2.13.5 From nobody Sun May 5 10:37:10 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.zohomail.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 1503506855767274.4496946263025; Wed, 23 Aug 2017 09:47:35 -0700 (PDT) Received: from localhost ([::1]:44795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYoY-0004fF-Ha for importer@patchew.org; Wed, 23 Aug 2017 12:47:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYbh-00006r-32 for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkYbf-0005Ut-SE for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:34:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48794) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkYbY-0005Rh-Pj; Wed, 23 Aug 2017 12:34:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1C085F73B; Wed, 23 Aug 2017 16:34:07 +0000 (UTC) Received: from red.redhat.com (ovpn-124-155.rdu2.redhat.com [10.10.124.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id B92836F11B; Wed, 23 Aug 2017 16:34:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C1C085F73B Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 11:33:49 -0500 Message-Id: <20170823163349.11663-7-eblake@redhat.com> In-Reply-To: <20170823163349.11663-1-eblake@redhat.com> References: <20170823163349.11663-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 23 Aug 2017 16:34: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 6/6] nbd-client: avoid spurious qio_channel_yield() re-entry 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: Kevin Wolf , Paolo Bonzini , "open list:Network Block Dev..." , Stefan Hajnoczi , Max Reitz 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: Stefan Hajnoczi The following scenario leads to an assertion failure in qio_channel_yield(): 1. Request coroutine calls qio_channel_yield() successfully when sending would block on the socket. It is now yielded. 2. nbd_read_reply_entry() calls nbd_recv_coroutines_enter_all() because nbd_receive_reply() failed. 3. Request coroutine is entered and returns from qio_channel_yield(). Note that the socket fd handler has not fired yet so ioc->write_coroutine is still set. 4. Request coroutine attempts to send the request body with nbd_rwv() but the socket would still block. qio_channel_yield() is called again and assert(!ioc->write_coroutine) is hit. The problem is that nbd_read_reply_entry() does not distinguish between request coroutines that are waiting to receive a reply and those that are not. This patch adds a per-request bool receiving flag so nbd_read_reply_entry() can avoid spurious aio_wake() calls. Reported-by: Dr. David Alan Gilbert Signed-off-by: Stefan Hajnoczi Message-Id: <20170822125113.5025-1-stefanha@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy Tested-by: Eric Blake Reviewed-by: Paolo Bonzini Signed-off-by: Eric Blake --- block/nbd-client.h | 7 ++++++- block/nbd-client.c | 35 ++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/block/nbd-client.h b/block/nbd-client.h index 1935ffbcaa..b435754b82 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -17,6 +17,11 @@ #define MAX_NBD_REQUESTS 16 +typedef struct { + Coroutine *coroutine; + bool receiving; /* waiting for read_reply_co? */ +} NBDClientRequest; + typedef struct NBDClientSession { QIOChannelSocket *sioc; /* The master data channel */ QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) = */ @@ -27,7 +32,7 @@ typedef struct NBDClientSession { Coroutine *read_reply_co; int in_flight; - Coroutine *recv_coroutine[MAX_NBD_REQUESTS]; + NBDClientRequest requests[MAX_NBD_REQUESTS]; NBDReply reply; bool quit; } NBDClientSession; diff --git a/block/nbd-client.c b/block/nbd-client.c index 02c8e207ef..25bcaa2346 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -39,8 +39,10 @@ static void nbd_recv_coroutines_enter_all(NBDClientSessi= on *s) int i; for (i =3D 0; i < MAX_NBD_REQUESTS; i++) { - if (s->recv_coroutine[i]) { - aio_co_wake(s->recv_coroutine[i]); + NBDClientRequest *req =3D &s->requests[i]; + + if (req->coroutine && req->receiving) { + aio_co_wake(req->coroutine); } } } @@ -88,28 +90,28 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) * one coroutine is called until the reply finishes. */ i =3D HANDLE_TO_INDEX(s, s->reply.handle); - if (i >=3D MAX_NBD_REQUESTS || !s->recv_coroutine[i]) { + if (i >=3D MAX_NBD_REQUESTS || + !s->requests[i].coroutine || + !s->requests[i].receiving) { break; } - /* We're woken up by the recv_coroutine itself. Note that there + /* We're woken up again by the request itself. Note that there * is no race between yielding and reentering read_reply_co. This * is because: * - * - if recv_coroutine[i] runs on the same AioContext, it is only + * - if the request runs on the same AioContext, it is only * entered after we yield * - * - if recv_coroutine[i] runs on a different AioContext, reenteri= ng + * - if the request runs on a different AioContext, reentering * read_reply_co happens through a bottom half, which can only * run after we yield. */ - aio_co_wake(s->recv_coroutine[i]); + aio_co_wake(s->requests[i].coroutine); qemu_coroutine_yield(); } - if (ret < 0) { - s->quit =3D true; - } + s->quit =3D true; nbd_recv_coroutines_enter_all(s); s->read_reply_co =3D NULL; } @@ -128,14 +130,17 @@ static int nbd_co_send_request(BlockDriverState *bs, s->in_flight++; for (i =3D 0; i < MAX_NBD_REQUESTS; i++) { - if (s->recv_coroutine[i] =3D=3D NULL) { - s->recv_coroutine[i] =3D qemu_coroutine_self(); + if (s->requests[i].coroutine =3D=3D NULL) { break; } } g_assert(qemu_in_coroutine()); assert(i < MAX_NBD_REQUESTS); + + s->requests[i].coroutine =3D qemu_coroutine_self(); + s->requests[i].receiving =3D false; + request->handle =3D INDEX_TO_HANDLE(s, i); if (s->quit) { @@ -173,10 +178,13 @@ static void nbd_co_receive_reply(NBDClientSession *s, NBDReply *reply, QEMUIOVector *qiov) { + int i =3D HANDLE_TO_INDEX(s, request->handle); int ret; /* Wait until we're woken up by nbd_read_reply_entry. */ + s->requests[i].receiving =3D true; qemu_coroutine_yield(); + s->requests[i].receiving =3D false; *reply =3D s->reply; if (reply->handle !=3D request->handle || !s->ioc || s->quit) { reply->error =3D EIO; @@ -186,6 +194,7 @@ static void nbd_co_receive_reply(NBDClientSession *s, NULL); if (ret !=3D request->len) { reply->error =3D EIO; + s->quit =3D true; } } @@ -200,7 +209,7 @@ static void nbd_coroutine_end(BlockDriverState *bs, NBDClientSession *s =3D nbd_get_client_session(bs); int i =3D HANDLE_TO_INDEX(s, request->handle); - s->recv_coroutine[i] =3D NULL; + s->requests[i].coroutine =3D NULL; /* Kick the read_reply_co to get the next reply. */ if (s->read_reply_co) { --=20 2.13.5