From nobody Thu Nov 28 11:03:20 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 1524842879898141.62114030729106; Fri, 27 Apr 2018 08:27:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 195354E918; Fri, 27 Apr 2018 15:27:58 +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 547E617D7C; Fri, 27 Apr 2018 15:27:57 +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 0EA17180215F; Fri, 27 Apr 2018 15:27:56 +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 w3RFPJf2032250 for ; Fri, 27 Apr 2018 11:25:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 208BD83B76; Fri, 27 Apr 2018 15:25:19 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E3BA83B77; Fri, 27 Apr 2018 15:25:18 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:01 +0100 Message-Id: <20180427152513.28928-3-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 02/14] nwfilter: remove methods that are trivial wrappers for virHash APIs 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 27 Apr 2018 15:27:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 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=C3=A9 Reviewed-by: Jiri Denemark --- 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); =20 VIR_FREE(def->filter); - virNWFilterHashTableFree(def->filterparams); + virHashFree(def->filterparams); def->filterparams =3D NULL; =20 virNetDevBandwidthFree(def->bandwidth); @@ -11046,7 +11046,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, goto error; } filter =3D virXMLPropString(cur, "filter"); - virNWFilterHashTableFree(filterparams); + virHashFree(filterparams); filterparams =3D virNWFilterParseParamAttributes(cur); } else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && virXMLNodeNameEqual(cur, "state")) { @@ -11679,7 +11679,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, VIR_FREE(vhost_path); VIR_FREE(localaddr); VIR_FREE(localport); - virNWFilterHashTableFree(filterparams); + virHashFree(filterparams); =20 return def; =20 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 *a= ddr) if (!val) goto cleanup; addrCopy =3D NULL; - ret =3D virNWFilterHashTablePut(ipAddressMap, ifname, val); + ret =3D 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 =3D virNWFilterHashTableRemoveEntry(ipAddressMap, ifname); - virNWFilterVarValueFree(val); + virHashRemoveEntry(ipAddressMap, ifname); ret =3D 0; } =20 @@ -164,6 +163,6 @@ virNWFilterIPAddrMapInit(void) void virNWFilterIPAddrMapShutdown(void) { - virNWFilterHashTableFree(ipAddressMap); + virHashFree(ipAddressMap); ipAddressMap =3D 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 ATTRIBUT= E_UNUSED) } =20 =20 -/** - * 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); } =20 - -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; } =20 - 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 =3D 1; virNWFilterVarValueFree(val); } @@ -814,7 +758,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur) value =3D virNWFilterParseVarValue(val); if (!value) goto skip_entry; - if (virNWFilterHashTablePut(table, nam, value) < 0) + if (virHashUpdateEntry(table, nam, value) < 0) goto err_exit; } value =3D NULL; @@ -833,7 +777,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur) VIR_FREE(nam); VIR_FREE(val); virNWFilterVarValueFree(value); - virNWFilterHashTableFree(table); + virHashFree(table); return NULL; } =20 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); =20 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_dhcp= snoop.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); =20 virMutexDestroy(&req->lock); virCondDestroy(&req->threadStatusCond); @@ -1617,7 +1617,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver, } /* a recycled req may still have filtername and vars */ VIR_FREE(req->filtername); - virNWFilterHashTableFree(req->vars); + virHashFree(req->vars); } else { req =3D 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; =20 - virNWFilterHashTableFree(inst->vars); + virHashFree(inst->vars); VIR_FREE(inst); } =20 @@ -200,7 +200,7 @@ virNWFilterCreateVarHashmap(char *macaddr, return NULL; =20 if (virNWFilterVarHashmapAddStdValues(table, macaddr, ipaddr) < 0) { - virNWFilterHashTableFree(table); + virHashFree(table); return NULL; } return table; @@ -295,7 +295,7 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1, return res; =20 err_exit: - virNWFilterHashTableFree(res); + virHashFree(res); return NULL; } =20 @@ -424,7 +424,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverStateP= tr driver, cleanup: if (ret < 0) virNWFilterInstReset(inst); - virNWFilterHashTableFree(tmpvars); + virHashFree(tmpvars); if (obj) virNWFilterObjUnlock(obj); return ret; @@ -524,7 +524,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr fi= lter, } =20 varAccess =3D virBufferContentAndReset(&buf); - rc =3D virNWFilterHashTablePut(missing_vars, varAccess= , val); + rc =3D virHashUpdateEntry(missing_vars, varAccess, val= ); VIR_FREE(varAccess); if (rc < 0) { virNWFilterVarValueFree(val); @@ -562,7 +562,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr fi= lter, useNewFilter, driver); =20 - virNWFilterHashTableFree(tmpvars); + virHashFree(tmpvars); =20 virNWFilterObjUnlock(obj); if (rc < 0) @@ -723,7 +723,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, =20 err_exit: virNWFilterInstReset(&inst); - virNWFilterHashTableFree(missing_vars); + virHashFree(missing_vars); =20 return rc; =20 @@ -832,10 +832,10 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverS= tatePtr driver, teardownOld, macaddr, driver, forceWithPendingReq); =20 - virNWFilterHashTableFree(vars); + virHashFree(vars); =20 err_exit_vars1: - virNWFilterHashTableFree(vars1); + virHashFree(vars1); =20 err_exit: virNWFilterObjUnlock(obj); diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 9ca0639576..f5b94cf27d 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -216,7 +216,7 @@ virNWFilterIPAddrLearnReqFree(virNWFilterIPAddrLearnReq= Ptr req) return; =20 VIR_FREE(req->filtername); - virNWFilterHashTableFree(req->filterparams); + virHashFree(req->filterparams); =20 VIR_FREE(req); } @@ -765,7 +765,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr tech= driver, 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/nwfilterxml2firewallt= est.c index bf1400d2d0..a51ad9412a 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -164,7 +164,7 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1, return res; =20 err_exit: - virNWFilterHashTableFree(res); + virHashFree(res); return NULL; } =20 @@ -175,7 +175,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst) if (!inst) return; =20 - virNWFilterHashTableFree(inst->vars); + virHashFree(inst->vars); VIR_FREE(inst); } =20 @@ -263,7 +263,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDefPt= r 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 =3D 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; } =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list