[PATCH 11/15] nodedev: Keep the node device lock longer in nodeDeviceDestroy

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

 



While perhaps improbable, it could be possible that after finding our
object that another thread running essentially in parallel could attempt
to delete the same vHBA.

So rather than dropping the lock right after finding the object, keep
the lock around while we drop the object lock and work on deleting the
object. Once the delete occurs we can safely drop the driver lock again.

Cleanup some of the usage of cleanup instead out for the goto label.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/node_device/node_device_driver.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 99eb56c..52f8058 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -639,21 +639,18 @@ nodeDeviceDestroy(virNodeDevicePtr dev)
     int parent_host = -1;
 
     nodeDeviceLock();
-    obj = virNodeDeviceFindByName(&driver->devs, dev->name);
-    nodeDeviceUnlock();
-
-    if (!obj) {
+    if (!(obj = virNodeDeviceFindByName(&driver->devs, dev->name))) {
         virReportError(VIR_ERR_NO_NODE_DEVICE,
                        _("no node device with matching name '%s'"),
                        dev->name);
-        goto out;
+        goto cleanup;
     }
 
     if (virNodeDeviceDestroyEnsureACL(dev->conn, obj->def) < 0)
-        goto out;
+        goto cleanup;
 
-    if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1)
-        goto out;
+    if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) < 0)
+        goto cleanup;
 
 
     /* virNodeDeviceGetParentHost will cause the device object's lock to be
@@ -663,20 +660,21 @@ nodeDeviceDestroy(virNodeDevicePtr dev)
     if (VIR_STRDUP(parent_name, obj->def->parent) < 0) {
         virNodeDeviceObjUnlock(obj);
         obj = NULL;
-        goto out;
+        goto cleanup;
     }
     virNodeDeviceObjUnlock(obj);
     obj = NULL;
 
     if (virNodeDeviceGetParentHost(&driver->devs, dev->name, parent_name,
                                    &parent_host) < 0)
-        goto out;
+        goto cleanup;
 
     if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0)
-        goto out;
+        goto cleanup;
 
     ret = 0;
- out:
+ cleanup:
+    nodeDeviceUnlock();
     if (obj)
         virNodeDeviceObjUnlock(obj);
     VIR_FREE(parent_name);
-- 
2.7.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]
  Powered by Linux