Skip to contentSkip to conversation

bonding: refuse to change bond type if it's used V3

PATCH In review Jiri Pirko 4 participants 10 messages Mar 10, 2010 – Mar 19, 2010

Subsystems (5)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

cover bonding: refuse to change bond type if it's used V3

v2->v3:
-changed defines name to NETDEV_[PRE/POST]_TYPE_CHANGE -added bits for vlan and macvlan

Reworked version of patch/patchset. This time I use netdevice notifier as Stephen suggested. Changed the name of the original ones (NETDEV_BONDING_*TYPE) to be more general and reused them.

Jirka

author
#1 lore raw

PATCH 1/3 net: rename notifier defines for netdev type change

Since generally there could be more netdevices changing type other than bonding, making this event type name "bonding-unrelated"

---
 drivers/net/bonding/bond_main.c |    6 ++++--
 include/linux/notifier.h        |    4 ++--
 net/ipv4/devinet.c              |    4 ++--
 net/ipv6/addrconf.c             |   16 ++++++++--------
 4 files changed, 16 insertions(+), 14 deletions(-)
drivers/net/bonding/bond_main.c +4 -2
index 430c022..7eeb187 100644
@@ -1480,14 +1480,16 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 				 bond_dev->name,
 				 bond_dev->type, slave_dev->type);
 
-			netdev_bonding_change(bond_dev, NETDEV_BONDING_OLDTYPE);
+			netdev_bonding_change(bond_dev,
+					      NETDEV_PRE_TYPE_CHANGE);
 
 			if (slave_dev->type != ARPHRD_ETHER)
 				bond_setup_by_slave(bond_dev, slave_dev);
 			else
 				ether_setup(bond_dev);
 
-			netdev_bonding_change(bond_dev, NETDEV_BONDING_NEWTYPE);
+			netdev_bonding_change(bond_dev,
+					      NETDEV_POST_TYPE_CHANGE);
 		}
 	} else if (bond_dev->type != slave_dev->type) {
 		pr_err("%s ether type (%d) is different from other slaves (%d), can not enslave it.\n",
include/linux/notifier.h +2 -2
index fee6c2f..f3635fc 100644
@@ -199,8 +199,8 @@ static inline int notifier_to_errno(int ret)
 #define NETDEV_FEAT_CHANGE	0x000B
 #define NETDEV_BONDING_FAILOVER 0x000C
 #define NETDEV_PRE_UP		0x000D
-#define NETDEV_BONDING_OLDTYPE  0x000E
-#define NETDEV_BONDING_NEWTYPE  0x000F
+#define NETDEV_PRE_TYPE_CHANGE	0x000E
+#define NETDEV_POST_TYPE_CHANGE	0x000F
 #define NETDEV_POST_INIT	0x0010
 #define NETDEV_UNREGISTER_BATCH 0x0011
 
net/ipv4/devinet.c +2 -2
index 51ca946..c75320e 100644
@@ -1095,10 +1095,10 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
 	case NETDEV_DOWN:
 		ip_mc_down(in_dev);
 		break;
-	case NETDEV_BONDING_OLDTYPE:
+	case NETDEV_PRE_TYPE_CHANGE:
 		ip_mc_unmap(in_dev);
 		break;
-	case NETDEV_BONDING_NEWTYPE:
+	case NETDEV_POST_TYPE_CHANGE:
 		ip_mc_remap(in_dev);
 		break;
 	case NETDEV_CHANGEMTU:
net/ipv6/addrconf.c +8 -8
index 88fd8c5..bf5349b 100644
@@ -137,8 +137,8 @@ static DEFINE_SPINLOCK(addrconf_verify_lock);
 static void addrconf_join_anycast(struct inet6_ifaddr *ifp);
 static void addrconf_leave_anycast(struct inet6_ifaddr *ifp);
 
-static void addrconf_bonding_change(struct net_device *dev,
-				    unsigned long event);
+static void addrconf_type_change(struct net_device *dev,
+				 unsigned long event);
 static int addrconf_ifdown(struct net_device *dev, int how);
 
 static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags);
@@ -2582,9 +2582,9 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
 				return notifier_from_errno(err);
 		}
 		break;
-	case NETDEV_BONDING_OLDTYPE:
-	case NETDEV_BONDING_NEWTYPE:
-		addrconf_bonding_change(dev, event);
+	case NETDEV_PRE_TYPE_CHANGE:
+	case NETDEV_POST_TYPE_CHANGE:
+		addrconf_type_change(dev, event);
 		break;
 	}
 
@@ -2599,16 +2599,16 @@ static struct notifier_block ipv6_dev_notf = {
 	.priority = 0
 };
 
-static void addrconf_bonding_change(struct net_device *dev, unsigned long event)
+static void addrconf_type_change(struct net_device *dev, unsigned long event)
 {
 	struct inet6_dev *idev;
 	ASSERT_RTNL();
 
 	idev = __in6_dev_get(dev);
 
-	if (event == NETDEV_BONDING_NEWTYPE)
+	if (event == NETDEV_POST_TYPE_CHANGE)
 		ipv6_mc_remap(idev);
-	else if (event == NETDEV_BONDING_OLDTYPE)
+	else if (event == NETDEV_PRE_TYPE_CHANGE)
 		ipv6_mc_unmap(idev);
 }
 
Signature · 1 line
1.6.6.1
author
#2 lore raw

PATCH 2/3 bonding: check return value of nofitier when changing type

In reply to Jiri Pirko

This patch adds the possibility to refuse the bonding type change for other subsystems (such as for example bridge, vlan, etc.)

---
 drivers/net/bonding/bond_main.c |   11 +++++++++--
 include/linux/netdevice.h       |    2 +-
 net/core/dev.c                  |    4 ++--
 3 files changed, 12 insertions(+), 5 deletions(-)
drivers/net/bonding/bond_main.c +9 -2
index 7eeb187..cbe9e35 100644
@@ -1480,8 +1480,15 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 				 bond_dev->name,
 				 bond_dev->type, slave_dev->type);
 
-			netdev_bonding_change(bond_dev,
-					      NETDEV_PRE_TYPE_CHANGE);
+			res = netdev_bonding_change(bond_dev,
+						    NETDEV_PRE_TYPE_CHANGE);
+			res = notifier_to_errno(res);
+			if (res) {
+				pr_err("%s: refused to change device type\n",
+				       bond_dev->name);
+				res = -EBUSY;
+				goto err_undo_flags;
+			}
 
 			if (slave_dev->type != ARPHRD_ETHER)
 				bond_setup_by_slave(bond_dev, slave_dev);
include/linux/netdevice.h +1 -1
index c79a88b..8cf1d50 100644
@@ -1975,7 +1975,7 @@ extern void		__dev_addr_unsync(struct dev_addr_list **to, int *to_count, struct
 extern int		dev_set_promiscuity(struct net_device *dev, int inc);
 extern int		dev_set_allmulti(struct net_device *dev, int inc);
 extern void		netdev_state_change(struct net_device *dev);
-extern void		netdev_bonding_change(struct net_device *dev,
+extern int		netdev_bonding_change(struct net_device *dev,
 					      unsigned long event);
 extern void		netdev_features_change(struct net_device *dev);
 /* Load a device via the kmod */
net/core/dev.c +2 -2
index bcc490c..5de4a15 100644
@@ -1084,9 +1084,9 @@ void netdev_state_change(struct net_device *dev)
 }
 EXPORT_SYMBOL(netdev_state_change);
 
-void netdev_bonding_change(struct net_device *dev, unsigned long event)
+int netdev_bonding_change(struct net_device *dev, unsigned long event)
 {
-	call_netdevice_notifiers(event, dev);
+	return call_netdevice_notifiers(event, dev);
 }
 EXPORT_SYMBOL(netdev_bonding_change);
 
Signature · 1 line
1.6.6.1
#3 lore raw

Re: [Bonding-devel] [net-next-2.6 PATCH 2/3] bonding: check return value of nofitier when changing type

Quoted 6 lines · On Wed, 10 Mar 2010 21:29:35 +0100 Jiri Pirko <[email protected]> wrote:
net/core/dev.c +0 -0
index bcc490c..5de4a15 100644
@@ -1084,9 +1084,9 @@ void netdev_state_change(struct net_device *dev)
 }

net/core/dev.c void netdev_state_change(struct net_device *dev) · line 1092

Quoted 10 lines
net/core/dev.c +2 -2
 EXPORT_SYMBOL(netdev_state_change);
 
-void netdev_bonding_change(struct net_device *dev, unsigned long event)
+int netdev_bonding_change(struct net_device *dev, unsigned long event)
 {
-	call_netdevice_notifiers(event, dev);
+	return call_netdevice_notifiers(event, dev);
 }
 EXPORT_SYMBOL(netdev_bonding_change);
 

I don't think all this pre-post stuff needed. Since this is general (not just bonding) how about

int netdev_change_type(struct net_device *dev, int newtype)

{
	int ret, oldtype;

	if (dev->flags & IFF_UP)
		return -EBUSY;

	oldtype = dev->type;
	dev->type = newtype;
	ret = call_netdevice_notifier(NETDEV_CHANGETYPE, dev);
	ret = notifier_to_errno(ret);
	if (ret)
	     dev->type = oldtype;

	return ret;
}
author
#4 lore raw

Re: [Bonding-devel] [net-next-2.6 PATCH 2/3] bonding: check return value of nofitier when changing type

Quoted 11 lines · Wed, Mar 10, 2010 at 11:47:10PM CET, [email protected] wrote:
Quoted 8 lines · On Wed, 10 Mar 2010 21:29:35 +0100 Jiri Pirko <[email protected]> wrote:
net/core/dev.c +0 -0
index bcc490c..5de4a15 100644
@@ -1084,9 +1084,9 @@ void netdev_state_change(struct net_device *dev)
 }
 EXPORT_SYMBOL(netdev_state_change);
 
Quoted 11 lines

net/core/dev.c void netdev_state_change(struct net_device *dev) · line 1092

Quoted 8 lines
net/core/dev.c +2 -2
-void netdev_bonding_change(struct net_device *dev, unsigned long event)
+int netdev_bonding_change(struct net_device *dev, unsigned long event)
 {
-	call_netdevice_notifiers(event, dev);
+	return call_netdevice_notifiers(event, dev);
 }
 EXPORT_SYMBOL(netdev_bonding_change);
 

I don't think all this pre-post stuff needed. Since this is general (not just bonding) how about

Well actually I reused NETDEV_BONDING_OLDTYPE. This and NETDEV_BONDING_NEWTYPE is used in inetdev_event() and addrconf_notify(). These functions apparently need to be notified before and after the change.

Quoted 17 lines

int netdev_change_type(struct net_device *dev, int newtype)

{
	int ret, oldtype;

	if (dev->flags & IFF_UP)
		return -EBUSY;

	oldtype = dev->type;
	dev->type = newtype;
	ret = call_netdevice_notifier(NETDEV_CHANGETYPE, dev);
	ret = notifier_to_errno(ret);
	if (ret)
	     dev->type = oldtype;

	return ret;
}

I see you point here, but that would be another notifier event. Do you suggest to have 3 of them finally? NETDEV_BONDING_OLDTYPE, NETDEV_BONDING_NEWTYPE and NETDEV_CHANGETYPE. Looks a bit redundant to me...

Thanks.

Jirka

author
#5 lore raw

Re: [Bonding-devel] [net-next-2.6 PATCH 2/3] bonding: check return value of nofitier when changing type

Quoted 24 lines · Thu, Mar 11, 2010 at 08:59:09AM CET, [email protected] wrote:
Quoted 11 lines · Wed, Mar 10, 2010 at 11:47:10PM CET, [email protected] wrote:
Quoted 8 lines · On Wed, 10 Mar 2010 21:29:35 +0100 Jiri Pirko <[email protected]> wrote:
net/core/dev.c +0 -0
index bcc490c..5de4a15 100644
@@ -1084,9 +1084,9 @@ void netdev_state_change(struct net_device *dev)
 }
 EXPORT_SYMBOL(netdev_state_change);
 
Quoted 11 lines

net/core/dev.c void netdev_state_change(struct net_device *dev) · line 1092

Quoted 8 lines
net/core/dev.c +2 -2
-void netdev_bonding_change(struct net_device *dev, unsigned long event)
+int netdev_bonding_change(struct net_device *dev, unsigned long event)
 {
-	call_netdevice_notifiers(event, dev);
+	return call_netdevice_notifiers(event, dev);
 }
 EXPORT_SYMBOL(netdev_bonding_change);
 

I don't think all this pre-post stuff needed. Since this is general (not just bonding) how about

Quoted 14 lines

Well actually I reused NETDEV_BONDING_OLDTYPE. This and NETDEV_BONDING_NEWTYPE is used in inetdev_event() and addrconf_notify(). These functions apparently need to be notified before and after the change.

Quoted 10 lines

int netdev_change_type(struct net_device *dev, int newtype)

{
	int ret, oldtype;

	if (dev->flags & IFF_UP)
		return -EBUSY;

	oldtype = dev->type;
	dev->type = newtype;

Also, the type change is not only about dev->type. See for example ether_setup(). This function and it's puprose might be misleading...

Quoted 16 lines
Quoted 7 lines
	ret = call_netdevice_notifier(NETDEV_CHANGETYPE, dev);
	ret = notifier_to_errno(ret);
	if (ret)
	     dev->type = oldtype;

	return ret;
}

I see you point here, but that would be another notifier event. Do you suggest to have 3 of them finally? NETDEV_BONDING_OLDTYPE, NETDEV_BONDING_NEWTYPE and NETDEV_CHANGETYPE. Looks a bit redundant to me...

Thanks.

Jirka

author
#6 lore raw

PATCH 3/3 net: forbid underlaying devices to change its type

In reply to Jiri Pirko

It's not desired for underlaying devices to change type. At the time, there is for example possible to have bond with changed type from Ethernet to Infiniband as a port of a bridge. This patch fixes this.

---
 drivers/net/macvlan.c  |    3 +++
 net/8021q/vlan.c       |    4 ++++
 net/bridge/br_notify.c |    4 ++++
 3 files changed, 11 insertions(+), 0 deletions(-)
drivers/net/macvlan.c +3 -0
index 40faa36..445e73c 100644
@@ -748,6 +748,9 @@ static int macvlan_device_event(struct notifier_block *unused,
 		list_for_each_entry_safe(vlan, next, &port->vlans, list)
 			vlan->dev->rtnl_link_ops->dellink(vlan->dev, NULL);
 		break;
+	case NETDEV_PRE_TYPE_CHANGE:
+		/* Forbid underlaying device to change its type. */
+		return NOTIFY_BAD;
 	}
 	return NOTIFY_DONE;
 }
net/8021q/vlan.c +4 -0
index 4535122..c39a5f4 100644
@@ -530,6 +530,10 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
 		}
 		unregister_netdevice_many(&list);
 		break;
+
+	case NETDEV_PRE_TYPE_CHANGE:
+		/* Forbid underlaying device to change its type. */
+		return NOTIFY_BAD;
 	}
 
 out:
net/bridge/br_notify.c +4 -0
index 763a3ec..1413b72 100644
@@ -82,6 +82,10 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v
 	case NETDEV_UNREGISTER:
 		br_del_if(br, dev);
 		break;
+
+	case NETDEV_PRE_TYPE_CHANGE:
+		/* Forbid underlaying device to change its type. */
+		return NOTIFY_BAD;
 	}
 
 	/* Events that may cause spanning tree to refresh */
Signature · 1 line
1.6.6.1
#7 lore raw

Re: [net-next-2.6 PATCH 3/3] net: forbid underlaying devices to change its type

Quoted 3 lines · Jiri Pirko

It's not desired for underlaying devices to change type. At the time, there is for example possible to have bond with changed type from Ethernet to Infiniband as a port of a bridge. This patch fixes this.

Do the current initscripts / sysconfig packages do things such
that this restriction won't break things? I.e., do those packages have a dependency on being able to change the type after setting up, e.g., a VLAN over bonding on Infiniband?

This isn't to suggest that this change should be rejected if the
above is true; rather, I'm curious as to how this came up as a problem, and whether initscripts / sysconfig require concurrent changes.

In any event, it all seems reasonable to me, so, at least for
the bonding bits:

	-J
Quoted 58 lines

---

drivers/net/macvlan.c  |    3 +++
net/8021q/vlan.c       |    4 ++++
net/bridge/br_notify.c |    4 ++++
3 files changed, 11 insertions(+), 0 deletions(-)
drivers/net/macvlan.c +3 -0
index 40faa36..445e73c 100644
@@ -748,6 +748,9 @@ static int macvlan_device_event(struct notifier_block *unused,
 		list_for_each_entry_safe(vlan, next, &port->vlans, list)
 			vlan->dev->rtnl_link_ops->dellink(vlan->dev, NULL);
 		break;
+	case NETDEV_PRE_TYPE_CHANGE:
+		/* Forbid underlaying device to change its type. */
+		return NOTIFY_BAD;
 	}
 	return NOTIFY_DONE;
 }
net/8021q/vlan.c +4 -0
index 4535122..c39a5f4 100644
@@ -530,6 +530,10 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
 		}
 		unregister_netdevice_many(&list);
 		break;
+
+	case NETDEV_PRE_TYPE_CHANGE:
+		/* Forbid underlaying device to change its type. */
+		return NOTIFY_BAD;
 	}
 

out:

net/bridge/br_notify.c +4 -0
index 763a3ec..1413b72 100644
@@ -82,6 +82,10 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v
 	case NETDEV_UNREGISTER:
 		br_del_if(br, dev);
 		break;
+
+	case NETDEV_PRE_TYPE_CHANGE:
+		/* Forbid underlaying device to change its type. */
+		return NOTIFY_BAD;
 	}
 
 	/* Events that may cause spanning tree to refresh */
Signature · 6 lines
1.6.6.1

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#8 lore raw

Re: [net-next-2.6 PATCH 3/3] net: forbid underlaying devices to change its type

Quoted 6 lines · Wed, Mar 10, 2010 at 10:04:10PM CET, [email protected] wrote:
Quoted 3 lines · Jiri Pirko

It's not desired for underlaying devices to change type. At the time, there is for example possible to have bond with changed type from Ethernet to Infiniband as a port of a bridge. This patch fixes this.

Quoted 8 lines

Do the current initscripts / sysconfig packages do things such
that this restriction won't break things? I.e., do those packages have a dependency on being able to change the type after setting up, e.g., a VLAN over bonding on Infiniband?

This isn't to suggest that this change should be rejected if the
above is true; rather, I'm curious as to how this came up as a problem, and whether initscripts / sysconfig require concurrent changes.

I'm not aware initscripts / sysconfig require type change. In fanc this wouldn't make sense. This popped up when I was converting mc_lists, I thought if this is possible, tried with infiniband and it was. Therefore I decided to fix this.

Jirka

Quoted 67 lines

In any event, it all seems reasonable to me, so, at least for
the bonding bits:

	-J
Quoted 58 lines

---

drivers/net/macvlan.c  |    3 +++
net/8021q/vlan.c       |    4 ++++
net/bridge/br_notify.c |    4 ++++
3 files changed, 11 insertions(+), 0 deletions(-)
drivers/net/macvlan.c +3 -0
index 40faa36..445e73c 100644
@@ -748,6 +748,9 @@ static int macvlan_device_event(struct notifier_block *unused,
 		list_for_each_entry_safe(vlan, next, &port->vlans, list)
 			vlan->dev->rtnl_link_ops->dellink(vlan->dev, NULL);
 		break;
+	case NETDEV_PRE_TYPE_CHANGE:
+		/* Forbid underlaying device to change its type. */
+		return NOTIFY_BAD;
 	}
 	return NOTIFY_DONE;
 }
net/8021q/vlan.c +4 -0
index 4535122..c39a5f4 100644
@@ -530,6 +530,10 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
 		}
 		unregister_netdevice_many(&list);
 		break;
+
+	case NETDEV_PRE_TYPE_CHANGE:
+		/* Forbid underlaying device to change its type. */
+		return NOTIFY_BAD;
 	}
 

out:

net/bridge/br_notify.c +4 -0
index 763a3ec..1413b72 100644
@@ -82,6 +82,10 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v
 	case NETDEV_UNREGISTER:
 		br_del_if(br, dev);
 		break;
+
+	case NETDEV_PRE_TYPE_CHANGE:
+		/* Forbid underlaying device to change its type. */
+		return NOTIFY_BAD;
 	}
 
 	/* Events that may cause spanning tree to refresh */
Signature · 6 lines
1.6.6.1

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#9 lore raw
In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>
Date: Wed, 10 Mar 2010 21:28:04 +0100

Quoted 7 lines

v2->v3:

(quoted diff) +0 -2
-changed defines name to NETDEV_[PRE/POST]_TYPE_CHANGE
-added bits for vlan and macvlan

Reworked version of patch/patchset. This time I use netdevice notifier as Stephen suggested. Changed the name of the original ones (NETDEV_BONDING_*TYPE) to be more general and reused them.

This looks really nice, applied thanks Jiri.

I know a lot of people who would have noticed this and just said "not my problem" and gone on to work on something else. Instead you stopped and fixed it, and this is very much appreciated.

Thanks again!