bonding: move active_slave getting into separate function
authorJiri Pirko <jiri@resnulli.us>
Fri, 18 Oct 2013 15:43:37 +0000 (17:43 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 19 Oct 2013 22:58:45 +0000 (18:58 -0400)
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/bond_options.c
drivers/net/bonding/bond_sysfs.c
drivers/net/bonding/bonding.h

index 09af5d10d43ac8135c94e146ec6535145ebb570b..9a5223c7b4d1a14f9b19354cfba6c4ea3dd933d0 100644 (file)
@@ -57,6 +57,24 @@ int bond_option_mode_set(struct bonding *bond, int mode)
        return 0;
 }
 
+static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
+                                                        struct slave *slave)
+{
+       return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL;
+}
+
+struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
+{
+       struct slave *slave = rcu_dereference(bond->curr_active_slave);
+
+       return __bond_option_active_slave_get(bond, slave);
+}
+
+struct net_device *bond_option_active_slave_get(struct bonding *bond)
+{
+       return __bond_option_active_slave_get(bond, bond->curr_active_slave);
+}
+
 int bond_option_active_slave_set(struct bonding *bond,
                                 struct net_device *slave_dev)
 {
index abd260047103e433fab7c9299bc2d72b5fe7bf4f..47749c970a01a67c189188767c41e94e2ff1fbd1 100644 (file)
@@ -1219,13 +1219,13 @@ static ssize_t bonding_show_active_slave(struct device *d,
                                         char *buf)
 {
        struct bonding *bond = to_bond(d);
-       struct slave *curr;
+       struct net_device *slave_dev;
        int count = 0;
 
        rcu_read_lock();
-       curr = rcu_dereference(bond->curr_active_slave);
-       if (USES_PRIMARY(bond->params.mode) && curr)
-               count = sprintf(buf, "%s\n", curr->dev->name);
+       slave_dev = bond_option_active_slave_get_rcu(bond);
+       if (slave_dev)
+               count = sprintf(buf, "%s\n", slave_dev->name);
        rcu_read_unlock();
 
        return count;
index 686759dce4c690b2c10b206f17002588e10be64c..046a60535e04e3fc7f9e6be79aa8c8cc0bb1867f 100644 (file)
@@ -428,6 +428,8 @@ int bond_netlink_init(void);
 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);
+struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
+struct net_device *bond_option_active_slave_get(struct bonding *bond);
 
 struct bond_net {
        struct net *            net;    /* Associated network namespace */