[PATCH 02/14] nwfilter: remove methods that are trivial wrappers for virHash APIs

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

 



This removes the virNWFilterHashTableFree, virNWFilterHashTablePut
and virNWFilterHashTableRemove methods, in favour of just calling
the virHash APIs directly.

The virNWFilterHashTablePut method was unreasonably complex because
the virHashUpdateEntry already knows how to create the entry if it
does not currently exist.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/conf/domain_conf.c                 |  6 ++--
 src/conf/nwfilter_conf.c               |  2 +-
 src/conf/nwfilter_ipaddrmap.c          |  7 ++--
 src/conf/nwfilter_params.c             | 62 ++--------------------------------
 src/conf/nwfilter_params.h             |  6 ----
 src/libvirt_private.syms               |  3 --
 src/nwfilter/nwfilter_dhcpsnoop.c      |  4 +--
 src/nwfilter/nwfilter_gentech_driver.c | 18 +++++-----
 src/nwfilter/nwfilter_learnipaddr.c    |  4 +--
 tests/nwfilterxml2firewalltest.c       | 10 +++---
 10 files changed, 28 insertions(+), 94 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b0257068da..627058a144 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2093,7 +2093,7 @@ virDomainNetDefClear(virDomainNetDefPtr def)
     virDomainDeviceInfoClear(&def->info);
 
     VIR_FREE(def->filter);
-    virNWFilterHashTableFree(def->filterparams);
+    virHashFree(def->filterparams);
     def->filterparams = NULL;
 
     virNetDevBandwidthFree(def->bandwidth);
@@ -11046,7 +11046,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
                     goto error;
                 }
                 filter = virXMLPropString(cur, "filter");
-                virNWFilterHashTableFree(filterparams);
+                virHashFree(filterparams);
                 filterparams = virNWFilterParseParamAttributes(cur);
             } else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) &&
                        virXMLNodeNameEqual(cur, "state")) {
@@ -11679,7 +11679,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
     VIR_FREE(vhost_path);
     VIR_FREE(localaddr);
     VIR_FREE(localport);
-    virNWFilterHashTableFree(filterparams);
+    virHashFree(filterparams);
 
     return def;
 
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index fd42d58c2c..5d04f2a93c 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -312,7 +312,7 @@ virNWFilterIncludeDefFree(virNWFilterIncludeDefPtr inc)
 {
     if (!inc)
         return;
-    virNWFilterHashTableFree(inc->params);
+    virHashFree(inc->params);
     VIR_FREE(inc->filterref);
     VIR_FREE(inc);
 }
diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c
index 680667bac9..a921d7cfd6 100644
--- a/src/conf/nwfilter_ipaddrmap.c
+++ b/src/conf/nwfilter_ipaddrmap.c
@@ -67,7 +67,7 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr)
         if (!val)
             goto cleanup;
         addrCopy = NULL;
-        ret = virNWFilterHashTablePut(ipAddressMap, ifname, val);
+        ret = virHashUpdateEntry(ipAddressMap, ifname, val);
         if (ret < 0)
             virNWFilterVarValueFree(val);
         goto cleanup;
@@ -121,8 +121,7 @@ virNWFilterIPAddrMapDelIPAddr(const char *ifname, const char *ipaddr)
     } else {
  remove_entry:
         /* remove whole entry */
-        val = virNWFilterHashTableRemoveEntry(ipAddressMap, ifname);
-        virNWFilterVarValueFree(val);
+        virHashRemoveEntry(ipAddressMap, ifname);
         ret = 0;
     }
 
@@ -164,6 +163,6 @@ virNWFilterIPAddrMapInit(void)
 void
 virNWFilterIPAddrMapShutdown(void)
 {
-    virNWFilterHashTableFree(ipAddressMap);
+    virHashFree(ipAddressMap);
     ipAddressMap = NULL;
 }
diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c
index e833c8cb5d..ee9c063941 100644
--- a/src/conf/nwfilter_params.c
+++ b/src/conf/nwfilter_params.c
@@ -631,65 +631,12 @@ hashDataFree(void *payload, const void *name ATTRIBUTE_UNUSED)
 }
 
 
-/**
- * virNWFilterHashTablePut:
- * @table: Pointer to a virNWFilterHashTable
- * @name: name of the key to enter
- * @val: The value associated with the key
- * @freeName: Whether the name must be freed on table destruction
- *
- * Returns 0 on success, -1 on failure.
- *
- * Put an entry into the hashmap replacing and freeing an existing entry
- * if one existed.
- */
-int
-virNWFilterHashTablePut(virNWFilterHashTablePtr table,
-                        const char *name,
-                        virNWFilterVarValuePtr val)
-{
-    if (!virHashLookup(table, name)) {
-        if (virHashAddEntry(table, name, val) < 0)
-            return -1;
-    } else {
-        if (virHashUpdateEntry(table, name, val) < 0)
-            return -1;
-    }
-    return 0;
-}
-
-
-/**
- * virNWFilterHashTableFree:
- * @table: Pointer to virNWFilterHashTable
- *
- * Free a hashtable de-allocating memory for all its entries.
- *
- * All hash tables within the NWFilter driver must use this
- * function to deallocate and free their content.
- */
-void
-virNWFilterHashTableFree(virNWFilterHashTablePtr table)
-{
-    virHashFree(table);
-}
-
-
 virNWFilterHashTablePtr
 virNWFilterHashTableCreate(int n)
 {
     return virHashCreate(n, hashDataFree);
 }
 
-
-void *
-virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr ht,
-                                const char *entry)
-{
-    return virHashSteal(ht, entry);
-}
-
-
 struct addToTableStruct {
     virNWFilterHashTablePtr target;
     int errOccurred;
@@ -711,10 +658,7 @@ addToTable(void *payload, const void *name, void *data)
         return 0;
     }
 
-    if (virNWFilterHashTablePut(atts->target, (const char *)name, val) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not put variable '%s' into hashmap"),
-                       (const char *)name);
+    if (virHashUpdateEntry(atts->target, (const char *)name, val) < 0) {
         atts->errOccurred = 1;
         virNWFilterVarValueFree(val);
     }
@@ -814,7 +758,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur)
                         value = virNWFilterParseVarValue(val);
                         if (!value)
                             goto skip_entry;
-                        if (virNWFilterHashTablePut(table, nam, value) < 0)
+                        if (virHashUpdateEntry(table, nam, value) < 0)
                             goto err_exit;
                     }
                     value = NULL;
@@ -833,7 +777,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur)
     VIR_FREE(nam);
     VIR_FREE(val);
     virNWFilterVarValueFree(value);
-    virNWFilterHashTableFree(table);
+    virHashFree(table);
     return NULL;
 }
 
diff --git a/src/conf/nwfilter_params.h b/src/conf/nwfilter_params.h
index b3ed3e6418..b24f023633 100644
--- a/src/conf/nwfilter_params.h
+++ b/src/conf/nwfilter_params.h
@@ -72,12 +72,6 @@ int virNWFilterFormatParamAttributes(virBufferPtr buf,
                                      const char *filterref);
 
 virNWFilterHashTablePtr virNWFilterHashTableCreate(int n);
-void virNWFilterHashTableFree(virNWFilterHashTablePtr table);
-int virNWFilterHashTablePut(virNWFilterHashTablePtr table,
-                            const char *name,
-                            virNWFilterVarValuePtr val);
-void *virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr table,
-                                      const char *name);
 int virNWFilterHashTablePutAll(virNWFilterHashTablePtr src,
                                virNWFilterHashTablePtr dest);
 bool virNWFilterHashTableEqual(virNWFilterHashTablePtr a,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d2728749fb..bf17d17777 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -820,10 +820,7 @@ virNWFilterIPAddrMapShutdown;
 # conf/nwfilter_params.h
 virNWFilterHashTableCreate;
 virNWFilterHashTableEqual;
-virNWFilterHashTableFree;
-virNWFilterHashTablePut;
 virNWFilterHashTablePutAll;
-virNWFilterHashTableRemoveEntry;
 virNWFilterVarAccessGetVarName;
 virNWFilterVarAccessIsAvailable;
 virNWFilterVarAccessPrint;
diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index d1e3f836a1..d23cad3b75 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -636,7 +636,7 @@ virNWFilterSnoopReqFree(virNWFilterSnoopReqPtr req)
     VIR_FREE(req->ifname);
     VIR_FREE(req->linkdev);
     VIR_FREE(req->filtername);
-    virNWFilterHashTableFree(req->vars);
+    virHashFree(req->vars);
 
     virMutexDestroy(&req->lock);
     virCondDestroy(&req->threadStatusCond);
@@ -1617,7 +1617,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
         }
         /* a recycled req may still have filtername and vars */
         VIR_FREE(req->filtername);
-        virNWFilterHashTableFree(req->vars);
+        virHashFree(req->vars);
     } else {
         req = virNWFilterSnoopReqNew(ifkey);
         if (!req)
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 4706f1f1da..130a366d67 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -123,7 +123,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst)
     if (!inst)
         return;
 
-    virNWFilterHashTableFree(inst->vars);
+    virHashFree(inst->vars);
     VIR_FREE(inst);
 }
 
@@ -200,7 +200,7 @@ virNWFilterCreateVarHashmap(char *macaddr,
         return NULL;
 
     if (virNWFilterVarHashmapAddStdValues(table, macaddr, ipaddr) < 0) {
-        virNWFilterHashTableFree(table);
+        virHashFree(table);
         return NULL;
     }
     return table;
@@ -295,7 +295,7 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1,
     return res;
 
  err_exit:
-    virNWFilterHashTableFree(res);
+    virHashFree(res);
     return NULL;
 }
 
@@ -424,7 +424,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverStatePtr driver,
  cleanup:
     if (ret < 0)
         virNWFilterInstReset(inst);
-    virNWFilterHashTableFree(tmpvars);
+    virHashFree(tmpvars);
     if (obj)
         virNWFilterObjUnlock(obj);
     return ret;
@@ -524,7 +524,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
                     }
 
                     varAccess = virBufferContentAndReset(&buf);
-                    rc = virNWFilterHashTablePut(missing_vars, varAccess, val);
+                    rc = virHashUpdateEntry(missing_vars, varAccess, val);
                     VIR_FREE(varAccess);
                     if (rc < 0) {
                         virNWFilterVarValueFree(val);
@@ -562,7 +562,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
                                                     useNewFilter,
                                                     driver);
 
-            virNWFilterHashTableFree(tmpvars);
+            virHashFree(tmpvars);
 
             virNWFilterObjUnlock(obj);
             if (rc < 0)
@@ -723,7 +723,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid,
 
  err_exit:
     virNWFilterInstReset(&inst);
-    virNWFilterHashTableFree(missing_vars);
+    virHashFree(missing_vars);
 
     return rc;
 
@@ -832,10 +832,10 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverStatePtr driver,
                                   teardownOld, macaddr, driver,
                                   forceWithPendingReq);
 
-    virNWFilterHashTableFree(vars);
+    virHashFree(vars);
 
  err_exit_vars1:
-    virNWFilterHashTableFree(vars1);
+    virHashFree(vars1);
 
  err_exit:
     virNWFilterObjUnlock(obj);
diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c
index 9ca0639576..f5b94cf27d 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -216,7 +216,7 @@ virNWFilterIPAddrLearnReqFree(virNWFilterIPAddrLearnReqPtr req)
         return;
 
     VIR_FREE(req->filtername);
-    virNWFilterHashTableFree(req->filterparams);
+    virHashFree(req->filterparams);
 
     VIR_FREE(req);
 }
@@ -765,7 +765,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
  err_dereg_req:
     virNWFilterDeregisterLearnReq(ifindex);
  err_free_ht:
-    virNWFilterHashTableFree(ht);
+    virHashFree(ht);
  err_free_req:
     virNWFilterIPAddrLearnReqFree(req);
  err_no_req:
diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c
index bf1400d2d0..a51ad9412a 100644
--- a/tests/nwfilterxml2firewalltest.c
+++ b/tests/nwfilterxml2firewalltest.c
@@ -164,7 +164,7 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1,
     return res;
 
  err_exit:
-    virNWFilterHashTableFree(res);
+    virHashFree(res);
     return NULL;
 }
 
@@ -175,7 +175,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst)
     if (!inst)
         return;
 
-    virNWFilterHashTableFree(inst->vars);
+    virHashFree(inst->vars);
     VIR_FREE(inst);
 }
 
@@ -263,7 +263,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDefPtr inc,
  cleanup:
     if (ret < 0)
         virNWFilterInstReset(inst);
-    virNWFilterHashTableFree(tmpvars);
+    virHashFree(tmpvars);
     VIR_FREE(xml);
     return ret;
 }
@@ -337,7 +337,7 @@ static int testSetOneParameter(virNWFilterHashTablePtr vars,
         val = virNWFilterVarValueCreateSimpleCopyValue(value);
         if (!val)
             goto cleanup;
-        if (virNWFilterHashTablePut(vars, name, val) < 0) {
+        if (virHashUpdateEntry(vars, name, val) < 0) {
             virNWFilterVarValueFree(val);
             goto cleanup;
         }
@@ -414,7 +414,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
     virBufferFreeAndReset(&buf);
     VIR_FREE(actualargv);
     virNWFilterInstReset(&inst);
-    virNWFilterHashTableFree(vars);
+    virHashFree(vars);
     return ret;
 }
 
-- 
2.14.3

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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux