From nobody Wed Mar 12 17:19:38 2025 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=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 1741703433638909.3181820688824; Tue, 11 Mar 2025 07:30:33 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 983A01CA6; Tue, 11 Mar 2025 10:30:32 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 85F721D4B; Tue, 11 Mar 2025 10:25:11 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A92D51C9A; Tue, 11 Mar 2025 10:25:05 -0400 (EDT) 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 E7FB51D76 for ; Tue, 11 Mar 2025 10:24:43 -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-529-DXpJBSllNOi_LGfwdJB_Ig-1; Tue, 11 Mar 2025 10:24:42 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 97F8F18001E3 for ; Tue, 11 Mar 2025 14:24:41 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.44]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 88E4F1944F12; Tue, 11 Mar 2025 14:24:40 +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=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741703083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ov+Xm6JtFDCbqwemgMyVfx8ZaTR0yIO8HWG0Sd0zYHE=; b=R3oRSDGc4wcFTlJJ+PbxkIRSUPYq0OFsbC4tlL5r2e/cj2Rih21M6+6rafFOR2EuQQwvMS Lhlwem2+iYzHAM1hJLiB1Ue6epcvgJYbpwiRndS60OjhOZ/ncqrLw8taKPfhBS2Uan2yAr rZYlpYP/3DAEeSbOB1iC6hPmSqjBIl8= X-MC-Unique: DXpJBSllNOi_LGfwdJB_Ig-1 X-Mimecast-MFC-AGG-ID: DXpJBSllNOi_LGfwdJB_Ig_1741703081 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: devel@lists.libvirt.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v2 06/23] src: add constants for guest info 'disk.' parameters Date: Tue, 11 Mar 2025 14:24:12 +0000 Message-ID: <20250311142429.1326816-7-berrange@redhat.com> In-Reply-To: <20250311142429.1326816-1-berrange@redhat.com> References: <20250311142429.1326816-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ni8RAtnPBuYzC6iP8BYISaMSuvNMcWLdx0dAnkAkWRk_1741703081 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: OZDA7GZP4ARUE3IX7ZD3PPTEBNAQT675 X-Message-ID-Hash: OZDA7GZP4ARUE3IX7ZD3PPTEBNAQT675 X-MailFrom: berrange@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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1741703435059019100 Content-Type: text/plain; charset="utf-8" Contrary to most APIs returning typed parameters, there are no constants defined for the guest info data keys. This is was because many of the keys needs to be dynamically constructed using one or more array index values. It is possible to define constants while still supporting dynamic array indexes by simply defining the prefixes and suffixes as constants. The consuming code can then combine the constants with array index value. With this approach, it is practical to add constants for the guest info API keys. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- include/libvirt/libvirt-domain.h | 110 +++++++++++++++++++++++++++++++ src/libvirt-domain.c | 20 +----- src/qemu/qemu_driver.c | 25 ++++--- 3 files changed, 129 insertions(+), 26 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 048036e2ed..fd7cf01243 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -6745,6 +6745,116 @@ int virDomainSetLaunchSecurityState(virDomainPtr do= main, */ #define VIR_DOMAIN_GUEST_INFO_FS_SUFFIX_DISK_SUFFIX_DEVICE ".device" =20 + +/** + * VIR_DOMAIN_GUEST_INFO_DISK_COUNT: + * + * The number of disks defined on this domain as an unsigned int. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_DISK_COUNT "disk.count" + +/** + * VIR_DOMAIN_GUEST_INFO_DISK_PREFIX: + * + * The parameter name prefix to access each disk entry. Concatenate the + * prefix, the entry number formatted as an unsigned integer and one of the + * disk suffix parameters to form a complete parameter name. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_DISK_PREFIX "disk." + +/** + * VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_NAME: + * + * Device node (Linux) or device UNC (Windows) as a string. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_NAME ".name" + +/** + * VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_PARTITION: + * + * Whether this is a partition (true) or disk (false) as a boolean. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_PARTITION ".partition" + +/** + * VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_DEPENDENCY_COUNT: + * + * The number of device dependencies as an unsigned int. + * + * e.g. for LVs of the LVM this will hold the list of PVs, for LUKS encryp= ted + * volume this will contain the disk where the volume is placed. (Linux). + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_DEPENDENCY_COUNT ".dependency.co= unt" + +/** + * VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_DEPENDENCY_PREFIX: + * + * The parameter name prefix to access each dependency entry. Concatenate = the + * disk prefix, the disk entry number formatted as an unsigned integer, the + * dependency prefix, the dependency entry number formatted as an unsigned + * integer and one of the dependency suffix parameters to form a complete + * parameter name. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_DEPENDENCY_PREFIX ".dependency." + +/** + * VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_DEPENDENCY_SUFFIX_NAME: + * + * A dependency name as a string. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_DEPENDENCY_SUFFIX_NAME ".name" + +/** + * VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_SERIAL: + * + * Optional disk serial number as a string. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_SERIAL ".serial" + +/** + * VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_ALIAS: + * + * The device alias of the disk (e.g. sda) as a string. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_ALIAS ".alias" + +/** + * VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_GUEST_ALIAS: + * + * Optional alias assigned to the disk, on Linux this is a name assigned by + * device mapper, as a string. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_GUEST_ALIAS ".guest_alias" + +/** + * VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_GUEST_BUS: + * + * Disk bus as reported by the guest OS. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_GUEST_BUS ".guest_bus" + /** * virDomainGuestInfoTypes: * diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index cb19516c35..87ea7a28ad 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -13228,23 +13228,9 @@ virDomainSetVcpu(virDomainPtr domain, * keys. * * VIR_DOMAIN_GUEST_INFO_DISKS: - * Returns information about the disks within the domain. The typed - * parameter keys are in this format: - * - * "disk.count" - the number of disks defined on this domain - * as an unsigned int - * "disk..name" - device node (Linux) or device UNC (Windows) - * "disk..partition" - whether this is a partition or disk - * "disk..dependency.count" - the number of device dependencies - * e.g. for LVs of the LVM this will - * hold the list of PVs, for LUKS encrypted volume th= is will - * contain the disk where the volume is placed. (Linu= x) - * "disk..dependency..name" - a dependency - * "disk..serial" - optional disk serial number (as string) - * "disk..alias" - the device alias of the disk (e.g. sda) - * "disk..guest_alias" - optional alias assigned to the disk, on= Linux - * this is a name assigned by device mapper - * "disk..guest_bus" - disk bus as reported by the guest OS + * Returns information about the disks within the domain. + * The VIR_DOMAIN_GUEST_INFO_DISK_* constants define the known typed para= meter + * keys. * * VIR_DOMAIN_GUEST_INFO_INTERFACES: * Returns information about the interfaces within the domain. The typed diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 22f656b890..8f7e232abd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -19206,22 +19206,25 @@ qemuAgentDiskInfoFormatParams(qemuAgentDiskInfo *= *info, { size_t i; =20 - virTypedParamListAddUInt(list, ndisks, "disk.count"); + virTypedParamListAddUInt(list, ndisks, VIR_DOMAIN_GUEST_INFO_DISK_COUN= T); =20 for (i =3D 0; i < ndisks; i++) { - virTypedParamListAddString(list, info[i]->name, "disk.%zu.name", i= ); - virTypedParamListAddBoolean(list, info[i]->partition, "disk.%zu.pa= rtition", i); + virTypedParamListAddString(list, info[i]->name, + VIR_DOMAIN_GUEST_INFO_DISK_PREFIX "%zu"= VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_NAME, i); + virTypedParamListAddBoolean(list, info[i]->partition, + VIR_DOMAIN_GUEST_INFO_DISK_PREFIX "%zu= " VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_PARTITION, i); =20 if (info[i]->dependencies) { size_t ndeps =3D g_strv_length(info[i]->dependencies); size_t j; =20 if (ndeps > 0) - virTypedParamListAddUInt(list, ndeps, "disk.%zu.dependency= .count", i); + virTypedParamListAddUInt(list, ndeps, + VIR_DOMAIN_GUEST_INFO_DISK_PREFIX= "%zu" VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_DEPENDENCY_COUNT, i); =20 for (j =3D 0; j < ndeps; j++) { virTypedParamListAddString(list, info[i]->dependencies[j], - "disk.%zu.dependency.%zu.name",= i, j); + VIR_DOMAIN_GUEST_INFO_DISK_PREF= IX "%zu" VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_DEPENDENCY_PREFIX "%zu" VIR_DOMA= IN_GUEST_INFO_DISK_SUFFIX_DEPENDENCY_SUFFIX_NAME, i, j); } } =20 @@ -19230,7 +19233,8 @@ qemuAgentDiskInfoFormatParams(qemuAgentDiskInfo **i= nfo, virDomainDiskDef *diskdef =3D NULL; =20 if (address->serial) - virTypedParamListAddString(list, address->serial, "disk.%z= u.serial", i); + virTypedParamListAddString(list, address->serial, + VIR_DOMAIN_GUEST_INFO_DISK_PREF= IX "%zu" VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_SERIAL, i); =20 /* match the disk to the target in the vm definition */ diskdef =3D virDomainDiskByAddress(vmdef, @@ -19241,14 +19245,17 @@ qemuAgentDiskInfoFormatParams(qemuAgentDiskInfo *= *info, address->unit); =20 if (diskdef && diskdef->dst) - virTypedParamListAddString(list, diskdef->dst, "disk.%zu.a= lias", i); + virTypedParamListAddString(list, diskdef->dst, + VIR_DOMAIN_GUEST_INFO_DISK_PREF= IX "%zu" VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_ALIAS, i); =20 if (address->bus_type) - virTypedParamListAddString(list, address->bus_type, "disk.= %zu.guest_bus", i); + virTypedParamListAddString(list, address->bus_type, + VIR_DOMAIN_GUEST_INFO_DISK_PREF= IX "%zu" VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_GUEST_BUS, i); } =20 if (info[i]->alias) - virTypedParamListAddString(list, info[i]->alias, "disk.%zu.gue= st_alias", i); + virTypedParamListAddString(list, info[i]->alias, + VIR_DOMAIN_GUEST_INFO_DISK_PREFIX "= %zu" VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_GUEST_ALIAS, i); } } =20 --=20 2.48.1