diff mbox

[3/4] nwfilter: Push configFile building into LoadConfig

Message ID c44c1e21a24c282a84b2a41311f4cba1359a4a30.1461540078.git.crobinso@redhat.com
State Accepted
Commit 0feb1c6c249e791405297c8a6c25fd81c00b424d
Headers show

Commit Message

Cole Robinson April 24, 2016, 11:22 p.m. UTC
This matches the pattern used for network object APIs, and we want
configDir in LoadConfig for upcoming patches
---
 src/conf/nwfilter_conf.c | 45 ++++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

-- 
2.7.3

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

Comments

Cole Robinson April 30, 2016, 7:19 p.m. UTC | #1
On 04/30/2016 09:32 AM, John Ferlan wrote:
> 

> 

> On 04/24/2016 07:22 PM, Cole Robinson wrote:

>> This matches the pattern used for network object APIs, and we want

>> configDir in LoadConfig for upcoming patches

>> ---

>>  src/conf/nwfilter_conf.c | 45 ++++++++++++++++++++++++---------------------

>>  1 file changed, 24 insertions(+), 21 deletions(-)

>>

>> diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c

>> index d02bbff..d8e83f0 100644

>> --- a/src/conf/nwfilter_conf.c

>> +++ b/src/conf/nwfilter_conf.c

>> @@ -3156,30 +3156,39 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,

>>  

>>  

>>  static virNWFilterObjPtr

>> -virNWFilterObjLoad(virNWFilterObjListPtr nwfilters,

>> -                   const char *file,

>> -                   const char *path)

>> +virNWFilterLoadConfig(virNWFilterObjListPtr nwfilters,

>> +                      const char *configDir,

>> +                      const char *name)

>>  {

>> -    virNWFilterDefPtr def;

>> +    virNWFilterDefPtr def = NULL;

>>      virNWFilterObjPtr nwfilter;

>> +    char *configFile = NULL;

>>  

>> -    if (!(def = virNWFilterDefParseFile(path)))

>> -        return NULL;

>> +    if (!(configFile = virFileBuildPath(configDir, name, ".xml")))

>> +        goto error;

>>  

>> -    if (!virFileMatchesNameSuffix(file, def->name, ".xml")) {

>> +    if (!(def = virNWFilterDefParseFile(configFile)))

>> +        goto error;

>> +

>> +    if (STRNEQ(name, def->name)) {

>>          virReportError(VIR_ERR_XML_ERROR,

>> -                       _("network filter config filename '%s' does not match name '%s'"),

>> -                       path, def->name);

>> -        virNWFilterDefFree(def);

>> -        return NULL;

>> +                       _("network filter config filename '%s' "

>> +                         "does not match name '%s'"),

>> +                       configFile, def->name);

>> +        goto error;

>>      }

>>  

>>      if (!(nwfilter = virNWFilterObjAssignDef(nwfilters, def))) {

>> -        virNWFilterDefFree(def);

>> -        return NULL;

>> +        goto error;

>>      }

> 

> Make sure you run 'syntax-check'... A window I had used for compiles was

> obscured and I see the syntax-check fails because of the { } and one

> line goto error.

> 


Yeah I just noticed that after your first review :/ Not sure how I keep
missing syntax-check ...

I've queued this series for after the release (with that bit fixed), thanks

- Cole

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

Patch

diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index d02bbff..d8e83f0 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -3156,30 +3156,39 @@  virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
 
 
 static virNWFilterObjPtr
-virNWFilterObjLoad(virNWFilterObjListPtr nwfilters,
-                   const char *file,
-                   const char *path)
+virNWFilterLoadConfig(virNWFilterObjListPtr nwfilters,
+                      const char *configDir,
+                      const char *name)
 {
-    virNWFilterDefPtr def;
+    virNWFilterDefPtr def = NULL;
     virNWFilterObjPtr nwfilter;
+    char *configFile = NULL;
 
-    if (!(def = virNWFilterDefParseFile(path)))
-        return NULL;
+    if (!(configFile = virFileBuildPath(configDir, name, ".xml")))
+        goto error;
 
-    if (!virFileMatchesNameSuffix(file, def->name, ".xml")) {
+    if (!(def = virNWFilterDefParseFile(configFile)))
+        goto error;
+
+    if (STRNEQ(name, def->name)) {
         virReportError(VIR_ERR_XML_ERROR,
-                       _("network filter config filename '%s' does not match name '%s'"),
-                       path, def->name);
-        virNWFilterDefFree(def);
-        return NULL;
+                       _("network filter config filename '%s' "
+                         "does not match name '%s'"),
+                       configFile, def->name);
+        goto error;
     }
 
     if (!(nwfilter = virNWFilterObjAssignDef(nwfilters, def))) {
-        virNWFilterDefFree(def);
-        return NULL;
+        goto error;
     }
 
+    VIR_FREE(configFile);
     return nwfilter;
+
+ error:
+    VIR_FREE(configFile);
+    virNWFilterDefFree(def);
+    return NULL;
 }
 
 
@@ -3200,23 +3209,17 @@  virNWFilterLoadAllConfigs(virNWFilterObjListPtr nwfilters,
     }
 
     while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
-        char *path;
         virNWFilterObjPtr nwfilter;
 
         if (entry->d_name[0] == '.')
             continue;
 
-        if (!virFileHasSuffix(entry->d_name, ".xml"))
-            continue;
-
-        if (!(path = virFileBuildPath(configDir, entry->d_name, NULL)))
+        if (!virFileStripSuffix(entry->d_name, ".xml"))
             continue;
 
-        nwfilter = virNWFilterObjLoad(nwfilters, entry->d_name, path);
+        nwfilter = virNWFilterLoadConfig(nwfilters, configDir, entry->d_name);
         if (nwfilter)
             virNWFilterObjUnlock(nwfilter);
-
-        VIR_FREE(path);
     }
 
     closedir(dir);