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

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Fri Nov 13 01:42:53 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, 36 insertions(+)

diff --git a/src/wok/plugins/kimchi/i18n.py b/src/wok/plugins/kimchi/i18n.py
index 59b61de..0a77fe7 100644
--- a/src/wok/plugins/kimchi/i18n.py
+++ b/src/wok/plugins/kimchi/i18n.py
@@ -19,6 +19,8 @@
 
 import gettext
 
+from wok.plugins.kimchi.osinfo import PPC_MEM_ALIGN
+
 _ = gettext.gettext
 
 
@@ -115,6 +117,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 " + str(PPC_MEM_ALIGN) + "MiB."),
 
     "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 f1ae8c2..8b7d4bd 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
@@ -45,6 +46,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
@@ -233,6 +235,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'] % PPC_MEM_ALIGN != 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)
@@ -803,6 +812,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),
@@ -816,6 +836,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