[Kimchi-devel] [PATCH] [Kimchi 2/4] CPU Hot plug/unplug: model changes

Daniel Henrique Barboza danielhb at linux.vnet.ibm.com
Fri Nov 11 17:16:22 UTC 2016



On 11/11/2016 01:24 PM, Aline Manera wrote:
>
>
> On 11/08/2016 11:33 AM, dhbarboza82 at gmail.com wrote:
>> From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
>>
>> This patch makes changes on model/vms.py to support
>> the hotplug of new CPUs in a running VM.
>>
>> For CPU Hot unplug in Power hypervisors there is a need
>> for guest software to be installed:
>>
>> * guest must have packages: powerpc-utils, ppc64-diag, librtas
>> * guest must have service rtas_err.service running
>>
>> Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
>> ---
>>   model/vms.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
>>   1 file changed, 49 insertions(+), 1 deletion(-)
>>
>> diff --git a/model/vms.py b/model/vms.py
>> index bff7ed2..cc9cd4c 100644
>> --- a/model/vms.py
>> +++ b/model/vms.py
>> @@ -82,7 +82,8 @@ DOM_STATE_MAP = {0: 'nostate',
>>                    7: 'pmsuspended'}
>>
>>   # update parameters which are updatable when the VM is online
>> -VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users']
>> +VM_ONLINE_UPDATE_PARAMS = ['cpu_info', 'graphics', 'groups',
>> +                           'memory', 'users']
>>
>>   # update parameters which are updatable when the VM is offline
>>   VM_OFFLINE_UPDATE_PARAMS = ['cpu_info', 'graphics', 'groups', 
>> 'memory',
>> @@ -1028,6 +1029,15 @@ class VMModel(object):
>>                                                  unit='Kib'))
>>           return ET.tostring(root, encoding="utf-8")
>>
>> +    def get_vm_cpu_cores(self, vm_xml):
>> +        return xpath_get_text(vm_xml, XPATH_TOPOLOGY + '/@cores')[0]
>> +
>> +    def get_vm_cpu_sockets(self, vm_xml):
>> +        return xpath_get_text(vm_xml, XPATH_TOPOLOGY + '/@sockets')[0]
>> +
>> +    def get_vm_cpu_threads(self, vm_xml):
>> +        return xpath_get_text(vm_xml, XPATH_TOPOLOGY + '/@threads')[0]
>> +
>>       def _update_cpu_info(self, new_xml, dom, new_info):
>>           topology = {}
>>           if self.has_topology(dom):
>> @@ -1064,6 +1074,44 @@ class VMModel(object):
>>           if (('memory' in params) and ('current' in params['memory'])):
>>               self._update_memory_live(dom, params)
>>
>> +        if 'vcpus' in params.get('cpu_info', {}):
>> +            self.cpu_hotplug_precheck(dom, params)
>> +            vcpus = params['cpu_info'].get('vcpus')
>> +            self.update_cpu_live(dom, vcpus)
>> +
>
>> +    def cpu_hotplug_precheck(self, dom, params):
>> +
>> +        if (('maxvcpus' in params['cpu_info']) or
>> +                ('topology' in params['cpu_info'])):
>> +            raise InvalidParameter('KCHCPUHOTP0001E')
>> +
>> +        vcpus = params['cpu_info'].get('vcpus')
>> +        if vcpus > dom.maxVcpus():
>> +            raise InvalidParameter(
>> +                'KCHCPUHOTP0002E',
>> +                {'vm': dom.name(), 'cpus': dom.maxVcpus()}
>> +            )
>> +
>> +        if self.has_topology(dom):
>> +            sockets = int(self.get_vm_cpu_sockets(dom.XMLDesc(0)))
>> +            cores = int(self.get_vm_cpu_cores(dom.XMLDesc(0)))
>> +            threads = int(self.get_vm_cpu_threads(dom.XMLDesc(0)))
>> +
>> +            if vcpus % threads != 0:
>> +                raise InvalidParameter(
>> +                    'KCHCPUHOTP0003E',
>> +                    {'sockets': str(sockets), 'cores': str(cores),
>> +                     'threads': str(threads)}
>> +                )
>> +
>
> Can't we use check_cpu_info() to do all the verification ? It would be 
> better to have a single place where we can do the checks for CPU.

In the time I've wrote this code, no. check_cpu_info() is not working 
properly
at that time, not considering the sockets number when checking if a
topology is valid.

I was planning to change this code to use check_cpu_info() as part of the
RFC "[RFC] Guest/Template CPU setup with topology​" work, when
I'll fix the check_cpu_info() check.


>
>> +    def update_cpu_live(self, dom, vcpus):
>> +        flags = libvirt.VIR_DOMAIN_AFFECT_LIVE | \
>> +                libvirt.VIR_DOMAIN_AFFECT_CONFIG
>> +        try:
>> +            dom.setVcpusFlags(vcpus, flags)
>> +        except libvirt.libvirtError as e:
>> +            raise OperationFailed('KCHCPUHOTP0004E', {'err': 
>> e.message})
>> +
>>       def _get_mem_dev_total_size(self, xml):
>>           root = ET.fromstring(xml)
>>           totMemDevs = 0
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>




More information about the Kimchi-devel mailing list