[libvirt] [PATCH 04/14] nwfilter: make virNWFilterIPAddrLearnReq type private

Daniel P. Berrangé posted 14 patches 6 years, 7 months ago
There is a newer version of this series
[libvirt] [PATCH 04/14] nwfilter: make virNWFilterIPAddrLearnReq type private
Posted by Daniel P. Berrangé 6 years, 7 months ago
The virNWFilterIPAddrLearnReq type should only be used by the IP address
learning code, so can live in the implementation file instead of header
file.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/nwfilter/nwfilter_gentech_driver.c |  8 ++++----
 src/nwfilter/nwfilter_learnipaddr.c    | 23 ++++++++++++++++++++---
 src/nwfilter/nwfilter_learnipaddr.h    | 19 +------------------
 3 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 0735426734..91794dd3ad 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -655,7 +655,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid,
                                              filter->name, vars, driver);
                 goto err_exit;
             } else if (STRCASEEQ(learning, "any")) {
-                if (virNWFilterLookupLearnReq(ifindex) == NULL) {
+                if (!virNWFilterHasLearnReq(ifindex)) {
                     rc = virNWFilterLearnIPAddress(techdriver,
                                                    ifname,
                                                    ifindex,
@@ -680,7 +680,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid,
     } else if (virHashSize(missing_vars) > 1) {
         goto err_unresolvable_vars;
     } else if (!forceWithPendingReq &&
-               virNWFilterLookupLearnReq(ifindex) != NULL) {
+               virNWFilterHasLearnReq(ifindex)) {
         goto err_exit;
     }
 
@@ -976,7 +976,7 @@ virNWFilterRollbackUpdateFilter(const virDomainNetDef *net)
     /* don't tear anything while the address is being learned */
     if (virNetDevGetIndex(net->ifname, &ifindex) < 0)
         virResetLastError();
-    else if (virNWFilterLookupLearnReq(ifindex) != NULL)
+    else if (virNWFilterHasLearnReq(ifindex))
         return 0;
 
     return techdriver->tearNewRules(net->ifname);
@@ -1002,7 +1002,7 @@ virNWFilterTearOldFilter(virDomainNetDefPtr net)
     /* don't tear anything while the address is being learned */
     if (virNetDevGetIndex(net->ifname, &ifindex) < 0)
         virResetLastError();
-    else if (virNWFilterLookupLearnReq(ifindex) != NULL)
+    else if (virNWFilterHasLearnReq(ifindex))
         return 0;
 
     return techdriver->tearOldRules(net->ifname);
diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c
index 2401857ddb..cc3bfd971c 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -133,6 +133,23 @@ struct _virNWFilterIfaceLock {
     int refctr;
 };
 
+typedef struct _virNWFilterIPAddrLearnReq virNWFilterIPAddrLearnReq;
+typedef virNWFilterIPAddrLearnReq *virNWFilterIPAddrLearnReqPtr;
+struct _virNWFilterIPAddrLearnReq {
+    virNWFilterTechDriverPtr techdriver;
+    char ifname[IF_NAMESIZE];
+    int ifindex;
+    char linkdev[IF_NAMESIZE];
+    virMacAddr macaddr;
+    char *filtername;
+    virHashTablePtr filterparams;
+    virNWFilterDriverStatePtr driver;
+    enum howDetect howDetect;
+
+    int status;
+    volatile bool terminate;
+};
+
 
 static bool threadsTerminate;
 
@@ -279,8 +296,8 @@ virNWFilterTerminateLearnReq(const char *ifname)
 }
 
 
-virNWFilterIPAddrLearnReqPtr
-virNWFilterLookupLearnReq(int ifindex)
+bool
+virNWFilterHasLearnReq(int ifindex)
 {
     void *res;
     IFINDEX2STR(ifindex_str, ifindex);
@@ -291,7 +308,7 @@ virNWFilterLookupLearnReq(int ifindex)
 
     virMutexUnlock(&pendingLearnReqLock);
 
-    return res;
+    return res != NULL;
 }
 
 
diff --git a/src/nwfilter/nwfilter_learnipaddr.h b/src/nwfilter/nwfilter_learnipaddr.h
index dc4c0d110f..06fea5bff8 100644
--- a/src/nwfilter/nwfilter_learnipaddr.h
+++ b/src/nwfilter/nwfilter_learnipaddr.h
@@ -35,23 +35,6 @@ enum howDetect {
   DETECT_STATIC = 2,
 };
 
-typedef struct _virNWFilterIPAddrLearnReq virNWFilterIPAddrLearnReq;
-typedef virNWFilterIPAddrLearnReq *virNWFilterIPAddrLearnReqPtr;
-struct _virNWFilterIPAddrLearnReq {
-    virNWFilterTechDriverPtr techdriver;
-    char ifname[IF_NAMESIZE];
-    int ifindex;
-    char linkdev[IF_NAMESIZE];
-    virMacAddr macaddr;
-    char *filtername;
-    virHashTablePtr filterparams;
-    virNWFilterDriverStatePtr driver;
-    enum howDetect howDetect;
-
-    int status;
-    volatile bool terminate;
-};
-
 int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
                               const char *ifname,
                               int ifindex,
@@ -62,7 +45,7 @@ int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
                               virNWFilterDriverStatePtr driver,
                               enum howDetect howDetect);
 
-virNWFilterIPAddrLearnReqPtr virNWFilterLookupLearnReq(int ifindex);
+bool virNWFilterHasLearnReq(int ifindex);
 int virNWFilterTerminateLearnReq(const char *ifname);
 
 int virNWFilterLockIface(const char *ifname) ATTRIBUTE_RETURN_CHECK;
-- 
2.14.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 04/14] nwfilter: make virNWFilterIPAddrLearnReq type private
Posted by Jiri Denemark 6 years, 7 months ago
On Fri, Apr 27, 2018 at 16:25:03 +0100, Daniel P. Berrangé wrote:
> The virNWFilterIPAddrLearnReq type should only be used by the IP address
> learning code, so can live in the implementation file instead of header
> file.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  src/nwfilter/nwfilter_gentech_driver.c |  8 ++++----
>  src/nwfilter/nwfilter_learnipaddr.c    | 23 ++++++++++++++++++++---
>  src/nwfilter/nwfilter_learnipaddr.h    | 19 +------------------
>  3 files changed, 25 insertions(+), 25 deletions(-)

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 04/14] nwfilter: make virNWFilterIPAddrLearnReq type private
Posted by Erik Skultety 6 years, 7 months ago
On Fri, Apr 27, 2018 at 04:25:03PM +0100, Daniel P. Berrangé wrote:
> The virNWFilterIPAddrLearnReq type should only be used by the IP address
> learning code, so can live in the implementation file instead of header
> file.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---

Could have split the patch in 2, one that moves the type and the other
refactoring the getter.

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 04/14] nwfilter: make virNWFilterIPAddrLearnReq type private
Posted by Daniel P. Berrangé 6 years, 6 months ago
On Mon, Apr 30, 2018 at 03:30:35PM +0200, Erik Skultety wrote:
> On Fri, Apr 27, 2018 at 04:25:03PM +0100, Daniel P. Berrangé wrote:
> > The virNWFilterIPAddrLearnReq type should only be used by the IP address
> > learning code, so can live in the implementation file instead of header
> > file.
> >
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> 
> Could have split the patch in 2, one that moves the type and the other
> refactoring the getter.

Ok, will split this before pushing with Jiri's ACK.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

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