Whamcloud - gitweb
LU-14668 lnet: don't delete peer created by Lustre 65/43565/10
authorAmir Shehata <ashehata@whamcloud.com>
Thu, 6 May 2021 06:02:22 +0000 (23:02 -0700)
committerOleg Drokin <green@whamcloud.com>
Wed, 8 Mar 2023 03:27:19 +0000 (03:27 +0000)
Peers created by Lustre have their primary NIDs locked.
If that peer is deleted, it'll confuse lustre. So when manually
deleting a peer using:
   lnetctl peer del --prim_nid ...
We must continue to preserve the primary NID. Therefore we delete
all the constituent NIDs, but keep the primary NID. We then
flag the peer for rediscovery.

Signed-off-by: Amir Shehata <ashehata@whamcloud.com>
Change-Id: I34eef9b0049435a01fde87dc8263dd50f631c551
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/43565
Tested-by: Maloo <maloo@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-by: Cyril Bordage <cbordage@whamcloud.com>
lnet/lnet/peer.c

index 6e71ec5..0a32194 100644 (file)
@@ -1994,6 +1994,40 @@ int lnet_user_add_peer_ni(struct lnet_nid *prim_nid, struct lnet_nid *nid, bool
        return lnet_add_peer_ni(prim_nid, nid, mr, LNET_PEER_CONFIGURED);
 }
 
+static int
+lnet_reset_peer(struct lnet_peer *lp)
+{
+       struct lnet_peer_net *lpn, *lpntmp;
+       struct lnet_peer_ni *lpni, *lpnitmp;
+       unsigned int flags;
+       int rc;
+
+       lnet_peer_cancel_discovery(lp);
+
+       flags = LNET_PEER_CONFIGURED;
+       if (lp->lp_state & LNET_PEER_MULTI_RAIL)
+               flags |= LNET_PEER_MULTI_RAIL;
+
+       list_for_each_entry_safe(lpn, lpntmp, &lp->lp_peer_nets, lpn_peer_nets) {
+               list_for_each_entry_safe(lpni, lpnitmp, &lpn->lpn_peer_nis,
+                                        lpni_peer_nis) {
+                       if (nid_same(&lpni->lpni_nid, &lp->lp_primary_nid))
+                               continue;
+
+                       rc = lnet_peer_del_nid(lp, &lpni->lpni_nid, flags);
+                       if (rc) {
+                               CERROR("Failed to delete %s from peer %s\n",
+                                      libcfs_nidstr(&lpni->lpni_nid),
+                                      libcfs_nidstr(&lp->lp_primary_nid));
+                       }
+               }
+       }
+
+       /* mark it for discovery the next time we use it */
+       lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
+       return 0;
+}
+
 /*
  * Implementation of IOC_LIBCFS_DEL_PEER_NI.
  *
@@ -2037,8 +2071,15 @@ lnet_del_peer_ni(struct lnet_nid *prim_nid, struct lnet_nid *nid)
        }
        lnet_net_unlock(LNET_LOCK_EX);
 
-       if (LNET_NID_IS_ANY(nid) || nid_same(nid, &lp->lp_primary_nid))
-               return lnet_peer_del(lp);
+       if (LNET_NID_IS_ANY(nid) || nid_same(nid, &lp->lp_primary_nid)) {
+               if (lp->lp_state & LNET_PEER_LOCK_PRIMARY) {
+                       CERROR("peer %s created by Lustre. Must preserve primary NID, but will remove other NIDs\n",
+                              libcfs_nidstr(&lp->lp_primary_nid));
+                       return lnet_reset_peer(lp);
+               } else {
+                       return lnet_peer_del(lp);
+               }
+       }
 
        flags = LNET_PEER_CONFIGURED;
        if (lp->lp_state & LNET_PEER_MULTI_RAIL)