[PATCH 0/3 - v3] Checks memory alignment to 256 MiB and number of slots in PPC

V3: - Make modifications asked by Aline - Rebase with latest master code V2: - Created global variable to hold PPC Memory aligment value: 256 currently - Fix missing platform import - Changed mathematical operators by bitwise operators when manipulate memory values V1: This patchset makes necessary changes to check and change in PPC: - memory and maxMemory must be aligned to 256 MiB - Number of slots must be <= 32 Rodrigo Trujillo (3): Check memory alignment in PowerPC to 256MiB Check and align number of memory slot to 32 in PowerPC Change memory multipliers/divisors by bitwise operators src/wok/plugins/kimchi/i18n.py | 3 +- src/wok/plugins/kimchi/model/vms.py | 38 ++++++++++++++++++++-- src/wok/plugins/kimchi/osinfo.py | 7 ++++ src/wok/plugins/kimchi/tests/test_livemigration.py | 2 +- src/wok/plugins/kimchi/vmtemplate.py | 8 ++++- 5 files changed, 52 insertions(+), 6 deletions(-) -- 2.1.0

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@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

This patch checks the number os memory slots needed in PowerPC and raises an error if > 32, or set it to 32. Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/wok/plugins/kimchi/model/vms.py | 8 ++++++++ src/wok/plugins/kimchi/vmtemplate.py | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wok/plugins/kimchi/model/vms.py b/src/wok/plugins/kimchi/model/vms.py index af9a537..9ddeaf2 100644 --- a/src/wok/plugins/kimchi/model/vms.py +++ b/src/wok/plugins/kimchi/model/vms.py @@ -827,6 +827,10 @@ class VMModel(object): int(maxMem.text) != (host_mem << 10): force_max_mem_update = True + # max 32 slots on Power + if slots > 32: + slots = 32 + if maxMem is None: max_mem_xml = E.maxMemory( str(host_mem * 1024), @@ -885,6 +889,10 @@ class VMModel(object): # New memory value is same that current memory set return + distro, _, _ = platform.linux_distribution() + if distro == "IBM_PowerKVM" and needed_slots > 32: + raise OperationFailed('KCHVM0045E') + # Finally, we are ok to hot add the memory devices try: self._hot_add_memory_devices(dom, needed_slots) diff --git a/src/wok/plugins/kimchi/vmtemplate.py b/src/wok/plugins/kimchi/vmtemplate.py index 283d94d..d653665 100644 --- a/src/wok/plugins/kimchi/vmtemplate.py +++ b/src/wok/plugins/kimchi/vmtemplate.py @@ -18,6 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import os +import platform import stat import time import urlparse @@ -328,13 +329,18 @@ class VMTemplate(object): # Setting maximum number of slots to avoid errors when hotplug memory # Number of slots are the numbers of chunks of 1GB that fit inside - # the max_memory of the host minus memory assigned to the VM + # the max_memory of the host minus memory assigned to the VM. It + # cannot have more than 32 slots in Power. params['slots'] = ((params['max_memory'] >> 10) - params['memory']) >> 10 if params['slots'] < 0: raise OperationFailed("KCHVM0041E") elif params['slots'] == 0: params['slots'] = 1 + elif params['slots'] > 32: + distro, _, _ = platform.linux_distribution() + if distro == "IBM_PowerKVM": + params['slots'] = 32 xml = """ <domain type='%(domain)s'> -- 2.1.0

In Kimchi memory manipulation code, memory values are most of the time multiplied or divided by 1024. This patch changes these operations, replacing by << 10 or >> 10, as standard. Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/wok/plugins/kimchi/model/vms.py | 4 ++-- src/wok/plugins/kimchi/tests/test_livemigration.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wok/plugins/kimchi/model/vms.py b/src/wok/plugins/kimchi/model/vms.py index 9ddeaf2..5623879 100644 --- a/src/wok/plugins/kimchi/model/vms.py +++ b/src/wok/plugins/kimchi/model/vms.py @@ -833,7 +833,7 @@ class VMModel(object): if maxMem is None: max_mem_xml = E.maxMemory( - str(host_mem * 1024), + str(host_mem << 10), unit='Kib', slots=str(slots)) root.insert(0, max_mem_xml) @@ -881,7 +881,7 @@ class VMModel(object): # Check slot spaces: total_slots = int(xpath_get_text(xml, './maxMemory/@slots')[0]) - needed_slots = (new_mem - old_mem) / 1024 + needed_slots = (new_mem - old_mem) >> 10 used_slots = len(xpath_get_text(xml, './devices/memory')) if needed_slots > (total_slots - used_slots): raise OperationFailed('KCHVM0045E') diff --git a/src/wok/plugins/kimchi/tests/test_livemigration.py b/src/wok/plugins/kimchi/tests/test_livemigration.py index 34c0b7e..607eb36 100644 --- a/src/wok/plugins/kimchi/tests/test_livemigration.py +++ b/src/wok/plugins/kimchi/tests/test_livemigration.py @@ -102,7 +102,7 @@ class LiveMigrationTests(unittest.TestCase): 'disks': [], 'cdrom': UBUNTU_ISO, 'memory': 2048, - 'max_memory': 4096*1024} + 'max_memory': 4096 << 10} self.inst.templates_create(params) params = {'name': u'template_test_vm_migrate_nonshared', 'disks': [{'name': 'test_vm_migrate.img', 'size': 1}], -- 2.1.0
participants (2)
-
Aline Manera
-
Rodrigo Trujillo