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 /* If we're asked to lock down the primary NID we shouldn't be
551 if (lp->lp_state & LNET_PEER_LOCK_PRIMARY &&
552 nid_same(&primary_nid, &nid)) {
557 lpni = lnet_peer_ni_find_locked(&nid);
562 lnet_peer_ni_decref_locked(lpni);
563 if (lp != lpni->lpni_peer_net->lpn_peer) {
569 * This function only allows deletion of the primary NID if it
572 if (nid_same(&nid, &lp->lp_primary_nid) && lp->lp_nnis != 1 && !force) {
577 lnet_net_lock(LNET_LOCK_EX);
579 if (nid_same(&nid, &lp->lp_primary_nid) && lp->lp_nnis != 1 && force) {
580 struct lnet_peer_ni *lpni2;
581 /* assign the next peer_ni to be the primary */
582 lpni2 = lnet_get_next_peer_ni_locked(lp, NULL, lpni);
584 lp->lp_primary_nid = lpni2->lpni_nid;
586 rc = lnet_peer_ni_del_locked(lpni, force);
588 lnet_net_unlock(LNET_LOCK_EX);
591 CDEBUG(D_NET, "peer %s NID %s flags %#x: %d\n",
592 libcfs_nidstr(&primary_nid), libcfs_nidstr(&nid),
599 lnet_peer_table_cleanup_locked(struct lnet_net *net,
600 struct lnet_peer_table *ptable)
603 struct lnet_peer_ni *next;
604 struct lnet_peer_ni *lpni;
605 struct lnet_peer *peer;
607 for (i = 0; i < LNET_PEER_HASH_SIZE; i++) {
608 list_for_each_entry_safe(lpni, next, &ptable->pt_hash[i],
610 if (net != NULL && net != lpni->lpni_net)
613 peer = lpni->lpni_peer_net->lpn_peer;
614 if (!nid_same(&peer->lp_primary_nid,
616 lnet_peer_ni_del_locked(lpni, false);
620 * Removing the primary NID implies removing
621 * the entire peer. Advance next beyond any
622 * peer_ni that belongs to the same peer.
624 list_for_each_entry_from(next, &ptable->pt_hash[i],
626 if (next->lpni_peer_net->lpn_peer != peer)
629 lnet_peer_del_locked(peer);
635 lnet_peer_ni_finalize_wait(struct lnet_peer_table *ptable)
637 wait_var_event_warning(&ptable->pt_zombies,
638 ptable->pt_zombies == 0,
639 "Waiting for %d zombies on peer table\n",
644 lnet_peer_table_del_rtrs_locked(struct lnet_net *net,
645 struct lnet_peer_table *ptable)
647 struct lnet_peer_ni *lp;
648 struct lnet_peer_ni *tmp;
652 for (i = 0; i < LNET_PEER_HASH_SIZE; i++) {
653 list_for_each_entry_safe(lp, tmp, &ptable->pt_hash[i],
655 if (net != lp->lpni_net)
658 if (!lnet_isrouter(lp))
661 /* FIXME handle large-addr nid */
662 gw_nid = lnet_nid_to_nid4(
663 &lp->lpni_peer_net->lpn_peer->lp_primary_nid);
665 lnet_net_unlock(LNET_LOCK_EX);
666 lnet_del_route(LNET_NET_ANY, gw_nid);
667 lnet_net_lock(LNET_LOCK_EX);
673 lnet_peer_tables_cleanup(struct lnet_net *net)
676 struct lnet_peer_table *ptable;
678 LASSERT(the_lnet.ln_state != LNET_STATE_SHUTDOWN || net != NULL);
679 /* If just deleting the peers for a NI, get rid of any routes these
680 * peers are gateways for. */
681 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
682 lnet_net_lock(LNET_LOCK_EX);
683 lnet_peer_table_del_rtrs_locked(net, ptable);
684 lnet_net_unlock(LNET_LOCK_EX);
687 /* Start the cleanup process */
688 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
689 lnet_net_lock(LNET_LOCK_EX);
690 lnet_peer_table_cleanup_locked(net, ptable);
691 lnet_net_unlock(LNET_LOCK_EX);
694 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables)
695 lnet_peer_ni_finalize_wait(ptable);
698 static struct lnet_peer_ni *
699 lnet_get_peer_ni_locked(struct lnet_peer_table *ptable, struct lnet_nid *nid)
701 struct list_head *peers;
702 struct lnet_peer_ni *lp;
704 if (the_lnet.ln_state != LNET_STATE_RUNNING)
707 peers = &ptable->pt_hash[lnet_nid2peerhash(nid)];
708 list_for_each_entry(lp, peers, lpni_hashlist) {
709 if (nid_same(&lp->lpni_nid, nid)) {
710 lnet_peer_ni_addref_locked(lp);
718 struct lnet_peer_ni *
719 lnet_find_peer_ni_locked(lnet_nid_t nid4)
721 struct lnet_peer_ni *lpni;
722 struct lnet_peer_table *ptable;
726 lnet_nid4_to_nid(nid4, &nid);
728 cpt = lnet_nid_cpt_hash(&nid, LNET_CPT_NUMBER);
730 ptable = the_lnet.ln_peer_tables[cpt];
731 lpni = lnet_get_peer_ni_locked(ptable, &nid);
736 struct lnet_peer_ni *
737 lnet_peer_ni_find_locked(struct lnet_nid *nid)
739 struct lnet_peer_ni *lpni;
740 struct lnet_peer_table *ptable;
743 cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
745 ptable = the_lnet.ln_peer_tables[cpt];
746 lpni = lnet_get_peer_ni_locked(ptable, nid);
751 struct lnet_peer_ni *
752 lnet_peer_get_ni_locked(struct lnet_peer *lp, lnet_nid_t nid)
754 struct lnet_peer_net *lpn;
755 struct lnet_peer_ni *lpni;
757 lpn = lnet_peer_get_net_locked(lp, LNET_NIDNET(nid));
761 list_for_each_entry(lpni, &lpn->lpn_peer_nis, lpni_peer_nis) {
762 if (lnet_nid_to_nid4(&lpni->lpni_nid) == nid)
769 struct lnet_peer_ni *
770 lnet_peer_ni_get_locked(struct lnet_peer *lp, struct lnet_nid *nid)
772 struct lnet_peer_net *lpn;
773 struct lnet_peer_ni *lpni;
775 lpn = lnet_peer_get_net_locked(lp, LNET_NID_NET(nid));
779 list_for_each_entry(lpni, &lpn->lpn_peer_nis, lpni_peer_nis) {
780 if (nid_same(&lpni->lpni_nid, nid))
788 lnet_find_peer(lnet_nid_t nid)
790 struct lnet_peer_ni *lpni;
791 struct lnet_peer *lp = NULL;
794 cpt = lnet_net_lock_current();
795 lpni = lnet_find_peer_ni_locked(nid);
797 lp = lpni->lpni_peer_net->lpn_peer;
798 lnet_peer_addref_locked(lp);
799 lnet_peer_ni_decref_locked(lpni);
801 lnet_net_unlock(cpt);
806 struct lnet_peer_net *
807 lnet_get_next_peer_net_locked(struct lnet_peer *lp, __u32 prev_lpn_id)
809 struct lnet_peer_net *net;
812 /* no net id provided return the first net */
813 net = list_first_entry_or_null(&lp->lp_peer_nets,
814 struct lnet_peer_net,
820 /* find the net after the one provided */
821 list_for_each_entry(net, &lp->lp_peer_nets, lpn_peer_nets) {
822 if (net->lpn_net_id == prev_lpn_id) {
824 * if we reached the end of the list loop to the
827 if (net->lpn_peer_nets.next == &lp->lp_peer_nets)
828 return list_first_entry_or_null(&lp->lp_peer_nets,
829 struct lnet_peer_net,
832 return list_next_entry(net, lpn_peer_nets);
839 struct lnet_peer_ni *
840 lnet_get_next_peer_ni_locked(struct lnet_peer *peer,
841 struct lnet_peer_net *peer_net,
842 struct lnet_peer_ni *prev)
844 struct lnet_peer_ni *lpni;
845 struct lnet_peer_net *net = peer_net;
849 if (list_empty(&peer->lp_peer_nets))
852 net = list_entry(peer->lp_peer_nets.next,
853 struct lnet_peer_net,
856 lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
862 if (prev->lpni_peer_nis.next == &prev->lpni_peer_net->lpn_peer_nis) {
864 * if you reached the end of the peer ni list and the peer
865 * net is specified then there are no more peer nis in that
872 * we reached the end of this net ni list. move to the
875 if (prev->lpni_peer_net->lpn_peer_nets.next ==
877 /* no more nets and no more NIs. */
880 /* get the next net */
881 net = list_entry(prev->lpni_peer_net->lpn_peer_nets.next,
882 struct lnet_peer_net,
884 /* get the ni on it */
885 lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
891 /* there are more nis left */
892 lpni = list_entry(prev->lpni_peer_nis.next,
893 struct lnet_peer_ni, lpni_peer_nis);
898 /* Call with the ln_api_mutex held */
899 int lnet_get_peer_list(u32 *countp, u32 *sizep, struct lnet_process_id __user *ids)
901 struct lnet_process_id id;
902 struct lnet_peer_table *ptable;
903 struct lnet_peer *lp;
912 if (the_lnet.ln_state != LNET_STATE_RUNNING)
915 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
918 * Count the number of peers, and return E2BIG if the buffer
919 * is too small. We'll also return the desired size.
922 for (cpt = 0; cpt < lncpt; cpt++) {
923 ptable = the_lnet.ln_peer_tables[cpt];
924 count += ptable->pt_peers;
926 size = count * sizeof(*ids);
931 * Walk the peer lists and copy out the primary nids.
932 * This is safe because the peer lists are only modified
933 * while the ln_api_mutex is held. So we don't need to
934 * hold the lnet_net_lock as well, and can therefore
935 * directly call copy_to_user().
938 memset(&id, 0, sizeof(id));
939 id.pid = LNET_PID_LUSTRE;
941 for (cpt = 0; cpt < lncpt; cpt++) {
942 ptable = the_lnet.ln_peer_tables[cpt];
943 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
944 if (!nid_is_nid4(&lp->lp_primary_nid))
948 id.nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
949 if (copy_to_user(&ids[i], &id, sizeof(id)))
962 * Start pushes to peers that need to be updated for a configuration
963 * change on this node.
966 lnet_push_update_to_peers(int force)
968 struct lnet_peer_table *ptable;
969 struct lnet_peer *lp;
973 lnet_net_lock(LNET_LOCK_EX);
974 if (lnet_peer_discovery_disabled)
976 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
977 for (cpt = 0; cpt < lncpt; cpt++) {
978 ptable = the_lnet.ln_peer_tables[cpt];
979 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
981 spin_lock(&lp->lp_lock);
982 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
983 lp->lp_state |= LNET_PEER_FORCE_PUSH;
984 spin_unlock(&lp->lp_lock);
986 if (lnet_peer_needs_push(lp))
987 lnet_peer_queue_for_discovery(lp);
990 lnet_net_unlock(LNET_LOCK_EX);
991 wake_up(&the_lnet.ln_dc_waitq);
994 /* find the NID in the preferred gateways for the remote peer
996 * false: list is not empty and NID is not preferred
997 * false: list is empty
998 * true: nid is found in the list
1001 lnet_peer_is_pref_rtr_locked(struct lnet_peer_ni *lpni,
1002 struct lnet_nid *gw_nid)
1004 struct lnet_nid_list *ne;
1006 CDEBUG(D_NET, "%s: rtr pref emtpy: %d\n",
1007 libcfs_nidstr(&lpni->lpni_nid),
1008 list_empty(&lpni->lpni_rtr_pref_nids));
1010 if (list_empty(&lpni->lpni_rtr_pref_nids))
1013 /* iterate through all the preferred NIDs and see if any of them
1014 * matches the provided gw_nid
1016 list_for_each_entry(ne, &lpni->lpni_rtr_pref_nids, nl_list) {
1017 CDEBUG(D_NET, "Comparing pref %s with gw %s\n",
1018 libcfs_nidstr(&ne->nl_nid),
1019 libcfs_nidstr(gw_nid));
1020 if (nid_same(&ne->nl_nid, gw_nid))
1028 lnet_peer_clr_pref_rtrs(struct lnet_peer_ni *lpni)
1030 struct list_head zombies;
1031 struct lnet_nid_list *ne;
1032 struct lnet_nid_list *tmp;
1033 int cpt = lpni->lpni_cpt;
1035 INIT_LIST_HEAD(&zombies);
1038 list_splice_init(&lpni->lpni_rtr_pref_nids, &zombies);
1039 lnet_net_unlock(cpt);
1041 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1042 list_del(&ne->nl_list);
1043 LIBCFS_FREE(ne, sizeof(*ne));
1048 lnet_peer_add_pref_rtr(struct lnet_peer_ni *lpni,
1049 struct lnet_nid *gw_nid)
1051 int cpt = lpni->lpni_cpt;
1052 struct lnet_nid_list *ne = NULL;
1054 /* This function is called with api_mutex held. When the api_mutex
1055 * is held the list can not be modified, as it is only modified as
1056 * a result of applying a UDSP and that happens under api_mutex
1059 __must_hold(&the_lnet.ln_api_mutex);
1061 list_for_each_entry(ne, &lpni->lpni_rtr_pref_nids, nl_list) {
1062 if (nid_same(&ne->nl_nid, gw_nid))
1066 LIBCFS_CPT_ALLOC(ne, lnet_cpt_table(), cpt, sizeof(*ne));
1070 ne->nl_nid = *gw_nid;
1072 /* Lock the cpt to protect against addition and checks in the
1073 * selection algorithm
1076 list_add(&ne->nl_list, &lpni->lpni_rtr_pref_nids);
1077 lnet_net_unlock(cpt);
1083 * Test whether a ni is a preferred ni for this peer_ni, e.g, whether
1084 * this is a preferred point-to-point path. Call with lnet_net_lock in
1088 lnet_peer_is_pref_nid_locked(struct lnet_peer_ni *lpni, struct lnet_nid *nid)
1090 struct lnet_nid_list *ne;
1092 if (lpni->lpni_pref_nnids == 0)
1094 if (lpni->lpni_pref_nnids == 1)
1095 return nid_same(&lpni->lpni_pref.nid, nid);
1096 list_for_each_entry(ne, &lpni->lpni_pref.nids, nl_list) {
1097 if (nid_same(&ne->nl_nid, nid))
1104 * Set a single ni as preferred, provided no preferred ni is already
1105 * defined. Only to be used for non-multi-rail peer_ni.
1108 lnet_peer_ni_set_non_mr_pref_nid(struct lnet_peer_ni *lpni,
1109 struct lnet_nid *nid)
1115 spin_lock(&lpni->lpni_lock);
1116 if (LNET_NID_IS_ANY(nid)) {
1118 } else if (lpni->lpni_pref_nnids > 0) {
1120 } else if (lpni->lpni_pref_nnids == 0) {
1121 lpni->lpni_pref.nid = *nid;
1122 lpni->lpni_pref_nnids = 1;
1123 lpni->lpni_state |= LNET_PEER_NI_NON_MR_PREF;
1125 spin_unlock(&lpni->lpni_lock);
1127 CDEBUG(D_NET, "peer %s nid %s: %d\n",
1128 libcfs_nidstr(&lpni->lpni_nid), libcfs_nidstr(nid), rc);
1133 * Clear the preferred NID from a non-multi-rail peer_ni, provided
1134 * this preference was set by lnet_peer_ni_set_non_mr_pref_nid().
1137 lnet_peer_ni_clr_non_mr_pref_nid(struct lnet_peer_ni *lpni)
1141 spin_lock(&lpni->lpni_lock);
1142 if (lpni->lpni_state & LNET_PEER_NI_NON_MR_PREF) {
1143 lpni->lpni_pref_nnids = 0;
1144 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1145 } else if (lpni->lpni_pref_nnids == 0) {
1150 spin_unlock(&lpni->lpni_lock);
1152 CDEBUG(D_NET, "peer %s: %d\n",
1153 libcfs_nidstr(&lpni->lpni_nid), rc);
1158 lnet_peer_ni_set_selection_priority(struct lnet_peer_ni *lpni, __u32 priority)
1160 lpni->lpni_sel_priority = priority;
1164 * Clear the preferred NIDs from a non-multi-rail peer.
1167 lnet_peer_clr_non_mr_pref_nids(struct lnet_peer *lp)
1169 struct lnet_peer_ni *lpni = NULL;
1171 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
1172 lnet_peer_ni_clr_non_mr_pref_nid(lpni);
1176 lnet_peer_add_pref_nid(struct lnet_peer_ni *lpni, struct lnet_nid *nid)
1178 struct lnet_peer *lp = lpni->lpni_peer_net->lpn_peer;
1179 struct lnet_nid_list *ne1 = NULL;
1180 struct lnet_nid_list *ne2 = NULL;
1181 struct lnet_nid *tmp_nid = NULL;
1184 if (LNET_NID_IS_ANY(nid)) {
1189 if (lpni->lpni_pref_nnids == 1 &&
1190 nid_same(&lpni->lpni_pref.nid, nid)) {
1195 /* A non-MR node may have only one preferred NI per peer_ni */
1196 if (lpni->lpni_pref_nnids > 0 &&
1197 !(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1202 /* add the new preferred nid to the list of preferred nids */
1203 if (lpni->lpni_pref_nnids != 0) {
1204 size_t alloc_size = sizeof(*ne1);
1206 if (lpni->lpni_pref_nnids == 1) {
1207 tmp_nid = &lpni->lpni_pref.nid;
1208 INIT_LIST_HEAD(&lpni->lpni_pref.nids);
1211 list_for_each_entry(ne1, &lpni->lpni_pref.nids, nl_list) {
1212 if (nid_same(&ne1->nl_nid, nid)) {
1218 LIBCFS_CPT_ALLOC(ne1, lnet_cpt_table(), lpni->lpni_cpt,
1225 /* move the originally stored nid to the list */
1226 if (lpni->lpni_pref_nnids == 1) {
1227 LIBCFS_CPT_ALLOC(ne2, lnet_cpt_table(),
1228 lpni->lpni_cpt, alloc_size);
1233 INIT_LIST_HEAD(&ne2->nl_list);
1234 ne2->nl_nid = *tmp_nid;
1239 lnet_net_lock(LNET_LOCK_EX);
1240 spin_lock(&lpni->lpni_lock);
1241 if (lpni->lpni_pref_nnids == 0) {
1242 lpni->lpni_pref.nid = *nid;
1245 list_add_tail(&ne2->nl_list, &lpni->lpni_pref.nids);
1246 list_add_tail(&ne1->nl_list, &lpni->lpni_pref.nids);
1248 lpni->lpni_pref_nnids++;
1249 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1250 spin_unlock(&lpni->lpni_lock);
1251 lnet_net_unlock(LNET_LOCK_EX);
1254 if (rc == -EEXIST && (lpni->lpni_state & LNET_PEER_NI_NON_MR_PREF)) {
1255 spin_lock(&lpni->lpni_lock);
1256 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1257 spin_unlock(&lpni->lpni_lock);
1259 CDEBUG(D_NET, "peer %s nid %s: %d\n",
1260 libcfs_nidstr(&lp->lp_primary_nid), libcfs_nidstr(nid), rc);
1265 lnet_peer_del_pref_nid(struct lnet_peer_ni *lpni, struct lnet_nid *nid)
1267 struct lnet_peer *lp = lpni->lpni_peer_net->lpn_peer;
1268 struct lnet_nid_list *ne = NULL;
1271 if (lpni->lpni_pref_nnids == 0) {
1276 if (lpni->lpni_pref_nnids == 1) {
1277 if (!nid_same(&lpni->lpni_pref.nid, nid)) {
1282 list_for_each_entry(ne, &lpni->lpni_pref.nids, nl_list) {
1283 if (nid_same(&ne->nl_nid, nid))
1284 goto remove_nid_entry;
1292 lnet_net_lock(LNET_LOCK_EX);
1293 spin_lock(&lpni->lpni_lock);
1294 if (lpni->lpni_pref_nnids == 1)
1295 lpni->lpni_pref.nid = LNET_ANY_NID;
1297 list_del_init(&ne->nl_list);
1298 if (lpni->lpni_pref_nnids == 2) {
1299 struct lnet_nid_list *ne, *tmp;
1301 list_for_each_entry_safe(ne, tmp,
1302 &lpni->lpni_pref.nids,
1304 lpni->lpni_pref.nid = ne->nl_nid;
1305 list_del_init(&ne->nl_list);
1306 LIBCFS_FREE(ne, sizeof(*ne));
1310 lpni->lpni_pref_nnids--;
1311 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1312 spin_unlock(&lpni->lpni_lock);
1313 lnet_net_unlock(LNET_LOCK_EX);
1316 LIBCFS_FREE(ne, sizeof(*ne));
1318 CDEBUG(D_NET, "peer %s nid %s: %d\n",
1319 libcfs_nidstr(&lp->lp_primary_nid), libcfs_nidstr(nid), rc);
1324 lnet_peer_clr_pref_nids(struct lnet_peer_ni *lpni)
1326 struct list_head zombies;
1327 struct lnet_nid_list *ne;
1328 struct lnet_nid_list *tmp;
1330 INIT_LIST_HEAD(&zombies);
1332 lnet_net_lock(LNET_LOCK_EX);
1333 if (lpni->lpni_pref_nnids == 1)
1334 lpni->lpni_pref.nid = LNET_ANY_NID;
1335 else if (lpni->lpni_pref_nnids > 1)
1336 list_splice_init(&lpni->lpni_pref.nids, &zombies);
1337 lpni->lpni_pref_nnids = 0;
1338 lnet_net_unlock(LNET_LOCK_EX);
1340 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1341 list_del_init(&ne->nl_list);
1342 LIBCFS_FREE(ne, sizeof(*ne));
1347 lnet_peer_primary_nid_locked(lnet_nid_t nid)
1349 /* FIXME handle large-addr nid */
1350 struct lnet_peer_ni *lpni;
1351 lnet_nid_t primary_nid = nid;
1353 lpni = lnet_find_peer_ni_locked(nid);
1355 primary_nid = lnet_nid_to_nid4(
1356 &lpni->lpni_peer_net->lpn_peer->lp_primary_nid);
1357 lnet_peer_ni_decref_locked(lpni);
1364 lnet_is_discovery_disabled_locked(struct lnet_peer *lp)
1365 __must_hold(&lp->lp_lock)
1367 if (lnet_peer_discovery_disabled)
1370 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL) ||
1371 (lp->lp_state & LNET_PEER_NO_DISCOVERY)) {
1382 lnet_is_discovery_disabled(struct lnet_peer *lp)
1386 spin_lock(&lp->lp_lock);
1387 rc = lnet_is_discovery_disabled_locked(lp);
1388 spin_unlock(&lp->lp_lock);
1394 LNetAddPeer(lnet_nid_t *nids, __u32 num_nids)
1396 lnet_nid_t pnid = 0;
1400 if (!nids || num_nids < 1)
1403 rc = LNetNIInit(LNET_PID_ANY);
1407 mutex_lock(&the_lnet.ln_api_mutex);
1409 mr = lnet_peer_discovery_disabled == 0;
1412 for (i = 0; i < num_nids; i++) {
1413 if (nids[i] == LNET_NID_LO_0)
1418 rc = lnet_add_peer_ni(pnid, LNET_NID_ANY, mr, true);
1419 } else if (lnet_peer_discovery_disabled) {
1420 rc = lnet_add_peer_ni(nids[i], LNET_NID_ANY, mr, true);
1422 rc = lnet_add_peer_ni(pnid, nids[i], mr, true);
1425 if (rc && rc != -EEXIST)
1430 mutex_unlock(&the_lnet.ln_api_mutex);
1434 return rc == -EEXIST ? 0 : rc;
1436 EXPORT_SYMBOL(LNetAddPeer);
1438 /* FIXME support large-addr nid */
1440 LNetPrimaryNID(lnet_nid_t nid)
1442 struct lnet_peer *lp;
1443 struct lnet_peer_ni *lpni;
1444 lnet_nid_t primary_nid = nid;
1448 if (nid == LNET_NID_LO_0)
1449 return LNET_NID_LO_0;
1451 cpt = lnet_net_lock_current();
1452 lpni = lnet_nid2peerni_locked(nid, LNET_NID_ANY, cpt);
1457 lp = lpni->lpni_peer_net->lpn_peer;
1459 /* If discovery is disabled locally then we needn't bother running
1460 * discovery here because discovery will not modify whatever
1461 * primary NID is currently set for this peer. If the specified peer is
1462 * down then this discovery can introduce long delays into the mount
1463 * process, so skip it if it isn't necessary.
1465 if (!lnet_peer_discovery_disabled && !lnet_peer_is_uptodate(lp)) {
1466 spin_lock(&lp->lp_lock);
1467 /* force a full discovery cycle */
1468 lp->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH |
1469 LNET_PEER_LOCK_PRIMARY;
1470 spin_unlock(&lp->lp_lock);
1472 /* start discovery in the background. Messages to that
1473 * peer will not go through until the discovery is
1476 rc = lnet_discover_peer_locked(lpni, cpt, false);
1479 /* The lpni (or lp) for this NID may have changed and our ref is
1480 * the only thing keeping the old one around. Release the ref
1481 * and lookup the lpni again
1483 lnet_peer_ni_decref_locked(lpni);
1484 lpni = lnet_find_peer_ni_locked(nid);
1489 lp = lpni->lpni_peer_net->lpn_peer;
1491 primary_nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
1493 lnet_peer_ni_decref_locked(lpni);
1495 lnet_net_unlock(cpt);
1497 CDEBUG(D_NET, "NID %s primary NID %s rc %d\n", libcfs_nid2str(nid),
1498 libcfs_nid2str(primary_nid), rc);
1501 EXPORT_SYMBOL(LNetPrimaryNID);
1503 struct lnet_peer_net *
1504 lnet_peer_get_net_locked(struct lnet_peer *peer, __u32 net_id)
1506 struct lnet_peer_net *peer_net;
1507 list_for_each_entry(peer_net, &peer->lp_peer_nets, lpn_peer_nets) {
1508 if (peer_net->lpn_net_id == net_id)
1515 * Attach a peer_ni to a peer_net and peer. This function assumes
1516 * peer_ni is not already attached to the peer_net/peer. The peer_ni
1517 * may be attached to a different peer, in which case it will be
1518 * properly detached first. The whole operation is done atomically.
1520 * This function consumes the reference on lpni and Always returns 0.
1521 * This is the last function called from functions that do return an
1522 * int, so returning 0 here allows the compiler to do a tail call.
1525 lnet_peer_attach_peer_ni(struct lnet_peer *lp,
1526 struct lnet_peer_net *lpn,
1527 struct lnet_peer_ni *lpni,
1530 struct lnet_peer_table *ptable;
1531 bool new_lpn = false;
1534 /* Install the new peer_ni */
1535 lnet_net_lock(LNET_LOCK_EX);
1536 /* Add peer_ni to global peer table hash, if necessary. */
1537 if (list_empty(&lpni->lpni_hashlist)) {
1538 int hash = lnet_nid2peerhash(&lpni->lpni_nid);
1540 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
1541 list_add_tail(&lpni->lpni_hashlist, &ptable->pt_hash[hash]);
1542 ptable->pt_version++;
1543 lnet_peer_ni_addref_locked(lpni);
1546 /* Detach the peer_ni from an existing peer, if necessary. */
1547 if (lpni->lpni_peer_net) {
1548 LASSERT(lpni->lpni_peer_net != lpn);
1549 LASSERT(lpni->lpni_peer_net->lpn_peer != lp);
1550 lnet_peer_detach_peer_ni_locked(lpni);
1551 lnet_peer_net_decref_locked(lpni->lpni_peer_net);
1552 lpni->lpni_peer_net = NULL;
1555 /* Add peer_ni to peer_net */
1556 lpni->lpni_peer_net = lpn;
1557 if (nid_same(&lp->lp_primary_nid, &lpni->lpni_nid))
1558 list_add(&lpni->lpni_peer_nis, &lpn->lpn_peer_nis);
1560 list_add_tail(&lpni->lpni_peer_nis, &lpn->lpn_peer_nis);
1561 lnet_update_peer_net_healthv(lpni);
1562 lnet_peer_net_addref_locked(lpn);
1564 /* Add peer_net to peer */
1565 if (!lpn->lpn_peer) {
1568 if (nid_same(&lp->lp_primary_nid, &lpni->lpni_nid))
1569 list_add(&lpn->lpn_peer_nets, &lp->lp_peer_nets);
1571 list_add_tail(&lpn->lpn_peer_nets, &lp->lp_peer_nets);
1572 lnet_peer_addref_locked(lp);
1575 /* Add peer to global peer list, if necessary */
1576 ptable = the_lnet.ln_peer_tables[lp->lp_cpt];
1577 if (list_empty(&lp->lp_peer_list)) {
1578 list_add_tail(&lp->lp_peer_list, &ptable->pt_peer_list);
1583 /* Update peer state */
1584 spin_lock(&lp->lp_lock);
1585 if (flags & LNET_PEER_CONFIGURED) {
1586 if (!(lp->lp_state & LNET_PEER_CONFIGURED))
1587 lp->lp_state |= LNET_PEER_CONFIGURED;
1589 if (flags & LNET_PEER_MULTI_RAIL) {
1590 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1591 lp->lp_state |= LNET_PEER_MULTI_RAIL;
1592 lnet_peer_clr_non_mr_pref_nids(lp);
1595 if (flags & LNET_PEER_LOCK_PRIMARY)
1596 lp->lp_state |= LNET_PEER_LOCK_PRIMARY;
1597 spin_unlock(&lp->lp_lock);
1603 rc = lnet_udsp_apply_policies_on_lpn(lpn);
1605 CERROR("Failed to apply UDSPs on lpn %s\n",
1606 libcfs_net2str(lpn->lpn_net_id));
1608 rc = lnet_udsp_apply_policies_on_lpni(lpni);
1610 CERROR("Failed to apply UDSPs on lpni %s\n",
1611 libcfs_nidstr(&lpni->lpni_nid));
1613 CDEBUG(D_NET, "peer %s NID %s flags %#x\n",
1614 libcfs_nidstr(&lp->lp_primary_nid),
1615 libcfs_nidstr(&lpni->lpni_nid), flags);
1616 lnet_peer_ni_decref_locked(lpni);
1617 lnet_net_unlock(LNET_LOCK_EX);
1623 * Create a new peer, with nid as its primary nid.
1625 * Call with the lnet_api_mutex held.
1628 lnet_peer_add(lnet_nid_t nid4, unsigned int flags)
1630 struct lnet_nid nid;
1631 struct lnet_peer *lp;
1632 struct lnet_peer_net *lpn;
1633 struct lnet_peer_ni *lpni;
1636 LASSERT(nid4 != LNET_NID_ANY);
1639 * No need for the lnet_net_lock here, because the
1640 * lnet_api_mutex is held.
1642 lpni = lnet_find_peer_ni_locked(nid4);
1644 /* A peer with this NID already exists. */
1645 lp = lpni->lpni_peer_net->lpn_peer;
1646 lnet_peer_ni_decref_locked(lpni);
1648 * This is an error if the peer was configured and the
1649 * primary NID differs or an attempt is made to change
1650 * the Multi-Rail flag. Otherwise the assumption is
1651 * that an existing peer is being modified.
1653 if (lp->lp_state & LNET_PEER_CONFIGURED) {
1654 if (lnet_nid_to_nid4(&lp->lp_primary_nid) != nid4)
1656 else if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL)
1659 } else if (!(flags & LNET_PEER_CONFIGURED)) {
1660 if (lnet_nid_to_nid4(&lp->lp_primary_nid) == nid4) {
1665 /* Delete and recreate as a configured peer. */
1666 rc = lnet_peer_del(lp);
1671 /* Create peer, peer_net, and peer_ni. */
1673 lnet_nid4_to_nid(nid4, &nid);
1674 lp = lnet_peer_alloc(&nid);
1677 lpn = lnet_peer_net_alloc(LNET_NID_NET(&nid));
1680 lpni = lnet_peer_ni_alloc(&nid);
1684 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1687 LIBCFS_FREE(lpn, sizeof(*lpn));
1689 LIBCFS_FREE(lp, sizeof(*lp));
1691 CDEBUG(D_NET, "peer %s NID flags %#x: %d\n",
1692 libcfs_nid2str(nid4), flags, rc);
1697 * Add a NID to a peer. Call with ln_api_mutex held.
1700 * -EPERM: Non-DLC addition to a DLC-configured peer.
1701 * -EEXIST: The NID was configured by DLC for a different peer.
1702 * -ENOMEM: Out of memory.
1703 * -ENOTUNIQ: Adding a second peer NID on a single network on a
1704 * non-multi-rail peer.
1707 lnet_peer_add_nid(struct lnet_peer *lp, lnet_nid_t nid4, unsigned int flags)
1709 struct lnet_peer_net *lpn;
1710 struct lnet_peer_ni *lpni;
1711 struct lnet_nid nid;
1715 LASSERT(nid4 != LNET_NID_ANY);
1717 lnet_nid4_to_nid(nid4, &nid);
1719 /* A configured peer can only be updated through configuration. */
1720 if (!(flags & LNET_PEER_CONFIGURED)) {
1721 if (lp->lp_state & LNET_PEER_CONFIGURED) {
1728 * The MULTI_RAIL flag can be set but not cleared, because
1729 * that would leave the peer struct in an invalid state.
1731 if (flags & LNET_PEER_MULTI_RAIL) {
1732 spin_lock(&lp->lp_lock);
1733 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1734 lp->lp_state |= LNET_PEER_MULTI_RAIL;
1735 lnet_peer_clr_non_mr_pref_nids(lp);
1737 spin_unlock(&lp->lp_lock);
1738 } else if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
1743 lpni = lnet_find_peer_ni_locked(nid4);
1746 * A peer_ni already exists. This is only a problem if
1747 * it is not connected to this peer and was configured
1750 if (lpni->lpni_peer_net->lpn_peer == lp)
1752 if (lnet_peer_ni_is_configured(lpni)) {
1756 /* If this is the primary NID, destroy the peer. */
1757 if (lnet_peer_ni_is_primary(lpni)) {
1758 struct lnet_peer *lp2 =
1759 lpni->lpni_peer_net->lpn_peer;
1760 int rtr_refcount = lp2->lp_rtr_refcount;
1762 /* If the new peer that this NID belongs to is
1763 * a primary NID for another peer which we're
1764 * suppose to preserve the Primary for then we
1765 * don't want to mess with it. But the
1766 * configuration is wrong at this point, so we
1767 * should flag both of these peers as in a bad
1770 if (lp2->lp_state & LNET_PEER_LOCK_PRIMARY) {
1771 spin_lock(&lp->lp_lock);
1772 lp->lp_state |= LNET_PEER_BAD_CONFIG;
1773 spin_unlock(&lp->lp_lock);
1774 spin_lock(&lp2->lp_lock);
1775 lp2->lp_state |= LNET_PEER_BAD_CONFIG;
1776 spin_unlock(&lp2->lp_lock);
1780 * if we're trying to delete a router it means
1781 * we're moving this peer NI to a new peer so must
1782 * transfer router properties to the new peer
1784 if (rtr_refcount > 0) {
1785 flags |= LNET_PEER_RTR_NI_FORCE_DEL;
1786 lnet_rtr_transfer_to_peer(lp2, lp);
1789 lnet_peer_ni_decref_locked(lpni);
1790 lpni = lnet_peer_ni_alloc(&nid);
1797 lpni = lnet_peer_ni_alloc(&nid);
1805 * Get the peer_net. Check that we're not adding a second
1806 * peer_ni on a peer_net of a non-multi-rail peer.
1808 lpn = lnet_peer_get_net_locked(lp, LNET_NIDNET(nid4));
1810 lpn = lnet_peer_net_alloc(LNET_NIDNET(nid4));
1815 } else if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1820 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1823 lnet_peer_ni_decref_locked(lpni);
1825 CDEBUG(D_NET, "peer %s NID %s flags %#x: %d\n",
1826 libcfs_nidstr(&lp->lp_primary_nid), libcfs_nid2str(nid4),
1832 * Update the primary NID of a peer, if possible.
1834 * Call with the lnet_api_mutex held.
1837 lnet_peer_set_primary_nid(struct lnet_peer *lp, lnet_nid_t nid,
1840 struct lnet_nid old = lp->lp_primary_nid;
1843 if (lnet_nid_to_nid4(&lp->lp_primary_nid) == nid)
1846 if (!(lp->lp_state & LNET_PEER_LOCK_PRIMARY))
1847 lnet_nid4_to_nid(nid, &lp->lp_primary_nid);
1849 rc = lnet_peer_add_nid(lp, nid, flags);
1851 lp->lp_primary_nid = old;
1855 /* if this is a configured peer or the primary for that peer has
1856 * been locked, then we don't want to flag this scenario as
1859 if (lp->lp_state & LNET_PEER_CONFIGURED ||
1860 lp->lp_state & LNET_PEER_LOCK_PRIMARY)
1863 CDEBUG(D_NET, "peer %s NID %s: %d\n",
1864 libcfs_nidstr(&old), libcfs_nid2str(nid), rc);
1870 * lpni creation initiated due to traffic either sending or receiving.
1873 lnet_peer_ni_traffic_add(struct lnet_nid *nid, struct lnet_nid *pref)
1875 struct lnet_peer *lp;
1876 struct lnet_peer_net *lpn;
1877 struct lnet_peer_ni *lpni;
1881 if (LNET_NID_IS_ANY(nid)) {
1886 /* lnet_net_lock is not needed here because ln_api_lock is held */
1887 lpni = lnet_peer_ni_find_locked(nid);
1890 * We must have raced with another thread. Since we
1891 * know next to nothing about a peer_ni created by
1892 * traffic, we just assume everything is ok and
1895 lnet_peer_ni_decref_locked(lpni);
1899 /* Create peer, peer_net, and peer_ni. */
1901 lp = lnet_peer_alloc(nid);
1904 lpn = lnet_peer_net_alloc(LNET_NID_NET(nid));
1907 lpni = lnet_peer_ni_alloc(nid);
1910 lnet_peer_ni_set_non_mr_pref_nid(lpni, pref);
1912 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1915 LIBCFS_FREE(lpn, sizeof(*lpn));
1917 LIBCFS_FREE(lp, sizeof(*lp));
1919 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nidstr(nid), rc);
1924 * Implementation of IOC_LIBCFS_ADD_PEER_NI.
1926 * This API handles the following combinations:
1927 * Create a peer with its primary NI if only the prim_nid is provided
1928 * Add a NID to a peer identified by the prim_nid. The peer identified
1929 * by the prim_nid must already exist.
1930 * The peer being created may be non-MR.
1932 * The caller must hold ln_api_mutex. This prevents the peer from
1933 * being created/modified/deleted by a different thread.
1936 lnet_add_peer_ni(lnet_nid_t prim_nid, lnet_nid_t nid, bool mr, bool temp)
1938 struct lnet_peer *lp = NULL;
1939 struct lnet_peer_ni *lpni;
1940 unsigned int flags = 0;
1942 /* The prim_nid must always be specified */
1943 if (prim_nid == LNET_NID_ANY)
1947 flags = LNET_PEER_CONFIGURED;
1950 flags |= LNET_PEER_MULTI_RAIL;
1953 * If nid isn't specified, we must create a new peer with
1954 * prim_nid as its primary nid.
1956 if (nid == LNET_NID_ANY)
1957 return lnet_peer_add(prim_nid, flags);
1959 /* Look up the prim_nid, which must exist. */
1960 lpni = lnet_find_peer_ni_locked(prim_nid);
1963 lnet_peer_ni_decref_locked(lpni);
1964 lp = lpni->lpni_peer_net->lpn_peer;
1966 /* Peer must have been configured. */
1967 if (!temp && !(lp->lp_state & LNET_PEER_CONFIGURED)) {
1968 CDEBUG(D_NET, "peer %s was not configured\n",
1969 libcfs_nid2str(prim_nid));
1973 /* Primary NID must match */
1974 if (lnet_nid_to_nid4(&lp->lp_primary_nid) != prim_nid) {
1975 CDEBUG(D_NET, "prim_nid %s is not primary for peer %s\n",
1976 libcfs_nid2str(prim_nid),
1977 libcfs_nidstr(&lp->lp_primary_nid));
1981 /* Multi-Rail flag must match. */
1982 if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL) {
1983 CDEBUG(D_NET, "multi-rail state mismatch for peer %s\n",
1984 libcfs_nid2str(prim_nid));
1988 return lnet_peer_add_nid(lp, nid, flags);
1992 * Implementation of IOC_LIBCFS_DEL_PEER_NI.
1994 * This API handles the following combinations:
1995 * Delete a NI from a peer if both prim_nid and nid are provided.
1996 * Delete a peer if only prim_nid is provided.
1997 * Delete a peer if its primary nid is provided.
1999 * The caller must hold ln_api_mutex. This prevents the peer from
2000 * being modified/deleted by a different thread.
2003 lnet_del_peer_ni(lnet_nid_t prim_nid, lnet_nid_t nid)
2005 struct lnet_peer *lp;
2006 struct lnet_peer_ni *lpni;
2009 if (prim_nid == LNET_NID_ANY)
2012 lpni = lnet_find_peer_ni_locked(prim_nid);
2015 lnet_peer_ni_decref_locked(lpni);
2016 lp = lpni->lpni_peer_net->lpn_peer;
2018 if (prim_nid != lnet_nid_to_nid4(&lp->lp_primary_nid)) {
2019 CDEBUG(D_NET, "prim_nid %s is not primary for peer %s\n",
2020 libcfs_nid2str(prim_nid),
2021 libcfs_nidstr(&lp->lp_primary_nid));
2025 lnet_net_lock(LNET_LOCK_EX);
2026 if (lp->lp_rtr_refcount > 0) {
2027 lnet_net_unlock(LNET_LOCK_EX);
2028 CERROR("%s is a router. Can not be deleted\n",
2029 libcfs_nid2str(prim_nid));
2032 lnet_net_unlock(LNET_LOCK_EX);
2034 if (nid == LNET_NID_ANY || nid == lnet_nid_to_nid4(&lp->lp_primary_nid))
2035 return lnet_peer_del(lp);
2037 flags = LNET_PEER_CONFIGURED;
2038 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
2039 flags |= LNET_PEER_MULTI_RAIL;
2041 return lnet_peer_del_nid(lp, nid, flags);
2045 lnet_destroy_peer_ni_locked(struct kref *ref)
2047 struct lnet_peer_ni *lpni = container_of(ref, struct lnet_peer_ni,
2049 struct lnet_peer_table *ptable;
2050 struct lnet_peer_net *lpn;
2052 CDEBUG(D_NET, "%p nid %s\n", lpni, libcfs_nidstr(&lpni->lpni_nid));
2054 LASSERT(kref_read(&lpni->lpni_kref) == 0);
2055 LASSERT(list_empty(&lpni->lpni_txq));
2056 LASSERT(lpni->lpni_txqnob == 0);
2057 LASSERT(list_empty(&lpni->lpni_peer_nis));
2058 LASSERT(list_empty(&lpni->lpni_on_remote_peer_ni_list));
2060 lpn = lpni->lpni_peer_net;
2061 lpni->lpni_peer_net = NULL;
2062 lpni->lpni_net = NULL;
2064 if (!list_empty(&lpni->lpni_hashlist)) {
2065 /* remove the peer ni from the zombie list */
2066 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
2067 spin_lock(&ptable->pt_zombie_lock);
2068 list_del_init(&lpni->lpni_hashlist);
2069 ptable->pt_zombies--;
2070 spin_unlock(&ptable->pt_zombie_lock);
2073 if (lpni->lpni_pref_nnids > 1) {
2074 struct lnet_nid_list *ne, *tmp;
2076 list_for_each_entry_safe(ne, tmp, &lpni->lpni_pref.nids,
2078 list_del_init(&ne->nl_list);
2079 LIBCFS_FREE(ne, sizeof(*ne));
2082 LIBCFS_FREE(lpni, sizeof(*lpni));
2085 lnet_peer_net_decref_locked(lpn);
2088 struct lnet_peer_ni *
2089 lnet_nid2peerni_ex(struct lnet_nid *nid, int cpt)
2091 struct lnet_peer_ni *lpni = NULL;
2094 if (the_lnet.ln_state != LNET_STATE_RUNNING)
2095 return ERR_PTR(-ESHUTDOWN);
2098 * find if a peer_ni already exists.
2099 * If so then just return that.
2101 lpni = lnet_peer_ni_find_locked(nid);
2105 lnet_net_unlock(cpt);
2107 rc = lnet_peer_ni_traffic_add(nid, NULL);
2110 goto out_net_relock;
2113 lpni = lnet_peer_ni_find_locked(nid);
2123 * Get a peer_ni for the given nid, create it if necessary. Takes a
2124 * hold on the peer_ni.
2126 struct lnet_peer_ni *
2127 lnet_peerni_by_nid_locked(struct lnet_nid *nid,
2128 struct lnet_nid *pref, int cpt)
2130 struct lnet_peer_ni *lpni = NULL;
2133 if (the_lnet.ln_state != LNET_STATE_RUNNING)
2134 return ERR_PTR(-ESHUTDOWN);
2137 * find if a peer_ni already exists.
2138 * If so then just return that.
2140 lpni = lnet_peer_ni_find_locked(nid);
2146 * use the lnet_api_mutex to serialize the creation of the peer_ni
2147 * and the creation/deletion of the local ni/net. When a local ni is
2148 * created, if there exists a set of peer_nis on that network,
2149 * they need to be traversed and updated. When a local NI is
2150 * deleted, which could result in a network being deleted, then
2151 * all peer nis on that network need to be removed as well.
2153 * Creation through traffic should also be serialized with
2154 * creation through DLC.
2156 lnet_net_unlock(cpt);
2157 mutex_lock(&the_lnet.ln_api_mutex);
2159 * Shutdown is only set under the ln_api_lock, so a single
2160 * check here is sufficent.
2162 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
2163 lpni = ERR_PTR(-ESHUTDOWN);
2164 goto out_mutex_unlock;
2167 rc = lnet_peer_ni_traffic_add(nid, pref);
2170 goto out_mutex_unlock;
2173 lpni = lnet_peer_ni_find_locked(nid);
2177 mutex_unlock(&the_lnet.ln_api_mutex);
2180 /* Lock has been dropped, check again for shutdown. */
2181 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
2183 lnet_peer_ni_decref_locked(lpni);
2184 lpni = ERR_PTR(-ESHUTDOWN);
2190 struct lnet_peer_ni *
2191 lnet_nid2peerni_locked(lnet_nid_t nid4, lnet_nid_t pref4, int cpt)
2193 struct lnet_nid nid, pref;
2195 lnet_nid4_to_nid(nid4, &nid);
2196 lnet_nid4_to_nid(pref4, &pref);
2197 if (pref4 == LNET_NID_ANY)
2198 return lnet_peerni_by_nid_locked(&nid, NULL, cpt);
2200 return lnet_peerni_by_nid_locked(&nid, &pref, cpt);
2204 lnet_peer_gw_discovery(struct lnet_peer *lp)
2208 spin_lock(&lp->lp_lock);
2209 if (lp->lp_state & LNET_PEER_RTR_DISCOVERY)
2211 spin_unlock(&lp->lp_lock);
2217 lnet_peer_is_uptodate(struct lnet_peer *lp)
2221 spin_lock(&lp->lp_lock);
2222 rc = lnet_peer_is_uptodate_locked(lp);
2223 spin_unlock(&lp->lp_lock);
2228 * Is a peer uptodate from the point of view of discovery?
2230 * If it is currently being processed, obviously not.
2231 * A forced Ping or Push is also handled by the discovery thread.
2233 * Otherwise look at whether the peer needs rediscovering.
2236 lnet_peer_is_uptodate_locked(struct lnet_peer *lp)
2237 __must_hold(&lp->lp_lock)
2241 if (lp->lp_state & (LNET_PEER_DISCOVERING |
2242 LNET_PEER_FORCE_PING |
2243 LNET_PEER_FORCE_PUSH)) {
2245 } else if (lp->lp_state & LNET_PEER_REDISCOVER) {
2247 } else if (lnet_peer_needs_push(lp)) {
2249 } else if (lp->lp_state & LNET_PEER_DISCOVERED) {
2250 if (lp->lp_state & LNET_PEER_NIDS_UPTODATE)
2261 /* Add the message to the peer's lp_dc_pendq and queue the peer for discovery */
2263 lnet_peer_queue_message(struct lnet_peer *lp, struct lnet_msg *msg)
2265 /* The discovery thread holds net_lock/EX and lp_lock when it splices
2266 * the lp_dc_pendq onto a local list for resending. Thus, we do the same
2267 * when adding to the list and queuing the peer to ensure that we do not
2268 * strand any messages on the lp_dc_pendq. This scheme ensures the
2269 * message will be resent even if the peer is already being discovered.
2270 * Therefore we needn't check the return value of
2271 * lnet_peer_queue_for_discovery(lp).
2273 lnet_net_lock(LNET_LOCK_EX);
2274 spin_lock(&lp->lp_lock);
2275 list_add_tail(&msg->msg_list, &lp->lp_dc_pendq);
2276 spin_unlock(&lp->lp_lock);
2277 lnet_peer_queue_for_discovery(lp);
2278 lnet_net_unlock(LNET_LOCK_EX);
2282 * Queue a peer for the attention of the discovery thread. Call with
2283 * lnet_net_lock/EX held. Returns 0 if the peer was queued, and
2284 * -EALREADY if the peer was already queued.
2286 static int lnet_peer_queue_for_discovery(struct lnet_peer *lp)
2290 spin_lock(&lp->lp_lock);
2291 if (!(lp->lp_state & LNET_PEER_DISCOVERING))
2292 lp->lp_state |= LNET_PEER_DISCOVERING;
2293 spin_unlock(&lp->lp_lock);
2294 if (list_empty(&lp->lp_dc_list)) {
2295 lnet_peer_addref_locked(lp);
2296 list_add_tail(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2297 wake_up(&the_lnet.ln_dc_waitq);
2303 CDEBUG(D_NET, "Queue peer %s: %d\n",
2304 libcfs_nidstr(&lp->lp_primary_nid), rc);
2310 * Discovery of a peer is complete. Wake all waiters on the peer.
2311 * Call with lnet_net_lock/EX held.
2313 static void lnet_peer_discovery_complete(struct lnet_peer *lp)
2315 struct lnet_msg *msg, *tmp;
2317 LIST_HEAD(pending_msgs);
2319 CDEBUG(D_NET, "Discovery complete. Dequeue peer %s\n",
2320 libcfs_nidstr(&lp->lp_primary_nid));
2322 list_del_init(&lp->lp_dc_list);
2323 spin_lock(&lp->lp_lock);
2324 list_splice_init(&lp->lp_dc_pendq, &pending_msgs);
2325 spin_unlock(&lp->lp_lock);
2326 wake_up(&lp->lp_dc_waitq);
2328 if (lp->lp_rtr_refcount > 0)
2329 lnet_router_discovery_complete(lp);
2331 lnet_net_unlock(LNET_LOCK_EX);
2333 /* iterate through all pending messages and send them again */
2334 list_for_each_entry_safe(msg, tmp, &pending_msgs, msg_list) {
2335 list_del_init(&msg->msg_list);
2336 if (lp->lp_dc_error) {
2337 lnet_finalize(msg, lp->lp_dc_error);
2341 CDEBUG(D_NET, "sending pending message %s to target %s\n",
2342 lnet_msgtyp2str(msg->msg_type),
2343 libcfs_id2str(msg->msg_target));
2344 rc = lnet_send(msg->msg_src_nid_param, msg,
2345 msg->msg_rtr_nid_param);
2347 CNETERR("Error sending %s to %s: %d\n",
2348 lnet_msgtyp2str(msg->msg_type),
2349 libcfs_id2str(msg->msg_target), rc);
2350 lnet_finalize(msg, rc);
2353 lnet_net_lock(LNET_LOCK_EX);
2354 lnet_peer_decref_locked(lp);
2358 * Handle inbound push.
2359 * Like any event handler, called with lnet_res_lock/CPT held.
2361 void lnet_peer_push_event(struct lnet_event *ev)
2363 struct lnet_ping_buffer *pbuf;
2364 struct lnet_peer *lp;
2366 pbuf = LNET_PING_INFO_TO_BUFFER(ev->md_start + ev->offset);
2368 /* lnet_find_peer() adds a refcount */
2369 lp = lnet_find_peer(ev->source.nid);
2371 CDEBUG(D_NET, "Push Put from unknown %s (source %s). Ignoring...\n",
2372 libcfs_nid2str(ev->initiator.nid),
2373 libcfs_nid2str(ev->source.nid));
2374 pbuf->pb_needs_post = true;
2378 /* Ensure peer state remains consistent while we modify it. */
2379 spin_lock(&lp->lp_lock);
2382 * If some kind of error happened the contents of the message
2383 * cannot be used. Clear the NIDS_UPTODATE and set the
2384 * FORCE_PING flag to trigger a ping.
2387 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2388 lp->lp_state |= LNET_PEER_FORCE_PING;
2389 CDEBUG(D_NET, "Push Put error %d from %s (source %s)\n",
2391 libcfs_nidstr(&lp->lp_primary_nid),
2392 libcfs_nid2str(ev->source.nid));
2397 * A push with invalid or corrupted info. Clear the UPTODATE
2398 * flag to trigger a ping.
2400 if (lnet_ping_info_validate(&pbuf->pb_info)) {
2401 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2402 lp->lp_state |= LNET_PEER_FORCE_PING;
2403 CDEBUG(D_NET, "Corrupted Push from %s\n",
2404 libcfs_nidstr(&lp->lp_primary_nid));
2409 * Make sure we'll allocate the correct size ping buffer when
2412 if (lp->lp_data_nnis < pbuf->pb_info.pi_nnis)
2413 lp->lp_data_nnis = pbuf->pb_info.pi_nnis;
2416 * A non-Multi-Rail peer is not supposed to be capable of
2419 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)) {
2420 CERROR("Push from non-Multi-Rail peer %s dropped\n",
2421 libcfs_nidstr(&lp->lp_primary_nid));
2426 * The peer may have discovery disabled at its end. Set
2427 * NO_DISCOVERY as appropriate.
2429 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_DISCOVERY)) {
2430 CDEBUG(D_NET, "Peer %s has discovery disabled\n",
2431 libcfs_nidstr(&lp->lp_primary_nid));
2433 * Mark the peer for deletion if we already know about it
2434 * and it's going from discovery set to no discovery set
2436 if (!(lp->lp_state & (LNET_PEER_NO_DISCOVERY |
2437 LNET_PEER_DISCOVERING)) &&
2438 lp->lp_state & LNET_PEER_DISCOVERED) {
2439 CDEBUG(D_NET, "Marking %s:0x%x for deletion\n",
2440 libcfs_nidstr(&lp->lp_primary_nid),
2442 lp->lp_state |= LNET_PEER_MARK_DELETION;
2444 lp->lp_state |= LNET_PEER_NO_DISCOVERY;
2445 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
2446 CDEBUG(D_NET, "Peer %s has discovery enabled\n",
2447 libcfs_nidstr(&lp->lp_primary_nid));
2448 lp->lp_state &= ~LNET_PEER_NO_DISCOVERY;
2452 * Update the MULTI_RAIL flag based on the push. If the peer
2453 * was configured with DLC then the setting should match what
2455 * NB: We verified above that the MR feature bit is set in pi_features
2457 if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2458 CDEBUG(D_NET, "peer %s(%p) is MR\n",
2459 libcfs_nidstr(&lp->lp_primary_nid), lp);
2460 } else if (lp->lp_state & LNET_PEER_CONFIGURED) {
2461 CWARN("Push says %s is Multi-Rail, DLC says not\n",
2462 libcfs_nidstr(&lp->lp_primary_nid));
2463 } else if (lnet_peer_discovery_disabled) {
2464 CDEBUG(D_NET, "peer %s(%p) not MR: DD disabled locally\n",
2465 libcfs_nidstr(&lp->lp_primary_nid), lp);
2466 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
2467 CDEBUG(D_NET, "peer %s(%p) not MR: DD disabled remotely\n",
2468 libcfs_nidstr(&lp->lp_primary_nid), lp);
2470 CDEBUG(D_NET, "peer %s(%p) is MR capable\n",
2471 libcfs_nidstr(&lp->lp_primary_nid), lp);
2472 lp->lp_state |= LNET_PEER_MULTI_RAIL;
2473 lnet_peer_clr_non_mr_pref_nids(lp);
2477 * Check for truncation of the Put message. Clear the
2478 * NIDS_UPTODATE flag and set FORCE_PING to trigger a ping,
2479 * and tell discovery to allocate a bigger buffer.
2481 if (ev->mlength < ev->rlength) {
2482 if (the_lnet.ln_push_target_nnis < pbuf->pb_info.pi_nnis)
2483 the_lnet.ln_push_target_nnis = pbuf->pb_info.pi_nnis;
2484 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2485 lp->lp_state |= LNET_PEER_FORCE_PING;
2486 CDEBUG(D_NET, "Truncated Push from %s (%d nids)\n",
2487 libcfs_nidstr(&lp->lp_primary_nid),
2488 pbuf->pb_info.pi_nnis);
2492 /* always assume new data */
2493 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2494 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2497 * If there is data present that hasn't been processed yet,
2498 * we'll replace it if the Put contained newer data and it
2499 * fits. We're racing with a Ping or earlier Push in this
2502 if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
2503 if (LNET_PING_BUFFER_SEQNO(pbuf) >
2504 LNET_PING_BUFFER_SEQNO(lp->lp_data) &&
2505 pbuf->pb_info.pi_nnis <= lp->lp_data->pb_nnis) {
2506 memcpy(&lp->lp_data->pb_info, &pbuf->pb_info,
2507 LNET_PING_INFO_SIZE(pbuf->pb_info.pi_nnis));
2508 CDEBUG(D_NET, "Ping/Push race from %s: %u vs %u\n",
2509 libcfs_nidstr(&lp->lp_primary_nid),
2510 LNET_PING_BUFFER_SEQNO(pbuf),
2511 LNET_PING_BUFFER_SEQNO(lp->lp_data));
2517 * Allocate a buffer to copy the data. On a failure we drop
2518 * the Push and set FORCE_PING to force the discovery
2519 * thread to fix the problem by pinging the peer.
2521 lp->lp_data = lnet_ping_buffer_alloc(lp->lp_data_nnis, GFP_ATOMIC);
2523 lp->lp_state |= LNET_PEER_FORCE_PING;
2524 CDEBUG(D_NET, "Cannot allocate Push buffer for %s %u\n",
2525 libcfs_nidstr(&lp->lp_primary_nid),
2526 LNET_PING_BUFFER_SEQNO(pbuf));
2531 memcpy(&lp->lp_data->pb_info, &pbuf->pb_info,
2532 LNET_PING_INFO_SIZE(pbuf->pb_info.pi_nnis));
2533 lp->lp_state |= LNET_PEER_DATA_PRESENT;
2534 CDEBUG(D_NET, "Received Push %s %u\n",
2535 libcfs_nidstr(&lp->lp_primary_nid),
2536 LNET_PING_BUFFER_SEQNO(pbuf));
2539 /* We've processed this buffer. It can be reposted */
2540 pbuf->pb_needs_post = true;
2543 * Queue the peer for discovery if not done, force it on the request
2544 * queue and wake the discovery thread if the peer was already queued,
2545 * because its status changed.
2547 spin_unlock(&lp->lp_lock);
2548 lnet_net_lock(LNET_LOCK_EX);
2549 if (!lnet_peer_is_uptodate(lp) && lnet_peer_queue_for_discovery(lp)) {
2550 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2551 wake_up(&the_lnet.ln_dc_waitq);
2553 /* Drop refcount from lookup */
2554 lnet_peer_decref_locked(lp);
2555 lnet_net_unlock(LNET_LOCK_EX);
2559 * Clear the discovery error state, unless we're already discovering
2560 * this peer, in which case the error is current.
2562 static void lnet_peer_clear_discovery_error(struct lnet_peer *lp)
2564 spin_lock(&lp->lp_lock);
2565 if (!(lp->lp_state & LNET_PEER_DISCOVERING))
2566 lp->lp_dc_error = 0;
2567 spin_unlock(&lp->lp_lock);
2571 * Peer discovery slow path. The ln_api_mutex is held on entry, and
2572 * dropped/retaken within this function. An lnet_peer_ni is passed in
2573 * because discovery could tear down an lnet_peer.
2576 lnet_discover_peer_locked(struct lnet_peer_ni *lpni, int cpt, bool block)
2579 struct lnet_peer *lp;
2584 lnet_net_unlock(cpt);
2585 lnet_net_lock(LNET_LOCK_EX);
2586 lp = lpni->lpni_peer_net->lpn_peer;
2587 lnet_peer_clear_discovery_error(lp);
2590 * We're willing to be interrupted. The lpni can become a
2591 * zombie if we race with DLC, so we must check for that.
2594 /* Keep lp alive when the lnet_net_lock is unlocked */
2595 lnet_peer_addref_locked(lp);
2596 prepare_to_wait(&lp->lp_dc_waitq, &wait, TASK_INTERRUPTIBLE);
2597 if (signal_pending(current))
2599 if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING)
2602 * Don't repeat discovery if discovery is disabled. This is
2603 * done to ensure we can use discovery as a standard ping as
2604 * well for backwards compatibility with routers which do not
2605 * have discovery or have discovery disabled
2607 if (lnet_is_discovery_disabled(lp) && count > 0)
2609 if (lp->lp_dc_error)
2611 if (lnet_peer_is_uptodate(lp))
2613 lnet_peer_queue_for_discovery(lp);
2615 CDEBUG(D_NET, "Discovery attempt # %d\n", count);
2618 * If caller requested a non-blocking operation then
2619 * return immediately. Once discovery is complete any
2620 * pending messages that were stopped due to discovery
2621 * will be transmitted.
2626 lnet_net_unlock(LNET_LOCK_EX);
2628 finish_wait(&lp->lp_dc_waitq, &wait);
2629 lnet_net_lock(LNET_LOCK_EX);
2630 lnet_peer_decref_locked(lp);
2631 /* Peer may have changed */
2632 lp = lpni->lpni_peer_net->lpn_peer;
2634 finish_wait(&lp->lp_dc_waitq, &wait);
2636 lnet_net_unlock(LNET_LOCK_EX);
2638 lnet_peer_decref_locked(lp);
2640 * The peer may have changed, so re-check and rediscover if that turns
2641 * out to have been the case. The reference count on lp ensured that
2642 * even if it was unlinked from lpni the memory could not be recycled.
2643 * Thus the check below is sufficient to determine whether the peer
2644 * changed. If the peer changed, then lp must not be dereferenced.
2646 if (lp != lpni->lpni_peer_net->lpn_peer)
2649 if (signal_pending(current))
2651 else if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING)
2653 else if (lp->lp_dc_error)
2654 rc = lp->lp_dc_error;
2656 CDEBUG(D_NET, "non-blocking discovery\n");
2657 else if (!lnet_peer_is_uptodate(lp) && !lnet_is_discovery_disabled(lp))
2660 CDEBUG(D_NET, "peer %s NID %s: %d. %s\n",
2661 (lp ? libcfs_nidstr(&lp->lp_primary_nid) : "(none)"),
2662 libcfs_nidstr(&lpni->lpni_nid), rc,
2663 (!block) ? "pending discovery" : "discovery complete");
2668 /* Handle an incoming ack for a push. */
2670 lnet_discovery_event_ack(struct lnet_peer *lp, struct lnet_event *ev)
2672 struct lnet_ping_buffer *pbuf;
2674 pbuf = LNET_PING_INFO_TO_BUFFER(ev->md_start);
2675 spin_lock(&lp->lp_lock);
2676 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2677 lp->lp_push_error = ev->status;
2679 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2681 lp->lp_node_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2682 spin_unlock(&lp->lp_lock);
2684 CDEBUG(D_NET, "peer %s ev->status %d\n",
2685 libcfs_nidstr(&lp->lp_primary_nid), ev->status);
2688 /* Handle a Reply message. This is the reply to a Ping message. */
2690 lnet_discovery_event_reply(struct lnet_peer *lp, struct lnet_event *ev)
2692 struct lnet_ping_buffer *pbuf;
2695 spin_lock(&lp->lp_lock);
2697 lnet_nid4_to_nid(ev->target.nid, &lp->lp_disc_src_nid);
2698 lnet_nid4_to_nid(ev->source.nid, &lp->lp_disc_dst_nid);
2701 * If some kind of error happened the contents of message
2702 * cannot be used. Set PING_FAILED to trigger a retry.
2705 lp->lp_state |= LNET_PEER_PING_FAILED;
2706 lp->lp_ping_error = ev->status;
2707 CDEBUG(D_NET, "Ping Reply error %d from %s (source %s)\n",
2709 libcfs_nidstr(&lp->lp_primary_nid),
2710 libcfs_nid2str(ev->source.nid));
2714 pbuf = LNET_PING_INFO_TO_BUFFER(ev->md_start);
2715 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
2716 lnet_swap_pinginfo(pbuf);
2719 * A reply with invalid or corrupted info. Set PING_FAILED to
2722 rc = lnet_ping_info_validate(&pbuf->pb_info);
2724 lp->lp_state |= LNET_PEER_PING_FAILED;
2725 lp->lp_ping_error = 0;
2726 CDEBUG(D_NET, "Corrupted Ping Reply from %s: %d\n",
2727 libcfs_nidstr(&lp->lp_primary_nid), rc);
2732 * The peer may have discovery disabled at its end. Set
2733 * NO_DISCOVERY as appropriate.
2735 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_DISCOVERY) ||
2736 lnet_peer_discovery_disabled) {
2737 CDEBUG(D_NET, "Peer %s has discovery disabled\n",
2738 libcfs_nidstr(&lp->lp_primary_nid));
2740 /* Detect whether this peer has toggled discovery from on to
2741 * off and whether we can delete and re-create the peer. Peers
2742 * that were manually configured cannot be deleted by discovery.
2743 * We need to delete this peer and re-create it if the peer was
2744 * not configured manually, is currently considered DD capable,
2746 * 1. We've already discovered the peer (the peer has toggled
2747 * the discovery feature from on to off), or
2748 * 2. The peer is considered MR, but it was not user configured
2749 * (this was a "temporary" peer created via the kernel APIs
2750 * that we're discovering for the first time)
2752 if (!(lp->lp_state & (LNET_PEER_CONFIGURED |
2753 LNET_PEER_NO_DISCOVERY)) &&
2754 (lp->lp_state & (LNET_PEER_DISCOVERED |
2755 LNET_PEER_MULTI_RAIL))) {
2756 CDEBUG(D_NET, "Marking %s:0x%x for deletion\n",
2757 libcfs_nidstr(&lp->lp_primary_nid),
2759 lp->lp_state |= LNET_PEER_MARK_DELETION;
2761 lp->lp_state |= LNET_PEER_NO_DISCOVERY;
2763 CDEBUG(D_NET, "Peer %s has discovery enabled\n",
2764 libcfs_nidstr(&lp->lp_primary_nid));
2765 lp->lp_state &= ~LNET_PEER_NO_DISCOVERY;
2769 * Update the MULTI_RAIL flag based on the reply. If the peer
2770 * was configured with DLC then the setting should match what
2773 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL) {
2774 if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2775 CDEBUG(D_NET, "peer %s(%p) is MR\n",
2776 libcfs_nidstr(&lp->lp_primary_nid), lp);
2777 } else if (lp->lp_state & LNET_PEER_CONFIGURED) {
2778 CWARN("Reply says %s is Multi-Rail, DLC says not\n",
2779 libcfs_nidstr(&lp->lp_primary_nid));
2780 } else if (lnet_peer_discovery_disabled) {
2782 "peer %s(%p) not MR: DD disabled locally\n",
2783 libcfs_nidstr(&lp->lp_primary_nid), lp);
2784 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
2786 "peer %s(%p) not MR: DD disabled remotely\n",
2787 libcfs_nidstr(&lp->lp_primary_nid), lp);
2789 CDEBUG(D_NET, "peer %s(%p) is MR capable\n",
2790 libcfs_nidstr(&lp->lp_primary_nid), lp);
2791 lp->lp_state |= LNET_PEER_MULTI_RAIL;
2792 lnet_peer_clr_non_mr_pref_nids(lp);
2794 } else if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2795 if (lp->lp_state & LNET_PEER_CONFIGURED) {
2796 CWARN("DLC says %s is Multi-Rail, Reply says not\n",
2797 libcfs_nidstr(&lp->lp_primary_nid));
2799 CERROR("Multi-Rail state vanished from %s\n",
2800 libcfs_nidstr(&lp->lp_primary_nid));
2801 lp->lp_state &= ~LNET_PEER_MULTI_RAIL;
2806 * Make sure we'll allocate the correct size ping buffer when
2809 if (lp->lp_data_nnis < pbuf->pb_info.pi_nnis)
2810 lp->lp_data_nnis = pbuf->pb_info.pi_nnis;
2813 * Check for truncation of the Reply. Clear PING_SENT and set
2814 * PING_FAILED to trigger a retry.
2816 if (pbuf->pb_nnis < pbuf->pb_info.pi_nnis) {
2817 if (the_lnet.ln_push_target_nnis < pbuf->pb_info.pi_nnis)
2818 the_lnet.ln_push_target_nnis = pbuf->pb_info.pi_nnis;
2819 lp->lp_state |= LNET_PEER_PING_FAILED;
2820 lp->lp_ping_error = 0;
2821 CDEBUG(D_NET, "Truncated Reply from %s (%d nids)\n",
2822 libcfs_nidstr(&lp->lp_primary_nid),
2823 pbuf->pb_info.pi_nnis);
2828 * Check the sequence numbers in the reply. These are only
2829 * available if the reply came from a Multi-Rail peer.
2831 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL &&
2832 pbuf->pb_info.pi_nnis > 1 &&
2833 lnet_nid_to_nid4(&lp->lp_primary_nid) ==
2834 pbuf->pb_info.pi_ni[1].ns_nid) {
2835 if (LNET_PING_BUFFER_SEQNO(pbuf) < lp->lp_peer_seqno)
2836 CDEBUG(D_NET, "peer %s: seq# got %u have %u. peer rebooted?\n",
2837 libcfs_nidstr(&lp->lp_primary_nid),
2838 LNET_PING_BUFFER_SEQNO(pbuf),
2841 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2844 /* We're happy with the state of the data in the buffer. */
2845 CDEBUG(D_NET, "peer %s data present %u. state = 0x%x\n",
2846 libcfs_nidstr(&lp->lp_primary_nid), lp->lp_peer_seqno,
2848 if (lp->lp_state & LNET_PEER_DATA_PRESENT)
2849 lnet_ping_buffer_decref(lp->lp_data);
2851 lp->lp_state |= LNET_PEER_DATA_PRESENT;
2852 lnet_ping_buffer_addref(pbuf);
2855 lp->lp_state &= ~LNET_PEER_PING_SENT;
2856 spin_unlock(&lp->lp_lock);
2858 lnet_net_lock(LNET_LOCK_EX);
2860 * If this peer is a gateway, call the routing callback to
2861 * handle the ping reply
2863 if (lp->lp_rtr_refcount > 0)
2864 lnet_router_discovery_ping_reply(lp);
2865 lnet_net_unlock(LNET_LOCK_EX);
2869 * Send event handling. Only matters for error cases, where we clean
2870 * up state on the peer and peer_ni that would otherwise be updated in
2871 * the REPLY event handler for a successful Ping, and the ACK event
2872 * handler for a successful Push.
2875 lnet_discovery_event_send(struct lnet_peer *lp, struct lnet_event *ev)
2882 spin_lock(&lp->lp_lock);
2883 if (ev->msg_type == LNET_MSG_GET) {
2884 lp->lp_state &= ~LNET_PEER_PING_SENT;
2885 lp->lp_state |= LNET_PEER_PING_FAILED;
2886 lp->lp_ping_error = ev->status;
2887 } else { /* ev->msg_type == LNET_MSG_PUT */
2888 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2889 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2890 lp->lp_push_error = ev->status;
2892 spin_unlock(&lp->lp_lock);
2893 rc = LNET_REDISCOVER_PEER;
2895 CDEBUG(D_NET, "%s Send to %s: %d\n",
2896 (ev->msg_type == LNET_MSG_GET ? "Ping" : "Push"),
2897 libcfs_nid2str(ev->target.nid), rc);
2902 * Unlink event handling. This event is only seen if a call to
2903 * LNetMDUnlink() caused the event to be unlinked. If this call was
2904 * made after the event was set up in LNetGet() or LNetPut() then we
2905 * assume the Ping or Push timed out.
2908 lnet_discovery_event_unlink(struct lnet_peer *lp, struct lnet_event *ev)
2910 spin_lock(&lp->lp_lock);
2911 /* We've passed through LNetGet() */
2912 if (lp->lp_state & LNET_PEER_PING_SENT) {
2913 lp->lp_state &= ~LNET_PEER_PING_SENT;
2914 lp->lp_state |= LNET_PEER_PING_FAILED;
2915 lp->lp_ping_error = -ETIMEDOUT;
2916 CDEBUG(D_NET, "Ping Unlink for message to peer %s\n",
2917 libcfs_nidstr(&lp->lp_primary_nid));
2919 /* We've passed through LNetPut() */
2920 if (lp->lp_state & LNET_PEER_PUSH_SENT) {
2921 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2922 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2923 lp->lp_push_error = -ETIMEDOUT;
2924 CDEBUG(D_NET, "Push Unlink for message to peer %s\n",
2925 libcfs_nidstr(&lp->lp_primary_nid));
2927 spin_unlock(&lp->lp_lock);
2931 * Event handler for the discovery EQ.
2933 * Called with lnet_res_lock(cpt) held. The cpt is the
2934 * lnet_cpt_of_cookie() of the md handle cookie.
2936 static void lnet_discovery_event_handler(struct lnet_event *event)
2938 struct lnet_peer *lp = event->md_user_ptr;
2939 struct lnet_ping_buffer *pbuf;
2942 /* discovery needs to take another look */
2943 rc = LNET_REDISCOVER_PEER;
2945 CDEBUG(D_NET, "Received event: %d\n", event->type);
2947 switch (event->type) {
2948 case LNET_EVENT_ACK:
2949 lnet_discovery_event_ack(lp, event);
2951 case LNET_EVENT_REPLY:
2952 lnet_discovery_event_reply(lp, event);
2954 case LNET_EVENT_SEND:
2955 /* Only send failure triggers a retry. */
2956 rc = lnet_discovery_event_send(lp, event);
2958 case LNET_EVENT_UNLINK:
2959 /* LNetMDUnlink() was called */
2960 lnet_discovery_event_unlink(lp, event);
2963 /* Invalid events. */
2966 lnet_net_lock(LNET_LOCK_EX);
2967 if (event->unlinked) {
2968 pbuf = LNET_PING_INFO_TO_BUFFER(event->md_start);
2969 lnet_ping_buffer_decref(pbuf);
2970 lnet_peer_decref_locked(lp);
2973 /* put peer back at end of request queue, if discovery not already
2975 if (rc == LNET_REDISCOVER_PEER && !lnet_peer_is_uptodate(lp) &&
2976 lnet_peer_queue_for_discovery(lp)) {
2977 list_move_tail(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2978 wake_up(&the_lnet.ln_dc_waitq);
2980 lnet_net_unlock(LNET_LOCK_EX);
2984 * Build a peer from incoming data.
2986 * The NIDs in the incoming data are supposed to be structured as follows:
2989 * - other NIDs in same net
2990 * - NIDs in second net
2991 * - NIDs in third net
2993 * This due to the way the list of NIDs in the data is created.
2995 * Note that this function will mark the peer uptodate unless an
2996 * ENOMEM is encontered. All other errors are due to a conflict
2997 * between the DLC configuration and what discovery sees. We treat DLC
2998 * as binding, and therefore set the NIDS_UPTODATE flag to prevent the
2999 * peer from becoming stuck in discovery.
3001 static int lnet_peer_merge_data(struct lnet_peer *lp,
3002 struct lnet_ping_buffer *pbuf)
3004 struct lnet_peer_net *lpn;
3005 struct lnet_peer_ni *lpni;
3006 lnet_nid_t *curnis = NULL;
3007 struct lnet_ni_status *addnis = NULL;
3008 lnet_nid_t *delnis = NULL;
3018 flags = LNET_PEER_DISCOVERED;
3019 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)
3020 flags |= LNET_PEER_MULTI_RAIL;
3023 * Cache the routing feature for the peer; whether it is enabled
3024 * for disabled as reported by the remote peer.
3026 spin_lock(&lp->lp_lock);
3027 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_RTE_DISABLED))
3028 lp->lp_state |= LNET_PEER_ROUTER_ENABLED;
3030 lp->lp_state &= ~LNET_PEER_ROUTER_ENABLED;
3031 spin_unlock(&lp->lp_lock);
3033 nnis = max_t(int, lp->lp_nnis, pbuf->pb_info.pi_nnis);
3034 CFS_ALLOC_PTR_ARRAY(curnis, nnis);
3035 CFS_ALLOC_PTR_ARRAY(addnis, nnis);
3036 CFS_ALLOC_PTR_ARRAY(delnis, nnis);
3037 if (!curnis || !addnis || !delnis) {
3045 /* Construct the list of NIDs present in peer. */
3047 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
3048 curnis[ncurnis++] = lnet_nid_to_nid4(&lpni->lpni_nid);
3051 * Check for NIDs in pbuf not present in curnis[].
3052 * The loop starts at 1 to skip the loopback NID.
3054 for (i = 1; i < pbuf->pb_info.pi_nnis; i++) {
3055 for (j = 0; j < ncurnis; j++)
3056 if (pbuf->pb_info.pi_ni[i].ns_nid == curnis[j])
3059 addnis[naddnis++] = pbuf->pb_info.pi_ni[i];
3062 * Check for NIDs in curnis[] not present in pbuf.
3063 * The nested loop starts at 1 to skip the loopback NID.
3065 * But never add the loopback NID to delnis[]: if it is
3066 * present in curnis[] then this peer is for this node.
3068 for (i = 0; i < ncurnis; i++) {
3069 if (curnis[i] == LNET_NID_LO_0)
3071 for (j = 1; j < pbuf->pb_info.pi_nnis; j++) {
3072 if (curnis[i] == pbuf->pb_info.pi_ni[j].ns_nid) {
3074 * update the information we cache for the
3075 * peer with the latest information we
3078 lpni = lnet_find_peer_ni_locked(curnis[i]);
3080 lpni->lpni_ns_status = pbuf->pb_info.pi_ni[j].ns_status;
3081 lnet_peer_ni_decref_locked(lpni);
3086 if (j == pbuf->pb_info.pi_nnis)
3087 delnis[ndelnis++] = curnis[i];
3091 * If we get here and the discovery is disabled then we don't want
3092 * to add or delete any NIs. We just updated the ones we have some
3093 * information on, and call it a day
3096 if (lnet_is_discovery_disabled(lp))
3099 for (i = 0; i < naddnis; i++) {
3100 rc = lnet_peer_add_nid(lp, addnis[i].ns_nid, flags);
3102 CERROR("Error adding NID %s to peer %s: %d\n",
3103 libcfs_nid2str(addnis[i].ns_nid),
3104 libcfs_nidstr(&lp->lp_primary_nid), rc);
3108 lpni = lnet_find_peer_ni_locked(addnis[i].ns_nid);
3110 lpni->lpni_ns_status = addnis[i].ns_status;
3111 lnet_peer_ni_decref_locked(lpni);
3115 for (i = 0; i < ndelnis; i++) {
3117 * for routers it's okay to delete the primary_nid because
3118 * the upper layers don't really rely on it. So if we're
3119 * being told that the router changed its primary_nid
3120 * then it's okay to delete it.
3122 if (lp->lp_rtr_refcount > 0)
3123 flags |= LNET_PEER_RTR_NI_FORCE_DEL;
3124 rc = lnet_peer_del_nid(lp, delnis[i], flags);
3126 CERROR("Error deleting NID %s from peer %s: %d\n",
3127 libcfs_nid2str(delnis[i]),
3128 libcfs_nidstr(&lp->lp_primary_nid), rc);
3134 /* The peer net for the primary NID should be the first entry in the
3135 * peer's lp_peer_nets list, and the peer NI for the primary NID should
3136 * be the first entry in its peer net's lpn_peer_nis list.
3138 lpni = lnet_find_peer_ni_locked(pbuf->pb_info.pi_ni[1].ns_nid);
3140 CERROR("Internal error: Failed to lookup peer NI for primary NID: %s\n",
3141 libcfs_nid2str(pbuf->pb_info.pi_ni[1].ns_nid));
3145 lnet_peer_ni_decref_locked(lpni);
3147 lpn = lpni->lpni_peer_net;
3148 if (lpn->lpn_peer_nets.prev != &lp->lp_peer_nets)
3149 list_move(&lpn->lpn_peer_nets, &lp->lp_peer_nets);
3151 if (lpni->lpni_peer_nis.prev != &lpni->lpni_peer_net->lpn_peer_nis)
3152 list_move(&lpni->lpni_peer_nis,
3153 &lpni->lpni_peer_net->lpn_peer_nis);
3156 * Errors other than -ENOMEM are due to peers having been
3157 * configured with DLC. Ignore these because DLC overrides
3162 CFS_FREE_PTR_ARRAY(curnis, nnis);
3163 CFS_FREE_PTR_ARRAY(addnis, nnis);
3164 CFS_FREE_PTR_ARRAY(delnis, nnis);
3165 lnet_ping_buffer_decref(pbuf);
3166 CDEBUG(D_NET, "peer %s (%p): %d\n",
3167 libcfs_nidstr(&lp->lp_primary_nid), lp, rc);
3170 spin_lock(&lp->lp_lock);
3171 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
3172 lp->lp_state |= LNET_PEER_FORCE_PING;
3173 spin_unlock(&lp->lp_lock);
3179 * The data in pbuf says lp is its primary peer, but the data was
3180 * received by a different peer. Try to update lp with the data.
3183 lnet_peer_set_primary_data(struct lnet_peer *lp, struct lnet_ping_buffer *pbuf)
3185 struct lnet_handle_md mdh;
3187 /* Queue lp for discovery, and force it on the request queue. */
3188 lnet_net_lock(LNET_LOCK_EX);
3189 if (lnet_peer_queue_for_discovery(lp))
3190 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_request);
3191 lnet_net_unlock(LNET_LOCK_EX);
3193 LNetInvalidateMDHandle(&mdh);
3196 * Decide whether we can move the peer to the DATA_PRESENT state.
3198 * We replace stale data for a multi-rail peer, repair PING_FAILED
3199 * status, and preempt FORCE_PING.
3201 * If after that we have DATA_PRESENT, we merge it into this peer.
3203 spin_lock(&lp->lp_lock);
3204 if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
3205 if (lp->lp_peer_seqno < LNET_PING_BUFFER_SEQNO(pbuf)) {
3206 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
3207 } else if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
3208 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
3209 lnet_ping_buffer_decref(pbuf);
3214 if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
3215 lnet_ping_buffer_decref(lp->lp_data);
3217 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
3219 if (lp->lp_state & LNET_PEER_PING_FAILED) {
3220 mdh = lp->lp_ping_mdh;
3221 LNetInvalidateMDHandle(&lp->lp_ping_mdh);
3222 lp->lp_state &= ~LNET_PEER_PING_FAILED;
3223 lp->lp_ping_error = 0;
3225 if (lp->lp_state & LNET_PEER_FORCE_PING)
3226 lp->lp_state &= ~LNET_PEER_FORCE_PING;
3227 lp->lp_state |= LNET_PEER_NIDS_UPTODATE;
3228 spin_unlock(&lp->lp_lock);
3230 if (!LNetMDHandleIsInvalid(mdh))
3234 return lnet_peer_merge_data(lp, pbuf);
3236 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3240 static bool lnet_is_nid_in_ping_info(lnet_nid_t nid, struct lnet_ping_info *pinfo)
3244 for (i = 0; i < pinfo->pi_nnis; i++) {
3245 if (pinfo->pi_ni[i].ns_nid == nid)
3252 /* Delete a peer that has been marked for deletion. NB: when this peer was added
3253 * to the discovery queue a reference was taken that will prevent the peer from
3254 * actually being freed by this function. After this function exits the
3255 * discovery thread should call lnet_peer_discovery_complete() which will
3256 * drop that reference as well as wake any waiters that may also be holding a
3259 static int lnet_peer_deletion(struct lnet_peer *lp)
3260 __must_hold(&lp->lp_lock)
3262 struct list_head rlist;
3263 struct lnet_route *route, *tmp;
3264 int sensitivity = lp->lp_health_sensitivity;
3267 INIT_LIST_HEAD(&rlist);
3269 lp->lp_state &= ~(LNET_PEER_DISCOVERING | LNET_PEER_FORCE_PING |
3270 LNET_PEER_FORCE_PUSH);
3271 CDEBUG(D_NET, "peer %s(%p) state %#x\n",
3272 libcfs_nidstr(&lp->lp_primary_nid), lp, lp->lp_state);
3274 /* no-op if lnet_peer_del() has already been called on this peer */
3275 if (lp->lp_state & LNET_PEER_MARK_DELETED)
3278 if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING)
3281 spin_unlock(&lp->lp_lock);
3283 mutex_lock(&the_lnet.ln_api_mutex);
3285 lnet_net_lock(LNET_LOCK_EX);
3286 /* remove the peer from the discovery work
3287 * queue if it's on there in preparation
3290 if (!list_empty(&lp->lp_dc_list))
3291 list_del_init(&lp->lp_dc_list);
3292 list_for_each_entry_safe(route, tmp,
3295 lnet_move_route(route, NULL, &rlist);
3296 lnet_net_unlock(LNET_LOCK_EX);
3298 /* lnet_peer_del() deletes all the peer NIs owned by this peer */
3299 rc = lnet_peer_del(lp);
3301 CNETERR("Internal error: Unable to delete peer %s rc %d\n",
3302 libcfs_nidstr(&lp->lp_primary_nid), rc);
3304 list_for_each_entry_safe(route, tmp,
3306 /* re-add these routes */
3307 lnet_add_route(route->lr_net,
3312 LIBCFS_FREE(route, sizeof(*route));
3315 mutex_unlock(&the_lnet.ln_api_mutex);
3317 spin_lock(&lp->lp_lock);
3323 * Update a peer using the data received.
3325 static int lnet_peer_data_present(struct lnet_peer *lp)
3326 __must_hold(&lp->lp_lock)
3328 struct lnet_ping_buffer *pbuf;
3329 struct lnet_peer_ni *lpni;
3330 lnet_nid_t nid = LNET_NID_ANY;
3336 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
3337 lp->lp_state |= LNET_PEER_NIDS_UPTODATE;
3338 spin_unlock(&lp->lp_lock);
3341 * Modifications of peer structures are done while holding the
3342 * ln_api_mutex. A global lock is required because we may be
3343 * modifying multiple peer structures, and a mutex greatly
3344 * simplifies memory management.
3346 * The actual changes to the data structures must also protect
3347 * against concurrent lookups, for which the lnet_net_lock in
3348 * LNET_LOCK_EX mode is used.
3350 mutex_lock(&the_lnet.ln_api_mutex);
3351 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3357 * If this peer is not on the peer list then it is being torn
3358 * down, and our reference count may be all that is keeping it
3359 * alive. Don't do any work on it.
3361 if (list_empty(&lp->lp_peer_list))
3364 flags = LNET_PEER_DISCOVERED;
3365 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)
3366 flags |= LNET_PEER_MULTI_RAIL;
3369 * Check whether the primary NID in the message matches the
3370 * primary NID of the peer. If it does, update the peer, if
3371 * it it does not, check whether there is already a peer with
3372 * that primary NID. If no such peer exists, try to update
3373 * the primary NID of the current peer (allowed if it was
3374 * created due to message traffic) and complete the update.
3375 * If the peer did exist, hand off the data to it.
3377 * The peer for the loopback interface is a special case: this
3378 * is the peer for the local node, and we want to set its
3379 * primary NID to the correct value here. Moreover, this peer
3380 * can show up with only the loopback NID in the ping buffer.
3382 if (pbuf->pb_info.pi_nnis <= 1)
3384 nid = pbuf->pb_info.pi_ni[1].ns_nid;
3385 if (nid_is_lo0(&lp->lp_primary_nid)) {
3386 rc = lnet_peer_set_primary_nid(lp, nid, flags);
3388 rc = lnet_peer_merge_data(lp, pbuf);
3390 * if the primary nid of the peer is present in the ping info returned
3391 * from the peer, but it's not the local primary peer we have
3392 * cached and discovery is disabled, then we don't want to update
3393 * our local peer info, by adding or removing NIDs, we just want
3394 * to update the status of the nids that we currently have
3395 * recorded in that peer.
3397 } else if (lnet_nid_to_nid4(&lp->lp_primary_nid) == nid ||
3398 (lnet_is_nid_in_ping_info(lnet_nid_to_nid4(&lp->lp_primary_nid),
3400 lnet_is_discovery_disabled(lp))) {
3401 rc = lnet_peer_merge_data(lp, pbuf);
3403 lpni = lnet_find_peer_ni_locked(nid);
3404 if (!lpni || lp == lpni->lpni_peer_net->lpn_peer) {
3405 rc = lnet_peer_set_primary_nid(lp, nid, flags);
3407 CERROR("Primary NID error %s versus %s: %d\n",
3408 libcfs_nidstr(&lp->lp_primary_nid),
3409 libcfs_nid2str(nid), rc);
3411 rc = lnet_peer_merge_data(lp, pbuf);
3414 lnet_peer_ni_decref_locked(lpni);
3416 struct lnet_peer *new_lp;
3417 new_lp = lpni->lpni_peer_net->lpn_peer;
3419 * if lp has discovery/MR enabled that means new_lp
3420 * should have discovery/MR enabled as well, since
3421 * it's the same peer, which we're about to merge
3423 spin_lock(&lp->lp_lock);
3424 spin_lock(&new_lp->lp_lock);
3425 if (!(lp->lp_state & LNET_PEER_NO_DISCOVERY))
3426 new_lp->lp_state &= ~LNET_PEER_NO_DISCOVERY;
3427 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
3428 new_lp->lp_state |= LNET_PEER_MULTI_RAIL;
3429 /* If we're processing a ping reply then we may be
3430 * about to send a push to the peer that we ping'd.
3431 * Since the ping reply that we're processing was
3432 * received by lp, we need to set the discovery source
3433 * NID for new_lp to the NID stored in lp.
3435 if (!LNET_NID_IS_ANY(&lp->lp_disc_src_nid)) {
3436 new_lp->lp_disc_src_nid = lp->lp_disc_src_nid;
3437 new_lp->lp_disc_dst_nid = lp->lp_disc_dst_nid;
3439 spin_unlock(&new_lp->lp_lock);
3440 spin_unlock(&lp->lp_lock);
3442 rc = lnet_peer_set_primary_data(new_lp, pbuf);
3443 lnet_consolidate_routes_locked(lp, new_lp);
3444 lnet_peer_ni_decref_locked(lpni);
3448 CDEBUG(D_NET, "peer %s(%p): %d. state = 0x%x\n",
3449 libcfs_nidstr(&lp->lp_primary_nid), lp, rc,
3451 mutex_unlock(&the_lnet.ln_api_mutex);
3453 spin_lock(&lp->lp_lock);
3454 /* Tell discovery to re-check the peer immediately. */
3456 rc = LNET_REDISCOVER_PEER;
3461 * A ping failed. Clear the PING_FAILED state and set the
3462 * FORCE_PING state, to ensure a retry even if discovery is
3463 * disabled. This avoids being left with incorrect state.
3465 static int lnet_peer_ping_failed(struct lnet_peer *lp)
3466 __must_hold(&lp->lp_lock)
3468 struct lnet_handle_md mdh;
3471 mdh = lp->lp_ping_mdh;
3472 LNetInvalidateMDHandle(&lp->lp_ping_mdh);
3473 lp->lp_state &= ~LNET_PEER_PING_FAILED;
3474 lp->lp_state |= LNET_PEER_FORCE_PING;
3475 rc = lp->lp_ping_error;
3476 lp->lp_ping_error = 0;
3477 spin_unlock(&lp->lp_lock);
3479 if (!LNetMDHandleIsInvalid(mdh))
3482 CDEBUG(D_NET, "peer %s:%d\n",
3483 libcfs_nidstr(&lp->lp_primary_nid), rc);
3485 spin_lock(&lp->lp_lock);
3486 return rc ? rc : LNET_REDISCOVER_PEER;
3489 /* Active side of ping. */
3490 static int lnet_peer_send_ping(struct lnet_peer *lp)
3491 __must_hold(&lp->lp_lock)
3497 lp->lp_state |= LNET_PEER_PING_SENT;
3498 lp->lp_state &= ~LNET_PEER_FORCE_PING;
3499 spin_unlock(&lp->lp_lock);
3501 cpt = lnet_net_lock_current();
3502 /* Refcount for MD. */
3503 lnet_peer_addref_locked(lp);
3504 lnet_net_unlock(cpt);
3506 nnis = max(lp->lp_data_nnis, LNET_INTERFACES_MIN);
3508 rc = lnet_send_ping(lnet_nid_to_nid4(&lp->lp_primary_nid),
3509 &lp->lp_ping_mdh, nnis, lp,
3510 the_lnet.ln_dc_handler, false);
3513 * if LNetMDBind in lnet_send_ping fails we need to decrement the
3514 * refcount on the peer, otherwise LNetMDUnlink will be called
3515 * which will eventually do that.
3519 lnet_peer_decref_locked(lp);
3520 lnet_net_unlock(cpt);
3521 rc = -rc; /* change the rc to negative value */
3523 } else if (rc < 0) {
3527 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3529 spin_lock(&lp->lp_lock);
3533 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nidstr(&lp->lp_primary_nid), rc);
3535 * The errors that get us here are considered hard errors and
3536 * cause Discovery to terminate. So we clear PING_SENT, but do
3537 * not set either PING_FAILED or FORCE_PING. In fact we need
3538 * to clear PING_FAILED, because the unlink event handler will
3539 * have set it if we called LNetMDUnlink() above.
3541 spin_lock(&lp->lp_lock);
3542 lp->lp_state &= ~(LNET_PEER_PING_SENT | LNET_PEER_PING_FAILED);
3547 * This function exists because you cannot call LNetMDUnlink() from an
3550 static int lnet_peer_push_failed(struct lnet_peer *lp)
3551 __must_hold(&lp->lp_lock)
3553 struct lnet_handle_md mdh;
3556 mdh = lp->lp_push_mdh;
3557 LNetInvalidateMDHandle(&lp->lp_push_mdh);
3558 lp->lp_state &= ~LNET_PEER_PUSH_FAILED;
3559 rc = lp->lp_push_error;
3560 lp->lp_push_error = 0;
3561 spin_unlock(&lp->lp_lock);
3563 if (!LNetMDHandleIsInvalid(mdh))
3566 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3567 spin_lock(&lp->lp_lock);
3568 return rc ? rc : LNET_REDISCOVER_PEER;
3572 * Mark the peer as discovered.
3574 static int lnet_peer_discovered(struct lnet_peer *lp)
3575 __must_hold(&lp->lp_lock)
3577 lp->lp_state |= LNET_PEER_DISCOVERED;
3578 lp->lp_state &= ~(LNET_PEER_DISCOVERING |
3579 LNET_PEER_REDISCOVER);
3581 lp->lp_dc_error = 0;
3583 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3588 /* Active side of push. */
3589 static int lnet_peer_send_push(struct lnet_peer *lp)
3590 __must_hold(&lp->lp_lock)
3592 struct lnet_ping_buffer *pbuf;
3593 struct lnet_process_id id;
3598 /* Don't push to a non-multi-rail peer. */
3599 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
3600 lp->lp_state &= ~LNET_PEER_FORCE_PUSH;
3601 /* if peer's NIDs are uptodate then peer is discovered */
3602 if (lp->lp_state & LNET_PEER_NIDS_UPTODATE) {
3603 rc = lnet_peer_discovered(lp);
3610 lp->lp_state |= LNET_PEER_PUSH_SENT;
3611 lp->lp_state &= ~LNET_PEER_FORCE_PUSH;
3612 spin_unlock(&lp->lp_lock);
3614 cpt = lnet_net_lock_current();
3615 pbuf = the_lnet.ln_ping_target;
3616 lnet_ping_buffer_addref(pbuf);
3617 lnet_net_unlock(cpt);
3619 /* Push source MD */
3620 md.start = &pbuf->pb_info;
3621 md.length = LNET_PING_INFO_SIZE(pbuf->pb_nnis);
3622 md.threshold = 2; /* Put/Ack */
3624 md.options = LNET_MD_TRACK_RESPONSE;
3625 md.handler = the_lnet.ln_dc_handler;
3628 rc = LNetMDBind(&md, LNET_UNLINK, &lp->lp_push_mdh);
3630 lnet_ping_buffer_decref(pbuf);
3631 CERROR("Can't bind push source MD: %d\n", rc);
3635 cpt = lnet_net_lock_current();
3636 /* Refcount for MD. */
3637 lnet_peer_addref_locked(lp);
3638 id.pid = LNET_PID_LUSTRE;
3639 if (!LNET_NID_IS_ANY(&lp->lp_disc_dst_nid))
3640 id.nid = lnet_nid_to_nid4(&lp->lp_disc_dst_nid);
3642 id.nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
3643 lnet_net_unlock(cpt);
3645 rc = LNetPut(lnet_nid_to_nid4(&lp->lp_disc_src_nid), lp->lp_push_mdh,
3646 LNET_ACK_REQ, id, LNET_RESERVED_PORTAL,
3647 LNET_PROTO_PING_MATCHBITS, 0, 0);
3650 * reset the discovery nid. There is no need to restrict sending
3651 * from that source, if we call lnet_push_update_to_peers(). It'll
3652 * get set to a specific NID, if we initiate discovery from the
3655 lp->lp_disc_src_nid = LNET_ANY_NID;
3656 lp->lp_disc_dst_nid = LNET_ANY_NID;
3661 CDEBUG(D_NET, "peer %s\n", libcfs_nidstr(&lp->lp_primary_nid));
3663 spin_lock(&lp->lp_lock);
3667 LNetMDUnlink(lp->lp_push_mdh);
3668 LNetInvalidateMDHandle(&lp->lp_push_mdh);
3670 CDEBUG(D_NET, "peer %s(%p): %d\n", libcfs_nidstr(&lp->lp_primary_nid),
3673 * The errors that get us here are considered hard errors and
3674 * cause Discovery to terminate. So we clear PUSH_SENT, but do
3675 * not set PUSH_FAILED. In fact we need to clear PUSH_FAILED,
3676 * because the unlink event handler will have set it if we
3677 * called LNetMDUnlink() above.
3679 spin_lock(&lp->lp_lock);
3680 lp->lp_state &= ~(LNET_PEER_PUSH_SENT | LNET_PEER_PUSH_FAILED);
3685 * An unrecoverable error was encountered during discovery.
3686 * Set error status in peer and abort discovery.
3688 static void lnet_peer_discovery_error(struct lnet_peer *lp, int error)
3690 CDEBUG(D_NET, "Discovery error %s: %d\n",
3691 libcfs_nidstr(&lp->lp_primary_nid), error);
3693 spin_lock(&lp->lp_lock);
3694 lp->lp_dc_error = error;
3695 lp->lp_state &= ~LNET_PEER_DISCOVERING;
3696 lp->lp_state |= LNET_PEER_REDISCOVER;
3697 spin_unlock(&lp->lp_lock);
3701 * Wait for work to be queued or some other change that must be
3702 * attended to. Returns non-zero if the discovery thread should shut
3705 static int lnet_peer_discovery_wait_for_work(void)
3712 cpt = lnet_net_lock_current();
3714 prepare_to_wait(&the_lnet.ln_dc_waitq, &wait,
3715 TASK_INTERRUPTIBLE);
3716 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3718 if (lnet_push_target_resize_needed() ||
3719 the_lnet.ln_push_target->pb_needs_post)
3721 if (!list_empty(&the_lnet.ln_dc_request))
3723 if (!list_empty(&the_lnet.ln_msg_resend))
3725 lnet_net_unlock(cpt);
3728 * wakeup max every second to check if there are peers that
3729 * have been stuck on the working queue for greater than
3732 schedule_timeout(cfs_time_seconds(1));
3733 finish_wait(&the_lnet.ln_dc_waitq, &wait);
3734 cpt = lnet_net_lock_current();
3736 finish_wait(&the_lnet.ln_dc_waitq, &wait);
3738 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3741 lnet_net_unlock(cpt);
3743 CDEBUG(D_NET, "woken: %d\n", rc);
3749 * Messages that were pending on a destroyed peer will be put on a global
3750 * resend list. The message resend list will be checked by
3751 * the discovery thread when it wakes up, and will resend messages. These
3752 * messages can still be sendable in the case the lpni which was the initial
3753 * cause of the message re-queue was transfered to another peer.
3755 * It is possible that LNet could be shutdown while we're iterating
3756 * through the list. lnet_shudown_lndnets() will attempt to access the
3757 * resend list, but will have to wait until the spinlock is released, by
3758 * which time there shouldn't be any more messages on the resend list.
3759 * During shutdown lnet_send() will fail and lnet_finalize() will be called
3760 * for the messages so they can be released. The other case is that
3761 * lnet_shudown_lndnets() can finalize all the messages before this
3762 * function can visit the resend list, in which case this function will be
3765 static void lnet_resend_msgs(void)
3767 struct lnet_msg *msg, *tmp;
3771 spin_lock(&the_lnet.ln_msg_resend_lock);
3772 list_splice(&the_lnet.ln_msg_resend, &resend);
3773 spin_unlock(&the_lnet.ln_msg_resend_lock);
3775 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
3776 list_del_init(&msg->msg_list);
3777 rc = lnet_send(msg->msg_src_nid_param, msg,
3778 msg->msg_rtr_nid_param);
3780 CNETERR("Error sending %s to %s: %d\n",
3781 lnet_msgtyp2str(msg->msg_type),
3782 libcfs_id2str(msg->msg_target), rc);
3783 lnet_finalize(msg, rc);
3788 /* The discovery thread. */
3789 static int lnet_peer_discovery(void *arg)
3791 struct lnet_peer *lp;
3794 wait_for_completion(&the_lnet.ln_started);
3796 CDEBUG(D_NET, "started\n");
3799 if (lnet_peer_discovery_wait_for_work())
3802 if (lnet_push_target_resize_needed())
3803 lnet_push_target_resize();
3804 else if (the_lnet.ln_push_target->pb_needs_post)
3805 lnet_push_target_post(the_lnet.ln_push_target,
3806 &the_lnet.ln_push_target_md);
3810 lnet_net_lock(LNET_LOCK_EX);
3811 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING) {
3812 lnet_net_unlock(LNET_LOCK_EX);
3817 * Process all incoming discovery work requests. When
3818 * discovery must wait on a peer to change state, it
3819 * is added to the tail of the ln_dc_working queue. A
3820 * timestamp keeps track of when the peer was added,
3821 * so we can time out discovery requests that take too
3824 while (!list_empty(&the_lnet.ln_dc_request)) {
3825 lp = list_first_entry(&the_lnet.ln_dc_request,
3826 struct lnet_peer, lp_dc_list);
3827 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_working);
3829 * set the time the peer was put on the dc_working
3830 * queue. It shouldn't remain on the queue
3831 * forever, in case the GET message (for ping)
3832 * doesn't get a REPLY or the PUT message (for
3833 * push) doesn't get an ACK.
3835 lp->lp_last_queued = ktime_get_real_seconds();
3836 lnet_net_unlock(LNET_LOCK_EX);
3838 if (lnet_push_target_resize_needed())
3839 lnet_push_target_resize();
3840 else if (the_lnet.ln_push_target->pb_needs_post)
3841 lnet_push_target_post(the_lnet.ln_push_target,
3842 &the_lnet.ln_push_target_md);
3845 * Select an action depending on the state of
3846 * the peer and whether discovery is disabled.
3847 * The check whether discovery is disabled is
3848 * done after the code that handles processing
3849 * for arrived data, cleanup for failures, and
3850 * forcing a Ping or Push.
3852 spin_lock(&lp->lp_lock);
3853 CDEBUG(D_NET, "peer %s(%p) state %#x\n",
3854 libcfs_nidstr(&lp->lp_primary_nid), lp,
3856 if (lp->lp_state & (LNET_PEER_MARK_DELETION |
3857 LNET_PEER_MARK_DELETED))
3858 rc = lnet_peer_deletion(lp);
3859 else if (lp->lp_state & LNET_PEER_DATA_PRESENT)
3860 rc = lnet_peer_data_present(lp);
3861 else if (lp->lp_state & LNET_PEER_PING_FAILED)
3862 rc = lnet_peer_ping_failed(lp);
3863 else if (lp->lp_state & LNET_PEER_PUSH_FAILED)
3864 rc = lnet_peer_push_failed(lp);
3865 else if (lp->lp_state & LNET_PEER_FORCE_PING)
3866 rc = lnet_peer_send_ping(lp);
3867 else if (lp->lp_state & LNET_PEER_FORCE_PUSH)
3868 rc = lnet_peer_send_push(lp);
3869 else if (!(lp->lp_state & LNET_PEER_NIDS_UPTODATE))
3870 rc = lnet_peer_send_ping(lp);
3871 else if (lnet_peer_needs_push(lp))
3872 rc = lnet_peer_send_push(lp);
3874 rc = lnet_peer_discovered(lp);
3875 CDEBUG(D_NET, "peer %s(%p) state %#x rc %d\n",
3876 libcfs_nidstr(&lp->lp_primary_nid), lp,
3878 spin_unlock(&lp->lp_lock);
3880 lnet_net_lock(LNET_LOCK_EX);
3881 if (rc == LNET_REDISCOVER_PEER) {
3882 list_move(&lp->lp_dc_list,
3883 &the_lnet.ln_dc_request);
3885 lnet_peer_discovery_error(lp, rc);
3887 if (!(lp->lp_state & LNET_PEER_DISCOVERING))
3888 lnet_peer_discovery_complete(lp);
3889 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3894 lnet_net_unlock(LNET_LOCK_EX);
3897 CDEBUG(D_NET, "stopping\n");
3899 * Clean up before telling lnet_peer_discovery_stop() that
3900 * we're done. Use wake_up() below to somewhat reduce the
3901 * size of the thundering herd if there are multiple threads
3902 * waiting on discovery of a single peer.
3905 /* Queue cleanup 1: stop all pending pings and pushes. */
3906 lnet_net_lock(LNET_LOCK_EX);
3907 while (!list_empty(&the_lnet.ln_dc_working)) {
3908 lp = list_first_entry(&the_lnet.ln_dc_working,
3909 struct lnet_peer, lp_dc_list);
3910 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_expired);
3911 lnet_net_unlock(LNET_LOCK_EX);
3912 lnet_peer_cancel_discovery(lp);
3913 lnet_net_lock(LNET_LOCK_EX);
3915 lnet_net_unlock(LNET_LOCK_EX);
3917 /* Queue cleanup 2: wait for the expired queue to clear. */
3918 while (!list_empty(&the_lnet.ln_dc_expired))
3919 schedule_timeout_uninterruptible(cfs_time_seconds(1));
3921 /* Queue cleanup 3: clear the request queue. */
3922 lnet_net_lock(LNET_LOCK_EX);
3923 while (!list_empty(&the_lnet.ln_dc_request)) {
3924 lp = list_first_entry(&the_lnet.ln_dc_request,
3925 struct lnet_peer, lp_dc_list);
3926 lnet_peer_discovery_error(lp, -ESHUTDOWN);
3927 lnet_peer_discovery_complete(lp);
3929 lnet_net_unlock(LNET_LOCK_EX);
3931 lnet_assert_handler_unused(the_lnet.ln_dc_handler);
3932 the_lnet.ln_dc_handler = NULL;
3934 the_lnet.ln_dc_state = LNET_DC_STATE_SHUTDOWN;
3935 wake_up(&the_lnet.ln_dc_waitq);
3937 CDEBUG(D_NET, "stopped\n");
3942 /* ln_api_mutex is held on entry. */
3943 int lnet_peer_discovery_start(void)
3945 struct task_struct *task;
3948 if (the_lnet.ln_dc_state != LNET_DC_STATE_SHUTDOWN)
3951 the_lnet.ln_dc_handler = lnet_discovery_event_handler;
3952 the_lnet.ln_dc_state = LNET_DC_STATE_RUNNING;
3953 task = kthread_run(lnet_peer_discovery, NULL, "lnet_discovery");
3956 CERROR("Can't start peer discovery thread: %d\n", rc);
3958 the_lnet.ln_dc_handler = NULL;
3960 the_lnet.ln_dc_state = LNET_DC_STATE_SHUTDOWN;
3963 CDEBUG(D_NET, "discovery start: %d\n", rc);
3968 /* ln_api_mutex is held on entry. */
3969 void lnet_peer_discovery_stop(void)
3971 if (the_lnet.ln_dc_state == LNET_DC_STATE_SHUTDOWN)
3974 LASSERT(the_lnet.ln_dc_state == LNET_DC_STATE_RUNNING);
3975 the_lnet.ln_dc_state = LNET_DC_STATE_STOPPING;
3977 /* In the LNetNIInit() path we may be stopping discovery before it
3978 * entered its work loop
3980 if (!completion_done(&the_lnet.ln_started))
3981 complete(&the_lnet.ln_started);
3983 wake_up(&the_lnet.ln_dc_waitq);
3985 wait_event(the_lnet.ln_dc_waitq,
3986 the_lnet.ln_dc_state == LNET_DC_STATE_SHUTDOWN);
3988 LASSERT(list_empty(&the_lnet.ln_dc_request));
3989 LASSERT(list_empty(&the_lnet.ln_dc_working));
3990 LASSERT(list_empty(&the_lnet.ln_dc_expired));
3992 CDEBUG(D_NET, "discovery stopped\n");
3998 lnet_debug_peer(lnet_nid_t nid)
4000 char *aliveness = "NA";
4001 struct lnet_peer_ni *lp;
4004 cpt = lnet_cpt_of_nid(nid, NULL);
4007 lp = lnet_nid2peerni_locked(nid, LNET_NID_ANY, cpt);
4009 lnet_net_unlock(cpt);
4010 CDEBUG(D_WARNING, "No peer %s\n", libcfs_nid2str(nid));
4014 if (lnet_isrouter(lp) || lnet_peer_aliveness_enabled(lp))
4015 aliveness = (lnet_is_peer_ni_alive(lp)) ? "up" : "down";
4017 CDEBUG(D_WARNING, "%-24s %4d %5s %5d %5d %5d %5d %5d %ld\n",
4018 libcfs_nidstr(&lp->lpni_nid), kref_read(&lp->lpni_kref),
4019 aliveness, lp->lpni_net->net_tunables.lct_peer_tx_credits,
4020 lp->lpni_rtrcredits, lp->lpni_minrtrcredits,
4021 lp->lpni_txcredits, lp->lpni_mintxcredits, lp->lpni_txqnob);
4023 lnet_peer_ni_decref_locked(lp);
4025 lnet_net_unlock(cpt);
4028 /* Gathering information for userspace. */
4030 int lnet_get_peer_ni_info(__u32 peer_index, __u64 *nid,
4031 char aliveness[LNET_MAX_STR_LEN],
4032 __u32 *cpt_iter, __u32 *refcount,
4033 __u32 *ni_peer_tx_credits, __u32 *peer_tx_credits,
4034 __u32 *peer_rtr_credits, __u32 *peer_min_rtr_credits,
4035 __u32 *peer_tx_qnob)
4037 struct lnet_peer_table *peer_table;
4038 struct lnet_peer_ni *lp;
4043 /* get the number of CPTs */
4044 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
4046 /* if the cpt number to be examined is >= the number of cpts in
4047 * the system then indicate that there are no more cpts to examin
4049 if (*cpt_iter >= lncpt)
4052 /* get the current table */
4053 peer_table = the_lnet.ln_peer_tables[*cpt_iter];
4054 /* if the ptable is NULL then there are no more cpts to examine */
4055 if (peer_table == NULL)
4058 lnet_net_lock(*cpt_iter);
4060 for (j = 0; j < LNET_PEER_HASH_SIZE && !found; j++) {
4061 struct list_head *peers = &peer_table->pt_hash[j];
4063 list_for_each_entry(lp, peers, lpni_hashlist) {
4064 if (!nid_is_nid4(&lp->lpni_nid))
4066 if (peer_index-- > 0)
4069 snprintf(aliveness, LNET_MAX_STR_LEN, "NA");
4070 if (lnet_isrouter(lp) ||
4071 lnet_peer_aliveness_enabled(lp))
4072 snprintf(aliveness, LNET_MAX_STR_LEN,
4073 lnet_is_peer_ni_alive(lp) ? "up" : "down");
4075 *nid = lnet_nid_to_nid4(&lp->lpni_nid);
4076 *refcount = kref_read(&lp->lpni_kref);
4077 *ni_peer_tx_credits =
4078 lp->lpni_net->net_tunables.lct_peer_tx_credits;
4079 *peer_tx_credits = lp->lpni_txcredits;
4080 *peer_rtr_credits = lp->lpni_rtrcredits;
4081 *peer_min_rtr_credits = lp->lpni_mintxcredits;
4082 *peer_tx_qnob = lp->lpni_txqnob;
4088 lnet_net_unlock(*cpt_iter);
4092 return found ? 0 : -ENOENT;
4095 /* ln_api_mutex is held, which keeps the peer list stable */
4096 int lnet_get_peer_info(struct lnet_ioctl_peer_cfg *cfg, void __user *bulk)
4098 struct lnet_ioctl_element_stats *lpni_stats;
4099 struct lnet_ioctl_element_msg_stats *lpni_msg_stats;
4100 struct lnet_ioctl_peer_ni_hstats *lpni_hstats;
4101 struct lnet_peer_ni_credit_info *lpni_info;
4102 struct lnet_peer_ni *lpni;
4103 struct lnet_peer *lp;
4108 lp = lnet_find_peer(cfg->prcfg_prim_nid);
4115 size = sizeof(nid) + sizeof(*lpni_info) + sizeof(*lpni_stats)
4116 + sizeof(*lpni_msg_stats) + sizeof(*lpni_hstats);
4117 size *= lp->lp_nnis;
4118 if (size > cfg->prcfg_size) {
4119 cfg->prcfg_size = size;
4124 cfg->prcfg_prim_nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
4125 cfg->prcfg_mr = lnet_peer_is_multi_rail(lp);
4126 cfg->prcfg_cfg_nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
4127 cfg->prcfg_count = lp->lp_nnis;
4128 cfg->prcfg_size = size;
4129 cfg->prcfg_state = lp->lp_state;
4131 /* Allocate helper buffers. */
4133 LIBCFS_ALLOC(lpni_info, sizeof(*lpni_info));
4136 LIBCFS_ALLOC(lpni_stats, sizeof(*lpni_stats));
4139 LIBCFS_ALLOC(lpni_msg_stats, sizeof(*lpni_msg_stats));
4140 if (!lpni_msg_stats)
4141 goto out_free_stats;
4142 LIBCFS_ALLOC(lpni_hstats, sizeof(*lpni_hstats));
4144 goto out_free_msg_stats;
4149 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL) {
4150 if (!nid_is_nid4(&lpni->lpni_nid))
4152 nid = lnet_nid_to_nid4(&lpni->lpni_nid);
4153 if (copy_to_user(bulk, &nid, sizeof(nid)))
4154 goto out_free_hstats;
4155 bulk += sizeof(nid);
4157 memset(lpni_info, 0, sizeof(*lpni_info));
4158 snprintf(lpni_info->cr_aliveness, LNET_MAX_STR_LEN, "NA");
4159 if (lnet_isrouter(lpni) ||
4160 lnet_peer_aliveness_enabled(lpni))
4161 snprintf(lpni_info->cr_aliveness, LNET_MAX_STR_LEN,
4162 lnet_is_peer_ni_alive(lpni) ? "up" : "down");
4164 lpni_info->cr_refcount = kref_read(&lpni->lpni_kref);
4165 lpni_info->cr_ni_peer_tx_credits = (lpni->lpni_net != NULL) ?
4166 lpni->lpni_net->net_tunables.lct_peer_tx_credits : 0;
4167 lpni_info->cr_peer_tx_credits = lpni->lpni_txcredits;
4168 lpni_info->cr_peer_rtr_credits = lpni->lpni_rtrcredits;
4169 lpni_info->cr_peer_min_rtr_credits = lpni->lpni_minrtrcredits;
4170 lpni_info->cr_peer_min_tx_credits = lpni->lpni_mintxcredits;
4171 lpni_info->cr_peer_tx_qnob = lpni->lpni_txqnob;
4172 if (copy_to_user(bulk, lpni_info, sizeof(*lpni_info)))
4173 goto out_free_hstats;
4174 bulk += sizeof(*lpni_info);
4176 memset(lpni_stats, 0, sizeof(*lpni_stats));
4177 lpni_stats->iel_send_count = lnet_sum_stats(&lpni->lpni_stats,
4178 LNET_STATS_TYPE_SEND);
4179 lpni_stats->iel_recv_count = lnet_sum_stats(&lpni->lpni_stats,
4180 LNET_STATS_TYPE_RECV);
4181 lpni_stats->iel_drop_count = lnet_sum_stats(&lpni->lpni_stats,
4182 LNET_STATS_TYPE_DROP);
4183 if (copy_to_user(bulk, lpni_stats, sizeof(*lpni_stats)))
4184 goto out_free_hstats;
4185 bulk += sizeof(*lpni_stats);
4186 lnet_usr_translate_stats(lpni_msg_stats, &lpni->lpni_stats);
4187 if (copy_to_user(bulk, lpni_msg_stats, sizeof(*lpni_msg_stats)))
4188 goto out_free_hstats;
4189 bulk += sizeof(*lpni_msg_stats);
4190 lpni_hstats->hlpni_network_timeout =
4191 atomic_read(&lpni->lpni_hstats.hlt_network_timeout);
4192 lpni_hstats->hlpni_remote_dropped =
4193 atomic_read(&lpni->lpni_hstats.hlt_remote_dropped);
4194 lpni_hstats->hlpni_remote_timeout =
4195 atomic_read(&lpni->lpni_hstats.hlt_remote_timeout);
4196 lpni_hstats->hlpni_remote_error =
4197 atomic_read(&lpni->lpni_hstats.hlt_remote_error);
4198 lpni_hstats->hlpni_health_value =
4199 atomic_read(&lpni->lpni_healthv);
4200 lpni_hstats->hlpni_ping_count = lpni->lpni_ping_count;
4201 lpni_hstats->hlpni_next_ping = lpni->lpni_next_ping;
4202 if (copy_to_user(bulk, lpni_hstats, sizeof(*lpni_hstats)))
4203 goto out_free_hstats;
4204 bulk += sizeof(*lpni_hstats);
4209 LIBCFS_FREE(lpni_hstats, sizeof(*lpni_hstats));
4211 LIBCFS_FREE(lpni_msg_stats, sizeof(*lpni_msg_stats));
4213 LIBCFS_FREE(lpni_stats, sizeof(*lpni_stats));
4215 LIBCFS_FREE(lpni_info, sizeof(*lpni_info));
4217 lnet_peer_decref_locked(lp);
4222 /* must hold net_lock/0 */
4224 lnet_peer_ni_add_to_recoveryq_locked(struct lnet_peer_ni *lpni,
4225 struct list_head *recovery_queue,
4228 /* the mt could've shutdown and cleaned up the queues */
4229 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING)
4232 if (!list_empty(&lpni->lpni_recovery))
4235 if (atomic_read(&lpni->lpni_healthv) == LNET_MAX_HEALTH_VALUE)
4238 if (!lpni->lpni_last_alive) {
4240 "lpni %s(%p) not eligible for recovery last alive %lld\n",
4241 libcfs_nidstr(&lpni->lpni_nid), lpni,
4242 lpni->lpni_last_alive);
4246 if (lnet_recovery_limit &&
4247 now > lpni->lpni_last_alive + lnet_recovery_limit) {
4248 CDEBUG(D_NET, "lpni %s aged out last alive %lld\n",
4249 libcfs_nidstr(&lpni->lpni_nid),
4250 lpni->lpni_last_alive);
4251 /* Reset the ping count so that if this peer NI is added back to
4252 * the recovery queue we will send the first ping right away.
4254 lpni->lpni_ping_count = 0;
4258 /* This peer NI is going on the recovery queue, so take a ref on it */
4259 lnet_peer_ni_addref_locked(lpni);
4261 lnet_peer_ni_set_next_ping(lpni, now);
4263 CDEBUG(D_NET, "%s added to recovery queue. ping count: %u next ping: %lld last alive: %lld health: %d\n",
4264 libcfs_nidstr(&lpni->lpni_nid),
4265 lpni->lpni_ping_count,
4266 lpni->lpni_next_ping,
4267 lpni->lpni_last_alive,
4268 atomic_read(&lpni->lpni_healthv));
4270 list_add_tail(&lpni->lpni_recovery, recovery_queue);
4273 /* Call with the ln_api_mutex held */
4275 lnet_peer_ni_set_healthv(lnet_nid_t nid, int value, bool all)
4277 struct lnet_peer_table *ptable;
4278 struct lnet_peer *lp;
4279 struct lnet_peer_net *lpn;
4280 struct lnet_peer_ni *lpni;
4285 if (the_lnet.ln_state != LNET_STATE_RUNNING)
4288 now = ktime_get_seconds();
4291 lnet_net_lock(LNET_LOCK_EX);
4292 lpni = lnet_find_peer_ni_locked(nid);
4294 lnet_net_unlock(LNET_LOCK_EX);
4297 lnet_set_lpni_healthv_locked(lpni, value);
4298 lnet_peer_ni_add_to_recoveryq_locked(lpni,
4299 &the_lnet.ln_mt_peerNIRecovq, now);
4300 lnet_peer_ni_decref_locked(lpni);
4301 lnet_net_unlock(LNET_LOCK_EX);
4305 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
4308 * Walk all the peers and reset the health value for each one to the
4311 lnet_net_lock(LNET_LOCK_EX);
4312 for (cpt = 0; cpt < lncpt; cpt++) {
4313 ptable = the_lnet.ln_peer_tables[cpt];
4314 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
4315 list_for_each_entry(lpn, &lp->lp_peer_nets, lpn_peer_nets) {
4316 list_for_each_entry(lpni, &lpn->lpn_peer_nis,
4318 lnet_set_lpni_healthv_locked(lpni,
4320 lnet_peer_ni_add_to_recoveryq_locked(lpni,
4321 &the_lnet.ln_mt_peerNIRecovq, now);
4326 lnet_net_unlock(LNET_LOCK_EX);