virInterfaceDefPtr def; /* The interface definition */
};
+struct _virInterfaceObjList {
+ size_t count;
+ virInterfaceObjPtr *objs;
+};
/* virInterfaceObj manipulation */
/* virInterfaceObjList manipulation */
+virInterfaceObjListPtr
+virInterfaceObjListNew(void)
+{
+ virInterfaceObjListPtr interfaces;
+
+ if (VIR_ALLOC(interfaces) < 0)
+ return NULL;
+ return interfaces;
+}
+
+
int
virInterfaceObjFindByMACString(virInterfaceObjListPtr interfaces,
const char *mac,
for (i = 0; i < interfaces->count; i++)
virInterfaceObjFree(interfaces->objs[i]);
-
VIR_FREE(interfaces->objs);
- interfaces->count = 0;
+ VIR_FREE(interfaces);
}
-int
-virInterfaceObjListClone(virInterfaceObjListPtr src,
- virInterfaceObjListPtr dest)
+virInterfaceObjListPtr
+virInterfaceObjListClone(virInterfaceObjListPtr interfaces)
{
- int ret = -1;
size_t i;
unsigned int cnt;
+ virInterfaceObjListPtr dest;
- if (!src || !dest)
- goto cleanup;
+ if (!interfaces)
+ return NULL;
- virInterfaceObjListFree(dest); /* start with an empty list */
- cnt = src->count;
+ if (!(dest = virInterfaceObjListNew()))
+ return NULL;
+
+ cnt = interfaces->count;
for (i = 0; i < cnt; i++) {
- virInterfaceObjPtr srcobj = src->objs[i];
+ virInterfaceObjPtr srcobj = interfaces->objs[i];
virInterfaceDefPtr backup;
virInterfaceObjPtr obj;
char *xml = virInterfaceDefFormat(srcobj->def);
if (!xml)
- goto cleanup;
+ goto error;
- if ((backup = virInterfaceDefParseString(xml)) == NULL) {
+ if (!(backup = virInterfaceDefParseString(xml))) {
VIR_FREE(xml);
- goto cleanup;
+ goto error;
}
VIR_FREE(xml);
- if ((obj = virInterfaceObjAssignDef(dest, backup)) == NULL)
- goto cleanup;
+ if (!(obj = virInterfaceObjAssignDef(dest, backup)))
+ goto error;
virInterfaceObjUnlock(obj); /* locked by virInterfaceObjAssignDef */
}
- ret = cnt;
- cleanup:
- if ((ret < 0) && dest)
- virInterfaceObjListFree(dest);
- return ret;
+ return dest;
+
+ error:
+ virInterfaceObjListFree(dest);
+ return NULL;
}
virMutex lock;
virNodeInfo nodeInfo;
- virInterfaceObjList ifaces;
+ virInterfaceObjListPtr ifaces;
bool transaction_running;
- virInterfaceObjList backupIfaces;
+ virInterfaceObjListPtr backupIfaces;
virStoragePoolObjList pools;
virNodeDeviceObjList devs;
int numCells;
virObjectUnref(driver->domains);
virNodeDeviceObjListFree(&driver->devs);
virObjectUnref(driver->networks);
- virInterfaceObjListFree(&driver->ifaces);
+ virInterfaceObjListFree(driver->ifaces);
virStoragePoolObjListFree(&driver->pools);
virObjectUnref(driver->eventState);
virMutexUnlock(&driver->lock);
if (!(ret->xmlopt = virDomainXMLOptionNew(NULL, NULL, &ns)) ||
!(ret->eventState = virObjectEventStateNew()) ||
+ !(ret->ifaces = virInterfaceObjListNew()) ||
!(ret->domains = virDomainObjListNew()) ||
!(ret->networks = virNetworkObjListNew()))
goto error;
if (!def)
goto error;
- if (!(obj = virInterfaceObjAssignDef(&privconn->ifaces, def))) {
+ if (!(obj = virInterfaceObjAssignDef(privconn->ifaces, def))) {
virInterfaceDefFree(def);
goto error;
}
virInterfaceObjPtr obj;
testDriverLock(privconn);
- obj = virInterfaceObjFindByName(&privconn->ifaces, name);
+ obj = virInterfaceObjFindByName(privconn->ifaces, name);
testDriverUnlock(privconn);
if (!obj)
int ninterfaces;
testDriverLock(privconn);
- ninterfaces = virInterfaceObjNumOfInterfaces(&privconn->ifaces, true);
+ ninterfaces = virInterfaceObjNumOfInterfaces(privconn->ifaces, true);
testDriverUnlock(privconn);
return ninterfaces;
}
int nnames;
testDriverLock(privconn);
- nnames = virInterfaceObjGetNames(&privconn->ifaces, true, names, maxnames);
+ nnames = virInterfaceObjGetNames(privconn->ifaces, true, names, maxnames);
testDriverUnlock(privconn);
return nnames;
int ninterfaces;
testDriverLock(privconn);
- ninterfaces = virInterfaceObjNumOfInterfaces(&privconn->ifaces, false);
+ ninterfaces = virInterfaceObjNumOfInterfaces(privconn->ifaces, false);
testDriverUnlock(privconn);
return ninterfaces;
}
int nnames;
testDriverLock(privconn);
- nnames = virInterfaceObjGetNames(&privconn->ifaces, false, names, maxnames);
+ nnames = virInterfaceObjGetNames(privconn->ifaces, false, names, maxnames);
testDriverUnlock(privconn);
return nnames;
virInterfacePtr ret = NULL;
testDriverLock(privconn);
- ifacect = virInterfaceObjFindByMACString(&privconn->ifaces, mac, &obj, 1);
+ ifacect = virInterfaceObjFindByMACString(privconn->ifaces, mac, &obj, 1);
testDriverUnlock(privconn);
if (ifacect == 0) {
privconn->transaction_running = true;
- if (virInterfaceObjListClone(&privconn->ifaces,
- &privconn->backupIfaces) < 0)
+ if (!(privconn->backupIfaces = virInterfaceObjListClone(privconn->ifaces)))
goto cleanup;
ret = 0;
goto cleanup;
}
- virInterfaceObjListFree(&privconn->backupIfaces);
+ virInterfaceObjListFree(privconn->backupIfaces);
privconn->transaction_running = false;
ret = 0;
goto cleanup;
}
- virInterfaceObjListFree(&privconn->ifaces);
- privconn->ifaces.count = privconn->backupIfaces.count;
- privconn->ifaces.objs = privconn->backupIfaces.objs;
- privconn->backupIfaces.count = 0;
- privconn->backupIfaces.objs = NULL;
+ virInterfaceObjListFree(privconn->ifaces);
+ privconn->ifaces = privconn->backupIfaces;
+ privconn->backupIfaces = NULL;
privconn->transaction_running = false;
if ((def = virInterfaceDefParseString(xmlStr)) == NULL)
goto cleanup;
- if ((obj = virInterfaceObjAssignDef(&privconn->ifaces, def)) == NULL)
+ if ((obj = virInterfaceObjAssignDef(privconn->ifaces, def)) == NULL)
goto cleanup;
def = NULL;
objdef = virInterfaceObjGetDef(obj);
if (!(obj = testInterfaceObjFindByName(privconn, iface->name)))
return -1;
- virInterfaceObjRemove(&privconn->ifaces, obj);
+ virInterfaceObjRemove(privconn->ifaces, obj);
return 0;
}