LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0004-lb-enable-disable-port-according-to-linkwatch-state.patch of Package libteam (Project home:ods:ppc64)

From fd0cff78f1c6235bead2530cbaf8830aa65dd9c4 Mon Sep 17 00:00:00 2001
From: Jiri Pirko <jiri@resnulli.us>
Date: Mon, 3 Feb 2014 08:34:49 +0100
Subject: [patch libteam] lb: enable/disable port according to linkwatch state

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 teamd/teamd.h                    |  3 +++
 teamd/teamd_per_port.c           | 34 ++++++++++++++++++++++++++++++++++
 teamd/teamd_runner_lacp.c        | 33 +++------------------------------
 teamd/teamd_runner_loadbalance.c | 10 ++++++++++
 4 files changed, 50 insertions(+), 30 deletions(-)

diff --git a/teamd/teamd.h b/teamd/teamd.h
index 122df30..103a2bc 100644
--- a/teamd/teamd.h
+++ b/teamd/teamd.h
@@ -308,6 +308,9 @@ int teamd_port_remove(struct teamd_context *ctx, const char *port_name);
 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);
+int teamd_port_check_enable(struct teamd_context *ctx,
+			    struct teamd_port *tdport,
+			    bool should_enable, bool should_disable);
 
 static inline bool teamd_port_present(struct teamd_context *ctx,
 				      struct teamd_port *tdport)
diff --git a/teamd/teamd_per_port.c b/teamd/teamd_per_port.c
index 5ca74b9..a596a78 100644
--- a/teamd/teamd_per_port.c
+++ b/teamd/teamd_per_port.c
@@ -364,3 +364,37 @@ int teamd_port_prio(struct teamd_context *ctx, struct teamd_port *tdport)
 	}
 	return prio;
 }
+
+int teamd_port_check_enable(struct teamd_context *ctx,
+			    struct teamd_port *tdport,
+			    bool should_enable, bool should_disable)
+{
+	bool new_enabled_state;
+	bool curr_enabled_state;
+	int err;
+
+	if (!teamd_port_present(ctx, tdport))
+		return 0;
+	err = teamd_port_enabled(ctx, tdport, &curr_enabled_state);
+	if (err)
+		return err;
+
+	if (!curr_enabled_state && should_enable)
+		new_enabled_state = true;
+	else if (curr_enabled_state && should_disable)
+		new_enabled_state = false;
+	else
+		return 0;
+
+	teamd_log_dbg("%s: %s port", tdport->ifname,
+		      new_enabled_state ? "Enabling": "Disabling");
+	err = team_set_port_enabled(ctx->th, tdport->ifindex,
+				    new_enabled_state);
+	if (err) {
+		teamd_log_err("%s: Failed to %s port.", tdport->ifname,
+			      new_enabled_state ? "enable": "disable");
+		if (!TEAMD_ENOENT(err))
+			return err;
+	}
+	return 0;
+}
diff --git a/teamd/teamd_runner_lacp.c b/teamd/teamd_runner_lacp.c
index b1aebeb..14f9473 100644
--- a/teamd/teamd_runner_lacp.c
+++ b/teamd/teamd_runner_lacp.c
@@ -337,36 +337,9 @@ static int lacp_port_should_be_disabled(struct lacp_port *lacp_port)
 
 static int lacp_port_update_enabled(struct lacp_port *lacp_port)
 {
-	struct teamd_port *tdport = lacp_port->tdport;
-	struct teamd_context *ctx = lacp_port->ctx;
-	bool new_enabled_state;
-	bool curr_enabled_state;
-	int err;
-
-	if (!teamd_port_present(ctx, tdport))
-		return 0;
-	err = teamd_port_enabled(ctx, tdport, &curr_enabled_state);
-	if (err)
-		return err;
-
-	if (!curr_enabled_state && lacp_port_should_be_enabled(lacp_port))
-		new_enabled_state = true;
-	else if (curr_enabled_state && lacp_port_should_be_disabled(lacp_port))
-		new_enabled_state = false;
-	else
-		return 0;
-
-	teamd_log_dbg("%s: %s port", tdport->ifname,
-		      new_enabled_state ? "Enabling": "Disabling");
-	err = team_set_port_enabled(ctx->th, tdport->ifindex,
-				    new_enabled_state);
-	if (err) {
-		teamd_log_err("%s: Failed to %s port.", tdport->ifname,
-			      new_enabled_state ? "enable": "disable");
-		if (!TEAMD_ENOENT(err))
-			return err;
-	}
-	return 0;
+	return teamd_port_check_enable(lacp_port->ctx, lacp_port->tdport,
+				       lacp_port_should_be_enabled(lacp_port),
+				       lacp_port_should_be_disabled(lacp_port));
 }
 
 static bool lacp_ports_aggregable(struct lacp_port *lacp_port1,
diff --git a/teamd/teamd_runner_loadbalance.c b/teamd/teamd_runner_loadbalance.c
index 950c6ad..6a01f61 100644
--- a/teamd/teamd_runner_loadbalance.c
+++ b/teamd/teamd_runner_loadbalance.c
@@ -51,9 +51,19 @@ static void lb_event_watch_port_removed(struct teamd_context *ctx,
 	teamd_balancer_port_removed(lb->tb, tdport);
 }
 
+static int lb_event_watch_port_link_changed(struct teamd_context *ctx,
+					    struct teamd_port *tdport,
+					    void *priv)
+{
+	bool port_up = teamd_link_watch_port_up(ctx, tdport);
+
+	return teamd_port_check_enable(ctx, tdport, port_up, !port_up);
+}
+
 static const struct teamd_event_watch_ops lb_port_watch_ops = {
 	.port_added = lb_event_watch_port_added,
 	.port_removed = lb_event_watch_port_removed,
+	.port_link_changed = lb_event_watch_port_link_changed,
 };
 
 static int lb_init(struct teamd_context *ctx, void *priv)
-- 
1.8.5.3