[libvirt] [PATCH v3 3/7] lib: introduce virDomainGetStateParams function
Daniel P. Berrangé
berrange at redhat.com
Thu Apr 4 10:41:31 UTC 2019
On Thu, Apr 04, 2019 at 10:01:30AM +0200, Bjoern Walk wrote:
> This API function extends the virDomainGetState function by returning
> additional state information as a dictionary of typed parameters.
>
> Reviewed-by: Boris Fiuczynski <fiuczy at linux.ibm.com>
> Signed-off-by: Bjoern Walk <bwalk at linux.ibm.com>
> ---
> include/libvirt/libvirt-domain.h | 76 ++++++++++++++++++++++++++++++++
> src/driver-hypervisor.h | 9 ++++
> src/libvirt-domain.c | 62 ++++++++++++++++++++++++++
> src/libvirt_public.syms | 5 +++
> 4 files changed, 152 insertions(+)
> +/**
> + * virDomainGetStateParams:
> + * @domain: a domain object
> + * @state: returned state of the domain (one of virDomainState)
> + * @reason: returned reason which led to @state (one of virDomain*Reason)
> + * @params: where to store additional state information, must be freed by
> + * the caller
> + * @nparams: number of items in @params
> + * @flags: bitwise-OR of virDomainGetStateFlags,
> + * not currently used yet, callers should always pass 0
> + *
> + * Extract domain state. Each state is accompanied by a reason (if known)
> + * and optional detailed information.
> + *
> + * Possible fields returned in @params are defined by VIR_DOMAIN_STATE_PARAMS_*
> + * macros and new fields will likely be introduced in the future so callers
> + * may receive fields that they do not understand in case they talk to a newer
> + * server. The caller is responsible to free allocated memory returned in
> + * @params by calling virTypedParamsFree.
> + *
> + * Returns 0 in case of success and -1 in case of failure.
> + */
> +int
> +virDomainGetStateParams(virDomainPtr domain,
> + int *state,
> + int *reason,
> + virTypedParameterPtr *params,
> + int *nparams,
> + unsigned int flags)
> +{
> + virConnectPtr conn = domain->conn;
> +
> + VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%p, flags=0x%x",
> + params, nparams, flags);
> +
> + virResetLastError();
> +
> + virCheckDomainReturn(domain, -1);
> + if (params)
> + virCheckNonNullArgGoto(nparams, error);
While I remember, we must forbid this for "read only" connections, as
some of the parameters are CPU registers which may hold sensitive data.
> +
> + if (VIR_DRV_SUPPORTS_FEATURE(conn->driver, conn,
> + VIR_DRV_FEATURE_TYPED_PARAM_STRING))
> + flags |= VIR_TYPED_PARAM_STRING_OKAY;
> +
> + if (conn->driver->domainGetStateParams) {
> + int ret;
> + ret = conn->driver->domainGetStateParams(domain, state, reason,
> + params, nparams, flags);
> + if (ret < 0)
> + goto error;
> + return ret;
> + }
> +
> + virReportUnsupportedError();
> +
> + error:
> + virDispatchError(domain->conn);
> + return -1;
> +}
> +
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
More information about the libvir-list
mailing list