From 8535cfe29a122c91d40ac986e31d57c430ca5d34 Mon Sep 17 00:00:00 2001 From: Chris Horn Date: Fri, 6 Dec 2024 12:51:19 -0700 Subject: [PATCH] LU-18572 lnet: Uninitialized var in lnet_peer_add This is a regression introduced in the b2_15 port of Lustre-change: https://review.whamcloud.com/50106 Lustre-commit: aacb16191a72bc6db1155030849efb0d6971a572 In b2_15, lnet_peer_add() takes an lnet_nid_t nid argument, but the backport uses an uninitalized large nid variable in various places. This results in incorrect behavior. HPE-bug-id: LUS-12633 Test-Parameters: trivial Fixes: b341288179 ("LU-14668 lnet: Lock primary NID logic") Signed-off-by: Chris Horn Change-Id: I6b9ca501bac97d40fd193b2c36874f632582714c Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57494 Reviewed-by: Serguei Smirnov Reviewed-by: Frank Sehr Reviewed-by: Cyril Bordage Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lnet/lnet/peer.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lnet/lnet/peer.c b/lnet/lnet/peer.c index 3a0fe0f..cb92e83 100644 --- a/lnet/lnet/peer.c +++ b/lnet/lnet/peer.c @@ -1680,7 +1680,7 @@ lnet_peer_attach_peer_ni(struct lnet_peer *lp, /* * Create a new peer, with nid as its primary nid. * - * Call with the lnet_api_mutex held. + * Call with the ln_api_mutex held. */ static int lnet_peer_add(lnet_nid_t nid4, unsigned int flags) @@ -1691,13 +1691,15 @@ lnet_peer_add(lnet_nid_t nid4, unsigned int flags) struct lnet_peer_ni *lpni; int rc = 0; - LASSERT(nid4 != LNET_NID_ANY); + lnet_nid4_to_nid(nid4, &nid); + + LASSERT(!LNET_NID_IS_ANY(&nid)); /* * No need for the lnet_net_lock here, because the * lnet_api_mutex is held. */ - lpni = lnet_find_peer_ni_locked(nid4); + lpni = lnet_peer_ni_find_locked(&nid); if (lpni) { /* A peer with this NID already exists. */ lp = lpni->lpni_peer_net->lpn_peer; @@ -1709,7 +1711,7 @@ lnet_peer_add(lnet_nid_t nid4, unsigned int flags) * that an existing peer is being modified. */ if (lp->lp_state & LNET_PEER_CONFIGURED) { - if (lnet_nid_to_nid4(&lp->lp_primary_nid) != nid4) + if (!nid_same(&lp->lp_primary_nid, &nid)) rc = -EEXIST; else if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL) rc = -EPERM; @@ -1752,7 +1754,6 @@ lnet_peer_add(lnet_nid_t nid4, unsigned int flags) /* Create peer, peer_net, and peer_ni. */ rc = -ENOMEM; - lnet_nid4_to_nid(nid4, &nid); lp = lnet_peer_alloc(&nid); if (!lp) goto out; @@ -1771,7 +1772,7 @@ out_free_lp: LIBCFS_FREE(lp, sizeof(*lp)); out: CDEBUG(D_NET, "peer %s NID flags %#x: %d\n", - libcfs_nid2str(nid4), flags, rc); + libcfs_nidstr(&nid), flags, rc); return rc; } -- 1.8.3.1