Rationalize the port reset logic.
This commit makes each pair of port functions, open/close and initialize/disable, balance each other in how they allocate or free resources. This change lays some ground work to allow proper fault handling and disable/enable logic later on. Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
1b78bb0b54
commit
2607806579
70
port.c
70
port.c
|
@ -518,6 +518,54 @@ out:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* port initialize and disable
|
||||||
|
*/
|
||||||
|
static int port_is_enabled(struct port *p)
|
||||||
|
{
|
||||||
|
switch (p->state) {
|
||||||
|
case PS_INITIALIZING:
|
||||||
|
case PS_FAULTY:
|
||||||
|
case PS_DISABLED:
|
||||||
|
return 0;
|
||||||
|
case PS_LISTENING:
|
||||||
|
case PS_PRE_MASTER:
|
||||||
|
case PS_MASTER:
|
||||||
|
case PS_GRAND_MASTER:
|
||||||
|
case PS_PASSIVE:
|
||||||
|
case PS_UNCALIBRATED:
|
||||||
|
case PS_SLAVE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void port_disable(struct port *p)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (p->last_follow_up) {
|
||||||
|
msg_put(p->last_follow_up);
|
||||||
|
p->last_follow_up = NULL;
|
||||||
|
}
|
||||||
|
if (p->last_sync) {
|
||||||
|
msg_put(p->last_sync);
|
||||||
|
p->last_sync = NULL;
|
||||||
|
}
|
||||||
|
if (p->delay_req) {
|
||||||
|
msg_put(p->delay_req);
|
||||||
|
p->delay_req = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free_foreign_masters(p);
|
||||||
|
clock_remove_fda(p->clock, p, p->fda);
|
||||||
|
transport_close(p->trp, &p->fda);
|
||||||
|
|
||||||
|
for (i = 0; i < N_TIMER_FDS; i++) {
|
||||||
|
close(p->fda.fd[FD_ANNOUNCE_TIMER + i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int port_initialize(struct port *p)
|
static int port_initialize(struct port *p)
|
||||||
{
|
{
|
||||||
int fd[N_TIMER_FDS], i;
|
int fd[N_TIMER_FDS], i;
|
||||||
|
@ -790,21 +838,10 @@ static void process_sync(struct port *p, struct ptp_message *m)
|
||||||
|
|
||||||
void port_close(struct port *p)
|
void port_close(struct port *p)
|
||||||
{
|
{
|
||||||
int i;
|
if (port_is_enabled(p)) {
|
||||||
|
port_disable(p);
|
||||||
if (p->last_follow_up)
|
|
||||||
msg_put(p->last_follow_up);
|
|
||||||
if (p->last_sync)
|
|
||||||
msg_put(p->last_sync);
|
|
||||||
if (p->delay_req)
|
|
||||||
msg_put(p->delay_req);
|
|
||||||
|
|
||||||
free_foreign_masters(p);
|
|
||||||
transport_close(p->trp, &p->fda);
|
|
||||||
transport_destroy(p->trp);
|
|
||||||
for (i = 0; i < N_TIMER_FDS; i++) {
|
|
||||||
close(p->fda.fd[FD_ANNOUNCE_TIMER + i]);
|
|
||||||
}
|
}
|
||||||
|
transport_destroy(p->trp);
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,6 +887,9 @@ void port_dispatch(struct port *p, enum fsm_event event, int mdiff)
|
||||||
* port immediately, we can skip right to listening
|
* port immediately, we can skip right to listening
|
||||||
* state if all goes well.
|
* state if all goes well.
|
||||||
*/
|
*/
|
||||||
|
if (port_is_enabled(p)) {
|
||||||
|
port_disable(p);
|
||||||
|
}
|
||||||
p->state = port_initialize(p) ? PS_FAULTY : PS_LISTENING;
|
p->state = port_initialize(p) ? PS_FAULTY : PS_LISTENING;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -868,8 +908,10 @@ void port_dispatch(struct port *p, enum fsm_event event, int mdiff)
|
||||||
|
|
||||||
switch (next) {
|
switch (next) {
|
||||||
case PS_INITIALIZING:
|
case PS_INITIALIZING:
|
||||||
|
break;
|
||||||
case PS_FAULTY:
|
case PS_FAULTY:
|
||||||
case PS_DISABLED:
|
case PS_DISABLED:
|
||||||
|
port_disable(p);
|
||||||
break;
|
break;
|
||||||
case PS_LISTENING:
|
case PS_LISTENING:
|
||||||
port_set_announce_tmo(p);
|
port_set_announce_tmo(p);
|
||||||
|
|
Loading…
Reference in New Issue