aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2007-03-28 17:29:08 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-04-26 01:28:26 -0400
commitc45d286e72dd72c0229dc9e2849743ba427fee84 (patch)
tree1fb22a5e71c89043671380087def5bc419a37886
parentf85958151900f9d30fa5ff941b0ce71eaa45a7de (diff)
[NET]: Inline net_device_stats
Network drivers which keep stats allocate their own stats structure then write a get_stats() function to return them. It would be nice if this were done by default. 1) Add a new "stats" field to "struct net_device". 2) Add a new feature field to say "this driver uses the internal one" 3) Have a default "get_stats" which returns NULL if that feature not set. 4) Change callers to check result of get_stats call for NULL, not if ->get_stats is set. This should not break backwards compatibility with older drivers, yet allow modern drivers to shed some boilerplate code. Lightly tested: works for a modified lguest network driver. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--arch/s390/appldata/appldata_net_sum.c4
-rw-r--r--drivers/net/bonding/bond_main.c5
-rw-r--r--drivers/parisc/led.c4
-rw-r--r--include/linux/netdevice.h2
-rw-r--r--net/core/dev.c13
5 files changed, 18 insertions, 10 deletions
diff --git a/arch/s390/appldata/appldata_net_sum.c b/arch/s390/appldata/appldata_net_sum.c
index f64b8c867ae2..516b3ac9a9b5 100644
--- a/arch/s390/appldata/appldata_net_sum.c
+++ b/arch/s390/appldata/appldata_net_sum.c
@@ -108,10 +108,10 @@ static void appldata_get_net_sum_data(void *data)
108 collisions = 0; 108 collisions = 0;
109 read_lock(&dev_base_lock); 109 read_lock(&dev_base_lock);
110 for (dev = dev_base; dev != NULL; dev = dev->next) { 110 for (dev = dev_base; dev != NULL; dev = dev->next) {
111 if (dev->get_stats == NULL) { 111 stats = dev->get_stats(dev);
112 if (stats == NULL) {
112 continue; 113 continue;
113 } 114 }
114 stats = dev->get_stats(dev);
115 rx_packets += stats->rx_packets; 115 rx_packets += stats->rx_packets;
116 tx_packets += stats->tx_packets; 116 tx_packets += stats->tx_packets;
117 rx_bytes += stats->rx_bytes; 117 rx_bytes += stats->rx_bytes;
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 76d3504505bd..cea3783c92c5 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -3640,9 +3640,8 @@ static struct net_device_stats *bond_get_stats(struct net_device *bond_dev)
3640 read_lock_bh(&bond->lock); 3640 read_lock_bh(&bond->lock);
3641 3641
3642 bond_for_each_slave(bond, slave, i) { 3642 bond_for_each_slave(bond, slave, i) {
3643 if (slave->dev->get_stats) { 3643 sstats = slave->dev->get_stats(slave->dev);
3644 sstats = slave->dev->get_stats(slave->dev); 3644 if (sstats) {
3645
3646 stats->rx_packets += sstats->rx_packets; 3645 stats->rx_packets += sstats->rx_packets;
3647 stats->rx_bytes += sstats->rx_bytes; 3646 stats->rx_bytes += sstats->rx_bytes;
3648 stats->rx_errors += sstats->rx_errors; 3647 stats->rx_errors += sstats->rx_errors;
diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
index d190c05d87ed..453e6829756c 100644
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -372,9 +372,9 @@ static __inline__ int led_get_net_activity(void)
372 continue; 372 continue;
373 if (LOOPBACK(in_dev->ifa_list->ifa_local)) 373 if (LOOPBACK(in_dev->ifa_list->ifa_local))
374 continue; 374 continue;
375 if (!dev->get_stats)
376 continue;
377 stats = dev->get_stats(dev); 375 stats = dev->get_stats(dev);
376 if (!stats)
377 continue;
378 rx_total += stats->rx_packets; 378 rx_total += stats->rx_packets;
379 tx_total += stats->tx_packets; 379 tx_total += stats->tx_packets;
380 } 380 }
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 1a528548cd1d..71fc8ff4888b 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -323,6 +323,7 @@ struct net_device
323#define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle VLAN packets */ 323#define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle VLAN packets */
324#define NETIF_F_GSO 2048 /* Enable software GSO. */ 324#define NETIF_F_GSO 2048 /* Enable software GSO. */
325#define NETIF_F_LLTX 4096 /* LockLess TX */ 325#define NETIF_F_LLTX 4096 /* LockLess TX */
326#define NETIF_F_INTERNAL_STATS 8192 /* Use stats structure in net_device */
326 327
327 /* Segmentation offload features */ 328 /* Segmentation offload features */
328#define NETIF_F_GSO_SHIFT 16 329#define NETIF_F_GSO_SHIFT 16
@@ -347,6 +348,7 @@ struct net_device
347 348
348 349
349 struct net_device_stats* (*get_stats)(struct net_device *dev); 350 struct net_device_stats* (*get_stats)(struct net_device *dev);
351 struct net_device_stats stats;
350 352
351 /* List of functions to handle Wireless Extensions (instead of ioctl). 353 /* List of functions to handle Wireless Extensions (instead of ioctl).
352 * See <net/iw_handler.h> for details. Jean II */ 354 * See <net/iw_handler.h> for details. Jean II */
diff --git a/net/core/dev.c b/net/core/dev.c
index 86dc9f693f66..fec8cf27f75d 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -817,7 +817,6 @@ static int default_rebuild_header(struct sk_buff *skb)
817 return 1; 817 return 1;
818} 818}
819 819
820
821/** 820/**
822 * dev_open - prepare an interface for use. 821 * dev_open - prepare an interface for use.
823 * @dev: device to open 822 * @dev: device to open
@@ -2096,9 +2095,9 @@ void dev_seq_stop(struct seq_file *seq, void *v)
2096 2095
2097static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev) 2096static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
2098{ 2097{
2099 if (dev->get_stats) { 2098 struct net_device_stats *stats = dev->get_stats(dev);
2100 struct net_device_stats *stats = dev->get_stats(dev);
2101 2099
2100 if (stats) {
2102 seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu " 2101 seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
2103 "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n", 2102 "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
2104 dev->name, stats->rx_bytes, stats->rx_packets, 2103 dev->name, stats->rx_bytes, stats->rx_packets,
@@ -3282,6 +3281,13 @@ out:
3282 mutex_unlock(&net_todo_run_mutex); 3281 mutex_unlock(&net_todo_run_mutex);
3283} 3282}
3284 3283
3284static struct net_device_stats *maybe_internal_stats(struct net_device *dev)
3285{
3286 if (dev->features & NETIF_F_INTERNAL_STATS)
3287 return &dev->stats;
3288 return NULL;
3289}
3290
3285/** 3291/**
3286 * alloc_netdev - allocate network device 3292 * alloc_netdev - allocate network device
3287 * @sizeof_priv: size of private data to allocate space for 3293 * @sizeof_priv: size of private data to allocate space for
@@ -3317,6 +3323,7 @@ struct net_device *alloc_netdev(int sizeof_priv, const char *name,
3317 if (sizeof_priv) 3323 if (sizeof_priv)
3318 dev->priv = netdev_priv(dev); 3324 dev->priv = netdev_priv(dev);
3319 3325
3326 dev->get_stats = maybe_internal_stats;
3320 setup(dev); 3327 setup(dev);
3321 strcpy(dev->name, name); 3328 strcpy(dev->name, name);
3322 return dev; 3329 return dev;