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é <berrange@xxxxxxxxxx> --- include/libvirt/libvirt-domain.h | 28 ++++++++++++++++++++++++++++ src/libvirt-domain.c | 8 +++----- src/qemu/qemu_driver.c | 6 +++--- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 38139ed8ec..d8161e148e 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -6943,6 +6943,34 @@ int virDomainSetLaunchSecurityState(virDomainPtr domain, */ #define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_PREFIX ".prefix" + +/** + * VIR_DOMAIN_GUEST_INFO_LOAD_1M: + * + * The guest load averaged over 1 minute as a double + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_LOAD_1M "load.1m" + +/** + * VIR_DOMAIN_GUEST_INFO_LOAD_5M: + * + * The guest load averaged over 5 minutes as a double + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_LOAD_5M "load.5m" + +/** + * VIR_DOMAIN_GUEST_INFO_LOAD_15M: + * + * The guest load averaged over 15 minutes as a double + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_GUEST_INFO_LOAD_15M "load.15m" + /** * virDomainGuestInfoTypes: * diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 4e91e7bd20..557efcc0c0 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -13239,11 +13239,9 @@ virDomainSetVcpu(virDomainPtr domain, * * VIR_DOMAIN_GUEST_INFO_LOAD: * Returns load (the number of processes in the runqueue or waiting for disk - * I/O) as double values: - * - * "load.1m" - load averaged over 1 minute - * "load.5m" - load averaged over 5 minutes - * "load.15m" - load averaged over 15 minutes + * I/O). + * The VIR_DOMAIN_GUEST_INFO_LOAD_* constants define the known typed parameter + * keys. * * Using 0 for @types returns all information groups supported by the given * hypervisor. diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 248787784e..bb12beb6da 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -19488,9 +19488,9 @@ qemuDomainGetGuestInfo(virDomainPtr dom, } if (format_load) { - virTypedParamListAddDouble(list, load1m, "load.1m"); - virTypedParamListAddDouble(list, load5m, "load.5m"); - virTypedParamListAddDouble(list, load15m, "load.15m"); + virTypedParamListAddDouble(list, load1m, VIR_DOMAIN_GUEST_INFO_LOAD_1M); + virTypedParamListAddDouble(list, load5m, VIR_DOMAIN_GUEST_INFO_LOAD_5M); + virTypedParamListAddDouble(list, load15m, VIR_DOMAIN_GUEST_INFO_LOAD_15M); } if (virTypedParamListSteal(list, params, nparams) < 0) -- 2.48.1