提交 1b4ad370 编写于 作者: J John Ferlan

nodedev: Convert virNodeDeviceObjList to use RWObjectLockable

Let's use the RWObjectLockable for the various list lock mgmt.
Only time need Write lock will be for Add/Remove logic.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 c37efe19
...@@ -40,7 +40,7 @@ struct _virNodeDeviceObj { ...@@ -40,7 +40,7 @@ struct _virNodeDeviceObj {
}; };
struct _virNodeDeviceObjList { struct _virNodeDeviceObjList {
virObjectLockable parent; virObjectRWLockable parent;
/* name string -> virNodeDeviceObj mapping /* name string -> virNodeDeviceObj mapping
* for O(1), lockless lookup-by-name */ * for O(1), lockless lookup-by-name */
...@@ -63,7 +63,7 @@ virNodeDeviceObjOnceInit(void) ...@@ -63,7 +63,7 @@ virNodeDeviceObjOnceInit(void)
virNodeDeviceObjDispose))) virNodeDeviceObjDispose)))
return -1; return -1;
if (!(virNodeDeviceObjListClass = virClassNew(virClassForObjectLockable(), if (!(virNodeDeviceObjListClass = virClassNew(virClassForObjectRWLockable(),
"virNodeDeviceObjList", "virNodeDeviceObjList",
sizeof(virNodeDeviceObjList), sizeof(virNodeDeviceObjList),
virNodeDeviceObjListDispose))) virNodeDeviceObjListDispose)))
...@@ -231,10 +231,10 @@ virNodeDeviceObjListSearch(virNodeDeviceObjListPtr devs, ...@@ -231,10 +231,10 @@ virNodeDeviceObjListSearch(virNodeDeviceObjListPtr devs,
{ {
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virObjectLock(devs); virObjectRWLockRead(devs);
obj = virHashSearch(devs->objs, callback, data, NULL); obj = virHashSearch(devs->objs, callback, data, NULL);
virObjectRef(obj); virObjectRef(obj);
virObjectUnlock(devs); virObjectRWUnlock(devs);
if (obj) if (obj)
virObjectLock(obj); virObjectLock(obj);
...@@ -284,9 +284,9 @@ virNodeDeviceObjListFindByName(virNodeDeviceObjListPtr devs, ...@@ -284,9 +284,9 @@ virNodeDeviceObjListFindByName(virNodeDeviceObjListPtr devs,
{ {
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virObjectLock(devs); virObjectRWLockRead(devs);
obj = virNodeDeviceObjListFindByNameLocked(devs, name); obj = virNodeDeviceObjListFindByNameLocked(devs, name);
virObjectUnlock(devs); virObjectRWUnlock(devs);
if (obj) if (obj)
virObjectLock(obj); virObjectLock(obj);
...@@ -462,7 +462,7 @@ virNodeDeviceObjListNew(void) ...@@ -462,7 +462,7 @@ virNodeDeviceObjListNew(void)
if (virNodeDeviceObjInitialize() < 0) if (virNodeDeviceObjInitialize() < 0)
return NULL; return NULL;
if (!(devs = virObjectLockableNew(virNodeDeviceObjListClass))) if (!(devs = virObjectRWLockableNew(virNodeDeviceObjListClass)))
return NULL; return NULL;
if (!(devs->objs = virHashCreate(50, virObjectFreeHashData))) { if (!(devs->objs = virHashCreate(50, virObjectFreeHashData))) {
...@@ -487,7 +487,7 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs, ...@@ -487,7 +487,7 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs,
{ {
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virObjectLock(devs); virObjectRWLockWrite(devs);
if ((obj = virNodeDeviceObjListFindByNameLocked(devs, def->name))) { if ((obj = virNodeDeviceObjListFindByNameLocked(devs, def->name))) {
virObjectLock(obj); virObjectLock(obj);
...@@ -507,7 +507,7 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs, ...@@ -507,7 +507,7 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs,
} }
cleanup: cleanup:
virObjectUnlock(devs); virObjectRWUnlock(devs);
return obj; return obj;
} }
...@@ -524,12 +524,12 @@ virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, ...@@ -524,12 +524,12 @@ virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs,
virObjectRef(obj); virObjectRef(obj);
virObjectUnlock(obj); virObjectUnlock(obj);
virObjectLock(devs); virObjectRWLockWrite(devs);
virObjectLock(obj); virObjectLock(obj);
virHashRemoveEntry(devs->objs, def->name); virHashRemoveEntry(devs->objs, def->name);
virObjectUnlock(obj); virObjectUnlock(obj);
virObjectUnref(obj); virObjectUnref(obj);
virObjectUnlock(devs); virObjectRWUnlock(devs);
} }
...@@ -767,9 +767,9 @@ virNodeDeviceObjListNumOfDevices(virNodeDeviceObjListPtr devs, ...@@ -767,9 +767,9 @@ virNodeDeviceObjListNumOfDevices(virNodeDeviceObjListPtr devs,
struct virNodeDeviceCountData data = { struct virNodeDeviceCountData data = {
.conn = conn, .filter = filter, .matchstr = cap, .count = 0 }; .conn = conn, .filter = filter, .matchstr = cap, .count = 0 };
virObjectLock(devs); virObjectRWLockRead(devs);
virHashForEach(devs->objs, virNodeDeviceObjListNumOfDevicesCallback, &data); virHashForEach(devs->objs, virNodeDeviceObjListNumOfDevicesCallback, &data);
virObjectUnlock(devs); virObjectRWUnlock(devs);
return data.count; return data.count;
} }
...@@ -828,9 +828,9 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr devs, ...@@ -828,9 +828,9 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr devs,
.conn = conn, .filter = filter, .matchstr = cap, .names = names, .conn = conn, .filter = filter, .matchstr = cap, .names = names,
.nnames = 0, .maxnames = maxnames, .error = false }; .nnames = 0, .maxnames = maxnames, .error = false };
virObjectLock(devs); virObjectRWLockRead(devs);
virHashForEach(devs->objs, virNodeDeviceObjListGetNamesCallback, &data); virHashForEach(devs->objs, virNodeDeviceObjListGetNamesCallback, &data);
virObjectUnlock(devs); virObjectRWUnlock(devs);
if (data.error) if (data.error)
goto error; goto error;
...@@ -932,15 +932,15 @@ virNodeDeviceObjListExport(virConnectPtr conn, ...@@ -932,15 +932,15 @@ virNodeDeviceObjListExport(virConnectPtr conn,
.conn = conn, .filter = filter, .flags = flags, .conn = conn, .filter = filter, .flags = flags,
.devices = NULL, .ndevices = 0, .error = false }; .devices = NULL, .ndevices = 0, .error = false };
virObjectLock(devs); virObjectRWLockRead(devs);
if (devices && if (devices &&
VIR_ALLOC_N(data.devices, virHashSize(devs->objs) + 1) < 0) { VIR_ALLOC_N(data.devices, virHashSize(devs->objs) + 1) < 0) {
virObjectUnlock(devs); virObjectRWUnlock(devs);
return -1; return -1;
} }
virHashForEach(devs->objs, virNodeDeviceObjListExportCallback, &data); virHashForEach(devs->objs, virNodeDeviceObjListExportCallback, &data);
virObjectUnlock(devs); virObjectRWUnlock(devs);
if (data.error) if (data.error)
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册