[Libvirt-cim] [PATCH] Add dynamic VCPU adjustments

Dan Smith danms at us.ibm.com
Tue Jan 22 18:24:14 UTC 2008


# 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
+         */
+        for (max = count; max == count; max += 32) {
+                foo = calloc(max, sizeof(*foo));
+                count = virDomainGetVcpus(dom, foo, max, NULL, 0);
+                free(foo);
+        }
+
+        CU_DEBUG("Changing VCPUs of %s from %i to %i",
+                 virDomainGetName(dom),
+                 count,
+                 count + delta);
+
+        virDomainSetVcpus(dom, count + 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 +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);
 




More information about the Libvirt-cim mailing list