Whamcloud - gitweb
LU-15138 lnet: Fail peer add for existing gw peer 37/45337/5
authorChris Horn <chris.horn@hpe.com>
Fri, 22 Oct 2021 00:13:19 +0000 (00:13 +0000)
committerOleg Drokin <green@whamcloud.com>
Sat, 20 Nov 2021 06:26:51 +0000 (06:26 +0000)
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 <chris.horn@hpe.com>
Change-Id: I9b7864a2bd21540336f72d96e180c89bd0aae8dc
Reviewed-on: https://review.whamcloud.com/45337
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alexander Boyko <alexander.boyko@hpe.com>
Reviewed-by: Andriy Skulysh <andriy.skulysh@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/lnet/peer.c
lustre/tests/sanity-lnet.sh

index cdf8984..a06b99d 100644 (file)
@@ -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) {
index ce4c27a..03e4a30 100755 (executable)
@@ -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