Whamcloud - gitweb
LU-17379 lnet: add LNetPeerDiscovered to LNet API 26/53926/8
authorSerguei Smirnov <ssmirnov@whamcloud.com>
Mon, 5 Feb 2024 20:14:30 +0000 (12:14 -0800)
committerOleg Drokin <green@whamcloud.com>
Fri, 23 Feb 2024 07:15:51 +0000 (07:15 +0000)
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 <ssmirnov@whamcloud.com>
Change-Id: I7c9964148a5a2a24d7889b8b4c2e488a433ca258
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53926
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: Mikhail Pershin <mpershin@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lnet/include/lnet/api.h
lnet/lnet/peer.c

index 2d15089..757d264 100644 (file)
@@ -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 */
 
index 540f7a7..40ce284 100644 (file)
@@ -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)
 {