Commit 01048d9a authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

team: allow to specify one option instance to be send to userspace

No need to walk through option instance list and look for ->changed ==
true when called knows exactly what one option instance changed.

Also use lists to pass option instances needed to be present in netlink
message.
Signed-off-by: default avatarJiri Pirko <jpirko@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3221c646
...@@ -89,6 +89,7 @@ static void team_refresh_port_linkup(struct team_port *port) ...@@ -89,6 +89,7 @@ static void team_refresh_port_linkup(struct team_port *port)
struct team_option_inst { /* One for each option instance */ struct team_option_inst { /* One for each option instance */
struct list_head list; struct list_head list;
struct list_head tmp_list;
struct team_option *option; struct team_option *option;
struct team_option_inst_info info; struct team_option_inst_info info;
bool changed; bool changed;
...@@ -319,6 +320,8 @@ static void __team_options_unregister(struct team *team, ...@@ -319,6 +320,8 @@ static void __team_options_unregister(struct team *team,
} }
static void __team_options_change_check(struct team *team); static void __team_options_change_check(struct team *team);
static void __team_option_inst_change(struct team *team,
struct team_option_inst *opt_inst);
int team_options_register(struct team *team, int team_options_register(struct team *team,
const struct team_option *option, const struct team_option *option,
...@@ -383,8 +386,7 @@ static int team_option_set(struct team *team, ...@@ -383,8 +386,7 @@ static int team_option_set(struct team *team,
if (err) if (err)
return err; return err;
opt_inst->changed = true; __team_option_inst_change(team, opt_inst);
__team_options_change_check(team);
return err; return err;
} }
...@@ -1565,35 +1567,15 @@ static int team_nl_send_generic(struct genl_info *info, struct team *team, ...@@ -1565,35 +1567,15 @@ static int team_nl_send_generic(struct genl_info *info, struct team *team,
return err; return err;
} }
static int team_nl_fill_options_get(struct sk_buff *skb, static int team_nl_fill_one_option_get(struct sk_buff *skb, struct team *team,
u32 pid, u32 seq, int flags, struct team_option_inst *opt_inst)
struct team *team, bool fillall)
{ {
struct nlattr *option_list;
void *hdr;
struct team_option_inst *opt_inst;
int err;
hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags,
TEAM_CMD_OPTIONS_GET);
if (IS_ERR(hdr))
return PTR_ERR(hdr);
if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
goto nla_put_failure;
option_list = nla_nest_start(skb, TEAM_ATTR_LIST_OPTION);
if (!option_list)
goto nla_put_failure;
list_for_each_entry(opt_inst, &team->option_inst_list, list) {
struct nlattr *option_item; struct nlattr *option_item;
struct team_option *option = opt_inst->option; struct team_option *option = opt_inst->option;
struct team_option_inst_info *opt_inst_info; struct team_option_inst_info *opt_inst_info;
struct team_gsetter_ctx ctx; struct team_gsetter_ctx ctx;
int err;
/* Include only changed options if fill all mode is not on */
if (!fillall && !opt_inst->changed)
continue;
option_item = nla_nest_start(skb, TEAM_ATTR_ITEM_OPTION); option_item = nla_nest_start(skb, TEAM_ATTR_ITEM_OPTION);
if (!option_item) if (!option_item)
goto nla_put_failure; goto nla_put_failure;
...@@ -1604,8 +1586,7 @@ static int team_nl_fill_options_get(struct sk_buff *skb, ...@@ -1604,8 +1586,7 @@ static int team_nl_fill_options_get(struct sk_buff *skb,
goto nla_put_failure; goto nla_put_failure;
opt_inst->changed = false; opt_inst->changed = false;
} }
if (opt_inst->removed && if (opt_inst->removed && nla_put_flag(skb, TEAM_ATTR_OPTION_REMOVED))
nla_put_flag(skb, TEAM_ATTR_OPTION_REMOVED))
goto nla_put_failure; goto nla_put_failure;
opt_inst_info = &opt_inst->info; opt_inst_info = &opt_inst->info;
...@@ -1626,8 +1607,7 @@ static int team_nl_fill_options_get(struct sk_buff *skb, ...@@ -1626,8 +1607,7 @@ static int team_nl_fill_options_get(struct sk_buff *skb,
err = team_option_get(team, opt_inst, &ctx); err = team_option_get(team, opt_inst, &ctx);
if (err) if (err)
goto errout; goto errout;
if (nla_put_u32(skb, TEAM_ATTR_OPTION_DATA, if (nla_put_u32(skb, TEAM_ATTR_OPTION_DATA, ctx.data.u32_val))
ctx.data.u32_val))
goto nla_put_failure; goto nla_put_failure;
break; break;
case TEAM_OPTION_TYPE_STRING: case TEAM_OPTION_TYPE_STRING:
...@@ -1646,8 +1626,8 @@ static int team_nl_fill_options_get(struct sk_buff *skb, ...@@ -1646,8 +1626,8 @@ static int team_nl_fill_options_get(struct sk_buff *skb,
err = team_option_get(team, opt_inst, &ctx); err = team_option_get(team, opt_inst, &ctx);
if (err) if (err)
goto errout; goto errout;
if (nla_put(skb, TEAM_ATTR_OPTION_DATA, if (nla_put(skb, TEAM_ATTR_OPTION_DATA, ctx.data.bin_val.len,
ctx.data.bin_val.len, ctx.data.bin_val.ptr)) ctx.data.bin_val.ptr))
goto nla_put_failure; goto nla_put_failure;
break; break;
case TEAM_OPTION_TYPE_BOOL: case TEAM_OPTION_TYPE_BOOL:
...@@ -1664,6 +1644,39 @@ static int team_nl_fill_options_get(struct sk_buff *skb, ...@@ -1664,6 +1644,39 @@ static int team_nl_fill_options_get(struct sk_buff *skb,
BUG(); BUG();
} }
nla_nest_end(skb, option_item); nla_nest_end(skb, option_item);
return 0;
nla_put_failure:
err = -EMSGSIZE;
errout:
return err;
}
static int team_nl_fill_options_get(struct sk_buff *skb,
u32 pid, u32 seq, int flags,
struct team *team,
struct list_head *sel_opt_inst_list)
{
struct nlattr *option_list;
void *hdr;
struct team_option_inst *opt_inst;
int err;
hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags,
TEAM_CMD_OPTIONS_GET);
if (IS_ERR(hdr))
return PTR_ERR(hdr);
if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
goto nla_put_failure;
option_list = nla_nest_start(skb, TEAM_ATTR_LIST_OPTION);
if (!option_list)
goto nla_put_failure;
list_for_each_entry(opt_inst, sel_opt_inst_list, tmp_list) {
err = team_nl_fill_one_option_get(skb, team, opt_inst);
if (err)
goto errout;
} }
nla_nest_end(skb, option_list); nla_nest_end(skb, option_list);
...@@ -1680,9 +1693,14 @@ static int team_nl_fill_options_get_all(struct sk_buff *skb, ...@@ -1680,9 +1693,14 @@ static int team_nl_fill_options_get_all(struct sk_buff *skb,
struct genl_info *info, int flags, struct genl_info *info, int flags,
struct team *team) struct team *team)
{ {
struct team_option_inst *opt_inst;
LIST_HEAD(sel_opt_inst_list);
list_for_each_entry(opt_inst, &team->option_inst_list, list)
list_add_tail(&opt_inst->tmp_list, &sel_opt_inst_list);
return team_nl_fill_options_get(skb, info->snd_pid, return team_nl_fill_options_get(skb, info->snd_pid,
info->snd_seq, NLM_F_ACK, info->snd_seq, NLM_F_ACK,
team, true); team, &sel_opt_inst_list);
} }
static int team_nl_cmd_options_get(struct sk_buff *skb, struct genl_info *info) static int team_nl_cmd_options_get(struct sk_buff *skb, struct genl_info *info)
...@@ -1941,7 +1959,8 @@ static struct genl_multicast_group team_change_event_mcgrp = { ...@@ -1941,7 +1959,8 @@ static struct genl_multicast_group team_change_event_mcgrp = {
.name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME,
}; };
static int team_nl_send_event_options_get(struct team *team) static int team_nl_send_event_options_get(struct team *team,
struct list_head *sel_opt_inst_list)
{ {
struct sk_buff *skb; struct sk_buff *skb;
int err; int err;
...@@ -1951,7 +1970,7 @@ static int team_nl_send_event_options_get(struct team *team) ...@@ -1951,7 +1970,7 @@ static int team_nl_send_event_options_get(struct team *team)
if (!skb) if (!skb)
return -ENOMEM; return -ENOMEM;
err = team_nl_fill_options_get(skb, 0, 0, 0, team, false); err = team_nl_fill_options_get(skb, 0, 0, 0, team, sel_opt_inst_list);
if (err < 0) if (err < 0)
goto err_fill; goto err_fill;
...@@ -2021,12 +2040,31 @@ static void team_nl_fini(void) ...@@ -2021,12 +2040,31 @@ static void team_nl_fini(void)
static void __team_options_change_check(struct team *team) static void __team_options_change_check(struct team *team)
{ {
int err; int err;
struct team_option_inst *opt_inst;
LIST_HEAD(sel_opt_inst_list);
err = team_nl_send_event_options_get(team); list_for_each_entry(opt_inst, &team->option_inst_list, list) {
if (opt_inst->changed)
list_add_tail(&opt_inst->tmp_list, &sel_opt_inst_list);
}
err = team_nl_send_event_options_get(team, &sel_opt_inst_list);
if (err) if (err)
netdev_warn(team->dev, "Failed to send options change via netlink\n"); netdev_warn(team->dev, "Failed to send options change via netlink\n");
} }
static void __team_option_inst_change(struct team *team,
struct team_option_inst *sel_opt_inst)
{
int err;
LIST_HEAD(sel_opt_inst_list);
sel_opt_inst->changed = true;
list_add(&sel_opt_inst->tmp_list, &sel_opt_inst_list);
err = team_nl_send_event_options_get(team, &sel_opt_inst_list);
if (err)
netdev_warn(team->dev, "Failed to send option change via netlink\n");
}
/* rtnl lock is held */ /* rtnl lock is held */
static void __team_port_change_check(struct team_port *port, bool linkup) static void __team_port_change_check(struct team_port *port, bool linkup)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment