virConnectGetCPUModelNames: implement the remote protocol

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2013-09-23 11:46:00 +02:00 committed by Eric Blake
parent 36cc09420a
commit fd69544965
4 changed files with 149 additions and 1 deletions

View File

@ -5055,6 +5055,58 @@ 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 len, rv = -1;
char **models = NULL;
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
if (!priv->conn) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
goto cleanup;
}
len = virConnectGetCPUModelNames(priv->conn, args->arch,
args->need_results ? &models : NULL,
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;
}
if (len && models) {
ret->models.models_val = models;
ret->models.models_len = len;
models = NULL;
} else {
ret->models.models_val = NULL;
ret->models.models_len = 0;
}
ret->ret = len;
rv = 0;
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
virStringFreeList(models);
return rv;
}
static int
remoteDispatchDomainCreateXMLWithFiles(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetServerClientPtr client,

View File

@ -5540,6 +5540,68 @@ done:
}
static int
remoteConnectGetCPUModelNames(virConnectPtr conn,
const char *arch,
char ***models,
unsigned int flags)
{
int rv = -1;
size_t i;
char **retmodels = NULL;
remote_connect_get_cpu_model_names_args args;
remote_connect_get_cpu_model_names_ret ret;
struct private_data *priv = conn->privateData;
remoteDriverLock(priv);
args.arch = (char *) arch;
args.need_results = !!models;
args.flags = flags;
memset(&ret, 0, sizeof(ret));
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 done;
/* Check the length of the returned list carefully. */
if (ret.models.models_len > REMOTE_CONNECT_CPU_MODELS_MAX) {
virReportError(VIR_ERR_RPC,
_("Too many model names '%d' for limit '%d'"),
ret.models.models_len,
REMOTE_CONNECT_CPU_MODELS_MAX);
goto cleanup;
}
if (models) {
if (VIR_ALLOC_N(retmodels, ret.models.models_len + 1) < 0)
goto cleanup;
for (i = 0; i < ret.models.models_len; i++) {
retmodels[i] = ret.models.models_val[i];
ret.models.models_val[i] = NULL;
}
*models = retmodels;
retmodels = NULL;
}
rv = ret.ret;
cleanup:
virStringFreeList(retmodels);
xdr_free((xdrproc_t) xdr_remote_connect_get_cpu_model_names_ret, (char *) &ret);
done:
remoteDriverUnlock(priv);
return rv;
}
static int
remoteDomainOpenGraphics(virDomainPtr dom,
unsigned int idx,
@ -6933,6 +6995,7 @@ static virDriver remote_driver = {
.domainMigratePerform3Params = remoteDomainMigratePerform3Params, /* 1.1.0 */
.domainMigrateFinish3Params = remoteDomainMigrateFinish3Params, /* 1.1.0 */
.domainMigrateConfirm3Params = remoteDomainMigrateConfirm3Params, /* 1.1.0 */
.connectGetCPUModelNames = remoteConnectGetCPUModelNames, /* 1.1.3 */
};
static virNetworkDriver network_driver = {

View File

@ -232,6 +232,9 @@ const REMOTE_DOMAIN_MIGRATE_PARAM_LIST_MAX = 64;
/* Upper limit on number of job stats */
const REMOTE_DOMAIN_JOB_STATS_MAX = 16;
/* Upper limit on number of CPU models */
const REMOTE_CONNECT_CPU_MODELS_MAX = 8192;
/* UUID. VIR_UUID_BUFLEN definition comes from libvirt.h */
typedef opaque remote_uuid[VIR_UUID_BUFLEN];
@ -2835,6 +2838,17 @@ struct remote_domain_event_device_removed_msg {
remote_nonnull_string devAlias;
};
struct remote_connect_get_cpu_model_names_args {
remote_nonnull_string arch;
int need_results;
unsigned int flags;
};
struct remote_connect_get_cpu_model_names_ret {
remote_nonnull_string models<REMOTE_CONNECT_CPU_MODELS_MAX>;
int ret;
};
/*----- Protocol. -----*/
/* Define the program number, protocol version and procedure numbers here. */
@ -4998,5 +5012,11 @@ enum remote_procedure {
* @generate: both
* @acl: none
*/
REMOTE_PROC_DOMAIN_EVENT_DEVICE_REMOVED = 311
REMOTE_PROC_DOMAIN_EVENT_DEVICE_REMOVED = 311,
/**
* @generate: none
* @acl: connect:read
*/
REMOTE_PROC_CONNECT_GET_CPU_MODEL_NAMES = 312
};

View File

@ -2316,6 +2316,18 @@ struct remote_domain_event_device_removed_msg {
remote_nonnull_domain dom;
remote_nonnull_string devAlias;
};
struct remote_connect_get_cpu_model_names_args {
remote_nonnull_string arch;
int need_results;
u_int flags;
};
struct remote_connect_get_cpu_model_names_ret {
struct {
u_int models_len;
remote_nonnull_string * models_val;
} models;
int ret;
};
enum remote_procedure {
REMOTE_PROC_CONNECT_OPEN = 1,
REMOTE_PROC_CONNECT_CLOSE = 2,
@ -2628,4 +2640,5 @@ enum remote_procedure {
REMOTE_PROC_DOMAIN_CREATE_XML_WITH_FILES = 309,
REMOTE_PROC_DOMAIN_CREATE_WITH_FILES = 310,
REMOTE_PROC_DOMAIN_EVENT_DEVICE_REMOVED = 311,
REMOTE_PROC_CONNECT_GET_CPU_MODEL_NAMES = 312,
};