[Libvirt-cim] [PATCH] Add dynamic VCPU adjustments
Heidi Eckhart
heidieck at linux.vnet.ibm.com
Wed Jan 23 11:45:09 UTC 2008
Dan Smith wrote:
> # HG changeset patch
> # User Dan Smith <danms at us.ibm.com>
> # Date 1201029734 28800
> # Node ID 84f80a8040eb29109d0fce50b582582527c2e50e
> # Parent 47438edf32be70e65bdb814ab609a70304fad2f4
> Add dynamic VCPU adjustments
>
> Signed-off-by: Dan Smith <danms at us.ibm.com>
>
> diff -r 47438edf32be -r 84f80a8040eb libxkutil/device_parsing.c
> --- a/libxkutil/device_parsing.c Tue Jan 22 10:55:59 2008 -0800
> +++ b/libxkutil/device_parsing.c Tue Jan 22 11:22:14 2008 -0800
> @@ -897,11 +897,38 @@ static int change_memory(virDomainPtr do
> return 1;
> }
>
> +static int change_vcpus(virDomainPtr dom, int delta)
> +{
> + int count = 32;
> + int max;
> + virVcpuInfoPtr foo;
> +
> + /* This is retarded, but I don't think there's an API to
> + * expose the total VCPU number otherwise
> + */
>
I saw that virDomainInfo contains a field nrVirtCpu. Maybe this is an
alternative.
> + for (max = count; max == count; max += 32) {
> + foo = calloc(max, sizeof(*foo));
> + count = virDomainGetVcpus(dom, foo, max, NULL, 0);
>
Wouldn't the case "virDomainGetVcpus = 32" cause an endless loop ? On
the other hand ... I can not quite follow the reason of this for loop,
which exits right after the first run in case of "count < 32" ?
> + free(foo);
> + }
> +
> + CU_DEBUG("Changing VCPUs of %s from %i to %i",
> + virDomainGetName(dom),
> + count,
> + count + delta);
> +
> + virDomainSetVcpus(dom, count + delta);
>
This function returns -1 in case of failure. Shouldn't this error case
be reported to the caller ? With the current setup the caller expects
that everything worked.
> +
> + return 1;
> +}
> +
> int attach_device(virDomainPtr dom, struct virt_device *dev)
> {
> if ((dev->type == VIRT_DEV_NET) ||
> (dev->type == VIRT_DEV_DISK))
> return _change_device(dom, dev, true);
> + else if (dev->type == VIRT_DEV_VCPU)
> + return change_vcpus(dom, 1);
>
> CU_DEBUG("Unhandled device type %i", dev->type);
>
> @@ -913,6 +940,8 @@ int detach_device(virDomainPtr dom, stru
> if ((dev->type == VIRT_DEV_NET) ||
> (dev->type == VIRT_DEV_DISK))
> return _change_device(dom, dev, false);
> + else if (dev->type == VIRT_DEV_VCPU)
> + return change_vcpus(dom, -1);
>
> CU_DEBUG("Unhandled device type %i", dev->type);
>
>
>
--
Regards
Heidi Eckhart
Software Engineer
IBM Linux Technology Center - Open Hypervisor
More information about the Libvirt-cim
mailing list