[Kimchi-devel] [PATCH 1/2] Forbid user to edit CPU value if topology is defined
Jose Ricardo Ziviani
joserz at linux.vnet.ibm.com
Tue Sep 15 17:15:34 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 ad186ea..487c66f 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -122,6 +122,7 @@ messages = {
"KCHVM0050E": _("VM '%(vm)s' cannot have more than %(cpus)d CPUs.
Please update the CPU value when the VM is not running."),
"KCHVM0051E": _("VM '%(vm)s' cannot have less than %(cpus)d CPUs.
Please update the CPU value when the VM is not running."),
"KCHVM0052E": _("Unable to hotplug CPUs. Details: %(err)s"),
+ "KCHVM0053E": _("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 d700c08..7c0a512 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -82,6 +82,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 = {}
@@ -809,6 +811,28 @@ class VMModel(object):
cpus = params['cpus']
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('KCHVM0053E',
+ {'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