net: introduce ethernet teaming device
Subsystems (4)
PATCH v5 1/1 net: introduce ethernet teaming device
This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.
Userspace library called libteam with couple of demo apps is available here:
https://github.com/jpirko/libteam
Note it's still in its dipers atm.
team<->libteam use generic netlink for communication. That and rtnl suppose to be the only way to configure team device, no sysfs etc.
Python binding basis for libteam was recently introduced (some need still need to be done on it though). Daemon providing arpmon/miimon active-backup functionality will be introduced shortly. All what's necessary is already implemented in kernel team driver.
v4->v5:
- team_change_mtu() uses team->lock while travesing though port list
- mac address changes are moved completely to jurisdiction of userspace daemon. This way the daemon can do FOM1, FOM2 and possibly other weird things with mac addresses. Only round-robin mode sets up all ports to bond's address then enslaved.
- Extended Kconfig text
v3->v4:
- remove redundant synchronize_rcu from __team_change_mode()
- revert "set and clear of mode_ops happens per pointer, not per byte"
- extend comment of function __team_change_mode()
v2->v3:
- team_change_mtu() uses rcu version of list traversal to unwind
- set and clear of mode_ops happens per pointer, not per byte
- port hashlist changed to be embedded into team structure
- error branch in team_port_enter() does cleanup now
- fixed rtln->rtnl
v1->v2:
- modes are made as modules. Makes team more modular and extendable.
- several commenters' nitpicks found on v1 were fixed
- several other bugs were fixed.
- note I ignored Eric's comment about roundrobin port selector as Eric's way may be easily implemented as another mode (mode "random") in future.
--- Documentation/networking/team.txt | 2 + MAINTAINERS | 7 + drivers/net/Kconfig | 2 + drivers/net/Makefile | 1 + drivers/net/team/Kconfig | 43 + drivers/net/team/Makefile | 7 + drivers/net/team/team.c | 1555 +++++++++++++++++++++++++++++ drivers/net/team/team_mode_activebackup.c | 137 +++ drivers/net/team/team_mode_roundrobin.c | 107 ++ include/linux/Kbuild | 1 + include/linux/if.h | 1 + include/linux/if_team.h | 230 +++++ 12 files changed, 2093 insertions(+), 0 deletions(-) create mode 100644 Documentation/networking/team.txt create mode 100644 drivers/net/team/Kconfig create mode 100644 drivers/net/team/Makefile create mode 100644 drivers/net/team/team.c create mode 100644 drivers/net/team/team_mode_activebackup.c create mode 100644 drivers/net/team/team_mode_roundrobin.c create mode 100644 include/linux/if_team.h
Documentation/networking/team.txt new file +2 -0
@@ -0,0 +1,2 @@ +Team devices are driven from userspace via libteam library which is here: + https://github.com/jpirko/libteam
MAINTAINERS +7 -0
@@ -6372,6 +6372,13 @@ W: http://tcp-lp-mod.sourceforge.net/ S: Maintained F: net/ipv4/tcp_lp.c +TEAM DRIVER +M: Jiri Pirko <[email protected]> +L: [email protected] +S: Supported +F: drivers/net/team/ +F: include/linux/if_team.h + TEGRA SUPPORT M: Colin Cross <[email protected]> M: Erik Gilling <[email protected]>
drivers/net/Kconfig +2 -0
@@ -125,6 +125,8 @@ config IFB 'ifb1' etc. Look at the iproute2 documentation directory for usage etc +source "drivers/net/team/Kconfig" + config MACVLAN tristate "MAC-VLAN support (EXPERIMENTAL)" depends on EXPERIMENTAL
drivers/net/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-$(CONFIG_NET) += Space.o loopback.o obj-$(CONFIG_NETCONSOLE) += netconsole.o obj-$(CONFIG_PHYLIB) += phy/ obj-$(CONFIG_RIONET) += rionet.o +obj-$(CONFIG_NET_TEAM) += team/ obj-$(CONFIG_TUN) += tun.o obj-$(CONFIG_VETH) += veth.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
drivers/net/team/Kconfig new file +43 -0
43 lines not on this page · raw message
drivers/net/team/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for the network team driver +# + +obj-$(CONFIG_NET_TEAM) += team.o +obj-$(CONFIG_NET_TEAM_MODE_ROUNDROBIN) += team_mode_roundrobin.o +obj-$(CONFIG_NET_TEAM_MODE_ACTIVEBACKUP) += team_mode_activebackup.o
drivers/net/team/team.c new file +1555 -0
1,555 lines not on this page · raw message
drivers/net/team/team_mode_activebackup.c new file +137 -0
137 lines not on this page · raw message
drivers/net/team/team_mode_roundrobin.c new file +107 -0
107 lines not on this page · raw message
include/linux/Kbuild +1 -0
@@ -185,6 +185,7 @@ header-y += if_pppol2tp.h header-y += if_pppox.h header-y += if_slip.h header-y += if_strip.h +header-y += if_team.h header-y += if_tr.h header-y += if_tun.h header-y += if_tunnel.h
include/linux/if.h +1 -0
@@ -79,6 +79,7 @@#define IFF_TX_SKB_SHARING 0x10000/* The interface supports sharing * skbs on transmit */ #define IFF_UNICAST_FLT 0x20000/* Supports unicast filtering */ +#define IFF_TEAM_PORT 0x40000/* device used as team port */ #define IF_GET_IFACE 0x0001/* for querying only */ #define IF_GET_PROTO 0x0002
include/linux/if_team.h new file +230 -0
230 lines not on this page · raw message
Signature · 1 line
1.7.6
Quoted 19 lines · Jiri Pirko
This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.
Userspace library called libteam with couple of demo apps is available here:
https://github.com/jpirko/libteam
Note it's still in its dipers atm.team<->libteam use generic netlink for communication. That and rtnl suppose to be the only way to configure team device, no sysfs etc.
Python binding basis for libteam was recently introduced (some need still need to be done on it though). Daemon providing arpmon/miimon active-backup functionality will be introduced shortly. All what's necessary is already implemented in kernel team driver.
Signed-off-by Jiri Pirko <[email protected]>
Quoted 9 lines
v4->v5:
-team_change_mtu()usesteam->lockwhile travesing though port list
- mac address changes are moved completely to jurisdiction of userspace daemon. This way the daemon can do FOM1, FOM2 and possibly other weird things with mac addresses. Only round-robin mode sets up all ports to bond's address then enslaved.
- ExtendedKconfigtext
Following is not called under rcu, but rtnl or team spinlock held.
Therefore, team_get_port_by_index_rcu() is not the right thing.
+static void __reconstruct_port_hlist(struct team *team, int rm_index) +{
+ int i;
+ struct team_port *port;
+
+ for (i = rm_index + 1; i < team->port_count; i++) {
+ port = team_get_port_by_index_rcu(team, i); + hlist_del_rcu(&port->hlist); + port->index--; + hlist_add_head_rcu(&port->hlist,
+ team_port_index_hash(team, port->index));
+ }
+}
+
In fact, I claim most of your rcu_read_lock() in management side are bogus and obfuscate code.
RCU is an exact science, not a commodity.
When RCU is used, rcu_read_lock()/rcu_read_unlock() are used by readers, not managers :
They should use a spin/mutex(rtnl usually in network land) and normal reads, no need for rcu_something
Only writes must take care of concurrent readers (aka rcu_assign_pointer())
For example:
team_nl_fill_port_list_get_changed() should not use
list_for_each_entry_rcu(port, &team->port_list, list) {
but a regular
list_for_each_entry(port, &team->port_list, list) {team_nl_team_get() should not play with RCU either.
It can use __dev_get_by_index() instead of dev_get_by_index_rcu()
Comment in front of team_nl_team_get() is bogus as well :
/*
* Netlink cmd functions should be locked by following two functions.
* To ensure team_uninit would not be called in between, hold rcu_read_lock
* all the time.
*/
How can holding rcu_read_lock() can prevent another cpu doing whatever he wants ?
It seems you believe rcu_read_lock() is a read_lock(), but it isnt.
Using right API is essential to get appropriate LOCKDEP semantic and code maintainability.
Quoted 31 lines · Tue, Oct 25, 2011 at 03:27:35PM CEST, [email protected] wrote:
Quoted 19 lines · Jiri Pirko
This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.
Userspace library called libteam with couple of demo apps is available here:
https://github.com/jpirko/libteam
Note it's still in its dipers atm.team<->libteam use generic netlink for communication. That and rtnl suppose to be the only way to configure team device, no sysfs etc.
Python binding basis for libteam was recently introduced (some need still need to be done on it though). Daemon providing arpmon/miimon active-backup functionality will be introduced shortly. All what's necessary is already implemented in kernel team driver.
Signed-off-by Jiri Pirko <[email protected]>Quoted 9 lines
v4->v5:
-team_change_mtu()usesteam->lockwhile travesing though port list
- mac address changes are moved completely to jurisdiction of userspace daemon. This way the daemon can do FOM1, FOM2 and possibly other weird things with mac addresses. Only round-robin mode sets up all ports to bond's address then enslaved.
- ExtendedKconfigtext
Quoted 3 lines
Following is not called under rcu, but rtnl or team spinlock held.
Therefore,
team_get_port_by_index_rcu()is not the right thing.
Yes, this is bug, I missed this.
Quoted 27 lines
drivers/net/team/team.c new file +14
-0+static void __reconstruct_port_hlist (struct team *team,int rm_index) +{ +int i; +struct team_port *port; + +for (i = rm_index +1 ; i < team->port_count; i++) { + port =team_get_port_by_index_rcu (team, i); +hlist_del_rcu (&port->hlist); + port->index--; +hlist_add_head_rcu (&port->hlist, +team_port_index_hash (team, port->index)); + } +} +In fact, I claim most of your
rcu_read_lock()in management side are bogus and obfuscate code.RCU is an exact science, not a commodity.
When RCU is used, rcu_read_lock()/rcu_read_unlock() are used by readers, not managers :
They should use a spin/mutex(rtnl usually in network land) and normal reads, no need for
rcu_something
Quoted 8 lines
Only writes must take care of concurrent readers (aka
rcu_assign_pointer())For example:
team_nl_fill_port_list_get_changed()should not uselist_for_each_entry_rcu(port, &team->port_list, list) { but a regular list_for_each_entry(port, &team->port_list, list) {
Nod. This I missed as well.
Quoted 4 lines
team_nl_team_get()should not play with RCU either.
It can use__dev_get_by_index()instead ofdev_get_by_index_rcu()
Not true. RTNL is not held here.
Quoted 9 lines
Comment in front of
team_nl_team_get()is bogus as well :/*
* Netlink cmd functions should be locked by following two functions.
* To ensureteam_uninitwould not be called in between, holdrcu_read_lock
* all the time.
*/
Quoted 3 lines
How can holding
rcu_read_lock()can prevent another cpu doing whatever he wants ?It seems you believe
rcu_read_lock()is aread_lock(), but it isnt.
I'm aware. But in this particular case, holding rcu_read_lock effectively does the thing. Because team_uninit is called from rollback_registered_many() after synchronize_net is called. The thing is that holding rcu_read_lock ensures that team->dev does not disappear until team_nl_team_put() is called.
Quoted 6 lines
Using right API is essential to get appropriate LOCKDEP semantic and code maintainability.