On Sat, Sep 07, 2013 at 01:11:23AM +0200, Giuseppe Scrivano wrote: > Signed-off-by: Giuseppe Scrivano <gscrivan@xxxxxxxxxx> > --- > daemon/remote.c | 47 +++++++++++++++++++++++++++++++++++ > src/remote/remote_driver.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ > src/remote/remote_protocol.x | 20 ++++++++++++++- > src/remote_protocol-structs | 11 +++++++++ > 4 files changed, 136 insertions(+), 1 deletion(-) > > diff --git a/daemon/remote.c b/daemon/remote.c > index 2aff7c1..4846ccb 100644 > --- a/daemon/remote.c > +++ b/daemon/remote.c > @@ -5037,6 +5037,53 @@ cleanup: > > > static int > +remoteDispatchConnectGetCPUModelNames(virNetServerPtr server ATTRIBUTE_UNUSED, > + virNetServerClientPtr client ATTRIBUTE_UNUSED, > + virNetMessagePtr msg ATTRIBUTE_UNUSED, > + virNetMessageErrorPtr rerr, > + remote_connect_get_cpu_model_names_args *args, > + remote_connect_get_cpu_model_names_ret *ret) > +{ > + int rv = -1; > + char **models; > + struct daemonClientPrivate *priv = > + virNetServerClientGetPrivateData(client); > + > + if (!priv->conn) { > + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open")); > + goto cleanup; > + } > + > + if (virConnectGetCPUModelNames(priv->conn, args->arch, &models, > + args->flags) < 0) > + goto cleanup; > + > + ret->models.models_val = models; > + ret->models.models_len = 0; > + while (*models++) > + ret->models.models_len++; You can avoid this if you make the API return value indicate the number of models. > + > + if (ret->models.models_len > REMOTE_CONNECT_CPU_MODELS_MAX) { > + virReportError(VIR_ERR_RPC, > + _("Too many CPU models '%d' for limit '%d'"), > + ret->models.models_len, REMOTE_CONNECT_CPU_MODELS_MAX); > + > + for (models = ret->models.models_val; *models; models++) > + VIR_FREE(*models); > + VIR_FREE(ret->models.models_val); virStringFeeList(models) > + goto cleanup; > + } > + > + rv = 0; > + > +cleanup: > + if (rv < 0) > + virNetMessageSaveError(rerr); > + return rv; > +} > + > + > +static int > remoteDispatchDomainCreateXMLWithFiles(virNetServerPtr server ATTRIBUTE_UNUSED, > virNetServerClientPtr client, > virNetMessagePtr msg ATTRIBUTE_UNUSED, > diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c > index 62e77a5..1b6635f 100644 > --- a/src/remote/remote_driver.c > +++ b/src/remote/remote_driver.c > @@ -5541,6 +5541,64 @@ done: > > > static int > +remoteConnectGetCPUModelNames(virConnectPtr conn, > + const char *arch, > + char ***models, > + unsigned int flags) > +{ > + int rv = -1; > + size_t i; > + char **retmodels; > + remote_connect_get_cpu_model_names_args args; > + remote_connect_get_cpu_model_names_ret ret; > + struct private_data *priv = conn->privateData; > + remoteDriverLock(priv); > + > + memset(&args, 0, sizeof(args)); > + memset(&ret, 0, sizeof(ret)); > + > + args.arch = (char *) arch; > + args.flags = flags; > + > + if (call(conn, priv, 0, REMOTE_PROC_CONNECT_GET_CPU_MODEL_NAMES, > + (xdrproc_t) xdr_remote_connect_get_cpu_model_names_args, > + (char *) &args, > + (xdrproc_t) xdr_remote_connect_get_cpu_model_names_ret, > + (char *) &ret) < 0) > + goto error; > + > + /* Check the length of the returned list carefully. */ > + if (ret.models.models_len > REMOTE_CONNECT_CPU_MODELS_MAX) { > + virReportError(VIR_ERR_RPC, "%s", > + _("remoteConnectGetCPUModelNames: " > + "returned number of CPU models exceeds limit")); > + goto error; > + } > + > + if (VIR_ALLOC_N(retmodels, ret.models.models_len + 1) < 0) > + goto error; > + > + for (i = 0; i < ret.models.models_len; i++) > + retmodels[i] = ret.models.models_val[i]; > + > + /* Caller frees MODELS. */ > + *models = retmodels; > + rv = 0; > + > +done: > + remoteDriverUnlock(priv); > + return rv; > + > +error: > + rv = -1; > + for (i = 0; i < ret.models.models_len; i++) > + VIR_FREE(ret.models.models_val[i]); > + VIR_FREE(ret.models.models_val); Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list