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