[PATCH 40/43] util: virObjectRWLockable: convert virRWLock to GRWLock

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/conf/virdomainobjlist.c          | 35 ++++++++++---------
 src/conf/virinterfaceobj.c           | 18 +++++-----
 src/conf/virnetworkobj.c             | 20 +++++------
 src/conf/virnodedeviceobj.c          | 16 ++++-----
 src/conf/virnwfilterbindingobjlist.c | 14 ++++----
 src/conf/virsecretobj.c              | 16 ++++-----
 src/conf/virstorageobj.c             | 50 ++++++++++++++--------------
 src/libvirt_private.syms             |  3 +-
 src/util/virobject.c                 | 27 +++++++++------
 src/util/virobject.h                 |  8 +++--
 10 files changed, 110 insertions(+), 97 deletions(-)

diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index 417025ae9f..f3d4d81bb1 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -120,7 +120,7 @@ virDomainObjListFindByID(virDomainObjListPtr doms,
     virObjectRWLockRead(doms);
     obj = virHashSearch(doms->objs, virDomainObjListSearchID, &id, NULL);
     virObjectRef(obj);
-    virObjectRWUnlock(doms);
+    virObjectRWUnlockRead(doms);
     if (obj) {
         virObjectLock(obj);
         if (obj->removing) {
@@ -167,7 +167,7 @@ virDomainObjListFindByUUID(virDomainObjListPtr doms,
 
     virObjectRWLockRead(doms);
     obj = virDomainObjListFindByUUIDLocked(doms, uuid);
-    virObjectRWUnlock(doms);
+    virObjectRWUnlockRead(doms);
 
     if (obj && obj->removing) {
         virObjectUnlock(obj);
@@ -210,7 +210,7 @@ virDomainObjListFindByName(virDomainObjListPtr doms,
 
     virObjectRWLockRead(doms);
     obj = virDomainObjListFindByNameLocked(doms, name);
-    virObjectRWUnlock(doms);
+    virObjectRWUnlockRead(doms);
 
     if (obj && obj->removing) {
         virObjectUnlock(obj);
@@ -361,7 +361,7 @@ virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms,
 
     virObjectRWLockWrite(doms);
     ret = virDomainObjListAddLocked(doms, def, xmlopt, flags, oldDef);
-    virObjectRWUnlock(doms);
+    virObjectRWUnlockWrite(doms);
     return ret;
 }
 
@@ -409,7 +409,7 @@ virDomainObjListRemove(virDomainObjListPtr doms,
     virObjectLock(dom);
     virDomainObjListRemoveLocked(doms, dom);
     virObjectUnref(dom);
-    virObjectRWUnlock(doms);
+    virObjectRWUnlockWrite(doms);
 }
 
 
@@ -475,7 +475,7 @@ virDomainObjListRename(virDomainObjListPtr doms,
 
     ret = 0;
  cleanup:
-    virObjectRWUnlock(doms);
+    virObjectRWUnlockWrite(doms);
     VIR_FREE(old_name);
     return ret;
 }
@@ -634,7 +634,7 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
     }
 
     VIR_DIR_CLOSE(dir);
-    virObjectRWUnlock(doms);
+    virObjectRWUnlockWrite(doms);
     return ret;
 }
 
@@ -680,7 +680,7 @@ virDomainObjListNumOfDomains(virDomainObjListPtr doms,
     struct virDomainObjListData data = { filter, conn, active, 0 };
     virObjectRWLockRead(doms);
     virHashForEach(doms->objs, virDomainObjListCount, &data);
-    virObjectRWUnlock(doms);
+    virObjectRWUnlockRead(doms);
     return data.count;
 }
 
@@ -724,7 +724,7 @@ virDomainObjListGetActiveIDs(virDomainObjListPtr doms,
                                     0, maxids, ids };
     virObjectRWLockRead(doms);
     virHashForEach(doms->objs, virDomainObjListCopyActiveIDs, &data);
-    virObjectRWUnlock(doms);
+    virObjectRWUnlockRead(doms);
     return data.numids;
 }
 
@@ -777,7 +777,7 @@ virDomainObjListGetInactiveNames(virDomainObjListPtr doms,
     size_t i;
     virObjectRWLockRead(doms);
     virHashForEach(doms->objs, virDomainObjListCopyInactiveNames, &data);
-    virObjectRWUnlock(doms);
+    virObjectRWUnlockRead(doms);
     if (data.oom) {
         for (i = 0; i < data.numnames; i++)
             VIR_FREE(data.names[i]);
@@ -839,7 +839,10 @@ virDomainObjListForEach(virDomainObjListPtr doms,
     else
         virObjectRWLockRead(doms);
     virHashForEach(doms->objs, virDomainObjListHelper, &data);
-    virObjectRWUnlock(doms);
+    if (modify)
+        virObjectRWUnlockWrite(doms);
+    else
+        virObjectRWUnlockRead(doms);
     return data.ret;
 }
 
@@ -982,12 +985,12 @@ virDomainObjListCollect(virDomainObjListPtr domlist,
     virObjectRWLockRead(domlist);
     sa_assert(domlist->objs);
     if (VIR_ALLOC_N(data.vms, virHashSize(domlist->objs)) < 0) {
-        virObjectRWUnlock(domlist);
+        virObjectRWUnlockRead(domlist);
         return -1;
     }
 
     virHashForEach(domlist->objs, virDomainObjListCollectIterator, &data);
-    virObjectRWUnlock(domlist);
+    virObjectRWUnlockRead(domlist);
 
     virDomainObjListFilter(&data.vms, &data.nvms, conn, filter, flags);
 
@@ -1026,7 +1029,7 @@ virDomainObjListConvert(virDomainObjListPtr domlist,
             if (skip_missing)
                 continue;
 
-            virObjectRWUnlock(domlist);
+            virObjectRWUnlockRead(domlist);
             virReportError(VIR_ERR_NO_DOMAIN,
                            _("no domain with matching uuid '%s' (%s)"),
                            uuidstr, dom->name);
@@ -1036,12 +1039,12 @@ virDomainObjListConvert(virDomainObjListPtr domlist,
         virObjectRef(vm);
 
         if (VIR_APPEND_ELEMENT(*vms, *nvms, vm) < 0) {
-            virObjectRWUnlock(domlist);
+            virObjectRWUnlockRead(domlist);
             virObjectUnref(vm);
             goto error;
         }
     }
-    virObjectRWUnlock(domlist);
+    virObjectRWUnlockRead(domlist);
 
     sa_assert(*vms);
     virDomainObjListFilter(vms, nvms, conn, filter, flags);
diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index 43ba395d2b..f52ff88c2a 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -200,7 +200,7 @@ virInterfaceObjListFindByMACString(virInterfaceObjListPtr interfaces,
     virObjectRWLockRead(interfaces);
     virHashForEach(interfaces->objsName, virInterfaceObjListFindByMACStringCb,
                    &data);
-    virObjectRWUnlock(interfaces);
+    virObjectRWUnlockRead(interfaces);
 
     if (data.error)
         goto error;
@@ -230,7 +230,7 @@ virInterfaceObjListFindByName(virInterfaceObjListPtr interfaces,
     virInterfaceObjPtr obj;
     virObjectRWLockRead(interfaces);
     obj = virInterfaceObjListFindByNameLocked(interfaces, name);
-    virObjectRWUnlock(interfaces);
+    virObjectRWUnlockRead(interfaces);
     if (obj)
         virObjectLock(obj);
 
@@ -337,7 +337,7 @@ virInterfaceObjListExport(virConnectPtr conn,
 
     ret = data.nifaces;
  cleanup:
-    virObjectRWUnlock(ifaceobjs);
+    virObjectRWUnlockRead(ifaceobjs);
     while (data.ifaces && data.nifaces)
         virObjectUnref(data.ifaces[--data.nifaces]);
 
@@ -413,7 +413,7 @@ virInterfaceObjListClone(virInterfaceObjListPtr interfaces)
 
     virObjectRWLockRead(interfaces);
     virHashForEach(interfaces->objsName, virInterfaceObjListCloneCb, &data);
-    virObjectRWUnlock(interfaces);
+    virObjectRWUnlockRead(interfaces);
 
     if (data.error)
         goto error;
@@ -445,13 +445,13 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr interfaces,
     }
 
     obj->def = def;
-    virObjectRWUnlock(interfaces);
+    virObjectRWUnlockWrite(interfaces);
 
     return obj;
 
  error:
     virInterfaceObjEndAPI(&obj);
-    virObjectRWUnlock(interfaces);
+    virObjectRWUnlockWrite(interfaces);
     return NULL;
 }
 
@@ -470,7 +470,7 @@ virInterfaceObjListRemove(virInterfaceObjListPtr interfaces,
     virHashRemoveEntry(interfaces->objsName, obj->def->name);
     virObjectUnlock(obj);
     virObjectUnref(obj);
-    virObjectRWUnlock(interfaces);
+    virObjectRWUnlockWrite(interfaces);
 }
 
 
@@ -507,7 +507,7 @@ virInterfaceObjListNumOfInterfaces(virInterfaceObjListPtr interfaces,
     virObjectRWLockRead(interfaces);
     virHashForEach(interfaces->objsName, virInterfaceObjListNumOfInterfacesCb,
                    &data);
-    virObjectRWUnlock(interfaces);
+    virObjectRWUnlockRead(interfaces);
 
     return data.count;
 }
@@ -562,7 +562,7 @@ virInterfaceObjListGetNames(virInterfaceObjListPtr interfaces,
 
     virObjectRWLockRead(interfaces);
     virHashForEach(interfaces->objsName, virInterfaceObjListGetNamesCb, &data);
-    virObjectRWUnlock(interfaces);
+    virObjectRWUnlockRead(interfaces);
 
     if (data.error)
         goto error;
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index b2affaacd3..d47e2ab793 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -395,7 +395,7 @@ virNetworkObjFindByUUID(virNetworkObjListPtr nets,
 
     virObjectRWLockRead(nets);
     obj = virNetworkObjFindByUUIDLocked(nets, uuid);
-    virObjectRWUnlock(nets);
+    virObjectRWUnlockRead(nets);
     if (obj)
         virObjectLock(obj);
     return obj;
@@ -449,7 +449,7 @@ virNetworkObjFindByName(virNetworkObjListPtr nets,
 
     virObjectRWLockRead(nets);
     obj = virNetworkObjFindByNameLocked(nets, name);
-    virObjectRWUnlock(nets);
+    virObjectRWUnlockRead(nets);
     if (obj)
         virObjectLock(obj);
     return obj;
@@ -652,7 +652,7 @@ virNetworkObjAssignDef(virNetworkObjListPtr nets,
 
     virObjectRWLockWrite(nets);
     obj = virNetworkObjAssignDefLocked(nets, def, flags);
-    virObjectRWUnlock(nets);
+    virObjectRWUnlockWrite(nets);
     return obj;
 }
 
@@ -805,7 +805,7 @@ virNetworkObjRemoveInactive(virNetworkObjListPtr nets,
     virObjectRWLockWrite(nets);
     virObjectLock(obj);
     virHashRemoveEntry(nets->objs, uuidstr);
-    virObjectRWUnlock(nets);
+    virObjectRWUnlockWrite(nets);
     virObjectUnref(obj);
 }
 
@@ -1218,7 +1218,7 @@ virNetworkObjBridgeInUse(virNetworkObjListPtr nets,
 
     virObjectRWLockRead(nets);
     obj = virHashSearch(nets->objs, virNetworkObjBridgeInUseHelper, &data, NULL);
-    virObjectRWUnlock(nets);
+    virObjectRWUnlockRead(nets);
 
     return obj != NULL;
 }
@@ -1428,7 +1428,7 @@ virNetworkObjListExport(virConnectPtr conn,
 
     ret = data.nnets;
  cleanup:
-    virObjectRWUnlock(netobjs);
+    virObjectRWUnlockWrite(netobjs);
     while (data.nets && data.nnets)
         virObjectUnref(data.nets[--data.nnets]);
 
@@ -1478,7 +1478,7 @@ virNetworkObjListForEach(virNetworkObjListPtr nets,
         .callback = callback, .opaque = opaque, .ret = 0};
     virObjectRWLockRead(nets);
     virHashForEach(nets->objs, virNetworkObjListForEachHelper, &data);
-    virObjectRWUnlock(nets);
+    virObjectRWUnlockRead(nets);
     return data.ret;
 }
 
@@ -1543,7 +1543,7 @@ virNetworkObjListGetNames(virNetworkObjListPtr nets,
 
     virObjectRWLockRead(nets);
     virHashForEach(nets->objs, virNetworkObjListGetHelper, &data);
-    virObjectRWUnlock(nets);
+    virObjectRWUnlockRead(nets);
 
     if (data.error)
         goto cleanup;
@@ -1570,7 +1570,7 @@ virNetworkObjListNumOfNetworks(virNetworkObjListPtr nets,
 
     virObjectRWLockRead(nets);
     virHashForEach(nets->objs, virNetworkObjListGetHelper, &data);
-    virObjectRWUnlock(nets);
+    virObjectRWUnlockRead(nets);
 
     return data.nnames;
 }
@@ -1612,7 +1612,7 @@ virNetworkObjListPrune(virNetworkObjListPtr nets,
 
     virObjectRWLockWrite(nets);
     virHashRemoveSet(nets->objs, virNetworkObjListPruneHelper, &data);
-    virObjectRWUnlock(nets);
+    virObjectRWUnlockWrite(nets);
 }
 
 
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index 3a34a324ca..14abf77cbf 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -188,7 +188,7 @@ virNodeDeviceObjListSearch(virNodeDeviceObjListPtr devs,
     virObjectRWLockRead(devs);
     obj = virHashSearch(devs->objs, callback, data, NULL);
     virObjectRef(obj);
-    virObjectRWUnlock(devs);
+    virObjectRWUnlockRead(devs);
 
     if (obj)
         virObjectLock(obj);
@@ -241,7 +241,7 @@ virNodeDeviceObjListFindByName(virNodeDeviceObjListPtr devs,
 
     virObjectRWLockRead(devs);
     obj = virNodeDeviceObjListFindByNameLocked(devs, name);
-    virObjectRWUnlock(devs);
+    virObjectRWUnlockRead(devs);
     if (obj)
         virObjectLock(obj);
 
@@ -462,7 +462,7 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs,
     }
 
  cleanup:
-    virObjectRWUnlock(devs);
+    virObjectRWUnlockWrite(devs);
     return obj;
 }
 
@@ -484,7 +484,7 @@ virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs,
     virHashRemoveEntry(devs->objs, def->name);
     virObjectUnlock(obj);
     virObjectUnref(obj);
-    virObjectRWUnlock(devs);
+    virObjectRWUnlockWrite(devs);
 }
 
 
@@ -724,7 +724,7 @@ virNodeDeviceObjListNumOfDevices(virNodeDeviceObjListPtr devs,
 
     virObjectRWLockRead(devs);
     virHashForEach(devs->objs, virNodeDeviceObjListNumOfDevicesCallback, &data);
-    virObjectRWUnlock(devs);
+    virObjectRWUnlockRead(devs);
 
     return data.count;
 }
@@ -784,7 +784,7 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr devs,
 
     virObjectRWLockRead(devs);
     virHashForEach(devs->objs, virNodeDeviceObjListGetNamesCallback, &data);
-    virObjectRWUnlock(devs);
+    virObjectRWUnlockRead(devs);
 
     if (data.error)
         goto error;
@@ -896,12 +896,12 @@ virNodeDeviceObjListExport(virConnectPtr conn,
     virObjectRWLockRead(devs);
     if (devices &&
         VIR_ALLOC_N(data.devices, virHashSize(devs->objs) + 1) < 0) {
-        virObjectRWUnlock(devs);
+        virObjectRWUnlockRead(devs);
         return -1;
     }
 
     virHashForEach(devs->objs, virNodeDeviceObjListExportCallback, &data);
-    virObjectRWUnlock(devs);
+    virObjectRWUnlockRead(devs);
 
     if (data.error)
         goto cleanup;
diff --git a/src/conf/virnwfilterbindingobjlist.c b/src/conf/virnwfilterbindingobjlist.c
index 97e4d3c49b..64b75a0cc3 100644
--- a/src/conf/virnwfilterbindingobjlist.c
+++ b/src/conf/virnwfilterbindingobjlist.c
@@ -115,7 +115,7 @@ virNWFilterBindingObjListFindByPortDev(virNWFilterBindingObjListPtr bindings,
 
     virObjectRWLockRead(bindings);
     obj = virNWFilterBindingObjListFindByPortDevLocked(bindings, name);
-    virObjectRWUnlock(bindings);
+    virObjectRWUnlockRead(bindings);
 
     if (obj && virNWFilterBindingObjGetRemoving(obj)) {
         virObjectUnlock(obj);
@@ -212,7 +212,7 @@ virNWFilterBindingObjListAdd(virNWFilterBindingObjListPtr bindings,
 
     virObjectRWLockWrite(bindings);
     ret = virNWFilterBindingObjListAddLocked(bindings, def);
-    virObjectRWUnlock(bindings);
+    virObjectRWUnlockWrite(bindings);
     return ret;
 }
 
@@ -256,7 +256,7 @@ virNWFilterBindingObjListRemove(virNWFilterBindingObjListPtr bindings,
     virObjectLock(binding);
     virNWFilterBindingObjListRemoveLocked(bindings, binding);
     virObjectUnref(binding);
-    virObjectRWUnlock(bindings);
+    virObjectRWUnlockWrite(bindings);
 }
 
 
@@ -331,7 +331,7 @@ virNWFilterBindingObjListLoadAllConfigs(virNWFilterBindingObjListPtr bindings,
     }
 
     VIR_DIR_CLOSE(dir);
-    virObjectRWUnlock(bindings);
+    virObjectRWUnlockWrite(bindings);
     return ret;
 }
 
@@ -366,7 +366,7 @@ virNWFilterBindingObjListForEach(virNWFilterBindingObjListPtr bindings,
     };
     virObjectRWLockRead(bindings);
     virHashForEach(bindings->objs, virNWFilterBindingObjListHelper, &data);
-    virObjectRWUnlock(bindings);
+    virObjectRWUnlockRead(bindings);
     return data.ret;
 }
 
@@ -435,12 +435,12 @@ virNWFilterBindingObjListCollect(virNWFilterBindingObjListPtr domlist,
     virObjectRWLockRead(domlist);
     sa_assert(domlist->objs);
     if (VIR_ALLOC_N(data.bindings, virHashSize(domlist->objs)) < 0) {
-        virObjectRWUnlock(domlist);
+        virObjectRWUnlockRead(domlist);
         return -1;
     }
 
     virHashForEach(domlist->objs, virNWFilterBindingObjListCollectIterator, &data);
-    virObjectRWUnlock(domlist);
+    virObjectRWUnlockRead(domlist);
 
     virNWFilterBindingObjListFilter(&data.bindings, &data.nbindings, conn, filter);
 
diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index 81c9f2c346..77cf03ad74 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -188,7 +188,7 @@ virSecretObjListFindByUUID(virSecretObjListPtr secrets,
 
     virObjectRWLockRead(secrets);
     obj = virSecretObjListFindByUUIDLocked(secrets, uuidstr);
-    virObjectRWUnlock(secrets);
+    virObjectRWUnlockRead(secrets);
     if (obj)
         virObjectLock(obj);
     return obj;
@@ -267,7 +267,7 @@ virSecretObjListFindByUsage(virSecretObjListPtr secrets,
 
     virObjectRWLockRead(secrets);
     obj = virSecretObjListFindByUsageLocked(secrets, usageType, usageID);
-    virObjectRWUnlock(secrets);
+    virObjectRWUnlockRead(secrets);
     if (obj)
         virObjectLock(obj);
     return obj;
@@ -303,7 +303,7 @@ virSecretObjListRemove(virSecretObjListPtr secrets,
     virHashRemoveEntry(secrets->objs, uuidstr);
     virObjectUnlock(obj);
     virObjectUnref(obj);
-    virObjectRWUnlock(secrets);
+    virObjectRWUnlockWrite(secrets);
 }
 
 
@@ -397,7 +397,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
 
  cleanup:
     virSecretObjEndAPI(&obj);
-    virObjectRWUnlock(secrets);
+    virObjectRWUnlockWrite(secrets);
     return ret;
 }
 
@@ -490,7 +490,7 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secrets,
 
     virObjectRWLockRead(secrets);
     virHashForEach(secrets->objs, virSecretObjListNumOfSecretsCallback, &data);
-    virObjectRWUnlock(secrets);
+    virObjectRWUnlockRead(secrets);
 
     return data.count;
 }
@@ -592,12 +592,12 @@ virSecretObjListExport(virConnectPtr conn,
     virObjectRWLockRead(secretobjs);
     if (secrets &&
         VIR_ALLOC_N(data.secrets, virHashSize(secretobjs->objs) + 1) < 0) {
-        virObjectRWUnlock(secretobjs);
+        virObjectRWUnlockRead(secretobjs);
         return -1;
     }
 
     virHashForEach(secretobjs->objs, virSecretObjListExportCallback, &data);
-    virObjectRWUnlock(secretobjs);
+    virObjectRWUnlockRead(secretobjs);
 
     if (data.error)
         goto error;
@@ -629,7 +629,7 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets,
 
     virObjectRWLockRead(secrets);
     virHashForEach(secrets->objs, virSecretObjListGetUUIDsCallback, &data);
-    virObjectRWUnlock(secrets);
+    virObjectRWUnlockRead(secrets);
 
     if (data.error)
         goto error;
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 5cbd30f93c..2f1e9e72aa 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -515,7 +515,7 @@ virStoragePoolObjListSearch(virStoragePoolObjListPtr pools,
 
     virObjectRWLockRead(pools);
     obj = virHashSearch(pools->objs, virStoragePoolObjListSearchCb, &data, NULL);
-    virObjectRWUnlock(pools);
+    virObjectRWUnlockRead(pools);
 
     return virObjectRef(obj);
 }
@@ -535,7 +535,7 @@ virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
     virHashRemoveEntry(pools->objs, uuidstr);
     virHashRemoveEntry(pools->objsName, obj->def->name);
     virObjectUnref(obj);
-    virObjectRWUnlock(pools);
+    virObjectRWUnlockWrite(pools);
 }
 
 
@@ -568,7 +568,7 @@ virStoragePoolObjFindByUUID(virStoragePoolObjListPtr pools,
 
     virObjectRWLockRead(pools);
     obj = virStoragePoolObjFindByUUIDLocked(pools, uuid);
-    virObjectRWUnlock(pools);
+    virObjectRWUnlockRead(pools);
     if (obj)
         virObjectLock(obj);
 
@@ -601,7 +601,7 @@ virStoragePoolObjFindByName(virStoragePoolObjListPtr pools,
 
     virObjectRWLockRead(pools);
     obj = virStoragePoolObjFindByNameLocked(pools, name);
-    virObjectRWUnlock(pools);
+    virObjectRWUnlockRead(pools);
     if (obj)
         virObjectLock(obj);
 
@@ -668,13 +668,13 @@ virStoragePoolObjAddVol(virStoragePoolObjPtr obj,
     virObjectRef(volobj);
 
     volobj->voldef = voldef;
-    virObjectRWUnlock(volumes);
+    virObjectRWUnlockWrite(volumes);
     virStorageVolObjEndAPI(&volobj);
     return 0;
 
  error:
     virStorageVolObjEndAPI(&volobj);
-    virObjectRWUnlock(volumes);
+    virObjectRWUnlockWrite(volumes);
     return -1;
 }
 
@@ -691,7 +691,7 @@ virStoragePoolObjRemoveVol(virStoragePoolObjPtr obj,
     if (!volobj) {
         VIR_INFO("Cannot find volume '%s' from storage pool '%s'",
                  voldef->name, obj->def->name);
-        virObjectRWUnlock(volumes);
+        virObjectRWUnlockWrite(volumes);
         return;
     }
     VIR_INFO("Deleting volume '%s' from storage pool '%s'",
@@ -704,7 +704,7 @@ virStoragePoolObjRemoveVol(virStoragePoolObjPtr obj,
     virHashRemoveEntry(volumes->objsPath, voldef->target.path);
     virStorageVolObjEndAPI(&volobj);
 
-    virObjectRWUnlock(volumes);
+    virObjectRWUnlockWrite(volumes);
 }
 
 
@@ -715,7 +715,7 @@ virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj)
 
     virObjectRWLockRead(obj->volumes);
     nbElems = virHashSize(obj->volumes->objsKey);
-    virObjectRWUnlock(obj->volumes);
+    virObjectRWUnlockRead(obj->volumes);
 
     return nbElems;
 }
@@ -755,7 +755,7 @@ virStoragePoolObjForEachVolume(virStoragePoolObjPtr obj,
     virObjectRWLockRead(obj->volumes);
     virHashForEach(obj->volumes->objsKey, virStoragePoolObjForEachVolumeCb,
                    &data);
-    virObjectRWUnlock(obj->volumes);
+    virObjectRWUnlockRead(obj->volumes);
     return 0;
 }
 
@@ -797,7 +797,7 @@ virStoragePoolObjSearchVolume(virStoragePoolObjPtr obj,
     volobj = virHashSearch(obj->volumes->objsKey,
                            virStoragePoolObjSearchVolumeCb,
                            &data, NULL);
-    virObjectRWUnlock(obj->volumes);
+    virObjectRWUnlockRead(obj->volumes);
 
     if (volobj)
         return volobj->voldef;
@@ -814,7 +814,7 @@ virStorageVolDefFindByKey(virStoragePoolObjPtr obj,
 
     virObjectRWLockRead(obj->volumes);
     volobj = virHashLookup(obj->volumes->objsKey, key);
-    virObjectRWUnlock(obj->volumes);
+    virObjectRWUnlockRead(obj->volumes);
 
     if (volobj)
         return volobj->voldef;
@@ -830,7 +830,7 @@ virStorageVolDefFindByPath(virStoragePoolObjPtr obj,
 
     virObjectRWLockRead(obj->volumes);
     volobj = virHashLookup(obj->volumes->objsPath, path);
-    virObjectRWUnlock(obj->volumes);
+    virObjectRWUnlockRead(obj->volumes);
 
     if (volobj)
         return volobj->voldef;
@@ -846,7 +846,7 @@ virStorageVolDefFindByName(virStoragePoolObjPtr obj,
 
     virObjectRWLockRead(obj->volumes);
     volobj = virHashLookup(obj->volumes->objsName, name);
-    virObjectRWUnlock(obj->volumes);
+    virObjectRWUnlockRead(obj->volumes);
 
     if (volobj)
         return volobj->voldef;
@@ -895,7 +895,7 @@ virStoragePoolObjNumOfVolumes(virStoragePoolObjPtr obj,
 
     virObjectRWLockRead(volumes);
     virHashForEach(volumes->objsName, virStoragePoolObjNumOfVolumesCb, &data);
-    virObjectRWUnlock(volumes);
+    virObjectRWUnlockRead(volumes);
 
     return data.count;
 }
@@ -956,7 +956,7 @@ virStoragePoolObjVolumeGetNames(virStoragePoolObjPtr obj,
 
     virObjectRWLockRead(volumes);
     virHashForEach(volumes->objsName, virStoragePoolObjVolumeGetNamesCb, &data);
-    virObjectRWUnlock(volumes);
+    virObjectRWUnlockRead(volumes);
 
     if (data.error)
         goto error;
@@ -1032,17 +1032,17 @@ virStoragePoolObjVolumeListExport(virConnectPtr conn,
 
     if (!vols) {
         int ret = virHashSize(volumes->objsName);
-        virObjectRWUnlock(volumes);
+        virObjectRWUnlockRead(volumes);
         return ret;
     }
 
     if (VIR_ALLOC_N(data.vols, virHashSize(volumes->objsName) + 1) < 0) {
-        virObjectRWUnlock(volumes);
+        virObjectRWUnlockRead(volumes);
         return -1;
     }
 
     virHashForEach(volumes->objsName, virStoragePoolObjVolumeListExportCallback, &data);
-    virObjectRWUnlock(volumes);
+    virObjectRWUnlockRead(volumes);
 
     if (data.error)
         goto error;
@@ -1584,7 +1584,7 @@ virStoragePoolObjListAdd(virStoragePoolObjListPtr pools,
         goto error;
     if (rc > 0) {
         virStoragePoolObjAssignDef(obj, def, flags);
-        virObjectRWUnlock(pools);
+        virObjectRWUnlockWrite(pools);
         return obj;
     }
 
@@ -1602,12 +1602,12 @@ virStoragePoolObjListAdd(virStoragePoolObjListPtr pools,
     }
     virObjectRef(obj);
     obj->def = def;
-    virObjectRWUnlock(pools);
+    virObjectRWUnlockWrite(pools);
     return obj;
 
  error:
     virStoragePoolObjEndAPI(&obj);
-    virObjectRWUnlock(pools);
+    virObjectRWUnlockWrite(pools);
     return NULL;
 }
 
@@ -1867,7 +1867,7 @@ virStoragePoolObjNumOfStoragePools(virStoragePoolObjListPtr pools,
 
     virObjectRWLockRead(pools);
     virHashForEach(pools->objs, virStoragePoolObjNumOfStoragePoolsCb, &data);
-    virObjectRWUnlock(pools);
+    virObjectRWUnlockRead(pools);
 
     return data.count;
 }
@@ -1931,7 +1931,7 @@ virStoragePoolObjGetNames(virStoragePoolObjListPtr pools,
 
     virObjectRWLockRead(pools);
     virHashForEach(pools->objs, virStoragePoolObjGetNamesCb, &data);
-    virObjectRWUnlock(pools);
+    virObjectRWUnlockRead(pools);
 
     if (data.error)
         goto error;
@@ -2081,7 +2081,7 @@ virStoragePoolObjListExport(virConnectPtr conn,
         goto error;
 
     virHashForEach(poolobjs->objs, virStoragePoolObjListExportCallback, &data);
-    virObjectRWUnlock(poolobjs);
+    virObjectRWUnlockRead(poolobjs);
 
     if (data.error)
         goto error;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c95c1a078c..c2abbf65c2 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2745,7 +2745,8 @@ virObjectRef;
 virObjectRWLockableNew;
 virObjectRWLockRead;
 virObjectRWLockWrite;
-virObjectRWUnlock;
+virObjectRWUnlockRead;
+virObjectRWUnlockWrite;
 virObjectUnlock;
 virObjectUnref;
 
diff --git a/src/util/virobject.c b/src/util/virobject.c
index c71781550f..aee1bb4af6 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -294,12 +294,7 @@ virObjectRWLockableNew(virClassPtr klass)
     if (!(obj = virObjectNew(klass)))
         return NULL;
 
-    if (virRWLockInit(&obj->lock) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Unable to initialize RW lock"));
-        virObjectUnref(obj);
-        return NULL;
-    }
+    g_rw_lock_init(&obj->lock);
 
     return obj;
 }
@@ -319,7 +314,7 @@ virObjectRWLockableDispose(void *anyobj)
 {
     virObjectRWLockablePtr obj = anyobj;
 
-    virRWLockDestroy(&obj->lock);
+    g_rw_lock_clear(&obj->lock);
 }
 
 
@@ -458,7 +453,7 @@ virObjectRWLockRead(void *anyobj)
     if (!obj)
         return;
 
-    virRWLockRead(&obj->lock);
+    g_rw_lock_reader_lock(&obj->lock);
 }
 
 
@@ -487,7 +482,7 @@ virObjectRWLockWrite(void *anyobj)
     if (!obj)
         return;
 
-    virRWLockWrite(&obj->lock);
+    g_rw_lock_writer_lock(&obj->lock);
 }
 
 
@@ -518,16 +513,26 @@ virObjectUnlock(void *anyobj)
  * virObjectRWLockRead or virObjectRWLockWrite.
  */
 void
-virObjectRWUnlock(void *anyobj)
+virObjectRWUnlockWrite(void *anyobj)
 {
     virObjectRWLockablePtr obj = virObjectGetRWLockableObj(anyobj);
 
     if (!obj)
         return;
 
-    virRWLockUnlock(&obj->lock);
+    g_rw_lock_writer_unlock(&obj->lock);
 }
 
+void
+virObjectRWUnlockRead(void *anyobj)
+{
+    virObjectRWLockablePtr obj = virObjectGetRWLockableObj(anyobj);
+
+    if (!obj)
+        return;
+
+    g_rw_lock_reader_unlock(&obj->lock);
+}
 
 /**
  * virObjectIsClass:
diff --git a/src/util/virobject.h b/src/util/virobject.h
index 62a8a3d132..fcfe77578b 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -63,7 +63,7 @@ struct _virObjectLockable {
 
 struct _virObjectRWLockable {
     virObject parent;
-    virRWLock lock;
+    GRWLock lock;
 };
 
 virClassPtr virClassForObject(void);
@@ -150,7 +150,11 @@ virObjectUnlock(void *lockableobj)
     ATTRIBUTE_NONNULL(1);
 
 void
-virObjectRWUnlock(void *lockableobj)
+virObjectRWUnlockRead(void *lockableobj)
+    ATTRIBUTE_NONNULL(1);
+
+void
+virObjectRWUnlockWrite(void *lockableobj)
     ATTRIBUTE_NONNULL(1);
 
 void
-- 
2.25.2






[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