On Mon, May 16, 2011 at 11:37:34AM +0900, Minoru Usui wrote:
virNodeGetCPUTimeParameters: Implement remote protocol
Signed-off-by: Minoru Usui <usui(a)mxm.nes.nec.co.jp>
---
daemon/remote.c | 81 ++++++++++++++++++++++++++++++++++++++++++
src/remote/remote_driver.c | 64 +++++++++++++++++++++++++++++++++
src/remote/remote_protocol.x | 21 ++++++++++-
3 files changed, 165 insertions(+), 1 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index 6e13958..f7b84d9 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -1749,6 +1749,87 @@ cleanup:
return rv;
}
+static int
+remoteDispatchNodeGetCPUTimeParameters (struct qemud_server *server
+ ATTRIBUTE_UNUSED,
+ struct qemud_client *client
+ ATTRIBUTE_UNUSED,
+ virConnectPtr conn,
+ remote_message_header *
+ hdr ATTRIBUTE_UNUSED,
+ remote_error *rerr,
+ remote_node_get_cpu_time_parameters_args *
+ args,
+ remote_node_get_cpu_time_parameters_ret *
+ ret)
This is horribly whitespace mangled. Please put the variable names + annotations
on the same line as the corresponding data types.
+{
+ virCPUTimeParameterPtr params = NULL;
+ int i;
+ int nparams = args->nparams;
+ unsigned int flags;
+ int rv = -1;
+
+ if (!conn) {
+ virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not
open"));
+ goto cleanup;
+ }
+
+ flags = args->flags;
+
+ if (nparams > REMOTE_NODE_CPU_TIME_PARAMETERS_MAX) {
+ virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too
large"));
+ goto cleanup;
+ }
+ if (VIR_ALLOC_N(params, nparams) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ if (virNodeGetCPUTimeParameters(conn, params, &nparams, flags) < 0)
+ goto cleanup;
+
+ /* In this case, we need to send back the number of parameters
+ * supported
+ */
+ if (args->nparams == 0) {
+ ret->nparams = nparams;
+ goto success;
+ }
+
+ /* Serialise the memory parameters. */
+ ret->params.params_len = nparams;
+ if (VIR_ALLOC_N(ret->params.params_val, nparams) < 0)
+ goto no_memory;
+
+ for (i = 0; i < nparams; ++i) {
+ /* remoteDispatchClientRequest will free this: */
+ ret->params.params_val[i].field = strdup(params[i].field);
+ if (ret->params.params_val[i].field == NULL)
+ goto no_memory;
+
+ ret->params.params_val[i].value = params[i].value;
+ }
+
+success:
+ rv = 0;
+
+cleanup:
+ if (rv < 0) {
+ remoteDispatchError(rerr);
+ if (ret->params.params_val) {
+ for (i = 0; i < nparams; i++)
+ VIR_FREE(ret->params.params_val[i].field);
+ VIR_FREE(ret->params.params_val);
+ }
+ }
+ VIR_FREE(params);
+ return rv;
+
+no_memory:
+ virReportOOMError();
+ goto cleanup;
+}
+
/*-------------------------------------------------------------*/
static int
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index f61afdc..46130ac 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1724,6 +1724,70 @@ done:
}
static int
+remoteNodeGetCPUTimeParameters (virConnectPtr conn,
+ virCPUTimeParameterPtr params, int *nparams,
+ unsigned int flags)
+{
+ int rv = -1;
+ remote_node_get_cpu_time_parameters_args args;
+ remote_node_get_cpu_time_parameters_ret ret;
+ int i = -1;
+ struct private_data *priv = conn->privateData;
+
+ remoteDriverLock(priv);
+
+ args.nparams = *nparams;
+ args.flags = flags;
+
+ memset (&ret, 0, sizeof ret);
+ if (call (conn, priv, 0, REMOTE_PROC_NODE_GET_CPU_TIME_PARAMETERS,
+ (xdrproc_t) xdr_remote_node_get_cpu_time_parameters_args,
+ (char *) &args,
+ (xdrproc_t) xdr_remote_node_get_cpu_time_parameters_ret,
+ (char *) &ret) == -1)
+ goto done;
+
+ /* Check the length of the returned list carefully. */
+ if (ret.params.params_len > REMOTE_NODE_CPU_TIME_PARAMETERS_MAX ||
+ ret.params.params_len > *nparams) {
+ remoteError(VIR_ERR_RPC, "%s",
+ _("remoteNodeGetCPUTimeParameters: "
+ "returned number of parameters exceeds limit"));
+ goto cleanup;
+ }
+ /* Handle the case when the caller does not know the number of parameters
+ * and is asking for the number of parameters supported
+ */
+ if (*nparams == 0) {
+ *nparams = ret.nparams;
+ rv = 0;
+ goto cleanup;
+ }
+
+ *nparams = ret.params.params_len;
+
+ /* Deserialise the result. */
+ for (i = 0; i < *nparams; ++i) {
+ if (virStrcpyStatic(params[i].field, ret.params.params_val[i].field) == NULL) {
+ remoteError(VIR_ERR_INTERNAL_ERROR,
+ _("Parameter %s too big for destination"),
+ ret.params.params_val[i].field);
+ goto cleanup;
+ }
+ params[i].value = ret.params.params_val[i].value;
+ }
+
+ rv = 0;
+
+cleanup:
+ xdr_free ((xdrproc_t) xdr_remote_node_get_cpu_time_parameters_ret,
+ (char *) &ret);
+done:
+ remoteDriverUnlock(priv);
+ return rv;
+}
+
+static int
remoteNodeGetCellsFreeMemory(virConnectPtr conn,
unsigned long long *freeMems,
int startCell,
This file is missing a chunk to add the method to the virDriver
struct. With the new coding style you want:
.nodeGetCPUTimeParameters = remoteNodeGetCPUTimeParameters, /* 0.9.2 */
diff --git a/src/remote/remote_protocol.x
b/src/remote/remote_protocol.x
index e115f39..587a1db 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -134,6 +134,9 @@ const REMOTE_DOMAIN_BLKIO_PARAMETERS_MAX = 16;
/* Upper limit on list of memory parameters. */
const REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX = 16;
+/* Upper limit on list of cpu time stats. */
+const REMOTE_NODE_CPU_TIME_PARAMETERS_MAX = 16;
+
/* Upper limit on number of NUMA cells */
const REMOTE_NODE_MAX_CELLS = 1024;
@@ -359,6 +362,11 @@ struct remote_memory_param {
remote_memory_param_value value;
};
+struct remote_node_get_cpu_time_param {
+ remote_nonnull_string field;
+ unsigned hyper value;
+};
+
/*----- Calls. -----*/
/* For each call we may have a 'remote_CALL_args' and 'remote_CALL_ret'
@@ -440,6 +448,16 @@ struct remote_get_capabilities_ret {
remote_nonnull_string capabilities;
};
+struct remote_node_get_cpu_time_parameters_args {
+ int nparams;
+ unsigned int flags;
+};
+
+struct remote_node_get_cpu_time_parameters_ret {
+ remote_node_get_cpu_time_param params<REMOTE_NODE_CPU_TIME_PARAMETERS_MAX>;
+ int nparams;
+};
+
struct remote_node_get_cells_free_memory_args {
int startCell;
int maxCells;
@@ -2196,8 +2214,9 @@ enum remote_procedure {
REMOTE_PROC_STORAGE_VOL_UPLOAD = 208, /* skipgen skipgen */
REMOTE_PROC_STORAGE_VOL_DOWNLOAD = 209, /* skipgen skipgen */
REMOTE_PROC_DOMAIN_INJECT_NMI = 210, /* autogen autogen */
+ REMOTE_PROC_DOMAIN_SCREENSHOT = 211, /* skipgen skipgen */
+ REMOTE_PROC_NODE_GET_CPU_TIME_PARAMETERS = 212 /* skipgen skipgen */
- REMOTE_PROC_DOMAIN_SCREENSHOT = 211 /* skipgen skipgen */
/*
* Notice how the entries are grouped in sets of 10 ?
* Nice isn't it. Please keep it this way when adding more.
This has messed up the grouping of entries in sets of 10.
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 :|