[libvirt PATCH 3/9] remote: Add RPC support for the virConnectGetHypervisorCPUModelNames API
Daniel P. Berrangé
berrange at redhat.com
Mon Jul 18 10:18:22 UTC 2022
On Tue, Jun 28, 2022 at 06:09:40PM +0200, Tim Wiederhake wrote:
> Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
> ---
> src/remote/remote_daemon_dispatch.c | 44 +++++++++++++++++++++
> src/remote/remote_driver.c | 59 +++++++++++++++++++++++++++++
> src/remote/remote_protocol.x | 19 +++++++++-
> src/remote_protocol-structs | 16 ++++++++
> 4 files changed, 137 insertions(+), 1 deletion(-)
>
> diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
> index dc5790f077..9011977e18 100644
> --- a/src/remote/remote_daemon_dispatch.c
> +++ b/src/remote/remote_daemon_dispatch.c
> @@ -5869,6 +5869,50 @@ remoteDispatchConnectGetCPUModelNames(virNetServer *server G_GNUC_UNUSED,
> }
>
>
> +static int
> +remoteDispatchConnectGetHypervisorCPUModelNames(virNetServer *server G_GNUC_UNUSED,
> + virNetServerClient *client,
> + virNetMessage *msg G_GNUC_UNUSED,
> + struct virNetMessageError *rerr,
> + remote_connect_get_hypervisor_cpu_model_names_args *args,
> + remote_connect_get_hypervisor_cpu_model_names_ret *ret)
> +{
> + int len = 0;
> + int rv = -1;
> + g_auto(GStrv) names = NULL;
> + g_auto(GStrv) aliases = NULL;
> + virConnectPtr conn = remoteGetHypervisorConn(client);
> +
> + if (!conn)
> + goto cleanup;
> +
> + len = virConnectGetHypervisorCPUModelNames(conn, args->arch, &names,
> + &aliases, args->flags);
> + if (len < 0)
> + goto cleanup;
> +
> + if (len > REMOTE_CONNECT_CPU_MODELS_MAX) {
> + virReportError(VIR_ERR_RPC,
> + _("Too many CPU models '%d' for limit '%d'"),
> + len, REMOTE_CONNECT_CPU_MODELS_MAX);
> + goto cleanup;
> + }
> +
> + ret->names.names_val = g_steal_pointer(&names);
> + ret->names.names_len = len;
> + ret->aliases.aliases_val = g_steal_pointer(&aliases);
> + ret->aliases.aliases_len = len;
> + ret->ret = len;
'ret->ret' is not required, since both 'names' and 'aliases' already
encode the length on the wire.
> +
> + rv = 0;
> +
> + cleanup:
> + if (rv < 0)
> + virNetMessageSaveError(rerr);
> + return rv;
> +}
> +
> +
> static int
> remoteDispatchDomainCreateXMLWithFiles(virNetServer *server G_GNUC_UNUSED,
> virNetServerClient *client,
> +static int
> +remoteConnectGetHypervisorCPUModelNames(virConnectPtr conn,
> + const char *archName,
> + char ***names,
> + char ***aliases,
> + unsigned int flags)
> +{
> + int rv = -1;
> + size_t i;
> + remote_connect_get_hypervisor_cpu_model_names_args args;
> + remote_connect_get_hypervisor_cpu_model_names_ret ret;
> +
> + struct private_data *priv = conn->privateData;
> +
> + remoteDriverLock(priv);
> +
> + args.arch = (char *) archName;
> + args.flags = flags;
> +
> + memset(&ret, 0, sizeof(ret));
> + if (call(conn, priv, 0, REMOTE_PROC_CONNECT_GET_HYPERVISOR_CPU_MODEL_NAMES,
> + (xdrproc_t) xdr_remote_connect_get_hypervisor_cpu_model_names_args,
> + (char *) &args,
> + (xdrproc_t) xdr_remote_connect_get_hypervisor_cpu_model_names_ret,
> + (char *) &ret) < 0)
> + goto done;
> +
> + /* Check the length of the returned list carefully. */
> + if (ret.names.names_len > REMOTE_CONNECT_CPU_MODELS_MAX) {
> + virReportError(VIR_ERR_RPC,
> + _("Too many model names '%d' for limit '%d'"),
> + ret.names.names_len,
> + REMOTE_CONNECT_CPU_MODELS_MAX);
> + goto cleanup;
> + }
Also validate ret.names.names_len == ret.aliases.aliases_len
> +
> + *names = g_new0(char *, ret.names.names_len + 1);
> + for (i = 0; i < ret.names.names_len; i++) {
> + (*names)[i] = g_steal_pointer(&ret.names.names_val[i]);
> + }
> +
> + *aliases = g_new0(char *, ret.aliases.aliases_len + 1);
> + for (i = 0; i < ret.aliases.aliases_len; i++) {
> + (*aliases)[i] = g_steal_pointer(&ret.aliases.aliases_val[i]);
> + }
> +
> + rv = ret.ret;
> +
> + cleanup:
> + xdr_free((xdrproc_t) xdr_remote_connect_get_hypervisor_cpu_model_names_ret,
> + (char *) &ret);
> +
> + done:
> + remoteDriverUnlock(priv);
> + return rv;
> +}
> +
> diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
> index 79ffc63f03..a5c60399c7 100644
> --- a/src/remote/remote_protocol.x
> +++ b/src/remote/remote_protocol.x
> @@ -3303,6 +3303,17 @@ struct remote_connect_get_cpu_model_names_ret {
> int ret;
> };
>
> +struct remote_connect_get_hypervisor_cpu_model_names_args {
> + remote_nonnull_string arch;
> + unsigned int flags;
> +};
> +
> +struct remote_connect_get_hypervisor_cpu_model_names_ret {
> + remote_nonnull_string names<REMOTE_CONNECT_CPU_MODELS_MAX>;
> + remote_nonnull_string aliases<REMOTE_CONNECT_CPU_MODELS_MAX>;
I'd expect 'remote_string', since aliases should be able to be NULL
> + int ret;
Drop 'ret'
> +};
> +
With 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