From 79a4b69adb1e365b16eb8521c79ef1c6985c6b91 Mon Sep 17 00:00:00 2001 From: Chris Horn Date: Fri, 22 Oct 2021 00:13:19 +0000 Subject: [PATCH] LU-15138 lnet: Fail peer add for existing gw peer If there's an existing peer entry for a peer that is being added via CLI, and that existing peer was not created via the CLI, then DLC will attempt to delete the existing peer before creating a new one. The exit status of the peer deletion was not being checked. This results in the ability to add duplicate peers for gateways, because gateways cannot be deleted via lnetctl unless the routes for that gateway have been removed first. Test-Parameters: trivial testlist=sanity-lnet Signed-off-by: Chris Horn Change-Id: I9b7864a2bd21540336f72d96e180c89bd0aae8dc Reviewed-on: https://review.whamcloud.com/45337 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Alexander Boyko Reviewed-by: Andriy Skulysh Reviewed-by: Oleg Drokin --- lnet/lnet/peer.c | 16 ++++++++++++---- lustre/tests/sanity-lnet.sh | 24 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lnet/lnet/peer.c b/lnet/lnet/peer.c index cdf8984..a06b99d 100644 --- a/lnet/lnet/peer.c +++ b/lnet/lnet/peer.c @@ -509,12 +509,14 @@ static void lnet_peer_cancel_discovery(struct lnet_peer *lp) static int lnet_peer_del(struct lnet_peer *peer) { + int rc; + lnet_peer_cancel_discovery(peer); lnet_net_lock(LNET_LOCK_EX); - lnet_peer_del_locked(peer); + rc = lnet_peer_del_locked(peer); lnet_net_unlock(LNET_LOCK_EX); - return 0; + return rc; } /* @@ -1661,7 +1663,9 @@ lnet_peer_add(lnet_nid_t nid4, unsigned int flags) } } /* Delete and recreate as a configured peer. */ - lnet_peer_del(lp); + rc = lnet_peer_del(lp); + if (rc) + goto out; } /* Create peer, peer_net, and peer_ni. */ @@ -3258,6 +3262,7 @@ __must_hold(&lp->lp_lock) struct list_head rlist; struct lnet_route *route, *tmp; int sensitivity = lp->lp_health_sensitivity; + int rc; INIT_LIST_HEAD(&rlist); @@ -3291,7 +3296,10 @@ __must_hold(&lp->lp_lock) lnet_net_unlock(LNET_LOCK_EX); /* lnet_peer_del() deletes all the peer NIs owned by this peer */ - lnet_peer_del(lp); + rc = lnet_peer_del(lp); + if (rc) + CNETERR("Internal error: Unable to delete peer %s rc %d\n", + libcfs_nidstr(&lp->lp_primary_nid), rc); list_for_each_entry_safe(route, tmp, &rlist, lr_list) { diff --git a/lustre/tests/sanity-lnet.sh b/lustre/tests/sanity-lnet.sh index ce4c27a..03e4a30 100755 --- a/lustre/tests/sanity-lnet.sh +++ b/lustre/tests/sanity-lnet.sh @@ -1258,7 +1258,29 @@ EOF } run_test 104 "Set/check response_tracking param" -### load lnet in default namespace, configure in target namespace +test_105() { + reinit_dlc || return $? + add_net "tcp" "${INTERFACES[0]}" + do_lnetctl route add --net tcp105 --gateway 105.105.105.105@tcp || + error "route add failed $?" + do_lnetctl peer add --prim 105.105.105.105@tcp && + error "peer add should fail" + + return 0 +} +run_test 105 "Adding duplicate GW peer should fail" + +test_106() { + reinit_dlc || return $? + add_net "tcp" "${INTERFACES[0]}" + do_lnetctl route add --net tcp106 --gateway 106.106.106.106@tcp || + error "route add failed $?" + do_lnetctl peer del --prim 106.106.106.106@tcp && + error "peer del should fail" + + return 0 +} +run_test 106 "Deleting GW peer should fail" test_200() { cleanup_lnet || exit 1 -- 1.8.3.1