fixeria has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmocom-bb/+/28862 )
Change subject: trxcon: rework trxcon_inst cleanup logic, add trxcon_fsm_pre_term_cb()
......................................................................
trxcon: rework trxcon_inst cleanup logic, add trxcon_fsm_pre_term_cb()
Change-Id: I5eb8ef6f62b1dc949dc60eaa558f123b3b93819c
Related: OS#5599
---
M src/host/trxcon/src/trxcon.c
M src/host/trxcon/src/trxcon_fsm.c
2 files changed, 33 insertions(+), 19 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/62/28862/1
diff --git a/src/host/trxcon/src/trxcon.c b/src/host/trxcon/src/trxcon.c
index 35687d7..539fb47 100644
--- a/src/host/trxcon/src/trxcon.c
+++ b/src/host/trxcon/src/trxcon.c
@@ -267,6 +267,9 @@
osmo_fsm_inst_update_id_f(trxcon->fi, "%u", id);
trxcon->id = id;
+ /* Reparent trxcon_inst from ctx to trxcon->fi */
+ talloc_reparent(ctx, trxcon->fi, trxcon);
+
/* Logging context to be used by both l1ctl and l1sched modules */
trxcon->log_prefix = talloc_asprintf(trxcon, "%s: ",
osmo_fsm_inst_name(trxcon->fi));
@@ -297,18 +300,9 @@
void trxcon_inst_free(struct trxcon_inst *trxcon)
{
- /* Shutdown the scheduler */
- if (trxcon->sched != NULL)
- l1sched_free(trxcon->sched);
- /* Close active connections */
- if (trxcon->l2if != NULL)
- l1ctl_client_conn_close(trxcon->l2if);
- if (trxcon->phyif != NULL)
- trx_if_close(trxcon->phyif);
-
- if (trxcon->fi != NULL)
- osmo_fsm_inst_free(trxcon->fi);
- talloc_free(trxcon);
+ if (trxcon == NULL || trxcon->fi == NULL)
+ return;
+ osmo_fsm_inst_term(trxcon->fi, OSMO_FSM_TERM_REQUEST, NULL);
}
static void l1ctl_conn_accept_cb(struct l1ctl_client *l1c)
@@ -334,10 +328,6 @@
return;
osmo_fsm_inst_dispatch(trxcon->fi, TRXCON_EV_L2IF_FAILURE, NULL);
-
- /* l2if is free()ed by the caller */
- trxcon->l2if = NULL;
- trxcon_inst_free(trxcon);
}
static void print_usage(const char *app)
diff --git a/src/host/trxcon/src/trxcon_fsm.c b/src/host/trxcon/src/trxcon_fsm.c
index 3032764..911f14e 100644
--- a/src/host/trxcon/src/trxcon_fsm.c
+++ b/src/host/trxcon/src/trxcon_fsm.c
@@ -46,10 +46,12 @@
switch (event) {
case TRXCON_EV_PHYIF_FAILURE:
+ trxcon->phyif = NULL;
+ osmo_fsm_inst_term(fi, OSMO_FSM_TERM_ERROR, NULL);
+ break;
case TRXCON_EV_L2IF_FAILURE:
- LOGPFSML(fi, LOGL_NOTICE, "Event %s is not handled\n",
- osmo_fsm_event_name(&trxcon_fsm_def, event));
- /* TODO: osmo_fsm_inst_term(fi, OSMO_FSM_TERM_ERROR, NULL); */
+ trxcon->l2if = NULL;
+ osmo_fsm_inst_term(fi, OSMO_FSM_TERM_ERROR, NULL);
break;
case TRXCON_EV_RESET_FULL_REQ:
if (fi->state != TRXCON_ST_RESET)
@@ -388,6 +390,27 @@
}
}
+static void trxcon_fsm_pre_term_cb(struct osmo_fsm_inst *fi,
+ enum osmo_fsm_term_cause cause)
+{
+ struct trxcon_inst *trxcon = fi->priv;
+
+ if (trxcon == NULL)
+ return;
+
+ /* Shutdown the scheduler */
+ if (trxcon->sched != NULL)
+ l1sched_free(trxcon->sched);
+ /* Close active connections */
+ if (trxcon->l2if != NULL)
+ l1ctl_client_conn_close(trxcon->l2if);
+ if (trxcon->phyif != NULL)
+ trx_if_close(trxcon->phyif);
+
+ talloc_free(trxcon);
+ fi->priv = NULL;
+}
+
static const struct osmo_fsm_state trxcon_fsm_states[] = {
[TRXCON_ST_RESET] = {
.name = "RESET",
@@ -474,6 +497,7 @@
| S(TRXCON_EV_PHY_CONFIG_REQ),
.allstate_action = &trxcon_allstate_action,
.timer_cb = &trxcon_timer_cb,
+ .pre_term = &trxcon_fsm_pre_term_cb,
};
static __attribute__((constructor)) void on_dso_load(void)
--
To view, visit
https://gerrit.osmocom.org/c/osmocom-bb/+/28862
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I5eb8ef6f62b1dc949dc60eaa558f123b3b93819c
Gerrit-Change-Number: 28862
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-MessageType: newchange