提交 118eac37 编写于 作者: H Hu Tao 提交者: Daniel Veillard

Add new flags for setting memory parameters

The new flags allow to pick current state, config or the live
parameter, with current being the existing API default (0).
This also hooks this to --config, --live, --current parameters for
the memtune virsh command

* include/libvirt/libvirt.h.in: defines the new flags
* tools/virsh.c: adds support at virsh level
* tools/virsh.pod: updates virsh documentation
上级 9c26d6f0
...@@ -883,6 +883,13 @@ typedef enum { ...@@ -883,6 +883,13 @@ typedef enum {
VIR_DOMAIN_MEMORY_PARAM_BOOLEAN = VIR_TYPED_PARAM_BOOLEAN, VIR_DOMAIN_MEMORY_PARAM_BOOLEAN = VIR_TYPED_PARAM_BOOLEAN,
} virMemoryParameterType; } virMemoryParameterType;
/* flags for setting memory parameters */
typedef enum {
VIR_DOMAIN_MEMORY_PARAM_CURRENT = 0, /* affect current domain state */
VIR_DOMAIN_MEMORY_PARAM_LIVE = (1 << 0), /* affect active domain */
VIR_DOMAIN_MEMORY_PARAM_CONFIG = (1 << 1) /* affect next boot */
} virMemoryParamFlags;
/** /**
* VIR_DOMAIN_MEMORY_FIELD_LENGTH: * VIR_DOMAIN_MEMORY_FIELD_LENGTH:
* *
......
...@@ -3307,6 +3307,9 @@ static const vshCmdOptDef opts_memtune[] = { ...@@ -3307,6 +3307,9 @@ static const vshCmdOptDef opts_memtune[] = {
N_("Max memory plus swap in kilobytes")}, N_("Max memory plus swap in kilobytes")},
{"min-guarantee", VSH_OT_INT, VSH_OFLAG_NONE, {"min-guarantee", VSH_OT_INT, VSH_OFLAG_NONE,
N_("Min guaranteed memory in kilobytes")}, N_("Min guaranteed memory in kilobytes")},
{"config", VSH_OT_BOOL, 0, N_("affect next boot")},
{"live", VSH_OT_BOOL, 0, N_("affect running domain")},
{"current", VSH_OT_BOOL, 0, N_("affect current domain")},
{NULL, 0, 0, NULL} {NULL, 0, 0, NULL}
}; };
...@@ -3320,6 +3323,23 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd) ...@@ -3320,6 +3323,23 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
unsigned int i = 0; unsigned int i = 0;
virMemoryParameterPtr params = NULL, temp = NULL; virMemoryParameterPtr params = NULL, temp = NULL;
bool ret = false; bool ret = false;
unsigned int flags = 0;
int current = vshCommandOptBool(cmd, "current");
int config = vshCommandOptBool(cmd, "config");
int live = vshCommandOptBool(cmd, "live");
if (current) {
if (live || config) {
vshError(ctl, "%s", _("--current must be specified exclusively"));
return false;
}
flags = VIR_DOMAIN_MEMORY_PARAM_CURRENT;
} else {
if (config)
flags |= VIR_DOMAIN_MEMORY_PARAM_CONFIG;
if (live)
flags |= VIR_DOMAIN_MEMORY_PARAM_LIVE;
}
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
return false; return false;
...@@ -3350,7 +3370,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd) ...@@ -3350,7 +3370,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
if (nparams == 0) { if (nparams == 0) {
/* get the number of memory parameters */ /* get the number of memory parameters */
if (virDomainGetMemoryParameters(dom, NULL, &nparams, 0) != 0) { if (virDomainGetMemoryParameters(dom, NULL, &nparams, flags) != 0) {
vshError(ctl, "%s", vshError(ctl, "%s",
_("Unable to get number of memory parameters")); _("Unable to get number of memory parameters"));
goto cleanup; goto cleanup;
...@@ -3364,7 +3384,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd) ...@@ -3364,7 +3384,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
/* now go get all the memory parameters */ /* now go get all the memory parameters */
params = vshCalloc(ctl, nparams, sizeof(*params)); params = vshCalloc(ctl, nparams, sizeof(*params));
if (virDomainGetMemoryParameters(dom, params, &nparams, 0) != 0) { if (virDomainGetMemoryParameters(dom, params, &nparams, flags) != 0) {
vshError(ctl, "%s", _("Unable to get memory parameters")); vshError(ctl, "%s", _("Unable to get memory parameters"));
goto cleanup; goto cleanup;
} }
...@@ -3444,7 +3464,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd) ...@@ -3444,7 +3464,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
if (temp->value.ul == -1) if (temp->value.ul == -1)
temp->value.ul = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; temp->value.ul = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
} }
if (virDomainSetMemoryParameters(dom, params, nparams, 0) != 0) if (virDomainSetMemoryParameters(dom, params, nparams, flags) != 0)
vshError(ctl, "%s", _("Unable to change memory parameters")); vshError(ctl, "%s", _("Unable to change memory parameters"));
else else
ret = true; ret = true;
......
...@@ -644,6 +644,13 @@ flags, the current settings are displayed; with a flag, the ...@@ -644,6 +644,13 @@ flags, the current settings are displayed; with a flag, the
appropriate limit is adjusted if supported by the hypervisor. LXC and appropriate limit is adjusted if supported by the hypervisor. LXC and
QEMU/KVM support I<--hard-limit>, I<--soft-limit>, and I<--swap-hard-limit>. QEMU/KVM support I<--hard-limit>, I<--soft-limit>, and I<--swap-hard-limit>.
If I<--live> is specified, affect a running guest.
If I<--config> is specified, affect the next boot of a persistent guest.
If I<--current> is specified, affect the current guest state.
Both I<--live> and I<--current> flags may be given, but I<--current> is
exclusive. If no flag is specified, behavior is different depending
on hypervisor.
For QEMU/KVM, the parameters are applied to the QEMU process as a whole. For QEMU/KVM, the parameters are applied to the QEMU process as a whole.
Thus, when counting them, one needs to add up guest RAM, guest video RAM, and Thus, when counting them, one needs to add up guest RAM, guest video RAM, and
some memory overhead of QEMU itself. The last piece is hard to determine so some memory overhead of QEMU itself. The last piece is hard to determine so
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册