Tested-by: Paulo Vital <pvital(a)linux.vnet.ibm.com>
Reviewed-by: Paulo Vital <pvital(a)linux.vnet.ibm.com>
On 02/27/2016 04:40 PM, Rodrigo Trujillo wrote:
There are issues when user attaches memory devices to a guest
(memory
hotplug) and try later to modify the memory values offline.
This patch fixes the problems, checking whether there are memory devices
configured and adjusting the newmemory value.
This patch sets the following rules:
- if new memory value is equal max memory, all memory devices will be
removed
- if new memory is greater than old value, just update the memory
- if new memory is lesser than old value, always remove 1G memory
devices first and then decrease the memory value until reach the
amount requested
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
---
model/vms.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/model/vms.py b/model/vms.py
index c376741..8c3d4c4 100644
--- a/model/vms.py
+++ b/model/vms.py
@@ -825,6 +825,24 @@ class VMModel(object):
validate_memory({'current': newMem >> 10,
'maxmemory': newMaxMem >> 10})
+ # Adjust memory devices to new memory, if necessary
+ memDevs = root.findall('./devices/memory')
+ if len(memDevs) != 0 and hasMem:
+ if newMem == newMaxMem:
+ for dev in memDevs:
+ root.find('./devices').remove(dev)
+ elif newMem > (oldMem << 10):
+ newMem = newMem - (len(memDevs) * (1024 << 10))
+ elif newMem < (oldMem << 10):
+ devsRemove = len(memDevs) - (oldMem - (newMem >> 10))/1024 - 1
+ for dev in memDevs:
+ if int(dev.xpath('./address/@slot')[0]) > devsRemove:
+ root.find('./devices').remove(dev)
+ newMem = newMem - (len(root.findall('./devices/memory'))
+ * 1024 << 10)
+ elif newMem == (oldMem << 10):
+ newMem = newMem - ((len(memDevs) * 1024) << 10)
+
def _get_slots(mem, maxMem):
slots = (maxMem - mem) >> 10 >> 10
# Libvirt does not accepts slots <= 1