[ovs-dev] [PATCH] datapath: Define net_device_ops->ndo_get_stats64() for internal_dev.
Pravin B Shelar
pshelar at nicira.com
Thu Nov 3 00:32:39 UTC 2011
Signed-off-by: Pravin Shelar <pshelar at nicira.com>
---
datapath/vport-internal_dev.c | 52 ++++++++++++++++++++++++++++------------
1 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/datapath/vport-internal_dev.c b/datapath/vport-internal_dev.c
index a468ac8..fa30161 100644
--- a/datapath/vport-internal_dev.c
+++ b/datapath/vport-internal_dev.c
@@ -36,31 +36,47 @@ static inline struct internal_dev *internal_dev_priv(struct net_device *netdev)
return netdev_priv(netdev);
}
+#define VPORT_STATS_TO_NETDEV_STAT(vport, stats) \
+ do { \
+ struct ovs_vport_stats vport_stats; \
+ vport_get_stats((vport), &vport_stats); \
+ \
+ /* The tx and rx stats need to be swapped because the \
+ * switch and host OS have opposite perspectives. */ \
+ (stats)->rx_packets = vport_stats.tx_packets; \
+ (stats)->tx_packets = vport_stats.rx_packets; \
+ (stats)->rx_bytes = vport_stats.tx_bytes; \
+ (stats)->tx_bytes = vport_stats.rx_bytes; \
+ (stats)->rx_errors = vport_stats.tx_errors; \
+ (stats)->tx_errors = vport_stats.rx_errors; \
+ (stats)->rx_dropped = vport_stats.tx_dropped; \
+ (stats)->tx_dropped = vport_stats.rx_dropped; \
+ } while(0)
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
/* This function is only called by the kernel network layer.*/
+static struct rtnl_link_stats64 *internal_dev_get_stats64(struct net_device *netdev,
+ struct rtnl_link_stats64 *stats64)
+{
+ struct vport *vport = internal_dev_get_vport(netdev);
+
+ if (vport)
+ VPORT_STATS_TO_NETDEV_STAT(vport, stats64);
+
+ return stats64;
+}
+#else
static struct net_device_stats *internal_dev_sys_stats(struct net_device *netdev)
{
struct vport *vport = internal_dev_get_vport(netdev);
struct net_device_stats *stats = &internal_dev_priv(netdev)->stats;
- if (vport) {
- struct ovs_vport_stats vport_stats;
-
- vport_get_stats(vport, &vport_stats);
-
- /* The tx and rx stats need to be swapped because the switch
- * and host OS have opposite perspectives. */
- stats->rx_packets = vport_stats.tx_packets;
- stats->tx_packets = vport_stats.rx_packets;
- stats->rx_bytes = vport_stats.tx_bytes;
- stats->tx_bytes = vport_stats.rx_bytes;
- stats->rx_errors = vport_stats.tx_errors;
- stats->tx_errors = vport_stats.rx_errors;
- stats->rx_dropped = vport_stats.tx_dropped;
- stats->tx_dropped = vport_stats.rx_dropped;
- }
+ if (vport)
+ VPORT_STATS_TO_NETDEV_STAT(vport, stats);
return stats;
}
+#endif
static int internal_dev_mac_addr(struct net_device *dev, void *p)
{
@@ -151,7 +167,11 @@ static const struct net_device_ops internal_dev_netdev_ops = {
.ndo_set_mac_address = internal_dev_mac_addr,
.ndo_do_ioctl = internal_dev_do_ioctl,
.ndo_change_mtu = internal_dev_change_mtu,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
+ .ndo_get_stats64 = internal_dev_get_stats64,
+#else
.ndo_get_stats = internal_dev_sys_stats,
+#endif
};
#endif
--
1.7.1
More information about the dev
mailing list