netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch net-next 0/7] bonding: introduce bonding options Netlink support
@ 2013-10-18 15:43 Jiri Pirko
  2013-10-18 15:43 ` [patch net-next 1/7] bonding: push Netlink bits into separate file Jiri Pirko
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: Jiri Pirko @ 2013-10-18 15:43 UTC (permalink / raw)
  To: netdev; +Cc: davem, fubar, vfalico, andy, stephen, vyasevic

This patchset basically allows "mode" and "active_slave" bonding options
to be propagated and set up via standart RT Netlink interface.

In future other options can be easily added as well.

Jiri Pirko (7):
  bonding: push Netlink bits into separate file
  bonding: move mode setting into separate function
  bonding: move active_slave setting into separate function
  bonding: remove bond_ioctl_change_active()
  bonding: move active_slave getting into separate function
  bonding: add Netlink support mode option
  bonding: add Netlink support active_slave option

 drivers/net/bonding/Makefile       |   2 +-
 drivers/net/bonding/bond_main.c    |  91 ++----------------------
 drivers/net/bonding/bond_netlink.c | 131 ++++++++++++++++++++++++++++++++++
 drivers/net/bonding/bond_options.c | 142 +++++++++++++++++++++++++++++++++++++
 drivers/net/bonding/bond_sysfs.c   | 127 ++++++++-------------------------
 drivers/net/bonding/bonding.h      |  19 ++++-
 include/uapi/linux/if_link.h       |  11 +++
 7 files changed, 337 insertions(+), 186 deletions(-)
 create mode 100644 drivers/net/bonding/bond_netlink.c
 create mode 100644 drivers/net/bonding/bond_options.c

-- 
1.8.3.1

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

* [patch net-next 1/7] bonding: push Netlink bits into separate file
  2013-10-18 15:43 [patch net-next 0/7] bonding: introduce bonding options Netlink support Jiri Pirko
@ 2013-10-18 15:43 ` Jiri Pirko
  2013-10-18 15:43 ` [patch net-next 2/7] bonding: move mode setting into separate function Jiri Pirko
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Jiri Pirko @ 2013-10-18 15:43 UTC (permalink / raw)
  To: netdev; +Cc: davem, fubar, vfalico, andy, stephen, vyasevic

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 drivers/net/bonding/Makefile       |  2 +-
 drivers/net/bonding/bond_main.c    | 32 ++++------------------
 drivers/net/bonding/bond_netlink.c | 54 ++++++++++++++++++++++++++++++++++++++
 drivers/net/bonding/bonding.h      |  7 +++++
 4 files changed, 67 insertions(+), 28 deletions(-)
 create mode 100644 drivers/net/bonding/bond_netlink.c

diff --git a/drivers/net/bonding/Makefile b/drivers/net/bonding/Makefile
index 4c21bf6..09e8b2c 100644
--- a/drivers/net/bonding/Makefile
+++ b/drivers/net/bonding/Makefile
@@ -4,7 +4,7 @@
 
 obj-$(CONFIG_BONDING) += bonding.o
 
-bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_debugfs.o
+bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_debugfs.o bond_netlink.o
 
 proc-$(CONFIG_PROC_FS) += bond_procfs.o
 bonding-objs += $(proc-y)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index dfb4f6d..a113e42 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -3951,7 +3951,7 @@ static void bond_destructor(struct net_device *bond_dev)
 	free_netdev(bond_dev);
 }
 
-static void bond_setup(struct net_device *bond_dev)
+void bond_setup(struct net_device *bond_dev)
 {
 	struct bonding *bond = netdev_priv(bond_dev);
 
@@ -4451,32 +4451,11 @@ static int bond_init(struct net_device *bond_dev)
 	return 0;
 }
 
-static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
-{
-	if (tb[IFLA_ADDRESS]) {
-		if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
-			return -EINVAL;
-		if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
-			return -EADDRNOTAVAIL;
-	}
-	return 0;
-}
-
-static unsigned int bond_get_num_tx_queues(void)
+unsigned int bond_get_num_tx_queues(void)
 {
 	return tx_queues;
 }
 
-static struct rtnl_link_ops bond_link_ops __read_mostly = {
-	.kind			= "bond",
-	.priv_size		= sizeof(struct bonding),
-	.setup			= bond_setup,
-	.validate		= bond_validate,
-	.get_num_tx_queues	= bond_get_num_tx_queues,
-	.get_num_rx_queues	= bond_get_num_tx_queues, /* Use the same number
-							     as for TX queues */
-};
-
 /* Create a new bond based on the specified name and bonding parameters.
  * If name is NULL, obtain a suitable "bond%d" name for us.
  * Caller must NOT hold rtnl_lock; we need to release it here before we
@@ -4563,7 +4542,7 @@ static int __init bonding_init(void)
 	if (res)
 		goto out;
 
-	res = rtnl_link_register(&bond_link_ops);
+	res = bond_netlink_init();
 	if (res)
 		goto err_link;
 
@@ -4579,7 +4558,7 @@ static int __init bonding_init(void)
 out:
 	return res;
 err:
-	rtnl_link_unregister(&bond_link_ops);
+	bond_netlink_fini();
 err_link:
 	unregister_pernet_subsys(&bond_net_ops);
 	goto out;
@@ -4592,7 +4571,7 @@ static void __exit bonding_exit(void)
 
 	bond_destroy_debugfs();
 
-	rtnl_link_unregister(&bond_link_ops);
+	bond_netlink_fini();
 	unregister_pernet_subsys(&bond_net_ops);
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
@@ -4609,4 +4588,3 @@ MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
 MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION);
 MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others");
-MODULE_ALIAS_RTNL_LINK("bond");
diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
new file mode 100644
index 0000000..3e5c5f8
--- /dev/null
+++ b/drivers/net/bonding/bond_netlink.c
@@ -0,0 +1,54 @@
+/*
+ * drivers/net/bond/bond_netlink.c - Netlink interface for bonding
+ * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/if_link.h>
+#include <linux/if_ether.h>
+#include <net/netlink.h>
+#include <net/rtnetlink.h>
+#include "bonding.h"
+
+static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
+{
+	if (tb[IFLA_ADDRESS]) {
+		if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
+			return -EINVAL;
+		if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
+			return -EADDRNOTAVAIL;
+	}
+	return 0;
+}
+
+struct rtnl_link_ops bond_link_ops __read_mostly = {
+	.kind			= "bond",
+	.priv_size		= sizeof(struct bonding),
+	.setup			= bond_setup,
+	.validate		= bond_validate,
+	.get_num_tx_queues	= bond_get_num_tx_queues,
+	.get_num_rx_queues	= bond_get_num_tx_queues, /* Use the same number
+							     as for TX queues */
+};
+
+int __init bond_netlink_init(void)
+{
+	return rtnl_link_register(&bond_link_ops);
+}
+
+void __exit bond_netlink_fini(void)
+{
+	rtnl_link_unregister(&bond_link_ops);
+}
+
+MODULE_ALIAS_RTNL_LINK("bond");
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index bb5c731..a2a353b 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -418,6 +418,10 @@ void bond_debug_register(struct bonding *bond);
 void bond_debug_unregister(struct bonding *bond);
 void bond_debug_reregister(struct bonding *bond);
 const char *bond_mode_name(int mode);
+void bond_setup(struct net_device *bond_dev);
+unsigned int bond_get_num_tx_queues(void);
+int bond_netlink_init(void);
+void bond_netlink_fini(void);
 
 struct bond_net {
 	struct net *		net;	/* Associated network namespace */
@@ -505,4 +509,7 @@ extern const struct bond_parm_tbl fail_over_mac_tbl[];
 extern const struct bond_parm_tbl pri_reselect_tbl[];
 extern struct bond_parm_tbl ad_select_tbl[];
 
+/* exported from bond_netlink.c */
+extern struct rtnl_link_ops bond_link_ops;
+
 #endif /* _LINUX_BONDING_H */
-- 
1.8.3.1

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

* [patch net-next 2/7] bonding: move mode setting into separate function
  2013-10-18 15:43 [patch net-next 0/7] bonding: introduce bonding options Netlink support Jiri Pirko
  2013-10-18 15:43 ` [patch net-next 1/7] bonding: push Netlink bits into separate file Jiri Pirko
@ 2013-10-18 15:43 ` Jiri Pirko
  2013-10-18 15:43 ` [patch net-next 3/7] bonding: move active_slave " Jiri Pirko
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Jiri Pirko @ 2013-10-18 15:43 UTC (permalink / raw)
  To: netdev; +Cc: davem, fubar, vfalico, andy, stephen, vyasevic

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 drivers/net/bonding/Makefile       |  2 +-
 drivers/net/bonding/bond_options.c | 55 ++++++++++++++++++++++++++++++++++++++
 drivers/net/bonding/bond_sysfs.c   | 45 ++++++++-----------------------
 drivers/net/bonding/bonding.h      |  9 +++++--
 4 files changed, 74 insertions(+), 37 deletions(-)
 create mode 100644 drivers/net/bonding/bond_options.c

diff --git a/drivers/net/bonding/Makefile b/drivers/net/bonding/Makefile
index 09e8b2c..5a5d720 100644
--- a/drivers/net/bonding/Makefile
+++ b/drivers/net/bonding/Makefile
@@ -4,7 +4,7 @@
 
 obj-$(CONFIG_BONDING) += bonding.o
 
-bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_debugfs.o bond_netlink.o
+bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_debugfs.o bond_netlink.o bond_options.o
 
 proc-$(CONFIG_PROC_FS) += bond_procfs.o
 bonding-objs += $(proc-y)
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
new file mode 100644
index 0000000..294b766
--- /dev/null
+++ b/drivers/net/bonding/bond_options.c
@@ -0,0 +1,55 @@
+/*
+ * drivers/net/bond/bond_options.c - bonding options
+ * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/errno.h>
+#include <linux/if.h>
+#include "bonding.h"
+
+static bool bond_mode_is_valid(int mode)
+{
+	int i;
+
+	for (i = 0; bond_mode_tbl[i].modename; i++);
+
+	return mode >= 0 && mode < i;
+}
+
+int bond_option_mode_set(struct bonding *bond, int mode)
+{
+	if (!bond_mode_is_valid(mode)) {
+		pr_err("invalid mode value %d.\n", mode);
+		return -EINVAL;
+	}
+
+	if (bond->dev->flags & IFF_UP) {
+		pr_err("%s: unable to update mode because interface is up.\n",
+		       bond->dev->name);
+		return -EPERM;
+	}
+
+	if (bond_has_slaves(bond)) {
+		pr_err("%s: unable to update mode because bond has slaves.\n",
+			bond->dev->name);
+		return -EPERM;
+	}
+
+	if (BOND_MODE_IS_LB(mode) && bond->params.arp_interval) {
+		pr_err("%s: %s mode is incompatible with arp monitoring.\n",
+		       bond->dev->name, bond_mode_tbl[mode].modename);
+		return -EINVAL;
+	}
+
+	/* don't cache arp_validate between modes */
+	bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
+	bond->params.mode = mode;
+	return 0;
+}
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 03bed0c..c234cec 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -283,49 +283,26 @@ static ssize_t bonding_store_mode(struct device *d,
 				  struct device_attribute *attr,
 				  const char *buf, size_t count)
 {
-	int new_value, ret = count;
+	int new_value, ret;
 	struct bonding *bond = to_bond(d);
 
-	if (!rtnl_trylock())
-		return restart_syscall();
-
-	if (bond->dev->flags & IFF_UP) {
-		pr_err("unable to update mode of %s because interface is up.\n",
-		       bond->dev->name);
-		ret = -EPERM;
-		goto out;
-	}
-
-	if (bond_has_slaves(bond)) {
-		pr_err("unable to update mode of %s because it has slaves.\n",
-			bond->dev->name);
-		ret = -EPERM;
-		goto out;
-	}
-
 	new_value = bond_parse_parm(buf, bond_mode_tbl);
 	if (new_value < 0)  {
 		pr_err("%s: Ignoring invalid mode value %.*s.\n",
 		       bond->dev->name, (int)strlen(buf) - 1, buf);
-		ret = -EINVAL;
-		goto out;
+		return -EINVAL;
 	}
-	if ((new_value == BOND_MODE_ALB ||
-	     new_value == BOND_MODE_TLB) &&
-	    bond->params.arp_interval) {
-		pr_err("%s: %s mode is incompatible with arp monitoring.\n",
-		       bond->dev->name, bond_mode_tbl[new_value].modename);
-		ret = -EINVAL;
-		goto out;
+	if (!rtnl_trylock())
+		return restart_syscall();
+
+	ret = bond_option_mode_set(bond, new_value);
+	if (!ret) {
+		pr_info("%s: setting mode to %s (%d).\n",
+			bond->dev->name, bond_mode_tbl[new_value].modename,
+			new_value);
+		ret = count;
 	}
 
-	/* don't cache arp_validate between modes */
-	bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
-	bond->params.mode = new_value;
-	pr_info("%s: setting mode to %s (%d).\n",
-		bond->dev->name, bond_mode_tbl[new_value].modename,
-		new_value);
-out:
 	rtnl_unlock();
 	return ret;
 }
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index a2a353b..7446849 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -58,6 +58,11 @@
 #define TX_QUEUE_OVERRIDE(mode)				\
 			(((mode) == BOND_MODE_ACTIVEBACKUP) ||	\
 			 ((mode) == BOND_MODE_ROUNDROBIN))
+
+#define BOND_MODE_IS_LB(mode)			\
+		(((mode) == BOND_MODE_TLB) ||	\
+		 ((mode) == BOND_MODE_ALB))
+
 /*
  * Less bad way to call ioctl from within the kernel; this needs to be
  * done some other way to get the call out of interrupt context.
@@ -259,8 +264,7 @@ static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
 
 static inline bool bond_is_lb(const struct bonding *bond)
 {
-	return (bond->params.mode == BOND_MODE_TLB ||
-		bond->params.mode == BOND_MODE_ALB);
+	return BOND_MODE_IS_LB(bond->params.mode);
 }
 
 static inline void bond_set_active_slave(struct slave *slave)
@@ -422,6 +426,7 @@ void bond_setup(struct net_device *bond_dev);
 unsigned int bond_get_num_tx_queues(void);
 int bond_netlink_init(void);
 void bond_netlink_fini(void);
+int bond_option_mode_set(struct bonding *bond, int mode);
 
 struct bond_net {
 	struct net *		net;	/* Associated network namespace */
-- 
1.8.3.1

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

* [patch net-next 3/7] bonding: move active_slave setting into separate function
  2013-10-18 15:43 [patch net-next 0/7] bonding: introduce bonding options Netlink support Jiri Pirko
  2013-10-18 15:43 ` [patch net-next 1/7] bonding: push Netlink bits into separate file Jiri Pirko
  2013-10-18 15:43 ` [patch net-next 2/7] bonding: move mode setting into separate function Jiri Pirko
@ 2013-10-18 15:43 ` Jiri Pirko
  2013-10-18 15:43 ` [patch net-next 4/7] bonding: remove bond_ioctl_change_active() Jiri Pirko
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Jiri Pirko @ 2013-10-18 15:43 UTC (permalink / raw)
  To: netdev; +Cc: davem, fubar, vfalico, andy, stephen, vyasevic

Do a bit of refactoring on the way.

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 drivers/net/bonding/bond_options.c | 69 +++++++++++++++++++++++++++++++++++
 drivers/net/bonding/bond_sysfs.c   | 74 +++++++-------------------------------
 drivers/net/bonding/bonding.h      |  1 +
 3 files changed, 83 insertions(+), 61 deletions(-)

diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 294b766..09af5d1 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -12,6 +12,9 @@
 
 #include <linux/errno.h>
 #include <linux/if.h>
+#include <linux/netdevice.h>
+#include <linux/rwlock.h>
+#include <linux/rcupdate.h>
 #include "bonding.h"
 
 static bool bond_mode_is_valid(int mode)
@@ -53,3 +56,69 @@ int bond_option_mode_set(struct bonding *bond, int mode)
 	bond->params.mode = mode;
 	return 0;
 }
+
+int bond_option_active_slave_set(struct bonding *bond,
+				 struct net_device *slave_dev)
+{
+	int ret = 0;
+
+	if (slave_dev) {
+		if (!netif_is_bond_slave(slave_dev)) {
+			pr_err("Device %s is not bonding slave.\n",
+			       slave_dev->name);
+			return -EINVAL;
+		}
+
+		if (bond->dev != netdev_master_upper_dev_get(slave_dev)) {
+			pr_err("%s: Device %s is not our slave.\n",
+			       bond->dev->name, slave_dev->name);
+			return -EINVAL;
+		}
+	}
+
+	if (!USES_PRIMARY(bond->params.mode)) {
+		pr_err("%s: Unable to change active slave; %s is in mode %d\n",
+		       bond->dev->name, bond->dev->name, bond->params.mode);
+		return -EINVAL;
+	}
+
+	block_netpoll_tx();
+	read_lock(&bond->lock);
+	write_lock_bh(&bond->curr_slave_lock);
+
+	/* check to see if we are clearing active */
+	if (!slave_dev) {
+		pr_info("%s: Clearing current active slave.\n",
+		bond->dev->name);
+		rcu_assign_pointer(bond->curr_active_slave, NULL);
+		bond_select_active_slave(bond);
+	} else {
+		struct slave *old_active = bond->curr_active_slave;
+		struct slave *new_active = bond_slave_get_rtnl(slave_dev);
+
+		BUG_ON(!new_active);
+
+		if (new_active == old_active) {
+			/* do nothing */
+			pr_info("%s: %s is already the current active slave.\n",
+				bond->dev->name, new_active->dev->name);
+		} else {
+			if (old_active && (new_active->link == BOND_LINK_UP) &&
+			    IS_UP(new_active->dev)) {
+				pr_info("%s: Setting %s as active slave.\n",
+					bond->dev->name, new_active->dev->name);
+				bond_change_active_slave(bond, new_active);
+			} else {
+				pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
+				       bond->dev->name, new_active->dev->name,
+				       new_active->dev->name);
+				ret = -EINVAL;
+			}
+		}
+	}
+
+	write_unlock_bh(&bond->curr_slave_lock);
+	read_unlock(&bond->lock);
+	unblock_netpoll_tx();
+	return ret;
+}
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index c234cec..abd2600 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -1235,81 +1235,33 @@ static ssize_t bonding_store_active_slave(struct device *d,
 					  struct device_attribute *attr,
 					  const char *buf, size_t count)
 {
-	struct slave *slave, *old_active, *new_active;
+	int ret;
 	struct bonding *bond = to_bond(d);
-	struct list_head *iter;
 	char ifname[IFNAMSIZ];
+	struct net_device *dev;
 
 	if (!rtnl_trylock())
 		return restart_syscall();
 
-	old_active = new_active = NULL;
-	block_netpoll_tx();
-	read_lock(&bond->lock);
-	write_lock_bh(&bond->curr_slave_lock);
-
-	if (!USES_PRIMARY(bond->params.mode)) {
-		pr_info("%s: Unable to change active slave; %s is in mode %d\n",
-			bond->dev->name, bond->dev->name, bond->params.mode);
-		goto out;
-	}
-
 	sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
-
-	/* check to see if we are clearing active */
 	if (!strlen(ifname) || buf[0] == '\n') {
-		pr_info("%s: Clearing current active slave.\n",
-			bond->dev->name);
-		rcu_assign_pointer(bond->curr_active_slave, NULL);
-		bond_select_active_slave(bond);
-		goto out;
-	}
-
-	bond_for_each_slave(bond, slave, iter) {
-		if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
-			old_active = bond->curr_active_slave;
-			new_active = slave;
-			if (new_active == old_active) {
-				/* do nothing */
-				pr_info("%s: %s is already the current"
-					" active slave.\n",
-					bond->dev->name,
-					slave->dev->name);
-				goto out;
-			} else {
-				if ((new_active) &&
-				    (old_active) &&
-				    (new_active->link == BOND_LINK_UP) &&
-				    IS_UP(new_active->dev)) {
-					pr_info("%s: Setting %s as active"
-						" slave.\n",
-						bond->dev->name,
-						slave->dev->name);
-					bond_change_active_slave(bond,
-								 new_active);
-				} else {
-					pr_info("%s: Could not set %s as"
-						" active slave; either %s is"
-						" down or the link is down.\n",
-						bond->dev->name,
-						slave->dev->name,
-						slave->dev->name);
-				}
-				goto out;
-			}
+		dev = NULL;
+	} else {
+		dev = __dev_get_by_name(dev_net(bond->dev), ifname);
+		if (!dev) {
+			ret = -ENODEV;
+			goto out;
 		}
 	}
 
-	pr_info("%s: Unable to set %.*s as active slave.\n",
-		bond->dev->name, (int)strlen(buf) - 1, buf);
- out:
-	write_unlock_bh(&bond->curr_slave_lock);
-	read_unlock(&bond->lock);
-	unblock_netpoll_tx();
+	ret = bond_option_active_slave_set(bond, dev);
+	if (!ret)
+		ret = count;
 
+ out:
 	rtnl_unlock();
 
-	return count;
+	return ret;
 
 }
 static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 7446849..686759d 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -427,6 +427,7 @@ unsigned int bond_get_num_tx_queues(void);
 int bond_netlink_init(void);
 void bond_netlink_fini(void);
 int bond_option_mode_set(struct bonding *bond, int mode);
+int bond_option_active_slave_set(struct bonding *bond, struct net_device *slave_dev);
 
 struct bond_net {
 	struct net *		net;	/* Associated network namespace */
-- 
1.8.3.1

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

* [patch net-next 4/7] bonding: remove bond_ioctl_change_active()
  2013-10-18 15:43 [patch net-next 0/7] bonding: introduce bonding options Netlink support Jiri Pirko
                   ` (2 preceding siblings ...)
  2013-10-18 15:43 ` [patch net-next 3/7] bonding: move active_slave " Jiri Pirko
@ 2013-10-18 15:43 ` Jiri Pirko
  2013-10-18 15:43 ` [patch net-next 5/7] bonding: move active_slave getting into separate function Jiri Pirko
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Jiri Pirko @ 2013-10-18 15:43 UTC (permalink / raw)
  To: netdev; +Cc: davem, fubar, vfalico, andy, stephen, vyasevic

no longer needed since bond_option_active_slave_set() can be used
instead.

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 drivers/net/bonding/bond_main.c | 59 ++---------------------------------------
 1 file changed, 2 insertions(+), 57 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index a113e42..d90734f 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1910,61 +1910,6 @@ static int  bond_release_and_destroy(struct net_device *bond_dev,
 	return ret;
 }
 
-/*
- * This function changes the active slave to slave <slave_dev>.
- * It returns -EINVAL in the following cases.
- *  - <slave_dev> is not found in the list.
- *  - There is not active slave now.
- *  - <slave_dev> is already active.
- *  - The link state of <slave_dev> is not BOND_LINK_UP.
- *  - <slave_dev> is not running.
- * In these cases, this function does nothing.
- * In the other cases, current_slave pointer is changed and 0 is returned.
- */
-static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_device *slave_dev)
-{
-	struct bonding *bond = netdev_priv(bond_dev);
-	struct slave *old_active = NULL;
-	struct slave *new_active = NULL;
-	int res = 0;
-
-	if (!USES_PRIMARY(bond->params.mode))
-		return -EINVAL;
-
-	/* Verify that bond_dev is indeed the master of slave_dev */
-	if (!(slave_dev->flags & IFF_SLAVE) ||
-	    !netdev_has_upper_dev(slave_dev, bond_dev))
-		return -EINVAL;
-
-	read_lock(&bond->lock);
-
-	old_active = bond->curr_active_slave;
-	new_active = bond_get_slave_by_dev(bond, slave_dev);
-	/*
-	 * Changing to the current active: do nothing; return success.
-	 */
-	if (new_active && new_active == old_active) {
-		read_unlock(&bond->lock);
-		return 0;
-	}
-
-	if (new_active &&
-	    old_active &&
-	    new_active->link == BOND_LINK_UP &&
-	    IS_UP(new_active->dev)) {
-		block_netpoll_tx();
-		write_lock_bh(&bond->curr_slave_lock);
-		bond_change_active_slave(bond, new_active);
-		write_unlock_bh(&bond->curr_slave_lock);
-		unblock_netpoll_tx();
-	} else
-		res = -EINVAL;
-
-	read_unlock(&bond->lock);
-
-	return res;
-}
-
 static int bond_info_query(struct net_device *bond_dev, struct ifbond *info)
 {
 	struct bonding *bond = netdev_priv(bond_dev);
@@ -3257,6 +3202,7 @@ static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev,
 
 static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd)
 {
+	struct bonding *bond = netdev_priv(bond_dev);
 	struct net_device *slave_dev = NULL;
 	struct ifbond k_binfo;
 	struct ifbond __user *u_binfo = NULL;
@@ -3287,7 +3233,6 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
 
 
 		if (mii->reg_num == 1) {
-			struct bonding *bond = netdev_priv(bond_dev);
 			mii->val_out = 0;
 			read_lock(&bond->lock);
 			read_lock(&bond->curr_slave_lock);
@@ -3359,7 +3304,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
 			break;
 		case BOND_CHANGE_ACTIVE_OLD:
 		case SIOCBONDCHANGEACTIVE:
-			res = bond_ioctl_change_active(bond_dev, slave_dev);
+			res = bond_option_active_slave_set(bond, slave_dev);
 			break;
 		default:
 			res = -EOPNOTSUPP;
-- 
1.8.3.1

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

* [patch net-next 5/7] bonding: move active_slave getting into separate function
  2013-10-18 15:43 [patch net-next 0/7] bonding: introduce bonding options Netlink support Jiri Pirko
                   ` (3 preceding siblings ...)
  2013-10-18 15:43 ` [patch net-next 4/7] bonding: remove bond_ioctl_change_active() Jiri Pirko
@ 2013-10-18 15:43 ` Jiri Pirko
  2013-10-18 15:43 ` [patch net-next 6/7] bonding: add Netlink support mode option Jiri Pirko
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Jiri Pirko @ 2013-10-18 15:43 UTC (permalink / raw)
  To: netdev; +Cc: davem, fubar, vfalico, andy, stephen, vyasevic

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 drivers/net/bonding/bond_options.c | 18 ++++++++++++++++++
 drivers/net/bonding/bond_sysfs.c   |  8 ++++----
 drivers/net/bonding/bonding.h      |  2 ++
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 09af5d1..9a5223c 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -57,6 +57,24 @@ int bond_option_mode_set(struct bonding *bond, int mode)
 	return 0;
 }
 
+static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
+							 struct slave *slave)
+{
+	return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL;
+}
+
+struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
+{
+	struct slave *slave = rcu_dereference(bond->curr_active_slave);
+
+	return __bond_option_active_slave_get(bond, slave);
+}
+
+struct net_device *bond_option_active_slave_get(struct bonding *bond)
+{
+	return __bond_option_active_slave_get(bond, bond->curr_active_slave);
+}
+
 int bond_option_active_slave_set(struct bonding *bond,
 				 struct net_device *slave_dev)
 {
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index abd2600..47749c9 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -1219,13 +1219,13 @@ static ssize_t bonding_show_active_slave(struct device *d,
 					 char *buf)
 {
 	struct bonding *bond = to_bond(d);
-	struct slave *curr;
+	struct net_device *slave_dev;
 	int count = 0;
 
 	rcu_read_lock();
-	curr = rcu_dereference(bond->curr_active_slave);
-	if (USES_PRIMARY(bond->params.mode) && curr)
-		count = sprintf(buf, "%s\n", curr->dev->name);
+	slave_dev = bond_option_active_slave_get_rcu(bond);
+	if (slave_dev)
+		count = sprintf(buf, "%s\n", slave_dev->name);
 	rcu_read_unlock();
 
 	return count;
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 686759d..046a605 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -428,6 +428,8 @@ int bond_netlink_init(void);
 void bond_netlink_fini(void);
 int bond_option_mode_set(struct bonding *bond, int mode);
 int bond_option_active_slave_set(struct bonding *bond, struct net_device *slave_dev);
+struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
+struct net_device *bond_option_active_slave_get(struct bonding *bond);
 
 struct bond_net {
 	struct net *		net;	/* Associated network namespace */
-- 
1.8.3.1

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

* [patch net-next 6/7] bonding: add Netlink support mode option
  2013-10-18 15:43 [patch net-next 0/7] bonding: introduce bonding options Netlink support Jiri Pirko
                   ` (4 preceding siblings ...)
  2013-10-18 15:43 ` [patch net-next 5/7] bonding: move active_slave getting into separate function Jiri Pirko
@ 2013-10-18 15:43 ` Jiri Pirko
  2013-10-18 15:43 ` [patch net-next 7/7] bonding: add Netlink support active_slave option Jiri Pirko
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Jiri Pirko @ 2013-10-18 15:43 UTC (permalink / raw)
  To: netdev; +Cc: davem, fubar, vfalico, andy, stephen, vyasevic

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 drivers/net/bonding/bond_netlink.c | 56 ++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/if_link.h       | 10 +++++++
 2 files changed, 66 insertions(+)

diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index 3e5c5f8..a94f870 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -20,6 +20,10 @@
 #include <net/rtnetlink.h>
 #include "bonding.h"
 
+static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
+	[IFLA_BOND_MODE]		= { .type = NLA_U8 },
+};
+
 static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
 {
 	if (tb[IFLA_ADDRESS]) {
@@ -31,11 +35,63 @@ static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
 	return 0;
 }
 
+static int bond_changelink(struct net_device *bond_dev,
+			   struct nlattr *tb[], struct nlattr *data[])
+{
+	struct bonding *bond = netdev_priv(bond_dev);
+	int err;
+
+	if (data && data[IFLA_BOND_MODE]) {
+		int mode = nla_get_u8(data[IFLA_BOND_MODE]);
+
+		err = bond_option_mode_set(bond, mode);
+		if (err)
+			return err;
+	}
+	return 0;
+}
+
+static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
+			struct nlattr *tb[], struct nlattr *data[])
+{
+	int err;
+
+	err = bond_changelink(bond_dev, tb, data);
+	if (err < 0)
+		return err;
+
+	return register_netdevice(bond_dev);
+}
+
+static size_t bond_get_size(const struct net_device *bond_dev)
+{
+	return nla_total_size(sizeof(u8));	/* IFLA_BOND_MODE */
+}
+
+static int bond_fill_info(struct sk_buff *skb,
+			  const struct net_device *bond_dev)
+{
+	struct bonding *bond = netdev_priv(bond_dev);
+
+	if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode))
+		goto nla_put_failure;
+	return 0;
+
+nla_put_failure:
+	return -EMSGSIZE;
+}
+
 struct rtnl_link_ops bond_link_ops __read_mostly = {
 	.kind			= "bond",
 	.priv_size		= sizeof(struct bonding),
 	.setup			= bond_setup,
+	.maxtype		= IFLA_BOND_MAX,
+	.policy			= bond_policy,
 	.validate		= bond_validate,
+	.newlink		= bond_newlink,
+	.changelink		= bond_changelink,
+	.get_size		= bond_get_size,
+	.fill_info		= bond_fill_info,
 	.get_num_tx_queues	= bond_get_num_tx_queues,
 	.get_num_rx_queues	= bond_get_num_tx_queues, /* Use the same number
 							     as for TX queues */
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 80394e8..06fd3fe 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -325,6 +325,16 @@ struct ifla_vxlan_port_range {
 	__be16	high;
 };
 
+/* Bonding section */
+
+enum {
+	IFLA_BOND_UNSPEC,
+	IFLA_BOND_MODE,
+	__IFLA_BOND_MAX,
+};
+
+#define IFLA_BOND_MAX	(__IFLA_BOND_MAX - 1)
+
 /* SR-IOV virtual function management section */
 
 enum {
-- 
1.8.3.1

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

* [patch net-next 7/7] bonding: add Netlink support active_slave option
  2013-10-18 15:43 [patch net-next 0/7] bonding: introduce bonding options Netlink support Jiri Pirko
                   ` (5 preceding siblings ...)
  2013-10-18 15:43 ` [patch net-next 6/7] bonding: add Netlink support mode option Jiri Pirko
@ 2013-10-18 15:43 ` Jiri Pirko
  2013-10-18 15:50 ` [patch iproute2] iplink: add support for bonding netlink Jiri Pirko
  2013-10-19 22:59 ` [patch net-next 0/7] bonding: introduce bonding options Netlink support David Miller
  8 siblings, 0 replies; 13+ messages in thread
From: Jiri Pirko @ 2013-10-18 15:43 UTC (permalink / raw)
  To: netdev; +Cc: davem, fubar, vfalico, andy, stephen, vyasevic

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 drivers/net/bonding/bond_netlink.c | 23 ++++++++++++++++++++++-
 include/uapi/linux/if_link.h       |  1 +
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index a94f870..fe3500b 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -22,6 +22,7 @@
 
 static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
 	[IFLA_BOND_MODE]		= { .type = NLA_U8 },
+	[IFLA_BOND_ACTIVE_SLAVE]	= { .type = NLA_U32 },
 };
 
 static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -48,6 +49,22 @@ static int bond_changelink(struct net_device *bond_dev,
 		if (err)
 			return err;
 	}
+	if (data && data[IFLA_BOND_ACTIVE_SLAVE]) {
+		int ifindex = nla_get_u32(data[IFLA_BOND_ACTIVE_SLAVE]);
+		struct net_device *slave_dev;
+
+		if (ifindex == 0) {
+			slave_dev = NULL;
+		} else {
+			slave_dev = __dev_get_by_index(dev_net(bond_dev),
+						       ifindex);
+			if (!slave_dev)
+				return -ENODEV;
+		}
+		err = bond_option_active_slave_set(bond, slave_dev);
+		if (err)
+			return err;
+	}
 	return 0;
 }
 
@@ -66,14 +83,18 @@ static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
 static size_t bond_get_size(const struct net_device *bond_dev)
 {
 	return nla_total_size(sizeof(u8));	/* IFLA_BOND_MODE */
+		+ nla_total_size(sizeof(u32));	/* IFLA_BOND_ACTIVE_SLAVE */
 }
 
 static int bond_fill_info(struct sk_buff *skb,
 			  const struct net_device *bond_dev)
 {
 	struct bonding *bond = netdev_priv(bond_dev);
+	struct net_device *slave_dev = bond_option_active_slave_get(bond);
 
-	if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode))
+	if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode) ||
+	    (slave_dev &&
+	     nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, slave_dev->ifindex)))
 		goto nla_put_failure;
 	return 0;
 
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 06fd3fe..8a1e346 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -330,6 +330,7 @@ struct ifla_vxlan_port_range {
 enum {
 	IFLA_BOND_UNSPEC,
 	IFLA_BOND_MODE,
+	IFLA_BOND_ACTIVE_SLAVE,
 	__IFLA_BOND_MAX,
 };
 
-- 
1.8.3.1

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

* [patch iproute2] iplink: add support for bonding netlink
  2013-10-18 15:43 [patch net-next 0/7] bonding: introduce bonding options Netlink support Jiri Pirko
                   ` (6 preceding siblings ...)
  2013-10-18 15:43 ` [patch net-next 7/7] bonding: add Netlink support active_slave option Jiri Pirko
@ 2013-10-18 15:50 ` Jiri Pirko
  2013-10-29 19:00   ` Scott Feldman
  2013-10-30 23:46   ` Stephen Hemminger
  2013-10-19 22:59 ` [patch net-next 0/7] bonding: introduce bonding options Netlink support David Miller
  8 siblings, 2 replies; 13+ messages in thread
From: Jiri Pirko @ 2013-10-18 15:50 UTC (permalink / raw)
  To: netdev; +Cc: davem, fubar, vfalico, andy, stephen, vyasevic

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 include/linux/if_link.h | 11 ++++++
 ip/Makefile             |  2 +-
 ip/iplink.c             |  4 +--
 ip/iplink_bond.c        | 92 +++++++++++++++++++++++++++++++++++++++++++++++++
 man/man8/ip-link.8.in   |  4 +++
 5 files changed, 110 insertions(+), 3 deletions(-)
 create mode 100644 ip/iplink_bond.c

diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index ee4f2ba..3f7b343 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -318,6 +318,17 @@ enum {
 };
 #define IFLA_VXLAN_MAX	(__IFLA_VXLAN_MAX - 1)
 
+/* Bonding section */
+
+enum {
+	IFLA_BOND_UNSPEC,
+	IFLA_BOND_MODE,
+	IFLA_BOND_ACTIVE_SLAVE,
+	__IFLA_BOND_MAX,
+};
+
+#define IFLA_BOND_MAX	(__IFLA_BOND_MAX - 1)
+
 struct ifla_vxlan_port_range {
 	__be16	low;
 	__be16	high;
diff --git a/ip/Makefile b/ip/Makefile
index f10d22f..89a7a36 100644
--- a/ip/Makefile
+++ b/ip/Makefile
@@ -5,7 +5,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \
     iplink_vlan.o link_veth.o link_gre.o iplink_can.o \
     iplink_macvlan.o iplink_macvtap.o ipl2tp.o link_vti.o \
     iplink_vxlan.o tcp_metrics.o iplink_ipoib.o ipnetconf.o link_ip6tnl.o \
-    link_iptnl.o link_gre6.o
+    link_iptnl.o link_gre6.o iplink_bond.o
 
 RTMONOBJ=rtmon.o
 
diff --git a/ip/iplink.c b/ip/iplink.c
index 6cde731..58b6c20 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -85,8 +85,8 @@ void iplink_usage(void)
 	if (iplink_have_newlink()) {
 		fprintf(stderr, "\n");
 		fprintf(stderr, "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n");
-		fprintf(stderr, "          can | bridge | ipoib | ip6tnl | ipip | sit | vxlan |\n");
-		fprintf(stderr, "          gre | gretap | ip6gre | ip6gretap | vti }\n");
+		fprintf(stderr, "          can | bridge | bond | ipoib | ip6tnl | ipip | sit |\n");
+		fprintf(stderr, "          vxlan | gre | gretap | ip6gre | ip6gretap | vti }\n");
 	}
 	exit(-1);
 }
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
new file mode 100644
index 0000000..3fb7f4f
--- /dev/null
+++ b/ip/iplink_bond.c
@@ -0,0 +1,92 @@
+/*
+ * iplink_bond.c	Bonding device support
+ *
+ *              This program is free software; you can redistribute it and/or
+ *              modify it under the terms of the GNU General Public License
+ *              as published by the Free Software Foundation; either version
+ *              2 of the License, or (at your option) any later version.
+ *
+ * Authors:     Jiri Pirko <jiri@resnulli.us>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <linux/if_link.h>
+#include <net/if.h>
+
+#include "rt_names.h"
+#include "utils.h"
+#include "ip_common.h"
+
+static void explain(void)
+{
+	fprintf(stderr,
+		"Usage: ... bond [ mode BONDMODE ] [ active_slave SLAVE_DEV ]\n"
+		"                [ clear_active_slave ]\n"
+		"\n"
+		"BONDMODE := 0-6\n"
+	);
+}
+
+static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
+			  struct nlmsghdr *n)
+{
+	__u8 mode;
+	unsigned ifindex;
+
+	while (argc > 0) {
+		if (matches(*argv, "mode") == 0) {
+			NEXT_ARG();
+			if (get_u8(&mode, *argv, 0)) {
+				invarg("mode %s is invalid", *argv);
+				return -1;
+			}
+			addattr8(n, 1024, IFLA_BOND_MODE, mode);
+		} else if (matches(*argv, "active_slave") == 0) {
+			NEXT_ARG();
+			ifindex = if_nametoindex(*argv);
+			if (!ifindex)
+				return -1;
+			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, ifindex);
+		} else if (matches(*argv, "clear_active_slave") == 0) {
+			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, 0);
+		} else {
+			fprintf(stderr, "bond: unknown command \"%s\"?\n", *argv);
+			explain();
+			return -1;
+		}
+		argc--, argv++;
+	}
+
+	return 0;
+}
+
+static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
+{
+	unsigned ifindex;
+
+	if (!tb)
+		return;
+
+	if (tb[IFLA_BOND_MODE])
+		fprintf(f, "mode %u ", rta_getattr_u8(tb[IFLA_BOND_MODE]));
+
+	if (tb[IFLA_BOND_ACTIVE_SLAVE] &&
+	    (ifindex = rta_getattr_u32(tb[IFLA_BOND_ACTIVE_SLAVE]))) {
+		char buf[IFNAMSIZ];
+		const char *n = if_indextoname(ifindex, buf);
+
+		if (n)
+			fprintf(f, "active_slave %s ", n);
+		else
+			fprintf(f, "active_slave %u ", ifindex);
+	}
+}
+
+struct link_util bond_link_util = {
+	.id		= "bond",
+	.maxattr	= IFLA_BOND_MAX,
+	.parse_opt	= bond_parse_opt,
+	.print_opt	= bond_print_opt,
+};
diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
index 8b68c78..1825dc5 100644
--- a/man/man8/ip-link.8.in
+++ b/man/man8/ip-link.8.in
@@ -51,6 +51,7 @@ ip-link \- network device configuration
 .ti -8
 .IR TYPE " := [ "
 .BR bridge " | "
+.BR bond " ]"
 .BR can " | "
 .BR dummy " | "
 .BR ifb " | "
@@ -155,6 +156,9 @@ Link types:
 .B bridge
 - Ethernet Bridge device
 .sp
+.B bond
+- Bonding device
+.sp
 .B can
 - Controller Area Network interface
 .sp
-- 
1.8.3.1

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

* Re: [patch net-next 0/7] bonding: introduce bonding options Netlink support
  2013-10-18 15:43 [patch net-next 0/7] bonding: introduce bonding options Netlink support Jiri Pirko
                   ` (7 preceding siblings ...)
  2013-10-18 15:50 ` [patch iproute2] iplink: add support for bonding netlink Jiri Pirko
@ 2013-10-19 22:59 ` David Miller
  8 siblings, 0 replies; 13+ messages in thread
From: David Miller @ 2013-10-19 22:59 UTC (permalink / raw)
  To: jiri; +Cc: netdev, fubar, vfalico, andy, stephen, vyasevic

From: Jiri Pirko <jiri@resnulli.us>
Date: Fri, 18 Oct 2013 17:43:32 +0200

> This patchset basically allows "mode" and "active_slave" bonding options
> to be propagated and set up via standart RT Netlink interface.
> 
> In future other options can be easily added as well.

Nice work Jiri, series applied, thanks.

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

* Re: [patch iproute2] iplink: add support for bonding netlink
  2013-10-18 15:50 ` [patch iproute2] iplink: add support for bonding netlink Jiri Pirko
@ 2013-10-29 19:00   ` Scott Feldman
  2013-10-29 20:12     ` Vlad Yasevich
  2013-10-30 23:46   ` Stephen Hemminger
  1 sibling, 1 reply; 13+ messages in thread
From: Scott Feldman @ 2013-10-29 19:00 UTC (permalink / raw)
  To: netdev

Jiri Pirko <jiri <at> resnulli.us> writes:

> +		} else if (matches(*argv, "active_slave") == 0) {
> +			NEXT_ARG();
> +			ifindex = if_nametoindex(*argv);
> +			if (!ifindex)
> +				return -1;
> +			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, ifindex);
> +		} else if (matches(*argv, "clear_active_slave") == 0) {
> +			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, 0);

How do active_slave and clear_active_slave work from the ip link cmd line 
when bond is added, but doesn't have any slaves yet?  I did:

  ip link add bond1 type bond mode 1
  ip link set dev eth1 master bond1
  ip link set dev eth2 master bond1

Then tried:

  ip link add bond1 type bond active_slave eth1
  RTNETLINK answers: File exists

Or:

  ip link set dev bond1 active_slave eth1
  Error: either "dev" is duplicate, or "active_slave" is a garbage.

I must be dense but I can't figure how you can set active_slave before 
slaves have been added to bond, or even after slaves have been added 
to bond.

> diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
> index 8b68c78..1825dc5 100644
> --- a/man/man8/ip-link.8.in
> +++ b/man/man8/ip-link.8.in
>  <at>  <at>  -51,6 +51,7  <at>  <at>  ip-link \- network device configuration
>  .ti -8
>  .IR TYPE " := [ "
>  .BR bridge " | "
> +.BR bond " ]"

That should be " | "?

With patch applied, the man page shows:

       TYPE := [ bridge | bond ] can | dummy | ifb | ipoib | macvlan | ...

-scott

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

* Re: [patch iproute2] iplink: add support for bonding netlink
  2013-10-29 19:00   ` Scott Feldman
@ 2013-10-29 20:12     ` Vlad Yasevich
  0 siblings, 0 replies; 13+ messages in thread
From: Vlad Yasevich @ 2013-10-29 20:12 UTC (permalink / raw)
  To: Scott Feldman, netdev

On 10/29/2013 03:00 PM, Scott Feldman wrote:
> Jiri Pirko <jiri <at> resnulli.us> writes:
>
>> +		} else if (matches(*argv, "active_slave") == 0) {
>> +			NEXT_ARG();
>> +			ifindex = if_nametoindex(*argv);
>> +			if (!ifindex)
>> +				return -1;
>> +			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, ifindex);
>> +		} else if (matches(*argv, "clear_active_slave") == 0) {
>> +			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, 0);
>
> How do active_slave and clear_active_slave work from the ip link cmd line
> when bond is added, but doesn't have any slaves yet?  I did:
>
>    ip link add bond1 type bond mode 1
>    ip link set dev eth1 master bond1
>    ip link set dev eth2 master bond1
>
> Then tried:
>
>    ip link add bond1 type bond active_slave eth1
>    RTNETLINK answers: File exists
>
> Or:
>
>    ip link set dev bond1 active_slave eth1
>    Error: either "dev" is duplicate, or "active_slave" is a garbage.

You need to do:
	ip link set dev bond1 type bond active_slave eth1

'active_slave' argument is only defined for the 'type bond' operations.

You can not set active slave before enslaving the device and this
series doesn't change that.

-vlad

>
> I must be dense but I can't figure how you can set active_slave before
> slaves have been added to bond, or even after slaves have been added
> to bond.
>
>> diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
>> index 8b68c78..1825dc5 100644
>> --- a/man/man8/ip-link.8.in
>> +++ b/man/man8/ip-link.8.in
>>   <at>  <at>  -51,6 +51,7  <at>  <at>  ip-link \- network device configuration
>>   .ti -8
>>   .IR TYPE " := [ "
>>   .BR bridge " | "
>> +.BR bond " ]"
>
> That should be " | "?
>
> With patch applied, the man page shows:
>
>         TYPE := [ bridge | bond ] can | dummy | ifb | ipoib | macvlan | ...
>
> -scott
>
> --
> 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
>

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

* Re: [patch iproute2] iplink: add support for bonding netlink
  2013-10-18 15:50 ` [patch iproute2] iplink: add support for bonding netlink Jiri Pirko
  2013-10-29 19:00   ` Scott Feldman
@ 2013-10-30 23:46   ` Stephen Hemminger
  1 sibling, 0 replies; 13+ messages in thread
From: Stephen Hemminger @ 2013-10-30 23:46 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, davem, fubar, vfalico, andy, vyasevic

On Fri, 18 Oct 2013 17:50:01 +0200
Jiri Pirko <jiri@resnulli.us> wrote:

> Signed-off-by: Jiri Pirko <jiri@resnulli.us>

Applied to the net-next-3.11 branch

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

end of thread, other threads:[~2013-10-30 23:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-18 15:43 [patch net-next 0/7] bonding: introduce bonding options Netlink support Jiri Pirko
2013-10-18 15:43 ` [patch net-next 1/7] bonding: push Netlink bits into separate file Jiri Pirko
2013-10-18 15:43 ` [patch net-next 2/7] bonding: move mode setting into separate function Jiri Pirko
2013-10-18 15:43 ` [patch net-next 3/7] bonding: move active_slave " Jiri Pirko
2013-10-18 15:43 ` [patch net-next 4/7] bonding: remove bond_ioctl_change_active() Jiri Pirko
2013-10-18 15:43 ` [patch net-next 5/7] bonding: move active_slave getting into separate function Jiri Pirko
2013-10-18 15:43 ` [patch net-next 6/7] bonding: add Netlink support mode option Jiri Pirko
2013-10-18 15:43 ` [patch net-next 7/7] bonding: add Netlink support active_slave option Jiri Pirko
2013-10-18 15:50 ` [patch iproute2] iplink: add support for bonding netlink Jiri Pirko
2013-10-29 19:00   ` Scott Feldman
2013-10-29 20:12     ` Vlad Yasevich
2013-10-30 23:46   ` Stephen Hemminger
2013-10-19 22:59 ` [patch net-next 0/7] bonding: introduce bonding options Netlink support David Miller

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).