From dba41355565397228f587f13a901b5d762521ed0 Mon Sep 17 00:00:00 2001 From: Serguei Smirnov Date: Mon, 5 Feb 2024 12:14:30 -0800 Subject: [PATCH] LU-17379 lnet: add LNetPeerDiscovered to LNet API LNetPeerDiscovered is added to allow lustre check whether the peer has been successfully discovered by LNet before attempting to open a connection to it. For example, given a mount command with a list of NIDs, Lustre can use LNetAddPeer API to initiate discovery on every candidate first, and later use LNetPeerDiscovered to select a reachable peer to connect to. Test-Parameters: trivial testlist=sanity-lnet Signed-off-by: Serguei Smirnov Change-Id: I7c9964148a5a2a24d7889b8b4c2e488a433ca258 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53926 Reviewed-by: Frank Sehr Reviewed-by: Mikhail Pershin Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lnet/include/lnet/api.h | 1 + lnet/lnet/peer.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lnet/include/lnet/api.h b/lnet/include/lnet/api.h index 2d15089..757d264 100644 --- a/lnet/include/lnet/api.h +++ b/lnet/include/lnet/api.h @@ -78,6 +78,7 @@ int LNetGetId(unsigned int index, struct lnet_processid *id, bool large_nids); int LNetDist(struct lnet_nid *nid, struct lnet_nid *srcnid, __u32 *order); void LNetPrimaryNID(struct lnet_nid *nid); bool LNetIsPeerLocal(struct lnet_nid *nid); +bool LNetPeerDiscovered(struct lnet_nid *nid); /** @} lnet_addr */ diff --git a/lnet/lnet/peer.c b/lnet/lnet/peer.c index 540f7a7..40ce284 100644 --- a/lnet/lnet/peer.c +++ b/lnet/lnet/peer.c @@ -1501,6 +1501,34 @@ out_unlock: } EXPORT_SYMBOL(LNetPrimaryNID); +bool +LNetPeerDiscovered(struct lnet_nid *nid) +{ + int cpt, disc = false; + struct lnet_peer *lp; + + lp = lnet_find_peer(nid); + if (!lp) + goto out; + + cpt = lnet_net_lock_current(); + spin_lock(&lp->lp_lock); + if (((lp->lp_state & LNET_PEER_DISCOVERED) && + (lp->lp_state & LNET_PEER_NIDS_UPTODATE)) || + (lp->lp_state & LNET_PEER_NO_DISCOVERY)) + disc = true; + spin_unlock(&lp->lp_lock); + + /* Drop refcount from lookup */ + lnet_peer_decref_locked(lp); + lnet_net_unlock(cpt); +out: + CDEBUG(D_NET, "Peer NID %s discovered: %d\n", libcfs_nidstr(nid), + disc); + return disc; +} +EXPORT_SYMBOL(LNetPeerDiscovered); + struct lnet_peer_net * lnet_peer_get_net_locked(struct lnet_peer *peer, __u32 net_id) { -- 1.8.3.1