[PATCH 1/4] secret: Return with locked obj from virSecretObjListRemove

[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
virSecretObjEndAPI on the object which will perform the Unref
and Unlock and clear the @obj.

Also clean up the virSecretObjListRemove function comments.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/virsecretobj.c    | 15 ++++++++-------
 src/secret/secret_driver.c |  4 ----
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index 47e0b28968..49c341484b 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -284,11 +284,14 @@ virSecretObjListFindByUsage(virSecretObjListPtr secrets,
 /*
  * virSecretObjListRemove:
  * @secrets: list of secret objects
- * @secret: a secret object
+ * @obj: a secret object
  *
- * Remove the object from the hash table.  The caller must hold the lock
- * on the driver owning @secrets and must have also locked @secret to
- * ensure no one else is either waiting for @secret or still using it.
+ * Remove @obj from the secret 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 virSecretObjEndAPI on it.
  */
 void
 virSecretObjListRemove(virSecretObjListPtr secrets,
@@ -308,7 +311,6 @@ virSecretObjListRemove(virSecretObjListPtr secrets,
     virObjectRWLockWrite(secrets);
     virObjectLock(obj);
     virHashRemoveEntry(secrets->objs, uuidstr);
-    virObjectUnlock(obj);
     virObjectUnref(obj);
     virObjectRWUnlock(secrets);
 }
@@ -927,8 +929,7 @@ virSecretLoad(virSecretObjListPtr secrets,
 
     if (virSecretLoadValue(obj) < 0) {
         virSecretObjListRemove(secrets, obj);
-        virObjectUnref(obj);
-        obj = NULL;
+        virSecretObjEndAPI(&obj); /* clears obj */
     }
 
  cleanup:
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 23a3c9bdad..7c611253aa 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -271,8 +271,6 @@ secretDefineXML(virConnectPtr conn,
         VIR_STEAL_PTR(def, objDef);
     } else {
         virSecretObjListRemove(driver->secrets, obj);
-        virObjectUnref(obj);
-        obj = NULL;
     }
 
  cleanup:
@@ -413,8 +411,6 @@ secretUndefine(virSecretPtr secret)
     virSecretObjDeleteData(obj);
 
     virSecretObjListRemove(driver->secrets, obj);
-    virObjectUnref(obj);
-    obj = NULL;
 
     ret = 0;
 
-- 
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