From b20a27a05241257320f33629069f9a351e88c92e Mon Sep 17 00:00:00 2001 From: "Luis R. Rodriguez" Date: Wed, 25 Jul 2012 09:44:23 -0700 Subject: [PATCH] compat: backport ndo_get_stats64 addition The net_device_ops data structure gets a new ndo_get_stats64 callback through two patches. For newer kernels that actually do have the net_device_ops data structure we have no other option but to #ifdef that code. For older kernels that do not have the net_device_ops we stuff the new callback into this compat module / header files and make netdev_attach_ops() ignore it. And again -- for newer kernels just #ifdef that stuff out. This is an example of a complex data structure series of changes through different sets of collateral evolutions. If we can figure out a way to not requre #ifdef changes for *newer* kernels that *do* have the net_device_ops it would be great. One way to likely accomplish this is to redefine the net_device_ops data structure through a define for all kernels and make it out own and in our own netdev_attach_ops() routine handle the differences. If this would be possible (needs to be proven but I think Ozan has already proven this) I'm hopeful we'll eventually be able to replace net_device_ops() collateral evolutions with 0 lines required to be changed on upstream code! There are two patches that added ndo_get_stats64, fortunately both were implemented during the 2.6.36 deveopment cycle. mcgrof@tux ~/linux-next (git::master)$ git describe --contains be1f3c2c v2.6.36-rc1~571^2~600 mcgrof@tux ~/linux-next (git::master)$ git describe --contains 28172739 v2.6.36-rc1~571^2~334 commit be1f3c2c027cc5ad735df6a45a542ed1db7ec48b Author: Ben Hutchings Date: Tue Jun 8 07:19:54 2010 +0000 net: Enable 64-bit net device statistics on 32-bit architectures Use struct rtnl_link_stats64 as the statistics structure. On 32-bit architectures, insert 32 bits of padding after/before each field of struct net_device_stats to make its layout compatible with struct rtnl_link_stats64. Add an anonymous union in net_device; move stats into the union and add struct rtnl_link_stats64 stats64. Add net_device_ops::ndo_get_stats64, implementations of which will return a pointer to struct rtnl_link_stats64. Drivers that implement this operation must not update the structure asynchronously. Change dev_get_stats() to call ndo_get_stats64 if available, and to return a pointer to struct rtnl_link_stats64. Change callers of dev_get_stats() accordingly. Signed-off-by: Ben Hutchings Signed-off-by: David S. Miller commit 28172739f0a276eb8d6ca917b3974c2edb036da3 Author: Eric Dumazet Date: Wed Jul 7 14:58:56 2010 -0700 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: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Luis R. Rodriguez --- include/linux/compat-2.6.29.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/compat-2.6.29.h b/include/linux/compat-2.6.29.h index 48b62e8a3912..e65c22980cc5 100644 --- a/include/linux/compat-2.6.29.h +++ b/include/linux/compat-2.6.29.h @@ -184,6 +184,11 @@ struct net_device_ops { struct neigh_parms *); void (*ndo_tx_timeout) (struct net_device *dev); +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)) + struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev, + struct rtnl_link_stats64 *storage); +#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)) */ + struct net_device_stats* (*ndo_get_stats)(struct net_device *dev); void (*ndo_vlan_rx_register)(struct net_device *dev, -- 2.30.2