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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LNET
35 #include <linux/ctype.h>
36 #include <linux/log2.h>
37 #include <linux/ktime.h>
38 #include <linux/moduleparam.h>
39 #include <linux/uaccess.h>
41 #include <lnet/lib-lnet.h>
43 #define D_LNI D_CONSOLE
46 * initialize ln_api_mutex statically, since it needs to be used in
47 * discovery_set callback. That module parameter callback can be called
48 * before module init completes. The mutex needs to be ready for use then.
50 struct lnet the_lnet = {
51 .ln_api_mutex = __MUTEX_INITIALIZER(the_lnet.ln_api_mutex),
52 }; /* THE state of the network */
53 EXPORT_SYMBOL(the_lnet);
55 static char *ip2nets = "";
56 module_param(ip2nets, charp, 0444);
57 MODULE_PARM_DESC(ip2nets, "LNET network <- IP table");
59 static char *networks = "";
60 module_param(networks, charp, 0444);
61 MODULE_PARM_DESC(networks, "local networks");
63 static char *routes = "";
64 module_param(routes, charp, 0444);
65 MODULE_PARM_DESC(routes, "routes to non-local networks");
67 static int rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
68 module_param(rnet_htable_size, int, 0444);
69 MODULE_PARM_DESC(rnet_htable_size, "size of remote network hash table");
71 static int use_tcp_bonding = false;
72 module_param(use_tcp_bonding, int, 0444);
73 MODULE_PARM_DESC(use_tcp_bonding,
74 "Set to 1 to use socklnd bonding. 0 to use Multi-Rail");
76 unsigned int lnet_numa_range = 0;
77 module_param(lnet_numa_range, uint, 0444);
78 MODULE_PARM_DESC(lnet_numa_range,
79 "NUMA range to consider during Multi-Rail selection");
82 * lnet_health_sensitivity determines by how much we decrement the health
83 * value on sending error. The value defaults to 0, which means health
84 * checking is turned off by default.
86 unsigned int lnet_health_sensitivity = 0;
87 static int sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp);
88 static struct kernel_param_ops param_ops_health_sensitivity = {
89 .set = sensitivity_set,
92 #define param_check_health_sensitivity(name, p) \
93 __param_check(name, p, int)
94 #ifdef HAVE_KERNEL_PARAM_OPS
95 module_param(lnet_health_sensitivity, health_sensitivity, S_IRUGO|S_IWUSR);
97 module_param_call(lnet_health_sensitivity, sensitivity_set, param_get_int,
98 &lnet_health_sensitivity, S_IRUGO|S_IWUSR);
100 MODULE_PARM_DESC(lnet_health_sensitivity,
101 "Value to decrement the health value by on error");
103 static int lnet_interfaces_max = LNET_INTERFACES_MAX_DEFAULT;
104 static int intf_max_set(const char *val, cfs_kernel_param_arg_t *kp);
106 static struct kernel_param_ops param_ops_interfaces_max = {
108 .get = param_get_int,
111 #define param_check_interfaces_max(name, p) \
112 __param_check(name, p, int)
114 #ifdef HAVE_KERNEL_PARAM_OPS
115 module_param(lnet_interfaces_max, interfaces_max, 0644);
117 module_param_call(lnet_interfaces_max, intf_max_set, param_get_int,
118 ¶m_ops_interfaces_max, 0644);
120 MODULE_PARM_DESC(lnet_interfaces_max,
121 "Maximum number of interfaces in a node.");
123 unsigned lnet_peer_discovery_disabled = 0;
124 static int discovery_set(const char *val, cfs_kernel_param_arg_t *kp);
126 static struct kernel_param_ops param_ops_discovery_disabled = {
127 .set = discovery_set,
128 .get = param_get_int,
131 #define param_check_discovery_disabled(name, p) \
132 __param_check(name, p, int)
133 #ifdef HAVE_KERNEL_PARAM_OPS
134 module_param(lnet_peer_discovery_disabled, discovery_disabled, 0644);
136 module_param_call(lnet_peer_discovery_disabled, discovery_set, param_get_int,
137 ¶m_ops_discovery_disabled, 0644);
139 MODULE_PARM_DESC(lnet_peer_discovery_disabled,
140 "Set to 1 to disable peer discovery on this node.");
142 unsigned lnet_transaction_timeout = 5;
143 static int transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp);
144 static struct kernel_param_ops param_ops_transaction_timeout = {
145 .set = transaction_to_set,
146 .get = param_get_int,
149 #define param_check_transaction_timeout(name, p) \
150 __param_check(name, p, int)
151 #ifdef HAVE_KERNEL_PARAM_OPS
152 module_param(lnet_transaction_timeout, transaction_timeout, S_IRUGO|S_IWUSR);
154 module_param_call(lnet_transaction_timeout, transaction_to_set, param_get_int,
155 &lnet_transaction_timeout, S_IRUGO|S_IWUSR);
157 MODULE_PARM_DESC(lnet_peer_discovery_disabled,
158 "Set to 1 to disable peer discovery on this node.");
160 unsigned lnet_retry_count = 0;
161 static int retry_count_set(const char *val, cfs_kernel_param_arg_t *kp);
162 static struct kernel_param_ops param_ops_retry_count = {
163 .set = retry_count_set,
164 .get = param_get_int,
167 #define param_check_retry_count(name, p) \
168 __param_check(name, p, int)
169 #ifdef HAVE_KERNEL_PARAM_OPS
170 module_param(lnet_retry_count, retry_count, S_IRUGO|S_IWUSR);
172 module_param_call(lnet_retry_count, retry_count_set, param_get_int,
173 &lnet_retry_count, S_IRUGO|S_IWUSR);
175 MODULE_PARM_DESC(lnet_retry_count,
176 "Maximum number of times to retry transmitting a message");
179 unsigned lnet_lnd_timeout = LNET_LND_DEFAULT_TIMEOUT;
182 * This sequence number keeps track of how many times DLC was used to
183 * update the local NIs. It is incremented when a NI is added or
184 * removed and checked when sending a message to determine if there is
185 * a need to re-run the selection algorithm. See lnet_select_pathway()
186 * for more details on its usage.
188 static atomic_t lnet_dlc_seq_no = ATOMIC_INIT(0);
190 static int lnet_ping(struct lnet_process_id id, signed long timeout,
191 struct lnet_process_id __user *ids, int n_ids);
193 static int lnet_discover(struct lnet_process_id id, __u32 force,
194 struct lnet_process_id __user *ids, int n_ids);
197 sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
200 unsigned *sensitivity = (unsigned *)kp->arg;
203 rc = kstrtoul(val, 0, &value);
205 CERROR("Invalid module parameter value for 'lnet_health_sensitivity'\n");
210 * The purpose of locking the api_mutex here is to ensure that
211 * the correct value ends up stored properly.
213 mutex_lock(&the_lnet.ln_api_mutex);
215 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
216 mutex_unlock(&the_lnet.ln_api_mutex);
220 if (value == *sensitivity) {
221 mutex_unlock(&the_lnet.ln_api_mutex);
225 *sensitivity = value;
227 mutex_unlock(&the_lnet.ln_api_mutex);
233 discovery_set(const char *val, cfs_kernel_param_arg_t *kp)
236 unsigned *discovery = (unsigned *)kp->arg;
238 struct lnet_ping_buffer *pbuf;
240 rc = kstrtoul(val, 0, &value);
242 CERROR("Invalid module parameter value for 'lnet_peer_discovery_disabled'\n");
246 value = (value) ? 1 : 0;
249 * The purpose of locking the api_mutex here is to ensure that
250 * the correct value ends up stored properly.
252 mutex_lock(&the_lnet.ln_api_mutex);
254 if (value == *discovery) {
255 mutex_unlock(&the_lnet.ln_api_mutex);
261 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
262 mutex_unlock(&the_lnet.ln_api_mutex);
266 /* tell peers that discovery setting has changed */
267 lnet_net_lock(LNET_LOCK_EX);
268 pbuf = the_lnet.ln_ping_target;
270 pbuf->pb_info.pi_features &= ~LNET_PING_FEAT_DISCOVERY;
272 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
273 lnet_net_unlock(LNET_LOCK_EX);
275 lnet_push_update_to_peers(1);
277 mutex_unlock(&the_lnet.ln_api_mutex);
283 transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp)
286 unsigned *transaction_to = (unsigned *)kp->arg;
289 rc = kstrtoul(val, 0, &value);
291 CERROR("Invalid module parameter value for 'lnet_transaction_timeout'\n");
296 * The purpose of locking the api_mutex here is to ensure that
297 * the correct value ends up stored properly.
299 mutex_lock(&the_lnet.ln_api_mutex);
301 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
302 mutex_unlock(&the_lnet.ln_api_mutex);
306 if (value < lnet_retry_count || value == 0) {
307 mutex_unlock(&the_lnet.ln_api_mutex);
308 CERROR("Invalid value for lnet_transaction_timeout (%lu). "
309 "Has to be greater than lnet_retry_count (%u)\n",
310 value, lnet_retry_count);
314 if (value == *transaction_to) {
315 mutex_unlock(&the_lnet.ln_api_mutex);
319 *transaction_to = value;
320 if (lnet_retry_count == 0)
321 lnet_lnd_timeout = value;
323 lnet_lnd_timeout = value / lnet_retry_count;
325 mutex_unlock(&the_lnet.ln_api_mutex);
331 retry_count_set(const char *val, cfs_kernel_param_arg_t *kp)
334 unsigned *retry_count = (unsigned *)kp->arg;
337 rc = kstrtoul(val, 0, &value);
339 CERROR("Invalid module parameter value for 'lnet_retry_count'\n");
344 * The purpose of locking the api_mutex here is to ensure that
345 * the correct value ends up stored properly.
347 mutex_lock(&the_lnet.ln_api_mutex);
349 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
350 mutex_unlock(&the_lnet.ln_api_mutex);
354 if (value > lnet_transaction_timeout) {
355 mutex_unlock(&the_lnet.ln_api_mutex);
356 CERROR("Invalid value for lnet_retry_count (%lu). "
357 "Has to be smaller than lnet_transaction_timeout (%u)\n",
358 value, lnet_transaction_timeout);
362 if (value == *retry_count) {
363 mutex_unlock(&the_lnet.ln_api_mutex);
367 *retry_count = value;
370 lnet_lnd_timeout = lnet_transaction_timeout;
372 lnet_lnd_timeout = lnet_transaction_timeout / value;
374 mutex_unlock(&the_lnet.ln_api_mutex);
380 intf_max_set(const char *val, cfs_kernel_param_arg_t *kp)
384 rc = kstrtoint(val, 0, &value);
386 CERROR("Invalid module parameter value for 'lnet_interfaces_max'\n");
390 if (value < LNET_INTERFACES_MIN) {
391 CWARN("max interfaces provided are too small, setting to %d\n",
392 LNET_INTERFACES_MAX_DEFAULT);
393 value = LNET_INTERFACES_MAX_DEFAULT;
396 *(int *)kp->arg = value;
402 lnet_get_routes(void)
408 lnet_get_networks(void)
413 if (*networks != 0 && *ip2nets != 0) {
414 LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
415 "'ip2nets' but not both at once\n");
420 rc = lnet_parse_ip2nets(&nets, ip2nets);
421 return (rc == 0) ? nets : NULL;
431 lnet_init_locks(void)
433 spin_lock_init(&the_lnet.ln_eq_wait_lock);
434 spin_lock_init(&the_lnet.ln_msg_resend_lock);
435 init_waitqueue_head(&the_lnet.ln_eq_waitq);
436 init_waitqueue_head(&the_lnet.ln_mt_waitq);
437 mutex_init(&the_lnet.ln_lnd_mutex);
441 lnet_fini_locks(void)
445 struct kmem_cache *lnet_mes_cachep; /* MEs kmem_cache */
446 struct kmem_cache *lnet_small_mds_cachep; /* <= LNET_SMALL_MD_SIZE bytes
450 lnet_descriptor_setup(void)
452 /* create specific kmem_cache for MEs and small MDs (i.e., originally
453 * allocated in <size-xxx> kmem_cache).
455 lnet_mes_cachep = kmem_cache_create("lnet_MEs", sizeof(struct lnet_me),
457 if (!lnet_mes_cachep)
460 lnet_small_mds_cachep = kmem_cache_create("lnet_small_MDs",
461 LNET_SMALL_MD_SIZE, 0, 0,
463 if (!lnet_small_mds_cachep)
470 lnet_descriptor_cleanup(void)
473 if (lnet_small_mds_cachep) {
474 kmem_cache_destroy(lnet_small_mds_cachep);
475 lnet_small_mds_cachep = NULL;
478 if (lnet_mes_cachep) {
479 kmem_cache_destroy(lnet_mes_cachep);
480 lnet_mes_cachep = NULL;
485 lnet_create_remote_nets_table(void)
488 struct list_head *hash;
490 LASSERT(the_lnet.ln_remote_nets_hash == NULL);
491 LASSERT(the_lnet.ln_remote_nets_hbits > 0);
492 LIBCFS_ALLOC(hash, LNET_REMOTE_NETS_HASH_SIZE * sizeof(*hash));
494 CERROR("Failed to create remote nets hash table\n");
498 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
499 INIT_LIST_HEAD(&hash[i]);
500 the_lnet.ln_remote_nets_hash = hash;
505 lnet_destroy_remote_nets_table(void)
509 if (the_lnet.ln_remote_nets_hash == NULL)
512 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
513 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
515 LIBCFS_FREE(the_lnet.ln_remote_nets_hash,
516 LNET_REMOTE_NETS_HASH_SIZE *
517 sizeof(the_lnet.ln_remote_nets_hash[0]));
518 the_lnet.ln_remote_nets_hash = NULL;
522 lnet_destroy_locks(void)
524 if (the_lnet.ln_res_lock != NULL) {
525 cfs_percpt_lock_free(the_lnet.ln_res_lock);
526 the_lnet.ln_res_lock = NULL;
529 if (the_lnet.ln_net_lock != NULL) {
530 cfs_percpt_lock_free(the_lnet.ln_net_lock);
531 the_lnet.ln_net_lock = NULL;
538 lnet_create_locks(void)
542 the_lnet.ln_res_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
543 if (the_lnet.ln_res_lock == NULL)
546 the_lnet.ln_net_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
547 if (the_lnet.ln_net_lock == NULL)
553 lnet_destroy_locks();
557 static void lnet_assert_wire_constants(void)
559 /* Wire protocol assertions generated by 'wirecheck'
560 * running on Linux robert.bartonsoftware.com 2.6.8-1.521
561 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux
562 * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) */
565 CLASSERT(LNET_PROTO_TCP_MAGIC == 0xeebc0ded);
566 CLASSERT(LNET_PROTO_TCP_VERSION_MAJOR == 1);
567 CLASSERT(LNET_PROTO_TCP_VERSION_MINOR == 0);
568 CLASSERT(LNET_MSG_ACK == 0);
569 CLASSERT(LNET_MSG_PUT == 1);
570 CLASSERT(LNET_MSG_GET == 2);
571 CLASSERT(LNET_MSG_REPLY == 3);
572 CLASSERT(LNET_MSG_HELLO == 4);
574 /* Checks for struct lnet_handle_wire */
575 CLASSERT((int)sizeof(struct lnet_handle_wire) == 16);
576 CLASSERT((int)offsetof(struct lnet_handle_wire, wh_interface_cookie) == 0);
577 CLASSERT((int)sizeof(((struct lnet_handle_wire *)0)->wh_interface_cookie) == 8);
578 CLASSERT((int)offsetof(struct lnet_handle_wire, wh_object_cookie) == 8);
579 CLASSERT((int)sizeof(((struct lnet_handle_wire *)0)->wh_object_cookie) == 8);
581 /* Checks for struct struct lnet_magicversion */
582 CLASSERT((int)sizeof(struct lnet_magicversion) == 8);
583 CLASSERT((int)offsetof(struct lnet_magicversion, magic) == 0);
584 CLASSERT((int)sizeof(((struct lnet_magicversion *)0)->magic) == 4);
585 CLASSERT((int)offsetof(struct lnet_magicversion, version_major) == 4);
586 CLASSERT((int)sizeof(((struct lnet_magicversion *)0)->version_major) == 2);
587 CLASSERT((int)offsetof(struct lnet_magicversion, version_minor) == 6);
588 CLASSERT((int)sizeof(((struct lnet_magicversion *)0)->version_minor) == 2);
590 /* Checks for struct struct lnet_hdr */
591 CLASSERT((int)sizeof(struct lnet_hdr) == 72);
592 CLASSERT((int)offsetof(struct lnet_hdr, dest_nid) == 0);
593 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->dest_nid) == 8);
594 CLASSERT((int)offsetof(struct lnet_hdr, src_nid) == 8);
595 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->src_nid) == 8);
596 CLASSERT((int)offsetof(struct lnet_hdr, dest_pid) == 16);
597 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->dest_pid) == 4);
598 CLASSERT((int)offsetof(struct lnet_hdr, src_pid) == 20);
599 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->src_pid) == 4);
600 CLASSERT((int)offsetof(struct lnet_hdr, type) == 24);
601 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->type) == 4);
602 CLASSERT((int)offsetof(struct lnet_hdr, payload_length) == 28);
603 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->payload_length) == 4);
604 CLASSERT((int)offsetof(struct lnet_hdr, msg) == 32);
605 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg) == 40);
608 CLASSERT((int)offsetof(struct lnet_hdr, msg.ack.dst_wmd) == 32);
609 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.ack.dst_wmd) == 16);
610 CLASSERT((int)offsetof(struct lnet_hdr, msg.ack.match_bits) == 48);
611 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.ack.match_bits) == 8);
612 CLASSERT((int)offsetof(struct lnet_hdr, msg.ack.mlength) == 56);
613 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.ack.mlength) == 4);
616 CLASSERT((int)offsetof(struct lnet_hdr, msg.put.ack_wmd) == 32);
617 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.put.ack_wmd) == 16);
618 CLASSERT((int)offsetof(struct lnet_hdr, msg.put.match_bits) == 48);
619 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.put.match_bits) == 8);
620 CLASSERT((int)offsetof(struct lnet_hdr, msg.put.hdr_data) == 56);
621 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.put.hdr_data) == 8);
622 CLASSERT((int)offsetof(struct lnet_hdr, msg.put.ptl_index) == 64);
623 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.put.ptl_index) == 4);
624 CLASSERT((int)offsetof(struct lnet_hdr, msg.put.offset) == 68);
625 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.put.offset) == 4);
628 CLASSERT((int)offsetof(struct lnet_hdr, msg.get.return_wmd) == 32);
629 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.get.return_wmd) == 16);
630 CLASSERT((int)offsetof(struct lnet_hdr, msg.get.match_bits) == 48);
631 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.get.match_bits) == 8);
632 CLASSERT((int)offsetof(struct lnet_hdr, msg.get.ptl_index) == 56);
633 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.get.ptl_index) == 4);
634 CLASSERT((int)offsetof(struct lnet_hdr, msg.get.src_offset) == 60);
635 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.get.src_offset) == 4);
636 CLASSERT((int)offsetof(struct lnet_hdr, msg.get.sink_length) == 64);
637 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.get.sink_length) == 4);
640 CLASSERT((int)offsetof(struct lnet_hdr, msg.reply.dst_wmd) == 32);
641 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.reply.dst_wmd) == 16);
644 CLASSERT((int)offsetof(struct lnet_hdr, msg.hello.incarnation) == 32);
645 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.hello.incarnation) == 8);
646 CLASSERT((int)offsetof(struct lnet_hdr, msg.hello.type) == 40);
647 CLASSERT((int)sizeof(((struct lnet_hdr *)0)->msg.hello.type) == 4);
649 /* Checks for struct lnet_ni_status and related constants */
650 CLASSERT(LNET_NI_STATUS_INVALID == 0x00000000);
651 CLASSERT(LNET_NI_STATUS_UP == 0x15aac0de);
652 CLASSERT(LNET_NI_STATUS_DOWN == 0xdeadface);
654 /* Checks for struct lnet_ni_status */
655 CLASSERT((int)sizeof(struct lnet_ni_status) == 16);
656 CLASSERT((int)offsetof(struct lnet_ni_status, ns_nid) == 0);
657 CLASSERT((int)sizeof(((struct lnet_ni_status *)0)->ns_nid) == 8);
658 CLASSERT((int)offsetof(struct lnet_ni_status, ns_status) == 8);
659 CLASSERT((int)sizeof(((struct lnet_ni_status *)0)->ns_status) == 4);
660 CLASSERT((int)offsetof(struct lnet_ni_status, ns_unused) == 12);
661 CLASSERT((int)sizeof(((struct lnet_ni_status *)0)->ns_unused) == 4);
663 /* Checks for struct lnet_ping_info and related constants */
664 CLASSERT(LNET_PROTO_PING_MAGIC == 0x70696E67);
665 CLASSERT(LNET_PING_FEAT_INVAL == 0);
666 CLASSERT(LNET_PING_FEAT_BASE == 1);
667 CLASSERT(LNET_PING_FEAT_NI_STATUS == 2);
668 CLASSERT(LNET_PING_FEAT_RTE_DISABLED == 4);
669 CLASSERT(LNET_PING_FEAT_MULTI_RAIL == 8);
670 CLASSERT(LNET_PING_FEAT_DISCOVERY == 16);
671 CLASSERT(LNET_PING_FEAT_BITS == 31);
673 /* Checks for struct lnet_ping_info */
674 CLASSERT((int)sizeof(struct lnet_ping_info) == 16);
675 CLASSERT((int)offsetof(struct lnet_ping_info, pi_magic) == 0);
676 CLASSERT((int)sizeof(((struct lnet_ping_info *)0)->pi_magic) == 4);
677 CLASSERT((int)offsetof(struct lnet_ping_info, pi_features) == 4);
678 CLASSERT((int)sizeof(((struct lnet_ping_info *)0)->pi_features) == 4);
679 CLASSERT((int)offsetof(struct lnet_ping_info, pi_pid) == 8);
680 CLASSERT((int)sizeof(((struct lnet_ping_info *)0)->pi_pid) == 4);
681 CLASSERT((int)offsetof(struct lnet_ping_info, pi_nnis) == 12);
682 CLASSERT((int)sizeof(((struct lnet_ping_info *)0)->pi_nnis) == 4);
683 CLASSERT((int)offsetof(struct lnet_ping_info, pi_ni) == 16);
684 CLASSERT((int)sizeof(((struct lnet_ping_info *)0)->pi_ni) == 0);
687 static struct lnet_lnd *lnet_find_lnd_by_type(__u32 type)
689 struct lnet_lnd *lnd;
690 struct list_head *tmp;
692 /* holding lnd mutex */
693 list_for_each(tmp, &the_lnet.ln_lnds) {
694 lnd = list_entry(tmp, struct lnet_lnd, lnd_list);
696 if (lnd->lnd_type == type)
703 lnet_get_lnd_timeout(void)
705 return lnet_lnd_timeout;
707 EXPORT_SYMBOL(lnet_get_lnd_timeout);
710 lnet_register_lnd(struct lnet_lnd *lnd)
712 mutex_lock(&the_lnet.ln_lnd_mutex);
714 LASSERT(libcfs_isknown_lnd(lnd->lnd_type));
715 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
717 list_add_tail(&lnd->lnd_list, &the_lnet.ln_lnds);
718 lnd->lnd_refcount = 0;
720 CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type));
722 mutex_unlock(&the_lnet.ln_lnd_mutex);
724 EXPORT_SYMBOL(lnet_register_lnd);
727 lnet_unregister_lnd(struct lnet_lnd *lnd)
729 mutex_lock(&the_lnet.ln_lnd_mutex);
731 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
732 LASSERT(lnd->lnd_refcount == 0);
734 list_del(&lnd->lnd_list);
735 CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type));
737 mutex_unlock(&the_lnet.ln_lnd_mutex);
739 EXPORT_SYMBOL(lnet_unregister_lnd);
742 lnet_counters_get(struct lnet_counters *counters)
744 struct lnet_counters *ctr;
747 memset(counters, 0, sizeof(*counters));
749 lnet_net_lock(LNET_LOCK_EX);
751 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
752 counters->msgs_max += ctr->msgs_max;
753 counters->msgs_alloc += ctr->msgs_alloc;
754 counters->rst_alloc += ctr->rst_alloc;
755 counters->errors += ctr->errors;
756 counters->resend_count += ctr->resend_count;
757 counters->response_timeout_count += ctr->response_timeout_count;
758 counters->local_interrupt_count += ctr->local_interrupt_count;
759 counters->local_dropped_count += ctr->local_dropped_count;
760 counters->local_aborted_count += ctr->local_aborted_count;
761 counters->local_no_route_count += ctr->local_no_route_count;
762 counters->local_timeout_count += ctr->local_timeout_count;
763 counters->local_error_count += ctr->local_error_count;
764 counters->remote_dropped_count += ctr->remote_dropped_count;
765 counters->remote_error_count += ctr->remote_error_count;
766 counters->remote_timeout_count += ctr->remote_timeout_count;
767 counters->network_timeout_count += ctr->network_timeout_count;
768 counters->send_count += ctr->send_count;
769 counters->recv_count += ctr->recv_count;
770 counters->route_count += ctr->route_count;
771 counters->drop_count += ctr->drop_count;
772 counters->send_length += ctr->send_length;
773 counters->recv_length += ctr->recv_length;
774 counters->route_length += ctr->route_length;
775 counters->drop_length += ctr->drop_length;
778 lnet_net_unlock(LNET_LOCK_EX);
780 EXPORT_SYMBOL(lnet_counters_get);
783 lnet_counters_reset(void)
785 struct lnet_counters *counters;
788 lnet_net_lock(LNET_LOCK_EX);
790 cfs_percpt_for_each(counters, i, the_lnet.ln_counters)
791 memset(counters, 0, sizeof(struct lnet_counters));
793 lnet_net_unlock(LNET_LOCK_EX);
797 lnet_res_type2str(int type)
802 case LNET_COOKIE_TYPE_MD:
804 case LNET_COOKIE_TYPE_ME:
806 case LNET_COOKIE_TYPE_EQ:
812 lnet_res_container_cleanup(struct lnet_res_container *rec)
816 if (rec->rec_type == 0) /* not set yet, it's uninitialized */
819 while (!list_empty(&rec->rec_active)) {
820 struct list_head *e = rec->rec_active.next;
823 if (rec->rec_type == LNET_COOKIE_TYPE_EQ) {
824 lnet_eq_free(list_entry(e, struct lnet_eq, eq_list));
826 } else if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
827 lnet_md_free(list_entry(e, struct lnet_libmd, md_list));
829 } else { /* NB: Active MEs should be attached on portals */
836 /* Found alive MD/ME/EQ, user really should unlink/free
837 * all of them before finalize LNet, but if someone didn't,
838 * we have to recycle garbage for him */
839 CERROR("%d active elements on exit of %s container\n",
840 count, lnet_res_type2str(rec->rec_type));
843 if (rec->rec_lh_hash != NULL) {
844 LIBCFS_FREE(rec->rec_lh_hash,
845 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
846 rec->rec_lh_hash = NULL;
849 rec->rec_type = 0; /* mark it as finalized */
853 lnet_res_container_setup(struct lnet_res_container *rec, int cpt, int type)
858 LASSERT(rec->rec_type == 0);
860 rec->rec_type = type;
861 INIT_LIST_HEAD(&rec->rec_active);
863 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type;
865 /* Arbitrary choice of hash table size */
866 LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt,
867 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
868 if (rec->rec_lh_hash == NULL) {
873 for (i = 0; i < LNET_LH_HASH_SIZE; i++)
874 INIT_LIST_HEAD(&rec->rec_lh_hash[i]);
879 CERROR("Failed to setup %s resource container\n",
880 lnet_res_type2str(type));
881 lnet_res_container_cleanup(rec);
886 lnet_res_containers_destroy(struct lnet_res_container **recs)
888 struct lnet_res_container *rec;
891 cfs_percpt_for_each(rec, i, recs)
892 lnet_res_container_cleanup(rec);
894 cfs_percpt_free(recs);
897 static struct lnet_res_container **
898 lnet_res_containers_create(int type)
900 struct lnet_res_container **recs;
901 struct lnet_res_container *rec;
905 recs = cfs_percpt_alloc(lnet_cpt_table(), sizeof(*rec));
907 CERROR("Failed to allocate %s resource containers\n",
908 lnet_res_type2str(type));
912 cfs_percpt_for_each(rec, i, recs) {
913 rc = lnet_res_container_setup(rec, i, type);
915 lnet_res_containers_destroy(recs);
923 struct lnet_libhandle *
924 lnet_res_lh_lookup(struct lnet_res_container *rec, __u64 cookie)
926 /* ALWAYS called with lnet_res_lock held */
927 struct list_head *head;
928 struct lnet_libhandle *lh;
931 if ((cookie & LNET_COOKIE_MASK) != rec->rec_type)
934 hash = cookie >> (LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS);
935 head = &rec->rec_lh_hash[hash & LNET_LH_HASH_MASK];
937 list_for_each_entry(lh, head, lh_hash_chain) {
938 if (lh->lh_cookie == cookie)
946 lnet_res_lh_initialize(struct lnet_res_container *rec,
947 struct lnet_libhandle *lh)
949 /* ALWAYS called with lnet_res_lock held */
950 unsigned int ibits = LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS;
953 lh->lh_cookie = rec->rec_lh_cookie;
954 rec->rec_lh_cookie += 1 << ibits;
956 hash = (lh->lh_cookie >> ibits) & LNET_LH_HASH_MASK;
958 list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
961 static int lnet_unprepare(void);
964 lnet_prepare(lnet_pid_t requested_pid)
966 /* Prepare to bring up the network */
967 struct lnet_res_container **recs;
970 if (requested_pid == LNET_PID_ANY) {
971 /* Don't instantiate LNET just for me */
975 LASSERT(the_lnet.ln_refcount == 0);
977 the_lnet.ln_routing = 0;
979 LASSERT((requested_pid & LNET_PID_USERFLAG) == 0);
980 the_lnet.ln_pid = requested_pid;
982 INIT_LIST_HEAD(&the_lnet.ln_test_peers);
983 INIT_LIST_HEAD(&the_lnet.ln_remote_peer_ni_list);
984 INIT_LIST_HEAD(&the_lnet.ln_nets);
985 INIT_LIST_HEAD(&the_lnet.ln_routers);
986 INIT_LIST_HEAD(&the_lnet.ln_drop_rules);
987 INIT_LIST_HEAD(&the_lnet.ln_delay_rules);
988 INIT_LIST_HEAD(&the_lnet.ln_dc_request);
989 INIT_LIST_HEAD(&the_lnet.ln_dc_working);
990 INIT_LIST_HEAD(&the_lnet.ln_dc_expired);
991 INIT_LIST_HEAD(&the_lnet.ln_mt_localNIRecovq);
992 INIT_LIST_HEAD(&the_lnet.ln_mt_peerNIRecovq);
993 init_waitqueue_head(&the_lnet.ln_dc_waitq);
995 rc = lnet_descriptor_setup();
999 rc = lnet_create_remote_nets_table();
1004 * NB the interface cookie in wire handles guards against delayed
1005 * replies and ACKs appearing valid after reboot.
1007 the_lnet.ln_interface_cookie = ktime_get_real_ns();
1009 the_lnet.ln_counters = cfs_percpt_alloc(lnet_cpt_table(),
1010 sizeof(struct lnet_counters));
1011 if (the_lnet.ln_counters == NULL) {
1012 CERROR("Failed to allocate counters for LNet\n");
1017 rc = lnet_peer_tables_create();
1021 rc = lnet_msg_containers_create();
1025 rc = lnet_res_container_setup(&the_lnet.ln_eq_container, 0,
1026 LNET_COOKIE_TYPE_EQ);
1030 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_ME);
1036 the_lnet.ln_me_containers = recs;
1038 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD);
1044 the_lnet.ln_md_containers = recs;
1046 rc = lnet_portals_create();
1048 CERROR("Failed to create portals for LNet: %d\n", rc);
1060 lnet_unprepare (void)
1062 /* NB no LNET_LOCK since this is the last reference. All LND instances
1063 * have shut down already, so it is safe to unlink and free all
1064 * descriptors, even those that appear committed to a network op (eg MD
1065 * with non-zero pending count) */
1067 lnet_fail_nid(LNET_NID_ANY, 0);
1069 LASSERT(the_lnet.ln_refcount == 0);
1070 LASSERT(list_empty(&the_lnet.ln_test_peers));
1071 LASSERT(list_empty(&the_lnet.ln_nets));
1073 lnet_portals_destroy();
1075 if (the_lnet.ln_md_containers != NULL) {
1076 lnet_res_containers_destroy(the_lnet.ln_md_containers);
1077 the_lnet.ln_md_containers = NULL;
1080 if (the_lnet.ln_me_containers != NULL) {
1081 lnet_res_containers_destroy(the_lnet.ln_me_containers);
1082 the_lnet.ln_me_containers = NULL;
1085 lnet_res_container_cleanup(&the_lnet.ln_eq_container);
1087 lnet_msg_containers_destroy();
1089 lnet_rtrpools_free(0);
1091 if (the_lnet.ln_counters != NULL) {
1092 cfs_percpt_free(the_lnet.ln_counters);
1093 the_lnet.ln_counters = NULL;
1095 lnet_destroy_remote_nets_table();
1096 lnet_descriptor_cleanup();
1102 lnet_net2ni_locked(__u32 net_id, int cpt)
1105 struct lnet_net *net;
1107 LASSERT(cpt != LNET_LOCK_EX);
1109 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1110 if (net->net_id == net_id) {
1111 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
1121 lnet_net2ni_addref(__u32 net)
1126 ni = lnet_net2ni_locked(net, 0);
1128 lnet_ni_addref_locked(ni, 0);
1133 EXPORT_SYMBOL(lnet_net2ni_addref);
1136 lnet_get_net_locked(__u32 net_id)
1138 struct lnet_net *net;
1140 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1141 if (net->net_id == net_id)
1149 lnet_nid_cpt_hash(lnet_nid_t nid, unsigned int number)
1154 LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
1159 val = hash_long(key, LNET_CPT_BITS);
1160 /* NB: LNET_CP_NUMBER doesn't have to be PO2 */
1164 return (unsigned int)(key + val + (val >> 1)) % number;
1168 lnet_cpt_of_nid_locked(lnet_nid_t nid, struct lnet_ni *ni)
1170 struct lnet_net *net;
1172 /* must called with hold of lnet_net_lock */
1173 if (LNET_CPT_NUMBER == 1)
1174 return 0; /* the only one */
1177 * If NI is provided then use the CPT identified in the NI cpt
1178 * list if one exists. If one doesn't exist, then that NI is
1179 * associated with all CPTs and it follows that the net it belongs
1180 * to is implicitly associated with all CPTs, so just hash the nid
1184 if (ni->ni_cpts != NULL)
1185 return ni->ni_cpts[lnet_nid_cpt_hash(nid,
1188 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1191 /* no NI provided so look at the net */
1192 net = lnet_get_net_locked(LNET_NIDNET(nid));
1194 if (net != NULL && net->net_cpts != NULL) {
1195 return net->net_cpts[lnet_nid_cpt_hash(nid, net->net_ncpts)];
1198 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1202 lnet_cpt_of_nid(lnet_nid_t nid, struct lnet_ni *ni)
1207 if (LNET_CPT_NUMBER == 1)
1208 return 0; /* the only one */
1210 cpt = lnet_net_lock_current();
1212 cpt2 = lnet_cpt_of_nid_locked(nid, ni);
1214 lnet_net_unlock(cpt);
1218 EXPORT_SYMBOL(lnet_cpt_of_nid);
1221 lnet_islocalnet(__u32 net_id)
1223 struct lnet_net *net;
1227 cpt = lnet_net_lock_current();
1229 net = lnet_get_net_locked(net_id);
1231 local = net != NULL;
1233 lnet_net_unlock(cpt);
1239 lnet_nid2ni_locked(lnet_nid_t nid, int cpt)
1241 struct lnet_net *net;
1244 LASSERT(cpt != LNET_LOCK_EX);
1246 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1247 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1248 if (ni->ni_nid == nid)
1257 lnet_nid2ni_addref(lnet_nid_t nid)
1262 ni = lnet_nid2ni_locked(nid, 0);
1264 lnet_ni_addref_locked(ni, 0);
1269 EXPORT_SYMBOL(lnet_nid2ni_addref);
1272 lnet_islocalnid(lnet_nid_t nid)
1277 cpt = lnet_net_lock_current();
1278 ni = lnet_nid2ni_locked(nid, cpt);
1279 lnet_net_unlock(cpt);
1285 lnet_count_acceptor_nets(void)
1287 /* Return the # of NIs that need the acceptor. */
1289 struct lnet_net *net;
1292 cpt = lnet_net_lock_current();
1293 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1294 /* all socklnd type networks should have the acceptor
1296 if (net->net_lnd->lnd_accept != NULL)
1300 lnet_net_unlock(cpt);
1305 struct lnet_ping_buffer *
1306 lnet_ping_buffer_alloc(int nnis, gfp_t gfp)
1308 struct lnet_ping_buffer *pbuf;
1310 LIBCFS_ALLOC_GFP(pbuf, LNET_PING_BUFFER_SIZE(nnis), gfp);
1312 pbuf->pb_nnis = nnis;
1313 atomic_set(&pbuf->pb_refcnt, 1);
1320 lnet_ping_buffer_free(struct lnet_ping_buffer *pbuf)
1322 LASSERT(lnet_ping_buffer_numref(pbuf) == 0);
1323 LIBCFS_FREE(pbuf, LNET_PING_BUFFER_SIZE(pbuf->pb_nnis));
1326 static struct lnet_ping_buffer *
1327 lnet_ping_target_create(int nnis)
1329 struct lnet_ping_buffer *pbuf;
1331 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
1333 CERROR("Can't allocate ping source [%d]\n", nnis);
1337 pbuf->pb_info.pi_nnis = nnis;
1338 pbuf->pb_info.pi_pid = the_lnet.ln_pid;
1339 pbuf->pb_info.pi_magic = LNET_PROTO_PING_MAGIC;
1340 pbuf->pb_info.pi_features =
1341 LNET_PING_FEAT_NI_STATUS | LNET_PING_FEAT_MULTI_RAIL;
1347 lnet_get_net_ni_count_locked(struct lnet_net *net)
1352 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1359 lnet_get_net_ni_count_pre(struct lnet_net *net)
1364 list_for_each_entry(ni, &net->net_ni_added, ni_netlist)
1371 lnet_get_ni_count(void)
1374 struct lnet_net *net;
1379 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1380 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1390 lnet_ping_info_validate(struct lnet_ping_info *pinfo)
1394 if (pinfo->pi_magic != LNET_PROTO_PING_MAGIC)
1396 if (!(pinfo->pi_features & LNET_PING_FEAT_NI_STATUS))
1398 /* Loopback is guaranteed to be present */
1399 if (pinfo->pi_nnis < 1 || pinfo->pi_nnis > lnet_interfaces_max)
1401 if (LNET_NETTYP(LNET_NIDNET(LNET_PING_INFO_LONI(pinfo))) != LOLND)
1407 lnet_ping_target_destroy(void)
1409 struct lnet_net *net;
1412 lnet_net_lock(LNET_LOCK_EX);
1414 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1415 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1417 ni->ni_status = NULL;
1422 lnet_ping_buffer_decref(the_lnet.ln_ping_target);
1423 the_lnet.ln_ping_target = NULL;
1425 lnet_net_unlock(LNET_LOCK_EX);
1429 lnet_ping_target_event_handler(struct lnet_event *event)
1431 struct lnet_ping_buffer *pbuf = event->md.user_ptr;
1433 if (event->unlinked)
1434 lnet_ping_buffer_decref(pbuf);
1438 lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
1439 struct lnet_handle_md *ping_mdh,
1440 int ni_count, bool set_eq)
1442 struct lnet_process_id id = {
1443 .nid = LNET_NID_ANY,
1446 struct lnet_handle_me me_handle;
1447 struct lnet_md md = { NULL };
1451 rc = LNetEQAlloc(0, lnet_ping_target_event_handler,
1452 &the_lnet.ln_ping_target_eq);
1454 CERROR("Can't allocate ping buffer EQ: %d\n", rc);
1459 *ppbuf = lnet_ping_target_create(ni_count);
1460 if (*ppbuf == NULL) {
1465 /* Ping target ME/MD */
1466 rc = LNetMEAttach(LNET_RESERVED_PORTAL, id,
1467 LNET_PROTO_PING_MATCHBITS, 0,
1468 LNET_UNLINK, LNET_INS_AFTER,
1471 CERROR("Can't create ping target ME: %d\n", rc);
1472 goto fail_decref_ping_buffer;
1475 /* initialize md content */
1476 md.start = &(*ppbuf)->pb_info;
1477 md.length = LNET_PING_INFO_SIZE((*ppbuf)->pb_nnis);
1478 md.threshold = LNET_MD_THRESH_INF;
1480 md.options = LNET_MD_OP_GET | LNET_MD_TRUNCATE |
1481 LNET_MD_MANAGE_REMOTE;
1482 md.eq_handle = the_lnet.ln_ping_target_eq;
1483 md.user_ptr = *ppbuf;
1485 rc = LNetMDAttach(me_handle, md, LNET_RETAIN, ping_mdh);
1487 CERROR("Can't attach ping target MD: %d\n", rc);
1488 goto fail_unlink_ping_me;
1490 lnet_ping_buffer_addref(*ppbuf);
1494 fail_unlink_ping_me:
1495 rc2 = LNetMEUnlink(me_handle);
1497 fail_decref_ping_buffer:
1498 LASSERT(lnet_ping_buffer_numref(*ppbuf) == 1);
1499 lnet_ping_buffer_decref(*ppbuf);
1503 rc2 = LNetEQFree(the_lnet.ln_ping_target_eq);
1510 lnet_ping_md_unlink(struct lnet_ping_buffer *pbuf,
1511 struct lnet_handle_md *ping_mdh)
1513 sigset_t blocked = cfs_block_allsigs();
1515 LNetMDUnlink(*ping_mdh);
1516 LNetInvalidateMDHandle(ping_mdh);
1518 /* NB the MD could be busy; this just starts the unlink */
1519 while (lnet_ping_buffer_numref(pbuf) > 1) {
1520 CDEBUG(D_NET, "Still waiting for ping data MD to unlink\n");
1521 set_current_state(TASK_UNINTERRUPTIBLE);
1522 schedule_timeout(cfs_time_seconds(1));
1525 cfs_restore_sigs(blocked);
1529 lnet_ping_target_install_locked(struct lnet_ping_buffer *pbuf)
1532 struct lnet_net *net;
1533 struct lnet_ni_status *ns;
1538 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1539 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1540 LASSERT(i < pbuf->pb_nnis);
1542 ns = &pbuf->pb_info.pi_ni[i];
1544 ns->ns_nid = ni->ni_nid;
1547 ns->ns_status = (ni->ni_status != NULL) ?
1548 ni->ni_status->ns_status :
1557 * We (ab)use the ns_status of the loopback interface to
1558 * transmit the sequence number. The first interface listed
1559 * must be the loopback interface.
1561 rc = lnet_ping_info_validate(&pbuf->pb_info);
1563 LCONSOLE_EMERG("Invalid ping target: %d\n", rc);
1566 LNET_PING_BUFFER_SEQNO(pbuf) =
1567 atomic_inc_return(&the_lnet.ln_ping_target_seqno);
1571 lnet_ping_target_update(struct lnet_ping_buffer *pbuf,
1572 struct lnet_handle_md ping_mdh)
1574 struct lnet_ping_buffer *old_pbuf = NULL;
1575 struct lnet_handle_md old_ping_md;
1577 /* switch the NIs to point to the new ping info created */
1578 lnet_net_lock(LNET_LOCK_EX);
1580 if (!the_lnet.ln_routing)
1581 pbuf->pb_info.pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1582 if (!lnet_peer_discovery_disabled)
1583 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
1585 /* Ensure only known feature bits have been set. */
1586 LASSERT(pbuf->pb_info.pi_features & LNET_PING_FEAT_BITS);
1587 LASSERT(!(pbuf->pb_info.pi_features & ~LNET_PING_FEAT_BITS));
1589 lnet_ping_target_install_locked(pbuf);
1591 if (the_lnet.ln_ping_target) {
1592 old_pbuf = the_lnet.ln_ping_target;
1593 old_ping_md = the_lnet.ln_ping_target_md;
1595 the_lnet.ln_ping_target_md = ping_mdh;
1596 the_lnet.ln_ping_target = pbuf;
1598 lnet_net_unlock(LNET_LOCK_EX);
1601 /* unlink and free the old ping info */
1602 lnet_ping_md_unlink(old_pbuf, &old_ping_md);
1603 lnet_ping_buffer_decref(old_pbuf);
1606 lnet_push_update_to_peers(0);
1610 lnet_ping_target_fini(void)
1614 lnet_ping_md_unlink(the_lnet.ln_ping_target,
1615 &the_lnet.ln_ping_target_md);
1617 rc = LNetEQFree(the_lnet.ln_ping_target_eq);
1620 lnet_ping_target_destroy();
1623 /* Resize the push target. */
1624 int lnet_push_target_resize(void)
1626 struct lnet_process_id id = { LNET_NID_ANY, LNET_PID_ANY };
1627 struct lnet_md md = { NULL };
1628 struct lnet_handle_me meh;
1629 struct lnet_handle_md mdh;
1630 struct lnet_handle_md old_mdh;
1631 struct lnet_ping_buffer *pbuf;
1632 struct lnet_ping_buffer *old_pbuf;
1633 int nnis = the_lnet.ln_push_target_nnis;
1641 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
1647 rc = LNetMEAttach(LNET_RESERVED_PORTAL, id,
1648 LNET_PROTO_PING_MATCHBITS, 0,
1649 LNET_UNLINK, LNET_INS_AFTER,
1652 CERROR("Can't create push target ME: %d\n", rc);
1653 goto fail_decref_pbuf;
1656 /* initialize md content */
1657 md.start = &pbuf->pb_info;
1658 md.length = LNET_PING_INFO_SIZE(nnis);
1659 md.threshold = LNET_MD_THRESH_INF;
1661 md.options = LNET_MD_OP_PUT | LNET_MD_TRUNCATE |
1662 LNET_MD_MANAGE_REMOTE;
1664 md.eq_handle = the_lnet.ln_push_target_eq;
1666 rc = LNetMDAttach(meh, md, LNET_RETAIN, &mdh);
1668 CERROR("Can't attach push MD: %d\n", rc);
1669 goto fail_unlink_meh;
1671 lnet_ping_buffer_addref(pbuf);
1673 lnet_net_lock(LNET_LOCK_EX);
1674 old_pbuf = the_lnet.ln_push_target;
1675 old_mdh = the_lnet.ln_push_target_md;
1676 the_lnet.ln_push_target = pbuf;
1677 the_lnet.ln_push_target_md = mdh;
1678 lnet_net_unlock(LNET_LOCK_EX);
1681 LNetMDUnlink(old_mdh);
1682 lnet_ping_buffer_decref(old_pbuf);
1685 if (nnis < the_lnet.ln_push_target_nnis)
1688 CDEBUG(D_NET, "nnis %d success\n", nnis);
1695 lnet_ping_buffer_decref(pbuf);
1697 CDEBUG(D_NET, "nnis %d error %d\n", nnis, rc);
1701 static void lnet_push_target_event_handler(struct lnet_event *ev)
1703 struct lnet_ping_buffer *pbuf = ev->md.user_ptr;
1705 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
1706 lnet_swap_pinginfo(pbuf);
1708 lnet_peer_push_event(ev);
1710 lnet_ping_buffer_decref(pbuf);
1713 /* Initialize the push target. */
1714 static int lnet_push_target_init(void)
1718 if (the_lnet.ln_push_target)
1721 rc = LNetEQAlloc(0, lnet_push_target_event_handler,
1722 &the_lnet.ln_push_target_eq);
1724 CERROR("Can't allocated push target EQ: %d\n", rc);
1728 /* Start at the required minimum, we'll enlarge if required. */
1729 the_lnet.ln_push_target_nnis = LNET_INTERFACES_MIN;
1731 rc = lnet_push_target_resize();
1734 LNetEQFree(the_lnet.ln_push_target_eq);
1735 LNetInvalidateEQHandle(&the_lnet.ln_push_target_eq);
1741 /* Clean up the push target. */
1742 static void lnet_push_target_fini(void)
1744 if (!the_lnet.ln_push_target)
1747 /* Unlink and invalidate to prevent new references. */
1748 LNetMDUnlink(the_lnet.ln_push_target_md);
1749 LNetInvalidateMDHandle(&the_lnet.ln_push_target_md);
1751 /* Wait for the unlink to complete. */
1752 while (lnet_ping_buffer_numref(the_lnet.ln_push_target) > 1) {
1753 CDEBUG(D_NET, "Still waiting for ping data MD to unlink\n");
1754 set_current_state(TASK_UNINTERRUPTIBLE);
1755 schedule_timeout(cfs_time_seconds(1));
1758 lnet_ping_buffer_decref(the_lnet.ln_push_target);
1759 the_lnet.ln_push_target = NULL;
1760 the_lnet.ln_push_target_nnis = 0;
1762 LNetEQFree(the_lnet.ln_push_target_eq);
1763 LNetInvalidateEQHandle(&the_lnet.ln_push_target_eq);
1767 lnet_ni_tq_credits(struct lnet_ni *ni)
1771 LASSERT(ni->ni_ncpts >= 1);
1773 if (ni->ni_ncpts == 1)
1774 return ni->ni_net->net_tunables.lct_max_tx_credits;
1776 credits = ni->ni_net->net_tunables.lct_max_tx_credits / ni->ni_ncpts;
1777 credits = max(credits, 8 * ni->ni_net->net_tunables.lct_peer_tx_credits);
1778 credits = min(credits, ni->ni_net->net_tunables.lct_max_tx_credits);
1784 lnet_ni_unlink_locked(struct lnet_ni *ni)
1786 /* move it to zombie list and nobody can find it anymore */
1787 LASSERT(!list_empty(&ni->ni_netlist));
1788 list_move(&ni->ni_netlist, &ni->ni_net->net_ni_zombie);
1789 lnet_ni_decref_locked(ni, 0);
1793 lnet_clear_zombies_nis_locked(struct lnet_net *net)
1798 struct list_head *zombie_list = &net->net_ni_zombie;
1801 * Now wait for the NIs I just nuked to show up on the zombie
1802 * list and shut them down in guaranteed thread context
1805 while (!list_empty(zombie_list)) {
1809 ni = list_entry(zombie_list->next,
1810 struct lnet_ni, ni_netlist);
1811 list_del_init(&ni->ni_netlist);
1812 /* the ni should be in deleting state. If it's not it's
1814 LASSERT(ni->ni_state & LNET_NI_STATE_DELETING);
1815 cfs_percpt_for_each(ref, j, ni->ni_refs) {
1818 /* still busy, add it back to zombie list */
1819 list_add(&ni->ni_netlist, zombie_list);
1823 if (!list_empty(&ni->ni_netlist)) {
1824 lnet_net_unlock(LNET_LOCK_EX);
1826 if ((i & (-i)) == i) {
1828 "Waiting for zombie LNI %s\n",
1829 libcfs_nid2str(ni->ni_nid));
1831 set_current_state(TASK_UNINTERRUPTIBLE);
1832 schedule_timeout(cfs_time_seconds(1));
1833 lnet_net_lock(LNET_LOCK_EX);
1837 lnet_net_unlock(LNET_LOCK_EX);
1839 islo = ni->ni_net->net_lnd->lnd_type == LOLND;
1841 LASSERT(!in_interrupt());
1842 (net->net_lnd->lnd_shutdown)(ni);
1845 CDEBUG(D_LNI, "Removed LNI %s\n",
1846 libcfs_nid2str(ni->ni_nid));
1850 lnet_net_lock(LNET_LOCK_EX);
1854 /* shutdown down the NI and release refcount */
1856 lnet_shutdown_lndni(struct lnet_ni *ni)
1859 struct lnet_net *net = ni->ni_net;
1861 lnet_net_lock(LNET_LOCK_EX);
1863 ni->ni_state |= LNET_NI_STATE_DELETING;
1864 ni->ni_state &= ~LNET_NI_STATE_ACTIVE;
1866 lnet_ni_unlink_locked(ni);
1867 lnet_incr_dlc_seq();
1868 lnet_net_unlock(LNET_LOCK_EX);
1870 /* clear messages for this NI on the lazy portal */
1871 for (i = 0; i < the_lnet.ln_nportals; i++)
1872 lnet_clear_lazy_portal(ni, i, "Shutting down NI");
1874 lnet_net_lock(LNET_LOCK_EX);
1875 lnet_clear_zombies_nis_locked(net);
1876 lnet_net_unlock(LNET_LOCK_EX);
1880 lnet_shutdown_lndnet(struct lnet_net *net)
1884 lnet_net_lock(LNET_LOCK_EX);
1886 net->net_state = LNET_NET_STATE_DELETING;
1888 list_del_init(&net->net_list);
1890 while (!list_empty(&net->net_ni_list)) {
1891 ni = list_entry(net->net_ni_list.next,
1892 struct lnet_ni, ni_netlist);
1893 lnet_net_unlock(LNET_LOCK_EX);
1894 lnet_shutdown_lndni(ni);
1895 lnet_net_lock(LNET_LOCK_EX);
1898 lnet_net_unlock(LNET_LOCK_EX);
1900 /* Do peer table cleanup for this net */
1901 lnet_peer_tables_cleanup(net);
1903 lnet_net_lock(LNET_LOCK_EX);
1905 * decrement ref count on lnd only when the entire network goes
1908 net->net_lnd->lnd_refcount--;
1910 lnet_net_unlock(LNET_LOCK_EX);
1916 lnet_shutdown_lndnets(void)
1918 struct lnet_net *net;
1919 struct list_head resend;
1920 struct lnet_msg *msg, *tmp;
1922 INIT_LIST_HEAD(&resend);
1924 /* NB called holding the global mutex */
1926 /* All quiet on the API front */
1927 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
1928 LASSERT(the_lnet.ln_refcount == 0);
1930 lnet_net_lock(LNET_LOCK_EX);
1931 the_lnet.ln_state = LNET_STATE_STOPPING;
1933 while (!list_empty(&the_lnet.ln_nets)) {
1935 * move the nets to the zombie list to avoid them being
1936 * picked up for new work. LONET is also included in the
1937 * Nets that will be moved to the zombie list
1939 net = list_entry(the_lnet.ln_nets.next,
1940 struct lnet_net, net_list);
1941 list_move(&net->net_list, &the_lnet.ln_net_zombie);
1944 /* Drop the cached loopback Net. */
1945 if (the_lnet.ln_loni != NULL) {
1946 lnet_ni_decref_locked(the_lnet.ln_loni, 0);
1947 the_lnet.ln_loni = NULL;
1949 lnet_net_unlock(LNET_LOCK_EX);
1951 /* iterate through the net zombie list and delete each net */
1952 while (!list_empty(&the_lnet.ln_net_zombie)) {
1953 net = list_entry(the_lnet.ln_net_zombie.next,
1954 struct lnet_net, net_list);
1955 lnet_shutdown_lndnet(net);
1958 spin_lock(&the_lnet.ln_msg_resend_lock);
1959 list_splice(&the_lnet.ln_msg_resend, &resend);
1960 spin_unlock(&the_lnet.ln_msg_resend_lock);
1962 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
1963 list_del_init(&msg->msg_list);
1964 msg->msg_no_resend = true;
1965 lnet_finalize(msg, -ECANCELED);
1968 lnet_net_lock(LNET_LOCK_EX);
1969 the_lnet.ln_state = LNET_STATE_SHUTDOWN;
1970 lnet_net_unlock(LNET_LOCK_EX);
1974 lnet_startup_lndni(struct lnet_ni *ni, struct lnet_lnd_tunables *tun)
1977 struct lnet_tx_queue *tq;
1979 struct lnet_net *net = ni->ni_net;
1981 mutex_lock(&the_lnet.ln_lnd_mutex);
1984 memcpy(&ni->ni_lnd_tunables, tun, sizeof(*tun));
1985 ni->ni_lnd_tunables_set = true;
1988 rc = (net->net_lnd->lnd_startup)(ni);
1990 mutex_unlock(&the_lnet.ln_lnd_mutex);
1993 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s\n",
1994 rc, libcfs_lnd2str(net->net_lnd->lnd_type));
1995 lnet_net_lock(LNET_LOCK_EX);
1996 net->net_lnd->lnd_refcount--;
1997 lnet_net_unlock(LNET_LOCK_EX);
2002 ni->ni_state |= LNET_NI_STATE_ACTIVE;
2003 ni->ni_state &= ~LNET_NI_STATE_INIT;
2006 /* We keep a reference on the loopback net through the loopback NI */
2007 if (net->net_lnd->lnd_type == LOLND) {
2009 LASSERT(the_lnet.ln_loni == NULL);
2010 the_lnet.ln_loni = ni;
2011 ni->ni_net->net_tunables.lct_peer_tx_credits = 0;
2012 ni->ni_net->net_tunables.lct_peer_rtr_credits = 0;
2013 ni->ni_net->net_tunables.lct_max_tx_credits = 0;
2014 ni->ni_net->net_tunables.lct_peer_timeout = 0;
2018 if (ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ||
2019 ni->ni_net->net_tunables.lct_max_tx_credits == 0) {
2020 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
2021 libcfs_lnd2str(net->net_lnd->lnd_type),
2022 ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ?
2024 /* shutdown the NI since if we get here then it must've already
2027 lnet_shutdown_lndni(ni);
2031 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
2032 tq->tq_credits_min =
2033 tq->tq_credits_max =
2034 tq->tq_credits = lnet_ni_tq_credits(ni);
2037 atomic_set(&ni->ni_tx_credits,
2038 lnet_ni_tq_credits(ni) * ni->ni_ncpts);
2039 atomic_set(&ni->ni_healthv, LNET_MAX_HEALTH_VALUE);
2041 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d/%d]\n",
2042 libcfs_nid2str(ni->ni_nid),
2043 ni->ni_net->net_tunables.lct_peer_tx_credits,
2044 lnet_ni_tq_credits(ni) * LNET_CPT_NUMBER,
2045 ni->ni_net->net_tunables.lct_peer_rtr_credits,
2046 ni->ni_net->net_tunables.lct_peer_timeout);
2055 lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
2058 struct lnet_net *net_l = NULL;
2059 struct list_head local_ni_list;
2063 struct lnet_lnd *lnd;
2065 net->net_tunables.lct_peer_timeout;
2067 net->net_tunables.lct_max_tx_credits;
2068 int peerrtrcredits =
2069 net->net_tunables.lct_peer_rtr_credits;
2071 INIT_LIST_HEAD(&local_ni_list);
2074 * make sure that this net is unique. If it isn't then
2075 * we are adding interfaces to an already existing network, and
2076 * 'net' is just a convenient way to pass in the list.
2077 * if it is unique we need to find the LND and load it if
2080 if (lnet_net_unique(net->net_id, &the_lnet.ln_nets, &net_l)) {
2081 lnd_type = LNET_NETTYP(net->net_id);
2083 mutex_lock(&the_lnet.ln_lnd_mutex);
2084 lnd = lnet_find_lnd_by_type(lnd_type);
2087 mutex_unlock(&the_lnet.ln_lnd_mutex);
2088 rc = request_module("%s", libcfs_lnd2modname(lnd_type));
2089 mutex_lock(&the_lnet.ln_lnd_mutex);
2091 lnd = lnet_find_lnd_by_type(lnd_type);
2093 mutex_unlock(&the_lnet.ln_lnd_mutex);
2094 CERROR("Can't load LND %s, module %s, rc=%d\n",
2095 libcfs_lnd2str(lnd_type),
2096 libcfs_lnd2modname(lnd_type), rc);
2097 #ifndef HAVE_MODULE_LOADING_SUPPORT
2098 LCONSOLE_ERROR_MSG(0x104, "Your kernel must be "
2099 "compiled with kernel module "
2100 "loading support.");
2107 lnet_net_lock(LNET_LOCK_EX);
2108 lnd->lnd_refcount++;
2109 lnet_net_unlock(LNET_LOCK_EX);
2113 mutex_unlock(&the_lnet.ln_lnd_mutex);
2119 * net_l: if the network being added is unique then net_l
2120 * will point to that network
2121 * if the network being added is not unique then
2122 * net_l points to the existing network.
2124 * When we enter the loop below, we'll pick NIs off he
2125 * network beign added and start them up, then add them to
2126 * a local ni list. Once we've successfully started all
2127 * the NIs then we join the local NI list (of started up
2128 * networks) with the net_l->net_ni_list, which should
2129 * point to the correct network to add the new ni list to
2131 * If any of the new NIs fail to start up, then we want to
2132 * iterate through the local ni list, which should include
2133 * any NIs which were successfully started up, and shut
2136 * After than we want to delete the network being added,
2137 * to avoid a memory leak.
2141 * When a network uses TCP bonding then all its interfaces
2142 * must be specified when the network is first defined: the
2143 * TCP bonding code doesn't allow for interfaces to be added
2146 if (net_l != net && net_l != NULL && use_tcp_bonding &&
2147 LNET_NETTYP(net_l->net_id) == SOCKLND) {
2152 while (!list_empty(&net->net_ni_added)) {
2153 ni = list_entry(net->net_ni_added.next, struct lnet_ni,
2155 list_del_init(&ni->ni_netlist);
2157 /* make sure that the the NI we're about to start
2158 * up is actually unique. if it's not fail. */
2159 if (!lnet_ni_unique_net(&net_l->net_ni_list,
2160 ni->ni_interfaces[0])) {
2165 /* adjust the pointer the parent network, just in case it
2166 * the net is a duplicate */
2169 rc = lnet_startup_lndni(ni, tun);
2171 LASSERT(ni->ni_net->net_tunables.lct_peer_timeout <= 0 ||
2172 ni->ni_net->net_lnd->lnd_query != NULL);
2178 list_add_tail(&ni->ni_netlist, &local_ni_list);
2183 lnet_net_lock(LNET_LOCK_EX);
2184 list_splice_tail(&local_ni_list, &net_l->net_ni_list);
2185 lnet_incr_dlc_seq();
2186 lnet_net_unlock(LNET_LOCK_EX);
2188 /* if the network is not unique then we don't want to keep
2189 * it around after we're done. Free it. Otherwise add that
2190 * net to the global the_lnet.ln_nets */
2191 if (net_l != net && net_l != NULL) {
2193 * TODO - note. currently the tunables can not be updated
2198 net->net_state = LNET_NET_STATE_ACTIVE;
2200 * restore tunables after it has been overwitten by the
2203 if (peer_timeout != -1)
2204 net->net_tunables.lct_peer_timeout = peer_timeout;
2205 if (maxtxcredits != -1)
2206 net->net_tunables.lct_max_tx_credits = maxtxcredits;
2207 if (peerrtrcredits != -1)
2208 net->net_tunables.lct_peer_rtr_credits = peerrtrcredits;
2210 lnet_net_lock(LNET_LOCK_EX);
2211 list_add_tail(&net->net_list, &the_lnet.ln_nets);
2212 lnet_net_unlock(LNET_LOCK_EX);
2219 * shutdown the new NIs that are being started up
2220 * free the NET being started
2222 while (!list_empty(&local_ni_list)) {
2223 ni = list_entry(local_ni_list.next, struct lnet_ni,
2226 lnet_shutdown_lndni(ni);
2236 lnet_startup_lndnets(struct list_head *netlist)
2238 struct lnet_net *net;
2243 * Change to running state before bringing up the LNDs. This
2244 * allows lnet_shutdown_lndnets() to assert that we've passed
2247 lnet_net_lock(LNET_LOCK_EX);
2248 the_lnet.ln_state = LNET_STATE_RUNNING;
2249 lnet_net_unlock(LNET_LOCK_EX);
2251 while (!list_empty(netlist)) {
2252 net = list_entry(netlist->next, struct lnet_net, net_list);
2253 list_del_init(&net->net_list);
2255 rc = lnet_startup_lndnet(net, NULL);
2265 lnet_shutdown_lndnets();
2271 * Initialize LNet library.
2273 * Automatically called at module loading time. Caller has to call
2274 * lnet_lib_exit() after a call to lnet_lib_init(), if and only if the
2275 * latter returned 0. It must be called exactly once.
2277 * \retval 0 on success
2278 * \retval -ve on failures.
2280 int lnet_lib_init(void)
2284 lnet_assert_wire_constants();
2286 /* refer to global cfs_cpt_table for now */
2287 the_lnet.ln_cpt_table = cfs_cpt_table;
2288 the_lnet.ln_cpt_number = cfs_cpt_number(cfs_cpt_table);
2290 LASSERT(the_lnet.ln_cpt_number > 0);
2291 if (the_lnet.ln_cpt_number > LNET_CPT_MAX) {
2292 /* we are under risk of consuming all lh_cookie */
2293 CERROR("Can't have %d CPTs for LNet (max allowed is %d), "
2294 "please change setting of CPT-table and retry\n",
2295 the_lnet.ln_cpt_number, LNET_CPT_MAX);
2299 while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number)
2300 the_lnet.ln_cpt_bits++;
2302 rc = lnet_create_locks();
2304 CERROR("Can't create LNet global locks: %d\n", rc);
2308 the_lnet.ln_refcount = 0;
2309 LNetInvalidateEQHandle(&the_lnet.ln_rc_eqh);
2310 INIT_LIST_HEAD(&the_lnet.ln_lnds);
2311 INIT_LIST_HEAD(&the_lnet.ln_net_zombie);
2312 INIT_LIST_HEAD(&the_lnet.ln_rcd_zombie);
2313 INIT_LIST_HEAD(&the_lnet.ln_msg_resend);
2314 INIT_LIST_HEAD(&the_lnet.ln_rcd_deathrow);
2316 /* The hash table size is the number of bits it takes to express the set
2317 * ln_num_routes, minus 1 (better to under estimate than over so we
2318 * don't waste memory). */
2319 if (rnet_htable_size <= 0)
2320 rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
2321 else if (rnet_htable_size > LNET_REMOTE_NETS_HASH_MAX)
2322 rnet_htable_size = LNET_REMOTE_NETS_HASH_MAX;
2323 the_lnet.ln_remote_nets_hbits = max_t(int, 1,
2324 order_base_2(rnet_htable_size) - 1);
2326 /* All LNDs apart from the LOLND are in separate modules. They
2327 * register themselves when their module loads, and unregister
2328 * themselves when their module is unloaded. */
2329 lnet_register_lnd(&the_lolnd);
2334 * Finalize LNet library.
2336 * \pre lnet_lib_init() called with success.
2337 * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls.
2339 void lnet_lib_exit(void)
2341 LASSERT(the_lnet.ln_refcount == 0);
2343 while (!list_empty(&the_lnet.ln_lnds))
2344 lnet_unregister_lnd(list_entry(the_lnet.ln_lnds.next,
2345 struct lnet_lnd, lnd_list));
2346 lnet_destroy_locks();
2350 * Set LNet PID and start LNet interfaces, routing, and forwarding.
2352 * Users must call this function at least once before any other functions.
2353 * For each successful call there must be a corresponding call to
2354 * LNetNIFini(). For subsequent calls to LNetNIInit(), \a requested_pid is
2357 * The PID used by LNet may be different from the one requested.
2360 * \param requested_pid PID requested by the caller.
2362 * \return >= 0 on success, and < 0 error code on failures.
2365 LNetNIInit(lnet_pid_t requested_pid)
2367 int im_a_router = 0;
2370 struct lnet_ping_buffer *pbuf;
2371 struct lnet_handle_md ping_mdh;
2372 struct list_head net_head;
2373 struct lnet_net *net;
2375 INIT_LIST_HEAD(&net_head);
2377 mutex_lock(&the_lnet.ln_api_mutex);
2379 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
2381 if (the_lnet.ln_refcount > 0) {
2382 rc = the_lnet.ln_refcount++;
2383 mutex_unlock(&the_lnet.ln_api_mutex);
2387 rc = lnet_prepare(requested_pid);
2389 mutex_unlock(&the_lnet.ln_api_mutex);
2393 /* create a network for Loopback network */
2394 net = lnet_net_alloc(LNET_MKNET(LOLND, 0), &net_head);
2397 goto err_empty_list;
2400 /* Add in the loopback NI */
2401 if (lnet_ni_alloc(net, NULL, NULL) == NULL) {
2403 goto err_empty_list;
2406 /* If LNet is being initialized via DLC it is possible
2407 * that the user requests not to load module parameters (ones which
2408 * are supported by DLC) on initialization. Therefore, make sure not
2409 * to load networks, routes and forwarding from module parameters
2410 * in this case. On cleanup in case of failure only clean up
2411 * routes if it has been loaded */
2412 if (!the_lnet.ln_nis_from_mod_params) {
2413 rc = lnet_parse_networks(&net_head, lnet_get_networks(),
2416 goto err_empty_list;
2419 ni_count = lnet_startup_lndnets(&net_head);
2422 goto err_empty_list;
2425 if (!the_lnet.ln_nis_from_mod_params) {
2426 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
2428 goto err_shutdown_lndnis;
2430 rc = lnet_check_routes();
2432 goto err_destroy_routes;
2434 rc = lnet_rtrpools_alloc(im_a_router);
2436 goto err_destroy_routes;
2439 rc = lnet_acceptor_start();
2441 goto err_destroy_routes;
2443 the_lnet.ln_refcount = 1;
2444 /* Now I may use my own API functions... */
2446 rc = lnet_ping_target_setup(&pbuf, &ping_mdh, ni_count, true);
2448 goto err_acceptor_stop;
2450 lnet_ping_target_update(pbuf, ping_mdh);
2452 rc = lnet_monitor_thr_start();
2456 rc = lnet_push_target_init();
2458 goto err_stop_monitor_thr;
2460 rc = lnet_peer_discovery_start();
2462 goto err_destroy_push_target;
2465 lnet_router_debugfs_init();
2467 mutex_unlock(&the_lnet.ln_api_mutex);
2471 err_destroy_push_target:
2472 lnet_push_target_fini();
2473 err_stop_monitor_thr:
2474 lnet_monitor_thr_stop();
2476 lnet_ping_target_fini();
2478 the_lnet.ln_refcount = 0;
2479 lnet_acceptor_stop();
2481 if (!the_lnet.ln_nis_from_mod_params)
2482 lnet_destroy_routes();
2483 err_shutdown_lndnis:
2484 lnet_shutdown_lndnets();
2488 mutex_unlock(&the_lnet.ln_api_mutex);
2489 while (!list_empty(&net_head)) {
2490 struct lnet_net *net;
2492 net = list_entry(net_head.next, struct lnet_net, net_list);
2493 list_del_init(&net->net_list);
2498 EXPORT_SYMBOL(LNetNIInit);
2501 * Stop LNet interfaces, routing, and forwarding.
2503 * Users must call this function once for each successful call to LNetNIInit().
2504 * Once the LNetNIFini() operation has been started, the results of pending
2505 * API operations are undefined.
2507 * \return always 0 for current implementation.
2512 mutex_lock(&the_lnet.ln_api_mutex);
2514 LASSERT(the_lnet.ln_refcount > 0);
2516 if (the_lnet.ln_refcount != 1) {
2517 the_lnet.ln_refcount--;
2519 LASSERT(!the_lnet.ln_niinit_self);
2523 lnet_router_debugfs_init();
2524 lnet_peer_discovery_stop();
2525 lnet_push_target_fini();
2526 lnet_monitor_thr_stop();
2527 lnet_ping_target_fini();
2529 /* Teardown fns that use my own API functions BEFORE here */
2530 the_lnet.ln_refcount = 0;
2532 lnet_acceptor_stop();
2533 lnet_destroy_routes();
2534 lnet_shutdown_lndnets();
2538 mutex_unlock(&the_lnet.ln_api_mutex);
2541 EXPORT_SYMBOL(LNetNIFini);
2544 * Grabs the ni data from the ni structure and fills the out
2547 * \param[in] ni network interface structure
2548 * \param[out] cfg_ni NI config information
2549 * \param[out] tun network and LND tunables
2552 lnet_fill_ni_info(struct lnet_ni *ni, struct lnet_ioctl_config_ni *cfg_ni,
2553 struct lnet_ioctl_config_lnd_tunables *tun,
2554 struct lnet_ioctl_element_stats *stats,
2557 size_t min_size = 0;
2560 if (!ni || !cfg_ni || !tun)
2563 if (ni->ni_interfaces[0] != NULL) {
2564 for (i = 0; i < ARRAY_SIZE(ni->ni_interfaces); i++) {
2565 if (ni->ni_interfaces[i] != NULL) {
2566 strncpy(cfg_ni->lic_ni_intf[i],
2567 ni->ni_interfaces[i],
2568 sizeof(cfg_ni->lic_ni_intf[i]));
2573 cfg_ni->lic_nid = ni->ni_nid;
2574 if (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND)
2575 cfg_ni->lic_status = LNET_NI_STATUS_UP;
2577 cfg_ni->lic_status = ni->ni_status->ns_status;
2578 cfg_ni->lic_tcp_bonding = use_tcp_bonding;
2579 cfg_ni->lic_dev_cpt = ni->ni_dev_cpt;
2581 memcpy(&tun->lt_cmn, &ni->ni_net->net_tunables, sizeof(tun->lt_cmn));
2584 stats->iel_send_count = lnet_sum_stats(&ni->ni_stats,
2585 LNET_STATS_TYPE_SEND);
2586 stats->iel_recv_count = lnet_sum_stats(&ni->ni_stats,
2587 LNET_STATS_TYPE_RECV);
2588 stats->iel_drop_count = lnet_sum_stats(&ni->ni_stats,
2589 LNET_STATS_TYPE_DROP);
2593 * tun->lt_tun will always be present, but in order to be
2594 * backwards compatible, we need to deal with the cases when
2595 * tun->lt_tun is smaller than what the kernel has, because it
2596 * comes from an older version of a userspace program, then we'll
2597 * need to copy as much information as we have available space.
2599 min_size = tun_size - sizeof(tun->lt_cmn);
2600 memcpy(&tun->lt_tun, &ni->ni_lnd_tunables, min_size);
2602 /* copy over the cpts */
2603 if (ni->ni_ncpts == LNET_CPT_NUMBER &&
2604 ni->ni_cpts == NULL) {
2605 for (i = 0; i < ni->ni_ncpts; i++)
2606 cfg_ni->lic_cpts[i] = i;
2609 ni->ni_cpts != NULL && i < ni->ni_ncpts &&
2610 i < LNET_MAX_SHOW_NUM_CPT;
2612 cfg_ni->lic_cpts[i] = ni->ni_cpts[i];
2614 cfg_ni->lic_ncpts = ni->ni_ncpts;
2618 * NOTE: This is a legacy function left in the code to be backwards
2619 * compatible with older userspace programs. It should eventually be
2622 * Grabs the ni data from the ni structure and fills the out
2625 * \param[in] ni network interface structure
2626 * \param[out] config config information
2629 lnet_fill_ni_info_legacy(struct lnet_ni *ni,
2630 struct lnet_ioctl_config_data *config)
2632 struct lnet_ioctl_net_config *net_config;
2633 struct lnet_ioctl_config_lnd_tunables *lnd_cfg = NULL;
2634 size_t min_size, tunable_size = 0;
2640 net_config = (struct lnet_ioctl_net_config *) config->cfg_bulk;
2644 BUILD_BUG_ON(ARRAY_SIZE(ni->ni_interfaces) !=
2645 ARRAY_SIZE(net_config->ni_interfaces));
2647 for (i = 0; i < ARRAY_SIZE(ni->ni_interfaces); i++) {
2648 if (!ni->ni_interfaces[i])
2651 strncpy(net_config->ni_interfaces[i],
2652 ni->ni_interfaces[i],
2653 sizeof(net_config->ni_interfaces[i]));
2656 config->cfg_nid = ni->ni_nid;
2657 config->cfg_config_u.cfg_net.net_peer_timeout =
2658 ni->ni_net->net_tunables.lct_peer_timeout;
2659 config->cfg_config_u.cfg_net.net_max_tx_credits =
2660 ni->ni_net->net_tunables.lct_max_tx_credits;
2661 config->cfg_config_u.cfg_net.net_peer_tx_credits =
2662 ni->ni_net->net_tunables.lct_peer_tx_credits;
2663 config->cfg_config_u.cfg_net.net_peer_rtr_credits =
2664 ni->ni_net->net_tunables.lct_peer_rtr_credits;
2666 if (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND)
2667 net_config->ni_status = LNET_NI_STATUS_UP;
2669 net_config->ni_status = ni->ni_status->ns_status;
2672 int num_cpts = min(ni->ni_ncpts, LNET_MAX_SHOW_NUM_CPT);
2674 for (i = 0; i < num_cpts; i++)
2675 net_config->ni_cpts[i] = ni->ni_cpts[i];
2677 config->cfg_ncpts = num_cpts;
2681 * See if user land tools sent in a newer and larger version
2682 * of struct lnet_tunables than what the kernel uses.
2684 min_size = sizeof(*config) + sizeof(*net_config);
2686 if (config->cfg_hdr.ioc_len > min_size)
2687 tunable_size = config->cfg_hdr.ioc_len - min_size;
2689 /* Don't copy too much data to user space */
2690 min_size = min(tunable_size, sizeof(ni->ni_lnd_tunables));
2691 lnd_cfg = (struct lnet_ioctl_config_lnd_tunables *)net_config->cfg_bulk;
2693 if (lnd_cfg && min_size) {
2694 memcpy(&lnd_cfg->lt_tun, &ni->ni_lnd_tunables, min_size);
2695 config->cfg_config_u.cfg_net.net_interface_count = 1;
2697 /* Tell user land that kernel side has less data */
2698 if (tunable_size > sizeof(ni->ni_lnd_tunables)) {
2699 min_size = tunable_size - sizeof(ni->ni_lnd_tunables);
2700 config->cfg_hdr.ioc_len -= min_size;
2706 lnet_get_ni_idx_locked(int idx)
2709 struct lnet_net *net;
2711 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
2712 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
2722 lnet_get_next_ni_locked(struct lnet_net *mynet, struct lnet_ni *prev)
2725 struct lnet_net *net = mynet;
2728 * It is possible that the net has been cleaned out while there is
2729 * a message being sent. This function accessed the net without
2730 * checking if the list is empty
2734 net = list_entry(the_lnet.ln_nets.next, struct lnet_net,
2736 if (list_empty(&net->net_ni_list))
2738 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
2744 if (prev->ni_netlist.next == &prev->ni_net->net_ni_list) {
2745 /* if you reached the end of the ni list and the net is
2746 * specified, then there are no more nis in that net */
2750 /* we reached the end of this net ni list. move to the
2752 if (prev->ni_net->net_list.next == &the_lnet.ln_nets)
2753 /* no more nets and no more NIs. */
2756 /* get the next net */
2757 net = list_entry(prev->ni_net->net_list.next, struct lnet_net,
2759 if (list_empty(&net->net_ni_list))
2761 /* get the ni on it */
2762 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
2768 if (list_empty(&prev->ni_netlist))
2771 /* there are more nis left */
2772 ni = list_entry(prev->ni_netlist.next, struct lnet_ni, ni_netlist);
2778 lnet_get_net_config(struct lnet_ioctl_config_data *config)
2783 int idx = config->cfg_count;
2785 cpt = lnet_net_lock_current();
2787 ni = lnet_get_ni_idx_locked(idx);
2792 lnet_fill_ni_info_legacy(ni, config);
2796 lnet_net_unlock(cpt);
2801 lnet_get_ni_config(struct lnet_ioctl_config_ni *cfg_ni,
2802 struct lnet_ioctl_config_lnd_tunables *tun,
2803 struct lnet_ioctl_element_stats *stats,
2810 if (!cfg_ni || !tun || !stats)
2813 cpt = lnet_net_lock_current();
2815 ni = lnet_get_ni_idx_locked(cfg_ni->lic_idx);
2820 lnet_fill_ni_info(ni, cfg_ni, tun, stats, tun_size);
2824 lnet_net_unlock(cpt);
2828 int lnet_get_ni_stats(struct lnet_ioctl_element_msg_stats *msg_stats)
2837 cpt = lnet_net_lock_current();
2839 ni = lnet_get_ni_idx_locked(msg_stats->im_idx);
2842 lnet_usr_translate_stats(msg_stats, &ni->ni_stats);
2846 lnet_net_unlock(cpt);
2851 static int lnet_add_net_common(struct lnet_net *net,
2852 struct lnet_ioctl_config_lnd_tunables *tun)
2855 struct lnet_ping_buffer *pbuf;
2856 struct lnet_handle_md ping_mdh;
2858 struct lnet_remotenet *rnet;
2860 int num_acceptor_nets;
2862 lnet_net_lock(LNET_LOCK_EX);
2863 rnet = lnet_find_rnet_locked(net->net_id);
2864 lnet_net_unlock(LNET_LOCK_EX);
2866 * make sure that the net added doesn't invalidate the current
2867 * configuration LNet is keeping
2870 CERROR("Adding net %s will invalidate routing configuration\n",
2871 libcfs_net2str(net->net_id));
2877 * make sure you calculate the correct number of slots in the ping
2878 * buffer. Since the ping info is a flattened list of all the NIs,
2879 * we should allocate enough slots to accomodate the number of NIs
2880 * which will be added.
2882 * since ni hasn't been configured yet, use
2883 * lnet_get_net_ni_count_pre() which checks the net_ni_added list
2885 net_ni_count = lnet_get_net_ni_count_pre(net);
2887 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
2888 net_ni_count + lnet_get_ni_count(),
2896 memcpy(&net->net_tunables,
2897 &tun->lt_cmn, sizeof(net->net_tunables));
2899 memset(&net->net_tunables, -1, sizeof(net->net_tunables));
2902 * before starting this network get a count of the current TCP
2903 * networks which require the acceptor thread running. If that
2904 * count is == 0 before we start up this network, then we'd want to
2905 * start up the acceptor thread after starting up this network
2907 num_acceptor_nets = lnet_count_acceptor_nets();
2909 net_id = net->net_id;
2911 rc = lnet_startup_lndnet(net,
2912 (tun) ? &tun->lt_tun : NULL);
2916 lnet_net_lock(LNET_LOCK_EX);
2917 net = lnet_get_net_locked(net_id);
2918 lnet_net_unlock(LNET_LOCK_EX);
2923 * Start the acceptor thread if this is the first network
2924 * being added that requires the thread.
2926 if (net->net_lnd->lnd_accept && num_acceptor_nets == 0) {
2927 rc = lnet_acceptor_start();
2929 /* shutdown the net that we just started */
2930 CERROR("Failed to start up acceptor thread\n");
2931 lnet_shutdown_lndnet(net);
2936 lnet_net_lock(LNET_LOCK_EX);
2937 lnet_peer_net_added(net);
2938 lnet_net_unlock(LNET_LOCK_EX);
2940 lnet_ping_target_update(pbuf, ping_mdh);
2945 lnet_ping_md_unlink(pbuf, &ping_mdh);
2946 lnet_ping_buffer_decref(pbuf);
2950 static int lnet_handle_legacy_ip2nets(char *ip2nets,
2951 struct lnet_ioctl_config_lnd_tunables *tun)
2953 struct lnet_net *net;
2956 struct list_head net_head;
2958 INIT_LIST_HEAD(&net_head);
2960 rc = lnet_parse_ip2nets(&nets, ip2nets);
2964 rc = lnet_parse_networks(&net_head, nets, use_tcp_bonding);
2968 mutex_lock(&the_lnet.ln_api_mutex);
2969 while (!list_empty(&net_head)) {
2970 net = list_entry(net_head.next, struct lnet_net, net_list);
2971 list_del_init(&net->net_list);
2972 rc = lnet_add_net_common(net, tun);
2978 mutex_unlock(&the_lnet.ln_api_mutex);
2980 while (!list_empty(&net_head)) {
2981 net = list_entry(net_head.next, struct lnet_net, net_list);
2982 list_del_init(&net->net_list);
2988 int lnet_dyn_add_ni(struct lnet_ioctl_config_ni *conf)
2990 struct lnet_net *net;
2992 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
2994 __u32 net_id, lnd_type;
2996 /* get the tunables if they are available */
2997 if (conf->lic_cfg_hdr.ioc_len >=
2998 sizeof(*conf) + sizeof(*tun))
2999 tun = (struct lnet_ioctl_config_lnd_tunables *)
3002 /* handle legacy ip2nets from DLC */
3003 if (conf->lic_legacy_ip2nets[0] != '\0')
3004 return lnet_handle_legacy_ip2nets(conf->lic_legacy_ip2nets,
3007 net_id = LNET_NIDNET(conf->lic_nid);
3008 lnd_type = LNET_NETTYP(net_id);
3010 if (!libcfs_isknown_lnd(lnd_type)) {
3011 CERROR("No valid net and lnd information provided\n");
3015 net = lnet_net_alloc(net_id, NULL);
3019 for (i = 0; i < conf->lic_ncpts; i++) {
3020 if (conf->lic_cpts[i] >= LNET_CPT_NUMBER)
3024 ni = lnet_ni_alloc_w_cpt_array(net, conf->lic_cpts, conf->lic_ncpts,
3025 conf->lic_ni_intf[0]);
3029 mutex_lock(&the_lnet.ln_api_mutex);
3031 rc = lnet_add_net_common(net, tun);
3033 mutex_unlock(&the_lnet.ln_api_mutex);
3038 int lnet_dyn_del_ni(struct lnet_ioctl_config_ni *conf)
3040 struct lnet_net *net;
3042 __u32 net_id = LNET_NIDNET(conf->lic_nid);
3043 struct lnet_ping_buffer *pbuf;
3044 struct lnet_handle_md ping_mdh;
3049 /* don't allow userspace to shutdown the LOLND */
3050 if (LNET_NETTYP(net_id) == LOLND)
3053 mutex_lock(&the_lnet.ln_api_mutex);
3057 net = lnet_get_net_locked(net_id);
3059 CERROR("net %s not found\n",
3060 libcfs_net2str(net_id));
3065 addr = LNET_NIDADDR(conf->lic_nid);
3067 /* remove the entire net */
3068 net_count = lnet_get_net_ni_count_locked(net);
3072 /* create and link a new ping info, before removing the old one */
3073 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3074 lnet_get_ni_count() - net_count,
3077 goto unlock_api_mutex;
3079 lnet_shutdown_lndnet(net);
3081 if (lnet_count_acceptor_nets() == 0)
3082 lnet_acceptor_stop();
3084 lnet_ping_target_update(pbuf, ping_mdh);
3086 goto unlock_api_mutex;
3089 ni = lnet_nid2ni_locked(conf->lic_nid, 0);
3091 CERROR("nid %s not found\n",
3092 libcfs_nid2str(conf->lic_nid));
3097 net_count = lnet_get_net_ni_count_locked(net);
3101 /* create and link a new ping info, before removing the old one */
3102 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3103 lnet_get_ni_count() - 1, false);
3105 goto unlock_api_mutex;
3107 lnet_shutdown_lndni(ni);
3109 if (lnet_count_acceptor_nets() == 0)
3110 lnet_acceptor_stop();
3112 lnet_ping_target_update(pbuf, ping_mdh);
3114 /* check if the net is empty and remove it if it is */
3116 lnet_shutdown_lndnet(net);
3118 goto unlock_api_mutex;
3123 mutex_unlock(&the_lnet.ln_api_mutex);
3129 * lnet_dyn_add_net and lnet_dyn_del_net are now deprecated.
3130 * They are only expected to be called for unique networks.
3131 * That can be as a result of older DLC library
3132 * calls. Multi-Rail DLC and beyond no longer uses these APIs.
3135 lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
3137 struct lnet_net *net;
3138 struct list_head net_head;
3140 struct lnet_ioctl_config_lnd_tunables tun;
3141 char *nets = conf->cfg_config_u.cfg_net.net_intf;
3143 INIT_LIST_HEAD(&net_head);
3145 /* Create a net/ni structures for the network string */
3146 rc = lnet_parse_networks(&net_head, nets, use_tcp_bonding);
3148 return rc == 0 ? -EINVAL : rc;
3150 mutex_lock(&the_lnet.ln_api_mutex);
3153 rc = -EINVAL; /* only add one network per call */
3154 goto out_unlock_clean;
3157 net = list_entry(net_head.next, struct lnet_net, net_list);
3158 list_del_init(&net->net_list);
3160 LASSERT(lnet_net_unique(net->net_id, &the_lnet.ln_nets, NULL));
3162 memset(&tun, 0, sizeof(tun));
3164 tun.lt_cmn.lct_peer_timeout =
3165 conf->cfg_config_u.cfg_net.net_peer_timeout;
3166 tun.lt_cmn.lct_peer_tx_credits =
3167 conf->cfg_config_u.cfg_net.net_peer_tx_credits;
3168 tun.lt_cmn.lct_peer_rtr_credits =
3169 conf->cfg_config_u.cfg_net.net_peer_rtr_credits;
3170 tun.lt_cmn.lct_max_tx_credits =
3171 conf->cfg_config_u.cfg_net.net_max_tx_credits;
3173 rc = lnet_add_net_common(net, &tun);
3176 mutex_unlock(&the_lnet.ln_api_mutex);
3177 while (!list_empty(&net_head)) {
3178 /* net_head list is empty in success case */
3179 net = list_entry(net_head.next, struct lnet_net, net_list);
3180 list_del_init(&net->net_list);
3187 lnet_dyn_del_net(__u32 net_id)
3189 struct lnet_net *net;
3190 struct lnet_ping_buffer *pbuf;
3191 struct lnet_handle_md ping_mdh;
3195 /* don't allow userspace to shutdown the LOLND */
3196 if (LNET_NETTYP(net_id) == LOLND)
3199 mutex_lock(&the_lnet.ln_api_mutex);
3203 net = lnet_get_net_locked(net_id);
3210 net_ni_count = lnet_get_net_ni_count_locked(net);
3214 /* create and link a new ping info, before removing the old one */
3215 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3216 lnet_get_ni_count() - net_ni_count, false);
3220 lnet_shutdown_lndnet(net);
3222 if (lnet_count_acceptor_nets() == 0)
3223 lnet_acceptor_stop();
3225 lnet_ping_target_update(pbuf, ping_mdh);
3228 mutex_unlock(&the_lnet.ln_api_mutex);
3233 void lnet_incr_dlc_seq(void)
3235 atomic_inc(&lnet_dlc_seq_no);
3238 __u32 lnet_get_dlc_seq_locked(void)
3240 return atomic_read(&lnet_dlc_seq_no);
3244 lnet_ni_set_healthv(lnet_nid_t nid, int value, bool all)
3246 struct lnet_net *net;
3249 lnet_net_lock(LNET_LOCK_EX);
3250 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3251 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3252 if (ni->ni_nid == nid || all) {
3253 atomic_set(&ni->ni_healthv, value);
3254 if (list_empty(&ni->ni_recovery) &&
3255 value < LNET_MAX_HEALTH_VALUE) {
3256 CERROR("manually adding local NI %s to recovery\n",
3257 libcfs_nid2str(ni->ni_nid));
3258 list_add_tail(&ni->ni_recovery,
3259 &the_lnet.ln_mt_localNIRecovq);
3260 lnet_ni_addref_locked(ni, 0);
3263 lnet_net_unlock(LNET_LOCK_EX);
3269 lnet_net_unlock(LNET_LOCK_EX);
3273 lnet_get_local_ni_hstats(struct lnet_ioctl_local_ni_hstats *stats)
3277 lnet_nid_t nid = stats->hlni_nid;
3279 cpt = lnet_net_lock_current();
3280 ni = lnet_nid2ni_locked(nid, cpt);
3287 stats->hlni_local_interrupt = atomic_read(&ni->ni_hstats.hlt_local_interrupt);
3288 stats->hlni_local_dropped = atomic_read(&ni->ni_hstats.hlt_local_dropped);
3289 stats->hlni_local_aborted = atomic_read(&ni->ni_hstats.hlt_local_aborted);
3290 stats->hlni_local_no_route = atomic_read(&ni->ni_hstats.hlt_local_no_route);
3291 stats->hlni_local_timeout = atomic_read(&ni->ni_hstats.hlt_local_timeout);
3292 stats->hlni_local_error = atomic_read(&ni->ni_hstats.hlt_local_error);
3293 stats->hlni_health_value = atomic_read(&ni->ni_healthv);
3296 lnet_net_unlock(cpt);
3302 lnet_get_local_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
3307 lnet_net_lock(LNET_LOCK_EX);
3308 list_for_each_entry(ni, &the_lnet.ln_mt_localNIRecovq, ni_recovery) {
3309 list->rlst_nid_array[i] = ni->ni_nid;
3311 if (i >= LNET_MAX_SHOW_NUM_NID)
3314 lnet_net_unlock(LNET_LOCK_EX);
3315 list->rlst_num_nids = i;
3321 lnet_get_peer_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
3323 struct lnet_peer_ni *lpni;
3326 lnet_net_lock(LNET_LOCK_EX);
3327 list_for_each_entry(lpni, &the_lnet.ln_mt_peerNIRecovq, lpni_recovery) {
3328 list->rlst_nid_array[i] = lpni->lpni_nid;
3330 if (i >= LNET_MAX_SHOW_NUM_NID)
3333 lnet_net_unlock(LNET_LOCK_EX);
3334 list->rlst_num_nids = i;
3340 * LNet ioctl handler.
3344 LNetCtl(unsigned int cmd, void *arg)
3346 struct libcfs_ioctl_data *data = arg;
3347 struct lnet_ioctl_config_data *config;
3348 struct lnet_process_id id = {0};
3352 BUILD_BUG_ON(sizeof(struct lnet_ioctl_net_config) +
3353 sizeof(struct lnet_ioctl_config_data) > LIBCFS_IOC_DATA_MAX);
3356 case IOC_LIBCFS_GET_NI:
3357 rc = LNetGetId(data->ioc_count, &id);
3358 data->ioc_nid = id.nid;
3361 case IOC_LIBCFS_FAIL_NID:
3362 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
3364 case IOC_LIBCFS_ADD_ROUTE:
3367 if (config->cfg_hdr.ioc_len < sizeof(*config))
3370 mutex_lock(&the_lnet.ln_api_mutex);
3371 rc = lnet_add_route(config->cfg_net,
3372 config->cfg_config_u.cfg_route.rtr_hop,
3374 config->cfg_config_u.cfg_route.
3377 rc = lnet_check_routes();
3379 lnet_del_route(config->cfg_net,
3382 mutex_unlock(&the_lnet.ln_api_mutex);
3385 case IOC_LIBCFS_DEL_ROUTE:
3388 if (config->cfg_hdr.ioc_len < sizeof(*config))
3391 mutex_lock(&the_lnet.ln_api_mutex);
3392 rc = lnet_del_route(config->cfg_net, config->cfg_nid);
3393 mutex_unlock(&the_lnet.ln_api_mutex);
3396 case IOC_LIBCFS_GET_ROUTE:
3399 if (config->cfg_hdr.ioc_len < sizeof(*config))
3402 mutex_lock(&the_lnet.ln_api_mutex);
3403 rc = lnet_get_route(config->cfg_count,
3405 &config->cfg_config_u.cfg_route.rtr_hop,
3407 &config->cfg_config_u.cfg_route.rtr_flags,
3408 &config->cfg_config_u.cfg_route.
3410 mutex_unlock(&the_lnet.ln_api_mutex);
3413 case IOC_LIBCFS_GET_LOCAL_NI: {
3414 struct lnet_ioctl_config_ni *cfg_ni;
3415 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
3416 struct lnet_ioctl_element_stats *stats;
3421 /* get the tunables if they are available */
3422 if (cfg_ni->lic_cfg_hdr.ioc_len <
3423 sizeof(*cfg_ni) + sizeof(*stats) + sizeof(*tun))
3426 stats = (struct lnet_ioctl_element_stats *)
3428 tun = (struct lnet_ioctl_config_lnd_tunables *)
3429 (cfg_ni->lic_bulk + sizeof(*stats));
3431 tun_size = cfg_ni->lic_cfg_hdr.ioc_len - sizeof(*cfg_ni) -
3434 mutex_lock(&the_lnet.ln_api_mutex);
3435 rc = lnet_get_ni_config(cfg_ni, tun, stats, tun_size);
3436 mutex_unlock(&the_lnet.ln_api_mutex);
3440 case IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS: {
3441 struct lnet_ioctl_element_msg_stats *msg_stats = arg;
3443 if (msg_stats->im_hdr.ioc_len != sizeof(*msg_stats))
3446 mutex_lock(&the_lnet.ln_api_mutex);
3447 rc = lnet_get_ni_stats(msg_stats);
3448 mutex_unlock(&the_lnet.ln_api_mutex);
3453 case IOC_LIBCFS_GET_NET: {
3454 size_t total = sizeof(*config) +
3455 sizeof(struct lnet_ioctl_net_config);
3458 if (config->cfg_hdr.ioc_len < total)
3461 mutex_lock(&the_lnet.ln_api_mutex);
3462 rc = lnet_get_net_config(config);
3463 mutex_unlock(&the_lnet.ln_api_mutex);
3467 case IOC_LIBCFS_GET_LNET_STATS:
3469 struct lnet_ioctl_lnet_stats *lnet_stats = arg;
3471 if (lnet_stats->st_hdr.ioc_len < sizeof(*lnet_stats))
3474 mutex_lock(&the_lnet.ln_api_mutex);
3475 lnet_counters_get(&lnet_stats->st_cntrs);
3476 mutex_unlock(&the_lnet.ln_api_mutex);
3480 case IOC_LIBCFS_CONFIG_RTR:
3483 if (config->cfg_hdr.ioc_len < sizeof(*config))
3486 mutex_lock(&the_lnet.ln_api_mutex);
3487 if (config->cfg_config_u.cfg_buffers.buf_enable) {
3488 rc = lnet_rtrpools_enable();
3489 mutex_unlock(&the_lnet.ln_api_mutex);
3492 lnet_rtrpools_disable();
3493 mutex_unlock(&the_lnet.ln_api_mutex);
3496 case IOC_LIBCFS_ADD_BUF:
3499 if (config->cfg_hdr.ioc_len < sizeof(*config))
3502 mutex_lock(&the_lnet.ln_api_mutex);
3503 rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
3505 config->cfg_config_u.cfg_buffers.
3507 config->cfg_config_u.cfg_buffers.
3509 mutex_unlock(&the_lnet.ln_api_mutex);
3512 case IOC_LIBCFS_SET_NUMA_RANGE: {
3513 struct lnet_ioctl_set_value *numa;
3515 if (numa->sv_hdr.ioc_len != sizeof(*numa))
3517 lnet_net_lock(LNET_LOCK_EX);
3518 lnet_numa_range = numa->sv_value;
3519 lnet_net_unlock(LNET_LOCK_EX);
3523 case IOC_LIBCFS_GET_NUMA_RANGE: {
3524 struct lnet_ioctl_set_value *numa;
3526 if (numa->sv_hdr.ioc_len != sizeof(*numa))
3528 numa->sv_value = lnet_numa_range;
3532 case IOC_LIBCFS_GET_BUF: {
3533 struct lnet_ioctl_pool_cfg *pool_cfg;
3534 size_t total = sizeof(*config) + sizeof(*pool_cfg);
3538 if (config->cfg_hdr.ioc_len < total)
3541 pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
3543 mutex_lock(&the_lnet.ln_api_mutex);
3544 rc = lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
3545 mutex_unlock(&the_lnet.ln_api_mutex);
3549 case IOC_LIBCFS_GET_LOCAL_HSTATS: {
3550 struct lnet_ioctl_local_ni_hstats *stats = arg;
3552 if (stats->hlni_hdr.ioc_len < sizeof(*stats))
3555 mutex_lock(&the_lnet.ln_api_mutex);
3556 rc = lnet_get_local_ni_hstats(stats);
3557 mutex_unlock(&the_lnet.ln_api_mutex);
3562 case IOC_LIBCFS_GET_RECOVERY_QUEUE: {
3563 struct lnet_ioctl_recovery_list *list = arg;
3564 if (list->rlst_hdr.ioc_len < sizeof(*list))
3567 mutex_lock(&the_lnet.ln_api_mutex);
3568 if (list->rlst_type == LNET_HEALTH_TYPE_LOCAL_NI)
3569 rc = lnet_get_local_ni_recovery_list(list);
3571 rc = lnet_get_peer_ni_recovery_list(list);
3572 mutex_unlock(&the_lnet.ln_api_mutex);
3576 case IOC_LIBCFS_ADD_PEER_NI: {
3577 struct lnet_ioctl_peer_cfg *cfg = arg;
3579 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
3582 mutex_lock(&the_lnet.ln_api_mutex);
3583 rc = lnet_add_peer_ni(cfg->prcfg_prim_nid,
3586 mutex_unlock(&the_lnet.ln_api_mutex);
3590 case IOC_LIBCFS_DEL_PEER_NI: {
3591 struct lnet_ioctl_peer_cfg *cfg = arg;
3593 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
3596 mutex_lock(&the_lnet.ln_api_mutex);
3597 rc = lnet_del_peer_ni(cfg->prcfg_prim_nid,
3598 cfg->prcfg_cfg_nid);
3599 mutex_unlock(&the_lnet.ln_api_mutex);
3603 case IOC_LIBCFS_GET_PEER_INFO: {
3604 struct lnet_ioctl_peer *peer_info = arg;
3606 if (peer_info->pr_hdr.ioc_len < sizeof(*peer_info))
3609 mutex_lock(&the_lnet.ln_api_mutex);
3610 rc = lnet_get_peer_ni_info(
3611 peer_info->pr_count,
3613 peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
3614 &peer_info->pr_lnd_u.pr_peer_credits.cr_ncpt,
3615 &peer_info->pr_lnd_u.pr_peer_credits.cr_refcount,
3616 &peer_info->pr_lnd_u.pr_peer_credits.cr_ni_peer_tx_credits,
3617 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_credits,
3618 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_rtr_credits,
3619 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_min_tx_credits,
3620 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_qnob);
3621 mutex_unlock(&the_lnet.ln_api_mutex);
3625 case IOC_LIBCFS_GET_PEER_NI: {
3626 struct lnet_ioctl_peer_cfg *cfg = arg;
3628 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
3631 mutex_lock(&the_lnet.ln_api_mutex);
3632 rc = lnet_get_peer_info(cfg,
3633 (void __user *)cfg->prcfg_bulk);
3634 mutex_unlock(&the_lnet.ln_api_mutex);
3638 case IOC_LIBCFS_GET_PEER_LIST: {
3639 struct lnet_ioctl_peer_cfg *cfg = arg;
3641 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
3644 mutex_lock(&the_lnet.ln_api_mutex);
3645 rc = lnet_get_peer_list(&cfg->prcfg_count, &cfg->prcfg_size,
3646 (struct lnet_process_id __user *)cfg->prcfg_bulk);
3647 mutex_unlock(&the_lnet.ln_api_mutex);
3651 case IOC_LIBCFS_SET_HEALHV: {
3652 struct lnet_ioctl_reset_health_cfg *cfg = arg;
3654 if (cfg->rh_hdr.ioc_len < sizeof(*cfg))
3656 if (cfg->rh_value < 0 ||
3657 cfg->rh_value > LNET_MAX_HEALTH_VALUE)
3658 value = LNET_MAX_HEALTH_VALUE;
3660 value = cfg->rh_value;
3661 CDEBUG(D_NET, "Manually setting healthv to %d for %s:%s. all = %d\n",
3662 value, (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI) ?
3663 "local" : "peer", libcfs_nid2str(cfg->rh_nid), cfg->rh_all);
3664 mutex_lock(&the_lnet.ln_api_mutex);
3665 if (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI)
3666 lnet_ni_set_healthv(cfg->rh_nid, value,
3669 lnet_peer_ni_set_healthv(cfg->rh_nid, value,
3671 mutex_unlock(&the_lnet.ln_api_mutex);
3675 case IOC_LIBCFS_NOTIFY_ROUTER: {
3676 time64_t deadline = ktime_get_real_seconds() - data->ioc_u64[0];
3678 /* The deadline passed in by the user should be some time in
3679 * seconds in the future since the UNIX epoch. We have to map
3680 * that deadline to the wall clock.
3682 deadline += ktime_get_seconds();
3683 return lnet_notify(NULL, data->ioc_nid, data->ioc_flags,
3687 case IOC_LIBCFS_LNET_DIST:
3688 rc = LNetDist(data->ioc_nid, &data->ioc_nid, &data->ioc_u32[1]);
3689 if (rc < 0 && rc != -EHOSTUNREACH)
3692 data->ioc_u32[0] = rc;
3695 case IOC_LIBCFS_TESTPROTOCOMPAT:
3696 lnet_net_lock(LNET_LOCK_EX);
3697 the_lnet.ln_testprotocompat = data->ioc_flags;
3698 lnet_net_unlock(LNET_LOCK_EX);
3701 case IOC_LIBCFS_LNET_FAULT:
3702 return lnet_fault_ctl(data->ioc_flags, data);
3704 case IOC_LIBCFS_PING: {
3705 signed long timeout;
3707 id.nid = data->ioc_nid;
3708 id.pid = data->ioc_u32[0];
3710 /* If timeout is negative then set default of 3 minutes */
3711 if (((s32)data->ioc_u32[1] <= 0) ||
3712 data->ioc_u32[1] > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
3713 timeout = msecs_to_jiffies(DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC);
3715 timeout = msecs_to_jiffies(data->ioc_u32[1]);
3717 rc = lnet_ping(id, timeout, data->ioc_pbuf1,
3718 data->ioc_plen1 / sizeof(struct lnet_process_id));
3723 data->ioc_count = rc;
3727 case IOC_LIBCFS_PING_PEER: {
3728 struct lnet_ioctl_ping_data *ping = arg;
3729 struct lnet_peer *lp;
3730 signed long timeout;
3732 /* If timeout is negative then set default of 3 minutes */
3733 if (((s32)ping->op_param) <= 0 ||
3734 ping->op_param > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
3735 timeout = msecs_to_jiffies(DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC);
3737 timeout = msecs_to_jiffies(ping->op_param);
3739 rc = lnet_ping(ping->ping_id, timeout,
3745 mutex_lock(&the_lnet.ln_api_mutex);
3746 lp = lnet_find_peer(ping->ping_id.nid);
3748 ping->ping_id.nid = lp->lp_primary_nid;
3749 ping->mr_info = lnet_peer_is_multi_rail(lp);
3750 lnet_peer_decref_locked(lp);
3752 mutex_unlock(&the_lnet.ln_api_mutex);
3754 ping->ping_count = rc;
3758 case IOC_LIBCFS_DISCOVER: {
3759 struct lnet_ioctl_ping_data *discover = arg;
3760 struct lnet_peer *lp;
3762 rc = lnet_discover(discover->ping_id, discover->op_param,
3764 discover->ping_count);
3768 mutex_lock(&the_lnet.ln_api_mutex);
3769 lp = lnet_find_peer(discover->ping_id.nid);
3771 discover->ping_id.nid = lp->lp_primary_nid;
3772 discover->mr_info = lnet_peer_is_multi_rail(lp);
3773 lnet_peer_decref_locked(lp);
3775 mutex_unlock(&the_lnet.ln_api_mutex);
3777 discover->ping_count = rc;
3782 ni = lnet_net2ni_addref(data->ioc_net);
3786 if (ni->ni_net->net_lnd->lnd_ctl == NULL)
3789 rc = ni->ni_net->net_lnd->lnd_ctl(ni, cmd, arg);
3796 EXPORT_SYMBOL(LNetCtl);
3798 void LNetDebugPeer(struct lnet_process_id id)
3800 lnet_debug_peer(id.nid);
3802 EXPORT_SYMBOL(LNetDebugPeer);
3805 * Determine if the specified peer \a nid is on the local node.
3807 * \param nid peer nid to check
3809 * \retval true If peer NID is on the local node.
3810 * \retval false If peer NID is not on the local node.
3812 bool LNetIsPeerLocal(lnet_nid_t nid)
3814 struct lnet_net *net;
3818 cpt = lnet_net_lock_current();
3819 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3820 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3821 if (ni->ni_nid == nid) {
3822 lnet_net_unlock(cpt);
3827 lnet_net_unlock(cpt);
3831 EXPORT_SYMBOL(LNetIsPeerLocal);
3834 * Retrieve the struct lnet_process_id ID of LNet interface at \a index.
3835 * Note that all interfaces share a same PID, as requested by LNetNIInit().
3837 * \param index Index of the interface to look up.
3838 * \param id On successful return, this location will hold the
3839 * struct lnet_process_id ID of the interface.
3841 * \retval 0 If an interface exists at \a index.
3842 * \retval -ENOENT If no interface has been found.
3845 LNetGetId(unsigned int index, struct lnet_process_id *id)
3848 struct lnet_net *net;
3852 LASSERT(the_lnet.ln_refcount > 0);
3854 cpt = lnet_net_lock_current();
3856 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3857 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3861 id->nid = ni->ni_nid;
3862 id->pid = the_lnet.ln_pid;
3868 lnet_net_unlock(cpt);
3871 EXPORT_SYMBOL(LNetGetId);
3873 static int lnet_ping(struct lnet_process_id id, signed long timeout,
3874 struct lnet_process_id __user *ids, int n_ids)
3876 struct lnet_handle_eq eqh;
3877 struct lnet_handle_md mdh;
3878 struct lnet_event event;
3879 struct lnet_md md = { NULL };
3883 const signed long a_long_time = msecs_to_jiffies(60 * MSEC_PER_SEC);
3884 struct lnet_ping_buffer *pbuf;
3885 struct lnet_process_id tmpid;
3892 /* n_ids limit is arbitrary */
3893 if (n_ids <= 0 || id.nid == LNET_NID_ANY)
3897 * if the user buffer has more space than the lnet_interfaces_max
3898 * then only fill it up to lnet_interfaces_max
3900 if (n_ids > lnet_interfaces_max)
3901 n_ids = lnet_interfaces_max;
3903 if (id.pid == LNET_PID_ANY)
3904 id.pid = LNET_PID_LUSTRE;
3906 pbuf = lnet_ping_buffer_alloc(n_ids, GFP_NOFS);
3910 /* NB 2 events max (including any unlink event) */
3911 rc = LNetEQAlloc(2, LNET_EQ_HANDLER_NONE, &eqh);
3913 CERROR("Can't allocate EQ: %d\n", rc);
3914 goto fail_ping_buffer_decref;
3917 /* initialize md content */
3918 md.start = &pbuf->pb_info;
3919 md.length = LNET_PING_INFO_SIZE(n_ids);
3920 md.threshold = 2; /* GET/REPLY */
3922 md.options = LNET_MD_TRUNCATE;
3926 rc = LNetMDBind(md, LNET_UNLINK, &mdh);
3928 CERROR("Can't bind MD: %d\n", rc);
3932 rc = LNetGet(LNET_NID_ANY, mdh, id,
3933 LNET_RESERVED_PORTAL,
3934 LNET_PROTO_PING_MATCHBITS, 0, false);
3937 /* Don't CERROR; this could be deliberate! */
3938 rc2 = LNetMDUnlink(mdh);
3941 /* NB must wait for the UNLINK event below... */
3943 timeout = a_long_time;
3947 /* MUST block for unlink to complete */
3949 blocked = cfs_block_allsigs();
3951 rc2 = LNetEQPoll(&eqh, 1, timeout, &event, &which);
3954 cfs_restore_sigs(blocked);
3956 CDEBUG(D_NET, "poll %d(%d %d)%s\n", rc2,
3957 (rc2 <= 0) ? -1 : event.type,
3958 (rc2 <= 0) ? -1 : event.status,
3959 (rc2 > 0 && event.unlinked) ? " unlinked" : "");
3961 LASSERT(rc2 != -EOVERFLOW); /* can't miss anything */
3963 if (rc2 <= 0 || event.status != 0) {
3964 /* timeout or error */
3965 if (!replied && rc == 0)
3966 rc = (rc2 < 0) ? rc2 :
3967 (rc2 == 0) ? -ETIMEDOUT :
3971 /* Ensure completion in finite time... */
3973 /* No assertion (racing with network) */
3975 timeout = a_long_time;
3976 } else if (rc2 == 0) {
3977 /* timed out waiting for unlink */
3978 CWARN("ping %s: late network completion\n",
3981 } else if (event.type == LNET_EVENT_REPLY) {
3985 } while (rc2 <= 0 || !event.unlinked);
3989 CWARN("%s: Unexpected rc >= 0 but no reply!\n",
3996 LASSERT(nob >= 0 && nob <= LNET_PING_INFO_SIZE(n_ids));
3998 rc = -EPROTO; /* if I can't parse... */
4001 CERROR("%s: ping info too short %d\n",
4002 libcfs_id2str(id), nob);
4006 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) {
4007 lnet_swap_pinginfo(pbuf);
4008 } else if (pbuf->pb_info.pi_magic != LNET_PROTO_PING_MAGIC) {
4009 CERROR("%s: Unexpected magic %08x\n",
4010 libcfs_id2str(id), pbuf->pb_info.pi_magic);
4014 if ((pbuf->pb_info.pi_features & LNET_PING_FEAT_NI_STATUS) == 0) {
4015 CERROR("%s: ping w/o NI status: 0x%x\n",
4016 libcfs_id2str(id), pbuf->pb_info.pi_features);
4020 if (nob < LNET_PING_INFO_SIZE(0)) {
4021 CERROR("%s: Short reply %d(%d min)\n",
4023 nob, (int)LNET_PING_INFO_SIZE(0));
4027 if (pbuf->pb_info.pi_nnis < n_ids)
4028 n_ids = pbuf->pb_info.pi_nnis;
4030 if (nob < LNET_PING_INFO_SIZE(n_ids)) {
4031 CERROR("%s: Short reply %d(%d expected)\n",
4033 nob, (int)LNET_PING_INFO_SIZE(n_ids));
4037 rc = -EFAULT; /* if I segv in copy_to_user()... */
4039 memset(&tmpid, 0, sizeof(tmpid));
4040 for (i = 0; i < n_ids; i++) {
4041 tmpid.pid = pbuf->pb_info.pi_pid;
4042 tmpid.nid = pbuf->pb_info.pi_ni[i].ns_nid;
4043 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid)))
4046 rc = pbuf->pb_info.pi_nnis;
4049 rc2 = LNetEQFree(eqh);
4051 CERROR("rc2 %d\n", rc2);
4054 fail_ping_buffer_decref:
4055 lnet_ping_buffer_decref(pbuf);
4060 lnet_discover(struct lnet_process_id id, __u32 force,
4061 struct lnet_process_id __user *ids, int n_ids)
4063 struct lnet_peer_ni *lpni;
4064 struct lnet_peer_ni *p;
4065 struct lnet_peer *lp;
4066 struct lnet_process_id *buf;
4070 int max_intf = lnet_interfaces_max;
4074 id.nid == LNET_NID_ANY)
4077 if (id.pid == LNET_PID_ANY)
4078 id.pid = LNET_PID_LUSTRE;
4081 * if the user buffer has more space than the max_intf
4082 * then only fill it up to max_intf
4084 if (n_ids > max_intf)
4087 buf_size = n_ids * sizeof(*buf);
4089 LIBCFS_ALLOC(buf, buf_size);
4093 cpt = lnet_net_lock_current();
4094 lpni = lnet_nid2peerni_locked(id.nid, LNET_NID_ANY, cpt);
4101 * Clearing the NIDS_UPTODATE flag ensures the peer will
4102 * be discovered, provided discovery has not been disabled.
4104 lp = lpni->lpni_peer_net->lpn_peer;
4105 spin_lock(&lp->lp_lock);
4106 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
4107 /* If the force flag is set, force a PING and PUSH as well. */
4109 lp->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH;
4110 spin_unlock(&lp->lp_lock);
4111 rc = lnet_discover_peer_locked(lpni, cpt, true);
4115 /* Peer may have changed. */
4116 lp = lpni->lpni_peer_net->lpn_peer;
4117 if (lp->lp_nnis < n_ids)
4118 n_ids = lp->lp_nnis;
4122 while ((p = lnet_get_next_peer_ni_locked(lp, NULL, p)) != NULL) {
4123 buf[i].pid = id.pid;
4124 buf[i].nid = p->lpni_nid;
4129 lnet_net_unlock(cpt);
4132 if (copy_to_user(ids, buf, n_ids * sizeof(*buf)))
4138 lnet_peer_ni_decref_locked(lpni);
4140 lnet_net_unlock(cpt);
4142 LIBCFS_FREE(buf, buf_size);
4148 * Retrieve peer discovery status.
4150 * \retval 1 if lnet_peer_discovery_disabled is 0
4151 * \retval 0 if lnet_peer_discovery_disabled is 1
4154 LNetGetPeerDiscoveryStatus(void)
4156 return !lnet_peer_discovery_disabled;
4158 EXPORT_SYMBOL(LNetGetPeerDiscoveryStatus);