From: Serguei Smirnov Date: Mon, 5 Feb 2024 20:14:30 +0000 (-0800) Subject: LU-17379 lnet: add LNetPeerDiscovered to LNet API X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=5623018dcdd484dbc01e6c267fe0b95d95a80eb8;p=fs%2Flustre-release.git 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. Lustre-change: https://review.whamcloud.com/53926 Lustre-commit: dba41355565397228f587f13a901b5d762521ed0 Test-Parameters: trivial testlist=sanity-lnet Signed-off-by: Serguei Smirnov Change-Id: I7c9964148a5a2a24d7889b8b4c2e488a433ca258 Reviewed-by: Frank Sehr Reviewed-by: Mikhail Pershin Reviewed-by: Oleg Drokin Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/54950 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/lnet/include/lnet/api.h b/lnet/include/lnet/api.h index 375afd4..92d48f9 100644 --- a/lnet/include/lnet/api.h +++ b/lnet/include/lnet/api.h @@ -79,6 +79,7 @@ int LNetGetId(unsigned int index, struct lnet_process_id *id); int LNetDist(lnet_nid_t nid, lnet_nid_t *srcnid, __u32 *order); lnet_nid_t LNetPrimaryNID(lnet_nid_t nid); bool LNetIsPeerLocal(lnet_nid_t nid); +bool LNetPeerDiscovered(lnet_nid_t nid); /** @} lnet_addr */ diff --git a/lnet/lnet/peer.c b/lnet/lnet/peer.c index 105d94b..55a7249 100644 --- a/lnet/lnet/peer.c +++ b/lnet/lnet/peer.c @@ -1375,6 +1375,34 @@ out_unlock: } EXPORT_SYMBOL(LNetPrimaryNID); +bool +LNetPeerDiscovered(lnet_nid_t 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_nid2str(nid), + disc); + return disc; +} +EXPORT_SYMBOL(LNetPeerDiscovered); + struct lnet_peer_net * lnet_peer_get_net_locked(struct lnet_peer *peer, __u32 net_id) {