dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone
4693f0
commit 73318c5b99571c8da01474ad665e2e2e06ab12bb
4693f0
Author: Richard Cochran <richardcochran@gmail.com>
4693f0
Date:   Sun Feb 5 18:31:27 2017 +0100
4693f0
4693f0
    clock: Force a BMC election when a port link goes down.
4693f0
    
4693f0
    Having one fewer port may affect the result of the BMCA.  This patch
4693f0
    changes the main loop so that a link down event also causes a state
4693f0
    decision event.
4693f0
    
4693f0
    Signed-off-by: Richard Cochran <richardcochran@gmail.com>
4693f0
    Reported-by: Henry Jesuiter <Henry.Jesuiter@alcnetworx.de>
4693f0
4693f0
diff --git a/clock.c b/clock.c
4693f0
index f027305..6ec3e72 100644
4693f0
--- a/clock.c
4693f0
+++ b/clock.c
4693f0
@@ -96,6 +96,7 @@ struct clock {
4693f0
 	int pollfd_valid;
4693f0
 	int nports; /* does not include the UDS port */
4693f0
 	int last_port_number;
4693f0
+	int sde;
4693f0
 	struct hash *index2port;
4693f0
 	int free_running;
4693f0
 	int freq_est_interval;
4693f0
@@ -341,6 +342,11 @@ static void clock_link_status(void *ctx, int index, int linkup)
4693f0
 		port_dispatch(p, EV_FAULT_CLEARED, 0);
4693f0
 	} else {
4693f0
 		port_dispatch(p, EV_FAULT_DETECTED, 0);
4693f0
+		/*
4693f0
+		 * A port going down can affect the BMCA result.
4693f0
+		 * Force a state decision event.
4693f0
+		 */
4693f0
+		c->sde = 1;
4693f0
 	}
4693f0
 }
4693f0
 
4693f0
@@ -1463,7 +1469,7 @@ struct PortIdentity clock_parent_identity(struct clock *c)
4693f0
 
4693f0
 int clock_poll(struct clock *c)
4693f0
 {
4693f0
-	int cnt, i, sde = 0;
4693f0
+	int cnt, i;
4693f0
 	enum fsm_event event;
4693f0
 	struct pollfd *cur;
4693f0
 	struct port *p;
4693f0
@@ -1494,9 +1500,9 @@ int clock_poll(struct clock *c)
4693f0
 			if (cur[i].revents & (POLLIN|POLLPRI)) {
4693f0
 				event = port_event(p, i);
4693f0
 				if (EV_STATE_DECISION_EVENT == event)
4693f0
-					sde = 1;
4693f0
+					c->sde = 1;
4693f0
 				if (EV_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES == event)
4693f0
-					sde = 1;
4693f0
+					c->sde = 1;
4693f0
 				port_dispatch(p, event, 0);
4693f0
 				/* Clear any fault after a little while. */
4693f0
 				if (PS_FAULTY == port_state(p)) {
4693f0
@@ -1525,13 +1531,14 @@ int clock_poll(struct clock *c)
4693f0
 		if (cur[i].revents & (POLLIN|POLLPRI)) {
4693f0
 			event = port_event(c->uds_port, i);
4693f0
 			if (EV_STATE_DECISION_EVENT == event)
4693f0
-				sde = 1;
4693f0
+				c->sde = 1;
4693f0
 		}
4693f0
 	}
4693f0
 
4693f0
-	if (sde)
4693f0
+	if (c->sde) {
4693f0
 		handle_state_decision_event(c);
4693f0
-
4693f0
+		c->sde = 0;
4693f0
+	}
4693f0
 	clock_prune_subscriptions(c);
4693f0
 	return 0;
4693f0
 }