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 unsigned int lnet_max_recovery_ping_interval = 900;
132 unsigned int lnet_max_recovery_ping_count = 9;
133 static int max_recovery_ping_interval_set(const char *val,
134 cfs_kernel_param_arg_t *kp);
136 #define param_check_max_recovery_ping_interval(name, p) \
137 __param_check(name, p, int)
139 #ifdef HAVE_KERNEL_PARAM_OPS
140 static struct kernel_param_ops param_ops_max_recovery_ping_interval = {
141 .set = max_recovery_ping_interval_set,
142 .get = param_get_int,
144 module_param(lnet_max_recovery_ping_interval, max_recovery_ping_interval, 0644);
146 module_param_call(lnet_max_recovery_ping_interval, max_recovery_ping_interval,
147 param_get_int, &lnet_max_recovery_ping_interval, 0644);
149 MODULE_PARM_DESC(lnet_max_recovery_ping_interval,
150 "The max interval between LNet recovery pings, in seconds");
152 static int lnet_interfaces_max = LNET_INTERFACES_MAX_DEFAULT;
153 static int intf_max_set(const char *val, cfs_kernel_param_arg_t *kp);
155 static struct kernel_param_ops param_ops_interfaces_max = {
157 .get = param_get_int,
160 #define param_check_interfaces_max(name, p) \
161 __param_check(name, p, int)
163 #ifdef HAVE_KERNEL_PARAM_OPS
164 module_param(lnet_interfaces_max, interfaces_max, 0644);
166 module_param_call(lnet_interfaces_max, intf_max_set, param_get_int,
167 ¶m_ops_interfaces_max, 0644);
169 MODULE_PARM_DESC(lnet_interfaces_max,
170 "Maximum number of interfaces in a node.");
172 unsigned lnet_peer_discovery_disabled = 0;
173 static int discovery_set(const char *val, cfs_kernel_param_arg_t *kp);
175 static struct kernel_param_ops param_ops_discovery_disabled = {
176 .set = discovery_set,
177 .get = param_get_int,
180 #define param_check_discovery_disabled(name, p) \
181 __param_check(name, p, int)
182 #ifdef HAVE_KERNEL_PARAM_OPS
183 module_param(lnet_peer_discovery_disabled, discovery_disabled, 0644);
185 module_param_call(lnet_peer_discovery_disabled, discovery_set, param_get_int,
186 ¶m_ops_discovery_disabled, 0644);
188 MODULE_PARM_DESC(lnet_peer_discovery_disabled,
189 "Set to 1 to disable peer discovery on this node.");
191 unsigned int lnet_drop_asym_route;
192 static int drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp);
194 static struct kernel_param_ops param_ops_drop_asym_route = {
195 .set = drop_asym_route_set,
196 .get = param_get_int,
199 #define param_check_drop_asym_route(name, p) \
200 __param_check(name, p, int)
201 #ifdef HAVE_KERNEL_PARAM_OPS
202 module_param(lnet_drop_asym_route, drop_asym_route, 0644);
204 module_param_call(lnet_drop_asym_route, drop_asym_route_set, param_get_int,
205 ¶m_ops_drop_asym_route, 0644);
207 MODULE_PARM_DESC(lnet_drop_asym_route,
208 "Set to 1 to drop asymmetrical route messages.");
210 #define LNET_TRANSACTION_TIMEOUT_DEFAULT 50
211 unsigned int lnet_transaction_timeout = LNET_TRANSACTION_TIMEOUT_DEFAULT;
212 static int transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp);
213 #ifdef HAVE_KERNEL_PARAM_OPS
214 static struct kernel_param_ops param_ops_transaction_timeout = {
215 .set = transaction_to_set,
216 .get = param_get_int,
219 #define param_check_transaction_timeout(name, p) \
220 __param_check(name, p, int)
221 module_param(lnet_transaction_timeout, transaction_timeout, S_IRUGO|S_IWUSR);
223 module_param_call(lnet_transaction_timeout, transaction_to_set, param_get_int,
224 &lnet_transaction_timeout, S_IRUGO|S_IWUSR);
226 MODULE_PARM_DESC(lnet_transaction_timeout,
227 "Maximum number of seconds to wait for a peer response.");
229 #define LNET_RETRY_COUNT_DEFAULT 2
230 unsigned int lnet_retry_count = LNET_RETRY_COUNT_DEFAULT;
231 static int retry_count_set(const char *val, cfs_kernel_param_arg_t *kp);
232 #ifdef HAVE_KERNEL_PARAM_OPS
233 static struct kernel_param_ops param_ops_retry_count = {
234 .set = retry_count_set,
235 .get = param_get_int,
238 #define param_check_retry_count(name, p) \
239 __param_check(name, p, int)
240 module_param(lnet_retry_count, retry_count, S_IRUGO|S_IWUSR);
242 module_param_call(lnet_retry_count, retry_count_set, param_get_int,
243 &lnet_retry_count, S_IRUGO|S_IWUSR);
245 MODULE_PARM_DESC(lnet_retry_count,
246 "Maximum number of times to retry transmitting a message");
248 unsigned int lnet_response_tracking = 3;
249 static int response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp);
251 #ifdef HAVE_KERNEL_PARAM_OPS
252 static struct kernel_param_ops param_ops_response_tracking = {
253 .set = response_tracking_set,
254 .get = param_get_int,
257 #define param_check_response_tracking(name, p) \
258 __param_check(name, p, int)
259 module_param(lnet_response_tracking, response_tracking, 0644);
261 module_param_call(lnet_response_tracking, response_tracking_set, param_get_int,
262 &lnet_response_tracking, 0644);
264 MODULE_PARM_DESC(lnet_response_tracking,
265 "(0|1|2|3) LNet Internal Only|GET Reply only|PUT ACK only|Full Tracking (default)");
267 #define LNET_LND_TIMEOUT_DEFAULT ((LNET_TRANSACTION_TIMEOUT_DEFAULT - 1) / \
268 (LNET_RETRY_COUNT_DEFAULT + 1))
269 unsigned int lnet_lnd_timeout = LNET_LND_TIMEOUT_DEFAULT;
270 static void lnet_set_lnd_timeout(void)
272 lnet_lnd_timeout = (lnet_transaction_timeout - 1) /
273 (lnet_retry_count + 1);
277 * This sequence number keeps track of how many times DLC was used to
278 * update the local NIs. It is incremented when a NI is added or
279 * removed and checked when sending a message to determine if there is
280 * a need to re-run the selection algorithm. See lnet_select_pathway()
281 * for more details on its usage.
283 static atomic_t lnet_dlc_seq_no = ATOMIC_INIT(0);
285 static int lnet_ping(struct lnet_process_id id4, struct lnet_nid *src_nid,
286 signed long timeout, struct lnet_process_id __user *ids,
289 static int lnet_discover(struct lnet_process_id id, __u32 force,
290 struct lnet_process_id __user *ids, int n_ids);
293 sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
296 unsigned *sensitivity = (unsigned *)kp->arg;
299 rc = kstrtoul(val, 0, &value);
301 CERROR("Invalid module parameter value for 'lnet_health_sensitivity'\n");
306 * The purpose of locking the api_mutex here is to ensure that
307 * the correct value ends up stored properly.
309 mutex_lock(&the_lnet.ln_api_mutex);
311 if (value > LNET_MAX_HEALTH_VALUE) {
312 mutex_unlock(&the_lnet.ln_api_mutex);
313 CERROR("Invalid health value. Maximum: %d value = %lu\n",
314 LNET_MAX_HEALTH_VALUE, value);
318 if (*sensitivity != 0 && value == 0 && lnet_retry_count != 0) {
319 lnet_retry_count = 0;
320 lnet_set_lnd_timeout();
323 *sensitivity = value;
325 mutex_unlock(&the_lnet.ln_api_mutex);
331 recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp)
333 CWARN("'lnet_recovery_interval' has been deprecated\n");
339 max_recovery_ping_interval_set(const char *val, cfs_kernel_param_arg_t *kp)
344 rc = kstrtoul(val, 0, &value);
346 CERROR("Invalid module parameter value for 'lnet_max_recovery_ping_interval'\n");
351 CERROR("Invalid max ping timeout. Must be strictly positive\n");
355 /* The purpose of locking the api_mutex here is to ensure that
356 * the correct value ends up stored properly.
358 mutex_lock(&the_lnet.ln_api_mutex);
359 lnet_max_recovery_ping_interval = value;
360 lnet_max_recovery_ping_count = 0;
363 lnet_max_recovery_ping_count++;
366 mutex_unlock(&the_lnet.ln_api_mutex);
372 discovery_set(const char *val, cfs_kernel_param_arg_t *kp)
375 unsigned *discovery_off = (unsigned *)kp->arg;
377 struct lnet_ping_buffer *pbuf;
379 rc = kstrtoul(val, 0, &value);
381 CERROR("Invalid module parameter value for 'lnet_peer_discovery_disabled'\n");
385 value = (value) ? 1 : 0;
388 * The purpose of locking the api_mutex here is to ensure that
389 * the correct value ends up stored properly.
391 mutex_lock(&the_lnet.ln_api_mutex);
393 if (value == *discovery_off) {
394 mutex_unlock(&the_lnet.ln_api_mutex);
399 * We still want to set the discovery value even when LNet is not
400 * running. This is the case when LNet is being loaded and we want
401 * the module parameters to take effect. Otherwise if we're
402 * changing the value dynamically, we want to set it after
405 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
406 *discovery_off = value;
407 mutex_unlock(&the_lnet.ln_api_mutex);
411 /* tell peers that discovery setting has changed */
412 lnet_net_lock(LNET_LOCK_EX);
413 pbuf = the_lnet.ln_ping_target;
415 pbuf->pb_info.pi_features &= ~LNET_PING_FEAT_DISCOVERY;
417 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
418 lnet_net_unlock(LNET_LOCK_EX);
420 /* only send a push when we're turning off discovery */
421 if (*discovery_off <= 0 && value > 0)
422 lnet_push_update_to_peers(1);
423 *discovery_off = value;
425 mutex_unlock(&the_lnet.ln_api_mutex);
431 drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp)
434 unsigned int *drop_asym_route = (unsigned int *)kp->arg;
437 rc = kstrtoul(val, 0, &value);
439 CERROR("Invalid module parameter value for "
440 "'lnet_drop_asym_route'\n");
445 * The purpose of locking the api_mutex here is to ensure that
446 * the correct value ends up stored properly.
448 mutex_lock(&the_lnet.ln_api_mutex);
450 if (value == *drop_asym_route) {
451 mutex_unlock(&the_lnet.ln_api_mutex);
455 *drop_asym_route = value;
457 mutex_unlock(&the_lnet.ln_api_mutex);
463 transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp)
466 unsigned *transaction_to = (unsigned *)kp->arg;
469 rc = kstrtoul(val, 0, &value);
471 CERROR("Invalid module parameter value for 'lnet_transaction_timeout'\n");
476 * The purpose of locking the api_mutex here is to ensure that
477 * the correct value ends up stored properly.
479 mutex_lock(&the_lnet.ln_api_mutex);
481 if (value <= lnet_retry_count || value == 0) {
482 mutex_unlock(&the_lnet.ln_api_mutex);
483 CERROR("Invalid value for lnet_transaction_timeout (%lu). "
484 "Has to be greater than lnet_retry_count (%u)\n",
485 value, lnet_retry_count);
489 if (value == *transaction_to) {
490 mutex_unlock(&the_lnet.ln_api_mutex);
494 *transaction_to = value;
495 /* Update the lnet_lnd_timeout now that we've modified the
496 * transaction timeout
498 lnet_set_lnd_timeout();
500 mutex_unlock(&the_lnet.ln_api_mutex);
506 retry_count_set(const char *val, cfs_kernel_param_arg_t *kp)
509 unsigned *retry_count = (unsigned *)kp->arg;
512 rc = kstrtoul(val, 0, &value);
514 CERROR("Invalid module parameter value for 'lnet_retry_count'\n");
519 * The purpose of locking the api_mutex here is to ensure that
520 * the correct value ends up stored properly.
522 mutex_lock(&the_lnet.ln_api_mutex);
524 if (lnet_health_sensitivity == 0 && value > 0) {
525 mutex_unlock(&the_lnet.ln_api_mutex);
526 CERROR("Can not set lnet_retry_count when health feature is turned off\n");
530 if (value > lnet_transaction_timeout) {
531 mutex_unlock(&the_lnet.ln_api_mutex);
532 CERROR("Invalid value for lnet_retry_count (%lu). "
533 "Has to be smaller than lnet_transaction_timeout (%u)\n",
534 value, lnet_transaction_timeout);
538 *retry_count = value;
540 /* Update the lnet_lnd_timeout now that we've modified the
543 lnet_set_lnd_timeout();
545 mutex_unlock(&the_lnet.ln_api_mutex);
551 intf_max_set(const char *val, cfs_kernel_param_arg_t *kp)
555 rc = kstrtoint(val, 0, &value);
557 CERROR("Invalid module parameter value for 'lnet_interfaces_max'\n");
561 if (value < LNET_INTERFACES_MIN) {
562 CWARN("max interfaces provided are too small, setting to %d\n",
563 LNET_INTERFACES_MAX_DEFAULT);
564 value = LNET_INTERFACES_MAX_DEFAULT;
567 *(int *)kp->arg = value;
573 response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp)
576 unsigned long new_value;
578 rc = kstrtoul(val, 0, &new_value);
580 CERROR("Invalid value for 'lnet_response_tracking'\n");
584 if (new_value < 0 || new_value > 3) {
585 CWARN("Invalid value (%lu) for 'lnet_response_tracking'\n",
590 lnet_response_tracking = new_value;
596 lnet_get_routes(void)
602 lnet_get_networks(void)
607 if (*networks != 0 && *ip2nets != 0) {
608 LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
609 "'ip2nets' but not both at once\n");
614 rc = lnet_parse_ip2nets(&nets, ip2nets);
615 return (rc == 0) ? nets : NULL;
625 lnet_init_locks(void)
627 spin_lock_init(&the_lnet.ln_eq_wait_lock);
628 spin_lock_init(&the_lnet.ln_msg_resend_lock);
629 init_completion(&the_lnet.ln_mt_wait_complete);
630 mutex_init(&the_lnet.ln_lnd_mutex);
633 struct kmem_cache *lnet_mes_cachep; /* MEs kmem_cache */
634 struct kmem_cache *lnet_small_mds_cachep; /* <= LNET_SMALL_MD_SIZE bytes
636 struct kmem_cache *lnet_udsp_cachep; /* udsp cache */
637 struct kmem_cache *lnet_rspt_cachep; /* response tracker cache */
638 struct kmem_cache *lnet_msg_cachep;
641 lnet_slab_setup(void)
643 /* create specific kmem_cache for MEs and small MDs (i.e., originally
644 * allocated in <size-xxx> kmem_cache).
646 lnet_mes_cachep = kmem_cache_create("lnet_MEs", sizeof(struct lnet_me),
648 if (!lnet_mes_cachep)
651 lnet_small_mds_cachep = kmem_cache_create("lnet_small_MDs",
652 LNET_SMALL_MD_SIZE, 0, 0,
654 if (!lnet_small_mds_cachep)
657 lnet_udsp_cachep = kmem_cache_create("lnet_udsp",
658 sizeof(struct lnet_udsp),
660 if (!lnet_udsp_cachep)
663 lnet_rspt_cachep = kmem_cache_create("lnet_rspt", sizeof(struct lnet_rsp_tracker),
665 if (!lnet_rspt_cachep)
668 lnet_msg_cachep = kmem_cache_create("lnet_msg", sizeof(struct lnet_msg),
670 if (!lnet_msg_cachep)
677 lnet_slab_cleanup(void)
679 if (lnet_msg_cachep) {
680 kmem_cache_destroy(lnet_msg_cachep);
681 lnet_msg_cachep = NULL;
684 if (lnet_rspt_cachep) {
685 kmem_cache_destroy(lnet_rspt_cachep);
686 lnet_rspt_cachep = NULL;
689 if (lnet_udsp_cachep) {
690 kmem_cache_destroy(lnet_udsp_cachep);
691 lnet_udsp_cachep = NULL;
694 if (lnet_small_mds_cachep) {
695 kmem_cache_destroy(lnet_small_mds_cachep);
696 lnet_small_mds_cachep = NULL;
699 if (lnet_mes_cachep) {
700 kmem_cache_destroy(lnet_mes_cachep);
701 lnet_mes_cachep = NULL;
706 lnet_create_remote_nets_table(void)
709 struct list_head *hash;
711 LASSERT(the_lnet.ln_remote_nets_hash == NULL);
712 LASSERT(the_lnet.ln_remote_nets_hbits > 0);
713 CFS_ALLOC_PTR_ARRAY(hash, LNET_REMOTE_NETS_HASH_SIZE);
715 CERROR("Failed to create remote nets hash table\n");
719 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
720 INIT_LIST_HEAD(&hash[i]);
721 the_lnet.ln_remote_nets_hash = hash;
726 lnet_destroy_remote_nets_table(void)
730 if (the_lnet.ln_remote_nets_hash == NULL)
733 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
734 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
736 CFS_FREE_PTR_ARRAY(the_lnet.ln_remote_nets_hash,
737 LNET_REMOTE_NETS_HASH_SIZE);
738 the_lnet.ln_remote_nets_hash = NULL;
742 lnet_destroy_locks(void)
744 if (the_lnet.ln_res_lock != NULL) {
745 cfs_percpt_lock_free(the_lnet.ln_res_lock);
746 the_lnet.ln_res_lock = NULL;
749 if (the_lnet.ln_net_lock != NULL) {
750 cfs_percpt_lock_free(the_lnet.ln_net_lock);
751 the_lnet.ln_net_lock = NULL;
756 lnet_create_locks(void)
760 the_lnet.ln_res_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
761 if (the_lnet.ln_res_lock == NULL)
764 the_lnet.ln_net_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
765 if (the_lnet.ln_net_lock == NULL)
771 lnet_destroy_locks();
775 static void lnet_assert_wire_constants(void)
777 /* Wire protocol assertions generated by 'wirecheck'
778 * running on Linux robert.bartonsoftware.com 2.6.8-1.521
779 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux
780 * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
784 BUILD_BUG_ON(LNET_PROTO_TCP_MAGIC != 0xeebc0ded);
785 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MAJOR != 1);
786 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MINOR != 0);
787 BUILD_BUG_ON(LNET_MSG_ACK != 0);
788 BUILD_BUG_ON(LNET_MSG_PUT != 1);
789 BUILD_BUG_ON(LNET_MSG_GET != 2);
790 BUILD_BUG_ON(LNET_MSG_REPLY != 3);
791 BUILD_BUG_ON(LNET_MSG_HELLO != 4);
793 BUILD_BUG_ON((int)sizeof(lnet_nid_t) != 8);
794 BUILD_BUG_ON((int)sizeof(lnet_pid_t) != 4);
796 /* Checks for struct lnet_nid */
797 BUILD_BUG_ON((int)sizeof(struct lnet_nid) != 20);
798 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_size) != 0);
799 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_size) != 1);
800 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_type) != 1);
801 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_type) != 1);
802 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_num) != 2);
803 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_num) != 2);
804 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_addr) != 4);
805 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_addr) != 16);
807 /* Checks for struct lnet_process_id_packed */
808 BUILD_BUG_ON((int)sizeof(struct lnet_process_id_packed) != 12);
809 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, nid) != 0);
810 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->nid) != 8);
811 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, pid) != 8);
812 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->pid) != 4);
814 /* Checks for struct lnet_handle_wire */
815 BUILD_BUG_ON((int)sizeof(struct lnet_handle_wire) != 16);
816 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
817 wh_interface_cookie) != 0);
818 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_interface_cookie) != 8);
819 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
820 wh_object_cookie) != 8);
821 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_object_cookie) != 8);
823 /* Checks for struct struct lnet_magicversion */
824 BUILD_BUG_ON((int)sizeof(struct lnet_magicversion) != 8);
825 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, magic) != 0);
826 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->magic) != 4);
827 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, version_major) != 4);
828 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_major) != 2);
829 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion,
830 version_minor) != 6);
831 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_minor) != 2);
833 /* Checks for struct _lnet_hdr_nid4 */
834 BUILD_BUG_ON((int)sizeof(struct _lnet_hdr_nid4) != 72);
835 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, dest_nid) != 0);
836 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->dest_nid) != 8);
837 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, src_nid) != 8);
838 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->src_nid) != 8);
839 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, dest_pid) != 16);
840 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->dest_pid) != 4);
841 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, src_pid) != 20);
842 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->src_pid) != 4);
843 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, type) != 24);
844 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->type) != 4);
845 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, payload_length) != 28);
846 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->payload_length) != 4);
847 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg) != 32);
848 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg) != 40);
851 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.dst_wmd) != 32);
852 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.dst_wmd) != 16);
853 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.match_bits) != 48);
854 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.match_bits) != 8);
855 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.mlength) != 56);
856 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.mlength) != 4);
859 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.ack_wmd) != 32);
860 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.ack_wmd) != 16);
861 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.match_bits) != 48);
862 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.match_bits) != 8);
863 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.hdr_data) != 56);
864 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.hdr_data) != 8);
865 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.ptl_index) != 64);
866 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.ptl_index) != 4);
867 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.offset) != 68);
868 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.offset) != 4);
871 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.return_wmd) != 32);
872 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.return_wmd) != 16);
873 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.match_bits) != 48);
874 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.match_bits) != 8);
875 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.ptl_index) != 56);
876 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.ptl_index) != 4);
877 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.src_offset) != 60);
878 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.src_offset) != 4);
879 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.sink_length) != 64);
880 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.sink_length) != 4);
883 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.reply.dst_wmd) != 32);
884 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.reply.dst_wmd) != 16);
887 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.hello.incarnation) != 32);
888 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.hello.incarnation) != 8);
889 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.hello.type) != 40);
890 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.hello.type) != 4);
892 /* Checks for struct lnet_ni_status and related constants */
893 BUILD_BUG_ON(LNET_NI_STATUS_INVALID != 0x00000000);
894 BUILD_BUG_ON(LNET_NI_STATUS_UP != 0x15aac0de);
895 BUILD_BUG_ON(LNET_NI_STATUS_DOWN != 0xdeadface);
897 /* Checks for struct lnet_ni_status */
898 BUILD_BUG_ON((int)sizeof(struct lnet_ni_status) != 16);
899 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_nid) != 0);
900 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_nid) != 8);
901 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_status) != 8);
902 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_status) != 4);
903 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_unused) != 12);
904 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_unused) != 4);
906 /* Checks for struct lnet_ping_info and related constants */
907 BUILD_BUG_ON(LNET_PROTO_PING_MAGIC != 0x70696E67);
908 BUILD_BUG_ON(LNET_PING_FEAT_INVAL != 0);
909 BUILD_BUG_ON(LNET_PING_FEAT_BASE != 1);
910 BUILD_BUG_ON(LNET_PING_FEAT_NI_STATUS != 2);
911 BUILD_BUG_ON(LNET_PING_FEAT_RTE_DISABLED != 4);
912 BUILD_BUG_ON(LNET_PING_FEAT_MULTI_RAIL != 8);
913 BUILD_BUG_ON(LNET_PING_FEAT_DISCOVERY != 16);
914 BUILD_BUG_ON(LNET_PING_FEAT_BITS != 31);
916 /* Checks for struct lnet_ping_info */
917 BUILD_BUG_ON((int)sizeof(struct lnet_ping_info) != 16);
918 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_magic) != 0);
919 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_magic) != 4);
920 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_features) != 4);
921 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_features) != 4);
922 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_pid) != 8);
923 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_pid) != 4);
924 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_nnis) != 12);
925 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_nnis) != 4);
926 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_ni) != 16);
927 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_ni) != 0);
929 /* Acceptor connection request */
930 BUILD_BUG_ON(LNET_PROTO_ACCEPTOR_VERSION != 1);
932 /* Checks for struct lnet_acceptor_connreq */
933 BUILD_BUG_ON((int)sizeof(struct lnet_acceptor_connreq) != 16);
934 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_magic) != 0);
935 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_magic) != 4);
936 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_version) != 4);
937 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_version) != 4);
938 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_nid) != 8);
939 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_nid) != 8);
941 /* Checks for struct lnet_acceptor_connreq_v2 */
942 BUILD_BUG_ON((int)sizeof(struct lnet_acceptor_connreq_v2) != 28);
943 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_magic) != 0);
944 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_magic) != 4);
945 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_version) != 4);
946 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_version) != 4);
947 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_nid) != 8);
948 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_nid) != 20);
950 /* Checks for struct lnet_counters_common */
951 BUILD_BUG_ON((int)sizeof(struct lnet_counters_common) != 60);
952 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_alloc) != 0);
953 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_alloc) != 4);
954 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_max) != 4);
955 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_max) != 4);
956 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_errors) != 8);
957 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_errors) != 4);
958 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_count) != 12);
959 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_count) != 4);
960 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_count) != 16);
961 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_count) != 4);
962 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_count) != 20);
963 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_count) != 4);
964 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_count) != 24);
965 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_count) != 4);
966 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_length) != 28);
967 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_length) != 8);
968 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_length) != 36);
969 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_length) != 8);
970 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_length) != 44);
971 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_length) != 8);
972 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_length) != 52);
973 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_length) != 8);
976 static const struct lnet_lnd *lnet_find_lnd_by_type(__u32 type)
978 const struct lnet_lnd *lnd;
980 /* holding lnd mutex */
981 if (type >= NUM_LNDS)
983 lnd = the_lnet.ln_lnds[type];
984 LASSERT(!lnd || lnd->lnd_type == type);
990 lnet_get_lnd_timeout(void)
992 return lnet_lnd_timeout;
994 EXPORT_SYMBOL(lnet_get_lnd_timeout);
997 lnet_register_lnd(const struct lnet_lnd *lnd)
999 mutex_lock(&the_lnet.ln_lnd_mutex);
1001 LASSERT(libcfs_isknown_lnd(lnd->lnd_type));
1002 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
1004 the_lnet.ln_lnds[lnd->lnd_type] = lnd;
1006 CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type));
1008 mutex_unlock(&the_lnet.ln_lnd_mutex);
1010 EXPORT_SYMBOL(lnet_register_lnd);
1013 lnet_unregister_lnd(const struct lnet_lnd *lnd)
1015 mutex_lock(&the_lnet.ln_lnd_mutex);
1017 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
1019 the_lnet.ln_lnds[lnd->lnd_type] = NULL;
1020 CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type));
1022 mutex_unlock(&the_lnet.ln_lnd_mutex);
1024 EXPORT_SYMBOL(lnet_unregister_lnd);
1027 lnet_counters_get_common_locked(struct lnet_counters_common *common)
1029 struct lnet_counters *ctr;
1032 /* FIXME !!! Their is no assert_lnet_net_locked() to ensure this
1033 * actually called under the protection of the lnet_net_lock.
1035 memset(common, 0, sizeof(*common));
1037 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
1038 common->lcc_msgs_max += ctr->lct_common.lcc_msgs_max;
1039 common->lcc_msgs_alloc += ctr->lct_common.lcc_msgs_alloc;
1040 common->lcc_errors += ctr->lct_common.lcc_errors;
1041 common->lcc_send_count += ctr->lct_common.lcc_send_count;
1042 common->lcc_recv_count += ctr->lct_common.lcc_recv_count;
1043 common->lcc_route_count += ctr->lct_common.lcc_route_count;
1044 common->lcc_drop_count += ctr->lct_common.lcc_drop_count;
1045 common->lcc_send_length += ctr->lct_common.lcc_send_length;
1046 common->lcc_recv_length += ctr->lct_common.lcc_recv_length;
1047 common->lcc_route_length += ctr->lct_common.lcc_route_length;
1048 common->lcc_drop_length += ctr->lct_common.lcc_drop_length;
1053 lnet_counters_get_common(struct lnet_counters_common *common)
1055 lnet_net_lock(LNET_LOCK_EX);
1056 lnet_counters_get_common_locked(common);
1057 lnet_net_unlock(LNET_LOCK_EX);
1059 EXPORT_SYMBOL(lnet_counters_get_common);
1062 lnet_counters_get(struct lnet_counters *counters)
1064 struct lnet_counters *ctr;
1065 struct lnet_counters_health *health = &counters->lct_health;
1068 memset(counters, 0, sizeof(*counters));
1070 lnet_net_lock(LNET_LOCK_EX);
1072 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1073 GOTO(out_unlock, rc = -ENODEV);
1075 lnet_counters_get_common_locked(&counters->lct_common);
1077 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
1078 health->lch_rst_alloc += ctr->lct_health.lch_rst_alloc;
1079 health->lch_resend_count += ctr->lct_health.lch_resend_count;
1080 health->lch_response_timeout_count +=
1081 ctr->lct_health.lch_response_timeout_count;
1082 health->lch_local_interrupt_count +=
1083 ctr->lct_health.lch_local_interrupt_count;
1084 health->lch_local_dropped_count +=
1085 ctr->lct_health.lch_local_dropped_count;
1086 health->lch_local_aborted_count +=
1087 ctr->lct_health.lch_local_aborted_count;
1088 health->lch_local_no_route_count +=
1089 ctr->lct_health.lch_local_no_route_count;
1090 health->lch_local_timeout_count +=
1091 ctr->lct_health.lch_local_timeout_count;
1092 health->lch_local_error_count +=
1093 ctr->lct_health.lch_local_error_count;
1094 health->lch_remote_dropped_count +=
1095 ctr->lct_health.lch_remote_dropped_count;
1096 health->lch_remote_error_count +=
1097 ctr->lct_health.lch_remote_error_count;
1098 health->lch_remote_timeout_count +=
1099 ctr->lct_health.lch_remote_timeout_count;
1100 health->lch_network_timeout_count +=
1101 ctr->lct_health.lch_network_timeout_count;
1104 lnet_net_unlock(LNET_LOCK_EX);
1107 EXPORT_SYMBOL(lnet_counters_get);
1110 lnet_counters_reset(void)
1112 struct lnet_counters *counters;
1115 lnet_net_lock(LNET_LOCK_EX);
1117 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1120 cfs_percpt_for_each(counters, i, the_lnet.ln_counters)
1121 memset(counters, 0, sizeof(struct lnet_counters));
1123 lnet_net_unlock(LNET_LOCK_EX);
1127 lnet_res_type2str(int type)
1132 case LNET_COOKIE_TYPE_MD:
1134 case LNET_COOKIE_TYPE_ME:
1136 case LNET_COOKIE_TYPE_EQ:
1142 lnet_res_container_cleanup(struct lnet_res_container *rec)
1146 if (rec->rec_type == 0) /* not set yet, it's uninitialized */
1149 while (!list_empty(&rec->rec_active)) {
1150 struct list_head *e = rec->rec_active.next;
1153 if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
1154 lnet_md_free(list_entry(e, struct lnet_libmd, md_list));
1156 } else { /* NB: Active MEs should be attached on portals */
1163 /* Found alive MD/ME/EQ, user really should unlink/free
1164 * all of them before finalize LNet, but if someone didn't,
1165 * we have to recycle garbage for him */
1166 CERROR("%d active elements on exit of %s container\n",
1167 count, lnet_res_type2str(rec->rec_type));
1170 if (rec->rec_lh_hash != NULL) {
1171 CFS_FREE_PTR_ARRAY(rec->rec_lh_hash, LNET_LH_HASH_SIZE);
1172 rec->rec_lh_hash = NULL;
1175 rec->rec_type = 0; /* mark it as finalized */
1179 lnet_res_container_setup(struct lnet_res_container *rec, int cpt, int type)
1184 LASSERT(rec->rec_type == 0);
1186 rec->rec_type = type;
1187 INIT_LIST_HEAD(&rec->rec_active);
1189 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type;
1191 /* Arbitrary choice of hash table size */
1192 LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt,
1193 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
1194 if (rec->rec_lh_hash == NULL) {
1199 for (i = 0; i < LNET_LH_HASH_SIZE; i++)
1200 INIT_LIST_HEAD(&rec->rec_lh_hash[i]);
1205 CERROR("Failed to setup %s resource container\n",
1206 lnet_res_type2str(type));
1207 lnet_res_container_cleanup(rec);
1212 lnet_res_containers_destroy(struct lnet_res_container **recs)
1214 struct lnet_res_container *rec;
1217 cfs_percpt_for_each(rec, i, recs)
1218 lnet_res_container_cleanup(rec);
1220 cfs_percpt_free(recs);
1223 static struct lnet_res_container **
1224 lnet_res_containers_create(int type)
1226 struct lnet_res_container **recs;
1227 struct lnet_res_container *rec;
1231 recs = cfs_percpt_alloc(lnet_cpt_table(), sizeof(*rec));
1233 CERROR("Failed to allocate %s resource containers\n",
1234 lnet_res_type2str(type));
1238 cfs_percpt_for_each(rec, i, recs) {
1239 rc = lnet_res_container_setup(rec, i, type);
1241 lnet_res_containers_destroy(recs);
1249 struct lnet_libhandle *
1250 lnet_res_lh_lookup(struct lnet_res_container *rec, __u64 cookie)
1252 /* ALWAYS called with lnet_res_lock held */
1253 struct list_head *head;
1254 struct lnet_libhandle *lh;
1257 if ((cookie & LNET_COOKIE_MASK) != rec->rec_type)
1260 hash = cookie >> (LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS);
1261 head = &rec->rec_lh_hash[hash & LNET_LH_HASH_MASK];
1263 list_for_each_entry(lh, head, lh_hash_chain) {
1264 if (lh->lh_cookie == cookie)
1272 lnet_res_lh_initialize(struct lnet_res_container *rec,
1273 struct lnet_libhandle *lh)
1275 /* ALWAYS called with lnet_res_lock held */
1276 unsigned int ibits = LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS;
1279 lh->lh_cookie = rec->rec_lh_cookie;
1280 rec->rec_lh_cookie += 1 << ibits;
1282 hash = (lh->lh_cookie >> ibits) & LNET_LH_HASH_MASK;
1284 list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
1288 lnet_create_array_of_queues(void)
1290 struct list_head **qs;
1291 struct list_head *q;
1294 qs = cfs_percpt_alloc(lnet_cpt_table(),
1295 sizeof(struct list_head));
1297 CERROR("Failed to allocate queues\n");
1301 cfs_percpt_for_each(q, i, qs)
1307 static int lnet_unprepare(void);
1310 lnet_prepare(lnet_pid_t requested_pid)
1312 /* Prepare to bring up the network */
1313 struct lnet_res_container **recs;
1316 if (requested_pid == LNET_PID_ANY) {
1317 /* Don't instantiate LNET just for me */
1321 LASSERT(the_lnet.ln_refcount == 0);
1323 the_lnet.ln_routing = 0;
1325 LASSERT((requested_pid & LNET_PID_USERFLAG) == 0);
1326 the_lnet.ln_pid = requested_pid;
1328 INIT_LIST_HEAD(&the_lnet.ln_test_peers);
1329 INIT_LIST_HEAD(&the_lnet.ln_remote_peer_ni_list);
1330 INIT_LIST_HEAD(&the_lnet.ln_nets);
1331 INIT_LIST_HEAD(&the_lnet.ln_routers);
1332 INIT_LIST_HEAD(&the_lnet.ln_drop_rules);
1333 INIT_LIST_HEAD(&the_lnet.ln_delay_rules);
1334 INIT_LIST_HEAD(&the_lnet.ln_dc_request);
1335 INIT_LIST_HEAD(&the_lnet.ln_dc_working);
1336 INIT_LIST_HEAD(&the_lnet.ln_dc_expired);
1337 INIT_LIST_HEAD(&the_lnet.ln_mt_localNIRecovq);
1338 INIT_LIST_HEAD(&the_lnet.ln_mt_peerNIRecovq);
1339 INIT_LIST_HEAD(&the_lnet.ln_udsp_list);
1340 init_waitqueue_head(&the_lnet.ln_dc_waitq);
1341 the_lnet.ln_mt_handler = NULL;
1342 init_completion(&the_lnet.ln_started);
1344 rc = lnet_slab_setup();
1348 rc = lnet_create_remote_nets_table();
1353 * NB the interface cookie in wire handles guards against delayed
1354 * replies and ACKs appearing valid after reboot.
1356 the_lnet.ln_interface_cookie = ktime_get_real_ns();
1358 the_lnet.ln_counters = cfs_percpt_alloc(lnet_cpt_table(),
1359 sizeof(struct lnet_counters));
1360 if (the_lnet.ln_counters == NULL) {
1361 CERROR("Failed to allocate counters for LNet\n");
1366 rc = lnet_peer_tables_create();
1370 rc = lnet_msg_containers_create();
1374 rc = lnet_res_container_setup(&the_lnet.ln_eq_container, 0,
1375 LNET_COOKIE_TYPE_EQ);
1379 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD);
1385 the_lnet.ln_md_containers = recs;
1387 rc = lnet_portals_create();
1389 CERROR("Failed to create portals for LNet: %d\n", rc);
1393 the_lnet.ln_mt_zombie_rstqs = lnet_create_array_of_queues();
1394 if (!the_lnet.ln_mt_zombie_rstqs) {
1407 lnet_unprepare(void)
1409 /* NB no LNET_LOCK since this is the last reference. All LND instances
1410 * have shut down already, so it is safe to unlink and free all
1411 * descriptors, even those that appear committed to a network op (eg MD
1412 * with non-zero pending count) */
1414 lnet_fail_nid(LNET_NID_ANY, 0);
1416 LASSERT(the_lnet.ln_refcount == 0);
1417 LASSERT(list_empty(&the_lnet.ln_test_peers));
1418 LASSERT(list_empty(&the_lnet.ln_nets));
1420 if (the_lnet.ln_mt_zombie_rstqs) {
1421 lnet_clean_zombie_rstqs();
1422 the_lnet.ln_mt_zombie_rstqs = NULL;
1425 lnet_assert_handler_unused(the_lnet.ln_mt_handler);
1426 the_lnet.ln_mt_handler = NULL;
1428 lnet_portals_destroy();
1430 if (the_lnet.ln_md_containers != NULL) {
1431 lnet_res_containers_destroy(the_lnet.ln_md_containers);
1432 the_lnet.ln_md_containers = NULL;
1435 lnet_res_container_cleanup(&the_lnet.ln_eq_container);
1437 lnet_msg_containers_destroy();
1439 lnet_rtrpools_free(0);
1441 if (the_lnet.ln_counters != NULL) {
1442 cfs_percpt_free(the_lnet.ln_counters);
1443 the_lnet.ln_counters = NULL;
1445 lnet_destroy_remote_nets_table();
1446 lnet_udsp_destroy(true);
1447 lnet_slab_cleanup();
1453 lnet_net2ni_locked(__u32 net_id, int cpt)
1456 struct lnet_net *net;
1458 LASSERT(cpt != LNET_LOCK_EX);
1460 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1461 if (net->net_id == net_id) {
1462 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
1472 lnet_net2ni_addref(__u32 net)
1477 ni = lnet_net2ni_locked(net, 0);
1479 lnet_ni_addref_locked(ni, 0);
1484 EXPORT_SYMBOL(lnet_net2ni_addref);
1487 lnet_get_net_locked(__u32 net_id)
1489 struct lnet_net *net;
1491 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1492 if (net->net_id == net_id)
1500 lnet_net_clr_pref_rtrs(struct lnet_net *net)
1502 struct list_head zombies;
1503 struct lnet_nid_list *ne;
1504 struct lnet_nid_list *tmp;
1506 INIT_LIST_HEAD(&zombies);
1508 lnet_net_lock(LNET_LOCK_EX);
1509 list_splice_init(&net->net_rtr_pref_nids, &zombies);
1510 lnet_net_unlock(LNET_LOCK_EX);
1512 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1513 list_del_init(&ne->nl_list);
1514 LIBCFS_FREE(ne, sizeof(*ne));
1519 lnet_net_add_pref_rtr(struct lnet_net *net,
1520 struct lnet_nid *gw_nid)
1521 __must_hold(&the_lnet.ln_api_mutex)
1523 struct lnet_nid_list *ne;
1525 /* This function is called with api_mutex held. When the api_mutex
1526 * is held the list can not be modified, as it is only modified as
1527 * a result of applying a UDSP and that happens under api_mutex
1530 list_for_each_entry(ne, &net->net_rtr_pref_nids, nl_list) {
1531 if (nid_same(&ne->nl_nid, gw_nid))
1535 LIBCFS_ALLOC(ne, sizeof(*ne));
1539 ne->nl_nid = *gw_nid;
1541 /* Lock the cpt to protect against addition and checks in the
1542 * selection algorithm
1544 lnet_net_lock(LNET_LOCK_EX);
1545 list_add(&ne->nl_list, &net->net_rtr_pref_nids);
1546 lnet_net_unlock(LNET_LOCK_EX);
1552 lnet_net_is_pref_rtr_locked(struct lnet_net *net, struct lnet_nid *rtr_nid)
1554 struct lnet_nid_list *ne;
1556 CDEBUG(D_NET, "%s: rtr pref empty: %d\n",
1557 libcfs_net2str(net->net_id),
1558 list_empty(&net->net_rtr_pref_nids));
1560 if (list_empty(&net->net_rtr_pref_nids))
1563 list_for_each_entry(ne, &net->net_rtr_pref_nids, nl_list) {
1564 CDEBUG(D_NET, "Comparing pref %s with gw %s\n",
1565 libcfs_nidstr(&ne->nl_nid),
1566 libcfs_nidstr(rtr_nid));
1567 if (nid_same(rtr_nid, &ne->nl_nid))
1575 lnet_nid4_cpt_hash(lnet_nid_t nid, unsigned int number)
1578 __u64 pair_bits = 0x0001000100010001LLU;
1579 __u64 mask = pair_bits * 0xFF;
1582 /* Use (sum-by-multiplication of nid bytes) mod (number of CPTs)
1583 * to match nid to a CPT.
1585 pair_sum = (key & mask) + ((key >> 8) & mask);
1586 pair_sum = (pair_sum * pair_bits) >> 48;
1588 CDEBUG(D_NET, "Match nid %s to cpt %u\n",
1589 libcfs_nid2str(nid), (unsigned int)(pair_sum) % number);
1591 return (unsigned int)(pair_sum) % number;
1595 lnet_nid_cpt_hash(struct lnet_nid *nid, unsigned int number)
1601 LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
1606 if (nid_is_nid4(nid))
1607 return lnet_nid4_cpt_hash(lnet_nid_to_nid4(nid), number);
1609 for (i = 0; i < 4; i++)
1610 h = hash_32(nid->nid_addr[i]^h, 32);
1611 val = hash_32(LNET_NID_NET(nid) ^ h, LNET_CPT_BITS);
1614 return (unsigned int)(h + val + (val >> 1)) % number;
1618 lnet_cpt_of_nid_locked(struct lnet_nid *nid, struct lnet_ni *ni)
1620 struct lnet_net *net;
1622 /* must called with hold of lnet_net_lock */
1623 if (LNET_CPT_NUMBER == 1)
1624 return 0; /* the only one */
1627 * If NI is provided then use the CPT identified in the NI cpt
1628 * list if one exists. If one doesn't exist, then that NI is
1629 * associated with all CPTs and it follows that the net it belongs
1630 * to is implicitly associated with all CPTs, so just hash the nid
1634 if (ni->ni_cpts != NULL)
1635 return ni->ni_cpts[lnet_nid_cpt_hash(nid,
1638 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1641 /* no NI provided so look at the net */
1642 net = lnet_get_net_locked(LNET_NID_NET(nid));
1644 if (net != NULL && net->net_cpts != NULL) {
1645 return net->net_cpts[lnet_nid_cpt_hash(nid, net->net_ncpts)];
1648 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1652 lnet_nid2cpt(struct lnet_nid *nid, struct lnet_ni *ni)
1657 if (LNET_CPT_NUMBER == 1)
1658 return 0; /* the only one */
1660 cpt = lnet_net_lock_current();
1662 cpt2 = lnet_cpt_of_nid_locked(nid, ni);
1664 lnet_net_unlock(cpt);
1668 EXPORT_SYMBOL(lnet_nid2cpt);
1671 lnet_cpt_of_nid(lnet_nid_t nid4, struct lnet_ni *ni)
1673 struct lnet_nid nid;
1675 if (LNET_CPT_NUMBER == 1)
1676 return 0; /* the only one */
1678 lnet_nid4_to_nid(nid4, &nid);
1679 return lnet_nid2cpt(&nid, ni);
1681 EXPORT_SYMBOL(lnet_cpt_of_nid);
1684 lnet_islocalnet_locked(__u32 net_id)
1686 struct lnet_net *net;
1689 net = lnet_get_net_locked(net_id);
1691 local = net != NULL;
1697 lnet_islocalnet(__u32 net_id)
1702 cpt = lnet_net_lock_current();
1704 local = lnet_islocalnet_locked(net_id);
1706 lnet_net_unlock(cpt);
1712 lnet_nid_to_ni_locked(struct lnet_nid *nid, int cpt)
1714 struct lnet_net *net;
1717 LASSERT(cpt != LNET_LOCK_EX);
1719 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1720 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1721 if (nid_same(&ni->ni_nid, nid))
1730 lnet_nid2ni_locked(lnet_nid_t nid4, int cpt)
1732 struct lnet_nid nid;
1734 lnet_nid4_to_nid(nid4, &nid);
1735 return lnet_nid_to_ni_locked(&nid, cpt);
1739 lnet_nid2ni_addref(lnet_nid_t nid4)
1742 struct lnet_nid nid;
1744 lnet_nid4_to_nid(nid4, &nid);
1747 ni = lnet_nid_to_ni_locked(&nid, 0);
1749 lnet_ni_addref_locked(ni, 0);
1754 EXPORT_SYMBOL(lnet_nid2ni_addref);
1757 lnet_nid_to_ni_addref(struct lnet_nid *nid)
1762 ni = lnet_nid_to_ni_locked(nid, 0);
1764 lnet_ni_addref_locked(ni, 0);
1769 EXPORT_SYMBOL(lnet_nid_to_ni_addref);
1772 lnet_islocalnid(struct lnet_nid *nid)
1777 cpt = lnet_net_lock_current();
1778 ni = lnet_nid_to_ni_locked(nid, cpt);
1779 lnet_net_unlock(cpt);
1785 lnet_count_acceptor_nets(void)
1787 /* Return the # of NIs that need the acceptor. */
1789 struct lnet_net *net;
1792 cpt = lnet_net_lock_current();
1793 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1794 /* all socklnd type networks should have the acceptor
1796 if (net->net_lnd->lnd_accept != NULL)
1800 lnet_net_unlock(cpt);
1805 struct lnet_ping_buffer *
1806 lnet_ping_buffer_alloc(int nnis, gfp_t gfp)
1808 struct lnet_ping_buffer *pbuf;
1810 LIBCFS_ALLOC_GFP(pbuf, LNET_PING_BUFFER_SIZE(nnis), gfp);
1812 pbuf->pb_nnis = nnis;
1813 pbuf->pb_needs_post = false;
1814 atomic_set(&pbuf->pb_refcnt, 1);
1821 lnet_ping_buffer_free(struct lnet_ping_buffer *pbuf)
1823 LASSERT(atomic_read(&pbuf->pb_refcnt) == 0);
1824 LIBCFS_FREE(pbuf, LNET_PING_BUFFER_SIZE(pbuf->pb_nnis));
1827 static struct lnet_ping_buffer *
1828 lnet_ping_target_create(int nnis)
1830 struct lnet_ping_buffer *pbuf;
1832 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
1834 CERROR("Can't allocate ping source [%d]\n", nnis);
1838 pbuf->pb_info.pi_nnis = nnis;
1839 pbuf->pb_info.pi_pid = the_lnet.ln_pid;
1840 pbuf->pb_info.pi_magic = LNET_PROTO_PING_MAGIC;
1841 pbuf->pb_info.pi_features =
1842 LNET_PING_FEAT_NI_STATUS | LNET_PING_FEAT_MULTI_RAIL;
1848 lnet_get_net_ni_count_locked(struct lnet_net *net)
1853 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1860 lnet_get_net_ni_count_pre(struct lnet_net *net)
1865 list_for_each_entry(ni, &net->net_ni_added, ni_netlist)
1872 lnet_get_ni_count(void)
1875 struct lnet_net *net;
1880 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1881 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1891 lnet_swap_pinginfo(struct lnet_ping_buffer *pbuf)
1893 struct lnet_ni_status *stat;
1897 __swab32s(&pbuf->pb_info.pi_magic);
1898 __swab32s(&pbuf->pb_info.pi_features);
1899 __swab32s(&pbuf->pb_info.pi_pid);
1900 __swab32s(&pbuf->pb_info.pi_nnis);
1901 nnis = pbuf->pb_info.pi_nnis;
1902 if (nnis > pbuf->pb_nnis)
1903 nnis = pbuf->pb_nnis;
1904 for (i = 0; i < nnis; i++) {
1905 stat = &pbuf->pb_info.pi_ni[i];
1906 __swab64s(&stat->ns_nid);
1907 __swab32s(&stat->ns_status);
1912 lnet_ping_info_validate(struct lnet_ping_info *pinfo)
1916 if (pinfo->pi_magic != LNET_PROTO_PING_MAGIC)
1918 if (!(pinfo->pi_features & LNET_PING_FEAT_NI_STATUS))
1920 /* Loopback is guaranteed to be present */
1921 if (pinfo->pi_nnis < 1 || pinfo->pi_nnis > lnet_interfaces_max)
1923 if (LNET_PING_INFO_LONI(pinfo) != LNET_NID_LO_0)
1929 lnet_ping_target_destroy(void)
1931 struct lnet_net *net;
1934 lnet_net_lock(LNET_LOCK_EX);
1936 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1937 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1939 ni->ni_status = NULL;
1944 lnet_ping_buffer_decref(the_lnet.ln_ping_target);
1945 the_lnet.ln_ping_target = NULL;
1947 lnet_net_unlock(LNET_LOCK_EX);
1951 lnet_ping_target_event_handler(struct lnet_event *event)
1953 struct lnet_ping_buffer *pbuf = event->md_user_ptr;
1955 if (event->unlinked)
1956 lnet_ping_buffer_decref(pbuf);
1960 lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
1961 struct lnet_handle_md *ping_mdh,
1962 int ni_count, bool set_eq)
1964 struct lnet_processid id = {
1965 .nid = LNET_ANY_NID,
1969 struct lnet_md md = { NULL };
1973 the_lnet.ln_ping_target_handler =
1974 lnet_ping_target_event_handler;
1976 *ppbuf = lnet_ping_target_create(ni_count);
1977 if (*ppbuf == NULL) {
1982 /* Ping target ME/MD */
1983 me = LNetMEAttach(LNET_RESERVED_PORTAL, &id,
1984 LNET_PROTO_PING_MATCHBITS, 0,
1985 LNET_UNLINK, LNET_INS_AFTER);
1988 CERROR("Can't create ping target ME: %d\n", rc);
1989 goto fail_decref_ping_buffer;
1992 /* initialize md content */
1993 md.start = &(*ppbuf)->pb_info;
1994 md.length = LNET_PING_INFO_SIZE((*ppbuf)->pb_nnis);
1995 md.threshold = LNET_MD_THRESH_INF;
1997 md.options = LNET_MD_OP_GET | LNET_MD_TRUNCATE |
1998 LNET_MD_MANAGE_REMOTE;
1999 md.handler = the_lnet.ln_ping_target_handler;
2000 md.user_ptr = *ppbuf;
2002 rc = LNetMDAttach(me, &md, LNET_RETAIN, ping_mdh);
2004 CERROR("Can't attach ping target MD: %d\n", rc);
2005 goto fail_decref_ping_buffer;
2007 lnet_ping_buffer_addref(*ppbuf);
2011 fail_decref_ping_buffer:
2012 LASSERT(atomic_read(&(*ppbuf)->pb_refcnt) == 1);
2013 lnet_ping_buffer_decref(*ppbuf);
2020 lnet_ping_md_unlink(struct lnet_ping_buffer *pbuf,
2021 struct lnet_handle_md *ping_mdh)
2023 LNetMDUnlink(*ping_mdh);
2024 LNetInvalidateMDHandle(ping_mdh);
2026 /* NB the MD could be busy; this just starts the unlink */
2027 wait_var_event_warning(&pbuf->pb_refcnt,
2028 atomic_read(&pbuf->pb_refcnt) <= 1,
2029 "Still waiting for ping data MD to unlink\n");
2033 lnet_ping_target_install_locked(struct lnet_ping_buffer *pbuf)
2036 struct lnet_net *net;
2037 struct lnet_ni_status *ns;
2042 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
2043 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
2044 LASSERT(i < pbuf->pb_nnis);
2046 ns = &pbuf->pb_info.pi_ni[i];
2048 if (!nid_is_nid4(&ni->ni_nid))
2050 ns->ns_nid = lnet_nid_to_nid4(&ni->ni_nid);
2053 ns->ns_status = lnet_ni_get_status_locked(ni);
2061 * We (ab)use the ns_status of the loopback interface to
2062 * transmit the sequence number. The first interface listed
2063 * must be the loopback interface.
2065 rc = lnet_ping_info_validate(&pbuf->pb_info);
2067 LCONSOLE_EMERG("Invalid ping target: %d\n", rc);
2070 LNET_PING_BUFFER_SEQNO(pbuf) =
2071 atomic_inc_return(&the_lnet.ln_ping_target_seqno);
2075 lnet_ping_target_update(struct lnet_ping_buffer *pbuf,
2076 struct lnet_handle_md ping_mdh)
2078 struct lnet_ping_buffer *old_pbuf = NULL;
2079 struct lnet_handle_md old_ping_md;
2081 /* switch the NIs to point to the new ping info created */
2082 lnet_net_lock(LNET_LOCK_EX);
2084 if (!the_lnet.ln_routing)
2085 pbuf->pb_info.pi_features |= LNET_PING_FEAT_RTE_DISABLED;
2086 if (!lnet_peer_discovery_disabled)
2087 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
2089 /* Ensure only known feature bits have been set. */
2090 LASSERT(pbuf->pb_info.pi_features & LNET_PING_FEAT_BITS);
2091 LASSERT(!(pbuf->pb_info.pi_features & ~LNET_PING_FEAT_BITS));
2093 lnet_ping_target_install_locked(pbuf);
2095 if (the_lnet.ln_ping_target) {
2096 old_pbuf = the_lnet.ln_ping_target;
2097 old_ping_md = the_lnet.ln_ping_target_md;
2099 the_lnet.ln_ping_target_md = ping_mdh;
2100 the_lnet.ln_ping_target = pbuf;
2102 lnet_net_unlock(LNET_LOCK_EX);
2105 /* unlink and free the old ping info */
2106 lnet_ping_md_unlink(old_pbuf, &old_ping_md);
2107 lnet_ping_buffer_decref(old_pbuf);
2110 lnet_push_update_to_peers(0);
2114 lnet_ping_target_fini(void)
2116 lnet_ping_md_unlink(the_lnet.ln_ping_target,
2117 &the_lnet.ln_ping_target_md);
2119 lnet_assert_handler_unused(the_lnet.ln_ping_target_handler);
2120 lnet_ping_target_destroy();
2123 /* Resize the push target. */
2124 int lnet_push_target_resize(void)
2126 struct lnet_handle_md mdh;
2127 struct lnet_handle_md old_mdh;
2128 struct lnet_ping_buffer *pbuf;
2129 struct lnet_ping_buffer *old_pbuf;
2134 nnis = the_lnet.ln_push_target_nnis;
2136 CDEBUG(D_NET, "Invalid nnis %d\n", nnis);
2140 /* NB: lnet_ping_buffer_alloc() sets pbuf refcount to 1. That ref is
2141 * dropped when we need to resize again (see "old_pbuf" below) or when
2142 * LNet is shutdown (see lnet_push_target_fini())
2144 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
2146 CDEBUG(D_NET, "Can't allocate pbuf for nnis %d\n", nnis);
2150 rc = lnet_push_target_post(pbuf, &mdh);
2152 CDEBUG(D_NET, "Failed to post push target: %d\n", rc);
2153 lnet_ping_buffer_decref(pbuf);
2157 lnet_net_lock(LNET_LOCK_EX);
2158 old_pbuf = the_lnet.ln_push_target;
2159 old_mdh = the_lnet.ln_push_target_md;
2160 the_lnet.ln_push_target = pbuf;
2161 the_lnet.ln_push_target_md = mdh;
2162 lnet_net_unlock(LNET_LOCK_EX);
2165 LNetMDUnlink(old_mdh);
2166 /* Drop ref set by lnet_ping_buffer_alloc() */
2167 lnet_ping_buffer_decref(old_pbuf);
2170 /* Received another push or reply that requires a larger buffer */
2171 if (nnis < the_lnet.ln_push_target_nnis)
2174 CDEBUG(D_NET, "nnis %d success\n", nnis);
2178 int lnet_push_target_post(struct lnet_ping_buffer *pbuf,
2179 struct lnet_handle_md *mdhp)
2181 struct lnet_processid id = { LNET_ANY_NID, LNET_PID_ANY };
2182 struct lnet_md md = { NULL };
2186 me = LNetMEAttach(LNET_RESERVED_PORTAL, &id,
2187 LNET_PROTO_PING_MATCHBITS, 0,
2188 LNET_UNLINK, LNET_INS_AFTER);
2191 CERROR("Can't create push target ME: %d\n", rc);
2195 pbuf->pb_needs_post = false;
2197 /* This reference is dropped by lnet_push_target_event_handler() */
2198 lnet_ping_buffer_addref(pbuf);
2200 /* initialize md content */
2201 md.start = &pbuf->pb_info;
2202 md.length = LNET_PING_INFO_SIZE(pbuf->pb_nnis);
2205 md.options = LNET_MD_OP_PUT | LNET_MD_TRUNCATE;
2207 md.handler = the_lnet.ln_push_target_handler;
2209 rc = LNetMDAttach(me, &md, LNET_UNLINK, mdhp);
2211 CERROR("Can't attach push MD: %d\n", rc);
2212 lnet_ping_buffer_decref(pbuf);
2213 pbuf->pb_needs_post = true;
2217 CDEBUG(D_NET, "posted push target %p\n", pbuf);
2222 static void lnet_push_target_event_handler(struct lnet_event *ev)
2224 struct lnet_ping_buffer *pbuf = ev->md_user_ptr;
2226 CDEBUG(D_NET, "type %d status %d unlinked %d\n", ev->type, ev->status,
2229 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
2230 lnet_swap_pinginfo(pbuf);
2232 if (ev->type == LNET_EVENT_UNLINK) {
2233 /* Drop ref added by lnet_push_target_post() */
2234 lnet_ping_buffer_decref(pbuf);
2238 lnet_peer_push_event(ev);
2240 /* Drop ref added by lnet_push_target_post */
2241 lnet_ping_buffer_decref(pbuf);
2244 /* Initialize the push target. */
2245 static int lnet_push_target_init(void)
2249 if (the_lnet.ln_push_target)
2252 the_lnet.ln_push_target_handler =
2253 lnet_push_target_event_handler;
2255 rc = LNetSetLazyPortal(LNET_RESERVED_PORTAL);
2258 /* Start at the required minimum, we'll enlarge if required. */
2259 the_lnet.ln_push_target_nnis = LNET_INTERFACES_MIN;
2261 rc = lnet_push_target_resize();
2264 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2265 the_lnet.ln_push_target_handler = NULL;
2271 /* Clean up the push target. */
2272 static void lnet_push_target_fini(void)
2274 if (!the_lnet.ln_push_target)
2277 /* Unlink and invalidate to prevent new references. */
2278 LNetMDUnlink(the_lnet.ln_push_target_md);
2279 LNetInvalidateMDHandle(&the_lnet.ln_push_target_md);
2281 /* Wait for the unlink to complete. */
2282 wait_var_event_warning(&the_lnet.ln_push_target->pb_refcnt,
2283 atomic_read(&the_lnet.ln_push_target->pb_refcnt) <= 1,
2284 "Still waiting for ping data MD to unlink\n");
2286 /* Drop ref set by lnet_ping_buffer_alloc() */
2287 lnet_ping_buffer_decref(the_lnet.ln_push_target);
2288 the_lnet.ln_push_target = NULL;
2289 the_lnet.ln_push_target_nnis = 0;
2291 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2292 lnet_assert_handler_unused(the_lnet.ln_push_target_handler);
2293 the_lnet.ln_push_target_handler = NULL;
2297 lnet_ni_tq_credits(struct lnet_ni *ni)
2301 LASSERT(ni->ni_ncpts >= 1);
2303 if (ni->ni_ncpts == 1)
2304 return ni->ni_net->net_tunables.lct_max_tx_credits;
2306 credits = ni->ni_net->net_tunables.lct_max_tx_credits / ni->ni_ncpts;
2307 credits = max(credits, 8 * ni->ni_net->net_tunables.lct_peer_tx_credits);
2308 credits = min(credits, ni->ni_net->net_tunables.lct_max_tx_credits);
2314 lnet_ni_unlink_locked(struct lnet_ni *ni)
2316 /* move it to zombie list and nobody can find it anymore */
2317 LASSERT(!list_empty(&ni->ni_netlist));
2318 list_move(&ni->ni_netlist, &ni->ni_net->net_ni_zombie);
2319 lnet_ni_decref_locked(ni, 0);
2323 lnet_clear_zombies_nis_locked(struct lnet_net *net)
2328 struct list_head *zombie_list = &net->net_ni_zombie;
2331 * Now wait for the NIs I just nuked to show up on the zombie
2332 * list and shut them down in guaranteed thread context
2335 while (!list_empty(zombie_list)) {
2339 ni = list_entry(zombie_list->next,
2340 struct lnet_ni, ni_netlist);
2341 list_del_init(&ni->ni_netlist);
2342 /* the ni should be in deleting state. If it's not it's
2344 LASSERT(ni->ni_state == LNET_NI_STATE_DELETING);
2345 cfs_percpt_for_each(ref, j, ni->ni_refs) {
2348 /* still busy, add it back to zombie list */
2349 list_add(&ni->ni_netlist, zombie_list);
2353 if (!list_empty(&ni->ni_netlist)) {
2354 /* Unlock mutex while waiting to allow other
2355 * threads to read the LNet state and fall through
2358 lnet_net_unlock(LNET_LOCK_EX);
2359 mutex_unlock(&the_lnet.ln_api_mutex);
2362 if ((i & (-i)) == i) {
2364 "Waiting for zombie LNI %s\n",
2365 libcfs_nidstr(&ni->ni_nid));
2367 schedule_timeout_uninterruptible(cfs_time_seconds(1));
2369 mutex_lock(&the_lnet.ln_api_mutex);
2370 lnet_net_lock(LNET_LOCK_EX);
2374 lnet_net_unlock(LNET_LOCK_EX);
2376 islo = ni->ni_net->net_lnd->lnd_type == LOLND;
2378 LASSERT(!in_interrupt());
2379 /* Holding the LND mutex makes it safe for lnd_shutdown
2380 * to call module_put(). Module unload cannot finish
2381 * until lnet_unregister_lnd() completes, and that
2382 * requires the LND mutex.
2384 mutex_unlock(&the_lnet.ln_api_mutex);
2385 mutex_lock(&the_lnet.ln_lnd_mutex);
2386 (net->net_lnd->lnd_shutdown)(ni);
2387 mutex_unlock(&the_lnet.ln_lnd_mutex);
2388 mutex_lock(&the_lnet.ln_api_mutex);
2391 CDEBUG(D_LNI, "Removed LNI %s\n",
2392 libcfs_nidstr(&ni->ni_nid));
2396 lnet_net_lock(LNET_LOCK_EX);
2400 /* shutdown down the NI and release refcount */
2402 lnet_shutdown_lndni(struct lnet_ni *ni)
2405 struct lnet_net *net = ni->ni_net;
2407 lnet_net_lock(LNET_LOCK_EX);
2409 ni->ni_state = LNET_NI_STATE_DELETING;
2411 lnet_ni_unlink_locked(ni);
2412 lnet_incr_dlc_seq();
2413 lnet_net_unlock(LNET_LOCK_EX);
2415 /* clear messages for this NI on the lazy portal */
2416 for (i = 0; i < the_lnet.ln_nportals; i++)
2417 lnet_clear_lazy_portal(ni, i, "Shutting down NI");
2419 lnet_net_lock(LNET_LOCK_EX);
2420 lnet_clear_zombies_nis_locked(net);
2421 lnet_net_unlock(LNET_LOCK_EX);
2425 lnet_shutdown_lndnet(struct lnet_net *net)
2429 lnet_net_lock(LNET_LOCK_EX);
2431 list_del_init(&net->net_list);
2433 while (!list_empty(&net->net_ni_list)) {
2434 ni = list_entry(net->net_ni_list.next,
2435 struct lnet_ni, ni_netlist);
2436 lnet_net_unlock(LNET_LOCK_EX);
2437 lnet_shutdown_lndni(ni);
2438 lnet_net_lock(LNET_LOCK_EX);
2441 lnet_net_unlock(LNET_LOCK_EX);
2443 /* Do peer table cleanup for this net */
2444 lnet_peer_tables_cleanup(net);
2450 lnet_shutdown_lndnets(void)
2452 struct lnet_net *net;
2454 struct lnet_msg *msg, *tmp;
2456 /* NB called holding the global mutex */
2458 /* All quiet on the API front */
2459 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING ||
2460 the_lnet.ln_state == LNET_STATE_STOPPING);
2461 LASSERT(the_lnet.ln_refcount == 0);
2463 lnet_net_lock(LNET_LOCK_EX);
2464 the_lnet.ln_state = LNET_STATE_STOPPING;
2467 * move the nets to the zombie list to avoid them being
2468 * picked up for new work. LONET is also included in the
2469 * Nets that will be moved to the zombie list
2471 list_splice_init(&the_lnet.ln_nets, &the_lnet.ln_net_zombie);
2473 /* Drop the cached loopback Net. */
2474 if (the_lnet.ln_loni != NULL) {
2475 lnet_ni_decref_locked(the_lnet.ln_loni, 0);
2476 the_lnet.ln_loni = NULL;
2478 lnet_net_unlock(LNET_LOCK_EX);
2480 /* iterate through the net zombie list and delete each net */
2481 while (!list_empty(&the_lnet.ln_net_zombie)) {
2482 net = list_entry(the_lnet.ln_net_zombie.next,
2483 struct lnet_net, net_list);
2484 lnet_shutdown_lndnet(net);
2487 spin_lock(&the_lnet.ln_msg_resend_lock);
2488 list_splice(&the_lnet.ln_msg_resend, &resend);
2489 spin_unlock(&the_lnet.ln_msg_resend_lock);
2491 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
2492 list_del_init(&msg->msg_list);
2493 msg->msg_no_resend = true;
2494 lnet_finalize(msg, -ECANCELED);
2497 lnet_net_lock(LNET_LOCK_EX);
2498 the_lnet.ln_state = LNET_STATE_SHUTDOWN;
2499 lnet_net_unlock(LNET_LOCK_EX);
2503 lnet_startup_lndni(struct lnet_ni *ni, struct lnet_lnd_tunables *tun)
2506 struct lnet_tx_queue *tq;
2508 struct lnet_net *net = ni->ni_net;
2510 mutex_lock(&the_lnet.ln_lnd_mutex);
2513 memcpy(&ni->ni_lnd_tunables, tun, sizeof(*tun));
2514 ni->ni_lnd_tunables_set = true;
2517 rc = (net->net_lnd->lnd_startup)(ni);
2519 mutex_unlock(&the_lnet.ln_lnd_mutex);
2522 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s\n",
2523 rc, libcfs_lnd2str(net->net_lnd->lnd_type));
2528 ni->ni_state = LNET_NI_STATE_ACTIVE;
2531 /* We keep a reference on the loopback net through the loopback NI */
2532 if (net->net_lnd->lnd_type == LOLND) {
2534 LASSERT(the_lnet.ln_loni == NULL);
2535 the_lnet.ln_loni = ni;
2536 ni->ni_net->net_tunables.lct_peer_tx_credits = 0;
2537 ni->ni_net->net_tunables.lct_peer_rtr_credits = 0;
2538 ni->ni_net->net_tunables.lct_max_tx_credits = 0;
2539 ni->ni_net->net_tunables.lct_peer_timeout = 0;
2543 if (ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ||
2544 ni->ni_net->net_tunables.lct_max_tx_credits == 0) {
2545 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
2546 libcfs_lnd2str(net->net_lnd->lnd_type),
2547 ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ?
2549 /* shutdown the NI since if we get here then it must've already
2552 lnet_shutdown_lndni(ni);
2556 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
2557 tq->tq_credits_min =
2558 tq->tq_credits_max =
2559 tq->tq_credits = lnet_ni_tq_credits(ni);
2562 atomic_set(&ni->ni_tx_credits,
2563 lnet_ni_tq_credits(ni) * ni->ni_ncpts);
2564 atomic_set(&ni->ni_healthv, LNET_MAX_HEALTH_VALUE);
2566 /* Nodes with small feet have little entropy. The NID for this
2567 * node gives the most entropy in the low bits.
2569 add_device_randomness(&ni->ni_nid, sizeof(ni->ni_nid));
2571 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d/%d]\n",
2572 libcfs_nidstr(&ni->ni_nid),
2573 ni->ni_net->net_tunables.lct_peer_tx_credits,
2574 lnet_ni_tq_credits(ni) * LNET_CPT_NUMBER,
2575 ni->ni_net->net_tunables.lct_peer_rtr_credits,
2576 ni->ni_net->net_tunables.lct_peer_timeout);
2585 lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
2588 struct lnet_net *net_l = NULL;
2589 LIST_HEAD(local_ni_list);
2593 const struct lnet_lnd *lnd;
2595 net->net_tunables.lct_peer_timeout;
2597 net->net_tunables.lct_max_tx_credits;
2598 int peerrtrcredits =
2599 net->net_tunables.lct_peer_rtr_credits;
2602 * make sure that this net is unique. If it isn't then
2603 * we are adding interfaces to an already existing network, and
2604 * 'net' is just a convenient way to pass in the list.
2605 * if it is unique we need to find the LND and load it if
2608 if (lnet_net_unique(net->net_id, &the_lnet.ln_nets, &net_l)) {
2609 lnd_type = LNET_NETTYP(net->net_id);
2611 mutex_lock(&the_lnet.ln_lnd_mutex);
2612 lnd = lnet_find_lnd_by_type(lnd_type);
2615 mutex_unlock(&the_lnet.ln_lnd_mutex);
2616 rc = request_module("%s", libcfs_lnd2modname(lnd_type));
2617 mutex_lock(&the_lnet.ln_lnd_mutex);
2619 lnd = lnet_find_lnd_by_type(lnd_type);
2621 mutex_unlock(&the_lnet.ln_lnd_mutex);
2622 CERROR("Can't load LND %s, module %s, rc=%d\n",
2623 libcfs_lnd2str(lnd_type),
2624 libcfs_lnd2modname(lnd_type), rc);
2625 #ifndef HAVE_MODULE_LOADING_SUPPORT
2626 LCONSOLE_ERROR_MSG(0x104, "Your kernel must be "
2627 "compiled with kernel module "
2628 "loading support.");
2637 mutex_unlock(&the_lnet.ln_lnd_mutex);
2643 * net_l: if the network being added is unique then net_l
2644 * will point to that network
2645 * if the network being added is not unique then
2646 * net_l points to the existing network.
2648 * When we enter the loop below, we'll pick NIs off he
2649 * network beign added and start them up, then add them to
2650 * a local ni list. Once we've successfully started all
2651 * the NIs then we join the local NI list (of started up
2652 * networks) with the net_l->net_ni_list, which should
2653 * point to the correct network to add the new ni list to
2655 * If any of the new NIs fail to start up, then we want to
2656 * iterate through the local ni list, which should include
2657 * any NIs which were successfully started up, and shut
2660 * After than we want to delete the network being added,
2661 * to avoid a memory leak.
2663 while (!list_empty(&net->net_ni_added)) {
2664 ni = list_entry(net->net_ni_added.next, struct lnet_ni,
2666 list_del_init(&ni->ni_netlist);
2668 /* make sure that the the NI we're about to start
2669 * up is actually unique. if it's not fail. */
2670 if (!lnet_ni_unique_net(&net_l->net_ni_list,
2671 ni->ni_interface)) {
2676 /* adjust the pointer the parent network, just in case it
2677 * the net is a duplicate */
2680 rc = lnet_startup_lndni(ni, tun);
2686 list_add_tail(&ni->ni_netlist, &local_ni_list);
2691 lnet_net_lock(LNET_LOCK_EX);
2692 list_splice_tail(&local_ni_list, &net_l->net_ni_list);
2693 lnet_incr_dlc_seq();
2694 lnet_net_unlock(LNET_LOCK_EX);
2696 /* if the network is not unique then we don't want to keep
2697 * it around after we're done. Free it. Otherwise add that
2698 * net to the global the_lnet.ln_nets */
2699 if (net_l != net && net_l != NULL) {
2701 * TODO - note. currently the tunables can not be updated
2707 * restore tunables after it has been overwitten by the
2710 if (peer_timeout != -1)
2711 net->net_tunables.lct_peer_timeout = peer_timeout;
2712 if (maxtxcredits != -1)
2713 net->net_tunables.lct_max_tx_credits = maxtxcredits;
2714 if (peerrtrcredits != -1)
2715 net->net_tunables.lct_peer_rtr_credits = peerrtrcredits;
2717 lnet_net_lock(LNET_LOCK_EX);
2718 list_add_tail(&net->net_list, &the_lnet.ln_nets);
2719 lnet_net_unlock(LNET_LOCK_EX);
2726 * shutdown the new NIs that are being started up
2727 * free the NET being started
2729 while (!list_empty(&local_ni_list)) {
2730 ni = list_entry(local_ni_list.next, struct lnet_ni,
2733 lnet_shutdown_lndni(ni);
2743 lnet_startup_lndnets(struct list_head *netlist)
2745 struct lnet_net *net;
2750 * Change to running state before bringing up the LNDs. This
2751 * allows lnet_shutdown_lndnets() to assert that we've passed
2754 lnet_net_lock(LNET_LOCK_EX);
2755 the_lnet.ln_state = LNET_STATE_RUNNING;
2756 lnet_net_unlock(LNET_LOCK_EX);
2758 while (!list_empty(netlist)) {
2759 net = list_entry(netlist->next, struct lnet_net, net_list);
2760 list_del_init(&net->net_list);
2762 rc = lnet_startup_lndnet(net, NULL);
2772 lnet_shutdown_lndnets();
2777 static int lnet_genl_parse_list(struct sk_buff *msg,
2778 const struct ln_key_list *data[], u16 idx)
2780 const struct ln_key_list *list = data[idx];
2781 const struct ln_key_props *props;
2782 struct nlattr *node;
2788 if (!list->lkl_maxattr)
2791 props = list->lkl_list;
2795 node = nla_nest_start(msg, LN_SCALAR_ATTR_LIST);
2799 for (count = 1; count <= list->lkl_maxattr; count++) {
2800 struct nlattr *key = nla_nest_start(msg, count);
2803 nla_put_u16(msg, LN_SCALAR_ATTR_LIST_SIZE,
2806 nla_put_u16(msg, LN_SCALAR_ATTR_INDEX, count);
2807 if (props[count].lkp_value)
2808 nla_put_string(msg, LN_SCALAR_ATTR_VALUE,
2809 props[count].lkp_value);
2810 if (props[count].lkp_key_format)
2811 nla_put_u16(msg, LN_SCALAR_ATTR_KEY_FORMAT,
2812 props[count].lkp_key_format);
2813 nla_put_u16(msg, LN_SCALAR_ATTR_NLA_TYPE,
2814 props[count].lkp_data_type);
2815 if (props[count].lkp_data_type == NLA_NESTED) {
2818 rc = lnet_genl_parse_list(msg, data, ++idx);
2824 nla_nest_end(msg, key);
2827 nla_nest_end(msg, node);
2831 int lnet_genl_send_scalar_list(struct sk_buff *msg, u32 portid, u32 seq,
2832 const struct genl_family *family, int flags,
2833 u8 cmd, const struct ln_key_list *data[])
2841 hdr = genlmsg_put(msg, portid, seq, family, flags, cmd);
2843 GOTO(canceled, rc = -EMSGSIZE);
2845 rc = lnet_genl_parse_list(msg, data, 0);
2849 genlmsg_end(msg, hdr);
2852 genlmsg_cancel(msg, hdr);
2853 return rc > 0 ? 0 : rc;
2855 EXPORT_SYMBOL(lnet_genl_send_scalar_list);
2858 * Initialize LNet library.
2860 * Automatically called at module loading time. Caller has to call
2861 * lnet_lib_exit() after a call to lnet_lib_init(), if and only if the
2862 * latter returned 0. It must be called exactly once.
2864 * \retval 0 on success
2865 * \retval -ve on failures.
2867 int lnet_lib_init(void)
2871 lnet_assert_wire_constants();
2873 /* refer to global cfs_cpt_table for now */
2874 the_lnet.ln_cpt_table = cfs_cpt_tab;
2875 the_lnet.ln_cpt_number = cfs_cpt_number(cfs_cpt_tab);
2877 LASSERT(the_lnet.ln_cpt_number > 0);
2878 if (the_lnet.ln_cpt_number > LNET_CPT_MAX) {
2879 /* we are under risk of consuming all lh_cookie */
2880 CERROR("Can't have %d CPTs for LNet (max allowed is %d), "
2881 "please change setting of CPT-table and retry\n",
2882 the_lnet.ln_cpt_number, LNET_CPT_MAX);
2886 while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number)
2887 the_lnet.ln_cpt_bits++;
2889 rc = lnet_create_locks();
2891 CERROR("Can't create LNet global locks: %d\n", rc);
2895 the_lnet.ln_refcount = 0;
2896 INIT_LIST_HEAD(&the_lnet.ln_net_zombie);
2897 INIT_LIST_HEAD(&the_lnet.ln_msg_resend);
2899 /* The hash table size is the number of bits it takes to express the set
2900 * ln_num_routes, minus 1 (better to under estimate than over so we
2901 * don't waste memory). */
2902 if (rnet_htable_size <= 0)
2903 rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
2904 else if (rnet_htable_size > LNET_REMOTE_NETS_HASH_MAX)
2905 rnet_htable_size = LNET_REMOTE_NETS_HASH_MAX;
2906 the_lnet.ln_remote_nets_hbits = max_t(int, 1,
2907 order_base_2(rnet_htable_size) - 1);
2909 /* All LNDs apart from the LOLND are in separate modules. They
2910 * register themselves when their module loads, and unregister
2911 * themselves when their module is unloaded. */
2912 lnet_register_lnd(&the_lolnd);
2917 * Finalize LNet library.
2919 * \pre lnet_lib_init() called with success.
2920 * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls.
2922 * As this happens at module-unload, all lnds must already be unloaded,
2923 * so they must already be unregistered.
2925 void lnet_lib_exit(void)
2929 LASSERT(the_lnet.ln_refcount == 0);
2930 lnet_unregister_lnd(&the_lolnd);
2931 for (i = 0; i < NUM_LNDS; i++)
2932 LASSERT(!the_lnet.ln_lnds[i]);
2933 lnet_destroy_locks();
2937 * Set LNet PID and start LNet interfaces, routing, and forwarding.
2939 * Users must call this function at least once before any other functions.
2940 * For each successful call there must be a corresponding call to
2941 * LNetNIFini(). For subsequent calls to LNetNIInit(), \a requested_pid is
2944 * The PID used by LNet may be different from the one requested.
2947 * \param requested_pid PID requested by the caller.
2949 * \return >= 0 on success, and < 0 error code on failures.
2952 LNetNIInit(lnet_pid_t requested_pid)
2954 int im_a_router = 0;
2957 struct lnet_ping_buffer *pbuf;
2958 struct lnet_handle_md ping_mdh;
2959 LIST_HEAD(net_head);
2960 struct lnet_net *net;
2962 mutex_lock(&the_lnet.ln_api_mutex);
2964 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
2966 if (the_lnet.ln_state == LNET_STATE_STOPPING) {
2967 mutex_unlock(&the_lnet.ln_api_mutex);
2971 if (the_lnet.ln_refcount > 0) {
2972 rc = the_lnet.ln_refcount++;
2973 mutex_unlock(&the_lnet.ln_api_mutex);
2977 rc = lnet_prepare(requested_pid);
2979 mutex_unlock(&the_lnet.ln_api_mutex);
2983 /* create a network for Loopback network */
2984 net = lnet_net_alloc(LNET_MKNET(LOLND, 0), &net_head);
2987 goto err_empty_list;
2990 /* Add in the loopback NI */
2991 if (lnet_ni_alloc(net, NULL, NULL) == NULL) {
2993 goto err_empty_list;
2996 if (use_tcp_bonding)
2997 CWARN("use_tcp_bonding has been removed. Use Multi-Rail and Dynamic Discovery instead, see LU-13641\n");
2999 /* If LNet is being initialized via DLC it is possible
3000 * that the user requests not to load module parameters (ones which
3001 * are supported by DLC) on initialization. Therefore, make sure not
3002 * to load networks, routes and forwarding from module parameters
3003 * in this case. On cleanup in case of failure only clean up
3004 * routes if it has been loaded */
3005 if (!the_lnet.ln_nis_from_mod_params) {
3006 rc = lnet_parse_networks(&net_head, lnet_get_networks());
3008 goto err_empty_list;
3011 ni_count = lnet_startup_lndnets(&net_head);
3014 goto err_empty_list;
3017 if (!the_lnet.ln_nis_from_mod_params) {
3018 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
3020 goto err_shutdown_lndnis;
3022 rc = lnet_rtrpools_alloc(im_a_router);
3024 goto err_destroy_routes;
3027 rc = lnet_acceptor_start();
3029 goto err_destroy_routes;
3031 the_lnet.ln_refcount = 1;
3032 /* Now I may use my own API functions... */
3034 rc = lnet_ping_target_setup(&pbuf, &ping_mdh, ni_count, true);
3036 goto err_acceptor_stop;
3038 lnet_ping_target_update(pbuf, ping_mdh);
3040 the_lnet.ln_mt_handler = lnet_mt_event_handler;
3042 rc = lnet_push_target_init();
3046 rc = lnet_peer_discovery_start();
3048 goto err_destroy_push_target;
3050 rc = lnet_monitor_thr_start();
3052 goto err_stop_discovery_thr;
3055 lnet_router_debugfs_init();
3057 mutex_unlock(&the_lnet.ln_api_mutex);
3059 complete_all(&the_lnet.ln_started);
3061 /* wait for all routers to start */
3062 lnet_wait_router_start();
3066 err_stop_discovery_thr:
3067 lnet_peer_discovery_stop();
3068 err_destroy_push_target:
3069 lnet_push_target_fini();
3071 lnet_ping_target_fini();
3073 the_lnet.ln_refcount = 0;
3074 lnet_acceptor_stop();
3076 if (!the_lnet.ln_nis_from_mod_params)
3077 lnet_destroy_routes();
3078 err_shutdown_lndnis:
3079 lnet_shutdown_lndnets();
3083 mutex_unlock(&the_lnet.ln_api_mutex);
3084 while (!list_empty(&net_head)) {
3085 struct lnet_net *net;
3087 net = list_entry(net_head.next, struct lnet_net, net_list);
3088 list_del_init(&net->net_list);
3093 EXPORT_SYMBOL(LNetNIInit);
3096 * Stop LNet interfaces, routing, and forwarding.
3098 * Users must call this function once for each successful call to LNetNIInit().
3099 * Once the LNetNIFini() operation has been started, the results of pending
3100 * API operations are undefined.
3102 * \return always 0 for current implementation.
3107 mutex_lock(&the_lnet.ln_api_mutex);
3109 LASSERT(the_lnet.ln_refcount > 0);
3111 if (the_lnet.ln_refcount != 1) {
3112 the_lnet.ln_refcount--;
3114 LASSERT(!the_lnet.ln_niinit_self);
3116 lnet_net_lock(LNET_LOCK_EX);
3117 the_lnet.ln_state = LNET_STATE_STOPPING;
3118 lnet_net_unlock(LNET_LOCK_EX);
3122 lnet_router_debugfs_fini();
3123 lnet_monitor_thr_stop();
3124 lnet_peer_discovery_stop();
3125 lnet_push_target_fini();
3126 lnet_ping_target_fini();
3128 /* Teardown fns that use my own API functions BEFORE here */
3129 the_lnet.ln_refcount = 0;
3131 lnet_acceptor_stop();
3132 lnet_destroy_routes();
3133 lnet_shutdown_lndnets();
3137 mutex_unlock(&the_lnet.ln_api_mutex);
3140 EXPORT_SYMBOL(LNetNIFini);
3143 * Grabs the ni data from the ni structure and fills the out
3146 * \param[in] ni network interface structure
3147 * \param[out] cfg_ni NI config information
3148 * \param[out] tun network and LND tunables
3151 lnet_fill_ni_info(struct lnet_ni *ni, struct lnet_ioctl_config_ni *cfg_ni,
3152 struct lnet_ioctl_config_lnd_tunables *tun,
3153 struct lnet_ioctl_element_stats *stats,
3156 size_t min_size = 0;
3159 if (!ni || !cfg_ni || !tun || !nid_is_nid4(&ni->ni_nid))
3162 if (ni->ni_interface != NULL) {
3163 strncpy(cfg_ni->lic_ni_intf,
3165 sizeof(cfg_ni->lic_ni_intf));
3168 cfg_ni->lic_nid = lnet_nid_to_nid4(&ni->ni_nid);
3169 cfg_ni->lic_status = lnet_ni_get_status_locked(ni);
3170 cfg_ni->lic_dev_cpt = ni->ni_dev_cpt;
3172 memcpy(&tun->lt_cmn, &ni->ni_net->net_tunables, sizeof(tun->lt_cmn));
3175 stats->iel_send_count = lnet_sum_stats(&ni->ni_stats,
3176 LNET_STATS_TYPE_SEND);
3177 stats->iel_recv_count = lnet_sum_stats(&ni->ni_stats,
3178 LNET_STATS_TYPE_RECV);
3179 stats->iel_drop_count = lnet_sum_stats(&ni->ni_stats,
3180 LNET_STATS_TYPE_DROP);
3184 * tun->lt_tun will always be present, but in order to be
3185 * backwards compatible, we need to deal with the cases when
3186 * tun->lt_tun is smaller than what the kernel has, because it
3187 * comes from an older version of a userspace program, then we'll
3188 * need to copy as much information as we have available space.
3190 min_size = tun_size - sizeof(tun->lt_cmn);
3191 memcpy(&tun->lt_tun, &ni->ni_lnd_tunables, min_size);
3193 /* copy over the cpts */
3194 if (ni->ni_ncpts == LNET_CPT_NUMBER &&
3195 ni->ni_cpts == NULL) {
3196 for (i = 0; i < ni->ni_ncpts; i++)
3197 cfg_ni->lic_cpts[i] = i;
3200 ni->ni_cpts != NULL && i < ni->ni_ncpts &&
3201 i < LNET_MAX_SHOW_NUM_CPT;
3203 cfg_ni->lic_cpts[i] = ni->ni_cpts[i];
3205 cfg_ni->lic_ncpts = ni->ni_ncpts;
3209 * NOTE: This is a legacy function left in the code to be backwards
3210 * compatible with older userspace programs. It should eventually be
3213 * Grabs the ni data from the ni structure and fills the out
3216 * \param[in] ni network interface structure
3217 * \param[out] config config information
3220 lnet_fill_ni_info_legacy(struct lnet_ni *ni,
3221 struct lnet_ioctl_config_data *config)
3223 struct lnet_ioctl_net_config *net_config;
3224 struct lnet_ioctl_config_lnd_tunables *lnd_cfg = NULL;
3225 size_t min_size, tunable_size = 0;
3228 if (!ni || !config || !nid_is_nid4(&ni->ni_nid))
3231 net_config = (struct lnet_ioctl_net_config *) config->cfg_bulk;
3235 if (!ni->ni_interface)
3238 strncpy(net_config->ni_interface,
3240 sizeof(net_config->ni_interface));
3242 config->cfg_nid = lnet_nid_to_nid4(&ni->ni_nid);
3243 config->cfg_config_u.cfg_net.net_peer_timeout =
3244 ni->ni_net->net_tunables.lct_peer_timeout;
3245 config->cfg_config_u.cfg_net.net_max_tx_credits =
3246 ni->ni_net->net_tunables.lct_max_tx_credits;
3247 config->cfg_config_u.cfg_net.net_peer_tx_credits =
3248 ni->ni_net->net_tunables.lct_peer_tx_credits;
3249 config->cfg_config_u.cfg_net.net_peer_rtr_credits =
3250 ni->ni_net->net_tunables.lct_peer_rtr_credits;
3252 net_config->ni_status = lnet_ni_get_status_locked(ni);
3255 int num_cpts = min(ni->ni_ncpts, LNET_MAX_SHOW_NUM_CPT);
3257 for (i = 0; i < num_cpts; i++)
3258 net_config->ni_cpts[i] = ni->ni_cpts[i];
3260 config->cfg_ncpts = num_cpts;
3264 * See if user land tools sent in a newer and larger version
3265 * of struct lnet_tunables than what the kernel uses.
3267 min_size = sizeof(*config) + sizeof(*net_config);
3269 if (config->cfg_hdr.ioc_len > min_size)
3270 tunable_size = config->cfg_hdr.ioc_len - min_size;
3272 /* Don't copy too much data to user space */
3273 min_size = min(tunable_size, sizeof(ni->ni_lnd_tunables));
3274 lnd_cfg = (struct lnet_ioctl_config_lnd_tunables *)net_config->cfg_bulk;
3276 if (lnd_cfg && min_size) {
3277 memcpy(&lnd_cfg->lt_tun, &ni->ni_lnd_tunables, min_size);
3278 config->cfg_config_u.cfg_net.net_interface_count = 1;
3280 /* Tell user land that kernel side has less data */
3281 if (tunable_size > sizeof(ni->ni_lnd_tunables)) {
3282 min_size = tunable_size - sizeof(ni->ni_lnd_tunables);
3283 config->cfg_hdr.ioc_len -= min_size;
3289 lnet_get_ni_idx_locked(int idx)
3292 struct lnet_net *net;
3294 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3295 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3304 int lnet_get_net_healthv_locked(struct lnet_net *net)
3307 int best_healthv = 0;
3308 int healthv, ni_fatal;
3310 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3311 healthv = atomic_read(&ni->ni_healthv);
3312 ni_fatal = atomic_read(&ni->ni_fatal_error_on);
3313 if (!ni_fatal && healthv > best_healthv)
3314 best_healthv = healthv;
3317 return best_healthv;
3321 lnet_get_next_ni_locked(struct lnet_net *mynet, struct lnet_ni *prev)
3324 struct lnet_net *net = mynet;
3327 * It is possible that the net has been cleaned out while there is
3328 * a message being sent. This function accessed the net without
3329 * checking if the list is empty
3333 net = list_entry(the_lnet.ln_nets.next, struct lnet_net,
3335 if (list_empty(&net->net_ni_list))
3337 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
3343 if (prev->ni_netlist.next == &prev->ni_net->net_ni_list) {
3344 /* if you reached the end of the ni list and the net is
3345 * specified, then there are no more nis in that net */
3349 /* we reached the end of this net ni list. move to the
3351 if (prev->ni_net->net_list.next == &the_lnet.ln_nets)
3352 /* no more nets and no more NIs. */
3355 /* get the next net */
3356 net = list_entry(prev->ni_net->net_list.next, struct lnet_net,
3358 if (list_empty(&net->net_ni_list))
3360 /* get the ni on it */
3361 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
3367 if (list_empty(&prev->ni_netlist))
3370 /* there are more nis left */
3371 ni = list_entry(prev->ni_netlist.next, struct lnet_ni, ni_netlist);
3377 lnet_get_net_config(struct lnet_ioctl_config_data *config)
3382 int idx = config->cfg_count;
3384 cpt = lnet_net_lock_current();
3386 ni = lnet_get_ni_idx_locked(idx);
3391 lnet_fill_ni_info_legacy(ni, config);
3395 lnet_net_unlock(cpt);
3400 lnet_get_ni_config(struct lnet_ioctl_config_ni *cfg_ni,
3401 struct lnet_ioctl_config_lnd_tunables *tun,
3402 struct lnet_ioctl_element_stats *stats,
3409 if (!cfg_ni || !tun || !stats)
3412 cpt = lnet_net_lock_current();
3414 ni = lnet_get_ni_idx_locked(cfg_ni->lic_idx);
3419 lnet_fill_ni_info(ni, cfg_ni, tun, stats, tun_size);
3423 lnet_net_unlock(cpt);
3427 int lnet_get_ni_stats(struct lnet_ioctl_element_msg_stats *msg_stats)
3436 cpt = lnet_net_lock_current();
3438 ni = lnet_get_ni_idx_locked(msg_stats->im_idx);
3441 lnet_usr_translate_stats(msg_stats, &ni->ni_stats);
3445 lnet_net_unlock(cpt);
3450 static int lnet_add_net_common(struct lnet_net *net,
3451 struct lnet_ioctl_config_lnd_tunables *tun)
3453 struct lnet_handle_md ping_mdh;
3454 struct lnet_ping_buffer *pbuf;
3455 struct lnet_remotenet *rnet;
3461 lnet_net_lock(LNET_LOCK_EX);
3462 rnet = lnet_find_rnet_locked(net->net_id);
3463 lnet_net_unlock(LNET_LOCK_EX);
3465 * make sure that the net added doesn't invalidate the current
3466 * configuration LNet is keeping
3469 CERROR("Adding net %s will invalidate routing configuration\n",
3470 libcfs_net2str(net->net_id));
3476 * make sure you calculate the correct number of slots in the ping
3477 * buffer. Since the ping info is a flattened list of all the NIs,
3478 * we should allocate enough slots to accomodate the number of NIs
3479 * which will be added.
3481 * since ni hasn't been configured yet, use
3482 * lnet_get_net_ni_count_pre() which checks the net_ni_added list
3484 net_ni_count = lnet_get_net_ni_count_pre(net);
3486 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3487 net_ni_count + lnet_get_ni_count(),
3495 memcpy(&net->net_tunables,
3496 &tun->lt_cmn, sizeof(net->net_tunables));
3498 memset(&net->net_tunables, -1, sizeof(net->net_tunables));
3500 net_id = net->net_id;
3502 rc = lnet_startup_lndnet(net,
3503 (tun) ? &tun->lt_tun : NULL);
3507 lnet_net_lock(LNET_LOCK_EX);
3508 net = lnet_get_net_locked(net_id);
3511 /* apply the UDSPs */
3512 rc = lnet_udsp_apply_policies_on_net(net);
3514 CERROR("Failed to apply UDSPs on local net %s\n",
3515 libcfs_net2str(net->net_id));
3517 /* At this point we lost track of which NI was just added, so we
3518 * just re-apply the policies on all of the NIs on this net
3520 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3521 rc = lnet_udsp_apply_policies_on_ni(ni);
3523 CERROR("Failed to apply UDSPs on ni %s\n",
3524 libcfs_nidstr(&ni->ni_nid));
3526 lnet_net_unlock(LNET_LOCK_EX);
3529 * Start the acceptor thread if this is the first network
3530 * being added that requires the thread.
3532 if (net->net_lnd->lnd_accept) {
3533 rc = lnet_acceptor_start();
3535 /* shutdown the net that we just started */
3536 CERROR("Failed to start up acceptor thread\n");
3537 lnet_shutdown_lndnet(net);
3542 lnet_net_lock(LNET_LOCK_EX);
3543 lnet_peer_net_added(net);
3544 lnet_net_unlock(LNET_LOCK_EX);
3546 lnet_ping_target_update(pbuf, ping_mdh);
3551 lnet_ping_md_unlink(pbuf, &ping_mdh);
3552 lnet_ping_buffer_decref(pbuf);
3557 lnet_set_tune_defaults(struct lnet_ioctl_config_lnd_tunables *tun)
3560 if (!tun->lt_cmn.lct_peer_timeout)
3561 tun->lt_cmn.lct_peer_timeout = DEFAULT_PEER_TIMEOUT;
3562 if (!tun->lt_cmn.lct_peer_tx_credits)
3563 tun->lt_cmn.lct_peer_tx_credits = DEFAULT_PEER_CREDITS;
3564 if (!tun->lt_cmn.lct_max_tx_credits)
3565 tun->lt_cmn.lct_max_tx_credits = DEFAULT_CREDITS;
3569 static int lnet_handle_legacy_ip2nets(char *ip2nets,
3570 struct lnet_ioctl_config_lnd_tunables *tun)
3572 struct lnet_net *net;
3575 LIST_HEAD(net_head);
3577 rc = lnet_parse_ip2nets(&nets, ip2nets);
3581 rc = lnet_parse_networks(&net_head, nets);
3585 lnet_set_tune_defaults(tun);
3587 mutex_lock(&the_lnet.ln_api_mutex);
3588 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3592 while (!list_empty(&net_head)) {
3593 net = list_entry(net_head.next, struct lnet_net, net_list);
3594 list_del_init(&net->net_list);
3595 rc = lnet_add_net_common(net, tun);
3601 mutex_unlock(&the_lnet.ln_api_mutex);
3603 while (!list_empty(&net_head)) {
3604 net = list_entry(net_head.next, struct lnet_net, net_list);
3605 list_del_init(&net->net_list);
3611 int lnet_dyn_add_ni(struct lnet_ioctl_config_ni *conf)
3613 struct lnet_net *net;
3615 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
3617 __u32 net_id, lnd_type;
3619 /* get the tunables if they are available */
3620 if (conf->lic_cfg_hdr.ioc_len >=
3621 sizeof(*conf) + sizeof(*tun))
3622 tun = (struct lnet_ioctl_config_lnd_tunables *)
3625 /* handle legacy ip2nets from DLC */
3626 if (conf->lic_legacy_ip2nets[0] != '\0')
3627 return lnet_handle_legacy_ip2nets(conf->lic_legacy_ip2nets,
3630 net_id = LNET_NIDNET(conf->lic_nid);
3631 lnd_type = LNET_NETTYP(net_id);
3633 if (!libcfs_isknown_lnd(lnd_type)) {
3634 CERROR("No valid net and lnd information provided\n");
3638 net = lnet_net_alloc(net_id, NULL);
3642 for (i = 0; i < conf->lic_ncpts; i++) {
3643 if (conf->lic_cpts[i] >= LNET_CPT_NUMBER)
3647 ni = lnet_ni_alloc_w_cpt_array(net, conf->lic_cpts, conf->lic_ncpts,
3652 lnet_set_tune_defaults(tun);
3654 mutex_lock(&the_lnet.ln_api_mutex);
3655 if (the_lnet.ln_state != LNET_STATE_RUNNING)
3658 rc = lnet_add_net_common(net, tun);
3660 mutex_unlock(&the_lnet.ln_api_mutex);
3665 int lnet_dyn_del_ni(struct lnet_ioctl_config_ni *conf)
3667 struct lnet_net *net;
3669 __u32 net_id = LNET_NIDNET(conf->lic_nid);
3670 struct lnet_ping_buffer *pbuf;
3671 struct lnet_handle_md ping_mdh;
3676 /* don't allow userspace to shutdown the LOLND */
3677 if (LNET_NETTYP(net_id) == LOLND)
3680 mutex_lock(&the_lnet.ln_api_mutex);
3681 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3683 goto unlock_api_mutex;
3688 net = lnet_get_net_locked(net_id);
3690 CERROR("net %s not found\n",
3691 libcfs_net2str(net_id));
3696 addr = LNET_NIDADDR(conf->lic_nid);
3698 /* remove the entire net */
3699 net_count = lnet_get_net_ni_count_locked(net);
3703 /* create and link a new ping info, before removing the old one */
3704 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3705 lnet_get_ni_count() - net_count,
3708 goto unlock_api_mutex;
3710 lnet_shutdown_lndnet(net);
3712 lnet_acceptor_stop();
3714 lnet_ping_target_update(pbuf, ping_mdh);
3716 goto unlock_api_mutex;
3719 ni = lnet_nid2ni_locked(conf->lic_nid, 0);
3721 CERROR("nid %s not found\n",
3722 libcfs_nid2str(conf->lic_nid));
3727 net_count = lnet_get_net_ni_count_locked(net);
3731 /* create and link a new ping info, before removing the old one */
3732 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3733 lnet_get_ni_count() - 1, false);
3735 goto unlock_api_mutex;
3737 lnet_shutdown_lndni(ni);
3739 lnet_acceptor_stop();
3741 lnet_ping_target_update(pbuf, ping_mdh);
3743 /* check if the net is empty and remove it if it is */
3745 lnet_shutdown_lndnet(net);
3747 goto unlock_api_mutex;
3752 mutex_unlock(&the_lnet.ln_api_mutex);
3758 * lnet_dyn_add_net and lnet_dyn_del_net are now deprecated.
3759 * They are only expected to be called for unique networks.
3760 * That can be as a result of older DLC library
3761 * calls. Multi-Rail DLC and beyond no longer uses these APIs.
3764 lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
3766 struct lnet_net *net;
3767 LIST_HEAD(net_head);
3769 struct lnet_ioctl_config_lnd_tunables tun;
3770 const char *nets = conf->cfg_config_u.cfg_net.net_intf;
3772 /* Create a net/ni structures for the network string */
3773 rc = lnet_parse_networks(&net_head, nets);
3775 return rc == 0 ? -EINVAL : rc;
3777 mutex_lock(&the_lnet.ln_api_mutex);
3778 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3780 goto out_unlock_clean;
3784 rc = -EINVAL; /* only add one network per call */
3785 goto out_unlock_clean;
3788 net = list_entry(net_head.next, struct lnet_net, net_list);
3789 list_del_init(&net->net_list);
3791 LASSERT(lnet_net_unique(net->net_id, &the_lnet.ln_nets, NULL));
3793 memset(&tun, 0, sizeof(tun));
3795 tun.lt_cmn.lct_peer_timeout =
3796 (!conf->cfg_config_u.cfg_net.net_peer_timeout) ? DEFAULT_PEER_TIMEOUT :
3797 conf->cfg_config_u.cfg_net.net_peer_timeout;
3798 tun.lt_cmn.lct_peer_tx_credits =
3799 (!conf->cfg_config_u.cfg_net.net_peer_tx_credits) ? DEFAULT_PEER_CREDITS :
3800 conf->cfg_config_u.cfg_net.net_peer_tx_credits;
3801 tun.lt_cmn.lct_peer_rtr_credits =
3802 conf->cfg_config_u.cfg_net.net_peer_rtr_credits;
3803 tun.lt_cmn.lct_max_tx_credits =
3804 (!conf->cfg_config_u.cfg_net.net_max_tx_credits) ? DEFAULT_CREDITS :
3805 conf->cfg_config_u.cfg_net.net_max_tx_credits;
3807 rc = lnet_add_net_common(net, &tun);
3810 mutex_unlock(&the_lnet.ln_api_mutex);
3811 while (!list_empty(&net_head)) {
3812 /* net_head list is empty in success case */
3813 net = list_entry(net_head.next, struct lnet_net, net_list);
3814 list_del_init(&net->net_list);
3821 lnet_dyn_del_net(__u32 net_id)
3823 struct lnet_net *net;
3824 struct lnet_ping_buffer *pbuf;
3825 struct lnet_handle_md ping_mdh;
3829 /* don't allow userspace to shutdown the LOLND */
3830 if (LNET_NETTYP(net_id) == LOLND)
3833 mutex_lock(&the_lnet.ln_api_mutex);
3834 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3841 net = lnet_get_net_locked(net_id);
3848 net_ni_count = lnet_get_net_ni_count_locked(net);
3852 /* create and link a new ping info, before removing the old one */
3853 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3854 lnet_get_ni_count() - net_ni_count, false);
3858 lnet_shutdown_lndnet(net);
3860 lnet_acceptor_stop();
3862 lnet_ping_target_update(pbuf, ping_mdh);
3865 mutex_unlock(&the_lnet.ln_api_mutex);
3870 void lnet_incr_dlc_seq(void)
3872 atomic_inc(&lnet_dlc_seq_no);
3875 __u32 lnet_get_dlc_seq_locked(void)
3877 return atomic_read(&lnet_dlc_seq_no);
3881 lnet_ni_set_healthv(lnet_nid_t nid, int value, bool all)
3883 struct lnet_net *net;
3886 lnet_net_lock(LNET_LOCK_EX);
3887 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3888 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3889 if (all || (nid_is_nid4(&ni->ni_nid) &&
3890 lnet_nid_to_nid4(&ni->ni_nid) == nid)) {
3891 atomic_set(&ni->ni_healthv, value);
3892 if (list_empty(&ni->ni_recovery) &&
3893 value < LNET_MAX_HEALTH_VALUE) {
3894 CERROR("manually adding local NI %s to recovery\n",
3895 libcfs_nidstr(&ni->ni_nid));
3896 list_add_tail(&ni->ni_recovery,
3897 &the_lnet.ln_mt_localNIRecovq);
3898 lnet_ni_addref_locked(ni, 0);
3901 lnet_net_unlock(LNET_LOCK_EX);
3907 lnet_net_unlock(LNET_LOCK_EX);
3911 lnet_ni_set_conns_per_peer(lnet_nid_t nid, int value, bool all)
3913 struct lnet_net *net;
3916 lnet_net_lock(LNET_LOCK_EX);
3917 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3918 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3919 if (lnet_nid_to_nid4(&ni->ni_nid) != nid && !all)
3921 if (LNET_NETTYP(net->net_id) == SOCKLND)
3922 ni->ni_lnd_tunables.lnd_tun_u.lnd_sock.lnd_conns_per_peer = value;
3923 else if (LNET_NETTYP(net->net_id) == O2IBLND)
3924 ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = value;
3926 lnet_net_unlock(LNET_LOCK_EX);
3931 lnet_net_unlock(LNET_LOCK_EX);
3935 lnet_get_local_ni_hstats(struct lnet_ioctl_local_ni_hstats *stats)
3939 lnet_nid_t nid = stats->hlni_nid;
3941 cpt = lnet_net_lock_current();
3942 ni = lnet_nid2ni_locked(nid, cpt);
3949 stats->hlni_local_interrupt = atomic_read(&ni->ni_hstats.hlt_local_interrupt);
3950 stats->hlni_local_dropped = atomic_read(&ni->ni_hstats.hlt_local_dropped);
3951 stats->hlni_local_aborted = atomic_read(&ni->ni_hstats.hlt_local_aborted);
3952 stats->hlni_local_no_route = atomic_read(&ni->ni_hstats.hlt_local_no_route);
3953 stats->hlni_local_timeout = atomic_read(&ni->ni_hstats.hlt_local_timeout);
3954 stats->hlni_local_error = atomic_read(&ni->ni_hstats.hlt_local_error);
3955 stats->hlni_fatal_error = atomic_read(&ni->ni_fatal_error_on);
3956 stats->hlni_health_value = atomic_read(&ni->ni_healthv);
3957 stats->hlni_ping_count = ni->ni_ping_count;
3958 stats->hlni_next_ping = ni->ni_next_ping;
3961 lnet_net_unlock(cpt);
3967 lnet_get_local_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
3972 lnet_net_lock(LNET_LOCK_EX);
3973 list_for_each_entry(ni, &the_lnet.ln_mt_localNIRecovq, ni_recovery) {
3974 if (!nid_is_nid4(&ni->ni_nid))
3976 list->rlst_nid_array[i] = lnet_nid_to_nid4(&ni->ni_nid);
3978 if (i >= LNET_MAX_SHOW_NUM_NID)
3981 lnet_net_unlock(LNET_LOCK_EX);
3982 list->rlst_num_nids = i;
3988 lnet_get_peer_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
3990 struct lnet_peer_ni *lpni;
3993 lnet_net_lock(LNET_LOCK_EX);
3994 list_for_each_entry(lpni, &the_lnet.ln_mt_peerNIRecovq, lpni_recovery) {
3995 list->rlst_nid_array[i] = lnet_nid_to_nid4(&lpni->lpni_nid);
3997 if (i >= LNET_MAX_SHOW_NUM_NID)
4000 lnet_net_unlock(LNET_LOCK_EX);
4001 list->rlst_num_nids = i;
4007 * LNet ioctl handler.
4011 LNetCtl(unsigned int cmd, void *arg)
4013 struct libcfs_ioctl_data *data = arg;
4014 struct lnet_ioctl_config_data *config;
4015 struct lnet_process_id id4 = {};
4016 struct lnet_processid id = {};
4018 struct lnet_nid nid;
4021 BUILD_BUG_ON(sizeof(struct lnet_ioctl_net_config) +
4022 sizeof(struct lnet_ioctl_config_data) > LIBCFS_IOC_DATA_MAX);
4025 case IOC_LIBCFS_GET_NI:
4026 rc = LNetGetId(data->ioc_count, &id);
4027 data->ioc_nid = lnet_nid_to_nid4(&id.nid);
4030 case IOC_LIBCFS_FAIL_NID:
4031 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
4033 case IOC_LIBCFS_ADD_ROUTE: {
4034 /* default router sensitivity to 1 */
4035 unsigned int sensitivity = 1;
4038 if (config->cfg_hdr.ioc_len < sizeof(*config))
4041 if (config->cfg_config_u.cfg_route.rtr_sensitivity) {
4043 config->cfg_config_u.cfg_route.rtr_sensitivity;
4046 lnet_nid4_to_nid(config->cfg_nid, &nid);
4047 mutex_lock(&the_lnet.ln_api_mutex);
4048 rc = lnet_add_route(config->cfg_net,
4049 config->cfg_config_u.cfg_route.rtr_hop,
4051 config->cfg_config_u.cfg_route.
4052 rtr_priority, sensitivity);
4053 mutex_unlock(&the_lnet.ln_api_mutex);
4057 case IOC_LIBCFS_DEL_ROUTE:
4060 if (config->cfg_hdr.ioc_len < sizeof(*config))
4063 lnet_nid4_to_nid(config->cfg_nid, &nid);
4064 mutex_lock(&the_lnet.ln_api_mutex);
4065 rc = lnet_del_route(config->cfg_net, &nid);
4066 mutex_unlock(&the_lnet.ln_api_mutex);
4069 case IOC_LIBCFS_GET_ROUTE:
4072 if (config->cfg_hdr.ioc_len < sizeof(*config))
4075 mutex_lock(&the_lnet.ln_api_mutex);
4076 rc = lnet_get_route(config->cfg_count,
4078 &config->cfg_config_u.cfg_route.rtr_hop,
4080 &config->cfg_config_u.cfg_route.rtr_flags,
4081 &config->cfg_config_u.cfg_route.
4083 &config->cfg_config_u.cfg_route.
4085 mutex_unlock(&the_lnet.ln_api_mutex);
4088 case IOC_LIBCFS_GET_LOCAL_NI: {
4089 struct lnet_ioctl_config_ni *cfg_ni;
4090 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
4091 struct lnet_ioctl_element_stats *stats;
4096 /* get the tunables if they are available */
4097 if (cfg_ni->lic_cfg_hdr.ioc_len <
4098 sizeof(*cfg_ni) + sizeof(*stats) + sizeof(*tun))
4101 stats = (struct lnet_ioctl_element_stats *)
4103 tun = (struct lnet_ioctl_config_lnd_tunables *)
4104 (cfg_ni->lic_bulk + sizeof(*stats));