#include "util.h"
#include "virsh-domain.h"
#include "xml.h"
+#include "virtypedparam.h"
/*
* "capabilities" command
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, ¶ms[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(¶ms[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(¶ms[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},