Skip to contentSkip to conversation

bonding: add updelay netlink support

PATCH In review Scott Feldman 2 participants 2 messages Dec 12, 2013 – Dec 13, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 2/8 bonding: add updelay netlink support

Add IFLA_BOND_UPDELAY to allow get/set of bonding parameter updelay via netlink.

---
 drivers/net/bonding/bond_netlink.c |   13 +++++++++++
 drivers/net/bonding/bond_options.c |   29 +++++++++++++++++++++++++
 drivers/net/bonding/bond_sysfs.c   |   42 +++++++++---------------------------
 drivers/net/bonding/bonding.h      |    1 +
 include/uapi/linux/if_link.h       |    1 +
 5 files changed, 54 insertions(+), 32 deletions(-)
drivers/net/bonding/bond_netlink.c +13 -0
index 28a88be..086cf4f 100644
@@ -25,6 +25,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 },
 	[IFLA_BOND_MIIMON]		= { .type = NLA_U32 },
+	[IFLA_BOND_UPDELAY]		= { .type = NLA_U32 },
 };
 
 static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -77,6 +78,13 @@ static int bond_changelink(struct net_device *bond_dev,
 		if (err)
 			return err;
 	}
+	if (data[IFLA_BOND_UPDELAY]) {
+		int updelay = nla_get_u32(data[IFLA_BOND_UPDELAY]);
+
+		err = bond_option_updelay_set(bond, updelay);
+		if (err)
+			return err;
+	}
 	return 0;
 }
 
@@ -97,6 +105,7 @@ 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 */
 		nla_total_size(sizeof(u32)) +	/* IFLA_BOND_MIIMON */
+		nla_total_size(sizeof(u32)) +	/* IFLA_BOND_UPDELAY */
 		0;
 }
 
@@ -116,6 +125,10 @@ static int bond_fill_info(struct sk_buff *skb,
 	if (nla_put_u32(skb, IFLA_BOND_MIIMON, bond->params.miimon))
 		goto nla_put_failure;
 
+	if (nla_put_u32(skb, IFLA_BOND_UPDELAY,
+			bond->params.updelay * bond->params.miimon))
+		goto nla_put_failure;
+
 	return 0;
 
 nla_put_failure:
drivers/net/bonding/bond_options.c +29 -0
index 8ae42d3..ae94b84 100644
@@ -187,3 +187,32 @@ int bond_option_miimon_set(struct bonding *bond, int miimon)
 	}
 	return 0;
 }
+
+int bond_option_updelay_set(struct bonding *bond, int updelay)
+{
+	if (!(bond->params.miimon)) {
+		pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
+		       bond->dev->name);
+		return -EPERM;
+	}
+
+	if (updelay < 0) {
+		pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n",
+		       bond->dev->name, updelay, 0, INT_MAX);
+		return -EINVAL;
+	} else {
+		if ((updelay % bond->params.miimon) != 0) {
+			pr_warn("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
+				bond->dev->name, updelay,
+				bond->params.miimon,
+				(updelay / bond->params.miimon) *
+				bond->params.miimon);
+		}
+		bond->params.updelay = updelay / bond->params.miimon;
+		pr_info("%s: Setting up delay to %d.\n",
+			bond->dev->name,
+			bond->params.updelay * bond->params.miimon);
+	}
+
+	return 0;
+}
drivers/net/bonding/bond_sysfs.c +10 -32

54 lines not on this page · raw message

drivers/net/bonding/bonding.h +1 -0
index b146479..8a91f71 100644
@@ -440,6 +440,7 @@ 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);
 int bond_option_miimon_set(struct bonding *bond, int miimon);
+int bond_option_updelay_set(struct bonding *bond, int updelay);
 struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
 struct net_device *bond_option_active_slave_get(struct bonding *bond);
 
include/uapi/linux/if_link.h +1 -0
index 739b2db..7588c81 100644
@@ -332,6 +332,7 @@ enum {
 	IFLA_BOND_MODE,
 	IFLA_BOND_ACTIVE_SLAVE,
 	IFLA_BOND_MIIMON,
+	IFLA_BOND_UPDELAY,
 	__IFLA_BOND_MAX,
 };
 
#1 lore raw
Quoted 4 lines · Thu, Dec 12, 2013 at 11:10:02PM CET, [email protected] wrote:

Add IFLA_BOND_UPDELAY to allow get/set of bonding parameter updelay via netlink.

Quoted 8 lines

---

drivers/net/bonding/bond_netlink.c |   13 +++++++++++
drivers/net/bonding/bond_options.c |   29 +++++++++++++++++++++++++
drivers/net/bonding/bond_sysfs.c   |   42 +++++++++---------------------------
drivers/net/bonding/bonding.h      |    1 +
include/uapi/linux/if_link.h       |    1 +
5 files changed, 54 insertions(+), 32 deletions(-)