Skip to content

Commit 5f0c5f7

Browse files
gospodavem330
authored andcommitted
bonding: make global bonding stats more reliable
As the code stands today, bonding stats are based simply on the stats from the member interfaces. If a member was to be removed from a bond, the stats would instantly drop. This would be confusing to an admin would would suddonly see interface stats drop while traffic is still flowing. In addition to preventing the stats drops mentioned above, new members will now be added to the bond and only traffic received after the member was added to the bond will be counted as part of bonding stats. Bonding counters will also be updated when any slaves are dropped to make sure the reported stats are reliable. v2: Changes suggested by Nik to properly allocate/free stats memory. v3: Properly destroy workqueue and fix netlink configuration path. v4: Moved cached stats into bonding and slave structs as there does not seem to be a complexity/performance benefit to using alloc'd memory vs in-struct memory. Signed-off-by: Andy Gospodarek <gospo@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b0ab6f9 commit 5f0c5f7

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

drivers/net/bonding/bond_main.c

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ static int lacp_fast;
208208

209209
static int bond_init(struct net_device *bond_dev);
210210
static void bond_uninit(struct net_device *bond_dev);
211+
static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev,
212+
struct rtnl_link_stats64 *stats);
211213

212214
/*---------------------------- General routines -----------------------------*/
213215

@@ -1344,6 +1346,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
13441346
}
13451347

13461348
slave_dev->priv_flags |= IFF_BONDING;
1349+
/* initialize slave stats */
1350+
dev_get_stats(new_slave->dev, &new_slave->slave_stats);
13471351

13481352
if (bond_is_lb(bond)) {
13491353
/* bond_alb_init_slave() must be called before all other stages since
@@ -1652,6 +1656,9 @@ static int __bond_release_one(struct net_device *bond_dev,
16521656

16531657
bond_sysfs_slave_del(slave);
16541658

1659+
/* recompute stats just before removing the slave */
1660+
bond_get_stats(bond->dev, &bond->bond_stats);
1661+
16551662
bond_upper_dev_unlink(bond_dev, slave_dev);
16561663
/* unregister rx_handler early so bond_handle_frame wouldn't be called
16571664
* for this slave anymore.
@@ -3085,38 +3092,43 @@ static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev,
30853092
struct list_head *iter;
30863093
struct slave *slave;
30873094

3088-
memset(stats, 0, sizeof(*stats));
3095+
memcpy(stats, &bond->bond_stats, sizeof(*stats));
30893096

30903097
bond_for_each_slave(bond, slave, iter) {
30913098
const struct rtnl_link_stats64 *sstats =
30923099
dev_get_stats(slave->dev, &temp);
3093-
3094-
stats->rx_packets += sstats->rx_packets;
3095-
stats->rx_bytes += sstats->rx_bytes;
3096-
stats->rx_errors += sstats->rx_errors;
3097-
stats->rx_dropped += sstats->rx_dropped;
3098-
3099-
stats->tx_packets += sstats->tx_packets;
3100-
stats->tx_bytes += sstats->tx_bytes;
3101-
stats->tx_errors += sstats->tx_errors;
3102-
stats->tx_dropped += sstats->tx_dropped;
3103-
3104-
stats->multicast += sstats->multicast;
3105-
stats->collisions += sstats->collisions;
3106-
3107-
stats->rx_length_errors += sstats->rx_length_errors;
3108-
stats->rx_over_errors += sstats->rx_over_errors;
3109-
stats->rx_crc_errors += sstats->rx_crc_errors;
3110-
stats->rx_frame_errors += sstats->rx_frame_errors;
3111-
stats->rx_fifo_errors += sstats->rx_fifo_errors;
3112-
stats->rx_missed_errors += sstats->rx_missed_errors;
3113-
3114-
stats->tx_aborted_errors += sstats->tx_aborted_errors;
3115-
stats->tx_carrier_errors += sstats->tx_carrier_errors;
3116-
stats->tx_fifo_errors += sstats->tx_fifo_errors;
3117-
stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
3118-
stats->tx_window_errors += sstats->tx_window_errors;
3119-
}
3100+
struct rtnl_link_stats64 *pstats = &slave->slave_stats;
3101+
3102+
stats->rx_packets += sstats->rx_packets - pstats->rx_packets;
3103+
stats->rx_bytes += sstats->rx_bytes - pstats->rx_bytes;
3104+
stats->rx_errors += sstats->rx_errors - pstats->rx_errors;
3105+
stats->rx_dropped += sstats->rx_dropped - pstats->rx_dropped;
3106+
3107+
stats->tx_packets += sstats->tx_packets - pstats->tx_packets;;
3108+
stats->tx_bytes += sstats->tx_bytes - pstats->tx_bytes;
3109+
stats->tx_errors += sstats->tx_errors - pstats->tx_errors;
3110+
stats->tx_dropped += sstats->tx_dropped - pstats->tx_dropped;
3111+
3112+
stats->multicast += sstats->multicast - pstats->multicast;
3113+
stats->collisions += sstats->collisions - pstats->collisions;
3114+
3115+
stats->rx_length_errors += sstats->rx_length_errors - pstats->rx_length_errors;
3116+
stats->rx_over_errors += sstats->rx_over_errors - pstats->rx_over_errors;
3117+
stats->rx_crc_errors += sstats->rx_crc_errors - pstats->rx_crc_errors;
3118+
stats->rx_frame_errors += sstats->rx_frame_errors - pstats->rx_frame_errors;
3119+
stats->rx_fifo_errors += sstats->rx_fifo_errors - pstats->rx_fifo_errors;
3120+
stats->rx_missed_errors += sstats->rx_missed_errors - pstats->rx_missed_errors;
3121+
3122+
stats->tx_aborted_errors += sstats->tx_aborted_errors - pstats->tx_aborted_errors;
3123+
stats->tx_carrier_errors += sstats->tx_carrier_errors - pstats->tx_carrier_errors;
3124+
stats->tx_fifo_errors += sstats->tx_fifo_errors - pstats->tx_fifo_errors;
3125+
stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors - pstats->tx_heartbeat_errors;
3126+
stats->tx_window_errors += sstats->tx_window_errors - pstats->tx_window_errors;
3127+
3128+
/* save off the slave stats for the next run */
3129+
memcpy(pstats, sstats, sizeof(*sstats));
3130+
}
3131+
memcpy(&bond->bond_stats, stats, sizeof(*stats));
31203132

31213133
return stats;
31223134
}

drivers/net/bonding/bonding.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/inetdevice.h>
2525
#include <linux/etherdevice.h>
2626
#include <linux/reciprocal_div.h>
27+
#include <linux/if_link.h>
2728

2829
#include "bond_3ad.h"
2930
#include "bond_alb.h"
@@ -175,6 +176,7 @@ struct slave {
175176
struct netpoll *np;
176177
#endif
177178
struct kobject kobj;
179+
struct rtnl_link_stats64 slave_stats;
178180
};
179181

180182
/*
@@ -224,6 +226,7 @@ struct bonding {
224226
/* debugging support via debugfs */
225227
struct dentry *debug_dir;
226228
#endif /* CONFIG_DEBUG_FS */
229+
struct rtnl_link_stats64 bond_stats;
227230
};
228231

229232
#define bond_slave_get_rcu(dev) \

0 commit comments

Comments
 (0)