aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@vyatta.com>2008-11-20 00:40:23 -0500
committerDavid S. Miller <davem@davemloft.net>2008-11-20 00:40:23 -0500
commiteeda3fd64f75bcbfaa70ce946513abaf3f23b8e0 (patch)
tree082d1921a5783ef5b07b4cf666804d6509f25f1a /net/core
parentd314774cf2cd5dfeb39a00d37deee65d4c627927 (diff)
netdev: introduce dev_get_stats()
In order for the network device ops get_stats call to be immutable, the handling of the default internal network device stats block has to be changed. Add a new helper function which replaces the old use of internal_get_stats. Note: change return code to make it clear that the caller should not go changing the returned statistics. Signed-off-by: Stephen Hemminger <shemminger@vyatta.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/dev.c23
-rw-r--r--net/core/net-sysfs.c3
-rw-r--r--net/core/rtnetlink.c6
3 files changed, 22 insertions, 10 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index ca14ab407b33..8843f4e3f5e1 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2620,7 +2620,7 @@ void dev_seq_stop(struct seq_file *seq, void *v)
2620 2620
2621static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev) 2621static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
2622{ 2622{
2623 struct net_device_stats *stats = dev->get_stats(dev); 2623 const struct net_device_stats *stats = dev_get_stats(dev);
2624 2624
2625 seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu " 2625 seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
2626 "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n", 2626 "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
@@ -4288,10 +4288,24 @@ void netdev_run_todo(void)
4288 } 4288 }
4289} 4289}
4290 4290
4291static struct net_device_stats *internal_stats(struct net_device *dev) 4291/**
4292{ 4292 * dev_get_stats - get network device statistics
4293 return &dev->stats; 4293 * @dev: device to get statistics from
4294 *
4295 * Get network statistics from device. The device driver may provide
4296 * its own method by setting dev->netdev_ops->get_stats; otherwise
4297 * the internal statistics structure is used.
4298 */
4299const struct net_device_stats *dev_get_stats(struct net_device *dev)
4300 {
4301 const struct net_device_ops *ops = dev->netdev_ops;
4302
4303 if (ops->ndo_get_stats)
4304 return ops->ndo_get_stats(dev);
4305 else
4306 return &dev->stats;
4294} 4307}
4308EXPORT_SYMBOL(dev_get_stats);
4295 4309
4296static void netdev_init_one_queue(struct net_device *dev, 4310static void netdev_init_one_queue(struct net_device *dev,
4297 struct netdev_queue *queue, 4311 struct netdev_queue *queue,
@@ -4370,7 +4384,6 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
4370 4384
4371 netdev_init_queues(dev); 4385 netdev_init_queues(dev);
4372 4386
4373 dev->get_stats = internal_stats;
4374 netpoll_netdev_init(dev); 4387 netpoll_netdev_init(dev);
4375 setup(dev); 4388 setup(dev);
4376 strcpy(dev->name, name); 4389 strcpy(dev->name, name);
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 146dcfeb060e..afd42d717320 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -270,7 +270,6 @@ static ssize_t netstat_show(const struct device *d,
270 unsigned long offset) 270 unsigned long offset)
271{ 271{
272 struct net_device *dev = to_net_dev(d); 272 struct net_device *dev = to_net_dev(d);
273 struct net_device_stats *stats;
274 ssize_t ret = -EINVAL; 273 ssize_t ret = -EINVAL;
275 274
276 WARN_ON(offset > sizeof(struct net_device_stats) || 275 WARN_ON(offset > sizeof(struct net_device_stats) ||
@@ -278,7 +277,7 @@ static ssize_t netstat_show(const struct device *d,
278 277
279 read_lock(&dev_base_lock); 278 read_lock(&dev_base_lock);
280 if (dev_isalive(dev)) { 279 if (dev_isalive(dev)) {
281 stats = dev->get_stats(dev); 280 const struct net_device_stats *stats = dev_get_stats(dev);
282 ret = sprintf(buf, fmt_ulong, 281 ret = sprintf(buf, fmt_ulong,
283 *(unsigned long *)(((u8 *) stats) + offset)); 282 *(unsigned long *)(((u8 *) stats) + offset));
284 } 283 }
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 6f8e0778e565..790dd205bb5d 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -551,7 +551,7 @@ static void set_operstate(struct net_device *dev, unsigned char transition)
551} 551}
552 552
553static void copy_rtnl_link_stats(struct rtnl_link_stats *a, 553static void copy_rtnl_link_stats(struct rtnl_link_stats *a,
554 struct net_device_stats *b) 554 const struct net_device_stats *b)
555{ 555{
556 a->rx_packets = b->rx_packets; 556 a->rx_packets = b->rx_packets;
557 a->tx_packets = b->tx_packets; 557 a->tx_packets = b->tx_packets;
@@ -609,7 +609,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
609 struct netdev_queue *txq; 609 struct netdev_queue *txq;
610 struct ifinfomsg *ifm; 610 struct ifinfomsg *ifm;
611 struct nlmsghdr *nlh; 611 struct nlmsghdr *nlh;
612 struct net_device_stats *stats; 612 const struct net_device_stats *stats;
613 struct nlattr *attr; 613 struct nlattr *attr;
614 614
615 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ifm), flags); 615 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ifm), flags);
@@ -666,7 +666,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
666 if (attr == NULL) 666 if (attr == NULL)
667 goto nla_put_failure; 667 goto nla_put_failure;
668 668
669 stats = dev->get_stats(dev); 669 stats = dev_get_stats(dev);
670 copy_rtnl_link_stats(nla_data(attr), stats); 670 copy_rtnl_link_stats(nla_data(attr), stats);
671 671
672 if (dev->rtnl_link_ops) { 672 if (dev->rtnl_link_ops) {