Re: [RFC PATCH 2/4] net: Add lower dev list helpers
From: Veaceslav Falico <hidden>
Date: 2013-09-14 12:29:48
On Wed, Sep 11, 2013 at 11:46:49AM -0700, John Fastabend wrote:
This patch adds helpers to traverse the lower dev lists, these helpers match the upper dev list implementation. VSI implementers may use these to track a list of connected netdevs. This is easier then having drivers do their own accounting.
Just as a note (as I have quite no idea how ixgbe works) - you are aware that the upper/lower lists currently include *all* upper/lower devices, and not only the first-connected ones? I've seen that you usually verify it, however not always, just a heads-up - sorry if misread. I'm also currently trying to get the new patchset included - which would split the first-tier connected devices from all the 'other' (as in - lower of a lower and upper of an upper) devices, so that way, I think, it would be easier/faster for you to use it. It also has a ->private field, easily accessible, which you could have used instead of/in conjunction with/for struct ixgbe_vsi_adapter. [PATCH v2 net-next 00/27] bonding: use neighbours instead of own lists Here's the patchset. Hope that helps.
quoted hunk ↗ jump to hunk
Signed-off-by: John Fastabend <redacted> --- include/linux/netdevice.h | 8 ++++++++ net/core/dev.c | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+)diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 041b42a..4d24b38 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h@@ -2813,6 +2813,8 @@ extern int bpf_jit_enable;extern bool netdev_has_upper_dev(struct net_device *dev, struct net_device *upper_dev); extern bool netdev_has_any_upper_dev(struct net_device *dev); +extern struct net_device *netdev_lower_get_next_dev_rcu(struct net_device *dev, + struct list_head **iter); extern struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev, struct list_head **iter);@@ -2823,6 +2825,12 @@ extern struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,upper; \ upper = netdev_upper_get_next_dev_rcu(dev, &(iter))) +#define netdev_for_each_lower_dev_rcu(dev, lower, iter) \ + for (iter = &(dev)->lower_dev_list, \ + lower = netdev_lower_get_next_dev_rcu(dev, &(iter)); \ + lower; \ + lower = netdev_lower_get_next_dev_rcu(dev, &(iter))) + extern struct net_device *netdev_master_upper_dev_get(struct net_device *dev); extern struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev); extern int netdev_upper_dev_link(struct net_device *dev,diff --git a/net/core/dev.c b/net/core/dev.c index 5c713f2..65ed610 100644 --- a/net/core/dev.c +++ b/net/core/dev.c@@ -4468,6 +4468,31 @@ struct net_device *netdev_master_upper_dev_get(struct net_device *dev)} EXPORT_SYMBOL(netdev_master_upper_dev_get); +/* netdev_lower_get_next_dev_rcu - Get the next dev from lower list + * @dev: device + * @iter: list_head ** of the current position + * + * Gets the next device from the dev's lower list, starting from iter + * position. The caller must hold RTNL/RCU read lock. + */ +struct net_device *netdev_lower_get_next_dev_rcu(struct net_device *dev, + struct list_head **iter) +{ + struct netdev_adjacent *lower; + + WARN_ON_ONCE(!rcu_read_lock_held()); + + lower = list_entry_rcu((*iter)->next, struct netdev_adjacent, list); + + if (&lower->list == &dev->lower_dev_list) + return NULL; + + *iter = &lower->list; + + return lower->dev; +} +EXPORT_SYMBOL(netdev_lower_get_next_dev_rcu); + /* netdev_upper_get_next_dev_rcu - Get the next dev from upper list * @dev: device * @iter: list_head ** of the current position