QEMU for Power requires memory aligned to 256MiB.
This patch makes the checking and changes if necessary.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
---
src/wok/plugins/kimchi/i18n.py | 1 +
src/wok/plugins/kimchi/model/vms.py | 25 +++++++++++++++++++++++++
src/wok/plugins/kimchi/osinfo.py | 4 ++++
3 files changed, 30 insertions(+)
diff --git a/src/wok/plugins/kimchi/i18n.py b/src/wok/plugins/kimchi/i18n.py
index 42a5e16..9fb4edc 100644
--- a/src/wok/plugins/kimchi/i18n.py
+++ b/src/wok/plugins/kimchi/i18n.py
@@ -115,6 +115,7 @@ messages = {
"KCHVM0058E": _("Failed to migrate virtual machine %(name)s due error:
%(err)s"),
"KCHVM0059E": _("User name of the remote server must be a
string."),
"KCHVM0060E": _("Destination host of the migration must be a
string."),
+ "KCHVM0061E": _("Memory value %(mem)s must be aligned to
256MiB."),
"KCHVMHDEV0001E": _("VM %(vmid)s does not contain directly assigned
host device %(dev_name)s."),
"KCHVMHDEV0002E": _("The host device %(dev_name)s is not allowed to
directly assign to VM."),
diff --git a/src/wok/plugins/kimchi/model/vms.py b/src/wok/plugins/kimchi/model/vms.py
index 0641ae8..3965906 100644
--- a/src/wok/plugins/kimchi/model/vms.py
+++ b/src/wok/plugins/kimchi/model/vms.py
@@ -21,6 +21,7 @@ import copy
import libvirt
import lxml.etree as ET
import os
+import platform
import random
import socket
import string
@@ -232,6 +233,13 @@ class VMModel(object):
vm_locks[name] = lock
with lock:
+ # make sure memory is alingned in 256MiB
+ distro, _, _ = platform.linux_distribution()
+ if 'memory' in params and distro == "IBM_PowerKVM":
+ if params['memory'] % 256 != 0:
+ raise InvalidParameter('KCHVM0061E',
+ {'mem':
str(params['memory'])})
+
dom = self.get_vm(name, self.conn)
vm_name, dom = self._static_vm_update(name, dom, params)
self._live_vm_update(dom, params)
@@ -800,6 +808,17 @@ class VMModel(object):
raise OperationFailed("KCHVM0041E")
elif slots == 0:
slots = 1
+
+ force_max_mem_update = False
+ distro, _, _ = platform.linux_distribution()
+ if distro == "IBM_PowerKVM":
+ # max memory 256MiB alignment
+ host_mem -= (host_mem % 256)
+ # force max memory update if it exists but it's wrong.
+ if maxMem is not None and\
+ int(maxMem.text) != (host_mem * 1024):
+ force_max_mem_update = True
+
if maxMem is None:
max_mem_xml = E.maxMemory(
str(host_mem * 1024),
@@ -813,6 +832,12 @@ class VMModel(object):
'./maxMemory',
str(slots),
attr='slots')
+
+ if force_max_mem_update:
+ new_xml = xml_item_update(new_xml,
+ './maxMemory',
+ str(host_mem * 1024))
+
return new_xml
return ET.tostring(root, encoding="utf-8")
diff --git a/src/wok/plugins/kimchi/osinfo.py b/src/wok/plugins/kimchi/osinfo.py
index 75a21ff..c915e6d 100644
--- a/src/wok/plugins/kimchi/osinfo.py
+++ b/src/wok/plugins/kimchi/osinfo.py
@@ -204,6 +204,10 @@ def lookup(distro, version):
# set up arch to ppc64 instead of ppc64le due to libvirt compatibility
if params["arch"] == "ppc64le":
params["arch"] = "ppc64"
+ # in Power, memory must be aligned in 256MiB
+ if (params['max_memory'] / 1024) % 256 != 0:
+ alignment = params['max_memory'] % (256 * 1024)
+ params['max_memory'] -= alignment
if distro in modern_version_bases[arch]:
if LooseVersion(version) >= LooseVersion(
--
2.1.0