# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1201101678 28800
# Node ID 8a5a12f5003b1e564fe21f29001a2843139614c3
# Parent 47438edf32be70e65bdb814ab609a70304fad2f4
(#2) Add dynamic VCPU adjustments
Changes:
- Removed stupidity from last patch
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 47438edf32be -r 8a5a12f5003b libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c Tue Jan 22 10:55:59 2008 -0800
+++ b/libxkutil/device_parsing.c Wed Jan 23 07:21:18 2008 -0800
@@ -897,11 +897,40 @@ static int change_memory(virDomainPtr do
return 1;
}
+static int change_vcpus(virDomainPtr dom, int delta)
+{
+ int ret;
+ virDomainInfo info;
+
+ ret = virDomainGetInfo(dom, &info);
+ if (ret == -1) {
+ CU_DEBUG("Failed to get domain info for %s",
+ virDomainGetName(dom));
+ return 0;
+ }
+
+ ret = virDomainSetVcpus(dom, info.nrVirtCpu + delta);
+ if (ret == -1) {
+ CU_DEBUG("Failed to set domain vcpus to %i",
+ info.nrVirtCpu + delta);
+ return 0;
+ }
+
+ CU_DEBUG("Changed %s vcpus from %i to %i",
+ virDomainGetName(dom),
+ info.nrVirtCpu,
+ info.nrVirtCpu + delta);
+
+ 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 +942,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);