When creating an object, save the configFile name in the object rather than needing to build it up each time for the SaveConfig. This involves adding a @configDir parameter to virNWFilterObjListAssignDef and removing the @configDir from virNWFilterObjSaveConfig. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/conf/virnwfilterobj.c | 38 ++++++++++++++++++++------------------ src/conf/virnwfilterobj.h | 6 +++--- src/nwfilter/nwfilter_driver.c | 5 +++-- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c index 5834b9d..ac99f47 100644 --- a/src/conf/virnwfilterobj.c +++ b/src/conf/virnwfilterobj.c @@ -40,6 +40,8 @@ struct _virNWFilterObj { virNWFilterDefPtr def; virNWFilterDefPtr newDef; + + char *configFile; }; struct _virNWFilterObjList { @@ -95,6 +97,7 @@ virNWFilterObjFree(virNWFilterObjPtr obj) if (!obj) return; + VIR_FREE(obj->configFile); virNWFilterDefFree(obj->def); virNWFilterDefFree(obj->newDef); @@ -296,7 +299,8 @@ virNWFilterDefEqual(const virNWFilterDef *def1, virNWFilterObjPtr virNWFilterObjListAssignDef(virNWFilterObjListPtr nwfilters, - virNWFilterDefPtr def) + virNWFilterDefPtr def, + const char *configDir) { virNWFilterObjPtr obj; virNWFilterDefPtr objdef; @@ -360,15 +364,20 @@ virNWFilterObjListAssignDef(virNWFilterObjListPtr nwfilters, if (!(obj = virNWFilterObjNew())) return NULL; - if (VIR_APPEND_ELEMENT_COPY(nwfilters->objs, - nwfilters->count, obj) < 0) { - virNWFilterObjUnlock(obj); - virNWFilterObjFree(obj); - return NULL; - } + if (!(obj->configFile = virFileBuildPath(configDir, def->name, ".xml"))) + goto error; + + if (VIR_APPEND_ELEMENT_COPY(nwfilters->objs, nwfilters->count, obj) < 0) + goto error; + obj->def = def; return obj; + + error: + virNWFilterObjUnlock(obj); + virNWFilterObjFree(obj); + return NULL; } @@ -479,28 +488,22 @@ virNWFilterObjListExport(virConnectPtr conn, int -virNWFilterObjSaveConfig(virNWFilterObjPtr obj, - const char *configDir) +virNWFilterObjSaveConfig(virNWFilterObjPtr obj) { virNWFilterDefPtr def = obj->def; int ret = -1; char *xml; char uuidstr[VIR_UUID_STRING_BUFLEN]; - char *configFile = NULL; if (!(xml = virNWFilterDefFormat(def))) goto cleanup; - if (!(configFile = virFileBuildPath(configDir, def->name, ".xml"))) - goto cleanup; - virUUIDFormat(def->uuid, uuidstr); - ret = virXMLSaveFile(configFile, + ret = virXMLSaveFile(obj->configFile, virXMLPickShellSafeComment(def->name, uuidstr), "nwfilter-edit", xml); cleanup: - VIR_FREE(configFile); VIR_FREE(xml); return ret; } @@ -530,7 +533,7 @@ virNWFilterObjListLoadConfig(virNWFilterObjListPtr nwfilters, goto error; } - if (!(obj = virNWFilterObjListAssignDef(nwfilters, def))) + if (!(obj = virNWFilterObjListAssignDef(nwfilters, def, configDir))) goto error; def = NULL; objdef = obj->def; @@ -539,8 +542,7 @@ virNWFilterObjListLoadConfig(virNWFilterObjListPtr nwfilters, * config to disk. If not successful, no need to fail or remove the * object as a future load would regenerate a UUID and try again, * but the existing config would still exist and can be used. */ - if (!objdef->uuid_specified && - virNWFilterObjSaveConfig(objdef, configDir) < 0) + if (!objdef->uuid_specified && virNWFilterObjSaveConfig(obj) < 0) VIR_INFO("failed to save generated UUID for filter '%s'", objdef->name); VIR_FREE(configFile); diff --git a/src/conf/virnwfilterobj.h b/src/conf/virnwfilterobj.h index 16f4e1b..e4dadda 100644 --- a/src/conf/virnwfilterobj.h +++ b/src/conf/virnwfilterobj.h @@ -70,7 +70,8 @@ virNWFilterObjListFindByName(virNWFilterObjListPtr nwfilters, virNWFilterObjPtr virNWFilterObjListAssignDef(virNWFilterObjListPtr nwfilters, - virNWFilterDefPtr def); + virNWFilterDefPtr def, + const char *configDir); int virNWFilterObjTestUnassignDef(virNWFilterObjPtr obj); @@ -98,8 +99,7 @@ virNWFilterObjListExport(virConnectPtr conn, virNWFilterObjListFilter aclfilter); int -virNWFilterObjSaveConfig(virNWFilterObjPtr obj, - const char *configDir); +virNWFilterObjSaveConfig(virNWFilterObjPtr obj); int virNWFilterObjListLoadAllConfigs(virNWFilterObjListPtr nwfilters, diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index c6139d9..c740c53 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -512,12 +512,13 @@ nwfilterDefineXML(virConnectPtr conn, if (virNWFilterDefineXMLEnsureACL(conn, def) < 0) goto cleanup; - if (!(obj = virNWFilterObjListAssignDef(driver->nwfilters, def))) + if (!(obj = virNWFilterObjListAssignDef(driver->nwfilters, def, + driver->configDir))) goto cleanup; def = NULL; objdef = virNWFilterObjGetDef(obj); - if (virNWFilterObjSaveConfig(obj, driver->configDir) < 0) { + if (virNWFilterObjSaveConfig(obj) < 0) { virNWFilterObjListRemove(driver->nwfilters, obj); goto cleanup; } -- 2.9.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list