From patchwork Thu Nov 28 18:25:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 13888275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F685D70DEB for ; Thu, 28 Nov 2024 18:40:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGjQb-00074g-M8; Thu, 28 Nov 2024 13:39:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQL-0006yL-Pr; Thu, 28 Nov 2024 13:39:34 -0500 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQI-00060K-Fo; Thu, 28 Nov 2024 13:39:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=T6/ShqNd7xJYNMPPHGpqxmzqmNhUuqpMqpttUwz93z0=; b=ky1fwoZwcM11 +LcP5EwVPNYtlGv9rcvasmG6KQPrOz+u5adXCUBaQ52gQgUmCDZDybRdm/CRMcheovWYZ22ewi/l+ Opg5qjOv9lhTbuUrxFqRDzoUtaGbMsIU5Nzs0z8X6X3GCxNJPyC9TK6lQ8GluiJq1Bo5Ok125wevM GIKbjDfHk4e9/ftP58hM9a/4iUn7rnJGR3fKhZSPop5Wg9O8xQDRsNU9HAoV5sT2OaTxLhUDk2Wrb VqJl7R9l7+n5gUf6PcaV6irj1uHP74gKuaVz2N5xLKjA+kzUqQJCwkeDzg7rdppbNnWR1+N9RBzec F20dx4nkIKomSBrxkK9q4g==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=iris.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1tGjPn-00E2DN-33; Thu, 28 Nov 2024 19:39:09 +0100 To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: den@openvz.org, Vladimir Sementsov-Ogievskiy , Andrey Drobyshev , Kevin Wolf , Hanna Reitz Subject: [PATCH 1/6] preallocate: truncate the image inside bdrv_inactivate() Date: Thu, 28 Nov 2024 19:25:48 +0100 Message-ID: <20241128183911.837699-2-den@openvz.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241128183911.837699-1-den@openvz.org> References: <20241128183911.837699-1-den@openvz.org> MIME-Version: 1.0 Received-SPF: pass client-ip=130.117.225.111; envelope-from=den@openvz.org; helo=relay.virtuozzo.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Denis V. Lunev" X-Patchwork-Original-From: "Denis V. Lunev" via From: "Denis V. Lunev\" via" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Let us assume that we have the following quite usual chain: QCOW2 -> preallocate-filter -> raw-file In this case in the case of the migration over shared storage, f.e. NFS we go through bdrv_inactivate() bdrv_inactivate_recurse() qcow2_inactivate() <- writes a lot of data, f.e. CBT bdrv_get_cumulative_perm(qcow2) qcow2->open_flags |= BDRV_O_INACTIVE; bdrv_refresh_perms(qcow2) bdrv_inactivate_recurse(preallocate) preallocate_inactivate() bdrv_get_cumulative_perm(preallocate) preallocate->open_flags |= BDRV_O_INACTIVE; bdrv_refresh_perms(preallocate) Right now preallocate_set_perm() is called through bdrv_refresh_perms(qcow2) and this is the only moment when permissions for the entire chain could be changed. If we will deny write permissions here for the sake of the next step, the only place left for a whole set of permissions changes would be preallocate_inactivate() callback. This is all looking really terrible. In addition to this, we are in trouble due truncate() operation requested inside prealloc_set_perm() would be in reality called seriously later, potentially once we have returned from bdrv_inactivate() to the caller and the control has been passed to the migration target. This patch has truncated the image inside preallocate_inactivate() thus making further work inside preallocate_drop_resize_bh() noop. Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev CC: Kevin Wolf CC: Hanna Reitz --- block/preallocate.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/preallocate.c b/block/preallocate.c index d215bc5d6d..c14e6a530d 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -594,6 +594,11 @@ static void preallocate_child_perm(BlockDriverState *bs, BdrvChild *c, } } +static int GRAPH_RDLOCK preallocate_inactivate(BlockDriverState *bs) +{ + return preallocate_drop_resize(bs, NULL); +} + static BlockDriver bdrv_preallocate_filter = { .format_name = "preallocate", .instance_size = sizeof(BDRVPreallocateState), @@ -616,6 +621,8 @@ static BlockDriver bdrv_preallocate_filter = { .bdrv_set_perm = preallocate_set_perm, .bdrv_child_perm = preallocate_child_perm, + .bdrv_inactivate = preallocate_inactivate, + .is_filter = true, }; From patchwork Thu Nov 28 18:25:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 13888277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45E77D70DEB for ; Thu, 28 Nov 2024 18:40:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGjQW-000735-Rc; Thu, 28 Nov 2024 13:39:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQN-0006zW-NH; Thu, 28 Nov 2024 13:39:35 -0500 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQI-00060J-HN; Thu, 28 Nov 2024 13:39:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=eFKiUc6Dqon9qjQmOVmuIQxOp19FJBFUFGirXOnfNrE=; b=aPHeyWz1z4gU zve7/yxfXxeEtK5LB5WXNzFm9OgeV7yXQ1aa3lwIIh8Tey/pPqRjyu7EBgXmzLuHFChL5+TkkOtlI 0NVbM/Dw1LggV5Fck5cxnTe/qqEIkn+r1S/Hu83QlkKgDi7dvu6ChF1kQjow1Ev2LqScWCaSSr2lO gtLaXsNbfm+9tXDFt/BeIwW5MD89neQ43IEkQkpB1IfWFQExA10zorms7bM7sbch1NNCBngOt47DA NlXMgMkdvCDMwywuGFzeOJ0XFizjXHyIB9o2YectRUVZEM+wh3OkHMFbX8bF0OeklCfXanuJkYGsh 2dqEBLGGM0yvpTUmJNcy5Q==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=iris.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1tGjPo-00E2DN-0n; Thu, 28 Nov 2024 19:39:10 +0100 To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: den@openvz.org, Vladimir Sementsov-Ogievskiy , Andrey Drobyshev , Kevin Wolf , Hanna Reitz Subject: [PATCH 2/6] preallocate: do not enable filter inside preallocate_co_getlength() Date: Thu, 28 Nov 2024 19:25:49 +0100 Message-ID: <20241128183911.837699-3-den@openvz.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241128183911.837699-1-den@openvz.org> References: <20241128183911.837699-1-den@openvz.org> MIME-Version: 1.0 Received-SPF: pass client-ip=130.117.225.111; envelope-from=den@openvz.org; helo=relay.virtuozzo.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Denis V. Lunev" X-Patchwork-Original-From: "Denis V. Lunev" via From: "Denis V. Lunev\" via" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Let us auto-enable it inside handle_write() and truncate(), i.e. on the actual write operation. This just makes things more relaxing. Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev CC: Kevin Wolf CC: Hanna Reitz --- block/preallocate.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/block/preallocate.c b/block/preallocate.c index c14e6a530d..d0ed56eecb 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -494,20 +494,13 @@ static int coroutine_fn GRAPH_RDLOCK preallocate_co_flush(BlockDriverState *bs) static int64_t coroutine_fn GRAPH_RDLOCK preallocate_co_getlength(BlockDriverState *bs) { - int64_t ret; BDRVPreallocateState *s = bs->opaque; if (s->data_end >= 0) { return s->data_end; } - ret = bdrv_co_getlength(bs->file->bs); - - if (has_prealloc_perms(bs)) { - s->file_end = s->zero_start = s->data_end = ret; - } - - return ret; + return bdrv_co_getlength(bs->file->bs); } static int GRAPH_RDLOCK From patchwork Thu Nov 28 18:25:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 13888280 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 117ECD70DE8 for ; Thu, 28 Nov 2024 18:41:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGjQQ-000714-Hx; Thu, 28 Nov 2024 13:39:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQL-0006yN-Qy; Thu, 28 Nov 2024 13:39:34 -0500 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQI-00060M-I4; Thu, 28 Nov 2024 13:39:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=XJ42Z62QlzdbZHtaE5BzFMve5MgZ1kwBIfta+yFGPaM=; b=Q6NGYyHZQ0p6 9oVMRMdoDgOfvXkPRiT6VhdI3z5YCYk2mkVE3B28jg+RYJkTQIs4jmJFpIjiMFW0QkPhpgFXjpHun DvYFlchkC60doKRxtInGbkpN86vtPxHUwSZjGl/yj9IUAoZzYXM0IEyJXsBdUQS9RNf8hIRJa0d5A x2ozFE0gfFwL2SH2FZQCr8E7Ceht/ULX+T9Q6VzIpHHtxbhG3SvNBusbjQScq9HOncNmtB+8mIHB9 fdkCdRA+gzbCEP3GhEU71JWH70Mz3y3xQsf9NVUrPdeiAi0iFNBCtcDA+gJIsenJX9+0WuMWseiUa ByWsjlXY0LiG5waHsXcxWA==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=iris.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1tGjPo-00E2DN-1t; Thu, 28 Nov 2024 19:39:10 +0100 To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: den@openvz.org, Vladimir Sementsov-Ogievskiy , Andrey Drobyshev , Kevin Wolf , Hanna Reitz Subject: [PATCH 3/6] preallocate: rework preallocate_truncate_to_real_size() Date: Thu, 28 Nov 2024 19:25:50 +0100 Message-ID: <20241128183911.837699-4-den@openvz.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241128183911.837699-1-den@openvz.org> References: <20241128183911.837699-1-den@openvz.org> MIME-Version: 1.0 Received-SPF: pass client-ip=130.117.225.111; envelope-from=den@openvz.org; helo=relay.virtuozzo.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Denis V. Lunev" X-Patchwork-Original-From: "Denis V. Lunev" via From: "Denis V. Lunev\" via" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The filter is not enabled if s->data_end is negative. In this case it would be useless completely to initialize s->file_end inside preallocate_truncate_to_real_size() without setting s->data_end. Here are we are going to reset the state and disable the filter as we are either in the process of switching to the read-only state or the driver is being closed. Now the driver is disabled unconditionally even on the error and this is pretty much correct. In the worst case the image would be a bit longer and that is all. The patch also adds redundant check for bs->open_flags into this helper for the convinience. Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev CC: Kevin Wolf CC: Hanna Reitz --- block/preallocate.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/block/preallocate.c b/block/preallocate.c index d0ed56eecb..65c1ff5d78 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -179,12 +179,11 @@ preallocate_truncate_to_real_size(BlockDriverState *bs, Error **errp) BDRVPreallocateState *s = bs->opaque; int ret; - if (s->file_end < 0) { - s->file_end = bdrv_getlength(bs->file->bs); - if (s->file_end < 0) { - error_setg_errno(errp, -s->file_end, "Failed to get file length"); - return s->file_end; - } + if (!(bs->open_flags & BDRV_O_RDWR)) { + return 0; + } + if (s->data_end < 0) { + return 0; } if (s->data_end < s->file_end) { @@ -192,11 +191,9 @@ preallocate_truncate_to_real_size(BlockDriverState *bs, Error **errp) NULL); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to drop preallocation"); - s->file_end = ret; - return ret; } - s->file_end = s->data_end; } + s->data_end = s->file_end = s->zero_start = -EINVAL; return 0; } @@ -211,9 +208,7 @@ static void preallocate_close(BlockDriverState *bs) qemu_bh_cancel(s->drop_resize_bh); qemu_bh_delete(s->drop_resize_bh); - if (s->data_end >= 0) { - preallocate_truncate_to_real_size(bs, NULL); - } + preallocate_truncate_to_real_size(bs, NULL); } @@ -528,8 +523,6 @@ preallocate_drop_resize(BlockDriverState *bs, Error **errp) * change the child, so mark all states invalid. We'll regain control if a * parent requests write access again. */ - s->data_end = s->file_end = s->zero_start = -EINVAL; - bdrv_child_refresh_perms(bs, bs->file, NULL); return 0; From patchwork Thu Nov 28 18:25:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 13888279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5155FD70DEB for ; Thu, 28 Nov 2024 18:40:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGjQU-00072l-KK; Thu, 28 Nov 2024 13:39:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQN-0006zY-Na; Thu, 28 Nov 2024 13:39:35 -0500 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQI-00060I-G1; Thu, 28 Nov 2024 13:39:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=xrg7ndqG9+Oki7uB+Q6dALsj7L6NNtOivee5Srln6YM=; b=Mn4PwxBUan3S WSefy3p3bE6Iu2r3m3V3McF0ol02uqTk6FyiO/T/YTwj50vWtxHMfcgaju/18Xqm7SzZ7YMsU/ks2 V1VfF9nUQXhx4BLu6dBg4d9ht/22rdq6PVwd/73MLoIJx/YxoZknOZcsEHhC3BCixWFDRqIEsLhrR eUa8ByeS+Ab2zG5qGX0V9PEDnzaOZ1v9LqTek6ETAdXlOgECoB5aFK0vgVt0kQ6xYOvvj/MGeG1wK /FdYZNpf5pNs89a9pTm5n5SYBpkxeXzrLqkcEbix78jK46/IQa+7vn4O+7ipiYkzMx0tIZBhzg3Io +qTtMiihwcA00x89wWWWeA==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=iris.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1tGjPo-00E2DN-2s; Thu, 28 Nov 2024 19:39:10 +0100 To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: den@openvz.org, Vladimir Sementsov-Ogievskiy , Andrey Drobyshev , Kevin Wolf , Hanna Reitz Subject: [PATCH 4/6] preallocate: remove bottom half from preallocate filter Date: Thu, 28 Nov 2024 19:25:51 +0100 Message-ID: <20241128183911.837699-5-den@openvz.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241128183911.837699-1-den@openvz.org> References: <20241128183911.837699-1-den@openvz.org> MIME-Version: 1.0 Received-SPF: pass client-ip=130.117.225.111; envelope-from=den@openvz.org; helo=relay.virtuozzo.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Denis V. Lunev" X-Patchwork-Original-From: "Denis V. Lunev" via From: "Denis V. Lunev\" via" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org IO operations like truncate inside preallocate_set_perm() looks like insane complexity which should not seen in the reality. Preallocate filter lifecycle is very close to the lifecycle of CBT. This is well handled inside QCOW2 driver. The approach should be the same inside preallocation filter. It should be enough to be handled inside preallocate_reopen_prepare() and preallocate_inactivate(). There is no more need to have preallocate_set_perm() and preallocate_child_perm() perms. Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev CC: Kevin Wolf CC: Hanna Reitz --- block/preallocate.c | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/block/preallocate.c b/block/preallocate.c index 65c1ff5d78..c448258c42 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -75,13 +75,9 @@ typedef struct BDRVPreallocateState { * be invalid (< 0) when we don't have both exclusive BLK_PERM_RESIZE and * BLK_PERM_WRITE permissions on file child. */ - - /* Gives up the resize permission on children when parents don't need it */ - QEMUBH *drop_resize_bh; } BDRVPreallocateState; static int preallocate_drop_resize(BlockDriverState *bs, Error **errp); -static void preallocate_drop_resize_bh(void *opaque); #define PREALLOCATE_OPT_PREALLOC_ALIGN "prealloc-align" #define PREALLOCATE_OPT_PREALLOC_SIZE "prealloc-size" @@ -150,7 +146,6 @@ static int preallocate_open(BlockDriverState *bs, QDict *options, int flags, * For this to work, mark them invalid. */ s->file_end = s->zero_start = s->data_end = -EINVAL; - s->drop_resize_bh = qemu_bh_new(preallocate_drop_resize_bh, bs); ret = bdrv_open_file_child(NULL, options, "file", bs, errp); if (ret < 0) { @@ -200,14 +195,9 @@ preallocate_truncate_to_real_size(BlockDriverState *bs, Error **errp) static void preallocate_close(BlockDriverState *bs) { - BDRVPreallocateState *s = bs->opaque; - GLOBAL_STATE_CODE(); GRAPH_RDLOCK_GUARD_MAINLOOP(); - qemu_bh_cancel(s->drop_resize_bh); - qemu_bh_delete(s->drop_resize_bh); - preallocate_truncate_to_real_size(bs, NULL); } @@ -528,34 +518,6 @@ preallocate_drop_resize(BlockDriverState *bs, Error **errp) return 0; } -static void preallocate_drop_resize_bh(void *opaque) -{ - GLOBAL_STATE_CODE(); - GRAPH_RDLOCK_GUARD_MAINLOOP(); - - /* - * In case of errors, we'll simply keep the exclusive lock on the image - * indefinitely. - */ - preallocate_drop_resize(opaque, NULL); -} - -static void GRAPH_RDLOCK -preallocate_set_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared) -{ - BDRVPreallocateState *s = bs->opaque; - - if (can_write_resize(perm)) { - qemu_bh_cancel(s->drop_resize_bh); - if (s->data_end < 0) { - s->data_end = s->file_end = s->zero_start = - bs->file->bs->total_sectors * BDRV_SECTOR_SIZE; - } - } else { - qemu_bh_schedule(s->drop_resize_bh); - } -} - static void preallocate_child_perm(BlockDriverState *bs, BdrvChild *c, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) @@ -604,7 +566,6 @@ static BlockDriver bdrv_preallocate_filter = { .bdrv_co_flush = preallocate_co_flush, .bdrv_co_truncate = preallocate_co_truncate, - .bdrv_set_perm = preallocate_set_perm, .bdrv_child_perm = preallocate_child_perm, .bdrv_inactivate = preallocate_inactivate, From patchwork Thu Nov 28 18:25:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 13888276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5B8DBD70DE8 for ; Thu, 28 Nov 2024 18:40:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGjQa-00074Z-FJ; Thu, 28 Nov 2024 13:39:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQN-0006zV-MZ; Thu, 28 Nov 2024 13:39:35 -0500 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQI-00060N-Jo; Thu, 28 Nov 2024 13:39:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=fk8PGJQHc/q4BIWFO0ftad01xvv3zgbb9jJTTEfmY/w=; b=Pw9ExQjRBGPv Kn1P/KK5HdgCpMk+Nwp3alqJL3iFBYXqfwv8B/qLQZR9GSBYI1aGLcas2aKtv5YGSXlmqnqt4xjv/ RAnXcZsN9dD8/dSl/s/T/Qg5cFZOmwEZwDRS22fmdDQywssVhpD/q7PUX0XEXxismcg+zfhIbUUpb KJI8oSaUDnAWkq+PsUe01jDozvkK8OieKLD6SDVO6OHspyjLRqwIH5iIjVjcXBO5sYHrvp6jVuCVP EK03ij9UO4VJoLc4np80e5OMkLph7XDzOgNzDCMG5BXRF4aCNi3h/ErtDO2g9ECohWzSrFV4FuN+A kauMtxXGAKlzRSxOITf08w==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=iris.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1tGjPp-00E2DN-0c; Thu, 28 Nov 2024 19:39:10 +0100 To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: den@openvz.org, Vladimir Sementsov-Ogievskiy , Andrey Drobyshev , Kevin Wolf , Hanna Reitz Subject: [PATCH 5/6] preallocate: simplify preallocate_drop_resize Date: Thu, 28 Nov 2024 19:25:52 +0100 Message-ID: <20241128183911.837699-6-den@openvz.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241128183911.837699-1-den@openvz.org> References: <20241128183911.837699-1-den@openvz.org> MIME-Version: 1.0 Received-SPF: pass client-ip=130.117.225.111; envelope-from=den@openvz.org; helo=relay.virtuozzo.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Denis V. Lunev" X-Patchwork-Original-From: "Denis V. Lunev" via From: "Denis V. Lunev\" via" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Once permission change process is normalized, there is no need to have permission update inside preallocate_drop_resize() and preallocate_truncate_to_real_size() could be merged into the caller. Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev CC: Kevin Wolf CC: Hanna Reitz --- block/preallocate.c | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/block/preallocate.c b/block/preallocate.c index c448258c42..886b1311f2 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -77,8 +77,6 @@ typedef struct BDRVPreallocateState { */ } BDRVPreallocateState; -static int preallocate_drop_resize(BlockDriverState *bs, Error **errp); - #define PREALLOCATE_OPT_PREALLOC_ALIGN "prealloc-align" #define PREALLOCATE_OPT_PREALLOC_SIZE "prealloc-size" static QemuOptsList runtime_opts = { @@ -169,7 +167,7 @@ static int preallocate_open(BlockDriverState *bs, QDict *options, int flags, } static int GRAPH_RDLOCK -preallocate_truncate_to_real_size(BlockDriverState *bs, Error **errp) +preallocate_drop_resize(BlockDriverState *bs, Error **errp) { BDRVPreallocateState *s = bs->opaque; int ret; @@ -198,7 +196,7 @@ static void preallocate_close(BlockDriverState *bs) GLOBAL_STATE_CODE(); GRAPH_RDLOCK_GUARD_MAINLOOP(); - preallocate_truncate_to_real_size(bs, NULL); + preallocate_drop_resize(bs, NULL); } @@ -488,36 +486,6 @@ preallocate_co_getlength(BlockDriverState *bs) return bdrv_co_getlength(bs->file->bs); } -static int GRAPH_RDLOCK -preallocate_drop_resize(BlockDriverState *bs, Error **errp) -{ - BDRVPreallocateState *s = bs->opaque; - int ret; - - if (s->data_end < 0) { - return 0; - } - - /* - * Before switching children to be read-only, truncate them to remove - * the preallocation and let them have the real size. - */ - ret = preallocate_truncate_to_real_size(bs, errp); - if (ret < 0) { - return ret; - } - - /* - * We'll drop our permissions and will allow other users to take write and - * resize permissions (see preallocate_child_perm). Anyone will be able to - * change the child, so mark all states invalid. We'll regain control if a - * parent requests write access again. - */ - bdrv_child_refresh_perms(bs, bs->file, NULL); - - return 0; -} - static void preallocate_child_perm(BlockDriverState *bs, BdrvChild *c, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) From patchwork Thu Nov 28 18:25:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 13888278 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 564E5D70DE8 for ; Thu, 28 Nov 2024 18:40:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGjQZ-000743-1O; Thu, 28 Nov 2024 13:39:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQL-0006yM-QV; Thu, 28 Nov 2024 13:39:34 -0500 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGjQI-00060O-Fq; Thu, 28 Nov 2024 13:39:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=UhBwOVLNTmzdrnNMePKQwoRxWaPb6x4aFbZNwX4XSQo=; b=N2JXXUvkaI4W W84aPRlNwFC/d6pV21NNAbAqeCrfxIa1PEOsJvX+uLntvYACV88MtkqHJ1YM4yuLra/uEafcrhoIQ BdOv7nL0kNkMusHOKyqVfK0nIDI/55tPKablsm6iORaOAWF66OFbVDY1azx93e1WvcArPK0POma0r pKuBTqIvW6NXZFd/Yf6QhySdAOHASEU1hVnz68/kGB0RGPMkAurYA7tExloLB0Ru07Vq4MfGSNu7s tkYSJRHs75Wrf3YM7/+DtPoWbCzRNUcWpaQ896QnXonV+7iETCA7vshvMY4Syk9T6oHkyZBbSDVoz do729TMeenZb/2biLS5zvQ==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=iris.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1tGjPp-00E2DN-1Z; Thu, 28 Nov 2024 19:39:11 +0100 To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: den@openvz.org, Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz Subject: [PATCH 6/6] iotests: add preallocate filter checks Date: Thu, 28 Nov 2024 19:25:53 +0100 Message-ID: <20241128183911.837699-7-den@openvz.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241128183911.837699-1-den@openvz.org> References: <20241128183911.837699-1-den@openvz.org> MIME-Version: 1.0 Received-SPF: pass client-ip=130.117.225.111; envelope-from=den@openvz.org; helo=relay.virtuozzo.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Denis V. Lunev" X-Patchwork-Original-From: "Denis V. Lunev" via From: "Denis V. Lunev\" via" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Andrey Drobyshev This test summaries the cases faced inside Virtuozzo with the preallocation filter worth to be added to unit tests: 1. Launch a VM whose block graph has preallocate filter node and migrate it locally into a file. 2. Same, but make sure preallocate filter is activated by performing a write op to it beyond the current disk length (which is zero). 3. Add testcase which would perform write operation to VM disk to make sure preallocation filter is active, and then run 'blockdev-snapshot' command to turn another image (also with preallocation) into an external snapshot and make it an active disk. Signed-off-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev CC: Kevin Wolf CC: Hanna Reitz --- tests/qemu-iotests/tests/prealloc-checks | 222 +++++++++++++++++++ tests/qemu-iotests/tests/prealloc-checks.out | 81 +++++++ 2 files changed, 303 insertions(+) create mode 100644 tests/qemu-iotests/tests/prealloc-checks create mode 100644 tests/qemu-iotests/tests/prealloc-checks.out diff --git a/tests/qemu-iotests/tests/prealloc-checks b/tests/qemu-iotests/tests/prealloc-checks new file mode 100644 index 0000000000..fc55353cb9 --- /dev/null +++ b/tests/qemu-iotests/tests/prealloc-checks @@ -0,0 +1,222 @@ +#!/usr/bin/env bash +# group: rw +# +# Checks for preallocate filter. +# +# Copyright (c) 2024 Virtuozzo International GmbH. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=andrey.drobyshev@virtuozzo.com + +seq=`basename $0` +echo "QA output created by $seq" + +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_qemu + rm -f $SOCK_DIR/nbd.sock + rm -f $TEST_IMG.snap + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ../common.rc +. ../common.filter +. ../common.qemu + +_supported_fmt qcow2 + +_recreate_test_img() +{ + local size="1M" + local imgopts="cluster_size=$size,extended_l2=on,lazy_refcounts=on" + local image="$TEST_IMG" + + if test -n "$1" ; then + image="$1" + fi + + rm -f $image + TEST_IMG=$image _make_test_img -o "$imgopts" $size +} + +blkopts="node-name=disk,driver=qcow2,file.driver=preallocate," +blkopts+="file.node-name=prealloc,file.file.driver=file," +blkopts+="file.file.filename=$TEST_IMG,file.file.node-name=storage" + +# +# 1. Launch a VM so that its block graph contains preallocate filter node, +# and perform its local migration to a file. That is similar to doing +# "virsh save VM /path/to/vmsave". +# + +echo +echo === 1. Migration to a local file === +echo + +echo "# Create image and start VM with preallocate filter:" +echo +_recreate_test_img +qemu_comm_method="monitor" _launch_qemu -blockdev "$blkopts" +handle=$QEMU_HANDLE +_send_qemu_cmd $handle "" "(qemu)" + +echo +echo "# Migrate VM to a local file (/dev/null):" +echo +_send_qemu_cmd $handle "migrate \"exec: cat > '/dev/null'\"" "(qemu)" + +echo +echo "# Exit VM:" +echo +_send_qemu_cmd $handle "quit" "" +wait=yes _cleanup_qemu + +# +# 2. Same as 1st, but this time we make sure that preallocate filter is +# actually active. To do that we perform a write op beyond current length +# (which is 0 as the image's just created). Then migrate VM to a local +# file (/dev/null). +# + +echo +echo === 2. Migration to a local file after a write operation === +echo + +echo "# Create image and start VM with preallocate filter:" +echo +_recreate_test_img +qemu_comm_method="monitor" _launch_qemu -blockdev "$blkopts" +handle=$QEMU_HANDLE +_send_qemu_cmd $handle "" "(qemu)" + +echo +echo "# Perform write op to the image to activate preallocate filter:" +echo +_send_qemu_cmd $handle 'qemu-io disk "write -P 0xff 0 1M"' "1 MiB" + +echo +echo "# Migrate VM to a local file (/dev/null):" +echo +_send_qemu_cmd $handle "migrate \"exec: cat > '/dev/null'\"" "(qemu)" + +echo +echo "# Exit VM:" +echo +_send_qemu_cmd $handle "quit" "" +wait=yes _cleanup_qemu + +# +# 3. Add another overlay image (with preallocation filter as well), launch +# VM, export its disk via nbd to perform a write operation and activate the +# preallocation filter, and then run 'blockdev-snapshot' to turn the overlay +# image into an external snapshot of the disk. +# + +echo +echo === 3. Taking external snapshot after a write operation === +echo + +snapblkopts="node-name=snap,driver=qcow2,file.driver=preallocate," +snapblkopts+="file.node-name=snap-prealloc,file.file.driver=file," +snapblkopts+="file.file.filename=$TEST_IMG.snap," +snapblkopts+="file.file.node-name=snap-storage" + +echo "# Create disk and snapshot images and start VM with preallocate filter:" +echo +_recreate_test_img +_recreate_test_img $TEST_IMG.snap + +qemu_comm_method="qmp" qmp_pretty= \ + _launch_qemu -blockdev "$snapblkopts" -blockdev "$blkopts" +handle=$QEMU_HANDLE +_send_qemu_cmd $handle "{ 'execute': 'qmp_capabilities' }" "return" + +silent=yes + +echo +echo "# Start nbd server:" +echo +_send_qemu_cmd $handle \ + "{ 'execute': 'nbd-server-start', + 'arguments': { 'addr': { 'type': 'unix', + 'data': { 'path': '$SOCK_DIR/nbd.sock' }}}}" +_send_qemu_cmd $handle "" "return" + +echo +echo "# Export 'disk' node via nbd server:" +echo +_send_qemu_cmd $handle \ + "{ 'execute': 'block-export-add', + 'arguments': { 'type': 'nbd', 'node-name': 'disk', 'id': 'nbdexp', + 'name': 'nbdexp', 'writable': true }}" +_send_qemu_cmd $handle "" "return" + +echo +echo "# Perform write op to the nbd-exported disk:" +echo +silent= +$QEMU_IO_PROG -f raw -c "write -P 0xff 0 1M" \ + "nbd+unix:///nbdexp?socket=$SOCK_DIR/nbd.sock" 2>&1 \ + | _filter_qemu_io | _filter_nbd + +echo +echo "# Delete nbd export:" +echo +silent=yes +_send_qemu_cmd $handle \ + "{ 'execute': 'block-export-del', 'arguments': { 'id': 'nbdexp' }}" +_send_qemu_cmd $handle "" "return" + +echo +echo "# Stop nbd server:" +echo +_send_qemu_cmd $handle \ + "{ 'execute': 'nbd-server-stop' }" +_send_qemu_cmd $handle "" "return" + +echo +echo "# Turn 'snap' node into the external snapshot of 'disk' node:" +echo +silent= +_send_qemu_cmd $handle \ + "{ 'execute': 'blockdev-snapshot', + 'arguments': { 'node': 'disk', 'overlay': 'snap' }}" +_send_qemu_cmd $handle "" "return" + +echo +echo "# Check block graph:" +echo +_send_qemu_cmd $handle \ + "{ 'execute': 'x-debug-query-block-graph' }" +_send_qemu_cmd $handle "" "return" + +echo +echo "# Exit VM:" +echo +qmp_pretty= +silent=yes +_send_qemu_cmd $handle "{ 'execute': 'quit' }" "qmp-quit" +wait=yes _cleanup_qemu + +# success, all done +echo "*** done" +rm -f $seq.full +status=0 diff --git a/tests/qemu-iotests/tests/prealloc-checks.out b/tests/qemu-iotests/tests/prealloc-checks.out new file mode 100644 index 0000000000..10b5f8fa8e --- /dev/null +++ b/tests/qemu-iotests/tests/prealloc-checks.out @@ -0,0 +1,81 @@ +QA output created by prealloc-checks + +=== 1. Migration to a local file === + +# Create image and start VM with preallocate filter: + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) + +# Migrate VM to a local file (/dev/null): + +(qemu) migrate "exec: cat > '/dev/null'" + +# Exit VM: + +(qemu) quit + +=== 2. Migration to a local file after a write operation === + +# Create image and start VM with preallocate filter: + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) + +# Perform write op to the image to activate preallocate filter: + +(qemu) qemu-io disk "write -P 0xff 0 1M" +wrote 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Migrate VM to a local file (/dev/null): + +(qemu) migrate "exec: cat > '/dev/null'" + +# Exit VM: + +(qemu) quit + +=== 3. Taking external snapshot after a write operation === + +# Create disk and snapshot images and start VM with preallocate filter: + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +Formatting 'TEST_DIR/t.IMGFMT.snap', fmt=IMGFMT size=1048576 +{ 'execute': 'qmp_capabilities' } +{"return": {}} + +# Start nbd server: + + +# Export 'disk' node via nbd server: + + +# Perform write op to the nbd-exported disk: + +wrote 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Delete nbd export: + + +# Stop nbd server: + + +# Turn 'snap' node into the external snapshot of 'disk' node: + +{ 'execute': 'blockdev-snapshot', + 'arguments': { 'node': 'disk', 'overlay': 'snap' }} +{"return": {}} + +# Check block graph: + +{ 'execute': 'x-debug-query-block-graph' } +{"return": {"edges": [{"name": "file", "parent": 4, "shared-perm": ["write-unchanged", "consistent-read"], "perm": ["consistent-read"], "child": 6}, {"name": "file", "parent": 6, "shared-perm": ["write-unchanged", "consistent-read"], "perm": ["consistent-read"], "child": 5}, {"name": "file", "parent": 3, "shared-perm": ["write-unchanged", "consistent-read"], "perm": ["resize", "write", "consistent-read"], "child": 2}, {"name": "backing", "parent": 3, "shared-perm": ["resize", "write-unchanged", "write", "consistent-read"], "perm": [], "child": 4}, {"name": "file", "parent": 2, "shared-perm": ["write-unchanged", "consistent-read"], "perm": ["resize", "write", "consistent-read"], "child": 1}], "nodes": [{"name": "disk", "type": "block-driver", "id": 4}, {"name": "prealloc", "type": "block-driver", "id": 6}, {"name": "storage", "type": "block-driver", "id": 5}, {"name": "snap", "type": "block-driver", "id": 3}, {"name": "snap-prealloc", "type": "block-driver", "id": 2}, {"name": "snap-storage", "type": "block-driver", "id": 1}]}} + +# Exit VM: + +{"return": {}} +*** done