netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net-next-2.6 PATCH] bonding: refuse to change bond type if it's used
@ 2010-03-08 17:54 Jiri Pirko
  2010-03-08 18:24 ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Jiri Pirko @ 2010-03-08 17:54 UTC (permalink / raw)
  To: netdev; +Cc: fubar, bonding-devel, davem, shemminger

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>

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)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [net-next-2.6 PATCH] bonding: refuse to change bond type if it's used
  2010-03-08 17:54 [net-next-2.6 PATCH] bonding: refuse to change bond type if it's used Jiri Pirko
@ 2010-03-08 18:24 ` Stephen Hemminger
  2010-03-08 20:16   ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2010-03-08 18:24 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, fubar, bonding-devel, davem

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [net-next-2.6 PATCH] bonding: refuse to change bond type if it's used
  2010-03-08 18:24 ` Stephen Hemminger
@ 2010-03-08 20:16   ` David Miller
  2010-03-08 21:35     ` Jiri Pirko
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2010-03-08 20:16 UTC (permalink / raw)
  To: shemminger; +Cc: jpirko, netdev, fubar, bonding-devel

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [net-next-2.6 PATCH] bonding: refuse to change bond type if it's used
  2010-03-08 20:16   ` David Miller
@ 2010-03-08 21:35     ` Jiri Pirko
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Pirko @ 2010-03-08 21:35 UTC (permalink / raw)
  To: David Miller; +Cc: shemminger, netdev, fubar, bonding-devel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-03-08 21:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-08 17:54 [net-next-2.6 PATCH] bonding: refuse to change bond type if it's used Jiri Pirko
2010-03-08 18:24 ` Stephen Hemminger
2010-03-08 20:16   ` David Miller
2010-03-08 21:35     ` Jiri Pirko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).