Re: [PATCH 4/7] qemu: Fix coldplug of vcpus

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 21, 2016 at 01:49:56PM +0200, Peter Krempa wrote:
> virDomainDefSetVcpus was not designed to handle coldplug of vcpus now
> that we can set state of vcpus individually.
> 
> Introduce qemuDomainSetVcpusConfig that properly handles state changes
> of vcpus when coldplugging so that invalid configurations are not
> created.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1375939
> ---
>  src/qemu/qemu_driver.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 53 insertions(+), 2 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index e29180d..336673d 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -4898,6 +4898,58 @@ qemuDomainSetVcpusLive(virQEMUDriverPtr driver,
>  }
> 
> 
> +/**
> + * qemuDomainSetVcpusConfig:
> + * @def: config/offline definition of a domain
> + * @nvcpus: target vcpu count
> + *
> + * Properly handle cold(un)plug of vcpus:
> + * - plug in inactive vcpus/uplug active rather than rewriting state
> + * - fix hotpluggable state
> + */
> +static void
> +qemuDomainSetVcpusConfig(virDomainDefPtr def,
> +                         unsigned int nvcpus)
> +{
> +    virDomainVcpuDefPtr vcpu;
> +    size_t curvcpus = virDomainDefGetVcpus(def);
> +    size_t maxvcpus = virDomainDefGetVcpusMax(def);
> +    size_t i;
> +
> +
> +    if (curvcpus == nvcpus)
> +        return;
> +
> +    if (curvcpus < nvcpus) {
> +        for (i = 0; i < maxvcpus; i++) {
> +            vcpu = virDomainDefGetVcpu(def, i);
> +
> +            if (!vcpu || vcpu->online)
> +                continue;

vcpu == NULL should not happen because virDomainDefGetVcpu() checks
if (i >= maxvcpus)

> +
> +            vcpu->online = true;
> +            vcpu->hotpluggable = VIR_TRISTATE_BOOL_NO;
> +
> +            if (++curvcpus == nvcpus)
> +                break;
> +        }
> +    } else {
> +        for (i = maxvcpus; i != 0; i--) {
> +            vcpu = virDomainDefGetVcpu(def, i - 1);
> +
> +            if (!vcpu || !vcpu->online)
> +                continue;
> +
> +            vcpu->online = false;
> +            vcpu->hotpluggable = VIR_TRISTATE_BOOL_YES;
> +
> +            if (--curvcpus == nvcpus)
> +                break;
> +        }
> +    }
> +}

ACK and safe for freeze.

Pavel

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]