From d804d35facb7462bd462e936dc9aa1e0becf0933 Mon Sep 17 00:00:00 2001 From: Viktor Mihajlovski Date: Tue, 16 Oct 2012 16:05:11 +0200 Subject: [PATCH] virNodeGetCPUMap: Implement wire protocol. - Defined the wire protocol format for virNodeGetCPUMap and its arguments - Implemented remote method invocation (remoteNodeGetCPUMap) - Implemented method dispatcher (remoteDispatchNodeGetCPUMap) Signed-off-by: Viktor Mihajlovski Signed-off-by: Eric Blake --- daemon/remote.c | 47 +++++++++++++++++++++++++++++++++++ src/remote/remote_driver.c | 48 ++++++++++++++++++++++++++++++++++++ src/remote/remote_protocol.x | 14 ++++++++++- src/remote_protocol-structs | 13 ++++++++++ 4 files changed, 121 insertions(+), 1 deletion(-) diff --git a/daemon/remote.c b/daemon/remote.c index 2c43b6d86f..7a9df60d00 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -4569,6 +4569,53 @@ cleanup: return rv; } +static int +remoteDispatchNodeGetCPUMap(virNetServerPtr server ATTRIBUTE_UNUSED, + virNetServerClientPtr client ATTRIBUTE_UNUSED, + virNetMessagePtr msg ATTRIBUTE_UNUSED, + virNetMessageErrorPtr rerr, + remote_node_get_cpu_map_args *args, + remote_node_get_cpu_map_ret *ret) +{ + unsigned char *cpumap = NULL; + unsigned int online; + unsigned int flags; + int cpunum; + int rv = -1; + struct daemonClientPrivate *priv = + virNetServerClientGetPrivateData(client); + + if (!priv->conn) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open")); + goto cleanup; + } + + flags = args->flags; + + cpunum = virNodeGetCPUMap(priv->conn, args->need_results ? &cpumap : NULL, + &online, flags); + if (cpunum < 0) + goto cleanup; + + /* 'serialize' return cpumap */ + if (args->need_results) { + ret->cpumap.cpumap_len = VIR_CPU_MAPLEN(cpunum); + ret->cpumap.cpumap_val = (char *) cpumap; + cpumap = NULL; + } + + ret->online = online; + ret->ret = cpunum; + + rv = 0; + +cleanup: + if (rv < 0) + virNetMessageSaveError(rerr); + VIR_FREE(cpumap); + return rv; +} + /*----- Helpers. -----*/ /* get_nonnull_domain and get_nonnull_network turn an on-wire diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 3253de760b..71218f0c9b 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -5780,6 +5780,53 @@ done: return rv; } +static int +remoteNodeGetCPUMap(virConnectPtr conn, + unsigned char **cpumap, + unsigned int *online, + unsigned int flags) +{ + int rv = -1; + remote_node_get_cpu_map_args args; + remote_node_get_cpu_map_ret ret; + struct private_data *priv = conn->privateData; + + remoteDriverLock(priv); + + args.need_results = !!cpumap; + args.flags = flags; + + memset (&ret, 0, sizeof(ret)); + if (call(conn, priv, 0, REMOTE_PROC_NODE_GET_CPU_MAP, + (xdrproc_t) xdr_remote_node_get_cpu_map_args, + (char *) &args, + (xdrproc_t) xdr_remote_node_get_cpu_map_ret, + (char *) &ret) == -1) + goto done; + + if (ret.ret < 0) + goto cleanup; + + if (cpumap) { + if (VIR_ALLOC_N(*cpumap, ret.cpumap.cpumap_len) < 0) { + virReportOOMError(); + goto cleanup; + } + memcpy(*cpumap, ret.cpumap.cpumap_val, ret.cpumap.cpumap_len); + } + + if (online) + *online = ret.online; + + rv = ret.ret; + +cleanup: + xdr_free((xdrproc_t) xdr_remote_node_get_cpu_map_ret, (char *) &ret); +done: + remoteDriverUnlock(priv); + return rv; +} + static void remoteDomainEventQueue(struct private_data *priv, virDomainEventPtr event) { @@ -6094,6 +6141,7 @@ static virDriver remote_driver = { .domainGetHostname = remoteDomainGetHostname, /* 0.10.0 */ .nodeSetMemoryParameters = remoteNodeSetMemoryParameters, /* 0.10.2 */ .nodeGetMemoryParameters = remoteNodeGetMemoryParameters, /* 0.10.2 */ + .nodeGetCPUMap = remoteNodeGetCPUMap, /* 1.0.0 */ }; static virNetworkDriver network_driver = { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 4359c829e0..765ffcddfc 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2670,6 +2670,17 @@ struct remote_node_get_memory_parameters_ret { int nparams; }; +struct remote_node_get_cpu_map_args { + int need_results; + unsigned int flags; +}; + +struct remote_node_get_cpu_map_ret { + opaque cpumap; + unsigned int online; + int ret; +}; + /*----- Protocol. -----*/ /* Define the program number, protocol version and procedure numbers here. */ @@ -3013,7 +3024,8 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_BLOCK_COMMIT = 290, /* autogen autogen */ REMOTE_PROC_NETWORK_UPDATE = 291, /* autogen autogen priority:high */ - REMOTE_PROC_DOMAIN_EVENT_PMSUSPEND_DISK = 292 /* autogen autogen */ + REMOTE_PROC_DOMAIN_EVENT_PMSUSPEND_DISK = 292, /* autogen autogen */ + REMOTE_PROC_NODE_GET_CPU_MAP = 293 /* skipgen skipgen */ /* * Notice how the entries are grouped in sets of 10 ? diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 0c0a317815..567864a182 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -2126,6 +2126,18 @@ struct remote_node_get_memory_parameters_ret { } params; int nparams; }; +struct remote_node_get_cpu_map_args { + int need_results; + u_int flags; +}; +struct remote_node_get_cpu_map_ret { + struct { + u_int cpumap_len; + char * cpumap_val; + } cpumap; + u_int online; + int ret; +}; enum remote_procedure { REMOTE_PROC_OPEN = 1, REMOTE_PROC_CLOSE = 2, @@ -2419,4 +2431,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_BLOCK_COMMIT = 290, REMOTE_PROC_NETWORK_UPDATE = 291, REMOTE_PROC_DOMAIN_EVENT_PMSUSPEND_DISK = 292, + REMOTE_PROC_NODE_GET_CPU_MAP = 293, };