From nobody Fri Dec 27 13:32:00 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