From: Rafael Zalamena Date: Fri, 17 Apr 2020 15:18:24 +0000 (-0300) Subject: zebra: gracefully shutdown fpm module X-Git-Tag: base_7.4~54^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=98a87504819a2e7ed0a9436390b6289998e560d0;p=matthieu%2Ffrr.git zebra: gracefully shutdown fpm module Lets stop and free all resources before shutting down. Signed-off-by: Rafael Zalamena --- diff --git a/zebra/dplane_fpm_nl.c b/zebra/dplane_fpm_nl.c index a697a306bf..ffc92babf5 100644 --- a/zebra/dplane_fpm_nl.c +++ b/zebra/dplane_fpm_nl.c @@ -1026,18 +1026,52 @@ static int fpm_nl_start(struct zebra_dplane_provider *prov) return 0; } -static int fpm_nl_finish(struct zebra_dplane_provider *prov, bool early) +static int fpm_nl_finish_early(struct fpm_nl_ctx *fnc) { - struct fpm_nl_ctx *fnc; + /* Disable all events and close socket. */ + THREAD_OFF(fnc->t_ribreset); + THREAD_OFF(fnc->t_ribwalk); + THREAD_OFF(fnc->t_rmacreset); + THREAD_OFF(fnc->t_rmacwalk); + thread_cancel_async(fnc->fthread->master, &fnc->t_read, NULL); + thread_cancel_async(fnc->fthread->master, &fnc->t_write, NULL); + thread_cancel_async(fnc->fthread->master, &fnc->t_connect, NULL); - fnc = dplane_provider_get_data(prov); + if (fnc->socket != -1) { + close(fnc->socket); + fnc->socket = -1; + } + + return 0; +} + +static int fpm_nl_finish_late(struct fpm_nl_ctx *fnc) +{ + /* Stop the running thread. */ + frr_pthread_stop(fnc->fthread, NULL); + + /* Free all allocated resources. */ + pthread_mutex_destroy(&fnc->obuf_mutex); + pthread_mutex_destroy(&fnc->ctxqueue_mutex); stream_free(fnc->ibuf); stream_free(fnc->obuf); - close(fnc->socket); + free(gfnc); + gfnc = NULL; return 0; } +static int fpm_nl_finish(struct zebra_dplane_provider *prov, bool early) +{ + struct fpm_nl_ctx *fnc; + + fnc = dplane_provider_get_data(prov); + if (early) + return fpm_nl_finish_early(fnc); + + return fpm_nl_finish_late(fnc); +} + static int fpm_nl_process(struct zebra_dplane_provider *prov) { struct zebra_dplane_ctx *ctx;