提交 c37efe19 编写于 作者: J John Ferlan

secrets: Convert to use ObjectRWLockable

Let's use the ObjectRWLockable for the various list lock mgmt.
Only time need Write lock will be for Add/Remove logic.
上级 3dcab1de
...@@ -52,7 +52,7 @@ static void virSecretObjDispose(void *obj); ...@@ -52,7 +52,7 @@ static void virSecretObjDispose(void *obj);
static void virSecretObjListDispose(void *obj); static void virSecretObjListDispose(void *obj);
struct _virSecretObjList { struct _virSecretObjList {
virObjectLockable parent; virObjectRWLockable parent;
/* uuid string -> virSecretObj mapping /* uuid string -> virSecretObj mapping
* for O(1), lockless lookup-by-uuid */ * for O(1), lockless lookup-by-uuid */
...@@ -74,7 +74,7 @@ virSecretObjOnceInit(void) ...@@ -74,7 +74,7 @@ virSecretObjOnceInit(void)
virSecretObjDispose))) virSecretObjDispose)))
return -1; return -1;
if (!(virSecretObjListClass = virClassNew(virClassForObjectLockable(), if (!(virSecretObjListClass = virClassNew(virClassForObjectRWLockable(),
"virSecretObjList", "virSecretObjList",
sizeof(virSecretObjList), sizeof(virSecretObjList),
virSecretObjListDispose))) virSecretObjListDispose)))
...@@ -123,7 +123,7 @@ virSecretObjListNew(void) ...@@ -123,7 +123,7 @@ virSecretObjListNew(void)
if (virSecretObjInitialize() < 0) if (virSecretObjInitialize() < 0)
return NULL; return NULL;
if (!(secrets = virObjectLockableNew(virSecretObjListClass))) if (!(secrets = virObjectRWLockableNew(virSecretObjListClass)))
return NULL; return NULL;
if (!(secrets->objs = virHashCreate(50, virObjectFreeHashData))) { if (!(secrets->objs = virHashCreate(50, virObjectFreeHashData))) {
...@@ -193,9 +193,9 @@ virSecretObjListFindByUUID(virSecretObjListPtr secrets, ...@@ -193,9 +193,9 @@ virSecretObjListFindByUUID(virSecretObjListPtr secrets,
{ {
virSecretObjPtr obj; virSecretObjPtr obj;
virObjectLock(secrets); virObjectRWLockRead(secrets);
obj = virSecretObjListFindByUUIDLocked(secrets, uuidstr); obj = virSecretObjListFindByUUIDLocked(secrets, uuidstr);
virObjectUnlock(secrets); virObjectRWUnlock(secrets);
if (obj) if (obj)
virObjectLock(obj); virObjectLock(obj);
return obj; return obj;
...@@ -272,9 +272,9 @@ virSecretObjListFindByUsage(virSecretObjListPtr secrets, ...@@ -272,9 +272,9 @@ virSecretObjListFindByUsage(virSecretObjListPtr secrets,
{ {
virSecretObjPtr obj; virSecretObjPtr obj;
virObjectLock(secrets); virObjectRWLockRead(secrets);
obj = virSecretObjListFindByUsageLocked(secrets, usageType, usageID); obj = virSecretObjListFindByUsageLocked(secrets, usageType, usageID);
virObjectUnlock(secrets); virObjectRWUnlock(secrets);
if (obj) if (obj)
virObjectLock(obj); virObjectLock(obj);
return obj; return obj;
...@@ -305,12 +305,12 @@ virSecretObjListRemove(virSecretObjListPtr secrets, ...@@ -305,12 +305,12 @@ virSecretObjListRemove(virSecretObjListPtr secrets,
virObjectRef(obj); virObjectRef(obj);
virObjectUnlock(obj); virObjectUnlock(obj);
virObjectLock(secrets); virObjectRWLockWrite(secrets);
virObjectLock(obj); virObjectLock(obj);
virHashRemoveEntry(secrets->objs, uuidstr); virHashRemoveEntry(secrets->objs, uuidstr);
virObjectUnlock(obj); virObjectUnlock(obj);
virObjectUnref(obj); virObjectUnref(obj);
virObjectUnlock(secrets); virObjectRWUnlock(secrets);
} }
...@@ -336,7 +336,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets, ...@@ -336,7 +336,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
virSecretObjPtr ret = NULL; virSecretObjPtr ret = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virObjectLock(secrets); virObjectRWLockWrite(secrets);
if (oldDef) if (oldDef)
*oldDef = NULL; *oldDef = NULL;
...@@ -405,7 +405,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets, ...@@ -405,7 +405,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
cleanup: cleanup:
virSecretObjEndAPI(&obj); virSecretObjEndAPI(&obj);
virObjectUnlock(secrets); virObjectRWUnlock(secrets);
return ret; return ret;
} }
...@@ -496,9 +496,9 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secrets, ...@@ -496,9 +496,9 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secrets,
struct virSecretCountData data = { struct virSecretCountData data = {
.conn = conn, .filter = filter, .count = 0 }; .conn = conn, .filter = filter, .count = 0 };
virObjectLock(secrets); virObjectRWLockRead(secrets);
virHashForEach(secrets->objs, virSecretObjListNumOfSecretsCallback, &data); virHashForEach(secrets->objs, virSecretObjListNumOfSecretsCallback, &data);
virObjectUnlock(secrets); virObjectRWUnlock(secrets);
return data.count; return data.count;
} }
...@@ -595,15 +595,15 @@ virSecretObjListExport(virConnectPtr conn, ...@@ -595,15 +595,15 @@ virSecretObjListExport(virConnectPtr conn,
.filter = filter, .flags = flags, .filter = filter, .flags = flags,
.nsecrets = 0, .error = false }; .nsecrets = 0, .error = false };
virObjectLock(secretobjs); virObjectRWLockRead(secretobjs);
if (secrets && if (secrets &&
VIR_ALLOC_N(data.secrets, virHashSize(secretobjs->objs) + 1) < 0) { VIR_ALLOC_N(data.secrets, virHashSize(secretobjs->objs) + 1) < 0) {
virObjectUnlock(secretobjs); virObjectRWUnlock(secretobjs);
return -1; return -1;
} }
virHashForEach(secretobjs->objs, virSecretObjListExportCallback, &data); virHashForEach(secretobjs->objs, virSecretObjListExportCallback, &data);
virObjectUnlock(secretobjs); virObjectRWUnlock(secretobjs);
if (data.error) if (data.error)
goto error; goto error;
...@@ -633,9 +633,9 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets, ...@@ -633,9 +633,9 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets,
.conn = conn, .filter = filter, .uuids = uuids, .nuuids = 0, .conn = conn, .filter = filter, .uuids = uuids, .nuuids = 0,
.maxuuids = maxuuids, .error = false }; .maxuuids = maxuuids, .error = false };
virObjectLock(secrets); virObjectRWLockRead(secrets);
virHashForEach(secrets->objs, virSecretObjListGetUUIDsCallback, &data); virHashForEach(secrets->objs, virSecretObjListGetUUIDsCallback, &data);
virObjectUnlock(secrets); virObjectRWUnlock(secrets);
if (data.error) if (data.error)
goto error; goto error;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册