From nobody Wed May 15 20:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1702545782431735.9905851519455; Thu, 14 Dec 2023 01:23:02 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 591811994; Thu, 14 Dec 2023 04:23:01 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6E22D1873; Thu, 14 Dec 2023 04:20:03 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 5F7FB17B1; Thu, 14 Dec 2023 04:19:50 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id D75EA178F for ; Thu, 14 Dec 2023 04:19:49 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-63-VSTfRHf5Pp-dE4Vzd6YjGQ-1; Thu, 14 Dec 2023 04:19:48 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id C932285A588 for ; Thu, 14 Dec 2023 09:19:47 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BF8740C6EB9 for ; Thu, 14 Dec 2023 09:19:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: VSTfRHf5Pp-dE4Vzd6YjGQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 01/10] qemu: block: Introduce helpers for properly testing for 'raw' and 'luks' images Date: Thu, 14 Dec 2023 10:19:36 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: IGT62FKDVPNB5UBZWDVSESZZUEGSWSU4 X-Message-ID-Hash: IGT62FKDVPNB5UBZWDVSESZZUEGSWSU4 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702545784450100001 Unfortunately a LUKS image to be decrypted by qemu has VIR_STORAGE_FILE_RAW as format, but has encryption properties populated. Many places in the code don't check it properly and also don't check properly whether the image is indeed LUKS to be decrypted by qemu. Introduce helpes which will simplify this task. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_block.h | 5 +++++ 2 files changed, 48 insertions(+) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 7e9daf0bdc..845b273b27 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3237,6 +3237,49 @@ qemuBlockReopenReadOnly(virDomainObj *vm, return qemuBlockReopenAccess(vm, src, true, asyncJob); } + +/** + * qemuBlockStorageSourceIsQEMULuks: + * @src: storage source object + * + * Returns true if @src is an image in 'luks' format, which is to be decry= pted + * in qemu (rather than transparently by the transport layer or host's ker= nel). + */ +bool +qemuBlockStorageSourceIsQEMULuks(const virStorageSource *src) +{ + if (src->format !=3D VIR_STORAGE_FILE_RAW) + return false; + + if (src->encryption && + src->encryption->engine =3D=3D VIR_STORAGE_ENCRYPTION_ENGINE_QEMU = && + src->encryption->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) + return true; + + return false; +} + + +/** + * qemuBlockStorageSourceIsRaw: + * @src: storage source object + * + * Returns true if @src is a true 'raw' image. This specifically excludes + * LUKS encrypted images to be decrypted by qemu. + */ +bool +qemuBlockStorageSourceIsRaw(const virStorageSource *src) +{ + if (src->format !=3D VIR_STORAGE_FILE_RAW) + return false; + + if (qemuBlockStorageSourceIsQEMULuks(src)) + return false; + + return true; +} + + /** * qemuBlockStorageSourceNeedSliceLayer: * @src: source to inspect diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 0eab0d822c..9d6167b6ef 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -267,6 +267,11 @@ qemuBlockReopenReadOnly(virDomainObj *vm, virStorageSource *src, virDomainAsyncJob asyncJob); +bool +qemuBlockStorageSourceIsQEMULuks(const virStorageSource *src); +bool +qemuBlockStorageSourceIsRaw(const virStorageSource *src); + bool qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src); --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 20:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1702545963851995.2008327263915; Thu, 14 Dec 2023 01:26:03 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id B801D175D; Thu, 14 Dec 2023 04:26:02 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 07E6318E3; Thu, 14 Dec 2023 04:20:23 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 770F6195F; Thu, 14 Dec 2023 04:19:56 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id C3EC91792 for ; Thu, 14 Dec 2023 04:19:51 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-259-T-mHVNF9MY-fq-Nwr1nXmA-1; Thu, 14 Dec 2023 04:19:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id AD8FD885623 for ; Thu, 14 Dec 2023 09:19:48 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 236A040C6EB9 for ; Thu, 14 Dec 2023 09:19:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: T-mHVNF9MY-fq-Nwr1nXmA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 02/10] qemu: Use qemuBlockStorageSourceIsQEMULuks/qemuBlockStorageSourceIsRaw Date: Thu, 14 Dec 2023 10:19:37 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: CBMC6XSZVFEOXXLQ72XVQNOPS2WSW4D2 X-Message-ID-Hash: CBMC6XSZVFEOXXLQ72XVQNOPS2WSW4D2 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702545964749100001 Refactor code checking whether image is raw. This fixes multiple places where a LUKS encrypted disk could be mistreated. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 32 ++++++++++++-------------------- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_driver.c | 4 ++-- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 845b273b27..83954690d6 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -177,7 +177,7 @@ bool qemuBlockStorageSourceSupportsConcurrentAccess(virStorageSource *src) { /* no need to check in backing chain since only RAW storage supports t= his */ - return src->format =3D=3D VIR_STORAGE_FILE_RAW; + return qemuBlockStorageSourceIsRaw(src); } @@ -1336,10 +1336,12 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virSto= rageSource *src) case VIR_STORAGE_FILE_FAT: /* The fat layer is emulated by the storage access layer, so we ne= ed to * put a raw layer on top */ + if (qemuBlockStorageSourceGetFormatRawProps(src, props) < 0) + return NULL; + break; + case VIR_STORAGE_FILE_RAW: - if (src->encryption && - src->encryption->engine =3D=3D VIR_STORAGE_ENCRYPTION_ENGINE_Q= EMU && - src->encryption->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_L= UKS) { + if (qemuBlockStorageSourceIsQEMULuks(src)) { if (qemuBlockStorageSourceGetFormatLUKSProps(src, props) < 0) return NULL; } else { @@ -2080,9 +2082,7 @@ qemuBlockStorageSourceCreateAddBacking(virStorageSour= ce *backing, return 0; if (format) { - if (backing->format =3D=3D VIR_STORAGE_FILE_RAW && - backing->encryption && - backing->encryption->format =3D=3D VIR_STORAGE_ENCRYPTION_FORM= AT_LUKS) + if (qemuBlockStorageSourceIsQEMULuks(backing)) backingFormatStr =3D "luks"; else backingFormatStr =3D virStorageFileFormatTypeToString(backing-= >format); @@ -2313,8 +2313,7 @@ qemuBlockStorageSourceCreateGetFormatProps(virStorage= Source *src, { switch ((virStorageFileFormat) src->format) { case VIR_STORAGE_FILE_RAW: - if (!src->encryption || - src->encryption->format !=3D VIR_STORAGE_ENCRYPTION_FORMAT_LUK= S) + if (!qemuBlockStorageSourceIsQEMULuks(src)) return 0; return qemuBlockStorageSourceCreateGetFormatPropsLUKS(src, props); @@ -2584,8 +2583,8 @@ qemuBlockStorageSourceCreateFormat(virDomainObj *vm, g_autoptr(virJSONValue) createformatprops =3D NULL; int ret; - if (src->format =3D=3D VIR_STORAGE_FILE_RAW && - !src->encryption) + /* we don't bother creating only a true 'raw' image */ + if (qemuBlockStorageSourceIsRaw(src)) return 0; if (qemuBlockStorageSourceCreateGetFormatProps(src, backingStore, @@ -2743,7 +2742,7 @@ qemuBlockStorageSourceCreateDetectSize(GHashTable *bl= ockNamedNodeData, } } - if (src->format =3D=3D VIR_STORAGE_FILE_RAW) { + if (qemuBlockStorageSourceIsRaw(src)) { src->physical =3D entry->capacity; } else { src->physical =3D entry->physical; @@ -3299,14 +3298,7 @@ qemuBlockStorageSourceNeedsStorageSliceLayer(const v= irStorageSource *src) if (!src->sliceStorage) return false; - if (src->format !=3D VIR_STORAGE_FILE_RAW) - return true; - - if (src->encryption && - src->encryption->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) - return true; - - return false; + return !qemuBlockStorageSourceIsRaw(src); } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 23909dbbab..47b18923c0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1631,7 +1631,7 @@ qemuBuildDriveSourceStr(virDomainDiskDef *disk, virBufferAddLit(buf, ","); if (encinfo) { - if (disk->src->format =3D=3D VIR_STORAGE_FILE_RAW) { + if (qemuBlockStorageSourceIsQEMULuks(disk->src)) { virBufferAsprintf(buf, "key-secret=3D%s,", encinfo[0]->alias); rawluks =3D true; } else if (disk->src->format =3D=3D VIR_STORAGE_FILE_QCOW2 && diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9331369d4d..4a21e5af9c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10090,7 +10090,7 @@ qemuDomainBlockPeek(virDomainPtr dom, goto cleanup; } - if (disk->src->format !=3D VIR_STORAGE_FILE_RAW) { + if (qemuBlockStorageSourceIsRaw(disk->src)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("peeking is only supported for disk with 'raw' fo= rmat not '%1$s'"), virStorageFileFormatTypeToString(disk->src->format)= ); @@ -10285,7 +10285,7 @@ qemuStorageLimitsRefresh(virQEMUDriverConfig *cfg, * query the highest allocated extent from QEMU */ if (virStorageSourceGetActualType(src) =3D=3D VIR_STORAGE_TYPE_BLOCK && - src->format !=3D VIR_STORAGE_FILE_RAW && + !qemuBlockStorageSourceIsRaw(src) && S_ISBLK(sb.st_mode)) src->allocation =3D 0; --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 20:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 170254586232289.53442183572588; Thu, 14 Dec 2023 01:24:22 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3C40D1992; Thu, 14 Dec 2023 04:24:21 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9A5B3240; Thu, 14 Dec 2023 04:20:12 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id EB1D917D5; Thu, 14 Dec 2023 04:19:52 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 8F5E11786 for ; Thu, 14 Dec 2023 04:19:51 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-202-Q9zIBA0bOkC8nduewHo5qg-1; Thu, 14 Dec 2023 04:19:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7F4883C0F249 for ; Thu, 14 Dec 2023 09:19:49 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0812040C6E2B for ; Thu, 14 Dec 2023 09:19:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: Q9zIBA0bOkC8nduewHo5qg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 03/10] qemuDomainBlockResize: Agregate all checks at the beginning Date: Thu, 14 Dec 2023 10:19:38 +0100 Message-ID: <15574b890c3e7c914d530686badd2dfa309ad885.1702543905.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: VXBOMM7LAK23BFJRV4GJJBLJ3FGKNUUV X-Message-ID-Hash: VXBOMM7LAK23BFJRV4GJJBLJ3FGKNUUV X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702545864198100001 Move the check for readonly and empty disks to the top where all other checks will be done. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4a21e5af9c..7f719c33de 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9279,6 +9279,13 @@ qemuDomainBlockResize(virDomainPtr dom, goto endjob; } + if (virStorageSourceIsEmpty(disk->src) || disk->src->readonly) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("can't resize empty or readonly disk '%1$s'"), + disk->dst); + goto endjob; + } + if (virStorageSourceGetActualType(disk->src) =3D=3D VIR_STORAGE_TYPE_V= HOST_USER) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("block resize is not supported for vhostuser disk= ")); @@ -9292,13 +9299,6 @@ qemuDomainBlockResize(virDomainPtr dom, disk->src->format =3D=3D VIR_STORAGE_FILE_QED) size =3D VIR_ROUND_UP(size, 512); - if (virStorageSourceIsEmpty(disk->src) || disk->src->readonly) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, - _("can't resize empty or readonly disk '%1$s'"), - disk->dst); - goto endjob; - } - if (!qemuDiskBusIsSD(disk->bus)) { nodename =3D qemuBlockStorageSourceGetEffectiveNodename(disk->src); } else { --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 20:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1702546052850345.99813979744374; Thu, 14 Dec 2023 01:27:32 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9BAC618D4; Thu, 14 Dec 2023 04:27:31 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D53F1192B; Thu, 14 Dec 2023 04:20:31 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 192051792; Thu, 14 Dec 2023 04:19:57 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 7A5DA17B1 for ; Thu, 14 Dec 2023 04:19:52 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-PoN5IbGBPiCLtK-13Tkgvw-1; Thu, 14 Dec 2023 04:19:50 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 48FEA2820B83 for ; Thu, 14 Dec 2023 09:19:50 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id C75AD40C6EB9 for ; Thu, 14 Dec 2023 09:19:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: PoN5IbGBPiCLtK-13Tkgvw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 04/10] vsh: Introduce simple version of VSH_ALTERNATIVE_OPTIONS_EXPR Date: Thu, 14 Dec 2023 10:19:39 +0100 Message-ID: <4969b7857879d42f561dbaeacfc15f43a9bd6bd0.1702543905.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: E2WN6O6QIPVTCTEVUJKRLUERZBJH3VHI X-Message-ID-Hash: E2WN6O6QIPVTCTEVUJKRLUERZBJH3VHI X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702546055009100001 VSH_ALTERNATIVE_OPTIONS takes just the name of the options instead of requiring also the getter functions. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/vsh.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/vsh.h b/tools/vsh.h index 377c5947c1..2a1be29b1c 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -551,6 +551,10 @@ void vshReadlineHistoryAdd(const char *cmd); } \ } while (0) +#define VSH_ALTERNATIVE_OPTIONS(NAME1, NAME2) \ + VSH_ALTERNATIVE_OPTIONS_EXPR(NAME1, vshCommandOptBool(cmd, NAME1), \ + NAME2, vshCommandOptBool(cmd, NAME2)) + /* Macros to help dealing with required options. */ /* VSH_REQUIRE_OPTION_EXPR: --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 20:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1702546149363961.2475134854617; Thu, 14 Dec 2023 01:29:09 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4D9BC19BF; Thu, 14 Dec 2023 04:29:08 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 65E07196B; Thu, 14 Dec 2023 04:20:49 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 438411947; Thu, 14 Dec 2023 04:20:37 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 3FCD817D5 for ; Thu, 14 Dec 2023 04:19:53 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-186-RFGPcv_5MLC0KfNFqPvSgQ-1; Thu, 14 Dec 2023 04:19:51 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 194B42820B74 for ; Thu, 14 Dec 2023 09:19:51 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9944040C6EB9 for ; Thu, 14 Dec 2023 09:19:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: RFGPcv_5MLC0KfNFqPvSgQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 05/10] virDomainBlockResize: Introduce VIR_DOMAIN_BLOCK_RESIZE_CAPACITY Date: Thu, 14 Dec 2023 10:19:40 +0100 Message-ID: <0004a34396cf08dffd226392e37760e6b4bee1ce.1702543905.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: E2HI7INPSLJIGYZMWVTGP3NCJ5E2UFOU X-Message-ID-Hash: E2HI7INPSLJIGYZMWVTGP3NCJ5E2UFOU X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702546151340100001 Allow users to easily resize 'raw' images on block devices to the full capacity of the block device. Obviously this won't work on file-backed storage (filling the remaining capacity is most likely wrong) or for formats with metadata due to the overhead. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- docs/manpages/virsh.rst | 6 +++++- include/libvirt/libvirt-domain.h | 1 + src/libvirt-domain.c | 5 +++++ tools/virsh-domain.c | 10 +++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 3e7a4c6c22..ed1027e133 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1421,7 +1421,7 @@ blockresize :: - blockresize domain path size + blockresize domain path ([size] | [--capacity]) Resize a block device of domain while the domain is running, *path* specifies the absolute path of the block device; it corresponds @@ -1429,6 +1429,10 @@ to a unique target name () or = source file () for one of the disk devices attached to *domain* (see also ``domblklist`` for listing these names). +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. + *size* is a scaled integer (see ``NOTES`` above) which defaults to KiB (blocks of 1024 bytes) if there is no suffix. You must use a suffix of "B" to get bytes (note that for historical reasons, this differs from diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index a1902546bb..30cce85b29 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2172,6 +2172,7 @@ int virDomainBlockPeek (virDomain= Ptr dom, */ 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) */ } virDomainBlockResizeFlags; int virDomainBlockResize (virDomainPtr dom, diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 77a9682ecb..94e5672ed8 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -6388,6 +6388,11 @@ virDomainBlockPeek(virDomainPtr dom, * size. Depending on the file format, the hypervisor may round up * to the next alignment boundary. * + * 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, + * ignoring @size. This is possible only for image formats with no metadata + * ('raw') and for source devices with limited capacity such as block devi= ces. + * * The @disk parameter is either an unambiguous source name of the * block device (the sub-element, such as * "/path/to/image"), or (since 0.9.5) the device target shorthand diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index fa9d356e15..327553f6d7 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2949,9 +2949,12 @@ static const vshCmdOptDef opts_blockresize[] =3D { }, {.name =3D "size", .type =3D VSH_OT_INT, - .flags =3D VSH_OFLAG_REQ, .help =3D N_("New size of the block device, as scaled integer (defaul= t KiB)") }, + {.name =3D "capacity", + .type =3D VSH_OT_BOOL, + .help =3D N_("resize to capacity of source (block device)") + }, {.name =3D NULL} }; @@ -2963,6 +2966,11 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd) unsigned long long size =3D 0; unsigned int flags =3D 0; + VSH_ALTERNATIVE_OPTIONS("size", "capacity"); + + if (vshCommandOptBool(cmd, "capacity")) + flags |=3D VIR_DOMAIN_BLOCK_RESIZE_CAPACITY; + if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < = 0) return false; --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 20:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1702546265658794.9755999663788; Thu, 14 Dec 2023 01:31:05 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8C61A17E5; Thu, 14 Dec 2023 04:31:04 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 51582188D; Thu, 14 Dec 2023 04:20:59 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id E43B91947; Thu, 14 Dec 2023 04:20:40 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 4253518B0 for ; Thu, 14 Dec 2023 04:19:54 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-0gtmk8wyOmWCyVOlblbWdQ-1; Thu, 14 Dec 2023 04:19:52 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id D93A3185A787 for ; Thu, 14 Dec 2023 09:19:51 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6321A40C6EB9 for ; Thu, 14 Dec 2023 09:19:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 0gtmk8wyOmWCyVOlblbWdQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 06/10] qemuDomainBlockResize: Implement VIR_DOMAIN_BLOCK_RESIZE_CAPACITY Date: Thu, 14 Dec 2023 10:19:41 +0100 Message-ID: <2356c43ec4f37a31e16e148540f1ee4a4c2703fd.1702543905.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: ETPP4YS4HBFM3E54DFLL4K2FBEOSIP7N X-Message-ID-Hash: ETPP4YS4HBFM3E54DFLL4K2FBEOSIP7N X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702546267955100001 Resizing of block-backed storage requires the user to pass the exact capacity of the device. Implement code which will query it instead so the user doesn't need to do that. Closes: https://gitlab.com/libvirt/libvirt/-/issues/449 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7f719c33de..db99d471d4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9246,7 +9246,8 @@ qemuDomainBlockResize(virDomainPtr dom, const char *nodename =3D NULL; virDomainDiskDef *disk =3D NULL; - virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1); + virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES | + VIR_DOMAIN_BLOCK_RESIZE_CAPACITY, -1); /* We prefer operating on bytes. */ if ((flags & VIR_DOMAIN_BLOCK_RESIZE_BYTES) =3D=3D 0) { @@ -9292,6 +9293,25 @@ qemuDomainBlockResize(virDomainPtr dom, goto endjob; } + if (flags & VIR_DOMAIN_BLOCK_RESIZE_CAPACITY) { + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv= ->driver); + + if (!qemuBlockStorageSourceIsRaw(disk->src) || + !virStorageSourceIsBlockLocal(disk->src)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("block resize to full capacity supported only= with 'raw' local block-based disks")); + goto endjob; + } + + if (qemuDomainStorageUpdatePhysical(cfg, vm, disk->src) < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("failed to update capacity of '%1$s'"), disk-= >src->path); + goto endjob; + } + + size =3D disk->src->physical; + } + /* qcow2 and qed must be sized on 512 byte blocks/sectors, * so adjust size if necessary to round up. */ --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 20:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1702546373732973.3208511148764; Thu, 14 Dec 2023 01:32:53 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 732161925; Thu, 14 Dec 2023 04:32:52 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 95396197D; Thu, 14 Dec 2023 04:21:08 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 452691927; Thu, 14 Dec 2023 04:20:42 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 8A4BC17E4 for ; Thu, 14 Dec 2023 04:19:54 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-684-ZkAUbh4UNYipdXZruN619g-1; Thu, 14 Dec 2023 04:19:52 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id AA5333814E8F for ; Thu, 14 Dec 2023 09:19:52 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F8F640C6EB9 for ; Thu, 14 Dec 2023 09:19:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: ZkAUbh4UNYipdXZruN619g-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 07/10] qemu: block: Make 'slice' layer effective for 'raw' storage source Date: Thu, 14 Dec 2023 10:19:42 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: GZSTDHGMOUL5MUNJNDVUHQROLOBD5EVM X-Message-ID-Hash: GZSTDHGMOUL5MUNJNDVUHQROLOBD5EVM X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702546374443100001 Rather than pulling the configuration of the storage slice into the 'format' layer make the 'slice' layer effective for raw disks with a storage slice. This was made possible by the recent refactors which made the 'format' layer optional if not needed. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 40 +++++-------------- .../disk-slices.x86_64-latest.args | 8 ++-- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 83954690d6..fd914d2e70 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1203,27 +1203,6 @@ qemuBlockStorageSourceGetFormatLUKSProps(virStorageS= ource *src, } -static int -qemuBlockStorageSourceGetFormatRawProps(virStorageSource *src, - virJSONValue *props) -{ - if (virJSONValueObjectAdd(&props, "s:driver", "raw", NULL) < 0) - return -1; - - /* Currently only storage slices are supported. We'll have to calculate - * the union of the slices here if we don't want to be adding needless - * 'raw' nodes. */ - if (src->sliceStorage && - virJSONValueObjectAdd(&props, - "U:offset", src->sliceStorage->offset, - "U:size", src->sliceStorage->size, - NULL) < 0) - return -1; - - return 0; -} - - static int qemuBlockStorageSourceGetCryptoProps(virStorageSource *src, virJSONValue **encprops) @@ -1336,8 +1315,7 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStora= geSource *src) case VIR_STORAGE_FILE_FAT: /* The fat layer is emulated by the storage access layer, so we ne= ed to * put a raw layer on top */ - if (qemuBlockStorageSourceGetFormatRawProps(src, props) < 0) - return NULL; + driver =3D "raw"; break; case VIR_STORAGE_FILE_RAW: @@ -1345,8 +1323,7 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStora= geSource *src) if (qemuBlockStorageSourceGetFormatLUKSProps(src, props) < 0) return NULL; } else { - if (qemuBlockStorageSourceGetFormatRawProps(src, props) < 0) - return NULL; + driver =3D "raw"; } break; @@ -3295,10 +3272,7 @@ qemuBlockStorageSourceIsRaw(const virStorageSource *= src) bool qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src) { - if (!src->sliceStorage) - return false; - - return !qemuBlockStorageSourceIsRaw(src); + return !!src->sliceStorage; } @@ -3314,9 +3288,13 @@ qemuBlockStorageSourceNeedsStorageSliceLayer(const v= irStorageSource *src) * existence of the format layer nodename. */ bool -qemuBlockStorageSourceNeedsFormatLayer(const virStorageSource *src G_GNUC_= UNUSED) +qemuBlockStorageSourceNeedsFormatLayer(const virStorageSource *src) { - /* Currently we always create a 'format' layer */ + /* Skip 'format' layer, when a storage slice for a raw image is in use= */ + if (qemuBlockStorageSourceIsRaw(src) && + src->sliceStorage) + return false; + return true; } diff --git a/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args b/tests/= qemuxml2argvdata/disk-slices.x86_64-latest.args index 363f0c0361..c28eeb827e 100644 --- a/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args @@ -28,8 +28,8 @@ XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGue= st1/.config \ -boot strict=3Don \ -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/raw.img","= node-name":"libvirt-6-storage","auto-read-only":true,"discard":"unmap"}' \ --blockdev '{"node-name":"libvirt-6-format","read-only":false,"driver":"raw= ","offset":0,"size":321,"file":"libvirt-6-storage"}' \ --device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x2","drive":"li= bvirt-6-format","id":"virtio-disk0","bootindex":1}' \ +-blockdev '{"driver":"raw","offset":0,"size":321,"file":"libvirt-6-storage= ","node-name":"libvirt-6-slice-sto","read-only":false}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x2","drive":"li= bvirt-6-slice-sto","id":"virtio-disk0","bootindex":1}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/raw.img","= node-name":"libvirt-5-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"driver":"raw","offset":9876,"size":123456789,"file":"libvirt-= 5-storage","node-name":"libvirt-5-slice-sto","auto-read-only":true,"discard= ":"unmap"}' \ -blockdev '{"node-name":"libvirt-5-format","read-only":true,"driver":"qcow= 2","file":"libvirt-5-slice-sto","backing":null}' \ @@ -42,8 +42,8 @@ XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGue= st1/.config \ -blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"luk= s","key-secret":"libvirt-3-format-encryption-secret0","file":"libvirt-3-sli= ce-sto"}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x4","drive":"li= bvirt-3-format","id":"virtio-disk2"}' \ -blockdev '{"driver":"nvme","device":"0000:02:00.0","namespace":1,"node-na= me":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ --blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw= ","offset":1234,"size":321,"file":"libvirt-2-storage"}' \ --device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x6","drive":"li= bvirt-2-format","id":"virtio-disk3"}' \ +-blockdev '{"driver":"raw","offset":1234,"size":321,"file":"libvirt-2-stor= age","node-name":"libvirt-2-slice-sto","read-only":false}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x6","drive":"li= bvirt-2-slice-sto","id":"virtio-disk3"}' \ -object '{"qom-type":"secret","id":"libvirt-1-format-encryption-secret0","= data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","k= eyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}' \ -blockdev '{"driver":"nvme","device":"0001:02:00.0","namespace":2,"node-na= me":"libvirt-1-storage","auto-read-only":true,"discard":"unmap","cache":{"d= irect":true,"no-flush":false}}' \ -blockdev '{"driver":"raw","offset":1234,"size":321,"file":"libvirt-1-stor= age","node-name":"libvirt-1-slice-sto","auto-read-only":true,"discard":"unm= ap","cache":{"direct":true,"no-flush":false}}' \ --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 20:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1702546481533482.32878743163224; Thu, 14 Dec 2023 01:34:41 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 723E719AF; Thu, 14 Dec 2023 04:34:40 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9D0161932; Thu, 14 Dec 2023 04:21:16 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 5F43C17E3; Thu, 14 Dec 2023 04:20:44 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 954D61946 for ; Thu, 14 Dec 2023 04:19:55 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-256-OJT07A4YNcybjYe9jO9FeA-1; Thu, 14 Dec 2023 04:19:53 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 74BF6863B88 for ; Thu, 14 Dec 2023 09:19:53 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id F08EB40C6EB9 for ; Thu, 14 Dec 2023 09:19:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: OJT07A4YNcybjYe9jO9FeA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 08/10] qemu: block: Format storage slice properties optionally Date: Thu, 14 Dec 2023 10:19:43 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: CFNMVWKTKV2UUAX3G65XKGSIDMJCKQBJ X-Message-ID-Hash: CFNMVWKTKV2UUAX3G65XKGSIDMJCKQBJ X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702546482969100001 Prepare the blockdev props formatter to skip formatting the slice props in case they are not applicable. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 19 ++++++++++++++----- .../disk-slices.x86_64-latest.args | 10 +++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index fd914d2e70..8e2da95139 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1434,22 +1434,31 @@ qemuBlockStorageSourceGetFormatProps(virStorageSour= ce *src, * qemuBlockStorageSourceGetBlockdevStorageSliceProps: * @src: storage source object * @effective: Whether this blockdev will be the 'effective' layer of @src + * @resize: If true, the 'size' and 'offset' parameters are not formatted * * Formats the JSON object representing -blockdev configuration required to * configure a 'slice' of @src. If @effective is true, the slice layer is = the - * topmost/effective blockdev layer of @src. + * topmost/effective blockdev layer of @src. If @resize is true the 'size'= and + * 'offset' are not formatted, which is used to remove a slice restriction + * to resize the image. */ static virJSONValue * qemuBlockStorageSourceGetBlockdevStorageSliceProps(virStorageSource *src, - bool effective) + bool effective, + bool resize) { g_autoptr(virJSONValue) props =3D NULL; if (virJSONValueObjectAdd(&props, "s:driver", "raw", + "s:file", qemuBlockStorageSourceGetStorageNo= dename(src), + NULL) < 0) + return NULL; + + if (!resize && + virJSONValueObjectAdd(&props, "U:offset", src->sliceStorage->offset, "U:size", src->sliceStorage->size, - "s:file", qemuBlockStorageSourceGetStorageNo= dename(src), NULL) < 0) return NULL; @@ -1530,7 +1539,7 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorag= eSource *src, } if ((data->storageSliceNodeName =3D qemuBlockStorageSourceGetSliceNode= name(src))) { - if (!(data->storageSliceProps =3D qemuBlockStorageSourceGetBlockde= vStorageSliceProps(src, effective))) + if (!(data->storageSliceProps =3D qemuBlockStorageSourceGetBlockde= vStorageSliceProps(src, effective, false))) return NULL; effective =3D false; @@ -3150,7 +3159,7 @@ qemuBlockReopenAccess(virDomainObj *vm, if (!(srcprops =3D qemuBlockStorageSourceGetFormatProps(src, src->= backingStore))) return -1; } else if (qemuBlockStorageSourceGetSliceNodename(src)) { - if (!(srcprops =3D qemuBlockStorageSourceGetBlockdevStorageSlicePr= ops(src, true))) + if (!(srcprops =3D qemuBlockStorageSourceGetBlockdevStorageSlicePr= ops(src, true, false))) return -1; } else { if (!(srcprops =3D qemuBlockStorageSourceGetBackendProps(src, diff --git a/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args b/tests/= qemuxml2argvdata/disk-slices.x86_64-latest.args index c28eeb827e..658391c477 100644 --- a/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args @@ -28,25 +28,25 @@ XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUG= uest1/.config \ -boot strict=3Don \ -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/raw.img","= node-name":"libvirt-6-storage","auto-read-only":true,"discard":"unmap"}' \ --blockdev '{"driver":"raw","offset":0,"size":321,"file":"libvirt-6-storage= ","node-name":"libvirt-6-slice-sto","read-only":false}' \ +-blockdev '{"driver":"raw","file":"libvirt-6-storage","offset":0,"size":32= 1,"node-name":"libvirt-6-slice-sto","read-only":false}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x2","drive":"li= bvirt-6-slice-sto","id":"virtio-disk0","bootindex":1}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/raw.img","= node-name":"libvirt-5-storage","auto-read-only":true,"discard":"unmap"}' \ --blockdev '{"driver":"raw","offset":9876,"size":123456789,"file":"libvirt-= 5-storage","node-name":"libvirt-5-slice-sto","auto-read-only":true,"discard= ":"unmap"}' \ +-blockdev '{"driver":"raw","file":"libvirt-5-storage","offset":9876,"size"= :123456789,"node-name":"libvirt-5-slice-sto","auto-read-only":true,"discard= ":"unmap"}' \ -blockdev '{"node-name":"libvirt-5-format","read-only":true,"driver":"qcow= 2","file":"libvirt-5-slice-sto","backing":null}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/overlay.qc= ow2","node-name":"libvirt-4-storage","auto-read-only":true,"discard":"unmap= "}' \ -blockdev '{"node-name":"libvirt-4-format","read-only":false,"driver":"qco= w2","file":"libvirt-4-storage","backing":"libvirt-5-format"}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x3","drive":"li= bvirt-4-format","id":"virtio-disk1"}' \ -object '{"qom-type":"secret","id":"libvirt-3-format-encryption-secret0","= data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","k= eyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/luks.img",= "node-name":"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \ --blockdev '{"driver":"raw","offset":1234,"size":321,"file":"libvirt-3-stor= age","node-name":"libvirt-3-slice-sto","auto-read-only":true,"discard":"unm= ap"}' \ +-blockdev '{"driver":"raw","file":"libvirt-3-storage","offset":1234,"size"= :321,"node-name":"libvirt-3-slice-sto","auto-read-only":true,"discard":"unm= ap"}' \ -blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"luk= s","key-secret":"libvirt-3-format-encryption-secret0","file":"libvirt-3-sli= ce-sto"}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x4","drive":"li= bvirt-3-format","id":"virtio-disk2"}' \ -blockdev '{"driver":"nvme","device":"0000:02:00.0","namespace":1,"node-na= me":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ --blockdev '{"driver":"raw","offset":1234,"size":321,"file":"libvirt-2-stor= age","node-name":"libvirt-2-slice-sto","read-only":false}' \ +-blockdev '{"driver":"raw","file":"libvirt-2-storage","offset":1234,"size"= :321,"node-name":"libvirt-2-slice-sto","read-only":false}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x6","drive":"li= bvirt-2-slice-sto","id":"virtio-disk3"}' \ -object '{"qom-type":"secret","id":"libvirt-1-format-encryption-secret0","= data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","k= eyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}' \ -blockdev '{"driver":"nvme","device":"0001:02:00.0","namespace":2,"node-na= me":"libvirt-1-storage","auto-read-only":true,"discard":"unmap","cache":{"d= irect":true,"no-flush":false}}' \ --blockdev '{"driver":"raw","offset":1234,"size":321,"file":"libvirt-1-stor= age","node-name":"libvirt-1-slice-sto","auto-read-only":true,"discard":"unm= ap","cache":{"direct":true,"no-flush":false}}' \ +-blockdev '{"driver":"raw","file":"libvirt-1-storage","offset":1234,"size"= :321,"node-name":"libvirt-1-slice-sto","auto-read-only":true,"discard":"unm= ap","cache":{"direct":true,"no-flush":false}}' \ -blockdev '{"node-name":"libvirt-1-format","read-only":false,"cache":{"dir= ect":true,"no-flush":false},"driver":"qcow2","encrypt":{"format":"luks","ke= y-secret":"libvirt-1-format-encryption-secret0"},"file":"libvirt-1-slice-st= o"}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x7","drive":"li= bvirt-1-format","id":"virtio-disk4","write-cache":"on"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 20:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1702546553093504.81314659530267; Thu, 14 Dec 2023 01:35:53 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0D4371875; Thu, 14 Dec 2023 04:35:52 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id EB5BE194D; Thu, 14 Dec 2023 04:21:25 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id A1CFB1934; Thu, 14 Dec 2023 04:20:46 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 30C6B195E for ; Thu, 14 Dec 2023 04:19:56 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-AS_tr1xKOKOPB36goqZb_w-1; Thu, 14 Dec 2023 04:19:54 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 45677101A551 for ; Thu, 14 Dec 2023 09:19:54 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id C09D840C6EB9 for ; Thu, 14 Dec 2023 09:19:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: AS_tr1xKOKOPB36goqZb_w-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 09/10] virStorageSourceSliceFree: Export function Date: Thu, 14 Dec 2023 10:19:44 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: XGRNC6VXX635OWI55C5KRQ6SEBEVN5KR X-Message-ID-Hash: XGRNC6VXX635OWI55C5KRQ6SEBEVN5KR X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702546553680100001 The function will be used in the code for resizing block devices with a slice. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/storage_source_conf.c | 2 +- src/conf/storage_source_conf.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index f974a521b1..959ec5ed40 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -765,7 +765,7 @@ virStorageSourceSliceCopy(const virStorageSourceSlice *= src) } -static void +void virStorageSourceSliceFree(virStorageSourceSlice *slice) { if (!slice) diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index 5e7d127453..05b4bda16c 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -258,6 +258,8 @@ struct _virStorageSourceSlice { char *nodename; }; +void +virStorageSourceSliceFree(virStorageSourceSlice *slice); struct _virStorageSourceFDTuple { GObject parent; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 553b01b8c0..31c0f169c3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1161,6 +1161,7 @@ virStorageSourcePoolModeTypeFromString; virStorageSourcePoolModeTypeToString; virStorageSourcePrivateDataFormatRelPath; virStorageSourcePrivateDataParseRelPath; +virStorageSourceSliceFree; virStorageTypeFromString; virStorageTypeToString; --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 20:16:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1702546657844661.9125818778672; Thu, 14 Dec 2023 01:37:37 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id BADC818F1; Thu, 14 Dec 2023 04:37:36 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 255DD1956; Thu, 14 Dec 2023 04:21:35 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id EA4A51934; Thu, 14 Dec 2023 04:20:49 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id D4356195C for ; Thu, 14 Dec 2023 04:19:57 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-416-8okWy_EMNU-KK5W0ltHwFg-1; Thu, 14 Dec 2023 04:19:55 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 153E3101A555 for ; Thu, 14 Dec 2023 09:19:55 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90CAE40C6EB9 for ; Thu, 14 Dec 2023 09:19:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 8okWy_EMNU-KK5W0ltHwFg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 10/10] qemuDomainBlockResize: Properly resize disks with storage slice Date: Thu, 14 Dec 2023 10:19:45 +0100 Message-ID: <3502c34fa1d87152691ea72ddb168decb2c0ccb8.1702543905.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: FHB3A5ZSXX3CPL76DM7K7OVJBR3I6MMO X-Message-ID-Hash: FHB3A5ZSXX3CPL76DM7K7OVJBR3I6MMO X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702546658335100001 Until now resizing a disk with a storage slice would break in one of the following ways: 1) for a non-raw format, the virtual size would change, but the slice would still remain in place 2) for raw disks qemu would refuse to change the size The only reasonable scenario we want to support is a 'raw' image with 0 offset (inside a block device), where we can just drop the slice. Anything else comes from a non-standard storage setup that we don't want to touch. To facilitate the resize, we first remove the 'size' parameter in qemu thus dropping the slice and then instructing qemu to resize the disk. Resolves: https://issues.redhat.com/browse/RHEL-18782 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 65 +++++++++++++++++++++++++++++++++++ src/qemu/qemu_block.h | 4 +++ src/qemu/qemu_driver.c | 77 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 139 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 8e2da95139..db620bf836 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3265,6 +3265,71 @@ qemuBlockStorageSourceIsRaw(const virStorageSource *= src) } +/** + * qemuBlockReopenSliceExpand: + * @vm: domain object + * @src: storage source to reopen + * + * Reopen @src image to remove it's storage slice. Note that this currently + * works only for 'raw' disks. + * + * Note: This changes transforms the definition such that the 'raw' driver + * becomes the 'format' layer rather than the 'slice' layer, to be a= ble + * to free the slice definition. + */ +int +qemuBlockReopenSliceExpand(virDomainObj *vm, + virStorageSource *src) +{ + g_autoptr(virJSONValue) reopenoptions =3D virJSONValueNewArray(); + g_autoptr(virJSONValue) srcprops =3D NULL; + int rc; + + /* If we are lacking the object here, qemu might have opened an image = with + * a node name unknown to us */ + /* Note: This is currently dead code, as only 'raw' images are support= ed */ + if (!src->backingStore) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("can't reopen image with unknown presence of back= ing store")); + return -1; + } + + /* If there is an explicit storage slice 'raw' driver layer we need to= modify that */ + if (qemuBlockStorageSourceGetSliceNodename(src)) { + /* we need to know whether the slice layer is the "effective" laye= r */ + bool isEffective =3D !qemuBlockStorageSourceGetSliceNodename(src); + + if (!(srcprops =3D qemuBlockStorageSourceGetBlockdevStorageSlicePr= ops(src, isEffective, true))) + return -1; + } else { + if (!(srcprops =3D qemuBlockStorageSourceGetFormatProps(src, src->= backingStore))) + return -1; + } + + if (virJSONValueArrayAppend(reopenoptions, &srcprops) < 0) + return -1; + + if (qemuDomainObjEnterMonitorAsync(vm, VIR_ASYNC_JOB_NONE) < 0) + return -1; + + rc =3D qemuMonitorBlockdevReopen(qemuDomainGetMonitor(vm), &reopenopti= ons); + + qemuDomainObjExitMonitor(vm); + if (rc < 0) + return -1; + + /* transform the 'slice' raw driver into a 'format' driver so that we = don't + * have to add extra code */ + if (qemuBlockStorageSourceGetSliceNodename(src)) + qemuBlockStorageSourceSetFormatNodename(src, g_strdup(qemuBlockSto= rageSourceGetSliceNodename(src))); + + /* get rid of the slice */ + g_clear_pointer(&src->sliceStorage, virStorageSourceSliceFree); + + return 0; +} + + /** * qemuBlockStorageSourceNeedSliceLayer: * @src: source to inspect diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 9d6167b6ef..d994520924 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -267,6 +267,10 @@ qemuBlockReopenReadOnly(virDomainObj *vm, virStorageSource *src, virDomainAsyncJob asyncJob); +int +qemuBlockReopenSliceExpand(virDomainObj *vm, + virStorageSource *src); + bool qemuBlockStorageSourceIsQEMULuks(const virStorageSource *src); bool diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index db99d471d4..1b9436da5c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9245,6 +9245,7 @@ qemuDomainBlockResize(virDomainPtr dom, g_autofree char *device =3D NULL; const char *nodename =3D NULL; virDomainDiskDef *disk =3D NULL; + virDomainDiskDef *persistDisk =3D NULL; virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES | VIR_DOMAIN_BLOCK_RESIZE_CAPACITY, -1); @@ -9293,9 +9294,23 @@ qemuDomainBlockResize(virDomainPtr dom, goto endjob; } - if (flags & VIR_DOMAIN_BLOCK_RESIZE_CAPACITY) { + /* The physical capacity is needed both when automatic sizing is reque= sted + * and when a slice is used on top of a block device. + */ + if (virStorageSourceIsBlockLocal(disk->src) && + ((flags & VIR_DOMAIN_BLOCK_RESIZE_CAPACITY) || + disk->src->sliceStorage)) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv= ->driver); + if (qemuDomainStorageUpdatePhysical(cfg, vm, disk->src) < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("failed to update capacity of '%1$s'"), disk-= >src->path); + goto endjob; + } + + } + + if (flags & VIR_DOMAIN_BLOCK_RESIZE_CAPACITY) { if (!qemuBlockStorageSourceIsRaw(disk->src) || !virStorageSourceIsBlockLocal(disk->src)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", @@ -9303,12 +9318,6 @@ qemuDomainBlockResize(virDomainPtr dom, goto endjob; } - if (qemuDomainStorageUpdatePhysical(cfg, vm, disk->src) < 0) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("failed to update capacity of '%1$s'"), disk-= >src->path); - goto endjob; - } - size =3D disk->src->physical; } @@ -9319,6 +9328,55 @@ qemuDomainBlockResize(virDomainPtr dom, disk->src->format =3D=3D VIR_STORAGE_FILE_QED) size =3D VIR_ROUND_UP(size, 512); + if (disk->src->sliceStorage) { + if (qemuDiskBusIsSD(disk->bus)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("resize of a 'sd' disk with storage slice is = not supported")); + goto endjob; + } + + /* If the storage slice has a non-zero 'offset' it's usually some = weird + * configuration that we'd rather not touch */ + if (disk->src->sliceStorage->offset > 0) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("resize of a disk with storage slice with non= -zero 'offset' is not supported")); + goto endjob; + } + + /* Removing the slice for non-raw will require introducing an attr= ibute that + * the slice was fully expanded so that the XML can keep the 'slic= e' element. + * For raw images we simply remove the slice definition as there i= s no + * extra layer. */ + if (!qemuBlockStorageSourceIsRaw(disk->src)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("resize of a disk with storage slice is suppo= rted only for 'raw' images")); + goto endjob; + } + + /* trying to resize a block device to a size not equal to the actu= al + * size of the block device will cause qemu to fail */ + if (virStorageSourceIsBlockLocal(disk->src) && + disk->src->physical !=3D size) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("block device backed disk must be resized to = it's actual size '%1$llu'"), + disk->src->physical); + goto endjob; + } + + if (vm->newDef && + (persistDisk =3D virDomainDiskByTarget(vm->newDef, disk->dst))= ) { + if (!virStorageSourceIsSameLocation(disk->src, persistDisk->sr= c) || + !persistDisk->src->sliceStorage) + persistDisk =3D NULL; + } + + /* remove the slice completely, we then instruct qemu to resize */ + if (qemuBlockReopenSliceExpand(vm, disk->src) < 0) + goto endjob; + + qemuDomainSaveStatus(vm); + } + if (!qemuDiskBusIsSD(disk->bus)) { nodename =3D qemuBlockStorageSourceGetEffectiveNodename(disk->src); } else { @@ -9333,6 +9391,11 @@ qemuDomainBlockResize(virDomainPtr dom, } qemuDomainObjExitMonitor(vm); + if (persistDisk) { + g_clear_pointer(&persistDisk->src->sliceStorage, virStorageSourceS= liceFree); + qemuDomainSaveConfig(vm); + } + ret =3D 0; endjob: --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org