netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <nikolay@redhat.com>
To: netdev@vger.kernel.org
Cc: Nikolay Aleksandrov <nikolay@redhat.com>
Subject: [PATCH net-next 22/25] bonding: convert all_slaves_active to use the new option API
Date: Tue, 21 Jan 2014 15:55:11 +0100	[thread overview]
Message-ID: <1390316114-17815-23-git-send-email-nikolay@redhat.com> (raw)
In-Reply-To: <1390316114-17815-1-git-send-email-nikolay@redhat.com>

This patch adds the necessary changes so all_slaves_active would use
the new bonding option API.

Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
---
 drivers/net/bonding/bond_netlink.c |  4 ++--
 drivers/net/bonding/bond_options.c | 29 +++++++++++++++++------------
 drivers/net/bonding/bond_options.h |  3 +++
 drivers/net/bonding/bond_sysfs.c   | 15 +++------------
 drivers/net/bonding/bonding.h      |  2 --
 5 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index bd26d1c..d0f22ff 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -283,8 +283,8 @@ static int bond_changelink(struct net_device *bond_dev,
 		int all_slaves_active =
 			nla_get_u8(data[IFLA_BOND_ALL_SLAVES_ACTIVE]);
 
-		err = bond_option_all_slaves_active_set(bond,
-							all_slaves_active);
+		bond_opt_initval(&newval, all_slaves_active);
+		err = __bond_opt_set(bond, BOND_OPT_ALL_SLAVES_ACTIVE, &newval);
 		if (err)
 			return err;
 	}
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 3fc2730..8309d51 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -106,6 +106,12 @@ static struct bond_opt_value bond_use_carrier_tbl[] = {
 	{ NULL,  -1, 0}
 };
 
+static struct bond_opt_value bond_all_slaves_active_tbl[] = {
+	{ "off", 0,  BOND_VALFLAG_DEFAULT},
+	{ "on",  1,  0},
+	{ NULL,  -1, 0}
+};
+
 static struct bond_option bond_opts[] = {
 	[BOND_OPT_MODE] = {
 		.id = BOND_OPT_MODE,
@@ -262,6 +268,13 @@ static struct bond_option bond_opts[] = {
 		.flags = BOND_OPTFLAG_RAWVAL,
 		.set = bond_option_queue_id_set
 	},
+	[BOND_OPT_ALL_SLAVES_ACTIVE] = {
+		.id = BOND_OPT_ALL_SLAVES_ACTIVE,
+		.name = "all_slaves_active",
+		.desc = "Keep all frames received on an interface by setting active flag for all slaves",
+		.values = bond_all_slaves_active_tbl,
+		.set = bond_option_all_slaves_active_set
+	},
 	{ }
 };
 
@@ -1050,25 +1063,17 @@ int bond_option_num_peer_notif_set(struct bonding *bond,
 }
 
 int bond_option_all_slaves_active_set(struct bonding *bond,
-				      int all_slaves_active)
+				      struct bond_opt_value *newval)
 {
 	struct list_head *iter;
 	struct slave *slave;
 
-	if (all_slaves_active == bond->params.all_slaves_active)
+	if (newval->value == bond->params.all_slaves_active)
 		return 0;
-
-	if ((all_slaves_active == 0) || (all_slaves_active == 1)) {
-		bond->params.all_slaves_active = all_slaves_active;
-	} else {
-		pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
-			bond->dev->name, all_slaves_active);
-		return -EINVAL;
-	}
-
+	bond->params.all_slaves_active = newval->value;
 	bond_for_each_slave(bond, slave, iter) {
 		if (!bond_is_active_slave(slave)) {
-			if (all_slaves_active)
+			if (newval->value)
 				slave->inactive = 0;
 			else
 				slave->inactive = 1;
diff --git a/drivers/net/bonding/bond_options.h b/drivers/net/bonding/bond_options.h
index 396d504..09ee8c8 100644
--- a/drivers/net/bonding/bond_options.h
+++ b/drivers/net/bonding/bond_options.h
@@ -58,6 +58,7 @@ enum {
 	BOND_OPT_USE_CARRIER,
 	BOND_OPT_ACTIVE_SLAVE,
 	BOND_OPT_QUEUE_ID,
+	BOND_OPT_ALL_SLAVES_ACTIVE,
 	BOND_OPT_LAST
 };
 
@@ -156,4 +157,6 @@ int bond_option_active_slave_set(struct bonding *bond,
 				 struct bond_opt_value *newval);
 int bond_option_queue_id_set(struct bonding *bond,
 			     struct bond_opt_value *newval);
+int bond_option_all_slaves_active_set(struct bonding *bond,
+				      struct bond_opt_value *newval);
 #endif /* _BOND_OPTIONS_H */
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 2da37bd..a403345 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -1016,22 +1016,13 @@ static ssize_t bonding_store_slaves_active(struct device *d,
 					   const char *buf, size_t count)
 {
 	struct bonding *bond = to_bond(d);
-	int new_value, ret;
-
-	if (sscanf(buf, "%d", &new_value) != 1) {
-		pr_err("%s: no all_slaves_active value specified.\n",
-		       bond->dev->name);
-		return -EINVAL;
-	}
-
-	if (!rtnl_trylock())
-		return restart_syscall();
+	int ret;
 
-	ret = bond_option_all_slaves_active_set(bond, new_value);
+	ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ALL_SLAVES_ACTIVE,
+				   (char *)buf);
 	if (!ret)
 		ret = count;
 
-	rtnl_unlock();
 	return ret;
 }
 static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 014605d..c021d54 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -452,8 +452,6 @@ void bond_netlink_fini(void);
 int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target);
 int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target);
 int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp);
-int bond_option_all_slaves_active_set(struct bonding *bond,
-				      int all_slaves_active);
 int bond_option_lp_interval_set(struct bonding *bond, int min_links);
 struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
 struct net_device *bond_option_active_slave_get(struct bonding *bond);
-- 
1.8.4.2

  parent reply	other threads:[~2014-01-21 14:56 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-21 14:54 [PATCH net-next 00/25] bonding: introduce new option API Nikolay Aleksandrov
2014-01-21 14:54 ` [PATCH net-next 01/25] bonding: add infrastructure for an " Nikolay Aleksandrov
2014-01-21 14:54 ` [PATCH net-next 02/25] bonding: convert mode setting to use the new " Nikolay Aleksandrov
2014-01-21 14:54 ` [PATCH net-next 03/25] bonding: convert packets_per_slave " Nikolay Aleksandrov
2014-01-22  7:25   ` Hannes Frederic Sowa
2014-01-22 13:09     ` Nikolay Aleksandrov
2014-01-21 14:54 ` [PATCH net-next 04/25] bonding: convert xmit_hash_policy " Nikolay Aleksandrov
2014-01-21 14:54 ` [PATCH net-next 05/25] bonding: convert arp_validate " Nikolay Aleksandrov
2014-01-21 14:54 ` [PATCH net-next 06/25] bonding: convert arp_all_targets " Nikolay Aleksandrov
2014-01-21 14:54 ` [PATCH net-next 07/25] bonding: convert fail_over_mac " Nikolay Aleksandrov
2014-01-21 14:54 ` [PATCH net-next 08/25] bonding: convert arp_interval " Nikolay Aleksandrov
2014-01-21 14:54 ` [PATCH net-next 09/25] bonding: convert arp_ip_target " Nikolay Aleksandrov
2014-01-21 14:54 ` [PATCH net-next 10/25] bonding: convert downdelay " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 11/25] bonding: convert updelay " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 12/25] bonding: convert lacp_rate " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 13/25] bonding: convert min_links " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 14/25] bonding: convert ad_select " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 15/25] bonding: convert num_peer_notif " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 16/25] bonding: convert miimon " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 17/25] bonding: convert primary " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 18/25] bonding: convert primary_reselect " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 19/25] bonding: convert use_carrier " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 20/25] bonding: convert active_slave " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 21/25] bonding: convert queue_id " Nikolay Aleksandrov
2014-01-21 14:55 ` Nikolay Aleksandrov [this message]
2014-01-21 14:55 ` [PATCH net-next 23/25] bonding: convert resend_igmp " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 24/25] bonding: convert lp_interval " Nikolay Aleksandrov
2014-01-21 14:55 ` [PATCH net-next 25/25] bonding: convert slaves " Nikolay Aleksandrov
2014-01-21 15:59 ` [PATCH net-next 00/25] bonding: introduce " Dan Williams
2014-01-21 16:06   ` Nikolay Aleksandrov
2014-01-21 21:51   ` Scott Feldman
2014-01-22  2:01 ` Ding Tianhong
2014-01-22 13:23   ` Nikolay Aleksandrov

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=1390316114-17815-23-git-send-email-nikolay@redhat.com \
    --to=nikolay@redhat.com \
    --cc=netdev@vger.kernel.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).