[Kimchi-devel] [PATCH][Kimchi 1/2] Modify max memory slots default numbers

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Thu May 19 12:14:07 UTC 2016


This patch sets the number of available memory device slots to the
number supported by each architecture in qemu/libvirt. Without the
restriction of 1GB per device, now kimchi Will allow users to hotplug
more devices than previous implementarion.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 model/vms.py  | 23 ++---------------------
 osinfo.py     | 11 +++++++++++
 vmtemplate.py | 20 +++++---------------
 3 files changed, 18 insertions(+), 36 deletions(-)

diff --git a/model/vms.py b/model/vms.py
index 0108381..48196dd 100644
--- a/model/vms.py
+++ b/model/vms.py
@@ -58,6 +58,7 @@ from wok.plugins.kimchi.model.utils import get_ascii_nonascii_name, get_vm_name
 from wok.plugins.kimchi.model.utils import get_metadata_node
 from wok.plugins.kimchi.model.utils import remove_metadata_node
 from wok.plugins.kimchi.model.utils import set_metadata_node
+from wok.plugins.kimchi.osinfo import defaults
 from wok.plugins.kimchi.screenshot import VMScreenshot
 from wok.plugins.kimchi.utils import get_next_clone_name
 from wok.plugins.kimchi.utils import template_name_from_uri
@@ -858,23 +859,6 @@ class VMModel(object):
             elif newMem == (oldMem << 10):
                 newMem = newMem - memDevsAmount
 
-        def _get_slots(mem, maxMem):
-            slots = (maxMem - mem) >> 10 >> 10
-            # Libvirt does not accepts slots <= 1
-            if slots < 0:
-                raise InvalidParameter("KCHTMPL0031E",
-                                       {'mem': str(mem >> 10),
-                                        'maxmem': str(maxMem >> 10)})
-            elif slots == 0:
-                slots = 1
-
-            # max 32 slots on Power
-            distro, _, _ = platform.linux_distribution()
-            if distro == "IBM_PowerKVM" and slots > 32:
-                slots = 32
-            return slots
-        # End of _get_slots
-
         # There is an issue in Libvirt/Qemu, where Guest does not start if
         # memory and max memory are the same. So we decided to remove max
         # memory and only add it if user explicitly provides it, willing to
@@ -886,7 +870,7 @@ class VMModel(object):
                 max_mem_xml = E.maxMemory(
                     str(newMaxMem),
                     unit='Kib',
-                    slots=str(_get_slots(newMem, newMaxMem)))
+                    slots=str(defaults['mem_dev_slots']))
                 root.insert(0, max_mem_xml)
             elif (maxMemTag is None) and (newMem == newMaxMem):
                 # Nothing to do
@@ -894,7 +878,6 @@ class VMModel(object):
             elif (maxMemTag is not None) and (newMem != newMaxMem):
                 # Just update value in max memory tag
                 maxMemTag.text = str(newMaxMem)
-                maxMemTag.set('slots', str(_get_slots(newMem, newMaxMem)))
             elif (maxMemTag is not None) and (newMem == newMaxMem):
                 if self._get_mem_dev_total_size(ET.tostring(root)) == 0:
                     # Remove the tag
@@ -928,8 +911,6 @@ class VMModel(object):
                 if (newMem == newMaxMem and
                    (self._get_mem_dev_total_size(ET.tostring(root)) == 0)):
                     root.remove(maxMemTag)
-                else:
-                    maxMemTag.set('slots', str(_get_slots(newMem, newMaxMem)))
 
         # Setting memory hard limit to max_memory + 1GiB
         memtune = root.find('memtune')
diff --git a/osinfo.py b/osinfo.py
index 7b80f29..d3909ad 100644
--- a/osinfo.py
+++ b/osinfo.py
@@ -34,6 +34,14 @@ SUPPORTED_ARCHS = {'x86': ('i386', 'i686', 'x86_64'),
                    'ppc64le': ('ppc64le')}
 
 
+# Memory devices slot limits by architecture
+MEM_DEV_SLOTS = {'ppc64': 32,
+                 'ppc64le': 32,
+                 'x86_64': 256,
+                 'i686': 256,
+                 'i386': 256}
+
+
 template_specs = {'x86': {'old': dict(disk_bus='ide',
                                       nic_model='e1000', sound_model='ich6'),
                           'modern': dict(disk_bus='virtio',
@@ -175,6 +183,9 @@ def _get_tmpl_defaults():
     # Update defaults values with graphics values
     defaults['graphics'] = default_config.pop('graphics')
 
+    # Setting default memory device slots
+    defaults['mem_dev_slots'] = MEM_DEV_SLOTS.get(os.uname()[4], 32)
+
     return defaults
 
 
diff --git a/vmtemplate.py b/vmtemplate.py
index 5e38275..ef92914 100644
--- a/vmtemplate.py
+++ b/vmtemplate.py
@@ -18,7 +18,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 import os
-import platform
 import stat
 import time
 import urlparse
@@ -369,25 +368,16 @@ class VMTemplate(object):
         # TODO: need modify this when boot order edition feature came upstream.
         params['boot_order'] = get_bootorder_xml()
 
-        # 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. It
-        # cannot have more than 32 slots in Power.
+        # Setting maximum number of memory slots
+        slots = str(self.info['mem_dev_slots'])
+
+        # Rearrange memory parameters
         memory = self.info['memory'].get('current')
         maxmemory = self.info['memory'].get('maxmemory')
-
-        slots = (maxmemory - memory) >> 10
-        if slots < 0:
+        if maxmemory < memory:
             raise OperationFailed("KCHVM0041E",
                                   {'maxmem': str(maxmemory)})
-        elif slots == 0:
-            slots = 1
-        elif slots > 32:
-            distro, _, _ = platform.linux_distribution()
-            if distro == "IBM_PowerKVM":
-                slots = 32
 
-        # Rearrange memory parameters
         params['memory'] = self.info['memory'].get('current')
         params['max_memory'] = ""
         # if there is not support to memory hotplug in Libvirt or qemu, we
-- 
2.1.0




More information about the Kimchi-devel mailing list