From nobody Thu Dec 26 22:33:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1732819228; cv=none; d=zohomail.com; s=zohoarc; b=O5X4yicBsIey2HY8comzfrYuAsQExrGdhkABfjUaXpzxBpX2IdmrdvMTrDN3tPCt3wpsfLDMnj8as4bDdLcN7NBlfQ4BxPH4tmb4UZxBUCIC9LFFDeBohBT4MOJACdYkAA1B0LWcDUIsWEvKMU9D5zlfjx9YR4UqelchqvQC6tM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732819228; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=T6/ShqNd7xJYNMPPHGpqxmzqmNhUuqpMqpttUwz93z0=; b=cc659GHRB3iQ6KwrAvETneGHxm5xgVVbw3J+rcRwqTETtnuTCRjUhYVWp3IgDR+ZB9klM6Z57mCXqq2/ZThvmbZOBJvfA4HaQws7X5mDPO5XjB2W7iJ7W/if+/XiYIUbynnAN+LZNILIyYRAO+Q6Q6uIIDziWxPy4fijLh2eBSk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732819228288151.32176663172277; Thu, 28 Nov 2024 10:40:28 -0800 (PST) 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 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 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==; 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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" From: "Denis V. Lunev" via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1732819228957019100 Content-Type: text/plain; charset="utf-8" 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 |=3D BDRV_O_INACTIVE; bdrv_refresh_perms(qcow2) bdrv_inactivate_recurse(preallocate) preallocate_inactivate() bdrv_get_cumulative_perm(preallocate) preallocate->open_flags |=3D 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 *b= s, BdrvChild *c, } } =20 +static int GRAPH_RDLOCK preallocate_inactivate(BlockDriverState *bs) +{ + return preallocate_drop_resize(bs, NULL); +} + static BlockDriver bdrv_preallocate_filter =3D { .format_name =3D "preallocate", .instance_size =3D sizeof(BDRVPreallocateState), @@ -616,6 +621,8 @@ static BlockDriver bdrv_preallocate_filter =3D { .bdrv_set_perm =3D preallocate_set_perm, .bdrv_child_perm =3D preallocate_child_perm, =20 + .bdrv_inactivate =3D preallocate_inactivate, + .is_filter =3D true, }; =20 --=20 2.45.2 From nobody Thu Dec 26 22:33:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1732819238; cv=none; d=zohomail.com; s=zohoarc; b=EZgtU6W3soZqo5N7yhju9DfKqtulJHZk3Mk/Mv7n9T4e7Ky8s+hRaX+p1oNQjCJqG+0PqhfpQdNdPU2EbTy945uwUT70TCjpUPNg6dVUsQDQy9zhVJMeE2Djk0UwaDtk0POZ8cz8rc+nH9gwXxYrLpfw8QXs7wCokNHYB+7pivo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732819238; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=eFKiUc6Dqon9qjQmOVmuIQxOp19FJBFUFGirXOnfNrE=; b=BPqt8nMGeeUDp/GRAhbJKZNzlWxid9600zOhrI4mwr8a58ddyWrabrUvkYAC8BfGvwkwO+0LY4it5ClNxXxTBOWs9zcAFh2W+7eABWDgXBtOSYza9DNi+5wMYEsjNwDJW6pLpMrD3nljaoZjf8ngEdM7zpTD4r48IODtbS0r5po= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732819238102356.5641543750471; Thu, 28 Nov 2024 10:40:38 -0800 (PST) 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 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 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==; 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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" From: "Denis V. Lunev" via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1732819238684019100 Content-Type: text/plain; charset="utf-8" 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_f= lush(BlockDriverState *bs) static int64_t coroutine_fn GRAPH_RDLOCK preallocate_co_getlength(BlockDriverState *bs) { - int64_t ret; BDRVPreallocateState *s =3D bs->opaque; =20 if (s->data_end >=3D 0) { return s->data_end; } =20 - ret =3D bdrv_co_getlength(bs->file->bs); - - if (has_prealloc_perms(bs)) { - s->file_end =3D s->zero_start =3D s->data_end =3D ret; - } - - return ret; + return bdrv_co_getlength(bs->file->bs); } =20 static int GRAPH_RDLOCK --=20 2.45.2 From nobody Thu Dec 26 22:33:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1732819276; cv=none; d=zohomail.com; s=zohoarc; b=JtobndtKuNUOYhnr9f3zumV+GHI7/Yv9G0oNTgEu1PQS9vD7k7Ap4T5CcxQhSFSipiYovr60t8Yb/6F92NnF2zaClrVM/EZYxoqbAmvQbbVfpkwKj20uQtrU7QM/kg3tyzl79KcLdwPxr6Hom6XlQIruKmIotztB8rWQXbzf/aE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732819276; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=XJ42Z62QlzdbZHtaE5BzFMve5MgZ1kwBIfta+yFGPaM=; b=hT/oke6gJfBBy4i/YWYJWhC7tG9hy4HAW4COt+z4D1GPhPOHn7j1X7Qz8NsHZBVUNcP/xwbIgVgXNHjBTcAqZymZzquaADAn5rkyIthBzez5qJH9ee4uzVukWQB45QwRtU4S/e2ax+oGxyyWruNRHmL0vdJODDFDW0Jjha0Dqd8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732819276026988.4739891781326; Thu, 28 Nov 2024 10:41:16 -0800 (PST) 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 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 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==; 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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" From: "Denis V. Lunev" via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1732819276965019100 Content-Type: text/plain; charset="utf-8" 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 *b= s, Error **errp) BDRVPreallocateState *s =3D bs->opaque; int ret; =20 - if (s->file_end < 0) { - s->file_end =3D bdrv_getlength(bs->file->bs); - if (s->file_end < 0) { - error_setg_errno(errp, -s->file_end, "Failed to get file lengt= h"); - return s->file_end; - } + if (!(bs->open_flags & BDRV_O_RDWR)) { + return 0; + } + if (s->data_end < 0) { + return 0; } =20 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 =3D ret; - return ret; } - s->file_end =3D s->data_end; } + s->data_end =3D s->file_end =3D s->zero_start =3D -EINVAL; =20 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); =20 - if (s->data_end >=3D 0) { - preallocate_truncate_to_real_size(bs, NULL); - } + preallocate_truncate_to_real_size(bs, NULL); } =20 =20 @@ -528,8 +523,6 @@ preallocate_drop_resize(BlockDriverState *bs, Error **e= rrp) * change the child, so mark all states invalid. We'll regain control = if a * parent requests write access again. */ - s->data_end =3D s->file_end =3D s->zero_start =3D -EINVAL; - bdrv_child_refresh_perms(bs, bs->file, NULL); =20 return 0; --=20 2.45.2 From nobody Thu Dec 26 22:33:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1732819257; cv=none; d=zohomail.com; s=zohoarc; b=CW4KX0yeqjWbU9P38+z7YnnFzvQEr/j04ox0tcFf2x7VK6/65YBRHUtqw3dGlihQLnCCZB33kC0JulwpWTsv4eZDLnr9utSVhf3e74wAzNtMMD0hQZmi93ivVm/OnkCzHiEjetlcbwTaWIAhuZvAM3wjQWY3Lgd27f3cSFyinLc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732819257; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=xrg7ndqG9+Oki7uB+Q6dALsj7L6NNtOivee5Srln6YM=; b=eE4YwwloXyepFFc0YjlGOo5t/QaJmMXwGmJrA9f16uyOhzv5bGUof9XfppZZVVf2Oi4MVPlIek3UN0gkfbRCv6aWAXxOAEzGN5lUnrbzHWn+vn7XNUE/4M7kmlwgDHoujs+vU05kxcRBwQUXUIAsmTU0OjvzQWLOMzphEHXg9Ww= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173281925707563.98105761734939; Thu, 28 Nov 2024 10:40:57 -0800 (PST) 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 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 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==; 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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" From: "Denis V. Lunev" via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1732819258962019100 Content-Type: text/plain; charset="utf-8" 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; =20 static int preallocate_drop_resize(BlockDriverState *bs, Error **errp); -static void preallocate_drop_resize_bh(void *opaque); =20 #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 =3D s->zero_start =3D s->data_end =3D -EINVAL; - s->drop_resize_bh =3D qemu_bh_new(preallocate_drop_resize_bh, bs); =20 ret =3D 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) =20 static void preallocate_close(BlockDriverState *bs) { - BDRVPreallocateState *s =3D bs->opaque; - GLOBAL_STATE_CODE(); GRAPH_RDLOCK_GUARD_MAINLOOP(); =20 - qemu_bh_cancel(s->drop_resize_bh); - qemu_bh_delete(s->drop_resize_bh); - preallocate_truncate_to_real_size(bs, NULL); } =20 @@ -528,34 +518,6 @@ preallocate_drop_resize(BlockDriverState *bs, Error **= errp) return 0; } =20 -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 =3D bs->opaque; - - if (can_write_resize(perm)) { - qemu_bh_cancel(s->drop_resize_bh); - if (s->data_end < 0) { - s->data_end =3D s->file_end =3D s->zero_start =3D - 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 =3D { .bdrv_co_flush =3D preallocate_co_flush, .bdrv_co_truncate =3D preallocate_co_truncate, =20 - .bdrv_set_perm =3D preallocate_set_perm, .bdrv_child_perm =3D preallocate_child_perm, =20 .bdrv_inactivate =3D preallocate_inactivate, --=20 2.45.2 From nobody Thu Dec 26 22:33:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1732819228; cv=none; d=zohomail.com; s=zohoarc; b=aYt1a7tmHE4xjg7OiFLEG7enR2yJX+viR3kmHtlWNgcJAsXGmTOL9PwxA1DoNAIjNi65PbwSFsTS65AtqCUGweet1Te4dRDwEEBNsd76m+o2ZrcVj/Gjfjd63/9BRcnBQz5feeM17YWIe+2JXBwMKFRGIFVv367LGZ22p6RWp20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732819228; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=fk8PGJQHc/q4BIWFO0ftad01xvv3zgbb9jJTTEfmY/w=; b=cW9EtcA+T16uX0Mfm4pZzv2ujOETHv3i9TVjmkM8XKQC2wp4BKP686NyhnK194v1hk42ZcA2SlkhAQU5m+LgsCvEWnCTq4pPSjUIQhv7KtpTGEu943F6LznMNJPdqXbwip+tFwXBIWb2A4Mk3iZHamhthgWLy6xq3vUdSZG29Mc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173281922828746.1011623356211; Thu, 28 Nov 2024 10:40:28 -0800 (PST) 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 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 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==; 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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" From: "Denis V. Lunev" via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1732819228730019100 Content-Type: text/plain; charset="utf-8" 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; =20 -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 =3D { @@ -169,7 +167,7 @@ static int preallocate_open(BlockDriverState *bs, QDict= *options, int flags, } =20 static int GRAPH_RDLOCK -preallocate_truncate_to_real_size(BlockDriverState *bs, Error **errp) +preallocate_drop_resize(BlockDriverState *bs, Error **errp) { BDRVPreallocateState *s =3D bs->opaque; int ret; @@ -198,7 +196,7 @@ static void preallocate_close(BlockDriverState *bs) GLOBAL_STATE_CODE(); GRAPH_RDLOCK_GUARD_MAINLOOP(); =20 - preallocate_truncate_to_real_size(bs, NULL); + preallocate_drop_resize(bs, NULL); } =20 =20 @@ -488,36 +486,6 @@ preallocate_co_getlength(BlockDriverState *bs) return bdrv_co_getlength(bs->file->bs); } =20 -static int GRAPH_RDLOCK -preallocate_drop_resize(BlockDriverState *bs, Error **errp) -{ - BDRVPreallocateState *s =3D 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 =3D 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 abl= e 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) --=20 2.45.2 From nobody Thu Dec 26 22:33:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1732819239; cv=none; d=zohomail.com; s=zohoarc; b=nL7+cQctAzfTI+SgL7lQ3BIiXNYVTPcC3KgYF0SNNyp5BMFHx/9RqxaWlk7ZRRjH/36lziPADRxSjh7URYlB9V8T1cryKMOvyNbdt1Dbbfv3KC4eHWoAkEi+iiSfuv47z6ahKvCyMi5SIUplhFLnPht0nLU93Zc27oHMglxx0zQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732819239; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=UhBwOVLNTmzdrnNMePKQwoRxWaPb6x4aFbZNwX4XSQo=; b=G3fl6ilQF1x9yhSMjjW+2t0Hcl7R5USX4VRyQDM1EyhAnvjgtd4GeZ7yQBreQo8dOZNzMbxXFx5N1d8y+n82YPAz0BImXoaebrcWb3e7k/bjn2gFbzLtY4DLim+456NlDeJlAbhCWhQ9Y+V5O8NSkZ6G9r1OrTnmkHEXJrb0g9Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732819239234603.1692365798644; Thu, 28 Nov 2024 10:40:39 -0800 (PST) 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 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 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==; 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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" From: "Denis V. Lunev" via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1732819240836019100 Content-Type: text/plain; charset="utf-8" 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=3Dandrey.drobyshev@virtuozzo.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # 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=3D"1M" + local imgopts=3D"cluster_size=3D$size,extended_l2=3Don,lazy_refcounts= =3Don" + local image=3D"$TEST_IMG" + + if test -n "$1" ; then + image=3D"$1" + fi + + rm -f $image + TEST_IMG=3D$image _make_test_img -o "$imgopts" $size +} + +blkopts=3D"node-name=3Ddisk,driver=3Dqcow2,file.driver=3Dpreallocate," +blkopts+=3D"file.node-name=3Dprealloc,file.file.driver=3Dfile," +blkopts+=3D"file.file.filename=3D$TEST_IMG,file.file.node-name=3Dstorage" + +# +# 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 =3D=3D=3D 1. Migration to a local file =3D=3D=3D +echo + +echo "# Create image and start VM with preallocate filter:" +echo +_recreate_test_img +qemu_comm_method=3D"monitor" _launch_qemu -blockdev "$blkopts" +handle=3D$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=3Dyes _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 =3D=3D=3D 2. Migration to a local file after a write operation =3D=3D= =3D +echo + +echo "# Create image and start VM with preallocate filter:" +echo +_recreate_test_img +qemu_comm_method=3D"monitor" _launch_qemu -blockdev "$blkopts" +handle=3D$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=3Dyes _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 overl= ay +# image into an external snapshot of the disk. +# + +echo +echo =3D=3D=3D 3. Taking external snapshot after a write operation =3D=3D= =3D +echo + +snapblkopts=3D"node-name=3Dsnap,driver=3Dqcow2,file.driver=3Dpreallocate," +snapblkopts+=3D"file.node-name=3Dsnap-prealloc,file.file.driver=3Dfile," +snapblkopts+=3D"file.file.filename=3D$TEST_IMG.snap," +snapblkopts+=3D"file.file.node-name=3Dsnap-storage" + +echo "# Create disk and snapshot images and start VM with preallocate filt= er:" +echo +_recreate_test_img +_recreate_test_img $TEST_IMG.snap + +qemu_comm_method=3D"qmp" qmp_pretty=3D \ + _launch_qemu -blockdev "$snapblkopts" -blockdev "$blkopts" +handle=3D$QEMU_HANDLE +_send_qemu_cmd $handle "{ 'execute': 'qmp_capabilities' }" "return" + +silent=3Dyes + +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=3D +$QEMU_IO_PROG -f raw -c "write -P 0xff 0 1M" \ + "nbd+unix:///nbdexp?socket=3D$SOCK_DIR/nbd.sock" 2>&1 \ + | _filter_qemu_io | _filter_nbd + +echo +echo "# Delete nbd export:" +echo +silent=3Dyes +_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=3D +_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=3D +silent=3Dyes +_send_qemu_cmd $handle "{ 'execute': 'quit' }" "qmp-quit" +wait=3Dyes _cleanup_qemu + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/tests/prealloc-checks.out b/tests/qemu-iote= sts/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 + +=3D=3D=3D 1. Migration to a local file =3D=3D=3D + +# Create image and start VM with preallocate filter: + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +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 + +=3D=3D=3D 2. Migration to a local file after a write operation =3D=3D=3D + +# Create image and start VM with preallocate filter: + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +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 + +=3D=3D=3D 3. Taking external snapshot after a write operation =3D=3D=3D + +# Create disk and snapshot images and start VM with preallocate filter: + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +Formatting 'TEST_DIR/t.IMGFMT.snap', fmt=3DIMGFMT size=3D1048576 +{ '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", "consisten= t-read"], "perm": ["consistent-read"], "child": 5}, {"name": "file", "paren= t": 3, "shared-perm": ["write-unchanged", "consistent-read"], "perm": ["res= ize", "write", "consistent-read"], "child": 2}, {"name": "backing", "parent= ": 3, "shared-perm": ["resize", "write-unchanged", "write", "consistent-rea= d"], "perm": [], "child": 4}, {"name": "file", "parent": 2, "shared-perm": = ["write-unchanged", "consistent-read"], "perm": ["resize", "write", "consis= tent-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": "bl= ock-driver", "id": 3}, {"name": "snap-prealloc", "type": "block-driver", "i= d": 2}, {"name": "snap-storage", "type": "block-driver", "id": 1}]}} + +# Exit VM: + +{"return": {}} +*** done --=20 2.45.2