1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-20 06:50:22 +03:00

src: add constants for domain stats 'state.' parameters

Contrary to most APIs returning typed parameters, there are no constants
defined for the domain stats 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 domain stats
API keys.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2025-02-27 13:42:08 +00:00
parent 8927d4eedc
commit df0513fa36
3 changed files with 27 additions and 8 deletions

View File

@ -2795,6 +2795,26 @@ struct _virDomainStatsRecord {
int nparams;
};
/**
* VIR_DOMAIN_STATS_STATE_STATE:
*
* State of the VM, returned as int from virDomainState enum.
*
* Since: 11.2.0
*/
# define VIR_DOMAIN_STATS_STATE_STATE "state.state"
/**
* VIR_DOMAIN_STATS_STATE_REASON:
*
* Reason for entering given state, returned as int from virDomain*Reason
* enum corresponding to given state.
*
* Since: 11.2.0
*/
# define VIR_DOMAIN_STATS_STATE_REASON "state.reason"
/**
* virDomainStatsTypes:
*

View File

@ -12240,12 +12240,9 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
* (although not necessarily implemented for each hypervisor):
*
* VIR_DOMAIN_STATS_STATE:
* Return domain state and reason for entering that state. The typed
* parameter keys are in this format:
*
* "state.state" - state of the VM, returned as int from virDomainState enum
* "state.reason" - reason for entering given state, returned as int from
* virDomain*Reason enum corresponding to given state.
* Return domain state and reason for entering that state.
* The VIR_DOMAIN_STATS_STATE_* constants define the known typed
* parameter keys.
*
* VIR_DOMAIN_STATS_CPU_TOTAL:
* Return CPU statistics and usage information. The typed parameter keys

View File

@ -16554,8 +16554,10 @@ qemuDomainGetStatsState(virQEMUDriver *driver G_GNUC_UNUSED,
virTypedParamList *params,
unsigned int privflags G_GNUC_UNUSED)
{
virTypedParamListAddInt(params, dom->state.state, "state.state");
virTypedParamListAddInt(params, dom->state.reason, "state.reason");
virTypedParamListAddInt(params, dom->state.state,
VIR_DOMAIN_STATS_STATE_STATE);
virTypedParamListAddInt(params, dom->state.reason,
VIR_DOMAIN_STATS_STATE_REASON);
}