[libvirt] [PATCH v2 4/7] remote: implement remoteDomainGetStateParams

Michal Privoznik mprivozn at redhat.com
Wed Mar 27 13:05:14 UTC 2019


On 3/25/19 9:04 AM, Bjoern Walk wrote:
> Implement the API function virDomainGetStateParams for the remote driver
> and wire up the remote protocol.
> 
> Reviewed-by: Boris Fiuczynski <fiuczy at linux.ibm.com>
> Signed-off-by: Bjoern Walk <bwalk at linux.ibm.com>
> ---
>   src/remote/remote_daemon_dispatch.c | 50 +++++++++++++++++++++++++++++
>   src/remote/remote_driver.c          | 44 +++++++++++++++++++++++++
>   src/remote/remote_protocol.x        | 22 ++++++++++++-
>   src/remote_protocol-structs         | 12 +++++++
>   4 files changed, 127 insertions(+), 1 deletion(-)
> 
> diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
> index df282590..e1e48559 100644
> --- a/src/remote/remote_daemon_dispatch.c
> +++ b/src/remote/remote_daemon_dispatch.c
> @@ -7392,3 +7392,53 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors,
>       }
>       return -1;
>   }
> +
> +static int
> +remoteDispatchDomainGetStateParams(virNetServerPtr server ATTRIBUTE_UNUSED,
> +                                   virNetServerClientPtr client,
> +                                   virNetMessagePtr msg ATTRIBUTE_UNUSED,
> +                                   virNetMessageErrorPtr rerr,
> +                                   remote_domain_get_state_params_args *args,
> +                                   remote_domain_get_state_params_ret *ret)
> +{
> +    virDomainPtr dom = NULL;
> +    virTypedParameterPtr params = NULL;
> +    int nparams = 0;
> +    int rv = -1;
> +    struct daemonClientPrivate *priv =
> +        virNetServerClientGetPrivateData(client);
> +
> +    if (!priv->conn) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
> +        goto cleanup;
> +    }
> +
> +    if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
> +        goto cleanup;
> +
> +    if (virDomainGetStateParams(dom, &ret->state, &ret->reason, &params,
> +                                &nparams, args->flags) < 0)
> +        goto cleanup;
> +
> +    if (nparams > REMOTE_DOMAIN_STATE_PARAMS_MAX) {
> +        virReportError(VIR_ERR_RPC,
> +                       _("Too many state information entries '%d' for limit '%d'"),
> +                       nparams, REMOTE_DOMAIN_STATE_PARAMS_MAX);
> +        goto cleanup;
> +    }
> +
> +    if (virTypedParamsSerialize(params, nparams,
> +                                (virTypedParameterRemotePtr *) &ret->params.params_val,
> +                                &ret->params.params_len,
> +                                VIR_TYPED_PARAM_STRING_OKAY) < 0)
> +        goto cleanup;
> +
> +    rv = 0;
> +
> + cleanup:
> +    if (rv < 0)
> +        virNetMessageSaveError(rerr);
> +    virTypedParamsFree(params, nparams);
> +    virObjectUnref(dom);
> +    return rv;
> +}
> diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
> index 5c4dd412..e0962014 100644
> --- a/src/remote/remote_driver.c
> +++ b/src/remote/remote_driver.c
> @@ -8131,6 +8131,49 @@ remoteStorageVolGetInfoFlags(virStorageVolPtr vol,
>       return rv;
>   }
>   
> +static int
> +remoteDomainGetStateParams(virDomainPtr domain,
> +                           int *state,
> +                           int *reason,
> +                           virTypedParameterPtr *params,
> +                           int *nparams,
> +                           unsigned int flags)
> +{
> +    int rv = -1;
> +    remote_domain_get_state_params_args args;
> +    remote_domain_get_state_params_ret ret;
> +    struct private_data *priv = domain->conn->privateData;
> +
> +    remoteDriverLock(priv);
> +
> +    make_nonnull_domain(&args.dom, domain);
> +    args.flags = flags;
> +
> +    memset(&ret, 0, sizeof(ret));
> +    if (call(domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_STATE_PARAMS,
> +             (xdrproc_t) xdr_remote_domain_get_state_params_args, (char *) &args,
> +             (xdrproc_t) xdr_remote_domain_get_state_params_ret, (char *) &ret) == -1)
> +        goto done;
> +
> +    *state = ret.state;
> +    *reason = ret.reason;

Neither @state nor @reason is required to be non-NULL. I mean, based on 
checks from 3/7 it's just fine to call virDomaingetStateParams(dom, 
NULL, NULL, ..);

> +
> +    if (virTypedParamsDeserialize((virTypedParameterRemotePtr) ret.params.params_val,
> +                                  ret.params.params_len,
> +                                  REMOTE_DOMAIN_STATE_PARAMS_MAX,
> +                                  params, nparams) < 0)
> +        goto cleanup;
> +
> +    rv = 0;
> +
> + cleanup:
> +    xdr_free((xdrproc_t) xdr_remote_domain_get_state_params_ret,
> +             (char *) &ret);
> + done:
> +    remoteDriverUnlock(priv);
> +    return rv;
> +}
> +
>   
>   /* get_nonnull_domain and get_nonnull_network turn an on-wire
>    * (name, uuid) pair into virDomainPtr or virNetworkPtr object.
> @@ -8326,6 +8369,7 @@ static virHypervisorDriver hypervisor_driver = {
>       .domainSetPerfEvents = remoteDomainSetPerfEvents, /* 1.3.3 */
>       .domainGetInfo = remoteDomainGetInfo, /* 0.3.0 */
>       .domainGetState = remoteDomainGetState, /* 0.9.2 */
> +    .domainGetStateParams = remoteDomainGetStateParams, /* TODO: 5.2.0 */

No need to mark it as TODO. It's okay to say these patches target 5.2.0.

>       .domainGetControlInfo = remoteDomainGetControlInfo, /* 0.9.3 */
>       .domainSave = remoteDomainSave, /* 0.3.0 */
>       .domainSaveFlags = remoteDomainSaveFlags, /* 0.9.4 */
> diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
> index 74be4b37..6db1ccc1 100644
> --- a/src/remote/remote_protocol.x
> +++ b/src/remote/remote_protocol.x
> @@ -263,6 +263,9 @@ const REMOTE_NODE_SEV_INFO_MAX = 64;
>   /* Upper limit on number of launch security information entries */
>   const REMOTE_DOMAIN_LAUNCH_SECURITY_INFO_PARAMS_MAX = 64;
>   
> +/* Upper limit on number of state information entries */
> +const REMOTE_DOMAIN_STATE_PARAMS_MAX = 16;
> +
>   /* UUID.  VIR_UUID_BUFLEN definition comes from libvirt.h */
>   typedef opaque remote_uuid[VIR_UUID_BUFLEN];
>   
> @@ -2789,6 +2792,17 @@ struct remote_domain_get_state_ret {
>       int reason;
>   };
>   
> +struct remote_domain_get_state_params_args {
> +    remote_nonnull_domain dom;
> +    unsigned int flags;
> +};
> +
> +struct remote_domain_get_state_params_ret {
> +    int state;
> +    int reason;
> +    remote_typed_param params<REMOTE_DOMAIN_STATE_PARAMS_MAX>;
> +};
> +
>   struct remote_domain_migrate_begin3_args {
>       remote_nonnull_domain dom;
>       remote_string xmlin;
> @@ -6342,5 +6356,11 @@ enum remote_procedure {
>        * @generate: both
>        * @acl: connect:read
>        */
> -    REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES = 403
> +    REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES = 403,
> +
> +    /**
> +     * @generate: none
> +     * @acl: domain:read
> +     */
> +    REMOTE_PROC_DOMAIN_GET_STATE_PARAMS = 404
>   };
> diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
> index 768189c5..670164de 100644
> --- a/src/remote_protocol-structs
> +++ b/src/remote_protocol-structs
> @@ -2162,6 +2162,18 @@ struct remote_domain_get_state_ret {
>           int                        state;
>           int                        reason;
>   };
> +struct remote_domain_get_state_params_args {
> +        remote_nonnull_domain      dom;
> +        u_int                      flags;
> +};
> +struct remote_domain_get_state_params_ret {
> +        int                        state;
> +        int                        reason;
> +        struct {
> +                u_int              params_len;
> +                remote_typed_param * params_val;
> +        } params;
> +};
>   struct remote_domain_migrate_begin3_args {
>           remote_nonnull_domain      dom;
>           remote_string              xmlin;
> 

This is missing REMOTE_PROC_DOMAIN_GET_STATE_PARAMS = 404, at EOF :-)

Michal




More information about the libvir-list mailing list