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

[libvirt] [PATCH 5/9] Implement controller hotplugging



This enables to hot-add disk controllers without attached
disks into the system. Previously, it was only possible to
(implicitly) add disk controllers in the static machine
configuration.

Notice that the actual functionality is only available
for qemu at present, but other emulators can be extended
likewise.

Signed-off-by: Wolfgang Mauerer <wolfgang mauerer siemens com>
Signed-off-by: Jan Kiszka <jan kiszka siemens com>
---
 src/domain_conf.c        |   26 +++++++++++++++++++++++---
 src/domain_conf.h        |    2 ++
 src/libvirt_private.syms |    1 +
 src/qemu_driver.c        |   21 +++++++++++++++++----
 4 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/src/domain_conf.c b/src/domain_conf.c
index d0fda64..ea51fda 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -647,7 +647,6 @@ void virDomainRemoveInactive(virDomainObjListPtr doms,
 
 }
 
-
 /* Parse the XML definition for a disk
  * @param node XML nodeset to parse for disk definition
  */
@@ -2554,6 +2553,27 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(virConnectPtr conn,
 #endif
 
 
+static int virDomainControllerCompare(virDomainControllerDefPtr a,
+                                      virDomainControllerDefPtr b) {
+    if (a->pci_addr.bus == b->pci_addr.bus) {
+        if (a->pci_addr.domain == b->pci_addr.domain) 
+            return a->pci_addr.slot - b->pci_addr.slot;
+
+        return a->pci_addr.domain - b->pci_addr.domain;
+    }
+
+    return a->pci_addr.bus - b->pci_addr.bus;
+}
+
+
+int virDomainControllerQSort(const void *a, const void *b)
+{
+    const virDomainControllerDefPtr *da = a;
+    const virDomainControllerDefPtr *db = b;
+
+    return virDomainControllerCompare(*da, *db);
+}
+
 int virDomainDiskInsert(virDomainDefPtr def,
                         virDomainDiskDefPtr disk)
 {
@@ -2935,8 +2955,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
 
         def->controllers[def->ncontrollers++] = controller;
     }
-    /*    qsort(def->controllers, def->ncontrollers, sizeof(*def->controllers),
-          virDomainControllerQSort); */
+    qsort(def->controllers, def->ncontrollers, sizeof(*def->controllers),
+          virDomainControllerQSort);
     VIR_FREE(nodes);
 
 
diff --git a/src/domain_conf.h b/src/domain_conf.h
index 41df8f6..17f8b14 100644
--- a/src/domain_conf.h
+++ b/src/domain_conf.h
@@ -728,6 +728,8 @@ int virDomainDiskInsert(virDomainDefPtr def,
 void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
                                    virDomainDiskDefPtr disk);
 
+int virDomainControllerQSort(const void *a, const void *b);
+
 int virDomainSaveXML(virConnectPtr conn,
                      const char *configDir,
                      virDomainDefPtr def,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f724493..ecc1123 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -86,6 +86,7 @@ virDomainDiskDefFree;
 virDomainDiskDeviceTypeToString;
 virDomainDiskInsert;
 virDomainDiskInsertPreAlloced;
+virDomainControllerQSort;
 virDomainFindByID;
 virDomainFindByName;
 virDomainFindByUUID;
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 4a30615..3bdd2d7 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -5424,6 +5424,15 @@ try_command:
 	bus    = dev->data.disk->controller_pci_addr.bus;
 	slot   = dev->data.disk->controller_pci_addr.slot;
 
+        if (dev->data.disk->controller_id) {
+            /* TODO: Obtain the PCI address of the controller
+               from the data structures using the ID */
+        } else {
+            domain = dev->data.disk->controller_pci_addr.domain;
+            bus    = dev->data.disk->controller_pci_addr.bus;
+            slot   = dev->data.disk->controller_pci_addr.slot;
+	}
+
         if (dev->data.disk->bus_id != -1) {
             virBufferVSprintf(&buf, ",bus=%d", dev->data.disk->bus_id);
         }
@@ -5582,6 +5591,8 @@ try_command:
 
     VIR_FREE(cmd);
 
+    /* Naturally, the controller hotplug reply is identical with
+       any other PCI hotplug reply */
     if (qemudParsePciAddReply(vm, reply, &domain, &bus, &slot) < 0) {
         if (!tryOldSyntax && strstr(reply, "invalid char in expression")) {
 	    VIR_FREE(reply);
@@ -5596,17 +5607,17 @@ try_command:
     }
 	
     /* Also fill in when the address was explicitely specified in
-       case qemu changed it (TODO: Can this really happen?) */
+       case qemu changed it */
     dev->data.controller->pci_addr.domain = domain;
     dev->data.controller->pci_addr.bus    = bus;
     dev->data.controller->pci_addr.slot   = slot;
 
     VIR_FREE(reply);
 
-    /* NOTE: Sort function is added in a later commit */
     vm->def->controllers[vm->def->ncontrollers++] = dev->data.controller;
-    /*    qsort(vm->def->disks, vm->def->ndisks, sizeof(*vm->def->disks),
-    virDomainDiskQSort);*/
+    qsort(vm->def->controllers, vm->def->ncontrollers, 
+          sizeof(*vm->def->controllers),
+          virDomainControllerQSort);
 
     return 0;
 }
@@ -6104,6 +6115,8 @@ static int qemudDomainAttachDevice(virDomainPtr dom,
             virCgroupDenyDevicePath(cgroup,
                                     dev->data.disk->src);
         }
+    } else if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
+        ret = qemudDomainAttachDiskController(dom->conn, vm, dev);
     } else if (dev->type == VIR_DOMAIN_DEVICE_NET) {
         ret = qemudDomainAttachNetDevice(dom->conn, driver, vm, dev, qemuCmdFlags);
     } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
-- 
1.6.4


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