From: Scott Feldman <sfeldma@cumulusnetworks.com>
To: vfalico@redhat.com, fubar@us.ibm.com, andy@greyhouse.net
Cc: netdev@vger.kernel.org, roopa@cumulusnetworks.com,
shm@cumulusnetworks.com, jiri@resnulli.us
Subject: [PATCH net-next 1/4] bonding: add lacp_rate attribute netlink support
Date: Fri, 27 Dec 2013 23:15:41 -0800 [thread overview]
Message-ID: <20131228071541.6296.29310.stgit@monster-03.cumulusnetworks.com> (raw)
Add IFLA_BOND_AD_LACP_RATE to allow get/set of bonding parameter
lacp_rate via netlink.
Signed-off-by: Scott Feldman <sfeldma@cumulusnetworks.com>
---
drivers/net/bonding/bond_netlink.c | 14 +++++++++++++
drivers/net/bonding/bond_options.c | 29 ++++++++++++++++++++++++++
drivers/net/bonding/bond_sysfs.c | 40 ++++++++++--------------------------
drivers/net/bonding/bonding.h | 1 +
include/uapi/linux/if_link.h | 1 +
5 files changed, 56 insertions(+), 29 deletions(-)
diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index 84acd144..45de873 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -43,6 +43,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
[IFLA_BOND_MIN_LINKS] = { .type = NLA_U32 },
[IFLA_BOND_LP_INTERVAL] = { .type = NLA_U32 },
[IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NLA_U32 },
+ [IFLA_BOND_AD_LACP_RATE] = { .type = NLA_U8 },
};
static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -252,6 +253,14 @@ static int bond_changelink(struct net_device *bond_dev,
if (err)
return err;
}
+ if (data[IFLA_BOND_AD_LACP_RATE]) {
+ int lacp_rate =
+ nla_get_u8(data[IFLA_BOND_AD_LACP_RATE]);
+
+ err = bond_option_lacp_rate_set(bond, lacp_rate);
+ if (err)
+ return err;
+ }
return 0;
}
@@ -290,6 +299,7 @@ static size_t bond_get_size(const struct net_device *bond_dev)
nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIN_LINKS */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_LP_INTERVAL */
nla_total_size(sizeof(u32)) + /* IFLA_BOND_PACKETS_PER_SLAVE */
+ nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_LACP_RATE */
0;
}
@@ -395,6 +405,10 @@ static int bond_fill_info(struct sk_buff *skb,
packets_per_slave))
goto nla_put_failure;
+ if (nla_put_u8(skb, IFLA_BOND_AD_LACP_RATE,
+ bond->params.lacp_fast))
+ goto nla_put_failure;
+
return 0;
nla_put_failure:
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index f8a2cd8..ad67fbf 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -656,3 +656,32 @@ int bond_option_packets_per_slave_set(struct bonding *bond,
return 0;
}
+
+int bond_option_lacp_rate_set(struct bonding *bond, int lacp_rate)
+{
+ if (bond->dev->flags & IFF_UP) {
+ pr_err("%s: Unable to update LACP rate because interface is up.\n",
+ bond->dev->name);
+ return -EPERM;
+ }
+
+ if (bond->params.mode != BOND_MODE_8023AD) {
+ pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
+ bond->dev->name);
+ return -EPERM;
+ }
+
+ if ((lacp_rate == 1) || (lacp_rate == 0)) {
+ bond->params.lacp_fast = lacp_rate;
+ bond_3ad_update_lacp_rate(bond);
+ pr_info("%s: Setting LACP rate to %s (%d).\n",
+ bond->dev->name, bond_lacp_tbl[lacp_rate].modename,
+ lacp_rate);
+ } else {
+ pr_err("%s: Ignoring invalid LACP rate value %d.\n",
+ bond->dev->name, lacp_rate);
+ return -EINVAL;
+ }
+
+ return 0;
+}
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index a0a3476f..62d33dc 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -658,41 +658,23 @@ static ssize_t bonding_store_lacp(struct device *d,
const char *buf, size_t count)
{
struct bonding *bond = to_bond(d);
- int new_value, ret = count;
-
- if (!rtnl_trylock())
- return restart_syscall();
-
- if (bond->dev->flags & IFF_UP) {
- pr_err("%s: Unable to update LACP rate because interface is up.\n",
- bond->dev->name);
- ret = -EPERM;
- goto out;
- }
-
- if (bond->params.mode != BOND_MODE_8023AD) {
- pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
- bond->dev->name);
- ret = -EPERM;
- goto out;
- }
+ int new_value, ret;
new_value = bond_parse_parm(buf, bond_lacp_tbl);
-
- if ((new_value == 1) || (new_value == 0)) {
- bond->params.lacp_fast = new_value;
- bond_3ad_update_lacp_rate(bond);
- pr_info("%s: Setting LACP rate to %s (%d).\n",
- bond->dev->name, bond_lacp_tbl[new_value].modename,
- new_value);
- } else {
+ if (new_value < 0) {
pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
bond->dev->name, (int)strlen(buf) - 1, buf);
- ret = -EINVAL;
+ return -EINVAL;
}
-out:
- rtnl_unlock();
+ if (!rtnl_trylock())
+ return restart_syscall();
+
+ ret = bond_option_lacp_rate_set(bond, new_value);
+ if (!ret)
+ ret = count;
+
+ rtnl_unlock();
return ret;
}
static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 5886f07..ef93667 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -468,6 +468,7 @@ int bond_option_min_links_set(struct bonding *bond, int min_links);
int bond_option_lp_interval_set(struct bonding *bond, int min_links);
int bond_option_packets_per_slave_set(struct bonding *bond,
int packets_per_slave);
+int bond_option_lacp_rate_set(struct bonding *bond, int lacp_rate);
struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
struct net_device *bond_option_active_slave_get(struct bonding *bond);
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 8fbc7ca..0f8f38f 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -349,6 +349,7 @@ enum {
IFLA_BOND_MIN_LINKS,
IFLA_BOND_LP_INTERVAL,
IFLA_BOND_PACKETS_PER_SLAVE,
+ IFLA_BOND_AD_LACP_RATE,
__IFLA_BOND_MAX,
};
next reply other threads:[~2013-12-28 7:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-28 7:15 Scott Feldman [this message]
2013-12-28 21:24 ` [PATCH net-next 1/4] bonding: add lacp_rate attribute netlink support 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=20131228071541.6296.29310.stgit@monster-03.cumulusnetworks.com \
--to=sfeldma@cumulusnetworks.com \
--cc=andy@greyhouse.net \
--cc=fubar@us.ibm.com \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
--cc=roopa@cumulusnetworks.com \
--cc=shm@cumulusnetworks.com \
--cc=vfalico@redhat.com \
/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