From d3fe77259dbd1e49d73998001904fb975679343a Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Thu, 1 Feb 2024 15:20:14 +0700 Subject: [PATCH] LU-17496 lnet: retry cleanup during shutdown LNet can work a little harder to cleanup during teardown to avoid an assert on module removal. Signed-off-by: Shaun Tancheff Change-Id: Ic19c7774fa354b55bbfe21e8d87171dd024748c4 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53876 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Serguei Smirnov Reviewed-by: Oleg Drokin --- lnet/include/lnet/api.h | 2 +- lnet/lnet/api-ni.c | 6 +++--- lnet/lnet/lib-md.c | 16 ++++++++++++---- lnet/lnet/peer.c | 6 +++++- lnet/selftest/rpc.c | 2 +- lustre/ptlrpc/events.c | 2 +- 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lnet/include/lnet/api.h b/lnet/include/lnet/api.h index 757d264..93510f4 100644 --- a/lnet/include/lnet/api.h +++ b/lnet/include/lnet/api.h @@ -128,7 +128,7 @@ int LNetMDBind(const struct lnet_md *md_in, int __LNetMDUnlink(struct lnet_handle_md md_in, bool discard); #define LNetMDUnlink(handle) __LNetMDUnlink(handle, false) -void lnet_assert_handler_unused(lnet_handler_t handler); +bool lnet_assert_handler_unused(lnet_handler_t handler, bool assert); /** @} lnet_md */ /** \defgroup lnet_data Data movement operations diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 2acdb38..0dc9107 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -1458,7 +1458,7 @@ lnet_unprepare(void) the_lnet.ln_mt_zombie_rstqs = NULL; } - lnet_assert_handler_unused(the_lnet.ln_mt_handler); + lnet_assert_handler_unused(the_lnet.ln_mt_handler, true); the_lnet.ln_mt_handler = NULL; lnet_portals_destroy(); @@ -2153,7 +2153,7 @@ lnet_ping_target_fini(void) lnet_ping_md_unlink(the_lnet.ln_ping_target, &the_lnet.ln_ping_target_md); - lnet_assert_handler_unused(the_lnet.ln_ping_target_handler); + lnet_assert_handler_unused(the_lnet.ln_ping_target_handler, true); lnet_ping_target_destroy(); } @@ -2325,7 +2325,7 @@ static void lnet_push_target_fini(void) the_lnet.ln_push_target_nbytes = 0; LNetClearLazyPortal(LNET_RESERVED_PORTAL); - lnet_assert_handler_unused(the_lnet.ln_push_target_handler); + lnet_assert_handler_unused(the_lnet.ln_push_target_handler, true); the_lnet.ln_push_target_handler = NULL; } diff --git a/lnet/lnet/lib-md.c b/lnet/lnet/lib-md.c index 9bd9e33..8d85b3e 100644 --- a/lnet/lnet/lib-md.c +++ b/lnet/lnet/lib-md.c @@ -266,21 +266,29 @@ lnet_md_link(struct lnet_libmd *md, lnet_handler_t handler, int cpt) list_add(&md->md_list, &container->rec_active); } -void lnet_assert_handler_unused(lnet_handler_t handler) +bool lnet_assert_handler_unused(lnet_handler_t handler, bool assert) { struct lnet_res_container *container; int cpt; + bool handler_in_use = false; if (!handler) - return; + return handler_in_use; cfs_percpt_for_each(container, cpt, the_lnet.ln_md_containers) { struct lnet_libmd *md; lnet_res_lock(cpt); - list_for_each_entry(md, &container->rec_active, md_list) - LASSERT(md->md_handler != handler); + list_for_each_entry(md, &container->rec_active, md_list) { + if (assert) { + LASSERT(md->md_handler != handler); + } else if (md->md_handler == handler) { + handler_in_use = true; + break; + } + } lnet_res_unlock(cpt); } + return handler_in_use; } EXPORT_SYMBOL(lnet_assert_handler_unused); diff --git a/lnet/lnet/peer.c b/lnet/lnet/peer.c index f890d3f..1f6d92d 100644 --- a/lnet/lnet/peer.c +++ b/lnet/lnet/peer.c @@ -4034,6 +4034,7 @@ static void lnet_resend_msgs(void) static int lnet_peer_discovery(void *arg) { struct lnet_peer *lp; + int retry = 3; int rc; wait_for_completion(&the_lnet.ln_started); @@ -4144,6 +4145,7 @@ static int lnet_peer_discovery(void *arg) lnet_net_unlock(LNET_LOCK_EX); } +cleanup: CDEBUG(D_NET, "stopping\n"); /* * Clean up before telling lnet_peer_discovery_stop() that @@ -4185,7 +4187,9 @@ static int lnet_peer_discovery(void *arg) } lnet_net_unlock(LNET_LOCK_EX); - lnet_assert_handler_unused(the_lnet.ln_dc_handler); + if (lnet_assert_handler_unused(the_lnet.ln_dc_handler, --retry <= 0)) + goto cleanup; + the_lnet.ln_dc_handler = NULL; the_lnet.ln_dc_state = LNET_DC_STATE_SHUTDOWN; diff --git a/lnet/selftest/rpc.c b/lnet/selftest/rpc.c index 153f0e8..93ad1fa 100644 --- a/lnet/selftest/rpc.c +++ b/lnet/selftest/rpc.c @@ -1693,7 +1693,7 @@ srpc_shutdown (void) rc = LNetClearLazyPortal(SRPC_FRAMEWORK_REQUEST_PORTAL); rc = LNetClearLazyPortal(SRPC_REQUEST_PORTAL); LASSERT(rc == 0); - lnet_assert_handler_unused(srpc_data.rpc_lnet_handler); + lnet_assert_handler_unused(srpc_data.rpc_lnet_handler, true); fallthrough; case SRPC_STATE_NI_INIT: diff --git a/lustre/ptlrpc/events.c b/lustre/ptlrpc/events.c index 789bc75..586fd3f 100644 --- a/lustre/ptlrpc/events.c +++ b/lustre/ptlrpc/events.c @@ -591,7 +591,7 @@ static void ptlrpc_ni_fini(void) percpu_ref_kill(&ptlrpc_pending); wait_for_completion(&ptlrpc_done); - lnet_assert_handler_unused(ptlrpc_handler); + lnet_assert_handler_unused(ptlrpc_handler, true); LNetNIFini(); } -- 1.8.3.1