From nobody Mon Apr 29 18:36:29 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; dkim=fail; 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 1543591967803415.99133941456216; Fri, 30 Nov 2018 07:32:47 -0800 (PST) Received: from localhost ([::1]:33330 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkmc-0004De-Kx for importer@patchew.org; Fri, 30 Nov 2018 10:32:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51508) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZa-0007S4-CQ for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZY-0006Wi-6L for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:18 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53253) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZU-00062b-54; Fri, 30 Nov 2018 10:19:14 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYp-0007X8-5y; Fri, 30 Nov 2018 16:18:31 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003eA-Cn; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=TKCMVeQAc6YWJjYhVmIKWfmS8u/QzRdzMGShOgGuU9s=; b=FrwSfm8wATwx7vqQPzK4xyWsB2iCSsHQ+I7IXC6PQN5YpXhFhue4Rzp0CpRc5yj0A+4fvr56kdaqlBukW+0ZgRUtUkbK6R29EnztTQI5t3/mf5KtZN8iznjjA8zUpq1DdXF5uYnv89DflVzg2mRVHK+Tjy60PouOr0rgaqBB68s0PmNUjSTV+PKxNTeifB3OvFNiYX8itMecL2IaJfPwRZgpcqLBqkSbxyDgcQqYmN1vNX4CHEd+lz9atFiiqG1Cbe38xZ4mPQ4PFWzXpKpAKXcjXpqe3dBLnzfYGmFctxQh3PD6mm9uSSx+WKIJnVkjzRPqgpugrqYz3c5+4aOcjg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:39 +0200 Message-Id: <5ed36dbab081a599ba9dcbeb7d43aa101461450d.1543590618.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 01/12] block: Allow freezing BdrvChild links 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Our permission system is useful to define what operations are allowed on a certain block node and includes things like BLK_PERM_WRITE or BLK_PERM_RESIZE among others. One of the permissions is BLK_PERM_GRAPH_MOD which allows "changing the node that this BdrvChild points to". The exact meaning of this has never been very clear, but it can be understood as "change any of the links connected to the node". This can be used to prevent changing a backing link, but it's too coarse. This patch adds a new 'frozen' attribute to BdrvChild, which forbids detaching the link from the node it points to, and new API to freeze and unfreeze a backing chain. Signed-off-by: Alberto Garcia --- block.c | 62 +++++++++++++++++++++++++++++++++++++++++++= ++++ include/block/block.h | 5 ++++ include/block/block_int.h | 5 ++++ 3 files changed, 72 insertions(+) diff --git a/block.c b/block.c index 4f5ff2cc12..4f55fb339a 100644 --- a/block.c +++ b/block.c @@ -2062,6 +2062,8 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, BlockDriverState *old_bs =3D child->bs; int i; =20 + assert(!child->frozen); + if (old_bs && new_bs) { assert(bdrv_get_aio_context(old_bs) =3D=3D bdrv_get_aio_context(ne= w_bs)); } @@ -2278,6 +2280,10 @@ void bdrv_set_backing_hd(BlockDriverState *bs, Block= DriverState *backing_hd, bool update_inherits_from =3D bdrv_chain_contains(bs, backing_hd) && bdrv_inherits_from_recursive(backing_hd, bs); =20 + if (bdrv_is_backing_chain_frozen(bs, backing_bs(bs), errp)) { + return; + } + if (backing_hd) { bdrv_ref(backing_hd); } @@ -3812,6 +3818,58 @@ BlockDriverState *bdrv_find_base(BlockDriverState *b= s) return bdrv_find_overlay(bs, NULL); } =20 +/* Return true if at least one of the backing links between @bs and + * @base is frozen. @errp is set if that's the case. */ +bool bdrv_is_backing_chain_frozen(BlockDriverState *bs, BlockDriverState *= base, + Error **errp) +{ + BlockDriverState *i; + + for (i =3D bs; i !=3D base && i->backing; i =3D backing_bs(i)) { + if (i->backing->frozen) { + error_setg(errp, "Cannot remove link from '%s' to '%s'", + i->node_name, backing_bs(i)->node_name); + return true; + } + } + + return false; +} + +/* + * Freeze all backing links between @bs and @base. + * If any of the links is already frozen the operation is aborted and + * none of the links are modified. + * Returns 0 on success. On failure returns < 0 and sets @errp. + */ +int bdrv_freeze_backing_chain(BlockDriverState *bs, BlockDriverState *base, + Error **errp) +{ + BlockDriverState *i; + + if (bdrv_is_backing_chain_frozen(bs, base, errp)) { + return -EPERM; + } + + for (i =3D bs; i !=3D base && i->backing; i =3D backing_bs(i)) { + i->backing->frozen =3D true; + } + + return 0; +} + +/* Unfreeze all backing links between @bs and @base. The caller must + * ensure that all links are frozen before using this function. */ +void bdrv_unfreeze_backing_chain(BlockDriverState *bs, BlockDriverState *b= ase) +{ + BlockDriverState *i; + + for (i =3D bs; i !=3D base && i->backing; i =3D backing_bs(i)) { + assert(i->backing->frozen); + i->backing->frozen =3D false; + } +} + /* * Drops images above 'base' up to and including 'top', and sets the image * above 'top' to have base as its backing file. @@ -3861,6 +3919,10 @@ int bdrv_drop_intermediate(BlockDriverState *top, Bl= ockDriverState *base, goto exit; } =20 + if (bdrv_is_backing_chain_frozen(top, base, NULL)) { + goto exit; + } + /* If 'base' recursively inherits from 'top' then we should set * base->inherits_from to top->inherits_from after 'top' and all * other intermediate nodes have been dropped. diff --git a/include/block/block.h b/include/block/block.h index f70a843b72..6f10a8fcfc 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -353,6 +353,11 @@ int bdrv_drop_intermediate(BlockDriverState *top, Bloc= kDriverState *base, BlockDriverState *bdrv_find_overlay(BlockDriverState *active, BlockDriverState *bs); BlockDriverState *bdrv_find_base(BlockDriverState *bs); +bool bdrv_is_backing_chain_frozen(BlockDriverState *bs, BlockDriverState *= base, + Error **errp); +int bdrv_freeze_backing_chain(BlockDriverState *bs, BlockDriverState *base, + Error **errp); +void bdrv_unfreeze_backing_chain(BlockDriverState *bs, BlockDriverState *b= ase); =20 =20 typedef struct BdrvCheckResult { diff --git a/include/block/block_int.h b/include/block/block_int.h index f605622216..05d925227a 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -661,6 +661,11 @@ struct BdrvChild { */ uint64_t shared_perm; =20 + /** + * This link is frozen: the child cannot be detached from the parent. + */ + bool frozen; + QLIST_ENTRY(BdrvChild) next; QLIST_ENTRY(BdrvChild) next_parent; }; --=20 2.11.0 From nobody Mon Apr 29 18:36:29 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; dkim=fail; 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 1543591616206659.0270589751516; Fri, 30 Nov 2018 07:26:56 -0800 (PST) Received: from localhost ([::1]:33295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkgx-0005Es-3G for importer@patchew.org; Fri, 30 Nov 2018 10:26:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZa-0007S1-BY for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZW-0006WF-CI for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:18 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53240) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZU-00062T-52; Fri, 30 Nov 2018 10:19:14 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYp-0007XB-5r; Fri, 30 Nov 2018 16:18:31 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003eD-E2; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=+/4khAbQMeVy1KVoG0qdWT2tHAMnDkEkpa2xD6AjZPA=; b=g+61V9WMJp0caVBWAJaTxDy16ShEl1ppzHIb0O29+f9ga0ofqchUcMtaPu9AJfJj8BzckwXtt7X6yJ98yCyTfgiqH8GIvwSuBXuhW84L+Wb+zNp6Pou5vMVHmh/6CLKl0f+GYroLliEnAxbrlvHPb33xULn8B/Rjr8Y5b5udCpNxGCHWSbn6EJYyXSG6J6tlJTSkr9ntNGvHPCbQqF8eHaC1qyksH9kybKnuroFvtGCOavgPp6VCYdaBwrvn3+EGLcK6gl+Cm+zsAU4cCUHBl0HW2qkpu1BB9wOCOfB110y7RhtP6DYbDDqxVlinF49kXmiRLTVIAHFOIJrPd4VQhA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:40 +0200 Message-Id: <3a01a1e6b2d21077f92cb880c9f6600d278b4aed.1543590618.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 02/12] block: Freeze the backing chain for the duration of the commit job 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Alberto Garcia --- block/commit.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/commit.c b/block/commit.c index 53148e610b..8824d135e0 100644 --- a/block/commit.c +++ b/block/commit.c @@ -73,6 +73,8 @@ static int commit_prepare(Job *job) { CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); =20 + bdrv_unfreeze_backing_chain(s->commit_top_bs, s->base_bs); + /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before * the normal backing chain can be restored. */ blk_unref(s->base); @@ -89,6 +91,8 @@ static void commit_abort(Job *job) CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); BlockDriverState *top_bs =3D blk_bs(s->top); =20 + bdrv_unfreeze_backing_chain(s->commit_top_bs, s->base_bs); + /* Make sure commit_top_bs and top stay around until bdrv_replace_node= () */ bdrv_ref(top_bs); bdrv_ref(s->commit_top_bs); @@ -336,6 +340,10 @@ void commit_start(const char *job_id, BlockDriverState= *bs, } } =20 + if (bdrv_freeze_backing_chain(commit_top_bs, base, errp) < 0) { + goto fail; + } + ret =3D block_job_add_bdrv(&s->common, "base", base, 0, BLK_PERM_ALL, = errp); if (ret < 0) { goto fail; --=20 2.11.0 From nobody Mon Apr 29 18:36:29 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543592035120966.181354340428; Fri, 30 Nov 2018 07:33:55 -0800 (PST) Received: from localhost ([::1]:33334 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSknO-00051x-1u for importer@patchew.org; Fri, 30 Nov 2018 10:33:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZa-0007SB-Cz for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZW-0006WB-C0 for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:18 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53245) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZU-00062Y-4w; Fri, 30 Nov 2018 10:19:14 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYp-0007XA-7B; Fri, 30 Nov 2018 16:18:31 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003eF-F6; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=dgl0Y/tkCf6OXswtvwf5rQuqlmWjkTxTgj/7Pur5HyE=; b=TRW7Nf2jcjAv7GHmt//y5HpoNGnEDAvD7dFO6+/rGZdhUDf+m/1a+/FH7HvplVYcTpn57wOUwCNZx3H9KePrcyvCPyieqwZhGXjPaPo87EDti8PA30dGbV+RuY8ZahBKI3eZvUWE7HwCtMyRDw6LWhk5HQ7phZ9ew1KtlHSDwWgGX8pU5VEjKAM8n3f80QyIm+dHDJ+8vVmyWcZjLMN1TDLkHoTg0ZGyH88Oa0hXCz1rl7BFtCE3Qfns1Bze2pnS72fTJsIqb7A6tH3QGNxfT0Dv3NUNvmih6tRwXu1Qs6As/NpMa/1dc9ipu5sUyr9XUrVwY+TUkgu3IwsaUPnQFw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:41 +0200 Message-Id: <21ebfe2fbdefe991b4d2a367410c477085c3ac05.1543590618.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 03/12] block: Freeze the backing chain for the duration of the mirror job 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Alberto Garcia --- block/mirror.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/mirror.c b/block/mirror.c index f746618224..944ece83ed 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -631,6 +631,10 @@ static int mirror_exit_common(Job *job) } s->prepared =3D true; =20 + if (bdrv_chain_contains(src, target_bs)) { + bdrv_unfreeze_backing_chain(mirror_top_bs, target_bs); + } + bdrv_release_dirty_bitmap(src, s->dirty_bitmap); =20 /* Make sure that the source BDS doesn't go away during bdrv_replace_n= ode, @@ -1641,6 +1645,10 @@ static void mirror_start_job(const char *job_id, Blo= ckDriverState *bs, goto fail; } } + + if (bdrv_freeze_backing_chain(mirror_top_bs, target, errp) < 0) { + goto fail; + } } =20 QTAILQ_INIT(&s->ops_in_flight); --=20 2.11.0 From nobody Mon Apr 29 18:36:29 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; dkim=fail; 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 1543591656821344.04982263514194; Fri, 30 Nov 2018 07:27:36 -0800 (PST) Received: from localhost ([::1]:33299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkhb-00061x-Lq for importer@patchew.org; Fri, 30 Nov 2018 10:27:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZa-0007SE-Cp for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZW-0006Vl-9c for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:18 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53238) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZU-00062U-47; Fri, 30 Nov 2018 10:19:14 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYp-0007XC-6L; Fri, 30 Nov 2018 16:18:31 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003eI-G4; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=e0GUrF7JL82rFLYaMP6oxS+DoRuyZI2A+aRkyKp9Afg=; b=Ctiw9wt2KHXeLE+BYOErTldOuWQkgRzu6ccjbaRTu/vXCv6i+kmsnTL75u0LJu6FOfCR/pltK/YDgoy8i7RpaYh6SIUSAibUmqHI8GfCFpWypIgRZHRph/lq2yNTgsbpK4P+asEJy/3QTLKUfX6dIFxXRnob1XDyUh4gNFkV8VRW51If/DIYuLWnqMl3+IAWPtGWurUWDr3voHWAxQYdYAQfGbCULboDJumutt3IDjHKJSUSFDHUn5EndKpHX+vgQqdVAzwd30aCe2KZcseFiBo2Ye77qbDnOLSyE6L/ONcHgF1slGBGPX4CpvC63yWRA1AO4G5XDil4JdJ3vL9d1A==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:42 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 04/12] block: Freeze the backing chain for the duration of the stream job 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Alberto Garcia --- block/stream.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/block/stream.c b/block/stream.c index 7a49ac0992..39a2e10892 100644 --- a/block/stream.c +++ b/block/stream.c @@ -54,6 +54,14 @@ static int coroutine_fn stream_populate(BlockBackend *bl= k, return blk_co_preadv(blk, offset, qiov.size, &qiov, BDRV_REQ_COPY_ON_R= EAD); } =20 +static void stream_abort(Job *job) +{ + StreamBlockJob *s =3D container_of(job, StreamBlockJob, common.job); + BlockJob *bjob =3D &s->common; + + bdrv_unfreeze_backing_chain(blk_bs(bjob->blk), s->base); +} + static int stream_prepare(Job *job) { StreamBlockJob *s =3D container_of(job, StreamBlockJob, common.job); @@ -63,6 +71,8 @@ static int stream_prepare(Job *job) Error *local_err =3D NULL; int ret =3D 0; =20 + bdrv_unfreeze_backing_chain(bs, base); + if (bs->backing) { const char *base_id =3D NULL, *base_fmt =3D NULL; if (base) { @@ -213,6 +223,7 @@ static const BlockJobDriver stream_job_driver =3D { .free =3D block_job_free, .run =3D stream_run, .prepare =3D stream_prepare, + .abort =3D stream_abort, .clean =3D stream_clean, .user_resume =3D block_job_user_resume, .drain =3D block_job_drain, @@ -259,6 +270,11 @@ void stream_start(const char *job_id, BlockDriverState= *bs, &error_abort); } =20 + if (bdrv_freeze_backing_chain(bs, base, errp) < 0) { + job_early_fail(&s->common.job); + goto fail; + } + s->base =3D base; s->backing_file_str =3D g_strdup(backing_file_str); s->bs_read_only =3D bs_read_only; --=20 2.11.0 From nobody Mon Apr 29 18:36:29 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; dkim=fail; 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 154359182096810.92646716049228; Fri, 30 Nov 2018 07:30:20 -0800 (PST) Received: from localhost ([::1]:33311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkkF-00029o-O3 for importer@patchew.org; Fri, 30 Nov 2018 10:30:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZa-0007SF-DC for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZW-0006Vx-Bp for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:18 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53248) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZU-00062c-4p; Fri, 30 Nov 2018 10:19:14 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYp-0007X9-5r; Fri, 30 Nov 2018 16:18:31 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003eL-Gw; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=tTHYG0e/tD19hTeauUIIFufxkypWiO++eQ40YYkfcZ8=; b=aGJF0/FslrVUPmeL7tr4+T3p6fv2Ioe87OsMsrAcV088W9XPC4LBWWmpkaKkqqVgbUNsduLZQcw/zWjg/4SqjMdAA5j+BxAEapxyn1worCcgCSXz6krkhFzbNL/JQUczL8UqyxI8/Bnhf8Dua6RFfvue/yjeVE2mANBFSnwHeFGJXeeWkOKuvjJWDn7ZSXuqbw3PF9Ex+91zaXoZtseLzuIiEL0FC9DP1W3alK5ULzkab7+ug1asyKJjNqI/mEiBhSkRXNUpV7wamIjjt5A5g97mgPimwUJ6YV6+L87OlGAZG4a4jnaGJTme7tzyznzpqM8j+2BZuffpkYBeRmDUpA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:43 +0200 Message-Id: <7547fa10fe3bbbda2919ba5499e00cfcb223aa2b.1543590618.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 05/12] block: Add 'keep_old_opts' parameter to bdrv_reopen_queue() 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The bdrv_reopen_queue() function is used to create a queue with the BDSs that are going to be reopened and their new options. Once the queue is ready bdrv_reopen_multiple() is called to perform the operation. The original options from each one of the BDSs are kept, with the new options passed to bdrv_reopen_queue() applied on top of them. For "x-blockdev-reopen" we want a function that behaves much like "blockdev-add". We want to ignore the previous set of options so that only the ones actually specified by the user are applied, with the rest having their default values. One of the things that we need is a way to tell bdrv_reopen_queue() whether we want to keep the old set of options or not, and that's what this patch does. All current callers are setting this new parameter to true and x-blockdev-reopen will set it to false. Signed-off-by: Alberto Garcia --- block.c | 34 +++++++++++++++++++--------------- block/replication.c | 4 ++-- include/block/block.h | 3 ++- qemu-io-cmds.c | 2 +- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/block.c b/block.c index 4f55fb339a..da4e062178 100644 --- a/block.c +++ b/block.c @@ -2935,7 +2935,8 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, QDict *options, const BdrvChildRole *role, QDict *parent_options, - int parent_flags) + int parent_flags, + bool keep_old_opts) { assert(bs !=3D NULL); =20 @@ -2975,13 +2976,13 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bl= ockReopenQueue *bs_queue, */ =20 /* Old explicitly set values (don't overwrite by inherited value) */ - if (bs_entry) { - old_options =3D qdict_clone_shallow(bs_entry->state.explicit_optio= ns); - } else { - old_options =3D qdict_clone_shallow(bs->explicit_options); + if (bs_entry || keep_old_opts) { + old_options =3D qdict_clone_shallow(bs_entry ? + bs_entry->state.explicit_options= : + bs->explicit_options); + bdrv_join_options(bs, options, old_options); + qobject_unref(old_options); } - bdrv_join_options(bs, options, old_options); - qobject_unref(old_options); =20 explicit_options =3D qdict_clone_shallow(options); =20 @@ -2993,10 +2994,12 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bl= ockReopenQueue *bs_queue, flags =3D bdrv_get_flags(bs); } =20 - /* Old values are used for options that aren't set yet */ - old_options =3D qdict_clone_shallow(bs->options); - bdrv_join_options(bs, options, old_options); - qobject_unref(old_options); + if (keep_old_opts) { + /* Old values are used for options that aren't set yet */ + old_options =3D qdict_clone_shallow(bs->options); + bdrv_join_options(bs, options, old_options); + qobject_unref(old_options); + } =20 /* We have the final set of options so let's update the flags */ options_copy =3D qdict_clone_shallow(options); @@ -3046,7 +3049,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, g_free(child_key_dot); =20 bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, - child->role, options, flags); + child->role, options, flags, keep_old_opts= ); } =20 return bs_queue; @@ -3054,9 +3057,10 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Blo= ckReopenQueue *bs_queue, =20 BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, - QDict *options) + QDict *options, bool keep_old_opts) { - return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, NULL, 0); + return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, NULL, 0, + keep_old_opts); } =20 /* @@ -3128,7 +3132,7 @@ int bdrv_reopen_set_read_only(BlockDriverState *bs, b= ool read_only, qdict_put_bool(opts, BDRV_OPT_READ_ONLY, read_only); =20 bdrv_subtree_drained_begin(bs); - queue =3D bdrv_reopen_queue(NULL, bs, opts); + queue =3D bdrv_reopen_queue(NULL, bs, opts, true); ret =3D bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, errp); bdrv_subtree_drained_end(bs); =20 diff --git a/block/replication.c b/block/replication.c index fdbfe47fa4..027cc02542 100644 --- a/block/replication.c +++ b/block/replication.c @@ -396,14 +396,14 @@ static void reopen_backing_file(BlockDriverState *bs,= bool writable, QDict *opts =3D qdict_new(); qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); reopen_queue =3D bdrv_reopen_queue(reopen_queue, s->hidden_disk->b= s, - opts); + opts, true); } =20 if (s->orig_secondary_read_only) { QDict *opts =3D qdict_new(); qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); reopen_queue =3D bdrv_reopen_queue(reopen_queue, s->secondary_disk= ->bs, - opts); + opts, true); } =20 if (reopen_queue) { diff --git a/include/block/block.h b/include/block/block.h index 6f10a8fcfc..a061ef3944 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -299,7 +299,8 @@ BlockDriverState *bdrv_open(const char *filename, const= char *reference, BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_= name, int flags, Error **errp); BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, - BlockDriverState *bs, QDict *options); + BlockDriverState *bs, QDict *options, + bool keep_old_opts); int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Erro= r **errp); int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 2c39124036..db8887205e 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -2075,7 +2075,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) } =20 bdrv_subtree_drained_begin(bs); - brq =3D bdrv_reopen_queue(NULL, bs, opts); + brq =3D bdrv_reopen_queue(NULL, bs, opts, true); bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err); bdrv_subtree_drained_end(bs); =20 --=20 2.11.0 From nobody Mon Apr 29 18:36:29 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; dkim=fail; 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 1543591786370513.0392653985599; Fri, 30 Nov 2018 07:29:46 -0800 (PST) Received: from localhost ([::1]:33308 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkjg-0000qF-T0 for importer@patchew.org; Fri, 30 Nov 2018 10:29:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZa-0007S3-CL for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZW-0006Va-8Y for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:18 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53250) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZU-00062Z-1I; Fri, 30 Nov 2018 10:19:12 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYp-0007XD-4F; Fri, 30 Nov 2018 16:18:31 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003eO-I6; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=DVQYrdiVdKT3JauIXY0Wq3Ez5mZk89LUsYDy0o6GKL8=; b=iAqgUxlfpMO321NJbW2kQ5LnmHTHMSIE1Y0/Y6f9C6yAncQ4xb5/dK1bhcwGLMaMgigP7M9ex5pOkGU5pJkAGRg3kKdOONuNJfYs5HLqOjgwTvJetmblfaTwnjiTqfKveqWo71DfD5KCOXVXFIbp+SF0cjVyw2jnv1AGzdqH2uAmRhOf7u1q2EC++YguqmexF3fdyCbekuginFTsfu+vH75zCmeLJ9oA6iAUd8D8FWjz5O/3jxbz4lpsulNePKxyXVY0noh0880MvgnLd8eVYFTcstmmAcclsEHKFBtEPLzGBRbKwTXwmGm8IQgZAvaUcEdgT/NCBX14jG+43G33PA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:44 +0200 Message-Id: <8f88f59eee7e9b7882fc4f6d0e6ff57bd8754375.1543590618.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 06/12] block: Handle child references in bdrv_reopen_queue() 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Children in QMP are specified with BlockdevRef / BlockdevRefOrNull, which can contain a set of child options, a child reference, or NULL. In optional attributes like "backing" it can also be missing. Only the first case (set of child options) is being handled properly by bdrv_reopen_queue(). This patch deals with all the others. Here's how these cases should be handled when bdrv_reopen_queue() is deciding what to do with each child of a BlockDriverState: 1) Set of child options: the options are removed from the parent's options QDict and are passed to the child with a recursive bdrv_reopen_queue() call. This case was already working fine. 2) Child reference: there's two possibilites here. 2a) Reference to the current child: the child is put in the reopen queue, keeping its current set of options (since this was a child reference there was no way to specify a different set of options). 2b) Reference to a different BDS: the current child is not put in the reopen queue at all. Passing a reference to a different BDS can be used to replace a child, although at the moment no driver implements this, so it results in an error. In any case, the current child is not going to be reopened (and might in fact disappear if it's replaced) 3) NULL: This is similar to (2b). Although no driver allows this yet it can be used to detach the current child so it should not be put in the reopen queue. 4) Missing option: at the moment "backing" is the only case where this can happen. With "blockdev-add", leaving "backing" out means that the default backing file is opened. We don't want to open a new image during reopen, so we require that "backing" is always present. We'll relax this requirement a bit in the next patch. Signed-off-by: Alberto Garcia --- block.c | 45 ++++++++++++++++++++++++++++++++++++++------- include/block/block.h | 1 + 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index da4e062178..4a2f81b129 100644 --- a/block.c +++ b/block.c @@ -3032,9 +3032,19 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Blo= ckReopenQueue *bs_queue, bs_entry->state.perm =3D UINT64_MAX; bs_entry->state.shared_perm =3D 0; =20 + /* If keep_old_opts is false then it means that unspecified + * options must be reset to its original value. We don't allow + * resetting 'backing' but we need to know if the option is + * missing in order to decide if we have to return an error. */ + if (!keep_old_opts) { + bs_entry->state.backing_missing =3D + !qdict_haskey(options, "backing") && + !qdict_haskey(options, "backing.driver"); + } + QLIST_FOREACH(child, &bs->children, next) { - QDict *new_child_options; - char *child_key_dot; + QDict *new_child_options =3D NULL; + bool child_keep_old =3D keep_old_opts; =20 /* reopen can only change the options of block devices that were * implicitly created and inherited options. For other (referenced) @@ -3043,13 +3053,27 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bl= ockReopenQueue *bs_queue, continue; } =20 - child_key_dot =3D g_strdup_printf("%s.", child->name); - qdict_extract_subqdict(explicit_options, NULL, child_key_dot); - qdict_extract_subqdict(options, &new_child_options, child_key_dot); - g_free(child_key_dot); + /* Check if the options contain a child reference */ + if (qdict_haskey(options, child->name)) { + const char *childref =3D qdict_get_try_str(options, child->nam= e); + /* The current child must not be reopened if the child + * reference does not point to it. */ + if (g_strcmp0(childref, child->bs->node_name)) { + continue; + } + /* If the child reference points to the current child then + * reopen it with its existing set of options. */ + child_keep_old =3D true; + } else { + /* Extract child options ("child-name.*") */ + char *child_key_dot =3D g_strdup_printf("%s.", child->name); + qdict_extract_subqdict(explicit_options, NULL, child_key_dot); + qdict_extract_subqdict(options, &new_child_options, child_key_= dot); + g_free(child_key_dot); + } =20 bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, - child->role, options, flags, keep_old_opts= ); + child->role, options, flags, child_keep_ol= d); } =20 return bs_queue; @@ -3306,6 +3330,13 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_stat= e, BlockReopenQueue *queue, =20 drv_prepared =3D true; =20 + if (reopen_state->backing_missing) { + error_setg(errp, "backing is missing for '%s'", + reopen_state->bs->node_name); + ret =3D -EINVAL; + goto error; + } + /* Options that are not handled are only okay if they are unchanged * compared to the old state. It is expected that some options are only * used for the initial open, but not reopen (e.g. filename) */ diff --git a/include/block/block.h b/include/block/block.h index a061ef3944..e21616a038 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -187,6 +187,7 @@ typedef struct BDRVReopenState { BlockDriverState *bs; int flags; BlockdevDetectZeroesOptions detect_zeroes; + bool backing_missing; uint64_t perm, shared_perm; QDict *options; QDict *explicit_options; --=20 2.11.0 From nobody Mon Apr 29 18:36:29 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; dkim=fail; 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 1543591776944987.9661487118915; Fri, 30 Nov 2018 07:29:36 -0800 (PST) Received: from localhost ([::1]:33307 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkjX-0000ah-Jn for importer@patchew.org; Fri, 30 Nov 2018 10:29:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51505) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZa-0007S2-Br for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZW-0006Vz-Ba for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:18 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53236) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZU-00062X-52; Fri, 30 Nov 2018 10:19:14 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYp-0007XE-60; Fri, 30 Nov 2018 16:18:31 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003eT-JE; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=CuPIpHcPpLuIgJjmVWnd2l0bSibdcfbLMjDkBkkdbr4=; b=ClTCi4EKWmCu6W2f8buIJ9DYOz14ANQIXzpRvb/ZxZUC090fVc1cm0KqNPZQ+41+NifAoUugIH7m3Y1TPGk1bzSPt/wyuKyKFt767BAVFhz/lI+SWbqUG4W5KD0Uy9mS23iwbJEOpexpM0meAIReVx9fgOJszADHw/xegmXo6se9rxGqKWwIwbe5GT6kPAmKcZkIPjlzGY4rR1iZISVU2zIuuRAfqfR8vUAWw3hfjv7aTgrw/cwjRzdGqn3pKZZu2CgN0ua1YYhbLSkGJIGWMmoR3LvBXNtaEsOmx5W99BP3qztXDWyPosRHSk1slvivNetSa16GfiUXAq3mGCP36A==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:45 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 07/12] block: Allow omitting the 'backing' option in certain 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Of all options of type BlockdevRef used to specify children in BlockdevOptions, 'backing' is the only one that is optional. For "x-blockdev-reopen" we want that if an option is omitted then it must be reset to its default value. The default value of 'backing' means that QEMU opens the backing file specified in the image metadata, but this is not something that we want to support for the reopen operation. Because of this the 'backing' option has to be specified during reopen, pointing to the existing backing file if we want to keep it, or pointing to a different one (or NULL) if we want to replace it (to be implemented in a subsequent patch). In order to simplify things a bit and not to require that the user passes the 'backing' option to every single block device even when it's clearly not necessary, this patch allows omitting this option if the block device being reopened doesn't have a backing file attached _and_ no default backing file is specified in the image metadata. Signed-off-by: Alberto Garcia --- block.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 4a2f81b129..5ecdbbac9e 100644 --- a/block.c +++ b/block.c @@ -3330,7 +3330,11 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_stat= e, BlockReopenQueue *queue, =20 drv_prepared =3D true; =20 - if (reopen_state->backing_missing) { + /* We must provide the 'backing' option if the BDS has a backing + * file or if the image file has a backing file name as part of + * its metadata. Otherwise the 'backing' option can be omitted. */ + if (reopen_state->backing_missing && + (backing_bs(reopen_state->bs) || reopen_state->bs->backing_file[0]= )) { error_setg(errp, "backing is missing for '%s'", reopen_state->bs->node_name); ret =3D -EINVAL; --=20 2.11.0 From nobody Mon Apr 29 18:36:29 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; dkim=fail; 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543592389315694.6083946931373; Fri, 30 Nov 2018 07:39:49 -0800 (PST) Received: from localhost ([::1]:33386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSktG-0003No-IW for importer@patchew.org; Fri, 30 Nov 2018 10:39:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZa-0007S9-Ci for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZY-0006Wm-6G for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:18 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53249) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZU-00062W-4y; Fri, 30 Nov 2018 10:19:14 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYp-0007XG-4M; Fri, 30 Nov 2018 16:18:31 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003eW-K9; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=vfOn7LrIPrUtIqwPybHPPVH5CxL4TEgXyWwWtzaWwR4=; b=Q3gIfvPYfjFmBZsL2j/jDjeGV50+nEL2la+hTFK78TF1PA1T7OivTXm8fpfK22dQyYRM0On65NKD3Ed6OkimxKFg7wb4edMhJ29nNmiG2ctmPPVOrrymdomdZ+aPhwUCaARbMEnjfV1pzmY2nYvEwnFiCTRCx03b49Wbn/bDJcguqGQN/hpuEG4jlthgqkMGf+AAey3PPd+WXN2U/wfems+EbMOAau8rwLULul5oSP7osMnEW4PaMxZFecfQMLVjP1Hf/4fEb265ROlpMJm/QQP5s7YCCYsOXVcBkUWPtWraLT//rFiBFTWSWNH/TJ4ZjY4qlqAyxS4EvCRWih6F9A==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:46 +0200 Message-Id: <290118caaf7b7247cf2d29e47041af0cf09c4835.1543590618.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 08/12] block: Allow changing the backing file on reopen 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch allows the user to change the backing file of an image that is being reopened. Here's what it does: - In bdrv_reopen_prepare(): check that the value of 'backing' points to an existing node or is null. If it points to an existing node it also needs to make sure that replacing the backing file will not create a cycle in the node graph (i.e. you cannot reach the parent from the new backing file). - In bdrv_reopen_commit(): perform the actual node replacement by calling bdrv_set_backing_hd(). It may happen that there are temporary implicit nodes between the BDS that we are reopening and the backing file that we want to replace (e.g. a commit fiter node), so we must skip them. Although x-blockdev-reopen is meant to be used like blockdev-add, there's an important thing that must be taken into account: the only way to set a new backing file is by using a reference to an existing node (previously added with e.g. blockdev-add). If 'backing' contains a dictionary with a new set of options ({"driver": "qcow2", "file": { ... }}) then it is interpreted that the _existing_ backing file must be reopened with those options. Signed-off-by: Alberto Garcia --- block.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 106 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 5ecdbbac9e..e8babee971 100644 --- a/block.c +++ b/block.c @@ -2909,6 +2909,27 @@ BlockDriverState *bdrv_open(const char *filename, co= nst char *reference, } =20 /* + * Returns true if @child can be reached recursively from @bs + */ +static bool bdrv_recurse_has_child(BlockDriverState *bs, + BlockDriverState *child) +{ + BdrvChild *c; + + if (bs =3D=3D child) { + return true; + } + + QLIST_FOREACH(c, &bs->children, next) { + if (bdrv_recurse_has_child(c->bs, child)) { + return true; + } + } + + return false; +} + +/* * Adds a BlockDriverState to a simple queue for an atomic, transactional * reopen of multiple devices. * @@ -3210,6 +3231,51 @@ static void bdrv_reopen_perm(BlockReopenQueue *q, Bl= ockDriverState *bs, *shared =3D cumulative_shared_perms; } =20 +/* Return 0 if the 'backing' option of @bs can be replaced with + * @value, otherwise return < 0 and set @errp. */ +static int bdrv_reopen_parse_backing(BlockDriverState *bs, QObject *value, + Error **errp) +{ + BlockDriverState *overlay_bs, *new_backing_bs; + const char *str; + + switch (qobject_type(value)) { + case QTYPE_QNULL: + new_backing_bs =3D NULL; + break; + case QTYPE_QSTRING: + str =3D qobject_get_try_str(value); + new_backing_bs =3D bdrv_lookup_bs(NULL, str, errp); + if (new_backing_bs =3D=3D NULL) { + return -EINVAL; + } else if (bdrv_recurse_has_child(new_backing_bs, bs)) { + error_setg(errp, "Making '%s' a backing file of '%s' " + "would create a cycle", str, bs->node_name); + return -EINVAL; + } + break; + default: + /* 'backing' does not allow any other data type */ + g_assert_not_reached(); + } + + /* Skip all links that point to an implicit node, if any + * (e.g. a commit filter node). We don't want to change those. */ + overlay_bs =3D bs; + while (backing_bs(overlay_bs) && backing_bs(overlay_bs)->implicit) { + overlay_bs =3D backing_bs(overlay_bs); + } + + if (new_backing_bs !=3D backing_bs(overlay_bs)) { + if (bdrv_is_backing_chain_frozen(overlay_bs, backing_bs(overlay_bs= ), + errp)) { + return -EPERM; + } + } + + return 0; +} + /* * Prepares a BlockDriverState for reopen. All changes are staged in the * 'opaque' field of the BDRVReopenState, which is used and allocated by @@ -3351,6 +3417,19 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_stat= e, BlockReopenQueue *queue, QObject *new =3D entry->value; QObject *old =3D qdict_get(reopen_state->bs->options, entry->k= ey); =20 + /* + * Allow changing the 'backing' option. The new value can be + * either a reference to an existing node (using its node name) + * or NULL to simply detach the current backing file. + */ + if (!strcmp(entry->key, "backing")) { + ret =3D bdrv_reopen_parse_backing(reopen_state->bs, new, e= rrp); + if (ret < 0) { + goto error; + } + continue; /* 'backing' option processed, go to the next on= e */ + } + /* Allow child references (child_name=3Dnode_name) as long as = they * point to the current child (i.e. everything stays the same)= . */ if (qobject_type(new) =3D=3D QTYPE_QSTRING) { @@ -3429,9 +3508,10 @@ error: void bdrv_reopen_commit(BDRVReopenState *reopen_state) { BlockDriver *drv; - BlockDriverState *bs; + BlockDriverState *bs, *new_backing_bs; BdrvChild *child; - bool old_can_write, new_can_write; + bool old_can_write, new_can_write, change_backing_bs; + QObject *qobj; =20 assert(reopen_state !=3D NULL); bs =3D reopen_state->bs; @@ -3456,6 +3536,15 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_stat= e) bs->read_only =3D !(reopen_state->flags & BDRV_O_RDWR); bs->detect_zeroes =3D reopen_state->detect_zeroes; =20 + qobj =3D qdict_get(bs->options, "backing"); + change_backing_bs =3D (qobj !=3D NULL); + if (change_backing_bs) { + const char *str =3D qobject_get_try_str(qobj); + new_backing_bs =3D str ? bdrv_find_node(str) : NULL; + qdict_del(bs->explicit_options, "backing"); + qdict_del(bs->options, "backing"); + } + /* Remove child references from bs->options and bs->explicit_options. * Child options were already removed in bdrv_reopen_queue_child() */ QLIST_FOREACH(child, &bs->children, next) { @@ -3463,6 +3552,21 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_stat= e) qdict_del(bs->options, child->name); } =20 + /* Change the backing file if a new one was specified. We do this + * after updating bs->options, so bdrv_refresh_filename() (called + * from bdrv_set_backing_hd()) has the new values. */ + if (change_backing_bs) { + BlockDriverState *overlay =3D bs; + /* Skip all links that point to an implicit node, if any + * (e.g. a commit filter node). We don't want to change those. */ + while (backing_bs(overlay) && backing_bs(overlay)->implicit) { + overlay =3D backing_bs(overlay); + } + if (new_backing_bs !=3D backing_bs(overlay)) { + bdrv_set_backing_hd(overlay, new_backing_bs, &error_abort); + } + } + bdrv_refresh_limits(bs, NULL); =20 bdrv_set_perm(reopen_state->bs, reopen_state->perm, --=20 2.11.0 From nobody Mon Apr 29 18:36:29 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; dkim=fail; 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 1543592508731788.9083668471711; Fri, 30 Nov 2018 07:41:48 -0800 (PST) Received: from localhost ([::1]:33406 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkvL-0005xB-Cg for importer@patchew.org; Fri, 30 Nov 2018 10:41:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZa-0007S8-CR for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZY-0006Wt-6H for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:18 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53247) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZU-00062a-4v; Fri, 30 Nov 2018 10:19:14 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYp-0007XI-3v; Fri, 30 Nov 2018 16:18:31 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003ea-L6; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=1kXvmYoxyJGoUUXnYzm5gW8sk4itu9NFqrumXuE/Ydc=; b=nvh5x9jy5HtuYKZZS6lpVbReR42Huw2ZVR47JO2to87UxbMRppVQ4NHmbrmR7J2qC2nN3iRsVjJy26I4gVrme2OxSr/ncDqWLi+sPuF7QZe0uSTYXejBLGidqzSVyEvKjVi1oPCJNdhRkFS95+opZAbOp/FfPLImIqg8s+P8zK0BK7hSTHI5iKlmExOCJfbOW7RL7FncY/P4Mq8U8q8cAzuoe2G44DgQAVT/av1ZQI6ecPAdClCfcKvAnE26q1P3XY+fxGGK85F1i+P/XOWWvn3wUlqzYeHnf6bbXZfgbbbbytolS+sE2FNesxegDHucxQNBE+gwG8q2Vmob6qnCzQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:47 +0200 Message-Id: <0a6d861a7b942e495dc79946a3eb225eb959decf.1543590618.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 09/12] block: Add 'runtime_opts' and 'mutable_opts' fields to BlockDriver 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds two new fields to BlockDriver: - runtime_opts: list of runtime options for a particular block driver. We'll use this list later to detect what options are missing when we try to reopen a block device. - mutable_opts: names of the runtime options that can be reset to their default value after a block device has been added. This way an option can not be reset by omitting it during reopen unless we explicitly allow it. This also sets runtime_opts (and mutable_opts where appropriate) in all drivers that allow reopening. Most of those drivers don't actually support changing any of their options. If the user specifies a new value for an option that can't be changed then we already detect that and forbid it (in bdrv_reopen_prepare()). But if the user omits an option in order to try to reset it to its default value we need to detect that, so we'll use these two new fields for that. Signed-off-by: Alberto Garcia --- block/blkdebug.c | 1 + block/crypto.c | 1 + block/file-posix.c | 10 ++++++++++ block/iscsi.c | 2 ++ block/null.c | 2 ++ block/nvme.c | 1 + block/qcow.c | 1 + block/rbd.c | 1 + block/sheepdog.c | 2 ++ block/vpc.c | 1 + include/block/block_int.h | 5 +++++ 11 files changed, 27 insertions(+) diff --git a/block/blkdebug.c b/block/blkdebug.c index 0759452925..bba7645e09 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -893,6 +893,7 @@ static BlockDriver bdrv_blkdebug =3D { .protocol_name =3D "blkdebug", .instance_size =3D sizeof(BDRVBlkdebugState), .is_filter =3D true, + .runtime_opts =3D &runtime_opts, =20 .bdrv_parse_filename =3D blkdebug_parse_filename, .bdrv_file_open =3D blkdebug_open, diff --git a/block/crypto.c b/block/crypto.c index 33ee01bebd..266b737bde 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -634,6 +634,7 @@ BlockDriver bdrv_crypto_luks =3D { .bdrv_co_create_opts =3D block_crypto_co_create_opts_luks, .bdrv_co_truncate =3D block_crypto_co_truncate, .create_opts =3D &block_crypto_create_opts_luks, + .runtime_opts =3D &block_crypto_runtime_opts_luks, =20 .bdrv_reopen_prepare =3D block_crypto_reopen_prepare, .bdrv_refresh_limits =3D block_crypto_refresh_limits, diff --git a/block/file-posix.c b/block/file-posix.c index 07bbdab953..9bffdf4566 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -439,6 +439,8 @@ static QemuOptsList raw_runtime_opts =3D { }, }; =20 +static const char *const mutable_opts[] =3D { "x-check-cache-dropped", NUL= L }; + static int raw_open_common(BlockDriverState *bs, QDict *options, int bdrv_flags, int open_flags, bool device, Error **errp) @@ -2722,6 +2724,8 @@ BlockDriver bdrv_file =3D { .format_name =3D "file", .protocol_name =3D "file", .instance_size =3D sizeof(BDRVRawState), + .runtime_opts =3D &raw_runtime_opts, + .mutable_opts =3D mutable_opts, .bdrv_needs_filename =3D true, .bdrv_probe =3D NULL, /* no probe for protocols */ .bdrv_parse_filename =3D raw_parse_filename, @@ -3204,6 +3208,8 @@ static BlockDriver bdrv_host_device =3D { .format_name =3D "host_device", .protocol_name =3D "host_device", .instance_size =3D sizeof(BDRVRawState), + .runtime_opts =3D &raw_runtime_opts, + .mutable_opts =3D mutable_opts, .bdrv_needs_filename =3D true, .bdrv_probe_device =3D hdev_probe_device, .bdrv_parse_filename =3D hdev_parse_filename, @@ -3330,6 +3336,8 @@ static BlockDriver bdrv_host_cdrom =3D { .format_name =3D "host_cdrom", .protocol_name =3D "host_cdrom", .instance_size =3D sizeof(BDRVRawState), + .runtime_opts =3D &raw_runtime_opts, + .mutable_opts =3D mutable_opts, .bdrv_needs_filename =3D true, .bdrv_probe_device =3D cdrom_probe_device, .bdrv_parse_filename =3D cdrom_parse_filename, @@ -3463,6 +3471,8 @@ static BlockDriver bdrv_host_cdrom =3D { .format_name =3D "host_cdrom", .protocol_name =3D "host_cdrom", .instance_size =3D sizeof(BDRVRawState), + .runtime_opts =3D &raw_runtime_opts, + .mutable_opts =3D mutable_opts, .bdrv_needs_filename =3D true, .bdrv_probe_device =3D cdrom_probe_device, .bdrv_parse_filename =3D cdrom_parse_filename, diff --git a/block/iscsi.c b/block/iscsi.c index 727dee50bf..adfa6da6b7 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2433,6 +2433,7 @@ static BlockDriver bdrv_iscsi =3D { .bdrv_close =3D iscsi_close, .bdrv_co_create_opts =3D iscsi_co_create_opts, .create_opts =3D &iscsi_create_opts, + .runtime_opts =3D &runtime_opts, .bdrv_reopen_prepare =3D iscsi_reopen_prepare, .bdrv_reopen_commit =3D iscsi_reopen_commit, .bdrv_co_invalidate_cache =3D iscsi_co_invalidate_cache, @@ -2470,6 +2471,7 @@ static BlockDriver bdrv_iser =3D { .bdrv_close =3D iscsi_close, .bdrv_co_create_opts =3D iscsi_co_create_opts, .create_opts =3D &iscsi_create_opts, + .runtime_opts =3D &runtime_opts, .bdrv_reopen_prepare =3D iscsi_reopen_prepare, .bdrv_reopen_commit =3D iscsi_reopen_commit, .bdrv_co_invalidate_cache =3D iscsi_co_invalidate_cache, diff --git a/block/null.c b/block/null.c index d442d3e901..5df4b46723 100644 --- a/block/null.c +++ b/block/null.c @@ -256,6 +256,7 @@ static BlockDriver bdrv_null_co =3D { .format_name =3D "null-co", .protocol_name =3D "null-co", .instance_size =3D sizeof(BDRVNullState), + .runtime_opts =3D &runtime_opts, =20 .bdrv_file_open =3D null_file_open, .bdrv_parse_filename =3D null_co_parse_filename, @@ -275,6 +276,7 @@ static BlockDriver bdrv_null_aio =3D { .format_name =3D "null-aio", .protocol_name =3D "null-aio", .instance_size =3D sizeof(BDRVNullState), + .runtime_opts =3D &runtime_opts, =20 .bdrv_file_open =3D null_file_open, .bdrv_parse_filename =3D null_aio_parse_filename, diff --git a/block/nvme.c b/block/nvme.c index 29294038fc..655b18dc27 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1143,6 +1143,7 @@ static BlockDriver bdrv_nvme =3D { .format_name =3D "nvme", .protocol_name =3D "nvme", .instance_size =3D sizeof(BDRVNVMeState), + .runtime_opts =3D &runtime_opts, =20 .bdrv_parse_filename =3D nvme_parse_filename, .bdrv_file_open =3D nvme_file_open, diff --git a/block/qcow.c b/block/qcow.c index 4518cb4c35..5cceba7c16 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -1186,6 +1186,7 @@ static QemuOptsList qcow_create_opts =3D { static BlockDriver bdrv_qcow =3D { .format_name =3D "qcow", .instance_size =3D sizeof(BDRVQcowState), + .runtime_opts =3D &qcow_runtime_opts, .bdrv_probe =3D qcow_probe, .bdrv_open =3D qcow_open, .bdrv_close =3D qcow_close, diff --git a/block/rbd.c b/block/rbd.c index 8a1a9f4b6e..6de6112ce8 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1231,6 +1231,7 @@ static QemuOptsList qemu_rbd_create_opts =3D { static BlockDriver bdrv_rbd =3D { .format_name =3D "rbd", .instance_size =3D sizeof(BDRVRBDState), + .runtime_opts =3D &runtime_opts, .bdrv_parse_filename =3D qemu_rbd_parse_filename, .bdrv_refresh_limits =3D qemu_rbd_refresh_limits, .bdrv_file_open =3D qemu_rbd_open, diff --git a/block/sheepdog.c b/block/sheepdog.c index 0125df9d49..28d64af517 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -3288,6 +3288,7 @@ static BlockDriver bdrv_sheepdog_tcp =3D { .bdrv_attach_aio_context =3D sd_attach_aio_context, =20 .create_opts =3D &sd_create_opts, + .runtime_opts =3D &runtime_opts, }; =20 static BlockDriver bdrv_sheepdog_unix =3D { @@ -3325,6 +3326,7 @@ static BlockDriver bdrv_sheepdog_unix =3D { .bdrv_attach_aio_context =3D sd_attach_aio_context, =20 .create_opts =3D &sd_create_opts, + .runtime_opts =3D &runtime_opts, }; =20 static void bdrv_sheepdog_init(void) diff --git a/block/vpc.c b/block/vpc.c index 80c5b2b197..159f5c9ec6 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1235,6 +1235,7 @@ static BlockDriver bdrv_vpc =3D { .bdrv_get_info =3D vpc_get_info, =20 .create_opts =3D &vpc_create_opts, + .runtime_opts =3D &vpc_runtime_opts, .bdrv_has_zero_init =3D vpc_has_zero_init, }; =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index 05d925227a..6c2dffd8b9 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -345,6 +345,11 @@ struct BlockDriver { =20 /* List of options for creating images, terminated by name =3D=3D NULL= */ QemuOptsList *create_opts; + /* Runtime options for a block device, terminated by name =3D=3D NULL = */ + QemuOptsList *runtime_opts; + /* Names of the runtime options that can be reset by omitting + * their value on reopen, NULL-terminated. */ + const char *const *mutable_opts; =20 /* * Returns 0 for completed check, -errno for internal errors. --=20 2.11.0 From nobody Mon Apr 29 18:36:29 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; dkim=fail; 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 154359260563231.811745376923568; Fri, 30 Nov 2018 07:43:25 -0800 (PST) Received: from localhost ([::1]:33414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkwp-0007WB-Eo for importer@patchew.org; Fri, 30 Nov 2018 10:43:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZt-0007kN-TK for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZq-0006kT-MG for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:37 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53273) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZq-00064X-Aj; Fri, 30 Nov 2018 10:19:34 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYu-0007XJ-Ev; Fri, 30 Nov 2018 16:18:36 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003ed-MA; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=RUwBM6Y/5bCiLeutme4ryUZuhEUQA4ab9CFhUSxhaaQ=; b=UFU2VwGKXMFpF5/OoM3+uwHNHCt4ihL2di7/tZINWKaomLF99827fvlqApQIBoaF+aSBKovKOmxn1lYAHyjfVqRXuIIALjxDmyK0TWQ6QnxH44jfZSp395ClLUSfzS9XZE+5XdA2o0o4INT1Kb2WWWJ4TSwN9WzYGQbfnLsyII4J7HHvwlE2taamwdyKAKnzXmUgVki2nTdG9lsvmwYbrhkbnmrUFUsnyEZdxk9xlLAU2Cg7jUNhfV+VjV02Rd+S9ffJBsEYzrd+0cGRDdo649UF42h1qM7CxhXrwNKbsUSWYD1xJ3feRiqJkWPaT2EgFrBkKlUi/IMHtsEq7vYJMg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:48 +0200 Message-Id: <1da8275a88ef7593d554ae1185b18ee83d91c3ae.1543590618.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 10/12] block: Add bdrv_reset_options_allowed() 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" bdrv_reopen_prepare() receives a BDRVReopenState with (among other things) a new set of options to be applied to that BlockDriverState. If an option is missing then it means that we want to reset it to its default value rather than keep the previous one. This way the state of the block device after being reopened is comparable to that of a device added with "blockdev-add" using the same set of options. Not all options from all drivers can be changed this way, however. If the user attempts to reset an immutable option to its default value using this method then we must forbid it. This new function takes a QemuOptsList with the options of a block driver and checks if there's any that was previously set but is missing from the new set of options in the BDRVReopenState. If the option is present in both sets we don't need to check that they have the same value. The loop at the end of bdrv_reopen_prepare() already takes care of that. Signed-off-by: Alberto Garcia --- block.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/block.c b/block.c index e8babee971..59aa72f15e 100644 --- a/block.c +++ b/block.c @@ -2909,6 +2909,43 @@ BlockDriverState *bdrv_open(const char *filename, co= nst char *reference, } =20 /* + * For every option in @list, check that if it is set in the current + * set of options (@state->bs->options) then it is also set in the new + * set (@state->options). Options listed in @mutable_opts are skipped. + * + * @mutable_opts is either NULL or a NULL-terminated array of option + * names. + * + * Return 0 on success, -EINVAL otherwise. + */ +static int bdrv_reset_options_allowed(BDRVReopenState *state, + QemuOptsList *list, + const char *const mutable_opts[], + Error **errp) +{ + QemuOptDesc *desc =3D list->desc; + while (desc->name) { + unsigned i; + for (i =3D 0; mutable_opts !=3D NULL && mutable_opts[i] !=3D NULL;= i++) { + if (!strcmp(desc->name, mutable_opts[i])) { + goto next; + } + } + + if (!qdict_haskey(state->options, desc->name) && + qdict_haskey(state->bs->options, desc->name)) { + error_setg(errp, "Option '%s' can't be reset to its default va= lue", + desc->name); + return -EINVAL; + } + next: + desc++; + } + + return 0; +} + +/* * Returns true if @child can be reached recursively from @bs */ static bool bdrv_recurse_has_child(BlockDriverState *bs, @@ -3374,6 +3411,17 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_stat= e, BlockReopenQueue *queue, } =20 if (drv->bdrv_reopen_prepare) { + /* If a driver-specific option is missing, it means that we + * should reset it to its default value. + * But not all options allow that, so we need to check it first. */ + if (drv->runtime_opts) { + ret =3D bdrv_reset_options_allowed(reopen_state, drv->runtime_= opts, + drv->mutable_opts, errp); + if (ret) { + goto error; + } + } + ret =3D drv->bdrv_reopen_prepare(reopen_state, queue, &local_err); if (ret) { if (local_err !=3D NULL) { --=20 2.11.0 From nobody Mon Apr 29 18:36:29 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; dkim=fail; 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543592208592141.4092173730569; Fri, 30 Nov 2018 07:36:48 -0800 (PST) Received: from localhost ([::1]:33370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkqP-0000ME-JR for importer@patchew.org; Fri, 30 Nov 2018 10:36:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZc-0007Sz-BQ for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZY-0006XH-E1 for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:20 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53270) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZW-00064V-4s; Fri, 30 Nov 2018 10:19:16 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYu-0007XK-Cn; Fri, 30 Nov 2018 16:18:36 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003eg-N5; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=0TUBz2CH/AcBzq9N24bSHbaTE5XpywX9NeA8H4BAOig=; b=To0X3yv2dFup7/b5BQpxpvM3c5VoQf2k/PtQNcxwQHjQSDgZoZjMKT36uQuEHDkOPW4PpeHiQZ/dZanf65znMa0pTMrQOWfoVQIl9lHRQ6LIwyd4+53dZOQC9gqK3WfFoGnj6BAqllcbUiRRiDyKy1TaESyV5xONWP6TsSYvw3+WVpiiE/J5vsGZ1hlKaxG+6sRZaQDENeX3EXIk1b7oXi0SkPu26x+h1eYJX1CpU7mDRK5pbtvpxZalU0n/lxAkKV8c8xVPN0kx9v1AhrF0f0HqOjpRSxuy2Kx3NN8S24lbOvYZ9b4xx8dRmFfu1TcVH7tvQ3I/S9pJe2zdDK5yQQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:49 +0200 Message-Id: <19f8c53d020fa7b71b5e129791bb556b4678f468.1543590618.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 11/12] block: Add an 'x-blockdev-reopen' QMP command 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This command allows reopening an arbitrary BlockDriverState with a new set of options. Some options (e.g node-name) cannot be changed and some block drivers don't allow reopening, but otherwise this command is modelled after 'blockdev-add' and the state of the reopened BlockDriverState should generally be the same as if it had just been added by 'blockdev-add' with the same set of options. One notable exception is the 'backing' option: 'x-blockdev-reopen' requires that it is always present unless the BlockDriverState in question doesn't have a current or default backing file. This command allows reconfiguring the graph by using the appropriate options to change the children of a node. At the moment it's possible to change a backing file by setting the 'backing' option to the name of the new node, but it should also be possible to add a similar functionality to other block drivers (e.g. Quorum, blkverify). Although the API is unlikely to change, this command is marked experimental for the time being so there's room to see if the semantics need changes. Signed-off-by: Alberto Garcia --- blockdev.c | 43 +++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/blockdev.c b/blockdev.c index e6c8349409..a95017df54 100644 --- a/blockdev.c +++ b/blockdev.c @@ -4233,6 +4233,49 @@ fail: visit_free(v); } =20 +void qmp_x_blockdev_reopen(BlockdevOptions *options, Error **errp) +{ + BlockDriverState *bs; + QObject *obj; + Visitor *v =3D qobject_output_visitor_new(&obj); + Error *local_err =3D NULL; + BlockReopenQueue *queue; + QDict *qdict; + + /* Check for the selected node name */ + if (!options->has_node_name) { + error_setg(errp, "Node name not specified"); + goto fail; + } + + bs =3D bdrv_find_node(options->node_name); + if (!bs) { + error_setg(errp, "Cannot find node named '%s'", options->node_name= ); + goto fail; + } + + /* Put all options in a QDict and flatten it */ + visit_type_BlockdevOptions(v, NULL, &options, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto fail; + } + + visit_complete(v, &obj); + qdict =3D qobject_to(QDict, obj); + + qdict_flatten(qdict); + + /* Perform the reopen operation */ + bdrv_subtree_drained_begin(bs); + queue =3D bdrv_reopen_queue(NULL, bs, qdict, false); + bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, errp); + bdrv_subtree_drained_end(bs); + +fail: + visit_free(v); +} + void qmp_blockdev_del(const char *node_name, Error **errp) { AioContext *aio_context; diff --git a/qapi/block-core.json b/qapi/block-core.json index d4fe710836..6afcd243b1 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3808,6 +3808,48 @@ { 'command': 'blockdev-add', 'data': 'BlockdevOptions', 'boxed': true } =20 ## +# @x-blockdev-reopen: +# +# Reopens a block device using the given set of options. Any option +# not specified will be reset to its default value regardless of its +# previous status. If an option cannot be changed or a particular +# driver does not support reopening then the command will return an +# error. +# +# The top-level @node-name option (from BlockdevOptions) must be +# specified and is used to select the block device to be reopened. +# Other @node-name options must be either omitted or set to the +# current name of the appropriate node. This command won't change any +# node name and any attempt to do it will result in an error. +# +# In the case of options that refer to child nodes, the behavior of +# this command depends on the value: +# +# 1) A set of options (BlockdevOptions): the child is reopened with +# the specified set of options. +# +# 2) A reference to the current child: the child is reopened using +# its existing set of options. +# +# 3) A reference to a different node: the current child is replaced +# with the specified one. +# +# 4) NULL: the current child (if any) is detached. +# +# Options (1) and (2) are supported in all cases, but at the moment +# only @backing allows replacing or detaching an existing child. +# +# Unlike with blockdev-add, the @backing option must always be present +# unless the node being reopened does not have a backing file and its +# image does not have a default backing file name as part of its +# metadata. +# +# Since: 3.2 +## +{ 'command': 'x-blockdev-reopen', + 'data': 'BlockdevOptions', 'boxed': true } + +## # @blockdev-del: # # Deletes a block device that has been added using blockdev-add. --=20 2.11.0 From nobody Mon Apr 29 18:36:29 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543592198135273.1205394400987; Fri, 30 Nov 2018 07:36:38 -0800 (PST) Received: from localhost ([::1]:33368 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkq5-0008W0-FY for importer@patchew.org; Fri, 30 Nov 2018 10:36:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkZv-0007lX-0E for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkZr-0006ke-12 for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:19:38 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:53276) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSkZq-00064d-CE; Fri, 30 Nov 2018 10:19:34 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gSkYu-0007XL-EK; Fri, 30 Nov 2018 16:18:36 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gSkYZ-0003ej-O1; Fri, 30 Nov 2018 17:18:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=unumJeez4qKBKQjBILE3pzIMng9RQZlVtRWBykIcDAY=; b=IeSlh5Uk3JwCQgIXudnOZOuqzB5EN/BizQArPmQmoXBeV5XariUThEc6OgZtyF9n6daPHk722Z8rNt5NjJydYXY6rhdw4/Cp3GQzPjbptDW2xGXGlUkWyH0462rDMomF8gtP0gLM8JGKrq/ia8pl3fSYOkxPNw9TWh3Ysp18fn/fc59la0e/+AvVdbM417G3pbpCCSZ+fkLusIo7dv6uf3JMCmcRZdTh0u4O5CRrsDC0J++KvUKVZiACOasCdICEVlvnOsPHDR7hQ+UmJbrb1CUr5H/GLtUdRuYVEOWrBsP/o1KAzu9NTqVBVgwLL9JaBGmL9O/R+3SL16CP0wmMbQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 17:17:50 +0200 Message-Id: <04391d8fbd252d8873ecede81f3f5c796f828a69.1543590618.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [RFC PATCH v2 12/12] qemu-iotests: Test the x-blockdev-reopen QMP command 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds several tests for the x-blockdev-reopen QMP command. Signed-off-by: Alberto Garcia --- tests/qemu-iotests/224 | 970 +++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/224.out | 5 + tests/qemu-iotests/group | 1 + 3 files changed, 976 insertions(+) create mode 100644 tests/qemu-iotests/224 create mode 100644 tests/qemu-iotests/224.out diff --git a/tests/qemu-iotests/224 b/tests/qemu-iotests/224 new file mode 100644 index 0000000000..6fc2cdd294 --- /dev/null +++ b/tests/qemu-iotests/224 @@ -0,0 +1,970 @@ +#!/usr/bin/env python +# +# Test cases for the QMP 'x-blockdev-reopen' command +# +# Copyright (C) 2018 Igalia, S.L. +# Author: Alberto Garcia +# +# 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 . +# + +import os +import re +import iotests +import copy +import json +from iotests import qemu_img, qemu_io + +hd_path =3D [ + os.path.join(iotests.test_dir, 'hd0.img'), + os.path.join(iotests.test_dir, 'hd1.img'), + os.path.join(iotests.test_dir, 'hd2.img') +] + +def hd_opts(idx): + return {'driver': iotests.imgfmt, + 'node-name': 'hd%d' % idx, + 'file': {'driver': 'file', + 'node-name': 'hd%d-file' % idx, + 'filename': hd_path[idx] } } + +class TestBlockdevReopen(iotests.QMPTestCase): + total_io_cmds =3D 0 + + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, hd_path[0], '3M') + qemu_img('create', '-f', iotests.imgfmt, '-b', hd_path[0], hd_path= [1]) + qemu_img('create', '-f', iotests.imgfmt, hd_path[2], '3M') + qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xa0 0 1M', hd_path= [0]) + qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xa1 1M 1M', hd_path= [1]) + qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xa2 2M 1M', hd_path= [2]) + self.vm =3D iotests.VM() + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + self.check_qemu_io_errors() + os.remove(hd_path[0]) + os.remove(hd_path[1]) + os.remove(hd_path[2]) + + # The output of qemu-io is not returned by vm.hmp_qemu_io() but + # it's stored in the log and can only be read when the VM has been + # shut down. This function runs qemu-io and keeps track of the + # number of times it's been called. + def run_qemu_io(self, img, cmd): + result =3D self.vm.hmp_qemu_io(img, cmd) + self.assert_qmp(result, 'return', '') + self.total_io_cmds +=3D 1 + + # Once the VM is shut down we can parse the log and see if qemu-io + # ran without errors. + def check_qemu_io_errors(self): + self.assertFalse(self.vm.is_running()) + found =3D 0 + log =3D self.vm.get_log() + for line in log.split("\n"): + if line.startswith("Pattern verification failed"): + raise Exception("%s (command #%d)" % (line, found)) + if re.match("read .*/.* bytes at offset", line): + found +=3D 1 + self.assertEqual(found, self.total_io_cmds, + "Expected output of %d qemu-io commands, found %d= " % + (found, self.total_io_cmds)) + + # Run x-blockdev-reopen with 'opts' but applying 'newopts' + # on top of it. The original 'opts' dict is unmodified + def reopen(self, opts, newopts =3D {}, errmsg =3D None): + opts =3D copy.deepcopy(opts) + + # Apply the changes from 'newopts' on top of 'opts' + for key in newopts: + value =3D newopts[key] + # If key has the form "foo.bar" then we need to do + # opts["foo"]["bar"] =3D value, not opts["foo.bar"] =3D value + subdict =3D opts + while key.find('.') !=3D -1: + [prefix, key] =3D key.split('.', 1) + subdict =3D opts[prefix] + subdict[key] =3D value + + result =3D self.vm.qmp('x-blockdev-reopen', conv_keys =3D False, *= *opts) + if errmsg: + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', errmsg) + else: + self.assert_qmp(result, 'return', {}) + + + # Run query-named-block-nodes and return the specified entry + def get_node(self, node_name): + result =3D self.vm.qmp('query-named-block-nodes') + for node in result['return']: + if node['node-name'] =3D=3D node_name: + return node + return None + + # Run 'query-named-block-nodes' and compare its output with the + # value passed by the user in 'graph' + def check_node_graph(self, graph): + result =3D self.vm.qmp('query-named-block-nodes') + self.assertEqual(json.dumps(graph, sort_keys=3DTrue), + json.dumps(result, sort_keys=3DTrue)) + + # This test opens one single disk image (without backing files) + # and tries to reopen it with illegal / incorrect parameters. + def test_incorrect_parameters_single_file(self): + # Open 'hd0' only (no backing files) + opts =3D hd_opts(0) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + original_graph =3D self.vm.qmp('query-named-block-nodes') + + # We can reopen the image passing the same options + self.reopen(opts) + + # We can also reopen passing a child reference in 'file' + self.reopen(opts, {'file': 'hd0-file'}) + + # We cannot change any of these + self.reopen(opts, {'node-name': 'not-found'}, "Cannot find node na= med 'not-found'") + self.reopen(opts, {'node-name': ''}, "Cannot find node named ''") + self.reopen(opts, {'node-name': None}, "Invalid parameter type for= 'node-name', expected: string") + self.reopen(opts, {'driver': 'raw'}, "Cannot change the option 'dr= iver'") + self.reopen(opts, {'driver': ''}, "Invalid parameter ''") + self.reopen(opts, {'driver': None}, "Invalid parameter type for 'd= river', expected: string") + self.reopen(opts, {'file': 'not-found'}, "Cannot change the option= 'file'") + self.reopen(opts, {'file': ''}, "Cannot change the option 'file'") + self.reopen(opts, {'file': None}, "Invalid parameter type for 'fil= e', expected: BlockdevRef") + self.reopen(opts, {'file.node-name': 'newname'}, "Cannot change th= e option 'node-name'") + self.reopen(opts, {'file.driver': 'host_device'}, "Cannot change t= he option 'driver'") + self.reopen(opts, {'file.filename': hd_path[1]}, "Cannot change th= e option 'filename'") + self.reopen(opts, {'file.aio': 'native'}, "Cannot change the optio= n 'aio'") + self.reopen(opts, {'file.locking': 'off'}, "Cannot change the opti= on 'locking'") + self.reopen(opts, {'file.filename': None}, "Invalid parameter type= for 'file.filename', expected: string") + + # node-name is optional in BlockdevOptions, but x-blockdev-reopen = needs it + del opts['node-name'] + self.reopen(opts, {}, "Node name not specified") + + # Check that nothing has changed + self.check_node_graph(original_graph) + + # Remove the node + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd0') + self.assert_qmp(result, 'return', {}) + + # This test opens an image with a backing file and tries to reopen + # it with illegal / incorrect parameters. + def test_incorrect_parameters_backing_file(self): + # Open hd1 omitting the backing options (hd0 will be opened + # with the default options) + opts =3D hd_opts(1) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + original_graph =3D self.vm.qmp('query-named-block-nodes') + + # We can't reopen the image passing the same options, 'backing' is= mandatory + self.reopen(opts, {}, "backing is missing for 'hd1'") + + # Everything works if we pass 'backing' using the existing node na= me + for node in original_graph['return']: + if node['drv'] =3D=3D iotests.imgfmt and node['file'] =3D=3D h= d_path[0]: + backing_node_name =3D node['node-name'] + self.reopen(opts, {'backing': backing_node_name}) + + # We can't use a non-existing or empty (non-NULL) node as the back= ing image + self.reopen(opts, {'backing': 'not-found'}, "Cannot find device=3D= nor node_name=3Dnot-found") + self.reopen(opts, {'backing': ''}, "Cannot find device=3D nor node= _name=3D") + + # We can reopen the image just fine if we specify the backing opti= ons + opts['backing'] =3D {'driver': iotests.imgfmt, + 'file': {'driver': 'file', + 'filename': hd_path[0]}} + self.reopen(opts) + + # We cannot change any of these options + self.reopen(opts, {'backing.node-name': 'newname'}, "Cannot change= the option 'node-name'") + self.reopen(opts, {'backing.driver': 'raw'}, "Cannot change the op= tion 'driver'") + self.reopen(opts, {'backing.file.node-name': 'newname'}, "Cannot c= hange the option 'node-name'") + self.reopen(opts, {'backing.file.driver': 'host_device'}, "Cannot = change the option 'driver'") + + # Check that nothing has changed since the beginning + self.check_node_graph(original_graph) + + # Remove the node + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd1') + self.assert_qmp(result, 'return', {}) + + # Reopen an image several times changing some of its options + def test_reopen(self): + # Open the hd1 image passing all backing options + opts =3D hd_opts(1) + opts['backing'] =3D hd_opts(0) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + original_graph =3D self.vm.qmp('query-named-block-nodes') + + # We can reopen the image passing the same options + self.reopen(opts) + + # Reopen in read-only mode + self.assert_qmp(self.get_node('hd1'), 'ro', False) + + self.reopen(opts, {'read-only': True}) + self.assert_qmp(self.get_node('hd1'), 'ro', True) + self.reopen(opts) + self.assert_qmp(self.get_node('hd1'), 'ro', False) + + # Change the cache options + self.assert_qmp(self.get_node('hd1'), 'cache/writeback', True) + self.assert_qmp(self.get_node('hd1'), 'cache/direct', False) + self.assert_qmp(self.get_node('hd1'), 'cache/no-flush', False) + self.reopen(opts, {'cache': { 'direct': True, 'no-flush': True }}) + self.assert_qmp(self.get_node('hd1'), 'cache/writeback', True) + self.assert_qmp(self.get_node('hd1'), 'cache/direct', True) + self.assert_qmp(self.get_node('hd1'), 'cache/no-flush', True) + + # Reopen again with the original options + self.reopen(opts) + self.assert_qmp(self.get_node('hd1'), 'cache/writeback', True) + self.assert_qmp(self.get_node('hd1'), 'cache/direct', False) + self.assert_qmp(self.get_node('hd1'), 'cache/no-flush', False) + + # Change 'detect-zeroes' and 'discard' + self.assert_qmp(self.get_node('hd1'), 'detect_zeroes', 'off') + self.reopen(opts, {'detect-zeroes': 'on'}) + self.assert_qmp(self.get_node('hd1'), 'detect_zeroes', 'on') + self.reopen(opts, {'detect-zeroes': 'unmap'}, + "setting detect-zeroes to unmap is not allowed " + + "without setting discard operation to unmap") + self.assert_qmp(self.get_node('hd1'), 'detect_zeroes', 'on') + self.reopen(opts, {'detect-zeroes': 'unmap', 'discard': 'unmap'}) + self.assert_qmp(self.get_node('hd1'), 'detect_zeroes', 'unmap') + self.reopen(opts) + self.assert_qmp(self.get_node('hd1'), 'detect_zeroes', 'off') + + # Changing 'force-share' is currently not supported + self.reopen(opts, {'force-share': True}, "Cannot change the option= 'force-share'") + + # Change some qcow2-specific options + # No way to test for success other than checking the return message + if iotests.imgfmt =3D=3D 'qcow2': + self.reopen(opts, {'l2-cache-entry-size': 128 * 1024}, + "L2 cache entry size must be a power of two "+ + "between 512 and the cluster size (65536)") + self.reopen(opts, {'l2-cache-size': 1024 * 1024, + 'cache-size': 512 * 1024}, + "l2-cache-size may not exceed cache-size") + self.reopen(opts, {'l2-cache-size': 4 * 1024 * 1024, + 'refcount-cache-size': 4 * 1024 * 1024, + 'l2-cache-entry-size': 32 * 1024}) + self.reopen(opts, {'pass-discard-request': True}) + + # Check that nothing has changed since the beginning + # (from the parameters that we can check) + self.check_node_graph(original_graph) + + # Check that the node names (other than the top-level one) are opt= ional + del opts['file']['node-name'] + del opts['backing']['node-name'] + del opts['backing']['file']['node-name'] + self.reopen(opts) + self.check_node_graph(original_graph) + + # Reopen setting backing =3D null, this removes the backing image = from the chain + self.reopen(opts, {'backing': None}) + self.assert_qmp_absent(self.get_node('hd1'), 'image/backing-image') + + # Open the 'hd0' image + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **hd_o= pts(0)) + self.assert_qmp(result, 'return', {}) + + # Reopen the hd1 image setting 'hd0' as its backing image + self.reopen(opts, {'backing': 'hd0'}) + self.assert_qmp(self.get_node('hd1'), 'image/backing-image/filenam= e', hd_path[0]) + + # Check that nothing has changed since the beginning + self.reopen(hd_opts(0), {'read-only': True}) + self.check_node_graph(original_graph) + + # The backing file (hd0) is now a reference, we cannot change back= ing.* anymore + self.reopen(opts, {}, "Cannot change the option 'backing.driver'") + + # We can't remove 'hd0' while it's a backing image of 'hd1' + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd0') + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', "Node 'hd0' is busy: node is= used as backing hd of 'hd1'") + + # But we can remove both nodes if done in the proper order + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd1') + self.assert_qmp(result, 'return', {}) + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd0') + self.assert_qmp(result, 'return', {}) + + # Reopen a raw image and see the effect of changing the 'offset' option + def test_reopen_raw(self): + opts =3D {'driver': 'raw', 'node-name': 'hd0', + 'file': { 'driver': 'file', + 'filename': hd_path[0], + 'node-name': 'hd0-file' } } + + # First we create a 2MB raw file, and fill each half with a + # different value + qemu_img('create', '-f', 'raw', hd_path[0], '2M') + qemu_io('-f', 'raw', '-c', 'write -P 0xa0 0 1M', hd_path[0]) + qemu_io('-f', 'raw', '-c', 'write -P 0xa1 1M 1M', hd_path[0]) + + # Open the raw file with QEMU + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # Read 1MB from offset 0 + self.run_qemu_io("hd0", "read -P 0xa0 0 1M") + + # Reopen the image with a 1MB offset. + # Now the results are different + self.reopen(opts, {'offset': 1024*1024}) + self.run_qemu_io("hd0", "read -P 0xa1 0 1M") + + # Reopen again with the original options. + # We get the original results again + self.reopen(opts) + self.run_qemu_io("hd0", "read -P 0xa0 0 1M") + + # Remove the block device + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd0') + self.assert_qmp(result, 'return', {}) + + # Omitting an option should reset it to the default value, but if + # an option cannot be changed it shouldn't be possible to reset it + # to its default value either + def test_reset_default_values(self): + opts =3D {'driver': 'qcow2', 'node-name': 'hd0', + 'file': { 'driver': 'file', + 'filename': hd_path[0], + 'x-check-cache-dropped': True, # This one can be= changed + 'locking': 'off', # This one can NO= T be changed + 'node-name': 'hd0-file' } } + + # Open the file with QEMU + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # file.x-check-cache-dropped can be changed... + self.reopen(opts, { 'file.x-check-cache-dropped': False }) + # ...and dropped completely (resetting to the default value) + del opts['file']['x-check-cache-dropped'] + self.reopen(opts) + + # file.locking cannot be changed nor reset to the default value + self.reopen(opts, { 'file.locking': 'on' }, "Cannot change the opt= ion 'locking'") + del opts['file']['locking'] + self.reopen(opts, {}, "Option 'locking' can't be reset to its defa= ult value") + # But we can reopen it if we maintain its previous value + self.reopen(opts, { 'file.locking': 'off' }) + + # Remove the block device + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd0') + self.assert_qmp(result, 'return', {}) + + # This test modifies the node graph a few times by changing the + # 'backing' option on reopen and verifies that the guest data that + # is read afterwards is consistent with the graph changes. + def test_io_with_graph_changes(self): + opts =3D [] + + # Open hd0, hd1 and hd2 without any backing image + for i in range(3): + opts.append(hd_opts(i)) + opts[i]['backing'] =3D None + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **= opts[i]) + self.assert_qmp(result, 'return', {}) + + # hd0 + self.run_qemu_io("hd0", "read -P 0xa0 0 1M") + self.run_qemu_io("hd0", "read -P 0 1M 1M") + self.run_qemu_io("hd0", "read -P 0 2M 1M") + + # hd1 <- hd0 + self.reopen(opts[0], {'backing': 'hd1'}) + + self.run_qemu_io("hd0", "read -P 0xa0 0 1M") + self.run_qemu_io("hd0", "read -P 0xa1 1M 1M") + self.run_qemu_io("hd0", "read -P 0 2M 1M") + + # hd1 <- hd0 , hd1 <- hd2 + self.reopen(opts[2], {'backing': 'hd1'}) + + self.run_qemu_io("hd2", "read -P 0 0 1M") + self.run_qemu_io("hd2", "read -P 0xa1 1M 1M") + self.run_qemu_io("hd2", "read -P 0xa2 2M 1M") + + # hd1 <- hd2 <- hd0 + self.reopen(opts[0], {'backing': 'hd2'}) + + self.run_qemu_io("hd0", "read -P 0xa0 0 1M") + self.run_qemu_io("hd0", "read -P 0xa1 1M 1M") + self.run_qemu_io("hd0", "read -P 0xa2 2M 1M") + + # hd2 <- hd0 + self.reopen(opts[2], {'backing': None}) + + self.run_qemu_io("hd0", "read -P 0xa0 0 1M") + self.run_qemu_io("hd0", "read -P 0 1M 1M") + self.run_qemu_io("hd0", "read -P 0xa2 2M 1M") + + # hd2 <- hd1 <- hd0 + self.reopen(opts[1], {'backing': 'hd2'}) + self.reopen(opts[0], {'backing': 'hd1'}) + + self.run_qemu_io("hd0", "read -P 0xa0 0 1M") + self.run_qemu_io("hd0", "read -P 0xa1 1M 1M") + self.run_qemu_io("hd0", "read -P 0xa2 2M 1M") + + # Illegal operation: hd2 is a child of hd1 + self.reopen(opts[2], {'backing': 'hd1'}, + "Making 'hd1' a backing file of 'hd2' would create a c= ycle") + + # hd2 <- hd0, hd2 <- hd1 + self.reopen(opts[0], {'backing': 'hd2'}) + + self.run_qemu_io("hd1", "read -P 0 0 1M") + self.run_qemu_io("hd1", "read -P 0xa1 1M 1M") + self.run_qemu_io("hd1", "read -P 0xa2 2M 1M") + + # More illegal operations + self.reopen(opts[2], {'backing': 'hd1'}, + "Making 'hd1' a backing file of 'hd2' would create a c= ycle") + self.reopen(opts[2], {'file': 'hd0-file'}, "Cannot change the opti= on 'file'") + + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd2') + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', "Node 'hd2' is busy: node is= used as backing hd of 'hd0'") + + # hd1 doesn't have a backing file now + self.reopen(opts[1], {'backing': None}) + + self.run_qemu_io("hd1", "read -P 0 0 1M") + self.run_qemu_io("hd1", "read -P 0xa1 1M 1M") + self.run_qemu_io("hd1", "read -P 0 2M 1M") + + # We can't remove the 'backing' option if the image has a + # default backing file + del opts[1]['backing'] + self.reopen(opts[1], {}, "backing is missing for 'hd1'") + + self.run_qemu_io("hd1", "read -P 0 0 1M") + self.run_qemu_io("hd1", "read -P 0xa1 1M 1M") + self.run_qemu_io("hd1", "read -P 0 2M 1M") + + # This test verifies that we can't change the children of a block + # device during a reopen operation in a way that would create + # cycles in the node graph + def test_graph_cycles(self): + opts =3D [] + + # Open all three images without backing file + for i in range(3): + opts.append(hd_opts(i)) + opts[i]['backing'] =3D None + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **= opts[i]) + self.assert_qmp(result, 'return', {}) + + # hd1 <- hd0, hd1 <- hd2 + self.reopen(opts[0], {'backing': 'hd1'}) + self.reopen(opts[2], {'backing': 'hd1'}) + + # Illegal: hd2 is backed by hd1 + self.reopen(opts[1], {'backing': 'hd2'}, + "Making 'hd2' a backing file of 'hd1' would create a c= ycle") + + # hd1 <- hd0 <- hd2 + self.reopen(opts[2], {'backing': 'hd0'}) + + # Illegal: hd2 is backed by hd0, which is backed by hd1 + self.reopen(opts[1], {'backing': 'hd2'}, + "Making 'hd2' a backing file of 'hd1' would create a c= ycle") + + # Illegal: hd1 cannot point to itself + self.reopen(opts[1], {'backing': 'hd1'}, + "Making 'hd1' a backing file of 'hd1' would create a c= ycle") + + # Remove all backing files + self.reopen(opts[0]) + self.reopen(opts[2]) + + ########################################## + # Add a blkverify node using hd0 and hd1 # + ########################################## + bvopts =3D {'driver': 'blkverify', + 'node-name': 'bv', + 'test': 'hd0', + 'raw': 'hd1'} + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **bvop= ts) + self.assert_qmp(result, 'return', {}) + + # blkverify doesn't currently allow reopening. TODO: implement this + self.reopen(bvopts, {}, "Block format 'blkverify' used by node 'bv= '" + + " does not support reopening files") + + # Illegal: hd0 is a child of the blkverify node + self.reopen(opts[0], {'backing': 'bv'}, + "Making 'bv' a backing file of 'hd0' would create a cy= cle") + + # Delete the blkverify node + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'bv') + self.assert_qmp(result, 'return', {}) + + # Misc reopen tests with different block drivers + def test_misc_drivers(self): + #################### + ###### quorum ###### + #################### + for i in range(3): + opts =3D hd_opts(i) + # Open all three images without backing file + opts['backing'] =3D None + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **= opts) + self.assert_qmp(result, 'return', {}) + + opts =3D {'driver': 'quorum', + 'node-name': 'quorum0', + 'children': ['hd0', 'hd1', 'hd2'], + 'vote-threshold': 2} + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # Quorum doesn't currently allow reopening. TODO: implement this + self.reopen(opts, {}, "Block format 'quorum' used by node 'quorum0= '" + + " does not support reopening files") + + # You can't make quorum0 a backing file of hd0: + # hd0 is already a child of quorum0. + self.reopen(hd_opts(0), {'backing': 'quorum0'}, + "Making 'quorum0' a backing file of 'hd0' would create= a cycle") + + # Delete quorum0 + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'quorum0') + self.assert_qmp(result, 'return', {}) + + # Delete hd0, hd1 and hd2 + for i in range(3): + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, + node_name =3D 'hd%d' % i) + self.assert_qmp(result, 'return', {}) + + ###################### + ###### blkdebug ###### + ###################### + opts =3D {'driver': 'blkdebug', + 'node-name': 'bd', + 'config': '/dev/null', + 'image': hd_opts(0)} + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # blkdebug allows reopening if we keep the same options + self.reopen(opts) + + # but it currently does not allow changes + self.reopen(opts, {'image': 'hd1'}, "Cannot change the option 'ima= ge'") + self.reopen(opts, {'align': 33554432}, "Cannot change the option '= align'") + self.reopen(opts, {'config': '/non/existent'}, "Cannot change the = option 'config'") + del opts['config'] + self.reopen(opts, {}, "Option 'config' can't be reset to its defau= lt value") + + # Delete the blkdebug node + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'bd') + self.assert_qmp(result, 'return', {}) + + ################## + ###### null ###### + ################## + opts =3D {'driver': 'null-aio', 'node-name': 'root', 'size': 1024} + + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # 1 << 30 is the default value, but we cannot change it explicitly + self.reopen(opts, {'size': (1 << 30)}, "Cannot change the option '= size'") + + # We cannot change 'size' back to its default value either + del opts['size'] + self.reopen(opts, {}, "Option 'size' can't be reset to its default= value") + + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'root') + self.assert_qmp(result, 'return', {}) + + ################## + ###### file ###### + ################## + opts =3D hd_opts(0) + opts['file']['locking'] =3D 'on' + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # 'locking' cannot be changed + del opts['file']['locking'] + self.reopen(opts, {'file.locking': 'on'}) + self.reopen(opts, {'file.locking': 'off'}, "Cannot change the opti= on 'locking'") + self.reopen(opts, {}, "Option 'locking' can't be reset to its defa= ult value") + + # Trying to reopen the 'file' node directly does not make a differ= ence + opts =3D opts['file'] + self.reopen(opts, {'locking': 'on'}) + self.reopen(opts, {'locking': 'off'}, "Cannot change the option 'l= ocking'") + self.reopen(opts, {}, "Option 'locking' can't be reset to its defa= ult value") + + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd0') + self.assert_qmp(result, 'return', {}) + + ###################### + ###### throttle ###### + ###################### + opts =3D { 'qom-type': 'throttle-group', 'id': 'group0', + 'props': { 'limits': { 'iops-total': 1000 } } } + result =3D self.vm.qmp('object-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + opts =3D { 'qom-type': 'throttle-group', 'id': 'group1', + 'props': { 'limits': { 'iops-total': 2000 } } } + result =3D self.vm.qmp('object-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # Add a throttle filter with group =3D group0 + opts =3D { 'driver': 'throttle', 'node-name': 'throttle0', + 'throttle-group': 'group0', 'file': hd_opts(0) } + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # We can reopen it if we keep the same options + self.reopen(opts) + + # We can also reopen if 'file' is a reference to the child + self.reopen(opts, {'file': 'hd0'}) + + # This is illegal + self.reopen(opts, {'throttle-group': 'notfound'}, "Throttle group = 'notfound' does not exist") + + # But it's possible to change the group to group1 + self.reopen(opts, {'throttle-group': 'group1'}) + + # Now group1 is in use, it cannot be deleted + result =3D self.vm.qmp('object-del', id =3D 'group1') + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', "object 'group1' is in use, = can not be deleted") + + # Default options, this switches the group back to group0 + self.reopen(opts) + + # So now we cannot delete group0 + result =3D self.vm.qmp('object-del', id =3D 'group0') + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', "object 'group0' is in use, = can not be deleted") + + # But group1 is free this time, and it can be deleted + result =3D self.vm.qmp('object-del', id =3D 'group1') + self.assert_qmp(result, 'return', {}) + + # Let's delete the filter node + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'throttle0') + self.assert_qmp(result, 'return', {}) + + # And we can finally get rid of group0 + result =3D self.vm.qmp('object-del', id =3D 'group0') + self.assert_qmp(result, 'return', {}) + + # If an image has a backing file then the 'backing' option must be + # passed on reopen. We don't allow leaving the option out in this + # case because it's unclear what the correct semantics would be. + def test_missing_backing_options_1(self): + # hd2 + opts =3D hd_opts(2) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # hd0 + opts =3D hd_opts(0) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # hd0 has no backing file: we can omit the 'backing' option + self.reopen(opts) + + # hd2 <- hd0 + self.reopen(opts, {'backing': 'hd2'}) + + # hd0 has a backing file: we must set the 'backing' option + self.reopen(opts, {}, "backing is missing for 'hd0'") + + # hd2 can't be removed because it's the backing file of hd0 + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd2') + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', "Node 'hd2' is busy: node is= used as backing hd of 'hd0'") + + # Detach hd2 from hd0. + self.reopen(opts, {'backing': None}) + self.reopen(opts, {}, "backing is missing for 'hd0'") + + # Remove both hd0 and hd2 + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd0') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd2') + self.assert_qmp(result, 'return', {}) + + # If an image has default backing file (as part of its metadata) + # then the 'backing' option must be passed on reopen. We don't + # allow leaving the option out in this case because it's unclear + # what the correct semantics would be. + def test_missing_backing_options_2(self): + # hd0 <- hd1 + # (hd0 is hd1's default backing file) + opts =3D hd_opts(1) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # hd1 has a backing file: we can't omit the 'backing' option + self.reopen(opts, {}, "backing is missing for 'hd1'") + + # Let's detach the backing file + self.reopen(opts, {'backing': None}) + + # No backing file attached to hd1 now, but we still can't omit the= 'backing' option + self.reopen(opts, {}, "backing is missing for 'hd1'") + + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd1') + self.assert_qmp(result, 'return', {}) + + # Test that making 'backing' a reference to an existing child + # keeps its current options + def test_backing_reference(self): + # hd2 <- hd1 <- hd0 + opts =3D hd_opts(0) + opts['backing'] =3D hd_opts(1) + opts['backing']['backing'] =3D hd_opts(2) + # Enable 'detect-zeroes' on all three nodes + opts['detect-zeroes'] =3D 'on' + opts['backing']['detect-zeroes'] =3D 'on' + opts['backing']['backing']['detect-zeroes'] =3D 'on' + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # Reopen the chain passing the minimum amount of required options. + # By making 'backing' a reference to hd1 (instead of a sub-dict) + # we tell QEMU to keep its current set of options. + opts =3D {'driver': iotests.imgfmt, + 'node-name': 'hd0', + 'file': 'hd0-file', + 'backing': 'hd1' } + self.reopen(opts) + + # This has reset 'detect-zeroes' on hd0, but not on hd1 and hd2. + self.assert_qmp(self.get_node('hd0'), 'detect_zeroes', 'off') + self.assert_qmp(self.get_node('hd1'), 'detect_zeroes', 'on') + self.assert_qmp(self.get_node('hd2'), 'detect_zeroes', 'on') + + # Test what happens if the graph changes due to other operations + # such as block-stream + def test_block_stream_1(self): + # hd1 <- hd0 + opts =3D hd_opts(0) + opts['backing'] =3D hd_opts(1) + opts['backing']['backing'] =3D None + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # Stream hd1 into hd0 and wait until it's done + result =3D self.vm.qmp('block-stream', conv_keys =3D True, job_id = =3D 'stream0', device =3D 'hd0') + self.assert_qmp(result, 'return', {}) + self.wait_until_completed(drive =3D 'stream0') + + # Now we have only hd0 + self.assertEqual(self.get_node('hd1'), None) + + # We have backing.* options but there's no backing file anymore + self.reopen(opts, {}, "Cannot change the option 'backing.driver'") + + # If we remove the 'backing' option then we can reopen hd0 just fi= ne + del opts['backing'] + self.reopen(opts) + + # We can also reopen hd0 if we set 'backing' to null + self.reopen(opts, {'backing': None}) + + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd0') + self.assert_qmp(result, 'return', {}) + + # Another block_stream test + def test_block_stream_2(self): + # hd2 <- hd1 <- hd0 + opts =3D hd_opts(0) + opts['backing'] =3D hd_opts(1) + opts['backing']['backing'] =3D hd_opts(2) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # Stream hd1 into hd0 and wait until it's done + result =3D self.vm.qmp('block-stream', conv_keys =3D True, job_id = =3D 'stream0', + device =3D 'hd0', base_node =3D 'hd2') + self.assert_qmp(result, 'return', {}) + self.wait_until_completed(drive =3D 'stream0') + + # The chain is hd2 <- hd0 now. hd1 is missing + self.assertEqual(self.get_node('hd1'), None) + + # The backing options in the dict were meant for hd1, but we cannot + # use them with hd2 because hd1 had a backing file while hd2 does = not. + self.reopen(opts, {}, "Cannot change the option 'backing.driver'") + + # If we remove hd1's options from the dict then things work fine + opts['backing'] =3D opts['backing']['backing'] + self.reopen(opts) + + # We can also reopen hd0 if we use a reference to the backing file + self.reopen(opts, {'backing': 'hd2'}) + + # But we cannot leave the option out + del opts['backing'] + self.reopen(opts, {}, "backing is missing for 'hd0'") + + # Now we can delete hd0 (and hd2) + result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd0') + self.assert_qmp(result, 'return', {}) + self.assertEqual(self.get_node('hd2'), None) + + # Reopen the chain during a block-stream job (from hd1 to hd0) + def test_block_stream_3(self): + # hd2 <- hd1 <- hd0 + opts =3D hd_opts(0) + opts['backing'] =3D hd_opts(1) + opts['backing']['backing'] =3D hd_opts(2) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # hd2 <- hd0 + result =3D self.vm.qmp('block-stream', conv_keys =3D True, job_id = =3D 'stream0', + device =3D 'hd0', base_node =3D 'hd2', speed = =3D 512 * 1024) + self.assert_qmp(result, 'return', {}) + + # We can't remove hd2 while the stream job is ongoing + opts['backing']['backing'] =3D None + self.reopen(opts, {}, "Cannot remove link from 'hd1' to 'hd2'") + + # We can't remove hd1 while the stream job is ongoing + opts['backing'] =3D None + self.reopen(opts, {}, "Cannot remove link from 'hd0' to 'hd1'") + + self.wait_until_completed(drive =3D 'stream0') + + # Reopen the chain during a block-stream job (from hd2 to hd1) + def test_block_stream_4(self): + # hd2 <- hd1 <- hd0 + opts =3D hd_opts(0) + opts['backing'] =3D hd_opts(1) + opts['backing']['backing'] =3D hd_opts(2) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + # hd1 <- hd0 + result =3D self.vm.qmp('block-stream', conv_keys =3D True, job_id = =3D 'stream0', + device =3D 'hd1', speed =3D 512 * 1024) + self.assert_qmp(result, 'return', {}) + + # We can't reopen with the original options because that would + # make hd1 read-only and block-stream requires it to be read-write + self.reopen(opts, {}, "Block node is read-only") + + # We can't remove hd2 while the stream job is ongoing + opts['backing']['backing'] =3D None + self.reopen(opts, {'backing.read-only': False}, "Cannot remove lin= k from 'hd1' to 'hd2'") + + # We can detach hd1 from hd0 because it doesn't affect the stream = job + opts['backing'] =3D None + self.reopen(opts) + + self.wait_until_completed(drive =3D 'stream0') + + # Reopen the chain during a block-commit job (from hd0 to hd2) + def test_block_commit_1(self): + # hd2 <- hd1 <- hd0 + opts =3D hd_opts(0) + opts['backing'] =3D hd_opts(1) + opts['backing']['backing'] =3D hd_opts(2) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('block-commit', conv_keys =3D True, job_id = =3D 'commit0', + device =3D 'hd0', speed =3D 1024 * 1024) + self.assert_qmp(result, 'return', {}) + + # We can't remove hd2 while the commit job is ongoing + opts['backing']['backing'] =3D None + self.reopen(opts, {}, "Cannot remove link from 'hd1' to 'hd2'") + + # We can't remove hd1 while the commit job is ongoing + opts['backing'] =3D None + self.reopen(opts, {}, "Cannot remove link from 'hd0' to 'hd1'") + + event =3D self.vm.event_wait(name=3D'BLOCK_JOB_READY') + self.assert_qmp(event, 'data/device', 'commit0') + self.assert_qmp(event, 'data/type', 'commit') + self.assert_qmp_absent(event, 'data/error') + + result =3D self.vm.qmp('block-job-complete', device=3D'commit0') + self.assert_qmp(result, 'return', {}) + + self.wait_until_completed(drive =3D 'commit0') + + # Reopen the chain during a block-commit job (from hd1 to hd2) + def test_block_commit_2(self): + # hd2 <- hd1 <- hd0 + opts =3D hd_opts(0) + opts['backing'] =3D hd_opts(1) + opts['backing']['backing'] =3D hd_opts(2) + result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('block-commit', conv_keys =3D True, job_id = =3D 'commit0', + device =3D 'hd0', top_node =3D 'hd1', speed = =3D 1024 * 1024) + self.assert_qmp(result, 'return', {}) + + # The commit job inserts a temporary node between hd0 and hd1. + # We need its node name in order to check the error messages. + commit_top_name =3D None + result =3D self.vm.qmp('query-named-block-nodes') + for node in result['return']: + if node['drv'] =3D=3D 'commit_top': + commit_top_name =3D node['node-name'] + self.assertIsNotNone(commit_top_name) + + # We can't remove hd2 while the commit job is ongoing + opts['backing']['backing'] =3D None + self.reopen(opts, {}, "Cannot change the option 'backing.driver'") + + # We can't remove hd1 while the commit job is ongoing + opts['backing'] =3D None + self.reopen(opts, {}, "Cannot remove link from '%s' to 'hd1'" % co= mmit_top_name) + + # hd2 <- hd0 + self.wait_until_completed(drive =3D 'commit0') + + self.assert_qmp(self.get_node('hd0'), 'ro', False) + self.assertEqual(self.get_node(commit_top_name), None) + self.assertEqual(self.get_node('hd1'), None) + self.assert_qmp(self.get_node('hd2'), 'ro', True) + +if __name__ =3D=3D '__main__': + iotests.main(supported_fmts=3D["qcow2"]) diff --git a/tests/qemu-iotests/224.out b/tests/qemu-iotests/224.out new file mode 100644 index 0000000000..52d796e60b --- /dev/null +++ b/tests/qemu-iotests/224.out @@ -0,0 +1,5 @@ +................. +---------------------------------------------------------------------- +Ran 17 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 8c56a0ad11..50f68b05e5 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -224,6 +224,7 @@ 221 rw auto quick 222 rw auto quick 223 rw auto quick +224 rw auto quick 225 rw auto quick 226 auto quick 227 auto quick --=20 2.11.0