Blame SOURCES/libvirt-Don-t-pass-virConnectPtr-in-nwfilter-struct-domUpdateCBStruct.patch

43fe83
From afca26500a5a66d5a833fe2c2be81db385c4971d Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <afca26500a5a66d5a833fe2c2be81db385c4971d.1381871411.git.jdenemar@redhat.com>
43fe83
From: "Daniel P. Berrange" <berrange@redhat.com>
43fe83
Date: Mon, 7 Oct 2013 16:43:11 +0100
43fe83
Subject: [PATCH] Don't pass virConnectPtr in nwfilter 'struct
43fe83
 domUpdateCBStruct'
43fe83
43fe83
https://bugzilla.redhat.com/show_bug.cgi?id=1015108
43fe83
43fe83
The nwfilter driver only needs a reference to its private
43fe83
state object, not a full virConnectPtr. Update the domUpdateCBStruct
43fe83
struct to have a 'void *opaque' field instead of a virConnectPtr.
43fe83
43fe83
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
43fe83
(cherry picked from commit ebca369e3fe5ac999c261c2d44e60a1bac3cfe65)
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 src/conf/nwfilter_conf.c               | 14 +++++++++++---
43fe83
 src/conf/nwfilter_conf.h               |  4 ++--
43fe83
 src/nwfilter/nwfilter_dhcpsnoop.c      | 12 ++++++------
43fe83
 src/nwfilter/nwfilter_driver.c         |  5 +++--
43fe83
 src/nwfilter/nwfilter_gentech_driver.c | 32 ++++++++++++++++----------------
43fe83
 src/nwfilter/nwfilter_gentech_driver.h | 10 +++++-----
43fe83
 src/nwfilter/nwfilter_learnipaddr.c    |  6 +++---
43fe83
 7 files changed, 46 insertions(+), 37 deletions(-)
43fe83
43fe83
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
43fe83
index 54a492d..424c396 100644
43fe83
--- a/src/conf/nwfilter_conf.c
43fe83
+++ b/src/conf/nwfilter_conf.c
43fe83
@@ -2849,6 +2849,7 @@ virNWFilterCallbackDriversUnlock(void)
43fe83
 
43fe83
 
43fe83
 static virDomainObjListIterator virNWFilterDomainFWUpdateCB;
43fe83
+static void *virNWFilterDomainFWUpdateOpaque;
43fe83
 
43fe83
 /**
43fe83
  * virNWFilterInstFiltersOnAllVMs:
43fe83
@@ -2860,7 +2861,7 @@ virNWFilterInstFiltersOnAllVMs(virConnectPtr conn)
43fe83
 {
43fe83
     size_t i;
43fe83
     struct domUpdateCBStruct cb = {
43fe83
-        .conn = conn,
43fe83
+        .opaque = virNWFilterDomainFWUpdateOpaque,
43fe83
         .step = STEP_APPLY_CURRENT,
43fe83
         .skipInterfaces = NULL, /* not needed */
43fe83
     };
43fe83
@@ -2879,7 +2880,7 @@ virNWFilterTriggerVMFilterRebuild(virConnectPtr conn)
43fe83
     size_t i;
43fe83
     int ret = 0;
43fe83
     struct domUpdateCBStruct cb = {
43fe83
-        .conn = conn,
43fe83
+        .opaque = virNWFilterDomainFWUpdateOpaque,
43fe83
         .step = STEP_APPLY_NEW,
43fe83
         .skipInterfaces = virHashCreate(0, NULL),
43fe83
     };
43fe83
@@ -3473,9 +3474,14 @@ char *virNWFilterConfigFile(const char *dir,
43fe83
 }
43fe83
 
43fe83
 
43fe83
-int virNWFilterConfLayerInit(virDomainObjListIterator domUpdateCB)
43fe83
+int virNWFilterConfLayerInit(virDomainObjListIterator domUpdateCB,
43fe83
+                             void *opaque)
43fe83
 {
43fe83
+    if (initialized)
43fe83
+        return -1;
43fe83
+
43fe83
     virNWFilterDomainFWUpdateCB = domUpdateCB;
43fe83
+    virNWFilterDomainFWUpdateOpaque = opaque;
43fe83
 
43fe83
     initialized = true;
43fe83
 
43fe83
@@ -3494,6 +3500,8 @@ void virNWFilterConfLayerShutdown(void)
43fe83
     virMutexDestroy(&updateMutex);
43fe83
 
43fe83
     initialized = false;
43fe83
+    virNWFilterDomainFWUpdateOpaque = NULL;
43fe83
+    virNWFilterDomainFWUpdateCB = NULL;
43fe83
 }
43fe83
 
43fe83
 
43fe83
diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h
43fe83
index faa7527..e470615 100644
43fe83
--- a/src/conf/nwfilter_conf.h
43fe83
+++ b/src/conf/nwfilter_conf.h
43fe83
@@ -586,7 +586,7 @@ enum UpdateStep {
43fe83
 };
43fe83
 
43fe83
 struct domUpdateCBStruct {
43fe83
-    virConnectPtr conn;
43fe83
+    void *opaque;
43fe83
     enum UpdateStep step;
43fe83
     virHashTablePtr skipInterfaces;
43fe83
 };
43fe83
@@ -722,7 +722,7 @@ void virNWFilterObjUnlock(virNWFilterObjPtr obj);
43fe83
 void virNWFilterLockFilterUpdates(void);
43fe83
 void virNWFilterUnlockFilterUpdates(void);
43fe83
 
43fe83
-int virNWFilterConfLayerInit(virDomainObjListIterator domUpdateCB);
43fe83
+int virNWFilterConfLayerInit(virDomainObjListIterator domUpdateCB, void *opaque);
43fe83
 void virNWFilterConfLayerShutdown(void);
43fe83
 
43fe83
 int virNWFilterInstFiltersOnAllVMs(virConnectPtr conn);
43fe83
diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
43fe83
index 3e9f046..2bc1686 100644
43fe83
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
43fe83
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
43fe83
@@ -481,15 +481,15 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIPLeasePtr ipl,
43fe83
     /* instantiate the filters */
43fe83
 
43fe83
     if (req->ifname)
43fe83
-        rc = virNWFilterInstantiateFilterLate(NULL,
43fe83
+        rc = virNWFilterInstantiateFilterLate(req->driver,
43fe83
+                                              NULL,
43fe83
                                               req->ifname,
43fe83
                                               req->ifindex,
43fe83
                                               req->linkdev,
43fe83
                                               req->nettype,
43fe83
                                               &req->macaddr,
43fe83
                                               req->filtername,
43fe83
-                                              req->vars,
43fe83
-                                              req->driver);
43fe83
+                                              req->vars);
43fe83
 
43fe83
 exit_snooprequnlock:
43fe83
     virNWFilterSnoopReqUnlock(req);
43fe83
@@ -867,15 +867,15 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req,
43fe83
         goto skip_instantiate;
43fe83
 
43fe83
     if (ipAddrLeft) {
43fe83
-        ret = virNWFilterInstantiateFilterLate(NULL,
43fe83
+        ret = virNWFilterInstantiateFilterLate(req->driver,
43fe83
+                                               NULL,
43fe83
                                                req->ifname,
43fe83
                                                req->ifindex,
43fe83
                                                req->linkdev,
43fe83
                                                req->nettype,
43fe83
                                                &req->macaddr,
43fe83
                                                req->filtername,
43fe83
-                                               req->vars,
43fe83
-                                               req->driver);
43fe83
+                                               req->vars);
43fe83
     } else {
43fe83
         const virNWFilterVarValuePtr dhcpsrvrs =
43fe83
             virHashLookup(req->vars->hashTable, NWFILTER_VARNAME_DHCPSERVER);
43fe83
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
43fe83
index 2cae0d0..0a515e7 100644
43fe83
--- a/src/nwfilter/nwfilter_driver.c
43fe83
+++ b/src/nwfilter/nwfilter_driver.c
43fe83
@@ -201,7 +201,8 @@ nwfilterStateInitialize(bool privileged,
43fe83
 
43fe83
     virNWFilterTechDriversInit(privileged);
43fe83
 
43fe83
-    if (virNWFilterConfLayerInit(virNWFilterDomainFWUpdateCB) < 0)
43fe83
+    if (virNWFilterConfLayerInit(virNWFilterDomainFWUpdateCB,
43fe83
+                                 driverState) < 0)
43fe83
         goto err_techdrivers_shutdown;
43fe83
 
43fe83
     /*
43fe83
@@ -676,7 +677,7 @@ nwfilterInstantiateFilter(virConnectPtr conn,
43fe83
                           const unsigned char *vmuuid,
43fe83
                           virDomainNetDefPtr net)
43fe83
 {
43fe83
-    return virNWFilterInstantiateFilter(conn, vmuuid, net);
43fe83
+    return virNWFilterInstantiateFilter(conn->nwfilterPrivateData, vmuuid, net);
43fe83
 }
43fe83
 
43fe83
 
43fe83
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
43fe83
index ee9195b..f517569 100644
43fe83
--- a/src/nwfilter/nwfilter_gentech_driver.c
43fe83
+++ b/src/nwfilter/nwfilter_gentech_driver.c
43fe83
@@ -800,7 +800,8 @@ err_unresolvable_vars:
43fe83
  * Call this function while holding the NWFilter filter update lock
43fe83
  */
43fe83
 static int
43fe83
-__virNWFilterInstantiateFilter(const unsigned char *vmuuid,
43fe83
+__virNWFilterInstantiateFilter(virNWFilterDriverStatePtr driver,
43fe83
+                               const unsigned char *vmuuid,
43fe83
                                bool teardownOld,
43fe83
                                const char *ifname,
43fe83
                                int ifindex,
43fe83
@@ -810,7 +811,6 @@ __virNWFilterInstantiateFilter(const unsigned char *vmuuid,
43fe83
                                const char *filtername,
43fe83
                                virNWFilterHashTablePtr filterparams,
43fe83
                                enum instCase useNewFilter,
43fe83
-                               virNWFilterDriverStatePtr driver,
43fe83
                                bool forceWithPendingReq,
43fe83
                                bool *foundNewFilter)
43fe83
 {
43fe83
@@ -921,7 +921,7 @@ err_exit:
43fe83
 
43fe83
 
43fe83
 static int
43fe83
-_virNWFilterInstantiateFilter(virConnectPtr conn,
43fe83
+_virNWFilterInstantiateFilter(virNWFilterDriverStatePtr driver,
43fe83
                               const unsigned char *vmuuid,
43fe83
                               const virDomainNetDefPtr net,
43fe83
                               bool teardownOld,
43fe83
@@ -948,7 +948,8 @@ _virNWFilterInstantiateFilter(virConnectPtr conn,
43fe83
         goto cleanup;
43fe83
     }
43fe83
 
43fe83
-    rc = __virNWFilterInstantiateFilter(vmuuid,
43fe83
+    rc = __virNWFilterInstantiateFilter(driver,
43fe83
+                                        vmuuid,
43fe83
                                         teardownOld,
43fe83
                                         net->ifname,
43fe83
                                         ifindex,
43fe83
@@ -958,7 +959,6 @@ _virNWFilterInstantiateFilter(virConnectPtr conn,
43fe83
                                         net->filter,
43fe83
                                         net->filterparams,
43fe83
                                         useNewFilter,
43fe83
-                                        conn->nwfilterPrivateData,
43fe83
                                         false,
43fe83
                                         foundNewFilter);
43fe83
 
43fe83
@@ -970,22 +970,23 @@ cleanup:
43fe83
 
43fe83
 
43fe83
 int
43fe83
-virNWFilterInstantiateFilterLate(const unsigned char *vmuuid,
43fe83
+virNWFilterInstantiateFilterLate(virNWFilterDriverStatePtr driver,
43fe83
+                                 const unsigned char *vmuuid,
43fe83
                                  const char *ifname,
43fe83
                                  int ifindex,
43fe83
                                  const char *linkdev,
43fe83
                                  enum virDomainNetType nettype,
43fe83
                                  const virMacAddrPtr macaddr,
43fe83
                                  const char *filtername,
43fe83
-                                 virNWFilterHashTablePtr filterparams,
43fe83
-                                 virNWFilterDriverStatePtr driver)
43fe83
+                                 virNWFilterHashTablePtr filterparams)
43fe83
 {
43fe83
     int rc;
43fe83
     bool foundNewFilter = false;
43fe83
 
43fe83
     virNWFilterLockFilterUpdates();
43fe83
 
43fe83
-    rc = __virNWFilterInstantiateFilter(vmuuid,
43fe83
+    rc = __virNWFilterInstantiateFilter(driver,
43fe83
+                                        vmuuid,
43fe83
                                         true,
43fe83
                                         ifname,
43fe83
                                         ifindex,
43fe83
@@ -995,7 +996,6 @@ virNWFilterInstantiateFilterLate(const unsigned char *vmuuid,
43fe83
                                         filtername,
43fe83
                                         filterparams,
43fe83
                                         INSTANTIATE_ALWAYS,
43fe83
-                                        driver,
43fe83
                                         true,
43fe83
                                         &foundNewFilter);
43fe83
     if (rc < 0) {
43fe83
@@ -1015,13 +1015,13 @@ virNWFilterInstantiateFilterLate(const unsigned char *vmuuid,
43fe83
 
43fe83
 
43fe83
 int
43fe83
-virNWFilterInstantiateFilter(virConnectPtr conn,
43fe83
+virNWFilterInstantiateFilter(virNWFilterDriverStatePtr driver,
43fe83
                              const unsigned char *vmuuid,
43fe83
                              const virDomainNetDefPtr net)
43fe83
 {
43fe83
     bool foundNewFilter = false;
43fe83
 
43fe83
-    return _virNWFilterInstantiateFilter(conn, vmuuid, net,
43fe83
+    return _virNWFilterInstantiateFilter(driver, vmuuid, net,
43fe83
                                          1,
43fe83
                                          INSTANTIATE_ALWAYS,
43fe83
                                          &foundNewFilter);
43fe83
@@ -1029,14 +1029,14 @@ virNWFilterInstantiateFilter(virConnectPtr conn,
43fe83
 
43fe83
 
43fe83
 int
43fe83
-virNWFilterUpdateInstantiateFilter(virConnectPtr conn,
43fe83
+virNWFilterUpdateInstantiateFilter(virNWFilterDriverStatePtr driver,
43fe83
                                    const unsigned char *vmuuid,
43fe83
                                    const virDomainNetDefPtr net,
43fe83
                                    bool *skipIface)
43fe83
 {
43fe83
     bool foundNewFilter = false;
43fe83
 
43fe83
-    int rc = _virNWFilterInstantiateFilter(conn, vmuuid, net,
43fe83
+    int rc = _virNWFilterInstantiateFilter(driver, vmuuid, net,
43fe83
                                            0,
43fe83
                                            INSTANTIATE_FOLLOW_NEWFILTER,
43fe83
                                            &foundNewFilter);
43fe83
@@ -1154,7 +1154,7 @@ virNWFilterDomainFWUpdateCB(virDomainObjPtr obj,
43fe83
             if ((net->filter) && (net->ifname)) {
43fe83
                 switch (cb->step) {
43fe83
                 case STEP_APPLY_NEW:
43fe83
-                    ret = virNWFilterUpdateInstantiateFilter(cb->conn,
43fe83
+                    ret = virNWFilterUpdateInstantiateFilter(cb->opaque,
43fe83
                                                              vm->uuid,
43fe83
                                                              net,
43fe83
                                                              &skipIface);
43fe83
@@ -1179,7 +1179,7 @@ virNWFilterDomainFWUpdateCB(virDomainObjPtr obj,
43fe83
                     break;
43fe83
 
43fe83
                 case STEP_APPLY_CURRENT:
43fe83
-                    ret = virNWFilterInstantiateFilter(cb->conn,
43fe83
+                    ret = virNWFilterInstantiateFilter(cb->opaque,
43fe83
                                                        vm->uuid,
43fe83
                                                        net);
43fe83
                     if (ret)
43fe83
diff --git a/src/nwfilter/nwfilter_gentech_driver.h b/src/nwfilter/nwfilter_gentech_driver.h
43fe83
index 4b47b4a..8528e2a 100644
43fe83
--- a/src/nwfilter/nwfilter_gentech_driver.h
43fe83
+++ b/src/nwfilter/nwfilter_gentech_driver.h
43fe83
@@ -39,23 +39,23 @@ enum instCase {
43fe83
 };
43fe83
 
43fe83
 
43fe83
-int virNWFilterInstantiateFilter(virConnectPtr conn,
43fe83
+int virNWFilterInstantiateFilter(virNWFilterDriverStatePtr driver,
43fe83
                                  const unsigned char *vmuuid,
43fe83
                                  const virDomainNetDefPtr net);
43fe83
-int virNWFilterUpdateInstantiateFilter(virConnectPtr conn,
43fe83
+int virNWFilterUpdateInstantiateFilter(virNWFilterDriverStatePtr driver,
43fe83
                                        const unsigned char *vmuuid,
43fe83
                                        const virDomainNetDefPtr net,
43fe83
                                        bool *skipIface);
43fe83
 
43fe83
-int virNWFilterInstantiateFilterLate(const unsigned char *vmuuid,
43fe83
+int virNWFilterInstantiateFilterLate(virNWFilterDriverStatePtr driver,
43fe83
+                                     const unsigned char *vmuuid,
43fe83
                                      const char *ifname,
43fe83
                                      int ifindex,
43fe83
                                      const char *linkdev,
43fe83
                                      enum virDomainNetType nettype,
43fe83
                                      const virMacAddrPtr macaddr,
43fe83
                                      const char *filtername,
43fe83
-                                     virNWFilterHashTablePtr filterparams,
43fe83
-                                     virNWFilterDriverStatePtr driver);
43fe83
+                                     virNWFilterHashTablePtr filterparams);
43fe83
 
43fe83
 int virNWFilterTeardownFilter(const virDomainNetDefPtr net);
43fe83
 
43fe83
diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c
43fe83
index 7e67203..093158a 100644
43fe83
--- a/src/nwfilter/nwfilter_learnipaddr.c
43fe83
+++ b/src/nwfilter/nwfilter_learnipaddr.c
43fe83
@@ -612,15 +612,15 @@ learnIPAddressThread(void *arg)
43fe83
                           "cache for interface %s"), inetaddr, req->ifname);
43fe83
             }
43fe83
 
43fe83
-            ret = virNWFilterInstantiateFilterLate(NULL,
43fe83
+            ret = virNWFilterInstantiateFilterLate(req->driver,
43fe83
+                                                   NULL,
43fe83
                                                    req->ifname,
43fe83
                                                    req->ifindex,
43fe83
                                                    req->linkdev,
43fe83
                                                    req->nettype,
43fe83
                                                    &req->macaddr,
43fe83
                                                    req->filtername,
43fe83
-                                                   req->filterparams,
43fe83
-                                                   req->driver);
43fe83
+                                                   req->filterparams);
43fe83
             VIR_DEBUG("Result from applying firewall rules on "
43fe83
                       "%s with IP addr %s : %d\n", req->ifname, inetaddr, ret);
43fe83
         }
43fe83
-- 
43fe83
1.8.3.2
43fe83