From nobody Wed Apr 1 20:42:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1775050130; cv=none; d=zohomail.com; s=zohoarc; b=TSInH+MtlciB8T+J7/aZCMIW9FM3h0rWiUWtJs2/AgAGfPQlu/KinQsB6F2A+a0hVWKgyGVhis/BvrzgB8fLf4lGXQUNWedSTB2bqCl9eDsCm/IxI0t/5Qmcf4z0arWuDVRVXfbWtY+J2opCyDGBYOdLx76uohZ1sohUiYOGuJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775050130; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=CMDrFsWw0Upeubj98oDhSrcZizVAVvH1WLxb7VUoIGs=; b=BwCaZTF+VqpfLkBFo+IrkO3Ug1HsBWz7FHchXAJioWp8/u9h9hZt9t6E7ES5il3F6aDWta/vVf2q67MeC51x6fl3Srf+kxS+7wpJzspnGQCTUo6amV0KwGfOmikN3eKvAY6tHx1uhhUAvXxJFXLzWi20leB/m0+q49O07ejR4Hg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1775050130485847.5754618412021; Wed, 1 Apr 2026 06:28:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 6B15C3F35C; Wed, 1 Apr 2026 09:28:49 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 04DD641915; Wed, 1 Apr 2026 09:27:29 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 5F4403F310; Wed, 1 Apr 2026 09:27:24 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 7D5CC3F302 for ; Wed, 1 Apr 2026 09:27:23 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-242RchnCPdOheeCcngH12Q-1; Wed, 01 Apr 2026 09:27:21 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2AE051954B23 for ; Wed, 1 Apr 2026 13:27:21 +0000 (UTC) Received: from speedmetal.lan (unknown [10.44.22.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6DCAC1954102 for ; Wed, 1 Apr 2026 13:27:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: * X-Spam-Status: No, score=1.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_SBL_CSS,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775050043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CMDrFsWw0Upeubj98oDhSrcZizVAVvH1WLxb7VUoIGs=; b=BDlqN+sknc5+/wk/IVW4a4YQ2rPNXTWSvfo1ATA4sw8qakbB/uCG3Gicio2CQfgv3CzTzI az5ggEAbsEcQ9tyuN1qaBwG/51tVtPqMYc2MRv4AKi3Mot9jNVsSIf1Yfm2RxPwq3FEfn+ nKXJ+LKvlukOUebkK+Rf5hhh2tunE+k= X-MC-Unique: 242RchnCPdOheeCcngH12Q-1 X-Mimecast-MFC-AGG-ID: 242RchnCPdOheeCcngH12Q_1775050041 To: devel@lists.libvirt.org Subject: [PATCH 1/6] virDomainBlockResizeFlags: Convert to prefix-style docs Date: Wed, 1 Apr 2026 15:27:12 +0200 Message-ID: <1d16ee59a6dfd95ddcd1f91ba2a13660f30d5ceb.1775049824.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: FGEL_TfvkCr42P6_PDBOQFefpBWjfDvx8mY_DK25r6M_1775050041 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: AYNZUNLN42HLZX6W35PQT6CIXYGDWSJP X-Message-ID-Hash: AYNZUNLN42HLZX6W35PQT6CIXYGDWSJP X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775050131914158500 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Upcoming patches will want to add more extensive docs for one of the new flags so this format will make it more readable. Signed-off-by: Peter Krempa --- include/libvirt/libvirt-domain.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 09a797cab6..084debbf21 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2346,8 +2346,11 @@ int virDomainBlockPeek (virDomai= nPtr dom, * Since: 0.9.11 */ typedef enum { - VIR_DOMAIN_BLOCK_RESIZE_BYTES =3D 1 << 0, /* size in bytes instead of = KiB (Since: 0.9.11) */ - VIR_DOMAIN_BLOCK_RESIZE_CAPACITY =3D 1 << 1, /* resize to full the cap= acity of the source (Since: 10.0.0) */ + /* size in bytes instead of KiB (Since: 0.9.11) */ + VIR_DOMAIN_BLOCK_RESIZE_BYTES =3D 1 << 0, + + /* resize to full the capacity of the source (Since: 10.0.0) */ + VIR_DOMAIN_BLOCK_RESIZE_CAPACITY =3D 1 << 1, } virDomainBlockResizeFlags; int virDomainBlockResize (virDomainPtr dom, --=20 2.53.0 From nobody Wed Apr 1 20:42:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1775050180; cv=none; d=zohomail.com; s=zohoarc; b=UvTwJsOQ8KbrLx8i6zye8yx9pTl3B2ej2natqIr7xjUXH4irnAy1J2hVNLhWSw2nBoyG0bwLhM+G/dSPRjy+4D5F4+eO/41yiEoo/PZ1EP5KBiNNC49M+k3lB+2Mr7yUVJu3+Y5piFVEpvwxy1kU52V33Sq1jieiWj/FGOcfYQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775050180; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=MNmETgk/gJRppxxkdcBE7FVP1lJbgpySX3sF46Eivt4=; b=h9YRhPLsOjuGdf2HgY/xivwdzXDbhlUw2Q+r7+xHuwX05BVVshGhCFlZ0sy9AQOPuAkanb1ATkLdhiMbXDmRl9hpyjoTouzfrRS4sd5/B7ZCFAxKahMdBk5Xmfz3IK9BPxC89rJQxd0+5Qpufy+U90/Lpf2WlnOfrVzbZtnULMY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1775050180692953.8684424696448; Wed, 1 Apr 2026 06:29:40 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id ABA033F844; Wed, 1 Apr 2026 09:29:39 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 4C50C41976; Wed, 1 Apr 2026 09:27:31 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 34F0B3F896; Wed, 1 Apr 2026 09:27:26 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A10473F302 for ; Wed, 1 Apr 2026 09:27:25 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-CTBOZmATPcCOKbVXzR0DLQ-1; Wed, 01 Apr 2026 09:27:23 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 517E31800614 for ; Wed, 1 Apr 2026 13:27:22 +0000 (UTC) Received: from speedmetal.lan (unknown [10.44.22.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9EC8B1954102 for ; Wed, 1 Apr 2026 13:27:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775050045; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MNmETgk/gJRppxxkdcBE7FVP1lJbgpySX3sF46Eivt4=; b=G2xhqYXFYilc0xyyhHttBWjAEtChM3thjTv8V+eAygji/qhDGie7oImj+N7o0FDzF0cqzT aPOlt11Mq+Fqfy20SjN9B1QGpmuDtbFOn+b83YdF8AUVEhl1D0brywq0DL0jcg6/3f1Wmb KKNx7SV1wpyhz8y3eIXmNjkbwS5qyhg= X-MC-Unique: CTBOZmATPcCOKbVXzR0DLQ-1 X-Mimecast-MFC-AGG-ID: CTBOZmATPcCOKbVXzR0DLQ_1775050042 To: devel@lists.libvirt.org Subject: [PATCH 2/6] API/qemu: Introduce 'VIR_DOMAIN_BLOCK_RESIZE_EXTEND' for 'virDomainBlockResize' Date: Wed, 1 Apr 2026 15:27:13 +0200 Message-ID: <83b57596b29dbf39f29173ed7f7e31d579582ef2.1775049824.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: cLXnuhgTeK_vC0ePQPIcSchhGkSAmPqzhpQAv_uEJrc_1775050042 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 6HURNW7U3MXMD3HZ4UW6NOMR3FL34OY2 X-Message-ID-Hash: 6HURNW7U3MXMD3HZ4UW6NOMR3FL34OY2 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775050181768158500 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Introduce a new flag VIR_DOMAIN_BLOCK_RESIZE_EXTEND which will prevent accidental shrinking of the block device. Warn callers that they ought to use it. While this won't prevent any old uses without the flag (which we couldn't change due to our API guarantees) it will give the users tools to handle the resizing of devices more safely. Implement it in the qemu driver. Signed-off-by: Peter Krempa --- include/libvirt/libvirt-domain.h | 3 +++ src/libvirt-domain.c | 5 +++++ src/qemu/qemu_driver.c | 32 +++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 084debbf21..4a8e3114b3 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2351,6 +2351,9 @@ typedef enum { /* resize to full the capacity of the source (Since: 10.0.0) */ VIR_DOMAIN_BLOCK_RESIZE_CAPACITY =3D 1 << 1, + + /* Disallow shrinking (Since: 12.3.0) */ + VIR_DOMAIN_BLOCK_RESIZE_EXTEND =3D 1 << 2, } virDomainBlockResizeFlags; int virDomainBlockResize (virDomainPtr dom, diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index ed51180c91..db9eea5774 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -6451,6 +6451,11 @@ virDomainBlockPeek(virDomainPtr dom, * size. Depending on the file format, the hypervisor may round up * to the next alignment boundary. * + * *BEWARE*: The block device may be shrunk if @size is less than the curr= ent + * guest visible size. Callers who wish to only extend @disk should always= pass + * VIR_DOMAIN_BLOCK_RESIZE_EXTEND (since 12.3.0) in @flags which instructs= the + * hypervisor to deny an attempt to shrink the device. + * * If @flag contains VIR_DOMAIN_BLOCK_RESIZE_CAPACITY (since 10.0.0) the * hypervisor will resize the guest block device to fully fill the source. * @size must be either set to zero, or to the exact size of the block diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 861795724a..551553df14 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9448,7 +9448,8 @@ qemuDomainBlockResize(virDomainPtr dom, virDomainDiskDef *persistDisk =3D NULL; virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES | - VIR_DOMAIN_BLOCK_RESIZE_CAPACITY, -1); + VIR_DOMAIN_BLOCK_RESIZE_CAPACITY | + VIR_DOMAIN_BLOCK_RESIZE_EXTEND, -1); /* We prefer operating on bytes. */ if ((flags & VIR_DOMAIN_BLOCK_RESIZE_BYTES) =3D=3D 0) { @@ -9587,11 +9588,40 @@ qemuDomainBlockResize(virDomainPtr dom, if (!qemuDiskBusIsSD(disk->bus)) { nodename =3D qemuBlockStorageSourceGetEffectiveNodename(disk->src); } else { + if (flags & VIR_DOMAIN_BLOCK_RESIZE_EXTEND) { + /* technically possible, just not implemented */ + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("cannot prevent shrink on SD devices")); + goto endjob; + } + if (!(device =3D qemuAliasDiskDriveFromDisk(disk))) goto endjob; } qemuDomainObjEnterMonitor(vm); + + if (flags & VIR_DOMAIN_BLOCK_RESIZE_EXTEND) { + g_autoptr(GHashTable) blockNamedNodeData =3D qemuMonitorBlockGetNa= medNodeData(priv->mon); + qemuBlockNamedNodeData *entry; + + if (!(entry =3D virHashLookup(blockNamedNodeData, nodename))) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("failed to determine current size of '%1$s'"), + path); + qemuDomainObjExitMonitor(vm); + goto endjob; + } + + if (entry->capacity > size) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("resize of '%1$s' would shrink it from '%2$ll= u' to '%3$llu' bytes"), + path, entry->capacity, size); + qemuDomainObjExitMonitor(vm); + goto endjob; + } + } + if (qemuMonitorBlockResize(priv->mon, device, nodename, size) < 0) { qemuDomainObjExitMonitor(vm); goto endjob; --=20 2.53.0 From nobody Wed Apr 1 20:42:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1775050216; cv=none; d=zohomail.com; s=zohoarc; b=J4OJnW4+mOGP/oL3+zXs5n05EEd3iI8hgPqrCE8saWVLPu8c0kNNdBPau/R0v2Q3+aZi6WAUnio/Rk+qmYaa3vXJHYITP7xP5L9YmFydM11zpim5KpvYIdbJcG+/w+02ICi4LFMBJ3SzlOPjGn5WxTKnjJGgbms2Go8gTGRztxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775050216; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=84iJsuxDydMRoDKUGxrTftwc1vqmeyURqyJvejUFyxI=; b=S5pnZlGQ1wHXcCNsqcNhlag4B14wqJ9IF8O7HjoT4lk2I9HBWi49dn9167I1u+ohTvxY+IYQzwMmhSqsodBoEBsO+jmfkXVxKigSDv6eFBjkClJlC0yn3k2QxCXOL/vRLPVQ6HDsRRc7+tdOUrJtRjwTo6h1dV0Ok+nFhsRfJbA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1775050216435923.8723370840152; Wed, 1 Apr 2026 06:30:16 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 822033F890; Wed, 1 Apr 2026 09:30:15 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 0419741A04; Wed, 1 Apr 2026 09:27:33 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 562523F8A7; Wed, 1 Apr 2026 09:27:26 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id CFE4D3F840 for ; Wed, 1 Apr 2026 09:27:25 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-316-tb-4R5cOM3e_sILZVJr4Aw-1; Wed, 01 Apr 2026 09:27:24 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 752CF1954B1E for ; Wed, 1 Apr 2026 13:27:23 +0000 (UTC) Received: from speedmetal.lan (unknown [10.44.22.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BC24E1954102 for ; Wed, 1 Apr 2026 13:27:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: * X-Spam-Status: No, score=1.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_SBL_CSS,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775050045; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=84iJsuxDydMRoDKUGxrTftwc1vqmeyURqyJvejUFyxI=; b=iT2nt+5AvncaFL+W0y2WCa7C/6YZR0088S8Ql3WzUZo1+7WfaDwpWxlPR1N1HMpwr4vmPi 6YbLW6WZC4eY7OX/FRbrRVyE55AkEJ8LZMgpMntZZlJ6+kadY3+2s7Cm6aeOpt3hMLnzbq ruj9F/ZxEEVRzl0laqlKwZvwc3Bm7D0= X-MC-Unique: tb-4R5cOM3e_sILZVJr4Aw-1 X-Mimecast-MFC-AGG-ID: tb-4R5cOM3e_sILZVJr4Aw_1775050043 To: devel@lists.libvirt.org Subject: [PATCH 3/6] virsh: blockresize: Introduce '--extend' flag Date: Wed, 1 Apr 2026 15:27:14 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 2MZnMSsmupHwg6lyDAtfD00MsbYBQqcDjRQxOnr44uU_1775050043 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: IUW6BHALFGQBZO27BMH7DW5WTR5774FV X-Message-ID-Hash: IUW6BHALFGQBZO27BMH7DW5WTR5774FV X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775050218054158500 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Use the new VIR_DOMAIN_BLOCK_RESIZE_EXTEND to prevent accidentally shrinking a disk and thus destroying data. Signed-off-by: Peter Krempa --- docs/manpages/virsh.rst | 7 ++++++- tools/virsh-domain.c | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 4b8bbec7d6..80b0ea14a8 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1642,7 +1642,7 @@ blockresize :: - blockresize domain path ([size] | [--capacity]) + blockresize domain path ([size] | [--capacity]) [--extend] Resize a block device of domain while the domain is running, *path* specifies the absolute path of the block device; it corresponds @@ -1650,6 +1650,11 @@ to a unique target name () or = source file () for one of the disk devices attached to *domain* (see also ``domblklist`` for listing these names). +The *--extend* flag instructs the hypervisor to ensure that the new size i= sn't +smaller than the old size, thus prevents (accidental) shrinking of the blo= ck +device which may lead to data loss. Users are encouraged to always use this +flag unless communicating with an older hypervisor. + For image formats without metadata (raw) stored inside fixed-size storage = (e.g. block devices) the --capacity flag can be used to resize the device to the full size of the backing device. diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index a17c8b42e2..08a1ce3953 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3339,6 +3339,10 @@ static const vshCmdOptDef opts_blockresize[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("resize to capacity of source (block device)") }, + {.name =3D "extend", + .type =3D VSH_OT_BOOL, + .help =3D N_("ensure that the new size is larger than actual capacity= (prevent shrink)") + }, {.name =3D NULL} }; @@ -3352,6 +3356,9 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd) VSH_ALTERNATIVE_OPTIONS("size", "capacity"); + if (vshCommandOptBool(cmd, "extend")) + flags |=3D VIR_DOMAIN_BLOCK_RESIZE_EXTEND; + if (vshCommandOptString(ctl, cmd, "path", (const char **) &path) < 0) return false; --=20 2.53.0 From nobody Wed Apr 1 20:42:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1775050261; cv=none; d=zohomail.com; s=zohoarc; b=b5Ucadkge2Z++x8qbGSayWvo5H7cTl3Ovjlx0lUaBNx39DBgemsIwFVHxlEcu9qWer+/JgM8l7UX0sPPbJNXGLveILjjzTcIWJizCPzj9FEAvbe+Z+fL9ArVi5BeO4MiKk0m8FV/M70Zf/4G4f/ZKpPlSzEv2X6wPoM1Af/Pmig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775050261; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=K0NmjR07FF0oTWfOduteo7CqOzQEF/BJgBToCZRMg6M=; b=MmzfFRA17ewLWv6WYq3kCpGn8/rHuS6zQD05sRUiBlaLfIBxlN48/fvw6u9bekaKxZyRy/y/TgykHxFh63KASGuSw0oSpHZe8vHEMUtw+q95ktdPbd2kqszUx0G94UL/UZCI+nIUpw+gddrLdX1xYDqNsj49KGrUbiV2DE0Ya5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1775050261870833.9540669854662; Wed, 1 Apr 2026 06:31:01 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 1AD353FD29; Wed, 1 Apr 2026 09:31:01 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 3FD4D41AC0; Wed, 1 Apr 2026 09:27:47 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 93E5641A80; Wed, 1 Apr 2026 09:27:41 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 9DD1F3F977 for ; Wed, 1 Apr 2026 09:27:27 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-oChn4dQRNtGXS6EslvKsfQ-1; Wed, 01 Apr 2026 09:27:25 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 901D51800344 for ; Wed, 1 Apr 2026 13:27:24 +0000 (UTC) Received: from speedmetal.lan (unknown [10.44.22.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DBB641954102 for ; Wed, 1 Apr 2026 13:27:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775050047; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K0NmjR07FF0oTWfOduteo7CqOzQEF/BJgBToCZRMg6M=; b=WVY4WZFeFZgFsikOWLiw6fRnect2w+0WrCNrQ/jPJhvjox94veUSlQUsL6R3EmOlzGhtQ6 KaFI+2UU9lks8UvrXq1w3+ze2xK1FmcsJ/wHcQBNFfiXfF9brtNyoIykfmc5ND3I/pu/xY FSPAFOHgd2m5Y89uUIgiUAqAAH2sLMk= X-MC-Unique: oChn4dQRNtGXS6EslvKsfQ-1 X-Mimecast-MFC-AGG-ID: oChn4dQRNtGXS6EslvKsfQ_1775050044 To: devel@lists.libvirt.org Subject: [PATCH 4/6] API: Introduce 'VIR_DOMAIN_BLOCK_RESIZE_PROBE_FLAGS' for 'virDomainBlockResize' Date: Wed, 1 Apr 2026 15:27:15 +0200 Message-ID: <4362e8bf525dfa8dffda8700c740df9e06f28b07.1775049824.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 726z4jAylWmhnH6AtaqSNvEfH208-UZx8fP_FzXJUzM_1775050044 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3GI65DXW2APFY2HXKLA7GMNKQEDAH4WG X-Message-ID-Hash: 3GI65DXW2APFY2HXKLA7GMNKQEDAH4WG X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775050262455158500 Content-Type: text/plain; charset="utf-8" From: Peter Krempa In certain cases it's useful for the caller to be able to determine if given API supports some flags. To do this with 'virDomainBlockResize', if 'VIR_DOMAIN_BLOCK_RESIZE_PROBE_FLAGS' is specified, the API will return success right after flag verification, regardless of other input arguments and without modifying anything. Signed-off-by: Peter Krempa --- include/libvirt/libvirt-domain.h | 9 +++++++++ src/libvirt-domain.c | 12 ++++++++++++ src/qemu/qemu_driver.c | 7 ++++++- src/vz/vz_driver.c | 7 ++++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 4a8e3114b3..113c7eefe6 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2354,6 +2354,15 @@ typedef enum { /* Disallow shrinking (Since: 12.3.0) */ VIR_DOMAIN_BLOCK_RESIZE_EXTEND =3D 1 << 2, + + /* Ensures that the 'virDomainBlockResize' API returns success after + * checking support of 'flags' regardless of other arguments without + * actually modifying any aspect of the domain. + * + * Use of the flag thus allows probing for support of other flags of t= his + * API. (Since: 12.3.0) */ + VIR_DOMAIN_BLOCK_RESIZE_PROBE_FLAGS =3D 1 << 3, + } virDomainBlockResizeFlags; int virDomainBlockResize (virDomainPtr dom, diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index db9eea5774..1b49d2f7e5 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -6469,6 +6469,18 @@ virDomainBlockPeek(virDomainPtr dom, * can be found by calling virDomainGetXMLDesc() and inspecting * elements within //domain/devices/disk. * + * If @flags contains VIR_DOMAIN_BLOCK_RESIZE_PROBE_FLAGS (since 12.3.0) t= he + * API will return success right after checking flags for support without + * modifying the disk in any way, thus allowing probing of flags with the + * following algorithm + * + * supp =3D virDomainBlockResize(dom, "", 0, VIR_DOMAIN_BLOCK_RESIZE_PRO= BE_FLAGS | VIR_DOMAIN_BLOCK_RESIZE_EXTEND); + * + * if (supp =3D=3D 0) + * //flag supported + * else + * virResetLastError(); + * * Note that this call may fail if the underlying virtualization hypervisor * does not support it; this call requires privileged access to the * hypervisor. diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 551553df14..aa064ca7a9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9449,7 +9449,12 @@ qemuDomainBlockResize(virDomainPtr dom, virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES | VIR_DOMAIN_BLOCK_RESIZE_CAPACITY | - VIR_DOMAIN_BLOCK_RESIZE_EXTEND, -1); + VIR_DOMAIN_BLOCK_RESIZE_EXTEND | + VIR_DOMAIN_BLOCK_RESIZE_PROBE_FLAGS, -1); + + /* Assume success if flag probing is requested */ + if (flags & VIR_DOMAIN_BLOCK_RESIZE_PROBE_FLAGS) + return 0; /* We prefer operating on bytes. */ if ((flags & VIR_DOMAIN_BLOCK_RESIZE_BYTES) =3D=3D 0) { diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 2d8878fe7f..efb0144093 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -3901,7 +3901,12 @@ vzDomainBlockResize(virDomainPtr domain, int ret =3D -1; bool job =3D false; - virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1); + virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES | + VIR_DOMAIN_BLOCK_RESIZE_PROBE_FLAGS, -1); + + /* Assume success if flag probing is requested */ + if (flags & VIR_DOMAIN_BLOCK_RESIZE_PROBE_FLAGS) + return 0; if (!(dom =3D vzDomObjFromDomain(domain))) goto cleanup; --=20 2.53.0 From nobody Wed Apr 1 20:42:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1775050305; cv=none; d=zohomail.com; s=zohoarc; b=EAD66i8R2+2/KSgUaDaue5fjMvUGujl0DJWKdN088NoE2dJ/ykoo+MRK5ANvso2Eoq+Cw5o9yFSswthhOOY5a0ngV6E0AjL36zGvUi5YvJChD9c4Yct+ddkUMzYa1RH9PtEkJNv/49AD7n9GPuGvmW7IIJrhIY8ullfXyufkb0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775050305; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=gou4NibwVgf3uDbltfZL8e6VgVR8KHH/oU2UOx/UpTo=; b=YMesGOl4NHvgAvKZYppZ2MLzQsnM2iKUBuotdJctscHqj58HTcMpnriLa1NsTjGDJQpe8dxDAdFszFoTam3Aj074UKjlFk50U5ByVZ+Ser5n8ghb3EUEcTkS2WFQi64q+tMTcGO7Qi5uuPt8ACXyL+E1t8I6Hie0NYFk9ZTrHdU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1775050305487393.29130922410775; Wed, 1 Apr 2026 06:31:45 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 955493F861; Wed, 1 Apr 2026 09:31:44 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 874B841AC9; Wed, 1 Apr 2026 09:28:15 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 19CBB41843; Wed, 1 Apr 2026 09:28:11 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 6B9114187A for ; Wed, 1 Apr 2026 09:27:28 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-569-5SpbD_LUMF-Mr0nln-G7bw-1; Wed, 01 Apr 2026 09:27:26 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ACBD618005B4 for ; Wed, 1 Apr 2026 13:27:25 +0000 (UTC) Received: from speedmetal.lan (unknown [10.44.22.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 064531954102 for ; Wed, 1 Apr 2026 13:27:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775050048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gou4NibwVgf3uDbltfZL8e6VgVR8KHH/oU2UOx/UpTo=; b=igAMGb/bz+9iYU0DVHYm2AHDIuy+QWX4Gs7+SpCfCsEbeySZnvxzaqSCmHg5y/Gqx2EUcs 1MCf/hN+4XlI2912E3WmC9T/7qjJlx/Dg8LsqTbTJ9Mo+P46WJz1vcUuaXcl42bK48pErK wHHcJ+ESnILZZMwtFPkgjfIH5yIwiKw= X-MC-Unique: 5SpbD_LUMF-Mr0nln-G7bw-1 X-Mimecast-MFC-AGG-ID: 5SpbD_LUMF-Mr0nln-G7bw_1775050045 To: devel@lists.libvirt.org Subject: [PATCH 5/6] virsh/virt-admin: Add possibility to probe for new arguments Date: Wed, 1 Apr 2026 15:27:16 +0200 Message-ID: <6dfdb6653dc7d6b9f1ac19ed0e1252e0c5a75d1d.1775049824.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: r_0gL_Yl5mnPYbNE4WhHodOSr8qPpsN4hrY2rmc0_OQ_1775050045 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LMDKP3UBTAZD3RCFEEHXUSM5JR67PAKO X-Message-ID-Hash: LMDKP3UBTAZD3RCFEEHXUSM5JR67PAKO X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775050306803158500 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Add users possibility to discover presence of arguments safely. The new global argument '--probe-arguments' which runs the argument parser but doesn't run the actual function and returning success if it gets to the point of actually trying to runt he parser. This will allow users to probe for new arguments (which were added after this patch: - virsh prior to this patch: $ virsh --probe-arguments blockresize cd vda 1 --extend ; echo $? error: unsupported option '--probe-arguments'. See --help. 1 - virsh with this patch but checking for something that doesn't yet exist: $ virsh --probe-arguments blockresize cd vda 1 --allow-shrink ; echo $? error: command 'blockresize' doesn't support option --allow-shrink 1 - virsh with this patch with the argument present: $ virsh --probe-arguments blockresize cd vda 1 --allow-shrink ; echo $? 0 Signed-off-by: Peter Krempa --- docs/manpages/virsh.rst | 17 ++++++++++++++++- tools/virsh.c | 4 ++++ tools/virt-admin.c | 9 +++++++++ tools/vsh.c | 3 +++ tools/vsh.h | 1 + 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 80b0ea14a8..9ede859aaf 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -161,7 +161,22 @@ Ignore all other arguments, and prints the version of = the libvirt library virsh is coming from and which options and driver are compiled in. - +- ``--probe-arguments`` + +Parse all incomming commands and their arguments. Return without actually +executing the command. This gives the caller the possibility to probe if g= iven +command or argument exists in this version of virsh without executing the +command. Mandatory arguments need to be provided albeit with dummy values = if +checking existence of optional features. +(Introduced in libvirt-12.3.0) + +Example:: + + if virsh --probe-arguments blockresize --domain dummy --path dummy --size= 1 --allow-shrink 2>/dev/null; then + echo "supported" + else + echo "unsupported" + fi NOTES =3D=3D=3D=3D=3D diff --git a/tools/virsh.c b/tools/virsh.c index fdce3220b3..57e2b9c1a9 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -646,6 +646,7 @@ virshParseArgv(vshControl *ctl, int argc, char **argv) { "timing", no_argument, NULL, 't' }, { "no-pkttyagent", no_argument, NULL, 0 }, { "version", optional_argument, NULL, 'v' }, + { "probe-arguments", no_argument, NULL, 0 }, { NULL, 0, NULL, 0 }, }; @@ -746,6 +747,9 @@ virshParseArgv(vshControl *ctl, int argc, char **argv) if (STREQ(opt[longindex].name, "no-pkttyagent")) { ctl->no_pkttyagent =3D true; break; + } else if (STREQ(opt[longindex].name, "probe-arguments")) { + ctl->probe_arguments =3D true; + break; } else { vshError(ctl, "%s", _("unknown option")); exit(EXIT_FAILURE); diff --git a/tools/virt-admin.c b/tools/virt-admin.c index ac8f3202b6..ff6f3856aa 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1292,6 +1292,7 @@ vshAdmParseArgv(vshControl *ctl, int argc, char **arg= v) { "log", required_argument, NULL, 'l' }, { "quiet", no_argument, NULL, 'q' }, { "version", optional_argument, NULL, 'v' }, + { "probe-arguments", no_argument, NULL, 0 }, { NULL, 0, NULL, 0 }, }; @@ -1337,6 +1338,14 @@ vshAdmParseArgv(vshControl *ctl, int argc, char **ar= gv) case 'V': vshAdmShowVersion(ctl); exit(EXIT_SUCCESS); + case 0: + if (STREQ(opt[longindex].name, "probe-arguments")) { + ctl->probe_arguments =3D true; + break; + } else { + vshError(ctl, "%s", _("unknown option")); + exit(EXIT_FAILURE); + } case ':': for (i =3D 0; opt[i].name !=3D NULL; i++) { if (opt[i].val =3D=3D optopt) diff --git a/tools/vsh.c b/tools/vsh.c index 74016c0043..e85d8b5001 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1366,6 +1366,9 @@ vshCommandRun(vshControl *ctl, const vshClientHooks *hooks =3D ctl->hooks; int ret =3D EXIT_SUCCESS; + if (ctl->probe_arguments) + return EXIT_SUCCESS; + while (cmd) { gint64 before, after; bool enable_timing =3D ctl->timing; diff --git a/tools/vsh.h b/tools/vsh.h index bd2494e899..18fa7ad594 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -203,6 +203,7 @@ struct _vshControl { bool timing; /* print timing info? */ bool no_pkttyagent; /* suppress registration of pkttyagent? */ int debug; /* print debug messages? */ + bool probe_arguments; /* process arguments but don't run command= */ char *logfile; /* log file name */ int log_fd; /* log file descriptor */ char *historydir; /* readline history directory name */ --=20 2.53.0 From nobody Wed Apr 1 20:42:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1775050346; cv=none; d=zohomail.com; s=zohoarc; b=g4kJ30UDdDCTruOEJS/ejW0N2yNyL1EnRtxatGqaDYEF3JbUapk6G5tttaJsr9kc6zW6u90ZCw5KNl4wbTDUjJYxkk4W7Ytgysmx6imIcdtBFwUkp46iLakDYItGkWKtAoAT8TDkO+E38lxDN+qQvhLU1ZqS1kB3ZTSd3obMPV4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775050346; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=UhV50d7PVAwUYr6RwTrxnEQvqsR9/1uqYaEGKkcaLGE=; b=IniIY18wjew0Bt0CjYdtfiHwvEhciHsrI2vttiCCY0vcCB995oXw/9BQYRW0qRuiIlm+9kJkNFyIZUXgeETWJt3mSxIV+Xsn4BZO2oEvQaRpTW2U/s1ZHUVkfqOJgjAWKAPV+MYXGSYpPV9sM/HrIVwBP+BRyLgnbl/XLM0a8NY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1775050346056566.4609697630715; Wed, 1 Apr 2026 06:32:26 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 390D63F280; Wed, 1 Apr 2026 09:32:25 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 6F98B41ADB; Wed, 1 Apr 2026 09:28:54 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id F218B3F861; Wed, 1 Apr 2026 09:28:48 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id F14C341913 for ; Wed, 1 Apr 2026 09:27:29 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-464-5AxZhlAjOu68Yn5u-nrivA-1; Wed, 01 Apr 2026 09:27:27 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CBC9D18002D1 for ; Wed, 1 Apr 2026 13:27:26 +0000 (UTC) Received: from speedmetal.lan (unknown [10.44.22.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 233FD1954102 for ; Wed, 1 Apr 2026 13:27:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775050049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UhV50d7PVAwUYr6RwTrxnEQvqsR9/1uqYaEGKkcaLGE=; b=bNcrlqJlMlcgZ1js2+SIAwKJEtvG0Z7flELVyrSX2rOVhg1o5RsUD6ZxuPiJbfAIcEGcgA 91sxT6N/y1LZrFXrXGOYbJOQQlyoY+AUp4sysrtromS4K0ekyHOrv3k2elPGfPLjTJBZDx qP3JQYAtX4TtCa6u+4Tj0Tfhe+B/EBo= X-MC-Unique: 5AxZhlAjOu68Yn5u-nrivA-1 X-Mimecast-MFC-AGG-ID: 5AxZhlAjOu68Yn5u-nrivA_1775050046 To: devel@lists.libvirt.org Subject: [PATCH 6/6] virsh: blockresize: Use VIR_DOMAIN_BLOCK_RESIZE_EXTEND when available and introduce --allow-shrink Date: Wed, 1 Apr 2026 15:27:17 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: XomrhUc_uH_iO2QO-I-y3kY1Auxo1k8b6LIbGmFddpE_1775050046 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: FX2H322IOOBFQOB47YNGAKDWLNGUGBK3 X-Message-ID-Hash: FX2H322IOOBFQOB47YNGAKDWLNGUGBK3 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775050347123158500 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Use the new VIR_DOMAIN_BLOCK_RESIZE_PROBE_FLAGS flag to probe for VIR_DOMAIN_BLOCK_RESIZE_EXTEND and use it if available. This will give users the same protection as with --extend in the default case. IMPORTANT: This patch changes behaviour for users who want to shrink their VM's block device knowingly. Such users, when using a newer daemon will be required to pass --allow-shrink now. I've contemplated either renaming the whole command to preserve functionality for the existing one and deprecating 'virsh blockresize' or adding just the '--extend', but unfortunately neither of those in the end looked appealing to me. As shrinking filesystems is much more invloved and much less common the benefit of preventing accidental data loss should outweigh the breakage from the change. To aleviate issues with scripts virsh now also provides the '--probe-arguments' option to allow safe probe if virsh supports this new argument. Closes: https://gitlab.com/libvirt/libvirt/-/work_items/789 Signed-off-by: Peter Krempa --- docs/manpages/virsh.rst | 11 ++++++++++- tools/virsh-domain.c | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 9ede859aaf..5138591595 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1657,7 +1657,7 @@ blockresize :: - blockresize domain path ([size] | [--capacity]) [--extend] + blockresize domain path ([size] | [--capacity]) [--extend] [--allow-shr= ink] Resize a block device of domain while the domain is running, *path* specifies the absolute path of the block device; it corresponds @@ -1670,6 +1670,15 @@ smaller than the old size, thus prevents (accidental= ) shrinking of the block device which may lead to data loss. Users are encouraged to always use this flag unless communicating with an older hypervisor. +As of libvirt 12.3.0 the 'virsh blockresize' command now probes whether the +hypervisor supports enforcing that the device is not shrunk accidentally a= nd +if it is supported this feature will be used as a precaution from accident= al +data loss even at the cost of change of behaviour. With older hypervisors +which do not support the feature the protection will not be avaliable. +Users wanting to shrink the block device must use the *--allow-shrink* +flag. In scripts it's possible to use the *--probe-arguments* flag to dete= rmine +if the flag is supported. + For image formats without metadata (raw) stored inside fixed-size storage = (e.g. block devices) the --capacity flag can be used to resize the device to the full size of the backing device. diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 08a1ce3953..95ce4dc845 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3343,6 +3343,10 @@ static const vshCmdOptDef opts_blockresize[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("ensure that the new size is larger than actual capacity= (prevent shrink)") }, + {.name =3D "allow-shrink", + .type =3D VSH_OT_BOOL, + .help =3D N_("disable size checks so that device can be shrunk") + }, {.name =3D NULL} }; @@ -3378,6 +3382,18 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd) if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; + /* probe for support of VIR_DOMAIN_BLOCK_RESIZE_EXTEND and use it if i= t's + * supported to prevent mishaps even at the cost of usability change */ + if (!vshCommandOptBool(cmd, "allow-shrink")) { + if (virDomainBlockResize(dom, "", 0, + VIR_DOMAIN_BLOCK_RESIZE_EXTEND | + VIR_DOMAIN_BLOCK_RESIZE_PROBE_FLAGS) =3D= =3D 0) { + flags |=3D VIR_DOMAIN_BLOCK_RESIZE_EXTEND; + } else { + vshResetLibvirtError(); + } + } + if (virDomainBlockResize(dom, path, size, flags) < 0) { vshError(ctl, _("Failed to resize block device '%1$s'"), path); return false; --=20 2.53.0