aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Gospodarek <gospo@cumulusnetworks.com>2014-09-28 22:34:37 -0400
committerDavid S. Miller <davem@davemloft.net>2014-09-30 01:20:07 -0400
commit5f0c5f73e5efaee2928c4cabcf48b03f6ba99fc8 (patch)
tree692fa18ddfe4fea8c3a9a43210dcfdb44300f95c
parentb0ab6f92752b9f9d8da980506e9df3bd9dcd7ed3 (diff)
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>
-rw-r--r--drivers/net/bonding/bond_main.c68
-rw-r--r--drivers/net/bonding/bonding.h3
2 files changed, 43 insertions, 28 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 53904758d693..c2adc2755ff6 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -208,6 +208,8 @@ static int lacp_fast;
208 208
209static int bond_init(struct net_device *bond_dev); 209static int bond_init(struct net_device *bond_dev);
210static void bond_uninit(struct net_device *bond_dev); 210static void bond_uninit(struct net_device *bond_dev);
211static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev,
212 struct rtnl_link_stats64 *stats);
211 213
212/*---------------------------- General routines -----------------------------*/ 214/*---------------------------- General routines -----------------------------*/
213 215
@@ -1344,6 +1346,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1344 } 1346 }
1345 1347
1346 slave_dev->priv_flags |= IFF_BONDING; 1348 slave_dev->priv_flags |= IFF_BONDING;
1349 /* initialize slave stats */
1350 dev_get_stats(new_slave->dev, &new_slave->slave_stats);
1347 1351
1348 if (bond_is_lb(bond)) { 1352 if (bond_is_lb(bond)) {
1349 /* bond_alb_init_slave() must be called before all other stages since 1353 /* 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,
1652 1656
1653 bond_sysfs_slave_del(slave); 1657 bond_sysfs_slave_del(slave);
1654 1658
1659 /* recompute stats just before removing the slave */
1660 bond_get_stats(bond->dev, &bond->bond_stats);
1661
1655 bond_upper_dev_unlink(bond_dev, slave_dev); 1662 bond_upper_dev_unlink(bond_dev, slave_dev);
1656 /* unregister rx_handler early so bond_handle_frame wouldn't be called 1663 /* unregister rx_handler early so bond_handle_frame wouldn't be called
1657 * for this slave anymore. 1664 * for this slave anymore.
@@ -3085,38 +3092,43 @@ static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev,
3085 struct list_head *iter; 3092 struct list_head *iter;
3086 struct slave *slave; 3093 struct slave *slave;
3087 3094
3088 memset(stats, 0, sizeof(*stats)); 3095 memcpy(stats, &bond->bond_stats, sizeof(*stats));
3089 3096
3090 bond_for_each_slave(bond, slave, iter) { 3097 bond_for_each_slave(bond, slave, iter) {
3091 const struct rtnl_link_stats64 *sstats = 3098 const struct rtnl_link_stats64 *sstats =
3092 dev_get_stats(slave->dev, &temp); 3099 dev_get_stats(slave->dev, &temp);
3093 3100 struct rtnl_link_stats64 *pstats = &slave->slave_stats;
3094 stats->rx_packets += sstats->rx_packets; 3101
3095 stats->rx_bytes += sstats->rx_bytes; 3102 stats->rx_packets += sstats->rx_packets - pstats->rx_packets;
3096 stats->rx_errors += sstats->rx_errors; 3103 stats->rx_bytes += sstats->rx_bytes - pstats->rx_bytes;
3097 stats->rx_dropped += sstats->rx_dropped; 3104 stats->rx_errors += sstats->rx_errors - pstats->rx_errors;
3098 3105 stats->rx_dropped += sstats->rx_dropped - pstats->rx_dropped;
3099 stats->tx_packets += sstats->tx_packets; 3106
3100 stats->tx_bytes += sstats->tx_bytes; 3107 stats->tx_packets += sstats->tx_packets - pstats->tx_packets;;
3101 stats->tx_errors += sstats->tx_errors; 3108 stats->tx_bytes += sstats->tx_bytes - pstats->tx_bytes;
3102 stats->tx_dropped += sstats->tx_dropped; 3109 stats->tx_errors += sstats->tx_errors - pstats->tx_errors;
3103 3110 stats->tx_dropped += sstats->tx_dropped - pstats->tx_dropped;
3104 stats->multicast += sstats->multicast; 3111
3105 stats->collisions += sstats->collisions; 3112 stats->multicast += sstats->multicast - pstats->multicast;
3106 3113 stats->collisions += sstats->collisions - pstats->collisions;
3107 stats->rx_length_errors += sstats->rx_length_errors; 3114
3108 stats->rx_over_errors += sstats->rx_over_errors; 3115 stats->rx_length_errors += sstats->rx_length_errors - pstats->rx_length_errors;
3109 stats->rx_crc_errors += sstats->rx_crc_errors; 3116 stats->rx_over_errors += sstats->rx_over_errors - pstats->rx_over_errors;
3110 stats->rx_frame_errors += sstats->rx_frame_errors; 3117 stats->rx_crc_errors += sstats->rx_crc_errors - pstats->rx_crc_errors;
3111 stats->rx_fifo_errors += sstats->rx_fifo_errors; 3118 stats->rx_frame_errors += sstats->rx_frame_errors - pstats->rx_frame_errors;
3112 stats->rx_missed_errors += sstats->rx_missed_errors; 3119 stats->rx_fifo_errors += sstats->rx_fifo_errors - pstats->rx_fifo_errors;
3113 3120 stats->rx_missed_errors += sstats->rx_missed_errors - pstats->rx_missed_errors;
3114 stats->tx_aborted_errors += sstats->tx_aborted_errors; 3121
3115 stats->tx_carrier_errors += sstats->tx_carrier_errors; 3122 stats->tx_aborted_errors += sstats->tx_aborted_errors - pstats->tx_aborted_errors;
3116 stats->tx_fifo_errors += sstats->tx_fifo_errors; 3123 stats->tx_carrier_errors += sstats->tx_carrier_errors - pstats->tx_carrier_errors;
3117 stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors; 3124 stats->tx_fifo_errors += sstats->tx_fifo_errors - pstats->tx_fifo_errors;
3118 stats->tx_window_errors += sstats->tx_window_errors; 3125 stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors - pstats->tx_heartbeat_errors;
3119 } 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));
3120 3132
3121 return stats; 3133 return stats;
3122} 3134}
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 6140bf0264a4..57917e63b4e6 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -24,6 +24,7 @@
24#include <linux/inetdevice.h> 24#include <linux/inetdevice.h>
25#include <linux/etherdevice.h> 25#include <linux/etherdevice.h>
26#include <linux/reciprocal_div.h> 26#include <linux/reciprocal_div.h>
27#include <linux/if_link.h>
27 28
28#include "bond_3ad.h" 29#include "bond_3ad.h"
29#include "bond_alb.h" 30#include "bond_alb.h"
@@ -175,6 +176,7 @@ struct slave {
175 struct netpoll *np; 176 struct netpoll *np;
176#endif 177#endif
177 struct kobject kobj; 178 struct kobject kobj;
179 struct rtnl_link_stats64 slave_stats;
178}; 180};
179 181
180/* 182/*
@@ -224,6 +226,7 @@ struct bonding {
224 /* debugging support via debugfs */ 226 /* debugging support via debugfs */
225 struct dentry *debug_dir; 227 struct dentry *debug_dir;
226#endif /* CONFIG_DEBUG_FS */ 228#endif /* CONFIG_DEBUG_FS */
229 struct rtnl_link_stats64 bond_stats;
227}; 230};
228 231
229#define bond_slave_get_rcu(dev) \ 232#define bond_slave_get_rcu(dev) \