[PATCH v2 0/2] Improve VCPU code

v2: - patch rebased *IMPORTANT*: This patch depends on cpu hotplug support. This patchset addresses two issues regarding vcpu: 1 - users cannot update the number of cpus when topology is defined. In such case, vcpu must always be sockets * cores * threads. If a VM has a topology defined and we try to simply change vcpu without taking care of that topology libvirt will complain. NOTE: Using Kimchi UI, we can define the topology only when creating a template, it means that thoses values cannot be updated because there is no interface to do that. 2 - the maximum vcpu returned by libvirt is wrong. In Power it returns 1024 however the VM won't even boot with that value. Jose Ricardo Ziviani (2): Forbid user to edit CPU value if topology is defined Do not use libvirt to retrieve max vcpu value src/kimchi/i18n.py | 1 + src/kimchi/model/vms.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) -- 1.9.1

- 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@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 3ea8903..871f51e 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -85,6 +85,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 = {} @@ -834,6 +836,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('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

- libvirt is not returning a right number for the maximum vcpus possible in PowerKVM. If such value is used, the VM refuses to boot complaining the value is greater than the machine type limit. However the limit can be retrieved from ppc64_cpu, which is the number of cores available * the number of threads per core. Signed-off-by: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 871f51e..fe1bfe5 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -38,6 +38,7 @@ from kimchi.exception import InvalidOperation, InvalidParameter from kimchi.exception import NotFoundError, OperationFailed from kimchi.kvmusertests import UserTests from kimchi.model.config import CapabilitiesModel +from kimchi.model.cpuinfo import CPUInfoModel from kimchi.model.featuretests import FeatureTests from kimchi.model.tasks import TaskModel from kimchi.model.templates import TemplateModel @@ -860,7 +861,9 @@ class VMModel(object): try: # set maximum VCPU count - max_vcpus = self.conn.get().getMaxVcpus('kvm') + cpu_model = CPUInfoModel(conn=self.conn) + max_vcpus = cpu_model.cores_available *\ + cpu_model.threads_per_core dom.setVcpusFlags(max_vcpus, libvirt.VIR_DOMAIN_AFFECT_CONFIG | libvirt.VIR_DOMAIN_VCPU_MAXIMUM) -- 1.9.1

Hi, like I wrote in "[Kimchi-devel] [PATCH v3 0/5] Improve VM CPU update code ", I think that this patch set should be merged with it. Then, we do not have a broken patch set and a fix patch set. Rodrigo Trujillo On 09/16/2015 04:02 PM, Jose Ricardo Ziviani wrote:
v2: - patch rebased
*IMPORTANT*: This patch depends on cpu hotplug support.
This patchset addresses two issues regarding vcpu:
1 - users cannot update the number of cpus when topology is defined. In such case, vcpu must always be sockets * cores * threads. If a VM has a topology defined and we try to simply change vcpu without taking care of that topology libvirt will complain.
NOTE: Using Kimchi UI, we can define the topology only when creating a template, it means that thoses values cannot be updated because there is no interface to do that.
2 - the maximum vcpu returned by libvirt is wrong. In Power it returns 1024 however the VM won't even boot with that value.
Jose Ricardo Ziviani (2): Forbid user to edit CPU value if topology is defined Do not use libvirt to retrieve max vcpu value
src/kimchi/i18n.py | 1 + src/kimchi/model/vms.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-)
participants (2)
-
Jose Ricardo Ziviani
-
Rodrigo Trujillo