From nobody Tue Feb 10 01:59:06 2026 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770302971; cv=none; d=zohomail.com; s=zohoarc; b=g4aV7q0JK6xWiUG3V7Itc4ghC8OVmo6CMoZFTdlWz9OdGh35xTsgEHsc5WyJKV9yFGIiNoqL82xWKT46S/t5cqGMUaz0wcu2KnVJAoPK+JBIkQeXKCtleJtXjr5ogmAGRG2n99YynTy7o9bRnHY7krZg8krgbeY2gcoOJeYVNj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770302971; h=Content-Type: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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fEIrvKrLd0swLY9/WjimKLsX0Z/fiphyqnNgm5gCblc=; b=QG2DC7Tda0j5YaOpKzBoZWNn7CCkL7BgMG7DYSlOFWIqnLvDihrINX9sKHYalGRJ8s3B7t9CCK8TJ/CSorLcDQgxJiydIxtdPcQRkbjTmU5YuXKtwlblVbt7S1bX+GtU2TQUSALsx4jKF/cH7MVo2vIsrT++hru0zueE19/8bCw= 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 1770302971143786.17594616133; Thu, 5 Feb 2026 06:49:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo0eM-0007ko-Ap; Thu, 05 Feb 2026 09:48:06 -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 1vo0eI-0007jb-62 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 09:48:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vo0eG-0004Bv-Q4 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 09:48:01 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-281-31h1vaoFN_ullotA8CN4Jg-1; Thu, 05 Feb 2026 09:47:57 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-480686b3b4cso15419705e9.0 for ; Thu, 05 Feb 2026 06:47:57 -0800 (PST) Received: from localhost (p200300cfd737d06375fda007e5d3c5c8.dip0.t-ipconnect.de. [2003:cf:d737:d063:75fd:a007:e5d3:c5c8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43617cc9515sm13083854f8f.0.2026.02.05.06.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 06:47:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770302879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fEIrvKrLd0swLY9/WjimKLsX0Z/fiphyqnNgm5gCblc=; b=Vy1LUkP1X6ZEcrzoQklCOqYfzHCmZEBUvXyfXHDDGD8VNElQ1BIpsPLorecIwiiq776omH Xv8VQx/XTElmQrhsJmW+MrfNTcyDgY1SJV+CC876Ns869e4K2M0DNRg0ZkhD3DcYI15kMX O4qz8/88aLhBKRg/gFqvkGhmsUcQCg8= X-MC-Unique: 31h1vaoFN_ullotA8CN4Jg-1 X-Mimecast-MFC-AGG-ID: 31h1vaoFN_ullotA8CN4Jg_1770302876 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770302876; x=1770907676; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fEIrvKrLd0swLY9/WjimKLsX0Z/fiphyqnNgm5gCblc=; b=etZ50a1YP8tO2hZmbrvS6vnVVPbHWkIosIFcJcW0BUoVI3ZqNskSNDYq2/b31rgAkx p+WSN5UmJTjGMFuA1zT50PvolSLmOx3Nkwezcky4TE2QCBMfvyStUEma9lL9VAqL+V+P 6j8jdkIsllNJh2IJv1z5uFEwPeY3drcZ2k0Pt5uXfJAI8cJ3/U82Dq4RHIX8BfnCVvSe r8uq1FdzGwuyF9zl7QlA23iC6CIboKMW1bx68JIzijonTLoYAROrjGnDnYRMkSioLzZ+ 6JfyS9r7mS2uK2Z/AomgcTzuoZuL7U14rqkz2b0K3z1QGhHSZ7tcKEXsOFHxCGKyjQ7I apsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770302876; x=1770907676; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=fEIrvKrLd0swLY9/WjimKLsX0Z/fiphyqnNgm5gCblc=; b=IAWFGqYKkO7ipDrpbA00vlR/3QE/T3LgkigGDUJiuU3B7WsjBAwHeY7R22Lmam5dT7 vUXHmT9QJPXcaHj7XYGgIrSnK47FmBthQZTvLPVGap1rijCI4zSMiUxTUH0JbWDe3SZx F7GntTBZQqGcAdPKyefpUhDCY53eqi39zXLPeFm/0ZYeUo9ZFWavxOQ7QH+kdp8euXFV HAqfdI8MCiN0IaTwCdzRXQN4X1zkJzFxOebKEycaaFriWGuij1RXqrI1L8Sg0xk9satx vwBt0D+ttghKZ9UZRo9nwYAsQhINyPr74A148ZaAp8ru8svf8F39gywxtK6wWvGZ1bWe hTZw== X-Gm-Message-State: AOJu0YxityxkdKqF+kPp2C4p6o94YV9ESMaLJ1Z1C9M02Lfbhr3GBt1W ThPZtIcIsw/U6xXVCAWyPB3BL9Q3q6E/4CmlmyRYTna7Q3GLaColF9pYRMoDS1MLH3h1bjPoGZp vKcNCl80y4qE11e4uC0L96KO5LNF7N/IpgeaXFe9qtWIEsV8FEa8hxO/h X-Gm-Gg: AZuq6aJ8hhjoHWWk0oIz3HPkJMyZDacORXvqiTMjW+sU7XrnNnhpNwgsYr+rb1NODzb zVPY5dgakxOY/D29yPLXQz9PGRQJVeCQwHXieL6axNQJU3i8+W/L0a2uIdjxgPvpgwqokDPJhMt 8S+RUZgzUhWpd7U7BWBE5xiQXLgkxvE5gR8igsznP0FFtceLf294wgPHrYp5rr7Y4hWNzYVcw06 cLX2yCAqzzYj/i33IwGKZcydE23uxr/0Xoyhn4EhE5uDpHMySF76WCBLzhQJxmb6Ev9RzYBIgXi WkENHEbDDKLQswtGoW3O+jt3yVXo3A+3cM4O13V8TTBlso3NMyTK2EvK6/6PrpXYVJeLf95yRmo RQn1JZMAsp85JUGNNeJeOBEIm0o02zpka++OId2s0r/vFXLBYhy0OrvKQ5aTZJts1IgqB X-Received: by 2002:a05:600c:848a:b0:47d:403e:9cd5 with SMTP id 5b1f17b1804b1-4830e9303a6mr98427225e9.11.1770302876183; Thu, 05 Feb 2026 06:47:56 -0800 (PST) X-Received: by 2002:a05:600c:848a:b0:47d:403e:9cd5 with SMTP id 5b1f17b1804b1-4830e9303a6mr98426815e9.11.1770302875705; Thu, 05 Feb 2026 06:47:55 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf Subject: [PATCH 1/5] qcow2: Skip data-file resize if possible Date: Thu, 5 Feb 2026 15:47:31 +0100 Message-ID: <20260205144737.31131-2-hreitz@redhat.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260205144737.31131-1-hreitz@redhat.com> References: <20260205144737.31131-1-hreitz@redhat.com> 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1770302973726154100 Content-Type: text/plain; charset="utf-8" With PREALLOC_MODE_OFF, we currently always resize the data file to the right length. This is definitely not necessary if it already has the correct length, and if @exact is false, we also don't need to shrink it. This is what other preallocation modes already do: preallocate_co() only increases the data file size if it is too small, but never shrinks it. (And note that for raw data files, PREALLOC_MODE_OFF is silently turned into PREALLOC_MODE_METADATA, so this commit only changes behavior for non-raw external data files.) For the next commits, having all preallocation modes behave the same will make it easier to decide when we can skip taking the RESIZE permission on the data-file child. Signed-off-by: Hanna Czenczek --- block/qcow2.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index e29810d86a..69d621e9bf 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4515,15 +4515,22 @@ qcow2_co_truncate(BlockDriverState *bs, int64_t off= set, bool exact, switch (prealloc) { case PREALLOC_MODE_OFF: if (has_data_file(bs)) { + int64_t data_file_length =3D bdrv_co_getlength(s->data_file->b= s); + /* * If the caller wants an exact resize, the external data * file should be resized to the exact target size, too, * so we pass @exact here. + * Without @exact, we leave it as-is if it is already big enou= gh. + * Implicitly handle bdrv_co_getlength() errors by resizing. */ - ret =3D bdrv_co_truncate(s->data_file, offset, exact, prealloc= , 0, - errp); - if (ret < 0) { - goto fail; + if (data_file_length < offset || + (exact && data_file_length !=3D offset)) { + ret =3D bdrv_co_truncate(s->data_file, offset, exact, prea= lloc, 0, + errp); + if (ret < 0) { + goto fail; + } } } break; --=20 2.52.0