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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
35 #define DEBUG_SUBSYSTEM S_LNET
37 #include <linux/sched.h>
38 #ifdef HAVE_SCHED_HEADERS
39 #include <linux/sched/signal.h>
41 #include <linux/uaccess.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_NIDNET(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 LIBCFS_FREE(hash, LNET_PEER_HASH_SIZE * sizeof(*hash));
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(lnet_nid_t 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 LNetInvalidateMDHandle(&lpni->lpni_recovery_ping_mdh);
171 spin_lock_init(&lpni->lpni_lock);
173 if (lnet_peers_start_down())
174 lpni->lpni_ns_status = LNET_NI_STATUS_DOWN;
176 lpni->lpni_ns_status = LNET_NI_STATUS_UP;
177 lpni->lpni_ping_feats = LNET_PING_FEAT_INVAL;
178 lpni->lpni_nid = nid;
179 lpni->lpni_cpt = cpt;
180 atomic_set(&lpni->lpni_healthv, LNET_MAX_HEALTH_VALUE);
182 net = lnet_get_net_locked(LNET_NIDNET(nid));
183 lpni->lpni_net = net;
185 lpni->lpni_txcredits = net->net_tunables.lct_peer_tx_credits;
186 lpni->lpni_mintxcredits = lpni->lpni_txcredits;
187 lpni->lpni_rtrcredits = lnet_peer_buffer_credits(net);
188 lpni->lpni_minrtrcredits = lpni->lpni_rtrcredits;
191 * This peer_ni is not on a local network, so we
192 * cannot add the credits here. In case the net is
193 * added later, add the peer_ni to the remote peer ni
194 * list so it can be easily found and revisited.
196 /* FIXME: per-net implementation instead? */
197 atomic_inc(&lpni->lpni_refcount);
198 list_add_tail(&lpni->lpni_on_remote_peer_ni_list,
199 &the_lnet.ln_remote_peer_ni_list);
202 CDEBUG(D_NET, "%p nid %s\n", lpni, libcfs_nid2str(lpni->lpni_nid));
207 static struct lnet_peer_net *
208 lnet_peer_net_alloc(__u32 net_id)
210 struct lnet_peer_net *lpn;
212 LIBCFS_CPT_ALLOC(lpn, lnet_cpt_table(), CFS_CPT_ANY, sizeof(*lpn));
216 INIT_LIST_HEAD(&lpn->lpn_peer_nets);
217 INIT_LIST_HEAD(&lpn->lpn_peer_nis);
218 lpn->lpn_net_id = net_id;
220 CDEBUG(D_NET, "%p net %s\n", lpn, libcfs_net2str(lpn->lpn_net_id));
226 lnet_destroy_peer_net_locked(struct lnet_peer_net *lpn)
228 struct lnet_peer *lp;
230 CDEBUG(D_NET, "%p net %s\n", lpn, libcfs_net2str(lpn->lpn_net_id));
232 LASSERT(atomic_read(&lpn->lpn_refcount) == 0);
233 LASSERT(list_empty(&lpn->lpn_peer_nis));
234 LASSERT(list_empty(&lpn->lpn_peer_nets));
236 lpn->lpn_peer = NULL;
237 LIBCFS_FREE(lpn, sizeof(*lpn));
239 lnet_peer_decref_locked(lp);
242 static struct lnet_peer *
243 lnet_peer_alloc(lnet_nid_t nid)
245 struct lnet_peer *lp;
247 LIBCFS_CPT_ALLOC(lp, lnet_cpt_table(), CFS_CPT_ANY, sizeof(*lp));
251 INIT_LIST_HEAD(&lp->lp_rtrq);
252 INIT_LIST_HEAD(&lp->lp_routes);
253 INIT_LIST_HEAD(&lp->lp_peer_list);
254 INIT_LIST_HEAD(&lp->lp_peer_nets);
255 INIT_LIST_HEAD(&lp->lp_dc_list);
256 INIT_LIST_HEAD(&lp->lp_dc_pendq);
257 INIT_LIST_HEAD(&lp->lp_rtr_list);
258 init_waitqueue_head(&lp->lp_dc_waitq);
259 spin_lock_init(&lp->lp_lock);
260 lp->lp_primary_nid = nid;
262 * Turn off discovery for loopback peer. If you're creating a peer
263 * for the loopback interface then that was initiated when we
264 * attempted to send a message over the loopback. There is no need
265 * to ever use a different interface when sending messages to
268 if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
269 lp->lp_state = LNET_PEER_NO_DISCOVERY;
270 lp->lp_cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
272 CDEBUG(D_NET, "%p nid %s\n", lp, libcfs_nid2str(lp->lp_primary_nid));
278 lnet_destroy_peer_locked(struct lnet_peer *lp)
280 CDEBUG(D_NET, "%p nid %s\n", lp, libcfs_nid2str(lp->lp_primary_nid));
282 LASSERT(atomic_read(&lp->lp_refcount) == 0);
283 LASSERT(lp->lp_rtr_refcount == 0);
284 LASSERT(list_empty(&lp->lp_peer_nets));
285 LASSERT(list_empty(&lp->lp_peer_list));
286 LASSERT(list_empty(&lp->lp_dc_list));
289 lnet_ping_buffer_decref(lp->lp_data);
292 * if there are messages still on the pending queue, then make
293 * sure to queue them on the ln_msg_resend list so they can be
294 * resent at a later point if the discovery thread is still
296 * If the discovery thread has stopped, then the wakeup will be a
297 * no-op, and it is expected the lnet_shutdown_lndnets() will
298 * eventually be called, which will traverse this list and
299 * finalize the messages on the list.
300 * We can not resend them now because we're holding the cpt lock.
301 * Releasing the lock can cause an inconsistent state
303 spin_lock(&the_lnet.ln_msg_resend_lock);
304 spin_lock(&lp->lp_lock);
305 list_splice(&lp->lp_dc_pendq, &the_lnet.ln_msg_resend);
306 spin_unlock(&lp->lp_lock);
307 spin_unlock(&the_lnet.ln_msg_resend_lock);
308 wake_up(&the_lnet.ln_dc_waitq);
310 LIBCFS_FREE(lp, sizeof(*lp));
314 * Detach a peer_ni from its peer_net. If this was the last peer_ni on
315 * that peer_net, detach the peer_net from the peer.
317 * Call with lnet_net_lock/EX held
320 lnet_peer_detach_peer_ni_locked(struct lnet_peer_ni *lpni)
322 struct lnet_peer_table *ptable;
323 struct lnet_peer_net *lpn;
324 struct lnet_peer *lp;
327 * Belts and suspenders: gracefully handle teardown of a
328 * partially connected peer_ni.
330 lpn = lpni->lpni_peer_net;
332 list_del_init(&lpni->lpni_peer_nis);
334 * If there are no lpni's left, we detach lpn from
335 * lp_peer_nets, so it cannot be found anymore.
337 if (list_empty(&lpn->lpn_peer_nis))
338 list_del_init(&lpn->lpn_peer_nets);
340 /* Update peer NID count. */
345 * If there are no more peer nets, make the peer unfindable
346 * via the peer_tables.
348 * Otherwise, if the peer is DISCOVERED, tell discovery to
349 * take another look at it. This is a no-op if discovery for
350 * this peer did the detaching.
352 if (list_empty(&lp->lp_peer_nets)) {
353 list_del_init(&lp->lp_peer_list);
354 ptable = the_lnet.ln_peer_tables[lp->lp_cpt];
356 } else if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING) {
357 /* Discovery isn't running, nothing to do here. */
358 } else if (lp->lp_state & LNET_PEER_DISCOVERED) {
359 lnet_peer_queue_for_discovery(lp);
360 wake_up(&the_lnet.ln_dc_waitq);
362 CDEBUG(D_NET, "peer %s NID %s\n",
363 libcfs_nid2str(lp->lp_primary_nid),
364 libcfs_nid2str(lpni->lpni_nid));
367 /* called with lnet_net_lock LNET_LOCK_EX held */
369 lnet_peer_ni_del_locked(struct lnet_peer_ni *lpni)
371 struct lnet_peer_table *ptable = NULL;
373 /* don't remove a peer_ni if it's also a gateway */
374 if (lnet_isrouter(lpni)) {
375 CERROR("Peer NI %s is a gateway. Can not delete it\n",
376 libcfs_nid2str(lpni->lpni_nid));
380 lnet_peer_remove_from_remote_list(lpni);
382 /* remove peer ni from the hash list. */
383 list_del_init(&lpni->lpni_hashlist);
386 * indicate the peer is being deleted so the monitor thread can
387 * remove it from the recovery queue.
389 spin_lock(&lpni->lpni_lock);
390 lpni->lpni_state |= LNET_PEER_NI_DELETING;
391 spin_unlock(&lpni->lpni_lock);
393 /* decrement the ref count on the peer table */
394 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
395 LASSERT(ptable->pt_number > 0);
399 * The peer_ni can no longer be found with a lookup. But there
400 * can be current users, so keep track of it on the zombie
401 * list until the reference count has gone to zero.
403 * The last reference may be lost in a place where the
404 * lnet_net_lock locks only a single cpt, and that cpt may not
405 * be lpni->lpni_cpt. So the zombie list of lnet_peer_table
408 spin_lock(&ptable->pt_zombie_lock);
409 list_add(&lpni->lpni_hashlist, &ptable->pt_zombie_list);
410 ptable->pt_zombies++;
411 spin_unlock(&ptable->pt_zombie_lock);
413 /* no need to keep this peer_ni on the hierarchy anymore */
414 lnet_peer_detach_peer_ni_locked(lpni);
416 /* remove hashlist reference on peer_ni */
417 lnet_peer_ni_decref_locked(lpni);
422 void lnet_peer_uninit(void)
424 struct lnet_peer_ni *lpni, *tmp;
426 lnet_net_lock(LNET_LOCK_EX);
428 /* remove all peer_nis from the remote peer and the hash list */
429 list_for_each_entry_safe(lpni, tmp, &the_lnet.ln_remote_peer_ni_list,
430 lpni_on_remote_peer_ni_list)
431 lnet_peer_ni_del_locked(lpni);
433 lnet_peer_tables_destroy();
435 lnet_net_unlock(LNET_LOCK_EX);
439 lnet_peer_del_locked(struct lnet_peer *peer)
441 struct lnet_peer_ni *lpni = NULL, *lpni2;
444 CDEBUG(D_NET, "peer %s\n", libcfs_nid2str(peer->lp_primary_nid));
446 lpni = lnet_get_next_peer_ni_locked(peer, NULL, lpni);
447 while (lpni != NULL) {
448 lpni2 = lnet_get_next_peer_ni_locked(peer, NULL, lpni);
449 rc = lnet_peer_ni_del_locked(lpni);
459 lnet_peer_del(struct lnet_peer *peer)
461 lnet_net_lock(LNET_LOCK_EX);
462 lnet_peer_del_locked(peer);
463 lnet_net_unlock(LNET_LOCK_EX);
469 * Delete a NID from a peer. Call with ln_api_mutex held.
472 * -EPERM: Non-DLC deletion from DLC-configured peer.
473 * -ENOENT: No lnet_peer_ni corresponding to the nid.
474 * -ECHILD: The lnet_peer_ni isn't connected to the peer.
475 * -EBUSY: The lnet_peer_ni is the primary, and not the only peer_ni.
478 lnet_peer_del_nid(struct lnet_peer *lp, lnet_nid_t nid, unsigned flags)
480 struct lnet_peer_ni *lpni;
481 lnet_nid_t primary_nid = lp->lp_primary_nid;
484 if (!(flags & LNET_PEER_CONFIGURED)) {
485 if (lp->lp_state & LNET_PEER_CONFIGURED) {
490 lpni = lnet_find_peer_ni_locked(nid);
495 lnet_peer_ni_decref_locked(lpni);
496 if (lp != lpni->lpni_peer_net->lpn_peer) {
502 * This function only allows deletion of the primary NID if it
505 if (nid == lp->lp_primary_nid && lp->lp_nnis != 1) {
510 lnet_net_lock(LNET_LOCK_EX);
512 rc = lnet_peer_ni_del_locked(lpni);
514 lnet_net_unlock(LNET_LOCK_EX);
517 CDEBUG(D_NET, "peer %s NID %s flags %#x: %d\n",
518 libcfs_nid2str(primary_nid), libcfs_nid2str(nid), flags, rc);
524 lnet_peer_table_cleanup_locked(struct lnet_net *net,
525 struct lnet_peer_table *ptable)
528 struct lnet_peer_ni *next;
529 struct lnet_peer_ni *lpni;
530 struct lnet_peer *peer;
532 for (i = 0; i < LNET_PEER_HASH_SIZE; i++) {
533 list_for_each_entry_safe(lpni, next, &ptable->pt_hash[i],
535 if (net != NULL && net != lpni->lpni_net)
538 peer = lpni->lpni_peer_net->lpn_peer;
539 if (peer->lp_primary_nid != lpni->lpni_nid) {
540 lnet_peer_ni_del_locked(lpni);
544 * Removing the primary NID implies removing
545 * the entire peer. Advance next beyond any
546 * peer_ni that belongs to the same peer.
548 list_for_each_entry_from(next, &ptable->pt_hash[i],
550 if (next->lpni_peer_net->lpn_peer != peer)
553 lnet_peer_del_locked(peer);
559 lnet_peer_ni_finalize_wait(struct lnet_peer_table *ptable)
563 spin_lock(&ptable->pt_zombie_lock);
564 while (ptable->pt_zombies) {
565 spin_unlock(&ptable->pt_zombie_lock);
567 if (is_power_of_2(i)) {
569 "Waiting for %d zombies on peer table\n",
572 set_current_state(TASK_UNINTERRUPTIBLE);
573 schedule_timeout(cfs_time_seconds(1) >> 1);
574 spin_lock(&ptable->pt_zombie_lock);
576 spin_unlock(&ptable->pt_zombie_lock);
580 lnet_peer_table_del_rtrs_locked(struct lnet_net *net,
581 struct lnet_peer_table *ptable)
583 struct lnet_peer_ni *lp;
584 struct lnet_peer_ni *tmp;
588 for (i = 0; i < LNET_PEER_HASH_SIZE; i++) {
589 list_for_each_entry_safe(lp, tmp, &ptable->pt_hash[i],
591 if (net != lp->lpni_net)
594 if (!lnet_isrouter(lp))
597 gw_nid = lp->lpni_peer_net->lpn_peer->lp_primary_nid;
599 lnet_net_unlock(LNET_LOCK_EX);
600 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), gw_nid);
601 lnet_net_lock(LNET_LOCK_EX);
607 lnet_peer_tables_cleanup(struct lnet_net *net)
610 struct lnet_peer_table *ptable;
612 LASSERT(the_lnet.ln_state != LNET_STATE_SHUTDOWN || net != NULL);
613 /* If just deleting the peers for a NI, get rid of any routes these
614 * peers are gateways for. */
615 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
616 lnet_net_lock(LNET_LOCK_EX);
617 lnet_peer_table_del_rtrs_locked(net, ptable);
618 lnet_net_unlock(LNET_LOCK_EX);
621 /* Start the cleanup process */
622 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
623 lnet_net_lock(LNET_LOCK_EX);
624 lnet_peer_table_cleanup_locked(net, ptable);
625 lnet_net_unlock(LNET_LOCK_EX);
628 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables)
629 lnet_peer_ni_finalize_wait(ptable);
632 static struct lnet_peer_ni *
633 lnet_get_peer_ni_locked(struct lnet_peer_table *ptable, lnet_nid_t nid)
635 struct list_head *peers;
636 struct lnet_peer_ni *lp;
638 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
640 peers = &ptable->pt_hash[lnet_nid2peerhash(nid)];
641 list_for_each_entry(lp, peers, lpni_hashlist) {
642 if (lp->lpni_nid == nid) {
643 lnet_peer_ni_addref_locked(lp);
651 struct lnet_peer_ni *
652 lnet_find_peer_ni_locked(lnet_nid_t nid)
654 struct lnet_peer_ni *lpni;
655 struct lnet_peer_table *ptable;
658 cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
660 ptable = the_lnet.ln_peer_tables[cpt];
661 lpni = lnet_get_peer_ni_locked(ptable, nid);
666 struct lnet_peer_ni *
667 lnet_peer_get_ni_locked(struct lnet_peer *lp, lnet_nid_t nid)
669 struct lnet_peer_net *lpn;
670 struct lnet_peer_ni *lpni;
672 lpn = lnet_peer_get_net_locked(lp, LNET_NIDNET(nid));
676 list_for_each_entry(lpni, &lpn->lpn_peer_nis, lpni_peer_nis) {
677 if (lpni->lpni_nid == nid)
685 lnet_find_peer(lnet_nid_t nid)
687 struct lnet_peer_ni *lpni;
688 struct lnet_peer *lp = NULL;
691 cpt = lnet_net_lock_current();
692 lpni = lnet_find_peer_ni_locked(nid);
694 lp = lpni->lpni_peer_net->lpn_peer;
695 lnet_peer_addref_locked(lp);
696 lnet_peer_ni_decref_locked(lpni);
698 lnet_net_unlock(cpt);
703 struct lnet_peer_ni *
704 lnet_get_next_peer_ni_locked(struct lnet_peer *peer,
705 struct lnet_peer_net *peer_net,
706 struct lnet_peer_ni *prev)
708 struct lnet_peer_ni *lpni;
709 struct lnet_peer_net *net = peer_net;
713 if (list_empty(&peer->lp_peer_nets))
716 net = list_entry(peer->lp_peer_nets.next,
717 struct lnet_peer_net,
720 lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
726 if (prev->lpni_peer_nis.next == &prev->lpni_peer_net->lpn_peer_nis) {
728 * if you reached the end of the peer ni list and the peer
729 * net is specified then there are no more peer nis in that
736 * we reached the end of this net ni list. move to the
739 if (prev->lpni_peer_net->lpn_peer_nets.next ==
741 /* no more nets and no more NIs. */
744 /* get the next net */
745 net = list_entry(prev->lpni_peer_net->lpn_peer_nets.next,
746 struct lnet_peer_net,
748 /* get the ni on it */
749 lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
755 /* there are more nis left */
756 lpni = list_entry(prev->lpni_peer_nis.next,
757 struct lnet_peer_ni, lpni_peer_nis);
762 /* Call with the ln_api_mutex held */
763 int lnet_get_peer_list(u32 *countp, u32 *sizep, struct lnet_process_id __user *ids)
765 struct lnet_process_id id;
766 struct lnet_peer_table *ptable;
767 struct lnet_peer *lp;
776 if (the_lnet.ln_state != LNET_STATE_RUNNING)
779 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
782 * Count the number of peers, and return E2BIG if the buffer
783 * is too small. We'll also return the desired size.
786 for (cpt = 0; cpt < lncpt; cpt++) {
787 ptable = the_lnet.ln_peer_tables[cpt];
788 count += ptable->pt_peers;
790 size = count * sizeof(*ids);
795 * Walk the peer lists and copy out the primary nids.
796 * This is safe because the peer lists are only modified
797 * while the ln_api_mutex is held. So we don't need to
798 * hold the lnet_net_lock as well, and can therefore
799 * directly call copy_to_user().
802 memset(&id, 0, sizeof(id));
803 id.pid = LNET_PID_LUSTRE;
805 for (cpt = 0; cpt < lncpt; cpt++) {
806 ptable = the_lnet.ln_peer_tables[cpt];
807 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
810 id.nid = lp->lp_primary_nid;
811 if (copy_to_user(&ids[i], &id, sizeof(id)))
824 * Start pushes to peers that need to be updated for a configuration
825 * change on this node.
828 lnet_push_update_to_peers(int force)
830 struct lnet_peer_table *ptable;
831 struct lnet_peer *lp;
835 lnet_net_lock(LNET_LOCK_EX);
836 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
837 for (cpt = 0; cpt < lncpt; cpt++) {
838 ptable = the_lnet.ln_peer_tables[cpt];
839 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
841 spin_lock(&lp->lp_lock);
842 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
843 lp->lp_state |= LNET_PEER_FORCE_PUSH;
844 spin_unlock(&lp->lp_lock);
846 if (lnet_peer_needs_push(lp))
847 lnet_peer_queue_for_discovery(lp);
850 lnet_net_unlock(LNET_LOCK_EX);
851 wake_up(&the_lnet.ln_dc_waitq);
855 * Test whether a ni is a preferred ni for this peer_ni, e.g, whether
856 * this is a preferred point-to-point path. Call with lnet_net_lock in
860 lnet_peer_is_pref_nid_locked(struct lnet_peer_ni *lpni, lnet_nid_t nid)
864 if (lpni->lpni_pref_nnids == 0)
866 if (lpni->lpni_pref_nnids == 1)
867 return lpni->lpni_pref.nid == nid;
868 for (i = 0; i < lpni->lpni_pref_nnids; i++) {
869 if (lpni->lpni_pref.nids[i] == nid)
876 * Set a single ni as preferred, provided no preferred ni is already
877 * defined. Only to be used for non-multi-rail peer_ni.
880 lnet_peer_ni_set_non_mr_pref_nid(struct lnet_peer_ni *lpni, lnet_nid_t nid)
884 spin_lock(&lpni->lpni_lock);
885 if (nid == LNET_NID_ANY) {
887 } else if (lpni->lpni_pref_nnids > 0) {
889 } else if (lpni->lpni_pref_nnids == 0) {
890 lpni->lpni_pref.nid = nid;
891 lpni->lpni_pref_nnids = 1;
892 lpni->lpni_state |= LNET_PEER_NI_NON_MR_PREF;
894 spin_unlock(&lpni->lpni_lock);
896 CDEBUG(D_NET, "peer %s nid %s: %d\n",
897 libcfs_nid2str(lpni->lpni_nid), libcfs_nid2str(nid), rc);
902 * Clear the preferred NID from a non-multi-rail peer_ni, provided
903 * this preference was set by lnet_peer_ni_set_non_mr_pref_nid().
906 lnet_peer_ni_clr_non_mr_pref_nid(struct lnet_peer_ni *lpni)
910 spin_lock(&lpni->lpni_lock);
911 if (lpni->lpni_state & LNET_PEER_NI_NON_MR_PREF) {
912 lpni->lpni_pref_nnids = 0;
913 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
914 } else if (lpni->lpni_pref_nnids == 0) {
919 spin_unlock(&lpni->lpni_lock);
921 CDEBUG(D_NET, "peer %s: %d\n",
922 libcfs_nid2str(lpni->lpni_nid), rc);
927 * Clear the preferred NIDs from a non-multi-rail peer.
930 lnet_peer_clr_non_mr_pref_nids(struct lnet_peer *lp)
932 struct lnet_peer_ni *lpni = NULL;
934 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
935 lnet_peer_ni_clr_non_mr_pref_nid(lpni);
939 lnet_peer_add_pref_nid(struct lnet_peer_ni *lpni, lnet_nid_t nid)
941 lnet_nid_t *nids = NULL;
942 lnet_nid_t *oldnids = NULL;
943 struct lnet_peer *lp = lpni->lpni_peer_net->lpn_peer;
948 if (nid == LNET_NID_ANY) {
953 if (lpni->lpni_pref_nnids == 1 && lpni->lpni_pref.nid == nid) {
958 /* A non-MR node may have only one preferred NI per peer_ni */
959 if (lpni->lpni_pref_nnids > 0) {
960 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
966 if (lpni->lpni_pref_nnids != 0) {
967 size = sizeof(*nids) * (lpni->lpni_pref_nnids + 1);
968 LIBCFS_CPT_ALLOC(nids, lnet_cpt_table(), lpni->lpni_cpt, size);
973 for (i = 0; i < lpni->lpni_pref_nnids; i++) {
974 if (lpni->lpni_pref.nids[i] == nid) {
975 LIBCFS_FREE(nids, size);
979 nids[i] = lpni->lpni_pref.nids[i];
984 lnet_net_lock(LNET_LOCK_EX);
985 spin_lock(&lpni->lpni_lock);
986 if (lpni->lpni_pref_nnids == 0) {
987 lpni->lpni_pref.nid = nid;
989 oldnids = lpni->lpni_pref.nids;
990 lpni->lpni_pref.nids = nids;
992 lpni->lpni_pref_nnids++;
993 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
994 spin_unlock(&lpni->lpni_lock);
995 lnet_net_unlock(LNET_LOCK_EX);
998 size = sizeof(*nids) * (lpni->lpni_pref_nnids - 1);
999 LIBCFS_FREE(oldnids, sizeof(*oldnids) * size);
1002 if (rc == -EEXIST && (lpni->lpni_state & LNET_PEER_NI_NON_MR_PREF)) {
1003 spin_lock(&lpni->lpni_lock);
1004 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1005 spin_unlock(&lpni->lpni_lock);
1007 CDEBUG(D_NET, "peer %s nid %s: %d\n",
1008 libcfs_nid2str(lp->lp_primary_nid), libcfs_nid2str(nid), rc);
1013 lnet_peer_del_pref_nid(struct lnet_peer_ni *lpni, lnet_nid_t nid)
1015 lnet_nid_t *nids = NULL;
1016 lnet_nid_t *oldnids = NULL;
1017 struct lnet_peer *lp = lpni->lpni_peer_net->lpn_peer;
1022 if (lpni->lpni_pref_nnids == 0) {
1027 if (lpni->lpni_pref_nnids == 1) {
1028 if (lpni->lpni_pref.nid != nid) {
1032 } else if (lpni->lpni_pref_nnids == 2) {
1033 if (lpni->lpni_pref.nids[0] != nid &&
1034 lpni->lpni_pref.nids[1] != nid) {
1039 size = sizeof(*nids) * (lpni->lpni_pref_nnids - 1);
1040 LIBCFS_CPT_ALLOC(nids, lnet_cpt_table(), lpni->lpni_cpt, size);
1045 for (i = 0, j = 0; i < lpni->lpni_pref_nnids; i++) {
1046 if (lpni->lpni_pref.nids[i] != nid)
1048 nids[j++] = lpni->lpni_pref.nids[i];
1050 /* Check if we actually removed a nid. */
1051 if (j == lpni->lpni_pref_nnids) {
1052 LIBCFS_FREE(nids, size);
1058 lnet_net_lock(LNET_LOCK_EX);
1059 spin_lock(&lpni->lpni_lock);
1060 if (lpni->lpni_pref_nnids == 1) {
1061 lpni->lpni_pref.nid = LNET_NID_ANY;
1062 } else if (lpni->lpni_pref_nnids == 2) {
1063 oldnids = lpni->lpni_pref.nids;
1064 if (oldnids[0] == nid)
1065 lpni->lpni_pref.nid = oldnids[1];
1067 lpni->lpni_pref.nid = oldnids[2];
1069 oldnids = lpni->lpni_pref.nids;
1070 lpni->lpni_pref.nids = nids;
1072 lpni->lpni_pref_nnids--;
1073 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
1074 spin_unlock(&lpni->lpni_lock);
1075 lnet_net_unlock(LNET_LOCK_EX);
1078 size = sizeof(*nids) * (lpni->lpni_pref_nnids + 1);
1079 LIBCFS_FREE(oldnids, sizeof(*oldnids) * size);
1082 CDEBUG(D_NET, "peer %s nid %s: %d\n",
1083 libcfs_nid2str(lp->lp_primary_nid), libcfs_nid2str(nid), rc);
1088 lnet_peer_primary_nid_locked(lnet_nid_t nid)
1090 struct lnet_peer_ni *lpni;
1091 lnet_nid_t primary_nid = nid;
1093 lpni = lnet_find_peer_ni_locked(nid);
1095 primary_nid = lpni->lpni_peer_net->lpn_peer->lp_primary_nid;
1096 lnet_peer_ni_decref_locked(lpni);
1103 LNetPrimaryNID(lnet_nid_t nid)
1105 struct lnet_peer *lp;
1106 struct lnet_peer_ni *lpni;
1107 lnet_nid_t primary_nid = nid;
1111 cpt = lnet_net_lock_current();
1112 lpni = lnet_nid2peerni_locked(nid, LNET_NID_ANY, cpt);
1117 lp = lpni->lpni_peer_net->lpn_peer;
1118 while (!lnet_peer_is_uptodate(lp)) {
1119 rc = lnet_discover_peer_locked(lpni, cpt, true);
1122 lp = lpni->lpni_peer_net->lpn_peer;
1124 primary_nid = lp->lp_primary_nid;
1126 lnet_peer_ni_decref_locked(lpni);
1128 lnet_net_unlock(cpt);
1130 CDEBUG(D_NET, "NID %s primary NID %s rc %d\n", libcfs_nid2str(nid),
1131 libcfs_nid2str(primary_nid), rc);
1134 EXPORT_SYMBOL(LNetPrimaryNID);
1136 struct lnet_peer_net *
1137 lnet_peer_get_net_locked(struct lnet_peer *peer, __u32 net_id)
1139 struct lnet_peer_net *peer_net;
1140 list_for_each_entry(peer_net, &peer->lp_peer_nets, lpn_peer_nets) {
1141 if (peer_net->lpn_net_id == net_id)
1148 * Attach a peer_ni to a peer_net and peer. This function assumes
1149 * peer_ni is not already attached to the peer_net/peer. The peer_ni
1150 * may be attached to a different peer, in which case it will be
1151 * properly detached first. The whole operation is done atomically.
1153 * Always returns 0. This is the last function called from functions
1154 * that do return an int, so returning 0 here allows the compiler to
1158 lnet_peer_attach_peer_ni(struct lnet_peer *lp,
1159 struct lnet_peer_net *lpn,
1160 struct lnet_peer_ni *lpni,
1163 struct lnet_peer_table *ptable;
1165 /* Install the new peer_ni */
1166 lnet_net_lock(LNET_LOCK_EX);
1167 /* Add peer_ni to global peer table hash, if necessary. */
1168 if (list_empty(&lpni->lpni_hashlist)) {
1169 int hash = lnet_nid2peerhash(lpni->lpni_nid);
1171 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
1172 list_add_tail(&lpni->lpni_hashlist, &ptable->pt_hash[hash]);
1173 ptable->pt_version++;
1174 ptable->pt_number++;
1175 /* This is the 1st refcount on lpni. */
1176 atomic_inc(&lpni->lpni_refcount);
1179 /* Detach the peer_ni from an existing peer, if necessary. */
1180 if (lpni->lpni_peer_net) {
1181 LASSERT(lpni->lpni_peer_net != lpn);
1182 LASSERT(lpni->lpni_peer_net->lpn_peer != lp);
1183 lnet_peer_detach_peer_ni_locked(lpni);
1184 lnet_peer_net_decref_locked(lpni->lpni_peer_net);
1185 lpni->lpni_peer_net = NULL;
1188 /* Add peer_ni to peer_net */
1189 lpni->lpni_peer_net = lpn;
1190 list_add_tail(&lpni->lpni_peer_nis, &lpn->lpn_peer_nis);
1191 lnet_peer_net_addref_locked(lpn);
1193 /* Add peer_net to peer */
1194 if (!lpn->lpn_peer) {
1196 list_add_tail(&lpn->lpn_peer_nets, &lp->lp_peer_nets);
1197 lnet_peer_addref_locked(lp);
1200 /* Add peer to global peer list, if necessary */
1201 ptable = the_lnet.ln_peer_tables[lp->lp_cpt];
1202 if (list_empty(&lp->lp_peer_list)) {
1203 list_add_tail(&lp->lp_peer_list, &ptable->pt_peer_list);
1208 /* Update peer state */
1209 spin_lock(&lp->lp_lock);
1210 if (flags & LNET_PEER_CONFIGURED) {
1211 if (!(lp->lp_state & LNET_PEER_CONFIGURED))
1212 lp->lp_state |= LNET_PEER_CONFIGURED;
1214 if (flags & LNET_PEER_MULTI_RAIL) {
1215 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1216 lp->lp_state |= LNET_PEER_MULTI_RAIL;
1217 lnet_peer_clr_non_mr_pref_nids(lp);
1220 spin_unlock(&lp->lp_lock);
1223 lnet_net_unlock(LNET_LOCK_EX);
1225 CDEBUG(D_NET, "peer %s NID %s flags %#x\n",
1226 libcfs_nid2str(lp->lp_primary_nid),
1227 libcfs_nid2str(lpni->lpni_nid), flags);
1233 * Create a new peer, with nid as its primary nid.
1235 * Call with the lnet_api_mutex held.
1238 lnet_peer_add(lnet_nid_t nid, unsigned flags)
1240 struct lnet_peer *lp;
1241 struct lnet_peer_net *lpn;
1242 struct lnet_peer_ni *lpni;
1245 LASSERT(nid != LNET_NID_ANY);
1248 * No need for the lnet_net_lock here, because the
1249 * lnet_api_mutex is held.
1251 lpni = lnet_find_peer_ni_locked(nid);
1253 /* A peer with this NID already exists. */
1254 lp = lpni->lpni_peer_net->lpn_peer;
1255 lnet_peer_ni_decref_locked(lpni);
1257 * This is an error if the peer was configured and the
1258 * primary NID differs or an attempt is made to change
1259 * the Multi-Rail flag. Otherwise the assumption is
1260 * that an existing peer is being modified.
1262 if (lp->lp_state & LNET_PEER_CONFIGURED) {
1263 if (lp->lp_primary_nid != nid)
1265 else if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL)
1269 /* Delete and recreate as a configured peer. */
1273 /* Create peer, peer_net, and peer_ni. */
1275 lp = lnet_peer_alloc(nid);
1278 lpn = lnet_peer_net_alloc(LNET_NIDNET(nid));
1281 lpni = lnet_peer_ni_alloc(nid);
1285 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1288 LIBCFS_FREE(lpn, sizeof(*lpn));
1290 LIBCFS_FREE(lp, sizeof(*lp));
1292 CDEBUG(D_NET, "peer %s NID flags %#x: %d\n",
1293 libcfs_nid2str(nid), flags, rc);
1298 * Add a NID to a peer. Call with ln_api_mutex held.
1301 * -EPERM: Non-DLC addition to a DLC-configured peer.
1302 * -EEXIST: The NID was configured by DLC for a different peer.
1303 * -ENOMEM: Out of memory.
1304 * -ENOTUNIQ: Adding a second peer NID on a single network on a
1305 * non-multi-rail peer.
1308 lnet_peer_add_nid(struct lnet_peer *lp, lnet_nid_t nid, unsigned flags)
1310 struct lnet_peer_net *lpn;
1311 struct lnet_peer_ni *lpni;
1315 LASSERT(nid != LNET_NID_ANY);
1317 /* A configured peer can only be updated through configuration. */
1318 if (!(flags & LNET_PEER_CONFIGURED)) {
1319 if (lp->lp_state & LNET_PEER_CONFIGURED) {
1326 * The MULTI_RAIL flag can be set but not cleared, because
1327 * that would leave the peer struct in an invalid state.
1329 if (flags & LNET_PEER_MULTI_RAIL) {
1330 spin_lock(&lp->lp_lock);
1331 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1332 lp->lp_state |= LNET_PEER_MULTI_RAIL;
1333 lnet_peer_clr_non_mr_pref_nids(lp);
1335 spin_unlock(&lp->lp_lock);
1336 } else if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
1341 lpni = lnet_find_peer_ni_locked(nid);
1344 * A peer_ni already exists. This is only a problem if
1345 * it is not connected to this peer and was configured
1348 lnet_peer_ni_decref_locked(lpni);
1349 if (lpni->lpni_peer_net->lpn_peer == lp)
1351 if (lnet_peer_ni_is_configured(lpni)) {
1355 /* If this is the primary NID, destroy the peer. */
1356 if (lnet_peer_ni_is_primary(lpni)) {
1357 lnet_peer_del(lpni->lpni_peer_net->lpn_peer);
1358 lpni = lnet_peer_ni_alloc(nid);
1365 lpni = lnet_peer_ni_alloc(nid);
1373 * Get the peer_net. Check that we're not adding a second
1374 * peer_ni on a peer_net of a non-multi-rail peer.
1376 lpn = lnet_peer_get_net_locked(lp, LNET_NIDNET(nid));
1378 lpn = lnet_peer_net_alloc(LNET_NIDNET(nid));
1383 } else if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1388 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1391 /* If the peer_ni was allocated above its peer_net pointer is NULL */
1392 if (!lpni->lpni_peer_net)
1393 LIBCFS_FREE(lpni, sizeof(*lpni));
1395 CDEBUG(D_NET, "peer %s NID %s flags %#x: %d\n",
1396 libcfs_nid2str(lp->lp_primary_nid), libcfs_nid2str(nid),
1402 * Update the primary NID of a peer, if possible.
1404 * Call with the lnet_api_mutex held.
1407 lnet_peer_set_primary_nid(struct lnet_peer *lp, lnet_nid_t nid, unsigned flags)
1409 lnet_nid_t old = lp->lp_primary_nid;
1412 if (lp->lp_primary_nid == nid)
1414 rc = lnet_peer_add_nid(lp, nid, flags);
1417 lp->lp_primary_nid = nid;
1419 CDEBUG(D_NET, "peer %s NID %s: %d\n",
1420 libcfs_nid2str(old), libcfs_nid2str(nid), rc);
1425 * lpni creation initiated due to traffic either sending or receiving.
1428 lnet_peer_ni_traffic_add(lnet_nid_t nid, lnet_nid_t pref)
1430 struct lnet_peer *lp;
1431 struct lnet_peer_net *lpn;
1432 struct lnet_peer_ni *lpni;
1436 if (nid == LNET_NID_ANY) {
1441 /* lnet_net_lock is not needed here because ln_api_lock is held */
1442 lpni = lnet_find_peer_ni_locked(nid);
1445 * We must have raced with another thread. Since we
1446 * know next to nothing about a peer_ni created by
1447 * traffic, we just assume everything is ok and
1450 lnet_peer_ni_decref_locked(lpni);
1454 /* Create peer, peer_net, and peer_ni. */
1456 lp = lnet_peer_alloc(nid);
1459 lpn = lnet_peer_net_alloc(LNET_NIDNET(nid));
1462 lpni = lnet_peer_ni_alloc(nid);
1465 if (pref != LNET_NID_ANY)
1466 lnet_peer_ni_set_non_mr_pref_nid(lpni, pref);
1468 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1471 LIBCFS_FREE(lpn, sizeof(*lpn));
1473 LIBCFS_FREE(lp, sizeof(*lp));
1475 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nid2str(nid), rc);
1480 * Implementation of IOC_LIBCFS_ADD_PEER_NI.
1482 * This API handles the following combinations:
1483 * Create a peer with its primary NI if only the prim_nid is provided
1484 * Add a NID to a peer identified by the prim_nid. The peer identified
1485 * by the prim_nid must already exist.
1486 * The peer being created may be non-MR.
1488 * The caller must hold ln_api_mutex. This prevents the peer from
1489 * being created/modified/deleted by a different thread.
1492 lnet_add_peer_ni(lnet_nid_t prim_nid, lnet_nid_t nid, bool mr)
1494 struct lnet_peer *lp = NULL;
1495 struct lnet_peer_ni *lpni;
1498 /* The prim_nid must always be specified */
1499 if (prim_nid == LNET_NID_ANY)
1502 flags = LNET_PEER_CONFIGURED;
1504 flags |= LNET_PEER_MULTI_RAIL;
1507 * If nid isn't specified, we must create a new peer with
1508 * prim_nid as its primary nid.
1510 if (nid == LNET_NID_ANY)
1511 return lnet_peer_add(prim_nid, flags);
1513 /* Look up the prim_nid, which must exist. */
1514 lpni = lnet_find_peer_ni_locked(prim_nid);
1517 lnet_peer_ni_decref_locked(lpni);
1518 lp = lpni->lpni_peer_net->lpn_peer;
1520 /* Peer must have been configured. */
1521 if (!(lp->lp_state & LNET_PEER_CONFIGURED)) {
1522 CDEBUG(D_NET, "peer %s was not configured\n",
1523 libcfs_nid2str(prim_nid));
1527 /* Primary NID must match */
1528 if (lp->lp_primary_nid != prim_nid) {
1529 CDEBUG(D_NET, "prim_nid %s is not primary for peer %s\n",
1530 libcfs_nid2str(prim_nid),
1531 libcfs_nid2str(lp->lp_primary_nid));
1535 /* Multi-Rail flag must match. */
1536 if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL) {
1537 CDEBUG(D_NET, "multi-rail state mismatch for peer %s\n",
1538 libcfs_nid2str(prim_nid));
1542 return lnet_peer_add_nid(lp, nid, flags);
1546 * Implementation of IOC_LIBCFS_DEL_PEER_NI.
1548 * This API handles the following combinations:
1549 * Delete a NI from a peer if both prim_nid and nid are provided.
1550 * Delete a peer if only prim_nid is provided.
1551 * Delete a peer if its primary nid is provided.
1553 * The caller must hold ln_api_mutex. This prevents the peer from
1554 * being modified/deleted by a different thread.
1557 lnet_del_peer_ni(lnet_nid_t prim_nid, lnet_nid_t nid)
1559 struct lnet_peer *lp;
1560 struct lnet_peer_ni *lpni;
1563 if (prim_nid == LNET_NID_ANY)
1566 lpni = lnet_find_peer_ni_locked(prim_nid);
1569 lnet_peer_ni_decref_locked(lpni);
1570 lp = lpni->lpni_peer_net->lpn_peer;
1572 if (prim_nid != lp->lp_primary_nid) {
1573 CDEBUG(D_NET, "prim_nid %s is not primary for peer %s\n",
1574 libcfs_nid2str(prim_nid),
1575 libcfs_nid2str(lp->lp_primary_nid));
1579 lnet_net_lock(LNET_LOCK_EX);
1580 if (lp->lp_rtr_refcount > 0) {
1581 lnet_net_unlock(LNET_LOCK_EX);
1582 CERROR("%s is a router. Can not be deleted\n",
1583 libcfs_nid2str(prim_nid));
1586 lnet_net_unlock(LNET_LOCK_EX);
1588 if (nid == LNET_NID_ANY || nid == lp->lp_primary_nid)
1589 return lnet_peer_del(lp);
1591 flags = LNET_PEER_CONFIGURED;
1592 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
1593 flags |= LNET_PEER_MULTI_RAIL;
1595 return lnet_peer_del_nid(lp, nid, flags);
1599 lnet_destroy_peer_ni_locked(struct lnet_peer_ni *lpni)
1601 struct lnet_peer_table *ptable;
1602 struct lnet_peer_net *lpn;
1604 CDEBUG(D_NET, "%p nid %s\n", lpni, libcfs_nid2str(lpni->lpni_nid));
1606 LASSERT(atomic_read(&lpni->lpni_refcount) == 0);
1607 LASSERT(list_empty(&lpni->lpni_txq));
1608 LASSERT(lpni->lpni_txqnob == 0);
1609 LASSERT(list_empty(&lpni->lpni_peer_nis));
1610 LASSERT(list_empty(&lpni->lpni_on_remote_peer_ni_list));
1612 lpn = lpni->lpni_peer_net;
1613 lpni->lpni_peer_net = NULL;
1614 lpni->lpni_net = NULL;
1616 /* remove the peer ni from the zombie list */
1617 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
1618 spin_lock(&ptable->pt_zombie_lock);
1619 list_del_init(&lpni->lpni_hashlist);
1620 ptable->pt_zombies--;
1621 spin_unlock(&ptable->pt_zombie_lock);
1623 if (lpni->lpni_pref_nnids > 1) {
1624 LIBCFS_FREE(lpni->lpni_pref.nids,
1625 sizeof(*lpni->lpni_pref.nids) * lpni->lpni_pref_nnids);
1627 LIBCFS_FREE(lpni, sizeof(*lpni));
1629 lnet_peer_net_decref_locked(lpn);
1632 struct lnet_peer_ni *
1633 lnet_nid2peerni_ex(lnet_nid_t nid, int cpt)
1635 struct lnet_peer_ni *lpni = NULL;
1638 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1639 return ERR_PTR(-ESHUTDOWN);
1642 * find if a peer_ni already exists.
1643 * If so then just return that.
1645 lpni = lnet_find_peer_ni_locked(nid);
1649 lnet_net_unlock(cpt);
1651 rc = lnet_peer_ni_traffic_add(nid, LNET_NID_ANY);
1654 goto out_net_relock;
1657 lpni = lnet_find_peer_ni_locked(nid);
1667 * Get a peer_ni for the given nid, create it if necessary. Takes a
1668 * hold on the peer_ni.
1670 struct lnet_peer_ni *
1671 lnet_nid2peerni_locked(lnet_nid_t nid, lnet_nid_t pref, int cpt)
1673 struct lnet_peer_ni *lpni = NULL;
1676 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1677 return ERR_PTR(-ESHUTDOWN);
1680 * find if a peer_ni already exists.
1681 * If so then just return that.
1683 lpni = lnet_find_peer_ni_locked(nid);
1689 * use the lnet_api_mutex to serialize the creation of the peer_ni
1690 * and the creation/deletion of the local ni/net. When a local ni is
1691 * created, if there exists a set of peer_nis on that network,
1692 * they need to be traversed and updated. When a local NI is
1693 * deleted, which could result in a network being deleted, then
1694 * all peer nis on that network need to be removed as well.
1696 * Creation through traffic should also be serialized with
1697 * creation through DLC.
1699 lnet_net_unlock(cpt);
1700 mutex_lock(&the_lnet.ln_api_mutex);
1702 * Shutdown is only set under the ln_api_lock, so a single
1703 * check here is sufficent.
1705 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1706 lpni = ERR_PTR(-ESHUTDOWN);
1707 goto out_mutex_unlock;
1710 rc = lnet_peer_ni_traffic_add(nid, pref);
1713 goto out_mutex_unlock;
1716 lpni = lnet_find_peer_ni_locked(nid);
1720 mutex_unlock(&the_lnet.ln_api_mutex);
1723 /* Lock has been dropped, check again for shutdown. */
1724 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1726 lnet_peer_ni_decref_locked(lpni);
1727 lpni = ERR_PTR(-ESHUTDOWN);
1738 lnet_peer_gw_discovery(struct lnet_peer *lp)
1742 spin_lock(&lp->lp_lock);
1743 if (lp->lp_state & LNET_PEER_RTR_DISCOVERY)
1745 spin_unlock(&lp->lp_lock);
1751 * Is a peer uptodate from the point of view of discovery?
1753 * If it is currently being processed, obviously not.
1754 * A forced Ping or Push is also handled by the discovery thread.
1756 * Otherwise look at whether the peer needs rediscovering.
1759 lnet_peer_is_uptodate(struct lnet_peer *lp)
1763 spin_lock(&lp->lp_lock);
1764 if (lp->lp_state & (LNET_PEER_DISCOVERING |
1765 LNET_PEER_FORCE_PING |
1766 LNET_PEER_FORCE_PUSH)) {
1768 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
1770 } else if (lp->lp_state & LNET_PEER_REDISCOVER) {
1771 if (lnet_peer_discovery_disabled)
1775 } else if (lnet_peer_needs_push(lp)) {
1777 } else if (lp->lp_state & LNET_PEER_DISCOVERED) {
1778 if (lp->lp_state & LNET_PEER_NIDS_UPTODATE)
1785 spin_unlock(&lp->lp_lock);
1791 * Queue a peer for the attention of the discovery thread. Call with
1792 * lnet_net_lock/EX held. Returns 0 if the peer was queued, and
1793 * -EALREADY if the peer was already queued.
1795 static int lnet_peer_queue_for_discovery(struct lnet_peer *lp)
1799 spin_lock(&lp->lp_lock);
1800 if (!(lp->lp_state & LNET_PEER_DISCOVERING))
1801 lp->lp_state |= LNET_PEER_DISCOVERING;
1802 spin_unlock(&lp->lp_lock);
1803 if (list_empty(&lp->lp_dc_list)) {
1804 lnet_peer_addref_locked(lp);
1805 list_add_tail(&lp->lp_dc_list, &the_lnet.ln_dc_request);
1806 wake_up(&the_lnet.ln_dc_waitq);
1812 CDEBUG(D_NET, "Queue peer %s: %d\n",
1813 libcfs_nid2str(lp->lp_primary_nid), rc);
1819 * Discovery of a peer is complete. Wake all waiters on the peer.
1820 * Call with lnet_net_lock/EX held.
1822 static void lnet_peer_discovery_complete(struct lnet_peer *lp)
1824 struct lnet_msg *msg, *tmp;
1826 struct list_head pending_msgs;
1828 INIT_LIST_HEAD(&pending_msgs);
1830 CDEBUG(D_NET, "Discovery complete. Dequeue peer %s\n",
1831 libcfs_nid2str(lp->lp_primary_nid));
1833 list_del_init(&lp->lp_dc_list);
1834 spin_lock(&lp->lp_lock);
1835 list_splice_init(&lp->lp_dc_pendq, &pending_msgs);
1836 spin_unlock(&lp->lp_lock);
1837 wake_up_all(&lp->lp_dc_waitq);
1839 if (lp->lp_rtr_refcount > 0)
1840 lnet_router_discovery_complete(lp);
1842 lnet_net_unlock(LNET_LOCK_EX);
1844 /* iterate through all pending messages and send them again */
1845 list_for_each_entry_safe(msg, tmp, &pending_msgs, msg_list) {
1846 list_del_init(&msg->msg_list);
1847 if (lp->lp_dc_error) {
1848 lnet_finalize(msg, lp->lp_dc_error);
1852 CDEBUG(D_NET, "sending pending message %s to target %s\n",
1853 lnet_msgtyp2str(msg->msg_type),
1854 libcfs_id2str(msg->msg_target));
1855 rc = lnet_send(msg->msg_src_nid_param, msg,
1856 msg->msg_rtr_nid_param);
1858 CNETERR("Error sending %s to %s: %d\n",
1859 lnet_msgtyp2str(msg->msg_type),
1860 libcfs_id2str(msg->msg_target), rc);
1861 lnet_finalize(msg, rc);
1864 lnet_net_lock(LNET_LOCK_EX);
1865 lnet_peer_decref_locked(lp);
1869 * Handle inbound push.
1870 * Like any event handler, called with lnet_res_lock/CPT held.
1872 void lnet_peer_push_event(struct lnet_event *ev)
1874 struct lnet_ping_buffer *pbuf = ev->md.user_ptr;
1875 struct lnet_peer *lp;
1877 /* lnet_find_peer() adds a refcount */
1878 lp = lnet_find_peer(ev->source.nid);
1880 CDEBUG(D_NET, "Push Put from unknown %s (source %s). Ignoring...\n",
1881 libcfs_nid2str(ev->initiator.nid),
1882 libcfs_nid2str(ev->source.nid));
1886 /* Ensure peer state remains consistent while we modify it. */
1887 spin_lock(&lp->lp_lock);
1890 * If some kind of error happened the contents of the message
1891 * cannot be used. Clear the NIDS_UPTODATE and set the
1892 * FORCE_PING flag to trigger a ping.
1895 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
1896 lp->lp_state |= LNET_PEER_FORCE_PING;
1897 CDEBUG(D_NET, "Push Put error %d from %s (source %s)\n",
1899 libcfs_nid2str(lp->lp_primary_nid),
1900 libcfs_nid2str(ev->source.nid));
1905 * A push with invalid or corrupted info. Clear the UPTODATE
1906 * flag to trigger a ping.
1908 if (lnet_ping_info_validate(&pbuf->pb_info)) {
1909 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
1910 lp->lp_state |= LNET_PEER_FORCE_PING;
1911 CDEBUG(D_NET, "Corrupted Push from %s\n",
1912 libcfs_nid2str(lp->lp_primary_nid));
1917 * Make sure we'll allocate the correct size ping buffer when
1920 if (lp->lp_data_nnis < pbuf->pb_info.pi_nnis)
1921 lp->lp_data_nnis = pbuf->pb_info.pi_nnis;
1924 * A non-Multi-Rail peer is not supposed to be capable of
1927 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)) {
1928 CERROR("Push from non-Multi-Rail peer %s dropped\n",
1929 libcfs_nid2str(lp->lp_primary_nid));
1934 * Check the MULTIRAIL flag. Complain if the peer was DLC
1935 * configured without it.
1937 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1938 if (lp->lp_state & LNET_PEER_CONFIGURED) {
1939 CERROR("Push says %s is Multi-Rail, DLC says not\n",
1940 libcfs_nid2str(lp->lp_primary_nid));
1942 lp->lp_state |= LNET_PEER_MULTI_RAIL;
1943 lnet_peer_clr_non_mr_pref_nids(lp);
1948 * The peer may have discovery disabled at its end. Set
1949 * NO_DISCOVERY as appropriate.
1951 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_DISCOVERY)) {
1952 CDEBUG(D_NET, "Peer %s has discovery disabled\n",
1953 libcfs_nid2str(lp->lp_primary_nid));
1954 lp->lp_state |= LNET_PEER_NO_DISCOVERY;
1955 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
1956 CDEBUG(D_NET, "Peer %s has discovery enabled\n",
1957 libcfs_nid2str(lp->lp_primary_nid));
1958 lp->lp_state &= ~LNET_PEER_NO_DISCOVERY;
1962 * Check for truncation of the Put message. Clear the
1963 * NIDS_UPTODATE flag and set FORCE_PING to trigger a ping,
1964 * and tell discovery to allocate a bigger buffer.
1966 if (pbuf->pb_nnis < pbuf->pb_info.pi_nnis) {
1967 if (the_lnet.ln_push_target_nnis < pbuf->pb_info.pi_nnis)
1968 the_lnet.ln_push_target_nnis = pbuf->pb_info.pi_nnis;
1969 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
1970 lp->lp_state |= LNET_PEER_FORCE_PING;
1971 CDEBUG(D_NET, "Truncated Push from %s (%d nids)\n",
1972 libcfs_nid2str(lp->lp_primary_nid),
1973 pbuf->pb_info.pi_nnis);
1978 * Check whether the Put data is stale. Stale data can just be
1981 if (pbuf->pb_info.pi_nnis > 1 &&
1982 lp->lp_primary_nid == pbuf->pb_info.pi_ni[1].ns_nid &&
1983 LNET_PING_BUFFER_SEQNO(pbuf) < lp->lp_peer_seqno) {
1984 CDEBUG(D_NET, "Stale Push from %s: got %u have %u\n",
1985 libcfs_nid2str(lp->lp_primary_nid),
1986 LNET_PING_BUFFER_SEQNO(pbuf),
1992 * Check whether the Put data is new, in which case we clear
1993 * the UPTODATE flag and prepare to process it.
1995 * If the Put data is current, and the peer is UPTODATE then
1996 * we assome everything is all right and drop the data as
1999 if (LNET_PING_BUFFER_SEQNO(pbuf) > lp->lp_peer_seqno) {
2000 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2001 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2002 } else if (lp->lp_state & LNET_PEER_NIDS_UPTODATE) {
2003 CDEBUG(D_NET, "Stale Push from %s: got %u have %u\n",
2004 libcfs_nid2str(lp->lp_primary_nid),
2005 LNET_PING_BUFFER_SEQNO(pbuf),
2011 * If there is data present that hasn't been processed yet,
2012 * we'll replace it if the Put contained newer data and it
2013 * fits. We're racing with a Ping or earlier Push in this
2016 if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
2017 if (LNET_PING_BUFFER_SEQNO(pbuf) >
2018 LNET_PING_BUFFER_SEQNO(lp->lp_data) &&
2019 pbuf->pb_info.pi_nnis <= lp->lp_data->pb_nnis) {
2020 memcpy(&lp->lp_data->pb_info, &pbuf->pb_info,
2021 LNET_PING_INFO_SIZE(pbuf->pb_info.pi_nnis));
2022 CDEBUG(D_NET, "Ping/Push race from %s: %u vs %u\n",
2023 libcfs_nid2str(lp->lp_primary_nid),
2024 LNET_PING_BUFFER_SEQNO(pbuf),
2025 LNET_PING_BUFFER_SEQNO(lp->lp_data));
2031 * Allocate a buffer to copy the data. On a failure we drop
2032 * the Push and set FORCE_PING to force the discovery
2033 * thread to fix the problem by pinging the peer.
2035 lp->lp_data = lnet_ping_buffer_alloc(lp->lp_data_nnis, GFP_ATOMIC);
2037 lp->lp_state |= LNET_PEER_FORCE_PING;
2038 CDEBUG(D_NET, "Cannot allocate Push buffer for %s %u\n",
2039 libcfs_nid2str(lp->lp_primary_nid),
2040 LNET_PING_BUFFER_SEQNO(pbuf));
2045 memcpy(&lp->lp_data->pb_info, &pbuf->pb_info,
2046 LNET_PING_INFO_SIZE(pbuf->pb_info.pi_nnis));
2047 lp->lp_state |= LNET_PEER_DATA_PRESENT;
2048 CDEBUG(D_NET, "Received Push %s %u\n",
2049 libcfs_nid2str(lp->lp_primary_nid),
2050 LNET_PING_BUFFER_SEQNO(pbuf));
2054 * Queue the peer for discovery if not done, force it on the request
2055 * queue and wake the discovery thread if the peer was already queued,
2056 * because its status changed.
2058 spin_unlock(&lp->lp_lock);
2059 lnet_net_lock(LNET_LOCK_EX);
2060 if (!lnet_peer_is_uptodate(lp) && lnet_peer_queue_for_discovery(lp)) {
2061 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2062 wake_up(&the_lnet.ln_dc_waitq);
2064 /* Drop refcount from lookup */
2065 lnet_peer_decref_locked(lp);
2066 lnet_net_unlock(LNET_LOCK_EX);
2070 * Clear the discovery error state, unless we're already discovering
2071 * this peer, in which case the error is current.
2073 static void lnet_peer_clear_discovery_error(struct lnet_peer *lp)
2075 spin_lock(&lp->lp_lock);
2076 if (!(lp->lp_state & LNET_PEER_DISCOVERING))
2077 lp->lp_dc_error = 0;
2078 spin_unlock(&lp->lp_lock);
2082 * Peer discovery slow path. The ln_api_mutex is held on entry, and
2083 * dropped/retaken within this function. An lnet_peer_ni is passed in
2084 * because discovery could tear down an lnet_peer.
2087 lnet_discover_peer_locked(struct lnet_peer_ni *lpni, int cpt, bool block)
2090 struct lnet_peer *lp;
2094 lnet_net_unlock(cpt);
2095 lnet_net_lock(LNET_LOCK_EX);
2096 lp = lpni->lpni_peer_net->lpn_peer;
2097 lnet_peer_clear_discovery_error(lp);
2100 * We're willing to be interrupted. The lpni can become a
2101 * zombie if we race with DLC, so we must check for that.
2104 prepare_to_wait(&lp->lp_dc_waitq, &wait, TASK_INTERRUPTIBLE);
2105 if (signal_pending(current))
2107 if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING)
2109 if (lp->lp_dc_error)
2111 if (lnet_peer_is_uptodate(lp))
2113 lnet_peer_queue_for_discovery(lp);
2115 * if caller requested a non-blocking operation then
2116 * return immediately. Once discovery is complete then the
2117 * peer ref will be decremented and any pending messages
2118 * that were stopped due to discovery will be transmitted.
2123 lnet_peer_addref_locked(lp);
2124 lnet_net_unlock(LNET_LOCK_EX);
2126 finish_wait(&lp->lp_dc_waitq, &wait);
2127 lnet_net_lock(LNET_LOCK_EX);
2128 lnet_peer_decref_locked(lp);
2129 /* Peer may have changed */
2130 lp = lpni->lpni_peer_net->lpn_peer;
2132 finish_wait(&lp->lp_dc_waitq, &wait);
2134 lnet_net_unlock(LNET_LOCK_EX);
2138 * If the peer has changed after we've discovered the older peer,
2139 * then we need to discovery the new peer to make sure the
2140 * interface information is up to date
2142 if (lp != lpni->lpni_peer_net->lpn_peer)
2145 if (signal_pending(current))
2147 else if (the_lnet.ln_dc_state != LNET_DC_STATE_RUNNING)
2149 else if (lp->lp_dc_error)
2150 rc = lp->lp_dc_error;
2152 CDEBUG(D_NET, "non-blocking discovery\n");
2153 else if (!lnet_peer_is_uptodate(lp))
2156 CDEBUG(D_NET, "peer %s NID %s: %d. %s\n",
2157 (lp ? libcfs_nid2str(lp->lp_primary_nid) : "(none)"),
2158 libcfs_nid2str(lpni->lpni_nid), rc,
2159 (!block) ? "pending discovery" : "discovery complete");
2164 /* Handle an incoming ack for a push. */
2166 lnet_discovery_event_ack(struct lnet_peer *lp, struct lnet_event *ev)
2168 struct lnet_ping_buffer *pbuf;
2170 pbuf = LNET_PING_INFO_TO_BUFFER(ev->md.start);
2171 spin_lock(&lp->lp_lock);
2172 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2173 lp->lp_push_error = ev->status;
2175 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2177 lp->lp_node_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2178 spin_unlock(&lp->lp_lock);
2180 CDEBUG(D_NET, "peer %s ev->status %d\n",
2181 libcfs_nid2str(lp->lp_primary_nid), ev->status);
2184 /* Handle a Reply message. This is the reply to a Ping message. */
2186 lnet_discovery_event_reply(struct lnet_peer *lp, struct lnet_event *ev)
2188 struct lnet_ping_buffer *pbuf;
2191 spin_lock(&lp->lp_lock);
2194 * If some kind of error happened the contents of message
2195 * cannot be used. Set PING_FAILED to trigger a retry.
2198 lp->lp_state |= LNET_PEER_PING_FAILED;
2199 lp->lp_ping_error = ev->status;
2200 CDEBUG(D_NET, "Ping Reply error %d from %s (source %s)\n",
2202 libcfs_nid2str(lp->lp_primary_nid),
2203 libcfs_nid2str(ev->source.nid));
2207 pbuf = LNET_PING_INFO_TO_BUFFER(ev->md.start);
2208 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
2209 lnet_swap_pinginfo(pbuf);
2212 * A reply with invalid or corrupted info. Set PING_FAILED to
2215 rc = lnet_ping_info_validate(&pbuf->pb_info);
2217 lp->lp_state |= LNET_PEER_PING_FAILED;
2218 lp->lp_ping_error = 0;
2219 CDEBUG(D_NET, "Corrupted Ping Reply from %s: %d\n",
2220 libcfs_nid2str(lp->lp_primary_nid), rc);
2225 * Update the MULTI_RAIL flag based on the reply. If the peer
2226 * was configured with DLC then the setting should match what
2229 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL) {
2230 if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2231 /* Everything's fine */
2232 } else if (lp->lp_state & LNET_PEER_CONFIGURED) {
2233 CWARN("Reply says %s is Multi-Rail, DLC says not\n",
2234 libcfs_nid2str(lp->lp_primary_nid));
2236 lp->lp_state |= LNET_PEER_MULTI_RAIL;
2237 lnet_peer_clr_non_mr_pref_nids(lp);
2239 } else if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2240 if (lp->lp_state & LNET_PEER_CONFIGURED) {
2241 CWARN("DLC says %s is Multi-Rail, Reply says not\n",
2242 libcfs_nid2str(lp->lp_primary_nid));
2244 CERROR("Multi-Rail state vanished from %s\n",
2245 libcfs_nid2str(lp->lp_primary_nid));
2246 lp->lp_state &= ~LNET_PEER_MULTI_RAIL;
2251 * Make sure we'll allocate the correct size ping buffer when
2254 if (lp->lp_data_nnis < pbuf->pb_info.pi_nnis)
2255 lp->lp_data_nnis = pbuf->pb_info.pi_nnis;
2258 * The peer may have discovery disabled at its end. Set
2259 * NO_DISCOVERY as appropriate.
2261 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_DISCOVERY)) {
2262 CDEBUG(D_NET, "Peer %s has discovery disabled\n",
2263 libcfs_nid2str(lp->lp_primary_nid));
2264 lp->lp_state |= LNET_PEER_NO_DISCOVERY;
2265 } else if (lp->lp_state & LNET_PEER_NO_DISCOVERY) {
2266 CDEBUG(D_NET, "Peer %s has discovery enabled\n",
2267 libcfs_nid2str(lp->lp_primary_nid));
2268 lp->lp_state &= ~LNET_PEER_NO_DISCOVERY;
2272 * Check for truncation of the Reply. Clear PING_SENT and set
2273 * PING_FAILED to trigger a retry.
2275 if (pbuf->pb_nnis < pbuf->pb_info.pi_nnis) {
2276 if (the_lnet.ln_push_target_nnis < pbuf->pb_info.pi_nnis)
2277 the_lnet.ln_push_target_nnis = pbuf->pb_info.pi_nnis;
2278 lp->lp_state |= LNET_PEER_PING_FAILED;
2279 lp->lp_ping_error = 0;
2280 CDEBUG(D_NET, "Truncated Reply from %s (%d nids)\n",
2281 libcfs_nid2str(lp->lp_primary_nid),
2282 pbuf->pb_info.pi_nnis);
2287 * Check the sequence numbers in the reply. These are only
2288 * available if the reply came from a Multi-Rail peer.
2290 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL &&
2291 pbuf->pb_info.pi_nnis > 1 &&
2292 lp->lp_primary_nid == pbuf->pb_info.pi_ni[1].ns_nid) {
2293 if (LNET_PING_BUFFER_SEQNO(pbuf) < lp->lp_peer_seqno) {
2294 CDEBUG(D_NET, "Stale Reply from %s: got %u have %u\n",
2295 libcfs_nid2str(lp->lp_primary_nid),
2296 LNET_PING_BUFFER_SEQNO(pbuf),
2301 if (LNET_PING_BUFFER_SEQNO(pbuf) > lp->lp_peer_seqno)
2302 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2305 /* We're happy with the state of the data in the buffer. */
2306 CDEBUG(D_NET, "peer %s data present %u\n",
2307 libcfs_nid2str(lp->lp_primary_nid), lp->lp_peer_seqno);
2308 if (lp->lp_state & LNET_PEER_DATA_PRESENT)
2309 lnet_ping_buffer_decref(lp->lp_data);
2311 lp->lp_state |= LNET_PEER_DATA_PRESENT;
2312 lnet_ping_buffer_addref(pbuf);
2315 lp->lp_state &= ~LNET_PEER_PING_SENT;
2316 spin_unlock(&lp->lp_lock);
2320 * Send event handling. Only matters for error cases, where we clean
2321 * up state on the peer and peer_ni that would otherwise be updated in
2322 * the REPLY event handler for a successful Ping, and the ACK event
2323 * handler for a successful Push.
2326 lnet_discovery_event_send(struct lnet_peer *lp, struct lnet_event *ev)
2333 spin_lock(&lp->lp_lock);
2334 if (ev->msg_type == LNET_MSG_GET) {
2335 lp->lp_state &= ~LNET_PEER_PING_SENT;
2336 lp->lp_state |= LNET_PEER_PING_FAILED;
2337 lp->lp_ping_error = ev->status;
2338 } else { /* ev->msg_type == LNET_MSG_PUT */
2339 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2340 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2341 lp->lp_push_error = ev->status;
2343 spin_unlock(&lp->lp_lock);
2344 rc = LNET_REDISCOVER_PEER;
2346 CDEBUG(D_NET, "%s Send to %s: %d\n",
2347 (ev->msg_type == LNET_MSG_GET ? "Ping" : "Push"),
2348 libcfs_nid2str(ev->target.nid), rc);
2353 * Unlink event handling. This event is only seen if a call to
2354 * LNetMDUnlink() caused the event to be unlinked. If this call was
2355 * made after the event was set up in LNetGet() or LNetPut() then we
2356 * assume the Ping or Push timed out.
2359 lnet_discovery_event_unlink(struct lnet_peer *lp, struct lnet_event *ev)
2361 spin_lock(&lp->lp_lock);
2362 /* We've passed through LNetGet() */
2363 if (lp->lp_state & LNET_PEER_PING_SENT) {
2364 lp->lp_state &= ~LNET_PEER_PING_SENT;
2365 lp->lp_state |= LNET_PEER_PING_FAILED;
2366 lp->lp_ping_error = -ETIMEDOUT;
2367 CDEBUG(D_NET, "Ping Unlink for message to peer %s\n",
2368 libcfs_nid2str(lp->lp_primary_nid));
2370 /* We've passed through LNetPut() */
2371 if (lp->lp_state & LNET_PEER_PUSH_SENT) {
2372 lp->lp_state &= ~LNET_PEER_PUSH_SENT;
2373 lp->lp_state |= LNET_PEER_PUSH_FAILED;
2374 lp->lp_push_error = -ETIMEDOUT;
2375 CDEBUG(D_NET, "Push Unlink for message to peer %s\n",
2376 libcfs_nid2str(lp->lp_primary_nid));
2378 spin_unlock(&lp->lp_lock);
2382 * Event handler for the discovery EQ.
2384 * Called with lnet_res_lock(cpt) held. The cpt is the
2385 * lnet_cpt_of_cookie() of the md handle cookie.
2387 static void lnet_discovery_event_handler(struct lnet_event *event)
2389 struct lnet_peer *lp = event->md.user_ptr;
2390 struct lnet_ping_buffer *pbuf;
2393 /* discovery needs to take another look */
2394 rc = LNET_REDISCOVER_PEER;
2396 CDEBUG(D_NET, "Received event: %d\n", event->type);
2398 switch (event->type) {
2399 case LNET_EVENT_ACK:
2400 lnet_discovery_event_ack(lp, event);
2402 case LNET_EVENT_REPLY:
2403 lnet_discovery_event_reply(lp, event);
2405 case LNET_EVENT_SEND:
2406 /* Only send failure triggers a retry. */
2407 rc = lnet_discovery_event_send(lp, event);
2409 case LNET_EVENT_UNLINK:
2410 /* LNetMDUnlink() was called */
2411 lnet_discovery_event_unlink(lp, event);
2414 /* Invalid events. */
2417 lnet_net_lock(LNET_LOCK_EX);
2418 if (event->unlinked) {
2419 pbuf = LNET_PING_INFO_TO_BUFFER(event->md.start);
2420 lnet_ping_buffer_decref(pbuf);
2421 lnet_peer_decref_locked(lp);
2424 /* put peer back at end of request queue, if discovery not already
2426 if (rc == LNET_REDISCOVER_PEER && !lnet_peer_is_uptodate(lp)) {
2427 list_move_tail(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2428 wake_up(&the_lnet.ln_dc_waitq);
2430 lnet_net_unlock(LNET_LOCK_EX);
2434 * Build a peer from incoming data.
2436 * The NIDs in the incoming data are supposed to be structured as follows:
2439 * - other NIDs in same net
2440 * - NIDs in second net
2441 * - NIDs in third net
2443 * This due to the way the list of NIDs in the data is created.
2445 * Note that this function will mark the peer uptodate unless an
2446 * ENOMEM is encontered. All other errors are due to a conflict
2447 * between the DLC configuration and what discovery sees. We treat DLC
2448 * as binding, and therefore set the NIDS_UPTODATE flag to prevent the
2449 * peer from becoming stuck in discovery.
2451 static int lnet_peer_merge_data(struct lnet_peer *lp,
2452 struct lnet_ping_buffer *pbuf)
2454 struct lnet_peer_ni *lpni;
2455 lnet_nid_t *curnis = NULL;
2456 struct lnet_ni_status *addnis = NULL;
2457 lnet_nid_t *delnis = NULL;
2467 flags = LNET_PEER_DISCOVERED;
2468 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)
2469 flags |= LNET_PEER_MULTI_RAIL;
2472 * Cache the routing feature for the peer; whether it is enabled
2473 * for disabled as reported by the remote peer.
2475 spin_lock(&lp->lp_lock);
2476 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_RTE_DISABLED))
2477 lp->lp_state |= LNET_PEER_ROUTER_ENABLED;
2479 lp->lp_state &= ~LNET_PEER_ROUTER_ENABLED;
2480 spin_unlock(&lp->lp_lock);
2482 nnis = MAX(lp->lp_nnis, pbuf->pb_info.pi_nnis);
2483 LIBCFS_ALLOC(curnis, nnis * sizeof(*curnis));
2484 LIBCFS_ALLOC(addnis, nnis * sizeof(*addnis));
2485 LIBCFS_ALLOC(delnis, nnis * sizeof(*delnis));
2486 if (!curnis || !addnis || !delnis) {
2494 /* Construct the list of NIDs present in peer. */
2496 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
2497 curnis[ncurnis++] = lpni->lpni_nid;
2500 * Check for NIDs in pbuf not present in curnis[].
2501 * The loop starts at 1 to skip the loopback NID.
2503 for (i = 1; i < pbuf->pb_info.pi_nnis; i++) {
2504 for (j = 0; j < ncurnis; j++)
2505 if (pbuf->pb_info.pi_ni[i].ns_nid == curnis[j])
2508 addnis[naddnis++] = pbuf->pb_info.pi_ni[i];
2511 * Check for NIDs in curnis[] not present in pbuf.
2512 * The nested loop starts at 1 to skip the loopback NID.
2514 * But never add the loopback NID to delnis[]: if it is
2515 * present in curnis[] then this peer is for this node.
2517 for (i = 0; i < ncurnis; i++) {
2518 if (LNET_NETTYP(LNET_NIDNET(curnis[i])) == LOLND)
2520 for (j = 1; j < pbuf->pb_info.pi_nnis; j++) {
2521 if (curnis[i] == pbuf->pb_info.pi_ni[j].ns_nid) {
2523 * update the information we cache for the
2524 * peer with the latest information we
2527 lpni = lnet_find_peer_ni_locked(curnis[i]);
2529 lpni->lpni_ns_status = pbuf->pb_info.pi_ni[j].ns_status;
2530 lnet_peer_ni_decref_locked(lpni);
2535 if (j == pbuf->pb_info.pi_nnis)
2536 delnis[ndelnis++] = curnis[i];
2539 for (i = 0; i < naddnis; i++) {
2540 rc = lnet_peer_add_nid(lp, addnis[i].ns_nid, flags);
2542 CERROR("Error adding NID %s to peer %s: %d\n",
2543 libcfs_nid2str(addnis[i].ns_nid),
2544 libcfs_nid2str(lp->lp_primary_nid), rc);
2548 lpni = lnet_find_peer_ni_locked(addnis[i].ns_nid);
2550 lpni->lpni_ns_status = addnis[i].ns_status;
2551 lnet_peer_ni_decref_locked(lpni);
2555 for (i = 0; i < ndelnis; i++) {
2556 rc = lnet_peer_del_nid(lp, delnis[i], flags);
2558 CERROR("Error deleting NID %s from peer %s: %d\n",
2559 libcfs_nid2str(delnis[i]),
2560 libcfs_nid2str(lp->lp_primary_nid), rc);
2566 * Errors other than -ENOMEM are due to peers having been
2567 * configured with DLC. Ignore these because DLC overrides
2572 LIBCFS_FREE(curnis, nnis * sizeof(*curnis));
2573 LIBCFS_FREE(addnis, nnis * sizeof(*addnis));
2574 LIBCFS_FREE(delnis, nnis * sizeof(*delnis));
2575 lnet_ping_buffer_decref(pbuf);
2576 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nid2str(lp->lp_primary_nid), rc);
2579 spin_lock(&lp->lp_lock);
2580 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
2581 lp->lp_state |= LNET_PEER_FORCE_PING;
2582 spin_unlock(&lp->lp_lock);
2588 * The data in pbuf says lp is its primary peer, but the data was
2589 * received by a different peer. Try to update lp with the data.
2592 lnet_peer_set_primary_data(struct lnet_peer *lp, struct lnet_ping_buffer *pbuf)
2594 struct lnet_handle_md mdh;
2596 /* Queue lp for discovery, and force it on the request queue. */
2597 lnet_net_lock(LNET_LOCK_EX);
2598 if (lnet_peer_queue_for_discovery(lp))
2599 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_request);
2600 lnet_net_unlock(LNET_LOCK_EX);
2602 LNetInvalidateMDHandle(&mdh);
2605 * Decide whether we can move the peer to the DATA_PRESENT state.
2607 * We replace stale data for a multi-rail peer, repair PING_FAILED
2608 * status, and preempt FORCE_PING.
2610 * If after that we have DATA_PRESENT, we merge it into this peer.
2612 spin_lock(&lp->lp_lock);
2613 if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
2614 if (lp->lp_peer_seqno < LNET_PING_BUFFER_SEQNO(pbuf)) {
2615 lp->lp_peer_seqno = LNET_PING_BUFFER_SEQNO(pbuf);
2616 } else if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
2617 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
2618 lnet_ping_buffer_decref(pbuf);
2623 if (lp->lp_state & LNET_PEER_DATA_PRESENT) {
2624 lnet_ping_buffer_decref(lp->lp_data);
2626 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
2628 if (lp->lp_state & LNET_PEER_PING_FAILED) {
2629 mdh = lp->lp_ping_mdh;
2630 LNetInvalidateMDHandle(&lp->lp_ping_mdh);
2631 lp->lp_state &= ~LNET_PEER_PING_FAILED;
2632 lp->lp_ping_error = 0;
2634 if (lp->lp_state & LNET_PEER_FORCE_PING)
2635 lp->lp_state &= ~LNET_PEER_FORCE_PING;
2636 lp->lp_state |= LNET_PEER_NIDS_UPTODATE;
2637 spin_unlock(&lp->lp_lock);
2639 if (!LNetMDHandleIsInvalid(mdh))
2643 return lnet_peer_merge_data(lp, pbuf);
2645 CDEBUG(D_NET, "peer %s\n", libcfs_nid2str(lp->lp_primary_nid));
2650 * Update a peer using the data received.
2652 static int lnet_peer_data_present(struct lnet_peer *lp)
2653 __must_hold(&lp->lp_lock)
2655 struct lnet_ping_buffer *pbuf;
2656 struct lnet_peer_ni *lpni;
2657 lnet_nid_t nid = LNET_NID_ANY;
2663 lp->lp_state &= ~LNET_PEER_DATA_PRESENT;
2664 lp->lp_state |= LNET_PEER_NIDS_UPTODATE;
2665 spin_unlock(&lp->lp_lock);
2668 * Modifications of peer structures are done while holding the
2669 * ln_api_mutex. A global lock is required because we may be
2670 * modifying multiple peer structures, and a mutex greatly
2671 * simplifies memory management.
2673 * The actual changes to the data structures must also protect
2674 * against concurrent lookups, for which the lnet_net_lock in
2675 * LNET_LOCK_EX mode is used.
2677 mutex_lock(&the_lnet.ln_api_mutex);
2678 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
2684 * If this peer is not on the peer list then it is being torn
2685 * down, and our reference count may be all that is keeping it
2686 * alive. Don't do any work on it.
2688 if (list_empty(&lp->lp_peer_list))
2691 flags = LNET_PEER_DISCOVERED;
2692 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_MULTI_RAIL)
2693 flags |= LNET_PEER_MULTI_RAIL;
2696 * Check whether the primary NID in the message matches the
2697 * primary NID of the peer. If it does, update the peer, if
2698 * it it does not, check whether there is already a peer with
2699 * that primary NID. If no such peer exists, try to update
2700 * the primary NID of the current peer (allowed if it was
2701 * created due to message traffic) and complete the update.
2702 * If the peer did exist, hand off the data to it.
2704 * The peer for the loopback interface is a special case: this
2705 * is the peer for the local node, and we want to set its
2706 * primary NID to the correct value here. Moreover, this peer
2707 * can show up with only the loopback NID in the ping buffer.
2709 if (pbuf->pb_info.pi_nnis <= 1)
2711 nid = pbuf->pb_info.pi_ni[1].ns_nid;
2712 if (LNET_NETTYP(LNET_NIDNET(lp->lp_primary_nid)) == LOLND) {
2713 rc = lnet_peer_set_primary_nid(lp, nid, flags);
2715 rc = lnet_peer_merge_data(lp, pbuf);
2716 } else if (lp->lp_primary_nid == nid) {
2717 rc = lnet_peer_merge_data(lp, pbuf);
2719 lpni = lnet_find_peer_ni_locked(nid);
2721 rc = lnet_peer_set_primary_nid(lp, nid, flags);
2723 CERROR("Primary NID error %s versus %s: %d\n",
2724 libcfs_nid2str(lp->lp_primary_nid),
2725 libcfs_nid2str(nid), rc);
2727 rc = lnet_peer_merge_data(lp, pbuf);
2730 struct lnet_peer *new_lp;
2731 new_lp = lpni->lpni_peer_net->lpn_peer;
2732 rc = lnet_peer_set_primary_data(new_lp, pbuf);
2733 lnet_consolidate_routes_locked(lp, new_lp);
2734 lnet_peer_ni_decref_locked(lpni);
2738 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nid2str(lp->lp_primary_nid), rc);
2739 mutex_unlock(&the_lnet.ln_api_mutex);
2741 spin_lock(&lp->lp_lock);
2742 /* Tell discovery to re-check the peer immediately. */
2744 rc = LNET_REDISCOVER_PEER;
2749 * A ping failed. Clear the PING_FAILED state and set the
2750 * FORCE_PING state, to ensure a retry even if discovery is
2751 * disabled. This avoids being left with incorrect state.
2753 static int lnet_peer_ping_failed(struct lnet_peer *lp)
2754 __must_hold(&lp->lp_lock)
2756 struct lnet_handle_md mdh;
2759 mdh = lp->lp_ping_mdh;
2760 LNetInvalidateMDHandle(&lp->lp_ping_mdh);
2761 lp->lp_state &= ~LNET_PEER_PING_FAILED;
2762 lp->lp_state |= LNET_PEER_FORCE_PING;
2763 rc = lp->lp_ping_error;
2764 lp->lp_ping_error = 0;
2765 spin_unlock(&lp->lp_lock);
2767 if (!LNetMDHandleIsInvalid(mdh))
2770 CDEBUG(D_NET, "peer %s:%d\n",
2771 libcfs_nid2str(lp->lp_primary_nid), rc);
2773 spin_lock(&lp->lp_lock);
2774 return rc ? rc : LNET_REDISCOVER_PEER;
2778 * Select NID to send a Ping or Push to.
2780 static lnet_nid_t lnet_peer_select_nid(struct lnet_peer *lp)
2782 struct lnet_peer_ni *lpni;
2784 /* Look for a direct-connected NID for this peer. */
2786 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL) {
2787 if (!lnet_get_net_locked(lpni->lpni_peer_net->lpn_net_id))
2792 return lpni->lpni_nid;
2794 /* Look for a routed-connected NID for this peer. */
2796 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL) {
2797 if (!lnet_find_rnet_locked(lpni->lpni_peer_net->lpn_net_id))
2802 return lpni->lpni_nid;
2804 return LNET_NID_ANY;
2807 /* Active side of ping. */
2808 static int lnet_peer_send_ping(struct lnet_peer *lp)
2809 __must_hold(&lp->lp_lock)
2816 lp->lp_state |= LNET_PEER_PING_SENT;
2817 lp->lp_state &= ~LNET_PEER_FORCE_PING;
2818 spin_unlock(&lp->lp_lock);
2820 cpt = lnet_net_lock_current();
2821 /* Refcount for MD. */
2822 lnet_peer_addref_locked(lp);
2823 pnid = lnet_peer_select_nid(lp);
2824 lnet_net_unlock(cpt);
2826 nnis = MAX(lp->lp_data_nnis, LNET_INTERFACES_MIN);
2828 rc = lnet_send_ping(pnid, &lp->lp_ping_mdh, nnis, lp,
2829 the_lnet.ln_dc_eqh, false);
2832 * if LNetMDBind in lnet_send_ping fails we need to decrement the
2833 * refcount on the peer, otherwise LNetMDUnlink will be called
2834 * which will eventually do that.
2838 lnet_peer_decref_locked(lp);
2839 lnet_net_unlock(cpt);
2840 rc = -rc; /* change the rc to negative value */
2842 } else if (rc < 0) {
2846 CDEBUG(D_NET, "peer %s\n", libcfs_nid2str(lp->lp_primary_nid));
2848 spin_lock(&lp->lp_lock);
2852 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nid2str(lp->lp_primary_nid), rc);
2854 * The errors that get us here are considered hard errors and
2855 * cause Discovery to terminate. So we clear PING_SENT, but do
2856 * not set either PING_FAILED or FORCE_PING. In fact we need
2857 * to clear PING_FAILED, because the unlink event handler will
2858 * have set it if we called LNetMDUnlink() above.
2860 spin_lock(&lp->lp_lock);
2861 lp->lp_state &= ~(LNET_PEER_PING_SENT | LNET_PEER_PING_FAILED);
2866 * This function exists because you cannot call LNetMDUnlink() from an
2869 static int lnet_peer_push_failed(struct lnet_peer *lp)
2870 __must_hold(&lp->lp_lock)
2872 struct lnet_handle_md mdh;
2875 mdh = lp->lp_push_mdh;
2876 LNetInvalidateMDHandle(&lp->lp_push_mdh);
2877 lp->lp_state &= ~LNET_PEER_PUSH_FAILED;
2878 rc = lp->lp_push_error;
2879 lp->lp_push_error = 0;
2880 spin_unlock(&lp->lp_lock);
2882 if (!LNetMDHandleIsInvalid(mdh))
2885 CDEBUG(D_NET, "peer %s\n", libcfs_nid2str(lp->lp_primary_nid));
2886 spin_lock(&lp->lp_lock);
2887 return rc ? rc : LNET_REDISCOVER_PEER;
2890 /* Active side of push. */
2891 static int lnet_peer_send_push(struct lnet_peer *lp)
2892 __must_hold(&lp->lp_lock)
2894 struct lnet_ping_buffer *pbuf;
2895 struct lnet_process_id id;
2900 /* Don't push to a non-multi-rail peer. */
2901 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
2902 lp->lp_state &= ~LNET_PEER_FORCE_PUSH;
2906 lp->lp_state |= LNET_PEER_PUSH_SENT;
2907 lp->lp_state &= ~LNET_PEER_FORCE_PUSH;
2908 spin_unlock(&lp->lp_lock);
2910 cpt = lnet_net_lock_current();
2911 pbuf = the_lnet.ln_ping_target;
2912 lnet_ping_buffer_addref(pbuf);
2913 lnet_net_unlock(cpt);
2915 /* Push source MD */
2916 md.start = &pbuf->pb_info;
2917 md.length = LNET_PING_INFO_SIZE(pbuf->pb_nnis);
2918 md.threshold = 2; /* Put/Ack */
2921 md.eq_handle = the_lnet.ln_dc_eqh;
2924 rc = LNetMDBind(md, LNET_UNLINK, &lp->lp_push_mdh);
2926 lnet_ping_buffer_decref(pbuf);
2927 CERROR("Can't bind push source MD: %d\n", rc);
2930 cpt = lnet_net_lock_current();
2931 /* Refcount for MD. */
2932 lnet_peer_addref_locked(lp);
2933 id.pid = LNET_PID_LUSTRE;
2934 id.nid = lnet_peer_select_nid(lp);
2935 lnet_net_unlock(cpt);
2937 if (id.nid == LNET_NID_ANY) {
2942 rc = LNetPut(LNET_NID_ANY, lp->lp_push_mdh,
2943 LNET_ACK_REQ, id, LNET_RESERVED_PORTAL,
2944 LNET_PROTO_PING_MATCHBITS, 0, 0);
2949 CDEBUG(D_NET, "peer %s\n", libcfs_nid2str(lp->lp_primary_nid));
2951 spin_lock(&lp->lp_lock);
2955 LNetMDUnlink(lp->lp_push_mdh);
2956 LNetInvalidateMDHandle(&lp->lp_push_mdh);
2958 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nid2str(lp->lp_primary_nid), rc);
2960 * The errors that get us here are considered hard errors and
2961 * cause Discovery to terminate. So we clear PUSH_SENT, but do
2962 * not set PUSH_FAILED. In fact we need to clear PUSH_FAILED,
2963 * because the unlink event handler will have set it if we
2964 * called LNetMDUnlink() above.
2966 spin_lock(&lp->lp_lock);
2967 lp->lp_state &= ~(LNET_PEER_PUSH_SENT | LNET_PEER_PUSH_FAILED);
2972 * An unrecoverable error was encountered during discovery.
2973 * Set error status in peer and abort discovery.
2975 static void lnet_peer_discovery_error(struct lnet_peer *lp, int error)
2977 CDEBUG(D_NET, "Discovery error %s: %d\n",
2978 libcfs_nid2str(lp->lp_primary_nid), error);
2980 spin_lock(&lp->lp_lock);
2981 lp->lp_dc_error = error;
2982 lp->lp_state &= ~LNET_PEER_DISCOVERING;
2983 lp->lp_state |= LNET_PEER_REDISCOVER;
2984 spin_unlock(&lp->lp_lock);
2988 * Mark the peer as discovered.
2990 static int lnet_peer_discovered(struct lnet_peer *lp)
2991 __must_hold(&lp->lp_lock)
2993 lp->lp_state |= LNET_PEER_DISCOVERED;
2994 lp->lp_state &= ~(LNET_PEER_DISCOVERING |
2995 LNET_PEER_REDISCOVER);
2997 CDEBUG(D_NET, "peer %s\n", libcfs_nid2str(lp->lp_primary_nid));
3003 * Mark the peer as to be rediscovered.
3005 static int lnet_peer_rediscover(struct lnet_peer *lp)
3006 __must_hold(&lp->lp_lock)
3008 lp->lp_state |= LNET_PEER_REDISCOVER;
3009 lp->lp_state &= ~LNET_PEER_DISCOVERING;
3011 CDEBUG(D_NET, "peer %s\n", libcfs_nid2str(lp->lp_primary_nid));
3017 * Discovering this peer is taking too long. Cancel any Ping or Push
3018 * that discovery is waiting on by unlinking the relevant MDs. The
3019 * lnet_discovery_event_handler() will proceed from here and complete
3022 static void lnet_peer_cancel_discovery(struct lnet_peer *lp)
3024 struct lnet_handle_md ping_mdh;
3025 struct lnet_handle_md push_mdh;
3027 LNetInvalidateMDHandle(&ping_mdh);
3028 LNetInvalidateMDHandle(&push_mdh);
3030 spin_lock(&lp->lp_lock);
3031 if (lp->lp_state & LNET_PEER_PING_SENT) {
3032 ping_mdh = lp->lp_ping_mdh;
3033 LNetInvalidateMDHandle(&lp->lp_ping_mdh);
3035 if (lp->lp_state & LNET_PEER_PUSH_SENT) {
3036 push_mdh = lp->lp_push_mdh;
3037 LNetInvalidateMDHandle(&lp->lp_push_mdh);
3039 spin_unlock(&lp->lp_lock);
3041 if (!LNetMDHandleIsInvalid(ping_mdh))
3042 LNetMDUnlink(ping_mdh);
3043 if (!LNetMDHandleIsInvalid(push_mdh))
3044 LNetMDUnlink(push_mdh);
3048 * Wait for work to be queued or some other change that must be
3049 * attended to. Returns non-zero if the discovery thread should shut
3052 static int lnet_peer_discovery_wait_for_work(void)
3059 cpt = lnet_net_lock_current();
3061 prepare_to_wait(&the_lnet.ln_dc_waitq, &wait,
3062 TASK_INTERRUPTIBLE);
3063 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3065 if (lnet_push_target_resize_needed())
3067 if (!list_empty(&the_lnet.ln_dc_request))
3069 if (!list_empty(&the_lnet.ln_msg_resend))
3071 lnet_net_unlock(cpt);
3074 * wakeup max every second to check if there are peers that
3075 * have been stuck on the working queue for greater than
3078 schedule_timeout(cfs_time_seconds(1));
3079 finish_wait(&the_lnet.ln_dc_waitq, &wait);
3080 cpt = lnet_net_lock_current();
3082 finish_wait(&the_lnet.ln_dc_waitq, &wait);
3084 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3087 lnet_net_unlock(cpt);
3089 CDEBUG(D_NET, "woken: %d\n", rc);
3095 * Messages that were pending on a destroyed peer will be put on a global
3096 * resend list. The message resend list will be checked by
3097 * the discovery thread when it wakes up, and will resend messages. These
3098 * messages can still be sendable in the case the lpni which was the initial
3099 * cause of the message re-queue was transfered to another peer.
3101 * It is possible that LNet could be shutdown while we're iterating
3102 * through the list. lnet_shudown_lndnets() will attempt to access the
3103 * resend list, but will have to wait until the spinlock is released, by
3104 * which time there shouldn't be any more messages on the resend list.
3105 * During shutdown lnet_send() will fail and lnet_finalize() will be called
3106 * for the messages so they can be released. The other case is that
3107 * lnet_shudown_lndnets() can finalize all the messages before this
3108 * function can visit the resend list, in which case this function will be
3111 static void lnet_resend_msgs(void)
3113 struct lnet_msg *msg, *tmp;
3114 struct list_head resend;
3117 INIT_LIST_HEAD(&resend);
3119 spin_lock(&the_lnet.ln_msg_resend_lock);
3120 list_splice(&the_lnet.ln_msg_resend, &resend);
3121 spin_unlock(&the_lnet.ln_msg_resend_lock);
3123 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
3124 list_del_init(&msg->msg_list);
3125 rc = lnet_send(msg->msg_src_nid_param, msg,
3126 msg->msg_rtr_nid_param);
3128 CNETERR("Error sending %s to %s: %d\n",
3129 lnet_msgtyp2str(msg->msg_type),
3130 libcfs_id2str(msg->msg_target), rc);
3131 lnet_finalize(msg, rc);
3136 /* The discovery thread. */
3137 static int lnet_peer_discovery(void *arg)
3139 struct lnet_peer *lp;
3142 CDEBUG(D_NET, "started\n");
3143 cfs_block_allsigs();
3146 if (lnet_peer_discovery_wait_for_work())
3151 if (lnet_push_target_resize_needed())
3152 lnet_push_target_resize();
3154 lnet_net_lock(LNET_LOCK_EX);
3155 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3159 * Process all incoming discovery work requests. When
3160 * discovery must wait on a peer to change state, it
3161 * is added to the tail of the ln_dc_working queue. A
3162 * timestamp keeps track of when the peer was added,
3163 * so we can time out discovery requests that take too
3166 while (!list_empty(&the_lnet.ln_dc_request)) {
3167 lp = list_first_entry(&the_lnet.ln_dc_request,
3168 struct lnet_peer, lp_dc_list);
3169 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_working);
3171 * set the time the peer was put on the dc_working
3172 * queue. It shouldn't remain on the queue
3173 * forever, in case the GET message (for ping)
3174 * doesn't get a REPLY or the PUT message (for
3175 * push) doesn't get an ACK.
3177 lp->lp_last_queued = ktime_get_real_seconds();
3178 lnet_net_unlock(LNET_LOCK_EX);
3181 * Select an action depending on the state of
3182 * the peer and whether discovery is disabled.
3183 * The check whether discovery is disabled is
3184 * done after the code that handles processing
3185 * for arrived data, cleanup for failures, and
3186 * forcing a Ping or Push.
3188 spin_lock(&lp->lp_lock);
3189 CDEBUG(D_NET, "peer %s state %#x\n",
3190 libcfs_nid2str(lp->lp_primary_nid),
3192 if (lp->lp_state & LNET_PEER_DATA_PRESENT)
3193 rc = lnet_peer_data_present(lp);
3194 else if (lp->lp_state & LNET_PEER_PING_FAILED)
3195 rc = lnet_peer_ping_failed(lp);
3196 else if (lp->lp_state & LNET_PEER_PUSH_FAILED)
3197 rc = lnet_peer_push_failed(lp);
3198 else if (lp->lp_state & LNET_PEER_FORCE_PING)
3199 rc = lnet_peer_send_ping(lp);
3200 else if (lp->lp_state & LNET_PEER_FORCE_PUSH)
3201 rc = lnet_peer_send_push(lp);
3202 else if (lnet_peer_discovery_disabled)
3203 rc = lnet_peer_rediscover(lp);
3204 else if (!(lp->lp_state & LNET_PEER_NIDS_UPTODATE))
3205 rc = lnet_peer_send_ping(lp);
3206 else if (lnet_peer_needs_push(lp))
3207 rc = lnet_peer_send_push(lp);
3209 rc = lnet_peer_discovered(lp);
3210 CDEBUG(D_NET, "peer %s state %#x rc %d\n",
3211 libcfs_nid2str(lp->lp_primary_nid),
3213 spin_unlock(&lp->lp_lock);
3215 lnet_net_lock(LNET_LOCK_EX);
3216 if (rc == LNET_REDISCOVER_PEER) {
3217 list_move(&lp->lp_dc_list,
3218 &the_lnet.ln_dc_request);
3220 lnet_peer_discovery_error(lp, rc);
3222 if (!(lp->lp_state & LNET_PEER_DISCOVERING))
3223 lnet_peer_discovery_complete(lp);
3224 if (the_lnet.ln_dc_state == LNET_DC_STATE_STOPPING)
3228 lnet_net_unlock(LNET_LOCK_EX);
3231 CDEBUG(D_NET, "stopping\n");
3233 * Clean up before telling lnet_peer_discovery_stop() that
3234 * we're done. Use wake_up() below to somewhat reduce the
3235 * size of the thundering herd if there are multiple threads
3236 * waiting on discovery of a single peer.
3239 /* Queue cleanup 1: stop all pending pings and pushes. */
3240 lnet_net_lock(LNET_LOCK_EX);
3241 while (!list_empty(&the_lnet.ln_dc_working)) {
3242 lp = list_first_entry(&the_lnet.ln_dc_working,
3243 struct lnet_peer, lp_dc_list);
3244 list_move(&lp->lp_dc_list, &the_lnet.ln_dc_expired);
3245 lnet_net_unlock(LNET_LOCK_EX);
3246 lnet_peer_cancel_discovery(lp);
3247 lnet_net_lock(LNET_LOCK_EX);
3249 lnet_net_unlock(LNET_LOCK_EX);
3251 /* Queue cleanup 2: wait for the expired queue to clear. */
3252 while (!list_empty(&the_lnet.ln_dc_expired))
3253 schedule_timeout(cfs_time_seconds(1));
3255 /* Queue cleanup 3: clear the request queue. */
3256 lnet_net_lock(LNET_LOCK_EX);
3257 while (!list_empty(&the_lnet.ln_dc_request)) {
3258 lp = list_first_entry(&the_lnet.ln_dc_request,
3259 struct lnet_peer, lp_dc_list);
3260 lnet_peer_discovery_error(lp, -ESHUTDOWN);
3261 lnet_peer_discovery_complete(lp);
3263 lnet_net_unlock(LNET_LOCK_EX);
3265 LNetEQFree(the_lnet.ln_dc_eqh);
3266 LNetInvalidateEQHandle(&the_lnet.ln_dc_eqh);
3268 the_lnet.ln_dc_state = LNET_DC_STATE_SHUTDOWN;
3269 wake_up(&the_lnet.ln_dc_waitq);
3271 CDEBUG(D_NET, "stopped\n");
3276 /* ln_api_mutex is held on entry. */
3277 int lnet_peer_discovery_start(void)
3279 struct task_struct *task;
3282 if (the_lnet.ln_dc_state != LNET_DC_STATE_SHUTDOWN)
3285 rc = LNetEQAlloc(0, lnet_discovery_event_handler, &the_lnet.ln_dc_eqh);
3287 CERROR("Can't allocate discovery EQ: %d\n", rc);
3291 the_lnet.ln_dc_state = LNET_DC_STATE_RUNNING;
3292 task = kthread_run(lnet_peer_discovery, NULL, "lnet_discovery");
3295 CERROR("Can't start peer discovery thread: %d\n", rc);
3297 LNetEQFree(the_lnet.ln_dc_eqh);
3298 LNetInvalidateEQHandle(&the_lnet.ln_dc_eqh);
3300 the_lnet.ln_dc_state = LNET_DC_STATE_SHUTDOWN;
3303 CDEBUG(D_NET, "discovery start: %d\n", rc);
3308 /* ln_api_mutex is held on entry. */
3309 void lnet_peer_discovery_stop(void)
3311 if (the_lnet.ln_dc_state == LNET_DC_STATE_SHUTDOWN)
3314 LASSERT(the_lnet.ln_dc_state == LNET_DC_STATE_RUNNING);
3315 the_lnet.ln_dc_state = LNET_DC_STATE_STOPPING;
3316 wake_up(&the_lnet.ln_dc_waitq);
3318 wait_event(the_lnet.ln_dc_waitq,
3319 the_lnet.ln_dc_state == LNET_DC_STATE_SHUTDOWN);
3321 LASSERT(list_empty(&the_lnet.ln_dc_request));
3322 LASSERT(list_empty(&the_lnet.ln_dc_working));
3323 LASSERT(list_empty(&the_lnet.ln_dc_expired));
3325 CDEBUG(D_NET, "discovery stopped\n");
3331 lnet_debug_peer(lnet_nid_t nid)
3333 char *aliveness = "NA";
3334 struct lnet_peer_ni *lp;
3337 cpt = lnet_cpt_of_nid(nid, NULL);
3340 lp = lnet_nid2peerni_locked(nid, LNET_NID_ANY, cpt);
3342 lnet_net_unlock(cpt);
3343 CDEBUG(D_WARNING, "No peer %s\n", libcfs_nid2str(nid));
3347 if (lnet_isrouter(lp) || lnet_peer_aliveness_enabled(lp))
3348 aliveness = (lnet_is_peer_ni_alive(lp)) ? "up" : "down";
3350 CDEBUG(D_WARNING, "%-24s %4d %5s %5d %5d %5d %5d %5d %ld\n",
3351 libcfs_nid2str(lp->lpni_nid), atomic_read(&lp->lpni_refcount),
3352 aliveness, lp->lpni_net->net_tunables.lct_peer_tx_credits,
3353 lp->lpni_rtrcredits, lp->lpni_minrtrcredits,
3354 lp->lpni_txcredits, lp->lpni_mintxcredits, lp->lpni_txqnob);
3356 lnet_peer_ni_decref_locked(lp);
3358 lnet_net_unlock(cpt);
3361 /* Gathering information for userspace. */
3363 int lnet_get_peer_ni_info(__u32 peer_index, __u64 *nid,
3364 char aliveness[LNET_MAX_STR_LEN],
3365 __u32 *cpt_iter, __u32 *refcount,
3366 __u32 *ni_peer_tx_credits, __u32 *peer_tx_credits,
3367 __u32 *peer_rtr_credits, __u32 *peer_min_rtr_credits,
3368 __u32 *peer_tx_qnob)
3370 struct lnet_peer_table *peer_table;
3371 struct lnet_peer_ni *lp;
3376 /* get the number of CPTs */
3377 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
3379 /* if the cpt number to be examined is >= the number of cpts in
3380 * the system then indicate that there are no more cpts to examin
3382 if (*cpt_iter >= lncpt)
3385 /* get the current table */
3386 peer_table = the_lnet.ln_peer_tables[*cpt_iter];
3387 /* if the ptable is NULL then there are no more cpts to examine */
3388 if (peer_table == NULL)
3391 lnet_net_lock(*cpt_iter);
3393 for (j = 0; j < LNET_PEER_HASH_SIZE && !found; j++) {
3394 struct list_head *peers = &peer_table->pt_hash[j];
3396 list_for_each_entry(lp, peers, lpni_hashlist) {
3397 if (peer_index-- > 0)
3400 snprintf(aliveness, LNET_MAX_STR_LEN, "NA");
3401 if (lnet_isrouter(lp) ||
3402 lnet_peer_aliveness_enabled(lp))
3403 snprintf(aliveness, LNET_MAX_STR_LEN,
3404 lnet_is_peer_ni_alive(lp) ? "up" : "down");
3406 *nid = lp->lpni_nid;
3407 *refcount = atomic_read(&lp->lpni_refcount);
3408 *ni_peer_tx_credits =
3409 lp->lpni_net->net_tunables.lct_peer_tx_credits;
3410 *peer_tx_credits = lp->lpni_txcredits;
3411 *peer_rtr_credits = lp->lpni_rtrcredits;
3412 *peer_min_rtr_credits = lp->lpni_mintxcredits;
3413 *peer_tx_qnob = lp->lpni_txqnob;
3419 lnet_net_unlock(*cpt_iter);
3423 return found ? 0 : -ENOENT;
3426 /* ln_api_mutex is held, which keeps the peer list stable */
3427 int lnet_get_peer_info(struct lnet_ioctl_peer_cfg *cfg, void __user *bulk)
3429 struct lnet_ioctl_element_stats *lpni_stats;
3430 struct lnet_ioctl_element_msg_stats *lpni_msg_stats;
3431 struct lnet_ioctl_peer_ni_hstats *lpni_hstats;
3432 struct lnet_peer_ni_credit_info *lpni_info;
3433 struct lnet_peer_ni *lpni;
3434 struct lnet_peer *lp;
3439 lp = lnet_find_peer(cfg->prcfg_prim_nid);
3446 size = sizeof(nid) + sizeof(*lpni_info) + sizeof(*lpni_stats)
3447 + sizeof(*lpni_msg_stats) + sizeof(*lpni_hstats);
3448 size *= lp->lp_nnis;
3449 if (size > cfg->prcfg_size) {
3450 cfg->prcfg_size = size;
3455 cfg->prcfg_prim_nid = lp->lp_primary_nid;
3456 cfg->prcfg_mr = lnet_peer_is_multi_rail(lp);
3457 cfg->prcfg_cfg_nid = lp->lp_primary_nid;
3458 cfg->prcfg_count = lp->lp_nnis;
3459 cfg->prcfg_size = size;
3460 cfg->prcfg_state = lp->lp_state;
3462 /* Allocate helper buffers. */
3464 LIBCFS_ALLOC(lpni_info, sizeof(*lpni_info));
3467 LIBCFS_ALLOC(lpni_stats, sizeof(*lpni_stats));
3470 LIBCFS_ALLOC(lpni_msg_stats, sizeof(*lpni_msg_stats));
3471 if (!lpni_msg_stats)
3472 goto out_free_stats;
3473 LIBCFS_ALLOC(lpni_hstats, sizeof(*lpni_hstats));
3475 goto out_free_msg_stats;
3480 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL) {
3481 nid = lpni->lpni_nid;
3482 if (copy_to_user(bulk, &nid, sizeof(nid)))
3483 goto out_free_hstats;
3484 bulk += sizeof(nid);
3486 memset(lpni_info, 0, sizeof(*lpni_info));
3487 snprintf(lpni_info->cr_aliveness, LNET_MAX_STR_LEN, "NA");
3488 if (lnet_isrouter(lpni) ||
3489 lnet_peer_aliveness_enabled(lpni))
3490 snprintf(lpni_info->cr_aliveness, LNET_MAX_STR_LEN,
3491 lnet_is_peer_ni_alive(lpni) ? "up" : "down");
3493 lpni_info->cr_refcount = atomic_read(&lpni->lpni_refcount);
3494 lpni_info->cr_ni_peer_tx_credits = (lpni->lpni_net != NULL) ?
3495 lpni->lpni_net->net_tunables.lct_peer_tx_credits : 0;
3496 lpni_info->cr_peer_tx_credits = lpni->lpni_txcredits;
3497 lpni_info->cr_peer_rtr_credits = lpni->lpni_rtrcredits;
3498 lpni_info->cr_peer_min_rtr_credits = lpni->lpni_minrtrcredits;
3499 lpni_info->cr_peer_min_tx_credits = lpni->lpni_mintxcredits;
3500 lpni_info->cr_peer_tx_qnob = lpni->lpni_txqnob;
3501 if (copy_to_user(bulk, lpni_info, sizeof(*lpni_info)))
3502 goto out_free_hstats;
3503 bulk += sizeof(*lpni_info);
3505 memset(lpni_stats, 0, sizeof(*lpni_stats));
3506 lpni_stats->iel_send_count = lnet_sum_stats(&lpni->lpni_stats,
3507 LNET_STATS_TYPE_SEND);
3508 lpni_stats->iel_recv_count = lnet_sum_stats(&lpni->lpni_stats,
3509 LNET_STATS_TYPE_RECV);
3510 lpni_stats->iel_drop_count = lnet_sum_stats(&lpni->lpni_stats,
3511 LNET_STATS_TYPE_DROP);
3512 if (copy_to_user(bulk, lpni_stats, sizeof(*lpni_stats)))
3513 goto out_free_hstats;
3514 bulk += sizeof(*lpni_stats);
3515 lnet_usr_translate_stats(lpni_msg_stats, &lpni->lpni_stats);
3516 if (copy_to_user(bulk, lpni_msg_stats, sizeof(*lpni_msg_stats)))
3517 goto out_free_hstats;
3518 bulk += sizeof(*lpni_msg_stats);
3519 lpni_hstats->hlpni_network_timeout =
3520 atomic_read(&lpni->lpni_hstats.hlt_network_timeout);
3521 lpni_hstats->hlpni_remote_dropped =
3522 atomic_read(&lpni->lpni_hstats.hlt_remote_dropped);
3523 lpni_hstats->hlpni_remote_timeout =
3524 atomic_read(&lpni->lpni_hstats.hlt_remote_timeout);
3525 lpni_hstats->hlpni_remote_error =
3526 atomic_read(&lpni->lpni_hstats.hlt_remote_error);
3527 lpni_hstats->hlpni_health_value =
3528 atomic_read(&lpni->lpni_healthv);
3529 if (copy_to_user(bulk, lpni_hstats, sizeof(*lpni_hstats)))
3530 goto out_free_hstats;
3531 bulk += sizeof(*lpni_hstats);
3536 LIBCFS_FREE(lpni_hstats, sizeof(*lpni_hstats));
3538 LIBCFS_FREE(lpni_msg_stats, sizeof(*lpni_msg_stats));
3540 LIBCFS_FREE(lpni_stats, sizeof(*lpni_stats));
3542 LIBCFS_FREE(lpni_info, sizeof(*lpni_info));
3544 lnet_peer_decref_locked(lp);
3550 lnet_peer_ni_add_to_recoveryq_locked(struct lnet_peer_ni *lpni)
3552 /* the mt could've shutdown and cleaned up the queues */
3553 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING)
3556 if (list_empty(&lpni->lpni_recovery) &&
3557 atomic_read(&lpni->lpni_healthv) < LNET_MAX_HEALTH_VALUE) {
3558 CERROR("lpni %s added to recovery queue. Health = %d\n",
3559 libcfs_nid2str(lpni->lpni_nid),
3560 atomic_read(&lpni->lpni_healthv));
3561 list_add_tail(&lpni->lpni_recovery, &the_lnet.ln_mt_peerNIRecovq);
3562 lnet_peer_ni_addref_locked(lpni);
3566 /* Call with the ln_api_mutex held */
3568 lnet_peer_ni_set_healthv(lnet_nid_t nid, int value, bool all)
3570 struct lnet_peer_table *ptable;
3571 struct lnet_peer *lp;
3572 struct lnet_peer_net *lpn;
3573 struct lnet_peer_ni *lpni;
3577 if (the_lnet.ln_state != LNET_STATE_RUNNING)
3581 lnet_net_lock(LNET_LOCK_EX);
3582 lpni = lnet_find_peer_ni_locked(nid);
3584 lnet_net_unlock(LNET_LOCK_EX);
3587 atomic_set(&lpni->lpni_healthv, value);
3588 lnet_peer_ni_add_to_recoveryq_locked(lpni);
3589 lnet_peer_ni_decref_locked(lpni);
3590 lnet_net_unlock(LNET_LOCK_EX);
3594 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
3597 * Walk all the peers and reset the healhv for each one to the
3600 lnet_net_lock(LNET_LOCK_EX);
3601 for (cpt = 0; cpt < lncpt; cpt++) {
3602 ptable = the_lnet.ln_peer_tables[cpt];
3603 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
3604 list_for_each_entry(lpn, &lp->lp_peer_nets, lpn_peer_nets) {
3605 list_for_each_entry(lpni, &lpn->lpn_peer_nis,
3607 atomic_set(&lpni->lpni_healthv, value);
3608 lnet_peer_ni_add_to_recoveryq_locked(lpni);
3613 lnet_net_unlock(LNET_LOCK_EX);