Skip to content

Commit

Permalink
teamd: do not remove ports from team dev in case of take over mode
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
  • Loading branch information
jpirko committed Feb 26, 2014
1 parent ad11b18 commit a3cf546
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 34 deletions.
32 changes: 2 additions & 30 deletions teamd/teamd.c
Expand Up @@ -329,7 +329,7 @@ static int teamd_flush_ports(struct teamd_context *ctx)
int err;

teamd_for_each_tdport(tdport, ctx) {
err = teamd_port_remove(ctx, tdport->ifname);
err = teamd_port_remove(ctx, tdport);
if (err)
return err;
}
Expand Down Expand Up @@ -828,34 +828,6 @@ static int teamd_set_hwaddr(struct teamd_context *ctx)
return err;
}

int teamd_port_add(struct teamd_context *ctx, const char *port_name)
{
int err;
uint32_t ifindex;

ifindex = team_ifname2ifindex(ctx->th, port_name);
teamd_log_dbg("%s: Adding port (found ifindex \"%d\").",
port_name, ifindex);
err = team_port_add(ctx->th, ifindex);
if (err)
teamd_log_err("%s: Failed to add port.", port_name);
return err;
}

int teamd_port_remove(struct teamd_context *ctx, const char *port_name)
{
int err;
uint32_t ifindex;

ifindex = team_ifname2ifindex(ctx->th, port_name);
teamd_log_dbg("%s: Removing port (found ifindex \"%d\").",
port_name, ifindex);
err = team_port_remove(ctx->th, ifindex);
if (err)
teamd_log_err("%s: Failed to remove port.", port_name);
return err;
}

static int teamd_add_ports(struct teamd_context *ctx)
{
int err;
Expand All @@ -866,7 +838,7 @@ static int teamd_add_ports(struct teamd_context *ctx)
return 0;

teamd_config_for_each_key(key, ctx, "$.ports") {
err = teamd_port_add(ctx, key);
err = teamd_port_add_ifname(ctx, key);
if (err)
return err;
}
Expand Down
5 changes: 3 additions & 2 deletions teamd/teamd.h
Expand Up @@ -304,8 +304,9 @@ static inline unsigned int teamd_port_count(struct teamd_context *ctx)
return ctx->port_obj_list_count;
}

int teamd_port_add(struct teamd_context *ctx, const char *port_name);
int teamd_port_remove(struct teamd_context *ctx, const char *port_name);
int teamd_port_add_ifname(struct teamd_context *ctx, const char *port_name);
int teamd_port_remove_ifname(struct teamd_context *ctx, const char *port_name);
int teamd_port_remove(struct teamd_context *ctx, struct teamd_port *tdport);
int teamd_port_enabled(struct teamd_context *ctx, struct teamd_port *tdport,
bool *enabled);
int teamd_port_prio(struct teamd_context *ctx, struct teamd_port *tdport);
Expand Down
4 changes: 2 additions & 2 deletions teamd/teamd_ctl.c
Expand Up @@ -101,7 +101,7 @@ static int teamd_ctl_method_port_add(struct teamd_context *ctx,
return ops->reply_err(ops_priv, "InvalidArgs", "Did not receive correct message arguments.");
teamd_log_dbgx(ctx, 2, "port_devname \"%s\"", port_devname);

err = teamd_port_add(ctx, port_devname);
err = teamd_port_add_ifname(ctx, port_devname);
switch (err) {
case -ENODEV:
return ops->reply_err(ops_priv, "NoSuchDev", "No such device.");
Expand All @@ -125,7 +125,7 @@ static int teamd_ctl_method_port_remove(struct teamd_context *ctx,
return ops->reply_err(ops_priv, "InvalidArgs", "Did not receive correct message arguments.");
teamd_log_dbgx(ctx, 2, "port_devname \"%s\"", port_devname);

err = teamd_port_remove(ctx, port_devname);
err = teamd_port_remove_ifname(ctx, port_devname);
switch (err) {
case -ENODEV:
return ops->reply_err(ops_priv, "NoSuchDev", "No such device.");
Expand Down
41 changes: 41 additions & 0 deletions teamd/teamd_per_port.c
Expand Up @@ -331,6 +331,47 @@ struct teamd_port *teamd_get_next_tdport(struct teamd_context *ctx,
return tdport;
}

int teamd_port_add_ifname(struct teamd_context *ctx, const char *port_name)
{
int err;
uint32_t ifindex;

ifindex = team_ifname2ifindex(ctx->th, port_name);
teamd_log_dbg("%s: Adding port (found ifindex \"%d\").",
port_name, ifindex);
err = team_port_add(ctx->th, ifindex);
if (err)
teamd_log_err("%s: Failed to add port.", port_name);
return err;
}

int teamd_port_remove(struct teamd_context *ctx, struct teamd_port *tdport)
{
struct port_obj *port_obj;
int err;

teamd_log_dbg("%s: Removing port (found ifindex \"%d\").",
tdport->ifname, tdport->ifindex);
if (ctx->take_over) {
port_obj = get_container(tdport, struct port_obj, port);
port_obj_remove(ctx, port_obj);
return 0;
}
err = team_port_remove(ctx->th, tdport->ifindex);
if (err)
teamd_log_err("%s: Failed to remove port.", tdport->ifname);
return err;
}

int teamd_port_remove_ifname(struct teamd_context *ctx, const char *port_name)
{
struct teamd_port *tdport = teamd_get_port_by_ifname(ctx, port_name);

if (!tdport)
return -ENODEV;
return teamd_port_remove(ctx, tdport);
}

int teamd_port_enabled(struct teamd_context *ctx, struct teamd_port *tdport,
bool *enabled)
{
Expand Down

0 comments on commit a3cf546

Please sign in to comment.