There is no reason why two threads trying to look up two node devices should mutually exclude each other. Utilize new virObjectRWLockable that was just introduced. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/virnodedeviceobj.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 3ab93a3ea..808365e21 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -40,7 +40,7 @@ struct _virNodeDeviceObj { }; struct _virNodeDeviceObjList { - virObjectLockable parent; + virObjectRWLockable parent; /* name string -> virNodeDeviceObj mapping * for O(1), lockless lookup-by-name */ @@ -63,7 +63,7 @@ virNodeDeviceObjOnceInit(void) virNodeDeviceObjDispose))) return -1; - if (!(virNodeDeviceObjListClass = virClassNew(virClassForObjectLockable(), + if (!(virNodeDeviceObjListClass = virClassNew(virClassForObjectRWLockable(), "virNodeDeviceObjList", sizeof(virNodeDeviceObjList), virNodeDeviceObjListDispose))) @@ -231,7 +231,7 @@ virNodeDeviceObjListSearch(virNodeDeviceObjListPtr devs, { virNodeDeviceObjPtr obj; - virObjectLock(devs); + virObjectLockRead(devs); obj = virHashSearch(devs->objs, callback, data, NULL); virObjectRef(obj); virObjectUnlock(devs); @@ -284,7 +284,7 @@ virNodeDeviceObjListFindByName(virNodeDeviceObjListPtr devs, { virNodeDeviceObjPtr obj; - virObjectLock(devs); + virObjectLockRead(devs); obj = virNodeDeviceObjListFindByNameLocked(devs, name); virObjectUnlock(devs); if (obj) @@ -462,7 +462,7 @@ virNodeDeviceObjListNew(void) if (virNodeDeviceObjInitialize() < 0) return NULL; - if (!(devs = virObjectLockableNew(virNodeDeviceObjListClass))) + if (!(devs = virObjectRWLockableNew(virNodeDeviceObjListClass))) return NULL; if (!(devs->objs = virHashCreate(50, virObjectFreeHashData))) { @@ -767,7 +767,7 @@ virNodeDeviceObjListNumOfDevices(virNodeDeviceObjListPtr devs, struct virNodeDeviceCountData data = { .conn = conn, .aclfilter = aclfilter, .matchstr = cap, .count = 0 }; - virObjectLock(devs); + virObjectLockRead(devs); virHashForEach(devs->objs, virNodeDeviceObjListNumOfDevicesCallback, &data); virObjectUnlock(devs); @@ -828,7 +828,7 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr devs, .conn = conn, .aclfilter = aclfilter, .matchstr = cap, .names = names, .nnames = 0, .maxnames = maxnames, .error = false }; - virObjectLock(devs); + virObjectLockRead(devs); virHashForEach(devs->objs, virNodeDeviceObjListGetNamesCallback, &data); virObjectUnlock(devs); @@ -932,7 +932,7 @@ virNodeDeviceObjListExport(virConnectPtr conn, .conn = conn, .aclfilter = aclfilter, .flags = flags, .devices = NULL, .ndevices = 0, .error = false }; - virObjectLock(devs); + virObjectLockRead(devs); if (devices && VIR_ALLOC_N(data.devices, virHashSize(devs->objs) + 1) < 0) { virObjectUnlock(devs); -- 2.13.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list