mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virNodeGetCPUStats: Implement remote protocol
Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp>
This commit is contained in:
parent
211c9f7b66
commit
daea15aa40
@ -1516,6 +1516,83 @@ cleanup:
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
remoteDispatchNodeGetCPUStats (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_stats_args *args,
|
||||||
|
remote_node_get_cpu_stats_ret *ret)
|
||||||
|
{
|
||||||
|
virCPUStatsPtr params = NULL;
|
||||||
|
int i;
|
||||||
|
int cpuNum = args->cpuNum;
|
||||||
|
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_STATS_MAX) {
|
||||||
|
virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (VIR_ALLOC_N(params, nparams) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virNodeGetCPUStats(conn, cpuNum, params, &nparams, flags) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
/* In this case, we need to send back the number of stats
|
||||||
|
* 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
|
static int
|
||||||
|
@ -1696,6 +1696,72 @@ done:
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
remoteNodeGetCPUStats (virConnectPtr conn,
|
||||||
|
int cpuNum,
|
||||||
|
virCPUStatsPtr params, int *nparams,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
int rv = -1;
|
||||||
|
remote_node_get_cpu_stats_args args;
|
||||||
|
remote_node_get_cpu_stats_ret ret;
|
||||||
|
int i = -1;
|
||||||
|
struct private_data *priv = conn->privateData;
|
||||||
|
|
||||||
|
remoteDriverLock(priv);
|
||||||
|
|
||||||
|
args.nparams = *nparams;
|
||||||
|
args.cpuNum = cpuNum;
|
||||||
|
args.flags = flags;
|
||||||
|
|
||||||
|
memset (&ret, 0, sizeof ret);
|
||||||
|
if (call (conn, priv, 0, REMOTE_PROC_NODE_GET_CPU_STATS,
|
||||||
|
(xdrproc_t) xdr_remote_node_get_cpu_stats_args,
|
||||||
|
(char *) &args,
|
||||||
|
(xdrproc_t) xdr_remote_node_get_cpu_stats_ret,
|
||||||
|
(char *) &ret) == -1)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
/* Check the length of the returned list carefully. */
|
||||||
|
if (ret.params.params_len > REMOTE_NODE_CPU_STATS_MAX ||
|
||||||
|
ret.params.params_len > *nparams) {
|
||||||
|
remoteError(VIR_ERR_RPC, "%s",
|
||||||
|
_("remoteNodeGetCPUStats: "
|
||||||
|
"returned number of stats exceeds limit"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
/* Handle the case when the caller does not know the number of stats
|
||||||
|
* and is asking for the number of stats 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,
|
||||||
|
_("Stats %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_stats_ret,
|
||||||
|
(char *) &ret);
|
||||||
|
done:
|
||||||
|
remoteDriverUnlock(priv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
remoteNodeGetCellsFreeMemory(virConnectPtr conn,
|
remoteNodeGetCellsFreeMemory(virConnectPtr conn,
|
||||||
unsigned long long *freeMems,
|
unsigned long long *freeMems,
|
||||||
@ -6294,6 +6360,7 @@ static virDriver remote_driver = {
|
|||||||
.domainBlockPeek = remoteDomainBlockPeek, /* 0.4.2 */
|
.domainBlockPeek = remoteDomainBlockPeek, /* 0.4.2 */
|
||||||
.domainMemoryPeek = remoteDomainMemoryPeek, /* 0.4.2 */
|
.domainMemoryPeek = remoteDomainMemoryPeek, /* 0.4.2 */
|
||||||
.domainGetBlockInfo = remoteDomainGetBlockInfo, /* 0.8.1 */
|
.domainGetBlockInfo = remoteDomainGetBlockInfo, /* 0.8.1 */
|
||||||
|
.nodeGetCPUStats = remoteNodeGetCPUStats, /* 0.9.3 */
|
||||||
.nodeGetCellsFreeMemory = remoteNodeGetCellsFreeMemory, /* 0.3.3 */
|
.nodeGetCellsFreeMemory = remoteNodeGetCellsFreeMemory, /* 0.3.3 */
|
||||||
.nodeGetFreeMemory = remoteNodeGetFreeMemory, /* 0.3.3 */
|
.nodeGetFreeMemory = remoteNodeGetFreeMemory, /* 0.3.3 */
|
||||||
.domainEventRegister = remoteDomainEventRegister, /* 0.5.0 */
|
.domainEventRegister = remoteDomainEventRegister, /* 0.5.0 */
|
||||||
|
@ -134,6 +134,9 @@ const REMOTE_DOMAIN_BLKIO_PARAMETERS_MAX = 16;
|
|||||||
/* Upper limit on list of memory parameters. */
|
/* Upper limit on list of memory parameters. */
|
||||||
const REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX = 16;
|
const REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX = 16;
|
||||||
|
|
||||||
|
/* Upper limit on list of node cpu stats. */
|
||||||
|
const REMOTE_NODE_CPU_STATS_MAX = 16;
|
||||||
|
|
||||||
/* Upper limit on number of NUMA cells */
|
/* Upper limit on number of NUMA cells */
|
||||||
const REMOTE_NODE_MAX_CELLS = 1024;
|
const REMOTE_NODE_MAX_CELLS = 1024;
|
||||||
|
|
||||||
@ -324,6 +327,11 @@ struct remote_typed_param {
|
|||||||
remote_typed_param_value value;
|
remote_typed_param_value value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct remote_node_get_cpu_stats {
|
||||||
|
remote_nonnull_string field;
|
||||||
|
unsigned hyper value;
|
||||||
|
};
|
||||||
|
|
||||||
/*----- Calls. -----*/
|
/*----- Calls. -----*/
|
||||||
|
|
||||||
/* For each call we may have a 'remote_CALL_args' and 'remote_CALL_ret'
|
/* For each call we may have a 'remote_CALL_args' and 'remote_CALL_ret'
|
||||||
@ -408,6 +416,17 @@ struct remote_get_capabilities_ret {
|
|||||||
remote_nonnull_string capabilities;
|
remote_nonnull_string capabilities;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct remote_node_get_cpu_stats_args {
|
||||||
|
int cpuNum;
|
||||||
|
int nparams;
|
||||||
|
unsigned int flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct remote_node_get_cpu_stats_ret {
|
||||||
|
remote_node_get_cpu_stats params<REMOTE_NODE_CPU_STATS_MAX>;
|
||||||
|
int nparams;
|
||||||
|
};
|
||||||
|
|
||||||
struct remote_node_get_cells_free_memory_args {
|
struct remote_node_get_cells_free_memory_args {
|
||||||
int startCell;
|
int startCell;
|
||||||
int maxcells;
|
int maxcells;
|
||||||
@ -2319,7 +2338,8 @@ enum remote_procedure {
|
|||||||
REMOTE_PROC_DOMAIN_GET_SCHEDULER_PARAMETERS_FLAGS = 223, /* skipgen autogen */
|
REMOTE_PROC_DOMAIN_GET_SCHEDULER_PARAMETERS_FLAGS = 223, /* skipgen autogen */
|
||||||
REMOTE_PROC_DOMAIN_EVENT_CONTROL_ERROR = 224, /* skipgen skipgen */
|
REMOTE_PROC_DOMAIN_EVENT_CONTROL_ERROR = 224, /* skipgen skipgen */
|
||||||
REMOTE_PROC_DOMAIN_PIN_VCPU_FLAGS = 225, /* skipgen autogen */
|
REMOTE_PROC_DOMAIN_PIN_VCPU_FLAGS = 225, /* skipgen autogen */
|
||||||
REMOTE_PROC_DOMAIN_SEND_KEY = 226 /* autogen autogen */
|
REMOTE_PROC_DOMAIN_SEND_KEY = 226, /* autogen autogen */
|
||||||
|
REMOTE_PROC_NODE_GET_CPU_STATS = 227 /* skipgen skipgen */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Notice how the entries are grouped in sets of 10 ?
|
* Notice how the entries are grouped in sets of 10 ?
|
||||||
|
@ -71,6 +71,10 @@ struct remote_typed_param {
|
|||||||
remote_nonnull_string field;
|
remote_nonnull_string field;
|
||||||
remote_typed_param_value value;
|
remote_typed_param_value value;
|
||||||
};
|
};
|
||||||
|
struct remote_node_get_cpu_stats {
|
||||||
|
remote_nonnull_string field;
|
||||||
|
uint64_t value;
|
||||||
|
};
|
||||||
struct remote_open_args {
|
struct remote_open_args {
|
||||||
remote_string name;
|
remote_string name;
|
||||||
int flags;
|
int flags;
|
||||||
@ -121,6 +125,18 @@ struct remote_node_get_info_ret {
|
|||||||
struct remote_get_capabilities_ret {
|
struct remote_get_capabilities_ret {
|
||||||
remote_nonnull_string capabilities;
|
remote_nonnull_string capabilities;
|
||||||
};
|
};
|
||||||
|
struct remote_node_get_cpu_stats_args {
|
||||||
|
int cpuNum;
|
||||||
|
int nparams;
|
||||||
|
u_int flags;
|
||||||
|
};
|
||||||
|
struct remote_node_get_cpu_stats_ret {
|
||||||
|
struct {
|
||||||
|
u_int params_len;
|
||||||
|
remote_node_get_cpu_stats * params_val;
|
||||||
|
} params;
|
||||||
|
int nparams;
|
||||||
|
};
|
||||||
struct remote_node_get_cells_free_memory_args {
|
struct remote_node_get_cells_free_memory_args {
|
||||||
int startCell;
|
int startCell;
|
||||||
int maxcells;
|
int maxcells;
|
||||||
|
Loading…
Reference in New Issue
Block a user