- lnet_clear_peer_table();
-
- LNET_LOCK();
- /* Now wait for the NI's I just nuked to show up on apini_zombie_nis
- * and shut them down in guaranteed thread context */
- i = 2;
- while (the_lnet.ln_nzombie_nis != 0) {
-
- while (list_empty(&the_lnet.ln_zombie_nis)) {
- LNET_UNLOCK();
- ++i;
- if ((i & (-i)) == i)
- CDEBUG(D_WARNING,"Waiting for %d zombie NIs\n",
- the_lnet.ln_nzombie_nis);
- cfs_pause(cfs_time_seconds(1));
- LNET_LOCK();
- }
-
- ni = list_entry(the_lnet.ln_zombie_nis.next,
- lnet_ni_t, ni_list);
- list_del(&ni->ni_list);
- ni->ni_lnd->lnd_refcount--;
-
- LNET_UNLOCK();
-
- islo = ni->ni_lnd->lnd_type == LOLND;
-
- LASSERT (!in_interrupt ());
- (ni->ni_lnd->lnd_shutdown)(ni);
-
- /* can't deref lnd anymore now; it might have unregistered
- * itself... */
-
- if (!islo)
- CDEBUG(D_LNI, "Removed LNI %s\n",
- libcfs_nid2str(ni->ni_nid));
-
- LIBCFS_FREE(ni, sizeof(*ni));
-
- LNET_LOCK();
- the_lnet.ln_nzombie_nis--;
- }
-
- the_lnet.ln_shutdown = 0;
- LNET_UNLOCK();
-
- if (the_lnet.ln_network_tokens != NULL) {
- LIBCFS_FREE(the_lnet.ln_network_tokens,
- the_lnet.ln_network_tokens_nob);
- the_lnet.ln_network_tokens = NULL;
- }
+ lnet_peer_tables_cleanup(NULL);
+
+ lnet_net_lock(LNET_LOCK_EX);
+ /* Now wait for the NI's I just nuked to show up on ln_zombie_nis
+ * and shut them down in guaranteed thread context */
+ i = 2;
+ while (!list_empty(&the_lnet.ln_nis_zombie)) {
+ int *ref;
+ int j;
+
+ ni = list_entry(the_lnet.ln_nis_zombie.next,
+ lnet_ni_t, ni_list);
+ list_del_init(&ni->ni_list);
+ cfs_percpt_for_each(ref, j, ni->ni_refs) {
+ if (*ref == 0)
+ continue;
+ /* still busy, add it back to zombie list */
+ list_add(&ni->ni_list, &the_lnet.ln_nis_zombie);
+ break;
+ }
+
+ if (!list_empty(&ni->ni_list)) {
+ lnet_net_unlock(LNET_LOCK_EX);
+ ++i;
+ if ((i & (-i)) == i) {
+ CDEBUG(D_WARNING, "Waiting for zombie LNI %s\n",
+ libcfs_nid2str(ni->ni_nid));
+ }
+ cfs_pause(cfs_time_seconds(1));
+ lnet_net_lock(LNET_LOCK_EX);
+ continue;
+ }
+
+ ni->ni_lnd->lnd_refcount--;
+ lnet_net_unlock(LNET_LOCK_EX);
+
+ islo = ni->ni_lnd->lnd_type == LOLND;
+
+ LASSERT (!in_interrupt ());
+ (ni->ni_lnd->lnd_shutdown)(ni);
+
+ /* can't deref lnd anymore now; it might have unregistered
+ * itself... */
+
+ if (!islo)
+ CDEBUG(D_LNI, "Removed LNI %s\n",
+ libcfs_nid2str(ni->ni_nid));
+
+ lnet_ni_free(ni);
+ i = 2;
+
+ lnet_net_lock(LNET_LOCK_EX);
+ }
+
+ the_lnet.ln_shutdown = 0;
+ lnet_net_unlock(LNET_LOCK_EX);