bonding: add downdelay netlink support
authorsfeldma@cumulusnetworks.com <sfeldma@cumulusnetworks.com>
Thu, 12 Dec 2013 22:10:09 +0000 (14:10 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sat, 14 Dec 2013 06:07:31 +0000 (01:07 -0500)
Add IFLA_BOND_DOWNDELAY to allow get/set of bonding parameter
downdelay via netlink.

Signed-off-by: Scott Feldman <sfeldma@cumulusnetworks.com>
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/bond_netlink.c
drivers/net/bonding/bond_options.c
drivers/net/bonding/bond_sysfs.c
drivers/net/bonding/bonding.h
include/uapi/linux/if_link.h

index 086cf4f..a0a2e8c 100644 (file)
@@ -26,6 +26,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
        [IFLA_BOND_ACTIVE_SLAVE]        = { .type = NLA_U32 },
        [IFLA_BOND_MIIMON]              = { .type = NLA_U32 },
        [IFLA_BOND_UPDELAY]             = { .type = NLA_U32 },
+       [IFLA_BOND_DOWNDELAY]           = { .type = NLA_U32 },
 };
 
 static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -85,6 +86,13 @@ static int bond_changelink(struct net_device *bond_dev,
                if (err)
                        return err;
        }
+       if (data[IFLA_BOND_DOWNDELAY]) {
+               int downdelay = nla_get_u32(data[IFLA_BOND_DOWNDELAY]);
+
+               err = bond_option_downdelay_set(bond, downdelay);
+               if (err)
+                       return err;
+       }
        return 0;
 }
 
@@ -106,6 +114,7 @@ static size_t bond_get_size(const struct net_device *bond_dev)
                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 */
+               nla_total_size(sizeof(u32)) +   /* IFLA_BOND_DOWNDELAY */
                0;
 }
 
@@ -129,6 +138,10 @@ static int bond_fill_info(struct sk_buff *skb,
                        bond->params.updelay * bond->params.miimon))
                goto nla_put_failure;
 
+       if (nla_put_u32(skb, IFLA_BOND_DOWNDELAY,
+                       bond->params.downdelay * bond->params.miimon))
+               goto nla_put_failure;
+
        return 0;
 
 nla_put_failure:
index ae94b84..2914d64 100644 (file)
@@ -216,3 +216,32 @@ int bond_option_updelay_set(struct bonding *bond, int updelay)
 
        return 0;
 }
+
+int bond_option_downdelay_set(struct bonding *bond, int downdelay)
+{
+       if (!(bond->params.miimon)) {
+               pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
+                      bond->dev->name);
+               return -EPERM;
+       }
+
+       if (downdelay < 0) {
+               pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
+                      bond->dev->name, downdelay, 0, INT_MAX);
+               return -EINVAL;
+       } else {
+               if ((downdelay % bond->params.miimon) != 0) {
+                       pr_warn("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
+                               bond->dev->name, downdelay,
+                               bond->params.miimon,
+                               (downdelay / bond->params.miimon) *
+                               bond->params.miimon);
+               }
+               bond->params.downdelay = downdelay / bond->params.miimon;
+               pr_info("%s: Setting down delay to %d.\n",
+                       bond->dev->name,
+                       bond->params.downdelay * bond->params.miimon);
+       }
+
+       return 0;
+}
index 4dcbec4..bec20bc 100644 (file)
@@ -689,44 +689,21 @@ static ssize_t bonding_store_downdelay(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->params.miimon)) {
-               pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
-                      bond->dev->name);
-               ret = -EPERM;
-               goto out;
-       }
-
        if (sscanf(buf, "%d", &new_value) != 1) {
                pr_err("%s: no down delay value specified.\n", bond->dev->name);
-               ret = -EINVAL;
-               goto out;
+               return -EINVAL;
        }
-       if (new_value < 0) {
-               pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
-                      bond->dev->name, new_value, 0, INT_MAX);
-               ret = -EINVAL;
-               goto out;
-       } else {
-               if ((new_value % bond->params.miimon) != 0) {
-                       pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
-                                  bond->dev->name, new_value,
-                                  bond->params.miimon,
-                                  (new_value / bond->params.miimon) *
-                                  bond->params.miimon);
-               }
-               bond->params.downdelay = new_value / bond->params.miimon;
-               pr_info("%s: Setting down delay to %d.\n",
-                       bond->dev->name,
-                       bond->params.downdelay * bond->params.miimon);
 
-       }
+       if (!rtnl_trylock())
+               return restart_syscall();
+
+       ret = bond_option_downdelay_set(bond, new_value);
+       if (!ret)
+               ret = count;
 
-out:
        rtnl_unlock();
        return ret;
 }
index 8a91f71..f5749b1 100644 (file)
@@ -441,6 +441,7 @@ 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);
+int bond_option_downdelay_set(struct bonding *bond, int downdelay);
 struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
 struct net_device *bond_option_active_slave_get(struct bonding *bond);
 
index 7588c81..f955067 100644 (file)
@@ -333,6 +333,7 @@ enum {
        IFLA_BOND_ACTIVE_SLAVE,
        IFLA_BOND_MIIMON,
        IFLA_BOND_UPDELAY,
+       IFLA_BOND_DOWNDELAY,
        __IFLA_BOND_MAX,
 };