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, 2014, 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 <lnet/lib-lnet.h>
38 #include <lnet/lib-dlc.h>
41 lnet_peer_remove_from_remote_list(struct lnet_peer_ni *lpni)
43 if (!list_empty(&lpni->lpni_on_remote_peer_ni_list)) {
44 list_del_init(&lpni->lpni_on_remote_peer_ni_list);
45 lnet_peer_ni_decref_locked(lpni);
50 lnet_peer_net_added(struct lnet_net *net)
52 struct lnet_peer_ni *lpni, *tmp;
54 list_for_each_entry_safe(lpni, tmp, &the_lnet.ln_remote_peer_ni_list,
55 lpni_on_remote_peer_ni_list) {
57 if (LNET_NIDNET(lpni->lpni_nid) == net->net_id) {
60 spin_lock(&lpni->lpni_lock);
61 lpni->lpni_txcredits =
62 lpni->lpni_net->net_tunables.lct_peer_tx_credits;
63 lpni->lpni_mintxcredits = lpni->lpni_txcredits;
64 lpni->lpni_rtrcredits =
65 lnet_peer_buffer_credits(lpni->lpni_net);
66 lpni->lpni_minrtrcredits = lpni->lpni_rtrcredits;
67 spin_unlock(&lpni->lpni_lock);
69 lnet_peer_remove_from_remote_list(lpni);
75 lnet_peer_tables_destroy(void)
77 struct lnet_peer_table *ptable;
78 struct list_head *hash;
82 if (!the_lnet.ln_peer_tables)
85 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
86 hash = ptable->pt_hash;
87 if (!hash) /* not intialized */
90 LASSERT(list_empty(&ptable->pt_zombie_list));
92 ptable->pt_hash = NULL;
93 for (j = 0; j < LNET_PEER_HASH_SIZE; j++)
94 LASSERT(list_empty(&hash[j]));
96 LIBCFS_FREE(hash, LNET_PEER_HASH_SIZE * sizeof(*hash));
99 cfs_percpt_free(the_lnet.ln_peer_tables);
100 the_lnet.ln_peer_tables = NULL;
104 lnet_peer_tables_create(void)
106 struct lnet_peer_table *ptable;
107 struct list_head *hash;
111 the_lnet.ln_peer_tables = cfs_percpt_alloc(lnet_cpt_table(),
113 if (the_lnet.ln_peer_tables == NULL) {
114 CERROR("Failed to allocate cpu-partition peer tables\n");
118 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
119 LIBCFS_CPT_ALLOC(hash, lnet_cpt_table(), i,
120 LNET_PEER_HASH_SIZE * sizeof(*hash));
122 CERROR("Failed to create peer hash table\n");
123 lnet_peer_tables_destroy();
127 spin_lock_init(&ptable->pt_zombie_lock);
128 INIT_LIST_HEAD(&ptable->pt_zombie_list);
130 INIT_LIST_HEAD(&ptable->pt_peer_list);
132 for (j = 0; j < LNET_PEER_HASH_SIZE; j++)
133 INIT_LIST_HEAD(&hash[j]);
134 ptable->pt_hash = hash; /* sign of initialization */
140 static struct lnet_peer_ni *
141 lnet_peer_ni_alloc(lnet_nid_t nid)
143 struct lnet_peer_ni *lpni;
144 struct lnet_net *net;
147 cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
149 LIBCFS_CPT_ALLOC(lpni, lnet_cpt_table(), cpt, sizeof(*lpni));
153 INIT_LIST_HEAD(&lpni->lpni_txq);
154 INIT_LIST_HEAD(&lpni->lpni_rtrq);
155 INIT_LIST_HEAD(&lpni->lpni_routes);
156 INIT_LIST_HEAD(&lpni->lpni_hashlist);
157 INIT_LIST_HEAD(&lpni->lpni_peer_nis);
158 INIT_LIST_HEAD(&lpni->lpni_on_remote_peer_ni_list);
160 spin_lock_init(&lpni->lpni_lock);
162 lpni->lpni_alive = !lnet_peers_start_down(); /* 1 bit!! */
163 lpni->lpni_last_alive = cfs_time_current(); /* assumes alive */
164 lpni->lpni_ping_feats = LNET_PING_FEAT_INVAL;
165 lpni->lpni_nid = nid;
166 lpni->lpni_cpt = cpt;
167 lnet_set_peer_ni_health_locked(lpni, true);
169 net = lnet_get_net_locked(LNET_NIDNET(nid));
170 lpni->lpni_net = net;
172 lpni->lpni_txcredits = net->net_tunables.lct_peer_tx_credits;
173 lpni->lpni_mintxcredits = lpni->lpni_txcredits;
174 lpni->lpni_rtrcredits = lnet_peer_buffer_credits(net);
175 lpni->lpni_minrtrcredits = lpni->lpni_rtrcredits;
178 * This peer_ni is not on a local network, so we
179 * cannot add the credits here. In case the net is
180 * added later, add the peer_ni to the remote peer ni
181 * list so it can be easily found and revisited.
183 /* FIXME: per-net implementation instead? */
184 atomic_inc(&lpni->lpni_refcount);
185 list_add_tail(&lpni->lpni_on_remote_peer_ni_list,
186 &the_lnet.ln_remote_peer_ni_list);
189 CDEBUG(D_NET, "%p nid %s\n", lpni, libcfs_nid2str(lpni->lpni_nid));
194 static struct lnet_peer_net *
195 lnet_peer_net_alloc(__u32 net_id)
197 struct lnet_peer_net *lpn;
199 LIBCFS_CPT_ALLOC(lpn, lnet_cpt_table(), CFS_CPT_ANY, sizeof(*lpn));
203 INIT_LIST_HEAD(&lpn->lpn_peer_nets);
204 INIT_LIST_HEAD(&lpn->lpn_peer_nis);
205 lpn->lpn_net_id = net_id;
207 CDEBUG(D_NET, "%p net %s\n", lpn, libcfs_net2str(lpn->lpn_net_id));
213 lnet_destroy_peer_net_locked(struct lnet_peer_net *lpn)
215 struct lnet_peer *lp;
217 CDEBUG(D_NET, "%p net %s\n", lpn, libcfs_net2str(lpn->lpn_net_id));
219 LASSERT(atomic_read(&lpn->lpn_refcount) == 0);
220 LASSERT(list_empty(&lpn->lpn_peer_nis));
221 LASSERT(list_empty(&lpn->lpn_peer_nets));
223 lpn->lpn_peer = NULL;
224 LIBCFS_FREE(lpn, sizeof(*lpn));
226 lnet_peer_decref_locked(lp);
229 static struct lnet_peer *
230 lnet_peer_alloc(lnet_nid_t nid)
232 struct lnet_peer *lp;
234 LIBCFS_CPT_ALLOC(lp, lnet_cpt_table(), CFS_CPT_ANY, sizeof(*lp));
238 INIT_LIST_HEAD(&lp->lp_peer_list);
239 INIT_LIST_HEAD(&lp->lp_peer_nets);
240 spin_lock_init(&lp->lp_lock);
241 lp->lp_primary_nid = nid;
242 lp->lp_cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
244 CDEBUG(D_NET, "%p nid %s\n", lp, libcfs_nid2str(lp->lp_primary_nid));
250 lnet_destroy_peer_locked(struct lnet_peer *lp)
252 CDEBUG(D_NET, "%p nid %s\n", lp, libcfs_nid2str(lp->lp_primary_nid));
254 LASSERT(atomic_read(&lp->lp_refcount) == 0);
255 LASSERT(list_empty(&lp->lp_peer_nets));
256 LASSERT(list_empty(&lp->lp_peer_list));
258 LIBCFS_FREE(lp, sizeof(*lp));
262 * Detach a peer_ni from its peer_net. If this was the last peer_ni on
263 * that peer_net, detach the peer_net from the peer.
265 * Call with lnet_net_lock/EX held
268 lnet_peer_detach_peer_ni_locked(struct lnet_peer_ni *lpni)
270 struct lnet_peer_table *ptable;
271 struct lnet_peer_net *lpn;
272 struct lnet_peer *lp;
275 * Belts and suspenders: gracefully handle teardown of a
276 * partially connected peer_ni.
278 lpn = lpni->lpni_peer_net;
280 list_del_init(&lpni->lpni_peer_nis);
282 * If there are no lpni's left, we detach lpn from
283 * lp_peer_nets, so it cannot be found anymore.
285 if (list_empty(&lpn->lpn_peer_nis))
286 list_del_init(&lpn->lpn_peer_nets);
288 /* Update peer NID count. */
290 ptable = the_lnet.ln_peer_tables[lp->lp_cpt];
292 ptable->pt_peer_nnids--;
295 * If there are no more peer nets, make the peer unfindable
296 * via the peer_tables.
298 if (list_empty(&lp->lp_peer_nets)) {
299 list_del_init(&lp->lp_peer_list);
302 CDEBUG(D_NET, "peer %s NID %s\n",
303 libcfs_nid2str(lp->lp_primary_nid),
304 libcfs_nid2str(lpni->lpni_nid));
307 /* called with lnet_net_lock LNET_LOCK_EX held */
309 lnet_peer_ni_del_locked(struct lnet_peer_ni *lpni)
311 struct lnet_peer_table *ptable = NULL;
313 /* don't remove a peer_ni if it's also a gateway */
314 if (lpni->lpni_rtr_refcount > 0) {
315 CERROR("Peer NI %s is a gateway. Can not delete it\n",
316 libcfs_nid2str(lpni->lpni_nid));
320 lnet_peer_remove_from_remote_list(lpni);
322 /* remove peer ni from the hash list. */
323 list_del_init(&lpni->lpni_hashlist);
325 /* decrement the ref count on the peer table */
326 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
327 LASSERT(ptable->pt_number > 0);
331 * The peer_ni can no longer be found with a lookup. But there
332 * can be current users, so keep track of it on the zombie
333 * list until the reference count has gone to zero.
335 * The last reference may be lost in a place where the
336 * lnet_net_lock locks only a single cpt, and that cpt may not
337 * be lpni->lpni_cpt. So the zombie list of lnet_peer_table
340 spin_lock(&ptable->pt_zombie_lock);
341 list_add(&lpni->lpni_hashlist, &ptable->pt_zombie_list);
342 ptable->pt_zombies++;
343 spin_unlock(&ptable->pt_zombie_lock);
345 /* no need to keep this peer_ni on the hierarchy anymore */
346 lnet_peer_detach_peer_ni_locked(lpni);
348 /* remove hashlist reference on peer_ni */
349 lnet_peer_ni_decref_locked(lpni);
354 void lnet_peer_uninit(void)
356 struct lnet_peer_ni *lpni, *tmp;
358 lnet_net_lock(LNET_LOCK_EX);
360 /* remove all peer_nis from the remote peer and the hash list */
361 list_for_each_entry_safe(lpni, tmp, &the_lnet.ln_remote_peer_ni_list,
362 lpni_on_remote_peer_ni_list)
363 lnet_peer_ni_del_locked(lpni);
365 lnet_peer_tables_destroy();
367 lnet_net_unlock(LNET_LOCK_EX);
371 lnet_peer_del_locked(struct lnet_peer *peer)
373 struct lnet_peer_ni *lpni = NULL, *lpni2;
376 CDEBUG(D_NET, "peer %s\n", libcfs_nid2str(peer->lp_primary_nid));
378 lpni = lnet_get_next_peer_ni_locked(peer, NULL, lpni);
379 while (lpni != NULL) {
380 lpni2 = lnet_get_next_peer_ni_locked(peer, NULL, lpni);
381 rc = lnet_peer_ni_del_locked(lpni);
391 lnet_peer_del(struct lnet_peer *peer)
393 lnet_net_lock(LNET_LOCK_EX);
394 lnet_peer_del_locked(peer);
395 lnet_net_unlock(LNET_LOCK_EX);
401 * Delete a NID from a peer. Call with ln_api_mutex held.
404 * -EPERM: Non-DLC deletion from DLC-configured peer.
405 * -ENOENT: No lnet_peer_ni corresponding to the nid.
406 * -ECHILD: The lnet_peer_ni isn't connected to the peer.
407 * -EBUSY: The lnet_peer_ni is the primary, and not the only peer_ni.
410 lnet_peer_del_nid(struct lnet_peer *lp, lnet_nid_t nid, unsigned flags)
412 struct lnet_peer_ni *lpni;
413 lnet_nid_t primary_nid = lp->lp_primary_nid;
416 if (!(flags & LNET_PEER_CONFIGURED)) {
417 if (lp->lp_state & LNET_PEER_CONFIGURED) {
422 lpni = lnet_find_peer_ni_locked(nid);
427 lnet_peer_ni_decref_locked(lpni);
428 if (lp != lpni->lpni_peer_net->lpn_peer) {
434 * This function only allows deletion of the primary NID if it
437 if (nid == lp->lp_primary_nid && lp->lp_nnis != 1) {
442 lnet_net_lock(LNET_LOCK_EX);
443 lnet_peer_ni_del_locked(lpni);
444 lnet_net_unlock(LNET_LOCK_EX);
447 CDEBUG(D_NET, "peer %s NID %s flags %#x: %d\n",
448 libcfs_nid2str(primary_nid), libcfs_nid2str(nid), flags, rc);
454 lnet_peer_table_cleanup_locked(struct lnet_net *net,
455 struct lnet_peer_table *ptable)
458 struct lnet_peer_ni *next;
459 struct lnet_peer_ni *lpni;
460 struct lnet_peer *peer;
462 for (i = 0; i < LNET_PEER_HASH_SIZE; i++) {
463 list_for_each_entry_safe(lpni, next, &ptable->pt_hash[i],
465 if (net != NULL && net != lpni->lpni_net)
468 peer = lpni->lpni_peer_net->lpn_peer;
469 if (peer->lp_primary_nid != lpni->lpni_nid) {
470 lnet_peer_ni_del_locked(lpni);
474 * Removing the primary NID implies removing
475 * the entire peer. Advance next beyond any
476 * peer_ni that belongs to the same peer.
478 list_for_each_entry_from(next, &ptable->pt_hash[i],
480 if (next->lpni_peer_net->lpn_peer != peer)
483 lnet_peer_del_locked(peer);
489 lnet_peer_ni_finalize_wait(struct lnet_peer_table *ptable)
493 spin_lock(&ptable->pt_zombie_lock);
494 while (ptable->pt_zombies) {
495 spin_unlock(&ptable->pt_zombie_lock);
499 "Waiting for %d zombies on peer table\n",
502 set_current_state(TASK_UNINTERRUPTIBLE);
503 schedule_timeout(cfs_time_seconds(1) >> 1);
504 spin_lock(&ptable->pt_zombie_lock);
506 spin_unlock(&ptable->pt_zombie_lock);
510 lnet_peer_table_del_rtrs_locked(struct lnet_net *net,
511 struct lnet_peer_table *ptable)
513 struct lnet_peer_ni *lp;
514 struct lnet_peer_ni *tmp;
518 for (i = 0; i < LNET_PEER_HASH_SIZE; i++) {
519 list_for_each_entry_safe(lp, tmp, &ptable->pt_hash[i],
521 if (net != lp->lpni_net)
524 if (lp->lpni_rtr_refcount == 0)
527 lpni_nid = lp->lpni_nid;
529 lnet_net_unlock(LNET_LOCK_EX);
530 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), lpni_nid);
531 lnet_net_lock(LNET_LOCK_EX);
537 lnet_peer_tables_cleanup(struct lnet_net *net)
540 struct lnet_peer_table *ptable;
542 LASSERT(the_lnet.ln_state != LNET_STATE_SHUTDOWN || net != NULL);
543 /* If just deleting the peers for a NI, get rid of any routes these
544 * peers are gateways for. */
545 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
546 lnet_net_lock(LNET_LOCK_EX);
547 lnet_peer_table_del_rtrs_locked(net, ptable);
548 lnet_net_unlock(LNET_LOCK_EX);
551 /* Start the cleanup process */
552 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables) {
553 lnet_net_lock(LNET_LOCK_EX);
554 lnet_peer_table_cleanup_locked(net, ptable);
555 lnet_net_unlock(LNET_LOCK_EX);
558 cfs_percpt_for_each(ptable, i, the_lnet.ln_peer_tables)
559 lnet_peer_ni_finalize_wait(ptable);
562 static struct lnet_peer_ni *
563 lnet_get_peer_ni_locked(struct lnet_peer_table *ptable, lnet_nid_t nid)
565 struct list_head *peers;
566 struct lnet_peer_ni *lp;
568 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
570 peers = &ptable->pt_hash[lnet_nid2peerhash(nid)];
571 list_for_each_entry(lp, peers, lpni_hashlist) {
572 if (lp->lpni_nid == nid) {
573 lnet_peer_ni_addref_locked(lp);
581 struct lnet_peer_ni *
582 lnet_find_peer_ni_locked(lnet_nid_t nid)
584 struct lnet_peer_ni *lpni;
585 struct lnet_peer_table *ptable;
588 cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
590 ptable = the_lnet.ln_peer_tables[cpt];
591 lpni = lnet_get_peer_ni_locked(ptable, nid);
596 struct lnet_peer_ni *
597 lnet_get_peer_ni_idx_locked(int idx, struct lnet_peer_net **lpn,
598 struct lnet_peer **lp)
600 struct lnet_peer_table *ptable;
601 struct lnet_peer_ni *lpni;
605 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
607 for (cpt = 0; cpt < lncpt; cpt++) {
608 ptable = the_lnet.ln_peer_tables[cpt];
609 if (ptable->pt_peer_nnids > idx)
611 idx -= ptable->pt_peer_nnids;
616 list_for_each_entry((*lp), &ptable->pt_peer_list, lp_peer_list) {
617 if ((*lp)->lp_nnis <= idx) {
618 idx -= (*lp)->lp_nnis;
621 list_for_each_entry((*lpn), &((*lp)->lp_peer_nets),
623 list_for_each_entry(lpni, &((*lpn)->lpn_peer_nis),
634 struct lnet_peer_ni *
635 lnet_get_next_peer_ni_locked(struct lnet_peer *peer,
636 struct lnet_peer_net *peer_net,
637 struct lnet_peer_ni *prev)
639 struct lnet_peer_ni *lpni;
640 struct lnet_peer_net *net = peer_net;
644 if (list_empty(&peer->lp_peer_nets))
647 net = list_entry(peer->lp_peer_nets.next,
648 struct lnet_peer_net,
651 lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
657 if (prev->lpni_peer_nis.next == &prev->lpni_peer_net->lpn_peer_nis) {
659 * if you reached the end of the peer ni list and the peer
660 * net is specified then there are no more peer nis in that
667 * we reached the end of this net ni list. move to the
670 if (prev->lpni_peer_net->lpn_peer_nets.next ==
672 /* no more nets and no more NIs. */
675 /* get the next net */
676 net = list_entry(prev->lpni_peer_net->lpn_peer_nets.next,
677 struct lnet_peer_net,
679 /* get the ni on it */
680 lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
686 /* there are more nis left */
687 lpni = list_entry(prev->lpni_peer_nis.next,
688 struct lnet_peer_ni, lpni_peer_nis);
694 * Test whether a ni is a preferred ni for this peer_ni, e.g, whether
695 * this is a preferred point-to-point path. Call with lnet_net_lock in
699 lnet_peer_is_pref_nid_locked(struct lnet_peer_ni *lpni, lnet_nid_t nid)
703 if (lpni->lpni_pref_nnids == 0)
705 if (lpni->lpni_pref_nnids == 1)
706 return lpni->lpni_pref.nid == nid;
707 for (i = 0; i < lpni->lpni_pref_nnids; i++) {
708 if (lpni->lpni_pref.nids[i] == nid)
715 * Set a single ni as preferred, provided no preferred ni is already
716 * defined. Only to be used for non-multi-rail peer_ni.
719 lnet_peer_ni_set_non_mr_pref_nid(struct lnet_peer_ni *lpni, lnet_nid_t nid)
723 spin_lock(&lpni->lpni_lock);
724 if (nid == LNET_NID_ANY) {
726 } else if (lpni->lpni_pref_nnids > 0) {
728 } else if (lpni->lpni_pref_nnids == 0) {
729 lpni->lpni_pref.nid = nid;
730 lpni->lpni_pref_nnids = 1;
731 lpni->lpni_state |= LNET_PEER_NI_NON_MR_PREF;
733 spin_unlock(&lpni->lpni_lock);
735 CDEBUG(D_NET, "peer %s nid %s: %d\n",
736 libcfs_nid2str(lpni->lpni_nid), libcfs_nid2str(nid), rc);
741 * Clear the preferred NID from a non-multi-rail peer_ni, provided
742 * this preference was set by lnet_peer_ni_set_non_mr_pref_nid().
745 lnet_peer_ni_clr_non_mr_pref_nid(struct lnet_peer_ni *lpni)
749 spin_lock(&lpni->lpni_lock);
750 if (lpni->lpni_state & LNET_PEER_NI_NON_MR_PREF) {
751 lpni->lpni_pref_nnids = 0;
752 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
753 } else if (lpni->lpni_pref_nnids == 0) {
758 spin_unlock(&lpni->lpni_lock);
760 CDEBUG(D_NET, "peer %s: %d\n",
761 libcfs_nid2str(lpni->lpni_nid), rc);
766 * Clear the preferred NIDs from a non-multi-rail peer.
769 lnet_peer_clr_non_mr_pref_nids(struct lnet_peer *lp)
771 struct lnet_peer_ni *lpni = NULL;
773 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
774 lnet_peer_ni_clr_non_mr_pref_nid(lpni);
778 lnet_peer_add_pref_nid(struct lnet_peer_ni *lpni, lnet_nid_t nid)
780 lnet_nid_t *nids = NULL;
781 lnet_nid_t *oldnids = NULL;
782 struct lnet_peer *lp = lpni->lpni_peer_net->lpn_peer;
787 if (nid == LNET_NID_ANY) {
792 if (lpni->lpni_pref_nnids == 1 && lpni->lpni_pref.nid == nid) {
797 /* A non-MR node may have only one preferred NI per peer_ni */
798 if (lpni->lpni_pref_nnids > 0) {
799 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
805 if (lpni->lpni_pref_nnids != 0) {
806 size = sizeof(*nids) * (lpni->lpni_pref_nnids + 1);
807 LIBCFS_CPT_ALLOC(nids, lnet_cpt_table(), lpni->lpni_cpt, size);
812 for (i = 0; i < lpni->lpni_pref_nnids; i++) {
813 if (lpni->lpni_pref.nids[i] == nid) {
814 LIBCFS_FREE(nids, size);
818 nids[i] = lpni->lpni_pref.nids[i];
823 lnet_net_lock(LNET_LOCK_EX);
824 spin_lock(&lpni->lpni_lock);
825 if (lpni->lpni_pref_nnids == 0) {
826 lpni->lpni_pref.nid = nid;
828 oldnids = lpni->lpni_pref.nids;
829 lpni->lpni_pref.nids = nids;
831 lpni->lpni_pref_nnids++;
832 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
833 spin_unlock(&lpni->lpni_lock);
834 lnet_net_unlock(LNET_LOCK_EX);
837 size = sizeof(*nids) * (lpni->lpni_pref_nnids - 1);
838 LIBCFS_FREE(oldnids, sizeof(*oldnids) * size);
841 if (rc == -EEXIST && (lpni->lpni_state & LNET_PEER_NI_NON_MR_PREF)) {
842 spin_lock(&lpni->lpni_lock);
843 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
844 spin_unlock(&lpni->lpni_lock);
846 CDEBUG(D_NET, "peer %s nid %s: %d\n",
847 libcfs_nid2str(lp->lp_primary_nid), libcfs_nid2str(nid), rc);
852 lnet_peer_del_pref_nid(struct lnet_peer_ni *lpni, lnet_nid_t nid)
854 lnet_nid_t *nids = NULL;
855 lnet_nid_t *oldnids = NULL;
856 struct lnet_peer *lp = lpni->lpni_peer_net->lpn_peer;
861 if (lpni->lpni_pref_nnids == 0) {
866 if (lpni->lpni_pref_nnids == 1) {
867 if (lpni->lpni_pref.nid != nid) {
871 } else if (lpni->lpni_pref_nnids == 2) {
872 if (lpni->lpni_pref.nids[0] != nid &&
873 lpni->lpni_pref.nids[1] != nid) {
878 size = sizeof(*nids) * (lpni->lpni_pref_nnids - 1);
879 LIBCFS_CPT_ALLOC(nids, lnet_cpt_table(), lpni->lpni_cpt, size);
884 for (i = 0, j = 0; i < lpni->lpni_pref_nnids; i++) {
885 if (lpni->lpni_pref.nids[i] != nid)
887 nids[j++] = lpni->lpni_pref.nids[i];
889 /* Check if we actually removed a nid. */
890 if (j == lpni->lpni_pref_nnids) {
891 LIBCFS_FREE(nids, size);
897 lnet_net_lock(LNET_LOCK_EX);
898 spin_lock(&lpni->lpni_lock);
899 if (lpni->lpni_pref_nnids == 1) {
900 lpni->lpni_pref.nid = LNET_NID_ANY;
901 } else if (lpni->lpni_pref_nnids == 2) {
902 oldnids = lpni->lpni_pref.nids;
903 if (oldnids[0] == nid)
904 lpni->lpni_pref.nid = oldnids[1];
906 lpni->lpni_pref.nid = oldnids[2];
908 oldnids = lpni->lpni_pref.nids;
909 lpni->lpni_pref.nids = nids;
911 lpni->lpni_pref_nnids--;
912 lpni->lpni_state &= ~LNET_PEER_NI_NON_MR_PREF;
913 spin_unlock(&lpni->lpni_lock);
914 lnet_net_unlock(LNET_LOCK_EX);
917 size = sizeof(*nids) * (lpni->lpni_pref_nnids + 1);
918 LIBCFS_FREE(oldnids, sizeof(*oldnids) * size);
921 CDEBUG(D_NET, "peer %s nid %s: %d\n",
922 libcfs_nid2str(lp->lp_primary_nid), libcfs_nid2str(nid), rc);
927 lnet_peer_primary_nid(lnet_nid_t nid)
929 struct lnet_peer_ni *lpni;
930 lnet_nid_t primary_nid = nid;
933 cpt = lnet_net_lock_current();
934 lpni = lnet_find_peer_ni_locked(nid);
936 primary_nid = lpni->lpni_peer_net->lpn_peer->lp_primary_nid;
937 lnet_peer_ni_decref_locked(lpni);
939 lnet_net_unlock(cpt);
945 LNetPrimaryNID(lnet_nid_t nid)
947 struct lnet_peer_ni *lpni;
948 lnet_nid_t primary_nid = nid;
952 cpt = lnet_net_lock_current();
953 lpni = lnet_nid2peerni_locked(nid, LNET_NID_ANY, cpt);
958 primary_nid = lpni->lpni_peer_net->lpn_peer->lp_primary_nid;
959 lnet_peer_ni_decref_locked(lpni);
961 lnet_net_unlock(cpt);
963 CDEBUG(D_NET, "NID %s primary NID %s rc %d\n", libcfs_nid2str(nid),
964 libcfs_nid2str(primary_nid), rc);
967 EXPORT_SYMBOL(LNetPrimaryNID);
969 struct lnet_peer_net *
970 lnet_peer_get_net_locked(struct lnet_peer *peer, __u32 net_id)
972 struct lnet_peer_net *peer_net;
973 list_for_each_entry(peer_net, &peer->lp_peer_nets, lpn_peer_nets) {
974 if (peer_net->lpn_net_id == net_id)
981 * Attach a peer_ni to a peer_net and peer. This function assumes
982 * peer_ni is not already attached to the peer_net/peer. The peer_ni
983 * may be attached to a different peer, in which case it will be
984 * properly detached first. The whole operation is done atomically.
986 * Always returns 0. This is the last function called from functions
987 * that do return an int, so returning 0 here allows the compiler to
991 lnet_peer_attach_peer_ni(struct lnet_peer *lp,
992 struct lnet_peer_net *lpn,
993 struct lnet_peer_ni *lpni,
996 struct lnet_peer_table *ptable;
998 /* Install the new peer_ni */
999 lnet_net_lock(LNET_LOCK_EX);
1000 /* Add peer_ni to global peer table hash, if necessary. */
1001 if (list_empty(&lpni->lpni_hashlist)) {
1002 int hash = lnet_nid2peerhash(lpni->lpni_nid);
1004 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
1005 list_add_tail(&lpni->lpni_hashlist, &ptable->pt_hash[hash]);
1006 ptable->pt_version++;
1007 ptable->pt_number++;
1008 /* This is the 1st refcount on lpni. */
1009 atomic_inc(&lpni->lpni_refcount);
1012 /* Detach the peer_ni from an existing peer, if necessary. */
1013 if (lpni->lpni_peer_net) {
1014 LASSERT(lpni->lpni_peer_net != lpn);
1015 LASSERT(lpni->lpni_peer_net->lpn_peer != lp);
1016 lnet_peer_detach_peer_ni_locked(lpni);
1017 lnet_peer_net_decref_locked(lpni->lpni_peer_net);
1018 lpni->lpni_peer_net = NULL;
1021 /* Add peer_ni to peer_net */
1022 lpni->lpni_peer_net = lpn;
1023 list_add_tail(&lpni->lpni_peer_nis, &lpn->lpn_peer_nis);
1024 lnet_peer_net_addref_locked(lpn);
1026 /* Add peer_net to peer */
1027 if (!lpn->lpn_peer) {
1029 list_add_tail(&lpn->lpn_peer_nets, &lp->lp_peer_nets);
1030 lnet_peer_addref_locked(lp);
1033 /* Add peer to global peer list, if necessary */
1034 ptable = the_lnet.ln_peer_tables[lp->lp_cpt];
1035 if (list_empty(&lp->lp_peer_list)) {
1036 list_add_tail(&lp->lp_peer_list, &ptable->pt_peer_list);
1041 /* Update peer state */
1042 spin_lock(&lp->lp_lock);
1043 if (flags & LNET_PEER_CONFIGURED) {
1044 if (!(lp->lp_state & LNET_PEER_CONFIGURED))
1045 lp->lp_state |= LNET_PEER_CONFIGURED;
1047 if (flags & LNET_PEER_MULTI_RAIL) {
1048 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1049 lp->lp_state |= LNET_PEER_MULTI_RAIL;
1050 lnet_peer_clr_non_mr_pref_nids(lp);
1053 spin_unlock(&lp->lp_lock);
1056 the_lnet.ln_peer_tables[lp->lp_cpt]->pt_peer_nnids++;
1057 lnet_net_unlock(LNET_LOCK_EX);
1059 CDEBUG(D_NET, "peer %s NID %s flags %#x\n",
1060 libcfs_nid2str(lp->lp_primary_nid),
1061 libcfs_nid2str(lpni->lpni_nid), flags);
1067 * Create a new peer, with nid as its primary nid.
1069 * Call with the lnet_api_mutex held.
1072 lnet_peer_add(lnet_nid_t nid, unsigned flags)
1074 struct lnet_peer *lp;
1075 struct lnet_peer_net *lpn;
1076 struct lnet_peer_ni *lpni;
1079 LASSERT(nid != LNET_NID_ANY);
1082 * No need for the lnet_net_lock here, because the
1083 * lnet_api_mutex is held.
1085 lpni = lnet_find_peer_ni_locked(nid);
1087 /* A peer with this NID already exists. */
1088 lp = lpni->lpni_peer_net->lpn_peer;
1089 lnet_peer_ni_decref_locked(lpni);
1091 * This is an error if the peer was configured and the
1092 * primary NID differs or an attempt is made to change
1093 * the Multi-Rail flag. Otherwise the assumption is
1094 * that an existing peer is being modified.
1096 if (lp->lp_state & LNET_PEER_CONFIGURED) {
1097 if (lp->lp_primary_nid != nid)
1099 else if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL)
1103 /* Delete and recreate as a configured peer. */
1107 /* Create peer, peer_net, and peer_ni. */
1109 lp = lnet_peer_alloc(nid);
1112 lpn = lnet_peer_net_alloc(LNET_NIDNET(nid));
1115 lpni = lnet_peer_ni_alloc(nid);
1119 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1122 LIBCFS_FREE(lpn, sizeof(*lpn));
1124 LIBCFS_FREE(lp, sizeof(*lp));
1126 CDEBUG(D_NET, "peer %s NID flags %#x: %d\n",
1127 libcfs_nid2str(nid), flags, rc);
1132 * Add a NID to a peer. Call with ln_api_mutex held.
1135 * -EPERM: Non-DLC addition to a DLC-configured peer.
1136 * -EEXIST: The NID was configured by DLC for a different peer.
1137 * -ENOMEM: Out of memory.
1138 * -ENOTUNIQ: Adding a second peer NID on a single network on a
1139 * non-multi-rail peer.
1142 lnet_peer_add_nid(struct lnet_peer *lp, lnet_nid_t nid, unsigned flags)
1144 struct lnet_peer_net *lpn;
1145 struct lnet_peer_ni *lpni;
1149 LASSERT(nid != LNET_NID_ANY);
1151 /* A configured peer can only be updated through configuration. */
1152 if (!(flags & LNET_PEER_CONFIGURED)) {
1153 if (lp->lp_state & LNET_PEER_CONFIGURED) {
1160 * The MULTI_RAIL flag can be set but not cleared, because
1161 * that would leave the peer struct in an invalid state.
1163 if (flags & LNET_PEER_MULTI_RAIL) {
1164 spin_lock(&lp->lp_lock);
1165 if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1166 lp->lp_state |= LNET_PEER_MULTI_RAIL;
1167 lnet_peer_clr_non_mr_pref_nids(lp);
1169 spin_unlock(&lp->lp_lock);
1170 } else if (lp->lp_state & LNET_PEER_MULTI_RAIL) {
1175 lpni = lnet_find_peer_ni_locked(nid);
1178 * A peer_ni already exists. This is only a problem if
1179 * it is not connected to this peer and was configured
1182 lnet_peer_ni_decref_locked(lpni);
1183 if (lpni->lpni_peer_net->lpn_peer == lp)
1185 if (lnet_peer_ni_is_configured(lpni)) {
1189 /* If this is the primary NID, destroy the peer. */
1190 if (lnet_peer_ni_is_primary(lpni)) {
1191 lnet_peer_del(lpni->lpni_peer_net->lpn_peer);
1192 lpni = lnet_peer_ni_alloc(nid);
1199 lpni = lnet_peer_ni_alloc(nid);
1207 * Get the peer_net. Check that we're not adding a second
1208 * peer_ni on a peer_net of a non-multi-rail peer.
1210 lpn = lnet_peer_get_net_locked(lp, LNET_NIDNET(nid));
1212 lpn = lnet_peer_net_alloc(LNET_NIDNET(nid));
1217 } else if (!(lp->lp_state & LNET_PEER_MULTI_RAIL)) {
1222 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1225 /* If the peer_ni was allocated above its peer_net pointer is NULL */
1226 if (!lpni->lpni_peer_net)
1227 LIBCFS_FREE(lpni, sizeof(*lpni));
1229 CDEBUG(D_NET, "peer %s NID %s flags %#x: %d\n",
1230 libcfs_nid2str(lp->lp_primary_nid), libcfs_nid2str(nid),
1236 * lpni creation initiated due to traffic either sending or receiving.
1239 lnet_peer_ni_traffic_add(lnet_nid_t nid, lnet_nid_t pref)
1241 struct lnet_peer *lp;
1242 struct lnet_peer_net *lpn;
1243 struct lnet_peer_ni *lpni;
1247 if (nid == LNET_NID_ANY) {
1252 /* lnet_net_lock is not needed here because ln_api_lock is held */
1253 lpni = lnet_find_peer_ni_locked(nid);
1256 * We must have raced with another thread. Since we
1257 * know next to nothing about a peer_ni created by
1258 * traffic, we just assume everything is ok and
1261 lnet_peer_ni_decref_locked(lpni);
1265 /* Create peer, peer_net, and peer_ni. */
1267 lp = lnet_peer_alloc(nid);
1270 lpn = lnet_peer_net_alloc(LNET_NIDNET(nid));
1273 lpni = lnet_peer_ni_alloc(nid);
1276 if (pref != LNET_NID_ANY)
1277 lnet_peer_ni_set_non_mr_pref_nid(lpni, pref);
1279 return lnet_peer_attach_peer_ni(lp, lpn, lpni, flags);
1282 LIBCFS_FREE(lpn, sizeof(*lpn));
1284 LIBCFS_FREE(lp, sizeof(*lp));
1286 CDEBUG(D_NET, "peer %s: %d\n", libcfs_nid2str(nid), rc);
1291 * Implementation of IOC_LIBCFS_ADD_PEER_NI.
1293 * This API handles the following combinations:
1294 * Create a peer with its primary NI if only the prim_nid is provided
1295 * Add a NID to a peer identified by the prim_nid. The peer identified
1296 * by the prim_nid must already exist.
1297 * The peer being created may be non-MR.
1299 * The caller must hold ln_api_mutex. This prevents the peer from
1300 * being created/modified/deleted by a different thread.
1303 lnet_add_peer_ni(lnet_nid_t prim_nid, lnet_nid_t nid, bool mr)
1305 struct lnet_peer *lp = NULL;
1306 struct lnet_peer_ni *lpni;
1309 /* The prim_nid must always be specified */
1310 if (prim_nid == LNET_NID_ANY)
1313 flags = LNET_PEER_CONFIGURED;
1315 flags |= LNET_PEER_MULTI_RAIL;
1318 * If nid isn't specified, we must create a new peer with
1319 * prim_nid as its primary nid.
1321 if (nid == LNET_NID_ANY)
1322 return lnet_peer_add(prim_nid, flags);
1324 /* Look up the prim_nid, which must exist. */
1325 lpni = lnet_find_peer_ni_locked(prim_nid);
1328 lnet_peer_ni_decref_locked(lpni);
1329 lp = lpni->lpni_peer_net->lpn_peer;
1331 /* Peer must have been configured. */
1332 if (!(lp->lp_state & LNET_PEER_CONFIGURED)) {
1333 CDEBUG(D_NET, "peer %s was not configured\n",
1334 libcfs_nid2str(prim_nid));
1338 /* Primary NID must match */
1339 if (lp->lp_primary_nid != prim_nid) {
1340 CDEBUG(D_NET, "prim_nid %s is not primary for peer %s\n",
1341 libcfs_nid2str(prim_nid),
1342 libcfs_nid2str(lp->lp_primary_nid));
1346 /* Multi-Rail flag must match. */
1347 if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL) {
1348 CDEBUG(D_NET, "multi-rail state mismatch for peer %s\n",
1349 libcfs_nid2str(prim_nid));
1353 return lnet_peer_add_nid(lp, nid, flags);
1357 * Implementation of IOC_LIBCFS_DEL_PEER_NI.
1359 * This API handles the following combinations:
1360 * Delete a NI from a peer if both prim_nid and nid are provided.
1361 * Delete a peer if only prim_nid is provided.
1362 * Delete a peer if its primary nid is provided.
1364 * The caller must hold ln_api_mutex. This prevents the peer from
1365 * being modified/deleted by a different thread.
1368 lnet_del_peer_ni(lnet_nid_t prim_nid, lnet_nid_t nid)
1370 struct lnet_peer *lp;
1371 struct lnet_peer_ni *lpni;
1374 if (prim_nid == LNET_NID_ANY)
1377 lpni = lnet_find_peer_ni_locked(prim_nid);
1380 lnet_peer_ni_decref_locked(lpni);
1381 lp = lpni->lpni_peer_net->lpn_peer;
1383 if (prim_nid != lp->lp_primary_nid) {
1384 CDEBUG(D_NET, "prim_nid %s is not primary for peer %s\n",
1385 libcfs_nid2str(prim_nid),
1386 libcfs_nid2str(lp->lp_primary_nid));
1390 if (nid == LNET_NID_ANY || nid == lp->lp_primary_nid)
1391 return lnet_peer_del(lp);
1393 flags = LNET_PEER_CONFIGURED;
1394 if (lp->lp_state & LNET_PEER_MULTI_RAIL)
1395 flags |= LNET_PEER_MULTI_RAIL;
1397 return lnet_peer_del_nid(lp, nid, flags);
1401 lnet_destroy_peer_ni_locked(struct lnet_peer_ni *lpni)
1403 struct lnet_peer_table *ptable;
1404 struct lnet_peer_net *lpn;
1406 CDEBUG(D_NET, "%p nid %s\n", lpni, libcfs_nid2str(lpni->lpni_nid));
1408 LASSERT(atomic_read(&lpni->lpni_refcount) == 0);
1409 LASSERT(lpni->lpni_rtr_refcount == 0);
1410 LASSERT(list_empty(&lpni->lpni_txq));
1411 LASSERT(lpni->lpni_txqnob == 0);
1413 lpn = lpni->lpni_peer_net;
1414 lpni->lpni_peer_net = NULL;
1415 lpni->lpni_net = NULL;
1417 /* remove the peer ni from the zombie list */
1418 ptable = the_lnet.ln_peer_tables[lpni->lpni_cpt];
1419 spin_lock(&ptable->pt_zombie_lock);
1420 list_del_init(&lpni->lpni_hashlist);
1421 ptable->pt_zombies--;
1422 spin_unlock(&ptable->pt_zombie_lock);
1424 if (lpni->lpni_pref_nnids > 1) {
1425 LIBCFS_FREE(lpni->lpni_pref.nids,
1426 sizeof(*lpni->lpni_pref.nids) * lpni->lpni_pref_nnids);
1428 LIBCFS_FREE(lpni, sizeof(*lpni));
1430 lnet_peer_net_decref_locked(lpn);
1433 struct lnet_peer_ni *
1434 lnet_nid2peerni_ex(lnet_nid_t nid, int cpt)
1436 struct lnet_peer_ni *lpni = NULL;
1439 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1440 return ERR_PTR(-ESHUTDOWN);
1443 * find if a peer_ni already exists.
1444 * If so then just return that.
1446 lpni = lnet_find_peer_ni_locked(nid);
1450 lnet_net_unlock(cpt);
1452 rc = lnet_peer_ni_traffic_add(nid, LNET_NID_ANY);
1455 goto out_net_relock;
1458 lpni = lnet_find_peer_ni_locked(nid);
1467 struct lnet_peer_ni *
1468 lnet_nid2peerni_locked(lnet_nid_t nid, lnet_nid_t pref, int cpt)
1470 struct lnet_peer_ni *lpni = NULL;
1473 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1474 return ERR_PTR(-ESHUTDOWN);
1477 * find if a peer_ni already exists.
1478 * If so then just return that.
1480 lpni = lnet_find_peer_ni_locked(nid);
1486 * use the lnet_api_mutex to serialize the creation of the peer_ni
1487 * and the creation/deletion of the local ni/net. When a local ni is
1488 * created, if there exists a set of peer_nis on that network,
1489 * they need to be traversed and updated. When a local NI is
1490 * deleted, which could result in a network being deleted, then
1491 * all peer nis on that network need to be removed as well.
1493 * Creation through traffic should also be serialized with
1494 * creation through DLC.
1496 lnet_net_unlock(cpt);
1497 mutex_lock(&the_lnet.ln_api_mutex);
1499 * Shutdown is only set under the ln_api_lock, so a single
1500 * check here is sufficent.
1502 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1503 lpni = ERR_PTR(-ESHUTDOWN);
1504 goto out_mutex_unlock;
1507 rc = lnet_peer_ni_traffic_add(nid, pref);
1510 goto out_mutex_unlock;
1513 lpni = lnet_find_peer_ni_locked(nid);
1517 mutex_unlock(&the_lnet.ln_api_mutex);
1524 lnet_debug_peer(lnet_nid_t nid)
1526 char *aliveness = "NA";
1527 struct lnet_peer_ni *lp;
1530 cpt = lnet_cpt_of_nid(nid, NULL);
1533 lp = lnet_nid2peerni_locked(nid, LNET_NID_ANY, cpt);
1535 lnet_net_unlock(cpt);
1536 CDEBUG(D_WARNING, "No peer %s\n", libcfs_nid2str(nid));
1540 if (lnet_isrouter(lp) || lnet_peer_aliveness_enabled(lp))
1541 aliveness = lp->lpni_alive ? "up" : "down";
1543 CDEBUG(D_WARNING, "%-24s %4d %5s %5d %5d %5d %5d %5d %ld\n",
1544 libcfs_nid2str(lp->lpni_nid), atomic_read(&lp->lpni_refcount),
1545 aliveness, lp->lpni_net->net_tunables.lct_peer_tx_credits,
1546 lp->lpni_rtrcredits, lp->lpni_minrtrcredits,
1547 lp->lpni_txcredits, lp->lpni_mintxcredits, lp->lpni_txqnob);
1549 lnet_peer_ni_decref_locked(lp);
1551 lnet_net_unlock(cpt);
1554 int lnet_get_peer_ni_info(__u32 peer_index, __u64 *nid,
1555 char aliveness[LNET_MAX_STR_LEN],
1556 __u32 *cpt_iter, __u32 *refcount,
1557 __u32 *ni_peer_tx_credits, __u32 *peer_tx_credits,
1558 __u32 *peer_rtr_credits, __u32 *peer_min_rtr_credits,
1559 __u32 *peer_tx_qnob)
1561 struct lnet_peer_table *peer_table;
1562 struct lnet_peer_ni *lp;
1567 /* get the number of CPTs */
1568 lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
1570 /* if the cpt number to be examined is >= the number of cpts in
1571 * the system then indicate that there are no more cpts to examin
1573 if (*cpt_iter >= lncpt)
1576 /* get the current table */
1577 peer_table = the_lnet.ln_peer_tables[*cpt_iter];
1578 /* if the ptable is NULL then there are no more cpts to examine */
1579 if (peer_table == NULL)
1582 lnet_net_lock(*cpt_iter);
1584 for (j = 0; j < LNET_PEER_HASH_SIZE && !found; j++) {
1585 struct list_head *peers = &peer_table->pt_hash[j];
1587 list_for_each_entry(lp, peers, lpni_hashlist) {
1588 if (peer_index-- > 0)
1591 snprintf(aliveness, LNET_MAX_STR_LEN, "NA");
1592 if (lnet_isrouter(lp) ||
1593 lnet_peer_aliveness_enabled(lp))
1594 snprintf(aliveness, LNET_MAX_STR_LEN,
1595 lp->lpni_alive ? "up" : "down");
1597 *nid = lp->lpni_nid;
1598 *refcount = atomic_read(&lp->lpni_refcount);
1599 *ni_peer_tx_credits =
1600 lp->lpni_net->net_tunables.lct_peer_tx_credits;
1601 *peer_tx_credits = lp->lpni_txcredits;
1602 *peer_rtr_credits = lp->lpni_rtrcredits;
1603 *peer_min_rtr_credits = lp->lpni_mintxcredits;
1604 *peer_tx_qnob = lp->lpni_txqnob;
1610 lnet_net_unlock(*cpt_iter);
1614 return found ? 0 : -ENOENT;
1617 /* ln_api_mutex is held, which keeps the peer list stable */
1618 int lnet_get_peer_info(__u32 idx, lnet_nid_t *primary_nid, lnet_nid_t *nid,
1619 bool *mr, struct lnet_peer_ni_credit_info *peer_ni_info,
1620 struct lnet_ioctl_element_stats *peer_ni_stats)
1622 struct lnet_peer_ni *lpni = NULL;
1623 struct lnet_peer_net *lpn = NULL;
1624 struct lnet_peer *lp = NULL;
1626 lpni = lnet_get_peer_ni_idx_locked(idx, &lpn, &lp);
1631 *primary_nid = lp->lp_primary_nid;
1632 *mr = lnet_peer_is_multi_rail(lp);
1633 *nid = lpni->lpni_nid;
1634 snprintf(peer_ni_info->cr_aliveness, LNET_MAX_STR_LEN, "NA");
1635 if (lnet_isrouter(lpni) ||
1636 lnet_peer_aliveness_enabled(lpni))
1637 snprintf(peer_ni_info->cr_aliveness, LNET_MAX_STR_LEN,
1638 lpni->lpni_alive ? "up" : "down");
1640 peer_ni_info->cr_refcount = atomic_read(&lpni->lpni_refcount);
1641 peer_ni_info->cr_ni_peer_tx_credits = (lpni->lpni_net != NULL) ?
1642 lpni->lpni_net->net_tunables.lct_peer_tx_credits : 0;
1643 peer_ni_info->cr_peer_tx_credits = lpni->lpni_txcredits;
1644 peer_ni_info->cr_peer_rtr_credits = lpni->lpni_rtrcredits;
1645 peer_ni_info->cr_peer_min_rtr_credits = lpni->lpni_minrtrcredits;
1646 peer_ni_info->cr_peer_min_tx_credits = lpni->lpni_mintxcredits;
1647 peer_ni_info->cr_peer_tx_qnob = lpni->lpni_txqnob;
1649 peer_ni_stats->send_count = atomic_read(&lpni->lpni_stats.send_count);
1650 peer_ni_stats->recv_count = atomic_read(&lpni->lpni_stats.recv_count);
1651 peer_ni_stats->drop_count = atomic_read(&lpni->lpni_stats.drop_count);