]> Git Repo - qemu.git/commitdiff
refactor drive_hot_add
authorGerd Hoffmann <[email protected]>
Fri, 25 Sep 2009 19:42:47 +0000 (21:42 +0200)
committerAnthony Liguori <[email protected]>
Mon, 5 Oct 2009 14:32:49 +0000 (09:32 -0500)
move pci device lookup into the "case IF_SCSI" section, so we
can do something else for other interface types.

Signed-off-by: Gerd Hoffmann <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>
hw/pci-hotplug.c

index 2cc43c3f249d2cb568da6ca1aee717e6efbbf053..833d5d8a984ce9270633d7957616df400d0ad9cf 100644 (file)
@@ -58,48 +58,48 @@ void drive_hot_add(Monitor *mon, const QDict *qdict)
     int dom, pci_bus;
     unsigned slot;
     int type, bus;
-    int success = 0;
     PCIDevice *dev;
-    DriveInfo *dinfo;
+    DriveInfo *dinfo = NULL;
     const char *pci_addr = qdict_get_str(qdict, "pci_addr");
     const char *opts = qdict_get_str(qdict, "opts");
     BusState *scsibus;
 
-    if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) {
-        return;
-    }
-
-    dev = pci_find_device(pci_bus, slot, 0);
-    if (!dev) {
-        monitor_printf(mon, "no pci device with address %s\n", pci_addr);
-        return;
-    }
-
     dinfo = add_init_drive(opts);
     if (!dinfo)
-        return;
+        goto err;
     if (dinfo->devaddr) {
         monitor_printf(mon, "Parameter addr not supported\n");
-        return;
+        goto err;
     }
     type = dinfo->type;
     bus = drive_get_max_bus (type);
 
     switch (type) {
     case IF_SCSI:
-        success = 1;
+        if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) {
+            goto err;
+        }
+        dev = pci_find_device(pci_bus, slot, 0);
+        if (!dev) {
+            monitor_printf(mon, "no pci device with address %s\n", pci_addr);
+            goto err;
+        }
         scsibus = QLIST_FIRST(&dev->qdev.child_bus);
         scsi_bus_legacy_add_drive(DO_UPCAST(SCSIBus, qbus, scsibus),
                                   dinfo, dinfo->unit);
+        monitor_printf(mon, "OK bus %d, unit %d\n",
+                       dinfo->bus,
+                       dinfo->unit);
         break;
     default:
         monitor_printf(mon, "Can't hot-add drive to type %d\n", type);
+        goto err;
     }
+    return;
 
-    if (success)
-        monitor_printf(mon, "OK bus %d, unit %d\n",
-                       dinfo->bus,
-                       dinfo->unit);
+err:
+    if (dinfo)
+        drive_uninit(dinfo);
     return;
 }
 
This page took 0.027556 seconds and 4 git commands to generate.