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

[libvirt] [PATCH RFC 5/9] nwfilter: Convert virNWFilterObj[List] to use virPoolObj[Table]



Use the virPoolObj[Table] object management model in order to manage the
NWFilter objects.

While making the adjustments to use the new model, there are some code
formatting adjustments that were also made with the goal to follow more
recent code flow and layout.

All nwfilter object management API's have their own virnwfilterobj
entry points now instead of being mashed in with nwfilter_conf

Signed-off-by: John Ferlan <jferlan redhat com>
---
 po/POTFILES.in                         |   1 +
 src/Makefile.am                        |   3 +-
 src/conf/nwfilter_conf.c               | 381 ++-------------------------------
 src/conf/nwfilter_conf.h               |  69 +-----
 src/conf/virnwfilterobj.c              | 373 ++++++++++++++++++++++++++++++++
 src/conf/virnwfilterobj.h              |  64 ++++++
 src/libvirt_private.syms               |  23 +-
 src/nwfilter/nwfilter_driver.c         | 225 +++++++------------
 src/nwfilter/nwfilter_gentech_driver.c | 111 +++++-----
 src/nwfilter/nwfilter_gentech_driver.h |   2 +-
 src/nwfilter/nwfilter_tech_driver.h    |   2 +-
 11 files changed, 612 insertions(+), 642 deletions(-)
 create mode 100644 src/conf/virnwfilterobj.c
 create mode 100644 src/conf/virnwfilterobj.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 37379b5..0435265 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -43,6 +43,7 @@ src/conf/storage_conf.c
 src/conf/virchrdev.c
 src/conf/virdomainobjlist.c
 src/conf/virnodedeviceobj.c
+src/conf/virnwfilterobj.c
 src/conf/virpoolobj.c
 src/conf/virsecretobj.c
 src/cpu/cpu.c
diff --git a/src/Makefile.am b/src/Makefile.am
index d864e6c..73f3dd0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -371,7 +371,8 @@ NWFILTER_PARAM_CONF_SOURCES =					\
 
 NWFILTER_CONF_SOURCES =						\
 		$(NWFILTER_PARAM_CONF_SOURCES)			\
-		conf/nwfilter_conf.c conf/nwfilter_conf.h
+		conf/nwfilter_conf.c conf/nwfilter_conf.h	\
+		conf/virnwfilterobj.c conf/virnwfilterobj.h
 
 # "Generic" poolobj sources
 POOLOBJ_SOURCES =						\
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 2cdcfa7..2d55667 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -30,7 +30,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <dirent.h>
 #if HAVE_NET_ETHERNET_H
 # include <net/ethernet.h>
 #endif
@@ -326,8 +325,9 @@ virNWFilterEntryFree(virNWFilterEntryPtr entry)
 
 
 void
-virNWFilterDefFree(virNWFilterDefPtr def)
+virNWFilterDefFree(void *opaque)
 {
+    virNWFilterDefPtr def = opaque;
     size_t i;
     if (!def)
         return;
@@ -344,32 +344,6 @@ virNWFilterDefFree(virNWFilterDefPtr def)
 }
 
 
-void
-virNWFilterObjFree(virNWFilterObjPtr obj)
-{
-    if (!obj)
-        return;
-
-    virNWFilterDefFree(obj->def);
-    virNWFilterDefFree(obj->newDef);
-
-    virMutexDestroy(&obj->lock);
-
-    VIR_FREE(obj);
-}
-
-
-void
-virNWFilterObjListFree(virNWFilterObjListPtr nwfilters)
-{
-    size_t i;
-    for (i = 0; i < nwfilters->count; i++)
-        virNWFilterObjFree(nwfilters->objs[i]);
-    VIR_FREE(nwfilters->objs);
-    nwfilters->count = 0;
-}
-
-
 static int
 virNWFilterRuleDefAddVar(virNWFilterRuleDefPtr nwf,
                          nwItemDesc *item,
@@ -418,27 +392,6 @@ virNWFilterRuleDefAddString(virNWFilterRuleDefPtr nwf,
 }
 
 
-void
-virNWFilterObjRemove(virNWFilterObjListPtr nwfilters,
-                     virNWFilterObjPtr nwfilter)
-{
-    size_t i;
-
-    virNWFilterObjUnlock(nwfilter);
-
-    for (i = 0; i < nwfilters->count; i++) {
-        virNWFilterObjLock(nwfilters->objs[i]);
-        if (nwfilters->objs[i] == nwfilter) {
-            virNWFilterObjUnlock(nwfilters->objs[i]);
-            virNWFilterObjFree(nwfilters->objs[i]);
-
-            VIR_DELETE_ELEMENT(nwfilters->objs, i, nwfilters->count);
-            break;
-        }
-        virNWFilterObjUnlock(nwfilters->objs[i]);
-    }
-}
-
 union data {
     void *v;
     char *c;
@@ -2779,39 +2732,6 @@ virNWFilterDefParseFile(const char *filename)
 }
 
 
-virNWFilterObjPtr
-virNWFilterObjFindByUUID(virNWFilterObjListPtr nwfilters,
-                         const unsigned char *uuid)
-{
-    size_t i;
-
-    for (i = 0; i < nwfilters->count; i++) {
-        virNWFilterObjLock(nwfilters->objs[i]);
-        if (!memcmp(nwfilters->objs[i]->def->uuid, uuid, VIR_UUID_BUFLEN))
-            return nwfilters->objs[i];
-        virNWFilterObjUnlock(nwfilters->objs[i]);
-    }
-
-    return NULL;
-}
-
-
-virNWFilterObjPtr
-virNWFilterObjFindByName(virNWFilterObjListPtr nwfilters, const char *name)
-{
-    size_t i;
-
-    for (i = 0; i < nwfilters->count; i++) {
-        virNWFilterObjLock(nwfilters->objs[i]);
-        if (STREQ_NULLABLE(nwfilters->objs[i]->def->name, name))
-            return nwfilters->objs[i];
-        virNWFilterObjUnlock(nwfilters->objs[i]);
-    }
-
-    return NULL;
-}
-
-
 int virNWFilterSaveXML(const char *configDir,
                        virNWFilterDefPtr def,
                        const char *xml)
@@ -2860,62 +2780,6 @@ int virNWFilterSaveConfig(const char *configDir,
 }
 
 
-static int
-_virNWFilterDefLoopDetect(virNWFilterObjListPtr nwfilters,
-                          virNWFilterDefPtr def,
-                          const char *filtername)
-{
-    int rc = 0;
-    size_t i;
-    virNWFilterEntryPtr entry;
-    virNWFilterObjPtr obj;
-
-    if (!def)
-        return 0;
-
-    for (i = 0; i < def->nentries; i++) {
-        entry = def->filterEntries[i];
-        if (entry->include) {
-
-            if (STREQ(filtername, entry->include->filterref)) {
-                rc = -1;
-                break;
-            }
-
-            obj = virNWFilterObjFindByName(nwfilters,
-                                           entry->include->filterref);
-            if (obj) {
-                rc = _virNWFilterDefLoopDetect(nwfilters,
-                                               obj->def, filtername);
-
-                virNWFilterObjUnlock(obj);
-                if (rc < 0)
-                    break;
-            }
-        }
-    }
-
-    return rc;
-}
-
-
-/*
- * virNWFilterDefLoopDetect:
- * @nwfilters : the nwfilters to search
- * @def : the filter definition that may add a loop and is to be tested
- *
- * Detect a loop introduced through the filters being able to
- * reference each other.
- *
- * Returns 0 in case no loop was detected, -1 otherwise.
- */
-static int
-virNWFilterDefLoopDetect(virNWFilterObjListPtr nwfilters,
-                         virNWFilterDefPtr def)
-{
-    return _virNWFilterDefLoopDetect(nwfilters, def, def->name);
-}
-
 int nCallbackDriver;
 #define MAX_CALLBACK_DRIVER 10
 static virNWFilterCallbackDriverPtr callbackDrvArray[MAX_CALLBACK_DRIVER];
@@ -2987,7 +2851,7 @@ virNWFilterInstFiltersOnAllVMs(void)
     return 0;
 }
 
-static int
+int
 virNWFilterTriggerVMFilterRebuild(void)
 {
     size_t i;
@@ -3028,223 +2892,23 @@ virNWFilterTriggerVMFilterRebuild(void)
 
 
 int
-virNWFilterTestUnassignDef(virNWFilterObjPtr nwfilter)
-{
-    int rc = 0;
-
-    nwfilter->wantRemoved = 1;
-    /* trigger the update on VMs referencing the filter */
-    if (virNWFilterTriggerVMFilterRebuild())
-        rc = -1;
-
-    nwfilter->wantRemoved = 0;
-
-    return rc;
-}
-
-static bool
-virNWFilterDefEqual(const virNWFilterDef *def1, virNWFilterDefPtr def2,
-                    bool cmpUUIDs)
-{
-    bool ret = false;
-    unsigned char rem_uuid[VIR_UUID_BUFLEN];
-    char *xml1, *xml2 = NULL;
-
-    if (!cmpUUIDs) {
-        /* make sure the UUIDs are equal */
-        memcpy(rem_uuid, def2->uuid, sizeof(rem_uuid));
-        memcpy(def2->uuid, def1->uuid, sizeof(def2->uuid));
-    }
-
-    if (!(xml1 = virNWFilterDefFormat(def1)) ||
-        !(xml2 = virNWFilterDefFormat(def2)))
-        goto cleanup;
-
-    ret = STREQ(xml1, xml2);
-
- cleanup:
-    if (!cmpUUIDs)
-        memcpy(def2->uuid, rem_uuid, sizeof(rem_uuid));
-
-    VIR_FREE(xml1);
-    VIR_FREE(xml2);
-
-    return ret;
-}
-
-virNWFilterObjPtr
-virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
-                        virNWFilterDefPtr def)
-{
-    virNWFilterObjPtr nwfilter;
-
-    nwfilter = virNWFilterObjFindByUUID(nwfilters, def->uuid);
-
-    if (nwfilter) {
-        if (STRNEQ(def->name, nwfilter->def->name)) {
-            virReportError(VIR_ERR_OPERATION_FAILED,
-                           _("filter with same UUID but different name "
-                             "('%s') already exists"),
-                           nwfilter->def->name);
-            virNWFilterObjUnlock(nwfilter);
-            return NULL;
-        }
-        virNWFilterObjUnlock(nwfilter);
-    } else {
-        nwfilter = virNWFilterObjFindByName(nwfilters, def->name);
-        if (nwfilter) {
-            char uuidstr[VIR_UUID_STRING_BUFLEN];
-            virUUIDFormat(nwfilter->def->uuid, uuidstr);
-            virReportError(VIR_ERR_OPERATION_FAILED,
-                           _("filter '%s' already exists with uuid %s"),
-                           def->name, uuidstr);
-            virNWFilterObjUnlock(nwfilter);
-            return NULL;
-        }
-    }
-
-    if (virNWFilterDefLoopDetect(nwfilters, def) < 0) {
-        virReportError(VIR_ERR_OPERATION_FAILED,
-                       "%s", _("filter would introduce a loop"));
-        return NULL;
-    }
-
-
-    if ((nwfilter = virNWFilterObjFindByName(nwfilters, def->name))) {
-
-        if (virNWFilterDefEqual(def, nwfilter->def, false)) {
-            virNWFilterDefFree(nwfilter->def);
-            nwfilter->def = def;
-            return nwfilter;
-        }
-
-        nwfilter->newDef = def;
-        /* trigger the update on VMs referencing the filter */
-        if (virNWFilterTriggerVMFilterRebuild()) {
-            nwfilter->newDef = NULL;
-            virNWFilterObjUnlock(nwfilter);
-            return NULL;
-        }
-
-        virNWFilterDefFree(nwfilter->def);
-        nwfilter->def = def;
-        nwfilter->newDef = NULL;
-        return nwfilter;
-    }
-
-    if (VIR_ALLOC(nwfilter) < 0)
-        return NULL;
-
-    if (virMutexInitRecursive(&nwfilter->lock) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("cannot initialize mutex"));
-        VIR_FREE(nwfilter);
-        return NULL;
-    }
-    virNWFilterObjLock(nwfilter);
-    nwfilter->active = 0;
-
-    if (VIR_APPEND_ELEMENT_COPY(nwfilters->objs,
-                                nwfilters->count, nwfilter) < 0) {
-        virNWFilterObjUnlock(nwfilter);
-        virNWFilterObjFree(nwfilter);
-        return NULL;
-    }
-    nwfilter->def = def;
-
-    return nwfilter;
-}
-
-
-static virNWFilterObjPtr
-virNWFilterLoadConfig(virNWFilterObjListPtr nwfilters,
-                      const char *configDir,
-                      const char *name)
-{
-    virNWFilterDefPtr def = NULL;
-    virNWFilterObjPtr nwfilter;
-    char *configFile = NULL;
-
-    if (!(configFile = virFileBuildPath(configDir, name, ".xml")))
-        goto error;
-
-    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'"),
-                       configFile, def->name);
-        goto error;
-    }
-
-    /* We generated a UUID, make it permanent by saving the config to disk */
-    if (!def->uuid_specified &&
-        virNWFilterSaveConfig(configDir, def) < 0)
-        goto error;
-
-    if (!(nwfilter = virNWFilterObjAssignDef(nwfilters, def)))
-        goto error;
-
-    VIR_FREE(configFile);
-    return nwfilter;
-
- error:
-    VIR_FREE(configFile);
-    virNWFilterDefFree(def);
-    return NULL;
-}
-
-
-int
-virNWFilterLoadAllConfigs(virNWFilterObjListPtr nwfilters,
-                          const char *configDir)
-{
-    DIR *dir;
-    struct dirent *entry;
-    int ret = -1;
-    int rc;
-
-    if ((rc = virDirOpenIfExists(&dir, configDir)) <= 0)
-        return rc;
-
-    while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
-        virNWFilterObjPtr nwfilter;
-
-        if (!virFileStripSuffix(entry->d_name, ".xml"))
-            continue;
-
-        nwfilter = virNWFilterLoadConfig(nwfilters, configDir, entry->d_name);
-        if (nwfilter)
-            virNWFilterObjUnlock(nwfilter);
-    }
-
-    VIR_DIR_CLOSE(dir);
-    return ret;
-}
-
-
-int
-virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
-                      virNWFilterDefPtr def)
+virNWFilterSaveDef(const char *configDir,
+                   virNWFilterDefPtr def)
 {
     char uuidstr[VIR_UUID_STRING_BUFLEN];
     char *xml;
     int ret = -1;
     char *configFile = NULL;
 
-    if (virFileMakePath(driver->configDir) < 0) {
+    if (virFileMakePath(configDir) < 0) {
         virReportSystemError(errno,
                              _("cannot create config directory %s"),
-                             driver->configDir);
+                             configDir);
         goto error;
     }
 
-    if (!(configFile = virFileBuildPath(driver->configDir,
-                                        def->name, ".xml"))) {
+    if (!(configFile = virFileBuildPath(configDir, def->name, ".xml")))
         goto error;
-    }
 
     if (!(xml = virNWFilterDefFormat(def))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3265,26 +2929,24 @@ virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
 
 
 int
-virNWFilterObjDeleteDef(const char *configDir,
-                        virNWFilterObjPtr nwfilter)
+virNWFilterDeleteDef(const char *configDir,
+                     virNWFilterDefPtr def)
 {
     int ret = -1;
     char *configFile = NULL;
 
-    if (!(configFile = virFileBuildPath(configDir,
-                                        nwfilter->def->name, ".xml"))) {
-        goto error;
-    }
+    if (!(configFile = virFileBuildPath(configDir, def->name, ".xml")))
+        return -1;
 
     if (unlink(configFile) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("cannot remove config for %s"),
-                       nwfilter->def->name);
-        goto error;
+                       _("cannot remove config for %s"), def->name);
+        goto cleanup;
     }
 
     ret = 0;
- error:
+
+ cleanup:
     VIR_FREE(configFile);
     return ret;
 }
@@ -3572,17 +3234,6 @@ void virNWFilterConfLayerShutdown(void)
 }
 
 
-void virNWFilterObjLock(virNWFilterObjPtr obj)
-{
-    virMutexLock(&obj->lock);
-}
-
-void virNWFilterObjUnlock(virNWFilterObjPtr obj)
-{
-    virMutexUnlock(&obj->lock);
-}
-
-
 bool virNWFilterRuleIsProtocolIPv4(virNWFilterRuleDefPtr rule)
 {
     if (rule->prtclType >= VIR_NWFILTER_RULE_PROTOCOL_TCP &&
diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h
index ea3cd5c..7f997a4 100644
--- a/src/conf/nwfilter_conf.h
+++ b/src/conf/nwfilter_conf.h
@@ -546,41 +546,6 @@ struct _virNWFilterDef {
 };
 
 
-typedef struct _virNWFilterObj virNWFilterObj;
-typedef virNWFilterObj *virNWFilterObjPtr;
-
-struct _virNWFilterObj {
-    virMutex lock;
-
-    int active;
-    int wantRemoved;
-
-    virNWFilterDefPtr def;
-    virNWFilterDefPtr newDef;
-};
-
-
-typedef struct _virNWFilterObjList virNWFilterObjList;
-typedef virNWFilterObjList *virNWFilterObjListPtr;
-struct _virNWFilterObjList {
-    size_t count;
-    virNWFilterObjPtr *objs;
-};
-
-
-typedef struct _virNWFilterDriverState virNWFilterDriverState;
-typedef virNWFilterDriverState *virNWFilterDriverStatePtr;
-struct _virNWFilterDriverState {
-    virMutex lock;
-    bool privileged;
-
-    virNWFilterObjList nwfilters;
-
-    char *configDir;
-    bool watchingFirewallD;
-};
-
-
 typedef enum {
     STEP_APPLY_NEW,
     STEP_TEAR_NEW,
@@ -597,30 +562,15 @@ struct domUpdateCBStruct {
 
 void virNWFilterRuleDefFree(virNWFilterRuleDefPtr def);
 
-void virNWFilterDefFree(virNWFilterDefPtr def);
-void virNWFilterObjListFree(virNWFilterObjListPtr nwfilters);
-void virNWFilterObjRemove(virNWFilterObjListPtr nwfilters,
-                          virNWFilterObjPtr nwfilter);
-
-void virNWFilterObjFree(virNWFilterObjPtr obj);
+void virNWFilterDefFree(void *opaque);
 
-virNWFilterObjPtr virNWFilterObjFindByUUID(virNWFilterObjListPtr nwfilters,
-                                           const unsigned char *uuid);
+int virNWFilterTriggerVMFilterRebuild(void);
 
-virNWFilterObjPtr virNWFilterObjFindByName(virNWFilterObjListPtr nwfilters,
-                                           const char *name);
-
-
-int virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
-                          virNWFilterDefPtr def);
+int virNWFilterSaveDef(const char *configDir,
+                       virNWFilterDefPtr def);
 
-int virNWFilterObjDeleteDef(const char *configDir,
-                            virNWFilterObjPtr nwfilter);
-
-virNWFilterObjPtr virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
-                                          virNWFilterDefPtr def);
-
-int virNWFilterTestUnassignDef(virNWFilterObjPtr nwfilter);
+int virNWFilterDeleteDef(const char *configDir,
+                         virNWFilterDefPtr def);
 
 virNWFilterDefPtr virNWFilterDefParseNode(xmlDocPtr xml,
                                           xmlNodePtr root);
@@ -634,18 +584,12 @@ int virNWFilterSaveXML(const char *configDir,
 int virNWFilterSaveConfig(const char *configDir,
                           virNWFilterDefPtr def);
 
-int virNWFilterLoadAllConfigs(virNWFilterObjListPtr nwfilters,
-                              const char *configDir);
-
 char *virNWFilterConfigFile(const char *dir,
                             const char *name);
 
 virNWFilterDefPtr virNWFilterDefParseString(const char *xml);
 virNWFilterDefPtr virNWFilterDefParseFile(const char *filename);
 
-void virNWFilterObjLock(virNWFilterObjPtr obj);
-void virNWFilterObjUnlock(virNWFilterObjPtr obj);
-
 void virNWFilterWriteLockFilterUpdates(void);
 void virNWFilterReadLockFilterUpdates(void);
 void virNWFilterUnlockFilterUpdates(void);
@@ -655,7 +599,6 @@ void virNWFilterConfLayerShutdown(void);
 
 int virNWFilterInstFiltersOnAllVMs(void);
 
-
 typedef int (*virNWFilterRebuild)(virDomainObjListIterator domUpdateCB,
                                   void *data);
 typedef void (*virNWFilterVoidCall)(void);
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
new file mode 100644
index 0000000..44c171f
--- /dev/null
+++ b/src/conf/virnwfilterobj.c
@@ -0,0 +1,373 @@
+/*
+ * virnwfilterobj.c: network filter object processing
+ *                   (derived from nwfilter_conf.c)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <dirent.h>
+
+#include "datatypes.h"
+
+#include "viralloc.h"
+#include "virerror.h"
+#include "virfile.h"
+#include "virlog.h"
+#include "virnwfilterobj.h"
+#include "virstring.h"
+
+#define VIR_FROM_THIS VIR_FROM_NWFILTER
+
+VIR_LOG_INIT("conf.virnwfilterobj");
+
+struct nwfilterLoopSearchData {
+    const char *filtername;
+};
+
+static bool
+nwfilterLoopSearch(virPoolObjPtr obj,
+                   void *opaque)
+{
+    virNWFilterDefPtr def = virPoolObjGetDef(obj);
+    struct nwfilterLoopSearchData *data = opaque;
+    virNWFilterEntryPtr entry;
+    size_t i;
+
+    for (i = 0; i < def->nentries; i++) {
+        entry = def->filterEntries[i];
+        if (entry->include &&
+            STREQ(data->filtername, entry->include->filterref))
+            return true;
+    }
+
+    return false;
+}
+
+
+/*
+ * nwfilterLoopDetect:
+ * @nwfilters : the nwfilters to search
+ * @filtername: the filter name that may add a loop and is to be tested
+ *
+ * Detect a loop introduced through the filters being able to
+ * reference each other.
+ *
+ * Returns 0 in case no loop was detected, -1 otherwise.
+ */
+static int
+nwfilterLoopDetect(virPoolObjTablePtr nwfilters,
+                   const char *filtername)
+{
+    struct nwfilterLoopSearchData data = { .filtername = filtername };
+    virPoolObjPtr obj;
+
+    if ((obj = virPoolObjTableSearch(nwfilters, nwfilterLoopSearch, &data))) {
+        virObjectUnlock(obj);
+        return -1;
+    }
+
+    return 0;
+}
+
+
+static bool
+nwfilterDefEqual(const virNWFilterDef *def1,
+                 virNWFilterDefPtr def2,
+                 bool cmpUUIDs)
+{
+    bool ret = false;
+    unsigned char rem_uuid[VIR_UUID_BUFLEN];
+    char *xml1, *xml2 = NULL;
+
+    if (!cmpUUIDs) {
+        /* make sure the UUIDs are equal */
+        memcpy(rem_uuid, def2->uuid, sizeof(rem_uuid));
+        memcpy(def2->uuid, def1->uuid, sizeof(def2->uuid));
+    }
+
+    if (!(xml1 = virNWFilterDefFormat(def1)) ||
+        !(xml2 = virNWFilterDefFormat(def2)))
+        goto cleanup;
+
+    ret = STREQ(xml1, xml2);
+
+ cleanup:
+    if (!cmpUUIDs)
+        memcpy(def2->uuid, rem_uuid, sizeof(rem_uuid));
+
+    VIR_FREE(xml1);
+    VIR_FREE(xml2);
+
+    return ret;
+}
+
+
+static int
+nwfilterAssignDef(virPoolObjPtr obj,
+                  void *newDef,
+                  void *oldDef ATTRIBUTE_UNUSED,
+                  unsigned int assignFlags ATTRIBUTE_UNUSED)
+{
+    virNWFilterDefPtr newdef = newDef;
+
+
+    if (nwfilterDefEqual(newdef, virPoolObjGetDef(obj), false)) {
+        virPoolObjSetDef(obj, newdef);
+    } else {
+        virPoolObjSetNewDef(obj, newdef);
+
+        /* trigger the update on VMs referencing the filter */
+        if (virNWFilterTriggerVMFilterRebuild()) {
+            virPoolObjSetNewDef(obj, NULL);
+            return -1;
+        }
+
+        virPoolObjSetDef(obj, newdef);
+        virPoolObjSetNewDef(obj, NULL);
+    }
+    return 0;
+}
+
+
+virPoolObjPtr
+virNWFilterObjAdd(virPoolObjTablePtr nwfilters,
+                  virNWFilterDefPtr def)
+{
+    virPoolObjPtr obj;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+    /* Check if this filter def's name is referenced already by
+     * some other filter's include path */
+    if (nwfilterLoopDetect(nwfilters, def->name) < 0) {
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       _("filter '%s' would introduce a loop"), def->name);
+        return NULL;
+    }
+
+    virUUIDFormat(def->uuid, uuidstr);
+    if (!(obj = virPoolObjTableAdd(nwfilters, uuidstr, def->name,
+                                   def, NULL, NULL, virNWFilterDefFree,
+                                   nwfilterAssignDef, 0)))
+        return NULL;
+
+    return obj;
+}
+
+
+int
+virNWFilterObjTestUnassignDef(virPoolObjPtr obj)
+{
+    int rc = 0;
+
+    virPoolObjSetBeingRemoved(obj, true);
+    /* trigger the update on VMs referencing the filter */
+    if (virNWFilterTriggerVMFilterRebuild())
+        rc = -1;
+    virPoolObjSetBeingRemoved(obj, false);
+
+    return rc;
+}
+
+
+struct nwfilterCountData {
+    int count;
+};
+
+static int
+nwfilterCount(virPoolObjPtr obj ATTRIBUTE_UNUSED,
+              void *opaque)
+{
+    struct nwfilterCountData *data = opaque;
+
+    data->count++;
+    return 0;
+}
+
+
+int
+virNWFilterObjNumOfNWFilters(virPoolObjTablePtr nwfilters,
+                             virConnectPtr conn,
+                             virPoolObjACLFilter aclfilter)
+{
+    struct nwfilterCountData data = { .count = 0 };
+
+    if (virPoolObjTableList(nwfilters, conn, aclfilter,
+                            nwfilterCount, &data) < 0)
+        return 0;
+
+    return data.count;
+}
+
+
+struct nwfilterNameData {
+    int nnames;
+    char **const names;
+    int maxnames;
+};
+
+static int nwfilterGetNames(virPoolObjPtr obj,
+                            void *opaque)
+{
+    virNWFilterDefPtr def = virPoolObjGetDef(obj);
+    struct nwfilterNameData *data = opaque;
+
+    if (data->nnames < data->maxnames) {
+        if (VIR_STRDUP(data->names[data->nnames++], def->name) < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
+
+int
+virNWFilterObjGetFilters(virPoolObjTablePtr nwfilters,
+                         virConnectPtr conn,
+                         virPoolObjACLFilter aclfilter,
+                         char **names,
+                         int maxnames)
+{
+    struct nwfilterNameData data = { .nnames = 0,
+                                     .names = names,
+                                     .maxnames = maxnames };
+
+    if (virPoolObjTableList(nwfilters, conn, aclfilter,
+                            nwfilterGetNames, &data) < 0)
+        goto failure;
+
+    return data.nnames;
+
+ failure:
+    while (data.nnames >= 0)
+        VIR_FREE(data.names[--data.nnames]);
+
+    return -1;
+}
+
+
+int
+virNWFilterObjExportList(virConnectPtr conn,
+                         virPoolObjTablePtr nwfilters,
+                         virNWFilterPtr **filters,
+                         virPoolObjACLFilter aclfilter,
+                         unsigned int flags)
+{
+    virPoolObjPtr *objs = NULL;
+    size_t nobjs = 0;
+    virNWFilterPtr *filts = NULL;
+    int ret = -1;
+    size_t i;
+
+    if (virPoolObjTableCollect(nwfilters, conn, &objs, &nobjs, aclfilter,
+                               NULL, flags) < 0)
+        return -1;
+
+    if (filters) {
+        if (VIR_ALLOC_N(filts, nobjs + 1) < 0)
+            goto cleanup;
+
+        for (i = 0; i < nobjs; i++) {
+            virPoolObjPtr obj = objs[i];
+            virNWFilterDefPtr def;
+
+            virObjectLock(obj);
+            def = virPoolObjGetDef(obj);
+            filts[i] = virGetNWFilter(conn, def->name, def->uuid);
+            virObjectUnlock(obj);
+
+            if (!filts[i])
+                goto cleanup;
+        }
+
+        *filters = filts;
+        filts = NULL;
+    }
+
+    ret = nobjs;
+
+ cleanup:
+    virObjectListFree(filts);
+    virObjectListFreeCount(objs, nobjs);
+    return ret;
+}
+
+
+static virPoolObjPtr
+virNWFilterLoadConfig(virPoolObjTablePtr nwfilters,
+                      const char *configDir,
+                      const char *name)
+{
+    virNWFilterDefPtr def = NULL;
+    virPoolObjPtr obj;
+    char *configFile = NULL;
+
+    if (!(configFile = virFileBuildPath(configDir, name, ".xml")))
+        goto error;
+
+    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'"),
+                       configFile, def->name);
+        goto error;
+    }
+
+    /* We generated a UUID, make it permanent by saving the config to disk */
+    if (!def->uuid_specified &&
+        virNWFilterSaveConfig(configDir, def) < 0)
+        goto error;
+
+    if (!(obj = virNWFilterObjAdd(nwfilters, def)))
+        goto error;
+
+    VIR_FREE(configFile);
+    return obj;
+
+ error:
+    VIR_FREE(configFile);
+    virNWFilterDefFree(def);
+    return NULL;
+}
+
+
+int
+virNWFilterObjLoadAllConfigs(virPoolObjTablePtr nwfilters,
+                             const char *configDir)
+{
+    DIR *dir;
+    struct dirent *entry;
+    int ret = -1;
+    int rc;
+
+    if ((rc = virDirOpenIfExists(&dir, configDir)) <= 0)
+        return rc;
+
+    while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
+        virPoolObjPtr obj;
+
+        if (!virFileStripSuffix(entry->d_name, ".xml"))
+            continue;
+
+        if ((obj = virNWFilterLoadConfig(nwfilters, configDir, entry->d_name)))
+            virPoolObjEndAPI(&obj);
+    }
+
+    VIR_DIR_CLOSE(dir);
+    return ret;
+}
diff --git a/src/conf/virnwfilterobj.h b/src/conf/virnwfilterobj.h
new file mode 100644
index 0000000..29eaf10
--- /dev/null
+++ b/src/conf/virnwfilterobj.h
@@ -0,0 +1,64 @@
+/*
+ * virnwfilterobj.h: network filter object processing
+ *                  (derived from nwfilter_conf.h)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+#ifndef VIRNWFILTEROBJ_H
+# define VIRNWFILTEROBJ_H
+
+# include "internal.h"
+
+# include "nwfilter_conf.h"
+# include "virpoolobj.h"
+
+typedef struct _virNWFilterDriverState virNWFilterDriverState;
+typedef virNWFilterDriverState *virNWFilterDriverStatePtr;
+struct _virNWFilterDriverState {
+    virMutex lock;
+    bool privileged;
+
+    virPoolObjTablePtr nwfilters;
+
+    char *configDir;
+    bool watchingFirewallD;
+};
+
+
+virPoolObjPtr virNWFilterObjAdd(virPoolObjTablePtr nwfilters,
+                                virNWFilterDefPtr def);
+
+int virNWFilterObjTestUnassignDef(virPoolObjPtr obj);
+
+int virNWFilterObjNumOfNWFilters(virPoolObjTablePtr nwfilters,
+                                 virConnectPtr conn,
+                                 virPoolObjACLFilter aclfilter);
+
+int virNWFilterObjGetFilters(virPoolObjTablePtr nwfilters,
+                             virConnectPtr conn,
+                             virPoolObjACLFilter aclfilter,
+                             char **names,
+                             int maxnames);
+
+int virNWFilterObjExportList(virConnectPtr conn,
+                             virPoolObjTablePtr nwfilters,
+                             virNWFilterPtr **filters,
+                             virPoolObjACLFilter aclfilter,
+                             unsigned int flags);
+
+int virNWFilterObjLoadAllConfigs(virPoolObjTablePtr nwfilters,
+                                 const char *configDir);
+
+#endif /* VIRNWFILTEROBJ_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5f95814..2e9f0c2 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -742,18 +742,9 @@ virNWFilterDefFormat;
 virNWFilterDefFree;
 virNWFilterDefParseFile;
 virNWFilterDefParseString;
+virNWFilterDeleteDef;
 virNWFilterInstFiltersOnAllVMs;
 virNWFilterJumpTargetTypeToString;
-virNWFilterLoadAllConfigs;
-virNWFilterObjAssignDef;
-virNWFilterObjDeleteDef;
-virNWFilterObjFindByName;
-virNWFilterObjFindByUUID;
-virNWFilterObjListFree;
-virNWFilterObjLock;
-virNWFilterObjRemove;
-virNWFilterObjSaveDef;
-virNWFilterObjUnlock;
 virNWFilterPrintStateMatchFlags;
 virNWFilterPrintTCPFlags;
 virNWFilterReadLockFilterUpdates;
@@ -764,7 +755,8 @@ virNWFilterRuleIsProtocolEthernet;
 virNWFilterRuleIsProtocolIPv4;
 virNWFilterRuleIsProtocolIPv6;
 virNWFilterRuleProtocolTypeToString;
-virNWFilterTestUnassignDef;
+virNWFilterSaveDef;
+virNWFilterTriggerVMFilterRebuild;
 virNWFilterUnlockFilterUpdates;
 virNWFilterUnRegisterCallbackDriver;
 virNWFilterWriteLockFilterUpdates;
@@ -959,6 +951,15 @@ virNodeDeviceObjGetParentHostByWWNs;
 virNodeDeviceObjNumOfDevices;
 
 
+# conf/virnwfilterobj.h
+virNWFilterObjAdd;
+virNWFilterObjExportList;
+virNWFilterObjGetFilters;
+virNWFilterObjLoadAllConfigs;
+virNWFilterObjNumOfNWFilters;
+virNWFilterObjTestUnassignDef;
+
+
 # conf/virpoolobj.h
 virPoolObjEndAPI;
 virPoolObjGetDef;
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 186830c..4d69072 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -37,7 +37,6 @@
 #include "viralloc.h"
 #include "domain_conf.h"
 #include "domain_nwfilter.h"
-#include "nwfilter_conf.h"
 #include "nwfilter_driver.h"
 #include "nwfilter_gentech_driver.h"
 #include "configmake.h"
@@ -238,8 +237,12 @@ nwfilterStateInitialize(bool privileged,
 
     VIR_FREE(base);
 
-    if (virNWFilterLoadAllConfigs(&driver->nwfilters,
-                                  driver->configDir) < 0)
+    if (!(driver->nwfilters =
+          virPoolObjTableNew(VIR_POOLOBJTABLE_NWFILTER,
+                             VIR_POOLOBJTABLE_NWFILTER_HASHSTART, false)))
+        goto error;
+
+    if (virNWFilterObjLoadAllConfigs(driver->nwfilters, driver->configDir) < 0)
         goto error;
 
     nwfilterDriverUnlock();
@@ -291,8 +294,7 @@ nwfilterStateReload(void)
     virNWFilterWriteLockFilterUpdates();
     virNWFilterCallbackDriversLock();
 
-    virNWFilterLoadAllConfigs(&driver->nwfilters,
-                              driver->configDir);
+    virNWFilterObjLoadAllConfigs(driver->nwfilters, driver->configDir);
 
     virNWFilterCallbackDriversUnlock();
     virNWFilterUnlockFilterUpdates();
@@ -343,7 +345,7 @@ nwfilterStateCleanup(void)
         nwfilterDriverRemoveDBusMatches();
 
         /* free inactive nwfilters */
-        virNWFilterObjListFree(&driver->nwfilters);
+        virObjectUnref(driver->nwfilters);
 
         VIR_FREE(driver->configDir);
         nwfilterDriverUnlock();
@@ -356,31 +358,45 @@ nwfilterStateCleanup(void)
 }
 
 
+static virPoolObjPtr
+nwfilterObjFromNWFilter(virNWFilterPtr nwfilter)
+{
+    virPoolObjPtr obj;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+    if (!(obj = virPoolObjTableFindByUUIDRef(driver->nwfilters,
+                                             nwfilter->uuid))) {
+        virReportError(VIR_ERR_NO_NWFILTER,
+                       _("no nwfilter with matching uuid '%s'"),
+                       uuidstr);
+        return NULL;
+    }
+    return obj;
+}
+
+
 static virNWFilterPtr
 nwfilterLookupByUUID(virConnectPtr conn,
                      const unsigned char *uuid)
 {
-    virNWFilterObjPtr nwfilter;
+    virPoolObjPtr obj;
+    virNWFilterDefPtr def;
     virNWFilterPtr ret = NULL;
 
-    nwfilterDriverLock();
-    nwfilter = virNWFilterObjFindByUUID(&driver->nwfilters, uuid);
-    nwfilterDriverUnlock();
-
-    if (!nwfilter) {
+    if (!(obj = virPoolObjTableFindByUUIDRef(driver->nwfilters, uuid))) {
         virReportError(VIR_ERR_NO_NWFILTER,
                        "%s", _("no nwfilter with matching uuid"));
         goto cleanup;
     }
 
-    if (virNWFilterLookupByUUIDEnsureACL(conn, nwfilter->def) < 0)
+    def = virPoolObjGetDef(obj);
+    if (virNWFilterLookupByUUIDEnsureACL(conn, def) < 0)
         goto cleanup;
 
-    ret = virGetNWFilter(conn, nwfilter->def->name, nwfilter->def->uuid);
+    ret = virGetNWFilter(conn, def->name, def->uuid);
 
  cleanup:
-    if (nwfilter)
-        virNWFilterObjUnlock(nwfilter);
+    virPoolObjEndAPI(&obj);
     return ret;
 }
 
@@ -389,27 +405,24 @@ static virNWFilterPtr
 nwfilterLookupByName(virConnectPtr conn,
                      const char *name)
 {
-    virNWFilterObjPtr nwfilter;
+    virPoolObjPtr obj;
+    virNWFilterDefPtr def;
     virNWFilterPtr ret = NULL;
 
-    nwfilterDriverLock();
-    nwfilter = virNWFilterObjFindByName(&driver->nwfilters, name);
-    nwfilterDriverUnlock();
-
-    if (!nwfilter) {
+    if (!(obj = virPoolObjTableFindByName(driver->nwfilters, name))) {
         virReportError(VIR_ERR_NO_NWFILTER,
                        _("no nwfilter with matching name '%s'"), name);
         goto cleanup;
     }
 
-    if (virNWFilterLookupByNameEnsureACL(conn, nwfilter->def) < 0)
+    def = virPoolObjGetDef(obj);
+    if (virNWFilterLookupByNameEnsureACL(conn, def) < 0)
         goto cleanup;
 
-    ret = virGetNWFilter(conn, nwfilter->def->name, nwfilter->def->uuid);
+    ret = virGetNWFilter(conn, def->name, def->uuid);
 
  cleanup:
-    if (nwfilter)
-        virNWFilterObjUnlock(nwfilter);
+    virPoolObjEndAPI(&obj);
     return ret;
 }
 
@@ -417,58 +430,27 @@ nwfilterLookupByName(virConnectPtr conn,
 static int
 nwfilterConnectNumOfNWFilters(virConnectPtr conn)
 {
-    size_t i;
-    int n;
-
     if (virConnectNumOfNWFiltersEnsureACL(conn) < 0)
         return -1;
 
-    n = 0;
-    for (i = 0; i < driver->nwfilters.count; i++) {
-        virNWFilterObjPtr obj = driver->nwfilters.objs[i];
-        virNWFilterObjLock(obj);
-        if (virConnectNumOfNWFiltersCheckACL(conn, obj->def))
-            n++;
-        virNWFilterObjUnlock(obj);
-    }
-
-    return n;
+    return virNWFilterObjNumOfNWFilters(driver->nwfilters, conn,
+                                        virConnectNumOfNWFiltersCheckACL);
 }
 
 
 static int
 nwfilterConnectListNWFilters(virConnectPtr conn,
-                             char **const names,
-                             int nnames)
+                             char **names,
+                             int maxnames)
 {
-    int got = 0;
-    size_t i;
+    memset(names, 0, maxnames * sizeof(*names));
 
     if (virConnectListNWFiltersEnsureACL(conn) < 0)
         return -1;
 
-    nwfilterDriverLock();
-    for (i = 0; i < driver->nwfilters.count && got < nnames; i++) {
-        virNWFilterObjPtr obj = driver->nwfilters.objs[i];
-        virNWFilterObjLock(obj);
-        if (virConnectListNWFiltersCheckACL(conn, obj->def)) {
-            if (VIR_STRDUP(names[got], obj->def->name) < 0) {
-                virNWFilterObjUnlock(obj);
-                goto cleanup;
-            }
-            got++;
-        }
-        virNWFilterObjUnlock(obj);
-    }
-    nwfilterDriverUnlock();
-    return got;
-
- cleanup:
-    nwfilterDriverUnlock();
-    for (i = 0; i < got; i++)
-        VIR_FREE(names[i]);
-    memset(names, 0, nnames * sizeof(*names));
-    return -1;
+    return virNWFilterObjGetFilters(driver->nwfilters, conn,
+                                    virConnectListNWFiltersCheckACL,
+                                    names, maxnames);
 }
 
 
@@ -477,63 +459,23 @@ nwfilterConnectListAllNWFilters(virConnectPtr conn,
                                 virNWFilterPtr **filters,
                                 unsigned int flags)
 {
-    virNWFilterPtr *tmp_filters = NULL;
-    int nfilters = 0;
-    virNWFilterPtr filter = NULL;
-    virNWFilterObjPtr obj = NULL;
-    size_t i;
-    int ret = -1;
-
     virCheckFlags(0, -1);
 
     if (virConnectListAllNWFiltersEnsureACL(conn) < 0)
         return -1;
 
-    nwfilterDriverLock();
-
-    if (!filters) {
-        ret = driver->nwfilters.count;
-        goto cleanup;
-    }
-
-    if (VIR_ALLOC_N(tmp_filters, driver->nwfilters.count + 1) < 0)
-        goto cleanup;
-
-    for (i = 0; i < driver->nwfilters.count; i++) {
-        obj = driver->nwfilters.objs[i];
-        virNWFilterObjLock(obj);
-        if (virConnectListAllNWFiltersCheckACL(conn, obj->def)) {
-            if (!(filter = virGetNWFilter(conn, obj->def->name,
-                                          obj->def->uuid))) {
-                virNWFilterObjUnlock(obj);
-                goto cleanup;
-            }
-            tmp_filters[nfilters++] = filter;
-        }
-        virNWFilterObjUnlock(obj);
-    }
-
-    *filters = tmp_filters;
-    tmp_filters = NULL;
-    ret = nfilters;
-
- cleanup:
-    nwfilterDriverUnlock();
-    if (tmp_filters) {
-        for (i = 0; i < nfilters; i ++)
-            virObjectUnref(tmp_filters[i]);
-    }
-    VIR_FREE(tmp_filters);
-
-    return ret;
+    return virNWFilterObjExportList(conn, driver->nwfilters, filters,
+                                    virConnectListAllNWFiltersCheckACL, flags);
 }
 
+
 static virNWFilterPtr
 nwfilterDefineXML(virConnectPtr conn,
                   const char *xml)
 {
     virNWFilterDefPtr def;
-    virNWFilterObjPtr nwfilter = NULL;
+    virNWFilterDefPtr objdef;
+    virPoolObjPtr obj = NULL;
     virNWFilterPtr ret = NULL;
 
     if (!driver->privileged) {
@@ -552,22 +494,20 @@ nwfilterDefineXML(virConnectPtr conn,
     if (virNWFilterDefineXMLEnsureACL(conn, def) < 0)
         goto cleanup;
 
-    if (!(nwfilter = virNWFilterObjAssignDef(&driver->nwfilters, def)))
+    if (!(obj = virNWFilterObjAdd(driver->nwfilters, def)))
         goto cleanup;
+    VIR_STEAL_PTR(objdef, def);
 
-    if (virNWFilterObjSaveDef(driver, def) < 0) {
-        virNWFilterObjRemove(&driver->nwfilters, nwfilter);
-        def = NULL;
+    if (virNWFilterSaveDef(driver->configDir, objdef) < 0) {
+        virPoolObjTableRemove(driver->nwfilters, &obj);
         goto cleanup;
     }
-    def = NULL;
 
-    ret = virGetNWFilter(conn, nwfilter->def->name, nwfilter->def->uuid);
+    ret = virGetNWFilter(conn, objdef->name, objdef->uuid);
 
  cleanup:
     virNWFilterDefFree(def);
-    if (nwfilter)
-        virNWFilterObjUnlock(nwfilter);
+    virPoolObjEndAPI(&obj);
 
     virNWFilterCallbackDriversUnlock();
     virNWFilterUnlockFilterUpdates();
@@ -577,42 +517,37 @@ nwfilterDefineXML(virConnectPtr conn,
 
 
 static int
-nwfilterUndefine(virNWFilterPtr obj)
+nwfilterUndefine(virNWFilterPtr nwfilter)
 {
-    virNWFilterObjPtr nwfilter;
+    virPoolObjPtr obj;
+    virNWFilterDefPtr def;
     int ret = -1;
 
     nwfilterDriverLock();
     virNWFilterWriteLockFilterUpdates();
     virNWFilterCallbackDriversLock();
 
-    nwfilter = virNWFilterObjFindByUUID(&driver->nwfilters, obj->uuid);
-    if (!nwfilter) {
-        virReportError(VIR_ERR_NO_NWFILTER,
-                       "%s", _("no nwfilter with matching uuid"));
+    if (!(obj = nwfilterObjFromNWFilter(nwfilter)))
         goto cleanup;
-    }
+    def = virPoolObjGetDef(obj);
 
-    if (virNWFilterUndefineEnsureACL(obj->conn, nwfilter->def) < 0)
+    if (virNWFilterUndefineEnsureACL(nwfilter->conn, def) < 0)
         goto cleanup;
 
-    if (virNWFilterTestUnassignDef(nwfilter) < 0) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       "%s",
+    if (virNWFilterObjTestUnassignDef(obj) < 0) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                        _("nwfilter is in use"));
         goto cleanup;
     }
 
-    if (virNWFilterObjDeleteDef(driver->configDir, nwfilter) < 0)
+    if (virNWFilterDeleteDef(driver->configDir, def) < 0)
         goto cleanup;
 
-    virNWFilterObjRemove(&driver->nwfilters, nwfilter);
-    nwfilter = NULL;
+    virPoolObjTableRemove(driver->nwfilters, &obj);
     ret = 0;
 
  cleanup:
-    if (nwfilter)
-        virNWFilterObjUnlock(nwfilter);
+    virPoolObjEndAPI(&obj);
 
     virNWFilterCallbackDriversUnlock();
     virNWFilterUnlockFilterUpdates();
@@ -622,32 +557,26 @@ nwfilterUndefine(virNWFilterPtr obj)
 
 
 static char *
-nwfilterGetXMLDesc(virNWFilterPtr obj,
+nwfilterGetXMLDesc(virNWFilterPtr nwfilter,
                    unsigned int flags)
 {
-    virNWFilterObjPtr nwfilter;
+    virPoolObjPtr obj;
+    virNWFilterDefPtr def;
     char *ret = NULL;
 
     virCheckFlags(0, NULL);
 
-    nwfilterDriverLock();
-    nwfilter = virNWFilterObjFindByUUID(&driver->nwfilters, obj->uuid);
-    nwfilterDriverUnlock();
-
-    if (!nwfilter) {
-        virReportError(VIR_ERR_NO_NWFILTER,
-                       "%s", _("no nwfilter with matching uuid"));
+    if (!(obj = nwfilterObjFromNWFilter(nwfilter)))
         goto cleanup;
-    }
 
-    if (virNWFilterGetXMLDescEnsureACL(obj->conn, nwfilter->def) < 0)
+    def = virPoolObjGetDef(obj);
+    if (virNWFilterGetXMLDescEnsureACL(nwfilter->conn, def) < 0)
         goto cleanup;
 
-    ret = virNWFilterDefFormat(nwfilter->def);
+    ret = virNWFilterDefFormat(def);
 
  cleanup:
-    if (nwfilter)
-        virNWFilterObjUnlock(nwfilter);
+    virPoolObjEndAPI(&obj);
     return ret;
 }
 
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 761a01b..3c2697d 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -302,7 +302,7 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1,
 typedef struct _virNWFilterInst virNWFilterInst;
 typedef virNWFilterInst *virNWFilterInstPtr;
 struct _virNWFilterInst {
-    virNWFilterObjPtr *filters;
+    virPoolObjPtr *filters;
     size_t nfilters;
     virNWFilterRuleInstPtr *rules;
     size_t nrules;
@@ -315,7 +315,7 @@ virNWFilterInstReset(virNWFilterInstPtr inst)
     size_t i;
 
     for (i = 0; i < inst->nfilters; i++)
-        virNWFilterObjUnlock(inst->filters[i]);
+        virObjectUnref(inst->filters[i]);
     VIR_FREE(inst->filters);
     inst->nfilters = 0;
 
@@ -368,6 +368,21 @@ virNWFilterRuleDefToRuleInst(virNWFilterDefPtr def,
 }
 
 
+static virPoolObjPtr
+nwfilterObjFromFiltername(virNWFilterDriverStatePtr driver,
+                          const char *name)
+{
+    virPoolObjPtr obj;
+
+    if (!(obj = virPoolObjTableFindByName(driver->nwfilters, name))) {
+        virReportError(VIR_ERR_NO_NWFILTER,
+                       _("Could not find filter '%s'"), name);
+    }
+
+    return obj;
+}
+
+
 static int
 virNWFilterIncludeDefToRuleInst(virNWFilterDriverStatePtr driver,
                                 virNWFilterIncludeDefPtr inc,
@@ -376,21 +391,20 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverStatePtr driver,
                                 bool *foundNewFilter,
                                 virNWFilterInstPtr inst)
 {
-    virNWFilterObjPtr obj;
+    virPoolObjPtr obj;
+    virNWFilterDefPtr def;
+    virNWFilterDefPtr newdef;
     virNWFilterHashTablePtr tmpvars = NULL;
     virNWFilterDefPtr childdef;
     int ret = -1;
 
     VIR_DEBUG("Instantiating filter %s", inc->filterref);
-    obj = virNWFilterObjFindByName(&driver->nwfilters,
-                                   inc->filterref);
-    if (!obj) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("referenced filter '%s' is missing"),
-                       inc->filterref);
-        goto cleanup;
-    }
-    if (obj->wantRemoved) {
+    if (!(obj = nwfilterObjFromFiltername(driver, inc->filterref)))
+        return -1;
+    def = virPoolObjGetDef(obj);
+    newdef = virPoolObjGetNewDef(obj);
+
+    if (virPoolObjIsBeingRemoved(obj)) {
         virReportError(VIR_ERR_NO_NWFILTER,
                        _("Filter '%s' is in use."),
                        inc->filterref);
@@ -398,16 +412,15 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverStatePtr driver,
     }
 
     /* create a temporary hashmap for depth-first tree traversal */
-    if (!(tmpvars = virNWFilterCreateVarsFrom(inc->params,
-                                              vars)))
+    if (!(tmpvars = virNWFilterCreateVarsFrom(inc->params, vars)))
         goto cleanup;
 
-    childdef = obj->def;
+    childdef = def;
 
     switch (useNewFilter) {
     case INSTANTIATE_FOLLOW_NEWFILTER:
-        if (obj->newDef) {
-            childdef = obj->newDef;
+        if (newdef) {
+            childdef = newdef;
             *foundNewFilter = true;
         }
         break;
@@ -419,7 +432,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverStatePtr driver,
                            inst->nfilters,
                            obj) < 0)
         goto cleanup;
-    obj = NULL;
+    virObjectRef(obj);
 
     if (virNWFilterDefToInst(driver,
                              childdef,
@@ -434,8 +447,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverStatePtr driver,
     if (ret < 0)
         virNWFilterInstReset(inst);
     virNWFilterHashTableFree(tmpvars);
-    if (obj)
-        virNWFilterObjUnlock(obj);
+    virPoolObjEndAPI(&obj);
     return ret;
 }
 
@@ -501,7 +513,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
                                    int useNewFilter,
                                    virNWFilterDriverStatePtr driver)
 {
-    virNWFilterObjPtr obj;
+    virPoolObjPtr obj = NULL;
     int rc = 0;
     size_t i, j;
     virNWFilterDefPtr next_filter;
@@ -542,34 +554,34 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
                 break;
         } else if (inc) {
             VIR_DEBUG("Following filter %s", inc->filterref);
-            obj = virNWFilterObjFindByName(&driver->nwfilters, inc->filterref);
-            if (obj) {
+            if (!(obj = nwfilterObjFromFiltername(driver, inc->filterref))) {
+                rc = -1;
+                break;
+            } else {
+                virNWFilterDefPtr def = virPoolObjGetDef(obj);
+                virNWFilterDefPtr newdef = virPoolObjGetNewDef(obj);
+                virNWFilterHashTablePtr tmpvars;
 
-                if (obj->wantRemoved) {
+                if (virPoolObjIsBeingRemoved(obj)) {
                     virReportError(VIR_ERR_NO_NWFILTER,
                                    _("Filter '%s' is in use."),
                                    inc->filterref);
                     rc = -1;
-                    virNWFilterObjUnlock(obj);
                     break;
                 }
 
                 /* create a temporary hashmap for depth-first tree traversal */
-                virNWFilterHashTablePtr tmpvars =
-                                      virNWFilterCreateVarsFrom(inc->params,
-                                                                vars);
-                if (!tmpvars) {
+                if (!(tmpvars = virNWFilterCreateVarsFrom(inc->params, vars))) {
                     rc = -1;
-                    virNWFilterObjUnlock(obj);
                     break;
                 }
 
-                next_filter = obj->def;
+                next_filter = def;
 
                 switch (useNewFilter) {
                 case INSTANTIATE_FOLLOW_NEWFILTER:
-                    if (obj->newDef)
-                        next_filter = obj->newDef;
+                    if (newdef)
+                        next_filter = newdef;
                     break;
                 case INSTANTIATE_ALWAYS:
                     break;
@@ -583,18 +595,14 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
 
                 virNWFilterHashTableFree(tmpvars);
 
-                virNWFilterObjUnlock(obj);
+                virPoolObjEndAPI(&obj);
                 if (rc < 0)
                     break;
-            } else {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("referenced filter '%s' is missing"),
-                               inc->filterref);
-                rc = -1;
-                break;
             }
         }
     }
+
+    virPoolObjEndAPI(&obj);
     return rc;
 }
 
@@ -787,7 +795,9 @@ __virNWFilterInstantiateFilter(virNWFilterDriverStatePtr driver,
     int rc;
     const char *drvname = EBIPTABLES_DRIVER_ID;
     virNWFilterTechDriverPtr techdriver;
-    virNWFilterObjPtr obj;
+    virPoolObjPtr obj;
+    virNWFilterDefPtr def;
+    virNWFilterDefPtr newdef;
     virNWFilterHashTablePtr vars, vars1;
     virNWFilterDefPtr filter;
     char vmmacaddr[VIR_MAC_STRING_BUFLEN] = {0};
@@ -807,15 +817,12 @@ __virNWFilterInstantiateFilter(virNWFilterDriverStatePtr driver,
 
     VIR_DEBUG("filter name: %s", filtername);
 
-    obj = virNWFilterObjFindByName(&driver->nwfilters, filtername);
-    if (!obj) {
-        virReportError(VIR_ERR_NO_NWFILTER,
-                       _("Could not find filter '%s'"),
-                       filtername);
+    if (!(obj = nwfilterObjFromFiltername(driver, filtername)))
         return -1;
-    }
+    def = virPoolObjGetDef(obj);
+    newdef = virPoolObjGetNewDef(obj);
 
-    if (obj->wantRemoved) {
+    if (virPoolObjIsBeingRemoved(obj)) {
         virReportError(VIR_ERR_NO_NWFILTER,
                        _("Filter '%s' is in use."),
                        filtername);
@@ -847,12 +854,12 @@ __virNWFilterInstantiateFilter(virNWFilterDriverStatePtr driver,
         goto err_exit_vars1;
     }
 
-    filter = obj->def;
+    filter = def;
 
     switch (useNewFilter) {
     case INSTANTIATE_FOLLOW_NEWFILTER:
-        if (obj->newDef) {
-            filter = obj->newDef;
+        if (newdef) {
+            filter = newdef;
             *foundNewFilter = true;
         }
         break;
@@ -880,7 +887,7 @@ __virNWFilterInstantiateFilter(virNWFilterDriverStatePtr driver,
     virNWFilterHashTableFree(vars1);
 
  err_exit:
-    virNWFilterObjUnlock(obj);
+    virPoolObjEndAPI(&obj);
 
     VIR_FREE(str_ipaddr);
     VIR_FREE(str_macaddr);
diff --git a/src/nwfilter/nwfilter_gentech_driver.h b/src/nwfilter/nwfilter_gentech_driver.h
index 8349ab4..7192487 100644
--- a/src/nwfilter/nwfilter_gentech_driver.h
+++ b/src/nwfilter/nwfilter_gentech_driver.h
@@ -24,7 +24,7 @@
 #ifndef __NWFILTER_GENTECH_DRIVER_H
 # define __NWFILTER_GENTECH_DRIVER_H
 
-# include "nwfilter_conf.h"
+# include "virnwfilterobj.h"
 # include "nwfilter_tech_driver.h"
 
 virNWFilterTechDriverPtr virNWFilterTechDriverForName(const char *name);
diff --git a/src/nwfilter/nwfilter_tech_driver.h b/src/nwfilter/nwfilter_tech_driver.h
index 7b6f56f..bc30496 100644
--- a/src/nwfilter/nwfilter_tech_driver.h
+++ b/src/nwfilter/nwfilter_tech_driver.h
@@ -26,7 +26,7 @@
 #ifndef __NWFILTER_TECH_DRIVER_H__
 # define __NWFILTER_TECH_DRIVER_H__
 
-# include "nwfilter_conf.h"
+# include "virnwfilterobj.h"
 
 typedef struct _virNWFilterTechDriver virNWFilterTechDriver;
 typedef virNWFilterTechDriver *virNWFilterTechDriverPtr;
-- 
2.7.4


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