[PATCH] libxl_driver.c: cleanup code

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

 



Following Jim's comments about "add pci passthrough to libxl" patch:
https://www.redhat.com/archives/libvir-list/2014-March/msg00170.html

Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 src/libxl/libxl_driver.c | 47 +++++++++++++++++++----------------------------
 1 file changed, 19 insertions(+), 28 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index a6ba10a..4d22fb7 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3357,10 +3357,10 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
     if (virHostdevPreparePCIDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
                                     vm->def->name, vm->def->uuid,
                                     &hostdev, 1, 0) < 0)
-        goto cleanup;
+        return -1;
 
     if (libxlMakePci(hostdev, &pcidev) < 0)
-        goto reattach_hostdev;
+        goto error;
 
     if (libxl_device_pci_add(priv->ctx, vm->def->id, &pcidev, 0) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3369,17 +3369,15 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
                        hostdev->source.subsys.u.pci.addr.bus,
                        hostdev->source.subsys.u.pci.addr.slot,
                        hostdev->source.subsys.u.pci.addr.function);
-        goto reattach_hostdev;
+        goto error;
     }
 
     vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
     return 0;
 
-reattach_hostdev:
+error:
     virHostdevReAttachPCIDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
                                  vm->def->name, &hostdev, 1, NULL);
-
-cleanup:
     return -1;
 }
 
@@ -3401,20 +3399,17 @@ libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver,
     switch (hostdev->source.subsys.type) {
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
         if (libxlDomainAttachHostPCIDevice(driver, priv, vm, hostdev) < 0)
-            goto error;
+            return -1;
         break;
 
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("hostdev subsys type '%s' not supported"),
                        virDomainHostdevSubsysTypeToString(hostdev->source.subsys.type));
-        goto error;
+        return -1;
     }
 
     return 0;
-
-error:
-    return -1;
 }
 
 static int
@@ -3608,14 +3603,14 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
                        _("cannot hot unplug multifunction PCI device: %.4x:%.2x:%.2x.%.1x"),
                        subsys->u.pci.addr.domain, subsys->u.pci.addr.bus,
                        subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
-        goto cleanup;
+        goto error;
     }
 
 
     libxl_device_pci_init(&pcidev);
 
     if (libxlMakePci(detach, &pcidev) < 0)
-        goto cleanup;
+        goto error;
 
     if (libxl_device_pci_remove(priv->ctx, vm->def->id, &pcidev, 0) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3623,7 +3618,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
                           %.4x:%.2x:%.2x.%.1x"),
                        subsys->u.pci.addr.domain, subsys->u.pci.addr.bus,
                        subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
-        goto cleanup;
+        goto error;
     }
 
     libxl_device_pci_dispose(&pcidev);
@@ -3635,7 +3630,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
 
     return 0;
 
-cleanup:
+error:
     virDomainHostdevDefFree(detach);
     return -1;
 }
@@ -4897,7 +4892,6 @@ libxlNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
                           unsigned *function)
 {
     virNodeDevCapsDefPtr cap;
-    int ret = -1;
 
     cap = def->caps;
     while (cap) {
@@ -4915,12 +4909,10 @@ libxlNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
     if (!cap) {
         virReportError(VIR_ERR_INVALID_ARG,
                        _("device %s is not a PCI device"), def->name);
-        goto out;
+        return -1;
     }
 
-    ret = 0;
-out:
-    return ret;
+    return 0;
 }
 
 static int
@@ -5012,12 +5004,12 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev)
         goto cleanup;
 
     if (virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci) < 0)
-        goto out;
+        goto cleanup;
 
     ret = 0;
-out:
-    virPCIDeviceFree(pci);
+
 cleanup:
+    virPCIDeviceFree(pci);
     virNodeDeviceDefFree(def);
     VIR_FREE(xml);
     return ret;
@@ -5026,7 +5018,7 @@ cleanup:
 static int
 libxlNodeDeviceReset(virNodeDevicePtr dev)
 {
-    virPCIDevicePtr pci;
+    virPCIDevicePtr pci = NULL;
     unsigned domain = 0, bus = 0, slot = 0, function = 0;
     int ret = -1;
     virNodeDeviceDefPtr def = NULL;
@@ -5053,18 +5045,17 @@ libxlNodeDeviceReset(virNodeDevicePtr dev)
         goto cleanup;
 
     if (virHostdevPCINodeDeviceReset(hostdev_mgr, pci) < 0)
-        goto out;
+        goto cleanup;
 
     ret = 0;
-out:
-    virPCIDeviceFree(pci);
+
 cleanup:
+    virPCIDeviceFree(pci);
     virNodeDeviceDefFree(def);
     VIR_FREE(xml);
     return ret;
 }
 
-
 static virDriver libxlDriver = {
     .no = VIR_DRV_LIBXL,
     .name = LIBXL_DRIVER_NAME,
-- 
1.7.12.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]