diff options
author | Stephen Hemminger <shemminger@vyatta.com> | 2008-11-20 00:40:23 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-11-20 00:40:23 -0500 |
commit | eeda3fd64f75bcbfaa70ce946513abaf3f23b8e0 (patch) | |
tree | 082d1921a5783ef5b07b4cf666804d6509f25f1a | |
parent | d314774cf2cd5dfeb39a00d37deee65d4c627927 (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>
-rw-r--r-- | arch/s390/appldata/appldata_net_sum.c | 4 | ||||
-rw-r--r-- | drivers/net/bonding/bond_main.c | 5 | ||||
-rw-r--r-- | drivers/net/sfc/ethtool.c | 2 | ||||
-rw-r--r-- | drivers/parisc/led.c | 4 | ||||
-rw-r--r-- | include/linux/netdevice.h | 4 | ||||
-rw-r--r-- | net/core/dev.c | 23 | ||||
-rw-r--r-- | net/core/net-sysfs.c | 3 | ||||
-rw-r--r-- | net/core/rtnetlink.c | 6 |
8 files changed, 33 insertions, 18 deletions
diff --git a/arch/s390/appldata/appldata_net_sum.c b/arch/s390/appldata/appldata_net_sum.c index 3b746556e1a3..fa741f84c5b9 100644 --- a/arch/s390/appldata/appldata_net_sum.c +++ b/arch/s390/appldata/appldata_net_sum.c | |||
@@ -67,7 +67,6 @@ static void appldata_get_net_sum_data(void *data) | |||
67 | int i; | 67 | int i; |
68 | struct appldata_net_sum_data *net_data; | 68 | struct appldata_net_sum_data *net_data; |
69 | struct net_device *dev; | 69 | struct net_device *dev; |
70 | struct net_device_stats *stats; | ||
71 | unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors, | 70 | unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors, |
72 | tx_errors, rx_dropped, tx_dropped, collisions; | 71 | tx_errors, rx_dropped, tx_dropped, collisions; |
73 | 72 | ||
@@ -86,7 +85,8 @@ static void appldata_get_net_sum_data(void *data) | |||
86 | collisions = 0; | 85 | collisions = 0; |
87 | read_lock(&dev_base_lock); | 86 | read_lock(&dev_base_lock); |
88 | for_each_netdev(&init_net, dev) { | 87 | for_each_netdev(&init_net, dev) { |
89 | stats = dev->get_stats(dev); | 88 | const struct net_device_stats *stats = dev_get_stats(dev); |
89 | |||
90 | rx_packets += stats->rx_packets; | 90 | rx_packets += stats->rx_packets; |
91 | tx_packets += stats->tx_packets; | 91 | tx_packets += stats->tx_packets; |
92 | rx_bytes += stats->rx_bytes; | 92 | rx_bytes += stats->rx_bytes; |
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index a08ea4808056..db5f5c24a250 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c | |||
@@ -3899,7 +3899,7 @@ static int bond_close(struct net_device *bond_dev) | |||
3899 | static struct net_device_stats *bond_get_stats(struct net_device *bond_dev) | 3899 | static struct net_device_stats *bond_get_stats(struct net_device *bond_dev) |
3900 | { | 3900 | { |
3901 | struct bonding *bond = netdev_priv(bond_dev); | 3901 | struct bonding *bond = netdev_priv(bond_dev); |
3902 | struct net_device_stats *stats = &(bond->stats), *sstats; | 3902 | struct net_device_stats *stats = &bond->stats; |
3903 | struct net_device_stats local_stats; | 3903 | struct net_device_stats local_stats; |
3904 | struct slave *slave; | 3904 | struct slave *slave; |
3905 | int i; | 3905 | int i; |
@@ -3909,7 +3909,8 @@ static struct net_device_stats *bond_get_stats(struct net_device *bond_dev) | |||
3909 | read_lock_bh(&bond->lock); | 3909 | read_lock_bh(&bond->lock); |
3910 | 3910 | ||
3911 | bond_for_each_slave(bond, slave, i) { | 3911 | bond_for_each_slave(bond, slave, i) { |
3912 | sstats = slave->dev->get_stats(slave->dev); | 3912 | const struct net_device_stats *sstats = dev_get_stats(slave->dev); |
3913 | |||
3913 | local_stats.rx_packets += sstats->rx_packets; | 3914 | local_stats.rx_packets += sstats->rx_packets; |
3914 | local_stats.rx_bytes += sstats->rx_bytes; | 3915 | local_stats.rx_bytes += sstats->rx_bytes; |
3915 | local_stats.rx_errors += sstats->rx_errors; | 3916 | local_stats.rx_errors += sstats->rx_errors; |
diff --git a/drivers/net/sfc/ethtool.c b/drivers/net/sfc/ethtool.c index abd8fcd6e62d..cd92c4d8dbc5 100644 --- a/drivers/net/sfc/ethtool.c +++ b/drivers/net/sfc/ethtool.c | |||
@@ -426,7 +426,7 @@ static void efx_ethtool_get_stats(struct net_device *net_dev, | |||
426 | EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS); | 426 | EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS); |
427 | 427 | ||
428 | /* Update MAC and NIC statistics */ | 428 | /* Update MAC and NIC statistics */ |
429 | net_dev->get_stats(net_dev); | 429 | dev_get_stats(net_dev); |
430 | 430 | ||
431 | /* Fill detailed statistics buffer */ | 431 | /* Fill detailed statistics buffer */ |
432 | for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) { | 432 | for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) { |
diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c index f9b12664f9fb..454b6532e409 100644 --- a/drivers/parisc/led.c +++ b/drivers/parisc/led.c | |||
@@ -360,13 +360,13 @@ static __inline__ int led_get_net_activity(void) | |||
360 | read_lock(&dev_base_lock); | 360 | read_lock(&dev_base_lock); |
361 | rcu_read_lock(); | 361 | rcu_read_lock(); |
362 | for_each_netdev(&init_net, dev) { | 362 | for_each_netdev(&init_net, dev) { |
363 | struct net_device_stats *stats; | 363 | const struct net_device_stats *stats; |
364 | struct in_device *in_dev = __in_dev_get_rcu(dev); | 364 | struct in_device *in_dev = __in_dev_get_rcu(dev); |
365 | if (!in_dev || !in_dev->ifa_list) | 365 | if (!in_dev || !in_dev->ifa_list) |
366 | continue; | 366 | continue; |
367 | if (ipv4_is_loopback(in_dev->ifa_list->ifa_local)) | 367 | if (ipv4_is_loopback(in_dev->ifa_list->ifa_local)) |
368 | continue; | 368 | continue; |
369 | stats = dev->get_stats(dev); | 369 | stats = dev_get_stats(dev); |
370 | rx_total += stats->rx_packets; | 370 | rx_total += stats->rx_packets; |
371 | tx_total += stats->tx_packets; | 371 | tx_total += stats->tx_packets; |
372 | } | 372 | } |
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 9060f5f3517a..981a089d5149 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h | |||
@@ -865,8 +865,8 @@ struct net_device | |||
865 | #ifdef CONFIG_NET_POLL_CONTROLLER | 865 | #ifdef CONFIG_NET_POLL_CONTROLLER |
866 | void (*poll_controller)(struct net_device *dev); | 866 | void (*poll_controller)(struct net_device *dev); |
867 | #endif | 867 | #endif |
868 | #endif | ||
869 | }; | 868 | }; |
869 | #endif | ||
870 | }; | 870 | }; |
871 | #define to_net_dev(d) container_of(d, struct net_device, dev) | 871 | #define to_net_dev(d) container_of(d, struct net_device, dev) |
872 | 872 | ||
@@ -1780,6 +1780,8 @@ extern void netdev_features_change(struct net_device *dev); | |||
1780 | /* Load a device via the kmod */ | 1780 | /* Load a device via the kmod */ |
1781 | extern void dev_load(struct net *net, const char *name); | 1781 | extern void dev_load(struct net *net, const char *name); |
1782 | extern void dev_mcast_init(void); | 1782 | extern void dev_mcast_init(void); |
1783 | extern const struct net_device_stats *dev_get_stats(struct net_device *dev); | ||
1784 | |||
1783 | extern int netdev_max_backlog; | 1785 | extern int netdev_max_backlog; |
1784 | extern int weight_p; | 1786 | extern int weight_p; |
1785 | extern int netdev_set_master(struct net_device *dev, struct net_device *master); | 1787 | extern int netdev_set_master(struct net_device *dev, struct net_device *master); |
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 | ||
2621 | static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev) | 2621 | static 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 | ||
4291 | static 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 | */ | ||
4299 | const 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 | } |
4308 | EXPORT_SYMBOL(dev_get_stats); | ||
4295 | 4309 | ||
4296 | static void netdev_init_one_queue(struct net_device *dev, | 4310 | static 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 | ||
553 | static void copy_rtnl_link_stats(struct rtnl_link_stats *a, | 553 | static 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) { |