[libvirt] [PATCH 11/13] Extract qemu monitor parts for controller hotplug

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

 



From: Wolfgang Mauerer <wolfgang.mauerer@xxxxxxxxxxx>

This separates the communication with qemu a bit from the more
libvirtish actions.

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@xxxxxxxxxxx>
Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
 src/qemu/qemu_driver.c       |   61 +--------------------------------------
 src/qemu/qemu_monitor_text.c |   65 ++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_text.h |    2 +
 3 files changed, 69 insertions(+), 59 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9f44685..289c3c6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4580,12 +4580,7 @@ static int qemudDomainAttachDiskController(virConnectPtr conn,
 					   virDomainObjPtr vm,
 					   virDomainDeviceDefPtr dev)
 {
-    int ret, i;
-    char *cmd, *reply;
-    char *tmp;
-    const char* type = virDomainDiskBusTypeToString(dev->data.controller->type);
-    int tryOldSyntax = 0;
-    unsigned domain, bus, slot;
+    int i;
 
     /* Only SCSI controllers are supported at the moment */
     if (dev->data.controller->address &&
@@ -4618,59 +4613,7 @@ static int qemudDomainAttachDiskController(virConnectPtr conn,
         return -1;
     }
 
-try_command:
-    if (dev->data.controller->address != NULL) {
-        domain = dev->data.controller->address->data.pci.domain;
-        bus    = dev->data.controller->address->data.pci.bus;
-        slot   = dev->data.controller->address->data.pci.slot;
-
-	ret = virAsprintf(&tmp, "%.2x:%.2x:%.2x", domain, bus, slot);
-        ret |= virAsprintf(&cmd, "pci_add %s%s storage if=%s",
-			   (tryOldSyntax ? "" : "pci_addr="), tmp, type);
-    } else {
-        ret = virAsprintf(&cmd, "pci_add %s storage if=%s",
-                          (tryOldSyntax ? "0" : "pci_addr=auto"), type);
-    }
-
-    if (ret == -1) {
-        virReportOOMError(conn);
-        return ret;
-    }
-
-    if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
-        qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
-                         _("cannot attach %s controller"), type);
-        VIR_FREE(cmd);
-        return -1;
-    }
-
-    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);
-	    tryOldSyntax = 1;
-	    goto try_command;
-	}
-
-	qemudReportError (conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
-			  _("adding %s controller failed: %s"), type, reply);
-	VIR_FREE(reply);
-	return -1;
-    }
-
-    /* Also fill in when the address was explicitely specified in
-       case qemu changed it */
-    dev->data.controller->address->data.pci.domain = domain;
-    dev->data.controller->address->data.pci.bus    = bus;
-    dev->data.controller->address->data.pci.slot   = slot;
-
-    VIR_FREE(reply);
-
-    vm->def->controllers[vm->def->ncontrollers++] = dev->data.controller;
-    return 0;
+    return qemuMonitorAttachDiskController(vm, dev);
 }
 
 static int qemudDomainAttachUsbMassstorageDevice(virConnectPtr conn,
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index f6f3e58..7326d05 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -1529,6 +1529,71 @@ qemudParseDriveAddReply(virDomainObjPtr vm,
     return 0;
 }
 
+int qemuMonitorAttachDiskController(virDomainObjPtr vm,
+                                    virDomainDeviceDefPtr dev)
+{
+    int ret;
+    char *cmd, *reply;
+    char *tmp;
+    const char* type = virDomainDiskBusTypeToString(dev->data.controller->type);
+    int tryOldSyntax = 0;
+    unsigned domain, bus, slot;
+
+try_command:
+    if (dev->data.controller->address != NULL) {
+        domain = dev->data.controller->address->data.pci.domain;
+	bus    = dev->data.controller->address->data.pci.bus;
+	slot   = dev->data.controller->address->data.pci.slot;
+
+	ret = virAsprintf(&tmp, "%.2x:%.2x:%.2x", domain, bus, slot);
+        ret |= virAsprintf(&cmd, "pci_add %s%s storage if=%s",
+			   (tryOldSyntax ? "" : "pci_addr="), tmp, type);
+    } else {
+        ret = virAsprintf(&cmd, "pci_add %s storage if=%s",
+			   (tryOldSyntax ? "0" : "pci_addr=auto"), type);
+    }
+
+    if (ret == -1) {
+        virReportOOMError(NULL);
+        return ret;
+    }
+
+    if (qemuMonitorCommand(vm, cmd, &reply) < 0) {
+        qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+                         _("cannot attach %s controller"), type);
+        VIR_FREE(cmd);
+        return -1;
+    }
+
+    VIR_FREE(cmd);
+
+    /* Naturally, the controller hotplug reply is identical with
+       any other PCI hotplug reply */
+    if (qemuMonitorParsePciAddReply(vm, reply, &domain, &bus, &slot) < 0) {
+        if (!tryOldSyntax && strstr(reply, "invalid char in expression")) {
+	    VIR_FREE(reply);
+	    tryOldSyntax = 1;
+	    goto try_command;
+	}
+
+	qemudReportError (NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+			  _("adding %s controller failed: %s"), type, reply);
+	VIR_FREE(reply);
+	return -1;
+    }
+
+    /* Also fill in when the address was explicitely specified in
+       case qemu changed it */
+    dev->data.controller->address->data.pci.domain = domain;
+    dev->data.controller->address->data.pci.bus    = bus;
+    dev->data.controller->address->data.pci.slot   = slot;
+
+    VIR_FREE(reply);
+
+    vm->def->controllers[vm->def->ncontrollers++] = dev->data.controller;
+    return 0;
+}
+
 int qemuMonitorAddPCIHostDevice(const virDomainObjPtr vm,
                                 unsigned hostDomain ATTRIBUTE_UNUSED,
                                 unsigned hostBus,
diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h
index 9175456..c674507 100644
--- a/src/qemu/qemu_monitor_text.h
+++ b/src/qemu/qemu_monitor_text.h
@@ -154,6 +154,8 @@ int qemuMonitorAddPCINetwork(const virDomainObjPtr vm,
                              unsigned *guestBus,
                              unsigned *guestSlot);
 
+int qemuMonitorAttachDiskController(virDomainObjPtr vm,
+                                    virDomainDeviceDefPtr dev);
 int qemuMonitorRemovePCIDevice(const virDomainObjPtr vm,
                                unsigned guestDomain,
                                unsigned guestBus,
-- 
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]