bonding: add primary_select attribute netlink support
authorsfeldma@cumulusnetworks.com <sfeldma@cumulusnetworks.com>
Mon, 16 Dec 2013 00:41:58 +0000 (16:41 -0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 17 Dec 2013 21:08:45 +0000 (16:08 -0500)
Add IFLA_BOND_PRIMARY_SELECT to allow get/set of bonding parameter
primary_select via netlink.

Signed-off-by: Scott Feldman <sfeldma@cumulusnetworks.com>
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 9445243593fcd6fcb0ea8f29f37e4175de9a7e8d..b361c674dc00718d294169457014358224d75116 100644 (file)
@@ -33,6 +33,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
        [IFLA_BOND_ARP_VALIDATE]        = { .type = NLA_U32 },
        [IFLA_BOND_ARP_ALL_TARGETS]     = { .type = NLA_U32 },
        [IFLA_BOND_PRIMARY]             = { .type = NLA_U32 },
+       [IFLA_BOND_PRIMARY_RESELECT]    = { .type = NLA_U8 },
 };
 
 static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -168,6 +169,14 @@ static int bond_changelink(struct net_device *bond_dev,
                if (err)
                        return err;
        }
+       if (data[IFLA_BOND_PRIMARY_RESELECT]) {
+               int primary_reselect =
+                       nla_get_u8(data[IFLA_BOND_PRIMARY_RESELECT]);
+
+               err = bond_option_primary_reselect_set(bond, primary_reselect);
+               if (err)
+                       return err;
+       }
        return 0;
 }
 
@@ -197,6 +206,7 @@ static size_t bond_get_size(const struct net_device *bond_dev)
                nla_total_size(sizeof(u32)) +   /* IFLA_BOND_ARP_VALIDATE */
                nla_total_size(sizeof(u32)) +   /* IFLA_BOND_ARP_ALL_TARGETS */
                nla_total_size(sizeof(u32)) +   /* IFLA_BOND_PRIMARY */
+               nla_total_size(sizeof(u8)) +    /* IFLA_BOND_PRIMARY_RESELECT */
                0;
 }
 
@@ -261,6 +271,10 @@ static int bond_fill_info(struct sk_buff *skb,
                        bond->primary_slave->dev->ifindex))
                goto nla_put_failure;
 
+       if (nla_put_u8(skb, IFLA_BOND_PRIMARY_RESELECT,
+                      bond->params.primary_reselect))
+               goto nla_put_failure;
+
        return 0;
 
 nla_put_failure:
index c410d2d0dc33f63d49898c8b05e7fabdfbe6a9d5..80a9df4e4bf72aa81a955fa3fa2ba8a1388c21c1 100644 (file)
@@ -519,3 +519,19 @@ out:
 
        return err;
 }
+
+int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect)
+{
+       bond->params.primary_reselect = primary_reselect;
+       pr_info("%s: setting primary_reselect to %s (%d).\n",
+               bond->dev->name, pri_reselect_tbl[primary_reselect].modename,
+               primary_reselect);
+
+       block_netpoll_tx();
+       write_lock_bh(&bond->curr_slave_lock);
+       bond_select_active_slave(bond);
+       write_unlock_bh(&bond->curr_slave_lock);
+       unblock_netpoll_tx();
+
+       return 0;
+}
index 7304c2bd2285f7fa1951921877d728ce2411345d..324afa5fda93c9b6026b08338c840e7ed14cb3c7 100644 (file)
@@ -909,32 +909,24 @@ static ssize_t bonding_store_primary_reselect(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();
-
        new_value = bond_parse_parm(buf, pri_reselect_tbl);
        if (new_value < 0)  {
                pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
                       bond->dev->name,
                       (int) strlen(buf) - 1, buf);
-               ret = -EINVAL;
-               goto out;
+               return -EINVAL;
        }
 
-       bond->params.primary_reselect = new_value;
-       pr_info("%s: setting primary_reselect to %s (%d).\n",
-               bond->dev->name, pri_reselect_tbl[new_value].modename,
-               new_value);
+       if (!rtnl_trylock())
+               return restart_syscall();
+
+       ret = bond_option_primary_reselect_set(bond, new_value);
+       if (!ret)
+               ret = count;
 
-       block_netpoll_tx();
-       write_lock_bh(&bond->curr_slave_lock);
-       bond_select_active_slave(bond);
-       write_unlock_bh(&bond->curr_slave_lock);
-       unblock_netpoll_tx();
-out:
        rtnl_unlock();
        return ret;
 }
index ec35802cd2656fa3ca9ad9a7d961415035fb933f..4e89d0480a5e4e7df07aab8ed95dedf8335d6f69 100644 (file)
@@ -455,6 +455,8 @@ int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target);
 int bond_option_arp_validate_set(struct bonding *bond, int arp_validate);
 int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets);
 int bond_option_primary_set(struct bonding *bond, const char *primary);
+int bond_option_primary_reselect_set(struct bonding *bond,
+                                    int primary_reselect);
 struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
 struct net_device *bond_option_active_slave_get(struct bonding *bond);
 
index fb3cfe2b176acce45e387224724db87867f2a0b8..cf59d54a199d11b70d27839c0e0c0bdff301a4b0 100644 (file)
@@ -340,6 +340,7 @@ enum {
        IFLA_BOND_ARP_VALIDATE,
        IFLA_BOND_ARP_ALL_TARGETS,
        IFLA_BOND_PRIMARY,
+       IFLA_BOND_PRIMARY_RESELECT,
        __IFLA_BOND_MAX,
 };