提交 0e96fa54 编写于 作者: O Osier Yang

node_memory: Expose the APIs to virsh

New command node-memory-tune to get/set the node memory parameters,
only two parameters are allowed to set (pages_to_scan, and sleep_millisecs,
see documents in this patch for more details).

Example of node-memory-tune's output:

Shared memory:
	pages_to_scan   100
	sleep_millisecs 20
	pages_shared    0
	pages_sharing   0
	pages_unshared  0
	pages_volatile  0
	full_scans      0
上级 8268a245
......@@ -37,6 +37,7 @@
#include "util.h"
#include "virsh-domain.h"
#include "xml.h"
#include "virtypedparam.h"
/*
* "capabilities" command
......@@ -884,12 +885,127 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
return true;
}
static const vshCmdInfo info_node_memory_tune[] = {
{"help", N_("Get or set node memory parameters")},
{"desc", N_("Get or set node memory parameters"
" To get the memory parameters, use following command: \n\n"
" virsh # node-memory-tune")},
{NULL, NULL}
};
static const vshCmdOptDef opts_node_memory_tune[] = {
{"shm-pages-to-scan", VSH_OT_INT, VSH_OFLAG_NONE,
N_("number of pages to scan before the shared memory service "
"goes to sleep")},
{"shm-sleep-millisecs", VSH_OT_INT, VSH_OFLAG_NONE,
N_("number of millisecs the shared memory service should "
"sleep before next scan")},
{NULL, 0, 0, NULL}
};
static bool
cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
{
virTypedParameterPtr params = NULL;
int nparams = 0;
unsigned int flags = 0;
unsigned int shm_pages_to_scan = 0;
unsigned int shm_sleep_millisecs = 0;
bool ret = false;
int i = 0;
if (vshCommandOptUInt(cmd, "shm-pages-to-scan",
&shm_pages_to_scan) < 0) {
vshError(ctl, "%s", _("invalid shm-pages-to-scan number"));
return false;
}
if (vshCommandOptUInt(cmd, "shm-sleep-millisecs",
&shm_sleep_millisecs) < 0) {
vshError(ctl, "%s", _("invalid shm-sleep-millisecs number"));
return false;
}
if (shm_pages_to_scan)
nparams++;
if (shm_sleep_millisecs)
nparams++;
if (nparams == 0) {
/* Get the number of memory parameters */
if (virNodeGetMemoryParameters(ctl->conn, NULL, &nparams, flags) != 0) {
vshError(ctl, "%s",
_("Unable to get number of memory parameters"));
goto cleanup;
}
if (nparams == 0) {
ret = true;
goto cleanup;
}
/* Now go get all the memory parameters */
params = vshCalloc(ctl, nparams, sizeof(*params));
if (virNodeGetMemoryParameters(ctl->conn, params, &nparams, flags) != 0) {
vshError(ctl, "%s", _("Unable to get memory parameters"));
goto cleanup;
}
/* XXX: Need to sort the returned params once new parameter
* fields not of shared memory are added.
*/
vshPrint(ctl, _("Shared memory:\n"));
for (i = 0; i < nparams; i++) {
char *str = vshGetTypedParamValue(ctl, &params[i]);
vshPrint(ctl, "\t%-15s %s\n", params[i].field, str);
VIR_FREE(str);
}
ret = true;
} else {
/* Set the memory parameters */
params = vshCalloc(ctl, nparams, sizeof(*params));
if (i < nparams && shm_pages_to_scan) {
if (virTypedParameterAssign(&params[i++],
VIR_NODE_MEMORY_SHARED_PAGES_TO_SCAN,
VIR_TYPED_PARAM_UINT,
shm_pages_to_scan) < 0)
goto error;
}
if (i < nparams && shm_sleep_millisecs) {
if (virTypedParameterAssign(&params[i++],
VIR_NODE_MEMORY_SHARED_SLEEP_MILLISECS,
VIR_TYPED_PARAM_UINT,
shm_sleep_millisecs) < 0)
goto error;
}
if (virNodeSetMemoryParameters(ctl->conn, params, nparams, flags) != 0)
goto error;
else
ret = true;
}
cleanup:
VIR_FREE(params);
return ret;
error:
vshError(ctl, "%s", _("Unable to change memory parameters"));
goto cleanup;
}
const vshCmdDef hostAndHypervisorCmds[] = {
{"capabilities", cmdCapabilities, NULL, info_capabilities, 0},
{"connect", cmdConnect, opts_connect, info_connect,
VSH_CMD_FLAG_NOCONNECT},
{"freecell", cmdFreecell, opts_freecell, info_freecell, 0},
{"hostname", cmdHostname, NULL, info_hostname, 0},
{"node-memory-tune", cmdNodeMemoryTune,
opts_node_memory_tune, info_node_memory_tune, 0},
{"nodecpustats", cmdNodeCpuStats, opts_node_cpustats, info_nodecpustats, 0},
{"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0},
{"nodememstats", cmdNodeMemStats, opts_node_memstats, info_nodememstats, 0},
......
......@@ -293,6 +293,14 @@ Real-Time-Clock interrupt to fire (to wake up the node) after a time delay
specified by the 'duration' parameter. The duration time should be
at least 60 seconds.
=item B<node-memory-tune> [I<shm-pages-to-scan>] [I<shm-sleep-millisecs>]
Allows you to display or set the node memory parameters.
I<shm-pages-to-scan> can be used to set the number of pages to scan
before the shared memory service goes to sleep; I<shm-sleep-millisecs>
can be used to set the number of millisecs the shared memory service should
sleep before next scan.
=item B<capabilities>
Print an XML document describing the capabilities of the hypervisor
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册