From nobody Thu Nov 28 10:45:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524843092961893.6821698089476; Fri, 27 Apr 2018 08:31:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 952F33150080; Fri, 27 Apr 2018 15:31:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CCFE65B54; Fri, 27 Apr 2018 15:31:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B963E180596E; Fri, 27 Apr 2018 15:31:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3RFPIMj032244 for ; Fri, 27 Apr 2018 11:25:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6B57083B71; Fri, 27 Apr 2018 15:25:18 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id D17E583B76; Fri, 27 Apr 2018 15:25:17 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:00 +0100 Message-Id: <20180427152513.28928-2-berrange@redhat.com> In-Reply-To: <20180427152513.28928-1-berrange@redhat.com> References: <20180427152513.28928-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/14] nwfilter: remove pointless virNWFilterHashTable struct X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 27 Apr 2018 15:31:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The virNWFilterHashTable struct only contains a single virHashTable member since commit 293d4fe2f11db98c91175525056c8883725d4b22 Author: Daniel P. Berrange 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=C3=A9 Reviewed-by: Jiri Denemark --- 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 *a= ddr) =20 virMutexLock(&ipAddressMapLock); =20 - val =3D virHashLookup(ipAddressMap->hashTable, ifname); + val =3D virHashLookup(ipAddressMap, ifname); if (!val) { val =3D virNWFilterVarValueCreateSimple(addrCopy); if (!val) @@ -109,7 +109,7 @@ virNWFilterIPAddrMapDelIPAddr(const char *ifname, const= char *ipaddr) virMutexLock(&ipAddressMapLock); =20 if (ipaddr !=3D NULL) { - val =3D virHashLookup(ipAddressMap->hashTable, ifname); + val =3D virHashLookup(ipAddressMap, ifname); if (val) { if (virNWFilterVarValueGetCardinality(val) =3D=3D 1 && STREQ(ipaddr, @@ -144,7 +144,7 @@ virNWFilterIPAddrMapGetIPAddr(const char *ifname) =20 virMutexLock(&ipAddressMapLock); =20 - res =3D virHashLookup(ipAddressMap->hashTable, ifname); + res =3D virHashLookup(ipAddressMap, ifname); =20 virMutexUnlock(&ipAddressMapLock); =20 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(virNWFilterVarCombIte= rEntryPtr cie, unsigned int maxValue =3D 0, minValue =3D 0; const char *varName =3D virNWFilterVarAccessGetVarName(varAccess); =20 - varValue =3D virHashLookup(hash->hashTable, varName); + varValue =3D virHashLookup(hash, varName); if (varValue =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find value for variable '%s'"), @@ -421,7 +421,7 @@ virNWFilterVarCombIterEntryAreUniqueEntries(virNWFilter= VarCombIterEntryPtr cie, virNWFilterVarValuePtr varValue, tmp; const char *value; =20 - varValue =3D virHashLookup(hash->hashTable, cie->varNames[0]); + varValue =3D virHashLookup(hash, cie->varNames[0]); if (!varValue) { /* caller's error */ VIR_ERROR(_("hash lookup resulted in NULL pointer")); @@ -439,7 +439,7 @@ virNWFilterVarCombIterEntryAreUniqueEntries(virNWFilter= VarCombIterEntryPtr cie, if (STREQ(value, virNWFilterVarValueGetNthValue(varValue, i))) { bool isSame =3D true; for (j =3D 1; j < cie->nVarNames; j++) { - tmp =3D virHashLookup(hash->hashTable, cie->varNames[j]); + tmp =3D virHashLookup(hash, cie->varNames[j]); if (!tmp) { /* should never occur to step on a NULL here */ return true; @@ -604,7 +604,7 @@ virNWFilterVarCombIterGetVarValue(virNWFilterVarCombIte= rPtr ci, return NULL; } =20 - value =3D virHashLookup(ci->hashTable->hashTable, varName); + value =3D 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); } =20 =20 virNWFilterHashTablePtr virNWFilterHashTableCreate(int n) { - virNWFilterHashTablePtr ret; - - if (VIR_ALLOC(ret) < 0) - return NULL; - ret->hashTable =3D virHashCreate(n, hashDataFree); - if (!ret->hashTable) { - VIR_FREE(ret); - return NULL; - } - return ret; + return virHashCreate(n, hashDataFree); } =20 =20 @@ -699,7 +686,7 @@ void * virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr ht, const char *entry) { - return virHashSteal(ht->hashTable, entry); + return virHashSteal(ht, entry); } =20 =20 @@ -745,7 +732,7 @@ virNWFilterHashTablePutAll(virNWFilterHashTablePtr src, .errOccurred =3D 0, }; =20 - virHashForEach(src->hashTable, addToTable, &atts); + virHashForEach(src, addToTable, &atts); if (atts.errOccurred) goto err_exit; =20 @@ -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, virNWFilterVarValueCom= pare); + return virHashEqual(a, b, virNWFilterVarValueCompare); } =20 static bool @@ -819,7 +802,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur) goto skip_entry; if (!isValidVarValue(val)) goto skip_entry; - value =3D virHashLookup(table->hashTable, nam); + value =3D 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; =20 - numKeys =3D virHashSize(table->hashTable); + numKeys =3D virHashSize(table); =20 if (numKeys < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -879,7 +862,7 @@ virNWFilterFormatParamAttributes(virBufferPtr buf, return -1; } =20 - items =3D virHashGetItems(table->hashTable, + items =3D virHashGetItems(table, virNWFilterFormatParameterNameSorter); if (!items) return -1; @@ -1103,7 +1086,7 @@ virNWFilterVarAccessIsAvailable(const virNWFilterVarA= ccess *varAccess, unsigned int idx; virNWFilterVarValuePtr varValue; =20 - varValue =3D virHashLookup(hash->hashTable, varName); + varValue =3D virHashLookup(hash, varName); if (!varValue) return false; =20 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 v= al, char *value); int virNWFilterVarValueAddValueCopy(virNWFilterVarValuePtr val, const char= *value); int virNWFilterVarValueDelValue(virNWFilterVarValuePtr val, const char *va= lue); =20 -typedef struct _virNWFilterHashTable virNWFilterHashTable; -typedef virNWFilterHashTable *virNWFilterHashTablePtr; -struct _virNWFilterHashTable { - virHashTablePtr hashTable; -}; - +typedef virHashTable virNWFilterHashTable; +typedef virHashTable *virNWFilterHashTablePtr; =20 virNWFilterHashTablePtr virNWFilterParseParamAttributes(xmlNodePtr cur); int virNWFilterFormatParamAttributes(virBufferPtr buf, diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.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 =3D - virHashLookup(req->vars->hashTable, NWFILTER_VARNAME_DHCPSERVE= R); + virHashLookup(req->vars, NWFILTER_VARNAME_DHCPSERVER); =20 if (req->techdriver && req->techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr, @@ -1648,7 +1648,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver, goto exit_snoopreqput; } =20 - dhcpsrvrs =3D virHashLookup(filterparams->hashTable, + dhcpsrvrs =3D virHashLookup(filterparams, NWFILTER_VARNAME_DHCPSERVER); =20 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(virNWFilterHashTableP= tr table, if (!val) return -1; =20 - if (virHashAddEntry(table->hashTable, + if (virHashAddEntry(table, NWFILTER_STD_VAR_MAC, val) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -167,7 +167,7 @@ virNWFilterVarHashmapAddStdValues(virNWFilterHashTableP= tr table, if (!val) return -1; =20 - 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; =20 - lv =3D virHashLookup(vars->hashTable, NWFILTER_VARNAME_CTRL_IP_LEARNIN= G); + lv =3D virHashLookup(vars, NWFILTER_VARNAME_CTRL_IP_LEARNING); if (lv) learning =3D virNWFilterVarValueGetNthValue(lv, 0); else @@ -642,8 +642,8 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, if (learning =3D=3D NULL) learning =3D NWFILTER_DFLT_LEARN; =20 - if (virHashSize(missing_vars->hashTable) =3D=3D 1) { - if (virHashLookup(missing_vars->hashTable, + if (virHashSize(missing_vars) =3D=3D 1) { + if (virHashLookup(missing_vars, NWFILTER_STD_VAR_IP) !=3D NULL) { if (STRCASEEQ(learning, "none")) { /* no learning */ reportIP =3D 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) !=3D NULL) { @@ -729,7 +729,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, =20 err_unresolvable_vars: =20 - buf =3D virNWFilterPrintVars(missing_vars->hashTable, ", ", false, rep= ortIP); + buf =3D 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/nwfilterxml2firewallt= est.c index b5eec538c4..bf1400d2d0 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -333,7 +333,7 @@ static int testSetOneParameter(virNWFilterHashTablePtr = vars, int ret =3D -1; virNWFilterVarValuePtr val; =20 - if ((val =3D virHashLookup(vars->hashTable, name)) =3D=3D NULL) { + if ((val =3D virHashLookup(vars, name)) =3D=3D NULL) { val =3D virNWFilterVarValueCreateSimpleCopyValue(value); if (!val) goto cleanup; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list