From e7a122a192ef5e2e7c1a5695a617bd1fabe79522 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Thu, 27 Feb 2025 13:42:08 +0000 Subject: [PATCH] src: add constants for guest info 'timezone.' parameters MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. Reviewed-by: Peter Krempa Signed-off-by: Daniel P. Berrangé --- include/libvirt/libvirt-domain.h | 19 +++++++++++++++++++ src/libvirt-domain.c | 8 +++----- src/qemu/qemu_agent.c | 4 ++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index d4d67e6c38..e3a4ab944c 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -6601,6 +6601,25 @@ int virDomainSetLaunchSecurityState(virDomainPtr domain, */ # define VIR_DOMAIN_GUEST_INFO_OS_VARIANT_ID "os.variant-id" + +/** + * VIR_DOMAIN_GUEST_INFO_TIMEZONE_NAME: + * + * The name of the timezone as a string. + * + * Since: 11.2.0 + */ +# define VIR_DOMAIN_GUEST_INFO_TIMEZONE_NAME "timezone.name" + +/** + * VIR_DOMAIN_GUEST_INFO_TIMEZONE_OFFSET: + * + * The offset to UTC in seconds as an int. + * + * Since: 11.2.0 + */ +# define VIR_DOMAIN_GUEST_INFO_TIMEZONE_OFFSET "timezone.offset" + /** * virDomainGuestInfoTypes: * diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index bbc6cfef9e..9c858622c2 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -13213,11 +13213,9 @@ virDomainSetVcpu(virDomainPtr domain, * keys. * * VIR_DOMAIN_GUEST_INFO_TIMEZONE: - * Returns information about the timezone within the domain. The typed - * parameter keys are in this format: - * - * "timezone.name" - the name of the timezone as a string - * "timezone.offset" - the offset to UTC in seconds as an int + * Returns information about the timezone within the domain. + * The VIR_DOMAIN_GUEST_INFO_TIMEZONE_* constants define the known typed parameter + * keys. * * VIR_DOMAIN_GUEST_INFO_FILESYSTEM: * Returns information about the filesystems within the domain. The typed diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 40cfe4fe3a..6f5aab5bf2 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2316,7 +2316,7 @@ qemuAgentGetTimezone(qemuAgent *agent, } if ((name = virJSONValueObjectGetString(data, "zone"))) - virTypedParamListAddString(list, name, "timezone.name"); + virTypedParamListAddString(list, name, VIR_DOMAIN_GUEST_INFO_TIMEZONE_NAME); if ((virJSONValueObjectGetNumberInt(data, "offset", &offset)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -2324,7 +2324,7 @@ qemuAgentGetTimezone(qemuAgent *agent, return -1; } - virTypedParamListAddInt(list, offset, "timezone.offset"); + virTypedParamListAddInt(list, offset, VIR_DOMAIN_GUEST_INFO_TIMEZONE_OFFSET); return 0; } -- 2.47.3