4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
34 #define DEBUG_SUBSYSTEM S_LNET
36 #include <linux/sched.h>
37 #ifdef HAVE_SCHED_HEADERS
38 #include <linux/sched/signal.h>
40 #include <linux/uaccess.h>
42 #include <lnet/udsp.h>
43 #include <lnet/lib-lnet.h>
44 #include <uapi/linux/lnet/lnet-dlc.h>
46 /* Value indicating that recovery needs to re-check a peer immediately. */
47 #define LNET_REDISCOVER_PEER (1)
49 static int lnet_peer_queue_for_discovery(struct lnet_peer *lp);
52 lnet_peer_remove_from_remote_list(struct lnet_peer_ni *lpni)
54 if (!list_empty(&lpni->lpni_on_remote_peer_ni_list)) {
55 list_del_init(&lpni->lpni_on_remote_peer_ni_list);
56 lnet_peer_ni_decref_locked(lpni);
61 lnet_peer_net_added(struct lnet_net *net)
63 struct lnet_peer_ni *lpni, *tmp;
65 list_for_each_entry_safe(lpni, tmp, &the_lnet.ln_remote_peer_ni_list,
66 lpni_on_remote_peer_ni_list) {
68 if (LNET_NID_NET(&lpni->lpni_nid) == net->net_id) {
71 spin_lock(&lpni->lpni_lock);
72 lpni->lpni_txcredits =
73 lpni->lpni_net->net_tunables.lct_peer_tx_credits;
74 lpni->lpni_mintxcredits = lpni->lpni_txcredits;
75 lpni->lpni_rtrcredits =
76 lnet_peer_buffer_credits(lpni->lpni_net);
77 lpni->lpni_minrtrcredits = lpni->lpni_rtrcredits;
78 spin_unlock(&lpni->lpni_lock);
80 lnet_peer_remove_from_remote_list(lpni);
86 lnet_peer_tables_destroy(void)
88 struct lnet_peer_table *ptable;
89 struct list_head *hash;
93 if (!the_lnet.ln_peer_tables)
96 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
97 hash = ptable->pt_hash;
98 if (!hash) /* not intialized */
101 LASSERT(list_empty(&ptable->pt_zombie_list));
103 ptable->pt_hash = NULL;
104 for (j = 0; j < LNET_PEER_HASH_SIZE; j++)
105 LASSERT(list_empty(&hash[j]));
107 CFS_FREE_PTR_ARRAY(hash, LNET_PEER_HASH_SIZE);
110 cfs_percpt_free(the_lnet.ln_peer_tables);
111 the_lnet.ln_peer_tables = NULL;
115 lnet_peer_tables_create(void)
117 struct lnet_peer_table *ptable;
118 struct list_head *hash;
122 the_lnet.ln_peer_tables = cfs_percpt_alloc(lnet_cpt_table(),
124 if (the_lnet.ln_peer_tables == NULL) {
125 CERROR("Failed to allocate cpu-partition peer tables\n");
129 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
130 LIBCFS_CPT_ALLOC(hash, lnet_cpt_table(), i,
131 LNET_PEER_HASH_SIZE * sizeof(*hash));
133 CERROR("Failed to create peer hash table\n");
134 lnet_peer_tables_destroy();
138 spin_lock_init(&ptable->pt_zombie_lock);
139 INIT_LIST_HEAD(&ptable->pt_zombie_list);
141 INIT_LIST_HEAD(&ptable->pt_peer_list);
143 for (j = 0; j < LNET_PEER_HASH_SIZE; j++)
144 INIT_LIST_HEAD(&hash[j]);
145 ptable->pt_hash = hash; /* sign of initialization */
151 static struct lnet_peer_ni *
152 lnet_peer_ni_alloc(struct lnet_nid *nid)
154 struct lnet_peer_ni *lpni;
155 struct lnet_net *net;
158 cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
160 LIBCFS_CPT_ALLOC(lpni, lnet_cpt_table(), cpt, sizeof(*lpni));
164 INIT_LIST_HEAD(&lpni->lpni_txq);
165 INIT_LIST_HEAD(&lpni->lpni_hashlist);
166 INIT_LIST_HEAD(&lpni->lpni_peer_nis);
167 INIT_LIST_HEAD(&lpni->lpni_recovery);
168 INIT_LIST_HEAD(&lpni->lpni_on_remote_peer_ni_list);
169 INIT_LIST_HEAD(&lpni->lpni_rtr_pref_nids);
170 LNetInvalidateMDHandle(&lpni->lpni_recovery_ping_mdh);
171 kref_init(&lpni->lpni_kref);
172 lpni->lpni_sel_priority = LNET_MAX_SELECTION_PRIORITY;
174 spin_lock_init(&lpni->lpni_lock);
176 if (lnet_peers_start_down())
177 lpni->lpni_ns_status = LNET_NI_STATUS_DOWN;
179 lpni->lpni_ns_status = LNET_NI_STATUS_UP;
180 lpni->lpni_ping_feats = LNET_PING_FEAT_INVAL;
181 lpni->lpni_nid = *nid;
182 lpni->lpni_cpt = cpt;
183 atomic_set(&lpni->lpni_healthv, LNET_MAX_HEALTH_VALUE);
185 net = lnet_get_net_locked(LNET_NID_NET(nid));
186 lpni->lpni_net = net;
188 lpni->lpni_txcredits = net->net_tunables.lct_peer_tx_credits;
189 lpni->lpni_mintxcredits = lpni->lpni_txcredits;
190 lpni->lpni_rtrcredits = lnet_peer_buffer_credits(net);
191 lpni->lpni_minrtrcredits = lpni->lpni_rtrcredits;
194 * This peer_ni is not on a local network, so we
195 * cannot add the credits here. In case the net is
196 * added later, add the peer_ni to the remote peer ni
197 * list so it can be easily found and revisited.
199 /* FIXME: per-net implementation instead? */
200 lnet_peer_ni_addref_locked(lpni);
201 list_add_tail(&lpni->lpni_on_remote_peer_ni_list,
202 &the_lnet.ln_remote_peer_ni_list);
205 CDEBUG(D_NET, "%p nid %s\n", lpni, libcfs_nidstr(&lpni->lpni_nid));
210 static struct lnet_peer_net *
211 lnet_peer_net_alloc(__u32 net_id)
213 struct lnet_peer_net *lpn;
215 LIBCFS_CPT_ALLOC(lpn, lnet_cpt_table(), CFS_CPT_ANY, sizeof(*lpn));
219 INIT_LIST_HEAD(&lpn->lpn_peer_nets);
220 INIT_LIST_HEAD(&lpn->lpn_peer_nis);
221 lpn->lpn_net_id = net_id;
222 lpn->lpn_sel_priority = LNET_MAX_SELECTION_PRIORITY;
224 CDEBUG(D_NET, "%p net %s\n", lpn, libcfs_net2str(lpn->lpn_net_id));
230 lnet_destroy_peer_net_locked(struct lnet_peer_net *lpn)
232 struct lnet_peer *lp;
234 CDEBUG(D_NET, "%p net %s\n", lpn, libcfs_net2str(lpn->lpn_net_id));
236 LASSERT(atomic_read(&lpn->lpn_refcount) == 0);
237 LASSERT(list_empty(&lpn->lpn_peer_nis));
238 LASSERT(list_empty(&lpn->lpn_peer_nets));
240 lpn->lpn_peer = NULL;
241 LIBCFS_FREE(lpn, sizeof(*lpn));
243 lnet_peer_decref_locked(lp);
246 static struct lnet_peer *
247 lnet_peer_alloc(struct lnet_nid *nid)
249 struct lnet_peer *lp;
251 LIBCFS_CPT_ALLOC(lp, lnet_cpt_table(), CFS_CPT_ANY, sizeof(*lp));
255 INIT_LIST_HEAD(&lp->lp_rtrq);
256 INIT_LIST_HEAD(&lp->lp_routes);
257 INIT_LIST_HEAD(&lp->lp_peer_list);
258 INIT_LIST_HEAD(&lp->lp_peer_nets);
259 INIT_LIST_HEAD(&lp->lp_dc_list);
260 INIT_LIST_HEAD(&lp->lp_dc_pendq);
261 INIT_LIST_HEAD(&lp->lp_rtr_list);
262 init_waitqueue_head(&lp->lp_dc_waitq);
263 spin_lock_init(&lp->lp_lock);
264 lp->lp_primary_nid = *nid;
265 lp->lp_disc_src_nid = LNET_ANY_NID;
266 lp->lp_disc_dst_nid = LNET_ANY_NID;
267 if (lnet_peers_start_down())
268 lp->lp_alive = false;
273 * all peers created on a router should have health on
274 * if it's not already on.
276 if (the_lnet.ln_routing && !lnet_health_sensitivity)
277 lp->lp_health_sensitivity = 1;
280 * Turn off discovery for loopback peer. If you're creating a peer
281 * for the loopback interface then that was initiated when we
282 * attempted to send a message over the loopback. There is no need
283 * to ever use a different interface when sending messages to
287 lp->lp_state = LNET_PEER_NO_DISCOVERY;
288 lp->lp_cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
290 CDEBUG(D_NET, "%p nid %s\n", lp, libcfs_nidstr(&lp->lp_primary_nid));
296 lnet_destroy_peer_locked(struct lnet_peer *lp)
298 CDEBUG(D_NET, "%p nid %s\n", lp, libcfs_nidstr(&lp->lp_primary_nid));
300 LASSERT(atomic_read(&lp->lp_refcount) == 0);
301 LASSERT(lp->lp_rtr_refcount == 0);
302 LASSERT(list_empty(&lp->lp_peer_nets));
303 LASSERT(list_empty(&lp->lp_peer_list));
304 LASSERT(list_empty(&lp->lp_dc_list));
307 lnet_ping_buffer_decref(lp->lp_data);
310 * if there are messages still on the pending queue, then make
311 * sure to queue them on the ln_msg_resend list so they can be
312 * resent at a later point if the discovery thread is still
314 * If the discovery thread has stopped, then the wakeup will be a
315 * no-op, and it is expected the lnet_shutdown_lndnets() will
316 * eventually be called, which will traverse this list and
317 * finalize the messages on the list.
318 * We can not resend them now because we're holding the cpt lock.
319 * Releasing the lock can cause an inconsistent state
321 spin_lock(&the_lnet.ln_msg_resend_lock);
322 spin_lock(&lp->lp_lock);
323 list_splice(&lp->lp_dc_pendq, &the_lnet.ln_msg_resend);
324 spin_unlock(&lp->lp_lock);
325 spin_unlock(&the_lnet.ln_msg_resend_lock);
326 wake_up(&the_lnet.ln_dc_waitq);
328 LIBCFS_FREE(lp, sizeof(*lp));
332 * Detach a peer_ni from its peer_net. If this was the last peer_ni on
333 * that peer_net, detach the peer_net from the peer.
335 * Call with lnet_net_lock/EX held
338 lnet_peer_detach_peer_ni_locked(struct lnet_peer_ni *lpni)
340 struct lnet_peer_table *ptable;
341 struct lnet_peer_net *lpn;
342 struct lnet_peer *lp;
345 * Belts and suspenders: gracefully handle teardown of a
346 * partially connected peer_ni.
348 lpn = lpni->lpni_peer_net;
350 list_del_init(&lpni->lpni_peer_nis);
352 * If there are no lpni's left, we detach lpn from
353 * lp_peer_nets, so it cannot be found anymore.
355 if (list_empty(&lpn->lpn_peer_nis))
356 list_del_init(&lpn->lpn_peer_nets);
358 /* Update peer NID count. */
363 * If there are no more peer nets, make the peer unfindable
364 * via the peer_tables.
366 * Otherwise, if the peer is DISCOVERED, tell discovery to
367 * take another look at it. This is a no-op if discovery for
368 * this peer did the detaching.
370 if (list_empty(&lp->lp_peer_nets)) {
371 list_del_init(&lp->lp_peer_list);
372 ptable = the_lnet.ln_peer_tables[lp->lp_cpt];
374 } else if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING) {
375 /* Discovery isn't running, nothing to do here. */
376 } else if (lp->lp_state & LNET_PEER_DISCOVERED) {
377 lnet_peer_queue_for_discovery(lp);
378 wake_up(&the_lnet.ln_dc_waitq);
380 CDEBUG(D_NET, "peer %s NID %s\n",
381 libcfs_nidstr(&lp->lp_primary_nid),
382 libcfs_nidstr(&lpni->lpni_nid));
385 /* called with lnet_net_lock LNET_LOCK_EX held */
387 lnet_peer_ni_del_locked(struct lnet_peer_ni *lpni, bool force)
389 struct lnet_peer_table *ptable = NULL;
391 /* don't remove a peer_ni if it's also a gateway */
392 if (lnet_isrouter(lpni) && !force) {
393 CERROR("Peer NI %s is a gateway. Can not delete it\n",
394 libcfs_nidstr(&lpni->lpni_nid));
398 lnet_peer_remove_from_remote_list(lpni);
400 /* remove peer ni from the hash list. */
401 list_del_init(&lpni->lpni_hashlist);
404 * indicate the peer is being deleted so the monitor thread can
405 * remove it from the recovery queue.
407 spin_lock(&lpni->lpni_lock);
408 lpni->lpni_state |= LNET_PEER_NI_DELETING;
409 spin_unlock(&lpni->lpni_lock);
411 /* decrement the ref count on the peer table */
412 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
415 * The peer_ni can no longer be found with a lookup. But there
416 * can be current users, so keep track of it on the zombie
417 * list until the reference count has gone to zero.
419 * The last reference may be lost in a place where the
420 * lnet_net_lock locks only a single cpt, and that cpt may not
421 * be lpni->lpni_cpt. So the zombie list of lnet_peer_table
424 spin_lock(&ptable->pt_zombie_lock);
425 list_add(&lpni->lpni_hashlist, &ptable->pt_zombie_list);
426 ptable->pt_zombies++;
427 spin_unlock(&ptable->pt_zombie_lock);
429 /* no need to keep this peer_ni on the hierarchy anymore */
430 lnet_peer_detach_peer_ni_locked(lpni);
432 /* remove hashlist reference on peer_ni */
433 lnet_peer_ni_decref_locked(lpni);
438 void lnet_peer_uninit(void)
440 struct lnet_peer_ni *lpni, *tmp;
442 lnet_net_lock(LNET_LOCK_EX);
444 /* remove all peer_nis from the remote peer and the hash list */
445 list_for_each_entry_safe(lpni, tmp, &the_lnet.ln_remote_peer_ni_list,
446 lpni_on_remote_peer_ni_list)
447 lnet_peer_ni_del_locked(lpni, false);
449 lnet_peer_tables_destroy();
451 lnet_net_unlock(LNET_LOCK_EX);
455 lnet_peer_del_locked(struct lnet_peer *peer)
457 struct lnet_peer_ni *lpni = NULL, *lpni2;
460 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&peer->lp_primary_nid));
462 spin_lock(&peer->lp_lock);
463 peer->lp_state |= LNET_PEER_MARK_DELETED;
464 spin_unlock(&peer->lp_lock);
466 lpni = lnet_get_next_peer_ni_locked(peer, NULL, lpni);
467 while (lpni != NULL) {
468 lpni2 = lnet_get_next_peer_ni_locked(peer, NULL, lpni);
469 rc = lnet_peer_ni_del_locked(lpni, false);
479 * Discovering this peer is taking too long. Cancel any Ping or Push
480 * that discovery is waiting on by unlinking the relevant MDs. The
481 * lnet_discovery_event_handler() will proceed from here and complete
484 static void lnet_peer_cancel_discovery(struct lnet_peer *lp)
486 struct lnet_handle_md ping_mdh;
487 struct lnet_handle_md push_mdh;
489 LNetInvalidateMDHandle(&ping_mdh);
490 LNetInvalidateMDHandle(&push_mdh);
492 spin_lock(&lp->lp_lock);
493 if (lp->lp_state & LNET_PEER_PING_SENT) {
494 ping_mdh = lp->lp_ping_mdh;
495 LNetInvalidateMDHandle(&lp->lp_ping_mdh);
497 if (lp->lp_state & LNET_PEER_PUSH_SENT) {
498 push_mdh = lp->lp_push_mdh;
499 LNetInvalidateMDHandle(&lp->lp_push_mdh);
501 spin_unlock(&lp->lp_lock);
503 if (!LNetMDHandleIsInvalid(ping_mdh))
504 LNetMDUnlink(ping_mdh);
505 if (!LNetMDHandleIsInvalid(push_mdh))
506 LNetMDUnlink(push_mdh);
510 lnet_peer_del(struct lnet_peer *peer)
514 lnet_peer_cancel_discovery(peer);
515 lnet_net_lock(LNET_LOCK_EX);
516 rc = lnet_peer_del_locked(peer);
517 lnet_net_unlock(LNET_LOCK_EX);
523 * Delete a NID from a peer. Call with ln_api_mutex held.
526 * -EPERM: Non-DLC deletion from DLC-configured peer.
527 * -ENOENT: No lnet_peer_ni corresponding to the nid.
528 * -ECHILD: The lnet_peer_ni isn't connected to the peer.
529 * -EBUSY: The lnet_peer_ni is the primary, and not the only peer_ni.
532 lnet_peer_del_nid(struct lnet_peer *lp, lnet_nid_t nid4, unsigned int flags)
534 struct lnet_peer_ni *lpni;
535 struct lnet_nid primary_nid = lp->lp_primary_nid;
538 bool force = (flags & LNET_PEER_RTR_NI_FORCE_DEL) ? true : false;
540 lnet_nid4_to_nid(nid4, &nid);
541 if (!(flags & LNET_PEER_CONFIGURED)) {
542 if (lp->lp_state & LNET_PEER_CONFIGURED) {
548 lpni = lnet_peer_ni_find_locked(&nid);
553 lnet_peer_ni_decref_locked(lpni);
554 if (lp != lpni->lpni_peer_net->lpn_peer) {
560 * This function only allows deletion of the primary NID if it
563 if (nid_same(&nid, &lp->lp_primary_nid) && lp->lp_nnis != 1 && !force) {
568 lnet_net_lock(LNET_LOCK_EX);
570 if (nid_same(&nid, &lp->lp_primary_nid) && lp->lp_nnis != 1 && force) {
571 struct lnet_peer_ni *lpni2;
572 /* assign the next peer_ni to be the primary */
573 lpni2 = lnet_get_next_peer_ni_locked(lp, NULL, lpni);
575 lp->lp_primary_nid = lpni2->lpni_nid;
577 rc = lnet_peer_ni_del_locked(lpni, force);
579 lnet_net_unlock(LNET_LOCK_EX);
582 CDEBUG(D_NET, "peer %s NID %s flags %#x: %d\n",
583 libcfs_nidstr(&primary_nid), libcfs_nidstr(&nid),
590 lnet_peer_table_cleanup_locked(struct lnet_net *net,
591 struct lnet_peer_table *ptable)
594 struct lnet_peer_ni *next;
595 struct lnet_peer_ni *lpni;
596 struct lnet_peer *peer;
598 for (i = 0; i < LNET_PEER_HASH_SIZE; i++) {
599 list_for_each_entry_safe(lpni, next, &ptable->pt_hash[i],
601 if (net != NULL && net != lpni->lpni_net)
604 peer = lpni->lpni_peer_net->lpn_peer;
605 if (!nid_same(&peer->lp_primary_nid,
607 lnet_peer_ni_del_locked(lpni, false);
611 * Removing the primary NID implies removing
612 * the entire peer. Advance next beyond any
613 * peer_ni that belongs to the same peer.
615 list_for_each_entry_from(next, &ptable->pt_hash[i],
617 if (next->lpni_peer_net->lpn_peer != peer)
620 lnet_peer_del_locked(peer);
626 lnet_peer_ni_finalize_wait(struct lnet_peer_table *ptable)
628 wait_var_event_warning(&ptable->pt_zombies,
629 ptable->pt_zombies == 0,
630 "Waiting for %d zombies on peer table\n",
635 lnet_peer_table_del_rtrs_locked(struct lnet_net *net,
636 struct lnet_peer_table *ptable)
638 struct lnet_peer_ni *lp;
639 struct lnet_peer_ni *tmp;
643 for (i = 0; i < LNET_PEER_HASH_SIZE; i++) {
644 list_for_each_entry_safe(lp, tmp, &ptable->pt_hash[i],
646 if (net != lp->lpni_net)
649 if (!lnet_isrouter(lp))
652 /* FIXME handle large-addr nid */
653 gw_nid = lnet_nid_to_nid4(
654 &lp->lpni_peer_net->lpn_peer->lp_primary_nid);
656 lnet_net_unlock(LNET_LOCK_EX);
657 lnet_del_route(LNET_NET_ANY, gw_nid);
658 lnet_net_lock(LNET_LOCK_EX);
664 lnet_peer_tables_cleanup(struct lnet_net *net)
667 struct lnet_peer_table *ptable;
669 LASSERT(the_lnet.ln_state != LNET_STATE_SHUTDOWN || net != NULL);
670 /* If just deleting the peers for a NI, get rid of any routes these
671 * peers are gateways for. */
672 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
673 lnet_net_lock(LNET_LOCK_EX);
674 lnet_peer_table_del_rtrs_locked(net, ptable);
675 lnet_net_unlock(LNET_LOCK_EX);
678 /* Start the cleanup process */
679 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
680 lnet_net_lock(LNET_LOCK_EX);
681 lnet_peer_table_cleanup_locked(net, ptable);
682 lnet_net_unlock(LNET_LOCK_EX);
685 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables)
686 lnet_peer_ni_finalize_wait(ptable);
689 static struct lnet_peer_ni *
690 lnet_get_peer_ni_locked(struct lnet_peer_table *ptable, struct lnet_nid *nid)
692 struct list_head *peers;
693 struct lnet_peer_ni *lp;
695 if (the_lnet.ln_state != LNET_STATE_RUNNING)
698 peers = &ptable->pt_hash[lnet_nid2peerhash(nid)];
699 list_for_each_entry(lp, peers, lpni_hashlist) {
700 if (nid_same(&lp->lpni_nid, nid)) {
701 lnet_peer_ni_addref_locked(lp);
709 struct lnet_peer_ni *
710 lnet_find_peer_ni_locked(lnet_nid_t nid4)
712 struct lnet_peer_ni *lpni;
713 struct lnet_peer_table *ptable;
717 lnet_nid4_to_nid(nid4, &nid);
719 cpt = lnet_nid_cpt_hash(&nid, LNET_CPT_NUMBER);
721 ptable = the_lnet.ln_peer_tables[cpt];
722 lpni = lnet_get_peer_ni_locked(ptable, &nid);
727 struct lnet_peer_ni *
728 lnet_peer_ni_find_locked(struct lnet_nid *nid)
730 struct lnet_peer_ni *lpni;
731 struct lnet_peer_table *ptable;
734 cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
736 ptable = the_lnet.ln_peer_tables[cpt];
737 lpni = lnet_get_peer_ni_locked(ptable, nid);
742 struct lnet_peer_ni *
743 lnet_peer_get_ni_locked(struct lnet_peer *lp, lnet_nid_t nid)
745 struct lnet_peer_net *lpn;
746 struct lnet_peer_ni *lpni;
748 lpn = lnet_peer_get_net_locked(lp, LNET_NIDNET(nid));
752 list_for_each_entry(lpni, &lpn->lpn_peer_nis, lpni_peer_nis) {
753 if (lnet_nid_to_nid4(&lpni->lpni_nid) == nid)
760 struct lnet_peer_ni *
761 lnet_peer_ni_get_locked(struct lnet_peer *lp, struct lnet_nid *nid)
763 struct lnet_peer_net *lpn;
764 struct lnet_peer_ni *lpni;
766 lpn = lnet_peer_get_net_locked(lp, LNET_NID_NET(nid));
770 list_for_each_entry(lpni, &lpn->lpn_peer_nis, lpni_peer_nis) {
771 if (nid_same(&lpni->lpni_nid, nid))
779 lnet_find_peer4(lnet_nid_t nid)
781 struct lnet_peer_ni *lpni;
782 struct lnet_peer *lp = NULL;
785 cpt = lnet_net_lock_current();
786 lpni = lnet_find_peer_ni_locked(nid);
788 lp = lpni->lpni_peer_net->lpn_peer;
789 lnet_peer_addref_locked(lp);
790 lnet_peer_ni_decref_locked(lpni);
792 lnet_net_unlock(cpt);
798 lnet_find_peer(struct lnet_nid *nid)
800 struct lnet_peer_ni *lpni;
801 struct lnet_peer *lp = NULL;
804 cpt = lnet_net_lock_current();
805 lpni = lnet_peer_ni_find_locked(nid);
807 lp = lpni->lpni_peer_net->lpn_peer;
808 lnet_peer_addref_locked(lp);
809 lnet_peer_ni_decref_locked(lpni);
811 lnet_net_unlock(cpt);
816 struct lnet_peer_net *
817 lnet_get_next_peer_net_locked(struct lnet_peer *lp, __u32 prev_lpn_id)
819 struct lnet_peer_net *net;
822 /* no net id provided return the first net */
823 net = list_first_entry_or_null(&lp->lp_peer_nets,
824 struct lnet_peer_net,
830 /* find the net after the one provided */
831 list_for_each_entry(net, &lp->lp_peer_nets, lpn_peer_nets) {
832 if (net->lpn_net_id == prev_lpn_id) {
834 * if we reached the end of the list loop to the
837 if (net->lpn_peer_nets.next == &lp->lp_peer_nets)
838 return list_first_entry_or_null(&lp->lp_peer_nets,
839 struct lnet_peer_net,
842 return list_next_entry(net, lpn_peer_nets);
849 struct lnet_peer_ni *
850 lnet_get_next_peer_ni_locked(struct lnet_peer *peer,
851 struct lnet_peer_net *peer_net,
852 struct lnet_peer_ni *prev)
854 struct lnet_peer_ni *lpni;
855 struct lnet_peer_net *net = peer_net;
859 if (list_empty(&peer->lp_peer_nets))
862 net = list_entry(peer->lp_peer_nets.next,
863 struct lnet_peer_net,
866 lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
872 if (prev->lpni_peer_nis.next == &prev->lpni_peer_net->lpn_peer_nis) {
874 * if you reached the end of the peer ni list and the peer
875 * net is specified then there are no more peer nis in that
882 * we reached the end of this net ni list. move to the
885 if (prev->lpni_peer_net->lpn_peer_nets.next ==
887 /* no more nets and no more NIs. */
890 /* get the next net */
891 net = list_entry(prev->lpni_peer_net->lpn_peer_nets.next,
892 struct lnet_peer_net,
894 /* get the ni on it */
895 lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
901 /* there are more nis left */
902 lpni = list_entry(prev->lpni_peer_nis.next,
903 struct lnet_peer_ni, lpni_peer_nis);
908 /* Call with the ln_api_mutex held */
909 int lnet_get_peer_list(u32 *countp, u32 *sizep, struct lnet_process_id __user *ids)
911 struct lnet_process_id id;
912 struct lnet_peer_table *ptable;
913 struct lnet_peer *lp;
922 if (the_lnet.ln_state != LNET_STATE_RUNNING)
925 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
928 * Count the number of peers, and return E2BIG if the buffer
929 * is too small. We'll also return the desired size.
932 for (cpt = 0; cpt < lncpt; cpt++) {
933 ptable = the_lnet.ln_peer_tables[cpt];
934 count += ptable->pt_peers;
936 size = count * sizeof(*ids);
941 * Walk the peer lists and copy out the primary nids.
942 * This is safe because the peer lists are only modified
943 * while the ln_api_mutex is held. So we don't need to
944 * hold the lnet_net_lock as well, and can therefore
945 * directly call copy_to_user().
948 memset(&id, 0, sizeof(id));
949 id.pid = LNET_PID_LUSTRE;
951 for (cpt = 0; cpt < lncpt; cpt++) {
952 ptable = the_lnet.ln_peer_tables[cpt];
953 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
954 if (!nid_is_nid4(&lp->lp_primary_nid))
958 id.nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
959 if (copy_to_user(&ids[i], &id, sizeof(id)))
972 * Start pushes to peers that need to be updated for a configuration
973 * change on this node.
976 lnet_push_update_to_peers(int force)
978 struct lnet_peer_table *ptable;
979 struct lnet_peer *lp;
983 lnet_net_lock(LNET_LOCK_EX);
984 if (lnet_peer_discovery_disabled)
986 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
987 for (cpt = 0; cpt < lncpt; cpt++) {
988 ptable = the_lnet.ln_peer_tables[cpt];
989 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
991 spin_lock(&lp->lp_lock);
992 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
993 lp->lp_state |= LNET_PEER_FORCE_PUSH;
994 spin_unlock(&lp->lp_lock);
996 if (lnet_peer_needs_push(lp))
997 lnet_peer_queue_for_discovery(lp);
1000 lnet_net_unlock(LNET_LOCK_EX);
1001 wake_up(&the_lnet.ln_dc_waitq);
1004 /* find the NID in the preferred gateways for the remote peer
1006 * false: list is not empty and NID is not preferred
1007 * false: list is empty
1008 * true: nid is found in the list
1011 lnet_peer_is_pref_rtr_locked(struct lnet_peer_ni *lpni,
1012 struct lnet_nid *gw_nid)
1014 struct lnet_nid_list *ne;
1016 CDEBUG(D_NET, "%s: rtr pref emtpy: %d\n",
1017 libcfs_nidstr(&lpni->lpni_nid),
1018 list_empty(&lpni->lpni_rtr_pref_nids));
1020 if (list_empty(&lpni->lpni_rtr_pref_nids))
1023 /* iterate through all the preferred NIDs and see if any of them
1024 * matches the provided gw_nid
1026 list_for_each_entry(ne, &lpni->lpni_rtr_pref_nids, nl_list) {
1027 CDEBUG(D_NET, "Comparing pref %s with gw %s\n",
1028 libcfs_nidstr(&ne->nl_nid),
1029 libcfs_nidstr(gw_nid));
1030 if (nid_same(&ne->nl_nid, gw_nid))
1038 lnet_peer_clr_pref_rtrs(struct lnet_peer_ni *lpni)
1040 struct list_head zombies;
1041 struct lnet_nid_list *ne;
1042 struct lnet_nid_list *tmp;
1043 int cpt = lpni->lpni_cpt;
1045 INIT_LIST_HEAD(&zombies);
1048 list_splice_init(&lpni->lpni_rtr_pref_nids, &zombies);
1049 lnet_net_unlock(cpt);
1051 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1052 list_del(&ne->nl_list);
1053 LIBCFS_FREE(ne, sizeof(*ne));
1058 lnet_peer_add_pref_rtr(struct lnet_peer_ni *lpni,
1059 struct lnet_nid *gw_nid)
1061 int cpt = lpni->lpni_cpt;
1062 struct lnet_nid_list *ne = NULL;
1064 /* This function is called with api_mutex held. When the api_mutex
1065 * is held the list can not be modified, as it is only modified as
1066 * a result of applying a UDSP and that happens under api_mutex
1069 __must_hold(&the_lnet.ln_api_mutex);
1071 list_for_each_entry(ne, &lpni->lpni_rtr_pref_nids, nl_list) {
1072 if (nid_same(&ne->nl_nid, gw_nid))
1076 LIBCFS_CPT_ALLOC(ne, lnet_cpt_table(), cpt, sizeof(*ne));
1080 ne->nl_nid = *gw_nid;
1082 /* Lock the cpt to protect against addition and checks in the
1083 * selection algorithm
1086 list_add(&ne->nl_list, &lpni->lpni_rtr_pref_nids);
1087 lnet_net_unlock(cpt);
1093 * Test whether a ni is a preferred ni for this peer_ni, e.g, whether
1094 * this is a preferred point-to-point path. Call with lnet_net_lock in
1098 lnet_peer_is_pref_nid_locked(struct lnet_peer_ni *lpni, struct lnet_nid *nid)
1100 struct lnet_nid_list *ne;
1102 if (lpni->lpni_pref_nnids == 0)
1104 if (lpni->lpni_pref_nnids == 1)
1105 return nid_same(&lpni->lpni_pref.nid, nid);
1106 list_for_each_entry(ne, &lpni->lpni_pref.nids, nl_list) {
1107 if (nid_same(&ne->nl_nid, nid))
1114 * Set a single ni as preferred, provided no preferred ni is already
1115 * defined. Only to be used for non-multi-rail peer_ni.
1118 lnet_peer_ni_set_non_mr_pref_nid(struct lnet_peer_ni *lpni,
1119 struct lnet_nid *nid)
1125 spin_lock(&lpni->lpni_lock);
1126 if (LNET_NID_IS_ANY(nid)) {
1128 } else if (lpni->lpni_pref_nnids > 0) {
1130 } else if (lpni->lpni_pref_nnids == 0) {
1131 lpni->lpni_pref.nid = *nid;
1132 lpni->lpni_pref_nnids = 1;
1133 lpni->lpni_state |= LNET_PEER_NI_NON_MR_PREF;
1135 spin_unlock(&lpni->lpni_lock);
1137 CDEBUG(D_NET, "peer %s nid %s: %d\n",
1138 libcfs_nidstr(&lpni->lpni_nid), libcfs_nidstr(nid), rc);
1143 * Clear the preferred NID from a non-multi-rail peer_ni, provided
1144 * this preference was set by lnet_peer_ni_set_non_mr_pref_nid().
1147 lnet_peer_ni_clr_non_mr_pref_nid(struct lnet_peer_ni *lpni)
1151 spin_lock(&lpni->lpni_lock);
1152 if (lpni->lpni_state & LNET_PEER_NI_NON_MR_PREF) {
1153 lpni->lpni_pref_nnids = 0;
1154 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1155 } else if (lpni->lpni_pref_nnids == 0) {
1160 spin_unlock(&lpni->lpni_lock);
1162 CDEBUG(D_NET, "peer %s: %d\n",
1163 libcfs_nidstr(&lpni->lpni_nid), rc);
1168 lnet_peer_ni_set_selection_priority(struct lnet_peer_ni *lpni, __u32 priority)
1170 lpni->lpni_sel_priority = priority;
1174 * Clear the preferred NIDs from a non-multi-rail peer.
1177 lnet_peer_clr_non_mr_pref_nids(struct lnet_peer *lp)
1179 struct lnet_peer_ni *lpni = NULL;
1181 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
1182 lnet_peer_ni_clr_non_mr_pref_nid(lpni);
1186 lnet_peer_add_pref_nid(struct lnet_peer_ni *lpni, struct lnet_nid *nid)
1188 struct lnet_peer *lp = lpni->lpni_peer_net->lpn_peer;
1189 struct lnet_nid_list *ne1 = NULL;
1190 struct lnet_nid_list *ne2 = NULL;
1191 struct lnet_nid *tmp_nid = NULL;
1194 if (LNET_NID_IS_ANY(nid)) {
1199 if (lpni->lpni_pref_nnids == 1 &&
1200 nid_same(&lpni->lpni_pref.nid, nid)) {
1205 /* A non-MR node may have only one preferred NI per peer_ni */
1206 if (lpni->lpni_pref_nnids > 0 &&
1207 !(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1212 /* add the new preferred nid to the list of preferred nids */
1213 if (lpni->lpni_pref_nnids != 0) {
1214 size_t alloc_size = sizeof(*ne1);
1216 if (lpni->lpni_pref_nnids == 1) {
1217 tmp_nid = &lpni->lpni_pref.nid;
1218 INIT_LIST_HEAD(&lpni->lpni_pref.nids);
1221 list_for_each_entry(ne1, &lpni->lpni_pref.nids, nl_list) {
1222 if (nid_same(&ne1->nl_nid, nid)) {
1228 LIBCFS_CPT_ALLOC(ne1, lnet_cpt_table(), lpni->lpni_cpt,
1235 /* move the originally stored nid to the list */
1236 if (lpni->lpni_pref_nnids == 1) {
1237 LIBCFS_CPT_ALLOC(ne2, lnet_cpt_table(),
1238 lpni->lpni_cpt, alloc_size);
1243 INIT_LIST_HEAD(&ne2->nl_list);
1244 ne2->nl_nid = *tmp_nid;
1249 lnet_net_lock(LNET_LOCK_EX);
1250 spin_lock(&lpni->lpni_lock);
1251 if (lpni->lpni_pref_nnids == 0) {
1252 lpni->lpni_pref.nid = *nid;
1255 list_add_tail(&ne2->nl_list, &lpni->lpni_pref.nids);
1256 list_add_tail(&ne1->nl_list, &lpni->lpni_pref.nids);
1258 lpni->lpni_pref_nnids++;
1259 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1260 spin_unlock(&lpni->lpni_lock);
1261 lnet_net_unlock(LNET_LOCK_EX);
1264 if (rc == -EEXIST && (lpni->lpni_state & LNET_PEER_NI_NON_MR_PREF)) {
1265 spin_lock(&lpni->lpni_lock);
1266 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1267 spin_unlock(&lpni->lpni_lock);
1269 CDEBUG(D_NET, "peer %s nid %s: %d\n",
1270 libcfs_nidstr(&lp->lp_primary_nid), libcfs_nidstr(nid), rc);
1275 lnet_peer_del_pref_nid(struct lnet_peer_ni *lpni, struct lnet_nid *nid)
1277 struct lnet_peer *lp = lpni->lpni_peer_net->lpn_peer;
1278 struct lnet_nid_list *ne = NULL;
1281 if (lpni->lpni_pref_nnids == 0) {
1286 if (lpni->lpni_pref_nnids == 1) {
1287 if (!nid_same(&lpni->lpni_pref.nid, nid)) {
1292 list_for_each_entry(ne, &lpni->lpni_pref.nids, nl_list) {
1293 if (nid_same(&ne->nl_nid, nid))
1294 goto remove_nid_entry;
1302 lnet_net_lock(LNET_LOCK_EX);
1303 spin_lock(&lpni->lpni_lock);
1304 if (lpni->lpni_pref_nnids == 1)
1305 lpni->lpni_pref.nid = LNET_ANY_NID;
1307 list_del_init(&ne->nl_list);
1308 if (lpni->lpni_pref_nnids == 2) {
1309 struct lnet_nid_list *ne, *tmp;
1311 list_for_each_entry_safe(ne, tmp,
1312 &lpni->lpni_pref.nids,
1314 lpni->lpni_pref.nid = ne->nl_nid;
1315 list_del_init(&ne->nl_list);
1316 LIBCFS_FREE(ne, sizeof(*ne));
1320 lpni->lpni_pref_nnids--;
1321 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1322 spin_unlock(&lpni->lpni_lock);
1323 lnet_net_unlock(LNET_LOCK_EX);
1326 LIBCFS_FREE(ne, sizeof(*ne));
1328 CDEBUG(D_NET, "peer %s nid %s: %d\n",
1329 libcfs_nidstr(&lp->lp_primary_nid), libcfs_nidstr(nid), rc);
1334 lnet_peer_clr_pref_nids(struct lnet_peer_ni *lpni)
1336 struct list_head zombies;
1337 struct lnet_nid_list *ne;
1338 struct lnet_nid_list *tmp;
1340 INIT_LIST_HEAD(&zombies);
1342 lnet_net_lock(LNET_LOCK_EX);
1343 if (lpni->lpni_pref_nnids == 1)
1344 lpni->lpni_pref.nid = LNET_ANY_NID;
1345 else if (lpni->lpni_pref_nnids > 1)
1346 list_splice_init(&lpni->lpni_pref.nids, &zombies);
1347 lpni->lpni_pref_nnids = 0;
1348 lnet_net_unlock(LNET_LOCK_EX);
1350 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1351 list_del_init(&ne->nl_list);
1352 LIBCFS_FREE(ne, sizeof(*ne));
1357 lnet_peer_primary_nid_locked(lnet_nid_t nid, struct lnet_nid *result)
1359 /* FIXME handle large-addr nid */
1360 struct lnet_peer_ni *lpni;
1362 lnet_nid4_to_nid(nid, result);
1363 lpni = lnet_find_peer_ni_locked(nid);
1365 *result = lpni->lpni_peer_net->lpn_peer->lp_primary_nid;
1366 lnet_peer_ni_decref_locked(lpni);
1371 lnet_is_discovery_disabled_locked(struct lnet_peer *lp)
1372 __must_hold(&lp->lp_lock)
1374 if (lnet_peer_discovery_disabled)
1377 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL) ||
1378 (lp->lp_state & LNET_PEER_NO_DISCOVERY)) {
1389 lnet_is_discovery_disabled(struct lnet_peer *lp)
1393 spin_lock(&lp->lp_lock);
1394 rc = lnet_is_discovery_disabled_locked(lp);
1395 spin_unlock(&lp->lp_lock);
1401 LNetAddPeer(lnet_nid_t *nids, __u32 num_nids)
1403 lnet_nid_t pnid = 0;
1407 if (!nids || num_nids < 1)
1410 rc = LNetNIInit(LNET_PID_ANY);
1414 mutex_lock(&the_lnet.ln_api_mutex);
1416 mr = lnet_peer_discovery_disabled == 0;
1419 for (i = 0; i < num_nids; i++) {
1420 if (nids[i] == LNET_NID_LO_0)
1425 rc = lnet_add_peer_ni(pnid, LNET_NID_ANY, mr, true);
1426 } else if (lnet_peer_discovery_disabled) {
1427 rc = lnet_add_peer_ni(nids[i], LNET_NID_ANY, mr, true);
1429 rc = lnet_add_peer_ni(pnid, nids[i], mr, true);
1432 if (rc && rc != -EEXIST)
1437 mutex_unlock(&the_lnet.ln_api_mutex);
1441 return rc == -EEXIST ? 0 : rc;
1443 EXPORT_SYMBOL(LNetAddPeer);
1445 /* FIXME support large-addr nid */
1447 LNetPrimaryNID(lnet_nid_t nid)
1449 struct lnet_peer *lp;
1450 struct lnet_peer_ni *lpni;
1451 lnet_nid_t primary_nid = nid;
1455 if (nid == LNET_NID_LO_0)
1456 return LNET_NID_LO_0;
1458 cpt = lnet_net_lock_current();
1459 lpni = lnet_nid2peerni_locked(nid, LNET_NID_ANY, cpt);
1464 lp = lpni->lpni_peer_net->lpn_peer;
1466 /* If discovery is disabled locally then we needn't bother running
1467 * discovery here because discovery will not modify whatever
1468 * primary NID is currently set for this peer. If the specified peer is
1469 * down then this discovery can introduce long delays into the mount
1470 * process, so skip it if it isn't necessary.
1472 while (!lnet_peer_discovery_disabled && !lnet_peer_is_uptodate(lp)) {
1473 spin_lock(&lp->lp_lock);
1474 /* force a full discovery cycle */
1475 lp->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH;
1476 spin_unlock(&lp->lp_lock);
1478 rc = lnet_discover_peer_locked(lpni, cpt, true);
1481 /* The lpni (or lp) for this NID may have changed and our ref is
1482 * the only thing keeping the old one around. Release the ref
1483 * and lookup the lpni again
1485 lnet_peer_ni_decref_locked(lpni);
1486 lpni = lnet_find_peer_ni_locked(nid);
1491 lp = lpni->lpni_peer_net->lpn_peer;
1493 /* If we find that the peer has discovery disabled then we will
1494 * not modify whatever primary NID is currently set for this
1495 * peer. Thus, we can break out of this loop even if the peer
1496 * is not fully up to date.
1498 if (lnet_is_discovery_disabled(lp))
1501 primary_nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
1503 lnet_peer_ni_decref_locked(lpni);
1505 lnet_net_unlock(cpt);
1507 CDEBUG(D_NET, "NID %s primary NID %s rc %d\n", libcfs_nid2str(nid),
1508 libcfs_nid2str(primary_nid), rc);
1511 EXPORT_SYMBOL(LNetPrimaryNID);
1513 struct lnet_peer_net *
1514 lnet_peer_get_net_locked(struct lnet_peer *peer, __u32 net_id)
1516 struct lnet_peer_net *peer_net;
1517 list_for_each_entry(peer_net, &peer->lp_peer_nets, lpn_peer_nets) {
1518 if (peer_net->lpn_net_id == net_id)
1525 * Attach a peer_ni to a peer_net and peer. This function assumes
1526 * peer_ni is not already attached to the peer_net/peer. The peer_ni
1527 * may be attached to a different peer, in which case it will be
1528 * properly detached first. The whole operation is done atomically.
1530 * This function consumes the reference on lpni and Always returns 0.
1531 * This is the last function called from functions that do return an
1532 * int, so returning 0 here allows the compiler to do a tail call.
1535 lnet_peer_attach_peer_ni(struct lnet_peer *lp,
1536 struct lnet_peer_net *lpn,
1537 struct lnet_peer_ni *lpni,
1540 struct lnet_peer_table *ptable;
1541 bool new_lpn = false;
1544 /* Install the new peer_ni */
1545 lnet_net_lock(LNET_LOCK_EX);
1546 /* Add peer_ni to global peer table hash, if necessary. */
1547 if (list_empty(&lpni->lpni_hashlist)) {
1548 int hash = lnet_nid2peerhash(&lpni->lpni_nid);
1550 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
1551 list_add_tail(&lpni->lpni_hashlist, &ptable->pt_hash[hash]);
1552 ptable->pt_version++;
1553 lnet_peer_ni_addref_locked(lpni);
1556 /* Detach the peer_ni from an existing peer, if necessary. */
1557 if (lpni->lpni_peer_net) {
1558 LASSERT(lpni->lpni_peer_net != lpn);
1559 LASSERT(lpni->lpni_peer_net->lpn_peer != lp);
1560 lnet_peer_detach_peer_ni_locked(lpni);
1561 lnet_peer_net_decref_locked(lpni->lpni_peer_net);
1562 lpni->lpni_peer_net = NULL;
1565 /* Add peer_ni to peer_net */
1566 lpni->lpni_peer_net = lpn;
1567 if (nid_same(&lp->lp_primary_nid, &lpni->lpni_nid))
1568 list_add(&lpni->lpni_peer_nis, &lpn->lpn_peer_nis);
1570 list_add_tail(&lpni->lpni_peer_nis, &lpn->lpn_peer_nis);
1571 lnet_update_peer_net_healthv(lpni);
1572 lnet_peer_net_addref_locked(lpn);
1574 /* Add peer_net to peer */
1575 if (!lpn->lpn_peer) {
1578 if (nid_same(&lp->lp_primary_nid, &lpni->lpni_nid))
1579 list_add(&lpn->lpn_peer_nets, &lp->lp_peer_nets);
1581 list_add_tail(&lpn->lpn_peer_nets, &lp->lp_peer_nets);
1582 lnet_peer_addref_locked(lp);
1585 /* Add peer to global peer list, if necessary */
1586 ptable = the_lnet.ln_peer_tables[lp->lp_cpt];
1587 if (list_empty(&lp->lp_peer_list)) {
1588 list_add_tail(&lp->lp_peer_list, &ptable->pt_peer_list);
1593 /* Update peer state */
1594 spin_lock(&lp->lp_lock);
1595 if (flags & LNET_PEER_CONFIGURED) {
1596 if (!(lp->lp_state & LNET_PEER_CONFIGURED))
1597 lp->lp_state |= LNET_PEER_CONFIGURED;
1599 if (flags & LNET_PEER_MULTI_RAIL) {
1600 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1601 lp->lp_state |= LNET_PEER_MULTI_RAIL;
1602 lnet_peer_clr_non_mr_pref_nids(lp);
1605 spin_unlock(&lp->lp_lock);
1611 rc = lnet_udsp_apply_policies_on_lpn(lpn);
1613 CERROR("Failed to apply UDSPs on lpn %s\n",
1614 libcfs_net2str(lpn->lpn_net_id));
1616 rc = lnet_udsp_apply_policies_on_lpni(lpni);
1618 CERROR("Failed to apply UDSPs on lpni %s\n",
1619 libcfs_nidstr(&lpni->lpni_nid));
1621 CDEBUG(D_NET, "peer %s NID %s flags %#x\n",
1622 libcfs_nidstr(&lp->lp_primary_nid),
1623 libcfs_nidstr(&lpni->lpni_nid), flags);
1624 lnet_peer_ni_decref_locked(lpni);
1625 lnet_net_unlock(LNET_LOCK_EX);
1631 * Create a new peer, with nid as its primary nid.
1633 * Call with the lnet_api_mutex held.
1636 lnet_peer_add(lnet_nid_t nid4, unsigned int flags)
1638 struct lnet_nid nid;
1639 struct lnet_peer *lp;
1640 struct lnet_peer_net *lpn;
1641 struct lnet_peer_ni *lpni;
1644 LASSERT(nid4 != LNET_NID_ANY);
1647 * No need for the lnet_net_lock here, because the
1648 * lnet_api_mutex is held.
1650 lpni = lnet_find_peer_ni_locked(nid4);
1652 /* A peer with this NID already exists. */
1653 lp = lpni->lpni_peer_net->lpn_peer;
1654 lnet_peer_ni_decref_locked(lpni);
1656 * This is an error if the peer was configured and the
1657 * primary NID differs or an attempt is made to change
1658 * the Multi-Rail flag. Otherwise the assumption is
1659 * that an existing peer is being modified.
1661 if (lp->lp_state & LNET_PEER_CONFIGURED) {
1662 if (lnet_nid_to_nid4(&lp->lp_primary_nid) != nid4)
1664 else if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL)
1667 } else if (!(flags & LNET_PEER_CONFIGURED)) {
1668 if (lnet_nid_to_nid4(&lp->lp_primary_nid) == nid4) {
1673 /* Delete and recreate as a configured peer. */
1674 rc = lnet_peer_del(lp);
1679 /* Create peer, peer_net, and peer_ni. */
1681 lnet_nid4_to_nid(nid4, &nid);
1682 lp = lnet_peer_alloc(&nid);
1685 lpn = lnet_peer_net_alloc(LNET_NID_NET(&nid));
1688 lpni = lnet_peer_ni_alloc(&nid);
1692 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1695 LIBCFS_FREE(lpn, sizeof(*lpn));
1697 LIBCFS_FREE(lp, sizeof(*lp));
1699 CDEBUG(D_NET, "peer %s NID flags %#x: %d\n",
1700 libcfs_nid2str(nid4), flags, rc);
1705 * Add a NID to a peer. Call with ln_api_mutex held.
1708 * -EPERM: Non-DLC addition to a DLC-configured peer.
1709 * -EEXIST: The NID was configured by DLC for a different peer.
1710 * -ENOMEM: Out of memory.
1711 * -ENOTUNIQ: Adding a second peer NID on a single network on a
1712 * non-multi-rail peer.
1715 lnet_peer_add_nid(struct lnet_peer *lp, lnet_nid_t nid4, unsigned int flags)
1717 struct lnet_peer_net *lpn;
1718 struct lnet_peer_ni *lpni;
1719 struct lnet_nid nid;
1723 LASSERT(nid4 != LNET_NID_ANY);
1725 lnet_nid4_to_nid(nid4, &nid);
1727 /* A configured peer can only be updated through configuration. */
1728 if (!(flags & LNET_PEER_CONFIGURED)) {
1729 if (lp->lp_state & LNET_PEER_CONFIGURED) {
1736 * The MULTI_RAIL flag can be set but not cleared, because
1737 * that would leave the peer struct in an invalid state.
1739 if (flags & LNET_PEER_MULTI_RAIL) {
1740 spin_lock(&lp->lp_lock);
1741 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1742 lp->lp_state |= LNET_PEER_MULTI_RAIL;
1743 lnet_peer_clr_non_mr_pref_nids(lp);
1745 spin_unlock(&lp->lp_lock);
1746 } else if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
1751 lpni = lnet_find_peer_ni_locked(nid4);
1754 * A peer_ni already exists. This is only a problem if
1755 * it is not connected to this peer and was configured
1758 if (lpni->lpni_peer_net->lpn_peer == lp)
1760 if (lnet_peer_ni_is_configured(lpni)) {
1764 /* If this is the primary NID, destroy the peer. */
1765 if (lnet_peer_ni_is_primary(lpni)) {
1766 struct lnet_peer *rtr_lp =
1767 lpni->lpni_peer_net->lpn_peer;
1768 int rtr_refcount = rtr_lp->lp_rtr_refcount;
1770 * if we're trying to delete a router it means
1771 * we're moving this peer NI to a new peer so must
1772 * transfer router properties to the new peer
1774 if (rtr_refcount > 0) {
1775 flags |= LNET_PEER_RTR_NI_FORCE_DEL;
1776 lnet_rtr_transfer_to_peer(rtr_lp, lp);
1778 lnet_peer_del(lpni->lpni_peer_net->lpn_peer);
1779 lnet_peer_ni_decref_locked(lpni);
1780 lpni = lnet_peer_ni_alloc(&nid);
1787 lpni = lnet_peer_ni_alloc(&nid);
1795 * Get the peer_net. Check that we're not adding a second
1796 * peer_ni on a peer_net of a non-multi-rail peer.
1798 lpn = lnet_peer_get_net_locked(lp, LNET_NIDNET(nid4));
1800 lpn = lnet_peer_net_alloc(LNET_NIDNET(nid4));
1805 } else if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1810 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1813 lnet_peer_ni_decref_locked(lpni);
1815 CDEBUG(D_NET, "peer %s NID %s flags %#x: %d\n",
1816 libcfs_nidstr(&lp->lp_primary_nid), libcfs_nid2str(nid4),
1822 * Update the primary NID of a peer, if possible.
1824 * Call with the lnet_api_mutex held.
1827 lnet_peer_set_primary_nid(struct lnet_peer *lp, lnet_nid_t nid,
1830 struct lnet_nid old = lp->lp_primary_nid;
1833 if (lnet_nid_to_nid4(&lp->lp_primary_nid) == nid)
1836 lnet_nid4_to_nid(nid, &lp->lp_primary_nid);
1838 rc = lnet_peer_add_nid(lp, nid, flags);
1840 lp->lp_primary_nid = old;
1844 CDEBUG(D_NET, "peer %s NID %s: %d\n",
1845 libcfs_nidstr(&old), libcfs_nid2str(nid), rc);
1851 * lpni creation initiated due to traffic either sending or receiving.
1854 lnet_peer_ni_traffic_add(struct lnet_nid *nid, struct lnet_nid *pref)
1856 struct lnet_peer *lp;
1857 struct lnet_peer_net *lpn;
1858 struct lnet_peer_ni *lpni;
1862 if (LNET_NID_IS_ANY(nid)) {
1867 /* lnet_net_lock is not needed here because ln_api_lock is held */
1868 lpni = lnet_peer_ni_find_locked(nid);
1871 * We must have raced with another thread. Since we
1872 * know next to nothing about a peer_ni created by
1873 * traffic, we just assume everything is ok and
1876 lnet_peer_ni_decref_locked(lpni);
1880 /* Create peer, peer_net, and peer_ni. */
1882 lp = lnet_peer_alloc(nid);
1885 lpn = lnet_peer_net_alloc(LNET_NID_NET(nid));
1888 lpni = lnet_peer_ni_alloc(nid);
1891 lnet_peer_ni_set_non_mr_pref_nid(lpni, pref);
1893 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1896 LIBCFS_FREE(lpn, sizeof(*lpn));
1898 LIBCFS_FREE(lp, sizeof(*lp));
1900 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nidstr(nid), rc);
1905 * Implementation of IOC_LIBCFS_ADD_PEER_NI.
1907 * This API handles the following combinations:
1908 * Create a peer with its primary NI if only the prim_nid is provided
1909 * Add a NID to a peer identified by the prim_nid. The peer identified
1910 * by the prim_nid must already exist.
1911 * The peer being created may be non-MR.
1913 * The caller must hold ln_api_mutex. This prevents the peer from
1914 * being created/modified/deleted by a different thread.
1917 lnet_add_peer_ni(lnet_nid_t prim_nid, lnet_nid_t nid, bool mr, bool temp)
1919 struct lnet_peer *lp = NULL;
1920 struct lnet_peer_ni *lpni;
1921 unsigned int flags = 0;
1923 /* The prim_nid must always be specified */
1924 if (prim_nid == LNET_NID_ANY)
1928 flags = LNET_PEER_CONFIGURED;
1931 flags |= LNET_PEER_MULTI_RAIL;
1934 * If nid isn't specified, we must create a new peer with
1935 * prim_nid as its primary nid.
1937 if (nid == LNET_NID_ANY)
1938 return lnet_peer_add(prim_nid, flags);
1940 /* Look up the prim_nid, which must exist. */
1941 lpni = lnet_find_peer_ni_locked(prim_nid);
1944 lnet_peer_ni_decref_locked(lpni);
1945 lp = lpni->lpni_peer_net->lpn_peer;
1947 /* Peer must have been configured. */
1948 if (!temp && !(lp->lp_state & LNET_PEER_CONFIGURED)) {
1949 CDEBUG(D_NET, "peer %s was not configured\n",
1950 libcfs_nid2str(prim_nid));
1954 /* Primary NID must match */
1955 if (lnet_nid_to_nid4(&lp->lp_primary_nid) != prim_nid) {
1956 CDEBUG(D_NET, "prim_nid %s is not primary for peer %s\n",
1957 libcfs_nid2str(prim_nid),
1958 libcfs_nidstr(&lp->lp_primary_nid));
1962 /* Multi-Rail flag must match. */
1963 if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL) {
1964 CDEBUG(D_NET, "multi-rail state mismatch for peer %s\n",
1965 libcfs_nid2str(prim_nid));
1969 return lnet_peer_add_nid(lp, nid, flags);
1973 * Implementation of IOC_LIBCFS_DEL_PEER_NI.
1975 * This API handles the following combinations:
1976 * Delete a NI from a peer if both prim_nid and nid are provided.
1977 * Delete a peer if only prim_nid is provided.
1978 * Delete a peer if its primary nid is provided.
1980 * The caller must hold ln_api_mutex. This prevents the peer from
1981 * being modified/deleted by a different thread.
1984 lnet_del_peer_ni(lnet_nid_t prim_nid, lnet_nid_t nid)
1986 struct lnet_peer *lp;
1987 struct lnet_peer_ni *lpni;
1990 if (prim_nid == LNET_NID_ANY)
1993 lpni = lnet_find_peer_ni_locked(prim_nid);
1996 lnet_peer_ni_decref_locked(lpni);
1997 lp = lpni->lpni_peer_net->lpn_peer;
1999 if (prim_nid != lnet_nid_to_nid4(&lp->lp_primary_nid)) {
2000 CDEBUG(D_NET, "prim_nid %s is not primary for peer %s\n",
2001 libcfs_nid2str(prim_nid),
2002 libcfs_nidstr(&lp->lp_primary_nid));
2006 lnet_net_lock(LNET_LOCK_EX);
2007 if (lp->lp_rtr_refcount > 0) {
2008 lnet_net_unlock(LNET_LOCK_EX);
2009 CERROR("%s is a router. Can not be deleted\n",
2010 libcfs_nid2str(prim_nid));
2013 lnet_net_unlock(LNET_LOCK_EX);
2015 if (nid == LNET_NID_ANY || nid == lnet_nid_to_nid4(&lp->lp_primary_nid))
2016 return lnet_peer_del(lp);
2018 flags = LNET_PEER_CONFIGURED;
2019 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
2020 flags |= LNET_PEER_MULTI_RAIL;
2022 return lnet_peer_del_nid(lp, nid, flags);
2026 lnet_destroy_peer_ni_locked(struct kref *ref)
2028 struct lnet_peer_ni *lpni = container_of(ref, struct lnet_peer_ni,
2030 struct lnet_peer_table *ptable;
2031 struct lnet_peer_net *lpn;
2033 CDEBUG(D_NET, "%p nid %s\n", lpni, libcfs_nidstr(&lpni->lpni_nid));
2035 LASSERT(kref_read(&lpni->lpni_kref) == 0);
2036 LASSERT(list_empty(&lpni->lpni_txq));
2037 LASSERT(lpni->lpni_txqnob == 0);
2038 LASSERT(list_empty(&lpni->lpni_peer_nis));
2039 LASSERT(list_empty(&lpni->lpni_on_remote_peer_ni_list));
2041 lpn = lpni->lpni_peer_net;
2042 lpni->lpni_peer_net = NULL;
2043 lpni->lpni_net = NULL;
2045 if (!list_empty(&lpni->lpni_hashlist)) {
2046 /* remove the peer ni from the zombie list */
2047 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
2048 spin_lock(&ptable->pt_zombie_lock);
2049 list_del_init(&lpni->lpni_hashlist);
2050 ptable->pt_zombies--;
2051 spin_unlock(&ptable->pt_zombie_lock);
2054 if (lpni->lpni_pref_nnids > 1) {
2055 struct lnet_nid_list *ne, *tmp;
2057 list_for_each_entry_safe(ne, tmp, &lpni->lpni_pref.nids,
2059 list_del_init(&ne->nl_list);
2060 LIBCFS_FREE(ne, sizeof(*ne));
2063 LIBCFS_FREE(lpni, sizeof(*lpni));
2066 lnet_peer_net_decref_locked(lpn);
2069 struct lnet_peer_ni *
2070 lnet_nid2peerni_ex(struct lnet_nid *nid, int cpt)
2072 struct lnet_peer_ni *lpni = NULL;
2075 if (the_lnet.ln_state != LNET_STATE_RUNNING)
2076 return ERR_PTR(-ESHUTDOWN);
2079 * find if a peer_ni already exists.
2080 * If so then just return that.
2082 lpni = lnet_peer_ni_find_locked(nid);
2086 lnet_net_unlock(cpt);
2088 rc = lnet_peer_ni_traffic_add(nid, NULL);
2091 goto out_net_relock;
2094 lpni = lnet_peer_ni_find_locked(nid);
2104 * Get a peer_ni for the given nid, create it if necessary. Takes a
2105 * hold on the peer_ni.
2107 struct lnet_peer_ni *
2108 lnet_peerni_by_nid_locked(struct lnet_nid *nid,
2109 struct lnet_nid *pref, int cpt)
2111 struct lnet_peer_ni *lpni = NULL;
2114 if (the_lnet.ln_state != LNET_STATE_RUNNING)
2115 return ERR_PTR(-ESHUTDOWN);
2118 * find if a peer_ni already exists.
2119 * If so then just return that.
2121 lpni = lnet_peer_ni_find_locked(nid);
2127 * use the lnet_api_mutex to serialize the creation of the peer_ni
2128 * and the creation/deletion of the local ni/net. When a local ni is
2129 * created, if there exists a set of peer_nis on that network,
2130 * they need to be traversed and updated. When a local NI is
2131 * deleted, which could result in a network being deleted, then
2132 * all peer nis on that network need to be removed as well.
2134 * Creation through traffic should also be serialized with
2135 * creation through DLC.
2137 lnet_net_unlock(cpt);
2138 mutex_lock(&the_lnet.ln_api_mutex);
2140 * Shutdown is only set under the ln_api_lock, so a single
2141 * check here is sufficent.
2143 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
2144 lpni = ERR_PTR(-ESHUTDOWN);
2145 goto out_mutex_unlock;
2148 rc = lnet_peer_ni_traffic_add(nid, pref);
2151 goto out_mutex_unlock;
2154 lpni = lnet_peer_ni_find_locked(nid);
2158 mutex_unlock(&the_lnet.ln_api_mutex);
2161 /* Lock has been dropped, check again for shutdown. */
2162 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
2164 lnet_peer_ni_decref_locked(lpni);
2165 lpni = ERR_PTR(-ESHUTDOWN);
2171 struct lnet_peer_ni *
2172 lnet_nid2peerni_locked(lnet_nid_t nid4, lnet_nid_t pref4, int cpt)
2174 struct lnet_nid nid, pref;
2176 lnet_nid4_to_nid(nid4, &nid);
2177 lnet_nid4_to_nid(pref4, &pref);
2178 if (pref4 == LNET_NID_ANY)
2179 return lnet_peerni_by_nid_locked(&nid, NULL, cpt);
2181 return lnet_peerni_by_nid_locked(&nid, &pref, cpt);
2185 lnet_peer_gw_discovery(struct lnet_peer *lp)
2189 spin_lock(&lp->lp_lock);
2190 if (lp->lp_state & LNET_PEER_RTR_DISCOVERY)
2192 spin_unlock(&lp->lp_lock);
2198 lnet_peer_is_uptodate(struct lnet_peer *lp)
2202 spin_lock(&lp->lp_lock);
2203 rc = lnet_peer_is_uptodate_locked(lp);
2204 spin_unlock(&lp->lp_lock);
2209 * Is a peer uptodate from the point of view of discovery?
2211 * If it is currently being processed, obviously not.
2212 * A forced Ping or Push is also handled by the discovery thread.
2214 * Otherwise look at whether the peer needs rediscovering.
2217 lnet_peer_is_uptodate_locked(struct lnet_peer *lp)
2218 __must_hold(&lp->lp_lock)
2222 if (lp->lp_state & (LNET_PEER_DISCOVERING |
2223 LNET_PEER_FORCE_PING |
2224 LNET_PEER_FORCE_PUSH)) {
2226 } else if (lp->lp_state & LNET_PEER_REDISCOVER) {
2228 } else if (lnet_peer_needs_push(lp)) {
2230 } else if (lp->lp_state & LNET_PEER_DISCOVERED) {
2231 if (lp->lp_state & LNET_PEER_NIDS_UPTODATE)
2242 /* Add the message to the peer's lp_dc_pendq and queue the peer for discovery */
2244 lnet_peer_queue_message(struct lnet_peer *lp, struct lnet_msg *msg)
2246 /* The discovery thread holds net_lock/EX and lp_lock when it splices
2247 * the lp_dc_pendq onto a local list for resending. Thus, we do the same
2248 * when adding to the list and queuing the peer to ensure that we do not
2249 * strand any messages on the lp_dc_pendq. This scheme ensures the
2250 * message will be resent even if the peer is already being discovered.
2251 * Therefore we needn't check the return value of
2252 * lnet_peer_queue_for_discovery(lp).
2254 lnet_net_lock(LNET_LOCK_EX);
2255 spin_lock(&lp->lp_lock);
2256 list_add_tail(&msg->msg_list, &lp->lp_dc_pendq);
2257 spin_unlock(&lp->lp_lock);
2258 lnet_peer_queue_for_discovery(lp);
2259 lnet_net_unlock(LNET_LOCK_EX);
2263 * Queue a peer for the attention of the discovery thread. Call with
2264 * lnet_net_lock/EX held. Returns 0 if the peer was queued, and
2265 * -EALREADY if the peer was already queued.
2267 static int lnet_peer_queue_for_discovery(struct lnet_peer *lp)
2271 spin_lock(&lp->lp_lock);
2272 if (!(lp->lp_state & LNET_PEER_DISCOVERING))
2273 lp->lp_state |= LNET_PEER_DISCOVERING;
2274 spin_unlock(&lp->lp_lock);
2275 if (list_empty(&lp->lp_dc_list)) {
2276 lnet_peer_addref_locked(lp);
2277 list_add_tail(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2278 wake_up(&the_lnet.ln_dc_waitq);
2284 CDEBUG(D_NET, "Queue peer %s: %d\n",
2285 libcfs_nidstr(&lp->lp_primary_nid), rc);
2291 * Discovery of a peer is complete. Wake all waiters on the peer.
2292 * Call with lnet_net_lock/EX held.
2294 static void lnet_peer_discovery_complete(struct lnet_peer *lp, int dc_error)
2296 struct lnet_msg *msg, *tmp;
2298 LIST_HEAD(pending_msgs);
2300 CDEBUG(D_NET, "Discovery complete. Dequeue peer %s\n",
2301 libcfs_nidstr(&lp->lp_primary_nid));
2303 list_del_init(&lp->lp_dc_list);
2304 spin_lock(&lp->lp_lock);
2306 lp->lp_dc_error = dc_error;
2307 lp->lp_state &= ~LNET_PEER_DISCOVERING;
2308 lp->lp_state |= LNET_PEER_REDISCOVER;
2310 list_splice_init(&lp->lp_dc_pendq, &pending_msgs);
2311 spin_unlock(&lp->lp_lock);
2312 wake_up(&lp->lp_dc_waitq);
2314 if (lp->lp_rtr_refcount > 0)
2315 lnet_router_discovery_complete(lp);
2317 lnet_net_unlock(LNET_LOCK_EX);
2319 /* iterate through all pending messages and send them again */
2320 list_for_each_entry_safe(msg, tmp, &pending_msgs, msg_list) {
2321 list_del_init(&msg->msg_list);
2323 lnet_finalize(msg, dc_error);
2327 CDEBUG(D_NET, "sending pending message %s to target %s\n",
2328 lnet_msgtyp2str(msg->msg_type),
2329 libcfs_idstr(&msg->msg_target));
2330 rc = lnet_send(&msg->msg_src_nid_param, msg,
2331 &msg->msg_rtr_nid_param);
2333 CNETERR("Error sending %s to %s: %d\n",
2334 lnet_msgtyp2str(msg->msg_type),
2335 libcfs_idstr(&msg->msg_target), rc);
2336 lnet_finalize(msg, rc);
2339 lnet_net_lock(LNET_LOCK_EX);
2340 lnet_peer_decref_locked(lp);
2344 * Handle inbound push.
2345 * Like any event handler, called with lnet_res_lock/CPT held.
2347 void lnet_peer_push_event(struct lnet_event *ev)
2349 struct lnet_ping_buffer *pbuf;
2350 struct lnet_peer *lp;
2352 pbuf = LNET_PING_INFO_TO_BUFFER(ev->md_start + ev->offset);
2354 /* lnet_find_peer() adds a refcount */
2355 lp = lnet_find_peer(&ev->source.nid);
2357 CDEBUG(D_NET, "Push Put from unknown %s (source %s). Ignoring...\n",
2358 libcfs_nidstr(&ev->initiator.nid),
2359 libcfs_nidstr(&ev->source.nid));
2360 pbuf->pb_needs_post = true;
2364 /* Ensure peer state remains consistent while we modify it. */
2365 spin_lock(&lp->lp_lock);
2368 * If some kind of error happened the contents of the message
2369 * cannot be used. Clear the NIDS_UPTODATE and set the
2370 * FORCE_PING flag to trigger a ping.
2373 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2374 lp->lp_state |= LNET_PEER_FORCE_PING;
2375 CDEBUG(D_NET, "Push Put error %d from %s (source %s)\n",
2377 libcfs_nidstr(&lp->lp_primary_nid),
2378 libcfs_nidstr(&ev->source.nid));
2383 * A push with invalid or corrupted info. Clear the UPTODATE
2384 * flag to trigger a ping.
2386 if (lnet_ping_info_validate(&pbuf->pb_info)) {
2387 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2388 lp->lp_state |= LNET_PEER_FORCE_PING;
2389 CDEBUG(D_NET, "Corrupted Push from %s\n",
2390 libcfs_nidstr(&lp->lp_primary_nid));
2395 * Make sure we'll allocate the correct size ping buffer when
2398 if (lp->lp_data_nnis < pbuf->pb_info.pi_nnis)
2399 lp->lp_data_nnis = pbuf->pb_info.pi_nnis;
2402 * A non-Multi-Rail peer is not supposed to be capable of
2405 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)) {
2406 CERROR("Push from non-Multi-Rail peer %s dropped\n",
2407 libcfs_nidstr(&lp->lp_primary_nid));
2412 * The peer may have discovery disabled at its end. Set
2413 * NO_DISCOVERY as appropriate.
2415 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_DISCOVERY)) {
2416 CDEBUG(D_NET, "Peer %s has discovery disabled\n",
2417 libcfs_nidstr(&lp->lp_primary_nid));
2419 * Mark the peer for deletion if we already know about it
2420 * and it's going from discovery set to no discovery set
2422 if (!(lp->lp_state & (LNET_PEER_NO_DISCOVERY |
2423 LNET_PEER_DISCOVERING)) &&
2424 lp->lp_state & LNET_PEER_DISCOVERED) {
2425 CDEBUG(D_NET, "Marking %s:0x%x for deletion\n",
2426 libcfs_nidstr(&lp->lp_primary_nid),
2428 lp->lp_state |= LNET_PEER_MARK_DELETION;
2430 lp->lp_state |= LNET_PEER_NO_DISCOVERY;
2431 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
2432 CDEBUG(D_NET, "Peer %s has discovery enabled\n",
2433 libcfs_nidstr(&lp->lp_primary_nid));
2434 lp->lp_state &= ~LNET_PEER_NO_DISCOVERY;
2438 * Update the MULTI_RAIL flag based on the push. If the peer
2439 * was configured with DLC then the setting should match what
2441 * NB: We verified above that the MR feature bit is set in pi_features
2443 if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2444 CDEBUG(D_NET, "peer %s(%p) is MR\n",
2445 libcfs_nidstr(&lp->lp_primary_nid), lp);
2446 } else if (lp->lp_state & LNET_PEER_CONFIGURED) {
2447 CWARN("Push says %s is Multi-Rail, DLC says not\n",
2448 libcfs_nidstr(&lp->lp_primary_nid));
2449 } else if (lnet_peer_discovery_disabled) {
2450 CDEBUG(D_NET, "peer %s(%p) not MR: DD disabled locally\n",
2451 libcfs_nidstr(&lp->lp_primary_nid), lp);
2452 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
2453 CDEBUG(D_NET, "peer %s(%p) not MR: DD disabled remotely\n",
2454 libcfs_nidstr(&lp->lp_primary_nid), lp);
2456 CDEBUG(D_NET, "peer %s(%p) is MR capable\n",
2457 libcfs_nidstr(&lp->lp_primary_nid), lp);
2458 lp->lp_state |= LNET_PEER_MULTI_RAIL;
2459 lnet_peer_clr_non_mr_pref_nids(lp);
2463 * Check for truncation of the Put message. Clear the
2464 * NIDS_UPTODATE flag and set FORCE_PING to trigger a ping,
2465 * and tell discovery to allocate a bigger buffer.
2467 if (ev->mlength < ev->rlength) {
2468 if (the_lnet.ln_push_target_nnis < pbuf->pb_info.pi_nnis)
2469 the_lnet.ln_push_target_nnis = pbuf->pb_info.pi_nnis;
2470 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2471 lp->lp_state |= LNET_PEER_FORCE_PING;
2472 CDEBUG(D_NET, "Truncated Push from %s (%d nids)\n",
2473 libcfs_nidstr(&lp->lp_primary_nid),
2474 pbuf->pb_info.pi_nnis);
2478 /* always assume new data */
2479 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2480 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2483 * If there is data present that hasn't been processed yet,
2484 * we'll replace it if the Put contained newer data and it
2485 * fits. We're racing with a Ping or earlier Push in this
2488 if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
2489 if (LNET_PING_BUFFER_SEQNO(pbuf) >
2490 LNET_PING_BUFFER_SEQNO(lp->lp_data) &&
2491 pbuf->pb_info.pi_nnis <= lp->lp_data->pb_nnis) {
2492 memcpy(&lp->lp_data->pb_info, &pbuf->pb_info,
2493 LNET_PING_INFO_SIZE(pbuf->pb_info.pi_nnis));
2494 CDEBUG(D_NET, "Ping/Push race from %s: %u vs %u\n",
2495 libcfs_nidstr(&lp->lp_primary_nid),
2496 LNET_PING_BUFFER_SEQNO(pbuf),
2497 LNET_PING_BUFFER_SEQNO(lp->lp_data));
2503 * Allocate a buffer to copy the data. On a failure we drop
2504 * the Push and set FORCE_PING to force the discovery
2505 * thread to fix the problem by pinging the peer.
2507 lp->lp_data = lnet_ping_buffer_alloc(lp->lp_data_nnis, GFP_ATOMIC);
2509 lp->lp_state |= LNET_PEER_FORCE_PING;
2510 CDEBUG(D_NET, "Cannot allocate Push buffer for %s %u\n",
2511 libcfs_nidstr(&lp->lp_primary_nid),
2512 LNET_PING_BUFFER_SEQNO(pbuf));
2517 memcpy(&lp->lp_data->pb_info, &pbuf->pb_info,
2518 LNET_PING_INFO_SIZE(pbuf->pb_info.pi_nnis));
2519 lp->lp_state |= LNET_PEER_DATA_PRESENT;
2520 CDEBUG(D_NET, "Received Push %s %u\n",
2521 libcfs_nidstr(&lp->lp_primary_nid),
2522 LNET_PING_BUFFER_SEQNO(pbuf));
2525 /* We've processed this buffer. It can be reposted */
2526 pbuf->pb_needs_post = true;
2529 * Queue the peer for discovery if not done, force it on the request
2530 * queue and wake the discovery thread if the peer was already queued,
2531 * because its status changed.
2533 spin_unlock(&lp->lp_lock);
2534 lnet_net_lock(LNET_LOCK_EX);
2535 if (!lnet_peer_is_uptodate(lp) && lnet_peer_queue_for_discovery(lp)) {
2536 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2537 wake_up(&the_lnet.ln_dc_waitq);
2539 /* Drop refcount from lookup */
2540 lnet_peer_decref_locked(lp);
2541 lnet_net_unlock(LNET_LOCK_EX);
2545 * Clear the discovery error state, unless we're already discovering
2546 * this peer, in which case the error is current.
2548 static void lnet_peer_clear_discovery_error(struct lnet_peer *lp)
2550 spin_lock(&lp->lp_lock);
2551 if (!(lp->lp_state & LNET_PEER_DISCOVERING))
2552 lp->lp_dc_error = 0;
2553 spin_unlock(&lp->lp_lock);
2557 * Peer discovery slow path. The ln_api_mutex is held on entry, and
2558 * dropped/retaken within this function. An lnet_peer_ni is passed in
2559 * because discovery could tear down an lnet_peer.
2562 lnet_discover_peer_locked(struct lnet_peer_ni *lpni, int cpt, bool block)
2565 struct lnet_peer *lp;
2570 lnet_net_unlock(cpt);
2571 lnet_net_lock(LNET_LOCK_EX);
2572 lp = lpni->lpni_peer_net->lpn_peer;
2573 lnet_peer_clear_discovery_error(lp);
2576 * We're willing to be interrupted. The lpni can become a
2577 * zombie if we race with DLC, so we must check for that.
2580 /* Keep lp alive when the lnet_net_lock is unlocked */
2581 lnet_peer_addref_locked(lp);
2582 prepare_to_wait(&lp->lp_dc_waitq, &wait, TASK_INTERRUPTIBLE);
2583 if (signal_pending(current))
2585 if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING)
2588 * Don't repeat discovery if discovery is disabled. This is
2589 * done to ensure we can use discovery as a standard ping as
2590 * well for backwards compatibility with routers which do not
2591 * have discovery or have discovery disabled
2593 if (lnet_is_discovery_disabled(lp) && count > 0)
2595 if (lp->lp_dc_error)
2597 if (lnet_peer_is_uptodate(lp))
2599 lnet_peer_queue_for_discovery(lp);
2601 CDEBUG(D_NET, "Discovery attempt # %d\n", count);
2604 * If caller requested a non-blocking operation then
2605 * return immediately. Once discovery is complete any
2606 * pending messages that were stopped due to discovery
2607 * will be transmitted.
2612 lnet_net_unlock(LNET_LOCK_EX);
2614 finish_wait(&lp->lp_dc_waitq, &wait);
2615 lnet_net_lock(LNET_LOCK_EX);
2616 lnet_peer_decref_locked(lp);
2617 /* Peer may have changed */
2618 lp = lpni->lpni_peer_net->lpn_peer;
2620 finish_wait(&lp->lp_dc_waitq, &wait);
2622 lnet_net_unlock(LNET_LOCK_EX);
2624 lnet_peer_decref_locked(lp);
2626 * The peer may have changed, so re-check and rediscover if that turns
2627 * out to have been the case. The reference count on lp ensured that
2628 * even if it was unlinked from lpni the memory could not be recycled.
2629 * Thus the check below is sufficient to determine whether the peer
2630 * changed. If the peer changed, then lp must not be dereferenced.
2632 if (lp != lpni->lpni_peer_net->lpn_peer)
2635 if (signal_pending(current))
2637 else if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING)
2639 else if (lp->lp_dc_error)
2640 rc = lp->lp_dc_error;
2642 CDEBUG(D_NET, "non-blocking discovery\n");
2643 else if (!lnet_peer_is_uptodate(lp) && !lnet_is_discovery_disabled(lp))
2646 CDEBUG(D_NET, "peer %s NID %s: %d. %s\n",
2647 (lp ? libcfs_nidstr(&lp->lp_primary_nid) : "(none)"),
2648 libcfs_nidstr(&lpni->lpni_nid), rc,
2649 (!block) ? "pending discovery" : "discovery complete");
2654 /* Handle an incoming ack for a push. */
2656 lnet_discovery_event_ack(struct lnet_peer *lp, struct lnet_event *ev)
2658 struct lnet_ping_buffer *pbuf;
2660 pbuf = LNET_PING_INFO_TO_BUFFER(ev->md_start);
2661 spin_lock(&lp->lp_lock);
2662 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2663 lp->lp_push_error = ev->status;
2665 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2667 lp->lp_node_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2668 spin_unlock(&lp->lp_lock);
2670 CDEBUG(D_NET, "peer %s ev->status %d\n",
2671 libcfs_nidstr(&lp->lp_primary_nid), ev->status);
2674 /* Handle a Reply message. This is the reply to a Ping message. */
2676 lnet_discovery_event_reply(struct lnet_peer *lp, struct lnet_event *ev)
2678 struct lnet_ping_buffer *pbuf;
2681 spin_lock(&lp->lp_lock);
2683 lp->lp_disc_src_nid = ev->target.nid;
2684 lp->lp_disc_dst_nid = ev->source.nid;
2687 * If some kind of error happened the contents of message
2688 * cannot be used. Set PING_FAILED to trigger a retry.
2691 lp->lp_state |= LNET_PEER_PING_FAILED;
2692 lp->lp_ping_error = ev->status;
2693 CDEBUG(D_NET, "Ping Reply error %d from %s (source %s)\n",
2695 libcfs_nidstr(&lp->lp_primary_nid),
2696 libcfs_nidstr(&ev->source.nid));
2700 pbuf = LNET_PING_INFO_TO_BUFFER(ev->md_start);
2701 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
2702 lnet_swap_pinginfo(pbuf);
2705 * A reply with invalid or corrupted info. Set PING_FAILED to
2708 rc = lnet_ping_info_validate(&pbuf->pb_info);
2710 lp->lp_state |= LNET_PEER_PING_FAILED;
2711 lp->lp_ping_error = 0;
2712 CDEBUG(D_NET, "Corrupted Ping Reply from %s: %d\n",
2713 libcfs_nidstr(&lp->lp_primary_nid), rc);
2718 * The peer may have discovery disabled at its end. Set
2719 * NO_DISCOVERY as appropriate.
2721 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_DISCOVERY) ||
2722 lnet_peer_discovery_disabled) {
2723 CDEBUG(D_NET, "Peer %s has discovery disabled\n",
2724 libcfs_nidstr(&lp->lp_primary_nid));
2726 /* Detect whether this peer has toggled discovery from on to
2727 * off and whether we can delete and re-create the peer. Peers
2728 * that were manually configured cannot be deleted by discovery.
2729 * We need to delete this peer and re-create it if the peer was
2730 * not configured manually, is currently considered DD capable,
2732 * 1. We've already discovered the peer (the peer has toggled
2733 * the discovery feature from on to off), or
2734 * 2. The peer is considered MR, but it was not user configured
2735 * (this was a "temporary" peer created via the kernel APIs
2736 * that we're discovering for the first time)
2738 if (!(lp->lp_state & (LNET_PEER_CONFIGURED |
2739 LNET_PEER_NO_DISCOVERY)) &&
2740 (lp->lp_state & (LNET_PEER_DISCOVERED |
2741 LNET_PEER_MULTI_RAIL))) {
2742 CDEBUG(D_NET, "Marking %s:0x%x for deletion\n",
2743 libcfs_nidstr(&lp->lp_primary_nid),
2745 lp->lp_state |= LNET_PEER_MARK_DELETION;
2747 lp->lp_state |= LNET_PEER_NO_DISCOVERY;
2749 CDEBUG(D_NET, "Peer %s has discovery enabled\n",
2750 libcfs_nidstr(&lp->lp_primary_nid));
2751 lp->lp_state &= ~LNET_PEER_NO_DISCOVERY;
2755 * Update the MULTI_RAIL flag based on the reply. If the peer
2756 * was configured with DLC then the setting should match what
2759 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL) {
2760 if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2761 CDEBUG(D_NET, "peer %s(%p) is MR\n",
2762 libcfs_nidstr(&lp->lp_primary_nid), lp);
2763 } else if (lp->lp_state & LNET_PEER_CONFIGURED) {
2764 CWARN("Reply says %s is Multi-Rail, DLC says not\n",
2765 libcfs_nidstr(&lp->lp_primary_nid));
2766 } else if (lnet_peer_discovery_disabled) {
2768 "peer %s(%p) not MR: DD disabled locally\n",
2769 libcfs_nidstr(&lp->lp_primary_nid), lp);
2770 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
2772 "peer %s(%p) not MR: DD disabled remotely\n",
2773 libcfs_nidstr(&lp->lp_primary_nid), lp);
2775 CDEBUG(D_NET, "peer %s(%p) is MR capable\n",
2776 libcfs_nidstr(&lp->lp_primary_nid), lp);
2777 lp->lp_state |= LNET_PEER_MULTI_RAIL;
2778 lnet_peer_clr_non_mr_pref_nids(lp);
2780 } else if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2781 if (lp->lp_state & LNET_PEER_CONFIGURED) {
2782 CWARN("DLC says %s is Multi-Rail, Reply says not\n",
2783 libcfs_nidstr(&lp->lp_primary_nid));
2785 CERROR("Multi-Rail state vanished from %s\n",
2786 libcfs_nidstr(&lp->lp_primary_nid));
2787 lp->lp_state &= ~LNET_PEER_MULTI_RAIL;
2792 * Make sure we'll allocate the correct size ping buffer when
2795 if (lp->lp_data_nnis < pbuf->pb_info.pi_nnis)
2796 lp->lp_data_nnis = pbuf->pb_info.pi_nnis;
2799 * Check for truncation of the Reply. Clear PING_SENT and set
2800 * PING_FAILED to trigger a retry.
2802 if (pbuf->pb_nnis < pbuf->pb_info.pi_nnis) {
2803 if (the_lnet.ln_push_target_nnis < pbuf->pb_info.pi_nnis)
2804 the_lnet.ln_push_target_nnis = pbuf->pb_info.pi_nnis;
2805 lp->lp_state |= LNET_PEER_PING_FAILED;
2806 lp->lp_ping_error = 0;
2807 CDEBUG(D_NET, "Truncated Reply from %s (%d nids)\n",
2808 libcfs_nidstr(&lp->lp_primary_nid),
2809 pbuf->pb_info.pi_nnis);
2814 * Check the sequence numbers in the reply. These are only
2815 * available if the reply came from a Multi-Rail peer.
2817 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL &&
2818 pbuf->pb_info.pi_nnis > 1 &&
2819 lnet_nid_to_nid4(&lp->lp_primary_nid) ==
2820 pbuf->pb_info.pi_ni[1].ns_nid) {
2821 if (LNET_PING_BUFFER_SEQNO(pbuf) < lp->lp_peer_seqno)
2822 CDEBUG(D_NET, "peer %s: seq# got %u have %u. peer rebooted?\n",
2823 libcfs_nidstr(&lp->lp_primary_nid),
2824 LNET_PING_BUFFER_SEQNO(pbuf),
2827 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2830 /* We're happy with the state of the data in the buffer. */
2831 CDEBUG(D_NET, "peer %s data present %u. state = 0x%x\n",
2832 libcfs_nidstr(&lp->lp_primary_nid), lp->lp_peer_seqno,
2834 if (lp->lp_state & LNET_PEER_DATA_PRESENT)
2835 lnet_ping_buffer_decref(lp->lp_data);
2837 lp->lp_state |= LNET_PEER_DATA_PRESENT;
2838 lnet_ping_buffer_addref(pbuf);
2841 lp->lp_state &= ~LNET_PEER_PING_SENT;
2842 spin_unlock(&lp->lp_lock);
2844 lnet_net_lock(LNET_LOCK_EX);
2846 * If this peer is a gateway, call the routing callback to
2847 * handle the ping reply
2849 if (lp->lp_rtr_refcount > 0)
2850 lnet_router_discovery_ping_reply(lp);
2851 lnet_net_unlock(LNET_LOCK_EX);
2855 * Send event handling. Only matters for error cases, where we clean
2856 * up state on the peer and peer_ni that would otherwise be updated in
2857 * the REPLY event handler for a successful Ping, and the ACK event
2858 * handler for a successful Push.
2861 lnet_discovery_event_send(struct lnet_peer *lp, struct lnet_event *ev)
2868 spin_lock(&lp->lp_lock);
2869 if (ev->msg_type == LNET_MSG_GET) {
2870 lp->lp_state &= ~LNET_PEER_PING_SENT;
2871 lp->lp_state |= LNET_PEER_PING_FAILED;
2872 lp->lp_ping_error = ev->status;
2873 } else { /* ev->msg_type == LNET_MSG_PUT */
2874 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2875 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2876 lp->lp_push_error = ev->status;
2878 spin_unlock(&lp->lp_lock);
2879 rc = LNET_REDISCOVER_PEER;
2881 CDEBUG(D_NET, "%s Send to %s: %d\n",
2882 (ev->msg_type == LNET_MSG_GET ? "Ping" : "Push"),
2883 libcfs_nidstr(&ev->target.nid), rc);
2888 * Unlink event handling. This event is only seen if a call to
2889 * LNetMDUnlink() caused the event to be unlinked. If this call was
2890 * made after the event was set up in LNetGet() or LNetPut() then we
2891 * assume the Ping or Push timed out.
2894 lnet_discovery_event_unlink(struct lnet_peer *lp, struct lnet_event *ev)
2896 spin_lock(&lp->lp_lock);
2897 /* We've passed through LNetGet() */
2898 if (lp->lp_state & LNET_PEER_PING_SENT) {
2899 lp->lp_state &= ~LNET_PEER_PING_SENT;
2900 lp->lp_state |= LNET_PEER_PING_FAILED;
2901 lp->lp_ping_error = -ETIMEDOUT;
2902 CDEBUG(D_NET, "Ping Unlink for message to peer %s\n",
2903 libcfs_nidstr(&lp->lp_primary_nid));
2905 /* We've passed through LNetPut() */
2906 if (lp->lp_state & LNET_PEER_PUSH_SENT) {
2907 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2908 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2909 lp->lp_push_error = -ETIMEDOUT;
2910 CDEBUG(D_NET, "Push Unlink for message to peer %s\n",
2911 libcfs_nidstr(&lp->lp_primary_nid));
2913 spin_unlock(&lp->lp_lock);
2917 * Event handler for the discovery EQ.
2919 * Called with lnet_res_lock(cpt) held. The cpt is the
2920 * lnet_cpt_of_cookie() of the md handle cookie.
2922 static void lnet_discovery_event_handler(struct lnet_event *event)
2924 struct lnet_peer *lp = event->md_user_ptr;
2925 struct lnet_ping_buffer *pbuf;
2928 /* discovery needs to take another look */
2929 rc = LNET_REDISCOVER_PEER;
2931 CDEBUG(D_NET, "Received event: %d\n", event->type);
2933 switch (event->type) {
2934 case LNET_EVENT_ACK:
2935 lnet_discovery_event_ack(lp, event);
2937 case LNET_EVENT_REPLY:
2938 lnet_discovery_event_reply(lp, event);
2940 case LNET_EVENT_SEND:
2941 /* Only send failure triggers a retry. */
2942 rc = lnet_discovery_event_send(lp, event);
2944 case LNET_EVENT_UNLINK:
2945 /* LNetMDUnlink() was called */
2946 lnet_discovery_event_unlink(lp, event);
2949 /* Invalid events. */
2952 lnet_net_lock(LNET_LOCK_EX);
2953 if (event->unlinked) {
2954 pbuf = LNET_PING_INFO_TO_BUFFER(event->md_start);
2955 lnet_ping_buffer_decref(pbuf);
2956 lnet_peer_decref_locked(lp);
2959 /* put peer back at end of request queue, if discovery not already
2961 if (rc == LNET_REDISCOVER_PEER && !lnet_peer_is_uptodate(lp) &&
2962 lnet_peer_queue_for_discovery(lp)) {
2963 list_move_tail(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2964 wake_up(&the_lnet.ln_dc_waitq);
2966 lnet_net_unlock(LNET_LOCK_EX);
2970 * Build a peer from incoming data.
2972 * The NIDs in the incoming data are supposed to be structured as follows:
2975 * - other NIDs in same net
2976 * - NIDs in second net
2977 * - NIDs in third net
2979 * This due to the way the list of NIDs in the data is created.
2981 * Note that this function will mark the peer uptodate unless an
2982 * ENOMEM is encontered. All other errors are due to a conflict
2983 * between the DLC configuration and what discovery sees. We treat DLC
2984 * as binding, and therefore set the NIDS_UPTODATE flag to prevent the
2985 * peer from becoming stuck in discovery.
2987 static int lnet_peer_merge_data(struct lnet_peer *lp,
2988 struct lnet_ping_buffer *pbuf)
2990 struct lnet_peer_net *lpn;
2991 struct lnet_peer_ni *lpni;
2992 lnet_nid_t *curnis = NULL;
2993 struct lnet_ni_status *addnis = NULL;
2994 lnet_nid_t *delnis = NULL;
3004 flags = LNET_PEER_DISCOVERED;
3005 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)
3006 flags |= LNET_PEER_MULTI_RAIL;
3009 * Cache the routing feature for the peer; whether it is enabled
3010 * for disabled as reported by the remote peer.
3012 spin_lock(&lp->lp_lock);
3013 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_RTE_DISABLED))
3014 lp->lp_state |= LNET_PEER_ROUTER_ENABLED;
3016 lp->lp_state &= ~LNET_PEER_ROUTER_ENABLED;
3017 spin_unlock(&lp->lp_lock);
3019 nnis = max_t(int, lp->lp_nnis, pbuf->pb_info.pi_nnis);
3020 CFS_ALLOC_PTR_ARRAY(curnis, nnis);
3021 CFS_ALLOC_PTR_ARRAY(addnis, nnis);
3022 CFS_ALLOC_PTR_ARRAY(delnis, nnis);
3023 if (!curnis || !addnis || !delnis) {
3031 /* Construct the list of NIDs present in peer. */
3033 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
3034 curnis[ncurnis++] = lnet_nid_to_nid4(&lpni->lpni_nid);
3037 * Check for NIDs in pbuf not present in curnis[].
3038 * The loop starts at 1 to skip the loopback NID.
3040 for (i = 1; i < pbuf->pb_info.pi_nnis; i++) {
3041 for (j = 0; j < ncurnis; j++)
3042 if (pbuf->pb_info.pi_ni[i].ns_nid == curnis[j])
3045 addnis[naddnis++] = pbuf->pb_info.pi_ni[i];
3048 * Check for NIDs in curnis[] not present in pbuf.
3049 * The nested loop starts at 1 to skip the loopback NID.
3051 * But never add the loopback NID to delnis[]: if it is
3052 * present in curnis[] then this peer is for this node.
3054 for (i = 0; i < ncurnis; i++) {
3055 if (curnis[i] == LNET_NID_LO_0)
3057 for (j = 1; j < pbuf->pb_info.pi_nnis; j++) {
3058 if (curnis[i] == pbuf->pb_info.pi_ni[j].ns_nid) {
3060 * update the information we cache for the
3061 * peer with the latest information we
3064 lpni = lnet_find_peer_ni_locked(curnis[i]);
3066 lpni->lpni_ns_status = pbuf->pb_info.pi_ni[j].ns_status;
3067 lnet_peer_ni_decref_locked(lpni);
3072 if (j == pbuf->pb_info.pi_nnis)
3073 delnis[ndelnis++] = curnis[i];
3077 * If we get here and the discovery is disabled then we don't want
3078 * to add or delete any NIs. We just updated the ones we have some
3079 * information on, and call it a day
3082 if (lnet_is_discovery_disabled(lp))
3085 for (i = 0; i < naddnis; i++) {
3086 rc = lnet_peer_add_nid(lp, addnis[i].ns_nid, flags);
3088 CERROR("Error adding NID %s to peer %s: %d\n",
3089 libcfs_nid2str(addnis[i].ns_nid),
3090 libcfs_nidstr(&lp->lp_primary_nid), rc);
3094 lpni = lnet_find_peer_ni_locked(addnis[i].ns_nid);
3096 lpni->lpni_ns_status = addnis[i].ns_status;
3097 lnet_peer_ni_decref_locked(lpni);
3101 for (i = 0; i < ndelnis; i++) {
3103 * for routers it's okay to delete the primary_nid because
3104 * the upper layers don't really rely on it. So if we're
3105 * being told that the router changed its primary_nid
3106 * then it's okay to delete it.
3108 if (lp->lp_rtr_refcount > 0)
3109 flags |= LNET_PEER_RTR_NI_FORCE_DEL;
3110 rc = lnet_peer_del_nid(lp, delnis[i], flags);
3112 CERROR("Error deleting NID %s from peer %s: %d\n",
3113 libcfs_nid2str(delnis[i]),
3114 libcfs_nidstr(&lp->lp_primary_nid), rc);
3120 /* The peer net for the primary NID should be the first entry in the
3121 * peer's lp_peer_nets list, and the peer NI for the primary NID should
3122 * be the first entry in its peer net's lpn_peer_nis list.
3124 lpni = lnet_find_peer_ni_locked(pbuf->pb_info.pi_ni[1].ns_nid);
3126 CERROR("Internal error: Failed to lookup peer NI for primary NID: %s\n",
3127 libcfs_nid2str(pbuf->pb_info.pi_ni[1].ns_nid));
3131 lnet_peer_ni_decref_locked(lpni);
3133 lpn = lpni->lpni_peer_net;
3134 if (lpn->lpn_peer_nets.prev != &lp->lp_peer_nets)
3135 list_move(&lpn->lpn_peer_nets, &lp->lp_peer_nets);
3137 if (lpni->lpni_peer_nis.prev != &lpni->lpni_peer_net->lpn_peer_nis)
3138 list_move(&lpni->lpni_peer_nis,
3139 &lpni->lpni_peer_net->lpn_peer_nis);
3142 * Errors other than -ENOMEM are due to peers having been
3143 * configured with DLC. Ignore these because DLC overrides
3148 CFS_FREE_PTR_ARRAY(curnis, nnis);
3149 CFS_FREE_PTR_ARRAY(addnis, nnis);
3150 CFS_FREE_PTR_ARRAY(delnis, nnis);
3151 lnet_ping_buffer_decref(pbuf);
3152 CDEBUG(D_NET, "peer %s (%p): %d\n",
3153 libcfs_nidstr(&lp->lp_primary_nid), lp, rc);
3156 spin_lock(&lp->lp_lock);
3157 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
3158 lp->lp_state |= LNET_PEER_FORCE_PING;
3159 spin_unlock(&lp->lp_lock);
3165 * The data in pbuf says lp is its primary peer, but the data was
3166 * received by a different peer. Try to update lp with the data.
3169 lnet_peer_set_primary_data(struct lnet_peer *lp, struct lnet_ping_buffer *pbuf)
3171 struct lnet_handle_md mdh;
3173 /* Queue lp for discovery, and force it on the request queue. */
3174 lnet_net_lock(LNET_LOCK_EX);
3175 if (lnet_peer_queue_for_discovery(lp))
3176 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_request);
3177 lnet_net_unlock(LNET_LOCK_EX);
3179 LNetInvalidateMDHandle(&mdh);
3182 * Decide whether we can move the peer to the DATA_PRESENT state.
3184 * We replace stale data for a multi-rail peer, repair PING_FAILED
3185 * status, and preempt FORCE_PING.
3187 * If after that we have DATA_PRESENT, we merge it into this peer.
3189 spin_lock(&lp->lp_lock);
3190 if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
3191 if (lp->lp_peer_seqno < LNET_PING_BUFFER_SEQNO(pbuf)) {
3192 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
3193 } else if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
3194 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
3195 lnet_ping_buffer_decref(pbuf);
3200 if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
3201 lnet_ping_buffer_decref(lp->lp_data);
3203 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
3205 if (lp->lp_state & LNET_PEER_PING_FAILED) {
3206 mdh = lp->lp_ping_mdh;
3207 LNetInvalidateMDHandle(&lp->lp_ping_mdh);
3208 lp->lp_state &= ~LNET_PEER_PING_FAILED;
3209 lp->lp_ping_error = 0;
3211 if (lp->lp_state & LNET_PEER_FORCE_PING)
3212 lp->lp_state &= ~LNET_PEER_FORCE_PING;
3213 lp->lp_state |= LNET_PEER_NIDS_UPTODATE;
3214 spin_unlock(&lp->lp_lock);
3216 if (!LNetMDHandleIsInvalid(mdh))
3220 return lnet_peer_merge_data(lp, pbuf);
3222 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3226 static bool lnet_is_nid_in_ping_info(lnet_nid_t nid, struct lnet_ping_info *pinfo)
3230 for (i = 0; i < pinfo->pi_nnis; i++) {
3231 if (pinfo->pi_ni[i].ns_nid == nid)
3238 /* Delete a peer that has been marked for deletion. NB: when this peer was added
3239 * to the discovery queue a reference was taken that will prevent the peer from
3240 * actually being freed by this function. After this function exits the
3241 * discovery thread should call lnet_peer_discovery_complete() which will
3242 * drop that reference as well as wake any waiters that may also be holding a
3245 static int lnet_peer_deletion(struct lnet_peer *lp)
3246 __must_hold(&lp->lp_lock)
3248 struct list_head rlist;
3249 struct lnet_route *route, *tmp;
3250 int sensitivity = lp->lp_health_sensitivity;
3253 INIT_LIST_HEAD(&rlist);
3255 lp->lp_state &= ~(LNET_PEER_DISCOVERING | LNET_PEER_FORCE_PING |
3256 LNET_PEER_FORCE_PUSH);
3257 CDEBUG(D_NET, "peer %s(%p) state %#x\n",
3258 libcfs_nidstr(&lp->lp_primary_nid), lp, lp->lp_state);
3260 /* no-op if lnet_peer_del() has already been called on this peer */
3261 if (lp->lp_state & LNET_PEER_MARK_DELETED)
3264 if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING)
3267 spin_unlock(&lp->lp_lock);
3269 mutex_lock(&the_lnet.ln_api_mutex);
3271 lnet_net_lock(LNET_LOCK_EX);
3272 /* remove the peer from the discovery work
3273 * queue if it's on there in preparation
3276 if (!list_empty(&lp->lp_dc_list))
3277 list_del_init(&lp->lp_dc_list);
3278 list_for_each_entry_safe(route, tmp,
3281 lnet_move_route(route, NULL, &rlist);
3282 lnet_net_unlock(LNET_LOCK_EX);
3284 /* lnet_peer_del() deletes all the peer NIs owned by this peer */
3285 rc = lnet_peer_del(lp);
3287 CNETERR("Internal error: Unable to delete peer %s rc %d\n",
3288 libcfs_nidstr(&lp->lp_primary_nid), rc);
3290 list_for_each_entry_safe(route, tmp,
3292 /* re-add these routes */
3293 lnet_add_route(route->lr_net,
3298 LIBCFS_FREE(route, sizeof(*route));
3301 mutex_unlock(&the_lnet.ln_api_mutex);
3303 spin_lock(&lp->lp_lock);
3309 * Update a peer using the data received.
3311 static int lnet_peer_data_present(struct lnet_peer *lp)
3312 __must_hold(&lp->lp_lock)
3314 struct lnet_ping_buffer *pbuf;
3315 struct lnet_peer_ni *lpni;
3316 lnet_nid_t nid = LNET_NID_ANY;
3322 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
3323 lp->lp_state |= LNET_PEER_NIDS_UPTODATE;
3324 spin_unlock(&lp->lp_lock);
3327 * Modifications of peer structures are done while holding the
3328 * ln_api_mutex. A global lock is required because we may be
3329 * modifying multiple peer structures, and a mutex greatly
3330 * simplifies memory management.
3332 * The actual changes to the data structures must also protect
3333 * against concurrent lookups, for which the lnet_net_lock in
3334 * LNET_LOCK_EX mode is used.
3336 mutex_lock(&the_lnet.ln_api_mutex);
3337 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3343 * If this peer is not on the peer list then it is being torn
3344 * down, and our reference count may be all that is keeping it
3345 * alive. Don't do any work on it.
3347 if (list_empty(&lp->lp_peer_list))
3350 flags = LNET_PEER_DISCOVERED;
3351 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)
3352 flags |= LNET_PEER_MULTI_RAIL;
3355 * Check whether the primary NID in the message matches the
3356 * primary NID of the peer. If it does, update the peer, if
3357 * it it does not, check whether there is already a peer with
3358 * that primary NID. If no such peer exists, try to update
3359 * the primary NID of the current peer (allowed if it was
3360 * created due to message traffic) and complete the update.
3361 * If the peer did exist, hand off the data to it.
3363 * The peer for the loopback interface is a special case: this
3364 * is the peer for the local node, and we want to set its
3365 * primary NID to the correct value here. Moreover, this peer
3366 * can show up with only the loopback NID in the ping buffer.
3368 if (pbuf->pb_info.pi_nnis <= 1)
3370 nid = pbuf->pb_info.pi_ni[1].ns_nid;
3371 if (nid_is_lo0(&lp->lp_primary_nid)) {
3372 rc = lnet_peer_set_primary_nid(lp, nid, flags);
3374 rc = lnet_peer_merge_data(lp, pbuf);
3376 * if the primary nid of the peer is present in the ping info returned
3377 * from the peer, but it's not the local primary peer we have
3378 * cached and discovery is disabled, then we don't want to update
3379 * our local peer info, by adding or removing NIDs, we just want
3380 * to update the status of the nids that we currently have
3381 * recorded in that peer.
3383 } else if (lnet_nid_to_nid4(&lp->lp_primary_nid) == nid ||
3384 (lnet_is_nid_in_ping_info(lnet_nid_to_nid4(&lp->lp_primary_nid),
3386 lnet_is_discovery_disabled(lp))) {
3387 rc = lnet_peer_merge_data(lp, pbuf);
3389 lpni = lnet_find_peer_ni_locked(nid);
3390 if (!lpni || lp == lpni->lpni_peer_net->lpn_peer) {
3391 rc = lnet_peer_set_primary_nid(lp, nid, flags);
3393 CERROR("Primary NID error %s versus %s: %d\n",
3394 libcfs_nidstr(&lp->lp_primary_nid),
3395 libcfs_nid2str(nid), rc);
3397 rc = lnet_peer_merge_data(lp, pbuf);
3400 lnet_peer_ni_decref_locked(lpni);
3402 struct lnet_peer *new_lp;
3403 new_lp = lpni->lpni_peer_net->lpn_peer;
3405 * if lp has discovery/MR enabled that means new_lp
3406 * should have discovery/MR enabled as well, since
3407 * it's the same peer, which we're about to merge
3409 spin_lock(&lp->lp_lock);
3410 spin_lock(&new_lp->lp_lock);
3411 if (!(lp->lp_state & LNET_PEER_NO_DISCOVERY))
3412 new_lp->lp_state &= ~LNET_PEER_NO_DISCOVERY;
3413 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
3414 new_lp->lp_state |= LNET_PEER_MULTI_RAIL;
3415 /* If we're processing a ping reply then we may be
3416 * about to send a push to the peer that we ping'd.
3417 * Since the ping reply that we're processing was
3418 * received by lp, we need to set the discovery source
3419 * NID for new_lp to the NID stored in lp.
3421 if (!LNET_NID_IS_ANY(&lp->lp_disc_src_nid)) {
3422 new_lp->lp_disc_src_nid = lp->lp_disc_src_nid;
3423 new_lp->lp_disc_dst_nid = lp->lp_disc_dst_nid;
3425 spin_unlock(&new_lp->lp_lock);
3426 spin_unlock(&lp->lp_lock);
3428 rc = lnet_peer_set_primary_data(new_lp, pbuf);
3429 lnet_consolidate_routes_locked(lp, new_lp);
3430 lnet_peer_ni_decref_locked(lpni);
3434 CDEBUG(D_NET, "peer %s(%p): %d. state = 0x%x\n",
3435 libcfs_nidstr(&lp->lp_primary_nid), lp, rc,
3437 mutex_unlock(&the_lnet.ln_api_mutex);
3439 spin_lock(&lp->lp_lock);
3440 /* Tell discovery to re-check the peer immediately. */
3442 rc = LNET_REDISCOVER_PEER;
3447 * A ping failed. Clear the PING_FAILED state and set the
3448 * FORCE_PING state, to ensure a retry even if discovery is
3449 * disabled. This avoids being left with incorrect state.
3451 static int lnet_peer_ping_failed(struct lnet_peer *lp)
3452 __must_hold(&lp->lp_lock)
3454 struct lnet_handle_md mdh;
3457 mdh = lp->lp_ping_mdh;
3458 LNetInvalidateMDHandle(&lp->lp_ping_mdh);
3459 lp->lp_state &= ~LNET_PEER_PING_FAILED;
3460 lp->lp_state |= LNET_PEER_FORCE_PING;
3461 rc = lp->lp_ping_error;
3462 lp->lp_ping_error = 0;
3463 spin_unlock(&lp->lp_lock);
3465 if (!LNetMDHandleIsInvalid(mdh))
3468 CDEBUG(D_NET, "peer %s:%d\n",
3469 libcfs_nidstr(&lp->lp_primary_nid), rc);
3471 spin_lock(&lp->lp_lock);
3472 return rc ? rc : LNET_REDISCOVER_PEER;
3475 /* Active side of ping. */
3476 static int lnet_peer_send_ping(struct lnet_peer *lp)
3477 __must_hold(&lp->lp_lock)
3483 lp->lp_state |= LNET_PEER_PING_SENT;
3484 lp->lp_state &= ~LNET_PEER_FORCE_PING;
3485 spin_unlock(&lp->lp_lock);
3487 cpt = lnet_net_lock_current();
3488 /* Refcount for MD. */
3489 lnet_peer_addref_locked(lp);
3490 lnet_net_unlock(cpt);
3492 nnis = max(lp->lp_data_nnis, LNET_INTERFACES_MIN);
3494 rc = lnet_send_ping(lnet_nid_to_nid4(&lp->lp_primary_nid),
3495 &lp->lp_ping_mdh, nnis, lp,
3496 the_lnet.ln_dc_handler, false);
3499 * if LNetMDBind in lnet_send_ping fails we need to decrement the
3500 * refcount on the peer, otherwise LNetMDUnlink will be called
3501 * which will eventually do that.
3505 lnet_peer_decref_locked(lp);
3506 lnet_net_unlock(cpt);
3507 rc = -rc; /* change the rc to negative value */
3509 } else if (rc < 0) {
3513 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3515 spin_lock(&lp->lp_lock);
3519 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nidstr(&lp->lp_primary_nid), rc);
3521 * The errors that get us here are considered hard errors and
3522 * cause Discovery to terminate. So we clear PING_SENT, but do
3523 * not set either PING_FAILED or FORCE_PING. In fact we need
3524 * to clear PING_FAILED, because the unlink event handler will
3525 * have set it if we called LNetMDUnlink() above.
3527 spin_lock(&lp->lp_lock);
3528 lp->lp_state &= ~(LNET_PEER_PING_SENT | LNET_PEER_PING_FAILED);
3533 * This function exists because you cannot call LNetMDUnlink() from an
3536 static int lnet_peer_push_failed(struct lnet_peer *lp)
3537 __must_hold(&lp->lp_lock)
3539 struct lnet_handle_md mdh;
3542 mdh = lp->lp_push_mdh;
3543 LNetInvalidateMDHandle(&lp->lp_push_mdh);
3544 lp->lp_state &= ~LNET_PEER_PUSH_FAILED;
3545 rc = lp->lp_push_error;
3546 lp->lp_push_error = 0;
3547 spin_unlock(&lp->lp_lock);
3549 if (!LNetMDHandleIsInvalid(mdh))
3552 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3553 spin_lock(&lp->lp_lock);
3554 return rc ? rc : LNET_REDISCOVER_PEER;
3558 * Mark the peer as discovered.
3560 static int lnet_peer_discovered(struct lnet_peer *lp)
3561 __must_hold(&lp->lp_lock)
3563 lp->lp_state |= LNET_PEER_DISCOVERED;
3564 lp->lp_state &= ~(LNET_PEER_DISCOVERING |
3565 LNET_PEER_REDISCOVER);
3567 lp->lp_dc_error = 0;
3569 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3574 /* Active side of push. */
3575 static int lnet_peer_send_push(struct lnet_peer *lp)
3576 __must_hold(&lp->lp_lock)
3578 struct lnet_ping_buffer *pbuf;
3579 struct lnet_process_id id;
3584 /* Don't push to a non-multi-rail peer. */
3585 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
3586 lp->lp_state &= ~LNET_PEER_FORCE_PUSH;
3587 /* if peer's NIDs are uptodate then peer is discovered */
3588 if (lp->lp_state & LNET_PEER_NIDS_UPTODATE) {
3589 rc = lnet_peer_discovered(lp);
3596 lp->lp_state |= LNET_PEER_PUSH_SENT;
3597 lp->lp_state &= ~LNET_PEER_FORCE_PUSH;
3598 spin_unlock(&lp->lp_lock);
3600 cpt = lnet_net_lock_current();
3601 pbuf = the_lnet.ln_ping_target;
3602 lnet_ping_buffer_addref(pbuf);
3603 lnet_net_unlock(cpt);
3605 /* Push source MD */
3606 md.start = &pbuf->pb_info;
3607 md.length = LNET_PING_INFO_SIZE(pbuf->pb_nnis);
3608 md.threshold = 2; /* Put/Ack */
3610 md.options = LNET_MD_TRACK_RESPONSE;
3611 md.handler = the_lnet.ln_dc_handler;
3614 rc = LNetMDBind(&md, LNET_UNLINK, &lp->lp_push_mdh);
3616 lnet_ping_buffer_decref(pbuf);
3617 CERROR("Can't bind push source MD: %d\n", rc);
3621 cpt = lnet_net_lock_current();
3622 /* Refcount for MD. */
3623 lnet_peer_addref_locked(lp);
3624 id.pid = LNET_PID_LUSTRE;
3625 if (!LNET_NID_IS_ANY(&lp->lp_disc_dst_nid))
3626 id.nid = lnet_nid_to_nid4(&lp->lp_disc_dst_nid);
3628 id.nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
3629 lnet_net_unlock(cpt);
3631 rc = LNetPut(lnet_nid_to_nid4(&lp->lp_disc_src_nid), lp->lp_push_mdh,
3632 LNET_ACK_REQ, id, LNET_RESERVED_PORTAL,
3633 LNET_PROTO_PING_MATCHBITS, 0, 0);
3636 * reset the discovery nid. There is no need to restrict sending
3637 * from that source, if we call lnet_push_update_to_peers(). It'll
3638 * get set to a specific NID, if we initiate discovery from the
3641 lp->lp_disc_src_nid = LNET_ANY_NID;
3642 lp->lp_disc_dst_nid = LNET_ANY_NID;
3647 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3649 spin_lock(&lp->lp_lock);
3653 LNetMDUnlink(lp->lp_push_mdh);
3654 LNetInvalidateMDHandle(&lp->lp_push_mdh);
3656 CDEBUG(D_NET, "peer %s(%p): %d\n", libcfs_nidstr(&lp->lp_primary_nid),
3659 * The errors that get us here are considered hard errors and
3660 * cause Discovery to terminate. So we clear PUSH_SENT, but do
3661 * not set PUSH_FAILED. In fact we need to clear PUSH_FAILED,
3662 * because the unlink event handler will have set it if we
3663 * called LNetMDUnlink() above.
3665 spin_lock(&lp->lp_lock);
3666 lp->lp_state &= ~(LNET_PEER_PUSH_SENT | LNET_PEER_PUSH_FAILED);
3671 * Wait for work to be queued or some other change that must be
3672 * attended to. Returns non-zero if the discovery thread should shut
3675 static int lnet_peer_discovery_wait_for_work(void)
3682 cpt = lnet_net_lock_current();
3684 prepare_to_wait(&the_lnet.ln_dc_waitq, &wait,
3685 TASK_INTERRUPTIBLE);
3686 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3688 if (lnet_push_target_resize_needed() ||
3689 the_lnet.ln_push_target->pb_needs_post)
3691 if (!list_empty(&the_lnet.ln_dc_request))
3693 if (!list_empty(&the_lnet.ln_msg_resend))
3695 lnet_net_unlock(cpt);
3698 * wakeup max every second to check if there are peers that
3699 * have been stuck on the working queue for greater than
3702 schedule_timeout(cfs_time_seconds(1));
3703 finish_wait(&the_lnet.ln_dc_waitq, &wait);
3704 cpt = lnet_net_lock_current();
3706 finish_wait(&the_lnet.ln_dc_waitq, &wait);
3708 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3711 lnet_net_unlock(cpt);
3713 CDEBUG(D_NET, "woken: %d\n", rc);
3719 * Messages that were pending on a destroyed peer will be put on a global
3720 * resend list. The message resend list will be checked by
3721 * the discovery thread when it wakes up, and will resend messages. These
3722 * messages can still be sendable in the case the lpni which was the initial
3723 * cause of the message re-queue was transfered to another peer.
3725 * It is possible that LNet could be shutdown while we're iterating
3726 * through the list. lnet_shudown_lndnets() will attempt to access the
3727 * resend list, but will have to wait until the spinlock is released, by
3728 * which time there shouldn't be any more messages on the resend list.
3729 * During shutdown lnet_send() will fail and lnet_finalize() will be called
3730 * for the messages so they can be released. The other case is that
3731 * lnet_shudown_lndnets() can finalize all the messages before this
3732 * function can visit the resend list, in which case this function will be
3735 static void lnet_resend_msgs(void)
3737 struct lnet_msg *msg, *tmp;
3741 spin_lock(&the_lnet.ln_msg_resend_lock);
3742 list_splice(&the_lnet.ln_msg_resend, &resend);
3743 spin_unlock(&the_lnet.ln_msg_resend_lock);
3745 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
3746 list_del_init(&msg->msg_list);
3747 rc = lnet_send(&msg->msg_src_nid_param, msg,
3748 &msg->msg_rtr_nid_param);
3750 CNETERR("Error sending %s to %s: %d\n",
3751 lnet_msgtyp2str(msg->msg_type),
3752 libcfs_idstr(&msg->msg_target), rc);
3753 lnet_finalize(msg, rc);
3758 /* The discovery thread. */
3759 static int lnet_peer_discovery(void *arg)
3761 struct lnet_peer *lp;
3764 wait_for_completion(&the_lnet.ln_started);
3766 CDEBUG(D_NET, "started\n");
3769 if (lnet_peer_discovery_wait_for_work())
3772 if (lnet_push_target_resize_needed())
3773 lnet_push_target_resize();
3774 else if (the_lnet.ln_push_target->pb_needs_post)
3775 lnet_push_target_post(the_lnet.ln_push_target,
3776 &the_lnet.ln_push_target_md);
3780 lnet_net_lock(LNET_LOCK_EX);
3781 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING) {
3782 lnet_net_unlock(LNET_LOCK_EX);
3787 * Process all incoming discovery work requests. When
3788 * discovery must wait on a peer to change state, it
3789 * is added to the tail of the ln_dc_working queue. A
3790 * timestamp keeps track of when the peer was added,
3791 * so we can time out discovery requests that take too
3794 while (!list_empty(&the_lnet.ln_dc_request)) {
3795 lp = list_first_entry(&the_lnet.ln_dc_request,
3796 struct lnet_peer, lp_dc_list);
3797 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_working);
3799 * set the time the peer was put on the dc_working
3800 * queue. It shouldn't remain on the queue
3801 * forever, in case the GET message (for ping)
3802 * doesn't get a REPLY or the PUT message (for
3803 * push) doesn't get an ACK.
3805 lp->lp_last_queued = ktime_get_real_seconds();
3806 lnet_net_unlock(LNET_LOCK_EX);
3808 if (lnet_push_target_resize_needed())
3809 lnet_push_target_resize();
3810 else if (the_lnet.ln_push_target->pb_needs_post)
3811 lnet_push_target_post(the_lnet.ln_push_target,
3812 &the_lnet.ln_push_target_md);
3815 * Select an action depending on the state of
3816 * the peer and whether discovery is disabled.
3817 * The check whether discovery is disabled is
3818 * done after the code that handles processing
3819 * for arrived data, cleanup for failures, and
3820 * forcing a Ping or Push.
3822 spin_lock(&lp->lp_lock);
3823 CDEBUG(D_NET, "peer %s(%p) state %#x\n",
3824 libcfs_nidstr(&lp->lp_primary_nid), lp,
3826 if (lp->lp_state & (LNET_PEER_MARK_DELETION |
3827 LNET_PEER_MARK_DELETED))
3828 rc = lnet_peer_deletion(lp);
3829 else if (lp->lp_state & LNET_PEER_DATA_PRESENT)
3830 rc = lnet_peer_data_present(lp);
3831 else if (lp->lp_state & LNET_PEER_PING_FAILED)
3832 rc = lnet_peer_ping_failed(lp);
3833 else if (lp->lp_state & LNET_PEER_PUSH_FAILED)
3834 rc = lnet_peer_push_failed(lp);
3835 else if (lp->lp_state & LNET_PEER_FORCE_PING)
3836 rc = lnet_peer_send_ping(lp);
3837 else if (lp->lp_state & LNET_PEER_FORCE_PUSH)
3838 rc = lnet_peer_send_push(lp);
3839 else if (!(lp->lp_state & LNET_PEER_NIDS_UPTODATE))
3840 rc = lnet_peer_send_ping(lp);
3841 else if (lnet_peer_needs_push(lp))
3842 rc = lnet_peer_send_push(lp);
3844 rc = lnet_peer_discovered(lp);
3845 CDEBUG(D_NET, "peer %s(%p) state %#x rc %d\n",
3846 libcfs_nidstr(&lp->lp_primary_nid), lp,
3849 if (rc == LNET_REDISCOVER_PEER) {
3850 spin_unlock(&lp->lp_lock);
3851 lnet_net_lock(LNET_LOCK_EX);
3852 list_move(&lp->lp_dc_list,
3853 &the_lnet.ln_dc_request);
3855 !(lp->lp_state & LNET_PEER_DISCOVERING)) {
3856 spin_unlock(&lp->lp_lock);
3857 lnet_net_lock(LNET_LOCK_EX);
3858 lnet_peer_discovery_complete(lp, rc);
3860 spin_unlock(&lp->lp_lock);
3861 lnet_net_lock(LNET_LOCK_EX);
3864 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3869 lnet_net_unlock(LNET_LOCK_EX);
3872 CDEBUG(D_NET, "stopping\n");
3874 * Clean up before telling lnet_peer_discovery_stop() that
3875 * we're done. Use wake_up() below to somewhat reduce the
3876 * size of the thundering herd if there are multiple threads
3877 * waiting on discovery of a single peer.
3880 /* Queue cleanup 1: stop all pending pings and pushes. */
3881 lnet_net_lock(LNET_LOCK_EX);
3882 while (!list_empty(&the_lnet.ln_dc_working)) {
3883 lp = list_first_entry(&the_lnet.ln_dc_working,
3884 struct lnet_peer, lp_dc_list);
3885 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_expired);
3886 lnet_net_unlock(LNET_LOCK_EX);
3887 lnet_peer_cancel_discovery(lp);
3888 lnet_net_lock(LNET_LOCK_EX);
3890 lnet_net_unlock(LNET_LOCK_EX);
3892 /* Queue cleanup 2: wait for the expired queue to clear. */
3893 while (!list_empty(&the_lnet.ln_dc_expired))
3894 schedule_timeout_uninterruptible(cfs_time_seconds(1));
3896 /* Queue cleanup 3: clear the request queue. */
3897 lnet_net_lock(LNET_LOCK_EX);
3898 while (!list_empty(&the_lnet.ln_dc_request)) {
3899 lp = list_first_entry(&the_lnet.ln_dc_request,
3900 struct lnet_peer, lp_dc_list);
3901 lnet_peer_discovery_complete(lp, -ESHUTDOWN);
3903 lnet_net_unlock(LNET_LOCK_EX);
3905 lnet_assert_handler_unused(the_lnet.ln_dc_handler);
3906 the_lnet.ln_dc_handler = NULL;
3908 the_lnet.ln_dc_state = LNET_DC_STATE_SHUTDOWN;
3909 wake_up(&the_lnet.ln_dc_waitq);
3911 CDEBUG(D_NET, "stopped\n");
3916 /* ln_api_mutex is held on entry. */
3917 int lnet_peer_discovery_start(void)
3919 struct task_struct *task;
3922 if (the_lnet.ln_dc_state != LNET_DC_STATE_SHUTDOWN)
3925 the_lnet.ln_dc_handler = lnet_discovery_event_handler;
3926 the_lnet.ln_dc_state = LNET_DC_STATE_RUNNING;
3927 task = kthread_run(lnet_peer_discovery, NULL, "lnet_discovery");
3930 CERROR("Can't start peer discovery thread: %d\n", rc);
3932 the_lnet.ln_dc_handler = NULL;
3934 the_lnet.ln_dc_state = LNET_DC_STATE_SHUTDOWN;
3937 CDEBUG(D_NET, "discovery start: %d\n", rc);
3942 /* ln_api_mutex is held on entry. */
3943 void lnet_peer_discovery_stop(void)
3945 if (the_lnet.ln_dc_state == LNET_DC_STATE_SHUTDOWN)
3948 LASSERT(the_lnet.ln_dc_state == LNET_DC_STATE_RUNNING);
3949 the_lnet.ln_dc_state = LNET_DC_STATE_STOPPING;
3951 /* In the LNetNIInit() path we may be stopping discovery before it
3952 * entered its work loop
3954 if (!completion_done(&the_lnet.ln_started))
3955 complete(&the_lnet.ln_started);
3957 wake_up(&the_lnet.ln_dc_waitq);
3959 wait_event(the_lnet.ln_dc_waitq,
3960 the_lnet.ln_dc_state == LNET_DC_STATE_SHUTDOWN);
3962 LASSERT(list_empty(&the_lnet.ln_dc_request));
3963 LASSERT(list_empty(&the_lnet.ln_dc_working));
3964 LASSERT(list_empty(&the_lnet.ln_dc_expired));
3966 CDEBUG(D_NET, "discovery stopped\n");
3972 lnet_debug_peer(lnet_nid_t nid)
3974 char *aliveness = "NA";
3975 struct lnet_peer_ni *lp;
3978 cpt = lnet_cpt_of_nid(nid, NULL);
3981 lp = lnet_nid2peerni_locked(nid, LNET_NID_ANY, cpt);
3983 lnet_net_unlock(cpt);
3984 CDEBUG(D_WARNING, "No peer %s\n", libcfs_nid2str(nid));
3988 if (lnet_isrouter(lp) || lnet_peer_aliveness_enabled(lp))
3989 aliveness = (lnet_is_peer_ni_alive(lp)) ? "up" : "down";
3991 CDEBUG(D_WARNING, "%-24s %4d %5s %5d %5d %5d %5d %5d %ld\n",
3992 libcfs_nidstr(&lp->lpni_nid), kref_read(&lp->lpni_kref),
3993 aliveness, lp->lpni_net->net_tunables.lct_peer_tx_credits,
3994 lp->lpni_rtrcredits, lp->lpni_minrtrcredits,
3995 lp->lpni_txcredits, lp->lpni_mintxcredits, lp->lpni_txqnob);
3997 lnet_peer_ni_decref_locked(lp);
3999 lnet_net_unlock(cpt);
4002 /* Gathering information for userspace. */
4004 int lnet_get_peer_ni_info(__u32 peer_index, __u64 *nid,
4005 char aliveness[LNET_MAX_STR_LEN],
4006 __u32 *cpt_iter, __u32 *refcount,
4007 __u32 *ni_peer_tx_credits, __u32 *peer_tx_credits,
4008 __u32 *peer_rtr_credits, __u32 *peer_min_rtr_credits,
4009 __u32 *peer_tx_qnob)
4011 struct lnet_peer_table *peer_table;
4012 struct lnet_peer_ni *lp;
4017 /* get the number of CPTs */
4018 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
4020 /* if the cpt number to be examined is >= the number of cpts in
4021 * the system then indicate that there are no more cpts to examin
4023 if (*cpt_iter >= lncpt)
4026 /* get the current table */
4027 peer_table = the_lnet.ln_peer_tables[*cpt_iter];
4028 /* if the ptable is NULL then there are no more cpts to examine */
4029 if (peer_table == NULL)
4032 lnet_net_lock(*cpt_iter);
4034 for (j = 0; j < LNET_PEER_HASH_SIZE && !found; j++) {
4035 struct list_head *peers = &peer_table->pt_hash[j];
4037 list_for_each_entry(lp, peers, lpni_hashlist) {
4038 if (!nid_is_nid4(&lp->lpni_nid))
4040 if (peer_index-- > 0)
4043 snprintf(aliveness, LNET_MAX_STR_LEN, "NA");
4044 if (lnet_isrouter(lp) ||
4045 lnet_peer_aliveness_enabled(lp))
4046 snprintf(aliveness, LNET_MAX_STR_LEN,
4047 lnet_is_peer_ni_alive(lp) ? "up" : "down");
4049 *nid = lnet_nid_to_nid4(&lp->lpni_nid);
4050 *refcount = kref_read(&lp->lpni_kref);
4051 *ni_peer_tx_credits =
4052 lp->lpni_net->net_tunables.lct_peer_tx_credits;
4053 *peer_tx_credits = lp->lpni_txcredits;
4054 *peer_rtr_credits = lp->lpni_rtrcredits;
4055 *peer_min_rtr_credits = lp->lpni_mintxcredits;
4056 *peer_tx_qnob = lp->lpni_txqnob;
4062 lnet_net_unlock(*cpt_iter);
4066 return found ? 0 : -ENOENT;
4069 /* ln_api_mutex is held, which keeps the peer list stable */
4070 int lnet_get_peer_info(struct lnet_ioctl_peer_cfg *cfg, void __user *bulk)
4072 struct lnet_ioctl_element_stats *lpni_stats;
4073 struct lnet_ioctl_element_msg_stats *lpni_msg_stats;
4074 struct lnet_ioctl_peer_ni_hstats *lpni_hstats;
4075 struct lnet_peer_ni_credit_info *lpni_info;
4076 struct lnet_peer_ni *lpni;
4077 struct lnet_peer *lp;
4082 lp = lnet_find_peer4(cfg->prcfg_prim_nid);
4089 size = sizeof(nid) + sizeof(*lpni_info) + sizeof(*lpni_stats)
4090 + sizeof(*lpni_msg_stats) + sizeof(*lpni_hstats);
4091 size *= lp->lp_nnis;
4092 if (size > cfg->prcfg_size) {
4093 cfg->prcfg_size = size;
4098 cfg->prcfg_prim_nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
4099 cfg->prcfg_mr = lnet_peer_is_multi_rail(lp);
4100 cfg->prcfg_cfg_nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
4101 cfg->prcfg_count = lp->lp_nnis;
4102 cfg->prcfg_size = size;
4103 cfg->prcfg_state = lp->lp_state;
4105 /* Allocate helper buffers. */
4107 LIBCFS_ALLOC(lpni_info, sizeof(*lpni_info));
4110 LIBCFS_ALLOC(lpni_stats, sizeof(*lpni_stats));
4113 LIBCFS_ALLOC(lpni_msg_stats, sizeof(*lpni_msg_stats));
4114 if (!lpni_msg_stats)
4115 goto out_free_stats;
4116 LIBCFS_ALLOC(lpni_hstats, sizeof(*lpni_hstats));
4118 goto out_free_msg_stats;
4123 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL) {
4124 if (!nid_is_nid4(&lpni->lpni_nid))
4126 nid = lnet_nid_to_nid4(&lpni->lpni_nid);
4127 if (copy_to_user(bulk, &nid, sizeof(nid)))
4128 goto out_free_hstats;
4129 bulk += sizeof(nid);
4131 memset(lpni_info, 0, sizeof(*lpni_info));
4132 snprintf(lpni_info->cr_aliveness, LNET_MAX_STR_LEN, "NA");
4133 if (lnet_isrouter(lpni) ||
4134 lnet_peer_aliveness_enabled(lpni))
4135 snprintf(lpni_info->cr_aliveness, LNET_MAX_STR_LEN,
4136 lnet_is_peer_ni_alive(lpni) ? "up" : "down");
4138 lpni_info->cr_refcount = kref_read(&lpni->lpni_kref);
4139 lpni_info->cr_ni_peer_tx_credits = (lpni->lpni_net != NULL) ?
4140 lpni->lpni_net->net_tunables.lct_peer_tx_credits : 0;
4141 lpni_info->cr_peer_tx_credits = lpni->lpni_txcredits;
4142 lpni_info->cr_peer_rtr_credits = lpni->lpni_rtrcredits;
4143 lpni_info->cr_peer_min_rtr_credits = lpni->lpni_minrtrcredits;
4144 lpni_info->cr_peer_min_tx_credits = lpni->lpni_mintxcredits;
4145 lpni_info->cr_peer_tx_qnob = lpni->lpni_txqnob;
4146 if (copy_to_user(bulk, lpni_info, sizeof(*lpni_info)))
4147 goto out_free_hstats;
4148 bulk += sizeof(*lpni_info);
4150 memset(lpni_stats, 0, sizeof(*lpni_stats));
4151 lpni_stats->iel_send_count = lnet_sum_stats(&lpni->lpni_stats,
4152 LNET_STATS_TYPE_SEND);
4153 lpni_stats->iel_recv_count = lnet_sum_stats(&lpni->lpni_stats,
4154 LNET_STATS_TYPE_RECV);
4155 lpni_stats->iel_drop_count = lnet_sum_stats(&lpni->lpni_stats,
4156 LNET_STATS_TYPE_DROP);
4157 if (copy_to_user(bulk, lpni_stats, sizeof(*lpni_stats)))
4158 goto out_free_hstats;
4159 bulk += sizeof(*lpni_stats);
4160 lnet_usr_translate_stats(lpni_msg_stats, &lpni->lpni_stats);
4161 if (copy_to_user(bulk, lpni_msg_stats, sizeof(*lpni_msg_stats)))
4162 goto out_free_hstats;
4163 bulk += sizeof(*lpni_msg_stats);
4164 lpni_hstats->hlpni_network_timeout =
4165 atomic_read(&lpni->lpni_hstats.hlt_network_timeout);
4166 lpni_hstats->hlpni_remote_dropped =
4167 atomic_read(&lpni->lpni_hstats.hlt_remote_dropped);
4168 lpni_hstats->hlpni_remote_timeout =
4169 atomic_read(&lpni->lpni_hstats.hlt_remote_timeout);
4170 lpni_hstats->hlpni_remote_error =
4171 atomic_read(&lpni->lpni_hstats.hlt_remote_error);
4172 lpni_hstats->hlpni_health_value =
4173 atomic_read(&lpni->lpni_healthv);
4174 lpni_hstats->hlpni_ping_count = lpni->lpni_ping_count;
4175 lpni_hstats->hlpni_next_ping = lpni->lpni_next_ping;
4176 if (copy_to_user(bulk, lpni_hstats, sizeof(*lpni_hstats)))
4177 goto out_free_hstats;
4178 bulk += sizeof(*lpni_hstats);
4183 LIBCFS_FREE(lpni_hstats, sizeof(*lpni_hstats));
4185 LIBCFS_FREE(lpni_msg_stats, sizeof(*lpni_msg_stats));
4187 LIBCFS_FREE(lpni_stats, sizeof(*lpni_stats));
4189 LIBCFS_FREE(lpni_info, sizeof(*lpni_info));
4191 lnet_peer_decref_locked(lp);
4196 /* must hold net_lock/0 */
4198 lnet_peer_ni_add_to_recoveryq_locked(struct lnet_peer_ni *lpni,
4199 struct list_head *recovery_queue,
4202 /* the mt could've shutdown and cleaned up the queues */
4203 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING)
4206 if (!list_empty(&lpni->lpni_recovery))
4209 if (atomic_read(&lpni->lpni_healthv) == LNET_MAX_HEALTH_VALUE)
4212 if (!lpni->lpni_last_alive) {
4214 "lpni %s(%p) not eligible for recovery last alive %lld\n",
4215 libcfs_nidstr(&lpni->lpni_nid), lpni,
4216 lpni->lpni_last_alive);
4220 if (lnet_recovery_limit &&
4221 now > lpni->lpni_last_alive + lnet_recovery_limit) {
4222 CDEBUG(D_NET, "lpni %s aged out last alive %lld\n",
4223 libcfs_nidstr(&lpni->lpni_nid),
4224 lpni->lpni_last_alive);
4225 /* Reset the ping count so that if this peer NI is added back to
4226 * the recovery queue we will send the first ping right away.
4228 lpni->lpni_ping_count = 0;
4232 /* This peer NI is going on the recovery queue, so take a ref on it */
4233 lnet_peer_ni_addref_locked(lpni);
4235 lnet_peer_ni_set_next_ping(lpni, now);
4237 CDEBUG(D_NET, "%s added to recovery queue. ping count: %u next ping: %lld last alive: %lld health: %d\n",
4238 libcfs_nidstr(&lpni->lpni_nid),
4239 lpni->lpni_ping_count,
4240 lpni->lpni_next_ping,
4241 lpni->lpni_last_alive,
4242 atomic_read(&lpni->lpni_healthv));
4244 list_add_tail(&lpni->lpni_recovery, recovery_queue);
4247 /* Call with the ln_api_mutex held */
4249 lnet_peer_ni_set_healthv(lnet_nid_t nid, int value, bool all)
4251 struct lnet_peer_table *ptable;
4252 struct lnet_peer *lp;
4253 struct lnet_peer_net *lpn;
4254 struct lnet_peer_ni *lpni;
4259 if (the_lnet.ln_state != LNET_STATE_RUNNING)
4262 now = ktime_get_seconds();
4265 lnet_net_lock(LNET_LOCK_EX);
4266 lpni = lnet_find_peer_ni_locked(nid);
4268 lnet_net_unlock(LNET_LOCK_EX);
4271 lnet_set_lpni_healthv_locked(lpni, value);
4272 lnet_peer_ni_add_to_recoveryq_locked(lpni,
4273 &the_lnet.ln_mt_peerNIRecovq, now);
4274 lnet_peer_ni_decref_locked(lpni);
4275 lnet_net_unlock(LNET_LOCK_EX);
4279 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
4282 * Walk all the peers and reset the health value for each one to the
4285 lnet_net_lock(LNET_LOCK_EX);
4286 for (cpt = 0; cpt < lncpt; cpt++) {
4287 ptable = the_lnet.ln_peer_tables[cpt];
4288 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
4289 list_for_each_entry(lpn, &lp->lp_peer_nets, lpn_peer_nets) {
4290 list_for_each_entry(lpni, &lpn->lpn_peer_nis,
4292 lnet_set_lpni_healthv_locked(lpni,
4294 lnet_peer_ni_add_to_recoveryq_locked(lpni,
4295 &the_lnet.ln_mt_peerNIRecovq, now);
4300 lnet_net_unlock(LNET_LOCK_EX);