From nobody Wed Mar 12 17:19:56 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 1741703638381602.4307710199341; Tue, 11 Mar 2025 07:33:58 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BF7001DBB; Tue, 11 Mar 2025 10:33:57 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 65A8D1DE6; Tue, 11 Mar 2025 10:25:35 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BAEDE1D43; Tue, 11 Mar 2025 10:25:27 -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 762BA1D7B for ; Tue, 11 Mar 2025 10:25:02 -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-553-zm1NnlStO-6ujVkDEiTL0g-1; Tue, 11 Mar 2025 10:24:44 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 458951954B1B for ; Tue, 11 Mar 2025 14:24:43 +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 3821F1955BCB; Tue, 11 Mar 2025 14:24:41 +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=1741703102; 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=Oa1EUQdIya0e2Y3Q2S4n5KoCfoDLITNmb8YR+Ps546k=; b=bIsbOsLv9FQy5yzsGBb5UvCFCE+/xsOdI4Lt9+hnmzo5JjuWSZtioKir4QL1LtSDg8ISPp UYFsP3anoXqSshuJ7DaYTmbBHUWRavNNaUgkHyrPj8ggqQngryoeRxkh9wIcgN8VVsDMTE 58Q7sm7iYEP9kFbL73D+TeOb7Lz8V94= X-MC-Unique: zm1NnlStO-6ujVkDEiTL0g-1 X-Mimecast-MFC-AGG-ID: zm1NnlStO-6ujVkDEiTL0g_1741703083 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 07/23] src: add constants for guest info 'if.' parameters Date: Tue, 11 Mar 2025 14:24:13 +0000 Message-ID: <20250311142429.1326816-8-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: yHjAMDv1aZdyw2Z7aLwpjSmmTNL0kIhmNVfo1dexVB4_1741703083 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: VP5FOFEQ73FWSNP3W2S6R5UG42OTHMJC X-Message-ID-Hash: VP5FOFEQ73FWSNP3W2S6R5UG42OTHMJC 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: 1741703639834019000 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 | 88 ++++++++++++++++++++++++++++++++ src/libvirt-domain.c | 13 ++--- src/qemu/qemu_driver.c | 21 +++++--- 3 files changed, 104 insertions(+), 18 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index fd7cf01243..38139ed8ec 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -6855,6 +6855,94 @@ int virDomainSetLaunchSecurityState(virDomainPtr dom= ain, */ #define VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_GUEST_BUS ".guest_bus" =20 + +/** + * VIR_DOMAIN_GUEST_INFO_IF_COUNT: + * + * The number of interfaces defined on this domain as an unsigned int. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_IF_COUNT "if.count" + +/** + * VIR_DOMAIN_GUEST_INFO_IF_PREFIX: + * + * The parameter name prefix to access each interface entry. Concatenate t= he + * prefix, the entry number formatted as an unsigned integer and one of the + * interface suffix parameters to form a complete parameter name. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_IF_PREFIX "if." + +/** + * VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_NAME: + * + * Name in the guest (e.g. ``eth0``) for the interface as a string. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_NAME ".name" + +/** + * VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_HWADDR: + * + * Hardware address in the guest of the interface as a string. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_HWADDR ".hwaddr" + +/** + * VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_COUNT: + * + * The number of IP addresses of interface as an unsigned int. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_COUNT ".addr.count" + +/** + * VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX: + * + * The parameter name prefix to access each address entry. Concatenate the + * interface prefix, the interface entry number formatted as an unsigned + * integer, the address prefix, the address entry number formatted as an + * unsigned integer and one of the address suffix parameters to form a + * complete parameter name. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX ".addr." + +/** + * VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_TYPE: + * + * The IP address type (e.g. ipv4) as a string. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_TYPE ".type" + +/** + * VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_ADDR: + * + * The IP address as a string. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_ADDR ".addr" + +/** + * VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_PREFIX: + * + * The prefix of IP address as an unsigned int. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_PREFIX ".prefix" + /** * virDomainGuestInfoTypes: * diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 87ea7a28ad..4e91e7bd20 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -13233,16 +13233,9 @@ virDomainSetVcpu(virDomainPtr domain, * keys. * * VIR_DOMAIN_GUEST_INFO_INTERFACES: - * Returns information about the interfaces within the domain. The typed - * parameter keys are in this format: - * - * "if.count" - the number of interfaces defined on this domain - * "if..name" - name in the guest (e.g. ``eth0``) for interface = - * "if..hwaddr" - hardware address in the guest for interface - * "if..addr.count - the number of IP addresses of interface - * "if..addr..type" - the IP address type of addr (= e.g. ipv4) - * "if..addr..addr" - the IP address of addr - * "if..addr..prefix" - the prefix of IP address of addr <= num1> + * Returns information about the interfaces within the domain. + * The VIR_DOMAIN_GUEST_INFO_IF_* constants define the known typed parame= ter + * keys. * * VIR_DOMAIN_GUEST_INFO_LOAD: * Returns load (the number of processes in the runqueue or waiting for d= isk diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8f7e232abd..248787784e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -19325,30 +19325,35 @@ virDomainInterfaceFormatParams(virDomainInterface= Ptr *ifaces, { size_t i; =20 - virTypedParamListAddUInt(list, nifaces, "if.count"); + virTypedParamListAddUInt(list, nifaces, VIR_DOMAIN_GUEST_INFO_IF_COUNT= ); =20 for (i =3D 0; i < nifaces; i++) { size_t j; =20 - virTypedParamListAddString(list, ifaces[i]->name, "if.%zu.name", i= ); - virTypedParamListAddString(list, ifaces[i]->hwaddr, "if.%zu.hwaddr= ", i); - virTypedParamListAddUInt(list, ifaces[i]->naddrs, "if.%zu.addr.cou= nt", i); + virTypedParamListAddString(list, ifaces[i]->name, + VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%zu" V= IR_DOMAIN_GUEST_INFO_IF_SUFFIX_NAME, i); + virTypedParamListAddString(list, ifaces[i]->hwaddr, + VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%zu" V= IR_DOMAIN_GUEST_INFO_IF_SUFFIX_HWADDR, i); + virTypedParamListAddUInt(list, ifaces[i]->naddrs, + VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%zu" VIR= _DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_COUNT, i); =20 for (j =3D 0; j < ifaces[i]->naddrs; j++) { switch (ifaces[i]->addrs[j].type) { case VIR_IP_ADDR_TYPE_IPV4: - virTypedParamListAddString(list, "ipv4", "if.%zu.addr.= %zu.type", i, j); + virTypedParamListAddString(list, "ipv4", + VIR_DOMAIN_GUEST_INFO_IF_PR= EFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX "%zu" VIR_DOMAIN_GUE= ST_INFO_IF_SUFFIX_ADDR_SUFFIX_TYPE, i, j); break; =20 case VIR_IP_ADDR_TYPE_IPV6: - virTypedParamListAddString(list, "ipv6", "if.%zu.addr.= %zu.type", i, j); + virTypedParamListAddString(list, "ipv6", + VIR_DOMAIN_GUEST_INFO_IF_PR= EFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX "%zu" VIR_DOMAIN_GUE= ST_INFO_IF_SUFFIX_ADDR_SUFFIX_TYPE, i, j); break; } =20 virTypedParamListAddString(list, ifaces[i]->addrs[j].addr, - "if.%zu.addr.%zu.addr", i, j); + VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%z= u" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_= IF_SUFFIX_ADDR_SUFFIX_ADDR, i, j); virTypedParamListAddUInt(list, ifaces[i]->addrs[j].prefix, - "if.%zu.addr.%zu.prefix", i, j); + VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%zu"= VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF= _SUFFIX_ADDR_SUFFIX_PREFIX, i, j); } } } --=20 2.48.1