The virNWFilterHashTable struct only contains a single virHashTable member since
commit 293d4fe2f11db98c91175525056c8883725d4b22 Author: Daniel P. Berrange <berra...@redhat.com> Date: Mon Mar 24 16:35:23 2014 +0000 Remove pointless storage of var names in virNWFilterHashTable Thus, this struct wrapper adds no real value over just using the virHashTable directly, but brings the complexity of needing to derefence the hashtable to call virHash* APIs, and adds extra memory allocation step. To minimize code churn this just turns virNWFilterHashTable into a typedef aliases virHashTable. Signed-off-by: Daniel P. Berrangé <berra...@redhat.com> --- src/conf/nwfilter_ipaddrmap.c | 6 ++--- src/conf/nwfilter_params.c | 49 +++++++++++----------------------- src/conf/nwfilter_params.h | 8 ++---- src/nwfilter/nwfilter_dhcpsnoop.c | 4 +-- src/nwfilter/nwfilter_gentech_driver.c | 14 +++++----- tests/nwfilterxml2firewalltest.c | 2 +- 6 files changed, 31 insertions(+), 52 deletions(-) diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c index 54e6d0f0f4..680667bac9 100644 --- a/src/conf/nwfilter_ipaddrmap.c +++ b/src/conf/nwfilter_ipaddrmap.c @@ -61,7 +61,7 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr) virMutexLock(&ipAddressMapLock); - val = virHashLookup(ipAddressMap->hashTable, ifname); + val = virHashLookup(ipAddressMap, ifname); if (!val) { val = virNWFilterVarValueCreateSimple(addrCopy); if (!val) @@ -109,7 +109,7 @@ virNWFilterIPAddrMapDelIPAddr(const char *ifname, const char *ipaddr) virMutexLock(&ipAddressMapLock); if (ipaddr != NULL) { - val = virHashLookup(ipAddressMap->hashTable, ifname); + val = virHashLookup(ipAddressMap, ifname); if (val) { if (virNWFilterVarValueGetCardinality(val) == 1 && STREQ(ipaddr, @@ -144,7 +144,7 @@ virNWFilterIPAddrMapGetIPAddr(const char *ifname) virMutexLock(&ipAddressMapLock); - res = virHashLookup(ipAddressMap->hashTable, ifname); + res = virHashLookup(ipAddressMap, ifname); virMutexUnlock(&ipAddressMapLock); diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index 3a01049182..e833c8cb5d 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -355,7 +355,7 @@ virNWFilterVarCombIterAddVariable(virNWFilterVarCombIterEntryPtr cie, unsigned int maxValue = 0, minValue = 0; const char *varName = virNWFilterVarAccessGetVarName(varAccess); - varValue = virHashLookup(hash->hashTable, varName); + varValue = virHashLookup(hash, varName); if (varValue == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find value for variable '%s'"), @@ -421,7 +421,7 @@ virNWFilterVarCombIterEntryAreUniqueEntries(virNWFilterVarCombIterEntryPtr cie, virNWFilterVarValuePtr varValue, tmp; const char *value; - varValue = virHashLookup(hash->hashTable, cie->varNames[0]); + varValue = virHashLookup(hash, cie->varNames[0]); if (!varValue) { /* caller's error */ VIR_ERROR(_("hash lookup resulted in NULL pointer")); @@ -439,7 +439,7 @@ virNWFilterVarCombIterEntryAreUniqueEntries(virNWFilterVarCombIterEntryPtr cie, if (STREQ(value, virNWFilterVarValueGetNthValue(varValue, i))) { bool isSame = true; for (j = 1; j < cie->nVarNames; j++) { - tmp = virHashLookup(hash->hashTable, cie->varNames[j]); + tmp = virHashLookup(hash, cie->varNames[j]); if (!tmp) { /* should never occur to step on a NULL here */ return true; @@ -604,7 +604,7 @@ virNWFilterVarCombIterGetVarValue(virNWFilterVarCombIterPtr ci, return NULL; } - value = virHashLookup(ci->hashTable->hashTable, varName); + value = virHashLookup(ci->hashTable, varName); if (!value) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find value for variable '%s'"), @@ -648,11 +648,11 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table, const char *name, virNWFilterVarValuePtr val) { - if (!virHashLookup(table->hashTable, name)) { - if (virHashAddEntry(table->hashTable, name, val) < 0) + if (!virHashLookup(table, name)) { + if (virHashAddEntry(table, name, val) < 0) return -1; } else { - if (virHashUpdateEntry(table->hashTable, name, val) < 0) + if (virHashUpdateEntry(table, name, val) < 0) return -1; } return 0; @@ -671,27 +671,14 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table, void virNWFilterHashTableFree(virNWFilterHashTablePtr table) { - if (!table) - return; - virHashFree(table->hashTable); - - VIR_FREE(table); + virHashFree(table); } virNWFilterHashTablePtr virNWFilterHashTableCreate(int n) { - virNWFilterHashTablePtr ret; - - if (VIR_ALLOC(ret) < 0) - return NULL; - ret->hashTable = virHashCreate(n, hashDataFree); - if (!ret->hashTable) { - VIR_FREE(ret); - return NULL; - } - return ret; + return virHashCreate(n, hashDataFree); } @@ -699,7 +686,7 @@ void * virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr ht, const char *entry) { - return virHashSteal(ht->hashTable, entry); + return virHashSteal(ht, entry); } @@ -745,7 +732,7 @@ virNWFilterHashTablePutAll(virNWFilterHashTablePtr src, .errOccurred = 0, }; - virHashForEach(src->hashTable, addToTable, &atts); + virHashForEach(src, addToTable, &atts); if (atts.errOccurred) goto err_exit; @@ -770,11 +757,7 @@ bool virNWFilterHashTableEqual(virNWFilterHashTablePtr a, virNWFilterHashTablePtr b) { - if (!(a || b)) - return true; - if (!(a && b)) - return false; - return virHashEqual(a->hashTable, b->hashTable, virNWFilterVarValueCompare); + return virHashEqual(a, b, virNWFilterVarValueCompare); } static bool @@ -819,7 +802,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur) goto skip_entry; if (!isValidVarValue(val)) goto skip_entry; - value = virHashLookup(table->hashTable, nam); + value = virHashLookup(table, nam); if (value) { /* add value to existing value -> list */ if (virNWFilterVarValueAddValue(value, val) < 0) { @@ -871,7 +854,7 @@ virNWFilterFormatParamAttributes(virBufferPtr buf, size_t i, j; int card, numKeys; - numKeys = virHashSize(table->hashTable); + numKeys = virHashSize(table); if (numKeys < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -879,7 +862,7 @@ virNWFilterFormatParamAttributes(virBufferPtr buf, return -1; } - items = virHashGetItems(table->hashTable, + items = virHashGetItems(table, virNWFilterFormatParameterNameSorter); if (!items) return -1; @@ -1103,7 +1086,7 @@ virNWFilterVarAccessIsAvailable(const virNWFilterVarAccess *varAccess, unsigned int idx; virNWFilterVarValuePtr varValue; - varValue = virHashLookup(hash->hashTable, varName); + varValue = virHashLookup(hash, varName); if (!varValue) return false; diff --git a/src/conf/nwfilter_params.h b/src/conf/nwfilter_params.h index abd5b85fec..b3ed3e6418 100644 --- a/src/conf/nwfilter_params.h +++ b/src/conf/nwfilter_params.h @@ -63,12 +63,8 @@ int virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value); int virNWFilterVarValueAddValueCopy(virNWFilterVarValuePtr val, const char *value); int virNWFilterVarValueDelValue(virNWFilterVarValuePtr val, const char *value); -typedef struct _virNWFilterHashTable virNWFilterHashTable; -typedef virNWFilterHashTable *virNWFilterHashTablePtr; -struct _virNWFilterHashTable { - virHashTablePtr hashTable; -}; - +typedef virHashTable virNWFilterHashTable; +typedef virHashTable *virNWFilterHashTablePtr; virNWFilterHashTablePtr virNWFilterParseParamAttributes(xmlNodePtr cur); int virNWFilterFormatParamAttributes(virBufferPtr buf, diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index 6069e70460..d1e3f836a1 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -883,7 +883,7 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req, req->vars); } else { virNWFilterVarValuePtr dhcpsrvrs = - virHashLookup(req->vars->hashTable, NWFILTER_VARNAME_DHCPSERVER); + virHashLookup(req->vars, NWFILTER_VARNAME_DHCPSERVER); if (req->techdriver && req->techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr, @@ -1648,7 +1648,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver, goto exit_snoopreqput; } - dhcpsrvrs = virHashLookup(filterparams->hashTable, + dhcpsrvrs = virHashLookup(filterparams, NWFILTER_VARNAME_DHCPSERVER); if (techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr, diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 5ef26b6afb..4706f1f1da 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -153,7 +153,7 @@ virNWFilterVarHashmapAddStdValues(virNWFilterHashTablePtr table, if (!val) return -1; - if (virHashAddEntry(table->hashTable, + if (virHashAddEntry(table, NWFILTER_STD_VAR_MAC, val) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -167,7 +167,7 @@ virNWFilterVarHashmapAddStdValues(virNWFilterHashTablePtr table, if (!val) return -1; - if (virHashAddEntry(table->hashTable, + if (virHashAddEntry(table, NWFILTER_STD_VAR_IP, val) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -633,7 +633,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, if (rc < 0) goto err_exit; - lv = virHashLookup(vars->hashTable, NWFILTER_VARNAME_CTRL_IP_LEARNING); + lv = virHashLookup(vars, NWFILTER_VARNAME_CTRL_IP_LEARNING); if (lv) learning = virNWFilterVarValueGetNthValue(lv, 0); else @@ -642,8 +642,8 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, if (learning == NULL) learning = NWFILTER_DFLT_LEARN; - if (virHashSize(missing_vars->hashTable) == 1) { - if (virHashLookup(missing_vars->hashTable, + if (virHashSize(missing_vars) == 1) { + if (virHashLookup(missing_vars, NWFILTER_STD_VAR_IP) != NULL) { if (STRCASEEQ(learning, "none")) { /* no learning */ reportIP = true; @@ -677,7 +677,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, } else { goto err_unresolvable_vars; } - } else if (virHashSize(missing_vars->hashTable) > 1) { + } else if (virHashSize(missing_vars) > 1) { goto err_unresolvable_vars; } else if (!forceWithPendingReq && virNWFilterLookupLearnReq(ifindex) != NULL) { @@ -729,7 +729,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, err_unresolvable_vars: - buf = virNWFilterPrintVars(missing_vars->hashTable, ", ", false, reportIP); + buf = virNWFilterPrintVars(missing_vars, ", ", false, reportIP); if (buf) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot instantiate filter due to unresolvable " diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c index b5eec538c4..bf1400d2d0 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -333,7 +333,7 @@ static int testSetOneParameter(virNWFilterHashTablePtr vars, int ret = -1; virNWFilterVarValuePtr val; - if ((val = virHashLookup(vars->hashTable, name)) == NULL) { + if ((val = virHashLookup(vars, name)) == NULL) { val = virNWFilterVarValueCreateSimpleCopyValue(value); if (!val) goto cleanup; -- 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list