[S] Change in osmo-remsim[master]: Add optional timeout to maintenance mapping
jolly has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-remsim/+/43746?usp=email ) Change subject: Add optional timeout to maintenance mapping ...................................................................... Add optional timeout to maintenance mapping To prevent a broken or crashed application from blocking a mapping for an undefined time, a timeout can be specified. The application that controls the mapping, chooses a timeout that is long enough to complete the operation before the timeout occurs. Related: SYS#8159 Change-Id: I2f7ee24e6c926b65876af2b14da3534555398769 --- M src/server/rest_api.c M src/server/rspro_server.c M src/slotmap.c M src/slotmap.h 4 files changed, 31 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-remsim refs/changes/46/43746/1 diff --git a/src/server/rest_api.c b/src/server/rest_api.c index 62e4c45..05ba3c1 100644 --- a/src/server/rest_api.c +++ b/src/server/rest_api.c @@ -316,6 +316,7 @@ static int api_cb_slotmaps_post(const struct _u_request *req, struct _u_response *resp, void *user_data) { const char *maintenance_str = u_map_get(req->map_url, "maintenance"); + const char *timeout_str = u_map_get(req->map_url, "timeout"); struct rspro_server *srv = g_rps; struct slot_mapping slotmap, *map, *other_map; struct rspro_client_conn *conn; @@ -323,9 +324,11 @@ json_t *json_req = NULL; bool suspending_map = false; bool maintenance; + int timeout; int rc; maintenance = (maintenance_str && !strcmp(maintenance_str, "true")); + timeout = (timeout_str) ? atoi(timeout_str) : 0; json_req = ulfius_get_json_body_request(req, &json_err); if (!json_req) { @@ -368,6 +371,8 @@ slotmap_state_change(map, SLMAP_S_INACTIVE, NULL); goto done; } + } else { + map->maintenance_timeout = timeout; } /* If we are suspended an exisisting maping, we stay inactive until the mapping was removed. */ diff --git a/src/server/rspro_server.c b/src/server/rspro_server.c index 9fbdaa9..48ccd6b 100644 --- a/src/server/rspro_server.c +++ b/src/server/rspro_server.c @@ -407,6 +407,21 @@ } } +/* Handle timeout for maintenance mapping. */ +static void maintenance_timeout(void *data) +{ + struct slot_mapping *map = data; + struct rspro_client_conn *conn; + + conn = bankd_conn_by_id(g_rps, map->bank.bank_id); + if (!conn) + return; + + /* The timer is only running in ACTIVE state, so we trigger deletion now. */ + slotmap_state_change(map, SLMAP_S_DELETE_REQ, &conn->bank.maps_delreq); + osmo_fsm_inst_dispatch(conn->fi, CLNTC_E_PUSH, NULL); +} + static void clnt_st_connected_bankd(struct osmo_fsm_inst *fi, uint32_t event, void *data) { struct rspro_client_conn *conn = fi->priv; @@ -437,6 +452,11 @@ client_conn_send(conn, pdu); slotmap_state_change(map, SLMAP_S_DELETING, &conn->bank.maps_deleting); } + /* If maintenance mapping has been created, start maintenance timeout timer. */ + if (map->maintenance && map->maintenance_timeout) { + osmo_timer_setup(&map->maintenance_timer, maintenance_timeout, map); + osmo_timer_schedule(&map->maintenance_timer, map->maintenance_timeout, 0); + } break; case CLNTC_E_REMOVE_MAP_RES: /* Bankd acknowledges mapping was removed */ rx = data; @@ -478,6 +498,8 @@ } /* If maintenance mapping is to be deleted, reactivate inactive mapping. */ if (map->maintenance) { + /* Delete maintenance timeout timer. */ + osmo_timer_del(&map->maintenance_timer); /* Search for non maintenance mapping. */ other_map = slotmap_by_bank_and_maintenance(slotmaps, &map->bank, false); if (other_map) { diff --git a/src/slotmap.c b/src/slotmap.c index 84bebea..72eac8f 100644 --- a/src/slotmap.c +++ b/src/slotmap.c @@ -171,6 +171,7 @@ llist_del(&map->list); #ifdef REMSIM_SERVER + osmo_timer_del(&map->maintenance_timer); llist_del(&map->bank_list); #endif diff --git a/src/slotmap.h b/src/slotmap.h index 225d453..07a80db 100644 --- a/src/slotmap.h +++ b/src/slotmap.h @@ -3,6 +3,7 @@ #include <stdbool.h> #include <pthread.h> #include <osmocom/core/linuxlist.h> +#include <osmocom/core/timer.h> #define REMSIM_SERVER 1 @@ -62,6 +63,8 @@ enum slot_mapping_state state; /* this mapping is for maintenenance */ bool maintenance; + int maintenance_timeout; + struct osmo_timer_list maintenance_timer; /* this mapping is (to be) suspended */ bool suspend; #endif -- To view, visit https://gerrit.osmocom.org/c/osmo-remsim/+/43746?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmo-remsim Gerrit-Branch: master Gerrit-Change-Id: I2f7ee24e6c926b65876af2b14da3534555398769 Gerrit-Change-Number: 43746 Gerrit-PatchSet: 1 Gerrit-Owner: jolly <andreas@eversberg.eu>
participants (1)
-
jolly