aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorBen Hutchings <bhutchings@solarflare.com>2010-07-09 05:11:52 -0400
committerDavid S. Miller <davem@davemloft.net>2010-07-09 20:41:56 -0400
commit3cfde79c6c7c8002375c4a8e5be7f602fbb9675d (patch)
tree53fe969e9f8bb45531c1e84c82e822ff47ea015c /net
parentcc7b86c1a8f207c8aa77aad6941475d8294a83c4 (diff)
net: Get rid of rtnl_link_stats64 / net_device_stats union
In commit be1f3c2c027cc5ad735df6a45a542ed1db7ec48b "net: Enable 64-bit net device statistics on 32-bit architectures" I redefined struct net_device_stats so that it could be used in a union with struct rtnl_link_stats64, avoiding the need for explicit copying or conversion between the two. However, this is unsafe because there is no locking required and no lock consistently held around calls to dev_get_stats() and use of the statistics structure it returns. In commit 28172739f0a276eb8d6ca917b3974c2edb036da3 "net: fix 64 bit counters on 32 bit arches" Eric Dumazet dealt with that problem by requiring callers of dev_get_stats() to provide storage for the result. This means that the net_device::stats64 field and the padding in struct net_device_stats are now redundant, so remove them. Update the comment on net_device_ops::ndo_get_stats64 to reflect its new usage. Change dev_txq_stats_fold() to use struct rtnl_link_stats64, since that is what all its callers are really using and it is no longer going to be compatible with struct net_device_stats. Eric Dumazet suggested the separate function for the structure conversion. Signed-off-by: Ben Hutchings <bhutchings@solarflare.com> Acked-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/8021q/vlan_dev.c2
-rw-r--r--net/core/dev.c31
2 files changed, 27 insertions, 6 deletions
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index a1b8171cfa7b..7cb285f96b99 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -805,7 +805,7 @@ static u32 vlan_ethtool_get_flags(struct net_device *dev)
805 805
806static struct rtnl_link_stats64 *vlan_dev_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) 806static struct rtnl_link_stats64 *vlan_dev_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
807{ 807{
808 dev_txq_stats_fold(dev, (struct net_device_stats *)stats); 808 dev_txq_stats_fold(dev, stats);
809 809
810 if (vlan_dev_info(dev)->vlan_rx_stats) { 810 if (vlan_dev_info(dev)->vlan_rx_stats) {
811 struct vlan_rx_stats *p, accum = {0}; 811 struct vlan_rx_stats *p, accum = {0};
diff --git a/net/core/dev.c b/net/core/dev.c
index eb4201cf9c8c..79ee26ef5095 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5274,10 +5274,10 @@ void netdev_run_todo(void)
5274/** 5274/**
5275 * dev_txq_stats_fold - fold tx_queues stats 5275 * dev_txq_stats_fold - fold tx_queues stats
5276 * @dev: device to get statistics from 5276 * @dev: device to get statistics from
5277 * @stats: struct net_device_stats to hold results 5277 * @stats: struct rtnl_link_stats64 to hold results
5278 */ 5278 */
5279void dev_txq_stats_fold(const struct net_device *dev, 5279void dev_txq_stats_fold(const struct net_device *dev,
5280 struct net_device_stats *stats) 5280 struct rtnl_link_stats64 *stats)
5281{ 5281{
5282 unsigned long tx_bytes = 0, tx_packets = 0, tx_dropped = 0; 5282 unsigned long tx_bytes = 0, tx_packets = 0, tx_dropped = 0;
5283 unsigned int i; 5283 unsigned int i;
@@ -5297,6 +5297,27 @@ void dev_txq_stats_fold(const struct net_device *dev,
5297} 5297}
5298EXPORT_SYMBOL(dev_txq_stats_fold); 5298EXPORT_SYMBOL(dev_txq_stats_fold);
5299 5299
5300/* Convert net_device_stats to rtnl_link_stats64. They have the same
5301 * fields in the same order, with only the type differing.
5302 */
5303static void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
5304 const struct net_device_stats *netdev_stats)
5305{
5306#if BITS_PER_LONG == 64
5307 BUILD_BUG_ON(sizeof(*stats64) != sizeof(*netdev_stats));
5308 memcpy(stats64, netdev_stats, sizeof(*stats64));
5309#else
5310 size_t i, n = sizeof(*stats64) / sizeof(u64);
5311 const unsigned long *src = (const unsigned long *)netdev_stats;
5312 u64 *dst = (u64 *)stats64;
5313
5314 BUILD_BUG_ON(sizeof(*netdev_stats) / sizeof(unsigned long) !=
5315 sizeof(*stats64) / sizeof(u64));
5316 for (i = 0; i < n; i++)
5317 dst[i] = src[i];
5318#endif
5319}
5320
5300/** 5321/**
5301 * dev_get_stats - get network device statistics 5322 * dev_get_stats - get network device statistics
5302 * @dev: device to get statistics from 5323 * @dev: device to get statistics from
@@ -5317,11 +5338,11 @@ const struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
5317 return ops->ndo_get_stats64(dev, storage); 5338 return ops->ndo_get_stats64(dev, storage);
5318 } 5339 }
5319 if (ops->ndo_get_stats) { 5340 if (ops->ndo_get_stats) {
5320 memcpy(storage, ops->ndo_get_stats(dev), sizeof(*storage)); 5341 netdev_stats_to_stats64(storage, ops->ndo_get_stats(dev));
5321 return storage; 5342 return storage;
5322 } 5343 }
5323 memcpy(storage, &dev->stats, sizeof(*storage)); 5344 netdev_stats_to_stats64(storage, &dev->stats);
5324 dev_txq_stats_fold(dev, (struct net_device_stats *)storage); 5345 dev_txq_stats_fold(dev, storage);
5325 return storage; 5346 return storage;
5326} 5347}
5327EXPORT_SYMBOL(dev_get_stats); 5348EXPORT_SYMBOL(dev_get_stats);