mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
interface: Make _virInterfaceObjList virObjectRWLockable
Modify the allocation to be a real RWLockable object and add the various RWLock{Read|Write} and RWUnlock calls to process the list of interfaces.
This commit is contained in:
parent
37537a7c64
commit
4102e22864
@ -40,6 +40,8 @@ struct _virInterfaceObj {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct _virInterfaceObjList {
|
struct _virInterfaceObjList {
|
||||||
|
virObjectRWLockable parent;
|
||||||
|
|
||||||
size_t count;
|
size_t count;
|
||||||
virInterfaceObjPtr *objs;
|
virInterfaceObjPtr *objs;
|
||||||
};
|
};
|
||||||
@ -47,7 +49,9 @@ struct _virInterfaceObjList {
|
|||||||
/* virInterfaceObj manipulation */
|
/* virInterfaceObj manipulation */
|
||||||
|
|
||||||
static virClassPtr virInterfaceObjClass;
|
static virClassPtr virInterfaceObjClass;
|
||||||
|
static virClassPtr virInterfaceObjListClass;
|
||||||
static void virInterfaceObjDispose(void *obj);
|
static void virInterfaceObjDispose(void *obj);
|
||||||
|
static void virInterfaceObjListDispose(void *obj);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virInterfaceObjOnceInit(void)
|
virInterfaceObjOnceInit(void)
|
||||||
@ -58,6 +62,12 @@ virInterfaceObjOnceInit(void)
|
|||||||
virInterfaceObjDispose)))
|
virInterfaceObjDispose)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (!(virInterfaceObjListClass = virClassNew(virClassForObjectRWLockable(),
|
||||||
|
"virInterfaceObjList",
|
||||||
|
sizeof(virInterfaceObjList),
|
||||||
|
virInterfaceObjListDispose)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,8 +140,12 @@ virInterfaceObjListNew(void)
|
|||||||
{
|
{
|
||||||
virInterfaceObjListPtr interfaces;
|
virInterfaceObjListPtr interfaces;
|
||||||
|
|
||||||
if (VIR_ALLOC(interfaces) < 0)
|
if (virInterfaceObjInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (!(interfaces = virObjectRWLockableNew(virInterfaceObjListClass)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
return interfaces;
|
return interfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,6 +159,7 @@ virInterfaceObjListFindByMACString(virInterfaceObjListPtr interfaces,
|
|||||||
size_t i;
|
size_t i;
|
||||||
int matchct = 0;
|
int matchct = 0;
|
||||||
|
|
||||||
|
virObjectRWLockRead(interfaces);
|
||||||
for (i = 0; i < interfaces->count; i++) {
|
for (i = 0; i < interfaces->count; i++) {
|
||||||
virInterfaceObjPtr obj = interfaces->objs[i];
|
virInterfaceObjPtr obj = interfaces->objs[i];
|
||||||
virInterfaceDefPtr def;
|
virInterfaceDefPtr def;
|
||||||
@ -162,11 +177,13 @@ virInterfaceObjListFindByMACString(virInterfaceObjListPtr interfaces,
|
|||||||
}
|
}
|
||||||
virObjectUnlock(obj);
|
virObjectUnlock(obj);
|
||||||
}
|
}
|
||||||
|
virObjectRWUnlock(interfaces);
|
||||||
return matchct;
|
return matchct;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
while (--matchct >= 0)
|
while (--matchct >= 0)
|
||||||
VIR_FREE(matches[matchct]);
|
VIR_FREE(matches[matchct]);
|
||||||
|
virObjectRWUnlock(interfaces);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -178,30 +195,34 @@ virInterfaceObjListFindByName(virInterfaceObjListPtr interfaces,
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
virObjectRWLockRead(interfaces);
|
||||||
for (i = 0; i < interfaces->count; i++) {
|
for (i = 0; i < interfaces->count; i++) {
|
||||||
virInterfaceObjPtr obj = interfaces->objs[i];
|
virInterfaceObjPtr obj = interfaces->objs[i];
|
||||||
virInterfaceDefPtr def;
|
virInterfaceDefPtr def;
|
||||||
|
|
||||||
virObjectLock(obj);
|
virObjectLock(obj);
|
||||||
def = obj->def;
|
def = obj->def;
|
||||||
if (STREQ(def->name, name))
|
if (STREQ(def->name, name)) {
|
||||||
|
virObjectRWUnlock(interfaces);
|
||||||
return virObjectRef(obj);
|
return virObjectRef(obj);
|
||||||
|
}
|
||||||
virObjectUnlock(obj);
|
virObjectUnlock(obj);
|
||||||
}
|
}
|
||||||
|
virObjectRWUnlock(interfaces);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
virInterfaceObjListFree(virInterfaceObjListPtr interfaces)
|
virInterfaceObjListDispose(void *obj)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
virInterfaceObjListPtr interfaces = obj;
|
||||||
|
|
||||||
for (i = 0; i < interfaces->count; i++)
|
for (i = 0; i < interfaces->count; i++)
|
||||||
virObjectUnref(interfaces->objs[i]);
|
virObjectUnref(interfaces->objs[i]);
|
||||||
VIR_FREE(interfaces->objs);
|
VIR_FREE(interfaces->objs);
|
||||||
VIR_FREE(interfaces);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -218,6 +239,7 @@ virInterfaceObjListClone(virInterfaceObjListPtr interfaces)
|
|||||||
if (!(dest = virInterfaceObjListNew()))
|
if (!(dest = virInterfaceObjListNew()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
virObjectRWLockRead(interfaces);
|
||||||
cnt = interfaces->count;
|
cnt = interfaces->count;
|
||||||
for (i = 0; i < cnt; i++) {
|
for (i = 0; i < cnt; i++) {
|
||||||
virInterfaceObjPtr srcobj = interfaces->objs[i];
|
virInterfaceObjPtr srcobj = interfaces->objs[i];
|
||||||
@ -238,11 +260,13 @@ virInterfaceObjListClone(virInterfaceObjListPtr interfaces)
|
|||||||
goto error;
|
goto error;
|
||||||
virInterfaceObjEndAPI(&obj);
|
virInterfaceObjEndAPI(&obj);
|
||||||
}
|
}
|
||||||
|
virObjectRWUnlock(interfaces);
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virInterfaceObjListFree(dest);
|
virObjectUnref(dest);
|
||||||
|
virObjectRWUnlock(interfaces);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,12 +287,15 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr interfaces,
|
|||||||
if (!(obj = virInterfaceObjNew()))
|
if (!(obj = virInterfaceObjNew()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
virObjectRWLockWrite(interfaces);
|
||||||
if (VIR_APPEND_ELEMENT_COPY(interfaces->objs,
|
if (VIR_APPEND_ELEMENT_COPY(interfaces->objs,
|
||||||
interfaces->count, obj) < 0) {
|
interfaces->count, obj) < 0) {
|
||||||
virInterfaceObjEndAPI(&obj);
|
virInterfaceObjEndAPI(&obj);
|
||||||
|
virObjectRWUnlock(interfaces);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
obj->def = def;
|
obj->def = def;
|
||||||
|
virObjectRWUnlock(interfaces);
|
||||||
return virObjectRef(obj);
|
return virObjectRef(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,6 +307,7 @@ virInterfaceObjListRemove(virInterfaceObjListPtr interfaces,
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
virObjectUnlock(obj);
|
virObjectUnlock(obj);
|
||||||
|
virObjectRWLockWrite(interfaces);
|
||||||
for (i = 0; i < interfaces->count; i++) {
|
for (i = 0; i < interfaces->count; i++) {
|
||||||
virObjectLock(interfaces->objs[i]);
|
virObjectLock(interfaces->objs[i]);
|
||||||
if (interfaces->objs[i] == obj) {
|
if (interfaces->objs[i] == obj) {
|
||||||
@ -291,6 +319,7 @@ virInterfaceObjListRemove(virInterfaceObjListPtr interfaces,
|
|||||||
}
|
}
|
||||||
virObjectUnlock(interfaces->objs[i]);
|
virObjectUnlock(interfaces->objs[i]);
|
||||||
}
|
}
|
||||||
|
virObjectRWUnlock(interfaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -301,6 +330,7 @@ virInterfaceObjListNumOfInterfaces(virInterfaceObjListPtr interfaces,
|
|||||||
size_t i;
|
size_t i;
|
||||||
int ninterfaces = 0;
|
int ninterfaces = 0;
|
||||||
|
|
||||||
|
virObjectRWLockRead(interfaces);
|
||||||
for (i = 0; (i < interfaces->count); i++) {
|
for (i = 0; (i < interfaces->count); i++) {
|
||||||
virInterfaceObjPtr obj = interfaces->objs[i];
|
virInterfaceObjPtr obj = interfaces->objs[i];
|
||||||
virObjectLock(obj);
|
virObjectLock(obj);
|
||||||
@ -308,6 +338,7 @@ virInterfaceObjListNumOfInterfaces(virInterfaceObjListPtr interfaces,
|
|||||||
ninterfaces++;
|
ninterfaces++;
|
||||||
virObjectUnlock(obj);
|
virObjectUnlock(obj);
|
||||||
}
|
}
|
||||||
|
virObjectRWUnlock(interfaces);
|
||||||
|
|
||||||
return ninterfaces;
|
return ninterfaces;
|
||||||
}
|
}
|
||||||
@ -322,6 +353,7 @@ virInterfaceObjListGetNames(virInterfaceObjListPtr interfaces,
|
|||||||
int nnames = 0;
|
int nnames = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
virObjectRWLockRead(interfaces);
|
||||||
for (i = 0; i < interfaces->count && nnames < maxnames; i++) {
|
for (i = 0; i < interfaces->count && nnames < maxnames; i++) {
|
||||||
virInterfaceObjPtr obj = interfaces->objs[i];
|
virInterfaceObjPtr obj = interfaces->objs[i];
|
||||||
virInterfaceDefPtr def;
|
virInterfaceDefPtr def;
|
||||||
@ -337,6 +369,7 @@ virInterfaceObjListGetNames(virInterfaceObjListPtr interfaces,
|
|||||||
}
|
}
|
||||||
virObjectUnlock(obj);
|
virObjectUnlock(obj);
|
||||||
}
|
}
|
||||||
|
virObjectRWUnlock(interfaces);
|
||||||
|
|
||||||
return nnames;
|
return nnames;
|
||||||
|
|
||||||
|
@ -57,9 +57,6 @@ virInterfaceObjListFindByName(virInterfaceObjListPtr interfaces,
|
|||||||
void
|
void
|
||||||
virInterfaceObjFree(virInterfaceObjPtr obj);
|
virInterfaceObjFree(virInterfaceObjPtr obj);
|
||||||
|
|
||||||
void
|
|
||||||
virInterfaceObjListFree(virInterfaceObjListPtr vms);
|
|
||||||
|
|
||||||
virInterfaceObjListPtr
|
virInterfaceObjListPtr
|
||||||
virInterfaceObjListClone(virInterfaceObjListPtr interfaces);
|
virInterfaceObjListClone(virInterfaceObjListPtr interfaces);
|
||||||
|
|
||||||
|
@ -936,7 +936,6 @@ virInterfaceObjListAssignDef;
|
|||||||
virInterfaceObjListClone;
|
virInterfaceObjListClone;
|
||||||
virInterfaceObjListFindByMACString;
|
virInterfaceObjListFindByMACString;
|
||||||
virInterfaceObjListFindByName;
|
virInterfaceObjListFindByName;
|
||||||
virInterfaceObjListFree;
|
|
||||||
virInterfaceObjListGetNames;
|
virInterfaceObjListGetNames;
|
||||||
virInterfaceObjListNew;
|
virInterfaceObjListNew;
|
||||||
virInterfaceObjListNumOfInterfaces;
|
virInterfaceObjListNumOfInterfaces;
|
||||||
|
@ -154,7 +154,7 @@ testDriverFree(testDriverPtr driver)
|
|||||||
virObjectUnref(driver->domains);
|
virObjectUnref(driver->domains);
|
||||||
virNodeDeviceObjListFree(driver->devs);
|
virNodeDeviceObjListFree(driver->devs);
|
||||||
virObjectUnref(driver->networks);
|
virObjectUnref(driver->networks);
|
||||||
virInterfaceObjListFree(driver->ifaces);
|
virObjectUnref(driver->ifaces);
|
||||||
virStoragePoolObjListFree(&driver->pools);
|
virStoragePoolObjListFree(&driver->pools);
|
||||||
virObjectUnref(driver->eventState);
|
virObjectUnref(driver->eventState);
|
||||||
virMutexUnlock(&driver->lock);
|
virMutexUnlock(&driver->lock);
|
||||||
@ -3878,7 +3878,7 @@ testInterfaceChangeCommit(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virInterfaceObjListFree(privconn->backupIfaces);
|
virObjectUnref(privconn->backupIfaces);
|
||||||
privconn->transaction_running = false;
|
privconn->transaction_running = false;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -3908,7 +3908,7 @@ testInterfaceChangeRollback(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virInterfaceObjListFree(privconn->ifaces);
|
virObjectUnref(privconn->ifaces);
|
||||||
privconn->ifaces = privconn->backupIfaces;
|
privconn->ifaces = privconn->backupIfaces;
|
||||||
privconn->backupIfaces = NULL;
|
privconn->backupIfaces = NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user