Whamcloud - gitweb
LU-17496 lnet: retry cleanup during shutdown 76/53876/4
authorShaun Tancheff <shaun.tancheff@hpe.com>
Thu, 1 Feb 2024 08:20:14 +0000 (15:20 +0700)
committerOleg Drokin <green@whamcloud.com>
Tue, 2 Apr 2024 20:57:14 +0000 (20:57 +0000)
LNet can work a little harder to cleanup during teardown to
avoid an assert on module removal.

Signed-off-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Change-Id: Ic19c7774fa354b55bbfe21e8d87171dd024748c4
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53876
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/include/lnet/api.h
lnet/lnet/api-ni.c
lnet/lnet/lib-md.c
lnet/lnet/peer.c
lnet/selftest/rpc.c
lustre/ptlrpc/events.c

index 757d264..93510f4 100644 (file)
@@ -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
index 2acdb38..0dc9107 100644 (file)
@@ -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;
 }
 
index 9bd9e33..8d85b3e 100644 (file)
@@ -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);
 
index f890d3f..1f6d92d 100644 (file)
@@ -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;
index 153f0e8..93ad1fa 100644 (file)
@@ -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:
index 789bc75..586fd3f 100644 (file)
@@ -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();
 }