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_peer(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);
797 struct lnet_peer_net *
798 lnet_get_next_peer_net_locked(struct lnet_peer *lp, __u32 prev_lpn_id)
800 struct lnet_peer_net *net;
803 /* no net id provided return the first net */
804 net = list_first_entry_or_null(&lp->lp_peer_nets,
805 struct lnet_peer_net,
811 /* find the net after the one provided */
812 list_for_each_entry(net, &lp->lp_peer_nets, lpn_peer_nets) {
813 if (net->lpn_net_id == prev_lpn_id) {
815 * if we reached the end of the list loop to the
818 if (net->lpn_peer_nets.next == &lp->lp_peer_nets)
819 return list_first_entry_or_null(&lp->lp_peer_nets,
820 struct lnet_peer_net,
823 return list_next_entry(net, lpn_peer_nets);
830 struct lnet_peer_ni *
831 lnet_get_next_peer_ni_locked(struct lnet_peer *peer,
832 struct lnet_peer_net *peer_net,
833 struct lnet_peer_ni *prev)
835 struct lnet_peer_ni *lpni;
836 struct lnet_peer_net *net = peer_net;
840 if (list_empty(&peer->lp_peer_nets))
843 net = list_entry(peer->lp_peer_nets.next,
844 struct lnet_peer_net,
847 lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
853 if (prev->lpni_peer_nis.next == &prev->lpni_peer_net->lpn_peer_nis) {
855 * if you reached the end of the peer ni list and the peer
856 * net is specified then there are no more peer nis in that
863 * we reached the end of this net ni list. move to the
866 if (prev->lpni_peer_net->lpn_peer_nets.next ==
868 /* no more nets and no more NIs. */
871 /* get the next net */
872 net = list_entry(prev->lpni_peer_net->lpn_peer_nets.next,
873 struct lnet_peer_net,
875 /* get the ni on it */
876 lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
882 /* there are more nis left */
883 lpni = list_entry(prev->lpni_peer_nis.next,
884 struct lnet_peer_ni, lpni_peer_nis);
889 /* Call with the ln_api_mutex held */
890 int lnet_get_peer_list(u32 *countp, u32 *sizep, struct lnet_process_id __user *ids)
892 struct lnet_process_id id;
893 struct lnet_peer_table *ptable;
894 struct lnet_peer *lp;
903 if (the_lnet.ln_state != LNET_STATE_RUNNING)
906 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
909 * Count the number of peers, and return E2BIG if the buffer
910 * is too small. We'll also return the desired size.
913 for (cpt = 0; cpt < lncpt; cpt++) {
914 ptable = the_lnet.ln_peer_tables[cpt];
915 count += ptable->pt_peers;
917 size = count * sizeof(*ids);
922 * Walk the peer lists and copy out the primary nids.
923 * This is safe because the peer lists are only modified
924 * while the ln_api_mutex is held. So we don't need to
925 * hold the lnet_net_lock as well, and can therefore
926 * directly call copy_to_user().
929 memset(&id, 0, sizeof(id));
930 id.pid = LNET_PID_LUSTRE;
932 for (cpt = 0; cpt < lncpt; cpt++) {
933 ptable = the_lnet.ln_peer_tables[cpt];
934 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
935 if (!nid_is_nid4(&lp->lp_primary_nid))
939 id.nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
940 if (copy_to_user(&ids[i], &id, sizeof(id)))
953 * Start pushes to peers that need to be updated for a configuration
954 * change on this node.
957 lnet_push_update_to_peers(int force)
959 struct lnet_peer_table *ptable;
960 struct lnet_peer *lp;
964 lnet_net_lock(LNET_LOCK_EX);
965 if (lnet_peer_discovery_disabled)
967 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
968 for (cpt = 0; cpt < lncpt; cpt++) {
969 ptable = the_lnet.ln_peer_tables[cpt];
970 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
972 spin_lock(&lp->lp_lock);
973 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
974 lp->lp_state |= LNET_PEER_FORCE_PUSH;
975 spin_unlock(&lp->lp_lock);
977 if (lnet_peer_needs_push(lp))
978 lnet_peer_queue_for_discovery(lp);
981 lnet_net_unlock(LNET_LOCK_EX);
982 wake_up(&the_lnet.ln_dc_waitq);
985 /* find the NID in the preferred gateways for the remote peer
987 * false: list is not empty and NID is not preferred
988 * false: list is empty
989 * true: nid is found in the list
992 lnet_peer_is_pref_rtr_locked(struct lnet_peer_ni *lpni,
993 struct lnet_nid *gw_nid)
995 struct lnet_nid_list *ne;
997 CDEBUG(D_NET, "%s: rtr pref emtpy: %d\n",
998 libcfs_nidstr(&lpni->lpni_nid),
999 list_empty(&lpni->lpni_rtr_pref_nids));
1001 if (list_empty(&lpni->lpni_rtr_pref_nids))
1004 /* iterate through all the preferred NIDs and see if any of them
1005 * matches the provided gw_nid
1007 list_for_each_entry(ne, &lpni->lpni_rtr_pref_nids, nl_list) {
1008 CDEBUG(D_NET, "Comparing pref %s with gw %s\n",
1009 libcfs_nidstr(&ne->nl_nid),
1010 libcfs_nidstr(gw_nid));
1011 if (nid_same(&ne->nl_nid, gw_nid))
1019 lnet_peer_clr_pref_rtrs(struct lnet_peer_ni *lpni)
1021 struct list_head zombies;
1022 struct lnet_nid_list *ne;
1023 struct lnet_nid_list *tmp;
1024 int cpt = lpni->lpni_cpt;
1026 INIT_LIST_HEAD(&zombies);
1029 list_splice_init(&lpni->lpni_rtr_pref_nids, &zombies);
1030 lnet_net_unlock(cpt);
1032 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1033 list_del(&ne->nl_list);
1034 LIBCFS_FREE(ne, sizeof(*ne));
1039 lnet_peer_add_pref_rtr(struct lnet_peer_ni *lpni,
1040 struct lnet_nid *gw_nid)
1042 int cpt = lpni->lpni_cpt;
1043 struct lnet_nid_list *ne = NULL;
1045 /* This function is called with api_mutex held. When the api_mutex
1046 * is held the list can not be modified, as it is only modified as
1047 * a result of applying a UDSP and that happens under api_mutex
1050 __must_hold(&the_lnet.ln_api_mutex);
1052 list_for_each_entry(ne, &lpni->lpni_rtr_pref_nids, nl_list) {
1053 if (nid_same(&ne->nl_nid, gw_nid))
1057 LIBCFS_CPT_ALLOC(ne, lnet_cpt_table(), cpt, sizeof(*ne));
1061 ne->nl_nid = *gw_nid;
1063 /* Lock the cpt to protect against addition and checks in the
1064 * selection algorithm
1067 list_add(&ne->nl_list, &lpni->lpni_rtr_pref_nids);
1068 lnet_net_unlock(cpt);
1074 * Test whether a ni is a preferred ni for this peer_ni, e.g, whether
1075 * this is a preferred point-to-point path. Call with lnet_net_lock in
1079 lnet_peer_is_pref_nid_locked(struct lnet_peer_ni *lpni, struct lnet_nid *nid)
1081 struct lnet_nid_list *ne;
1083 if (lpni->lpni_pref_nnids == 0)
1085 if (lpni->lpni_pref_nnids == 1)
1086 return nid_same(&lpni->lpni_pref.nid, nid);
1087 list_for_each_entry(ne, &lpni->lpni_pref.nids, nl_list) {
1088 if (nid_same(&ne->nl_nid, nid))
1095 * Set a single ni as preferred, provided no preferred ni is already
1096 * defined. Only to be used for non-multi-rail peer_ni.
1099 lnet_peer_ni_set_non_mr_pref_nid(struct lnet_peer_ni *lpni,
1100 struct lnet_nid *nid)
1106 spin_lock(&lpni->lpni_lock);
1107 if (LNET_NID_IS_ANY(nid)) {
1109 } else if (lpni->lpni_pref_nnids > 0) {
1111 } else if (lpni->lpni_pref_nnids == 0) {
1112 lpni->lpni_pref.nid = *nid;
1113 lpni->lpni_pref_nnids = 1;
1114 lpni->lpni_state |= LNET_PEER_NI_NON_MR_PREF;
1116 spin_unlock(&lpni->lpni_lock);
1118 CDEBUG(D_NET, "peer %s nid %s: %d\n",
1119 libcfs_nidstr(&lpni->lpni_nid), libcfs_nidstr(nid), rc);
1124 * Clear the preferred NID from a non-multi-rail peer_ni, provided
1125 * this preference was set by lnet_peer_ni_set_non_mr_pref_nid().
1128 lnet_peer_ni_clr_non_mr_pref_nid(struct lnet_peer_ni *lpni)
1132 spin_lock(&lpni->lpni_lock);
1133 if (lpni->lpni_state & LNET_PEER_NI_NON_MR_PREF) {
1134 lpni->lpni_pref_nnids = 0;
1135 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1136 } else if (lpni->lpni_pref_nnids == 0) {
1141 spin_unlock(&lpni->lpni_lock);
1143 CDEBUG(D_NET, "peer %s: %d\n",
1144 libcfs_nidstr(&lpni->lpni_nid), rc);
1149 lnet_peer_ni_set_selection_priority(struct lnet_peer_ni *lpni, __u32 priority)
1151 lpni->lpni_sel_priority = priority;
1155 * Clear the preferred NIDs from a non-multi-rail peer.
1158 lnet_peer_clr_non_mr_pref_nids(struct lnet_peer *lp)
1160 struct lnet_peer_ni *lpni = NULL;
1162 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
1163 lnet_peer_ni_clr_non_mr_pref_nid(lpni);
1167 lnet_peer_add_pref_nid(struct lnet_peer_ni *lpni, struct lnet_nid *nid)
1169 struct lnet_peer *lp = lpni->lpni_peer_net->lpn_peer;
1170 struct lnet_nid_list *ne1 = NULL;
1171 struct lnet_nid_list *ne2 = NULL;
1172 struct lnet_nid *tmp_nid = NULL;
1175 if (LNET_NID_IS_ANY(nid)) {
1180 if (lpni->lpni_pref_nnids == 1 &&
1181 nid_same(&lpni->lpni_pref.nid, nid)) {
1186 /* A non-MR node may have only one preferred NI per peer_ni */
1187 if (lpni->lpni_pref_nnids > 0 &&
1188 !(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1193 /* add the new preferred nid to the list of preferred nids */
1194 if (lpni->lpni_pref_nnids != 0) {
1195 size_t alloc_size = sizeof(*ne1);
1197 if (lpni->lpni_pref_nnids == 1) {
1198 tmp_nid = &lpni->lpni_pref.nid;
1199 INIT_LIST_HEAD(&lpni->lpni_pref.nids);
1202 list_for_each_entry(ne1, &lpni->lpni_pref.nids, nl_list) {
1203 if (nid_same(&ne1->nl_nid, nid)) {
1209 LIBCFS_CPT_ALLOC(ne1, lnet_cpt_table(), lpni->lpni_cpt,
1216 /* move the originally stored nid to the list */
1217 if (lpni->lpni_pref_nnids == 1) {
1218 LIBCFS_CPT_ALLOC(ne2, lnet_cpt_table(),
1219 lpni->lpni_cpt, alloc_size);
1224 INIT_LIST_HEAD(&ne2->nl_list);
1225 ne2->nl_nid = *tmp_nid;
1230 lnet_net_lock(LNET_LOCK_EX);
1231 spin_lock(&lpni->lpni_lock);
1232 if (lpni->lpni_pref_nnids == 0) {
1233 lpni->lpni_pref.nid = *nid;
1236 list_add_tail(&ne2->nl_list, &lpni->lpni_pref.nids);
1237 list_add_tail(&ne1->nl_list, &lpni->lpni_pref.nids);
1239 lpni->lpni_pref_nnids++;
1240 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1241 spin_unlock(&lpni->lpni_lock);
1242 lnet_net_unlock(LNET_LOCK_EX);
1245 if (rc == -EEXIST && (lpni->lpni_state & LNET_PEER_NI_NON_MR_PREF)) {
1246 spin_lock(&lpni->lpni_lock);
1247 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1248 spin_unlock(&lpni->lpni_lock);
1250 CDEBUG(D_NET, "peer %s nid %s: %d\n",
1251 libcfs_nidstr(&lp->lp_primary_nid), libcfs_nidstr(nid), rc);
1256 lnet_peer_del_pref_nid(struct lnet_peer_ni *lpni, struct lnet_nid *nid)
1258 struct lnet_peer *lp = lpni->lpni_peer_net->lpn_peer;
1259 struct lnet_nid_list *ne = NULL;
1262 if (lpni->lpni_pref_nnids == 0) {
1267 if (lpni->lpni_pref_nnids == 1) {
1268 if (!nid_same(&lpni->lpni_pref.nid, nid)) {
1273 list_for_each_entry(ne, &lpni->lpni_pref.nids, nl_list) {
1274 if (nid_same(&ne->nl_nid, nid))
1275 goto remove_nid_entry;
1283 lnet_net_lock(LNET_LOCK_EX);
1284 spin_lock(&lpni->lpni_lock);
1285 if (lpni->lpni_pref_nnids == 1)
1286 lpni->lpni_pref.nid = LNET_ANY_NID;
1288 list_del_init(&ne->nl_list);
1289 if (lpni->lpni_pref_nnids == 2) {
1290 struct lnet_nid_list *ne, *tmp;
1292 list_for_each_entry_safe(ne, tmp,
1293 &lpni->lpni_pref.nids,
1295 lpni->lpni_pref.nid = ne->nl_nid;
1296 list_del_init(&ne->nl_list);
1297 LIBCFS_FREE(ne, sizeof(*ne));
1301 lpni->lpni_pref_nnids--;
1302 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1303 spin_unlock(&lpni->lpni_lock);
1304 lnet_net_unlock(LNET_LOCK_EX);
1307 LIBCFS_FREE(ne, sizeof(*ne));
1309 CDEBUG(D_NET, "peer %s nid %s: %d\n",
1310 libcfs_nidstr(&lp->lp_primary_nid), libcfs_nidstr(nid), rc);
1315 lnet_peer_clr_pref_nids(struct lnet_peer_ni *lpni)
1317 struct list_head zombies;
1318 struct lnet_nid_list *ne;
1319 struct lnet_nid_list *tmp;
1321 INIT_LIST_HEAD(&zombies);
1323 lnet_net_lock(LNET_LOCK_EX);
1324 if (lpni->lpni_pref_nnids == 1)
1325 lpni->lpni_pref.nid = LNET_ANY_NID;
1326 else if (lpni->lpni_pref_nnids > 1)
1327 list_splice_init(&lpni->lpni_pref.nids, &zombies);
1328 lpni->lpni_pref_nnids = 0;
1329 lnet_net_unlock(LNET_LOCK_EX);
1331 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1332 list_del_init(&ne->nl_list);
1333 LIBCFS_FREE(ne, sizeof(*ne));
1338 lnet_peer_primary_nid_locked(lnet_nid_t nid)
1340 /* FIXME handle large-addr nid */
1341 struct lnet_peer_ni *lpni;
1342 lnet_nid_t primary_nid = nid;
1344 lpni = lnet_find_peer_ni_locked(nid);
1346 primary_nid = lnet_nid_to_nid4(
1347 &lpni->lpni_peer_net->lpn_peer->lp_primary_nid);
1348 lnet_peer_ni_decref_locked(lpni);
1355 lnet_is_discovery_disabled_locked(struct lnet_peer *lp)
1356 __must_hold(&lp->lp_lock)
1358 if (lnet_peer_discovery_disabled)
1361 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL) ||
1362 (lp->lp_state & LNET_PEER_NO_DISCOVERY)) {
1373 lnet_is_discovery_disabled(struct lnet_peer *lp)
1377 spin_lock(&lp->lp_lock);
1378 rc = lnet_is_discovery_disabled_locked(lp);
1379 spin_unlock(&lp->lp_lock);
1385 LNetAddPeer(lnet_nid_t *nids, __u32 num_nids)
1387 lnet_nid_t pnid = 0;
1391 if (!nids || num_nids < 1)
1394 rc = LNetNIInit(LNET_PID_ANY);
1398 mutex_lock(&the_lnet.ln_api_mutex);
1400 mr = lnet_peer_discovery_disabled == 0;
1403 for (i = 0; i < num_nids; i++) {
1404 if (nids[i] == LNET_NID_LO_0)
1409 rc = lnet_add_peer_ni(pnid, LNET_NID_ANY, mr, true);
1410 } else if (lnet_peer_discovery_disabled) {
1411 rc = lnet_add_peer_ni(nids[i], LNET_NID_ANY, mr, true);
1413 rc = lnet_add_peer_ni(pnid, nids[i], mr, true);
1416 if (rc && rc != -EEXIST)
1421 mutex_unlock(&the_lnet.ln_api_mutex);
1425 return rc == -EEXIST ? 0 : rc;
1427 EXPORT_SYMBOL(LNetAddPeer);
1429 /* FIXME support large-addr nid */
1431 LNetPrimaryNID(lnet_nid_t nid)
1433 struct lnet_peer *lp;
1434 struct lnet_peer_ni *lpni;
1435 lnet_nid_t primary_nid = nid;
1439 if (nid == LNET_NID_LO_0)
1440 return LNET_NID_LO_0;
1442 cpt = lnet_net_lock_current();
1443 lpni = lnet_nid2peerni_locked(nid, LNET_NID_ANY, cpt);
1448 lp = lpni->lpni_peer_net->lpn_peer;
1450 /* If discovery is disabled locally then we needn't bother running
1451 * discovery here because discovery will not modify whatever
1452 * primary NID is currently set for this peer. If the specified peer is
1453 * down then this discovery can introduce long delays into the mount
1454 * process, so skip it if it isn't necessary.
1456 while (!lnet_peer_discovery_disabled && !lnet_peer_is_uptodate(lp)) {
1457 spin_lock(&lp->lp_lock);
1458 /* force a full discovery cycle */
1459 lp->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH;
1460 spin_unlock(&lp->lp_lock);
1462 rc = lnet_discover_peer_locked(lpni, cpt, true);
1465 /* The lpni (or lp) for this NID may have changed and our ref is
1466 * the only thing keeping the old one around. Release the ref
1467 * and lookup the lpni again
1469 lnet_peer_ni_decref_locked(lpni);
1470 lpni = lnet_find_peer_ni_locked(nid);
1475 lp = lpni->lpni_peer_net->lpn_peer;
1477 /* If we find that the peer has discovery disabled then we will
1478 * not modify whatever primary NID is currently set for this
1479 * peer. Thus, we can break out of this loop even if the peer
1480 * is not fully up to date.
1482 if (lnet_is_discovery_disabled(lp))
1485 primary_nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
1487 lnet_peer_ni_decref_locked(lpni);
1489 lnet_net_unlock(cpt);
1491 CDEBUG(D_NET, "NID %s primary NID %s rc %d\n", libcfs_nid2str(nid),
1492 libcfs_nid2str(primary_nid), rc);
1495 EXPORT_SYMBOL(LNetPrimaryNID);
1497 struct lnet_peer_net *
1498 lnet_peer_get_net_locked(struct lnet_peer *peer, __u32 net_id)
1500 struct lnet_peer_net *peer_net;
1501 list_for_each_entry(peer_net, &peer->lp_peer_nets, lpn_peer_nets) {
1502 if (peer_net->lpn_net_id == net_id)
1509 * Attach a peer_ni to a peer_net and peer. This function assumes
1510 * peer_ni is not already attached to the peer_net/peer. The peer_ni
1511 * may be attached to a different peer, in which case it will be
1512 * properly detached first. The whole operation is done atomically.
1514 * This function consumes the reference on lpni and Always returns 0.
1515 * This is the last function called from functions that do return an
1516 * int, so returning 0 here allows the compiler to do a tail call.
1519 lnet_peer_attach_peer_ni(struct lnet_peer *lp,
1520 struct lnet_peer_net *lpn,
1521 struct lnet_peer_ni *lpni,
1524 struct lnet_peer_table *ptable;
1525 bool new_lpn = false;
1528 /* Install the new peer_ni */
1529 lnet_net_lock(LNET_LOCK_EX);
1530 /* Add peer_ni to global peer table hash, if necessary. */
1531 if (list_empty(&lpni->lpni_hashlist)) {
1532 int hash = lnet_nid2peerhash(&lpni->lpni_nid);
1534 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
1535 list_add_tail(&lpni->lpni_hashlist, &ptable->pt_hash[hash]);
1536 ptable->pt_version++;
1537 lnet_peer_ni_addref_locked(lpni);
1540 /* Detach the peer_ni from an existing peer, if necessary. */
1541 if (lpni->lpni_peer_net) {
1542 LASSERT(lpni->lpni_peer_net != lpn);
1543 LASSERT(lpni->lpni_peer_net->lpn_peer != lp);
1544 lnet_peer_detach_peer_ni_locked(lpni);
1545 lnet_peer_net_decref_locked(lpni->lpni_peer_net);
1546 lpni->lpni_peer_net = NULL;
1549 /* Add peer_ni to peer_net */
1550 lpni->lpni_peer_net = lpn;
1551 if (nid_same(&lp->lp_primary_nid, &lpni->lpni_nid))
1552 list_add(&lpni->lpni_peer_nis, &lpn->lpn_peer_nis);
1554 list_add_tail(&lpni->lpni_peer_nis, &lpn->lpn_peer_nis);
1555 lnet_update_peer_net_healthv(lpni);
1556 lnet_peer_net_addref_locked(lpn);
1558 /* Add peer_net to peer */
1559 if (!lpn->lpn_peer) {
1562 if (nid_same(&lp->lp_primary_nid, &lpni->lpni_nid))
1563 list_add(&lpn->lpn_peer_nets, &lp->lp_peer_nets);
1565 list_add_tail(&lpn->lpn_peer_nets, &lp->lp_peer_nets);
1566 lnet_peer_addref_locked(lp);
1569 /* Add peer to global peer list, if necessary */
1570 ptable = the_lnet.ln_peer_tables[lp->lp_cpt];
1571 if (list_empty(&lp->lp_peer_list)) {
1572 list_add_tail(&lp->lp_peer_list, &ptable->pt_peer_list);
1577 /* Update peer state */
1578 spin_lock(&lp->lp_lock);
1579 if (flags & LNET_PEER_CONFIGURED) {
1580 if (!(lp->lp_state & LNET_PEER_CONFIGURED))
1581 lp->lp_state |= LNET_PEER_CONFIGURED;
1583 if (flags & LNET_PEER_MULTI_RAIL) {
1584 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1585 lp->lp_state |= LNET_PEER_MULTI_RAIL;
1586 lnet_peer_clr_non_mr_pref_nids(lp);
1589 spin_unlock(&lp->lp_lock);
1595 rc = lnet_udsp_apply_policies_on_lpn(lpn);
1597 CERROR("Failed to apply UDSPs on lpn %s\n",
1598 libcfs_net2str(lpn->lpn_net_id));
1600 rc = lnet_udsp_apply_policies_on_lpni(lpni);
1602 CERROR("Failed to apply UDSPs on lpni %s\n",
1603 libcfs_nidstr(&lpni->lpni_nid));
1605 CDEBUG(D_NET, "peer %s NID %s flags %#x\n",
1606 libcfs_nidstr(&lp->lp_primary_nid),
1607 libcfs_nidstr(&lpni->lpni_nid), flags);
1608 lnet_peer_ni_decref_locked(lpni);
1609 lnet_net_unlock(LNET_LOCK_EX);
1615 * Create a new peer, with nid as its primary nid.
1617 * Call with the lnet_api_mutex held.
1620 lnet_peer_add(lnet_nid_t nid4, unsigned int flags)
1622 struct lnet_nid nid;
1623 struct lnet_peer *lp;
1624 struct lnet_peer_net *lpn;
1625 struct lnet_peer_ni *lpni;
1628 LASSERT(nid4 != LNET_NID_ANY);
1631 * No need for the lnet_net_lock here, because the
1632 * lnet_api_mutex is held.
1634 lpni = lnet_find_peer_ni_locked(nid4);
1636 /* A peer with this NID already exists. */
1637 lp = lpni->lpni_peer_net->lpn_peer;
1638 lnet_peer_ni_decref_locked(lpni);
1640 * This is an error if the peer was configured and the
1641 * primary NID differs or an attempt is made to change
1642 * the Multi-Rail flag. Otherwise the assumption is
1643 * that an existing peer is being modified.
1645 if (lp->lp_state & LNET_PEER_CONFIGURED) {
1646 if (lnet_nid_to_nid4(&lp->lp_primary_nid) != nid4)
1648 else if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL)
1651 } else if (!(flags & LNET_PEER_CONFIGURED)) {
1652 if (lnet_nid_to_nid4(&lp->lp_primary_nid) == nid4) {
1657 /* Delete and recreate as a configured peer. */
1658 rc = lnet_peer_del(lp);
1663 /* Create peer, peer_net, and peer_ni. */
1665 lnet_nid4_to_nid(nid4, &nid);
1666 lp = lnet_peer_alloc(&nid);
1669 lpn = lnet_peer_net_alloc(LNET_NID_NET(&nid));
1672 lpni = lnet_peer_ni_alloc(&nid);
1676 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1679 LIBCFS_FREE(lpn, sizeof(*lpn));
1681 LIBCFS_FREE(lp, sizeof(*lp));
1683 CDEBUG(D_NET, "peer %s NID flags %#x: %d\n",
1684 libcfs_nid2str(nid4), flags, rc);
1689 * Add a NID to a peer. Call with ln_api_mutex held.
1692 * -EPERM: Non-DLC addition to a DLC-configured peer.
1693 * -EEXIST: The NID was configured by DLC for a different peer.
1694 * -ENOMEM: Out of memory.
1695 * -ENOTUNIQ: Adding a second peer NID on a single network on a
1696 * non-multi-rail peer.
1699 lnet_peer_add_nid(struct lnet_peer *lp, lnet_nid_t nid4, unsigned int flags)
1701 struct lnet_peer_net *lpn;
1702 struct lnet_peer_ni *lpni;
1703 struct lnet_nid nid;
1707 LASSERT(nid4 != LNET_NID_ANY);
1709 lnet_nid4_to_nid(nid4, &nid);
1711 /* A configured peer can only be updated through configuration. */
1712 if (!(flags & LNET_PEER_CONFIGURED)) {
1713 if (lp->lp_state & LNET_PEER_CONFIGURED) {
1720 * The MULTI_RAIL flag can be set but not cleared, because
1721 * that would leave the peer struct in an invalid state.
1723 if (flags & LNET_PEER_MULTI_RAIL) {
1724 spin_lock(&lp->lp_lock);
1725 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1726 lp->lp_state |= LNET_PEER_MULTI_RAIL;
1727 lnet_peer_clr_non_mr_pref_nids(lp);
1729 spin_unlock(&lp->lp_lock);
1730 } else if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
1735 lpni = lnet_find_peer_ni_locked(nid4);
1738 * A peer_ni already exists. This is only a problem if
1739 * it is not connected to this peer and was configured
1742 if (lpni->lpni_peer_net->lpn_peer == lp)
1744 if (lnet_peer_ni_is_configured(lpni)) {
1748 /* If this is the primary NID, destroy the peer. */
1749 if (lnet_peer_ni_is_primary(lpni)) {
1750 struct lnet_peer *rtr_lp =
1751 lpni->lpni_peer_net->lpn_peer;
1752 int rtr_refcount = rtr_lp->lp_rtr_refcount;
1754 * if we're trying to delete a router it means
1755 * we're moving this peer NI to a new peer so must
1756 * transfer router properties to the new peer
1758 if (rtr_refcount > 0) {
1759 flags |= LNET_PEER_RTR_NI_FORCE_DEL;
1760 lnet_rtr_transfer_to_peer(rtr_lp, lp);
1762 lnet_peer_del(lpni->lpni_peer_net->lpn_peer);
1763 lnet_peer_ni_decref_locked(lpni);
1764 lpni = lnet_peer_ni_alloc(&nid);
1771 lpni = lnet_peer_ni_alloc(&nid);
1779 * Get the peer_net. Check that we're not adding a second
1780 * peer_ni on a peer_net of a non-multi-rail peer.
1782 lpn = lnet_peer_get_net_locked(lp, LNET_NIDNET(nid4));
1784 lpn = lnet_peer_net_alloc(LNET_NIDNET(nid4));
1789 } else if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1794 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1797 lnet_peer_ni_decref_locked(lpni);
1799 CDEBUG(D_NET, "peer %s NID %s flags %#x: %d\n",
1800 libcfs_nidstr(&lp->lp_primary_nid), libcfs_nid2str(nid4),
1806 * Update the primary NID of a peer, if possible.
1808 * Call with the lnet_api_mutex held.
1811 lnet_peer_set_primary_nid(struct lnet_peer *lp, lnet_nid_t nid,
1814 struct lnet_nid old = lp->lp_primary_nid;
1817 if (lnet_nid_to_nid4(&lp->lp_primary_nid) == nid)
1820 lnet_nid4_to_nid(nid, &lp->lp_primary_nid);
1822 rc = lnet_peer_add_nid(lp, nid, flags);
1824 lp->lp_primary_nid = old;
1828 CDEBUG(D_NET, "peer %s NID %s: %d\n",
1829 libcfs_nidstr(&old), libcfs_nid2str(nid), rc);
1835 * lpni creation initiated due to traffic either sending or receiving.
1838 lnet_peer_ni_traffic_add(struct lnet_nid *nid, struct lnet_nid *pref)
1840 struct lnet_peer *lp;
1841 struct lnet_peer_net *lpn;
1842 struct lnet_peer_ni *lpni;
1846 if (LNET_NID_IS_ANY(nid)) {
1851 /* lnet_net_lock is not needed here because ln_api_lock is held */
1852 lpni = lnet_peer_ni_find_locked(nid);
1855 * We must have raced with another thread. Since we
1856 * know next to nothing about a peer_ni created by
1857 * traffic, we just assume everything is ok and
1860 lnet_peer_ni_decref_locked(lpni);
1864 /* Create peer, peer_net, and peer_ni. */
1866 lp = lnet_peer_alloc(nid);
1869 lpn = lnet_peer_net_alloc(LNET_NID_NET(nid));
1872 lpni = lnet_peer_ni_alloc(nid);
1875 lnet_peer_ni_set_non_mr_pref_nid(lpni, pref);
1877 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1880 LIBCFS_FREE(lpn, sizeof(*lpn));
1882 LIBCFS_FREE(lp, sizeof(*lp));
1884 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nidstr(nid), rc);
1889 * Implementation of IOC_LIBCFS_ADD_PEER_NI.
1891 * This API handles the following combinations:
1892 * Create a peer with its primary NI if only the prim_nid is provided
1893 * Add a NID to a peer identified by the prim_nid. The peer identified
1894 * by the prim_nid must already exist.
1895 * The peer being created may be non-MR.
1897 * The caller must hold ln_api_mutex. This prevents the peer from
1898 * being created/modified/deleted by a different thread.
1901 lnet_add_peer_ni(lnet_nid_t prim_nid, lnet_nid_t nid, bool mr, bool temp)
1903 struct lnet_peer *lp = NULL;
1904 struct lnet_peer_ni *lpni;
1905 unsigned int flags = 0;
1907 /* The prim_nid must always be specified */
1908 if (prim_nid == LNET_NID_ANY)
1912 flags = LNET_PEER_CONFIGURED;
1915 flags |= LNET_PEER_MULTI_RAIL;
1918 * If nid isn't specified, we must create a new peer with
1919 * prim_nid as its primary nid.
1921 if (nid == LNET_NID_ANY)
1922 return lnet_peer_add(prim_nid, flags);
1924 /* Look up the prim_nid, which must exist. */
1925 lpni = lnet_find_peer_ni_locked(prim_nid);
1928 lnet_peer_ni_decref_locked(lpni);
1929 lp = lpni->lpni_peer_net->lpn_peer;
1931 /* Peer must have been configured. */
1932 if (!temp && !(lp->lp_state & LNET_PEER_CONFIGURED)) {
1933 CDEBUG(D_NET, "peer %s was not configured\n",
1934 libcfs_nid2str(prim_nid));
1938 /* Primary NID must match */
1939 if (lnet_nid_to_nid4(&lp->lp_primary_nid) != prim_nid) {
1940 CDEBUG(D_NET, "prim_nid %s is not primary for peer %s\n",
1941 libcfs_nid2str(prim_nid),
1942 libcfs_nidstr(&lp->lp_primary_nid));
1946 /* Multi-Rail flag must match. */
1947 if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL) {
1948 CDEBUG(D_NET, "multi-rail state mismatch for peer %s\n",
1949 libcfs_nid2str(prim_nid));
1953 return lnet_peer_add_nid(lp, nid, flags);
1957 * Implementation of IOC_LIBCFS_DEL_PEER_NI.
1959 * This API handles the following combinations:
1960 * Delete a NI from a peer if both prim_nid and nid are provided.
1961 * Delete a peer if only prim_nid is provided.
1962 * Delete a peer if its primary nid is provided.
1964 * The caller must hold ln_api_mutex. This prevents the peer from
1965 * being modified/deleted by a different thread.
1968 lnet_del_peer_ni(lnet_nid_t prim_nid, lnet_nid_t nid)
1970 struct lnet_peer *lp;
1971 struct lnet_peer_ni *lpni;
1974 if (prim_nid == LNET_NID_ANY)
1977 lpni = lnet_find_peer_ni_locked(prim_nid);
1980 lnet_peer_ni_decref_locked(lpni);
1981 lp = lpni->lpni_peer_net->lpn_peer;
1983 if (prim_nid != lnet_nid_to_nid4(&lp->lp_primary_nid)) {
1984 CDEBUG(D_NET, "prim_nid %s is not primary for peer %s\n",
1985 libcfs_nid2str(prim_nid),
1986 libcfs_nidstr(&lp->lp_primary_nid));
1990 lnet_net_lock(LNET_LOCK_EX);
1991 if (lp->lp_rtr_refcount > 0) {
1992 lnet_net_unlock(LNET_LOCK_EX);
1993 CERROR("%s is a router. Can not be deleted\n",
1994 libcfs_nid2str(prim_nid));
1997 lnet_net_unlock(LNET_LOCK_EX);
1999 if (nid == LNET_NID_ANY || nid == lnet_nid_to_nid4(&lp->lp_primary_nid))
2000 return lnet_peer_del(lp);
2002 flags = LNET_PEER_CONFIGURED;
2003 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
2004 flags |= LNET_PEER_MULTI_RAIL;
2006 return lnet_peer_del_nid(lp, nid, flags);
2010 lnet_destroy_peer_ni_locked(struct kref *ref)
2012 struct lnet_peer_ni *lpni = container_of(ref, struct lnet_peer_ni,
2014 struct lnet_peer_table *ptable;
2015 struct lnet_peer_net *lpn;
2017 CDEBUG(D_NET, "%p nid %s\n", lpni, libcfs_nidstr(&lpni->lpni_nid));
2019 LASSERT(kref_read(&lpni->lpni_kref) == 0);
2020 LASSERT(list_empty(&lpni->lpni_txq));
2021 LASSERT(lpni->lpni_txqnob == 0);
2022 LASSERT(list_empty(&lpni->lpni_peer_nis));
2023 LASSERT(list_empty(&lpni->lpni_on_remote_peer_ni_list));
2025 lpn = lpni->lpni_peer_net;
2026 lpni->lpni_peer_net = NULL;
2027 lpni->lpni_net = NULL;
2029 if (!list_empty(&lpni->lpni_hashlist)) {
2030 /* remove the peer ni from the zombie list */
2031 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
2032 spin_lock(&ptable->pt_zombie_lock);
2033 list_del_init(&lpni->lpni_hashlist);
2034 ptable->pt_zombies--;
2035 spin_unlock(&ptable->pt_zombie_lock);
2038 if (lpni->lpni_pref_nnids > 1) {
2039 struct lnet_nid_list *ne, *tmp;
2041 list_for_each_entry_safe(ne, tmp, &lpni->lpni_pref.nids,
2043 list_del_init(&ne->nl_list);
2044 LIBCFS_FREE(ne, sizeof(*ne));
2047 LIBCFS_FREE(lpni, sizeof(*lpni));
2050 lnet_peer_net_decref_locked(lpn);
2053 struct lnet_peer_ni *
2054 lnet_nid2peerni_ex(struct lnet_nid *nid, int cpt)
2056 struct lnet_peer_ni *lpni = NULL;
2059 if (the_lnet.ln_state != LNET_STATE_RUNNING)
2060 return ERR_PTR(-ESHUTDOWN);
2063 * find if a peer_ni already exists.
2064 * If so then just return that.
2066 lpni = lnet_peer_ni_find_locked(nid);
2070 lnet_net_unlock(cpt);
2072 rc = lnet_peer_ni_traffic_add(nid, NULL);
2075 goto out_net_relock;
2078 lpni = lnet_peer_ni_find_locked(nid);
2088 * Get a peer_ni for the given nid, create it if necessary. Takes a
2089 * hold on the peer_ni.
2091 struct lnet_peer_ni *
2092 lnet_peerni_by_nid_locked(struct lnet_nid *nid,
2093 struct lnet_nid *pref, int cpt)
2095 struct lnet_peer_ni *lpni = NULL;
2098 if (the_lnet.ln_state != LNET_STATE_RUNNING)
2099 return ERR_PTR(-ESHUTDOWN);
2102 * find if a peer_ni already exists.
2103 * If so then just return that.
2105 lpni = lnet_peer_ni_find_locked(nid);
2111 * use the lnet_api_mutex to serialize the creation of the peer_ni
2112 * and the creation/deletion of the local ni/net. When a local ni is
2113 * created, if there exists a set of peer_nis on that network,
2114 * they need to be traversed and updated. When a local NI is
2115 * deleted, which could result in a network being deleted, then
2116 * all peer nis on that network need to be removed as well.
2118 * Creation through traffic should also be serialized with
2119 * creation through DLC.
2121 lnet_net_unlock(cpt);
2122 mutex_lock(&the_lnet.ln_api_mutex);
2124 * Shutdown is only set under the ln_api_lock, so a single
2125 * check here is sufficent.
2127 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
2128 lpni = ERR_PTR(-ESHUTDOWN);
2129 goto out_mutex_unlock;
2132 rc = lnet_peer_ni_traffic_add(nid, pref);
2135 goto out_mutex_unlock;
2138 lpni = lnet_peer_ni_find_locked(nid);
2142 mutex_unlock(&the_lnet.ln_api_mutex);
2145 /* Lock has been dropped, check again for shutdown. */
2146 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
2148 lnet_peer_ni_decref_locked(lpni);
2149 lpni = ERR_PTR(-ESHUTDOWN);
2155 struct lnet_peer_ni *
2156 lnet_nid2peerni_locked(lnet_nid_t nid4, lnet_nid_t pref4, int cpt)
2158 struct lnet_nid nid, pref;
2160 lnet_nid4_to_nid(nid4, &nid);
2161 lnet_nid4_to_nid(pref4, &pref);
2162 if (pref4 == LNET_NID_ANY)
2163 return lnet_peerni_by_nid_locked(&nid, NULL, cpt);
2165 return lnet_peerni_by_nid_locked(&nid, &pref, cpt);
2169 lnet_peer_gw_discovery(struct lnet_peer *lp)
2173 spin_lock(&lp->lp_lock);
2174 if (lp->lp_state & LNET_PEER_RTR_DISCOVERY)
2176 spin_unlock(&lp->lp_lock);
2182 lnet_peer_is_uptodate(struct lnet_peer *lp)
2186 spin_lock(&lp->lp_lock);
2187 rc = lnet_peer_is_uptodate_locked(lp);
2188 spin_unlock(&lp->lp_lock);
2193 * Is a peer uptodate from the point of view of discovery?
2195 * If it is currently being processed, obviously not.
2196 * A forced Ping or Push is also handled by the discovery thread.
2198 * Otherwise look at whether the peer needs rediscovering.
2201 lnet_peer_is_uptodate_locked(struct lnet_peer *lp)
2202 __must_hold(&lp->lp_lock)
2206 if (lp->lp_state & (LNET_PEER_DISCOVERING |
2207 LNET_PEER_FORCE_PING |
2208 LNET_PEER_FORCE_PUSH)) {
2210 } else if (lp->lp_state & LNET_PEER_REDISCOVER) {
2212 } else if (lnet_peer_needs_push(lp)) {
2214 } else if (lp->lp_state & LNET_PEER_DISCOVERED) {
2215 if (lp->lp_state & LNET_PEER_NIDS_UPTODATE)
2226 /* Add the message to the peer's lp_dc_pendq and queue the peer for discovery */
2228 lnet_peer_queue_message(struct lnet_peer *lp, struct lnet_msg *msg)
2230 /* The discovery thread holds net_lock/EX and lp_lock when it splices
2231 * the lp_dc_pendq onto a local list for resending. Thus, we do the same
2232 * when adding to the list and queuing the peer to ensure that we do not
2233 * strand any messages on the lp_dc_pendq. This scheme ensures the
2234 * message will be resent even if the peer is already being discovered.
2235 * Therefore we needn't check the return value of
2236 * lnet_peer_queue_for_discovery(lp).
2238 lnet_net_lock(LNET_LOCK_EX);
2239 spin_lock(&lp->lp_lock);
2240 list_add_tail(&msg->msg_list, &lp->lp_dc_pendq);
2241 spin_unlock(&lp->lp_lock);
2242 lnet_peer_queue_for_discovery(lp);
2243 lnet_net_unlock(LNET_LOCK_EX);
2247 * Queue a peer for the attention of the discovery thread. Call with
2248 * lnet_net_lock/EX held. Returns 0 if the peer was queued, and
2249 * -EALREADY if the peer was already queued.
2251 static int lnet_peer_queue_for_discovery(struct lnet_peer *lp)
2255 spin_lock(&lp->lp_lock);
2256 if (!(lp->lp_state & LNET_PEER_DISCOVERING))
2257 lp->lp_state |= LNET_PEER_DISCOVERING;
2258 spin_unlock(&lp->lp_lock);
2259 if (list_empty(&lp->lp_dc_list)) {
2260 lnet_peer_addref_locked(lp);
2261 list_add_tail(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2262 wake_up(&the_lnet.ln_dc_waitq);
2268 CDEBUG(D_NET, "Queue peer %s: %d\n",
2269 libcfs_nidstr(&lp->lp_primary_nid), rc);
2275 * Discovery of a peer is complete. Wake all waiters on the peer.
2276 * Call with lnet_net_lock/EX held.
2278 static void lnet_peer_discovery_complete(struct lnet_peer *lp)
2280 struct lnet_msg *msg, *tmp;
2282 LIST_HEAD(pending_msgs);
2284 CDEBUG(D_NET, "Discovery complete. Dequeue peer %s\n",
2285 libcfs_nidstr(&lp->lp_primary_nid));
2287 list_del_init(&lp->lp_dc_list);
2288 spin_lock(&lp->lp_lock);
2289 list_splice_init(&lp->lp_dc_pendq, &pending_msgs);
2290 spin_unlock(&lp->lp_lock);
2291 wake_up(&lp->lp_dc_waitq);
2293 if (lp->lp_rtr_refcount > 0)
2294 lnet_router_discovery_complete(lp);
2296 lnet_net_unlock(LNET_LOCK_EX);
2298 /* iterate through all pending messages and send them again */
2299 list_for_each_entry_safe(msg, tmp, &pending_msgs, msg_list) {
2300 list_del_init(&msg->msg_list);
2301 if (lp->lp_dc_error) {
2302 lnet_finalize(msg, lp->lp_dc_error);
2306 CDEBUG(D_NET, "sending pending message %s to target %s\n",
2307 lnet_msgtyp2str(msg->msg_type),
2308 libcfs_id2str(msg->msg_target));
2309 rc = lnet_send(msg->msg_src_nid_param, msg,
2310 msg->msg_rtr_nid_param);
2312 CNETERR("Error sending %s to %s: %d\n",
2313 lnet_msgtyp2str(msg->msg_type),
2314 libcfs_id2str(msg->msg_target), rc);
2315 lnet_finalize(msg, rc);
2318 lnet_net_lock(LNET_LOCK_EX);
2319 lnet_peer_decref_locked(lp);
2323 * Handle inbound push.
2324 * Like any event handler, called with lnet_res_lock/CPT held.
2326 void lnet_peer_push_event(struct lnet_event *ev)
2328 struct lnet_ping_buffer *pbuf;
2329 struct lnet_peer *lp;
2331 pbuf = LNET_PING_INFO_TO_BUFFER(ev->md_start + ev->offset);
2333 /* lnet_find_peer() adds a refcount */
2334 lp = lnet_find_peer(ev->source.nid);
2336 CDEBUG(D_NET, "Push Put from unknown %s (source %s). Ignoring...\n",
2337 libcfs_nid2str(ev->initiator.nid),
2338 libcfs_nid2str(ev->source.nid));
2339 pbuf->pb_needs_post = true;
2343 /* Ensure peer state remains consistent while we modify it. */
2344 spin_lock(&lp->lp_lock);
2347 * If some kind of error happened the contents of the message
2348 * cannot be used. Clear the NIDS_UPTODATE and set the
2349 * FORCE_PING flag to trigger a ping.
2352 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2353 lp->lp_state |= LNET_PEER_FORCE_PING;
2354 CDEBUG(D_NET, "Push Put error %d from %s (source %s)\n",
2356 libcfs_nidstr(&lp->lp_primary_nid),
2357 libcfs_nid2str(ev->source.nid));
2362 * A push with invalid or corrupted info. Clear the UPTODATE
2363 * flag to trigger a ping.
2365 if (lnet_ping_info_validate(&pbuf->pb_info)) {
2366 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2367 lp->lp_state |= LNET_PEER_FORCE_PING;
2368 CDEBUG(D_NET, "Corrupted Push from %s\n",
2369 libcfs_nidstr(&lp->lp_primary_nid));
2374 * Make sure we'll allocate the correct size ping buffer when
2377 if (lp->lp_data_nnis < pbuf->pb_info.pi_nnis)
2378 lp->lp_data_nnis = pbuf->pb_info.pi_nnis;
2381 * A non-Multi-Rail peer is not supposed to be capable of
2384 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)) {
2385 CERROR("Push from non-Multi-Rail peer %s dropped\n",
2386 libcfs_nidstr(&lp->lp_primary_nid));
2391 * The peer may have discovery disabled at its end. Set
2392 * NO_DISCOVERY as appropriate.
2394 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_DISCOVERY)) {
2395 CDEBUG(D_NET, "Peer %s has discovery disabled\n",
2396 libcfs_nidstr(&lp->lp_primary_nid));
2398 * Mark the peer for deletion if we already know about it
2399 * and it's going from discovery set to no discovery set
2401 if (!(lp->lp_state & (LNET_PEER_NO_DISCOVERY |
2402 LNET_PEER_DISCOVERING)) &&
2403 lp->lp_state & LNET_PEER_DISCOVERED) {
2404 CDEBUG(D_NET, "Marking %s:0x%x for deletion\n",
2405 libcfs_nidstr(&lp->lp_primary_nid),
2407 lp->lp_state |= LNET_PEER_MARK_DELETION;
2409 lp->lp_state |= LNET_PEER_NO_DISCOVERY;
2410 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
2411 CDEBUG(D_NET, "Peer %s has discovery enabled\n",
2412 libcfs_nidstr(&lp->lp_primary_nid));
2413 lp->lp_state &= ~LNET_PEER_NO_DISCOVERY;
2417 * Update the MULTI_RAIL flag based on the push. If the peer
2418 * was configured with DLC then the setting should match what
2420 * NB: We verified above that the MR feature bit is set in pi_features
2422 if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2423 CDEBUG(D_NET, "peer %s(%p) is MR\n",
2424 libcfs_nidstr(&lp->lp_primary_nid), lp);
2425 } else if (lp->lp_state & LNET_PEER_CONFIGURED) {
2426 CWARN("Push says %s is Multi-Rail, DLC says not\n",
2427 libcfs_nidstr(&lp->lp_primary_nid));
2428 } else if (lnet_peer_discovery_disabled) {
2429 CDEBUG(D_NET, "peer %s(%p) not MR: DD disabled locally\n",
2430 libcfs_nidstr(&lp->lp_primary_nid), lp);
2431 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
2432 CDEBUG(D_NET, "peer %s(%p) not MR: DD disabled remotely\n",
2433 libcfs_nidstr(&lp->lp_primary_nid), lp);
2435 CDEBUG(D_NET, "peer %s(%p) is MR capable\n",
2436 libcfs_nidstr(&lp->lp_primary_nid), lp);
2437 lp->lp_state |= LNET_PEER_MULTI_RAIL;
2438 lnet_peer_clr_non_mr_pref_nids(lp);
2442 * Check for truncation of the Put message. Clear the
2443 * NIDS_UPTODATE flag and set FORCE_PING to trigger a ping,
2444 * and tell discovery to allocate a bigger buffer.
2446 if (ev->mlength < ev->rlength) {
2447 if (the_lnet.ln_push_target_nnis < pbuf->pb_info.pi_nnis)
2448 the_lnet.ln_push_target_nnis = pbuf->pb_info.pi_nnis;
2449 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2450 lp->lp_state |= LNET_PEER_FORCE_PING;
2451 CDEBUG(D_NET, "Truncated Push from %s (%d nids)\n",
2452 libcfs_nidstr(&lp->lp_primary_nid),
2453 pbuf->pb_info.pi_nnis);
2457 /* always assume new data */
2458 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2459 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2462 * If there is data present that hasn't been processed yet,
2463 * we'll replace it if the Put contained newer data and it
2464 * fits. We're racing with a Ping or earlier Push in this
2467 if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
2468 if (LNET_PING_BUFFER_SEQNO(pbuf) >
2469 LNET_PING_BUFFER_SEQNO(lp->lp_data) &&
2470 pbuf->pb_info.pi_nnis <= lp->lp_data->pb_nnis) {
2471 memcpy(&lp->lp_data->pb_info, &pbuf->pb_info,
2472 LNET_PING_INFO_SIZE(pbuf->pb_info.pi_nnis));
2473 CDEBUG(D_NET, "Ping/Push race from %s: %u vs %u\n",
2474 libcfs_nidstr(&lp->lp_primary_nid),
2475 LNET_PING_BUFFER_SEQNO(pbuf),
2476 LNET_PING_BUFFER_SEQNO(lp->lp_data));
2482 * Allocate a buffer to copy the data. On a failure we drop
2483 * the Push and set FORCE_PING to force the discovery
2484 * thread to fix the problem by pinging the peer.
2486 lp->lp_data = lnet_ping_buffer_alloc(lp->lp_data_nnis, GFP_ATOMIC);
2488 lp->lp_state |= LNET_PEER_FORCE_PING;
2489 CDEBUG(D_NET, "Cannot allocate Push buffer for %s %u\n",
2490 libcfs_nidstr(&lp->lp_primary_nid),
2491 LNET_PING_BUFFER_SEQNO(pbuf));
2496 memcpy(&lp->lp_data->pb_info, &pbuf->pb_info,
2497 LNET_PING_INFO_SIZE(pbuf->pb_info.pi_nnis));
2498 lp->lp_state |= LNET_PEER_DATA_PRESENT;
2499 CDEBUG(D_NET, "Received Push %s %u\n",
2500 libcfs_nidstr(&lp->lp_primary_nid),
2501 LNET_PING_BUFFER_SEQNO(pbuf));
2504 /* We've processed this buffer. It can be reposted */
2505 pbuf->pb_needs_post = true;
2508 * Queue the peer for discovery if not done, force it on the request
2509 * queue and wake the discovery thread if the peer was already queued,
2510 * because its status changed.
2512 spin_unlock(&lp->lp_lock);
2513 lnet_net_lock(LNET_LOCK_EX);
2514 if (!lnet_peer_is_uptodate(lp) && lnet_peer_queue_for_discovery(lp)) {
2515 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2516 wake_up(&the_lnet.ln_dc_waitq);
2518 /* Drop refcount from lookup */
2519 lnet_peer_decref_locked(lp);
2520 lnet_net_unlock(LNET_LOCK_EX);
2524 * Clear the discovery error state, unless we're already discovering
2525 * this peer, in which case the error is current.
2527 static void lnet_peer_clear_discovery_error(struct lnet_peer *lp)
2529 spin_lock(&lp->lp_lock);
2530 if (!(lp->lp_state & LNET_PEER_DISCOVERING))
2531 lp->lp_dc_error = 0;
2532 spin_unlock(&lp->lp_lock);
2536 * Peer discovery slow path. The ln_api_mutex is held on entry, and
2537 * dropped/retaken within this function. An lnet_peer_ni is passed in
2538 * because discovery could tear down an lnet_peer.
2541 lnet_discover_peer_locked(struct lnet_peer_ni *lpni, int cpt, bool block)
2544 struct lnet_peer *lp;
2549 lnet_net_unlock(cpt);
2550 lnet_net_lock(LNET_LOCK_EX);
2551 lp = lpni->lpni_peer_net->lpn_peer;
2552 lnet_peer_clear_discovery_error(lp);
2555 * We're willing to be interrupted. The lpni can become a
2556 * zombie if we race with DLC, so we must check for that.
2559 /* Keep lp alive when the lnet_net_lock is unlocked */
2560 lnet_peer_addref_locked(lp);
2561 prepare_to_wait(&lp->lp_dc_waitq, &wait, TASK_INTERRUPTIBLE);
2562 if (signal_pending(current))
2564 if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING)
2567 * Don't repeat discovery if discovery is disabled. This is
2568 * done to ensure we can use discovery as a standard ping as
2569 * well for backwards compatibility with routers which do not
2570 * have discovery or have discovery disabled
2572 if (lnet_is_discovery_disabled(lp) && count > 0)
2574 if (lp->lp_dc_error)
2576 if (lnet_peer_is_uptodate(lp))
2578 lnet_peer_queue_for_discovery(lp);
2580 CDEBUG(D_NET, "Discovery attempt # %d\n", count);
2583 * If caller requested a non-blocking operation then
2584 * return immediately. Once discovery is complete any
2585 * pending messages that were stopped due to discovery
2586 * will be transmitted.
2591 lnet_net_unlock(LNET_LOCK_EX);
2593 finish_wait(&lp->lp_dc_waitq, &wait);
2594 lnet_net_lock(LNET_LOCK_EX);
2595 lnet_peer_decref_locked(lp);
2596 /* Peer may have changed */
2597 lp = lpni->lpni_peer_net->lpn_peer;
2599 finish_wait(&lp->lp_dc_waitq, &wait);
2601 lnet_net_unlock(LNET_LOCK_EX);
2603 lnet_peer_decref_locked(lp);
2605 * The peer may have changed, so re-check and rediscover if that turns
2606 * out to have been the case. The reference count on lp ensured that
2607 * even if it was unlinked from lpni the memory could not be recycled.
2608 * Thus the check below is sufficient to determine whether the peer
2609 * changed. If the peer changed, then lp must not be dereferenced.
2611 if (lp != lpni->lpni_peer_net->lpn_peer)
2614 if (signal_pending(current))
2616 else if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING)
2618 else if (lp->lp_dc_error)
2619 rc = lp->lp_dc_error;
2621 CDEBUG(D_NET, "non-blocking discovery\n");
2622 else if (!lnet_peer_is_uptodate(lp) && !lnet_is_discovery_disabled(lp))
2625 CDEBUG(D_NET, "peer %s NID %s: %d. %s\n",
2626 (lp ? libcfs_nidstr(&lp->lp_primary_nid) : "(none)"),
2627 libcfs_nidstr(&lpni->lpni_nid), rc,
2628 (!block) ? "pending discovery" : "discovery complete");
2633 /* Handle an incoming ack for a push. */
2635 lnet_discovery_event_ack(struct lnet_peer *lp, struct lnet_event *ev)
2637 struct lnet_ping_buffer *pbuf;
2639 pbuf = LNET_PING_INFO_TO_BUFFER(ev->md_start);
2640 spin_lock(&lp->lp_lock);
2641 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2642 lp->lp_push_error = ev->status;
2644 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2646 lp->lp_node_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2647 spin_unlock(&lp->lp_lock);
2649 CDEBUG(D_NET, "peer %s ev->status %d\n",
2650 libcfs_nidstr(&lp->lp_primary_nid), ev->status);
2653 /* Handle a Reply message. This is the reply to a Ping message. */
2655 lnet_discovery_event_reply(struct lnet_peer *lp, struct lnet_event *ev)
2657 struct lnet_ping_buffer *pbuf;
2660 spin_lock(&lp->lp_lock);
2662 lnet_nid4_to_nid(ev->target.nid, &lp->lp_disc_src_nid);
2663 lnet_nid4_to_nid(ev->source.nid, &lp->lp_disc_dst_nid);
2666 * If some kind of error happened the contents of message
2667 * cannot be used. Set PING_FAILED to trigger a retry.
2670 lp->lp_state |= LNET_PEER_PING_FAILED;
2671 lp->lp_ping_error = ev->status;
2672 CDEBUG(D_NET, "Ping Reply error %d from %s (source %s)\n",
2674 libcfs_nidstr(&lp->lp_primary_nid),
2675 libcfs_nid2str(ev->source.nid));
2679 pbuf = LNET_PING_INFO_TO_BUFFER(ev->md_start);
2680 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
2681 lnet_swap_pinginfo(pbuf);
2684 * A reply with invalid or corrupted info. Set PING_FAILED to
2687 rc = lnet_ping_info_validate(&pbuf->pb_info);
2689 lp->lp_state |= LNET_PEER_PING_FAILED;
2690 lp->lp_ping_error = 0;
2691 CDEBUG(D_NET, "Corrupted Ping Reply from %s: %d\n",
2692 libcfs_nidstr(&lp->lp_primary_nid), rc);
2697 * The peer may have discovery disabled at its end. Set
2698 * NO_DISCOVERY as appropriate.
2700 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_DISCOVERY) ||
2701 lnet_peer_discovery_disabled) {
2702 CDEBUG(D_NET, "Peer %s has discovery disabled\n",
2703 libcfs_nidstr(&lp->lp_primary_nid));
2705 /* Detect whether this peer has toggled discovery from on to
2706 * off and whether we can delete and re-create the peer. Peers
2707 * that were manually configured cannot be deleted by discovery.
2708 * We need to delete this peer and re-create it if the peer was
2709 * not configured manually, is currently considered DD capable,
2711 * 1. We've already discovered the peer (the peer has toggled
2712 * the discovery feature from on to off), or
2713 * 2. The peer is considered MR, but it was not user configured
2714 * (this was a "temporary" peer created via the kernel APIs
2715 * that we're discovering for the first time)
2717 if (!(lp->lp_state & (LNET_PEER_CONFIGURED |
2718 LNET_PEER_NO_DISCOVERY)) &&
2719 (lp->lp_state & (LNET_PEER_DISCOVERED |
2720 LNET_PEER_MULTI_RAIL))) {
2721 CDEBUG(D_NET, "Marking %s:0x%x for deletion\n",
2722 libcfs_nidstr(&lp->lp_primary_nid),
2724 lp->lp_state |= LNET_PEER_MARK_DELETION;
2726 lp->lp_state |= LNET_PEER_NO_DISCOVERY;
2728 CDEBUG(D_NET, "Peer %s has discovery enabled\n",
2729 libcfs_nidstr(&lp->lp_primary_nid));
2730 lp->lp_state &= ~LNET_PEER_NO_DISCOVERY;
2734 * Update the MULTI_RAIL flag based on the reply. If the peer
2735 * was configured with DLC then the setting should match what
2738 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL) {
2739 if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2740 CDEBUG(D_NET, "peer %s(%p) is MR\n",
2741 libcfs_nidstr(&lp->lp_primary_nid), lp);
2742 } else if (lp->lp_state & LNET_PEER_CONFIGURED) {
2743 CWARN("Reply says %s is Multi-Rail, DLC says not\n",
2744 libcfs_nidstr(&lp->lp_primary_nid));
2745 } else if (lnet_peer_discovery_disabled) {
2747 "peer %s(%p) not MR: DD disabled locally\n",
2748 libcfs_nidstr(&lp->lp_primary_nid), lp);
2749 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
2751 "peer %s(%p) not MR: DD disabled remotely\n",
2752 libcfs_nidstr(&lp->lp_primary_nid), lp);
2754 CDEBUG(D_NET, "peer %s(%p) is MR capable\n",
2755 libcfs_nidstr(&lp->lp_primary_nid), lp);
2756 lp->lp_state |= LNET_PEER_MULTI_RAIL;
2757 lnet_peer_clr_non_mr_pref_nids(lp);
2759 } else if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2760 if (lp->lp_state & LNET_PEER_CONFIGURED) {
2761 CWARN("DLC says %s is Multi-Rail, Reply says not\n",
2762 libcfs_nidstr(&lp->lp_primary_nid));
2764 CERROR("Multi-Rail state vanished from %s\n",
2765 libcfs_nidstr(&lp->lp_primary_nid));
2766 lp->lp_state &= ~LNET_PEER_MULTI_RAIL;
2771 * Make sure we'll allocate the correct size ping buffer when
2774 if (lp->lp_data_nnis < pbuf->pb_info.pi_nnis)
2775 lp->lp_data_nnis = pbuf->pb_info.pi_nnis;
2778 * Check for truncation of the Reply. Clear PING_SENT and set
2779 * PING_FAILED to trigger a retry.
2781 if (pbuf->pb_nnis < pbuf->pb_info.pi_nnis) {
2782 if (the_lnet.ln_push_target_nnis < pbuf->pb_info.pi_nnis)
2783 the_lnet.ln_push_target_nnis = pbuf->pb_info.pi_nnis;
2784 lp->lp_state |= LNET_PEER_PING_FAILED;
2785 lp->lp_ping_error = 0;
2786 CDEBUG(D_NET, "Truncated Reply from %s (%d nids)\n",
2787 libcfs_nidstr(&lp->lp_primary_nid),
2788 pbuf->pb_info.pi_nnis);
2793 * Check the sequence numbers in the reply. These are only
2794 * available if the reply came from a Multi-Rail peer.
2796 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL &&
2797 pbuf->pb_info.pi_nnis > 1 &&
2798 lnet_nid_to_nid4(&lp->lp_primary_nid) ==
2799 pbuf->pb_info.pi_ni[1].ns_nid) {
2800 if (LNET_PING_BUFFER_SEQNO(pbuf) < lp->lp_peer_seqno)
2801 CDEBUG(D_NET, "peer %s: seq# got %u have %u. peer rebooted?\n",
2802 libcfs_nidstr(&lp->lp_primary_nid),
2803 LNET_PING_BUFFER_SEQNO(pbuf),
2806 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2809 /* We're happy with the state of the data in the buffer. */
2810 CDEBUG(D_NET, "peer %s data present %u. state = 0x%x\n",
2811 libcfs_nidstr(&lp->lp_primary_nid), lp->lp_peer_seqno,
2813 if (lp->lp_state & LNET_PEER_DATA_PRESENT)
2814 lnet_ping_buffer_decref(lp->lp_data);
2816 lp->lp_state |= LNET_PEER_DATA_PRESENT;
2817 lnet_ping_buffer_addref(pbuf);
2820 lp->lp_state &= ~LNET_PEER_PING_SENT;
2821 spin_unlock(&lp->lp_lock);
2823 lnet_net_lock(LNET_LOCK_EX);
2825 * If this peer is a gateway, call the routing callback to
2826 * handle the ping reply
2828 if (lp->lp_rtr_refcount > 0)
2829 lnet_router_discovery_ping_reply(lp);
2830 lnet_net_unlock(LNET_LOCK_EX);
2834 * Send event handling. Only matters for error cases, where we clean
2835 * up state on the peer and peer_ni that would otherwise be updated in
2836 * the REPLY event handler for a successful Ping, and the ACK event
2837 * handler for a successful Push.
2840 lnet_discovery_event_send(struct lnet_peer *lp, struct lnet_event *ev)
2847 spin_lock(&lp->lp_lock);
2848 if (ev->msg_type == LNET_MSG_GET) {
2849 lp->lp_state &= ~LNET_PEER_PING_SENT;
2850 lp->lp_state |= LNET_PEER_PING_FAILED;
2851 lp->lp_ping_error = ev->status;
2852 } else { /* ev->msg_type == LNET_MSG_PUT */
2853 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2854 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2855 lp->lp_push_error = ev->status;
2857 spin_unlock(&lp->lp_lock);
2858 rc = LNET_REDISCOVER_PEER;
2860 CDEBUG(D_NET, "%s Send to %s: %d\n",
2861 (ev->msg_type == LNET_MSG_GET ? "Ping" : "Push"),
2862 libcfs_nid2str(ev->target.nid), rc);
2867 * Unlink event handling. This event is only seen if a call to
2868 * LNetMDUnlink() caused the event to be unlinked. If this call was
2869 * made after the event was set up in LNetGet() or LNetPut() then we
2870 * assume the Ping or Push timed out.
2873 lnet_discovery_event_unlink(struct lnet_peer *lp, struct lnet_event *ev)
2875 spin_lock(&lp->lp_lock);
2876 /* We've passed through LNetGet() */
2877 if (lp->lp_state & LNET_PEER_PING_SENT) {
2878 lp->lp_state &= ~LNET_PEER_PING_SENT;
2879 lp->lp_state |= LNET_PEER_PING_FAILED;
2880 lp->lp_ping_error = -ETIMEDOUT;
2881 CDEBUG(D_NET, "Ping Unlink for message to peer %s\n",
2882 libcfs_nidstr(&lp->lp_primary_nid));
2884 /* We've passed through LNetPut() */
2885 if (lp->lp_state & LNET_PEER_PUSH_SENT) {
2886 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2887 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2888 lp->lp_push_error = -ETIMEDOUT;
2889 CDEBUG(D_NET, "Push Unlink for message to peer %s\n",
2890 libcfs_nidstr(&lp->lp_primary_nid));
2892 spin_unlock(&lp->lp_lock);
2896 * Event handler for the discovery EQ.
2898 * Called with lnet_res_lock(cpt) held. The cpt is the
2899 * lnet_cpt_of_cookie() of the md handle cookie.
2901 static void lnet_discovery_event_handler(struct lnet_event *event)
2903 struct lnet_peer *lp = event->md_user_ptr;
2904 struct lnet_ping_buffer *pbuf;
2907 /* discovery needs to take another look */
2908 rc = LNET_REDISCOVER_PEER;
2910 CDEBUG(D_NET, "Received event: %d\n", event->type);
2912 switch (event->type) {
2913 case LNET_EVENT_ACK:
2914 lnet_discovery_event_ack(lp, event);
2916 case LNET_EVENT_REPLY:
2917 lnet_discovery_event_reply(lp, event);
2919 case LNET_EVENT_SEND:
2920 /* Only send failure triggers a retry. */
2921 rc = lnet_discovery_event_send(lp, event);
2923 case LNET_EVENT_UNLINK:
2924 /* LNetMDUnlink() was called */
2925 lnet_discovery_event_unlink(lp, event);
2928 /* Invalid events. */
2931 lnet_net_lock(LNET_LOCK_EX);
2932 if (event->unlinked) {
2933 pbuf = LNET_PING_INFO_TO_BUFFER(event->md_start);
2934 lnet_ping_buffer_decref(pbuf);
2935 lnet_peer_decref_locked(lp);
2938 /* put peer back at end of request queue, if discovery not already
2940 if (rc == LNET_REDISCOVER_PEER && !lnet_peer_is_uptodate(lp) &&
2941 lnet_peer_queue_for_discovery(lp)) {
2942 list_move_tail(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2943 wake_up(&the_lnet.ln_dc_waitq);
2945 lnet_net_unlock(LNET_LOCK_EX);
2949 * Build a peer from incoming data.
2951 * The NIDs in the incoming data are supposed to be structured as follows:
2954 * - other NIDs in same net
2955 * - NIDs in second net
2956 * - NIDs in third net
2958 * This due to the way the list of NIDs in the data is created.
2960 * Note that this function will mark the peer uptodate unless an
2961 * ENOMEM is encontered. All other errors are due to a conflict
2962 * between the DLC configuration and what discovery sees. We treat DLC
2963 * as binding, and therefore set the NIDS_UPTODATE flag to prevent the
2964 * peer from becoming stuck in discovery.
2966 static int lnet_peer_merge_data(struct lnet_peer *lp,
2967 struct lnet_ping_buffer *pbuf)
2969 struct lnet_peer_net *lpn;
2970 struct lnet_peer_ni *lpni;
2971 lnet_nid_t *curnis = NULL;
2972 struct lnet_ni_status *addnis = NULL;
2973 lnet_nid_t *delnis = NULL;
2983 flags = LNET_PEER_DISCOVERED;
2984 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)
2985 flags |= LNET_PEER_MULTI_RAIL;
2988 * Cache the routing feature for the peer; whether it is enabled
2989 * for disabled as reported by the remote peer.
2991 spin_lock(&lp->lp_lock);
2992 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_RTE_DISABLED))
2993 lp->lp_state |= LNET_PEER_ROUTER_ENABLED;
2995 lp->lp_state &= ~LNET_PEER_ROUTER_ENABLED;
2996 spin_unlock(&lp->lp_lock);
2998 nnis = max_t(int, lp->lp_nnis, pbuf->pb_info.pi_nnis);
2999 CFS_ALLOC_PTR_ARRAY(curnis, nnis);
3000 CFS_ALLOC_PTR_ARRAY(addnis, nnis);
3001 CFS_ALLOC_PTR_ARRAY(delnis, nnis);
3002 if (!curnis || !addnis || !delnis) {
3010 /* Construct the list of NIDs present in peer. */
3012 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
3013 curnis[ncurnis++] = lnet_nid_to_nid4(&lpni->lpni_nid);
3016 * Check for NIDs in pbuf not present in curnis[].
3017 * The loop starts at 1 to skip the loopback NID.
3019 for (i = 1; i < pbuf->pb_info.pi_nnis; i++) {
3020 for (j = 0; j < ncurnis; j++)
3021 if (pbuf->pb_info.pi_ni[i].ns_nid == curnis[j])
3024 addnis[naddnis++] = pbuf->pb_info.pi_ni[i];
3027 * Check for NIDs in curnis[] not present in pbuf.
3028 * The nested loop starts at 1 to skip the loopback NID.
3030 * But never add the loopback NID to delnis[]: if it is
3031 * present in curnis[] then this peer is for this node.
3033 for (i = 0; i < ncurnis; i++) {
3034 if (curnis[i] == LNET_NID_LO_0)
3036 for (j = 1; j < pbuf->pb_info.pi_nnis; j++) {
3037 if (curnis[i] == pbuf->pb_info.pi_ni[j].ns_nid) {
3039 * update the information we cache for the
3040 * peer with the latest information we
3043 lpni = lnet_find_peer_ni_locked(curnis[i]);
3045 lpni->lpni_ns_status = pbuf->pb_info.pi_ni[j].ns_status;
3046 lnet_peer_ni_decref_locked(lpni);
3051 if (j == pbuf->pb_info.pi_nnis)
3052 delnis[ndelnis++] = curnis[i];
3056 * If we get here and the discovery is disabled then we don't want
3057 * to add or delete any NIs. We just updated the ones we have some
3058 * information on, and call it a day
3061 if (lnet_is_discovery_disabled(lp))
3064 for (i = 0; i < naddnis; i++) {
3065 rc = lnet_peer_add_nid(lp, addnis[i].ns_nid, flags);
3067 CERROR("Error adding NID %s to peer %s: %d\n",
3068 libcfs_nid2str(addnis[i].ns_nid),
3069 libcfs_nidstr(&lp->lp_primary_nid), rc);
3073 lpni = lnet_find_peer_ni_locked(addnis[i].ns_nid);
3075 lpni->lpni_ns_status = addnis[i].ns_status;
3076 lnet_peer_ni_decref_locked(lpni);
3080 for (i = 0; i < ndelnis; i++) {
3082 * for routers it's okay to delete the primary_nid because
3083 * the upper layers don't really rely on it. So if we're
3084 * being told that the router changed its primary_nid
3085 * then it's okay to delete it.
3087 if (lp->lp_rtr_refcount > 0)
3088 flags |= LNET_PEER_RTR_NI_FORCE_DEL;
3089 rc = lnet_peer_del_nid(lp, delnis[i], flags);
3091 CERROR("Error deleting NID %s from peer %s: %d\n",
3092 libcfs_nid2str(delnis[i]),
3093 libcfs_nidstr(&lp->lp_primary_nid), rc);
3099 /* The peer net for the primary NID should be the first entry in the
3100 * peer's lp_peer_nets list, and the peer NI for the primary NID should
3101 * be the first entry in its peer net's lpn_peer_nis list.
3103 lpni = lnet_find_peer_ni_locked(pbuf->pb_info.pi_ni[1].ns_nid);
3105 CERROR("Internal error: Failed to lookup peer NI for primary NID: %s\n",
3106 libcfs_nid2str(pbuf->pb_info.pi_ni[1].ns_nid));
3110 lnet_peer_ni_decref_locked(lpni);
3112 lpn = lpni->lpni_peer_net;
3113 if (lpn->lpn_peer_nets.prev != &lp->lp_peer_nets)
3114 list_move(&lpn->lpn_peer_nets, &lp->lp_peer_nets);
3116 if (lpni->lpni_peer_nis.prev != &lpni->lpni_peer_net->lpn_peer_nis)
3117 list_move(&lpni->lpni_peer_nis,
3118 &lpni->lpni_peer_net->lpn_peer_nis);
3121 * Errors other than -ENOMEM are due to peers having been
3122 * configured with DLC. Ignore these because DLC overrides
3127 CFS_FREE_PTR_ARRAY(curnis, nnis);
3128 CFS_FREE_PTR_ARRAY(addnis, nnis);
3129 CFS_FREE_PTR_ARRAY(delnis, nnis);
3130 lnet_ping_buffer_decref(pbuf);
3131 CDEBUG(D_NET, "peer %s (%p): %d\n",
3132 libcfs_nidstr(&lp->lp_primary_nid), lp, rc);
3135 spin_lock(&lp->lp_lock);
3136 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
3137 lp->lp_state |= LNET_PEER_FORCE_PING;
3138 spin_unlock(&lp->lp_lock);
3144 * The data in pbuf says lp is its primary peer, but the data was
3145 * received by a different peer. Try to update lp with the data.
3148 lnet_peer_set_primary_data(struct lnet_peer *lp, struct lnet_ping_buffer *pbuf)
3150 struct lnet_handle_md mdh;
3152 /* Queue lp for discovery, and force it on the request queue. */
3153 lnet_net_lock(LNET_LOCK_EX);
3154 if (lnet_peer_queue_for_discovery(lp))
3155 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_request);
3156 lnet_net_unlock(LNET_LOCK_EX);
3158 LNetInvalidateMDHandle(&mdh);
3161 * Decide whether we can move the peer to the DATA_PRESENT state.
3163 * We replace stale data for a multi-rail peer, repair PING_FAILED
3164 * status, and preempt FORCE_PING.
3166 * If after that we have DATA_PRESENT, we merge it into this peer.
3168 spin_lock(&lp->lp_lock);
3169 if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
3170 if (lp->lp_peer_seqno < LNET_PING_BUFFER_SEQNO(pbuf)) {
3171 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
3172 } else if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
3173 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
3174 lnet_ping_buffer_decref(pbuf);
3179 if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
3180 lnet_ping_buffer_decref(lp->lp_data);
3182 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
3184 if (lp->lp_state & LNET_PEER_PING_FAILED) {
3185 mdh = lp->lp_ping_mdh;
3186 LNetInvalidateMDHandle(&lp->lp_ping_mdh);
3187 lp->lp_state &= ~LNET_PEER_PING_FAILED;
3188 lp->lp_ping_error = 0;
3190 if (lp->lp_state & LNET_PEER_FORCE_PING)
3191 lp->lp_state &= ~LNET_PEER_FORCE_PING;
3192 lp->lp_state |= LNET_PEER_NIDS_UPTODATE;
3193 spin_unlock(&lp->lp_lock);
3195 if (!LNetMDHandleIsInvalid(mdh))
3199 return lnet_peer_merge_data(lp, pbuf);
3201 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3205 static bool lnet_is_nid_in_ping_info(lnet_nid_t nid, struct lnet_ping_info *pinfo)
3209 for (i = 0; i < pinfo->pi_nnis; i++) {
3210 if (pinfo->pi_ni[i].ns_nid == nid)
3217 /* Delete a peer that has been marked for deletion. NB: when this peer was added
3218 * to the discovery queue a reference was taken that will prevent the peer from
3219 * actually being freed by this function. After this function exits the
3220 * discovery thread should call lnet_peer_discovery_complete() which will
3221 * drop that reference as well as wake any waiters that may also be holding a
3224 static int lnet_peer_deletion(struct lnet_peer *lp)
3225 __must_hold(&lp->lp_lock)
3227 struct list_head rlist;
3228 struct lnet_route *route, *tmp;
3229 int sensitivity = lp->lp_health_sensitivity;
3232 INIT_LIST_HEAD(&rlist);
3234 lp->lp_state &= ~(LNET_PEER_DISCOVERING | LNET_PEER_FORCE_PING |
3235 LNET_PEER_FORCE_PUSH);
3236 CDEBUG(D_NET, "peer %s(%p) state %#x\n",
3237 libcfs_nidstr(&lp->lp_primary_nid), lp, lp->lp_state);
3239 /* no-op if lnet_peer_del() has already been called on this peer */
3240 if (lp->lp_state & LNET_PEER_MARK_DELETED)
3243 if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING)
3246 spin_unlock(&lp->lp_lock);
3248 mutex_lock(&the_lnet.ln_api_mutex);
3250 lnet_net_lock(LNET_LOCK_EX);
3251 /* remove the peer from the discovery work
3252 * queue if it's on there in preparation
3255 if (!list_empty(&lp->lp_dc_list))
3256 list_del_init(&lp->lp_dc_list);
3257 list_for_each_entry_safe(route, tmp,
3260 lnet_move_route(route, NULL, &rlist);
3261 lnet_net_unlock(LNET_LOCK_EX);
3263 /* lnet_peer_del() deletes all the peer NIs owned by this peer */
3264 rc = lnet_peer_del(lp);
3266 CNETERR("Internal error: Unable to delete peer %s rc %d\n",
3267 libcfs_nidstr(&lp->lp_primary_nid), rc);
3269 list_for_each_entry_safe(route, tmp,
3271 /* re-add these routes */
3272 lnet_add_route(route->lr_net,
3277 LIBCFS_FREE(route, sizeof(*route));
3280 mutex_unlock(&the_lnet.ln_api_mutex);
3282 spin_lock(&lp->lp_lock);
3288 * Update a peer using the data received.
3290 static int lnet_peer_data_present(struct lnet_peer *lp)
3291 __must_hold(&lp->lp_lock)
3293 struct lnet_ping_buffer *pbuf;
3294 struct lnet_peer_ni *lpni;
3295 lnet_nid_t nid = LNET_NID_ANY;
3301 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
3302 lp->lp_state |= LNET_PEER_NIDS_UPTODATE;
3303 spin_unlock(&lp->lp_lock);
3306 * Modifications of peer structures are done while holding the
3307 * ln_api_mutex. A global lock is required because we may be
3308 * modifying multiple peer structures, and a mutex greatly
3309 * simplifies memory management.
3311 * The actual changes to the data structures must also protect
3312 * against concurrent lookups, for which the lnet_net_lock in
3313 * LNET_LOCK_EX mode is used.
3315 mutex_lock(&the_lnet.ln_api_mutex);
3316 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3322 * If this peer is not on the peer list then it is being torn
3323 * down, and our reference count may be all that is keeping it
3324 * alive. Don't do any work on it.
3326 if (list_empty(&lp->lp_peer_list))
3329 flags = LNET_PEER_DISCOVERED;
3330 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)
3331 flags |= LNET_PEER_MULTI_RAIL;
3334 * Check whether the primary NID in the message matches the
3335 * primary NID of the peer. If it does, update the peer, if
3336 * it it does not, check whether there is already a peer with
3337 * that primary NID. If no such peer exists, try to update
3338 * the primary NID of the current peer (allowed if it was
3339 * created due to message traffic) and complete the update.
3340 * If the peer did exist, hand off the data to it.
3342 * The peer for the loopback interface is a special case: this
3343 * is the peer for the local node, and we want to set its
3344 * primary NID to the correct value here. Moreover, this peer
3345 * can show up with only the loopback NID in the ping buffer.
3347 if (pbuf->pb_info.pi_nnis <= 1)
3349 nid = pbuf->pb_info.pi_ni[1].ns_nid;
3350 if (nid_is_lo0(&lp->lp_primary_nid)) {
3351 rc = lnet_peer_set_primary_nid(lp, nid, flags);
3353 rc = lnet_peer_merge_data(lp, pbuf);
3355 * if the primary nid of the peer is present in the ping info returned
3356 * from the peer, but it's not the local primary peer we have
3357 * cached and discovery is disabled, then we don't want to update
3358 * our local peer info, by adding or removing NIDs, we just want
3359 * to update the status of the nids that we currently have
3360 * recorded in that peer.
3362 } else if (lnet_nid_to_nid4(&lp->lp_primary_nid) == nid ||
3363 (lnet_is_nid_in_ping_info(lnet_nid_to_nid4(&lp->lp_primary_nid),
3365 lnet_is_discovery_disabled(lp))) {
3366 rc = lnet_peer_merge_data(lp, pbuf);
3368 lpni = lnet_find_peer_ni_locked(nid);
3369 if (!lpni || lp == lpni->lpni_peer_net->lpn_peer) {
3370 rc = lnet_peer_set_primary_nid(lp, nid, flags);
3372 CERROR("Primary NID error %s versus %s: %d\n",
3373 libcfs_nidstr(&lp->lp_primary_nid),
3374 libcfs_nid2str(nid), rc);
3376 rc = lnet_peer_merge_data(lp, pbuf);
3379 lnet_peer_ni_decref_locked(lpni);
3381 struct lnet_peer *new_lp;
3382 new_lp = lpni->lpni_peer_net->lpn_peer;
3384 * if lp has discovery/MR enabled that means new_lp
3385 * should have discovery/MR enabled as well, since
3386 * it's the same peer, which we're about to merge
3388 spin_lock(&lp->lp_lock);
3389 spin_lock(&new_lp->lp_lock);
3390 if (!(lp->lp_state & LNET_PEER_NO_DISCOVERY))
3391 new_lp->lp_state &= ~LNET_PEER_NO_DISCOVERY;
3392 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
3393 new_lp->lp_state |= LNET_PEER_MULTI_RAIL;
3394 /* If we're processing a ping reply then we may be
3395 * about to send a push to the peer that we ping'd.
3396 * Since the ping reply that we're processing was
3397 * received by lp, we need to set the discovery source
3398 * NID for new_lp to the NID stored in lp.
3400 if (!LNET_NID_IS_ANY(&lp->lp_disc_src_nid)) {
3401 new_lp->lp_disc_src_nid = lp->lp_disc_src_nid;
3402 new_lp->lp_disc_dst_nid = lp->lp_disc_dst_nid;
3404 spin_unlock(&new_lp->lp_lock);
3405 spin_unlock(&lp->lp_lock);
3407 rc = lnet_peer_set_primary_data(new_lp, pbuf);
3408 lnet_consolidate_routes_locked(lp, new_lp);
3409 lnet_peer_ni_decref_locked(lpni);
3413 CDEBUG(D_NET, "peer %s(%p): %d. state = 0x%x\n",
3414 libcfs_nidstr(&lp->lp_primary_nid), lp, rc,
3416 mutex_unlock(&the_lnet.ln_api_mutex);
3418 spin_lock(&lp->lp_lock);
3419 /* Tell discovery to re-check the peer immediately. */
3421 rc = LNET_REDISCOVER_PEER;
3426 * A ping failed. Clear the PING_FAILED state and set the
3427 * FORCE_PING state, to ensure a retry even if discovery is
3428 * disabled. This avoids being left with incorrect state.
3430 static int lnet_peer_ping_failed(struct lnet_peer *lp)
3431 __must_hold(&lp->lp_lock)
3433 struct lnet_handle_md mdh;
3436 mdh = lp->lp_ping_mdh;
3437 LNetInvalidateMDHandle(&lp->lp_ping_mdh);
3438 lp->lp_state &= ~LNET_PEER_PING_FAILED;
3439 lp->lp_state |= LNET_PEER_FORCE_PING;
3440 rc = lp->lp_ping_error;
3441 lp->lp_ping_error = 0;
3442 spin_unlock(&lp->lp_lock);
3444 if (!LNetMDHandleIsInvalid(mdh))
3447 CDEBUG(D_NET, "peer %s:%d\n",
3448 libcfs_nidstr(&lp->lp_primary_nid), rc);
3450 spin_lock(&lp->lp_lock);
3451 return rc ? rc : LNET_REDISCOVER_PEER;
3454 /* Active side of ping. */
3455 static int lnet_peer_send_ping(struct lnet_peer *lp)
3456 __must_hold(&lp->lp_lock)
3462 lp->lp_state |= LNET_PEER_PING_SENT;
3463 lp->lp_state &= ~LNET_PEER_FORCE_PING;
3464 spin_unlock(&lp->lp_lock);
3466 cpt = lnet_net_lock_current();
3467 /* Refcount for MD. */
3468 lnet_peer_addref_locked(lp);
3469 lnet_net_unlock(cpt);
3471 nnis = max(lp->lp_data_nnis, LNET_INTERFACES_MIN);
3473 rc = lnet_send_ping(lnet_nid_to_nid4(&lp->lp_primary_nid),
3474 &lp->lp_ping_mdh, nnis, lp,
3475 the_lnet.ln_dc_handler, false);
3478 * if LNetMDBind in lnet_send_ping fails we need to decrement the
3479 * refcount on the peer, otherwise LNetMDUnlink will be called
3480 * which will eventually do that.
3484 lnet_peer_decref_locked(lp);
3485 lnet_net_unlock(cpt);
3486 rc = -rc; /* change the rc to negative value */
3488 } else if (rc < 0) {
3492 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3494 spin_lock(&lp->lp_lock);
3498 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nidstr(&lp->lp_primary_nid), rc);
3500 * The errors that get us here are considered hard errors and
3501 * cause Discovery to terminate. So we clear PING_SENT, but do
3502 * not set either PING_FAILED or FORCE_PING. In fact we need
3503 * to clear PING_FAILED, because the unlink event handler will
3504 * have set it if we called LNetMDUnlink() above.
3506 spin_lock(&lp->lp_lock);
3507 lp->lp_state &= ~(LNET_PEER_PING_SENT | LNET_PEER_PING_FAILED);
3512 * This function exists because you cannot call LNetMDUnlink() from an
3515 static int lnet_peer_push_failed(struct lnet_peer *lp)
3516 __must_hold(&lp->lp_lock)
3518 struct lnet_handle_md mdh;
3521 mdh = lp->lp_push_mdh;
3522 LNetInvalidateMDHandle(&lp->lp_push_mdh);
3523 lp->lp_state &= ~LNET_PEER_PUSH_FAILED;
3524 rc = lp->lp_push_error;
3525 lp->lp_push_error = 0;
3526 spin_unlock(&lp->lp_lock);
3528 if (!LNetMDHandleIsInvalid(mdh))
3531 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3532 spin_lock(&lp->lp_lock);
3533 return rc ? rc : LNET_REDISCOVER_PEER;
3537 * Mark the peer as discovered.
3539 static int lnet_peer_discovered(struct lnet_peer *lp)
3540 __must_hold(&lp->lp_lock)
3542 lp->lp_state |= LNET_PEER_DISCOVERED;
3543 lp->lp_state &= ~(LNET_PEER_DISCOVERING |
3544 LNET_PEER_REDISCOVER);
3546 lp->lp_dc_error = 0;
3548 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3553 /* Active side of push. */
3554 static int lnet_peer_send_push(struct lnet_peer *lp)
3555 __must_hold(&lp->lp_lock)
3557 struct lnet_ping_buffer *pbuf;
3558 struct lnet_process_id id;
3563 /* Don't push to a non-multi-rail peer. */
3564 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
3565 lp->lp_state &= ~LNET_PEER_FORCE_PUSH;
3566 /* if peer's NIDs are uptodate then peer is discovered */
3567 if (lp->lp_state & LNET_PEER_NIDS_UPTODATE) {
3568 rc = lnet_peer_discovered(lp);
3575 lp->lp_state |= LNET_PEER_PUSH_SENT;
3576 lp->lp_state &= ~LNET_PEER_FORCE_PUSH;
3577 spin_unlock(&lp->lp_lock);
3579 cpt = lnet_net_lock_current();
3580 pbuf = the_lnet.ln_ping_target;
3581 lnet_ping_buffer_addref(pbuf);
3582 lnet_net_unlock(cpt);
3584 /* Push source MD */
3585 md.start = &pbuf->pb_info;
3586 md.length = LNET_PING_INFO_SIZE(pbuf->pb_nnis);
3587 md.threshold = 2; /* Put/Ack */
3589 md.options = LNET_MD_TRACK_RESPONSE;
3590 md.handler = the_lnet.ln_dc_handler;
3593 rc = LNetMDBind(&md, LNET_UNLINK, &lp->lp_push_mdh);
3595 lnet_ping_buffer_decref(pbuf);
3596 CERROR("Can't bind push source MD: %d\n", rc);
3600 cpt = lnet_net_lock_current();
3601 /* Refcount for MD. */
3602 lnet_peer_addref_locked(lp);
3603 id.pid = LNET_PID_LUSTRE;
3604 if (!LNET_NID_IS_ANY(&lp->lp_disc_dst_nid))
3605 id.nid = lnet_nid_to_nid4(&lp->lp_disc_dst_nid);
3607 id.nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
3608 lnet_net_unlock(cpt);
3610 rc = LNetPut(lnet_nid_to_nid4(&lp->lp_disc_src_nid), lp->lp_push_mdh,
3611 LNET_ACK_REQ, id, LNET_RESERVED_PORTAL,
3612 LNET_PROTO_PING_MATCHBITS, 0, 0);
3615 * reset the discovery nid. There is no need to restrict sending
3616 * from that source, if we call lnet_push_update_to_peers(). It'll
3617 * get set to a specific NID, if we initiate discovery from the
3620 lp->lp_disc_src_nid = LNET_ANY_NID;
3621 lp->lp_disc_dst_nid = LNET_ANY_NID;
3626 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3628 spin_lock(&lp->lp_lock);
3632 LNetMDUnlink(lp->lp_push_mdh);
3633 LNetInvalidateMDHandle(&lp->lp_push_mdh);
3635 CDEBUG(D_NET, "peer %s(%p): %d\n", libcfs_nidstr(&lp->lp_primary_nid),
3638 * The errors that get us here are considered hard errors and
3639 * cause Discovery to terminate. So we clear PUSH_SENT, but do
3640 * not set PUSH_FAILED. In fact we need to clear PUSH_FAILED,
3641 * because the unlink event handler will have set it if we
3642 * called LNetMDUnlink() above.
3644 spin_lock(&lp->lp_lock);
3645 lp->lp_state &= ~(LNET_PEER_PUSH_SENT | LNET_PEER_PUSH_FAILED);
3650 * An unrecoverable error was encountered during discovery.
3651 * Set error status in peer and abort discovery.
3653 static void lnet_peer_discovery_error(struct lnet_peer *lp, int error)
3655 CDEBUG(D_NET, "Discovery error %s: %d\n",
3656 libcfs_nidstr(&lp->lp_primary_nid), error);
3658 spin_lock(&lp->lp_lock);
3659 lp->lp_dc_error = error;
3660 lp->lp_state &= ~LNET_PEER_DISCOVERING;
3661 lp->lp_state |= LNET_PEER_REDISCOVER;
3662 spin_unlock(&lp->lp_lock);
3666 * Wait for work to be queued or some other change that must be
3667 * attended to. Returns non-zero if the discovery thread should shut
3670 static int lnet_peer_discovery_wait_for_work(void)
3677 cpt = lnet_net_lock_current();
3679 prepare_to_wait(&the_lnet.ln_dc_waitq, &wait,
3680 TASK_INTERRUPTIBLE);
3681 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3683 if (lnet_push_target_resize_needed() ||
3684 the_lnet.ln_push_target->pb_needs_post)
3686 if (!list_empty(&the_lnet.ln_dc_request))
3688 if (!list_empty(&the_lnet.ln_msg_resend))
3690 lnet_net_unlock(cpt);
3693 * wakeup max every second to check if there are peers that
3694 * have been stuck on the working queue for greater than
3697 schedule_timeout(cfs_time_seconds(1));
3698 finish_wait(&the_lnet.ln_dc_waitq, &wait);
3699 cpt = lnet_net_lock_current();
3701 finish_wait(&the_lnet.ln_dc_waitq, &wait);
3703 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3706 lnet_net_unlock(cpt);
3708 CDEBUG(D_NET, "woken: %d\n", rc);
3714 * Messages that were pending on a destroyed peer will be put on a global
3715 * resend list. The message resend list will be checked by
3716 * the discovery thread when it wakes up, and will resend messages. These
3717 * messages can still be sendable in the case the lpni which was the initial
3718 * cause of the message re-queue was transfered to another peer.
3720 * It is possible that LNet could be shutdown while we're iterating
3721 * through the list. lnet_shudown_lndnets() will attempt to access the
3722 * resend list, but will have to wait until the spinlock is released, by
3723 * which time there shouldn't be any more messages on the resend list.
3724 * During shutdown lnet_send() will fail and lnet_finalize() will be called
3725 * for the messages so they can be released. The other case is that
3726 * lnet_shudown_lndnets() can finalize all the messages before this
3727 * function can visit the resend list, in which case this function will be
3730 static void lnet_resend_msgs(void)
3732 struct lnet_msg *msg, *tmp;
3736 spin_lock(&the_lnet.ln_msg_resend_lock);
3737 list_splice(&the_lnet.ln_msg_resend, &resend);
3738 spin_unlock(&the_lnet.ln_msg_resend_lock);
3740 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
3741 list_del_init(&msg->msg_list);
3742 rc = lnet_send(msg->msg_src_nid_param, msg,
3743 msg->msg_rtr_nid_param);
3745 CNETERR("Error sending %s to %s: %d\n",
3746 lnet_msgtyp2str(msg->msg_type),
3747 libcfs_id2str(msg->msg_target), rc);
3748 lnet_finalize(msg, rc);
3753 /* The discovery thread. */
3754 static int lnet_peer_discovery(void *arg)
3756 struct lnet_peer *lp;
3759 wait_for_completion(&the_lnet.ln_started);
3761 CDEBUG(D_NET, "started\n");
3764 if (lnet_peer_discovery_wait_for_work())
3767 if (lnet_push_target_resize_needed())
3768 lnet_push_target_resize();
3769 else if (the_lnet.ln_push_target->pb_needs_post)
3770 lnet_push_target_post(the_lnet.ln_push_target,
3771 &the_lnet.ln_push_target_md);
3775 lnet_net_lock(LNET_LOCK_EX);
3776 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING) {
3777 lnet_net_unlock(LNET_LOCK_EX);
3782 * Process all incoming discovery work requests. When
3783 * discovery must wait on a peer to change state, it
3784 * is added to the tail of the ln_dc_working queue. A
3785 * timestamp keeps track of when the peer was added,
3786 * so we can time out discovery requests that take too
3789 while (!list_empty(&the_lnet.ln_dc_request)) {
3790 lp = list_first_entry(&the_lnet.ln_dc_request,
3791 struct lnet_peer, lp_dc_list);
3792 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_working);
3794 * set the time the peer was put on the dc_working
3795 * queue. It shouldn't remain on the queue
3796 * forever, in case the GET message (for ping)
3797 * doesn't get a REPLY or the PUT message (for
3798 * push) doesn't get an ACK.
3800 lp->lp_last_queued = ktime_get_real_seconds();
3801 lnet_net_unlock(LNET_LOCK_EX);
3803 if (lnet_push_target_resize_needed())
3804 lnet_push_target_resize();
3805 else if (the_lnet.ln_push_target->pb_needs_post)
3806 lnet_push_target_post(the_lnet.ln_push_target,
3807 &the_lnet.ln_push_target_md);
3810 * Select an action depending on the state of
3811 * the peer and whether discovery is disabled.
3812 * The check whether discovery is disabled is
3813 * done after the code that handles processing
3814 * for arrived data, cleanup for failures, and
3815 * forcing a Ping or Push.
3817 spin_lock(&lp->lp_lock);
3818 CDEBUG(D_NET, "peer %s(%p) state %#x\n",
3819 libcfs_nidstr(&lp->lp_primary_nid), lp,
3821 if (lp->lp_state & (LNET_PEER_MARK_DELETION |
3822 LNET_PEER_MARK_DELETED))
3823 rc = lnet_peer_deletion(lp);
3824 else if (lp->lp_state & LNET_PEER_DATA_PRESENT)
3825 rc = lnet_peer_data_present(lp);
3826 else if (lp->lp_state & LNET_PEER_PING_FAILED)
3827 rc = lnet_peer_ping_failed(lp);
3828 else if (lp->lp_state & LNET_PEER_PUSH_FAILED)
3829 rc = lnet_peer_push_failed(lp);
3830 else if (lp->lp_state & LNET_PEER_FORCE_PING)
3831 rc = lnet_peer_send_ping(lp);
3832 else if (lp->lp_state & LNET_PEER_FORCE_PUSH)
3833 rc = lnet_peer_send_push(lp);
3834 else if (!(lp->lp_state & LNET_PEER_NIDS_UPTODATE))
3835 rc = lnet_peer_send_ping(lp);
3836 else if (lnet_peer_needs_push(lp))
3837 rc = lnet_peer_send_push(lp);
3839 rc = lnet_peer_discovered(lp);
3840 CDEBUG(D_NET, "peer %s(%p) state %#x rc %d\n",
3841 libcfs_nidstr(&lp->lp_primary_nid), lp,
3843 spin_unlock(&lp->lp_lock);
3845 lnet_net_lock(LNET_LOCK_EX);
3846 if (rc == LNET_REDISCOVER_PEER) {
3847 list_move(&lp->lp_dc_list,
3848 &the_lnet.ln_dc_request);
3850 lnet_peer_discovery_error(lp, rc);
3852 if (!(lp->lp_state & LNET_PEER_DISCOVERING))
3853 lnet_peer_discovery_complete(lp);
3854 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3859 lnet_net_unlock(LNET_LOCK_EX);
3862 CDEBUG(D_NET, "stopping\n");
3864 * Clean up before telling lnet_peer_discovery_stop() that
3865 * we're done. Use wake_up() below to somewhat reduce the
3866 * size of the thundering herd if there are multiple threads
3867 * waiting on discovery of a single peer.
3870 /* Queue cleanup 1: stop all pending pings and pushes. */
3871 lnet_net_lock(LNET_LOCK_EX);
3872 while (!list_empty(&the_lnet.ln_dc_working)) {
3873 lp = list_first_entry(&the_lnet.ln_dc_working,
3874 struct lnet_peer, lp_dc_list);
3875 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_expired);
3876 lnet_net_unlock(LNET_LOCK_EX);
3877 lnet_peer_cancel_discovery(lp);
3878 lnet_net_lock(LNET_LOCK_EX);
3880 lnet_net_unlock(LNET_LOCK_EX);
3882 /* Queue cleanup 2: wait for the expired queue to clear. */
3883 while (!list_empty(&the_lnet.ln_dc_expired))
3884 schedule_timeout_uninterruptible(cfs_time_seconds(1));
3886 /* Queue cleanup 3: clear the request queue. */
3887 lnet_net_lock(LNET_LOCK_EX);
3888 while (!list_empty(&the_lnet.ln_dc_request)) {
3889 lp = list_first_entry(&the_lnet.ln_dc_request,
3890 struct lnet_peer, lp_dc_list);
3891 lnet_peer_discovery_error(lp, -ESHUTDOWN);
3892 lnet_peer_discovery_complete(lp);
3894 lnet_net_unlock(LNET_LOCK_EX);
3896 lnet_assert_handler_unused(the_lnet.ln_dc_handler);
3897 the_lnet.ln_dc_handler = NULL;
3899 the_lnet.ln_dc_state = LNET_DC_STATE_SHUTDOWN;
3900 wake_up(&the_lnet.ln_dc_waitq);
3902 CDEBUG(D_NET, "stopped\n");
3907 /* ln_api_mutex is held on entry. */
3908 int lnet_peer_discovery_start(void)
3910 struct task_struct *task;
3913 if (the_lnet.ln_dc_state != LNET_DC_STATE_SHUTDOWN)
3916 the_lnet.ln_dc_handler = lnet_discovery_event_handler;
3917 the_lnet.ln_dc_state = LNET_DC_STATE_RUNNING;
3918 task = kthread_run(lnet_peer_discovery, NULL, "lnet_discovery");
3921 CERROR("Can't start peer discovery thread: %d\n", rc);
3923 the_lnet.ln_dc_handler = NULL;
3925 the_lnet.ln_dc_state = LNET_DC_STATE_SHUTDOWN;
3928 CDEBUG(D_NET, "discovery start: %d\n", rc);
3933 /* ln_api_mutex is held on entry. */
3934 void lnet_peer_discovery_stop(void)
3936 if (the_lnet.ln_dc_state == LNET_DC_STATE_SHUTDOWN)
3939 LASSERT(the_lnet.ln_dc_state == LNET_DC_STATE_RUNNING);
3940 the_lnet.ln_dc_state = LNET_DC_STATE_STOPPING;
3942 /* In the LNetNIInit() path we may be stopping discovery before it
3943 * entered its work loop
3945 if (!completion_done(&the_lnet.ln_started))
3946 complete(&the_lnet.ln_started);
3948 wake_up(&the_lnet.ln_dc_waitq);
3950 wait_event(the_lnet.ln_dc_waitq,
3951 the_lnet.ln_dc_state == LNET_DC_STATE_SHUTDOWN);
3953 LASSERT(list_empty(&the_lnet.ln_dc_request));
3954 LASSERT(list_empty(&the_lnet.ln_dc_working));
3955 LASSERT(list_empty(&the_lnet.ln_dc_expired));
3957 CDEBUG(D_NET, "discovery stopped\n");
3963 lnet_debug_peer(lnet_nid_t nid)
3965 char *aliveness = "NA";
3966 struct lnet_peer_ni *lp;
3969 cpt = lnet_cpt_of_nid(nid, NULL);
3972 lp = lnet_nid2peerni_locked(nid, LNET_NID_ANY, cpt);
3974 lnet_net_unlock(cpt);
3975 CDEBUG(D_WARNING, "No peer %s\n", libcfs_nid2str(nid));
3979 if (lnet_isrouter(lp) || lnet_peer_aliveness_enabled(lp))
3980 aliveness = (lnet_is_peer_ni_alive(lp)) ? "up" : "down";
3982 CDEBUG(D_WARNING, "%-24s %4d %5s %5d %5d %5d %5d %5d %ld\n",
3983 libcfs_nidstr(&lp->lpni_nid), kref_read(&lp->lpni_kref),
3984 aliveness, lp->lpni_net->net_tunables.lct_peer_tx_credits,
3985 lp->lpni_rtrcredits, lp->lpni_minrtrcredits,
3986 lp->lpni_txcredits, lp->lpni_mintxcredits, lp->lpni_txqnob);
3988 lnet_peer_ni_decref_locked(lp);
3990 lnet_net_unlock(cpt);
3993 /* Gathering information for userspace. */
3995 int lnet_get_peer_ni_info(__u32 peer_index, __u64 *nid,
3996 char aliveness[LNET_MAX_STR_LEN],
3997 __u32 *cpt_iter, __u32 *refcount,
3998 __u32 *ni_peer_tx_credits, __u32 *peer_tx_credits,
3999 __u32 *peer_rtr_credits, __u32 *peer_min_rtr_credits,
4000 __u32 *peer_tx_qnob)
4002 struct lnet_peer_table *peer_table;
4003 struct lnet_peer_ni *lp;
4008 /* get the number of CPTs */
4009 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
4011 /* if the cpt number to be examined is >= the number of cpts in
4012 * the system then indicate that there are no more cpts to examin
4014 if (*cpt_iter >= lncpt)
4017 /* get the current table */
4018 peer_table = the_lnet.ln_peer_tables[*cpt_iter];
4019 /* if the ptable is NULL then there are no more cpts to examine */
4020 if (peer_table == NULL)
4023 lnet_net_lock(*cpt_iter);
4025 for (j = 0; j < LNET_PEER_HASH_SIZE && !found; j++) {
4026 struct list_head *peers = &peer_table->pt_hash[j];
4028 list_for_each_entry(lp, peers, lpni_hashlist) {
4029 if (!nid_is_nid4(&lp->lpni_nid))
4031 if (peer_index-- > 0)
4034 snprintf(aliveness, LNET_MAX_STR_LEN, "NA");
4035 if (lnet_isrouter(lp) ||
4036 lnet_peer_aliveness_enabled(lp))
4037 snprintf(aliveness, LNET_MAX_STR_LEN,
4038 lnet_is_peer_ni_alive(lp) ? "up" : "down");
4040 *nid = lnet_nid_to_nid4(&lp->lpni_nid);
4041 *refcount = kref_read(&lp->lpni_kref);
4042 *ni_peer_tx_credits =
4043 lp->lpni_net->net_tunables.lct_peer_tx_credits;
4044 *peer_tx_credits = lp->lpni_txcredits;
4045 *peer_rtr_credits = lp->lpni_rtrcredits;
4046 *peer_min_rtr_credits = lp->lpni_mintxcredits;
4047 *peer_tx_qnob = lp->lpni_txqnob;
4053 lnet_net_unlock(*cpt_iter);
4057 return found ? 0 : -ENOENT;
4060 /* ln_api_mutex is held, which keeps the peer list stable */
4061 int lnet_get_peer_info(struct lnet_ioctl_peer_cfg *cfg, void __user *bulk)
4063 struct lnet_ioctl_element_stats *lpni_stats;
4064 struct lnet_ioctl_element_msg_stats *lpni_msg_stats;
4065 struct lnet_ioctl_peer_ni_hstats *lpni_hstats;
4066 struct lnet_peer_ni_credit_info *lpni_info;
4067 struct lnet_peer_ni *lpni;
4068 struct lnet_peer *lp;
4073 lp = lnet_find_peer(cfg->prcfg_prim_nid);
4080 size = sizeof(nid) + sizeof(*lpni_info) + sizeof(*lpni_stats)
4081 + sizeof(*lpni_msg_stats) + sizeof(*lpni_hstats);
4082 size *= lp->lp_nnis;
4083 if (size > cfg->prcfg_size) {
4084 cfg->prcfg_size = size;
4089 cfg->prcfg_prim_nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
4090 cfg->prcfg_mr = lnet_peer_is_multi_rail(lp);
4091 cfg->prcfg_cfg_nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
4092 cfg->prcfg_count = lp->lp_nnis;
4093 cfg->prcfg_size = size;
4094 cfg->prcfg_state = lp->lp_state;
4096 /* Allocate helper buffers. */
4098 LIBCFS_ALLOC(lpni_info, sizeof(*lpni_info));
4101 LIBCFS_ALLOC(lpni_stats, sizeof(*lpni_stats));
4104 LIBCFS_ALLOC(lpni_msg_stats, sizeof(*lpni_msg_stats));
4105 if (!lpni_msg_stats)
4106 goto out_free_stats;
4107 LIBCFS_ALLOC(lpni_hstats, sizeof(*lpni_hstats));
4109 goto out_free_msg_stats;
4114 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL) {
4115 if (!nid_is_nid4(&lpni->lpni_nid))
4117 nid = lnet_nid_to_nid4(&lpni->lpni_nid);
4118 if (copy_to_user(bulk, &nid, sizeof(nid)))
4119 goto out_free_hstats;
4120 bulk += sizeof(nid);
4122 memset(lpni_info, 0, sizeof(*lpni_info));
4123 snprintf(lpni_info->cr_aliveness, LNET_MAX_STR_LEN, "NA");
4124 if (lnet_isrouter(lpni) ||
4125 lnet_peer_aliveness_enabled(lpni))
4126 snprintf(lpni_info->cr_aliveness, LNET_MAX_STR_LEN,
4127 lnet_is_peer_ni_alive(lpni) ? "up" : "down");
4129 lpni_info->cr_refcount = kref_read(&lpni->lpni_kref);
4130 lpni_info->cr_ni_peer_tx_credits = (lpni->lpni_net != NULL) ?
4131 lpni->lpni_net->net_tunables.lct_peer_tx_credits : 0;
4132 lpni_info->cr_peer_tx_credits = lpni->lpni_txcredits;
4133 lpni_info->cr_peer_rtr_credits = lpni->lpni_rtrcredits;
4134 lpni_info->cr_peer_min_rtr_credits = lpni->lpni_minrtrcredits;
4135 lpni_info->cr_peer_min_tx_credits = lpni->lpni_mintxcredits;
4136 lpni_info->cr_peer_tx_qnob = lpni->lpni_txqnob;
4137 if (copy_to_user(bulk, lpni_info, sizeof(*lpni_info)))
4138 goto out_free_hstats;
4139 bulk += sizeof(*lpni_info);
4141 memset(lpni_stats, 0, sizeof(*lpni_stats));
4142 lpni_stats->iel_send_count = lnet_sum_stats(&lpni->lpni_stats,
4143 LNET_STATS_TYPE_SEND);
4144 lpni_stats->iel_recv_count = lnet_sum_stats(&lpni->lpni_stats,
4145 LNET_STATS_TYPE_RECV);
4146 lpni_stats->iel_drop_count = lnet_sum_stats(&lpni->lpni_stats,
4147 LNET_STATS_TYPE_DROP);
4148 if (copy_to_user(bulk, lpni_stats, sizeof(*lpni_stats)))
4149 goto out_free_hstats;
4150 bulk += sizeof(*lpni_stats);
4151 lnet_usr_translate_stats(lpni_msg_stats, &lpni->lpni_stats);
4152 if (copy_to_user(bulk, lpni_msg_stats, sizeof(*lpni_msg_stats)))
4153 goto out_free_hstats;
4154 bulk += sizeof(*lpni_msg_stats);
4155 lpni_hstats->hlpni_network_timeout =
4156 atomic_read(&lpni->lpni_hstats.hlt_network_timeout);
4157 lpni_hstats->hlpni_remote_dropped =
4158 atomic_read(&lpni->lpni_hstats.hlt_remote_dropped);
4159 lpni_hstats->hlpni_remote_timeout =
4160 atomic_read(&lpni->lpni_hstats.hlt_remote_timeout);
4161 lpni_hstats->hlpni_remote_error =
4162 atomic_read(&lpni->lpni_hstats.hlt_remote_error);
4163 lpni_hstats->hlpni_health_value =
4164 atomic_read(&lpni->lpni_healthv);
4165 lpni_hstats->hlpni_ping_count = lpni->lpni_ping_count;
4166 lpni_hstats->hlpni_next_ping = lpni->lpni_next_ping;
4167 if (copy_to_user(bulk, lpni_hstats, sizeof(*lpni_hstats)))
4168 goto out_free_hstats;
4169 bulk += sizeof(*lpni_hstats);
4174 LIBCFS_FREE(lpni_hstats, sizeof(*lpni_hstats));
4176 LIBCFS_FREE(lpni_msg_stats, sizeof(*lpni_msg_stats));
4178 LIBCFS_FREE(lpni_stats, sizeof(*lpni_stats));
4180 LIBCFS_FREE(lpni_info, sizeof(*lpni_info));
4182 lnet_peer_decref_locked(lp);
4187 /* must hold net_lock/0 */
4189 lnet_peer_ni_add_to_recoveryq_locked(struct lnet_peer_ni *lpni,
4190 struct list_head *recovery_queue,
4193 /* the mt could've shutdown and cleaned up the queues */
4194 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING)
4197 if (!list_empty(&lpni->lpni_recovery))
4200 if (atomic_read(&lpni->lpni_healthv) == LNET_MAX_HEALTH_VALUE)
4203 if (!lpni->lpni_last_alive) {
4205 "lpni %s(%p) not eligible for recovery last alive %lld\n",
4206 libcfs_nidstr(&lpni->lpni_nid), lpni,
4207 lpni->lpni_last_alive);
4211 if (lnet_recovery_limit &&
4212 now > lpni->lpni_last_alive + lnet_recovery_limit) {
4213 CDEBUG(D_NET, "lpni %s aged out last alive %lld\n",
4214 libcfs_nidstr(&lpni->lpni_nid),
4215 lpni->lpni_last_alive);
4216 /* Reset the ping count so that if this peer NI is added back to
4217 * the recovery queue we will send the first ping right away.
4219 lpni->lpni_ping_count = 0;
4223 /* This peer NI is going on the recovery queue, so take a ref on it */
4224 lnet_peer_ni_addref_locked(lpni);
4226 lnet_peer_ni_set_next_ping(lpni, now);
4228 CDEBUG(D_NET, "%s added to recovery queue. ping count: %u next ping: %lld last alive: %lld health: %d\n",
4229 libcfs_nidstr(&lpni->lpni_nid),
4230 lpni->lpni_ping_count,
4231 lpni->lpni_next_ping,
4232 lpni->lpni_last_alive,
4233 atomic_read(&lpni->lpni_healthv));
4235 list_add_tail(&lpni->lpni_recovery, recovery_queue);
4238 /* Call with the ln_api_mutex held */
4240 lnet_peer_ni_set_healthv(lnet_nid_t nid, int value, bool all)
4242 struct lnet_peer_table *ptable;
4243 struct lnet_peer *lp;
4244 struct lnet_peer_net *lpn;
4245 struct lnet_peer_ni *lpni;
4250 if (the_lnet.ln_state != LNET_STATE_RUNNING)
4253 now = ktime_get_seconds();
4256 lnet_net_lock(LNET_LOCK_EX);
4257 lpni = lnet_find_peer_ni_locked(nid);
4259 lnet_net_unlock(LNET_LOCK_EX);
4262 lnet_set_lpni_healthv_locked(lpni, value);
4263 lnet_peer_ni_add_to_recoveryq_locked(lpni,
4264 &the_lnet.ln_mt_peerNIRecovq, now);
4265 lnet_peer_ni_decref_locked(lpni);
4266 lnet_net_unlock(LNET_LOCK_EX);
4270 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
4273 * Walk all the peers and reset the health value for each one to the
4276 lnet_net_lock(LNET_LOCK_EX);
4277 for (cpt = 0; cpt < lncpt; cpt++) {
4278 ptable = the_lnet.ln_peer_tables[cpt];
4279 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
4280 list_for_each_entry(lpn, &lp->lp_peer_nets, lpn_peer_nets) {
4281 list_for_each_entry(lpni, &lpn->lpn_peer_nis,
4283 lnet_set_lpni_healthv_locked(lpni,
4285 lnet_peer_ni_add_to_recoveryq_locked(lpni,
4286 &the_lnet.ln_mt_peerNIRecovq, now);
4291 lnet_net_unlock(LNET_LOCK_EX);