int virNWFilterObjListExport(virConnectPtr conn, virNWFilterObjListPtr nwfilters, virNWFilterPtr **filters, virNWFilterObjListFilter filter) { virNWFilterPtr *tmp_filters = NULL; int nfilters = 0; virNWFilterPtr nwfilter = NULL; virNWFilterObjPtr obj = NULL; virNWFilterDefPtr def; size_t i; int ret = -1; if (!filters) { ret = nwfilters->count; goto cleanup; } if (VIR_ALLOC_N(tmp_filters, nwfilters->count + 1) < 0) goto cleanup; for (i = 0; i < nwfilters->count; i++) { obj = nwfilters->objs[i]; virNWFilterObjLock(obj); def = obj->def; if (!filter || filter(conn, def)) { if (!(nwfilter = virGetNWFilter(conn, def->name, def->uuid))) { virNWFilterObjUnlock(obj); goto cleanup; } tmp_filters[nfilters++] = nwfilter; } virNWFilterObjUnlock(obj); } *filters = tmp_filters; tmp_filters = NULL; ret = nfilters; cleanup: if (tmp_filters) { for (i = 0; i < nfilters; i ++) virObjectUnref(tmp_filters[i]); } VIR_FREE(tmp_filters); return ret; }
static virNWFilterPtr nwfilterDefine(virConnectPtr conn, const char *xml) { virNWFilterDriverStatePtr driver = conn->nwfilterPrivateData; virNWFilterDefPtr def; virNWFilterObjPtr nwfilter = NULL; virNWFilterPtr ret = NULL; nwfilterDriverLock(driver); virNWFilterCallbackDriversLock(); if (!(def = virNWFilterDefParseString(conn, xml))) goto cleanup; if (!(nwfilter = virNWFilterObjAssignDef(conn, &driver->nwfilters, def))) goto cleanup; if (virNWFilterObjSaveDef(driver, nwfilter, def) < 0) { virNWFilterObjRemove(&driver->nwfilters, nwfilter); def = NULL; goto cleanup; } def = NULL; ret = virGetNWFilter(conn, nwfilter->def->name, nwfilter->def->uuid); cleanup: virNWFilterDefFree(def); if (nwfilter) virNWFilterObjUnlock(nwfilter); virNWFilterCallbackDriversUnlock(); nwfilterDriverUnlock(driver); return ret; }
static virNWFilterPtr nwfilterLookupByName(virConnectPtr conn, const char *name) { virNWFilterDriverStatePtr driver = conn->nwfilterPrivateData; virNWFilterObjPtr nwfilter; virNWFilterPtr ret = NULL; nwfilterDriverLock(driver); nwfilter = virNWFilterObjFindByName(&driver->nwfilters, name); nwfilterDriverUnlock(driver); if (!nwfilter) { virNWFilterReportError(VIR_ERR_NO_NWFILTER, _("no nwfilter with matching name '%s'"), name); goto cleanup; } ret = virGetNWFilter(conn, nwfilter->def->name, nwfilter->def->uuid); cleanup: if (nwfilter) virNWFilterObjUnlock(nwfilter); return ret; }