Commit 28172739 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net: fix 64 bit counters on 32 bit arches

There is a small possibility that a reader gets incorrect values on 32
bit arches. SNMP applications could catch incorrect counters when a
32bit high part is changed by another stats consumer/provider.

One way to solve this is to add a rtnl_link_stats64 param to all
ndo_get_stats64() methods, and also add such a parameter to
dev_get_stats().

Rule is that we are not allowed to use dev->stats64 as a temporary
storage for 64bit stats, but a caller provided area (usually on stack)

Old drivers (only providing get_stats() method) need no changes.
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 217d32dc
...@@ -85,7 +85,8 @@ static void appldata_get_net_sum_data(void *data) ...@@ -85,7 +85,8 @@ static void appldata_get_net_sum_data(void *data)
rcu_read_lock(); rcu_read_lock();
for_each_netdev_rcu(&init_net, dev) { for_each_netdev_rcu(&init_net, dev) {
const struct net_device_stats *stats = dev_get_stats(dev); struct rtnl_link_stats64 temp;
const struct net_device_stats *stats = dev_get_stats(dev, &temp);
rx_packets += stats->rx_packets; rx_packets += stats->rx_packets;
tx_packets += stats->tx_packets; tx_packets += stats->tx_packets;
......
...@@ -3804,51 +3804,49 @@ static int bond_close(struct net_device *bond_dev) ...@@ -3804,51 +3804,49 @@ static int bond_close(struct net_device *bond_dev)
return 0; return 0;
} }
static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev) static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev,
struct rtnl_link_stats64 *stats)
{ {
struct bonding *bond = netdev_priv(bond_dev); struct bonding *bond = netdev_priv(bond_dev);
struct rtnl_link_stats64 *stats = &bond_dev->stats64; struct rtnl_link_stats64 temp;
struct rtnl_link_stats64 local_stats;
struct slave *slave; struct slave *slave;
int i; int i;
memset(&local_stats, 0, sizeof(local_stats)); memset(stats, 0, sizeof(*stats));
read_lock_bh(&bond->lock); read_lock_bh(&bond->lock);
bond_for_each_slave(bond, slave, i) { bond_for_each_slave(bond, slave, i) {
const struct rtnl_link_stats64 *sstats = const struct rtnl_link_stats64 *sstats =
dev_get_stats(slave->dev); dev_get_stats(slave->dev, &temp);
local_stats.rx_packets += sstats->rx_packets; stats->rx_packets += sstats->rx_packets;
local_stats.rx_bytes += sstats->rx_bytes; stats->rx_bytes += sstats->rx_bytes;
local_stats.rx_errors += sstats->rx_errors; stats->rx_errors += sstats->rx_errors;
local_stats.rx_dropped += sstats->rx_dropped; stats->rx_dropped += sstats->rx_dropped;
local_stats.tx_packets += sstats->tx_packets; stats->tx_packets += sstats->tx_packets;
local_stats.tx_bytes += sstats->tx_bytes; stats->tx_bytes += sstats->tx_bytes;
local_stats.tx_errors += sstats->tx_errors; stats->tx_errors += sstats->tx_errors;
local_stats.tx_dropped += sstats->tx_dropped; stats->tx_dropped += sstats->tx_dropped;
local_stats.multicast += sstats->multicast; stats->multicast += sstats->multicast;
local_stats.collisions += sstats->collisions; stats->collisions += sstats->collisions;
local_stats.rx_length_errors += sstats->rx_length_errors; stats->rx_length_errors += sstats->rx_length_errors;
local_stats.rx_over_errors += sstats->rx_over_errors; stats->rx_over_errors += sstats->rx_over_errors;
local_stats.rx_crc_errors += sstats->rx_crc_errors; stats->rx_crc_errors += sstats->rx_crc_errors;
local_stats.rx_frame_errors += sstats->rx_frame_errors; stats->rx_frame_errors += sstats->rx_frame_errors;
local_stats.rx_fifo_errors += sstats->rx_fifo_errors; stats->rx_fifo_errors += sstats->rx_fifo_errors;
local_stats.rx_missed_errors += sstats->rx_missed_errors; stats->rx_missed_errors += sstats->rx_missed_errors;
local_stats.tx_aborted_errors += sstats->tx_aborted_errors; stats->tx_aborted_errors += sstats->tx_aborted_errors;
local_stats.tx_carrier_errors += sstats->tx_carrier_errors; stats->tx_carrier_errors += sstats->tx_carrier_errors;
local_stats.tx_fifo_errors += sstats->tx_fifo_errors; stats->tx_fifo_errors += sstats->tx_fifo_errors;
local_stats.tx_heartbeat_errors += sstats->tx_heartbeat_errors; stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
local_stats.tx_window_errors += sstats->tx_window_errors; stats->tx_window_errors += sstats->tx_window_errors;
} }
memcpy(stats, &local_stats, sizeof(struct net_device_stats));
read_unlock_bh(&bond->lock); read_unlock_bh(&bond->lock);
return stats; return stats;
......
...@@ -55,7 +55,7 @@ struct ixgbe_stats { ...@@ -55,7 +55,7 @@ struct ixgbe_stats {
offsetof(struct ixgbe_adapter, m) offsetof(struct ixgbe_adapter, m)
#define IXGBE_NETDEV_STAT(m) NETDEV_STATS, \ #define IXGBE_NETDEV_STAT(m) NETDEV_STATS, \
sizeof(((struct net_device *)0)->m), \ sizeof(((struct net_device *)0)->m), \
offsetof(struct net_device, m) offsetof(struct net_device, m) - offsetof(struct net_device, stats)
static struct ixgbe_stats ixgbe_gstrings_stats[] = { static struct ixgbe_stats ixgbe_gstrings_stats[] = {
{"rx_packets", IXGBE_NETDEV_STAT(stats.rx_packets)}, {"rx_packets", IXGBE_NETDEV_STAT(stats.rx_packets)},
...@@ -998,16 +998,18 @@ static void ixgbe_get_ethtool_stats(struct net_device *netdev, ...@@ -998,16 +998,18 @@ static void ixgbe_get_ethtool_stats(struct net_device *netdev,
struct ixgbe_adapter *adapter = netdev_priv(netdev); struct ixgbe_adapter *adapter = netdev_priv(netdev);
u64 *queue_stat; u64 *queue_stat;
int stat_count = sizeof(struct ixgbe_queue_stats) / sizeof(u64); int stat_count = sizeof(struct ixgbe_queue_stats) / sizeof(u64);
struct rtnl_link_stats64 temp;
const struct rtnl_link_stats64 *net_stats;
int j, k; int j, k;
int i; int i;
char *p = NULL; char *p = NULL;
ixgbe_update_stats(adapter); ixgbe_update_stats(adapter);
dev_get_stats(netdev); net_stats = dev_get_stats(netdev, &temp);
for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) { for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) {
switch (ixgbe_gstrings_stats[i].type) { switch (ixgbe_gstrings_stats[i].type) {
case NETDEV_STATS: case NETDEV_STATS:
p = (char *) netdev + p = (char *) net_stats +
ixgbe_gstrings_stats[i].stat_offset; ixgbe_gstrings_stats[i].stat_offset;
break; break;
case IXGBE_STATS: case IXGBE_STATS:
......
...@@ -98,10 +98,10 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb, ...@@ -98,10 +98,10 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
return NETDEV_TX_OK; return NETDEV_TX_OK;
} }
static struct rtnl_link_stats64 *loopback_get_stats64(struct net_device *dev) static struct rtnl_link_stats64 *loopback_get_stats64(struct net_device *dev,
struct rtnl_link_stats64 *stats)
{ {
const struct pcpu_lstats __percpu *pcpu_lstats; const struct pcpu_lstats __percpu *pcpu_lstats;
struct rtnl_link_stats64 *stats = &dev->stats64;
u64 bytes = 0; u64 bytes = 0;
u64 packets = 0; u64 packets = 0;
u64 drops = 0; u64 drops = 0;
......
...@@ -431,12 +431,12 @@ static void macvlan_uninit(struct net_device *dev) ...@@ -431,12 +431,12 @@ static void macvlan_uninit(struct net_device *dev)
free_percpu(vlan->rx_stats); free_percpu(vlan->rx_stats);
} }
static struct rtnl_link_stats64 *macvlan_dev_get_stats64(struct net_device *dev) static struct rtnl_link_stats64 *macvlan_dev_get_stats64(struct net_device *dev,
struct rtnl_link_stats64 *stats)
{ {
struct rtnl_link_stats64 *stats = &dev->stats64;
struct macvlan_dev *vlan = netdev_priv(dev); struct macvlan_dev *vlan = netdev_priv(dev);
dev_txq_stats_fold(dev, &dev->stats); dev_txq_stats_fold(dev, (struct net_device_stats *)stats);
if (vlan->rx_stats) { if (vlan->rx_stats) {
struct macvlan_rx_stats *p, accum = {0}; struct macvlan_rx_stats *p, accum = {0};
......
...@@ -1533,11 +1533,10 @@ static int efx_net_stop(struct net_device *net_dev) ...@@ -1533,11 +1533,10 @@ static int efx_net_stop(struct net_device *net_dev)
} }
/* Context: process, dev_base_lock or RTNL held, non-blocking. */ /* Context: process, dev_base_lock or RTNL held, non-blocking. */
static struct rtnl_link_stats64 *efx_net_stats(struct net_device *net_dev) static struct rtnl_link_stats64 *efx_net_stats(struct net_device *net_dev, struct rtnl_link_stats64 *stats)
{ {
struct efx_nic *efx = netdev_priv(net_dev); struct efx_nic *efx = netdev_priv(net_dev);
struct efx_mac_stats *mac_stats = &efx->mac_stats; struct efx_mac_stats *mac_stats = &efx->mac_stats;
struct rtnl_link_stats64 *stats = &net_dev->stats64;
spin_lock_bh(&efx->stats_lock); spin_lock_bh(&efx->stats_lock);
efx->type->update_stats(efx); efx->type->update_stats(efx);
......
...@@ -469,12 +469,13 @@ static void efx_ethtool_get_stats(struct net_device *net_dev, ...@@ -469,12 +469,13 @@ static void efx_ethtool_get_stats(struct net_device *net_dev,
struct efx_mac_stats *mac_stats = &efx->mac_stats; struct efx_mac_stats *mac_stats = &efx->mac_stats;
struct efx_ethtool_stat *stat; struct efx_ethtool_stat *stat;
struct efx_channel *channel; struct efx_channel *channel;
struct rtnl_link_stats64 temp;
int i; int i;
EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS); EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
/* Update MAC and NIC statistics */ /* Update MAC and NIC statistics */
dev_get_stats(net_dev); dev_get_stats(net_dev, &temp);
/* Fill detailed statistics buffer */ /* Fill detailed statistics buffer */
for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) { for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
......
...@@ -355,12 +355,13 @@ static __inline__ int led_get_net_activity(void) ...@@ -355,12 +355,13 @@ static __inline__ int led_get_net_activity(void)
rcu_read_lock(); rcu_read_lock();
for_each_netdev_rcu(&init_net, dev) { for_each_netdev_rcu(&init_net, dev) {
const struct net_device_stats *stats; const struct net_device_stats *stats;
struct rtnl_link_stats64 temp;
struct in_device *in_dev = __in_dev_get_rcu(dev); struct in_device *in_dev = __in_dev_get_rcu(dev);
if (!in_dev || !in_dev->ifa_list) if (!in_dev || !in_dev->ifa_list)
continue; continue;
if (ipv4_is_loopback(in_dev->ifa_list->ifa_local)) if (ipv4_is_loopback(in_dev->ifa_list->ifa_local))
continue; continue;
stats = dev_get_stats(dev); stats = dev_get_stats(dev, &temp);
rx_total += stats->rx_packets; rx_total += stats->rx_packets;
tx_total += stats->tx_packets; tx_total += stats->tx_packets;
} }
......
...@@ -2653,6 +2653,7 @@ static void fcoe_get_lesb(struct fc_lport *lport, ...@@ -2653,6 +2653,7 @@ static void fcoe_get_lesb(struct fc_lport *lport,
u32 lfc, vlfc, mdac; u32 lfc, vlfc, mdac;
struct fcoe_dev_stats *devst; struct fcoe_dev_stats *devst;
struct fcoe_fc_els_lesb *lesb; struct fcoe_fc_els_lesb *lesb;
struct rtnl_link_stats64 temp;
struct net_device *netdev = fcoe_netdev(lport); struct net_device *netdev = fcoe_netdev(lport);
lfc = 0; lfc = 0;
...@@ -2669,7 +2670,7 @@ static void fcoe_get_lesb(struct fc_lport *lport, ...@@ -2669,7 +2670,7 @@ static void fcoe_get_lesb(struct fc_lport *lport,
lesb->lesb_link_fail = htonl(lfc); lesb->lesb_link_fail = htonl(lfc);
lesb->lesb_vlink_fail = htonl(vlfc); lesb->lesb_vlink_fail = htonl(vlfc);
lesb->lesb_miss_fka = htonl(mdac); lesb->lesb_miss_fka = htonl(mdac);
lesb->lesb_fcs_error = htonl(dev_get_stats(netdev)->rx_crc_errors); lesb->lesb_fcs_error = htonl(dev_get_stats(netdev, &temp)->rx_crc_errors);
} }
/** /**
......
...@@ -440,6 +440,7 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev, ...@@ -440,6 +440,7 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
struct batman_packet *batman_packet; struct batman_packet *batman_packet;
struct batman_if *batman_if; struct batman_if *batman_if;
struct net_device_stats *stats; struct net_device_stats *stats;
struct rtnl_link_stats64 temp;
int ret; int ret;
skb = skb_share_check(skb, GFP_ATOMIC); skb = skb_share_check(skb, GFP_ATOMIC);
...@@ -468,7 +469,7 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev, ...@@ -468,7 +469,7 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
if (batman_if->if_status != IF_ACTIVE) if (batman_if->if_status != IF_ACTIVE)
goto err_free; goto err_free;
stats = (struct net_device_stats *)dev_get_stats(skb->dev); stats = (struct net_device_stats *)dev_get_stats(skb->dev, &temp);
if (stats) { if (stats) {
stats->rx_packets++; stats->rx_packets++;
stats->rx_bytes += skb->len; stats->rx_bytes += skb->len;
......
...@@ -171,6 +171,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, ...@@ -171,6 +171,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
int i, count; int i, count;
rndis_query_cmplt_type *resp; rndis_query_cmplt_type *resp;
struct net_device *net; struct net_device *net;
struct rtnl_link_stats64 temp;
const struct rtnl_link_stats64 *stats; const struct rtnl_link_stats64 *stats;
if (!r) return -ENOMEM; if (!r) return -ENOMEM;
...@@ -194,7 +195,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, ...@@ -194,7 +195,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
resp->InformationBufferOffset = cpu_to_le32 (16); resp->InformationBufferOffset = cpu_to_le32 (16);
net = rndis_per_dev_params[configNr].dev; net = rndis_per_dev_params[configNr].dev;
stats = dev_get_stats(net); stats = dev_get_stats(net, &temp);
switch (OID) { switch (OID) {
......
...@@ -666,7 +666,8 @@ struct netdev_rx_queue { ...@@ -666,7 +666,8 @@ struct netdev_rx_queue {
* Callback uses when the transmitter has not made any progress * Callback uses when the transmitter has not made any progress
* for dev->watchdog ticks. * for dev->watchdog ticks.
* *
* struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev); * struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev
* struct rtnl_link_stats64 *storage);
* struct net_device_stats* (*ndo_get_stats)(struct net_device *dev); * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
* Called when a user wants to get the network device usage * Called when a user wants to get the network device usage
* statistics. Drivers must do one of the following: * statistics. Drivers must do one of the following:
...@@ -733,7 +734,8 @@ struct net_device_ops { ...@@ -733,7 +734,8 @@ struct net_device_ops {
struct neigh_parms *); struct neigh_parms *);
void (*ndo_tx_timeout) (struct net_device *dev); void (*ndo_tx_timeout) (struct net_device *dev);
struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev); struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
struct rtnl_link_stats64 *storage);
struct net_device_stats* (*ndo_get_stats)(struct net_device *dev); struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
void (*ndo_vlan_rx_register)(struct net_device *dev, void (*ndo_vlan_rx_register)(struct net_device *dev,
...@@ -2139,8 +2141,10 @@ extern void netdev_features_change(struct net_device *dev); ...@@ -2139,8 +2141,10 @@ extern void netdev_features_change(struct net_device *dev);
/* Load a device via the kmod */ /* Load a device via the kmod */
extern void dev_load(struct net *net, const char *name); extern void dev_load(struct net *net, const char *name);
extern void dev_mcast_init(void); extern void dev_mcast_init(void);
extern const struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev); extern const struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
extern void dev_txq_stats_fold(const struct net_device *dev, struct net_device_stats *stats); struct rtnl_link_stats64 *storage);
extern void dev_txq_stats_fold(const struct net_device *dev,
struct net_device_stats *stats);
extern int netdev_max_backlog; extern int netdev_max_backlog;
extern int netdev_tstamp_prequeue; extern int netdev_tstamp_prequeue;
......
...@@ -803,11 +803,9 @@ static u32 vlan_ethtool_get_flags(struct net_device *dev) ...@@ -803,11 +803,9 @@ static u32 vlan_ethtool_get_flags(struct net_device *dev)
return dev_ethtool_get_flags(vlan->real_dev); return dev_ethtool_get_flags(vlan->real_dev);
} }
static struct rtnl_link_stats64 *vlan_dev_get_stats64(struct net_device *dev) static struct rtnl_link_stats64 *vlan_dev_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
{ {
struct rtnl_link_stats64 *stats = &dev->stats64; dev_txq_stats_fold(dev, (struct net_device_stats *)stats);
dev_txq_stats_fold(dev, &dev->stats);
if (vlan_dev_info(dev)->vlan_rx_stats) { if (vlan_dev_info(dev)->vlan_rx_stats) {
struct vlan_rx_stats *p, accum = {0}; struct vlan_rx_stats *p, accum = {0};
......
...@@ -278,6 +278,7 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset) ...@@ -278,6 +278,7 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset)
{ {
struct net_device *vlandev = (struct net_device *) seq->private; struct net_device *vlandev = (struct net_device *) seq->private;
const struct vlan_dev_info *dev_info = vlan_dev_info(vlandev); const struct vlan_dev_info *dev_info = vlan_dev_info(vlandev);
struct rtnl_link_stats64 temp;
const struct rtnl_link_stats64 *stats; const struct rtnl_link_stats64 *stats;
static const char fmt[] = "%30s %12lu\n"; static const char fmt[] = "%30s %12lu\n";
static const char fmt64[] = "%30s %12llu\n"; static const char fmt64[] = "%30s %12llu\n";
...@@ -286,7 +287,7 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset) ...@@ -286,7 +287,7 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset)
if (!is_vlan_dev(vlandev)) if (!is_vlan_dev(vlandev))
return 0; return 0;
stats = dev_get_stats(vlandev); stats = dev_get_stats(vlandev, &temp);
seq_printf(seq, seq_printf(seq,
"%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n", "%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n",
vlandev->name, dev_info->vlan_id, vlandev->name, dev_info->vlan_id,
......
...@@ -98,10 +98,10 @@ static int br_dev_stop(struct net_device *dev) ...@@ -98,10 +98,10 @@ static int br_dev_stop(struct net_device *dev)
return 0; return 0;
} }
static struct rtnl_link_stats64 *br_get_stats64(struct net_device *dev) static struct rtnl_link_stats64 *br_get_stats64(struct net_device *dev,
struct rtnl_link_stats64 *stats)
{ {
struct net_bridge *br = netdev_priv(dev); struct net_bridge *br = netdev_priv(dev);
struct rtnl_link_stats64 *stats = &dev->stats64;
struct br_cpu_netstats tmp, sum = { 0 }; struct br_cpu_netstats tmp, sum = { 0 };
unsigned int cpu; unsigned int cpu;
......
...@@ -3703,7 +3703,8 @@ void dev_seq_stop(struct seq_file *seq, void *v) ...@@ -3703,7 +3703,8 @@ void dev_seq_stop(struct seq_file *seq, void *v)
static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev) static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
{ {
const struct rtnl_link_stats64 *stats = dev_get_stats(dev); struct rtnl_link_stats64 temp;
const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu " seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
"%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n", "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
...@@ -5281,23 +5282,29 @@ EXPORT_SYMBOL(dev_txq_stats_fold); ...@@ -5281,23 +5282,29 @@ EXPORT_SYMBOL(dev_txq_stats_fold);
/** /**
* dev_get_stats - get network device statistics * dev_get_stats - get network device statistics
* @dev: device to get statistics from * @dev: device to get statistics from
* @storage: place to store stats
* *
* Get network statistics from device. The device driver may provide * Get network statistics from device. The device driver may provide
* its own method by setting dev->netdev_ops->get_stats64 or * its own method by setting dev->netdev_ops->get_stats64 or
* dev->netdev_ops->get_stats; otherwise the internal statistics * dev->netdev_ops->get_stats; otherwise the internal statistics
* structure is used. * structure is used.
*/ */
const struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev) const struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
struct rtnl_link_stats64 *storage)
{ {
const struct net_device_ops *ops = dev->netdev_ops; const struct net_device_ops *ops = dev->netdev_ops;
if (ops->ndo_get_stats64) if (ops->ndo_get_stats64) {
return ops->ndo_get_stats64(dev); memset(storage, 0, sizeof(*storage));
if (ops->ndo_get_stats) return ops->ndo_get_stats64(dev, storage);
return (struct rtnl_link_stats64 *)ops->ndo_get_stats(dev); }
if (ops->ndo_get_stats) {
dev_txq_stats_fold(dev, &dev->stats); memcpy(storage, ops->ndo_get_stats(dev), sizeof(*storage));
return &dev->stats64; return storage;
}
memcpy(storage, &dev->stats, sizeof(*storage));
dev_txq_stats_fold(dev, (struct net_device_stats *)storage);
return storage;
} }
EXPORT_SYMBOL(dev_get_stats); EXPORT_SYMBOL(dev_get_stats);
......
...@@ -330,7 +330,9 @@ static ssize_t netstat_show(const struct device *d, ...@@ -330,7 +330,9 @@ static ssize_t netstat_show(const struct device *d,
read_lock(&dev_base_lock); read_lock(&dev_base_lock);
if (dev_isalive(dev)) { if (dev_isalive(dev)) {
const struct rtnl_link_stats64 *stats = dev_get_stats(dev); struct rtnl_link_stats64 temp;
const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *) stats) + offset)); ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *) stats) + offset));
} }
read_unlock(&dev_base_lock); read_unlock(&dev_base_lock);
......
...@@ -791,6 +791,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, ...@@ -791,6 +791,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
{ {
struct ifinfomsg *ifm; struct ifinfomsg *ifm;
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
struct rtnl_link_stats64 temp;
const struct rtnl_link_stats64 *stats; const struct rtnl_link_stats64 *stats;
struct nlattr *attr; struct nlattr *attr;
...@@ -847,7 +848,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, ...@@ -847,7 +848,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
if (attr == NULL) if (attr == NULL)
goto nla_put_failure; goto nla_put_failure;
stats = dev_get_stats(dev); stats = dev_get_stats(dev, &temp);
copy_rtnl_link_stats(nla_data(attr), stats); copy_rtnl_link_stats(nla_data(attr), stats);
attr = nla_reserve(skb, IFLA_STATS64, attr = nla_reserve(skb, IFLA_STATS64,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment