mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 11:01:19 +00:00
nwfilter: remove methods that are trivial wrappers for virHash APIs
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. Reviewed-by: Jiri Denemark <jdenemar@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
77646d9478
commit
1cf16d755e
@ -2094,7 +2094,7 @@ virDomainNetDefClear(virDomainNetDefPtr def)
|
|||||||
virDomainDeviceInfoClear(&def->info);
|
virDomainDeviceInfoClear(&def->info);
|
||||||
|
|
||||||
VIR_FREE(def->filter);
|
VIR_FREE(def->filter);
|
||||||
virNWFilterHashTableFree(def->filterparams);
|
virHashFree(def->filterparams);
|
||||||
def->filterparams = NULL;
|
def->filterparams = NULL;
|
||||||
|
|
||||||
virNetDevBandwidthFree(def->bandwidth);
|
virNetDevBandwidthFree(def->bandwidth);
|
||||||
@ -11047,7 +11047,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
filter = virXMLPropString(cur, "filter");
|
filter = virXMLPropString(cur, "filter");
|
||||||
virNWFilterHashTableFree(filterparams);
|
virHashFree(filterparams);
|
||||||
filterparams = virNWFilterParseParamAttributes(cur);
|
filterparams = virNWFilterParseParamAttributes(cur);
|
||||||
} else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) &&
|
} else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) &&
|
||||||
virXMLNodeNameEqual(cur, "state")) {
|
virXMLNodeNameEqual(cur, "state")) {
|
||||||
@ -11680,7 +11680,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||||||
VIR_FREE(vhost_path);
|
VIR_FREE(vhost_path);
|
||||||
VIR_FREE(localaddr);
|
VIR_FREE(localaddr);
|
||||||
VIR_FREE(localport);
|
VIR_FREE(localport);
|
||||||
virNWFilterHashTableFree(filterparams);
|
virHashFree(filterparams);
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ virNWFilterIncludeDefFree(virNWFilterIncludeDefPtr inc)
|
|||||||
{
|
{
|
||||||
if (!inc)
|
if (!inc)
|
||||||
return;
|
return;
|
||||||
virNWFilterHashTableFree(inc->params);
|
virHashFree(inc->params);
|
||||||
VIR_FREE(inc->filterref);
|
VIR_FREE(inc->filterref);
|
||||||
VIR_FREE(inc);
|
VIR_FREE(inc);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr)
|
|||||||
if (!val)
|
if (!val)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
addrCopy = NULL;
|
addrCopy = NULL;
|
||||||
ret = virNWFilterHashTablePut(ipAddressMap, ifname, val);
|
ret = virHashUpdateEntry(ipAddressMap, ifname, val);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
virNWFilterVarValueFree(val);
|
virNWFilterVarValueFree(val);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -121,8 +121,7 @@ virNWFilterIPAddrMapDelIPAddr(const char *ifname, const char *ipaddr)
|
|||||||
} else {
|
} else {
|
||||||
remove_entry:
|
remove_entry:
|
||||||
/* remove whole entry */
|
/* remove whole entry */
|
||||||
val = virNWFilterHashTableRemoveEntry(ipAddressMap, ifname);
|
virHashRemoveEntry(ipAddressMap, ifname);
|
||||||
virNWFilterVarValueFree(val);
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +163,6 @@ virNWFilterIPAddrMapInit(void)
|
|||||||
void
|
void
|
||||||
virNWFilterIPAddrMapShutdown(void)
|
virNWFilterIPAddrMapShutdown(void)
|
||||||
{
|
{
|
||||||
virNWFilterHashTableFree(ipAddressMap);
|
virHashFree(ipAddressMap);
|
||||||
ipAddressMap = NULL;
|
ipAddressMap = NULL;
|
||||||
}
|
}
|
||||||
|
@ -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
|
virNWFilterHashTablePtr
|
||||||
virNWFilterHashTableCreate(int n)
|
virNWFilterHashTableCreate(int n)
|
||||||
{
|
{
|
||||||
return virHashCreate(n, hashDataFree);
|
return virHashCreate(n, hashDataFree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *
|
|
||||||
virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr ht,
|
|
||||||
const char *entry)
|
|
||||||
{
|
|
||||||
return virHashSteal(ht, entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct addToTableStruct {
|
struct addToTableStruct {
|
||||||
virNWFilterHashTablePtr target;
|
virNWFilterHashTablePtr target;
|
||||||
int errOccurred;
|
int errOccurred;
|
||||||
@ -711,10 +658,7 @@ addToTable(void *payload, const void *name, void *data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virNWFilterHashTablePut(atts->target, (const char *)name, val) < 0) {
|
if (virHashUpdateEntry(atts->target, (const char *)name, val) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Could not put variable '%s' into hashmap"),
|
|
||||||
(const char *)name);
|
|
||||||
atts->errOccurred = 1;
|
atts->errOccurred = 1;
|
||||||
virNWFilterVarValueFree(val);
|
virNWFilterVarValueFree(val);
|
||||||
}
|
}
|
||||||
@ -814,7 +758,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur)
|
|||||||
value = virNWFilterParseVarValue(val);
|
value = virNWFilterParseVarValue(val);
|
||||||
if (!value)
|
if (!value)
|
||||||
goto skip_entry;
|
goto skip_entry;
|
||||||
if (virNWFilterHashTablePut(table, nam, value) < 0)
|
if (virHashUpdateEntry(table, nam, value) < 0)
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
value = NULL;
|
value = NULL;
|
||||||
@ -833,7 +777,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur)
|
|||||||
VIR_FREE(nam);
|
VIR_FREE(nam);
|
||||||
VIR_FREE(val);
|
VIR_FREE(val);
|
||||||
virNWFilterVarValueFree(value);
|
virNWFilterVarValueFree(value);
|
||||||
virNWFilterHashTableFree(table);
|
virHashFree(table);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,12 +72,6 @@ int virNWFilterFormatParamAttributes(virBufferPtr buf,
|
|||||||
const char *filterref);
|
const char *filterref);
|
||||||
|
|
||||||
virNWFilterHashTablePtr virNWFilterHashTableCreate(int n);
|
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,
|
int virNWFilterHashTablePutAll(virNWFilterHashTablePtr src,
|
||||||
virNWFilterHashTablePtr dest);
|
virNWFilterHashTablePtr dest);
|
||||||
bool virNWFilterHashTableEqual(virNWFilterHashTablePtr a,
|
bool virNWFilterHashTableEqual(virNWFilterHashTablePtr a,
|
||||||
|
@ -820,10 +820,7 @@ virNWFilterIPAddrMapShutdown;
|
|||||||
# conf/nwfilter_params.h
|
# conf/nwfilter_params.h
|
||||||
virNWFilterHashTableCreate;
|
virNWFilterHashTableCreate;
|
||||||
virNWFilterHashTableEqual;
|
virNWFilterHashTableEqual;
|
||||||
virNWFilterHashTableFree;
|
|
||||||
virNWFilterHashTablePut;
|
|
||||||
virNWFilterHashTablePutAll;
|
virNWFilterHashTablePutAll;
|
||||||
virNWFilterHashTableRemoveEntry;
|
|
||||||
virNWFilterVarAccessGetVarName;
|
virNWFilterVarAccessGetVarName;
|
||||||
virNWFilterVarAccessIsAvailable;
|
virNWFilterVarAccessIsAvailable;
|
||||||
virNWFilterVarAccessPrint;
|
virNWFilterVarAccessPrint;
|
||||||
|
@ -647,7 +647,7 @@ virNWFilterSnoopReqFree(virNWFilterSnoopReqPtr req)
|
|||||||
VIR_FREE(req->ifname);
|
VIR_FREE(req->ifname);
|
||||||
VIR_FREE(req->linkdev);
|
VIR_FREE(req->linkdev);
|
||||||
VIR_FREE(req->filtername);
|
VIR_FREE(req->filtername);
|
||||||
virNWFilterHashTableFree(req->vars);
|
virHashFree(req->vars);
|
||||||
|
|
||||||
virMutexDestroy(&req->lock);
|
virMutexDestroy(&req->lock);
|
||||||
virCondDestroy(&req->threadStatusCond);
|
virCondDestroy(&req->threadStatusCond);
|
||||||
@ -1633,7 +1633,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
|
|||||||
}
|
}
|
||||||
/* a recycled req may still have filtername and vars */
|
/* a recycled req may still have filtername and vars */
|
||||||
VIR_FREE(req->filtername);
|
VIR_FREE(req->filtername);
|
||||||
virNWFilterHashTableFree(req->vars);
|
virHashFree(req->vars);
|
||||||
} else {
|
} else {
|
||||||
req = virNWFilterSnoopReqNew(ifkey);
|
req = virNWFilterSnoopReqNew(ifkey);
|
||||||
if (!req)
|
if (!req)
|
||||||
|
@ -123,7 +123,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst)
|
|||||||
if (!inst)
|
if (!inst)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virNWFilterHashTableFree(inst->vars);
|
virHashFree(inst->vars);
|
||||||
VIR_FREE(inst);
|
VIR_FREE(inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ virNWFilterCreateVarHashmap(char *macaddr,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virNWFilterVarHashmapAddStdValues(table, macaddr, ipaddr) < 0) {
|
if (virNWFilterVarHashmapAddStdValues(table, macaddr, ipaddr) < 0) {
|
||||||
virNWFilterHashTableFree(table);
|
virHashFree(table);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return table;
|
return table;
|
||||||
@ -295,7 +295,7 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1,
|
|||||||
return res;
|
return res;
|
||||||
|
|
||||||
err_exit:
|
err_exit:
|
||||||
virNWFilterHashTableFree(res);
|
virHashFree(res);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,7 +424,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverStatePtr driver,
|
|||||||
cleanup:
|
cleanup:
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
virNWFilterInstReset(inst);
|
virNWFilterInstReset(inst);
|
||||||
virNWFilterHashTableFree(tmpvars);
|
virHashFree(tmpvars);
|
||||||
if (obj)
|
if (obj)
|
||||||
virNWFilterObjUnlock(obj);
|
virNWFilterObjUnlock(obj);
|
||||||
return ret;
|
return ret;
|
||||||
@ -524,7 +524,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
|
|||||||
}
|
}
|
||||||
|
|
||||||
varAccess = virBufferContentAndReset(&buf);
|
varAccess = virBufferContentAndReset(&buf);
|
||||||
rc = virNWFilterHashTablePut(missing_vars, varAccess, val);
|
rc = virHashUpdateEntry(missing_vars, varAccess, val);
|
||||||
VIR_FREE(varAccess);
|
VIR_FREE(varAccess);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
virNWFilterVarValueFree(val);
|
virNWFilterVarValueFree(val);
|
||||||
@ -562,7 +562,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
|
|||||||
useNewFilter,
|
useNewFilter,
|
||||||
driver);
|
driver);
|
||||||
|
|
||||||
virNWFilterHashTableFree(tmpvars);
|
virHashFree(tmpvars);
|
||||||
|
|
||||||
virNWFilterObjUnlock(obj);
|
virNWFilterObjUnlock(obj);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
@ -723,7 +723,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid,
|
|||||||
|
|
||||||
err_exit:
|
err_exit:
|
||||||
virNWFilterInstReset(&inst);
|
virNWFilterInstReset(&inst);
|
||||||
virNWFilterHashTableFree(missing_vars);
|
virHashFree(missing_vars);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
@ -832,10 +832,10 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverStatePtr driver,
|
|||||||
teardownOld, macaddr, driver,
|
teardownOld, macaddr, driver,
|
||||||
forceWithPendingReq);
|
forceWithPendingReq);
|
||||||
|
|
||||||
virNWFilterHashTableFree(vars);
|
virHashFree(vars);
|
||||||
|
|
||||||
err_exit_vars1:
|
err_exit_vars1:
|
||||||
virNWFilterHashTableFree(vars1);
|
virHashFree(vars1);
|
||||||
|
|
||||||
err_exit:
|
err_exit:
|
||||||
virNWFilterObjUnlock(obj);
|
virNWFilterObjUnlock(obj);
|
||||||
|
@ -216,7 +216,7 @@ virNWFilterIPAddrLearnReqFree(virNWFilterIPAddrLearnReqPtr req)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
VIR_FREE(req->filtername);
|
VIR_FREE(req->filtername);
|
||||||
virNWFilterHashTableFree(req->filterparams);
|
virHashFree(req->filterparams);
|
||||||
|
|
||||||
VIR_FREE(req);
|
VIR_FREE(req);
|
||||||
}
|
}
|
||||||
@ -765,7 +765,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
|
|||||||
err_dereg_req:
|
err_dereg_req:
|
||||||
virNWFilterDeregisterLearnReq(ifindex);
|
virNWFilterDeregisterLearnReq(ifindex);
|
||||||
err_free_ht:
|
err_free_ht:
|
||||||
virNWFilterHashTableFree(ht);
|
virHashFree(ht);
|
||||||
err_free_req:
|
err_free_req:
|
||||||
virNWFilterIPAddrLearnReqFree(req);
|
virNWFilterIPAddrLearnReqFree(req);
|
||||||
err_no_req:
|
err_no_req:
|
||||||
|
@ -164,7 +164,7 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1,
|
|||||||
return res;
|
return res;
|
||||||
|
|
||||||
err_exit:
|
err_exit:
|
||||||
virNWFilterHashTableFree(res);
|
virHashFree(res);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst)
|
|||||||
if (!inst)
|
if (!inst)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virNWFilterHashTableFree(inst->vars);
|
virHashFree(inst->vars);
|
||||||
VIR_FREE(inst);
|
VIR_FREE(inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDefPtr inc,
|
|||||||
cleanup:
|
cleanup:
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
virNWFilterInstReset(inst);
|
virNWFilterInstReset(inst);
|
||||||
virNWFilterHashTableFree(tmpvars);
|
virHashFree(tmpvars);
|
||||||
VIR_FREE(xml);
|
VIR_FREE(xml);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -337,7 +337,7 @@ static int testSetOneParameter(virNWFilterHashTablePtr vars,
|
|||||||
val = virNWFilterVarValueCreateSimpleCopyValue(value);
|
val = virNWFilterVarValueCreateSimpleCopyValue(value);
|
||||||
if (!val)
|
if (!val)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (virNWFilterHashTablePut(vars, name, val) < 0) {
|
if (virHashUpdateEntry(vars, name, val) < 0) {
|
||||||
virNWFilterVarValueFree(val);
|
virNWFilterVarValueFree(val);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -414,7 +414,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
|||||||
virBufferFreeAndReset(&buf);
|
virBufferFreeAndReset(&buf);
|
||||||
VIR_FREE(actualargv);
|
VIR_FREE(actualargv);
|
||||||
virNWFilterInstReset(&inst);
|
virNWFilterInstReset(&inst);
|
||||||
virNWFilterHashTableFree(vars);
|
virHashFree(vars);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user