mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03: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);
|
||||
|
||||
VIR_FREE(def->filter);
|
||||
virNWFilterHashTableFree(def->filterparams);
|
||||
virHashFree(def->filterparams);
|
||||
def->filterparams = NULL;
|
||||
|
||||
virNetDevBandwidthFree(def->bandwidth);
|
||||
@ -11047,7 +11047,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")) {
|
||||
@ -11680,7 +11680,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
VIR_FREE(vhost_path);
|
||||
VIR_FREE(localaddr);
|
||||
VIR_FREE(localport);
|
||||
virNWFilterHashTableFree(filterparams);
|
||||
virHashFree(filterparams);
|
||||
|
||||
return def;
|
||||
|
||||
|
@ -312,7 +312,7 @@ virNWFilterIncludeDefFree(virNWFilterIncludeDefPtr inc)
|
||||
{
|
||||
if (!inc)
|
||||
return;
|
||||
virNWFilterHashTableFree(inc->params);
|
||||
virHashFree(inc->params);
|
||||
VIR_FREE(inc->filterref);
|
||||
VIR_FREE(inc);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -820,10 +820,7 @@ virNWFilterIPAddrMapShutdown;
|
||||
# conf/nwfilter_params.h
|
||||
virNWFilterHashTableCreate;
|
||||
virNWFilterHashTableEqual;
|
||||
virNWFilterHashTableFree;
|
||||
virNWFilterHashTablePut;
|
||||
virNWFilterHashTablePutAll;
|
||||
virNWFilterHashTableRemoveEntry;
|
||||
virNWFilterVarAccessGetVarName;
|
||||
virNWFilterVarAccessIsAvailable;
|
||||
virNWFilterVarAccessPrint;
|
||||
|
@ -647,7 +647,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);
|
||||
@ -1633,7 +1633,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)
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user