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>
42 #include <lnet/udsp.h>
43 #include <lnet/lib-lnet.h>
45 #define D_LNI D_CONSOLE
48 * initialize ln_api_mutex statically, since it needs to be used in
49 * discovery_set callback. That module parameter callback can be called
50 * before module init completes. The mutex needs to be ready for use then.
52 struct lnet the_lnet = {
53 .ln_api_mutex = __MUTEX_INITIALIZER(the_lnet.ln_api_mutex),
54 }; /* THE state of the network */
55 EXPORT_SYMBOL(the_lnet);
57 static char *ip2nets = "";
58 module_param(ip2nets, charp, 0444);
59 MODULE_PARM_DESC(ip2nets, "LNET network <- IP table");
61 static char *networks = "";
62 module_param(networks, charp, 0444);
63 MODULE_PARM_DESC(networks, "local networks");
65 static char *routes = "";
66 module_param(routes, charp, 0444);
67 MODULE_PARM_DESC(routes, "routes to non-local networks");
69 static int rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
70 module_param(rnet_htable_size, int, 0444);
71 MODULE_PARM_DESC(rnet_htable_size, "size of remote network hash table");
73 static int use_tcp_bonding;
74 module_param(use_tcp_bonding, int, 0444);
75 MODULE_PARM_DESC(use_tcp_bonding,
76 "use_tcp_bonding parameter has been removed");
78 unsigned int lnet_numa_range = 0;
79 module_param(lnet_numa_range, uint, 0444);
80 MODULE_PARM_DESC(lnet_numa_range,
81 "NUMA range to consider during Multi-Rail selection");
84 * lnet_health_sensitivity determines by how much we decrement the health
85 * value on sending error. The value defaults to 100, which means health
86 * interface health is decremented by 100 points every failure.
88 unsigned int lnet_health_sensitivity = 100;
89 static int sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp);
90 #ifdef HAVE_KERNEL_PARAM_OPS
91 static struct kernel_param_ops param_ops_health_sensitivity = {
92 .set = sensitivity_set,
95 #define param_check_health_sensitivity(name, p) \
96 __param_check(name, p, int)
97 module_param(lnet_health_sensitivity, health_sensitivity, S_IRUGO|S_IWUSR);
99 module_param_call(lnet_health_sensitivity, sensitivity_set, param_get_int,
100 &lnet_health_sensitivity, S_IRUGO|S_IWUSR);
102 MODULE_PARM_DESC(lnet_health_sensitivity,
103 "Value to decrement the health value by on error");
106 * lnet_recovery_interval determines how often we should perform recovery
107 * on unhealthy interfaces.
109 unsigned int lnet_recovery_interval = 1;
110 static int recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp);
111 #ifdef HAVE_KERNEL_PARAM_OPS
112 static struct kernel_param_ops param_ops_recovery_interval = {
113 .set = recovery_interval_set,
114 .get = param_get_int,
116 #define param_check_recovery_interval(name, p) \
117 __param_check(name, p, int)
118 module_param(lnet_recovery_interval, recovery_interval, S_IRUGO|S_IWUSR);
120 module_param_call(lnet_recovery_interval, recovery_interval_set, param_get_int,
121 &lnet_recovery_interval, S_IRUGO|S_IWUSR);
123 MODULE_PARM_DESC(lnet_recovery_interval,
124 "DEPRECATED - Interval to recover unhealthy interfaces in seconds");
126 unsigned int lnet_recovery_limit;
127 module_param(lnet_recovery_limit, uint, 0644);
128 MODULE_PARM_DESC(lnet_recovery_limit,
129 "How long to attempt recovery of unhealthy peer interfaces in seconds. Set to 0 to allow indefinite recovery");
131 static int lnet_interfaces_max = LNET_INTERFACES_MAX_DEFAULT;
132 static int intf_max_set(const char *val, cfs_kernel_param_arg_t *kp);
134 static struct kernel_param_ops param_ops_interfaces_max = {
136 .get = param_get_int,
139 #define param_check_interfaces_max(name, p) \
140 __param_check(name, p, int)
142 #ifdef HAVE_KERNEL_PARAM_OPS
143 module_param(lnet_interfaces_max, interfaces_max, 0644);
145 module_param_call(lnet_interfaces_max, intf_max_set, param_get_int,
146 ¶m_ops_interfaces_max, 0644);
148 MODULE_PARM_DESC(lnet_interfaces_max,
149 "Maximum number of interfaces in a node.");
151 unsigned lnet_peer_discovery_disabled = 0;
152 static int discovery_set(const char *val, cfs_kernel_param_arg_t *kp);
154 static struct kernel_param_ops param_ops_discovery_disabled = {
155 .set = discovery_set,
156 .get = param_get_int,
159 #define param_check_discovery_disabled(name, p) \
160 __param_check(name, p, int)
161 #ifdef HAVE_KERNEL_PARAM_OPS
162 module_param(lnet_peer_discovery_disabled, discovery_disabled, 0644);
164 module_param_call(lnet_peer_discovery_disabled, discovery_set, param_get_int,
165 ¶m_ops_discovery_disabled, 0644);
167 MODULE_PARM_DESC(lnet_peer_discovery_disabled,
168 "Set to 1 to disable peer discovery on this node.");
170 unsigned int lnet_drop_asym_route;
171 static int drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp);
173 static struct kernel_param_ops param_ops_drop_asym_route = {
174 .set = drop_asym_route_set,
175 .get = param_get_int,
178 #define param_check_drop_asym_route(name, p) \
179 __param_check(name, p, int)
180 #ifdef HAVE_KERNEL_PARAM_OPS
181 module_param(lnet_drop_asym_route, drop_asym_route, 0644);
183 module_param_call(lnet_drop_asym_route, drop_asym_route_set, param_get_int,
184 ¶m_ops_drop_asym_route, 0644);
186 MODULE_PARM_DESC(lnet_drop_asym_route,
187 "Set to 1 to drop asymmetrical route messages.");
189 #define LNET_TRANSACTION_TIMEOUT_DEFAULT 50
190 unsigned int lnet_transaction_timeout = LNET_TRANSACTION_TIMEOUT_DEFAULT;
191 static int transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp);
192 #ifdef HAVE_KERNEL_PARAM_OPS
193 static struct kernel_param_ops param_ops_transaction_timeout = {
194 .set = transaction_to_set,
195 .get = param_get_int,
198 #define param_check_transaction_timeout(name, p) \
199 __param_check(name, p, int)
200 module_param(lnet_transaction_timeout, transaction_timeout, S_IRUGO|S_IWUSR);
202 module_param_call(lnet_transaction_timeout, transaction_to_set, param_get_int,
203 &lnet_transaction_timeout, S_IRUGO|S_IWUSR);
205 MODULE_PARM_DESC(lnet_transaction_timeout,
206 "Maximum number of seconds to wait for a peer response.");
208 #define LNET_RETRY_COUNT_DEFAULT 2
209 unsigned int lnet_retry_count = LNET_RETRY_COUNT_DEFAULT;
210 static int retry_count_set(const char *val, cfs_kernel_param_arg_t *kp);
211 #ifdef HAVE_KERNEL_PARAM_OPS
212 static struct kernel_param_ops param_ops_retry_count = {
213 .set = retry_count_set,
214 .get = param_get_int,
217 #define param_check_retry_count(name, p) \
218 __param_check(name, p, int)
219 module_param(lnet_retry_count, retry_count, S_IRUGO|S_IWUSR);
221 module_param_call(lnet_retry_count, retry_count_set, param_get_int,
222 &lnet_retry_count, S_IRUGO|S_IWUSR);
224 MODULE_PARM_DESC(lnet_retry_count,
225 "Maximum number of times to retry transmitting a message");
227 unsigned int lnet_response_tracking = 3;
228 static int response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp);
230 #ifdef HAVE_KERNEL_PARAM_OPS
231 static struct kernel_param_ops param_ops_response_tracking = {
232 .set = response_tracking_set,
233 .get = param_get_int,
236 #define param_check_response_tracking(name, p) \
237 __param_check(name, p, int)
238 module_param(lnet_response_tracking, response_tracking, 0644);
240 module_param_call(lnet_response_tracking, response_tracking_set, param_get_int,
241 &lnet_response_tracking, 0644);
243 MODULE_PARM_DESC(lnet_response_tracking,
244 "(0|1|2|3) LNet Internal Only|GET Reply only|PUT ACK only|Full Tracking (default)");
246 #define LNET_LND_TIMEOUT_DEFAULT ((LNET_TRANSACTION_TIMEOUT_DEFAULT - 1) / \
247 (LNET_RETRY_COUNT_DEFAULT + 1))
248 unsigned int lnet_lnd_timeout = LNET_LND_TIMEOUT_DEFAULT;
249 static void lnet_set_lnd_timeout(void)
251 lnet_lnd_timeout = (lnet_transaction_timeout - 1) /
252 (lnet_retry_count + 1);
256 * This sequence number keeps track of how many times DLC was used to
257 * update the local NIs. It is incremented when a NI is added or
258 * removed and checked when sending a message to determine if there is
259 * a need to re-run the selection algorithm. See lnet_select_pathway()
260 * for more details on its usage.
262 static atomic_t lnet_dlc_seq_no = ATOMIC_INIT(0);
264 static int lnet_ping(struct lnet_process_id id, signed long timeout,
265 struct lnet_process_id __user *ids, int n_ids);
267 static int lnet_discover(struct lnet_process_id id, __u32 force,
268 struct lnet_process_id __user *ids, int n_ids);
271 sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
274 unsigned *sensitivity = (unsigned *)kp->arg;
277 rc = kstrtoul(val, 0, &value);
279 CERROR("Invalid module parameter value for 'lnet_health_sensitivity'\n");
284 * The purpose of locking the api_mutex here is to ensure that
285 * the correct value ends up stored properly.
287 mutex_lock(&the_lnet.ln_api_mutex);
289 if (value > LNET_MAX_HEALTH_VALUE) {
290 mutex_unlock(&the_lnet.ln_api_mutex);
291 CERROR("Invalid health value. Maximum: %d value = %lu\n",
292 LNET_MAX_HEALTH_VALUE, value);
296 if (*sensitivity != 0 && value == 0 && lnet_retry_count != 0) {
297 lnet_retry_count = 0;
298 lnet_set_lnd_timeout();
301 *sensitivity = value;
303 mutex_unlock(&the_lnet.ln_api_mutex);
309 recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp)
311 CWARN("'lnet_recovery_interval' has been deprecated\n");
317 discovery_set(const char *val, cfs_kernel_param_arg_t *kp)
320 unsigned *discovery_off = (unsigned *)kp->arg;
322 struct lnet_ping_buffer *pbuf;
324 rc = kstrtoul(val, 0, &value);
326 CERROR("Invalid module parameter value for 'lnet_peer_discovery_disabled'\n");
330 value = (value) ? 1 : 0;
333 * The purpose of locking the api_mutex here is to ensure that
334 * the correct value ends up stored properly.
336 mutex_lock(&the_lnet.ln_api_mutex);
338 if (value == *discovery_off) {
339 mutex_unlock(&the_lnet.ln_api_mutex);
344 * We still want to set the discovery value even when LNet is not
345 * running. This is the case when LNet is being loaded and we want
346 * the module parameters to take effect. Otherwise if we're
347 * changing the value dynamically, we want to set it after
350 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
351 *discovery_off = value;
352 mutex_unlock(&the_lnet.ln_api_mutex);
356 /* tell peers that discovery setting has changed */
357 lnet_net_lock(LNET_LOCK_EX);
358 pbuf = the_lnet.ln_ping_target;
360 pbuf->pb_info.pi_features &= ~LNET_PING_FEAT_DISCOVERY;
362 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
363 lnet_net_unlock(LNET_LOCK_EX);
365 /* only send a push when we're turning off discovery */
366 if (*discovery_off <= 0 && value > 0)
367 lnet_push_update_to_peers(1);
368 *discovery_off = value;
370 mutex_unlock(&the_lnet.ln_api_mutex);
376 drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp)
379 unsigned int *drop_asym_route = (unsigned int *)kp->arg;
382 rc = kstrtoul(val, 0, &value);
384 CERROR("Invalid module parameter value for "
385 "'lnet_drop_asym_route'\n");
390 * The purpose of locking the api_mutex here is to ensure that
391 * the correct value ends up stored properly.
393 mutex_lock(&the_lnet.ln_api_mutex);
395 if (value == *drop_asym_route) {
396 mutex_unlock(&the_lnet.ln_api_mutex);
400 *drop_asym_route = value;
402 mutex_unlock(&the_lnet.ln_api_mutex);
408 transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp)
411 unsigned *transaction_to = (unsigned *)kp->arg;
414 rc = kstrtoul(val, 0, &value);
416 CERROR("Invalid module parameter value for 'lnet_transaction_timeout'\n");
421 * The purpose of locking the api_mutex here is to ensure that
422 * the correct value ends up stored properly.
424 mutex_lock(&the_lnet.ln_api_mutex);
426 if (value <= lnet_retry_count || value == 0) {
427 mutex_unlock(&the_lnet.ln_api_mutex);
428 CERROR("Invalid value for lnet_transaction_timeout (%lu). "
429 "Has to be greater than lnet_retry_count (%u)\n",
430 value, lnet_retry_count);
434 if (value == *transaction_to) {
435 mutex_unlock(&the_lnet.ln_api_mutex);
439 *transaction_to = value;
440 /* Update the lnet_lnd_timeout now that we've modified the
441 * transaction timeout
443 lnet_set_lnd_timeout();
445 mutex_unlock(&the_lnet.ln_api_mutex);
451 retry_count_set(const char *val, cfs_kernel_param_arg_t *kp)
454 unsigned *retry_count = (unsigned *)kp->arg;
457 rc = kstrtoul(val, 0, &value);
459 CERROR("Invalid module parameter value for 'lnet_retry_count'\n");
464 * The purpose of locking the api_mutex here is to ensure that
465 * the correct value ends up stored properly.
467 mutex_lock(&the_lnet.ln_api_mutex);
469 if (lnet_health_sensitivity == 0 && value > 0) {
470 mutex_unlock(&the_lnet.ln_api_mutex);
471 CERROR("Can not set lnet_retry_count when health feature is turned off\n");
475 if (value > lnet_transaction_timeout) {
476 mutex_unlock(&the_lnet.ln_api_mutex);
477 CERROR("Invalid value for lnet_retry_count (%lu). "
478 "Has to be smaller than lnet_transaction_timeout (%u)\n",
479 value, lnet_transaction_timeout);
483 *retry_count = value;
485 /* Update the lnet_lnd_timeout now that we've modified the
488 lnet_set_lnd_timeout();
490 mutex_unlock(&the_lnet.ln_api_mutex);
496 intf_max_set(const char *val, cfs_kernel_param_arg_t *kp)
500 rc = kstrtoint(val, 0, &value);
502 CERROR("Invalid module parameter value for 'lnet_interfaces_max'\n");
506 if (value < LNET_INTERFACES_MIN) {
507 CWARN("max interfaces provided are too small, setting to %d\n",
508 LNET_INTERFACES_MAX_DEFAULT);
509 value = LNET_INTERFACES_MAX_DEFAULT;
512 *(int *)kp->arg = value;
518 response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp)
521 unsigned long new_value;
523 rc = kstrtoul(val, 0, &new_value);
525 CERROR("Invalid value for 'lnet_response_tracking'\n");
529 if (new_value < 0 || new_value > 3) {
530 CWARN("Invalid value (%lu) for 'lnet_response_tracking'\n",
535 lnet_response_tracking = new_value;
541 lnet_get_routes(void)
547 lnet_get_networks(void)
552 if (*networks != 0 && *ip2nets != 0) {
553 LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
554 "'ip2nets' but not both at once\n");
559 rc = lnet_parse_ip2nets(&nets, ip2nets);
560 return (rc == 0) ? nets : NULL;
570 lnet_init_locks(void)
572 spin_lock_init(&the_lnet.ln_eq_wait_lock);
573 spin_lock_init(&the_lnet.ln_msg_resend_lock);
574 init_completion(&the_lnet.ln_mt_wait_complete);
575 mutex_init(&the_lnet.ln_lnd_mutex);
578 struct kmem_cache *lnet_mes_cachep; /* MEs kmem_cache */
579 struct kmem_cache *lnet_small_mds_cachep; /* <= LNET_SMALL_MD_SIZE bytes
581 struct kmem_cache *lnet_udsp_cachep; /* udsp cache */
582 struct kmem_cache *lnet_rspt_cachep; /* response tracker cache */
583 struct kmem_cache *lnet_msg_cachep;
586 lnet_slab_setup(void)
588 /* create specific kmem_cache for MEs and small MDs (i.e., originally
589 * allocated in <size-xxx> kmem_cache).
591 lnet_mes_cachep = kmem_cache_create("lnet_MEs", sizeof(struct lnet_me),
593 if (!lnet_mes_cachep)
596 lnet_small_mds_cachep = kmem_cache_create("lnet_small_MDs",
597 LNET_SMALL_MD_SIZE, 0, 0,
599 if (!lnet_small_mds_cachep)
602 lnet_udsp_cachep = kmem_cache_create("lnet_udsp",
603 sizeof(struct lnet_udsp),
605 if (!lnet_udsp_cachep)
608 lnet_rspt_cachep = kmem_cache_create("lnet_rspt", sizeof(struct lnet_rsp_tracker),
610 if (!lnet_rspt_cachep)
613 lnet_msg_cachep = kmem_cache_create("lnet_msg", sizeof(struct lnet_msg),
615 if (!lnet_msg_cachep)
622 lnet_slab_cleanup(void)
624 if (lnet_msg_cachep) {
625 kmem_cache_destroy(lnet_msg_cachep);
626 lnet_msg_cachep = NULL;
629 if (lnet_rspt_cachep) {
630 kmem_cache_destroy(lnet_rspt_cachep);
631 lnet_rspt_cachep = NULL;
634 if (lnet_udsp_cachep) {
635 kmem_cache_destroy(lnet_udsp_cachep);
636 lnet_udsp_cachep = NULL;
639 if (lnet_small_mds_cachep) {
640 kmem_cache_destroy(lnet_small_mds_cachep);
641 lnet_small_mds_cachep = NULL;
644 if (lnet_mes_cachep) {
645 kmem_cache_destroy(lnet_mes_cachep);
646 lnet_mes_cachep = NULL;
651 lnet_create_remote_nets_table(void)
654 struct list_head *hash;
656 LASSERT(the_lnet.ln_remote_nets_hash == NULL);
657 LASSERT(the_lnet.ln_remote_nets_hbits > 0);
658 CFS_ALLOC_PTR_ARRAY(hash, LNET_REMOTE_NETS_HASH_SIZE);
660 CERROR("Failed to create remote nets hash table\n");
664 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
665 INIT_LIST_HEAD(&hash[i]);
666 the_lnet.ln_remote_nets_hash = hash;
671 lnet_destroy_remote_nets_table(void)
675 if (the_lnet.ln_remote_nets_hash == NULL)
678 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
679 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
681 CFS_FREE_PTR_ARRAY(the_lnet.ln_remote_nets_hash,
682 LNET_REMOTE_NETS_HASH_SIZE);
683 the_lnet.ln_remote_nets_hash = NULL;
687 lnet_destroy_locks(void)
689 if (the_lnet.ln_res_lock != NULL) {
690 cfs_percpt_lock_free(the_lnet.ln_res_lock);
691 the_lnet.ln_res_lock = NULL;
694 if (the_lnet.ln_net_lock != NULL) {
695 cfs_percpt_lock_free(the_lnet.ln_net_lock);
696 the_lnet.ln_net_lock = NULL;
701 lnet_create_locks(void)
705 the_lnet.ln_res_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
706 if (the_lnet.ln_res_lock == NULL)
709 the_lnet.ln_net_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
710 if (the_lnet.ln_net_lock == NULL)
716 lnet_destroy_locks();
720 static void lnet_assert_wire_constants(void)
722 /* Wire protocol assertions generated by 'wirecheck'
723 * running on Linux robert.bartonsoftware.com 2.6.8-1.521
724 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux
725 * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
729 BUILD_BUG_ON(LNET_PROTO_TCP_MAGIC != 0xeebc0ded);
730 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MAJOR != 1);
731 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MINOR != 0);
732 BUILD_BUG_ON(LNET_MSG_ACK != 0);
733 BUILD_BUG_ON(LNET_MSG_PUT != 1);
734 BUILD_BUG_ON(LNET_MSG_GET != 2);
735 BUILD_BUG_ON(LNET_MSG_REPLY != 3);
736 BUILD_BUG_ON(LNET_MSG_HELLO != 4);
738 BUILD_BUG_ON((int)sizeof(lnet_nid_t) != 8);
739 BUILD_BUG_ON((int)sizeof(lnet_pid_t) != 4);
741 /* Checks for struct lnet_nid */
742 BUILD_BUG_ON((int)sizeof(struct lnet_nid) != 20);
743 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_size) != 0);
744 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_size) != 1);
745 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_type) != 1);
746 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_type) != 1);
747 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_num) != 2);
748 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_num) != 2);
749 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_addr) != 4);
750 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_addr) != 16);
752 /* Checks for struct lnet_process_id_packed */
753 BUILD_BUG_ON((int)sizeof(struct lnet_process_id_packed) != 12);
754 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, nid) != 0);
755 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->nid) != 8);
756 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, pid) != 8);
757 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->pid) != 4);
759 /* Checks for struct lnet_handle_wire */
760 BUILD_BUG_ON((int)sizeof(struct lnet_handle_wire) != 16);
761 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
762 wh_interface_cookie) != 0);
763 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_interface_cookie) != 8);
764 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
765 wh_object_cookie) != 8);
766 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_object_cookie) != 8);
768 /* Checks for struct struct lnet_magicversion */
769 BUILD_BUG_ON((int)sizeof(struct lnet_magicversion) != 8);
770 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, magic) != 0);
771 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->magic) != 4);
772 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, version_major) != 4);
773 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_major) != 2);
774 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion,
775 version_minor) != 6);
776 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_minor) != 2);
778 /* Checks for struct struct lnet_hdr */
779 BUILD_BUG_ON((int)sizeof(struct lnet_hdr) != 72);
780 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, dest_nid) != 0);
781 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->dest_nid) != 8);
782 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, src_nid) != 8);
783 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->src_nid) != 8);
784 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, dest_pid) != 16);
785 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->dest_pid) != 4);
786 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, src_pid) != 20);
787 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->src_pid) != 4);
788 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, type) != 24);
789 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->type) != 4);
790 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, payload_length) != 28);
791 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->payload_length) != 4);
792 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg) != 32);
793 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg) != 40);
796 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.dst_wmd) != 32);
797 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.dst_wmd) != 16);
798 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.match_bits) != 48);
799 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.match_bits) != 8);
800 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.mlength) != 56);
801 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.mlength) != 4);
804 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.ack_wmd) != 32);
805 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.ack_wmd) != 16);
806 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.match_bits) != 48);
807 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.match_bits) != 8);
808 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.hdr_data) != 56);
809 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.hdr_data) != 8);
810 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.ptl_index) != 64);
811 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.ptl_index) != 4);
812 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.offset) != 68);
813 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.offset) != 4);
816 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.return_wmd) != 32);
817 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.return_wmd) != 16);
818 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.match_bits) != 48);
819 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.match_bits) != 8);
820 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.ptl_index) != 56);
821 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.ptl_index) != 4);
822 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.src_offset) != 60);
823 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.src_offset) != 4);
824 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.sink_length) != 64);
825 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.sink_length) != 4);
828 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.reply.dst_wmd) != 32);
829 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.reply.dst_wmd) != 16);
832 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.hello.incarnation) != 32);
833 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.hello.incarnation) != 8);
834 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.hello.type) != 40);
835 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.hello.type) != 4);
837 /* Checks for struct lnet_ni_status and related constants */
838 BUILD_BUG_ON(LNET_NI_STATUS_INVALID != 0x00000000);
839 BUILD_BUG_ON(LNET_NI_STATUS_UP != 0x15aac0de);
840 BUILD_BUG_ON(LNET_NI_STATUS_DOWN != 0xdeadface);
842 /* Checks for struct lnet_ni_status */
843 BUILD_BUG_ON((int)sizeof(struct lnet_ni_status) != 16);
844 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_nid) != 0);
845 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_nid) != 8);
846 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_status) != 8);
847 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_status) != 4);
848 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_unused) != 12);
849 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_unused) != 4);
851 /* Checks for struct lnet_ping_info and related constants */
852 BUILD_BUG_ON(LNET_PROTO_PING_MAGIC != 0x70696E67);
853 BUILD_BUG_ON(LNET_PING_FEAT_INVAL != 0);
854 BUILD_BUG_ON(LNET_PING_FEAT_BASE != 1);
855 BUILD_BUG_ON(LNET_PING_FEAT_NI_STATUS != 2);
856 BUILD_BUG_ON(LNET_PING_FEAT_RTE_DISABLED != 4);
857 BUILD_BUG_ON(LNET_PING_FEAT_MULTI_RAIL != 8);
858 BUILD_BUG_ON(LNET_PING_FEAT_DISCOVERY != 16);
859 BUILD_BUG_ON(LNET_PING_FEAT_BITS != 31);
861 /* Checks for struct lnet_ping_info */
862 BUILD_BUG_ON((int)sizeof(struct lnet_ping_info) != 16);
863 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_magic) != 0);
864 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_magic) != 4);
865 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_features) != 4);
866 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_features) != 4);
867 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_pid) != 8);
868 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_pid) != 4);
869 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_nnis) != 12);
870 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_nnis) != 4);
871 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_ni) != 16);
872 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_ni) != 0);
874 /* Acceptor connection request */
875 BUILD_BUG_ON(LNET_PROTO_ACCEPTOR_VERSION != 1);
877 /* Checks for struct lnet_acceptor_connreq */
878 BUILD_BUG_ON((int)sizeof(struct lnet_acceptor_connreq) != 16);
879 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_magic) != 0);
880 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_magic) != 4);
881 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_version) != 4);
882 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_version) != 4);
883 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_nid) != 8);
884 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_nid) != 8);
886 /* Checks for struct lnet_counters_common */
887 BUILD_BUG_ON((int)sizeof(struct lnet_counters_common) != 60);
888 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_alloc) != 0);
889 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_alloc) != 4);
890 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_max) != 4);
891 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_max) != 4);
892 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_errors) != 8);
893 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_errors) != 4);
894 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_count) != 12);
895 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_count) != 4);
896 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_count) != 16);
897 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_count) != 4);
898 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_count) != 20);
899 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_count) != 4);
900 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_count) != 24);
901 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_count) != 4);
902 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_length) != 28);
903 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_length) != 8);
904 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_length) != 36);
905 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_length) != 8);
906 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_length) != 44);
907 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_length) != 8);
908 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_length) != 52);
909 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_length) != 8);
912 static const struct lnet_lnd *lnet_find_lnd_by_type(__u32 type)
914 const struct lnet_lnd *lnd;
916 /* holding lnd mutex */
917 if (type >= NUM_LNDS)
919 lnd = the_lnet.ln_lnds[type];
920 LASSERT(!lnd || lnd->lnd_type == type);
926 lnet_get_lnd_timeout(void)
928 return lnet_lnd_timeout;
930 EXPORT_SYMBOL(lnet_get_lnd_timeout);
933 lnet_register_lnd(const struct lnet_lnd *lnd)
935 mutex_lock(&the_lnet.ln_lnd_mutex);
937 LASSERT(libcfs_isknown_lnd(lnd->lnd_type));
938 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
940 the_lnet.ln_lnds[lnd->lnd_type] = lnd;
942 CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type));
944 mutex_unlock(&the_lnet.ln_lnd_mutex);
946 EXPORT_SYMBOL(lnet_register_lnd);
949 lnet_unregister_lnd(const struct lnet_lnd *lnd)
951 mutex_lock(&the_lnet.ln_lnd_mutex);
953 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
955 the_lnet.ln_lnds[lnd->lnd_type] = NULL;
956 CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type));
958 mutex_unlock(&the_lnet.ln_lnd_mutex);
960 EXPORT_SYMBOL(lnet_unregister_lnd);
963 lnet_counters_get_common_locked(struct lnet_counters_common *common)
965 struct lnet_counters *ctr;
968 /* FIXME !!! Their is no assert_lnet_net_locked() to ensure this
969 * actually called under the protection of the lnet_net_lock.
971 memset(common, 0, sizeof(*common));
973 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
974 common->lcc_msgs_max += ctr->lct_common.lcc_msgs_max;
975 common->lcc_msgs_alloc += ctr->lct_common.lcc_msgs_alloc;
976 common->lcc_errors += ctr->lct_common.lcc_errors;
977 common->lcc_send_count += ctr->lct_common.lcc_send_count;
978 common->lcc_recv_count += ctr->lct_common.lcc_recv_count;
979 common->lcc_route_count += ctr->lct_common.lcc_route_count;
980 common->lcc_drop_count += ctr->lct_common.lcc_drop_count;
981 common->lcc_send_length += ctr->lct_common.lcc_send_length;
982 common->lcc_recv_length += ctr->lct_common.lcc_recv_length;
983 common->lcc_route_length += ctr->lct_common.lcc_route_length;
984 common->lcc_drop_length += ctr->lct_common.lcc_drop_length;
989 lnet_counters_get_common(struct lnet_counters_common *common)
991 lnet_net_lock(LNET_LOCK_EX);
992 lnet_counters_get_common_locked(common);
993 lnet_net_unlock(LNET_LOCK_EX);
995 EXPORT_SYMBOL(lnet_counters_get_common);
998 lnet_counters_get(struct lnet_counters *counters)
1000 struct lnet_counters *ctr;
1001 struct lnet_counters_health *health = &counters->lct_health;
1004 memset(counters, 0, sizeof(*counters));
1006 lnet_net_lock(LNET_LOCK_EX);
1008 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1009 GOTO(out_unlock, rc = -ENODEV);
1011 lnet_counters_get_common_locked(&counters->lct_common);
1013 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
1014 health->lch_rst_alloc += ctr->lct_health.lch_rst_alloc;
1015 health->lch_resend_count += ctr->lct_health.lch_resend_count;
1016 health->lch_response_timeout_count +=
1017 ctr->lct_health.lch_response_timeout_count;
1018 health->lch_local_interrupt_count +=
1019 ctr->lct_health.lch_local_interrupt_count;
1020 health->lch_local_dropped_count +=
1021 ctr->lct_health.lch_local_dropped_count;
1022 health->lch_local_aborted_count +=
1023 ctr->lct_health.lch_local_aborted_count;
1024 health->lch_local_no_route_count +=
1025 ctr->lct_health.lch_local_no_route_count;
1026 health->lch_local_timeout_count +=
1027 ctr->lct_health.lch_local_timeout_count;
1028 health->lch_local_error_count +=
1029 ctr->lct_health.lch_local_error_count;
1030 health->lch_remote_dropped_count +=
1031 ctr->lct_health.lch_remote_dropped_count;
1032 health->lch_remote_error_count +=
1033 ctr->lct_health.lch_remote_error_count;
1034 health->lch_remote_timeout_count +=
1035 ctr->lct_health.lch_remote_timeout_count;
1036 health->lch_network_timeout_count +=
1037 ctr->lct_health.lch_network_timeout_count;
1040 lnet_net_unlock(LNET_LOCK_EX);
1043 EXPORT_SYMBOL(lnet_counters_get);
1046 lnet_counters_reset(void)
1048 struct lnet_counters *counters;
1051 lnet_net_lock(LNET_LOCK_EX);
1053 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1056 cfs_percpt_for_each(counters, i, the_lnet.ln_counters)
1057 memset(counters, 0, sizeof(struct lnet_counters));
1059 lnet_net_unlock(LNET_LOCK_EX);
1063 lnet_res_type2str(int type)
1068 case LNET_COOKIE_TYPE_MD:
1070 case LNET_COOKIE_TYPE_ME:
1072 case LNET_COOKIE_TYPE_EQ:
1078 lnet_res_container_cleanup(struct lnet_res_container *rec)
1082 if (rec->rec_type == 0) /* not set yet, it's uninitialized */
1085 while (!list_empty(&rec->rec_active)) {
1086 struct list_head *e = rec->rec_active.next;
1089 if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
1090 lnet_md_free(list_entry(e, struct lnet_libmd, md_list));
1092 } else { /* NB: Active MEs should be attached on portals */
1099 /* Found alive MD/ME/EQ, user really should unlink/free
1100 * all of them before finalize LNet, but if someone didn't,
1101 * we have to recycle garbage for him */
1102 CERROR("%d active elements on exit of %s container\n",
1103 count, lnet_res_type2str(rec->rec_type));
1106 if (rec->rec_lh_hash != NULL) {
1107 CFS_FREE_PTR_ARRAY(rec->rec_lh_hash, LNET_LH_HASH_SIZE);
1108 rec->rec_lh_hash = NULL;
1111 rec->rec_type = 0; /* mark it as finalized */
1115 lnet_res_container_setup(struct lnet_res_container *rec, int cpt, int type)
1120 LASSERT(rec->rec_type == 0);
1122 rec->rec_type = type;
1123 INIT_LIST_HEAD(&rec->rec_active);
1125 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type;
1127 /* Arbitrary choice of hash table size */
1128 LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt,
1129 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
1130 if (rec->rec_lh_hash == NULL) {
1135 for (i = 0; i < LNET_LH_HASH_SIZE; i++)
1136 INIT_LIST_HEAD(&rec->rec_lh_hash[i]);
1141 CERROR("Failed to setup %s resource container\n",
1142 lnet_res_type2str(type));
1143 lnet_res_container_cleanup(rec);
1148 lnet_res_containers_destroy(struct lnet_res_container **recs)
1150 struct lnet_res_container *rec;
1153 cfs_percpt_for_each(rec, i, recs)
1154 lnet_res_container_cleanup(rec);
1156 cfs_percpt_free(recs);
1159 static struct lnet_res_container **
1160 lnet_res_containers_create(int type)
1162 struct lnet_res_container **recs;
1163 struct lnet_res_container *rec;
1167 recs = cfs_percpt_alloc(lnet_cpt_table(), sizeof(*rec));
1169 CERROR("Failed to allocate %s resource containers\n",
1170 lnet_res_type2str(type));
1174 cfs_percpt_for_each(rec, i, recs) {
1175 rc = lnet_res_container_setup(rec, i, type);
1177 lnet_res_containers_destroy(recs);
1185 struct lnet_libhandle *
1186 lnet_res_lh_lookup(struct lnet_res_container *rec, __u64 cookie)
1188 /* ALWAYS called with lnet_res_lock held */
1189 struct list_head *head;
1190 struct lnet_libhandle *lh;
1193 if ((cookie & LNET_COOKIE_MASK) != rec->rec_type)
1196 hash = cookie >> (LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS);
1197 head = &rec->rec_lh_hash[hash & LNET_LH_HASH_MASK];
1199 list_for_each_entry(lh, head, lh_hash_chain) {
1200 if (lh->lh_cookie == cookie)
1208 lnet_res_lh_initialize(struct lnet_res_container *rec,
1209 struct lnet_libhandle *lh)
1211 /* ALWAYS called with lnet_res_lock held */
1212 unsigned int ibits = LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS;
1215 lh->lh_cookie = rec->rec_lh_cookie;
1216 rec->rec_lh_cookie += 1 << ibits;
1218 hash = (lh->lh_cookie >> ibits) & LNET_LH_HASH_MASK;
1220 list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
1224 lnet_create_array_of_queues(void)
1226 struct list_head **qs;
1227 struct list_head *q;
1230 qs = cfs_percpt_alloc(lnet_cpt_table(),
1231 sizeof(struct list_head));
1233 CERROR("Failed to allocate queues\n");
1237 cfs_percpt_for_each(q, i, qs)
1243 static int lnet_unprepare(void);
1246 lnet_prepare(lnet_pid_t requested_pid)
1248 /* Prepare to bring up the network */
1249 struct lnet_res_container **recs;
1252 if (requested_pid == LNET_PID_ANY) {
1253 /* Don't instantiate LNET just for me */
1257 LASSERT(the_lnet.ln_refcount == 0);
1259 the_lnet.ln_routing = 0;
1261 LASSERT((requested_pid & LNET_PID_USERFLAG) == 0);
1262 the_lnet.ln_pid = requested_pid;
1264 INIT_LIST_HEAD(&the_lnet.ln_test_peers);
1265 INIT_LIST_HEAD(&the_lnet.ln_remote_peer_ni_list);
1266 INIT_LIST_HEAD(&the_lnet.ln_nets);
1267 INIT_LIST_HEAD(&the_lnet.ln_routers);
1268 INIT_LIST_HEAD(&the_lnet.ln_drop_rules);
1269 INIT_LIST_HEAD(&the_lnet.ln_delay_rules);
1270 INIT_LIST_HEAD(&the_lnet.ln_dc_request);
1271 INIT_LIST_HEAD(&the_lnet.ln_dc_working);
1272 INIT_LIST_HEAD(&the_lnet.ln_dc_expired);
1273 INIT_LIST_HEAD(&the_lnet.ln_mt_localNIRecovq);
1274 INIT_LIST_HEAD(&the_lnet.ln_mt_peerNIRecovq);
1275 INIT_LIST_HEAD(&the_lnet.ln_udsp_list);
1276 init_waitqueue_head(&the_lnet.ln_dc_waitq);
1277 the_lnet.ln_mt_handler = NULL;
1278 init_completion(&the_lnet.ln_started);
1280 rc = lnet_slab_setup();
1284 rc = lnet_create_remote_nets_table();
1289 * NB the interface cookie in wire handles guards against delayed
1290 * replies and ACKs appearing valid after reboot.
1292 the_lnet.ln_interface_cookie = ktime_get_real_ns();
1294 the_lnet.ln_counters = cfs_percpt_alloc(lnet_cpt_table(),
1295 sizeof(struct lnet_counters));
1296 if (the_lnet.ln_counters == NULL) {
1297 CERROR("Failed to allocate counters for LNet\n");
1302 rc = lnet_peer_tables_create();
1306 rc = lnet_msg_containers_create();
1310 rc = lnet_res_container_setup(&the_lnet.ln_eq_container, 0,
1311 LNET_COOKIE_TYPE_EQ);
1315 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD);
1321 the_lnet.ln_md_containers = recs;
1323 rc = lnet_portals_create();
1325 CERROR("Failed to create portals for LNet: %d\n", rc);
1329 the_lnet.ln_mt_zombie_rstqs = lnet_create_array_of_queues();
1330 if (!the_lnet.ln_mt_zombie_rstqs) {
1343 lnet_unprepare (void)
1345 /* NB no LNET_LOCK since this is the last reference. All LND instances
1346 * have shut down already, so it is safe to unlink and free all
1347 * descriptors, even those that appear committed to a network op (eg MD
1348 * with non-zero pending count) */
1350 lnet_fail_nid(LNET_NID_ANY, 0);
1352 LASSERT(the_lnet.ln_refcount == 0);
1353 LASSERT(list_empty(&the_lnet.ln_test_peers));
1354 LASSERT(list_empty(&the_lnet.ln_nets));
1356 if (the_lnet.ln_mt_zombie_rstqs) {
1357 lnet_clean_zombie_rstqs();
1358 the_lnet.ln_mt_zombie_rstqs = NULL;
1361 lnet_assert_handler_unused(the_lnet.ln_mt_handler);
1362 the_lnet.ln_mt_handler = NULL;
1364 lnet_portals_destroy();
1366 if (the_lnet.ln_md_containers != NULL) {
1367 lnet_res_containers_destroy(the_lnet.ln_md_containers);
1368 the_lnet.ln_md_containers = NULL;
1371 lnet_res_container_cleanup(&the_lnet.ln_eq_container);
1373 lnet_msg_containers_destroy();
1375 lnet_rtrpools_free(0);
1377 if (the_lnet.ln_counters != NULL) {
1378 cfs_percpt_free(the_lnet.ln_counters);
1379 the_lnet.ln_counters = NULL;
1381 lnet_destroy_remote_nets_table();
1382 lnet_udsp_destroy(true);
1383 lnet_slab_cleanup();
1389 lnet_net2ni_locked(__u32 net_id, int cpt)
1392 struct lnet_net *net;
1394 LASSERT(cpt != LNET_LOCK_EX);
1396 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1397 if (net->net_id == net_id) {
1398 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
1408 lnet_net2ni_addref(__u32 net)
1413 ni = lnet_net2ni_locked(net, 0);
1415 lnet_ni_addref_locked(ni, 0);
1420 EXPORT_SYMBOL(lnet_net2ni_addref);
1423 lnet_get_net_locked(__u32 net_id)
1425 struct lnet_net *net;
1427 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1428 if (net->net_id == net_id)
1436 lnet_net_clr_pref_rtrs(struct lnet_net *net)
1438 struct list_head zombies;
1439 struct lnet_nid_list *ne;
1440 struct lnet_nid_list *tmp;
1442 INIT_LIST_HEAD(&zombies);
1444 lnet_net_lock(LNET_LOCK_EX);
1445 list_splice_init(&net->net_rtr_pref_nids, &zombies);
1446 lnet_net_unlock(LNET_LOCK_EX);
1448 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1449 list_del_init(&ne->nl_list);
1450 LIBCFS_FREE(ne, sizeof(*ne));
1455 lnet_net_add_pref_rtr(struct lnet_net *net,
1457 __must_hold(&the_lnet.ln_api_mutex)
1459 struct lnet_nid_list *ne;
1461 /* This function is called with api_mutex held. When the api_mutex
1462 * is held the list can not be modified, as it is only modified as
1463 * a result of applying a UDSP and that happens under api_mutex
1466 list_for_each_entry(ne, &net->net_rtr_pref_nids, nl_list) {
1467 if (ne->nl_nid == gw_nid)
1471 LIBCFS_ALLOC(ne, sizeof(*ne));
1475 ne->nl_nid = gw_nid;
1477 /* Lock the cpt to protect against addition and checks in the
1478 * selection algorithm
1480 lnet_net_lock(LNET_LOCK_EX);
1481 list_add(&ne->nl_list, &net->net_rtr_pref_nids);
1482 lnet_net_unlock(LNET_LOCK_EX);
1488 lnet_net_is_pref_rtr_locked(struct lnet_net *net, lnet_nid_t rtr_nid)
1490 struct lnet_nid_list *ne;
1492 CDEBUG(D_NET, "%s: rtr pref emtpy: %d\n",
1493 libcfs_net2str(net->net_id),
1494 list_empty(&net->net_rtr_pref_nids));
1496 if (list_empty(&net->net_rtr_pref_nids))
1499 list_for_each_entry(ne, &net->net_rtr_pref_nids, nl_list) {
1500 CDEBUG(D_NET, "Comparing pref %s with gw %s\n",
1501 libcfs_nid2str(ne->nl_nid),
1502 libcfs_nid2str(rtr_nid));
1503 if (rtr_nid == ne->nl_nid)
1511 lnet_nid_cpt_hash(lnet_nid_t nid, unsigned int number)
1516 LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
1521 val = hash_long(key, LNET_CPT_BITS);
1522 /* NB: LNET_CP_NUMBER doesn't have to be PO2 */
1526 return (unsigned int)(key + val + (val >> 1)) % number;
1530 lnet_cpt_of_nid_locked(lnet_nid_t nid, struct lnet_ni *ni)
1532 struct lnet_net *net;
1534 /* must called with hold of lnet_net_lock */
1535 if (LNET_CPT_NUMBER == 1)
1536 return 0; /* the only one */
1539 * If NI is provided then use the CPT identified in the NI cpt
1540 * list if one exists. If one doesn't exist, then that NI is
1541 * associated with all CPTs and it follows that the net it belongs
1542 * to is implicitly associated with all CPTs, so just hash the nid
1546 if (ni->ni_cpts != NULL)
1547 return ni->ni_cpts[lnet_nid_cpt_hash(nid,
1550 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1553 /* no NI provided so look at the net */
1554 net = lnet_get_net_locked(LNET_NIDNET(nid));
1556 if (net != NULL && net->net_cpts != NULL) {
1557 return net->net_cpts[lnet_nid_cpt_hash(nid, net->net_ncpts)];
1560 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1564 lnet_cpt_of_nid(lnet_nid_t nid, struct lnet_ni *ni)
1569 if (LNET_CPT_NUMBER == 1)
1570 return 0; /* the only one */
1572 cpt = lnet_net_lock_current();
1574 cpt2 = lnet_cpt_of_nid_locked(nid, ni);
1576 lnet_net_unlock(cpt);
1580 EXPORT_SYMBOL(lnet_cpt_of_nid);
1583 lnet_islocalnet_locked(__u32 net_id)
1585 struct lnet_net *net;
1588 net = lnet_get_net_locked(net_id);
1590 local = net != NULL;
1596 lnet_islocalnet(__u32 net_id)
1601 cpt = lnet_net_lock_current();
1603 local = lnet_islocalnet_locked(net_id);
1605 lnet_net_unlock(cpt);
1611 lnet_nid2ni_locked(lnet_nid_t nid4, int cpt)
1613 struct lnet_net *net;
1615 struct lnet_nid nid;
1617 LASSERT(cpt != LNET_LOCK_EX);
1618 lnet_nid4_to_nid(nid4, &nid);
1620 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1621 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1622 if (nid_same(&ni->ni_nid, &nid))
1631 lnet_nid2ni_addref(lnet_nid_t nid)
1636 ni = lnet_nid2ni_locked(nid, 0);
1638 lnet_ni_addref_locked(ni, 0);
1643 EXPORT_SYMBOL(lnet_nid2ni_addref);
1646 lnet_islocalnid(lnet_nid_t nid)
1651 cpt = lnet_net_lock_current();
1652 ni = lnet_nid2ni_locked(nid, cpt);
1653 lnet_net_unlock(cpt);
1659 lnet_count_acceptor_nets(void)
1661 /* Return the # of NIs that need the acceptor. */
1663 struct lnet_net *net;
1666 cpt = lnet_net_lock_current();
1667 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1668 /* all socklnd type networks should have the acceptor
1670 if (net->net_lnd->lnd_accept != NULL)
1674 lnet_net_unlock(cpt);
1679 struct lnet_ping_buffer *
1680 lnet_ping_buffer_alloc(int nnis, gfp_t gfp)
1682 struct lnet_ping_buffer *pbuf;
1684 LIBCFS_ALLOC_GFP(pbuf, LNET_PING_BUFFER_SIZE(nnis), gfp);
1686 pbuf->pb_nnis = nnis;
1687 pbuf->pb_needs_post = false;
1688 atomic_set(&pbuf->pb_refcnt, 1);
1695 lnet_ping_buffer_free(struct lnet_ping_buffer *pbuf)
1697 LASSERT(atomic_read(&pbuf->pb_refcnt) == 0);
1698 LIBCFS_FREE(pbuf, LNET_PING_BUFFER_SIZE(pbuf->pb_nnis));
1701 static struct lnet_ping_buffer *
1702 lnet_ping_target_create(int nnis)
1704 struct lnet_ping_buffer *pbuf;
1706 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
1708 CERROR("Can't allocate ping source [%d]\n", nnis);
1712 pbuf->pb_info.pi_nnis = nnis;
1713 pbuf->pb_info.pi_pid = the_lnet.ln_pid;
1714 pbuf->pb_info.pi_magic = LNET_PROTO_PING_MAGIC;
1715 pbuf->pb_info.pi_features =
1716 LNET_PING_FEAT_NI_STATUS | LNET_PING_FEAT_MULTI_RAIL;
1722 lnet_get_net_ni_count_locked(struct lnet_net *net)
1727 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1734 lnet_get_net_ni_count_pre(struct lnet_net *net)
1739 list_for_each_entry(ni, &net->net_ni_added, ni_netlist)
1746 lnet_get_ni_count(void)
1749 struct lnet_net *net;
1754 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1755 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1765 lnet_swap_pinginfo(struct lnet_ping_buffer *pbuf)
1767 struct lnet_ni_status *stat;
1771 __swab32s(&pbuf->pb_info.pi_magic);
1772 __swab32s(&pbuf->pb_info.pi_features);
1773 __swab32s(&pbuf->pb_info.pi_pid);
1774 __swab32s(&pbuf->pb_info.pi_nnis);
1775 nnis = pbuf->pb_info.pi_nnis;
1776 if (nnis > pbuf->pb_nnis)
1777 nnis = pbuf->pb_nnis;
1778 for (i = 0; i < nnis; i++) {
1779 stat = &pbuf->pb_info.pi_ni[i];
1780 __swab64s(&stat->ns_nid);
1781 __swab32s(&stat->ns_status);
1786 lnet_ping_info_validate(struct lnet_ping_info *pinfo)
1790 if (pinfo->pi_magic != LNET_PROTO_PING_MAGIC)
1792 if (!(pinfo->pi_features & LNET_PING_FEAT_NI_STATUS))
1794 /* Loopback is guaranteed to be present */
1795 if (pinfo->pi_nnis < 1 || pinfo->pi_nnis > lnet_interfaces_max)
1797 if (LNET_PING_INFO_LONI(pinfo) != LNET_NID_LO_0)
1803 lnet_ping_target_destroy(void)
1805 struct lnet_net *net;
1808 lnet_net_lock(LNET_LOCK_EX);
1810 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1811 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1813 ni->ni_status = NULL;
1818 lnet_ping_buffer_decref(the_lnet.ln_ping_target);
1819 the_lnet.ln_ping_target = NULL;
1821 lnet_net_unlock(LNET_LOCK_EX);
1825 lnet_ping_target_event_handler(struct lnet_event *event)
1827 struct lnet_ping_buffer *pbuf = event->md_user_ptr;
1829 if (event->unlinked)
1830 lnet_ping_buffer_decref(pbuf);
1834 lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
1835 struct lnet_handle_md *ping_mdh,
1836 int ni_count, bool set_eq)
1838 struct lnet_process_id id = {
1839 .nid = LNET_NID_ANY,
1843 struct lnet_md md = { NULL };
1847 the_lnet.ln_ping_target_handler =
1848 lnet_ping_target_event_handler;
1850 *ppbuf = lnet_ping_target_create(ni_count);
1851 if (*ppbuf == NULL) {
1856 /* Ping target ME/MD */
1857 me = LNetMEAttach(LNET_RESERVED_PORTAL, id,
1858 LNET_PROTO_PING_MATCHBITS, 0,
1859 LNET_UNLINK, LNET_INS_AFTER);
1862 CERROR("Can't create ping target ME: %d\n", rc);
1863 goto fail_decref_ping_buffer;
1866 /* initialize md content */
1867 md.start = &(*ppbuf)->pb_info;
1868 md.length = LNET_PING_INFO_SIZE((*ppbuf)->pb_nnis);
1869 md.threshold = LNET_MD_THRESH_INF;
1871 md.options = LNET_MD_OP_GET | LNET_MD_TRUNCATE |
1872 LNET_MD_MANAGE_REMOTE;
1873 md.handler = the_lnet.ln_ping_target_handler;
1874 md.user_ptr = *ppbuf;
1876 rc = LNetMDAttach(me, &md, LNET_RETAIN, ping_mdh);
1878 CERROR("Can't attach ping target MD: %d\n", rc);
1879 goto fail_decref_ping_buffer;
1881 lnet_ping_buffer_addref(*ppbuf);
1885 fail_decref_ping_buffer:
1886 LASSERT(atomic_read(&(*ppbuf)->pb_refcnt) == 1);
1887 lnet_ping_buffer_decref(*ppbuf);
1894 lnet_ping_md_unlink(struct lnet_ping_buffer *pbuf,
1895 struct lnet_handle_md *ping_mdh)
1897 LNetMDUnlink(*ping_mdh);
1898 LNetInvalidateMDHandle(ping_mdh);
1900 /* NB the MD could be busy; this just starts the unlink */
1901 wait_var_event_warning(&pbuf->pb_refcnt,
1902 atomic_read(&pbuf->pb_refcnt) <= 1,
1903 "Still waiting for ping data MD to unlink\n");
1907 lnet_ping_target_install_locked(struct lnet_ping_buffer *pbuf)
1910 struct lnet_net *net;
1911 struct lnet_ni_status *ns;
1916 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1917 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1918 LASSERT(i < pbuf->pb_nnis);
1920 ns = &pbuf->pb_info.pi_ni[i];
1922 if (!nid_is_nid4(&ni->ni_nid))
1924 ns->ns_nid = lnet_nid_to_nid4(&ni->ni_nid);
1927 ns->ns_status = lnet_ni_get_status_locked(ni);
1935 * We (ab)use the ns_status of the loopback interface to
1936 * transmit the sequence number. The first interface listed
1937 * must be the loopback interface.
1939 rc = lnet_ping_info_validate(&pbuf->pb_info);
1941 LCONSOLE_EMERG("Invalid ping target: %d\n", rc);
1944 LNET_PING_BUFFER_SEQNO(pbuf) =
1945 atomic_inc_return(&the_lnet.ln_ping_target_seqno);
1949 lnet_ping_target_update(struct lnet_ping_buffer *pbuf,
1950 struct lnet_handle_md ping_mdh)
1952 struct lnet_ping_buffer *old_pbuf = NULL;
1953 struct lnet_handle_md old_ping_md;
1955 /* switch the NIs to point to the new ping info created */
1956 lnet_net_lock(LNET_LOCK_EX);
1958 if (!the_lnet.ln_routing)
1959 pbuf->pb_info.pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1960 if (!lnet_peer_discovery_disabled)
1961 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
1963 /* Ensure only known feature bits have been set. */
1964 LASSERT(pbuf->pb_info.pi_features & LNET_PING_FEAT_BITS);
1965 LASSERT(!(pbuf->pb_info.pi_features & ~LNET_PING_FEAT_BITS));
1967 lnet_ping_target_install_locked(pbuf);
1969 if (the_lnet.ln_ping_target) {
1970 old_pbuf = the_lnet.ln_ping_target;
1971 old_ping_md = the_lnet.ln_ping_target_md;
1973 the_lnet.ln_ping_target_md = ping_mdh;
1974 the_lnet.ln_ping_target = pbuf;
1976 lnet_net_unlock(LNET_LOCK_EX);
1979 /* unlink and free the old ping info */
1980 lnet_ping_md_unlink(old_pbuf, &old_ping_md);
1981 lnet_ping_buffer_decref(old_pbuf);
1984 lnet_push_update_to_peers(0);
1988 lnet_ping_target_fini(void)
1990 lnet_ping_md_unlink(the_lnet.ln_ping_target,
1991 &the_lnet.ln_ping_target_md);
1993 lnet_assert_handler_unused(the_lnet.ln_ping_target_handler);
1994 lnet_ping_target_destroy();
1997 /* Resize the push target. */
1998 int lnet_push_target_resize(void)
2000 struct lnet_handle_md mdh;
2001 struct lnet_handle_md old_mdh;
2002 struct lnet_ping_buffer *pbuf;
2003 struct lnet_ping_buffer *old_pbuf;
2008 nnis = the_lnet.ln_push_target_nnis;
2010 CDEBUG(D_NET, "Invalid nnis %d\n", nnis);
2014 /* NB: lnet_ping_buffer_alloc() sets pbuf refcount to 1. That ref is
2015 * dropped when we need to resize again (see "old_pbuf" below) or when
2016 * LNet is shutdown (see lnet_push_target_fini())
2018 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
2020 CDEBUG(D_NET, "Can't allocate pbuf for nnis %d\n", nnis);
2024 rc = lnet_push_target_post(pbuf, &mdh);
2026 CDEBUG(D_NET, "Failed to post push target: %d\n", rc);
2027 lnet_ping_buffer_decref(pbuf);
2031 lnet_net_lock(LNET_LOCK_EX);
2032 old_pbuf = the_lnet.ln_push_target;
2033 old_mdh = the_lnet.ln_push_target_md;
2034 the_lnet.ln_push_target = pbuf;
2035 the_lnet.ln_push_target_md = mdh;
2036 lnet_net_unlock(LNET_LOCK_EX);
2039 LNetMDUnlink(old_mdh);
2040 /* Drop ref set by lnet_ping_buffer_alloc() */
2041 lnet_ping_buffer_decref(old_pbuf);
2044 /* Received another push or reply that requires a larger buffer */
2045 if (nnis < the_lnet.ln_push_target_nnis)
2048 CDEBUG(D_NET, "nnis %d success\n", nnis);
2052 int lnet_push_target_post(struct lnet_ping_buffer *pbuf,
2053 struct lnet_handle_md *mdhp)
2055 struct lnet_process_id id = { LNET_NID_ANY, LNET_PID_ANY };
2056 struct lnet_md md = { NULL };
2060 me = LNetMEAttach(LNET_RESERVED_PORTAL, id,
2061 LNET_PROTO_PING_MATCHBITS, 0,
2062 LNET_UNLINK, LNET_INS_AFTER);
2065 CERROR("Can't create push target ME: %d\n", rc);
2069 pbuf->pb_needs_post = false;
2071 /* This reference is dropped by lnet_push_target_event_handler() */
2072 lnet_ping_buffer_addref(pbuf);
2074 /* initialize md content */
2075 md.start = &pbuf->pb_info;
2076 md.length = LNET_PING_INFO_SIZE(pbuf->pb_nnis);
2079 md.options = LNET_MD_OP_PUT | LNET_MD_TRUNCATE;
2081 md.handler = the_lnet.ln_push_target_handler;
2083 rc = LNetMDAttach(me, &md, LNET_UNLINK, mdhp);
2085 CERROR("Can't attach push MD: %d\n", rc);
2086 lnet_ping_buffer_decref(pbuf);
2087 pbuf->pb_needs_post = true;
2091 CDEBUG(D_NET, "posted push target %p\n", pbuf);
2096 static void lnet_push_target_event_handler(struct lnet_event *ev)
2098 struct lnet_ping_buffer *pbuf = ev->md_user_ptr;
2100 CDEBUG(D_NET, "type %d status %d unlinked %d\n", ev->type, ev->status,
2103 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
2104 lnet_swap_pinginfo(pbuf);
2106 if (ev->type == LNET_EVENT_UNLINK) {
2107 /* Drop ref added by lnet_push_target_post() */
2108 lnet_ping_buffer_decref(pbuf);
2112 lnet_peer_push_event(ev);
2114 /* Drop ref added by lnet_push_target_post */
2115 lnet_ping_buffer_decref(pbuf);
2118 /* Initialize the push target. */
2119 static int lnet_push_target_init(void)
2123 if (the_lnet.ln_push_target)
2126 the_lnet.ln_push_target_handler =
2127 lnet_push_target_event_handler;
2129 rc = LNetSetLazyPortal(LNET_RESERVED_PORTAL);
2132 /* Start at the required minimum, we'll enlarge if required. */
2133 the_lnet.ln_push_target_nnis = LNET_INTERFACES_MIN;
2135 rc = lnet_push_target_resize();
2138 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2139 the_lnet.ln_push_target_handler = NULL;
2145 /* Clean up the push target. */
2146 static void lnet_push_target_fini(void)
2148 if (!the_lnet.ln_push_target)
2151 /* Unlink and invalidate to prevent new references. */
2152 LNetMDUnlink(the_lnet.ln_push_target_md);
2153 LNetInvalidateMDHandle(&the_lnet.ln_push_target_md);
2155 /* Wait for the unlink to complete. */
2156 wait_var_event_warning(&the_lnet.ln_push_target->pb_refcnt,
2157 atomic_read(&the_lnet.ln_push_target->pb_refcnt) <= 1,
2158 "Still waiting for ping data MD to unlink\n");
2160 /* Drop ref set by lnet_ping_buffer_alloc() */
2161 lnet_ping_buffer_decref(the_lnet.ln_push_target);
2162 the_lnet.ln_push_target = NULL;
2163 the_lnet.ln_push_target_nnis = 0;
2165 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2166 lnet_assert_handler_unused(the_lnet.ln_push_target_handler);
2167 the_lnet.ln_push_target_handler = NULL;
2171 lnet_ni_tq_credits(struct lnet_ni *ni)
2175 LASSERT(ni->ni_ncpts >= 1);
2177 if (ni->ni_ncpts == 1)
2178 return ni->ni_net->net_tunables.lct_max_tx_credits;
2180 credits = ni->ni_net->net_tunables.lct_max_tx_credits / ni->ni_ncpts;
2181 credits = max(credits, 8 * ni->ni_net->net_tunables.lct_peer_tx_credits);
2182 credits = min(credits, ni->ni_net->net_tunables.lct_max_tx_credits);
2188 lnet_ni_unlink_locked(struct lnet_ni *ni)
2190 /* move it to zombie list and nobody can find it anymore */
2191 LASSERT(!list_empty(&ni->ni_netlist));
2192 list_move(&ni->ni_netlist, &ni->ni_net->net_ni_zombie);
2193 lnet_ni_decref_locked(ni, 0);
2197 lnet_clear_zombies_nis_locked(struct lnet_net *net)
2202 struct list_head *zombie_list = &net->net_ni_zombie;
2205 * Now wait for the NIs I just nuked to show up on the zombie
2206 * list and shut them down in guaranteed thread context
2209 while (!list_empty(zombie_list)) {
2213 ni = list_entry(zombie_list->next,
2214 struct lnet_ni, ni_netlist);
2215 list_del_init(&ni->ni_netlist);
2216 /* the ni should be in deleting state. If it's not it's
2218 LASSERT(ni->ni_state == LNET_NI_STATE_DELETING);
2219 cfs_percpt_for_each(ref, j, ni->ni_refs) {
2222 /* still busy, add it back to zombie list */
2223 list_add(&ni->ni_netlist, zombie_list);
2227 if (!list_empty(&ni->ni_netlist)) {
2228 /* Unlock mutex while waiting to allow other
2229 * threads to read the LNet state and fall through
2232 lnet_net_unlock(LNET_LOCK_EX);
2233 mutex_unlock(&the_lnet.ln_api_mutex);
2236 if ((i & (-i)) == i) {
2238 "Waiting for zombie LNI %s\n",
2239 libcfs_nidstr(&ni->ni_nid));
2241 schedule_timeout_uninterruptible(cfs_time_seconds(1));
2243 mutex_lock(&the_lnet.ln_api_mutex);
2244 lnet_net_lock(LNET_LOCK_EX);
2248 lnet_net_unlock(LNET_LOCK_EX);
2250 islo = ni->ni_net->net_lnd->lnd_type == LOLND;
2252 LASSERT(!in_interrupt());
2253 /* Holding the mutex makes it safe for lnd_shutdown
2254 * to call module_put(). Module unload cannot finish
2255 * until lnet_unregister_lnd() completes, and that
2256 * requires the mutex.
2258 mutex_lock(&the_lnet.ln_lnd_mutex);
2259 (net->net_lnd->lnd_shutdown)(ni);
2260 mutex_unlock(&the_lnet.ln_lnd_mutex);
2263 CDEBUG(D_LNI, "Removed LNI %s\n",
2264 libcfs_nidstr(&ni->ni_nid));
2268 lnet_net_lock(LNET_LOCK_EX);
2272 /* shutdown down the NI and release refcount */
2274 lnet_shutdown_lndni(struct lnet_ni *ni)
2277 struct lnet_net *net = ni->ni_net;
2279 lnet_net_lock(LNET_LOCK_EX);
2281 ni->ni_state = LNET_NI_STATE_DELETING;
2283 lnet_ni_unlink_locked(ni);
2284 lnet_incr_dlc_seq();
2285 lnet_net_unlock(LNET_LOCK_EX);
2287 /* clear messages for this NI on the lazy portal */
2288 for (i = 0; i < the_lnet.ln_nportals; i++)
2289 lnet_clear_lazy_portal(ni, i, "Shutting down NI");
2291 lnet_net_lock(LNET_LOCK_EX);
2292 lnet_clear_zombies_nis_locked(net);
2293 lnet_net_unlock(LNET_LOCK_EX);
2297 lnet_shutdown_lndnet(struct lnet_net *net)
2301 lnet_net_lock(LNET_LOCK_EX);
2303 list_del_init(&net->net_list);
2305 while (!list_empty(&net->net_ni_list)) {
2306 ni = list_entry(net->net_ni_list.next,
2307 struct lnet_ni, ni_netlist);
2308 lnet_net_unlock(LNET_LOCK_EX);
2309 lnet_shutdown_lndni(ni);
2310 lnet_net_lock(LNET_LOCK_EX);
2313 lnet_net_unlock(LNET_LOCK_EX);
2315 /* Do peer table cleanup for this net */
2316 lnet_peer_tables_cleanup(net);
2322 lnet_shutdown_lndnets(void)
2324 struct lnet_net *net;
2326 struct lnet_msg *msg, *tmp;
2328 /* NB called holding the global mutex */
2330 /* All quiet on the API front */
2331 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
2332 LASSERT(the_lnet.ln_refcount == 0);
2334 lnet_net_lock(LNET_LOCK_EX);
2335 the_lnet.ln_state = LNET_STATE_STOPPING;
2338 * move the nets to the zombie list to avoid them being
2339 * picked up for new work. LONET is also included in the
2340 * Nets that will be moved to the zombie list
2342 list_splice_init(&the_lnet.ln_nets, &the_lnet.ln_net_zombie);
2344 /* Drop the cached loopback Net. */
2345 if (the_lnet.ln_loni != NULL) {
2346 lnet_ni_decref_locked(the_lnet.ln_loni, 0);
2347 the_lnet.ln_loni = NULL;
2349 lnet_net_unlock(LNET_LOCK_EX);
2351 /* iterate through the net zombie list and delete each net */
2352 while (!list_empty(&the_lnet.ln_net_zombie)) {
2353 net = list_entry(the_lnet.ln_net_zombie.next,
2354 struct lnet_net, net_list);
2355 lnet_shutdown_lndnet(net);
2358 spin_lock(&the_lnet.ln_msg_resend_lock);
2359 list_splice(&the_lnet.ln_msg_resend, &resend);
2360 spin_unlock(&the_lnet.ln_msg_resend_lock);
2362 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
2363 list_del_init(&msg->msg_list);
2364 msg->msg_no_resend = true;
2365 lnet_finalize(msg, -ECANCELED);
2368 lnet_net_lock(LNET_LOCK_EX);
2369 the_lnet.ln_state = LNET_STATE_SHUTDOWN;
2370 lnet_net_unlock(LNET_LOCK_EX);
2374 lnet_startup_lndni(struct lnet_ni *ni, struct lnet_lnd_tunables *tun)
2377 struct lnet_tx_queue *tq;
2379 struct lnet_net *net = ni->ni_net;
2381 mutex_lock(&the_lnet.ln_lnd_mutex);
2384 memcpy(&ni->ni_lnd_tunables, tun, sizeof(*tun));
2385 ni->ni_lnd_tunables_set = true;
2388 rc = (net->net_lnd->lnd_startup)(ni);
2390 mutex_unlock(&the_lnet.ln_lnd_mutex);
2393 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s\n",
2394 rc, libcfs_lnd2str(net->net_lnd->lnd_type));
2399 ni->ni_state = LNET_NI_STATE_ACTIVE;
2402 /* We keep a reference on the loopback net through the loopback NI */
2403 if (net->net_lnd->lnd_type == LOLND) {
2405 LASSERT(the_lnet.ln_loni == NULL);
2406 the_lnet.ln_loni = ni;
2407 ni->ni_net->net_tunables.lct_peer_tx_credits = 0;
2408 ni->ni_net->net_tunables.lct_peer_rtr_credits = 0;
2409 ni->ni_net->net_tunables.lct_max_tx_credits = 0;
2410 ni->ni_net->net_tunables.lct_peer_timeout = 0;
2414 if (ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ||
2415 ni->ni_net->net_tunables.lct_max_tx_credits == 0) {
2416 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
2417 libcfs_lnd2str(net->net_lnd->lnd_type),
2418 ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ?
2420 /* shutdown the NI since if we get here then it must've already
2423 lnet_shutdown_lndni(ni);
2427 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
2428 tq->tq_credits_min =
2429 tq->tq_credits_max =
2430 tq->tq_credits = lnet_ni_tq_credits(ni);
2433 atomic_set(&ni->ni_tx_credits,
2434 lnet_ni_tq_credits(ni) * ni->ni_ncpts);
2435 atomic_set(&ni->ni_healthv, LNET_MAX_HEALTH_VALUE);
2437 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d/%d]\n",
2438 libcfs_nidstr(&ni->ni_nid),
2439 ni->ni_net->net_tunables.lct_peer_tx_credits,
2440 lnet_ni_tq_credits(ni) * LNET_CPT_NUMBER,
2441 ni->ni_net->net_tunables.lct_peer_rtr_credits,
2442 ni->ni_net->net_tunables.lct_peer_timeout);
2451 lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
2454 struct lnet_net *net_l = NULL;
2455 LIST_HEAD(local_ni_list);
2459 const struct lnet_lnd *lnd;
2461 net->net_tunables.lct_peer_timeout;
2463 net->net_tunables.lct_max_tx_credits;
2464 int peerrtrcredits =
2465 net->net_tunables.lct_peer_rtr_credits;
2468 * make sure that this net is unique. If it isn't then
2469 * we are adding interfaces to an already existing network, and
2470 * 'net' is just a convenient way to pass in the list.
2471 * if it is unique we need to find the LND and load it if
2474 if (lnet_net_unique(net->net_id, &the_lnet.ln_nets, &net_l)) {
2475 lnd_type = LNET_NETTYP(net->net_id);
2477 mutex_lock(&the_lnet.ln_lnd_mutex);
2478 lnd = lnet_find_lnd_by_type(lnd_type);
2481 mutex_unlock(&the_lnet.ln_lnd_mutex);
2482 rc = request_module("%s", libcfs_lnd2modname(lnd_type));
2483 mutex_lock(&the_lnet.ln_lnd_mutex);
2485 lnd = lnet_find_lnd_by_type(lnd_type);
2487 mutex_unlock(&the_lnet.ln_lnd_mutex);
2488 CERROR("Can't load LND %s, module %s, rc=%d\n",
2489 libcfs_lnd2str(lnd_type),
2490 libcfs_lnd2modname(lnd_type), rc);
2491 #ifndef HAVE_MODULE_LOADING_SUPPORT
2492 LCONSOLE_ERROR_MSG(0x104, "Your kernel must be "
2493 "compiled with kernel module "
2494 "loading support.");
2503 mutex_unlock(&the_lnet.ln_lnd_mutex);
2509 * net_l: if the network being added is unique then net_l
2510 * will point to that network
2511 * if the network being added is not unique then
2512 * net_l points to the existing network.
2514 * When we enter the loop below, we'll pick NIs off he
2515 * network beign added and start them up, then add them to
2516 * a local ni list. Once we've successfully started all
2517 * the NIs then we join the local NI list (of started up
2518 * networks) with the net_l->net_ni_list, which should
2519 * point to the correct network to add the new ni list to
2521 * If any of the new NIs fail to start up, then we want to
2522 * iterate through the local ni list, which should include
2523 * any NIs which were successfully started up, and shut
2526 * After than we want to delete the network being added,
2527 * to avoid a memory leak.
2529 while (!list_empty(&net->net_ni_added)) {
2530 ni = list_entry(net->net_ni_added.next, struct lnet_ni,
2532 list_del_init(&ni->ni_netlist);
2534 /* make sure that the the NI we're about to start
2535 * up is actually unique. if it's not fail. */
2536 if (!lnet_ni_unique_net(&net_l->net_ni_list,
2537 ni->ni_interface)) {
2542 /* adjust the pointer the parent network, just in case it
2543 * the net is a duplicate */
2546 rc = lnet_startup_lndni(ni, tun);
2552 list_add_tail(&ni->ni_netlist, &local_ni_list);
2557 lnet_net_lock(LNET_LOCK_EX);
2558 list_splice_tail(&local_ni_list, &net_l->net_ni_list);
2559 lnet_incr_dlc_seq();
2560 lnet_net_unlock(LNET_LOCK_EX);
2562 /* if the network is not unique then we don't want to keep
2563 * it around after we're done. Free it. Otherwise add that
2564 * net to the global the_lnet.ln_nets */
2565 if (net_l != net && net_l != NULL) {
2567 * TODO - note. currently the tunables can not be updated
2573 * restore tunables after it has been overwitten by the
2576 if (peer_timeout != -1)
2577 net->net_tunables.lct_peer_timeout = peer_timeout;
2578 if (maxtxcredits != -1)
2579 net->net_tunables.lct_max_tx_credits = maxtxcredits;
2580 if (peerrtrcredits != -1)
2581 net->net_tunables.lct_peer_rtr_credits = peerrtrcredits;
2583 lnet_net_lock(LNET_LOCK_EX);
2584 list_add_tail(&net->net_list, &the_lnet.ln_nets);
2585 lnet_net_unlock(LNET_LOCK_EX);
2592 * shutdown the new NIs that are being started up
2593 * free the NET being started
2595 while (!list_empty(&local_ni_list)) {
2596 ni = list_entry(local_ni_list.next, struct lnet_ni,
2599 lnet_shutdown_lndni(ni);
2609 lnet_startup_lndnets(struct list_head *netlist)
2611 struct lnet_net *net;
2616 * Change to running state before bringing up the LNDs. This
2617 * allows lnet_shutdown_lndnets() to assert that we've passed
2620 lnet_net_lock(LNET_LOCK_EX);
2621 the_lnet.ln_state = LNET_STATE_RUNNING;
2622 lnet_net_unlock(LNET_LOCK_EX);
2624 while (!list_empty(netlist)) {
2625 net = list_entry(netlist->next, struct lnet_net, net_list);
2626 list_del_init(&net->net_list);
2628 rc = lnet_startup_lndnet(net, NULL);
2638 lnet_shutdown_lndnets();
2643 static int lnet_genl_parse_list(struct sk_buff *msg,
2644 const struct ln_key_list *data[], u16 idx)
2646 const struct ln_key_list *list = data[idx];
2647 const struct ln_key_props *props;
2648 struct nlattr *node;
2654 if (!list->lkl_maxattr)
2657 props = list->lkl_list;
2661 node = nla_nest_start(msg, LN_SCALAR_ATTR_LIST);
2665 for (count = 1; count <= list->lkl_maxattr; count++) {
2666 struct nlattr *key = nla_nest_start(msg, count);
2669 nla_put_u16(msg, LN_SCALAR_ATTR_LIST_SIZE,
2672 nla_put_u16(msg, LN_SCALAR_ATTR_INDEX, count);
2673 if (props[count].lkp_values)
2674 nla_put_string(msg, LN_SCALAR_ATTR_VALUE,
2675 props[count].lkp_values);
2676 if (props[count].lkp_key_format)
2677 nla_put_u16(msg, LN_SCALAR_ATTR_KEY_FORMAT,
2678 props[count].lkp_key_format);
2679 nla_put_u16(msg, LN_SCALAR_ATTR_NLA_TYPE,
2680 props[count].lkp_data_type);
2681 if (props[count].lkp_data_type == NLA_NESTED) {
2684 rc = lnet_genl_parse_list(msg, data, ++idx);
2689 nla_nest_end(msg, key);
2692 nla_nest_end(msg, node);
2696 int lnet_genl_send_scalar_list(struct sk_buff *msg, u32 portid, u32 seq,
2697 const struct genl_family *family, int flags,
2698 u8 cmd, const struct ln_key_list *data[])
2706 hdr = genlmsg_put(msg, portid, seq, family, flags, cmd);
2708 GOTO(canceled, rc = -EMSGSIZE);
2710 rc = lnet_genl_parse_list(msg, data, 0);
2714 genlmsg_end(msg, hdr);
2717 genlmsg_cancel(msg, hdr);
2720 EXPORT_SYMBOL(lnet_genl_send_scalar_list);
2723 * Initialize LNet library.
2725 * Automatically called at module loading time. Caller has to call
2726 * lnet_lib_exit() after a call to lnet_lib_init(), if and only if the
2727 * latter returned 0. It must be called exactly once.
2729 * \retval 0 on success
2730 * \retval -ve on failures.
2732 int lnet_lib_init(void)
2736 lnet_assert_wire_constants();
2738 /* refer to global cfs_cpt_table for now */
2739 the_lnet.ln_cpt_table = cfs_cpt_tab;
2740 the_lnet.ln_cpt_number = cfs_cpt_number(cfs_cpt_tab);
2742 LASSERT(the_lnet.ln_cpt_number > 0);
2743 if (the_lnet.ln_cpt_number > LNET_CPT_MAX) {
2744 /* we are under risk of consuming all lh_cookie */
2745 CERROR("Can't have %d CPTs for LNet (max allowed is %d), "
2746 "please change setting of CPT-table and retry\n",
2747 the_lnet.ln_cpt_number, LNET_CPT_MAX);
2751 while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number)
2752 the_lnet.ln_cpt_bits++;
2754 rc = lnet_create_locks();
2756 CERROR("Can't create LNet global locks: %d\n", rc);
2760 the_lnet.ln_refcount = 0;
2761 INIT_LIST_HEAD(&the_lnet.ln_net_zombie);
2762 INIT_LIST_HEAD(&the_lnet.ln_msg_resend);
2764 /* The hash table size is the number of bits it takes to express the set
2765 * ln_num_routes, minus 1 (better to under estimate than over so we
2766 * don't waste memory). */
2767 if (rnet_htable_size <= 0)
2768 rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
2769 else if (rnet_htable_size > LNET_REMOTE_NETS_HASH_MAX)
2770 rnet_htable_size = LNET_REMOTE_NETS_HASH_MAX;
2771 the_lnet.ln_remote_nets_hbits = max_t(int, 1,
2772 order_base_2(rnet_htable_size) - 1);
2774 /* All LNDs apart from the LOLND are in separate modules. They
2775 * register themselves when their module loads, and unregister
2776 * themselves when their module is unloaded. */
2777 lnet_register_lnd(&the_lolnd);
2782 * Finalize LNet library.
2784 * \pre lnet_lib_init() called with success.
2785 * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls.
2787 * As this happens at module-unload, all lnds must already be unloaded,
2788 * so they must already be unregistered.
2790 void lnet_lib_exit(void)
2794 LASSERT(the_lnet.ln_refcount == 0);
2795 lnet_unregister_lnd(&the_lolnd);
2796 for (i = 0; i < NUM_LNDS; i++)
2797 LASSERT(!the_lnet.ln_lnds[i]);
2798 lnet_destroy_locks();
2802 * Set LNet PID and start LNet interfaces, routing, and forwarding.
2804 * Users must call this function at least once before any other functions.
2805 * For each successful call there must be a corresponding call to
2806 * LNetNIFini(). For subsequent calls to LNetNIInit(), \a requested_pid is
2809 * The PID used by LNet may be different from the one requested.
2812 * \param requested_pid PID requested by the caller.
2814 * \return >= 0 on success, and < 0 error code on failures.
2817 LNetNIInit(lnet_pid_t requested_pid)
2819 int im_a_router = 0;
2822 struct lnet_ping_buffer *pbuf;
2823 struct lnet_handle_md ping_mdh;
2824 LIST_HEAD(net_head);
2825 struct lnet_net *net;
2827 mutex_lock(&the_lnet.ln_api_mutex);
2829 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
2831 if (the_lnet.ln_refcount > 0) {
2832 rc = the_lnet.ln_refcount++;
2833 mutex_unlock(&the_lnet.ln_api_mutex);
2837 rc = lnet_prepare(requested_pid);
2839 mutex_unlock(&the_lnet.ln_api_mutex);
2843 /* create a network for Loopback network */
2844 net = lnet_net_alloc(LNET_MKNET(LOLND, 0), &net_head);
2847 goto err_empty_list;
2850 /* Add in the loopback NI */
2851 if (lnet_ni_alloc(net, NULL, NULL) == NULL) {
2853 goto err_empty_list;
2856 if (use_tcp_bonding)
2857 CWARN("use_tcp_bonding has been removed. Use Multi-Rail and Dynamic Discovery instead, see LU-13641\n");
2859 /* If LNet is being initialized via DLC it is possible
2860 * that the user requests not to load module parameters (ones which
2861 * are supported by DLC) on initialization. Therefore, make sure not
2862 * to load networks, routes and forwarding from module parameters
2863 * in this case. On cleanup in case of failure only clean up
2864 * routes if it has been loaded */
2865 if (!the_lnet.ln_nis_from_mod_params) {
2866 rc = lnet_parse_networks(&net_head, lnet_get_networks());
2868 goto err_empty_list;
2871 ni_count = lnet_startup_lndnets(&net_head);
2874 goto err_empty_list;
2877 if (!the_lnet.ln_nis_from_mod_params) {
2878 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
2880 goto err_shutdown_lndnis;
2882 rc = lnet_rtrpools_alloc(im_a_router);
2884 goto err_destroy_routes;
2887 rc = lnet_acceptor_start();
2889 goto err_destroy_routes;
2891 the_lnet.ln_refcount = 1;
2892 /* Now I may use my own API functions... */
2894 rc = lnet_ping_target_setup(&pbuf, &ping_mdh, ni_count, true);
2896 goto err_acceptor_stop;
2898 lnet_ping_target_update(pbuf, ping_mdh);
2900 the_lnet.ln_mt_handler = lnet_mt_event_handler;
2902 rc = lnet_push_target_init();
2906 rc = lnet_peer_discovery_start();
2908 goto err_destroy_push_target;
2910 rc = lnet_monitor_thr_start();
2912 goto err_stop_discovery_thr;
2915 lnet_router_debugfs_init();
2917 mutex_unlock(&the_lnet.ln_api_mutex);
2919 complete_all(&the_lnet.ln_started);
2921 /* wait for all routers to start */
2922 lnet_wait_router_start();
2926 err_stop_discovery_thr:
2927 lnet_peer_discovery_stop();
2928 err_destroy_push_target:
2929 lnet_push_target_fini();
2931 lnet_ping_target_fini();
2933 the_lnet.ln_refcount = 0;
2934 lnet_acceptor_stop();
2936 if (!the_lnet.ln_nis_from_mod_params)
2937 lnet_destroy_routes();
2938 err_shutdown_lndnis:
2939 lnet_shutdown_lndnets();
2943 mutex_unlock(&the_lnet.ln_api_mutex);
2944 while (!list_empty(&net_head)) {
2945 struct lnet_net *net;
2947 net = list_entry(net_head.next, struct lnet_net, net_list);
2948 list_del_init(&net->net_list);
2953 EXPORT_SYMBOL(LNetNIInit);
2956 * Stop LNet interfaces, routing, and forwarding.
2958 * Users must call this function once for each successful call to LNetNIInit().
2959 * Once the LNetNIFini() operation has been started, the results of pending
2960 * API operations are undefined.
2962 * \return always 0 for current implementation.
2967 mutex_lock(&the_lnet.ln_api_mutex);
2969 LASSERT(the_lnet.ln_refcount > 0);
2971 if (the_lnet.ln_refcount != 1) {
2972 the_lnet.ln_refcount--;
2974 LASSERT(!the_lnet.ln_niinit_self);
2978 lnet_router_debugfs_fini();
2979 lnet_monitor_thr_stop();
2980 lnet_peer_discovery_stop();
2981 lnet_push_target_fini();
2982 lnet_ping_target_fini();
2984 /* Teardown fns that use my own API functions BEFORE here */
2985 the_lnet.ln_refcount = 0;
2987 lnet_acceptor_stop();
2988 lnet_destroy_routes();
2989 lnet_shutdown_lndnets();
2993 mutex_unlock(&the_lnet.ln_api_mutex);
2996 EXPORT_SYMBOL(LNetNIFini);
2999 * Grabs the ni data from the ni structure and fills the out
3002 * \param[in] ni network interface structure
3003 * \param[out] cfg_ni NI config information
3004 * \param[out] tun network and LND tunables
3007 lnet_fill_ni_info(struct lnet_ni *ni, struct lnet_ioctl_config_ni *cfg_ni,
3008 struct lnet_ioctl_config_lnd_tunables *tun,
3009 struct lnet_ioctl_element_stats *stats,
3012 size_t min_size = 0;
3015 if (!ni || !cfg_ni || !tun || !nid_is_nid4(&ni->ni_nid))
3018 if (ni->ni_interface != NULL) {
3019 strncpy(cfg_ni->lic_ni_intf,
3021 sizeof(cfg_ni->lic_ni_intf));
3024 cfg_ni->lic_nid = lnet_nid_to_nid4(&ni->ni_nid);
3025 cfg_ni->lic_status = lnet_ni_get_status_locked(ni);
3026 cfg_ni->lic_dev_cpt = ni->ni_dev_cpt;
3028 memcpy(&tun->lt_cmn, &ni->ni_net->net_tunables, sizeof(tun->lt_cmn));
3031 stats->iel_send_count = lnet_sum_stats(&ni->ni_stats,
3032 LNET_STATS_TYPE_SEND);
3033 stats->iel_recv_count = lnet_sum_stats(&ni->ni_stats,
3034 LNET_STATS_TYPE_RECV);
3035 stats->iel_drop_count = lnet_sum_stats(&ni->ni_stats,
3036 LNET_STATS_TYPE_DROP);
3040 * tun->lt_tun will always be present, but in order to be
3041 * backwards compatible, we need to deal with the cases when
3042 * tun->lt_tun is smaller than what the kernel has, because it
3043 * comes from an older version of a userspace program, then we'll
3044 * need to copy as much information as we have available space.
3046 min_size = tun_size - sizeof(tun->lt_cmn);
3047 memcpy(&tun->lt_tun, &ni->ni_lnd_tunables, min_size);
3049 /* copy over the cpts */
3050 if (ni->ni_ncpts == LNET_CPT_NUMBER &&
3051 ni->ni_cpts == NULL) {
3052 for (i = 0; i < ni->ni_ncpts; i++)
3053 cfg_ni->lic_cpts[i] = i;
3056 ni->ni_cpts != NULL && i < ni->ni_ncpts &&
3057 i < LNET_MAX_SHOW_NUM_CPT;
3059 cfg_ni->lic_cpts[i] = ni->ni_cpts[i];
3061 cfg_ni->lic_ncpts = ni->ni_ncpts;
3065 * NOTE: This is a legacy function left in the code to be backwards
3066 * compatible with older userspace programs. It should eventually be
3069 * Grabs the ni data from the ni structure and fills the out
3072 * \param[in] ni network interface structure
3073 * \param[out] config config information
3076 lnet_fill_ni_info_legacy(struct lnet_ni *ni,
3077 struct lnet_ioctl_config_data *config)
3079 struct lnet_ioctl_net_config *net_config;
3080 struct lnet_ioctl_config_lnd_tunables *lnd_cfg = NULL;
3081 size_t min_size, tunable_size = 0;
3084 if (!ni || !config || !nid_is_nid4(&ni->ni_nid))
3087 net_config = (struct lnet_ioctl_net_config *) config->cfg_bulk;
3091 if (!ni->ni_interface)
3094 strncpy(net_config->ni_interface,
3096 sizeof(net_config->ni_interface));
3098 config->cfg_nid = lnet_nid_to_nid4(&ni->ni_nid);
3099 config->cfg_config_u.cfg_net.net_peer_timeout =
3100 ni->ni_net->net_tunables.lct_peer_timeout;
3101 config->cfg_config_u.cfg_net.net_max_tx_credits =
3102 ni->ni_net->net_tunables.lct_max_tx_credits;
3103 config->cfg_config_u.cfg_net.net_peer_tx_credits =
3104 ni->ni_net->net_tunables.lct_peer_tx_credits;
3105 config->cfg_config_u.cfg_net.net_peer_rtr_credits =
3106 ni->ni_net->net_tunables.lct_peer_rtr_credits;
3108 net_config->ni_status = lnet_ni_get_status_locked(ni);
3111 int num_cpts = min(ni->ni_ncpts, LNET_MAX_SHOW_NUM_CPT);
3113 for (i = 0; i < num_cpts; i++)
3114 net_config->ni_cpts[i] = ni->ni_cpts[i];
3116 config->cfg_ncpts = num_cpts;
3120 * See if user land tools sent in a newer and larger version
3121 * of struct lnet_tunables than what the kernel uses.
3123 min_size = sizeof(*config) + sizeof(*net_config);
3125 if (config->cfg_hdr.ioc_len > min_size)
3126 tunable_size = config->cfg_hdr.ioc_len - min_size;
3128 /* Don't copy too much data to user space */
3129 min_size = min(tunable_size, sizeof(ni->ni_lnd_tunables));
3130 lnd_cfg = (struct lnet_ioctl_config_lnd_tunables *)net_config->cfg_bulk;
3132 if (lnd_cfg && min_size) {
3133 memcpy(&lnd_cfg->lt_tun, &ni->ni_lnd_tunables, min_size);
3134 config->cfg_config_u.cfg_net.net_interface_count = 1;
3136 /* Tell user land that kernel side has less data */
3137 if (tunable_size > sizeof(ni->ni_lnd_tunables)) {
3138 min_size = tunable_size - sizeof(ni->ni_lnd_tunables);
3139 config->cfg_hdr.ioc_len -= min_size;
3145 lnet_get_ni_idx_locked(int idx)
3148 struct lnet_net *net;
3150 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3151 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3160 int lnet_get_net_healthv_locked(struct lnet_net *net)
3163 int best_healthv = 0;
3164 int healthv, ni_fatal;
3166 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3167 healthv = atomic_read(&ni->ni_healthv);
3168 ni_fatal = atomic_read(&ni->ni_fatal_error_on);
3169 if (!ni_fatal && healthv > best_healthv)
3170 best_healthv = healthv;
3173 return best_healthv;
3177 lnet_get_next_ni_locked(struct lnet_net *mynet, struct lnet_ni *prev)
3180 struct lnet_net *net = mynet;
3183 * It is possible that the net has been cleaned out while there is
3184 * a message being sent. This function accessed the net without
3185 * checking if the list is empty
3189 net = list_entry(the_lnet.ln_nets.next, struct lnet_net,
3191 if (list_empty(&net->net_ni_list))
3193 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
3199 if (prev->ni_netlist.next == &prev->ni_net->net_ni_list) {
3200 /* if you reached the end of the ni list and the net is
3201 * specified, then there are no more nis in that net */
3205 /* we reached the end of this net ni list. move to the
3207 if (prev->ni_net->net_list.next == &the_lnet.ln_nets)
3208 /* no more nets and no more NIs. */
3211 /* get the next net */
3212 net = list_entry(prev->ni_net->net_list.next, struct lnet_net,
3214 if (list_empty(&net->net_ni_list))
3216 /* get the ni on it */
3217 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
3223 if (list_empty(&prev->ni_netlist))
3226 /* there are more nis left */
3227 ni = list_entry(prev->ni_netlist.next, struct lnet_ni, ni_netlist);
3233 lnet_get_net_config(struct lnet_ioctl_config_data *config)
3238 int idx = config->cfg_count;
3240 cpt = lnet_net_lock_current();
3242 ni = lnet_get_ni_idx_locked(idx);
3247 lnet_fill_ni_info_legacy(ni, config);
3251 lnet_net_unlock(cpt);
3256 lnet_get_ni_config(struct lnet_ioctl_config_ni *cfg_ni,
3257 struct lnet_ioctl_config_lnd_tunables *tun,
3258 struct lnet_ioctl_element_stats *stats,
3265 if (!cfg_ni || !tun || !stats)
3268 cpt = lnet_net_lock_current();
3270 ni = lnet_get_ni_idx_locked(cfg_ni->lic_idx);
3275 lnet_fill_ni_info(ni, cfg_ni, tun, stats, tun_size);
3279 lnet_net_unlock(cpt);
3283 int lnet_get_ni_stats(struct lnet_ioctl_element_msg_stats *msg_stats)
3292 cpt = lnet_net_lock_current();
3294 ni = lnet_get_ni_idx_locked(msg_stats->im_idx);
3297 lnet_usr_translate_stats(msg_stats, &ni->ni_stats);
3301 lnet_net_unlock(cpt);
3306 static int lnet_add_net_common(struct lnet_net *net,
3307 struct lnet_ioctl_config_lnd_tunables *tun)
3309 struct lnet_handle_md ping_mdh;
3310 struct lnet_ping_buffer *pbuf;
3311 struct lnet_remotenet *rnet;
3317 lnet_net_lock(LNET_LOCK_EX);
3318 rnet = lnet_find_rnet_locked(net->net_id);
3319 lnet_net_unlock(LNET_LOCK_EX);
3321 * make sure that the net added doesn't invalidate the current
3322 * configuration LNet is keeping
3325 CERROR("Adding net %s will invalidate routing configuration\n",
3326 libcfs_net2str(net->net_id));
3332 * make sure you calculate the correct number of slots in the ping
3333 * buffer. Since the ping info is a flattened list of all the NIs,
3334 * we should allocate enough slots to accomodate the number of NIs
3335 * which will be added.
3337 * since ni hasn't been configured yet, use
3338 * lnet_get_net_ni_count_pre() which checks the net_ni_added list
3340 net_ni_count = lnet_get_net_ni_count_pre(net);
3342 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3343 net_ni_count + lnet_get_ni_count(),
3351 memcpy(&net->net_tunables,
3352 &tun->lt_cmn, sizeof(net->net_tunables));
3354 memset(&net->net_tunables, -1, sizeof(net->net_tunables));
3356 net_id = net->net_id;
3358 rc = lnet_startup_lndnet(net,
3359 (tun) ? &tun->lt_tun : NULL);
3363 lnet_net_lock(LNET_LOCK_EX);
3364 net = lnet_get_net_locked(net_id);
3367 /* apply the UDSPs */
3368 rc = lnet_udsp_apply_policies_on_net(net);
3370 CERROR("Failed to apply UDSPs on local net %s\n",
3371 libcfs_net2str(net->net_id));
3373 /* At this point we lost track of which NI was just added, so we
3374 * just re-apply the policies on all of the NIs on this net
3376 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3377 rc = lnet_udsp_apply_policies_on_ni(ni);
3379 CERROR("Failed to apply UDSPs on ni %s\n",
3380 libcfs_nidstr(&ni->ni_nid));
3382 lnet_net_unlock(LNET_LOCK_EX);
3385 * Start the acceptor thread if this is the first network
3386 * being added that requires the thread.
3388 if (net->net_lnd->lnd_accept) {
3389 rc = lnet_acceptor_start();
3391 /* shutdown the net that we just started */
3392 CERROR("Failed to start up acceptor thread\n");
3393 lnet_shutdown_lndnet(net);
3398 lnet_net_lock(LNET_LOCK_EX);
3399 lnet_peer_net_added(net);
3400 lnet_net_unlock(LNET_LOCK_EX);
3402 lnet_ping_target_update(pbuf, ping_mdh);
3407 lnet_ping_md_unlink(pbuf, &ping_mdh);
3408 lnet_ping_buffer_decref(pbuf);
3413 lnet_set_tune_defaults(struct lnet_ioctl_config_lnd_tunables *tun)
3416 if (!tun->lt_cmn.lct_peer_timeout)
3417 tun->lt_cmn.lct_peer_timeout = DEFAULT_PEER_TIMEOUT;
3418 if (!tun->lt_cmn.lct_peer_tx_credits)
3419 tun->lt_cmn.lct_peer_tx_credits = DEFAULT_PEER_CREDITS;
3420 if (!tun->lt_cmn.lct_max_tx_credits)
3421 tun->lt_cmn.lct_max_tx_credits = DEFAULT_CREDITS;
3425 static int lnet_handle_legacy_ip2nets(char *ip2nets,
3426 struct lnet_ioctl_config_lnd_tunables *tun)
3428 struct lnet_net *net;
3431 LIST_HEAD(net_head);
3433 rc = lnet_parse_ip2nets(&nets, ip2nets);
3437 rc = lnet_parse_networks(&net_head, nets);
3441 lnet_set_tune_defaults(tun);
3443 mutex_lock(&the_lnet.ln_api_mutex);
3444 while (!list_empty(&net_head)) {
3445 net = list_entry(net_head.next, struct lnet_net, net_list);
3446 list_del_init(&net->net_list);
3447 rc = lnet_add_net_common(net, tun);
3453 mutex_unlock(&the_lnet.ln_api_mutex);
3455 while (!list_empty(&net_head)) {
3456 net = list_entry(net_head.next, struct lnet_net, net_list);
3457 list_del_init(&net->net_list);
3463 int lnet_dyn_add_ni(struct lnet_ioctl_config_ni *conf)
3465 struct lnet_net *net;
3467 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
3469 __u32 net_id, lnd_type;
3471 /* get the tunables if they are available */
3472 if (conf->lic_cfg_hdr.ioc_len >=
3473 sizeof(*conf) + sizeof(*tun))
3474 tun = (struct lnet_ioctl_config_lnd_tunables *)
3477 /* handle legacy ip2nets from DLC */
3478 if (conf->lic_legacy_ip2nets[0] != '\0')
3479 return lnet_handle_legacy_ip2nets(conf->lic_legacy_ip2nets,
3482 net_id = LNET_NIDNET(conf->lic_nid);
3483 lnd_type = LNET_NETTYP(net_id);
3485 if (!libcfs_isknown_lnd(lnd_type)) {
3486 CERROR("No valid net and lnd information provided\n");
3490 net = lnet_net_alloc(net_id, NULL);
3494 for (i = 0; i < conf->lic_ncpts; i++) {
3495 if (conf->lic_cpts[i] >= LNET_CPT_NUMBER)
3499 ni = lnet_ni_alloc_w_cpt_array(net, conf->lic_cpts, conf->lic_ncpts,
3504 lnet_set_tune_defaults(tun);
3506 mutex_lock(&the_lnet.ln_api_mutex);
3508 rc = lnet_add_net_common(net, tun);
3510 mutex_unlock(&the_lnet.ln_api_mutex);
3515 int lnet_dyn_del_ni(struct lnet_ioctl_config_ni *conf)
3517 struct lnet_net *net;
3519 __u32 net_id = LNET_NIDNET(conf->lic_nid);
3520 struct lnet_ping_buffer *pbuf;
3521 struct lnet_handle_md ping_mdh;
3526 /* don't allow userspace to shutdown the LOLND */
3527 if (LNET_NETTYP(net_id) == LOLND)
3530 mutex_lock(&the_lnet.ln_api_mutex);
3534 net = lnet_get_net_locked(net_id);
3536 CERROR("net %s not found\n",
3537 libcfs_net2str(net_id));
3542 addr = LNET_NIDADDR(conf->lic_nid);
3544 /* remove the entire net */
3545 net_count = lnet_get_net_ni_count_locked(net);
3549 /* create and link a new ping info, before removing the old one */
3550 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3551 lnet_get_ni_count() - net_count,
3554 goto unlock_api_mutex;
3556 lnet_shutdown_lndnet(net);
3558 lnet_acceptor_stop();
3560 lnet_ping_target_update(pbuf, ping_mdh);
3562 goto unlock_api_mutex;
3565 ni = lnet_nid2ni_locked(conf->lic_nid, 0);
3567 CERROR("nid %s not found\n",
3568 libcfs_nid2str(conf->lic_nid));
3573 net_count = lnet_get_net_ni_count_locked(net);
3577 /* create and link a new ping info, before removing the old one */
3578 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3579 lnet_get_ni_count() - 1, false);
3581 goto unlock_api_mutex;
3583 lnet_shutdown_lndni(ni);
3585 lnet_acceptor_stop();
3587 lnet_ping_target_update(pbuf, ping_mdh);
3589 /* check if the net is empty and remove it if it is */
3591 lnet_shutdown_lndnet(net);
3593 goto unlock_api_mutex;
3598 mutex_unlock(&the_lnet.ln_api_mutex);
3604 * lnet_dyn_add_net and lnet_dyn_del_net are now deprecated.
3605 * They are only expected to be called for unique networks.
3606 * That can be as a result of older DLC library
3607 * calls. Multi-Rail DLC and beyond no longer uses these APIs.
3610 lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
3612 struct lnet_net *net;
3613 LIST_HEAD(net_head);
3615 struct lnet_ioctl_config_lnd_tunables tun;
3616 const char *nets = conf->cfg_config_u.cfg_net.net_intf;
3618 /* Create a net/ni structures for the network string */
3619 rc = lnet_parse_networks(&net_head, nets);
3621 return rc == 0 ? -EINVAL : rc;
3623 mutex_lock(&the_lnet.ln_api_mutex);
3626 rc = -EINVAL; /* only add one network per call */
3627 goto out_unlock_clean;
3630 net = list_entry(net_head.next, struct lnet_net, net_list);
3631 list_del_init(&net->net_list);
3633 LASSERT(lnet_net_unique(net->net_id, &the_lnet.ln_nets, NULL));
3635 memset(&tun, 0, sizeof(tun));
3637 tun.lt_cmn.lct_peer_timeout =
3638 (!conf->cfg_config_u.cfg_net.net_peer_timeout) ? DEFAULT_PEER_TIMEOUT :
3639 conf->cfg_config_u.cfg_net.net_peer_timeout;
3640 tun.lt_cmn.lct_peer_tx_credits =
3641 (!conf->cfg_config_u.cfg_net.net_peer_tx_credits) ? DEFAULT_PEER_CREDITS :
3642 conf->cfg_config_u.cfg_net.net_peer_tx_credits;
3643 tun.lt_cmn.lct_peer_rtr_credits =
3644 conf->cfg_config_u.cfg_net.net_peer_rtr_credits;
3645 tun.lt_cmn.lct_max_tx_credits =
3646 (!conf->cfg_config_u.cfg_net.net_max_tx_credits) ? DEFAULT_CREDITS :
3647 conf->cfg_config_u.cfg_net.net_max_tx_credits;
3649 rc = lnet_add_net_common(net, &tun);
3652 mutex_unlock(&the_lnet.ln_api_mutex);
3653 while (!list_empty(&net_head)) {
3654 /* net_head list is empty in success case */
3655 net = list_entry(net_head.next, struct lnet_net, net_list);
3656 list_del_init(&net->net_list);
3663 lnet_dyn_del_net(__u32 net_id)
3665 struct lnet_net *net;
3666 struct lnet_ping_buffer *pbuf;
3667 struct lnet_handle_md ping_mdh;
3671 /* don't allow userspace to shutdown the LOLND */
3672 if (LNET_NETTYP(net_id) == LOLND)
3675 mutex_lock(&the_lnet.ln_api_mutex);
3679 net = lnet_get_net_locked(net_id);
3686 net_ni_count = lnet_get_net_ni_count_locked(net);
3690 /* create and link a new ping info, before removing the old one */
3691 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3692 lnet_get_ni_count() - net_ni_count, false);
3696 lnet_shutdown_lndnet(net);
3698 lnet_acceptor_stop();
3700 lnet_ping_target_update(pbuf, ping_mdh);
3703 mutex_unlock(&the_lnet.ln_api_mutex);
3708 void lnet_incr_dlc_seq(void)
3710 atomic_inc(&lnet_dlc_seq_no);
3713 __u32 lnet_get_dlc_seq_locked(void)
3715 return atomic_read(&lnet_dlc_seq_no);
3719 lnet_ni_set_healthv(lnet_nid_t nid, int value, bool all)
3721 struct lnet_net *net;
3724 lnet_net_lock(LNET_LOCK_EX);
3725 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3726 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3727 if (all || (nid_is_nid4(&ni->ni_nid) &&
3728 lnet_nid_to_nid4(&ni->ni_nid) == nid)) {
3729 atomic_set(&ni->ni_healthv, value);
3730 if (list_empty(&ni->ni_recovery) &&
3731 value < LNET_MAX_HEALTH_VALUE) {
3732 CERROR("manually adding local NI %s to recovery\n",
3733 libcfs_nidstr(&ni->ni_nid));
3734 list_add_tail(&ni->ni_recovery,
3735 &the_lnet.ln_mt_localNIRecovq);
3736 lnet_ni_addref_locked(ni, 0);
3739 lnet_net_unlock(LNET_LOCK_EX);
3745 lnet_net_unlock(LNET_LOCK_EX);
3749 lnet_ni_set_conns_per_peer(lnet_nid_t nid, int value, bool all)
3751 struct lnet_net *net;
3754 lnet_net_lock(LNET_LOCK_EX);
3755 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3756 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3757 if (lnet_nid_to_nid4(&ni->ni_nid) != nid && !all)
3759 if (LNET_NETTYP(net->net_id) == SOCKLND)
3760 ni->ni_lnd_tunables.lnd_tun_u.lnd_sock.lnd_conns_per_peer = value;
3761 else if (LNET_NETTYP(net->net_id) == O2IBLND)
3762 ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = value;
3764 lnet_net_unlock(LNET_LOCK_EX);
3769 lnet_net_unlock(LNET_LOCK_EX);
3773 lnet_get_local_ni_hstats(struct lnet_ioctl_local_ni_hstats *stats)
3777 lnet_nid_t nid = stats->hlni_nid;
3779 cpt = lnet_net_lock_current();
3780 ni = lnet_nid2ni_locked(nid, cpt);
3787 stats->hlni_local_interrupt = atomic_read(&ni->ni_hstats.hlt_local_interrupt);
3788 stats->hlni_local_dropped = atomic_read(&ni->ni_hstats.hlt_local_dropped);
3789 stats->hlni_local_aborted = atomic_read(&ni->ni_hstats.hlt_local_aborted);
3790 stats->hlni_local_no_route = atomic_read(&ni->ni_hstats.hlt_local_no_route);
3791 stats->hlni_local_timeout = atomic_read(&ni->ni_hstats.hlt_local_timeout);
3792 stats->hlni_local_error = atomic_read(&ni->ni_hstats.hlt_local_error);
3793 stats->hlni_fatal_error = atomic_read(&ni->ni_fatal_error_on);
3794 stats->hlni_health_value = atomic_read(&ni->ni_healthv);
3795 stats->hlni_ping_count = ni->ni_ping_count;
3796 stats->hlni_next_ping = ni->ni_next_ping;
3799 lnet_net_unlock(cpt);
3805 lnet_get_local_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
3810 lnet_net_lock(LNET_LOCK_EX);
3811 list_for_each_entry(ni, &the_lnet.ln_mt_localNIRecovq, ni_recovery) {
3812 if (!nid_is_nid4(&ni->ni_nid))
3814 list->rlst_nid_array[i] = lnet_nid_to_nid4(&ni->ni_nid);
3816 if (i >= LNET_MAX_SHOW_NUM_NID)
3819 lnet_net_unlock(LNET_LOCK_EX);
3820 list->rlst_num_nids = i;
3826 lnet_get_peer_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
3828 struct lnet_peer_ni *lpni;
3831 lnet_net_lock(LNET_LOCK_EX);
3832 list_for_each_entry(lpni, &the_lnet.ln_mt_peerNIRecovq, lpni_recovery) {
3833 list->rlst_nid_array[i] = lpni->lpni_nid;
3835 if (i >= LNET_MAX_SHOW_NUM_NID)
3838 lnet_net_unlock(LNET_LOCK_EX);
3839 list->rlst_num_nids = i;
3845 * LNet ioctl handler.
3849 LNetCtl(unsigned int cmd, void *arg)
3851 struct libcfs_ioctl_data *data = arg;
3852 struct lnet_ioctl_config_data *config;
3853 struct lnet_process_id id = {0};
3857 BUILD_BUG_ON(sizeof(struct lnet_ioctl_net_config) +
3858 sizeof(struct lnet_ioctl_config_data) > LIBCFS_IOC_DATA_MAX);
3861 case IOC_LIBCFS_GET_NI:
3862 rc = LNetGetId(data->ioc_count, &id);
3863 data->ioc_nid = id.nid;
3866 case IOC_LIBCFS_FAIL_NID:
3867 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
3869 case IOC_LIBCFS_ADD_ROUTE: {
3870 /* default router sensitivity to 1 */
3871 unsigned int sensitivity = 1;
3874 if (config->cfg_hdr.ioc_len < sizeof(*config))
3877 if (config->cfg_config_u.cfg_route.rtr_sensitivity) {
3879 config->cfg_config_u.cfg_route.rtr_sensitivity;
3882 mutex_lock(&the_lnet.ln_api_mutex);
3883 rc = lnet_add_route(config->cfg_net,
3884 config->cfg_config_u.cfg_route.rtr_hop,
3886 config->cfg_config_u.cfg_route.
3887 rtr_priority, sensitivity);
3888 mutex_unlock(&the_lnet.ln_api_mutex);
3892 case IOC_LIBCFS_DEL_ROUTE:
3895 if (config->cfg_hdr.ioc_len < sizeof(*config))
3898 mutex_lock(&the_lnet.ln_api_mutex);
3899 rc = lnet_del_route(config->cfg_net, config->cfg_nid);
3900 mutex_unlock(&the_lnet.ln_api_mutex);
3903 case IOC_LIBCFS_GET_ROUTE:
3906 if (config->cfg_hdr.ioc_len < sizeof(*config))
3909 mutex_lock(&the_lnet.ln_api_mutex);
3910 rc = lnet_get_route(config->cfg_count,
3912 &config->cfg_config_u.cfg_route.rtr_hop,
3914 &config->cfg_config_u.cfg_route.rtr_flags,
3915 &config->cfg_config_u.cfg_route.
3917 &config->cfg_config_u.cfg_route.
3919 mutex_unlock(&the_lnet.ln_api_mutex);
3922 case IOC_LIBCFS_GET_LOCAL_NI: {
3923 struct lnet_ioctl_config_ni *cfg_ni;
3924 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
3925 struct lnet_ioctl_element_stats *stats;
3930 /* get the tunables if they are available */
3931 if (cfg_ni->lic_cfg_hdr.ioc_len <
3932 sizeof(*cfg_ni) + sizeof(*stats) + sizeof(*tun))
3935 stats = (struct lnet_ioctl_element_stats *)
3937 tun = (struct lnet_ioctl_config_lnd_tunables *)
3938 (cfg_ni->lic_bulk + sizeof(*stats));
3940 tun_size = cfg_ni->lic_cfg_hdr.ioc_len - sizeof(*cfg_ni) -
3943 mutex_lock(&the_lnet.ln_api_mutex);
3944 rc = lnet_get_ni_config(cfg_ni, tun, stats, tun_size);
3945 mutex_unlock(&the_lnet.ln_api_mutex);
3949 case IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS: {
3950 struct lnet_ioctl_element_msg_stats *msg_stats = arg;
3952 if (msg_stats->im_hdr.ioc_len != sizeof(*msg_stats))
3955 mutex_lock(&the_lnet.ln_api_mutex);
3956 rc = lnet_get_ni_stats(msg_stats);
3957 mutex_unlock(&the_lnet.ln_api_mutex);
3962 case IOC_LIBCFS_GET_NET: {
3963 size_t total = sizeof(*config) +
3964 sizeof(struct lnet_ioctl_net_config);
3967 if (config->cfg_hdr.ioc_len < total)
3970 mutex_lock(&the_lnet.ln_api_mutex);
3971 rc = lnet_get_net_config(config);
3972 mutex_unlock(&the_lnet.ln_api_mutex);
3976 case IOC_LIBCFS_GET_LNET_STATS:
3978 struct lnet_ioctl_lnet_stats *lnet_stats = arg;
3980 if (lnet_stats->st_hdr.ioc_len < sizeof(*lnet_stats))
3983 mutex_lock(&the_lnet.ln_api_mutex);
3984 rc = lnet_counters_get(&lnet_stats->st_cntrs);
3985 mutex_unlock(&the_lnet.ln_api_mutex);
3989 case IOC_LIBCFS_RESET_LNET_STATS:
3991 mutex_lock(&the_lnet.ln_api_mutex);
3992 lnet_counters_reset();
3993 mutex_unlock(&the_lnet.ln_api_mutex);
3997 case IOC_LIBCFS_CONFIG_RTR:
4000 if (config->cfg_hdr.ioc_len < sizeof(*config))
4003 mutex_lock(&the_lnet.ln_api_mutex);
4004 if (config->cfg_config_u.cfg_buffers.buf_enable) {
4005 rc = lnet_rtrpools_enable();
4006 mutex_unlock(&the_lnet.ln_api_mutex);
4009 lnet_rtrpools_disable();
4010 mutex_unlock(&the_lnet.ln_api_mutex);
4013 case IOC_LIBCFS_ADD_BUF:
4016 if (config->cfg_hdr.ioc_len < sizeof(*config))
4019 mutex_lock(&the_lnet.ln_api_mutex);
4020 rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
4022 config->cfg_config_u.cfg_buffers.
4024 config->cfg_config_u.cfg_buffers.
4026 mutex_unlock(&the_lnet.ln_api_mutex);
4029 case IOC_LIBCFS_SET_NUMA_RANGE: {
4030 struct lnet_ioctl_set_value *numa;
4032 if (numa->sv_hdr.ioc_len != sizeof(*numa))
4034 lnet_net_lock(LNET_LOCK_EX);
4035 lnet_numa_range = numa->sv_value;
4036 lnet_net_unlock(LNET_LOCK_EX);
4040 case IOC_LIBCFS_GET_NUMA_RANGE: {
4041 struct lnet_ioctl_set_value *numa;
4043 if (numa->sv_hdr.ioc_len != sizeof(*numa))
4045 numa->sv_value = lnet_numa_range;
4049 case IOC_LIBCFS_GET_BUF: {
4050 struct lnet_ioctl_pool_cfg *pool_cfg;
4051 size_t total = sizeof(*config) + sizeof(*pool_cfg);
4055 if (config->cfg_hdr.ioc_len < total)
4058 pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
4060 mutex_lock(&the_lnet.ln_api_mutex);
4061 rc = lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
4062 mutex_unlock(&the_lnet.ln_api_mutex);
4066 case IOC_LIBCFS_GET_LOCAL_HSTATS: {
4067 struct lnet_ioctl_local_ni_hstats *stats = arg;
4069 if (stats->hlni_hdr.ioc_len < sizeof(*stats))
4072 mutex_lock(&the_lnet.ln_api_mutex);
4073 rc = lnet_get_local_ni_hstats(stats);
4074 mutex_unlock(&the_lnet.ln_api_mutex);
4079 case IOC_LIBCFS_GET_RECOVERY_QUEUE: {
4080 struct lnet_ioctl_recovery_list *list = arg;
4081 if (list->rlst_hdr.ioc_len < sizeof(*list))
4084 mutex_lock(&the_lnet.ln_api_mutex);
4085 if (list->rlst_type == LNET_HEALTH_TYPE_LOCAL_NI)
4086 rc = lnet_get_local_ni_recovery_list(list);
4088 rc = lnet_get_peer_ni_recovery_list(list);
4089 mutex_unlock(&the_lnet.ln_api_mutex);
4093 case IOC_LIBCFS_ADD_PEER_NI: {
4094 struct lnet_ioctl_peer_cfg *cfg = arg;
4096 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4099 mutex_lock(&the_lnet.ln_api_mutex);
4100 rc = lnet_add_peer_ni(cfg->prcfg_prim_nid,
4102 cfg->prcfg_mr, false);
4103 mutex_unlock(&the_lnet.ln_api_mutex);
4107 case IOC_LIBCFS_DEL_PEER_NI: {
4108 struct lnet_ioctl_peer_cfg *cfg = arg;
4110 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4113 mutex_lock(&the_lnet.ln_api_mutex);
4114 rc = lnet_del_peer_ni(cfg->prcfg_prim_nid,
4115 cfg->prcfg_cfg_nid);
4116 mutex_unlock(&the_lnet.ln_api_mutex);
4120 case IOC_LIBCFS_GET_PEER_INFO: {
4121 struct lnet_ioctl_peer *peer_info = arg;
4123 if (peer_info->pr_hdr.ioc_len < sizeof(*peer_info))
4126 mutex_lock(&the_lnet.ln_api_mutex);
4127 rc = lnet_get_peer_ni_info(
4128 peer_info->pr_count,
4130 peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
4131 &peer_info->pr_lnd_u.pr_peer_credits.cr_ncpt,
4132 &peer_info->pr_lnd_u.pr_peer_credits.cr_refcount,
4133 &peer_info->pr_lnd_u.pr_peer_credits.cr_ni_peer_tx_credits,
4134 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_credits,
4135 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_rtr_credits,
4136 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_min_tx_credits,
4137 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_qnob);
4138 mutex_unlock(&the_lnet.ln_api_mutex);
4142 case IOC_LIBCFS_GET_PEER_NI: {
4143 struct lnet_ioctl_peer_cfg *cfg = arg;
4145 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4148 mutex_lock(&the_lnet.ln_api_mutex);
4149 rc = lnet_get_peer_info(cfg,
4150 (void __user *)cfg->prcfg_bulk);
4151 mutex_unlock(&the_lnet.ln_api_mutex);
4155 case IOC_LIBCFS_GET_PEER_LIST: {
4156 struct lnet_ioctl_peer_cfg *cfg = arg;
4158 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4161 mutex_lock(&the_lnet.ln_api_mutex);
4162 rc = lnet_get_peer_list(&cfg->prcfg_count, &cfg->prcfg_size,
4163 (struct lnet_process_id __user *)cfg->prcfg_bulk);
4164 mutex_unlock(&the_lnet.ln_api_mutex);
4168 case IOC_LIBCFS_SET_HEALHV: {
4169 struct lnet_ioctl_reset_health_cfg *cfg = arg;
4171 if (cfg->rh_hdr.ioc_len < sizeof(*cfg))
4173 if (cfg->rh_value < 0 ||
4174 cfg->rh_value > LNET_MAX_HEALTH_VALUE)
4175 value = LNET_MAX_HEALTH_VALUE;
4177 value = cfg->rh_value;
4178 CDEBUG(D_NET, "Manually setting healthv to %d for %s:%s. all = %d\n",
4179 value, (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI) ?
4180 "local" : "peer", libcfs_nid2str(cfg->rh_nid), cfg->rh_all);
4181 mutex_lock(&the_lnet.ln_api_mutex);
4182 if (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI)
4183 lnet_ni_set_healthv(cfg->rh_nid, value,
4186 lnet_peer_ni_set_healthv(cfg->rh_nid, value,
4188 mutex_unlock(&the_lnet.ln_api_mutex);
4192 case IOC_LIBCFS_SET_CONNS_PER_PEER: {
4193 struct lnet_ioctl_reset_conns_per_peer_cfg *cfg = arg;
4196 if (cfg->rcpp_hdr.ioc_len < sizeof(*cfg))
4198 if (cfg->rcpp_value < 0)
4201 value = cfg->rcpp_value;
4203 "Setting conns_per_peer to %d for %s. all = %d\n",
4204 value, libcfs_nid2str(cfg->rcpp_nid), cfg->rcpp_all);
4205 mutex_lock(&the_lnet.ln_api_mutex);
4206 lnet_ni_set_conns_per_peer(cfg->rcpp_nid, value, cfg->rcpp_all);
4207 mutex_unlock(&the_lnet.ln_api_mutex);
4211 case IOC_LIBCFS_NOTIFY_ROUTER: {
4212 time64_t deadline = ktime_get_real_seconds() - data->ioc_u64[0];
4214 /* The deadline passed in by the user should be some time in
4215 * seconds in the future since the UNIX epoch. We have to map
4216 * that deadline to the wall clock.
4218 deadline += ktime_get_seconds();
4219 return lnet_notify(NULL, data->ioc_nid, data->ioc_flags, false,
4223 case IOC_LIBCFS_LNET_DIST:
4224 rc = LNetDist(data->ioc_nid, &data->ioc_nid, &data->ioc_u32[1]);
4225 if (rc < 0 && rc != -EHOSTUNREACH)
4228 data->ioc_u32[0] = rc;
4231 case IOC_LIBCFS_TESTPROTOCOMPAT:
4232 the_lnet.ln_testprotocompat = data->ioc_flags;
4235 case IOC_LIBCFS_LNET_FAULT:
4236 return lnet_fault_ctl(data->ioc_flags, data);
4238 case IOC_LIBCFS_PING: {
4239 signed long timeout;
4241 id.nid = data->ioc_nid;
4242 id.pid = data->ioc_u32[0];
4244 /* If timeout is negative then set default of 3 minutes */
4245 if (((s32)data->ioc_u32[1] <= 0) ||
4246 data->ioc_u32[1] > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
4247 timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
4249 timeout = nsecs_to_jiffies(data->ioc_u32[1] * NSEC_PER_MSEC);
4251 rc = lnet_ping(id, timeout, data->ioc_pbuf1,
4252 data->ioc_plen1 / sizeof(struct lnet_process_id));
4257 data->ioc_count = rc;
4261 case IOC_LIBCFS_PING_PEER: {
4262 struct lnet_ioctl_ping_data *ping = arg;
4263 struct lnet_peer *lp;
4264 signed long timeout;
4266 /* If timeout is negative then set default of 3 minutes */
4267 if (((s32)ping->op_param) <= 0 ||
4268 ping->op_param > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
4269 timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
4271 timeout = nsecs_to_jiffies(ping->op_param * NSEC_PER_MSEC);
4273 rc = lnet_ping(ping->ping_id, timeout,
4279 mutex_lock(&the_lnet.ln_api_mutex);
4280 lp = lnet_find_peer(ping->ping_id.nid);
4282 ping->ping_id.nid = lp->lp_primary_nid;
4283 ping->mr_info = lnet_peer_is_multi_rail(lp);
4284 lnet_peer_decref_locked(lp);
4286 mutex_unlock(&the_lnet.ln_api_mutex);
4288 ping->ping_count = rc;
4292 case IOC_LIBCFS_DISCOVER: {
4293 struct lnet_ioctl_ping_data *discover = arg;
4294 struct lnet_peer *lp;
4296 rc = lnet_discover(discover->ping_id, discover->op_param,
4298 discover->ping_count);
4302 mutex_lock(&the_lnet.ln_api_mutex);
4303 lp = lnet_find_peer(discover->ping_id.nid);
4305 discover->ping_id.nid = lp->lp_primary_nid;
4306 discover->mr_info = lnet_peer_is_multi_rail(lp);
4307 lnet_peer_decref_locked(lp);
4309 mutex_unlock(&the_lnet.ln_api_mutex);
4311 discover->ping_count = rc;
4315 case IOC_LIBCFS_ADD_UDSP: {
4316 struct lnet_ioctl_udsp *ioc_udsp = arg;
4317 __u32 bulk_size = ioc_udsp->iou_hdr.ioc_len;
4319 mutex_lock(&the_lnet.ln_api_mutex);
4320 rc = lnet_udsp_demarshal_add(arg, bulk_size);
4322 rc = lnet_udsp_apply_policies(NULL, false);
4323 CDEBUG(D_NET, "policy application returned %d\n", rc);
4326 mutex_unlock(&the_lnet.ln_api_mutex);
4331 case IOC_LIBCFS_DEL_UDSP: {
4332 struct lnet_ioctl_udsp *ioc_udsp = arg;
4333 int idx = ioc_udsp->iou_idx;
4335 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4338 mutex_lock(&the_lnet.ln_api_mutex);
4339 rc = lnet_udsp_del_policy(idx);
4341 rc = lnet_udsp_apply_policies(NULL, false);
4342 CDEBUG(D_NET, "policy re-application returned %d\n",
4346 mutex_unlock(&the_lnet.ln_api_mutex);
4351 case IOC_LIBCFS_GET_UDSP_SIZE: {
4352 struct lnet_ioctl_udsp *ioc_udsp = arg;
4353 struct lnet_udsp *udsp;
4355 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4360 mutex_lock(&the_lnet.ln_api_mutex);
4361 udsp = lnet_udsp_get_policy(ioc_udsp->iou_idx);
4365 /* coming in iou_idx will hold the idx of the udsp
4366 * to get the size of. going out the iou_idx will
4367 * hold the size of the UDSP found at the passed
4370 ioc_udsp->iou_idx = lnet_get_udsp_size(udsp);
4371 if (ioc_udsp->iou_idx < 0)
4374 mutex_unlock(&the_lnet.ln_api_mutex);
4379 case IOC_LIBCFS_GET_UDSP: {
4380 struct lnet_ioctl_udsp *ioc_udsp = arg;
4381 struct lnet_udsp *udsp;
4383 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4388 mutex_lock(&the_lnet.ln_api_mutex);
4389 udsp = lnet_udsp_get_policy(ioc_udsp->iou_idx);
4393 rc = lnet_udsp_marshal(udsp, ioc_udsp);
4394 mutex_unlock(&the_lnet.ln_api_mutex);
4399 case IOC_LIBCFS_GET_CONST_UDSP_INFO: {
4400 struct lnet_ioctl_construct_udsp_info *info = arg;
4402 if (info->cud_hdr.ioc_len < sizeof(*info))
4405 CDEBUG(D_NET, "GET_UDSP_INFO for %s\n",
4406 libcfs_nid2str(info->cud_nid));
4408 mutex_lock(&the_lnet.ln_api_mutex);
4409 lnet_udsp_get_construct_info(info);
4410 mutex_unlock(&the_lnet.ln_api_mutex);
4416 ni = lnet_net2ni_addref(data->ioc_net);
4420 if (ni->ni_net->net_lnd->lnd_ctl == NULL)
4423 rc = ni->ni_net->net_lnd->lnd_ctl(ni, cmd, arg);
4430 EXPORT_SYMBOL(LNetCtl);
4432 void LNetDebugPeer(struct lnet_process_id id)
4434 lnet_debug_peer(id.nid);
4436 EXPORT_SYMBOL(LNetDebugPeer);
4439 * Determine if the specified peer \a nid is on the local node.
4441 * \param nid peer nid to check
4443 * \retval true If peer NID is on the local node.
4444 * \retval false If peer NID is not on the local node.
4446 bool LNetIsPeerLocal(lnet_nid_t nid)
4448 struct lnet_net *net;
4452 cpt = lnet_net_lock_current();
4453 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
4454 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
4455 if (lnet_nid_to_nid4(&ni->ni_nid) == nid) {
4456 lnet_net_unlock(cpt);
4461 lnet_net_unlock(cpt);
4465 EXPORT_SYMBOL(LNetIsPeerLocal);
4468 * Retrieve the struct lnet_process_id ID of LNet interface at \a index.
4469 * Note that all interfaces share a same PID, as requested by LNetNIInit().
4471 * \param index Index of the interface to look up.
4472 * \param id On successful return, this location will hold the
4473 * struct lnet_process_id ID of the interface.
4475 * \retval 0 If an interface exists at \a index.
4476 * \retval -ENOENT If no interface has been found.
4479 LNetGetId(unsigned int index, struct lnet_process_id *id)
4482 struct lnet_net *net;
4486 LASSERT(the_lnet.ln_refcount > 0);
4488 cpt = lnet_net_lock_current();
4490 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
4491 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
4492 if (!nid_is_nid4(&ni->ni_nid))
4493 /* FIXME this needs to be handled */
4498 id->nid = lnet_nid_to_nid4(&ni->ni_nid);
4499 id->pid = the_lnet.ln_pid;
4505 lnet_net_unlock(cpt);
4508 EXPORT_SYMBOL(LNetGetId);
4513 struct lnet_handle_md mdh;
4514 struct completion completion;
4518 lnet_ping_event_handler(struct lnet_event *event)
4520 struct ping_data *pd = event->md_user_ptr;
4522 CDEBUG(D_NET, "ping event (%d %d)%s\n",
4523 event->type, event->status,
4524 event->unlinked ? " unlinked" : "");
4526 if (event->status) {
4528 pd->rc = event->status;
4529 } else if (event->type == LNET_EVENT_REPLY) {
4531 pd->rc = event->mlength;
4533 if (event->unlinked)
4534 complete(&pd->completion);
4537 static int lnet_ping(struct lnet_process_id id, signed long timeout,
4538 struct lnet_process_id __user *ids, int n_ids)
4540 struct lnet_md md = { NULL };
4541 struct ping_data pd = { 0 };
4542 struct lnet_ping_buffer *pbuf;
4543 struct lnet_process_id tmpid;
4549 /* n_ids limit is arbitrary */
4550 if (n_ids <= 0 || id.nid == LNET_NID_ANY)
4554 * if the user buffer has more space than the lnet_interfaces_max
4555 * then only fill it up to lnet_interfaces_max
4557 if (n_ids > lnet_interfaces_max)
4558 n_ids = lnet_interfaces_max;
4560 if (id.pid == LNET_PID_ANY)
4561 id.pid = LNET_PID_LUSTRE;
4563 pbuf = lnet_ping_buffer_alloc(n_ids, GFP_NOFS);
4567 /* initialize md content */
4568 md.start = &pbuf->pb_info;
4569 md.length = LNET_PING_INFO_SIZE(n_ids);
4570 md.threshold = 2; /* GET/REPLY */
4572 md.options = LNET_MD_TRUNCATE;
4574 md.handler = lnet_ping_event_handler;
4576 init_completion(&pd.completion);
4578 rc = LNetMDBind(&md, LNET_UNLINK, &pd.mdh);
4580 CERROR("Can't bind MD: %d\n", rc);
4581 goto fail_ping_buffer_decref;
4584 rc = LNetGet(LNET_NID_ANY, pd.mdh, id,
4585 LNET_RESERVED_PORTAL,
4586 LNET_PROTO_PING_MATCHBITS, 0, false);
4589 /* Don't CERROR; this could be deliberate! */
4590 rc2 = LNetMDUnlink(pd.mdh);
4593 /* NB must wait for the UNLINK event below... */
4596 if (wait_for_completion_timeout(&pd.completion, timeout) == 0) {
4597 /* Ensure completion in finite time... */
4598 LNetMDUnlink(pd.mdh);
4599 wait_for_completion(&pd.completion);
4603 goto fail_ping_buffer_decref;
4607 LASSERT(nob >= 0 && nob <= LNET_PING_INFO_SIZE(n_ids));
4609 rc = -EPROTO; /* if I can't parse... */
4612 CERROR("%s: ping info too short %d\n",
4613 libcfs_id2str(id), nob);
4614 goto fail_ping_buffer_decref;
4617 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) {
4618 lnet_swap_pinginfo(pbuf);
4619 } else if (pbuf->pb_info.pi_magic != LNET_PROTO_PING_MAGIC) {
4620 CERROR("%s: Unexpected magic %08x\n",
4621 libcfs_id2str(id), pbuf->pb_info.pi_magic);
4622 goto fail_ping_buffer_decref;
4625 if ((pbuf->pb_info.pi_features & LNET_PING_FEAT_NI_STATUS) == 0) {
4626 CERROR("%s: ping w/o NI status: 0x%x\n",
4627 libcfs_id2str(id), pbuf->pb_info.pi_features);
4628 goto fail_ping_buffer_decref;
4631 if (nob < LNET_PING_INFO_SIZE(0)) {
4632 CERROR("%s: Short reply %d(%d min)\n",
4634 nob, (int)LNET_PING_INFO_SIZE(0));
4635 goto fail_ping_buffer_decref;
4638 if (pbuf->pb_info.pi_nnis < n_ids)
4639 n_ids = pbuf->pb_info.pi_nnis;
4641 if (nob < LNET_PING_INFO_SIZE(n_ids)) {
4642 CERROR("%s: Short reply %d(%d expected)\n",
4644 nob, (int)LNET_PING_INFO_SIZE(n_ids));
4645 goto fail_ping_buffer_decref;
4648 rc = -EFAULT; /* if I segv in copy_to_user()... */
4650 memset(&tmpid, 0, sizeof(tmpid));
4651 for (i = 0; i < n_ids; i++) {
4652 tmpid.pid = pbuf->pb_info.pi_pid;
4653 tmpid.nid = pbuf->pb_info.pi_ni[i].ns_nid;
4654 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid)))
4655 goto fail_ping_buffer_decref;
4657 rc = pbuf->pb_info.pi_nnis;
4659 fail_ping_buffer_decref:
4660 lnet_ping_buffer_decref(pbuf);
4665 lnet_discover(struct lnet_process_id id, __u32 force,
4666 struct lnet_process_id __user *ids, int n_ids)
4668 struct lnet_peer_ni *lpni;
4669 struct lnet_peer_ni *p;
4670 struct lnet_peer *lp;
4671 struct lnet_process_id *buf;
4677 id.nid == LNET_NID_ANY)
4680 if (id.pid == LNET_PID_ANY)
4681 id.pid = LNET_PID_LUSTRE;
4684 * If the user buffer has more space than the lnet_interfaces_max,
4685 * then only fill it up to lnet_interfaces_max.
4687 if (n_ids > lnet_interfaces_max)
4688 n_ids = lnet_interfaces_max;
4690 CFS_ALLOC_PTR_ARRAY(buf, n_ids);
4694 cpt = lnet_net_lock_current();
4695 lpni = lnet_nid2peerni_locked(id.nid, LNET_NID_ANY, cpt);
4702 * Clearing the NIDS_UPTODATE flag ensures the peer will
4703 * be discovered, provided discovery has not been disabled.
4705 lp = lpni->lpni_peer_net->lpn_peer;
4706 spin_lock(&lp->lp_lock);
4707 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
4708 /* If the force flag is set, force a PING and PUSH as well. */
4710 lp->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH;
4711 spin_unlock(&lp->lp_lock);
4712 rc = lnet_discover_peer_locked(lpni, cpt, true);
4716 /* The lpni (or lp) for this NID may have changed and our ref is
4717 * the only thing keeping the old one around. Release the ref
4718 * and lookup the lpni again
4720 lnet_peer_ni_decref_locked(lpni);
4721 lpni = lnet_find_peer_ni_locked(id.nid);
4726 lp = lpni->lpni_peer_net->lpn_peer;
4730 while ((p = lnet_get_next_peer_ni_locked(lp, NULL, p)) != NULL) {
4731 buf[i].pid = id.pid;
4732 buf[i].nid = p->lpni_nid;
4739 lnet_peer_ni_decref_locked(lpni);
4741 lnet_net_unlock(cpt);
4744 if (copy_to_user(ids, buf, rc * sizeof(*buf)))
4746 CFS_FREE_PTR_ARRAY(buf, n_ids);
4752 * Retrieve peer discovery status.
4754 * \retval 1 if lnet_peer_discovery_disabled is 0
4755 * \retval 0 if lnet_peer_discovery_disabled is 1
4758 LNetGetPeerDiscoveryStatus(void)
4760 return !lnet_peer_discovery_disabled;
4762 EXPORT_SYMBOL(LNetGetPeerDiscoveryStatus);