[PATCH 13/15] nwfilter: Move configFile name processing into driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In preparation for it becoming part of the nwfilter object, move all the
processing of the generation of the configFile name into the driver code.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/nwfilter_conf.c       | 36 +++++++++---------------------------
 src/conf/nwfilter_conf.h       |  6 +++---
 src/conf/virnwfilterobj.c      |  2 +-
 src/nwfilter/nwfilter_driver.c | 14 ++++++++++++--
 4 files changed, 25 insertions(+), 33 deletions(-)

diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 032700c..6b67c3a 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -2767,30 +2767,21 @@ virNWFilterDefParseFile(const char *filename)
 
 
 int
-virNWFilterSaveXML(const char *configDir,
+virNWFilterSaveXML(const char *configFile,
                    virNWFilterDefPtr def,
                    const char *xml)
 {
     char uuidstr[VIR_UUID_STRING_BUFLEN];
-    char *configFile = NULL;
-    int ret = -1;
-
-    if (!(configFile = virFileBuildPath(configDir, def->name, ".xml")))
-        goto cleanup;
 
     virUUIDFormat(def->uuid, uuidstr);
-    ret = virXMLSaveFile(configFile,
-                         virXMLPickShellSafeComment(def->name, uuidstr),
-                         "nwfilter-edit", xml);
-
- cleanup:
-    VIR_FREE(configFile);
-    return ret;
+    return virXMLSaveFile(configFile,
+                          virXMLPickShellSafeComment(def->name, uuidstr),
+                          "nwfilter-edit", xml);
 }
 
 
 int
-virNWFilterSaveConfig(const char *configDir,
+virNWFilterSaveConfig(const char *configFile,
                       virNWFilterDefPtr def)
 {
     int ret = -1;
@@ -2799,7 +2790,7 @@ virNWFilterSaveConfig(const char *configDir,
     if (!(xml = virNWFilterDefFormat(def)))
         goto cleanup;
 
-    if (virNWFilterSaveXML(configDir, def, xml) < 0)
+    if (virNWFilterSaveXML(configFile, def, xml) < 0)
         goto cleanup;
 
     ret = 0;
@@ -2925,26 +2916,17 @@ virNWFilterTriggerVMFilterRebuild(void)
 
 
 int
-virNWFilterDeleteDef(const char *configDir,
+virNWFilterDeleteDef(const char *configFile,
                      virNWFilterDefPtr def)
 {
-    int ret = -1;
-    char *configFile = NULL;
-
-    if (!(configFile = virFileBuildPath(configDir, def->name, ".xml")))
-        goto error;
-
     if (unlink(configFile) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot remove config for %s"),
                        def->name);
-        goto error;
+        return -1;
     }
 
-    ret = 0;
- error:
-    VIR_FREE(configFile);
-    return ret;
+    return  0;
 }
 
 
diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h
index 5cac260..5a3f008 100644
--- a/src/conf/nwfilter_conf.h
+++ b/src/conf/nwfilter_conf.h
@@ -570,7 +570,7 @@ int
 virNWFilterTriggerVMFilterRebuild(void);
 
 int
-virNWFilterDeleteDef(const char *configDir,
+virNWFilterDeleteDef(const char *configFile,
                      virNWFilterDefPtr def);
 
 virNWFilterDefPtr
@@ -581,12 +581,12 @@ char *
 virNWFilterDefFormat(const virNWFilterDef *def);
 
 int
-virNWFilterSaveXML(const char *configDir,
+virNWFilterSaveXML(const char *configFile,
                    virNWFilterDefPtr def,
                    const char *xml);
 
 int
-virNWFilterSaveConfig(const char *configDir,
+virNWFilterSaveConfig(const char *configFile,
                       virNWFilterDefPtr def);
 
 virNWFilterDefPtr
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index 7410047..ec28b05 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -512,7 +512,7 @@ virNWFilterObjListLoadConfig(virNWFilterObjListPtr nwfilters,
 
     /* We generated a UUID, make it permanent by saving the config to disk */
     if (!def->uuid_specified &&
-        virNWFilterSaveConfig(configDir, def) < 0)
+        virNWFilterSaveConfig(configFile, def) < 0)
         goto error;
 
     if (!(obj = virNWFilterObjListAssignDef(nwfilters, def)))
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 5e62023..97d6952 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -495,6 +495,7 @@ nwfilterDefineXML(virConnectPtr conn,
     virNWFilterObjPtr obj = NULL;
     virNWFilterDefPtr objdef;
     virNWFilterPtr ret = NULL;
+    char *configFile = NULL;
 
     if (!driver->privileged) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -512,12 +513,15 @@ nwfilterDefineXML(virConnectPtr conn,
     if (virNWFilterDefineXMLEnsureACL(conn, def) < 0)
         goto cleanup;
 
+    if (!(configFile = virFileBuildPath(driver->configDir, def->name, ".xml")))
+        goto cleanup;
+
     if (!(obj = virNWFilterObjListAssignDef(driver->nwfilters, def)))
         goto cleanup;
     def = NULL;
     objdef = virNWFilterObjGetDef(obj);
 
-    if (virNWFilterSaveConfig(driver->configDir, objdef) < 0) {
+    if (virNWFilterSaveConfig(configFile, objdef) < 0) {
         virNWFilterObjListRemove(driver->nwfilters, obj);
         goto cleanup;
     }
@@ -525,6 +529,7 @@ nwfilterDefineXML(virConnectPtr conn,
     ret = virGetNWFilter(conn, objdef->name, objdef->uuid);
 
  cleanup:
+    VIR_FREE(configFile);
     virNWFilterDefFree(def);
     if (obj)
         virNWFilterObjUnlock(obj);
@@ -541,6 +546,7 @@ nwfilterUndefine(virNWFilterPtr nwfilter)
 {
     virNWFilterObjPtr obj;
     virNWFilterDefPtr def;
+    char *configFile = NULL;
     int ret = -1;
 
     nwfilterDriverLock();
@@ -561,7 +567,10 @@ nwfilterUndefine(virNWFilterPtr nwfilter)
         goto cleanup;
     }
 
-    if (virNWFilterDeleteDef(driver->configDir, def) < 0)
+    if (!(configFile = virFileBuildPath(driver->configDir, def->name, ".xml")))
+        goto cleanup;
+
+    if (virNWFilterDeleteDef(configFile, def) < 0)
         goto cleanup;
 
     virNWFilterObjListRemove(driver->nwfilters, obj);
@@ -569,6 +578,7 @@ nwfilterUndefine(virNWFilterPtr nwfilter)
     ret = 0;
 
  cleanup:
+    VIR_FREE(configFile);
     if (obj)
         virNWFilterObjUnlock(obj);
 
-- 
2.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux