diff mbox

[net-next-2.6] bonding: refuse to change bond type if it's used

Message ID 20100308175406.GA2834@psychotron.lab.eng.brq.redhat.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Jiri Pirko March 8, 2010, 5:54 p.m. UTC
It's not desirable to be able to change the type of net_device in bond device if
it's in use by bridge, or vlan, or so. At the moment, there is possible for
example to have INFINIBAND bond type in bridge (by adding bond with eth type to
a bridge first and then enslave INFINIBAND device).

This patch adds netdev_is_independent() function to check if device is not
"enslaved" and use this function to do the check before type change is performed.

From now on, the type change is allowed only for those bond devices not used by
any other net dev.

Signed-off-by: Jiri Pirko <jpirko@redhat.com>

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Stephen Hemminger March 8, 2010, 6:24 p.m. UTC | #1
On Mon, 8 Mar 2010 18:54:06 +0100
Jiri Pirko <jpirko@redhat.com> wrote:

> It's not desirable to be able to change the type of net_device in bond device if
> it's in use by bridge, or vlan, or so. At the moment, there is possible for
> example to have INFINIBAND bond type in bridge (by adding bond with eth type to
> a bridge first and then enslave INFINIBAND device).

Rather than building lots of back pointer dependencies, why not
have another netdevice notifier that allows other subsystems to
see the type change and reject it if they care? That way the code
would be more modular and expandable.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller March 8, 2010, 8:16 p.m. UTC | #2
From: Stephen Hemminger <shemminger@linux-foundation.org>
Date: Mon, 8 Mar 2010 10:24:48 -0800

> On Mon, 8 Mar 2010 18:54:06 +0100
> Jiri Pirko <jpirko@redhat.com> wrote:
> 
>> It's not desirable to be able to change the type of net_device in bond device if
>> it's in use by bridge, or vlan, or so. At the moment, there is possible for
>> example to have INFINIBAND bond type in bridge (by adding bond with eth type to
>> a bridge first and then enslave INFINIBAND device).
> 
> Rather than building lots of back pointer dependencies, why not
> have another netdevice notifier that allows other subsystems to
> see the type change and reject it if they care? That way the code
> would be more modular and expandable.

Agreed.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jiri Pirko March 8, 2010, 9:35 p.m. UTC | #3
Mon, Mar 08, 2010 at 09:16:32PM CET, davem@davemloft.net wrote:
>From: Stephen Hemminger <shemminger@linux-foundation.org>
>Date: Mon, 8 Mar 2010 10:24:48 -0800
>
>> On Mon, 8 Mar 2010 18:54:06 +0100
>> Jiri Pirko <jpirko@redhat.com> wrote:
>> 
>>> It's not desirable to be able to change the type of net_device in bond device if
>>> it's in use by bridge, or vlan, or so. At the moment, there is possible for
>>> example to have INFINIBAND bond type in bridge (by adding bond with eth type to
>>> a bridge first and then enslave INFINIBAND device).
>> 
>> Rather than building lots of back pointer dependencies, why not
>> have another netdevice notifier that allows other subsystems to
>> see the type change and reject it if they care? That way the code
>> would be more modular and expandable.
>
>Agreed.

Fair enough, I will rework this.

Thanks a lot guys for looking at this.

Jirka
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 430c022..4e64af1 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1476,6 +1476,15 @@  int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 	 */
 	if (bond->slave_cnt == 0) {
 		if (bond_dev->type != slave_dev->type) {
+			/* check if device is not used by bridge, vlan, etc */
+			if (!netdev_is_independent(bond_dev)) {
+				pr_debug("%s: can't change device type from "
+					 "%d to %d, device is busy\n",
+					 bond_dev->name,
+					 bond_dev->type, slave_dev->type);
+				res = -EBUSY;
+				goto err_undo_flags;
+			}
 			pr_debug("%s: change device type from %d to %d\n",
 				 bond_dev->name,
 				 bond_dev->type, slave_dev->type);
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index c79a88b..0c90a57 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -984,6 +984,12 @@  struct net_device {
 
 #define	NETDEV_ALIGN		32
 
+static inline int netdev_is_independent(const struct net_device *dev)
+{
+	return dev->master == NULL && dev->br_port == NULL &&
+	       dev->macvlan_port == NULL && dev->garp_port == NULL;
+}
+
 static inline
 struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
 					 unsigned int index)