From nobody Wed Nov 19 19:06:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1702292231; cv=none; d=zohomail.com; s=zohoarc; b=G1wL3thOOxcj6qEwi9FQl4LLetP7/O+tu346lbj3smfOykNd/RYyDtdbkt+CNLtbG32frl8snsJu2EQBTd7z+gkN9j/dUKJMWe8PIO4itukMAx8d/nqGqJVHZ385fRB02/RnvU7pFQrnRkL93Eajv1rGoURZi1As2jFbEz/SbAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702292231; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8tcRn2Jik/WAZu/NnQABjEZ/osafgiaB916KAVIfTxk=; b=VqS4wF/bcdL/pLW1Dhgj/TLDpAvucjSTAubHTbinRRjnon5BlKk/+wYPrPGwnCFykCYSMQAGQoq9RfAFSqFwurbZzMRdWJvu43Dw5GeiT8mOHb/E+ghfWVTUpDHGxEIASwpTX5oStrwLOyin4TFZkNqbCGYIteA6ChrbgDd6kyA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1702292231354778.9573137726293; Mon, 11 Dec 2023 02:57:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rCdxM-0000Ps-E7; Mon, 11 Dec 2023 05:56:12 -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 1rCdxK-0000Pc-HO; Mon, 11 Dec 2023 05:56:10 -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 1rCdxG-00069b-S2; Mon, 11 Dec 2023 05:56:10 -0500 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rCdvL-000MeT-3A; Mon, 11 Dec 2023 11:55:52 +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=8tcRn2Jik/WAZu/NnQABjEZ/osafgiaB916KAVIfTxk=; b=i7+1a0ZVpOiW rI5zDw1RBGtZg8rp9ZR91AT/DJvVOl7iqCw84IRAqvX8GuEemJw4tKrgqp4MOi7XoLhYuMqaYMB3K YU6mm7ze/+uLsJ2tehQt+uDmo/ZQ28vlnyI1Irvv01FHZMZj8aAmwzw9vMNbQeG5Ws0GnyHkkFilV sPkUM6PSqsFcwzl8sqOZ3pQehFYZCPmJLTaTYvgKtXy1GLvnpFrCjYfBMkk8ygHVaIxZKxaL+KWFm 3BXssR39NlPhseAFj+zE7jF9ma5HKYrwOG6G6ZviwsHUAMk4arEdWtHC0BdCw9BNb+GB2R7UpNaE6 5XmktvTREIQu7LiwC8jjiA==; From: Andrey Drobyshev To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH] block: allocate aligned write buffer for 'truncate -m full' Date: Mon, 11 Dec 2023 12:55:59 +0200 Message-Id: <20231211105559.316897-1-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 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=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1702292232999100003 Content-Type: text/plain; charset="utf-8" In case we're truncating an image opened with O_DIRECT, we might get -EINVAL on write with unaligned buffer. In particular, when running iotests/298 with '-nocache' we get: qemu-io: Failed to resize underlying file: Could not write zeros for preallocation: Invalid argument Let's just allocate the buffer using qemu_blockalign0() instead. Signed-off-by: Andrey Drobyshev Reviewed-by: Denis V. Lunev Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/file-posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index b862406c71..cee8de510b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2354,7 +2354,7 @@ static int handle_aiocb_truncate(void *opaque) goto out; } =20 - buf =3D g_malloc0(65536); + buf =3D qemu_blockalign0(aiocb->bs, 65536); =20 seek_result =3D lseek(fd, current_length, SEEK_SET); if (seek_result < 0) { @@ -2413,7 +2413,7 @@ out: } } =20 - g_free(buf); + qemu_vfree(buf); return result; } =20 --=20 2.39.3