Commit 60f7303c151cccdbe214b9f9ac59ecaf95cbf24b introduced the error
message but it's unclear whether the persistent config or the live
config tripped the message. Later the LXC driver copied the same code.
Separate the message which will also clarify the code.
---
Notes:
Version 2:
- reworded error message
src/lxc/lxc_driver.c | 22 +++++++++++++---------
src/qemu/qemu_driver.c | 24 ++++++++++++++----------
2 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 3adb21d..fea9599 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -742,18 +742,22 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long
newmem,
goto cleanup;
}
} else {
- unsigned long oldmax = 0;
-
- if (flags & VIR_DOMAIN_AFFECT_LIVE)
- oldmax = vm->def->mem.max_balloon;
- if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
- if (!oldmax || oldmax > persistentDef->mem.max_balloon)
- oldmax = persistentDef->mem.max_balloon;
+ if (flags & VIR_DOMAIN_AFFECT_LIVE &&
+ newmem > vm->def->mem.max_balloon) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("new memory value '%lu' cannot be greater than
"
+ "the maximum value '%llu' for the live
instance"),
+ newmem, vm->def->mem.max_balloon);
+ goto cleanup;
}
- if (newmem > oldmax) {
+ if (flags & VIR_DOMAIN_AFFECT_CONFIG &&
+ newmem > persistentDef->mem.max_balloon) {
virReportError(VIR_ERR_INVALID_ARG,
- "%s", _("Cannot set memory higher than max
memory"));
+ _("new memory value '%lu' cannot be greater than
"
+ "the maximum value '%llu' for the persistent
"
+ "configuration"),
+ newmem, persistentDef->mem.max_balloon);
goto cleanup;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 27cb3bf..bf19de8 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2326,18 +2326,22 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned
long newmem,
} else {
/* resize the current memory */
- unsigned long oldmax = 0;
-
- if (flags & VIR_DOMAIN_AFFECT_LIVE)
- oldmax = vm->def->mem.max_balloon;
- if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
- if (!oldmax || oldmax > persistentDef->mem.max_balloon)
- oldmax = persistentDef->mem.max_balloon;
+ if (flags & VIR_DOMAIN_AFFECT_LIVE &&
+ newmem > vm->def->mem.max_balloon) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("new memory value '%lu' cannot be greater than
"
+ "the maximum value '%llu' for the live
instance"),
+ newmem, vm->def->mem.max_balloon);
+ goto endjob;
}
- if (newmem > oldmax) {
- virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("cannot set memory higher than max memory"));
+ if (flags & VIR_DOMAIN_AFFECT_CONFIG &&
+ newmem > persistentDef->mem.max_balloon) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("new memory value '%lu' cannot be greater than
"
+ "the maximum value '%llu' for the persistent
"
+ "configuration"),
+ newmem, persistentDef->mem.max_balloon);
goto endjob;
}
--
2.2.2