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/
32 #define DEBUG_SUBSYSTEM S_LNET
34 #include <linux/ctype.h>
35 #include <linux/log2.h>
36 #include <linux/ktime.h>
37 #include <linux/moduleparam.h>
38 #include <linux/uaccess.h>
39 #ifdef HAVE_SCHED_HEADERS
40 #include <linux/sched/signal.h>
43 #include <lnet/udsp.h>
44 #include <lnet/lib-lnet.h>
46 #define D_LNI D_CONSOLE
49 * initialize ln_api_mutex statically, since it needs to be used in
50 * discovery_set callback. That module parameter callback can be called
51 * before module init completes. The mutex needs to be ready for use then.
53 struct lnet the_lnet = {
54 .ln_api_mutex = __MUTEX_INITIALIZER(the_lnet.ln_api_mutex),
55 }; /* THE state of the network */
56 EXPORT_SYMBOL(the_lnet);
58 static char *ip2nets = "";
59 module_param(ip2nets, charp, 0444);
60 MODULE_PARM_DESC(ip2nets, "LNET network <- IP table");
62 static char *networks = "";
63 module_param(networks, charp, 0444);
64 MODULE_PARM_DESC(networks, "local networks");
66 static char *routes = "";
67 module_param(routes, charp, 0444);
68 MODULE_PARM_DESC(routes, "routes to non-local networks");
70 static int rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
71 module_param(rnet_htable_size, int, 0444);
72 MODULE_PARM_DESC(rnet_htable_size, "size of remote network hash table");
74 static int use_tcp_bonding;
75 module_param(use_tcp_bonding, int, 0444);
76 MODULE_PARM_DESC(use_tcp_bonding,
77 "use_tcp_bonding parameter has been removed");
79 unsigned int lnet_numa_range = 0;
80 module_param(lnet_numa_range, uint, 0444);
81 MODULE_PARM_DESC(lnet_numa_range,
82 "NUMA range to consider during Multi-Rail selection");
85 * lnet_health_sensitivity determines by how much we decrement the health
86 * value on sending error. The value defaults to 100, which means health
87 * interface health is decremented by 100 points every failure.
89 unsigned int lnet_health_sensitivity = 100;
90 static int sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp);
91 #ifdef HAVE_KERNEL_PARAM_OPS
92 static struct kernel_param_ops param_ops_health_sensitivity = {
93 .set = sensitivity_set,
96 #define param_check_health_sensitivity(name, p) \
97 __param_check(name, p, int)
98 module_param(lnet_health_sensitivity, health_sensitivity, S_IRUGO|S_IWUSR);
100 module_param_call(lnet_health_sensitivity, sensitivity_set, param_get_int,
101 &lnet_health_sensitivity, S_IRUGO|S_IWUSR);
103 MODULE_PARM_DESC(lnet_health_sensitivity,
104 "Value to decrement the health value by on error");
107 * lnet_recovery_interval determines how often we should perform recovery
108 * on unhealthy interfaces.
110 unsigned int lnet_recovery_interval = 1;
111 static int recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp);
112 #ifdef HAVE_KERNEL_PARAM_OPS
113 static struct kernel_param_ops param_ops_recovery_interval = {
114 .set = recovery_interval_set,
115 .get = param_get_int,
117 #define param_check_recovery_interval(name, p) \
118 __param_check(name, p, int)
119 module_param(lnet_recovery_interval, recovery_interval, S_IRUGO|S_IWUSR);
121 module_param_call(lnet_recovery_interval, recovery_interval_set, param_get_int,
122 &lnet_recovery_interval, S_IRUGO|S_IWUSR);
124 MODULE_PARM_DESC(lnet_recovery_interval,
125 "DEPRECATED - Interval to recover unhealthy interfaces in seconds");
127 unsigned int lnet_recovery_limit;
128 module_param(lnet_recovery_limit, uint, 0644);
129 MODULE_PARM_DESC(lnet_recovery_limit,
130 "How long to attempt recovery of unhealthy peer interfaces in seconds. Set to 0 to allow indefinite recovery");
132 static int lnet_interfaces_max = LNET_INTERFACES_MAX_DEFAULT;
133 static int intf_max_set(const char *val, cfs_kernel_param_arg_t *kp);
135 static struct kernel_param_ops param_ops_interfaces_max = {
137 .get = param_get_int,
140 #define param_check_interfaces_max(name, p) \
141 __param_check(name, p, int)
143 #ifdef HAVE_KERNEL_PARAM_OPS
144 module_param(lnet_interfaces_max, interfaces_max, 0644);
146 module_param_call(lnet_interfaces_max, intf_max_set, param_get_int,
147 ¶m_ops_interfaces_max, 0644);
149 MODULE_PARM_DESC(lnet_interfaces_max,
150 "Maximum number of interfaces in a node.");
152 unsigned lnet_peer_discovery_disabled = 0;
153 static int discovery_set(const char *val, cfs_kernel_param_arg_t *kp);
155 static struct kernel_param_ops param_ops_discovery_disabled = {
156 .set = discovery_set,
157 .get = param_get_int,
160 #define param_check_discovery_disabled(name, p) \
161 __param_check(name, p, int)
162 #ifdef HAVE_KERNEL_PARAM_OPS
163 module_param(lnet_peer_discovery_disabled, discovery_disabled, 0644);
165 module_param_call(lnet_peer_discovery_disabled, discovery_set, param_get_int,
166 ¶m_ops_discovery_disabled, 0644);
168 MODULE_PARM_DESC(lnet_peer_discovery_disabled,
169 "Set to 1 to disable peer discovery on this node.");
171 unsigned int lnet_drop_asym_route;
172 static int drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp);
174 static struct kernel_param_ops param_ops_drop_asym_route = {
175 .set = drop_asym_route_set,
176 .get = param_get_int,
179 #define param_check_drop_asym_route(name, p) \
180 __param_check(name, p, int)
181 #ifdef HAVE_KERNEL_PARAM_OPS
182 module_param(lnet_drop_asym_route, drop_asym_route, 0644);
184 module_param_call(lnet_drop_asym_route, drop_asym_route_set, param_get_int,
185 ¶m_ops_drop_asym_route, 0644);
187 MODULE_PARM_DESC(lnet_drop_asym_route,
188 "Set to 1 to drop asymmetrical route messages.");
190 #define LNET_TRANSACTION_TIMEOUT_DEFAULT 50
191 unsigned int lnet_transaction_timeout = LNET_TRANSACTION_TIMEOUT_DEFAULT;
192 static int transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp);
193 #ifdef HAVE_KERNEL_PARAM_OPS
194 static struct kernel_param_ops param_ops_transaction_timeout = {
195 .set = transaction_to_set,
196 .get = param_get_int,
199 #define param_check_transaction_timeout(name, p) \
200 __param_check(name, p, int)
201 module_param(lnet_transaction_timeout, transaction_timeout, S_IRUGO|S_IWUSR);
203 module_param_call(lnet_transaction_timeout, transaction_to_set, param_get_int,
204 &lnet_transaction_timeout, S_IRUGO|S_IWUSR);
206 MODULE_PARM_DESC(lnet_transaction_timeout,
207 "Maximum number of seconds to wait for a peer response.");
209 #define LNET_RETRY_COUNT_DEFAULT 2
210 unsigned int lnet_retry_count = LNET_RETRY_COUNT_DEFAULT;
211 static int retry_count_set(const char *val, cfs_kernel_param_arg_t *kp);
212 #ifdef HAVE_KERNEL_PARAM_OPS
213 static struct kernel_param_ops param_ops_retry_count = {
214 .set = retry_count_set,
215 .get = param_get_int,
218 #define param_check_retry_count(name, p) \
219 __param_check(name, p, int)
220 module_param(lnet_retry_count, retry_count, S_IRUGO|S_IWUSR);
222 module_param_call(lnet_retry_count, retry_count_set, param_get_int,
223 &lnet_retry_count, S_IRUGO|S_IWUSR);
225 MODULE_PARM_DESC(lnet_retry_count,
226 "Maximum number of times to retry transmitting a message");
228 unsigned int lnet_response_tracking = 3;
229 static int response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp);
231 #ifdef HAVE_KERNEL_PARAM_OPS
232 static struct kernel_param_ops param_ops_response_tracking = {
233 .set = response_tracking_set,
234 .get = param_get_int,
237 #define param_check_response_tracking(name, p) \
238 __param_check(name, p, int)
239 module_param(lnet_response_tracking, response_tracking, 0644);
241 module_param_call(lnet_response_tracking, response_tracking_set, param_get_int,
242 &lnet_response_tracking, 0644);
244 MODULE_PARM_DESC(lnet_response_tracking,
245 "(0|1|2|3) LNet Internal Only|GET Reply only|PUT ACK only|Full Tracking (default)");
247 #define LNET_LND_TIMEOUT_DEFAULT ((LNET_TRANSACTION_TIMEOUT_DEFAULT - 1) / \
248 (LNET_RETRY_COUNT_DEFAULT + 1))
249 unsigned int lnet_lnd_timeout = LNET_LND_TIMEOUT_DEFAULT;
250 static void lnet_set_lnd_timeout(void)
252 lnet_lnd_timeout = (lnet_transaction_timeout - 1) /
253 (lnet_retry_count + 1);
257 * This sequence number keeps track of how many times DLC was used to
258 * update the local NIs. It is incremented when a NI is added or
259 * removed and checked when sending a message to determine if there is
260 * a need to re-run the selection algorithm. See lnet_select_pathway()
261 * for more details on its usage.
263 static atomic_t lnet_dlc_seq_no = ATOMIC_INIT(0);
265 static int lnet_ping(struct lnet_process_id id, signed long timeout,
266 struct lnet_process_id __user *ids, int n_ids);
268 static int lnet_discover(struct lnet_process_id id, __u32 force,
269 struct lnet_process_id __user *ids, int n_ids);
272 sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
275 unsigned *sensitivity = (unsigned *)kp->arg;
278 rc = kstrtoul(val, 0, &value);
280 CERROR("Invalid module parameter value for 'lnet_health_sensitivity'\n");
285 * The purpose of locking the api_mutex here is to ensure that
286 * the correct value ends up stored properly.
288 mutex_lock(&the_lnet.ln_api_mutex);
290 if (value > LNET_MAX_HEALTH_VALUE) {
291 mutex_unlock(&the_lnet.ln_api_mutex);
292 CERROR("Invalid health value. Maximum: %d value = %lu\n",
293 LNET_MAX_HEALTH_VALUE, value);
297 if (*sensitivity != 0 && value == 0 && lnet_retry_count != 0) {
298 lnet_retry_count = 0;
299 lnet_set_lnd_timeout();
302 *sensitivity = value;
304 mutex_unlock(&the_lnet.ln_api_mutex);
310 recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp)
312 CWARN("'lnet_recovery_interval' has been deprecated\n");
318 discovery_set(const char *val, cfs_kernel_param_arg_t *kp)
321 unsigned *discovery_off = (unsigned *)kp->arg;
323 struct lnet_ping_buffer *pbuf;
325 rc = kstrtoul(val, 0, &value);
327 CERROR("Invalid module parameter value for 'lnet_peer_discovery_disabled'\n");
331 value = (value) ? 1 : 0;
334 * The purpose of locking the api_mutex here is to ensure that
335 * the correct value ends up stored properly.
337 mutex_lock(&the_lnet.ln_api_mutex);
339 if (value == *discovery_off) {
340 mutex_unlock(&the_lnet.ln_api_mutex);
345 * We still want to set the discovery value even when LNet is not
346 * running. This is the case when LNet is being loaded and we want
347 * the module parameters to take effect. Otherwise if we're
348 * changing the value dynamically, we want to set it after
351 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
352 *discovery_off = value;
353 mutex_unlock(&the_lnet.ln_api_mutex);
357 /* tell peers that discovery setting has changed */
358 lnet_net_lock(LNET_LOCK_EX);
359 pbuf = the_lnet.ln_ping_target;
361 pbuf->pb_info.pi_features &= ~LNET_PING_FEAT_DISCOVERY;
363 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
364 lnet_net_unlock(LNET_LOCK_EX);
366 /* only send a push when we're turning off discovery */
367 if (*discovery_off <= 0 && value > 0)
368 lnet_push_update_to_peers(1);
369 *discovery_off = value;
371 mutex_unlock(&the_lnet.ln_api_mutex);
377 drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp)
380 unsigned int *drop_asym_route = (unsigned int *)kp->arg;
383 rc = kstrtoul(val, 0, &value);
385 CERROR("Invalid module parameter value for "
386 "'lnet_drop_asym_route'\n");
391 * The purpose of locking the api_mutex here is to ensure that
392 * the correct value ends up stored properly.
394 mutex_lock(&the_lnet.ln_api_mutex);
396 if (value == *drop_asym_route) {
397 mutex_unlock(&the_lnet.ln_api_mutex);
401 *drop_asym_route = value;
403 mutex_unlock(&the_lnet.ln_api_mutex);
409 transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp)
412 unsigned *transaction_to = (unsigned *)kp->arg;
415 rc = kstrtoul(val, 0, &value);
417 CERROR("Invalid module parameter value for 'lnet_transaction_timeout'\n");
422 * The purpose of locking the api_mutex here is to ensure that
423 * the correct value ends up stored properly.
425 mutex_lock(&the_lnet.ln_api_mutex);
427 if (value <= lnet_retry_count || value == 0) {
428 mutex_unlock(&the_lnet.ln_api_mutex);
429 CERROR("Invalid value for lnet_transaction_timeout (%lu). "
430 "Has to be greater than lnet_retry_count (%u)\n",
431 value, lnet_retry_count);
435 if (value == *transaction_to) {
436 mutex_unlock(&the_lnet.ln_api_mutex);
440 *transaction_to = value;
441 /* Update the lnet_lnd_timeout now that we've modified the
442 * transaction timeout
444 lnet_set_lnd_timeout();
446 mutex_unlock(&the_lnet.ln_api_mutex);
452 retry_count_set(const char *val, cfs_kernel_param_arg_t *kp)
455 unsigned *retry_count = (unsigned *)kp->arg;
458 rc = kstrtoul(val, 0, &value);
460 CERROR("Invalid module parameter value for 'lnet_retry_count'\n");
465 * The purpose of locking the api_mutex here is to ensure that
466 * the correct value ends up stored properly.
468 mutex_lock(&the_lnet.ln_api_mutex);
470 if (lnet_health_sensitivity == 0 && value > 0) {
471 mutex_unlock(&the_lnet.ln_api_mutex);
472 CERROR("Can not set lnet_retry_count when health feature is turned off\n");
476 if (value > lnet_transaction_timeout) {
477 mutex_unlock(&the_lnet.ln_api_mutex);
478 CERROR("Invalid value for lnet_retry_count (%lu). "
479 "Has to be smaller than lnet_transaction_timeout (%u)\n",
480 value, lnet_transaction_timeout);
484 *retry_count = value;
486 /* Update the lnet_lnd_timeout now that we've modified the
489 lnet_set_lnd_timeout();
491 mutex_unlock(&the_lnet.ln_api_mutex);
497 intf_max_set(const char *val, cfs_kernel_param_arg_t *kp)
501 rc = kstrtoint(val, 0, &value);
503 CERROR("Invalid module parameter value for 'lnet_interfaces_max'\n");
507 if (value < LNET_INTERFACES_MIN) {
508 CWARN("max interfaces provided are too small, setting to %d\n",
509 LNET_INTERFACES_MAX_DEFAULT);
510 value = LNET_INTERFACES_MAX_DEFAULT;
513 *(int *)kp->arg = value;
519 response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp)
522 unsigned long new_value;
524 rc = kstrtoul(val, 0, &new_value);
526 CERROR("Invalid value for 'lnet_response_tracking'\n");
530 if (new_value < 0 || new_value > 3) {
531 CWARN("Invalid value (%lu) for 'lnet_response_tracking'\n",
536 lnet_response_tracking = new_value;
542 lnet_get_routes(void)
548 lnet_get_networks(void)
553 if (*networks != 0 && *ip2nets != 0) {
554 LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
555 "'ip2nets' but not both at once\n");
560 rc = lnet_parse_ip2nets(&nets, ip2nets);
561 return (rc == 0) ? nets : NULL;
571 lnet_init_locks(void)
573 spin_lock_init(&the_lnet.ln_eq_wait_lock);
574 spin_lock_init(&the_lnet.ln_msg_resend_lock);
575 init_completion(&the_lnet.ln_mt_wait_complete);
576 mutex_init(&the_lnet.ln_lnd_mutex);
579 struct kmem_cache *lnet_mes_cachep; /* MEs kmem_cache */
580 struct kmem_cache *lnet_small_mds_cachep; /* <= LNET_SMALL_MD_SIZE bytes
582 struct kmem_cache *lnet_udsp_cachep; /* udsp cache */
583 struct kmem_cache *lnet_rspt_cachep; /* response tracker cache */
584 struct kmem_cache *lnet_msg_cachep;
587 lnet_slab_setup(void)
589 /* create specific kmem_cache for MEs and small MDs (i.e., originally
590 * allocated in <size-xxx> kmem_cache).
592 lnet_mes_cachep = kmem_cache_create("lnet_MEs", sizeof(struct lnet_me),
594 if (!lnet_mes_cachep)
597 lnet_small_mds_cachep = kmem_cache_create("lnet_small_MDs",
598 LNET_SMALL_MD_SIZE, 0, 0,
600 if (!lnet_small_mds_cachep)
603 lnet_udsp_cachep = kmem_cache_create("lnet_udsp",
604 sizeof(struct lnet_udsp),
606 if (!lnet_udsp_cachep)
609 lnet_rspt_cachep = kmem_cache_create("lnet_rspt", sizeof(struct lnet_rsp_tracker),
611 if (!lnet_rspt_cachep)
614 lnet_msg_cachep = kmem_cache_create("lnet_msg", sizeof(struct lnet_msg),
616 if (!lnet_msg_cachep)
623 lnet_slab_cleanup(void)
625 if (lnet_msg_cachep) {
626 kmem_cache_destroy(lnet_msg_cachep);
627 lnet_msg_cachep = NULL;
630 if (lnet_rspt_cachep) {
631 kmem_cache_destroy(lnet_rspt_cachep);
632 lnet_rspt_cachep = NULL;
635 if (lnet_udsp_cachep) {
636 kmem_cache_destroy(lnet_udsp_cachep);
637 lnet_udsp_cachep = NULL;
640 if (lnet_small_mds_cachep) {
641 kmem_cache_destroy(lnet_small_mds_cachep);
642 lnet_small_mds_cachep = NULL;
645 if (lnet_mes_cachep) {
646 kmem_cache_destroy(lnet_mes_cachep);
647 lnet_mes_cachep = NULL;
652 lnet_create_remote_nets_table(void)
655 struct list_head *hash;
657 LASSERT(the_lnet.ln_remote_nets_hash == NULL);
658 LASSERT(the_lnet.ln_remote_nets_hbits > 0);
659 CFS_ALLOC_PTR_ARRAY(hash, LNET_REMOTE_NETS_HASH_SIZE);
661 CERROR("Failed to create remote nets hash table\n");
665 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
666 INIT_LIST_HEAD(&hash[i]);
667 the_lnet.ln_remote_nets_hash = hash;
672 lnet_destroy_remote_nets_table(void)
676 if (the_lnet.ln_remote_nets_hash == NULL)
679 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
680 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
682 CFS_FREE_PTR_ARRAY(the_lnet.ln_remote_nets_hash,
683 LNET_REMOTE_NETS_HASH_SIZE);
684 the_lnet.ln_remote_nets_hash = NULL;
688 lnet_destroy_locks(void)
690 if (the_lnet.ln_res_lock != NULL) {
691 cfs_percpt_lock_free(the_lnet.ln_res_lock);
692 the_lnet.ln_res_lock = NULL;
695 if (the_lnet.ln_net_lock != NULL) {
696 cfs_percpt_lock_free(the_lnet.ln_net_lock);
697 the_lnet.ln_net_lock = NULL;
702 lnet_create_locks(void)
706 the_lnet.ln_res_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
707 if (the_lnet.ln_res_lock == NULL)
710 the_lnet.ln_net_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
711 if (the_lnet.ln_net_lock == NULL)
717 lnet_destroy_locks();
721 static void lnet_assert_wire_constants(void)
723 /* Wire protocol assertions generated by 'wirecheck'
724 * running on Linux robert.bartonsoftware.com 2.6.8-1.521
725 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux
726 * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
730 BUILD_BUG_ON(LNET_PROTO_TCP_MAGIC != 0xeebc0ded);
731 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MAJOR != 1);
732 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MINOR != 0);
733 BUILD_BUG_ON(LNET_MSG_ACK != 0);
734 BUILD_BUG_ON(LNET_MSG_PUT != 1);
735 BUILD_BUG_ON(LNET_MSG_GET != 2);
736 BUILD_BUG_ON(LNET_MSG_REPLY != 3);
737 BUILD_BUG_ON(LNET_MSG_HELLO != 4);
739 BUILD_BUG_ON((int)sizeof(lnet_nid_t) != 8);
740 BUILD_BUG_ON((int)sizeof(lnet_pid_t) != 4);
742 /* Checks for struct lnet_process_id_packed */
743 BUILD_BUG_ON((int)sizeof(struct lnet_process_id_packed) != 12);
744 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, nid) != 0);
745 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->nid) != 8);
746 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, pid) != 8);
747 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->pid) != 4);
749 /* Checks for struct lnet_handle_wire */
750 BUILD_BUG_ON((int)sizeof(struct lnet_handle_wire) != 16);
751 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
752 wh_interface_cookie) != 0);
753 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_interface_cookie) != 8);
754 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
755 wh_object_cookie) != 8);
756 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_object_cookie) != 8);
758 /* Checks for struct struct lnet_magicversion */
759 BUILD_BUG_ON((int)sizeof(struct lnet_magicversion) != 8);
760 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, magic) != 0);
761 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->magic) != 4);
762 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, version_major) != 4);
763 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_major) != 2);
764 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion,
765 version_minor) != 6);
766 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_minor) != 2);
768 /* Checks for struct struct lnet_hdr */
769 BUILD_BUG_ON((int)sizeof(struct lnet_hdr) != 72);
770 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, dest_nid) != 0);
771 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->dest_nid) != 8);
772 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, src_nid) != 8);
773 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->src_nid) != 8);
774 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, dest_pid) != 16);
775 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->dest_pid) != 4);
776 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, src_pid) != 20);
777 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->src_pid) != 4);
778 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, type) != 24);
779 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->type) != 4);
780 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, payload_length) != 28);
781 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->payload_length) != 4);
782 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg) != 32);
783 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg) != 40);
786 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.dst_wmd) != 32);
787 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.dst_wmd) != 16);
788 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.match_bits) != 48);
789 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.match_bits) != 8);
790 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.mlength) != 56);
791 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.mlength) != 4);
794 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.ack_wmd) != 32);
795 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.ack_wmd) != 16);
796 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.match_bits) != 48);
797 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.match_bits) != 8);
798 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.hdr_data) != 56);
799 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.hdr_data) != 8);
800 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.ptl_index) != 64);
801 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.ptl_index) != 4);
802 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.offset) != 68);
803 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.offset) != 4);
806 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.return_wmd) != 32);
807 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.return_wmd) != 16);
808 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.match_bits) != 48);
809 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.match_bits) != 8);
810 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.ptl_index) != 56);
811 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.ptl_index) != 4);
812 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.src_offset) != 60);
813 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.src_offset) != 4);
814 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.sink_length) != 64);
815 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.sink_length) != 4);
818 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.reply.dst_wmd) != 32);
819 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.reply.dst_wmd) != 16);
822 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.hello.incarnation) != 32);
823 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.hello.incarnation) != 8);
824 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.hello.type) != 40);
825 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.hello.type) != 4);
827 /* Checks for struct lnet_ni_status and related constants */
828 BUILD_BUG_ON(LNET_NI_STATUS_INVALID != 0x00000000);
829 BUILD_BUG_ON(LNET_NI_STATUS_UP != 0x15aac0de);
830 BUILD_BUG_ON(LNET_NI_STATUS_DOWN != 0xdeadface);
832 /* Checks for struct lnet_ni_status */
833 BUILD_BUG_ON((int)sizeof(struct lnet_ni_status) != 16);
834 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_nid) != 0);
835 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_nid) != 8);
836 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_status) != 8);
837 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_status) != 4);
838 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_unused) != 12);
839 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_unused) != 4);
841 /* Checks for struct lnet_ping_info and related constants */
842 BUILD_BUG_ON(LNET_PROTO_PING_MAGIC != 0x70696E67);
843 BUILD_BUG_ON(LNET_PING_FEAT_INVAL != 0);
844 BUILD_BUG_ON(LNET_PING_FEAT_BASE != 1);
845 BUILD_BUG_ON(LNET_PING_FEAT_NI_STATUS != 2);
846 BUILD_BUG_ON(LNET_PING_FEAT_RTE_DISABLED != 4);
847 BUILD_BUG_ON(LNET_PING_FEAT_MULTI_RAIL != 8);
848 BUILD_BUG_ON(LNET_PING_FEAT_DISCOVERY != 16);
849 BUILD_BUG_ON(LNET_PING_FEAT_BITS != 31);
851 /* Checks for struct lnet_ping_info */
852 BUILD_BUG_ON((int)sizeof(struct lnet_ping_info) != 16);
853 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_magic) != 0);
854 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_magic) != 4);
855 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_features) != 4);
856 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_features) != 4);
857 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_pid) != 8);
858 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_pid) != 4);
859 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_nnis) != 12);
860 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_nnis) != 4);
861 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_ni) != 16);
862 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_ni) != 0);
864 /* Acceptor connection request */
865 BUILD_BUG_ON(LNET_PROTO_ACCEPTOR_VERSION != 1);
867 /* Checks for struct lnet_acceptor_connreq */
868 BUILD_BUG_ON((int)sizeof(struct lnet_acceptor_connreq) != 16);
869 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_magic) != 0);
870 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_magic) != 4);
871 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_version) != 4);
872 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_version) != 4);
873 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_nid) != 8);
874 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_nid) != 8);
876 /* Checks for struct lnet_counters_common */
877 BUILD_BUG_ON((int)sizeof(struct lnet_counters_common) != 60);
878 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_alloc) != 0);
879 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_alloc) != 4);
880 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_max) != 4);
881 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_max) != 4);
882 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_errors) != 8);
883 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_errors) != 4);
884 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_count) != 12);
885 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_count) != 4);
886 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_count) != 16);
887 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_count) != 4);
888 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_count) != 20);
889 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_count) != 4);
890 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_count) != 24);
891 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_count) != 4);
892 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_length) != 28);
893 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_length) != 8);
894 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_length) != 36);
895 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_length) != 8);
896 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_length) != 44);
897 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_length) != 8);
898 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_length) != 52);
899 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_length) != 8);
902 static const struct lnet_lnd *lnet_find_lnd_by_type(__u32 type)
904 const struct lnet_lnd *lnd;
906 /* holding lnd mutex */
907 if (type >= NUM_LNDS)
909 lnd = the_lnet.ln_lnds[type];
910 LASSERT(!lnd || lnd->lnd_type == type);
916 lnet_get_lnd_timeout(void)
918 return lnet_lnd_timeout;
920 EXPORT_SYMBOL(lnet_get_lnd_timeout);
923 lnet_register_lnd(const struct lnet_lnd *lnd)
925 mutex_lock(&the_lnet.ln_lnd_mutex);
927 LASSERT(libcfs_isknown_lnd(lnd->lnd_type));
928 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
930 the_lnet.ln_lnds[lnd->lnd_type] = lnd;
932 CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type));
934 mutex_unlock(&the_lnet.ln_lnd_mutex);
936 EXPORT_SYMBOL(lnet_register_lnd);
939 lnet_unregister_lnd(const struct lnet_lnd *lnd)
941 mutex_lock(&the_lnet.ln_lnd_mutex);
943 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
945 the_lnet.ln_lnds[lnd->lnd_type] = NULL;
946 CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type));
948 mutex_unlock(&the_lnet.ln_lnd_mutex);
950 EXPORT_SYMBOL(lnet_unregister_lnd);
953 lnet_counters_get_common_locked(struct lnet_counters_common *common)
955 struct lnet_counters *ctr;
958 /* FIXME !!! Their is no assert_lnet_net_locked() to ensure this
959 * actually called under the protection of the lnet_net_lock.
961 memset(common, 0, sizeof(*common));
963 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
964 common->lcc_msgs_max += ctr->lct_common.lcc_msgs_max;
965 common->lcc_msgs_alloc += ctr->lct_common.lcc_msgs_alloc;
966 common->lcc_errors += ctr->lct_common.lcc_errors;
967 common->lcc_send_count += ctr->lct_common.lcc_send_count;
968 common->lcc_recv_count += ctr->lct_common.lcc_recv_count;
969 common->lcc_route_count += ctr->lct_common.lcc_route_count;
970 common->lcc_drop_count += ctr->lct_common.lcc_drop_count;
971 common->lcc_send_length += ctr->lct_common.lcc_send_length;
972 common->lcc_recv_length += ctr->lct_common.lcc_recv_length;
973 common->lcc_route_length += ctr->lct_common.lcc_route_length;
974 common->lcc_drop_length += ctr->lct_common.lcc_drop_length;
979 lnet_counters_get_common(struct lnet_counters_common *common)
981 lnet_net_lock(LNET_LOCK_EX);
982 lnet_counters_get_common_locked(common);
983 lnet_net_unlock(LNET_LOCK_EX);
985 EXPORT_SYMBOL(lnet_counters_get_common);
988 lnet_counters_get(struct lnet_counters *counters)
990 struct lnet_counters *ctr;
991 struct lnet_counters_health *health = &counters->lct_health;
994 memset(counters, 0, sizeof(*counters));
996 lnet_net_lock(LNET_LOCK_EX);
998 if (the_lnet.ln_state != LNET_STATE_RUNNING)
999 GOTO(out_unlock, rc = -ENODEV);
1001 lnet_counters_get_common_locked(&counters->lct_common);
1003 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
1004 health->lch_rst_alloc += ctr->lct_health.lch_rst_alloc;
1005 health->lch_resend_count += ctr->lct_health.lch_resend_count;
1006 health->lch_response_timeout_count +=
1007 ctr->lct_health.lch_response_timeout_count;
1008 health->lch_local_interrupt_count +=
1009 ctr->lct_health.lch_local_interrupt_count;
1010 health->lch_local_dropped_count +=
1011 ctr->lct_health.lch_local_dropped_count;
1012 health->lch_local_aborted_count +=
1013 ctr->lct_health.lch_local_aborted_count;
1014 health->lch_local_no_route_count +=
1015 ctr->lct_health.lch_local_no_route_count;
1016 health->lch_local_timeout_count +=
1017 ctr->lct_health.lch_local_timeout_count;
1018 health->lch_local_error_count +=
1019 ctr->lct_health.lch_local_error_count;
1020 health->lch_remote_dropped_count +=
1021 ctr->lct_health.lch_remote_dropped_count;
1022 health->lch_remote_error_count +=
1023 ctr->lct_health.lch_remote_error_count;
1024 health->lch_remote_timeout_count +=
1025 ctr->lct_health.lch_remote_timeout_count;
1026 health->lch_network_timeout_count +=
1027 ctr->lct_health.lch_network_timeout_count;
1030 lnet_net_unlock(LNET_LOCK_EX);
1033 EXPORT_SYMBOL(lnet_counters_get);
1036 lnet_counters_reset(void)
1038 struct lnet_counters *counters;
1041 lnet_net_lock(LNET_LOCK_EX);
1043 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1046 cfs_percpt_for_each(counters, i, the_lnet.ln_counters)
1047 memset(counters, 0, sizeof(struct lnet_counters));
1049 lnet_net_unlock(LNET_LOCK_EX);
1053 lnet_res_type2str(int type)
1058 case LNET_COOKIE_TYPE_MD:
1060 case LNET_COOKIE_TYPE_ME:
1062 case LNET_COOKIE_TYPE_EQ:
1068 lnet_res_container_cleanup(struct lnet_res_container *rec)
1072 if (rec->rec_type == 0) /* not set yet, it's uninitialized */
1075 while (!list_empty(&rec->rec_active)) {
1076 struct list_head *e = rec->rec_active.next;
1079 if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
1080 lnet_md_free(list_entry(e, struct lnet_libmd, md_list));
1082 } else { /* NB: Active MEs should be attached on portals */
1089 /* Found alive MD/ME/EQ, user really should unlink/free
1090 * all of them before finalize LNet, but if someone didn't,
1091 * we have to recycle garbage for him */
1092 CERROR("%d active elements on exit of %s container\n",
1093 count, lnet_res_type2str(rec->rec_type));
1096 if (rec->rec_lh_hash != NULL) {
1097 CFS_FREE_PTR_ARRAY(rec->rec_lh_hash, LNET_LH_HASH_SIZE);
1098 rec->rec_lh_hash = NULL;
1101 rec->rec_type = 0; /* mark it as finalized */
1105 lnet_res_container_setup(struct lnet_res_container *rec, int cpt, int type)
1110 LASSERT(rec->rec_type == 0);
1112 rec->rec_type = type;
1113 INIT_LIST_HEAD(&rec->rec_active);
1115 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type;
1117 /* Arbitrary choice of hash table size */
1118 LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt,
1119 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
1120 if (rec->rec_lh_hash == NULL) {
1125 for (i = 0; i < LNET_LH_HASH_SIZE; i++)
1126 INIT_LIST_HEAD(&rec->rec_lh_hash[i]);
1131 CERROR("Failed to setup %s resource container\n",
1132 lnet_res_type2str(type));
1133 lnet_res_container_cleanup(rec);
1138 lnet_res_containers_destroy(struct lnet_res_container **recs)
1140 struct lnet_res_container *rec;
1143 cfs_percpt_for_each(rec, i, recs)
1144 lnet_res_container_cleanup(rec);
1146 cfs_percpt_free(recs);
1149 static struct lnet_res_container **
1150 lnet_res_containers_create(int type)
1152 struct lnet_res_container **recs;
1153 struct lnet_res_container *rec;
1157 recs = cfs_percpt_alloc(lnet_cpt_table(), sizeof(*rec));
1159 CERROR("Failed to allocate %s resource containers\n",
1160 lnet_res_type2str(type));
1164 cfs_percpt_for_each(rec, i, recs) {
1165 rc = lnet_res_container_setup(rec, i, type);
1167 lnet_res_containers_destroy(recs);
1175 struct lnet_libhandle *
1176 lnet_res_lh_lookup(struct lnet_res_container *rec, __u64 cookie)
1178 /* ALWAYS called with lnet_res_lock held */
1179 struct list_head *head;
1180 struct lnet_libhandle *lh;
1183 if ((cookie & LNET_COOKIE_MASK) != rec->rec_type)
1186 hash = cookie >> (LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS);
1187 head = &rec->rec_lh_hash[hash & LNET_LH_HASH_MASK];
1189 list_for_each_entry(lh, head, lh_hash_chain) {
1190 if (lh->lh_cookie == cookie)
1198 lnet_res_lh_initialize(struct lnet_res_container *rec,
1199 struct lnet_libhandle *lh)
1201 /* ALWAYS called with lnet_res_lock held */
1202 unsigned int ibits = LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS;
1205 lh->lh_cookie = rec->rec_lh_cookie;
1206 rec->rec_lh_cookie += 1 << ibits;
1208 hash = (lh->lh_cookie >> ibits) & LNET_LH_HASH_MASK;
1210 list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
1214 lnet_create_array_of_queues(void)
1216 struct list_head **qs;
1217 struct list_head *q;
1220 qs = cfs_percpt_alloc(lnet_cpt_table(),
1221 sizeof(struct list_head));
1223 CERROR("Failed to allocate queues\n");
1227 cfs_percpt_for_each(q, i, qs)
1233 static int lnet_unprepare(void);
1236 lnet_prepare(lnet_pid_t requested_pid)
1238 /* Prepare to bring up the network */
1239 struct lnet_res_container **recs;
1242 if (requested_pid == LNET_PID_ANY) {
1243 /* Don't instantiate LNET just for me */
1247 LASSERT(the_lnet.ln_refcount == 0);
1249 the_lnet.ln_routing = 0;
1251 LASSERT((requested_pid & LNET_PID_USERFLAG) == 0);
1252 the_lnet.ln_pid = requested_pid;
1254 INIT_LIST_HEAD(&the_lnet.ln_test_peers);
1255 INIT_LIST_HEAD(&the_lnet.ln_remote_peer_ni_list);
1256 INIT_LIST_HEAD(&the_lnet.ln_nets);
1257 INIT_LIST_HEAD(&the_lnet.ln_routers);
1258 INIT_LIST_HEAD(&the_lnet.ln_drop_rules);
1259 INIT_LIST_HEAD(&the_lnet.ln_delay_rules);
1260 INIT_LIST_HEAD(&the_lnet.ln_dc_request);
1261 INIT_LIST_HEAD(&the_lnet.ln_dc_working);
1262 INIT_LIST_HEAD(&the_lnet.ln_dc_expired);
1263 INIT_LIST_HEAD(&the_lnet.ln_mt_localNIRecovq);
1264 INIT_LIST_HEAD(&the_lnet.ln_mt_peerNIRecovq);
1265 INIT_LIST_HEAD(&the_lnet.ln_udsp_list);
1266 init_waitqueue_head(&the_lnet.ln_dc_waitq);
1267 the_lnet.ln_mt_handler = NULL;
1268 init_completion(&the_lnet.ln_started);
1270 rc = lnet_slab_setup();
1274 rc = lnet_create_remote_nets_table();
1279 * NB the interface cookie in wire handles guards against delayed
1280 * replies and ACKs appearing valid after reboot.
1282 the_lnet.ln_interface_cookie = ktime_get_real_ns();
1284 the_lnet.ln_counters = cfs_percpt_alloc(lnet_cpt_table(),
1285 sizeof(struct lnet_counters));
1286 if (the_lnet.ln_counters == NULL) {
1287 CERROR("Failed to allocate counters for LNet\n");
1292 rc = lnet_peer_tables_create();
1296 rc = lnet_msg_containers_create();
1300 rc = lnet_res_container_setup(&the_lnet.ln_eq_container, 0,
1301 LNET_COOKIE_TYPE_EQ);
1305 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD);
1311 the_lnet.ln_md_containers = recs;
1313 rc = lnet_portals_create();
1315 CERROR("Failed to create portals for LNet: %d\n", rc);
1319 the_lnet.ln_mt_zombie_rstqs = lnet_create_array_of_queues();
1320 if (!the_lnet.ln_mt_zombie_rstqs) {
1333 lnet_unprepare (void)
1335 /* NB no LNET_LOCK since this is the last reference. All LND instances
1336 * have shut down already, so it is safe to unlink and free all
1337 * descriptors, even those that appear committed to a network op (eg MD
1338 * with non-zero pending count) */
1340 lnet_fail_nid(LNET_NID_ANY, 0);
1342 LASSERT(the_lnet.ln_refcount == 0);
1343 LASSERT(list_empty(&the_lnet.ln_test_peers));
1344 LASSERT(list_empty(&the_lnet.ln_nets));
1346 if (the_lnet.ln_mt_zombie_rstqs) {
1347 lnet_clean_zombie_rstqs();
1348 the_lnet.ln_mt_zombie_rstqs = NULL;
1351 lnet_assert_handler_unused(the_lnet.ln_mt_handler);
1352 the_lnet.ln_mt_handler = NULL;
1354 lnet_portals_destroy();
1356 if (the_lnet.ln_md_containers != NULL) {
1357 lnet_res_containers_destroy(the_lnet.ln_md_containers);
1358 the_lnet.ln_md_containers = NULL;
1361 lnet_res_container_cleanup(&the_lnet.ln_eq_container);
1363 lnet_msg_containers_destroy();
1365 lnet_rtrpools_free(0);
1367 if (the_lnet.ln_counters != NULL) {
1368 cfs_percpt_free(the_lnet.ln_counters);
1369 the_lnet.ln_counters = NULL;
1371 lnet_destroy_remote_nets_table();
1372 lnet_udsp_destroy(true);
1373 lnet_slab_cleanup();
1379 lnet_net2ni_locked(__u32 net_id, int cpt)
1382 struct lnet_net *net;
1384 LASSERT(cpt != LNET_LOCK_EX);
1386 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1387 if (net->net_id == net_id) {
1388 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
1398 lnet_net2ni_addref(__u32 net)
1403 ni = lnet_net2ni_locked(net, 0);
1405 lnet_ni_addref_locked(ni, 0);
1410 EXPORT_SYMBOL(lnet_net2ni_addref);
1413 lnet_get_net_locked(__u32 net_id)
1415 struct lnet_net *net;
1417 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1418 if (net->net_id == net_id)
1426 lnet_net_clr_pref_rtrs(struct lnet_net *net)
1428 struct list_head zombies;
1429 struct lnet_nid_list *ne;
1430 struct lnet_nid_list *tmp;
1432 INIT_LIST_HEAD(&zombies);
1434 lnet_net_lock(LNET_LOCK_EX);
1435 list_splice_init(&net->net_rtr_pref_nids, &zombies);
1436 lnet_net_unlock(LNET_LOCK_EX);
1438 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1439 list_del_init(&ne->nl_list);
1440 LIBCFS_FREE(ne, sizeof(*ne));
1445 lnet_net_add_pref_rtr(struct lnet_net *net,
1447 __must_hold(&the_lnet.ln_api_mutex)
1449 struct lnet_nid_list *ne;
1451 /* This function is called with api_mutex held. When the api_mutex
1452 * is held the list can not be modified, as it is only modified as
1453 * a result of applying a UDSP and that happens under api_mutex
1456 list_for_each_entry(ne, &net->net_rtr_pref_nids, nl_list) {
1457 if (ne->nl_nid == gw_nid)
1461 LIBCFS_ALLOC(ne, sizeof(*ne));
1465 ne->nl_nid = gw_nid;
1467 /* Lock the cpt to protect against addition and checks in the
1468 * selection algorithm
1470 lnet_net_lock(LNET_LOCK_EX);
1471 list_add(&ne->nl_list, &net->net_rtr_pref_nids);
1472 lnet_net_unlock(LNET_LOCK_EX);
1478 lnet_net_is_pref_rtr_locked(struct lnet_net *net, lnet_nid_t rtr_nid)
1480 struct lnet_nid_list *ne;
1482 CDEBUG(D_NET, "%s: rtr pref emtpy: %d\n",
1483 libcfs_net2str(net->net_id),
1484 list_empty(&net->net_rtr_pref_nids));
1486 if (list_empty(&net->net_rtr_pref_nids))
1489 list_for_each_entry(ne, &net->net_rtr_pref_nids, nl_list) {
1490 CDEBUG(D_NET, "Comparing pref %s with gw %s\n",
1491 libcfs_nid2str(ne->nl_nid),
1492 libcfs_nid2str(rtr_nid));
1493 if (rtr_nid == ne->nl_nid)
1501 lnet_nid_cpt_hash(lnet_nid_t nid, unsigned int number)
1506 LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
1511 val = hash_long(key, LNET_CPT_BITS);
1512 /* NB: LNET_CP_NUMBER doesn't have to be PO2 */
1516 return (unsigned int)(key + val + (val >> 1)) % number;
1520 lnet_cpt_of_nid_locked(lnet_nid_t nid, struct lnet_ni *ni)
1522 struct lnet_net *net;
1524 /* must called with hold of lnet_net_lock */
1525 if (LNET_CPT_NUMBER == 1)
1526 return 0; /* the only one */
1529 * If NI is provided then use the CPT identified in the NI cpt
1530 * list if one exists. If one doesn't exist, then that NI is
1531 * associated with all CPTs and it follows that the net it belongs
1532 * to is implicitly associated with all CPTs, so just hash the nid
1536 if (ni->ni_cpts != NULL)
1537 return ni->ni_cpts[lnet_nid_cpt_hash(nid,
1540 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1543 /* no NI provided so look at the net */
1544 net = lnet_get_net_locked(LNET_NIDNET(nid));
1546 if (net != NULL && net->net_cpts != NULL) {
1547 return net->net_cpts[lnet_nid_cpt_hash(nid, net->net_ncpts)];
1550 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1554 lnet_cpt_of_nid(lnet_nid_t nid, struct lnet_ni *ni)
1559 if (LNET_CPT_NUMBER == 1)
1560 return 0; /* the only one */
1562 cpt = lnet_net_lock_current();
1564 cpt2 = lnet_cpt_of_nid_locked(nid, ni);
1566 lnet_net_unlock(cpt);
1570 EXPORT_SYMBOL(lnet_cpt_of_nid);
1573 lnet_islocalnet_locked(__u32 net_id)
1575 struct lnet_net *net;
1578 net = lnet_get_net_locked(net_id);
1580 local = net != NULL;
1586 lnet_islocalnet(__u32 net_id)
1591 cpt = lnet_net_lock_current();
1593 local = lnet_islocalnet_locked(net_id);
1595 lnet_net_unlock(cpt);
1601 lnet_nid2ni_locked(lnet_nid_t nid, int cpt)
1603 struct lnet_net *net;
1606 LASSERT(cpt != LNET_LOCK_EX);
1608 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1609 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1610 if (ni->ni_nid == nid)
1619 lnet_nid2ni_addref(lnet_nid_t nid)
1624 ni = lnet_nid2ni_locked(nid, 0);
1626 lnet_ni_addref_locked(ni, 0);
1631 EXPORT_SYMBOL(lnet_nid2ni_addref);
1634 lnet_islocalnid(lnet_nid_t nid)
1639 cpt = lnet_net_lock_current();
1640 ni = lnet_nid2ni_locked(nid, cpt);
1641 lnet_net_unlock(cpt);
1647 lnet_count_acceptor_nets(void)
1649 /* Return the # of NIs that need the acceptor. */
1651 struct lnet_net *net;
1654 cpt = lnet_net_lock_current();
1655 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1656 /* all socklnd type networks should have the acceptor
1658 if (net->net_lnd->lnd_accept != NULL)
1662 lnet_net_unlock(cpt);
1667 struct lnet_ping_buffer *
1668 lnet_ping_buffer_alloc(int nnis, gfp_t gfp)
1670 struct lnet_ping_buffer *pbuf;
1672 LIBCFS_ALLOC_GFP(pbuf, LNET_PING_BUFFER_SIZE(nnis), gfp);
1674 pbuf->pb_nnis = nnis;
1675 pbuf->pb_needs_post = false;
1676 atomic_set(&pbuf->pb_refcnt, 1);
1683 lnet_ping_buffer_free(struct lnet_ping_buffer *pbuf)
1685 LASSERT(atomic_read(&pbuf->pb_refcnt) == 0);
1686 LIBCFS_FREE(pbuf, LNET_PING_BUFFER_SIZE(pbuf->pb_nnis));
1689 static struct lnet_ping_buffer *
1690 lnet_ping_target_create(int nnis)
1692 struct lnet_ping_buffer *pbuf;
1694 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
1696 CERROR("Can't allocate ping source [%d]\n", nnis);
1700 pbuf->pb_info.pi_nnis = nnis;
1701 pbuf->pb_info.pi_pid = the_lnet.ln_pid;
1702 pbuf->pb_info.pi_magic = LNET_PROTO_PING_MAGIC;
1703 pbuf->pb_info.pi_features =
1704 LNET_PING_FEAT_NI_STATUS | LNET_PING_FEAT_MULTI_RAIL;
1710 lnet_get_net_ni_count_locked(struct lnet_net *net)
1715 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1722 lnet_get_net_ni_count_pre(struct lnet_net *net)
1727 list_for_each_entry(ni, &net->net_ni_added, ni_netlist)
1734 lnet_get_ni_count(void)
1737 struct lnet_net *net;
1742 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1743 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1753 lnet_swap_pinginfo(struct lnet_ping_buffer *pbuf)
1755 struct lnet_ni_status *stat;
1759 __swab32s(&pbuf->pb_info.pi_magic);
1760 __swab32s(&pbuf->pb_info.pi_features);
1761 __swab32s(&pbuf->pb_info.pi_pid);
1762 __swab32s(&pbuf->pb_info.pi_nnis);
1763 nnis = pbuf->pb_info.pi_nnis;
1764 if (nnis > pbuf->pb_nnis)
1765 nnis = pbuf->pb_nnis;
1766 for (i = 0; i < nnis; i++) {
1767 stat = &pbuf->pb_info.pi_ni[i];
1768 __swab64s(&stat->ns_nid);
1769 __swab32s(&stat->ns_status);
1774 lnet_ping_info_validate(struct lnet_ping_info *pinfo)
1778 if (pinfo->pi_magic != LNET_PROTO_PING_MAGIC)
1780 if (!(pinfo->pi_features & LNET_PING_FEAT_NI_STATUS))
1782 /* Loopback is guaranteed to be present */
1783 if (pinfo->pi_nnis < 1 || pinfo->pi_nnis > lnet_interfaces_max)
1785 if (LNET_PING_INFO_LONI(pinfo) != LNET_NID_LO_0)
1791 lnet_ping_target_destroy(void)
1793 struct lnet_net *net;
1796 lnet_net_lock(LNET_LOCK_EX);
1798 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1799 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1801 ni->ni_status = NULL;
1806 lnet_ping_buffer_decref(the_lnet.ln_ping_target);
1807 the_lnet.ln_ping_target = NULL;
1809 lnet_net_unlock(LNET_LOCK_EX);
1813 lnet_ping_target_event_handler(struct lnet_event *event)
1815 struct lnet_ping_buffer *pbuf = event->md_user_ptr;
1817 if (event->unlinked)
1818 lnet_ping_buffer_decref(pbuf);
1822 lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
1823 struct lnet_handle_md *ping_mdh,
1824 int ni_count, bool set_eq)
1826 struct lnet_process_id id = {
1827 .nid = LNET_NID_ANY,
1831 struct lnet_md md = { NULL };
1835 the_lnet.ln_ping_target_handler =
1836 lnet_ping_target_event_handler;
1838 *ppbuf = lnet_ping_target_create(ni_count);
1839 if (*ppbuf == NULL) {
1844 /* Ping target ME/MD */
1845 me = LNetMEAttach(LNET_RESERVED_PORTAL, id,
1846 LNET_PROTO_PING_MATCHBITS, 0,
1847 LNET_UNLINK, LNET_INS_AFTER);
1850 CERROR("Can't create ping target ME: %d\n", rc);
1851 goto fail_decref_ping_buffer;
1854 /* initialize md content */
1855 md.start = &(*ppbuf)->pb_info;
1856 md.length = LNET_PING_INFO_SIZE((*ppbuf)->pb_nnis);
1857 md.threshold = LNET_MD_THRESH_INF;
1859 md.options = LNET_MD_OP_GET | LNET_MD_TRUNCATE |
1860 LNET_MD_MANAGE_REMOTE;
1861 md.handler = the_lnet.ln_ping_target_handler;
1862 md.user_ptr = *ppbuf;
1864 rc = LNetMDAttach(me, &md, LNET_RETAIN, ping_mdh);
1866 CERROR("Can't attach ping target MD: %d\n", rc);
1867 goto fail_decref_ping_buffer;
1869 lnet_ping_buffer_addref(*ppbuf);
1873 fail_decref_ping_buffer:
1874 LASSERT(atomic_read(&(*ppbuf)->pb_refcnt) == 1);
1875 lnet_ping_buffer_decref(*ppbuf);
1882 lnet_ping_md_unlink(struct lnet_ping_buffer *pbuf,
1883 struct lnet_handle_md *ping_mdh)
1885 LNetMDUnlink(*ping_mdh);
1886 LNetInvalidateMDHandle(ping_mdh);
1888 /* NB the MD could be busy; this just starts the unlink */
1889 wait_var_event_warning(&pbuf->pb_refcnt,
1890 atomic_read(&pbuf->pb_refcnt) <= 1,
1891 "Still waiting for ping data MD to unlink\n");
1895 lnet_ping_target_install_locked(struct lnet_ping_buffer *pbuf)
1898 struct lnet_net *net;
1899 struct lnet_ni_status *ns;
1904 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1905 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1906 LASSERT(i < pbuf->pb_nnis);
1908 ns = &pbuf->pb_info.pi_ni[i];
1910 ns->ns_nid = ni->ni_nid;
1913 ns->ns_status = (ni->ni_status != NULL) ?
1914 ni->ni_status->ns_status :
1923 * We (ab)use the ns_status of the loopback interface to
1924 * transmit the sequence number. The first interface listed
1925 * must be the loopback interface.
1927 rc = lnet_ping_info_validate(&pbuf->pb_info);
1929 LCONSOLE_EMERG("Invalid ping target: %d\n", rc);
1932 LNET_PING_BUFFER_SEQNO(pbuf) =
1933 atomic_inc_return(&the_lnet.ln_ping_target_seqno);
1937 lnet_ping_target_update(struct lnet_ping_buffer *pbuf,
1938 struct lnet_handle_md ping_mdh)
1940 struct lnet_ping_buffer *old_pbuf = NULL;
1941 struct lnet_handle_md old_ping_md;
1943 /* switch the NIs to point to the new ping info created */
1944 lnet_net_lock(LNET_LOCK_EX);
1946 if (!the_lnet.ln_routing)
1947 pbuf->pb_info.pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1948 if (!lnet_peer_discovery_disabled)
1949 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
1951 /* Ensure only known feature bits have been set. */
1952 LASSERT(pbuf->pb_info.pi_features & LNET_PING_FEAT_BITS);
1953 LASSERT(!(pbuf->pb_info.pi_features & ~LNET_PING_FEAT_BITS));
1955 lnet_ping_target_install_locked(pbuf);
1957 if (the_lnet.ln_ping_target) {
1958 old_pbuf = the_lnet.ln_ping_target;
1959 old_ping_md = the_lnet.ln_ping_target_md;
1961 the_lnet.ln_ping_target_md = ping_mdh;
1962 the_lnet.ln_ping_target = pbuf;
1964 lnet_net_unlock(LNET_LOCK_EX);
1967 /* unlink and free the old ping info */
1968 lnet_ping_md_unlink(old_pbuf, &old_ping_md);
1969 lnet_ping_buffer_decref(old_pbuf);
1972 lnet_push_update_to_peers(0);
1976 lnet_ping_target_fini(void)
1978 lnet_ping_md_unlink(the_lnet.ln_ping_target,
1979 &the_lnet.ln_ping_target_md);
1981 lnet_assert_handler_unused(the_lnet.ln_ping_target_handler);
1982 lnet_ping_target_destroy();
1985 /* Resize the push target. */
1986 int lnet_push_target_resize(void)
1988 struct lnet_handle_md mdh;
1989 struct lnet_handle_md old_mdh;
1990 struct lnet_ping_buffer *pbuf;
1991 struct lnet_ping_buffer *old_pbuf;
1996 nnis = the_lnet.ln_push_target_nnis;
1998 CDEBUG(D_NET, "Invalid nnis %d\n", nnis);
2002 /* NB: lnet_ping_buffer_alloc() sets pbuf refcount to 1. That ref is
2003 * dropped when we need to resize again (see "old_pbuf" below) or when
2004 * LNet is shutdown (see lnet_push_target_fini())
2006 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
2008 CDEBUG(D_NET, "Can't allocate pbuf for nnis %d\n", nnis);
2012 rc = lnet_push_target_post(pbuf, &mdh);
2014 CDEBUG(D_NET, "Failed to post push target: %d\n", rc);
2015 lnet_ping_buffer_decref(pbuf);
2019 lnet_net_lock(LNET_LOCK_EX);
2020 old_pbuf = the_lnet.ln_push_target;
2021 old_mdh = the_lnet.ln_push_target_md;
2022 the_lnet.ln_push_target = pbuf;
2023 the_lnet.ln_push_target_md = mdh;
2024 lnet_net_unlock(LNET_LOCK_EX);
2027 LNetMDUnlink(old_mdh);
2028 /* Drop ref set by lnet_ping_buffer_alloc() */
2029 lnet_ping_buffer_decref(old_pbuf);
2032 /* Received another push or reply that requires a larger buffer */
2033 if (nnis < the_lnet.ln_push_target_nnis)
2036 CDEBUG(D_NET, "nnis %d success\n", nnis);
2040 int lnet_push_target_post(struct lnet_ping_buffer *pbuf,
2041 struct lnet_handle_md *mdhp)
2043 struct lnet_process_id id = { LNET_NID_ANY, LNET_PID_ANY };
2044 struct lnet_md md = { NULL };
2048 me = LNetMEAttach(LNET_RESERVED_PORTAL, id,
2049 LNET_PROTO_PING_MATCHBITS, 0,
2050 LNET_UNLINK, LNET_INS_AFTER);
2053 CERROR("Can't create push target ME: %d\n", rc);
2057 pbuf->pb_needs_post = false;
2059 /* This reference is dropped by lnet_push_target_event_handler() */
2060 lnet_ping_buffer_addref(pbuf);
2062 /* initialize md content */
2063 md.start = &pbuf->pb_info;
2064 md.length = LNET_PING_INFO_SIZE(pbuf->pb_nnis);
2067 md.options = LNET_MD_OP_PUT | LNET_MD_TRUNCATE;
2069 md.handler = the_lnet.ln_push_target_handler;
2071 rc = LNetMDAttach(me, &md, LNET_UNLINK, mdhp);
2073 CERROR("Can't attach push MD: %d\n", rc);
2074 lnet_ping_buffer_decref(pbuf);
2075 pbuf->pb_needs_post = true;
2079 CDEBUG(D_NET, "posted push target %p\n", pbuf);
2084 static void lnet_push_target_event_handler(struct lnet_event *ev)
2086 struct lnet_ping_buffer *pbuf = ev->md_user_ptr;
2088 CDEBUG(D_NET, "type %d status %d unlinked %d\n", ev->type, ev->status,
2091 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
2092 lnet_swap_pinginfo(pbuf);
2094 if (ev->type == LNET_EVENT_UNLINK) {
2095 /* Drop ref added by lnet_push_target_post() */
2096 lnet_ping_buffer_decref(pbuf);
2100 lnet_peer_push_event(ev);
2102 /* Drop ref added by lnet_push_target_post */
2103 lnet_ping_buffer_decref(pbuf);
2106 /* Initialize the push target. */
2107 static int lnet_push_target_init(void)
2111 if (the_lnet.ln_push_target)
2114 the_lnet.ln_push_target_handler =
2115 lnet_push_target_event_handler;
2117 rc = LNetSetLazyPortal(LNET_RESERVED_PORTAL);
2120 /* Start at the required minimum, we'll enlarge if required. */
2121 the_lnet.ln_push_target_nnis = LNET_INTERFACES_MIN;
2123 rc = lnet_push_target_resize();
2126 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2127 the_lnet.ln_push_target_handler = NULL;
2133 /* Clean up the push target. */
2134 static void lnet_push_target_fini(void)
2136 if (!the_lnet.ln_push_target)
2139 /* Unlink and invalidate to prevent new references. */
2140 LNetMDUnlink(the_lnet.ln_push_target_md);
2141 LNetInvalidateMDHandle(&the_lnet.ln_push_target_md);
2143 /* Wait for the unlink to complete. */
2144 wait_var_event_warning(&the_lnet.ln_push_target->pb_refcnt,
2145 atomic_read(&the_lnet.ln_push_target->pb_refcnt) <= 1,
2146 "Still waiting for ping data MD to unlink\n");
2148 /* Drop ref set by lnet_ping_buffer_alloc() */
2149 lnet_ping_buffer_decref(the_lnet.ln_push_target);
2150 the_lnet.ln_push_target = NULL;
2151 the_lnet.ln_push_target_nnis = 0;
2153 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2154 lnet_assert_handler_unused(the_lnet.ln_push_target_handler);
2155 the_lnet.ln_push_target_handler = NULL;
2159 lnet_ni_tq_credits(struct lnet_ni *ni)
2163 LASSERT(ni->ni_ncpts >= 1);
2165 if (ni->ni_ncpts == 1)
2166 return ni->ni_net->net_tunables.lct_max_tx_credits;
2168 credits = ni->ni_net->net_tunables.lct_max_tx_credits / ni->ni_ncpts;
2169 credits = max(credits, 8 * ni->ni_net->net_tunables.lct_peer_tx_credits);
2170 credits = min(credits, ni->ni_net->net_tunables.lct_max_tx_credits);
2176 lnet_ni_unlink_locked(struct lnet_ni *ni)
2178 /* move it to zombie list and nobody can find it anymore */
2179 LASSERT(!list_empty(&ni->ni_netlist));
2180 list_move(&ni->ni_netlist, &ni->ni_net->net_ni_zombie);
2181 lnet_ni_decref_locked(ni, 0);
2185 lnet_clear_zombies_nis_locked(struct lnet_net *net)
2190 struct list_head *zombie_list = &net->net_ni_zombie;
2193 * Now wait for the NIs I just nuked to show up on the zombie
2194 * list and shut them down in guaranteed thread context
2197 while (!list_empty(zombie_list)) {
2201 ni = list_entry(zombie_list->next,
2202 struct lnet_ni, ni_netlist);
2203 list_del_init(&ni->ni_netlist);
2204 /* the ni should be in deleting state. If it's not it's
2206 LASSERT(ni->ni_state == LNET_NI_STATE_DELETING);
2207 cfs_percpt_for_each(ref, j, ni->ni_refs) {
2210 /* still busy, add it back to zombie list */
2211 list_add(&ni->ni_netlist, zombie_list);
2215 if (!list_empty(&ni->ni_netlist)) {
2216 /* Unlock mutex while waiting to allow other
2217 * threads to read the LNet state and fall through
2220 lnet_net_unlock(LNET_LOCK_EX);
2221 mutex_unlock(&the_lnet.ln_api_mutex);
2224 if ((i & (-i)) == i) {
2226 "Waiting for zombie LNI %s\n",
2227 libcfs_nid2str(ni->ni_nid));
2229 schedule_timeout_uninterruptible(cfs_time_seconds(1));
2231 mutex_lock(&the_lnet.ln_api_mutex);
2232 lnet_net_lock(LNET_LOCK_EX);
2236 lnet_net_unlock(LNET_LOCK_EX);
2238 islo = ni->ni_net->net_lnd->lnd_type == LOLND;
2240 LASSERT(!in_interrupt());
2241 /* Holding the mutex makes it safe for lnd_shutdown
2242 * to call module_put(). Module unload cannot finish
2243 * until lnet_unregister_lnd() completes, and that
2244 * requires the mutex.
2246 mutex_lock(&the_lnet.ln_lnd_mutex);
2247 (net->net_lnd->lnd_shutdown)(ni);
2248 mutex_unlock(&the_lnet.ln_lnd_mutex);
2251 CDEBUG(D_LNI, "Removed LNI %s\n",
2252 libcfs_nid2str(ni->ni_nid));
2256 lnet_net_lock(LNET_LOCK_EX);
2260 /* shutdown down the NI and release refcount */
2262 lnet_shutdown_lndni(struct lnet_ni *ni)
2265 struct lnet_net *net = ni->ni_net;
2267 lnet_net_lock(LNET_LOCK_EX);
2269 ni->ni_state = LNET_NI_STATE_DELETING;
2271 lnet_ni_unlink_locked(ni);
2272 lnet_incr_dlc_seq();
2273 lnet_net_unlock(LNET_LOCK_EX);
2275 /* clear messages for this NI on the lazy portal */
2276 for (i = 0; i < the_lnet.ln_nportals; i++)
2277 lnet_clear_lazy_portal(ni, i, "Shutting down NI");
2279 lnet_net_lock(LNET_LOCK_EX);
2280 lnet_clear_zombies_nis_locked(net);
2281 lnet_net_unlock(LNET_LOCK_EX);
2285 lnet_shutdown_lndnet(struct lnet_net *net)
2289 lnet_net_lock(LNET_LOCK_EX);
2291 list_del_init(&net->net_list);
2293 while (!list_empty(&net->net_ni_list)) {
2294 ni = list_entry(net->net_ni_list.next,
2295 struct lnet_ni, ni_netlist);
2296 lnet_net_unlock(LNET_LOCK_EX);
2297 lnet_shutdown_lndni(ni);
2298 lnet_net_lock(LNET_LOCK_EX);
2301 lnet_net_unlock(LNET_LOCK_EX);
2303 /* Do peer table cleanup for this net */
2304 lnet_peer_tables_cleanup(net);
2310 lnet_shutdown_lndnets(void)
2312 struct lnet_net *net;
2314 struct lnet_msg *msg, *tmp;
2316 /* NB called holding the global mutex */
2318 /* All quiet on the API front */
2319 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
2320 LASSERT(the_lnet.ln_refcount == 0);
2322 lnet_net_lock(LNET_LOCK_EX);
2323 the_lnet.ln_state = LNET_STATE_STOPPING;
2326 * move the nets to the zombie list to avoid them being
2327 * picked up for new work. LONET is also included in the
2328 * Nets that will be moved to the zombie list
2330 list_splice_init(&the_lnet.ln_nets, &the_lnet.ln_net_zombie);
2332 /* Drop the cached loopback Net. */
2333 if (the_lnet.ln_loni != NULL) {
2334 lnet_ni_decref_locked(the_lnet.ln_loni, 0);
2335 the_lnet.ln_loni = NULL;
2337 lnet_net_unlock(LNET_LOCK_EX);
2339 /* iterate through the net zombie list and delete each net */
2340 while (!list_empty(&the_lnet.ln_net_zombie)) {
2341 net = list_entry(the_lnet.ln_net_zombie.next,
2342 struct lnet_net, net_list);
2343 lnet_shutdown_lndnet(net);
2346 spin_lock(&the_lnet.ln_msg_resend_lock);
2347 list_splice(&the_lnet.ln_msg_resend, &resend);
2348 spin_unlock(&the_lnet.ln_msg_resend_lock);
2350 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
2351 list_del_init(&msg->msg_list);
2352 msg->msg_no_resend = true;
2353 lnet_finalize(msg, -ECANCELED);
2356 lnet_net_lock(LNET_LOCK_EX);
2357 the_lnet.ln_state = LNET_STATE_SHUTDOWN;
2358 lnet_net_unlock(LNET_LOCK_EX);
2362 lnet_startup_lndni(struct lnet_ni *ni, struct lnet_lnd_tunables *tun)
2365 struct lnet_tx_queue *tq;
2367 struct lnet_net *net = ni->ni_net;
2369 mutex_lock(&the_lnet.ln_lnd_mutex);
2372 memcpy(&ni->ni_lnd_tunables, tun, sizeof(*tun));
2373 ni->ni_lnd_tunables_set = true;
2376 rc = (net->net_lnd->lnd_startup)(ni);
2378 mutex_unlock(&the_lnet.ln_lnd_mutex);
2381 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s\n",
2382 rc, libcfs_lnd2str(net->net_lnd->lnd_type));
2387 ni->ni_state = LNET_NI_STATE_ACTIVE;
2390 /* We keep a reference on the loopback net through the loopback NI */
2391 if (net->net_lnd->lnd_type == LOLND) {
2393 LASSERT(the_lnet.ln_loni == NULL);
2394 the_lnet.ln_loni = ni;
2395 ni->ni_net->net_tunables.lct_peer_tx_credits = 0;
2396 ni->ni_net->net_tunables.lct_peer_rtr_credits = 0;
2397 ni->ni_net->net_tunables.lct_max_tx_credits = 0;
2398 ni->ni_net->net_tunables.lct_peer_timeout = 0;
2402 if (ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ||
2403 ni->ni_net->net_tunables.lct_max_tx_credits == 0) {
2404 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
2405 libcfs_lnd2str(net->net_lnd->lnd_type),
2406 ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ?
2408 /* shutdown the NI since if we get here then it must've already
2411 lnet_shutdown_lndni(ni);
2415 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
2416 tq->tq_credits_min =
2417 tq->tq_credits_max =
2418 tq->tq_credits = lnet_ni_tq_credits(ni);
2421 atomic_set(&ni->ni_tx_credits,
2422 lnet_ni_tq_credits(ni) * ni->ni_ncpts);
2423 atomic_set(&ni->ni_healthv, LNET_MAX_HEALTH_VALUE);
2425 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d/%d]\n",
2426 libcfs_nid2str(ni->ni_nid),
2427 ni->ni_net->net_tunables.lct_peer_tx_credits,
2428 lnet_ni_tq_credits(ni) * LNET_CPT_NUMBER,
2429 ni->ni_net->net_tunables.lct_peer_rtr_credits,
2430 ni->ni_net->net_tunables.lct_peer_timeout);
2439 lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
2442 struct lnet_net *net_l = NULL;
2443 LIST_HEAD(local_ni_list);
2447 const struct lnet_lnd *lnd;
2449 net->net_tunables.lct_peer_timeout;
2451 net->net_tunables.lct_max_tx_credits;
2452 int peerrtrcredits =
2453 net->net_tunables.lct_peer_rtr_credits;
2456 * make sure that this net is unique. If it isn't then
2457 * we are adding interfaces to an already existing network, and
2458 * 'net' is just a convenient way to pass in the list.
2459 * if it is unique we need to find the LND and load it if
2462 if (lnet_net_unique(net->net_id, &the_lnet.ln_nets, &net_l)) {
2463 lnd_type = LNET_NETTYP(net->net_id);
2465 mutex_lock(&the_lnet.ln_lnd_mutex);
2466 lnd = lnet_find_lnd_by_type(lnd_type);
2469 mutex_unlock(&the_lnet.ln_lnd_mutex);
2470 rc = request_module("%s", libcfs_lnd2modname(lnd_type));
2471 mutex_lock(&the_lnet.ln_lnd_mutex);
2473 lnd = lnet_find_lnd_by_type(lnd_type);
2475 mutex_unlock(&the_lnet.ln_lnd_mutex);
2476 CERROR("Can't load LND %s, module %s, rc=%d\n",
2477 libcfs_lnd2str(lnd_type),
2478 libcfs_lnd2modname(lnd_type), rc);
2479 #ifndef HAVE_MODULE_LOADING_SUPPORT
2480 LCONSOLE_ERROR_MSG(0x104, "Your kernel must be "
2481 "compiled with kernel module "
2482 "loading support.");
2491 mutex_unlock(&the_lnet.ln_lnd_mutex);
2497 * net_l: if the network being added is unique then net_l
2498 * will point to that network
2499 * if the network being added is not unique then
2500 * net_l points to the existing network.
2502 * When we enter the loop below, we'll pick NIs off he
2503 * network beign added and start them up, then add them to
2504 * a local ni list. Once we've successfully started all
2505 * the NIs then we join the local NI list (of started up
2506 * networks) with the net_l->net_ni_list, which should
2507 * point to the correct network to add the new ni list to
2509 * If any of the new NIs fail to start up, then we want to
2510 * iterate through the local ni list, which should include
2511 * any NIs which were successfully started up, and shut
2514 * After than we want to delete the network being added,
2515 * to avoid a memory leak.
2517 while (!list_empty(&net->net_ni_added)) {
2518 ni = list_entry(net->net_ni_added.next, struct lnet_ni,
2520 list_del_init(&ni->ni_netlist);
2522 /* make sure that the the NI we're about to start
2523 * up is actually unique. if it's not fail. */
2524 if (!lnet_ni_unique_net(&net_l->net_ni_list,
2525 ni->ni_interface)) {
2530 /* adjust the pointer the parent network, just in case it
2531 * the net is a duplicate */
2534 rc = lnet_startup_lndni(ni, tun);
2540 list_add_tail(&ni->ni_netlist, &local_ni_list);
2545 lnet_net_lock(LNET_LOCK_EX);
2546 list_splice_tail(&local_ni_list, &net_l->net_ni_list);
2547 lnet_incr_dlc_seq();
2548 lnet_net_unlock(LNET_LOCK_EX);
2550 /* if the network is not unique then we don't want to keep
2551 * it around after we're done. Free it. Otherwise add that
2552 * net to the global the_lnet.ln_nets */
2553 if (net_l != net && net_l != NULL) {
2555 * TODO - note. currently the tunables can not be updated
2561 * restore tunables after it has been overwitten by the
2564 if (peer_timeout != -1)
2565 net->net_tunables.lct_peer_timeout = peer_timeout;
2566 if (maxtxcredits != -1)
2567 net->net_tunables.lct_max_tx_credits = maxtxcredits;
2568 if (peerrtrcredits != -1)
2569 net->net_tunables.lct_peer_rtr_credits = peerrtrcredits;
2571 lnet_net_lock(LNET_LOCK_EX);
2572 list_add_tail(&net->net_list, &the_lnet.ln_nets);
2573 lnet_net_unlock(LNET_LOCK_EX);
2580 * shutdown the new NIs that are being started up
2581 * free the NET being started
2583 while (!list_empty(&local_ni_list)) {
2584 ni = list_entry(local_ni_list.next, struct lnet_ni,
2587 lnet_shutdown_lndni(ni);
2597 lnet_startup_lndnets(struct list_head *netlist)
2599 struct lnet_net *net;
2604 * Change to running state before bringing up the LNDs. This
2605 * allows lnet_shutdown_lndnets() to assert that we've passed
2608 lnet_net_lock(LNET_LOCK_EX);
2609 the_lnet.ln_state = LNET_STATE_RUNNING;
2610 lnet_net_unlock(LNET_LOCK_EX);
2612 while (!list_empty(netlist)) {
2613 net = list_entry(netlist->next, struct lnet_net, net_list);
2614 list_del_init(&net->net_list);
2616 rc = lnet_startup_lndnet(net, NULL);
2626 lnet_shutdown_lndnets();
2631 static int lnet_genl_parse_list(struct sk_buff *msg,
2632 const struct ln_key_list *data[], u16 idx)
2634 const struct ln_key_list *list = data[idx];
2635 const struct ln_key_props *props;
2636 struct nlattr *node;
2642 if (!list->lkl_maxattr)
2645 props = list->lkl_list;
2649 node = nla_nest_start(msg, LN_SCALAR_ATTR_LIST);
2653 for (count = 1; count <= list->lkl_maxattr; count++) {
2654 struct nlattr *key = nla_nest_start(msg, count);
2657 nla_put_u16(msg, LN_SCALAR_ATTR_LIST_SIZE,
2660 nla_put_u16(msg, LN_SCALAR_ATTR_INDEX, count);
2661 if (props[count].lkp_values)
2662 nla_put_string(msg, LN_SCALAR_ATTR_VALUE,
2663 props[count].lkp_values);
2664 if (props[count].lkp_key_format)
2665 nla_put_u16(msg, LN_SCALAR_ATTR_KEY_FORMAT,
2666 props[count].lkp_key_format);
2667 nla_put_u16(msg, LN_SCALAR_ATTR_NLA_TYPE,
2668 props[count].lkp_data_type);
2669 if (props[count].lkp_data_type == NLA_NESTED) {
2672 rc = lnet_genl_parse_list(msg, data, ++idx);
2677 nla_nest_end(msg, key);
2680 nla_nest_end(msg, node);
2684 int lnet_genl_send_scalar_list(struct sk_buff *msg, u32 portid, u32 seq,
2685 const struct genl_family *family, int flags,
2686 u8 cmd, const struct ln_key_list *data[])
2694 hdr = genlmsg_put(msg, portid, seq, family, flags, cmd);
2696 GOTO(canceled, rc = -EMSGSIZE);
2698 rc = lnet_genl_parse_list(msg, data, 0);
2702 genlmsg_end(msg, hdr);
2705 genlmsg_cancel(msg, hdr);
2708 EXPORT_SYMBOL(lnet_genl_send_scalar_list);
2711 * Initialize LNet library.
2713 * Automatically called at module loading time. Caller has to call
2714 * lnet_lib_exit() after a call to lnet_lib_init(), if and only if the
2715 * latter returned 0. It must be called exactly once.
2717 * \retval 0 on success
2718 * \retval -ve on failures.
2720 int lnet_lib_init(void)
2724 lnet_assert_wire_constants();
2726 /* refer to global cfs_cpt_table for now */
2727 the_lnet.ln_cpt_table = cfs_cpt_tab;
2728 the_lnet.ln_cpt_number = cfs_cpt_number(cfs_cpt_tab);
2730 LASSERT(the_lnet.ln_cpt_number > 0);
2731 if (the_lnet.ln_cpt_number > LNET_CPT_MAX) {
2732 /* we are under risk of consuming all lh_cookie */
2733 CERROR("Can't have %d CPTs for LNet (max allowed is %d), "
2734 "please change setting of CPT-table and retry\n",
2735 the_lnet.ln_cpt_number, LNET_CPT_MAX);
2739 while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number)
2740 the_lnet.ln_cpt_bits++;
2742 rc = lnet_create_locks();
2744 CERROR("Can't create LNet global locks: %d\n", rc);
2748 the_lnet.ln_refcount = 0;
2749 INIT_LIST_HEAD(&the_lnet.ln_net_zombie);
2750 INIT_LIST_HEAD(&the_lnet.ln_msg_resend);
2752 /* The hash table size is the number of bits it takes to express the set
2753 * ln_num_routes, minus 1 (better to under estimate than over so we
2754 * don't waste memory). */
2755 if (rnet_htable_size <= 0)
2756 rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
2757 else if (rnet_htable_size > LNET_REMOTE_NETS_HASH_MAX)
2758 rnet_htable_size = LNET_REMOTE_NETS_HASH_MAX;
2759 the_lnet.ln_remote_nets_hbits = max_t(int, 1,
2760 order_base_2(rnet_htable_size) - 1);
2762 /* All LNDs apart from the LOLND are in separate modules. They
2763 * register themselves when their module loads, and unregister
2764 * themselves when their module is unloaded. */
2765 lnet_register_lnd(&the_lolnd);
2770 * Finalize LNet library.
2772 * \pre lnet_lib_init() called with success.
2773 * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls.
2775 * As this happens at module-unload, all lnds must already be unloaded,
2776 * so they must already be unregistered.
2778 void lnet_lib_exit(void)
2782 LASSERT(the_lnet.ln_refcount == 0);
2783 lnet_unregister_lnd(&the_lolnd);
2784 for (i = 0; i < NUM_LNDS; i++)
2785 LASSERT(!the_lnet.ln_lnds[i]);
2786 lnet_destroy_locks();
2790 * Set LNet PID and start LNet interfaces, routing, and forwarding.
2792 * Users must call this function at least once before any other functions.
2793 * For each successful call there must be a corresponding call to
2794 * LNetNIFini(). For subsequent calls to LNetNIInit(), \a requested_pid is
2797 * The PID used by LNet may be different from the one requested.
2800 * \param requested_pid PID requested by the caller.
2802 * \return >= 0 on success, and < 0 error code on failures.
2805 LNetNIInit(lnet_pid_t requested_pid)
2807 int im_a_router = 0;
2810 struct lnet_ping_buffer *pbuf;
2811 struct lnet_handle_md ping_mdh;
2812 LIST_HEAD(net_head);
2813 struct lnet_net *net;
2815 mutex_lock(&the_lnet.ln_api_mutex);
2817 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
2819 if (the_lnet.ln_refcount > 0) {
2820 rc = the_lnet.ln_refcount++;
2821 mutex_unlock(&the_lnet.ln_api_mutex);
2825 rc = lnet_prepare(requested_pid);
2827 mutex_unlock(&the_lnet.ln_api_mutex);
2831 /* create a network for Loopback network */
2832 net = lnet_net_alloc(LNET_MKNET(LOLND, 0), &net_head);
2835 goto err_empty_list;
2838 /* Add in the loopback NI */
2839 if (lnet_ni_alloc(net, NULL, NULL) == NULL) {
2841 goto err_empty_list;
2844 if (use_tcp_bonding)
2845 CWARN("use_tcp_bonding has been removed. Use Multi-Rail and Dynamic Discovery instead, see LU-13641\n");
2847 /* If LNet is being initialized via DLC it is possible
2848 * that the user requests not to load module parameters (ones which
2849 * are supported by DLC) on initialization. Therefore, make sure not
2850 * to load networks, routes and forwarding from module parameters
2851 * in this case. On cleanup in case of failure only clean up
2852 * routes if it has been loaded */
2853 if (!the_lnet.ln_nis_from_mod_params) {
2854 rc = lnet_parse_networks(&net_head, lnet_get_networks());
2856 goto err_empty_list;
2859 ni_count = lnet_startup_lndnets(&net_head);
2862 goto err_empty_list;
2865 if (!the_lnet.ln_nis_from_mod_params) {
2866 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
2868 goto err_shutdown_lndnis;
2870 rc = lnet_rtrpools_alloc(im_a_router);
2872 goto err_destroy_routes;
2875 rc = lnet_acceptor_start();
2877 goto err_destroy_routes;
2879 the_lnet.ln_refcount = 1;
2880 /* Now I may use my own API functions... */
2882 rc = lnet_ping_target_setup(&pbuf, &ping_mdh, ni_count, true);
2884 goto err_acceptor_stop;
2886 lnet_ping_target_update(pbuf, ping_mdh);
2888 the_lnet.ln_mt_handler = lnet_mt_event_handler;
2890 rc = lnet_push_target_init();
2894 rc = lnet_peer_discovery_start();
2896 goto err_destroy_push_target;
2898 rc = lnet_monitor_thr_start();
2900 goto err_stop_discovery_thr;
2903 lnet_router_debugfs_init();
2905 mutex_unlock(&the_lnet.ln_api_mutex);
2907 complete_all(&the_lnet.ln_started);
2909 /* wait for all routers to start */
2910 lnet_wait_router_start();
2914 err_stop_discovery_thr:
2915 lnet_peer_discovery_stop();
2916 err_destroy_push_target:
2917 lnet_push_target_fini();
2919 lnet_ping_target_fini();
2921 the_lnet.ln_refcount = 0;
2922 lnet_acceptor_stop();
2924 if (!the_lnet.ln_nis_from_mod_params)
2925 lnet_destroy_routes();
2926 err_shutdown_lndnis:
2927 lnet_shutdown_lndnets();
2931 mutex_unlock(&the_lnet.ln_api_mutex);
2932 while (!list_empty(&net_head)) {
2933 struct lnet_net *net;
2935 net = list_entry(net_head.next, struct lnet_net, net_list);
2936 list_del_init(&net->net_list);
2941 EXPORT_SYMBOL(LNetNIInit);
2944 * Stop LNet interfaces, routing, and forwarding.
2946 * Users must call this function once for each successful call to LNetNIInit().
2947 * Once the LNetNIFini() operation has been started, the results of pending
2948 * API operations are undefined.
2950 * \return always 0 for current implementation.
2955 mutex_lock(&the_lnet.ln_api_mutex);
2957 LASSERT(the_lnet.ln_refcount > 0);
2959 if (the_lnet.ln_refcount != 1) {
2960 the_lnet.ln_refcount--;
2962 LASSERT(!the_lnet.ln_niinit_self);
2966 lnet_router_debugfs_fini();
2967 lnet_monitor_thr_stop();
2968 lnet_peer_discovery_stop();
2969 lnet_push_target_fini();
2970 lnet_ping_target_fini();
2972 /* Teardown fns that use my own API functions BEFORE here */
2973 the_lnet.ln_refcount = 0;
2975 lnet_acceptor_stop();
2976 lnet_destroy_routes();
2977 lnet_shutdown_lndnets();
2981 mutex_unlock(&the_lnet.ln_api_mutex);
2984 EXPORT_SYMBOL(LNetNIFini);
2987 * Grabs the ni data from the ni structure and fills the out
2990 * \param[in] ni network interface structure
2991 * \param[out] cfg_ni NI config information
2992 * \param[out] tun network and LND tunables
2995 lnet_fill_ni_info(struct lnet_ni *ni, struct lnet_ioctl_config_ni *cfg_ni,
2996 struct lnet_ioctl_config_lnd_tunables *tun,
2997 struct lnet_ioctl_element_stats *stats,
3000 size_t min_size = 0;
3003 if (!ni || !cfg_ni || !tun)
3006 if (ni->ni_interface != NULL) {
3007 strncpy(cfg_ni->lic_ni_intf,
3009 sizeof(cfg_ni->lic_ni_intf));
3012 cfg_ni->lic_nid = ni->ni_nid;
3013 if (ni->ni_nid == LNET_NID_LO_0)
3014 cfg_ni->lic_status = LNET_NI_STATUS_UP;
3016 cfg_ni->lic_status = ni->ni_status->ns_status;
3017 cfg_ni->lic_dev_cpt = ni->ni_dev_cpt;
3019 memcpy(&tun->lt_cmn, &ni->ni_net->net_tunables, sizeof(tun->lt_cmn));
3022 stats->iel_send_count = lnet_sum_stats(&ni->ni_stats,
3023 LNET_STATS_TYPE_SEND);
3024 stats->iel_recv_count = lnet_sum_stats(&ni->ni_stats,
3025 LNET_STATS_TYPE_RECV);
3026 stats->iel_drop_count = lnet_sum_stats(&ni->ni_stats,
3027 LNET_STATS_TYPE_DROP);
3031 * tun->lt_tun will always be present, but in order to be
3032 * backwards compatible, we need to deal with the cases when
3033 * tun->lt_tun is smaller than what the kernel has, because it
3034 * comes from an older version of a userspace program, then we'll
3035 * need to copy as much information as we have available space.
3037 min_size = tun_size - sizeof(tun->lt_cmn);
3038 memcpy(&tun->lt_tun, &ni->ni_lnd_tunables, min_size);
3040 /* copy over the cpts */
3041 if (ni->ni_ncpts == LNET_CPT_NUMBER &&
3042 ni->ni_cpts == NULL) {
3043 for (i = 0; i < ni->ni_ncpts; i++)
3044 cfg_ni->lic_cpts[i] = i;
3047 ni->ni_cpts != NULL && i < ni->ni_ncpts &&
3048 i < LNET_MAX_SHOW_NUM_CPT;
3050 cfg_ni->lic_cpts[i] = ni->ni_cpts[i];
3052 cfg_ni->lic_ncpts = ni->ni_ncpts;
3056 * NOTE: This is a legacy function left in the code to be backwards
3057 * compatible with older userspace programs. It should eventually be
3060 * Grabs the ni data from the ni structure and fills the out
3063 * \param[in] ni network interface structure
3064 * \param[out] config config information
3067 lnet_fill_ni_info_legacy(struct lnet_ni *ni,
3068 struct lnet_ioctl_config_data *config)
3070 struct lnet_ioctl_net_config *net_config;
3071 struct lnet_ioctl_config_lnd_tunables *lnd_cfg = NULL;
3072 size_t min_size, tunable_size = 0;
3078 net_config = (struct lnet_ioctl_net_config *) config->cfg_bulk;
3082 if (!ni->ni_interface)
3085 strncpy(net_config->ni_interface,
3087 sizeof(net_config->ni_interface));
3089 config->cfg_nid = ni->ni_nid;
3090 config->cfg_config_u.cfg_net.net_peer_timeout =
3091 ni->ni_net->net_tunables.lct_peer_timeout;
3092 config->cfg_config_u.cfg_net.net_max_tx_credits =
3093 ni->ni_net->net_tunables.lct_max_tx_credits;
3094 config->cfg_config_u.cfg_net.net_peer_tx_credits =
3095 ni->ni_net->net_tunables.lct_peer_tx_credits;
3096 config->cfg_config_u.cfg_net.net_peer_rtr_credits =
3097 ni->ni_net->net_tunables.lct_peer_rtr_credits;
3099 if (ni->ni_nid == LNET_NID_LO_0)
3100 net_config->ni_status = LNET_NI_STATUS_UP;
3102 net_config->ni_status = ni->ni_status->ns_status;
3105 int num_cpts = min(ni->ni_ncpts, LNET_MAX_SHOW_NUM_CPT);
3107 for (i = 0; i < num_cpts; i++)
3108 net_config->ni_cpts[i] = ni->ni_cpts[i];
3110 config->cfg_ncpts = num_cpts;
3114 * See if user land tools sent in a newer and larger version
3115 * of struct lnet_tunables than what the kernel uses.
3117 min_size = sizeof(*config) + sizeof(*net_config);
3119 if (config->cfg_hdr.ioc_len > min_size)
3120 tunable_size = config->cfg_hdr.ioc_len - min_size;
3122 /* Don't copy too much data to user space */
3123 min_size = min(tunable_size, sizeof(ni->ni_lnd_tunables));
3124 lnd_cfg = (struct lnet_ioctl_config_lnd_tunables *)net_config->cfg_bulk;
3126 if (lnd_cfg && min_size) {
3127 memcpy(&lnd_cfg->lt_tun, &ni->ni_lnd_tunables, min_size);
3128 config->cfg_config_u.cfg_net.net_interface_count = 1;
3130 /* Tell user land that kernel side has less data */
3131 if (tunable_size > sizeof(ni->ni_lnd_tunables)) {
3132 min_size = tunable_size - sizeof(ni->ni_lnd_tunables);
3133 config->cfg_hdr.ioc_len -= min_size;
3139 lnet_get_ni_idx_locked(int idx)
3142 struct lnet_net *net;
3144 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3145 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3154 int lnet_get_net_healthv_locked(struct lnet_net *net)
3157 int best_healthv = 0;
3158 int healthv, ni_fatal;
3160 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3161 healthv = atomic_read(&ni->ni_healthv);
3162 ni_fatal = atomic_read(&ni->ni_fatal_error_on);
3163 if (!ni_fatal && healthv > best_healthv)
3164 best_healthv = healthv;
3167 return best_healthv;
3171 lnet_get_next_ni_locked(struct lnet_net *mynet, struct lnet_ni *prev)
3174 struct lnet_net *net = mynet;
3177 * It is possible that the net has been cleaned out while there is
3178 * a message being sent. This function accessed the net without
3179 * checking if the list is empty
3183 net = list_entry(the_lnet.ln_nets.next, struct lnet_net,
3185 if (list_empty(&net->net_ni_list))
3187 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
3193 if (prev->ni_netlist.next == &prev->ni_net->net_ni_list) {
3194 /* if you reached the end of the ni list and the net is
3195 * specified, then there are no more nis in that net */
3199 /* we reached the end of this net ni list. move to the
3201 if (prev->ni_net->net_list.next == &the_lnet.ln_nets)
3202 /* no more nets and no more NIs. */
3205 /* get the next net */
3206 net = list_entry(prev->ni_net->net_list.next, struct lnet_net,
3208 if (list_empty(&net->net_ni_list))
3210 /* get the ni on it */
3211 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
3217 if (list_empty(&prev->ni_netlist))
3220 /* there are more nis left */
3221 ni = list_entry(prev->ni_netlist.next, struct lnet_ni, ni_netlist);
3227 lnet_get_net_config(struct lnet_ioctl_config_data *config)
3232 int idx = config->cfg_count;
3234 cpt = lnet_net_lock_current();
3236 ni = lnet_get_ni_idx_locked(idx);
3241 lnet_fill_ni_info_legacy(ni, config);
3245 lnet_net_unlock(cpt);
3250 lnet_get_ni_config(struct lnet_ioctl_config_ni *cfg_ni,
3251 struct lnet_ioctl_config_lnd_tunables *tun,
3252 struct lnet_ioctl_element_stats *stats,
3259 if (!cfg_ni || !tun || !stats)
3262 cpt = lnet_net_lock_current();
3264 ni = lnet_get_ni_idx_locked(cfg_ni->lic_idx);
3269 lnet_fill_ni_info(ni, cfg_ni, tun, stats, tun_size);
3273 lnet_net_unlock(cpt);
3277 int lnet_get_ni_stats(struct lnet_ioctl_element_msg_stats *msg_stats)
3286 cpt = lnet_net_lock_current();
3288 ni = lnet_get_ni_idx_locked(msg_stats->im_idx);
3291 lnet_usr_translate_stats(msg_stats, &ni->ni_stats);
3295 lnet_net_unlock(cpt);
3300 static int lnet_add_net_common(struct lnet_net *net,
3301 struct lnet_ioctl_config_lnd_tunables *tun)
3303 struct lnet_handle_md ping_mdh;
3304 struct lnet_ping_buffer *pbuf;
3305 struct lnet_remotenet *rnet;
3311 lnet_net_lock(LNET_LOCK_EX);
3312 rnet = lnet_find_rnet_locked(net->net_id);
3313 lnet_net_unlock(LNET_LOCK_EX);
3315 * make sure that the net added doesn't invalidate the current
3316 * configuration LNet is keeping
3319 CERROR("Adding net %s will invalidate routing configuration\n",
3320 libcfs_net2str(net->net_id));
3326 * make sure you calculate the correct number of slots in the ping
3327 * buffer. Since the ping info is a flattened list of all the NIs,
3328 * we should allocate enough slots to accomodate the number of NIs
3329 * which will be added.
3331 * since ni hasn't been configured yet, use
3332 * lnet_get_net_ni_count_pre() which checks the net_ni_added list
3334 net_ni_count = lnet_get_net_ni_count_pre(net);
3336 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3337 net_ni_count + lnet_get_ni_count(),
3345 memcpy(&net->net_tunables,
3346 &tun->lt_cmn, sizeof(net->net_tunables));
3348 memset(&net->net_tunables, -1, sizeof(net->net_tunables));
3350 net_id = net->net_id;
3352 rc = lnet_startup_lndnet(net,
3353 (tun) ? &tun->lt_tun : NULL);
3357 lnet_net_lock(LNET_LOCK_EX);
3358 net = lnet_get_net_locked(net_id);
3361 /* apply the UDSPs */
3362 rc = lnet_udsp_apply_policies_on_net(net);
3364 CERROR("Failed to apply UDSPs on local net %s\n",
3365 libcfs_net2str(net->net_id));
3367 /* At this point we lost track of which NI was just added, so we
3368 * just re-apply the policies on all of the NIs on this net
3370 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3371 rc = lnet_udsp_apply_policies_on_ni(ni);
3373 CERROR("Failed to apply UDSPs on ni %s\n",
3374 libcfs_nid2str(ni->ni_nid));
3376 lnet_net_unlock(LNET_LOCK_EX);
3379 * Start the acceptor thread if this is the first network
3380 * being added that requires the thread.
3382 if (net->net_lnd->lnd_accept) {
3383 rc = lnet_acceptor_start();
3385 /* shutdown the net that we just started */
3386 CERROR("Failed to start up acceptor thread\n");
3387 lnet_shutdown_lndnet(net);
3392 lnet_net_lock(LNET_LOCK_EX);
3393 lnet_peer_net_added(net);
3394 lnet_net_unlock(LNET_LOCK_EX);
3396 lnet_ping_target_update(pbuf, ping_mdh);
3401 lnet_ping_md_unlink(pbuf, &ping_mdh);
3402 lnet_ping_buffer_decref(pbuf);
3407 lnet_set_tune_defaults(struct lnet_ioctl_config_lnd_tunables *tun)
3410 if (!tun->lt_cmn.lct_peer_timeout)
3411 tun->lt_cmn.lct_peer_timeout = DEFAULT_PEER_TIMEOUT;
3412 if (!tun->lt_cmn.lct_peer_tx_credits)
3413 tun->lt_cmn.lct_peer_tx_credits = DEFAULT_PEER_CREDITS;
3414 if (!tun->lt_cmn.lct_max_tx_credits)
3415 tun->lt_cmn.lct_max_tx_credits = DEFAULT_CREDITS;
3419 static int lnet_handle_legacy_ip2nets(char *ip2nets,
3420 struct lnet_ioctl_config_lnd_tunables *tun)
3422 struct lnet_net *net;
3425 LIST_HEAD(net_head);
3427 rc = lnet_parse_ip2nets(&nets, ip2nets);
3431 rc = lnet_parse_networks(&net_head, nets);
3435 lnet_set_tune_defaults(tun);
3437 mutex_lock(&the_lnet.ln_api_mutex);
3438 while (!list_empty(&net_head)) {
3439 net = list_entry(net_head.next, struct lnet_net, net_list);
3440 list_del_init(&net->net_list);
3441 rc = lnet_add_net_common(net, tun);
3447 mutex_unlock(&the_lnet.ln_api_mutex);
3449 while (!list_empty(&net_head)) {
3450 net = list_entry(net_head.next, struct lnet_net, net_list);
3451 list_del_init(&net->net_list);
3457 int lnet_dyn_add_ni(struct lnet_ioctl_config_ni *conf)
3459 struct lnet_net *net;
3461 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
3463 __u32 net_id, lnd_type;
3465 /* get the tunables if they are available */
3466 if (conf->lic_cfg_hdr.ioc_len >=
3467 sizeof(*conf) + sizeof(*tun))
3468 tun = (struct lnet_ioctl_config_lnd_tunables *)
3471 /* handle legacy ip2nets from DLC */
3472 if (conf->lic_legacy_ip2nets[0] != '\0')
3473 return lnet_handle_legacy_ip2nets(conf->lic_legacy_ip2nets,
3476 net_id = LNET_NIDNET(conf->lic_nid);
3477 lnd_type = LNET_NETTYP(net_id);
3479 if (!libcfs_isknown_lnd(lnd_type)) {
3480 CERROR("No valid net and lnd information provided\n");
3484 net = lnet_net_alloc(net_id, NULL);
3488 for (i = 0; i < conf->lic_ncpts; i++) {
3489 if (conf->lic_cpts[i] >= LNET_CPT_NUMBER)
3493 ni = lnet_ni_alloc_w_cpt_array(net, conf->lic_cpts, conf->lic_ncpts,
3498 lnet_set_tune_defaults(tun);
3500 mutex_lock(&the_lnet.ln_api_mutex);
3502 rc = lnet_add_net_common(net, tun);
3504 mutex_unlock(&the_lnet.ln_api_mutex);
3509 int lnet_dyn_del_ni(struct lnet_ioctl_config_ni *conf)
3511 struct lnet_net *net;
3513 __u32 net_id = LNET_NIDNET(conf->lic_nid);
3514 struct lnet_ping_buffer *pbuf;
3515 struct lnet_handle_md ping_mdh;
3520 /* don't allow userspace to shutdown the LOLND */
3521 if (LNET_NETTYP(net_id) == LOLND)
3524 mutex_lock(&the_lnet.ln_api_mutex);
3528 net = lnet_get_net_locked(net_id);
3530 CERROR("net %s not found\n",
3531 libcfs_net2str(net_id));
3536 addr = LNET_NIDADDR(conf->lic_nid);
3538 /* remove the entire net */
3539 net_count = lnet_get_net_ni_count_locked(net);
3543 /* create and link a new ping info, before removing the old one */
3544 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3545 lnet_get_ni_count() - net_count,
3548 goto unlock_api_mutex;
3550 lnet_shutdown_lndnet(net);
3552 lnet_acceptor_stop();
3554 lnet_ping_target_update(pbuf, ping_mdh);
3556 goto unlock_api_mutex;
3559 ni = lnet_nid2ni_locked(conf->lic_nid, 0);
3561 CERROR("nid %s not found\n",
3562 libcfs_nid2str(conf->lic_nid));
3567 net_count = lnet_get_net_ni_count_locked(net);
3571 /* create and link a new ping info, before removing the old one */
3572 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3573 lnet_get_ni_count() - 1, false);
3575 goto unlock_api_mutex;
3577 lnet_shutdown_lndni(ni);
3579 lnet_acceptor_stop();
3581 lnet_ping_target_update(pbuf, ping_mdh);
3583 /* check if the net is empty and remove it if it is */
3585 lnet_shutdown_lndnet(net);
3587 goto unlock_api_mutex;
3592 mutex_unlock(&the_lnet.ln_api_mutex);
3598 * lnet_dyn_add_net and lnet_dyn_del_net are now deprecated.
3599 * They are only expected to be called for unique networks.
3600 * That can be as a result of older DLC library
3601 * calls. Multi-Rail DLC and beyond no longer uses these APIs.
3604 lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
3606 struct lnet_net *net;
3607 LIST_HEAD(net_head);
3609 struct lnet_ioctl_config_lnd_tunables tun;
3610 const char *nets = conf->cfg_config_u.cfg_net.net_intf;
3612 /* Create a net/ni structures for the network string */
3613 rc = lnet_parse_networks(&net_head, nets);
3615 return rc == 0 ? -EINVAL : rc;
3617 mutex_lock(&the_lnet.ln_api_mutex);
3620 rc = -EINVAL; /* only add one network per call */
3621 goto out_unlock_clean;
3624 net = list_entry(net_head.next, struct lnet_net, net_list);
3625 list_del_init(&net->net_list);
3627 LASSERT(lnet_net_unique(net->net_id, &the_lnet.ln_nets, NULL));
3629 memset(&tun, 0, sizeof(tun));
3631 tun.lt_cmn.lct_peer_timeout =
3632 (!conf->cfg_config_u.cfg_net.net_peer_timeout) ? DEFAULT_PEER_TIMEOUT :
3633 conf->cfg_config_u.cfg_net.net_peer_timeout;
3634 tun.lt_cmn.lct_peer_tx_credits =
3635 (!conf->cfg_config_u.cfg_net.net_peer_tx_credits) ? DEFAULT_PEER_CREDITS :
3636 conf->cfg_config_u.cfg_net.net_peer_tx_credits;
3637 tun.lt_cmn.lct_peer_rtr_credits =
3638 conf->cfg_config_u.cfg_net.net_peer_rtr_credits;
3639 tun.lt_cmn.lct_max_tx_credits =
3640 (!conf->cfg_config_u.cfg_net.net_max_tx_credits) ? DEFAULT_CREDITS :
3641 conf->cfg_config_u.cfg_net.net_max_tx_credits;
3643 rc = lnet_add_net_common(net, &tun);
3646 mutex_unlock(&the_lnet.ln_api_mutex);
3647 while (!list_empty(&net_head)) {
3648 /* net_head list is empty in success case */
3649 net = list_entry(net_head.next, struct lnet_net, net_list);
3650 list_del_init(&net->net_list);
3657 lnet_dyn_del_net(__u32 net_id)
3659 struct lnet_net *net;
3660 struct lnet_ping_buffer *pbuf;
3661 struct lnet_handle_md ping_mdh;
3665 /* don't allow userspace to shutdown the LOLND */
3666 if (LNET_NETTYP(net_id) == LOLND)
3669 mutex_lock(&the_lnet.ln_api_mutex);
3673 net = lnet_get_net_locked(net_id);
3680 net_ni_count = lnet_get_net_ni_count_locked(net);
3684 /* create and link a new ping info, before removing the old one */
3685 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3686 lnet_get_ni_count() - net_ni_count, false);
3690 lnet_shutdown_lndnet(net);
3692 lnet_acceptor_stop();
3694 lnet_ping_target_update(pbuf, ping_mdh);
3697 mutex_unlock(&the_lnet.ln_api_mutex);
3702 void lnet_incr_dlc_seq(void)
3704 atomic_inc(&lnet_dlc_seq_no);
3707 __u32 lnet_get_dlc_seq_locked(void)
3709 return atomic_read(&lnet_dlc_seq_no);
3713 lnet_ni_set_healthv(lnet_nid_t nid, int value, bool all)
3715 struct lnet_net *net;
3718 lnet_net_lock(LNET_LOCK_EX);
3719 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3720 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3721 if (ni->ni_nid == nid || all) {
3722 atomic_set(&ni->ni_healthv, value);
3723 if (list_empty(&ni->ni_recovery) &&
3724 value < LNET_MAX_HEALTH_VALUE) {
3725 CERROR("manually adding local NI %s to recovery\n",
3726 libcfs_nid2str(ni->ni_nid));
3727 list_add_tail(&ni->ni_recovery,
3728 &the_lnet.ln_mt_localNIRecovq);
3729 lnet_ni_addref_locked(ni, 0);
3732 lnet_net_unlock(LNET_LOCK_EX);
3738 lnet_net_unlock(LNET_LOCK_EX);
3742 lnet_get_local_ni_hstats(struct lnet_ioctl_local_ni_hstats *stats)
3746 lnet_nid_t nid = stats->hlni_nid;
3748 cpt = lnet_net_lock_current();
3749 ni = lnet_nid2ni_locked(nid, cpt);
3756 stats->hlni_local_interrupt = atomic_read(&ni->ni_hstats.hlt_local_interrupt);
3757 stats->hlni_local_dropped = atomic_read(&ni->ni_hstats.hlt_local_dropped);
3758 stats->hlni_local_aborted = atomic_read(&ni->ni_hstats.hlt_local_aborted);
3759 stats->hlni_local_no_route = atomic_read(&ni->ni_hstats.hlt_local_no_route);
3760 stats->hlni_local_timeout = atomic_read(&ni->ni_hstats.hlt_local_timeout);
3761 stats->hlni_local_error = atomic_read(&ni->ni_hstats.hlt_local_error);
3762 stats->hlni_health_value = atomic_read(&ni->ni_healthv);
3763 stats->hlni_ping_count = ni->ni_ping_count;
3764 stats->hlni_next_ping = ni->ni_next_ping;
3767 lnet_net_unlock(cpt);
3773 lnet_get_local_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
3778 lnet_net_lock(LNET_LOCK_EX);
3779 list_for_each_entry(ni, &the_lnet.ln_mt_localNIRecovq, ni_recovery) {
3780 list->rlst_nid_array[i] = ni->ni_nid;
3782 if (i >= LNET_MAX_SHOW_NUM_NID)
3785 lnet_net_unlock(LNET_LOCK_EX);
3786 list->rlst_num_nids = i;
3792 lnet_get_peer_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
3794 struct lnet_peer_ni *lpni;
3797 lnet_net_lock(LNET_LOCK_EX);
3798 list_for_each_entry(lpni, &the_lnet.ln_mt_peerNIRecovq, lpni_recovery) {
3799 list->rlst_nid_array[i] = lpni->lpni_nid;
3801 if (i >= LNET_MAX_SHOW_NUM_NID)
3804 lnet_net_unlock(LNET_LOCK_EX);
3805 list->rlst_num_nids = i;
3811 * LNet ioctl handler.
3815 LNetCtl(unsigned int cmd, void *arg)
3817 struct libcfs_ioctl_data *data = arg;
3818 struct lnet_ioctl_config_data *config;
3819 struct lnet_process_id id = {0};
3823 BUILD_BUG_ON(sizeof(struct lnet_ioctl_net_config) +
3824 sizeof(struct lnet_ioctl_config_data) > LIBCFS_IOC_DATA_MAX);
3827 case IOC_LIBCFS_GET_NI:
3828 rc = LNetGetId(data->ioc_count, &id);
3829 data->ioc_nid = id.nid;
3832 case IOC_LIBCFS_FAIL_NID:
3833 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
3835 case IOC_LIBCFS_ADD_ROUTE: {
3836 /* default router sensitivity to 1 */
3837 unsigned int sensitivity = 1;
3840 if (config->cfg_hdr.ioc_len < sizeof(*config))
3843 if (config->cfg_config_u.cfg_route.rtr_sensitivity) {
3845 config->cfg_config_u.cfg_route.rtr_sensitivity;
3848 mutex_lock(&the_lnet.ln_api_mutex);
3849 rc = lnet_add_route(config->cfg_net,
3850 config->cfg_config_u.cfg_route.rtr_hop,
3852 config->cfg_config_u.cfg_route.
3853 rtr_priority, sensitivity);
3854 mutex_unlock(&the_lnet.ln_api_mutex);
3858 case IOC_LIBCFS_DEL_ROUTE:
3861 if (config->cfg_hdr.ioc_len < sizeof(*config))
3864 mutex_lock(&the_lnet.ln_api_mutex);
3865 rc = lnet_del_route(config->cfg_net, config->cfg_nid);
3866 mutex_unlock(&the_lnet.ln_api_mutex);
3869 case IOC_LIBCFS_GET_ROUTE:
3872 if (config->cfg_hdr.ioc_len < sizeof(*config))
3875 mutex_lock(&the_lnet.ln_api_mutex);
3876 rc = lnet_get_route(config->cfg_count,
3878 &config->cfg_config_u.cfg_route.rtr_hop,
3880 &config->cfg_config_u.cfg_route.rtr_flags,
3881 &config->cfg_config_u.cfg_route.
3883 &config->cfg_config_u.cfg_route.
3885 mutex_unlock(&the_lnet.ln_api_mutex);
3888 case IOC_LIBCFS_GET_LOCAL_NI: {
3889 struct lnet_ioctl_config_ni *cfg_ni;
3890 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
3891 struct lnet_ioctl_element_stats *stats;
3896 /* get the tunables if they are available */
3897 if (cfg_ni->lic_cfg_hdr.ioc_len <
3898 sizeof(*cfg_ni) + sizeof(*stats) + sizeof(*tun))
3901 stats = (struct lnet_ioctl_element_stats *)
3903 tun = (struct lnet_ioctl_config_lnd_tunables *)
3904 (cfg_ni->lic_bulk + sizeof(*stats));
3906 tun_size = cfg_ni->lic_cfg_hdr.ioc_len - sizeof(*cfg_ni) -
3909 mutex_lock(&the_lnet.ln_api_mutex);
3910 rc = lnet_get_ni_config(cfg_ni, tun, stats, tun_size);
3911 mutex_unlock(&the_lnet.ln_api_mutex);
3915 case IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS: {
3916 struct lnet_ioctl_element_msg_stats *msg_stats = arg;
3918 if (msg_stats->im_hdr.ioc_len != sizeof(*msg_stats))
3921 mutex_lock(&the_lnet.ln_api_mutex);
3922 rc = lnet_get_ni_stats(msg_stats);
3923 mutex_unlock(&the_lnet.ln_api_mutex);
3928 case IOC_LIBCFS_GET_NET: {
3929 size_t total = sizeof(*config) +
3930 sizeof(struct lnet_ioctl_net_config);
3933 if (config->cfg_hdr.ioc_len < total)
3936 mutex_lock(&the_lnet.ln_api_mutex);
3937 rc = lnet_get_net_config(config);
3938 mutex_unlock(&the_lnet.ln_api_mutex);
3942 case IOC_LIBCFS_GET_LNET_STATS:
3944 struct lnet_ioctl_lnet_stats *lnet_stats = arg;
3946 if (lnet_stats->st_hdr.ioc_len < sizeof(*lnet_stats))
3949 mutex_lock(&the_lnet.ln_api_mutex);
3950 rc = lnet_counters_get(&lnet_stats->st_cntrs);
3951 mutex_unlock(&the_lnet.ln_api_mutex);
3955 case IOC_LIBCFS_CONFIG_RTR:
3958 if (config->cfg_hdr.ioc_len < sizeof(*config))
3961 mutex_lock(&the_lnet.ln_api_mutex);
3962 if (config->cfg_config_u.cfg_buffers.buf_enable) {
3963 rc = lnet_rtrpools_enable();
3964 mutex_unlock(&the_lnet.ln_api_mutex);
3967 lnet_rtrpools_disable();
3968 mutex_unlock(&the_lnet.ln_api_mutex);
3971 case IOC_LIBCFS_ADD_BUF:
3974 if (config->cfg_hdr.ioc_len < sizeof(*config))
3977 mutex_lock(&the_lnet.ln_api_mutex);
3978 rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
3980 config->cfg_config_u.cfg_buffers.
3982 config->cfg_config_u.cfg_buffers.
3984 mutex_unlock(&the_lnet.ln_api_mutex);
3987 case IOC_LIBCFS_SET_NUMA_RANGE: {
3988 struct lnet_ioctl_set_value *numa;
3990 if (numa->sv_hdr.ioc_len != sizeof(*numa))
3992 lnet_net_lock(LNET_LOCK_EX);
3993 lnet_numa_range = numa->sv_value;
3994 lnet_net_unlock(LNET_LOCK_EX);
3998 case IOC_LIBCFS_GET_NUMA_RANGE: {
3999 struct lnet_ioctl_set_value *numa;
4001 if (numa->sv_hdr.ioc_len != sizeof(*numa))
4003 numa->sv_value = lnet_numa_range;
4007 case IOC_LIBCFS_GET_BUF: {
4008 struct lnet_ioctl_pool_cfg *pool_cfg;
4009 size_t total = sizeof(*config) + sizeof(*pool_cfg);
4013 if (config->cfg_hdr.ioc_len < total)
4016 pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
4018 mutex_lock(&the_lnet.ln_api_mutex);
4019 rc = lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
4020 mutex_unlock(&the_lnet.ln_api_mutex);
4024 case IOC_LIBCFS_GET_LOCAL_HSTATS: {
4025 struct lnet_ioctl_local_ni_hstats *stats = arg;
4027 if (stats->hlni_hdr.ioc_len < sizeof(*stats))
4030 mutex_lock(&the_lnet.ln_api_mutex);
4031 rc = lnet_get_local_ni_hstats(stats);
4032 mutex_unlock(&the_lnet.ln_api_mutex);
4037 case IOC_LIBCFS_GET_RECOVERY_QUEUE: {
4038 struct lnet_ioctl_recovery_list *list = arg;
4039 if (list->rlst_hdr.ioc_len < sizeof(*list))
4042 mutex_lock(&the_lnet.ln_api_mutex);
4043 if (list->rlst_type == LNET_HEALTH_TYPE_LOCAL_NI)
4044 rc = lnet_get_local_ni_recovery_list(list);
4046 rc = lnet_get_peer_ni_recovery_list(list);
4047 mutex_unlock(&the_lnet.ln_api_mutex);
4051 case IOC_LIBCFS_ADD_PEER_NI: {
4052 struct lnet_ioctl_peer_cfg *cfg = arg;
4054 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4057 mutex_lock(&the_lnet.ln_api_mutex);
4058 rc = lnet_add_peer_ni(cfg->prcfg_prim_nid,
4061 mutex_unlock(&the_lnet.ln_api_mutex);
4065 case IOC_LIBCFS_DEL_PEER_NI: {
4066 struct lnet_ioctl_peer_cfg *cfg = arg;
4068 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4071 mutex_lock(&the_lnet.ln_api_mutex);
4072 rc = lnet_del_peer_ni(cfg->prcfg_prim_nid,
4073 cfg->prcfg_cfg_nid);
4074 mutex_unlock(&the_lnet.ln_api_mutex);
4078 case IOC_LIBCFS_GET_PEER_INFO: {
4079 struct lnet_ioctl_peer *peer_info = arg;
4081 if (peer_info->pr_hdr.ioc_len < sizeof(*peer_info))
4084 mutex_lock(&the_lnet.ln_api_mutex);
4085 rc = lnet_get_peer_ni_info(
4086 peer_info->pr_count,
4088 peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
4089 &peer_info->pr_lnd_u.pr_peer_credits.cr_ncpt,
4090 &peer_info->pr_lnd_u.pr_peer_credits.cr_refcount,
4091 &peer_info->pr_lnd_u.pr_peer_credits.cr_ni_peer_tx_credits,
4092 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_credits,
4093 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_rtr_credits,
4094 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_min_tx_credits,
4095 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_qnob);
4096 mutex_unlock(&the_lnet.ln_api_mutex);
4100 case IOC_LIBCFS_GET_PEER_NI: {
4101 struct lnet_ioctl_peer_cfg *cfg = arg;
4103 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4106 mutex_lock(&the_lnet.ln_api_mutex);
4107 rc = lnet_get_peer_info(cfg,
4108 (void __user *)cfg->prcfg_bulk);
4109 mutex_unlock(&the_lnet.ln_api_mutex);
4113 case IOC_LIBCFS_GET_PEER_LIST: {
4114 struct lnet_ioctl_peer_cfg *cfg = arg;
4116 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4119 mutex_lock(&the_lnet.ln_api_mutex);
4120 rc = lnet_get_peer_list(&cfg->prcfg_count, &cfg->prcfg_size,
4121 (struct lnet_process_id __user *)cfg->prcfg_bulk);
4122 mutex_unlock(&the_lnet.ln_api_mutex);
4126 case IOC_LIBCFS_SET_HEALHV: {
4127 struct lnet_ioctl_reset_health_cfg *cfg = arg;
4129 if (cfg->rh_hdr.ioc_len < sizeof(*cfg))
4131 if (cfg->rh_value < 0 ||
4132 cfg->rh_value > LNET_MAX_HEALTH_VALUE)
4133 value = LNET_MAX_HEALTH_VALUE;
4135 value = cfg->rh_value;
4136 CDEBUG(D_NET, "Manually setting healthv to %d for %s:%s. all = %d\n",
4137 value, (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI) ?
4138 "local" : "peer", libcfs_nid2str(cfg->rh_nid), cfg->rh_all);
4139 mutex_lock(&the_lnet.ln_api_mutex);
4140 if (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI)
4141 lnet_ni_set_healthv(cfg->rh_nid, value,
4144 lnet_peer_ni_set_healthv(cfg->rh_nid, value,
4146 mutex_unlock(&the_lnet.ln_api_mutex);
4150 case IOC_LIBCFS_NOTIFY_ROUTER: {
4151 time64_t deadline = ktime_get_real_seconds() - data->ioc_u64[0];
4153 /* The deadline passed in by the user should be some time in
4154 * seconds in the future since the UNIX epoch. We have to map
4155 * that deadline to the wall clock.
4157 deadline += ktime_get_seconds();
4158 return lnet_notify(NULL, data->ioc_nid, data->ioc_flags, false,
4162 case IOC_LIBCFS_LNET_DIST:
4163 rc = LNetDist(data->ioc_nid, &data->ioc_nid, &data->ioc_u32[1]);
4164 if (rc < 0 && rc != -EHOSTUNREACH)
4167 data->ioc_u32[0] = rc;
4170 case IOC_LIBCFS_TESTPROTOCOMPAT:
4171 the_lnet.ln_testprotocompat = data->ioc_flags;
4174 case IOC_LIBCFS_LNET_FAULT:
4175 return lnet_fault_ctl(data->ioc_flags, data);
4177 case IOC_LIBCFS_PING: {
4178 signed long timeout;
4180 id.nid = data->ioc_nid;
4181 id.pid = data->ioc_u32[0];
4183 /* If timeout is negative then set default of 3 minutes */
4184 if (((s32)data->ioc_u32[1] <= 0) ||
4185 data->ioc_u32[1] > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
4186 timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
4188 timeout = nsecs_to_jiffies(data->ioc_u32[1] * NSEC_PER_MSEC);
4190 rc = lnet_ping(id, timeout, data->ioc_pbuf1,
4191 data->ioc_plen1 / sizeof(struct lnet_process_id));
4196 data->ioc_count = rc;
4200 case IOC_LIBCFS_PING_PEER: {
4201 struct lnet_ioctl_ping_data *ping = arg;
4202 struct lnet_peer *lp;
4203 signed long timeout;
4205 /* If timeout is negative then set default of 3 minutes */
4206 if (((s32)ping->op_param) <= 0 ||
4207 ping->op_param > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
4208 timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
4210 timeout = nsecs_to_jiffies(ping->op_param * NSEC_PER_MSEC);
4212 rc = lnet_ping(ping->ping_id, timeout,
4218 mutex_lock(&the_lnet.ln_api_mutex);
4219 lp = lnet_find_peer(ping->ping_id.nid);
4221 ping->ping_id.nid = lp->lp_primary_nid;
4222 ping->mr_info = lnet_peer_is_multi_rail(lp);
4223 lnet_peer_decref_locked(lp);
4225 mutex_unlock(&the_lnet.ln_api_mutex);
4227 ping->ping_count = rc;
4231 case IOC_LIBCFS_DISCOVER: {
4232 struct lnet_ioctl_ping_data *discover = arg;
4233 struct lnet_peer *lp;
4235 rc = lnet_discover(discover->ping_id, discover->op_param,
4237 discover->ping_count);
4241 mutex_lock(&the_lnet.ln_api_mutex);
4242 lp = lnet_find_peer(discover->ping_id.nid);
4244 discover->ping_id.nid = lp->lp_primary_nid;
4245 discover->mr_info = lnet_peer_is_multi_rail(lp);
4246 lnet_peer_decref_locked(lp);
4248 mutex_unlock(&the_lnet.ln_api_mutex);
4250 discover->ping_count = rc;
4254 case IOC_LIBCFS_ADD_UDSP: {
4255 struct lnet_ioctl_udsp *ioc_udsp = arg;
4256 __u32 bulk_size = ioc_udsp->iou_hdr.ioc_len;
4258 mutex_lock(&the_lnet.ln_api_mutex);
4259 rc = lnet_udsp_demarshal_add(arg, bulk_size);
4261 rc = lnet_udsp_apply_policies(NULL, false);
4262 CDEBUG(D_NET, "policy application returned %d\n", rc);
4265 mutex_unlock(&the_lnet.ln_api_mutex);
4270 case IOC_LIBCFS_DEL_UDSP: {
4271 struct lnet_ioctl_udsp *ioc_udsp = arg;
4272 int idx = ioc_udsp->iou_idx;
4274 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4277 mutex_lock(&the_lnet.ln_api_mutex);
4278 rc = lnet_udsp_del_policy(idx);
4280 rc = lnet_udsp_apply_policies(NULL, false);
4281 CDEBUG(D_NET, "policy re-application returned %d\n",
4285 mutex_unlock(&the_lnet.ln_api_mutex);
4290 case IOC_LIBCFS_GET_UDSP_SIZE: {
4291 struct lnet_ioctl_udsp *ioc_udsp = arg;
4292 struct lnet_udsp *udsp;
4294 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4299 mutex_lock(&the_lnet.ln_api_mutex);
4300 udsp = lnet_udsp_get_policy(ioc_udsp->iou_idx);
4304 /* coming in iou_idx will hold the idx of the udsp
4305 * to get the size of. going out the iou_idx will
4306 * hold the size of the UDSP found at the passed
4309 ioc_udsp->iou_idx = lnet_get_udsp_size(udsp);
4310 if (ioc_udsp->iou_idx < 0)
4313 mutex_unlock(&the_lnet.ln_api_mutex);
4318 case IOC_LIBCFS_GET_UDSP: {
4319 struct lnet_ioctl_udsp *ioc_udsp = arg;
4320 struct lnet_udsp *udsp;
4322 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4327 mutex_lock(&the_lnet.ln_api_mutex);
4328 udsp = lnet_udsp_get_policy(ioc_udsp->iou_idx);
4332 rc = lnet_udsp_marshal(udsp, ioc_udsp);
4333 mutex_unlock(&the_lnet.ln_api_mutex);
4338 case IOC_LIBCFS_GET_CONST_UDSP_INFO: {
4339 struct lnet_ioctl_construct_udsp_info *info = arg;
4341 if (info->cud_hdr.ioc_len < sizeof(*info))
4344 CDEBUG(D_NET, "GET_UDSP_INFO for %s\n",
4345 libcfs_nid2str(info->cud_nid));
4347 mutex_lock(&the_lnet.ln_api_mutex);
4348 lnet_udsp_get_construct_info(info);
4349 mutex_unlock(&the_lnet.ln_api_mutex);
4355 ni = lnet_net2ni_addref(data->ioc_net);
4359 if (ni->ni_net->net_lnd->lnd_ctl == NULL)
4362 rc = ni->ni_net->net_lnd->lnd_ctl(ni, cmd, arg);
4369 EXPORT_SYMBOL(LNetCtl);
4371 void LNetDebugPeer(struct lnet_process_id id)
4373 lnet_debug_peer(id.nid);
4375 EXPORT_SYMBOL(LNetDebugPeer);
4378 * Determine if the specified peer \a nid is on the local node.
4380 * \param nid peer nid to check
4382 * \retval true If peer NID is on the local node.
4383 * \retval false If peer NID is not on the local node.
4385 bool LNetIsPeerLocal(lnet_nid_t nid)
4387 struct lnet_net *net;
4391 cpt = lnet_net_lock_current();
4392 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
4393 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
4394 if (ni->ni_nid == nid) {
4395 lnet_net_unlock(cpt);
4400 lnet_net_unlock(cpt);
4404 EXPORT_SYMBOL(LNetIsPeerLocal);
4407 * Retrieve the struct lnet_process_id ID of LNet interface at \a index.
4408 * Note that all interfaces share a same PID, as requested by LNetNIInit().
4410 * \param index Index of the interface to look up.
4411 * \param id On successful return, this location will hold the
4412 * struct lnet_process_id ID of the interface.
4414 * \retval 0 If an interface exists at \a index.
4415 * \retval -ENOENT If no interface has been found.
4418 LNetGetId(unsigned int index, struct lnet_process_id *id)
4421 struct lnet_net *net;
4425 LASSERT(the_lnet.ln_refcount > 0);
4427 cpt = lnet_net_lock_current();
4429 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
4430 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
4434 id->nid = ni->ni_nid;
4435 id->pid = the_lnet.ln_pid;
4441 lnet_net_unlock(cpt);
4444 EXPORT_SYMBOL(LNetGetId);
4449 struct lnet_handle_md mdh;
4450 struct completion completion;
4454 lnet_ping_event_handler(struct lnet_event *event)
4456 struct ping_data *pd = event->md_user_ptr;
4458 CDEBUG(D_NET, "ping event (%d %d)%s\n",
4459 event->type, event->status,
4460 event->unlinked ? " unlinked" : "");
4462 if (event->status) {
4464 pd->rc = event->status;
4465 } else if (event->type == LNET_EVENT_REPLY) {
4467 pd->rc = event->mlength;
4469 if (event->unlinked)
4470 complete(&pd->completion);
4473 static int lnet_ping(struct lnet_process_id id, signed long timeout,
4474 struct lnet_process_id __user *ids, int n_ids)
4476 struct lnet_md md = { NULL };
4477 struct ping_data pd = { 0 };
4478 struct lnet_ping_buffer *pbuf;
4479 struct lnet_process_id tmpid;
4485 /* n_ids limit is arbitrary */
4486 if (n_ids <= 0 || id.nid == LNET_NID_ANY)
4490 * if the user buffer has more space than the lnet_interfaces_max
4491 * then only fill it up to lnet_interfaces_max
4493 if (n_ids > lnet_interfaces_max)
4494 n_ids = lnet_interfaces_max;
4496 if (id.pid == LNET_PID_ANY)
4497 id.pid = LNET_PID_LUSTRE;
4499 pbuf = lnet_ping_buffer_alloc(n_ids, GFP_NOFS);
4503 /* initialize md content */
4504 md.start = &pbuf->pb_info;
4505 md.length = LNET_PING_INFO_SIZE(n_ids);
4506 md.threshold = 2; /* GET/REPLY */
4508 md.options = LNET_MD_TRUNCATE;
4510 md.handler = lnet_ping_event_handler;
4512 init_completion(&pd.completion);
4514 rc = LNetMDBind(&md, LNET_UNLINK, &pd.mdh);
4516 CERROR("Can't bind MD: %d\n", rc);
4517 goto fail_ping_buffer_decref;
4520 rc = LNetGet(LNET_NID_ANY, pd.mdh, id,
4521 LNET_RESERVED_PORTAL,
4522 LNET_PROTO_PING_MATCHBITS, 0, false);
4525 /* Don't CERROR; this could be deliberate! */
4526 rc2 = LNetMDUnlink(pd.mdh);
4529 /* NB must wait for the UNLINK event below... */
4532 if (wait_for_completion_timeout(&pd.completion, timeout) == 0) {
4533 /* Ensure completion in finite time... */
4534 LNetMDUnlink(pd.mdh);
4535 wait_for_completion(&pd.completion);
4539 goto fail_ping_buffer_decref;
4543 LASSERT(nob >= 0 && nob <= LNET_PING_INFO_SIZE(n_ids));
4545 rc = -EPROTO; /* if I can't parse... */
4548 CERROR("%s: ping info too short %d\n",
4549 libcfs_id2str(id), nob);
4550 goto fail_ping_buffer_decref;
4553 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) {
4554 lnet_swap_pinginfo(pbuf);
4555 } else if (pbuf->pb_info.pi_magic != LNET_PROTO_PING_MAGIC) {
4556 CERROR("%s: Unexpected magic %08x\n",
4557 libcfs_id2str(id), pbuf->pb_info.pi_magic);
4558 goto fail_ping_buffer_decref;
4561 if ((pbuf->pb_info.pi_features & LNET_PING_FEAT_NI_STATUS) == 0) {
4562 CERROR("%s: ping w/o NI status: 0x%x\n",
4563 libcfs_id2str(id), pbuf->pb_info.pi_features);
4564 goto fail_ping_buffer_decref;
4567 if (nob < LNET_PING_INFO_SIZE(0)) {
4568 CERROR("%s: Short reply %d(%d min)\n",
4570 nob, (int)LNET_PING_INFO_SIZE(0));
4571 goto fail_ping_buffer_decref;
4574 if (pbuf->pb_info.pi_nnis < n_ids)
4575 n_ids = pbuf->pb_info.pi_nnis;
4577 if (nob < LNET_PING_INFO_SIZE(n_ids)) {
4578 CERROR("%s: Short reply %d(%d expected)\n",
4580 nob, (int)LNET_PING_INFO_SIZE(n_ids));
4581 goto fail_ping_buffer_decref;
4584 rc = -EFAULT; /* if I segv in copy_to_user()... */
4586 memset(&tmpid, 0, sizeof(tmpid));
4587 for (i = 0; i < n_ids; i++) {
4588 tmpid.pid = pbuf->pb_info.pi_pid;
4589 tmpid.nid = pbuf->pb_info.pi_ni[i].ns_nid;
4590 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid)))
4591 goto fail_ping_buffer_decref;
4593 rc = pbuf->pb_info.pi_nnis;
4595 fail_ping_buffer_decref:
4596 lnet_ping_buffer_decref(pbuf);
4601 lnet_discover(struct lnet_process_id id, __u32 force,
4602 struct lnet_process_id __user *ids, int n_ids)
4604 struct lnet_peer_ni *lpni;
4605 struct lnet_peer_ni *p;
4606 struct lnet_peer *lp;
4607 struct lnet_process_id *buf;
4613 id.nid == LNET_NID_ANY)
4616 if (id.pid == LNET_PID_ANY)
4617 id.pid = LNET_PID_LUSTRE;
4620 * If the user buffer has more space than the lnet_interfaces_max,
4621 * then only fill it up to lnet_interfaces_max.
4623 if (n_ids > lnet_interfaces_max)
4624 n_ids = lnet_interfaces_max;
4626 CFS_ALLOC_PTR_ARRAY(buf, n_ids);
4630 cpt = lnet_net_lock_current();
4631 lpni = lnet_nid2peerni_locked(id.nid, LNET_NID_ANY, cpt);
4638 * Clearing the NIDS_UPTODATE flag ensures the peer will
4639 * be discovered, provided discovery has not been disabled.
4641 lp = lpni->lpni_peer_net->lpn_peer;
4642 spin_lock(&lp->lp_lock);
4643 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
4644 /* If the force flag is set, force a PING and PUSH as well. */
4646 lp->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH;
4647 spin_unlock(&lp->lp_lock);
4648 rc = lnet_discover_peer_locked(lpni, cpt, true);
4652 /* The lpni (or lp) for this NID may have changed and our ref is
4653 * the only thing keeping the old one around. Release the ref
4654 * and lookup the lpni again
4656 lnet_peer_ni_decref_locked(lpni);
4657 lpni = lnet_find_peer_ni_locked(id.nid);
4662 lp = lpni->lpni_peer_net->lpn_peer;
4666 while ((p = lnet_get_next_peer_ni_locked(lp, NULL, p)) != NULL) {
4667 buf[i].pid = id.pid;
4668 buf[i].nid = p->lpni_nid;
4675 lnet_peer_ni_decref_locked(lpni);
4677 lnet_net_unlock(cpt);
4680 if (copy_to_user(ids, buf, rc * sizeof(*buf)))
4682 CFS_FREE_PTR_ARRAY(buf, n_ids);
4688 * Retrieve peer discovery status.
4690 * \retval 1 if lnet_peer_discovery_disabled is 0
4691 * \retval 0 if lnet_peer_discovery_disabled is 1
4694 LNetGetPeerDiscoveryStatus(void)
4696 return !lnet_peer_discovery_disabled;
4698 EXPORT_SYMBOL(LNetGetPeerDiscoveryStatus);