BpfNetworkStats: switch final iterate(f(K)) to forAll(f(K))
The only real way readValue(K) can fail while iterating is if K gets deleted *while* we're walking the map. That shouldn't be able to happen, and even if it does, we're better off simply continuing and getting what data we can. Test: TreeHugger Flag: EXEMPT mainline/noop Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: Ia286b4067546ef550cd1d9e6864fcddd9d0e5951
This commit is contained in:
parent
1ad3d7f43d
commit
c5180c3766
1 changed files with 5 additions and 6 deletions
|
|
@ -129,19 +129,18 @@ int bpfGetIfaceStatsInternal(const char* iface, StatsValue* stats,
|
|||
}
|
||||
|
||||
// Before 5.10 we try to avoid doing readValue unless needed
|
||||
auto res = ifaceStatsMap.iterate(
|
||||
[iface, stats, ifindex2name, &unknownIfaceBytesTotal, &ifaceStatsMap](const uint32_t& key) -> Result<void> {
|
||||
auto res = ifaceStatsMap.forAll(
|
||||
[iface, stats, ifindex2name, &unknownIfaceBytesTotal, &ifaceStatsMap](const uint32_t& key) {
|
||||
Result<IfaceValue> ifname = ifindex2name(key);
|
||||
if (!ifname.ok()) {
|
||||
maybeLogUnknownIface(key, ifaceStatsMap, key, &unknownIfaceBytesTotal);
|
||||
return {};
|
||||
return;
|
||||
}
|
||||
if (!strcmp(iface, ifname.value().name)) {
|
||||
Result<StatsValue> statsEntry = ifaceStatsMap.readValue(key);
|
||||
if (!statsEntry.ok()) return statsEntry.error();
|
||||
*stats += statsEntry.value();
|
||||
// error shouldn't be possible, if it somehow does, just ignore it and keep going
|
||||
if (statsEntry.ok()) *stats += statsEntry.value();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
);
|
||||
return res.ok() ? 0 : -res.error().code();
|
||||
|
|
|
|||
Loading…
Reference in a new issue