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

[libvirt] [PATCH] Remove driver dependency from nwfilter_conf.c



This patch removes the driver dependency from nwfilter_conf.c and moves
a callback function calling into the driver into
nwfilter_gentech_driver.c and passes a pointer to that callback function
upon initialization of nwfilter_conf.c.

Signed-off-by: Stefan Berger <stefanb us ibm com>


Index: libvirt-acl/src/conf/nwfilter_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_conf.c
+++ libvirt-acl/src/conf/nwfilter_conf.c
@@ -39,7 +39,6 @@
 #include "nwfilter_params.h"
 #include "nwfilter_conf.h"
 #include "domain_conf.h"
-#include "nwfilter/nwfilter_gentech_driver.h"
 
 
 #define VIR_FROM_THIS VIR_FROM_NWFILTER
@@ -2064,56 +2063,7 @@ virNWFilterRegisterCallbackDriver(virNWF
 }
 
 
-enum UpdateStep {
-    STEP_APPLY_NEW,
-    STEP_TEAR_NEW,
-    STEP_TEAR_OLD,
-};
-
-struct cbStruct {
-    virConnectPtr conn;
-    enum UpdateStep step;
-    int err;
-};
-
-static void
-virNWFilterDomainFWUpdateCB(void *payload,
-                            const char *name ATTRIBUTE_UNUSED,
-                            void *data)
-{
-    virDomainObjPtr obj = payload;
-    virDomainDefPtr vm = obj->def;
-    struct cbStruct *cb = data;
-    int i;
-
-    virDomainObjLock(obj);
-
-    if (virDomainObjIsActive(obj)) {
-        for (i = 0; i < vm->nnets; i++) {
-            virDomainNetDefPtr net = vm->nets[i];
-            if ((net->filter) && (net->ifname)) {
-                switch (cb->step) {
-                case STEP_APPLY_NEW:
-                    cb->err = virNWFilterUpdateInstantiateFilter(cb->conn,
-                                                                 net);
-                    break;
-
-                case STEP_TEAR_NEW:
-                    cb->err = virNWFilterRollbackUpdateFilter(cb->conn, net);
-                    break;
-
-                case STEP_TEAR_OLD:
-                    cb->err = virNWFilterTearOldFilter(cb->conn, net);
-                    break;
-                }
-                if (cb->err)
-                    break;
-            }
-        }
-    }
-
-    virDomainObjUnlock(obj);
-}
+static virHashIterator virNWFilterDomainFWUpdateCB;
 
 
 static int
@@ -2121,7 +2071,7 @@ virNWFilterTriggerVMFilterRebuild(virCon
 {
     int i;
     int err;
-    struct cbStruct cb = {
+    struct domUpdateCBStruct cb = {
         .conn = conn,
         .err = 0,
         .step = STEP_APPLY_NEW,
@@ -2717,8 +2667,10 @@ char *virNWFilterConfigFile(virConnectPt
 }
 
 
-int virNWFilterConfLayerInit(void)
+int virNWFilterConfLayerInit(virHashIterator domUpdateCB)
 {
+    virNWFilterDomainFWUpdateCB = domUpdateCB;
+
     if (virMutexInit(&updateMutex))
         return 1;
 
Index: libvirt-acl/src/conf/nwfilter_conf.h
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_conf.h
+++ libvirt-acl/src/conf/nwfilter_conf.h
@@ -402,6 +402,19 @@ struct _virNWFilterRuleInst {
 };
 
 
+enum UpdateStep {
+    STEP_APPLY_NEW,
+    STEP_TEAR_NEW,
+    STEP_TEAR_OLD,
+};
+
+struct domUpdateCBStruct {
+    virConnectPtr conn;
+    enum UpdateStep step;
+    int err;
+};
+
+
 enum virDomainNetType;
 
 typedef int (*virNWFilterRuleCreateInstance)(virConnectPtr conn,
@@ -516,7 +529,7 @@ virNWFilterDefPtr virNWFilterDefParseFil
 void virNWFilterPoolObjLock(virNWFilterPoolObjPtr obj);
 void virNWFilterPoolObjUnlock(virNWFilterPoolObjPtr obj);
 
-int virNWFilterConfLayerInit(void);
+int virNWFilterConfLayerInit(virHashIterator domUpdateCB);
 void virNWFilterConfLayerShutdown(void);
 
 int virNWFilterParamConfLayerInit(void);
Index: libvirt-acl/src/nwfilter/nwfilter_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_driver.c
@@ -34,6 +34,7 @@
 #include "memory.h"
 #include "domain_conf.h"
 #include "nwfilter_driver.h"
+#include "nwfilter_gentech_driver.h"
 
 
 #define VIR_FROM_THIS VIR_FROM_NWFILTER
@@ -64,7 +65,7 @@ static int
 nwfilterDriverStartup(int privileged) {
     char *base = NULL;
 
-    if (virNWFilterConfLayerInit() < 0)
+    if (virNWFilterConfLayerInit(virNWFilterDomainFWUpdateCB) < 0)
         return -1;
 
     if (VIR_ALLOC(driverState) < 0)
Index: libvirt-acl/src/nwfilter/nwfilter_gentech_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_gentech_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_gentech_driver.c
@@ -681,3 +681,43 @@ virNWFilterTeardownFilter(const virDomai
 
     return 0;
 }
+
+
+void
+virNWFilterDomainFWUpdateCB(void *payload,
+                            const char *name ATTRIBUTE_UNUSED,
+                            void *data)
+{
+    virDomainObjPtr obj = payload;
+    virDomainDefPtr vm = obj->def;
+    struct domUpdateCBStruct *cb = data;
+    int i;
+
+    virDomainObjLock(obj);
+
+    if (virDomainObjIsActive(obj)) {
+        for (i = 0; i < vm->nnets; i++) {
+            virDomainNetDefPtr net = vm->nets[i];
+            if ((net->filter) && (net->ifname)) {
+                switch (cb->step) {
+                case STEP_APPLY_NEW:
+                    cb->err = virNWFilterUpdateInstantiateFilter(cb->conn,
+                                                                 net);
+                    break;
+
+                case STEP_TEAR_NEW:
+                    cb->err = virNWFilterRollbackUpdateFilter(cb->conn, net);
+                    break;
+
+                case STEP_TEAR_OLD:
+                    cb->err = virNWFilterTearOldFilter(cb->conn, net);
+                    break;
+                }
+                if (cb->err)
+                    break;
+            }
+        }
+    }
+
+    virDomainObjUnlock(obj);
+}
Index: libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_gentech_driver.h
+++ libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
@@ -51,4 +51,8 @@ int virNWFilterTeardownFilter(const virD
 virNWFilterHashTablePtr virNWFilterCreateVarHashmap(virConnectPtr conn,
                                                      char *macaddr);
 
+void virNWFilterDomainFWUpdateCB(void *payload,
+                                 const char *name ATTRIBUTE_UNUSED,
+                                 void *data);
+
 #endif



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