From nobody Mon Feb 9 11:33:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.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 1502810039077125.77255089026573; Tue, 15 Aug 2017 08:13:59 -0700 (PDT) Received: from localhost ([::1]:40172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhdXZ-0007TU-Ok for importer@patchew.org; Tue, 15 Aug 2017 11:13:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhdTC-00048D-1G for qemu-devel@nongnu.org; Tue, 15 Aug 2017 11:09:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhdTB-0002cN-08 for qemu-devel@nongnu.org; Tue, 15 Aug 2017 11:09:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54530) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhdT6-0002Za-F2; Tue, 15 Aug 2017 11:09:20 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8AAE5C02C738; Tue, 15 Aug 2017 15:09:19 +0000 (UTC) Received: from red.redhat.com (ovpn-121-22.rdu2.redhat.com [10.10.121.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82A7B5D9CA; Tue, 15 Aug 2017 15:09:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8AAE5C02C738 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 15 Aug 2017 10:09:05 -0500 Message-Id: <20170815150907.21495-6-eblake@redhat.com> In-Reply-To: <20170815150907.21495-1-eblake@redhat.com> References: <20170815150907.21495-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 15 Aug 2017 15:09: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 5/7] block-backend: Defer shared_perm tightening migration completion 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 As in the case of nbd_export_new(), bdrv_invalidate_cache() can be called when migration is still in progress. In this case we are not ready to tighten the shared permissions fenced by blk->disable_perm. Defer to a VM state change handler. Signed-off-by: Fam Zheng Message-Id: <20170815130740.31229-4-famz@redhat.com> Signed-off-by: Eric Blake --- block/block-backend.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 968438c149..e9798e897d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -20,6 +20,7 @@ #include "qapi-event.h" #include "qemu/id.h" #include "trace.h" +#include "migration/misc.h" /* Number of coroutines to reserve per attached device model */ #define COROUTINE_POOL_RESERVATION 64 @@ -68,6 +69,7 @@ struct BlockBackend { NotifierList remove_bs_notifiers, insert_bs_notifiers; int quiesce_counter; + VMChangeStateEntry *vmsh; }; typedef struct BlockBackendAIOCB { @@ -129,6 +131,23 @@ static const char *blk_root_get_name(BdrvChild *child) return blk_name(child->opaque); } +static void blk_vm_state_changed(void *opaque, int running, RunState state) +{ + Error *local_err =3D NULL; + BlockBackend *blk =3D opaque; + + if (state =3D=3D RUN_STATE_INMIGRATE) { + return; + } + + qemu_del_vm_change_state_handler(blk->vmsh); + blk->vmsh =3D NULL; + blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err); + if (local_err) { + error_report_err(local_err); + } +} + /* * Notifies the user of the BlockBackend that migration has completed. qdev * devices can tighten their permissions in response (specifically revoke @@ -147,6 +166,24 @@ static void blk_root_activate(BdrvChild *child, Error = **errp) blk->disable_perm =3D false; + blk_set_perm(blk, blk->perm, BLK_PERM_ALL, &local_err); + if (local_err) { + error_propagate(errp, local_err); + blk->disable_perm =3D true; + return; + } + + if (runstate_check(RUN_STATE_INMIGRATE)) { + /* Activation can happen when migration process is still active, f= or + * example when nbd_server_add is called during non-shared storage + * migration. Defer the shared_perm update to migration completion= . */ + if (!blk->vmsh) { + blk->vmsh =3D qemu_add_vm_change_state_handler(blk_vm_state_ch= anged, + blk); + } + return; + } + blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err); if (local_err) { error_propagate(errp, local_err); @@ -291,6 +328,10 @@ static void blk_delete(BlockBackend *blk) if (blk->root) { blk_remove_bs(blk); } + if (blk->vmsh) { + qemu_del_vm_change_state_handler(blk->vmsh); + blk->vmsh =3D NULL; + } assert(QLIST_EMPTY(&blk->remove_bs_notifiers.notifiers)); assert(QLIST_EMPTY(&blk->insert_bs_notifiers.notifiers)); QTAILQ_REMOVE(&block_backends, blk, link); --=20 2.13.5