[PATCH 3/4] nodedev: Return with locked obj from virNodeDeviceObjListRemove

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

 



Rather than unlock the object that was expected to be locked on
input, let the caller perform the unlock or more succinctly a
virNodeDeviceObjEndAPI on the object which will perform the Unref
and Unlock and clear the @obj.

Also add comments for virNodeDeviceObjListRemove.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/virnodedeviceobj.c        | 13 ++++++++++++-
 src/node_device/node_device_hal.c  |  4 ++--
 src/node_device/node_device_udev.c |  2 +-
 src/test/test_driver.c             |  4 +---
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index ad0f27ee47..a5939c5de5 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -470,6 +470,18 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs,
 }
 
 
+/*
+ * virNodeDeviceObjListRemove:
+ * @devs: list of node device objects
+ * @obj: a node device object
+ *
+ * Remove @obj from the node device obj list hash table. The caller must hold
+ * the lock on @obj to ensure no one else is either waiting for @obj or
+ * still using it.
+ *
+ * Upon return the @obj remains locked with at least 1 reference and
+ * the caller is expected to use virNodeDeviceObjEndAPI on it.
+ */
 void
 virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs,
                            virNodeDeviceObjPtr obj)
@@ -485,7 +497,6 @@ virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs,
     virObjectRWLockWrite(devs);
     virObjectLock(obj);
     virHashRemoveEntry(devs->objs, def->name);
-    virObjectUnlock(obj);
     virObjectUnref(obj);
     virObjectRWUnlock(devs);
 }
diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index 6ad56f4166..8aac806a64 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -512,7 +512,7 @@ dev_refresh(const char *udi)
          * to sub-capabilities (like net.80203) is nasty ... so avoid it.
          */
         virNodeDeviceObjListRemove(driver->devs, obj);
-        virObjectUnref(obj);
+        virNodeDeviceObjEndAPI(&obj);
         dev_create(udi);
     } else {
         VIR_DEBUG("no device named %s", name);
@@ -541,7 +541,7 @@ device_removed(LibHalContext *ctx ATTRIBUTE_UNUSED,
         virNodeDeviceObjListRemove(driver->devs, obj);
     else
         VIR_DEBUG("no device named %s", name);
-    virObjectUnref(obj);
+    virNodeDeviceObjEndAPI(&obj);
 }
 
 
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index e87eb32a85..1151b04ecb 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1298,7 +1298,7 @@ udevRemoveOneDevice(struct udev_device *device)
     VIR_DEBUG("Removing device '%s' with sysfs path '%s'",
               def->name, name);
     virNodeDeviceObjListRemove(driver->devs, obj);
-    virObjectUnref(obj);
+    virNodeDeviceObjEndAPI(&obj);
 
     if (event)
         virObjectEventStateQueue(driver->nodeDeviceEventState, event);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index b0aa350d95..a7aaabe09b 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4716,7 +4716,7 @@ testDestroyVport(testDriverPtr privconn,
                                            0);
 
     virNodeDeviceObjListRemove(privconn->devs, obj);
-    virObjectUnref(obj);
+    virNodeDeviceObjEndAPI(&obj);
 
     testObjectEventQueue(privconn, event);
     return 0;
@@ -5695,8 +5695,6 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
 
     virObjectLock(obj);
     virNodeDeviceObjListRemove(driver->devs, obj);
-    virObjectUnref(obj);
-    obj = NULL;
 
  cleanup:
     virNodeDeviceObjEndAPI(&obj);
-- 
2.13.6

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