[libvirt] [PATCH 6/9] Allow controller selection by ID

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

 



... by simply traversing the list of controllers
to find the associated PCI address.

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@xxxxxxxxxxx>
Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
 src/qemu_driver.c |   41 +++++++++++++++++++++++++++++++----------
 1 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 3bdd2d7..990f05a 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -5418,19 +5418,40 @@ try_command:
     }
 
     if (controller_specified) {
-        /* NOTE: Proper check for the controller will be implemented
-           in a later commit */
-	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->controller_id) {
-            /* TODO: Obtain the PCI address of the controller
-               from the data structures using the ID */
+            for (i = 0 ; i < vm->def->ncontrollers ; i++) {
+                if (STREQ(dev->data.disk->controller_id, 
+                          vm->def->controllers[i]->id)) {
+                    break;
+                }
+            }
+
+            if (i == vm->def->ncontrollers) {
+                qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+                                 _("Controller does not exist"));
+                return -1;
+            }
+
+            domain = vm->def->controllers[i]->pci_addr.domain;
+            bus    = vm->def->controllers[i]->pci_addr.bus;
+            slot   = vm->def->controllers[i]->pci_addr.slot;
         } 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;
+
+            for (i = 0 ; i < vm->def->ncontrollers ; i++) {
+                if (domain ==  vm->def->controllers[i]->pci_addr.domain &&
+                    bus    ==  vm->def->controllers[i]->pci_addr.bus &&
+                    slot   ==  vm->def->controllers[i]->pci_addr.slot)
+                    break;
+            }
+
+            if (i == vm->def->ncontrollers) {
+                qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+                                 _("Controller does not exist"));
+                return -1;
+            }
 	}
 
         if (dev->data.disk->bus_id != -1) {
@@ -5457,13 +5478,13 @@ try_command:
         ret = virAsprintf(&cmd, "pci_add %s storage file=%s,if=%s",
                    (tryOldSyntax ? "0": "pci_addr=auto"), safe_path, type);
     }
-
+    
     VIR_FREE(safe_path);
     if (ret == -1) {
         virReportOOMError(conn);
         return ret;
     }
-
+    
     if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
         qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
                          _("cannot attach %s disk"), type);
-- 
1.6.4

--
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]