[Kimchi-devel] [PATCH 1/3 - v3] Check memory alignment in PowerPC to 256MiB

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Thu Nov 19 02:52:02 UTC 2015


QEMU for Power requires memory aligned to 256MiB.
This patch makes the checking and changes if necessary.
This patch sets a global variable in osinfo.py, in case of this value
change in the feature, code will be easier to update.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 src/wok/plugins/kimchi/i18n.py      |  3 +--
 src/wok/plugins/kimchi/model/vms.py | 26 ++++++++++++++++++++++++++
 src/wok/plugins/kimchi/osinfo.py    |  7 +++++++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/src/wok/plugins/kimchi/i18n.py b/src/wok/plugins/kimchi/i18n.py
index d2bc408..c69d072 100644
--- a/src/wok/plugins/kimchi/i18n.py
+++ b/src/wok/plugins/kimchi/i18n.py
@@ -125,8 +125,7 @@ messages = {
     "KCHVM0068E": _("Unable to setup password-less login at remote host %(host)s using user %(user)s. Error: %(error)s"),
     "KCHVM0069E": _("Password field must be a string."),
     "KCHVM0070E": _("Error creating local host ssh rsa key of user 'root'."),
-
-
+    "KCHVM0071E": _("Memory value %(mem)s must be aligned to %(alignment)sMiB."),
 
     "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 48e99a3..af9a537 100644
--- a/src/wok/plugins/kimchi/model/vms.py
+++ b/src/wok/plugins/kimchi/model/vms.py
@@ -48,6 +48,7 @@ from wok.plugins.kimchi import model
 from wok.plugins.kimchi import vnc
 from wok.plugins.kimchi.config import READONLY_POOL_TYPE, get_kimchi_version
 from wok.plugins.kimchi.kvmusertests import UserTests
+from wok.plugins.kimchi.osinfo import PPC_MEM_ALIGN
 from wok.plugins.kimchi.model.config import CapabilitiesModel
 from wok.plugins.kimchi.model.featuretests import FeatureTests
 from wok.plugins.kimchi.model.templates import TemplateModel
@@ -237,6 +238,14 @@ 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'] % PPC_MEM_ALIGN != 0:
+                    raise InvalidParameter('KCHVM0071E',
+                                           {'mem': str(params['memory']),
+                                            'alignment': str(PPC_MEM_ALIGN)})
+
             dom = self.get_vm(name, self.conn)
             vm_name, dom = self._static_vm_update(name, dom, params)
             self._live_vm_update(dom, params)
@@ -807,6 +816,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 % PPC_MEM_ALIGN)
+                # force max memory update if it exists but it's wrong.
+                if maxMem is not None and\
+                   int(maxMem.text) != (host_mem << 10):
+                    force_max_mem_update = True
+
             if maxMem is None:
                 max_mem_xml = E.maxMemory(
                     str(host_mem * 1024),
@@ -820,6 +840,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 << 10))
+
             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 7f8ace9..30ecd4f 100644
--- a/src/wok/plugins/kimchi/osinfo.py
+++ b/src/wok/plugins/kimchi/osinfo.py
@@ -27,6 +27,9 @@ from distutils.version import LooseVersion
 
 from wok.config import PluginPaths
 
+# In PowerPC, memories must be aligned to 256 MiB
+PPC_MEM_ALIGN = 256
+
 
 SUPPORTED_ARCHS = {'x86': ('i386', 'i686', 'x86_64'),
                    'power': ('ppc', 'ppc64'),
@@ -204,6 +207,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'] >> 10) % PPC_MEM_ALIGN != 0:
+            alignment = params['max_memory'] % (PPC_MEM_ALIGN << 10)
+            params['max_memory'] -= alignment
 
     if distro in modern_version_bases[arch]:
         if LooseVersion(version) >= LooseVersion(
-- 
2.1.0




More information about the Kimchi-devel mailing list