[Kimchi-devel] [PATCH v4 3/3] Forbid user to edit CPU value if topology is defined
Jose Ricardo Ziviani
joserz at linux.vnet.ibm.com
Mon Sep 28 13:11:54 UTC 2015
- When a cpu topology is defined, the number of cpus must always be the
product of sockets * cores * threads, otherwise libvirt will complain
about it.
Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
---
src/kimchi/i18n.py | 1 +
src/kimchi/model/vms.py | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index ecc10ff..26621a1 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -127,6 +127,7 @@ messages = {
"KCHVM0054E": _("VM '%(vm)s' cannot have more than %(cpus)d CPUs. Please update the CPU value when the VM is not running."),
"KCHVM0055E": _("VM '%(vm)s' cannot have less than %(cpus)d CPUs. Please update the CPU value when the VM is not running."),
"KCHVM0056E": _("Unable to hotplug CPUs. Details: %(err)s"),
+ "KCHVM0057E": _("Cannot change VCPU value because '%(vm)s' has a topology defined - sockets: %(sockets)s, cores: %(cores)s, threads: %(threads)s."),
"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/kimchi/model/vms.py b/src/kimchi/model/vms.py
index 96dd273..8389694 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -86,6 +86,8 @@ XPATH_DOMAIN_DEV_CPU_ID = '/domain/devices/spapr-cpu-socket/@id'
XPATH_NUMA_CELL = './cpu/numa/cell'
+XPATH_TOPOLOGY = './cpu/topology'
+
# key: VM name; value: lock object
vm_locks = {}
@@ -832,6 +834,28 @@ class VMModel(object):
self._update_memory_live(dom, params)
if DOM_STATE_MAP[dom.info()[0]] == 'shutoff':
+
+ # user cannot change vcpu if topology is defined. In this case
+ # vcpu must always be sockets * cores * threads.
+ xml = dom.XMLDesc(0)
+ sockets = xpath_get_text(xml, XPATH_TOPOLOGY + '/@sockets')
+ cores = xpath_get_text(xml, XPATH_TOPOLOGY + '/@cores')
+ threads = xpath_get_text(xml, XPATH_TOPOLOGY + '/@threads')
+ current_vcpu = dom.vcpusFlags(libvirt.VIR_DOMAIN_VCPU_MAXIMUM)
+
+ if sockets and cores and threads:
+ if current_vcpu != cpus:
+ raise InvalidOperation('KCHVM0057E',
+ {'vm': dom.name(),
+ 'sockets': sockets[0],
+ 'cores': cores[0],
+ 'threads': threads[0]})
+
+ # do not need to update vcpu if the value edit did not
+ # change
+ else:
+ return
+
try:
# set maximum VCPU count
max_vcpus = self.conn.get().getMaxVcpus('kvm')
--
1.9.1
More information about the Kimchi-devel
mailing list