LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0011-teamd-do-not-remove-ports-from-team-dev-in-case-of-t.patch of Package libteam (Project home:ods:ppc64)

From a3cf54617487a05dc1666a856deace46f9c2df5a Mon Sep 17 00:00:00 2001
From: Jiri Pirko <jiri@resnulli.us>
Date: Wed, 26 Feb 2014 12:17:27 +0100
Subject: [patch libteam 3/3] teamd: do not remove ports from team dev in case
 of take over mode

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 teamd/teamd.c          | 32 ++------------------------------
 teamd/teamd.h          |  5 +++--
 teamd/teamd_ctl.c      |  4 ++--
 teamd/teamd_per_port.c | 41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 34 deletions(-)

diff --git a/teamd/teamd.c b/teamd/teamd.c
index f8e2347..d06e33f 100644
--- a/teamd/teamd.c
+++ b/teamd/teamd.c
@@ -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;
 	}
@@ -828,34 +828,6 @@ free_hwaddr:
 	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;
@@ -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;
 	}
diff --git a/teamd/teamd.h b/teamd/teamd.h
index e644171..509bbb9 100644
--- a/teamd/teamd.h
+++ b/teamd/teamd.h
@@ -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);
diff --git a/teamd/teamd_ctl.c b/teamd/teamd_ctl.c
index bc554ed..bb1d3d1 100644
--- a/teamd/teamd_ctl.c
+++ b/teamd/teamd_ctl.c
@@ -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.");
@@ -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.");
diff --git a/teamd/teamd_per_port.c b/teamd/teamd_per_port.c
index a596a78..8ca4447 100644
--- a/teamd/teamd_per_port.c
+++ b/teamd/teamd_per_port.c
@@ -331,6 +331,47 @@ next_one:
 	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)
 {
-- 
1.8.5.3