New command node-shared-memory-tune to get/set the node shared memory parameters, only two parameters are allowed to set (pages_to_scan, and sleep_millisecs, see documents in this patch for more details). --- tools/virsh-host.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 8 ++++ 2 files changed, 118 insertions(+), 0 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index c46288b..a33cdd7 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -37,6 +37,7 @@ #include "util.h" #include "virsh-domain.h" #include "xml.h" +#include "virtypedparam.h" /* * "capabilities" command @@ -884,12 +885,121 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) return true; } +static const vshCmdInfo info_node_shared_memory_tune[] = { + {"help", N_("Get or set node shared memory parameters")}, + {"desc", N_("Get or set node shared memory parameters" + " To get the shared memory parameters, use following command: \n\n" + " virsh # node-shared-memory-tune")}, + {NULL, NULL} +}; + +static const vshCmdOptDef opts_node_shared_memory_tune[] = { + {"pages-to-scan", VSH_OT_INT, VSH_OFLAG_NONE, + N_("number of pages to scan before shared memory service " + "goes to sleep")}, + {"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 +cmdNodeSharedMemoryTune(vshControl *ctl, const vshCmd *cmd) +{ + virTypedParameterPtr params = NULL; + int nparams = 0; + unsigned int flags = 0; + unsigned int pages_to_scan = 0; + unsigned int sleep_millisecs = 0; + bool ret = false; + int i = 0; + + if (vshCommandOptUInt(cmd, "pages-to-scan", &pages_to_scan) < 0) { + vshError(ctl, "%s", _("invalid pages-to-scan number")); + return false; + } + + if (vshCommandOptUInt(cmd, "sleep-millisecs", &sleep_millisecs) < 0) { + vshError(ctl, "%s", _("invalid sleep-millisecs number")); + return false; + } + + if (pages_to_scan) + nparams++; + + if (sleep_millisecs) + nparams++; + + if (nparams == 0) { + /* Get the number of shared memory parameters */ + if (virNodeGetSharedMemoryParameters(ctl->conn, NULL, &nparams, flags) != 0) { + vshError(ctl, "%s", + _("Unable to get number of shared memory parameters")); + goto cleanup; + } + + if (nparams == 0) { + ret = true; + goto cleanup; + } + + /* Now go get all the shared memory parameters */ + params = vshCalloc(ctl, nparams, sizeof(*params)); + if (virNodeGetSharedMemoryParameters(ctl->conn, params, &nparams, flags) != 0) { + vshError(ctl, "%s", _("Unable to get shared memory parameters")); + goto cleanup; + } + + for (i = 0; i < nparams; i++) { + char *str = vshGetTypedParamValue(ctl, ¶ms[i]); + vshPrint(ctl, "%-15s: %s\n", params[i].field, str); + VIR_FREE(str); + } + + ret = true; + } else { + /* Set the shared memory parameters */ + params = vshCalloc(ctl, nparams, sizeof(*params)); + + if (i < nparams && pages_to_scan) { + if (virTypedParameterAssign(¶ms[i++], + VIR_NODE_SHARED_MEMORY_PAGES_TO_SCAN, + VIR_TYPED_PARAM_UINT, + pages_to_scan) < 0) + goto error; + } + + if (i < nparams && sleep_millisecs) { + if (virTypedParameterAssign(¶ms[i++], + VIR_NODE_SHARED_MEMORY_SLEEP_MILLISECS, + VIR_TYPED_PARAM_UINT, + sleep_millisecs) < 0) + goto error; + } + + if (virNodeSetSharedMemoryParameters(ctl->conn, params, nparams, flags) != 0) + goto error; + else + ret = true; + } + +cleanup: + VIR_FREE(params); + return ret; + +error: + vshError(ctl, "%s", _("Unable to change shared 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-shared-memory-tune", cmdNodeSharedMemoryTune, + opts_node_shared_memory_tune, info_node_shared_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}, diff --git a/tools/virsh.pod b/tools/virsh.pod index 68138e5..6c9e14e 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -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-shared-memory-tune> [I<pages-to-scan>] [I<sleep-millisecs>] + +Allows you to display or set the node shared memory parameters. +I<pages-to-scan> can be used to set the number of pages to scan +before the shared memory service goes to sleep; I<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 -- 1.7.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list