summaryrefslogtreecommitdiff
path: root/drivers/net/team/team.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/team/team.c')
-rw-r--r--drivers/net/team/team.c119
1 files changed, 87 insertions, 32 deletions
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index 60672bb09960..f3092749b072 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -80,30 +80,78 @@ EXPORT_SYMBOL(team_port_set_team_mac);
* Options handling
*******************/
-void team_options_register(struct team *team, struct team_option *option,
- size_t option_count)
+struct team_option *__team_find_option(struct team *team, const char *opt_name)
+{
+ struct team_option *option;
+
+ list_for_each_entry(option, &team->option_list, list) {
+ if (strcmp(option->name, opt_name) == 0)
+ return option;
+ }
+ return NULL;
+}
+
+int team_options_register(struct team *team,
+ const struct team_option *option,
+ size_t option_count)
{
int i;
+ struct team_option *dst_opts[option_count];
+ int err;
+
+ memset(dst_opts, 0, sizeof(dst_opts));
+ for (i = 0; i < option_count; i++, option++) {
+ struct team_option *dst_opt;
+
+ if (__team_find_option(team, option->name)) {
+ err = -EEXIST;
+ goto rollback;
+ }
+ dst_opt = kmalloc(sizeof(*option), GFP_KERNEL);
+ if (!dst_opt) {
+ err = -ENOMEM;
+ goto rollback;
+ }
+ memcpy(dst_opt, option, sizeof(*option));
+ dst_opts[i] = dst_opt;
+ }
+
+ for (i = 0; i < option_count; i++)
+ list_add_tail(&dst_opts[i]->list, &team->option_list);
+
+ return 0;
+
+rollback:
+ for (i = 0; i < option_count; i++)
+ kfree(dst_opts[i]);
- for (i = 0; i < option_count; i++, option++)
- list_add_tail(&option->list, &team->option_list);
+ return err;
}
+
EXPORT_SYMBOL(team_options_register);
static void __team_options_change_check(struct team *team,
struct team_option *changed_option);
static void __team_options_unregister(struct team *team,
- struct team_option *option,
+ const struct team_option *option,
size_t option_count)
{
int i;
- for (i = 0; i < option_count; i++, option++)
- list_del(&option->list);
+ for (i = 0; i < option_count; i++, option++) {
+ struct team_option *del_opt;
+
+ del_opt = __team_find_option(team, option->name);
+ if (del_opt) {
+ list_del(&del_opt->list);
+ kfree(del_opt);
+ }
+ }
}
-void team_options_unregister(struct team *team, struct team_option *option,
+void team_options_unregister(struct team *team,
+ const struct team_option *option,
size_t option_count)
{
__team_options_unregister(team, option, option_count);
@@ -443,9 +491,9 @@ static void __team_compute_features(struct team *team)
static void team_compute_features(struct team *team)
{
- spin_lock(&team->lock);
+ mutex_lock(&team->lock);
__team_compute_features(team);
- spin_unlock(&team->lock);
+ mutex_unlock(&team->lock);
}
static int team_port_enter(struct team *team, struct team_port *port)
@@ -632,7 +680,7 @@ static int team_mode_option_set(struct team *team, void *arg)
return team_change_mode(team, *str);
}
-static struct team_option team_options[] = {
+static const struct team_option team_options[] = {
{
.name = "mode",
.type = TEAM_OPTION_TYPE_STRING,
@@ -645,9 +693,10 @@ static int team_init(struct net_device *dev)
{
struct team *team = netdev_priv(dev);
int i;
+ int err;
team->dev = dev;
- spin_lock_init(&team->lock);
+ mutex_init(&team->lock);
team->pcpu_stats = alloc_percpu(struct team_pcpu_stats);
if (!team->pcpu_stats)
@@ -660,10 +709,17 @@ static int team_init(struct net_device *dev)
team_adjust_ops(team);
INIT_LIST_HEAD(&team->option_list);
- team_options_register(team, team_options, ARRAY_SIZE(team_options));
+ err = team_options_register(team, team_options, ARRAY_SIZE(team_options));
+ if (err)
+ goto err_options_register;
netif_carrier_off(dev);
return 0;
+
+err_options_register:
+ free_percpu(team->pcpu_stats);
+
+ return err;
}
static void team_uninit(struct net_device *dev)
@@ -672,13 +728,13 @@ static void team_uninit(struct net_device *dev)
struct team_port *port;
struct team_port *tmp;
- spin_lock(&team->lock);
+ mutex_lock(&team->lock);
list_for_each_entry_safe(port, tmp, &team->port_list, list)
team_port_del(team, port->dev);
__team_change_mode(team, NULL); /* cleanup */
__team_options_unregister(team, team_options, ARRAY_SIZE(team_options));
- spin_unlock(&team->lock);
+ mutex_unlock(&team->lock);
}
static void team_destructor(struct net_device *dev)
@@ -784,7 +840,7 @@ static int team_change_mtu(struct net_device *dev, int new_mtu)
* Alhough this is reader, it's guarded by team lock. It's not possible
* to traverse list in reverse under rcu_read_lock
*/
- spin_lock(&team->lock);
+ mutex_lock(&team->lock);
list_for_each_entry(port, &team->port_list, list) {
err = dev_set_mtu(port->dev, new_mtu);
if (err) {
@@ -793,7 +849,7 @@ static int team_change_mtu(struct net_device *dev, int new_mtu)
goto unwind;
}
}
- spin_unlock(&team->lock);
+ mutex_unlock(&team->lock);
dev->mtu = new_mtu;
@@ -802,7 +858,7 @@ static int team_change_mtu(struct net_device *dev, int new_mtu)
unwind:
list_for_each_entry_continue_reverse(port, &team->port_list, list)
dev_set_mtu(port->dev, dev->mtu);
- spin_unlock(&team->lock);
+ mutex_unlock(&team->lock);
return err;
}
@@ -880,9 +936,9 @@ static int team_add_slave(struct net_device *dev, struct net_device *port_dev)
struct team *team = netdev_priv(dev);
int err;
- spin_lock(&team->lock);
+ mutex_lock(&team->lock);
err = team_port_add(team, port_dev);
- spin_unlock(&team->lock);
+ mutex_unlock(&team->lock);
return err;
}
@@ -891,9 +947,9 @@ static int team_del_slave(struct net_device *dev, struct net_device *port_dev)
struct team *team = netdev_priv(dev);
int err;
- spin_lock(&team->lock);
+ mutex_lock(&team->lock);
err = team_port_del(team, port_dev);
- spin_unlock(&team->lock);
+ mutex_unlock(&team->lock);
return err;
}
@@ -1043,8 +1099,7 @@ err_msg_put:
/*
* Netlink cmd functions should be locked by following two functions.
- * To ensure team_uninit would not be called in between, hold rcu_read_lock
- * all the time.
+ * Since dev gets held here, that ensures dev won't disappear in between.
*/
static struct team *team_nl_team_get(struct genl_info *info)
{
@@ -1057,22 +1112,22 @@ static struct team *team_nl_team_get(struct genl_info *info)
return NULL;
ifindex = nla_get_u32(info->attrs[TEAM_ATTR_TEAM_IFINDEX]);
- rcu_read_lock();
- dev = dev_get_by_index_rcu(net, ifindex);
+ dev = dev_get_by_index(net, ifindex);
if (!dev || dev->netdev_ops != &team_netdev_ops) {
- rcu_read_unlock();
+ if (dev)
+ dev_put(dev);
return NULL;
}
team = netdev_priv(dev);
- spin_lock(&team->lock);
+ mutex_lock(&team->lock);
return team;
}
static void team_nl_team_put(struct team *team)
{
- spin_unlock(&team->lock);
- rcu_read_unlock();
+ mutex_unlock(&team->lock);
+ dev_put(team->dev);
}
static int team_nl_send_generic(struct genl_info *info, struct team *team,
@@ -1487,9 +1542,9 @@ static void team_port_change_check(struct team_port *port, bool linkup)
{
struct team *team = port->team;
- spin_lock(&team->lock);
+ mutex_lock(&team->lock);
__team_port_change_check(port, linkup);
- spin_unlock(&team->lock);
+ mutex_unlock(&team->lock);
}
/************************************