netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jpirko@redhat.com>
To: netdev@vger.kernel.org
Cc: fubar@us.ibm.com, bonding-devel@lists.sourceforge.net,
	davem@davemloft.net, shemminger@linux-foundation.org
Subject: [net-next-2.6 PATCH] bonding: refuse to change bond type if it's used
Date: Mon, 8 Mar 2010 18:54:06 +0100	[thread overview]
Message-ID: <20100308175406.GA2834@psychotron.lab.eng.brq.redhat.com> (raw)

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)

             reply	other threads:[~2010-03-08 17:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-08 17:54 Jiri Pirko [this message]
2010-03-08 18:24 ` [net-next-2.6 PATCH] bonding: refuse to change bond type if it's used Stephen Hemminger
2010-03-08 20:16   ` David Miller
2010-03-08 21:35     ` Jiri Pirko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100308175406.GA2834@psychotron.lab.eng.brq.redhat.com \
    --to=jpirko@redhat.com \
    --cc=bonding-devel@lists.sourceforge.net \
    --cc=davem@davemloft.net \
    --cc=fubar@us.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).