bankd: Implement new ResetStateReq

Change-Id: Ib794e605162903a2b2c4f4516887ec91fc8d139a
This commit is contained in:
Harald Welte 2019-12-04 19:51:32 +01:00
parent cd7fcd717c
commit f34fb79cc1
3 changed files with 30 additions and 0 deletions

View File

@ -150,6 +150,7 @@ static int bankd_srvc_handle_rx(struct rspro_server_conn *srvc, const RsproPDU_t
{
const CreateMappingReq_t *creq = NULL;
const RemoveMappingReq_t *rreq = NULL;
struct bankd_worker *worker;
struct slot_mapping *map;
struct bank_slot bs;
struct client_slot cs;
@ -230,6 +231,19 @@ send_resp:
}
server_conn_send_rspro(srvc, resp);
break;
case RsproPDUchoice_PR_resetStateReq:
/* delete all slotmaps */
slotmap_del_all(g_bankd->slotmaps);
/* notify all workers about maps having disappeared */
pthread_mutex_lock(&g_bankd->workers_mutex);
llist_for_each_entry(worker, &g_bankd->workers, list) {
pthread_kill(worker->thread, SIGMAPDEL);
}
pthread_mutex_unlock(&g_bankd->workers_mutex);
/* send response to server */
resp = rspro_gen_ResetStateRes(ResultCode_ok);
server_conn_send_rspro(srvc, resp);
break;
default:
LOGPFSML(srvc->fi, LOGL_ERROR, "Unknown/Unsupported RSPRO PDU type: %u\n",
pdu->msg.present);

View File

@ -159,6 +159,19 @@ void slotmap_del(struct slotmaps *maps, struct slot_mapping *map)
slotmaps_unlock(maps);
}
/* thread-safe removal of all bank<->client maps */
void slotmap_del_all(struct slotmaps *maps)
{
struct slot_mapping *map, *map2;
slotmaps_wrlock(maps);
llist_for_each_entry_safe(map, map2, &maps->mappings, list) {
_slotmap_del(maps, map);
}
slotmaps_unlock(maps);
}
struct slotmaps *slotmap_init(void *ctx)
{
struct slotmaps *sm = talloc_zero(ctx, struct slotmaps);

View File

@ -83,6 +83,9 @@ struct slot_mapping *slotmap_add(struct slotmaps *maps, const struct bank_slot *
void slotmap_del(struct slotmaps *maps, struct slot_mapping *map);
void _slotmap_del(struct slotmaps *maps, struct slot_mapping *map);
/* thread-safe removal of all bank<->client maps */
void slotmap_del_all(struct slotmaps *maps);
/* initialize the entire map collection */
struct slotmaps *slotmap_init(void *ctx);