4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LNET
35 #include <linux/ctype.h>
36 #include <linux/log2.h>
37 #include <linux/ktime.h>
38 #include <linux/moduleparam.h>
39 #include <linux/uaccess.h>
40 #ifdef HAVE_SCHED_HEADERS
41 #include <linux/sched/signal.h>
44 #include <lnet/lib-lnet.h>
46 #define D_LNI D_CONSOLE
49 * initialize ln_api_mutex statically, since it needs to be used in
50 * discovery_set callback. That module parameter callback can be called
51 * before module init completes. The mutex needs to be ready for use then.
53 struct lnet the_lnet = {
54 .ln_api_mutex = __MUTEX_INITIALIZER(the_lnet.ln_api_mutex),
55 }; /* THE state of the network */
56 EXPORT_SYMBOL(the_lnet);
58 static char *ip2nets = "";
59 module_param(ip2nets, charp, 0444);
60 MODULE_PARM_DESC(ip2nets, "LNET network <- IP table");
62 static char *networks = "";
63 module_param(networks, charp, 0444);
64 MODULE_PARM_DESC(networks, "local networks");
66 static char *routes = "";
67 module_param(routes, charp, 0444);
68 MODULE_PARM_DESC(routes, "routes to non-local networks");
70 static int rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
71 module_param(rnet_htable_size, int, 0444);
72 MODULE_PARM_DESC(rnet_htable_size, "size of remote network hash table");
74 static int use_tcp_bonding = false;
75 module_param(use_tcp_bonding, int, 0444);
76 MODULE_PARM_DESC(use_tcp_bonding,
77 "Set to 1 to use socklnd bonding. 0 to use Multi-Rail");
79 unsigned int lnet_numa_range = 0;
80 module_param(lnet_numa_range, uint, 0444);
81 MODULE_PARM_DESC(lnet_numa_range,
82 "NUMA range to consider during Multi-Rail selection");
85 * lnet_health_sensitivity determines by how much we decrement the health
86 * value on sending error. The value defaults to 100, which means health
87 * interface health is decremented by 100 points every failure.
89 unsigned int lnet_health_sensitivity = 100;
90 static int sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp);
91 #ifdef HAVE_KERNEL_PARAM_OPS
92 static struct kernel_param_ops param_ops_health_sensitivity = {
93 .set = sensitivity_set,
96 #define param_check_health_sensitivity(name, p) \
97 __param_check(name, p, int)
98 module_param(lnet_health_sensitivity, health_sensitivity, S_IRUGO|S_IWUSR);
100 module_param_call(lnet_health_sensitivity, sensitivity_set, param_get_int,
101 &lnet_health_sensitivity, S_IRUGO|S_IWUSR);
103 MODULE_PARM_DESC(lnet_health_sensitivity,
104 "Value to decrement the health value by on error");
107 * lnet_recovery_interval determines how often we should perform recovery
108 * on unhealthy interfaces.
110 unsigned int lnet_recovery_interval = 1;
111 static int recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp);
112 #ifdef HAVE_KERNEL_PARAM_OPS
113 static struct kernel_param_ops param_ops_recovery_interval = {
114 .set = recovery_interval_set,
115 .get = param_get_int,
117 #define param_check_recovery_interval(name, p) \
118 __param_check(name, p, int)
119 module_param(lnet_recovery_interval, recovery_interval, S_IRUGO|S_IWUSR);
121 module_param_call(lnet_recovery_interval, recovery_interval_set, param_get_int,
122 &lnet_recovery_interval, S_IRUGO|S_IWUSR);
124 MODULE_PARM_DESC(lnet_recovery_interval,
125 "Interval to recover unhealthy interfaces in seconds");
127 static int lnet_interfaces_max = LNET_INTERFACES_MAX_DEFAULT;
128 static int intf_max_set(const char *val, cfs_kernel_param_arg_t *kp);
130 static struct kernel_param_ops param_ops_interfaces_max = {
132 .get = param_get_int,
135 #define param_check_interfaces_max(name, p) \
136 __param_check(name, p, int)
138 #ifdef HAVE_KERNEL_PARAM_OPS
139 module_param(lnet_interfaces_max, interfaces_max, 0644);
141 module_param_call(lnet_interfaces_max, intf_max_set, param_get_int,
142 ¶m_ops_interfaces_max, 0644);
144 MODULE_PARM_DESC(lnet_interfaces_max,
145 "Maximum number of interfaces in a node.");
147 unsigned lnet_peer_discovery_disabled = 0;
148 static int discovery_set(const char *val, cfs_kernel_param_arg_t *kp);
150 static struct kernel_param_ops param_ops_discovery_disabled = {
151 .set = discovery_set,
152 .get = param_get_int,
155 #define param_check_discovery_disabled(name, p) \
156 __param_check(name, p, int)
157 #ifdef HAVE_KERNEL_PARAM_OPS
158 module_param(lnet_peer_discovery_disabled, discovery_disabled, 0644);
160 module_param_call(lnet_peer_discovery_disabled, discovery_set, param_get_int,
161 ¶m_ops_discovery_disabled, 0644);
163 MODULE_PARM_DESC(lnet_peer_discovery_disabled,
164 "Set to 1 to disable peer discovery on this node.");
166 unsigned int lnet_drop_asym_route;
167 static int drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp);
169 static struct kernel_param_ops param_ops_drop_asym_route = {
170 .set = drop_asym_route_set,
171 .get = param_get_int,
174 #define param_check_drop_asym_route(name, p) \
175 __param_check(name, p, int)
176 #ifdef HAVE_KERNEL_PARAM_OPS
177 module_param(lnet_drop_asym_route, drop_asym_route, 0644);
179 module_param_call(lnet_drop_asym_route, drop_asym_route_set, param_get_int,
180 ¶m_ops_drop_asym_route, 0644);
182 MODULE_PARM_DESC(lnet_drop_asym_route,
183 "Set to 1 to drop asymmetrical route messages.");
185 #define LNET_TRANSACTION_TIMEOUT_DEFAULT 50
186 unsigned int lnet_transaction_timeout = LNET_TRANSACTION_TIMEOUT_DEFAULT;
187 static int transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp);
188 #ifdef HAVE_KERNEL_PARAM_OPS
189 static struct kernel_param_ops param_ops_transaction_timeout = {
190 .set = transaction_to_set,
191 .get = param_get_int,
194 #define param_check_transaction_timeout(name, p) \
195 __param_check(name, p, int)
196 module_param(lnet_transaction_timeout, transaction_timeout, S_IRUGO|S_IWUSR);
198 module_param_call(lnet_transaction_timeout, transaction_to_set, param_get_int,
199 &lnet_transaction_timeout, S_IRUGO|S_IWUSR);
201 MODULE_PARM_DESC(lnet_transaction_timeout,
202 "Maximum number of seconds to wait for a peer response.");
204 #define LNET_RETRY_COUNT_DEFAULT 2
205 unsigned int lnet_retry_count = LNET_RETRY_COUNT_DEFAULT;
206 static int retry_count_set(const char *val, cfs_kernel_param_arg_t *kp);
207 #ifdef HAVE_KERNEL_PARAM_OPS
208 static struct kernel_param_ops param_ops_retry_count = {
209 .set = retry_count_set,
210 .get = param_get_int,
213 #define param_check_retry_count(name, p) \
214 __param_check(name, p, int)
215 module_param(lnet_retry_count, retry_count, S_IRUGO|S_IWUSR);
217 module_param_call(lnet_retry_count, retry_count_set, param_get_int,
218 &lnet_retry_count, S_IRUGO|S_IWUSR);
220 MODULE_PARM_DESC(lnet_retry_count,
221 "Maximum number of times to retry transmitting a message");
223 unsigned int lnet_response_tracking = 3;
224 static int response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp);
226 #ifdef HAVE_KERNEL_PARAM_OPS
227 static struct kernel_param_ops param_ops_response_tracking = {
228 .set = response_tracking_set,
229 .get = param_get_int,
232 #define param_check_response_tracking(name, p) \
233 __param_check(name, p, int)
234 module_param(lnet_response_tracking, response_tracking, 0644);
236 module_param_call(lnet_response_tracking, response_tracking_set, param_get_int,
237 &lnet_response_tracking, 0644);
239 MODULE_PARM_DESC(lnet_response_tracking,
240 "(0|1|2|3) LNet Internal Only|GET Reply only|PUT ACK only|Full Tracking (default)");
242 #define LNET_LND_TIMEOUT_DEFAULT ((LNET_TRANSACTION_TIMEOUT_DEFAULT - 1) / \
243 (LNET_RETRY_COUNT_DEFAULT + 1))
244 unsigned int lnet_lnd_timeout = LNET_LND_TIMEOUT_DEFAULT;
245 static void lnet_set_lnd_timeout(void)
247 lnet_lnd_timeout = (lnet_transaction_timeout - 1) /
248 (lnet_retry_count + 1);
251 unsigned int lnet_current_net_count;
254 * This sequence number keeps track of how many times DLC was used to
255 * update the local NIs. It is incremented when a NI is added or
256 * removed and checked when sending a message to determine if there is
257 * a need to re-run the selection algorithm. See lnet_select_pathway()
258 * for more details on its usage.
260 static atomic_t lnet_dlc_seq_no = ATOMIC_INIT(0);
262 static int lnet_ping(struct lnet_process_id id, signed long timeout,
263 struct lnet_process_id __user *ids, int n_ids);
265 static int lnet_discover(struct lnet_process_id id, __u32 force,
266 struct lnet_process_id __user *ids, int n_ids);
269 sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
272 unsigned *sensitivity = (unsigned *)kp->arg;
275 rc = kstrtoul(val, 0, &value);
277 CERROR("Invalid module parameter value for 'lnet_health_sensitivity'\n");
282 * The purpose of locking the api_mutex here is to ensure that
283 * the correct value ends up stored properly.
285 mutex_lock(&the_lnet.ln_api_mutex);
287 if (value > LNET_MAX_HEALTH_VALUE) {
288 mutex_unlock(&the_lnet.ln_api_mutex);
289 CERROR("Invalid health value. Maximum: %d value = %lu\n",
290 LNET_MAX_HEALTH_VALUE, value);
294 if (*sensitivity != 0 && value == 0 && lnet_retry_count != 0) {
295 lnet_retry_count = 0;
296 lnet_set_lnd_timeout();
299 *sensitivity = value;
301 mutex_unlock(&the_lnet.ln_api_mutex);
307 recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp)
310 unsigned *interval = (unsigned *)kp->arg;
313 rc = kstrtoul(val, 0, &value);
315 CERROR("Invalid module parameter value for 'lnet_recovery_interval'\n");
320 CERROR("lnet_recovery_interval must be at least 1 second\n");
325 * The purpose of locking the api_mutex here is to ensure that
326 * the correct value ends up stored properly.
328 mutex_lock(&the_lnet.ln_api_mutex);
332 mutex_unlock(&the_lnet.ln_api_mutex);
338 discovery_set(const char *val, cfs_kernel_param_arg_t *kp)
341 unsigned *discovery_off = (unsigned *)kp->arg;
343 struct lnet_ping_buffer *pbuf;
345 rc = kstrtoul(val, 0, &value);
347 CERROR("Invalid module parameter value for 'lnet_peer_discovery_disabled'\n");
351 value = (value) ? 1 : 0;
354 * The purpose of locking the api_mutex here is to ensure that
355 * the correct value ends up stored properly.
357 mutex_lock(&the_lnet.ln_api_mutex);
359 if (value == *discovery_off) {
360 mutex_unlock(&the_lnet.ln_api_mutex);
365 * We still want to set the discovery value even when LNet is not
366 * running. This is the case when LNet is being loaded and we want
367 * the module parameters to take effect. Otherwise if we're
368 * changing the value dynamically, we want to set it after
371 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
372 *discovery_off = value;
373 mutex_unlock(&the_lnet.ln_api_mutex);
377 /* tell peers that discovery setting has changed */
378 lnet_net_lock(LNET_LOCK_EX);
379 pbuf = the_lnet.ln_ping_target;
381 pbuf->pb_info.pi_features &= ~LNET_PING_FEAT_DISCOVERY;
383 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
384 lnet_net_unlock(LNET_LOCK_EX);
386 /* only send a push when we're turning off discovery */
387 if (*discovery_off <= 0 && value > 0)
388 lnet_push_update_to_peers(1);
389 *discovery_off = value;
391 mutex_unlock(&the_lnet.ln_api_mutex);
397 drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp)
400 unsigned int *drop_asym_route = (unsigned int *)kp->arg;
403 rc = kstrtoul(val, 0, &value);
405 CERROR("Invalid module parameter value for "
406 "'lnet_drop_asym_route'\n");
411 * The purpose of locking the api_mutex here is to ensure that
412 * the correct value ends up stored properly.
414 mutex_lock(&the_lnet.ln_api_mutex);
416 if (value == *drop_asym_route) {
417 mutex_unlock(&the_lnet.ln_api_mutex);
421 *drop_asym_route = value;
423 mutex_unlock(&the_lnet.ln_api_mutex);
429 transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp)
432 unsigned *transaction_to = (unsigned *)kp->arg;
435 rc = kstrtoul(val, 0, &value);
437 CERROR("Invalid module parameter value for 'lnet_transaction_timeout'\n");
442 * The purpose of locking the api_mutex here is to ensure that
443 * the correct value ends up stored properly.
445 mutex_lock(&the_lnet.ln_api_mutex);
447 if (value <= lnet_retry_count || value == 0) {
448 mutex_unlock(&the_lnet.ln_api_mutex);
449 CERROR("Invalid value for lnet_transaction_timeout (%lu). "
450 "Has to be greater than lnet_retry_count (%u)\n",
451 value, lnet_retry_count);
455 if (value == *transaction_to) {
456 mutex_unlock(&the_lnet.ln_api_mutex);
460 *transaction_to = value;
461 /* Update the lnet_lnd_timeout now that we've modified the
462 * transaction timeout
464 lnet_set_lnd_timeout();
466 mutex_unlock(&the_lnet.ln_api_mutex);
472 retry_count_set(const char *val, cfs_kernel_param_arg_t *kp)
475 unsigned *retry_count = (unsigned *)kp->arg;
478 rc = kstrtoul(val, 0, &value);
480 CERROR("Invalid module parameter value for 'lnet_retry_count'\n");
485 * The purpose of locking the api_mutex here is to ensure that
486 * the correct value ends up stored properly.
488 mutex_lock(&the_lnet.ln_api_mutex);
490 if (lnet_health_sensitivity == 0 && value > 0) {
491 mutex_unlock(&the_lnet.ln_api_mutex);
492 CERROR("Can not set lnet_retry_count when health feature is turned off\n");
496 if (value > lnet_transaction_timeout) {
497 mutex_unlock(&the_lnet.ln_api_mutex);
498 CERROR("Invalid value for lnet_retry_count (%lu). "
499 "Has to be smaller than lnet_transaction_timeout (%u)\n",
500 value, lnet_transaction_timeout);
504 *retry_count = value;
506 /* Update the lnet_lnd_timeout now that we've modified the
509 lnet_set_lnd_timeout();
511 mutex_unlock(&the_lnet.ln_api_mutex);
517 intf_max_set(const char *val, cfs_kernel_param_arg_t *kp)
521 rc = kstrtoint(val, 0, &value);
523 CERROR("Invalid module parameter value for 'lnet_interfaces_max'\n");
527 if (value < LNET_INTERFACES_MIN) {
528 CWARN("max interfaces provided are too small, setting to %d\n",
529 LNET_INTERFACES_MAX_DEFAULT);
530 value = LNET_INTERFACES_MAX_DEFAULT;
533 *(int *)kp->arg = value;
539 response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp)
542 unsigned long new_value;
544 rc = kstrtoul(val, 0, &new_value);
546 CERROR("Invalid value for 'lnet_response_tracking'\n");
550 if (new_value < 0 || new_value > 3) {
551 CWARN("Invalid value (%lu) for 'lnet_response_tracking'\n",
556 lnet_response_tracking = new_value;
562 lnet_get_routes(void)
568 lnet_get_networks(void)
573 if (*networks != 0 && *ip2nets != 0) {
574 LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
575 "'ip2nets' but not both at once\n");
580 rc = lnet_parse_ip2nets(&nets, ip2nets);
581 return (rc == 0) ? nets : NULL;
591 lnet_init_locks(void)
593 spin_lock_init(&the_lnet.ln_eq_wait_lock);
594 spin_lock_init(&the_lnet.ln_msg_resend_lock);
595 init_completion(&the_lnet.ln_mt_wait_complete);
596 mutex_init(&the_lnet.ln_lnd_mutex);
599 struct kmem_cache *lnet_mes_cachep; /* MEs kmem_cache */
600 struct kmem_cache *lnet_small_mds_cachep; /* <= LNET_SMALL_MD_SIZE bytes
602 struct kmem_cache *lnet_rspt_cachep; /* response tracker cache */
603 struct kmem_cache *lnet_msg_cachep;
606 lnet_slab_setup(void)
608 /* create specific kmem_cache for MEs and small MDs (i.e., originally
609 * allocated in <size-xxx> kmem_cache).
611 lnet_mes_cachep = kmem_cache_create("lnet_MEs", sizeof(struct lnet_me),
613 if (!lnet_mes_cachep)
616 lnet_small_mds_cachep = kmem_cache_create("lnet_small_MDs",
617 LNET_SMALL_MD_SIZE, 0, 0,
619 if (!lnet_small_mds_cachep)
622 lnet_rspt_cachep = kmem_cache_create("lnet_rspt", sizeof(struct lnet_rsp_tracker),
624 if (!lnet_rspt_cachep)
627 lnet_msg_cachep = kmem_cache_create("lnet_msg", sizeof(struct lnet_msg),
629 if (!lnet_msg_cachep)
636 lnet_slab_cleanup(void)
638 if (lnet_msg_cachep) {
639 kmem_cache_destroy(lnet_msg_cachep);
640 lnet_msg_cachep = NULL;
644 if (lnet_rspt_cachep) {
645 kmem_cache_destroy(lnet_rspt_cachep);
646 lnet_rspt_cachep = NULL;
649 if (lnet_small_mds_cachep) {
650 kmem_cache_destroy(lnet_small_mds_cachep);
651 lnet_small_mds_cachep = NULL;
654 if (lnet_mes_cachep) {
655 kmem_cache_destroy(lnet_mes_cachep);
656 lnet_mes_cachep = NULL;
661 lnet_create_remote_nets_table(void)
664 struct list_head *hash;
666 LASSERT(the_lnet.ln_remote_nets_hash == NULL);
667 LASSERT(the_lnet.ln_remote_nets_hbits > 0);
668 CFS_ALLOC_PTR_ARRAY(hash, LNET_REMOTE_NETS_HASH_SIZE);
670 CERROR("Failed to create remote nets hash table\n");
674 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
675 INIT_LIST_HEAD(&hash[i]);
676 the_lnet.ln_remote_nets_hash = hash;
681 lnet_destroy_remote_nets_table(void)
685 if (the_lnet.ln_remote_nets_hash == NULL)
688 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
689 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
691 CFS_FREE_PTR_ARRAY(the_lnet.ln_remote_nets_hash,
692 LNET_REMOTE_NETS_HASH_SIZE);
693 the_lnet.ln_remote_nets_hash = NULL;
697 lnet_destroy_locks(void)
699 if (the_lnet.ln_res_lock != NULL) {
700 cfs_percpt_lock_free(the_lnet.ln_res_lock);
701 the_lnet.ln_res_lock = NULL;
704 if (the_lnet.ln_net_lock != NULL) {
705 cfs_percpt_lock_free(the_lnet.ln_net_lock);
706 the_lnet.ln_net_lock = NULL;
711 lnet_create_locks(void)
715 the_lnet.ln_res_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
716 if (the_lnet.ln_res_lock == NULL)
719 the_lnet.ln_net_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
720 if (the_lnet.ln_net_lock == NULL)
726 lnet_destroy_locks();
730 static void lnet_assert_wire_constants(void)
732 /* Wire protocol assertions generated by 'wirecheck'
733 * running on Linux robert.bartonsoftware.com 2.6.8-1.521
734 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux
735 * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) */
738 BUILD_BUG_ON(LNET_PROTO_TCP_MAGIC != 0xeebc0ded);
739 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MAJOR != 1);
740 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MINOR != 0);
741 BUILD_BUG_ON(LNET_MSG_ACK != 0);
742 BUILD_BUG_ON(LNET_MSG_PUT != 1);
743 BUILD_BUG_ON(LNET_MSG_GET != 2);
744 BUILD_BUG_ON(LNET_MSG_REPLY != 3);
745 BUILD_BUG_ON(LNET_MSG_HELLO != 4);
747 /* Checks for struct lnet_handle_wire */
748 BUILD_BUG_ON((int)sizeof(struct lnet_handle_wire) != 16);
749 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
750 wh_interface_cookie) != 0);
751 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_interface_cookie) != 8);
752 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
753 wh_object_cookie) != 8);
754 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_object_cookie) != 8);
756 /* Checks for struct struct lnet_magicversion */
757 BUILD_BUG_ON((int)sizeof(struct lnet_magicversion) != 8);
758 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, magic) != 0);
759 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->magic) != 4);
760 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, version_major) != 4);
761 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_major) != 2);
762 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion,
763 version_minor) != 6);
764 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_minor) != 2);
766 /* Checks for struct struct lnet_hdr */
767 BUILD_BUG_ON((int)sizeof(struct lnet_hdr) != 72);
768 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, dest_nid) != 0);
769 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->dest_nid) != 8);
770 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, src_nid) != 8);
771 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->src_nid) != 8);
772 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, dest_pid) != 16);
773 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->dest_pid) != 4);
774 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, src_pid) != 20);
775 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->src_pid) != 4);
776 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, type) != 24);
777 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->type) != 4);
778 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, payload_length) != 28);
779 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->payload_length) != 4);
780 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg) != 32);
781 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg) != 40);
784 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.dst_wmd) != 32);
785 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.dst_wmd) != 16);
786 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.match_bits) != 48);
787 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.match_bits) != 8);
788 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.mlength) != 56);
789 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.mlength) != 4);
792 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.ack_wmd) != 32);
793 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.ack_wmd) != 16);
794 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.match_bits) != 48);
795 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.match_bits) != 8);
796 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.hdr_data) != 56);
797 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.hdr_data) != 8);
798 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.ptl_index) != 64);
799 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.ptl_index) != 4);
800 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.offset) != 68);
801 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.offset) != 4);
804 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.return_wmd) != 32);
805 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.return_wmd) != 16);
806 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.match_bits) != 48);
807 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.match_bits) != 8);
808 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.ptl_index) != 56);
809 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.ptl_index) != 4);
810 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.src_offset) != 60);
811 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.src_offset) != 4);
812 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.sink_length) != 64);
813 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.sink_length) != 4);
816 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.reply.dst_wmd) != 32);
817 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.reply.dst_wmd) != 16);
820 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.hello.incarnation) != 32);
821 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.hello.incarnation) != 8);
822 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.hello.type) != 40);
823 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.hello.type) != 4);
825 /* Checks for struct lnet_ni_status and related constants */
826 BUILD_BUG_ON(LNET_NI_STATUS_INVALID != 0x00000000);
827 BUILD_BUG_ON(LNET_NI_STATUS_UP != 0x15aac0de);
828 BUILD_BUG_ON(LNET_NI_STATUS_DOWN != 0xdeadface);
830 /* Checks for struct lnet_ni_status */
831 BUILD_BUG_ON((int)sizeof(struct lnet_ni_status) != 16);
832 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_nid) != 0);
833 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_nid) != 8);
834 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_status) != 8);
835 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_status) != 4);
836 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_unused) != 12);
837 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_unused) != 4);
839 /* Checks for struct lnet_ping_info and related constants */
840 BUILD_BUG_ON(LNET_PROTO_PING_MAGIC != 0x70696E67);
841 BUILD_BUG_ON(LNET_PING_FEAT_INVAL != 0);
842 BUILD_BUG_ON(LNET_PING_FEAT_BASE != 1);
843 BUILD_BUG_ON(LNET_PING_FEAT_NI_STATUS != 2);
844 BUILD_BUG_ON(LNET_PING_FEAT_RTE_DISABLED != 4);
845 BUILD_BUG_ON(LNET_PING_FEAT_MULTI_RAIL != 8);
846 BUILD_BUG_ON(LNET_PING_FEAT_DISCOVERY != 16);
847 BUILD_BUG_ON(LNET_PING_FEAT_BITS != 31);
849 /* Checks for struct lnet_ping_info */
850 BUILD_BUG_ON((int)sizeof(struct lnet_ping_info) != 16);
851 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_magic) != 0);
852 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_magic) != 4);
853 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_features) != 4);
854 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_features) != 4);
855 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_pid) != 8);
856 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_pid) != 4);
857 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_nnis) != 12);
858 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_nnis) != 4);
859 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_ni) != 16);
860 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_ni) != 0);
863 static const struct lnet_lnd *lnet_find_lnd_by_type(__u32 type)
865 const struct lnet_lnd *lnd;
867 /* holding lnd mutex */
868 if (type >= NUM_LNDS)
870 lnd = the_lnet.ln_lnds[type];
871 LASSERT(!lnd || lnd->lnd_type == type);
877 lnet_get_lnd_timeout(void)
879 return lnet_lnd_timeout;
881 EXPORT_SYMBOL(lnet_get_lnd_timeout);
884 lnet_register_lnd(const struct lnet_lnd *lnd)
886 mutex_lock(&the_lnet.ln_lnd_mutex);
888 LASSERT(libcfs_isknown_lnd(lnd->lnd_type));
889 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
891 the_lnet.ln_lnds[lnd->lnd_type] = lnd;
893 CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type));
895 mutex_unlock(&the_lnet.ln_lnd_mutex);
897 EXPORT_SYMBOL(lnet_register_lnd);
900 lnet_unregister_lnd(const struct lnet_lnd *lnd)
902 mutex_lock(&the_lnet.ln_lnd_mutex);
904 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
906 the_lnet.ln_lnds[lnd->lnd_type] = NULL;
907 CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type));
909 mutex_unlock(&the_lnet.ln_lnd_mutex);
911 EXPORT_SYMBOL(lnet_unregister_lnd);
914 lnet_counters_get_common_locked(struct lnet_counters_common *common)
916 struct lnet_counters *ctr;
919 /* FIXME !!! Their is no assert_lnet_net_locked() to ensure this
920 * actually called under the protection of the lnet_net_lock.
922 memset(common, 0, sizeof(*common));
924 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
925 common->lcc_msgs_max += ctr->lct_common.lcc_msgs_max;
926 common->lcc_msgs_alloc += ctr->lct_common.lcc_msgs_alloc;
927 common->lcc_errors += ctr->lct_common.lcc_errors;
928 common->lcc_send_count += ctr->lct_common.lcc_send_count;
929 common->lcc_recv_count += ctr->lct_common.lcc_recv_count;
930 common->lcc_route_count += ctr->lct_common.lcc_route_count;
931 common->lcc_drop_count += ctr->lct_common.lcc_drop_count;
932 common->lcc_send_length += ctr->lct_common.lcc_send_length;
933 common->lcc_recv_length += ctr->lct_common.lcc_recv_length;
934 common->lcc_route_length += ctr->lct_common.lcc_route_length;
935 common->lcc_drop_length += ctr->lct_common.lcc_drop_length;
940 lnet_counters_get_common(struct lnet_counters_common *common)
942 lnet_net_lock(LNET_LOCK_EX);
943 lnet_counters_get_common_locked(common);
944 lnet_net_unlock(LNET_LOCK_EX);
946 EXPORT_SYMBOL(lnet_counters_get_common);
949 lnet_counters_get(struct lnet_counters *counters)
951 struct lnet_counters *ctr;
952 struct lnet_counters_health *health = &counters->lct_health;
955 memset(counters, 0, sizeof(*counters));
957 lnet_net_lock(LNET_LOCK_EX);
959 if (the_lnet.ln_state != LNET_STATE_RUNNING)
960 GOTO(out_unlock, rc = -ENODEV);
962 lnet_counters_get_common_locked(&counters->lct_common);
964 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
965 health->lch_rst_alloc += ctr->lct_health.lch_rst_alloc;
966 health->lch_resend_count += ctr->lct_health.lch_resend_count;
967 health->lch_response_timeout_count +=
968 ctr->lct_health.lch_response_timeout_count;
969 health->lch_local_interrupt_count +=
970 ctr->lct_health.lch_local_interrupt_count;
971 health->lch_local_dropped_count +=
972 ctr->lct_health.lch_local_dropped_count;
973 health->lch_local_aborted_count +=
974 ctr->lct_health.lch_local_aborted_count;
975 health->lch_local_no_route_count +=
976 ctr->lct_health.lch_local_no_route_count;
977 health->lch_local_timeout_count +=
978 ctr->lct_health.lch_local_timeout_count;
979 health->lch_local_error_count +=
980 ctr->lct_health.lch_local_error_count;
981 health->lch_remote_dropped_count +=
982 ctr->lct_health.lch_remote_dropped_count;
983 health->lch_remote_error_count +=
984 ctr->lct_health.lch_remote_error_count;
985 health->lch_remote_timeout_count +=
986 ctr->lct_health.lch_remote_timeout_count;
987 health->lch_network_timeout_count +=
988 ctr->lct_health.lch_network_timeout_count;
991 lnet_net_unlock(LNET_LOCK_EX);
994 EXPORT_SYMBOL(lnet_counters_get);
997 lnet_counters_reset(void)
999 struct lnet_counters *counters;
1002 lnet_net_lock(LNET_LOCK_EX);
1004 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1007 cfs_percpt_for_each(counters, i, the_lnet.ln_counters)
1008 memset(counters, 0, sizeof(struct lnet_counters));
1010 lnet_net_unlock(LNET_LOCK_EX);
1014 lnet_res_type2str(int type)
1019 case LNET_COOKIE_TYPE_MD:
1021 case LNET_COOKIE_TYPE_ME:
1023 case LNET_COOKIE_TYPE_EQ:
1029 lnet_res_container_cleanup(struct lnet_res_container *rec)
1033 if (rec->rec_type == 0) /* not set yet, it's uninitialized */
1036 while (!list_empty(&rec->rec_active)) {
1037 struct list_head *e = rec->rec_active.next;
1040 if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
1041 lnet_md_free(list_entry(e, struct lnet_libmd, md_list));
1043 } else { /* NB: Active MEs should be attached on portals */
1050 /* Found alive MD/ME/EQ, user really should unlink/free
1051 * all of them before finalize LNet, but if someone didn't,
1052 * we have to recycle garbage for him */
1053 CERROR("%d active elements on exit of %s container\n",
1054 count, lnet_res_type2str(rec->rec_type));
1057 if (rec->rec_lh_hash != NULL) {
1058 CFS_FREE_PTR_ARRAY(rec->rec_lh_hash, LNET_LH_HASH_SIZE);
1059 rec->rec_lh_hash = NULL;
1062 rec->rec_type = 0; /* mark it as finalized */
1066 lnet_res_container_setup(struct lnet_res_container *rec, int cpt, int type)
1071 LASSERT(rec->rec_type == 0);
1073 rec->rec_type = type;
1074 INIT_LIST_HEAD(&rec->rec_active);
1076 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type;
1078 /* Arbitrary choice of hash table size */
1079 LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt,
1080 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
1081 if (rec->rec_lh_hash == NULL) {
1086 for (i = 0; i < LNET_LH_HASH_SIZE; i++)
1087 INIT_LIST_HEAD(&rec->rec_lh_hash[i]);
1092 CERROR("Failed to setup %s resource container\n",
1093 lnet_res_type2str(type));
1094 lnet_res_container_cleanup(rec);
1099 lnet_res_containers_destroy(struct lnet_res_container **recs)
1101 struct lnet_res_container *rec;
1104 cfs_percpt_for_each(rec, i, recs)
1105 lnet_res_container_cleanup(rec);
1107 cfs_percpt_free(recs);
1110 static struct lnet_res_container **
1111 lnet_res_containers_create(int type)
1113 struct lnet_res_container **recs;
1114 struct lnet_res_container *rec;
1118 recs = cfs_percpt_alloc(lnet_cpt_table(), sizeof(*rec));
1120 CERROR("Failed to allocate %s resource containers\n",
1121 lnet_res_type2str(type));
1125 cfs_percpt_for_each(rec, i, recs) {
1126 rc = lnet_res_container_setup(rec, i, type);
1128 lnet_res_containers_destroy(recs);
1136 struct lnet_libhandle *
1137 lnet_res_lh_lookup(struct lnet_res_container *rec, __u64 cookie)
1139 /* ALWAYS called with lnet_res_lock held */
1140 struct list_head *head;
1141 struct lnet_libhandle *lh;
1144 if ((cookie & LNET_COOKIE_MASK) != rec->rec_type)
1147 hash = cookie >> (LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS);
1148 head = &rec->rec_lh_hash[hash & LNET_LH_HASH_MASK];
1150 list_for_each_entry(lh, head, lh_hash_chain) {
1151 if (lh->lh_cookie == cookie)
1159 lnet_res_lh_initialize(struct lnet_res_container *rec,
1160 struct lnet_libhandle *lh)
1162 /* ALWAYS called with lnet_res_lock held */
1163 unsigned int ibits = LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS;
1166 lh->lh_cookie = rec->rec_lh_cookie;
1167 rec->rec_lh_cookie += 1 << ibits;
1169 hash = (lh->lh_cookie >> ibits) & LNET_LH_HASH_MASK;
1171 list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
1175 lnet_create_array_of_queues(void)
1177 struct list_head **qs;
1178 struct list_head *q;
1181 qs = cfs_percpt_alloc(lnet_cpt_table(),
1182 sizeof(struct list_head));
1184 CERROR("Failed to allocate queues\n");
1188 cfs_percpt_for_each(q, i, qs)
1194 static int lnet_unprepare(void);
1197 lnet_prepare(lnet_pid_t requested_pid)
1199 /* Prepare to bring up the network */
1200 struct lnet_res_container **recs;
1203 if (requested_pid == LNET_PID_ANY) {
1204 /* Don't instantiate LNET just for me */
1208 LASSERT(the_lnet.ln_refcount == 0);
1210 the_lnet.ln_routing = 0;
1212 LASSERT((requested_pid & LNET_PID_USERFLAG) == 0);
1213 the_lnet.ln_pid = requested_pid;
1215 INIT_LIST_HEAD(&the_lnet.ln_test_peers);
1216 INIT_LIST_HEAD(&the_lnet.ln_remote_peer_ni_list);
1217 INIT_LIST_HEAD(&the_lnet.ln_nets);
1218 INIT_LIST_HEAD(&the_lnet.ln_routers);
1219 INIT_LIST_HEAD(&the_lnet.ln_drop_rules);
1220 INIT_LIST_HEAD(&the_lnet.ln_delay_rules);
1221 INIT_LIST_HEAD(&the_lnet.ln_dc_request);
1222 INIT_LIST_HEAD(&the_lnet.ln_dc_working);
1223 INIT_LIST_HEAD(&the_lnet.ln_dc_expired);
1224 INIT_LIST_HEAD(&the_lnet.ln_mt_localNIRecovq);
1225 INIT_LIST_HEAD(&the_lnet.ln_mt_peerNIRecovq);
1226 init_waitqueue_head(&the_lnet.ln_dc_waitq);
1227 the_lnet.ln_mt_handler = NULL;
1228 init_completion(&the_lnet.ln_started);
1230 rc = lnet_slab_setup();
1234 rc = lnet_create_remote_nets_table();
1239 * NB the interface cookie in wire handles guards against delayed
1240 * replies and ACKs appearing valid after reboot.
1242 the_lnet.ln_interface_cookie = ktime_get_real_ns();
1244 the_lnet.ln_counters = cfs_percpt_alloc(lnet_cpt_table(),
1245 sizeof(struct lnet_counters));
1246 if (the_lnet.ln_counters == NULL) {
1247 CERROR("Failed to allocate counters for LNet\n");
1252 rc = lnet_peer_tables_create();
1256 rc = lnet_msg_containers_create();
1260 rc = lnet_res_container_setup(&the_lnet.ln_eq_container, 0,
1261 LNET_COOKIE_TYPE_EQ);
1265 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD);
1271 the_lnet.ln_md_containers = recs;
1273 rc = lnet_portals_create();
1275 CERROR("Failed to create portals for LNet: %d\n", rc);
1279 the_lnet.ln_mt_zombie_rstqs = lnet_create_array_of_queues();
1280 if (!the_lnet.ln_mt_zombie_rstqs) {
1293 lnet_unprepare (void)
1295 /* NB no LNET_LOCK since this is the last reference. All LND instances
1296 * have shut down already, so it is safe to unlink and free all
1297 * descriptors, even those that appear committed to a network op (eg MD
1298 * with non-zero pending count) */
1300 lnet_fail_nid(LNET_NID_ANY, 0);
1302 LASSERT(the_lnet.ln_refcount == 0);
1303 LASSERT(list_empty(&the_lnet.ln_test_peers));
1304 LASSERT(list_empty(&the_lnet.ln_nets));
1306 if (the_lnet.ln_mt_zombie_rstqs) {
1307 lnet_clean_zombie_rstqs();
1308 the_lnet.ln_mt_zombie_rstqs = NULL;
1311 lnet_assert_handler_unused(the_lnet.ln_mt_handler);
1312 the_lnet.ln_mt_handler = NULL;
1314 lnet_portals_destroy();
1316 if (the_lnet.ln_md_containers != NULL) {
1317 lnet_res_containers_destroy(the_lnet.ln_md_containers);
1318 the_lnet.ln_md_containers = NULL;
1321 lnet_res_container_cleanup(&the_lnet.ln_eq_container);
1323 lnet_msg_containers_destroy();
1325 lnet_rtrpools_free(0);
1327 if (the_lnet.ln_counters != NULL) {
1328 cfs_percpt_free(the_lnet.ln_counters);
1329 the_lnet.ln_counters = NULL;
1331 lnet_destroy_remote_nets_table();
1332 lnet_slab_cleanup();
1338 lnet_net2ni_locked(__u32 net_id, int cpt)
1341 struct lnet_net *net;
1343 LASSERT(cpt != LNET_LOCK_EX);
1345 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1346 if (net->net_id == net_id) {
1347 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
1357 lnet_net2ni_addref(__u32 net)
1362 ni = lnet_net2ni_locked(net, 0);
1364 lnet_ni_addref_locked(ni, 0);
1369 EXPORT_SYMBOL(lnet_net2ni_addref);
1372 lnet_get_net_locked(__u32 net_id)
1374 struct lnet_net *net;
1376 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1377 if (net->net_id == net_id)
1385 lnet_nid_cpt_hash(lnet_nid_t nid, unsigned int number)
1390 LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
1395 val = hash_long(key, LNET_CPT_BITS);
1396 /* NB: LNET_CP_NUMBER doesn't have to be PO2 */
1400 return (unsigned int)(key + val + (val >> 1)) % number;
1404 lnet_cpt_of_nid_locked(lnet_nid_t nid, struct lnet_ni *ni)
1406 struct lnet_net *net;
1408 /* must called with hold of lnet_net_lock */
1409 if (LNET_CPT_NUMBER == 1)
1410 return 0; /* the only one */
1413 * If NI is provided then use the CPT identified in the NI cpt
1414 * list if one exists. If one doesn't exist, then that NI is
1415 * associated with all CPTs and it follows that the net it belongs
1416 * to is implicitly associated with all CPTs, so just hash the nid
1420 if (ni->ni_cpts != NULL)
1421 return ni->ni_cpts[lnet_nid_cpt_hash(nid,
1424 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1427 /* no NI provided so look at the net */
1428 net = lnet_get_net_locked(LNET_NIDNET(nid));
1430 if (net != NULL && net->net_cpts != NULL) {
1431 return net->net_cpts[lnet_nid_cpt_hash(nid, net->net_ncpts)];
1434 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1438 lnet_cpt_of_nid(lnet_nid_t nid, struct lnet_ni *ni)
1443 if (LNET_CPT_NUMBER == 1)
1444 return 0; /* the only one */
1446 cpt = lnet_net_lock_current();
1448 cpt2 = lnet_cpt_of_nid_locked(nid, ni);
1450 lnet_net_unlock(cpt);
1454 EXPORT_SYMBOL(lnet_cpt_of_nid);
1457 lnet_islocalnet_locked(__u32 net_id)
1459 struct lnet_net *net;
1462 net = lnet_get_net_locked(net_id);
1464 local = net != NULL;
1470 lnet_islocalnet(__u32 net_id)
1475 cpt = lnet_net_lock_current();
1477 local = lnet_islocalnet_locked(net_id);
1479 lnet_net_unlock(cpt);
1485 lnet_nid2ni_locked(lnet_nid_t nid, int cpt)
1487 struct lnet_net *net;
1490 LASSERT(cpt != LNET_LOCK_EX);
1492 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1493 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1494 if (ni->ni_nid == nid)
1503 lnet_nid2ni_addref(lnet_nid_t nid)
1508 ni = lnet_nid2ni_locked(nid, 0);
1510 lnet_ni_addref_locked(ni, 0);
1515 EXPORT_SYMBOL(lnet_nid2ni_addref);
1518 lnet_islocalnid(lnet_nid_t nid)
1523 cpt = lnet_net_lock_current();
1524 ni = lnet_nid2ni_locked(nid, cpt);
1525 lnet_net_unlock(cpt);
1531 lnet_count_acceptor_nets(void)
1533 /* Return the # of NIs that need the acceptor. */
1535 struct lnet_net *net;
1538 cpt = lnet_net_lock_current();
1539 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1540 /* all socklnd type networks should have the acceptor
1542 if (net->net_lnd->lnd_accept != NULL)
1546 lnet_net_unlock(cpt);
1551 struct lnet_ping_buffer *
1552 lnet_ping_buffer_alloc(int nnis, gfp_t gfp)
1554 struct lnet_ping_buffer *pbuf;
1556 LIBCFS_ALLOC_GFP(pbuf, LNET_PING_BUFFER_SIZE(nnis), gfp);
1558 pbuf->pb_nnis = nnis;
1559 pbuf->pb_needs_post = false;
1560 atomic_set(&pbuf->pb_refcnt, 1);
1567 lnet_ping_buffer_free(struct lnet_ping_buffer *pbuf)
1569 LASSERT(atomic_read(&pbuf->pb_refcnt) == 0);
1570 LIBCFS_FREE(pbuf, LNET_PING_BUFFER_SIZE(pbuf->pb_nnis));
1573 static struct lnet_ping_buffer *
1574 lnet_ping_target_create(int nnis)
1576 struct lnet_ping_buffer *pbuf;
1578 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
1580 CERROR("Can't allocate ping source [%d]\n", nnis);
1584 pbuf->pb_info.pi_nnis = nnis;
1585 pbuf->pb_info.pi_pid = the_lnet.ln_pid;
1586 pbuf->pb_info.pi_magic = LNET_PROTO_PING_MAGIC;
1587 pbuf->pb_info.pi_features =
1588 LNET_PING_FEAT_NI_STATUS | LNET_PING_FEAT_MULTI_RAIL;
1594 lnet_get_net_ni_count_locked(struct lnet_net *net)
1599 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1606 lnet_get_net_ni_count_pre(struct lnet_net *net)
1611 list_for_each_entry(ni, &net->net_ni_added, ni_netlist)
1618 lnet_get_ni_count(void)
1621 struct lnet_net *net;
1626 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1627 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1637 lnet_get_net_count(void)
1639 struct lnet_net *net;
1644 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1654 lnet_swap_pinginfo(struct lnet_ping_buffer *pbuf)
1656 struct lnet_ni_status *stat;
1660 __swab32s(&pbuf->pb_info.pi_magic);
1661 __swab32s(&pbuf->pb_info.pi_features);
1662 __swab32s(&pbuf->pb_info.pi_pid);
1663 __swab32s(&pbuf->pb_info.pi_nnis);
1664 nnis = pbuf->pb_info.pi_nnis;
1665 if (nnis > pbuf->pb_nnis)
1666 nnis = pbuf->pb_nnis;
1667 for (i = 0; i < nnis; i++) {
1668 stat = &pbuf->pb_info.pi_ni[i];
1669 __swab64s(&stat->ns_nid);
1670 __swab32s(&stat->ns_status);
1675 lnet_ping_info_validate(struct lnet_ping_info *pinfo)
1679 if (pinfo->pi_magic != LNET_PROTO_PING_MAGIC)
1681 if (!(pinfo->pi_features & LNET_PING_FEAT_NI_STATUS))
1683 /* Loopback is guaranteed to be present */
1684 if (pinfo->pi_nnis < 1 || pinfo->pi_nnis > lnet_interfaces_max)
1686 if (LNET_PING_INFO_LONI(pinfo) != LNET_NID_LO_0)
1692 lnet_ping_target_destroy(void)
1694 struct lnet_net *net;
1697 lnet_net_lock(LNET_LOCK_EX);
1699 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1700 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1702 ni->ni_status = NULL;
1707 lnet_ping_buffer_decref(the_lnet.ln_ping_target);
1708 the_lnet.ln_ping_target = NULL;
1710 lnet_net_unlock(LNET_LOCK_EX);
1714 lnet_ping_target_event_handler(struct lnet_event *event)
1716 struct lnet_ping_buffer *pbuf = event->md_user_ptr;
1718 if (event->unlinked)
1719 lnet_ping_buffer_decref(pbuf);
1723 lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
1724 struct lnet_handle_md *ping_mdh,
1725 int ni_count, bool set_eq)
1727 struct lnet_process_id id = {
1728 .nid = LNET_NID_ANY,
1732 struct lnet_md md = { NULL };
1736 the_lnet.ln_ping_target_handler =
1737 lnet_ping_target_event_handler;
1739 *ppbuf = lnet_ping_target_create(ni_count);
1740 if (*ppbuf == NULL) {
1745 /* Ping target ME/MD */
1746 me = LNetMEAttach(LNET_RESERVED_PORTAL, id,
1747 LNET_PROTO_PING_MATCHBITS, 0,
1748 LNET_UNLINK, LNET_INS_AFTER);
1751 CERROR("Can't create ping target ME: %d\n", rc);
1752 goto fail_decref_ping_buffer;
1755 /* initialize md content */
1756 md.start = &(*ppbuf)->pb_info;
1757 md.length = LNET_PING_INFO_SIZE((*ppbuf)->pb_nnis);
1758 md.threshold = LNET_MD_THRESH_INF;
1760 md.options = LNET_MD_OP_GET | LNET_MD_TRUNCATE |
1761 LNET_MD_MANAGE_REMOTE;
1762 md.handler = the_lnet.ln_ping_target_handler;
1763 md.user_ptr = *ppbuf;
1765 rc = LNetMDAttach(me, &md, LNET_RETAIN, ping_mdh);
1767 CERROR("Can't attach ping target MD: %d\n", rc);
1768 goto fail_decref_ping_buffer;
1770 lnet_ping_buffer_addref(*ppbuf);
1774 fail_decref_ping_buffer:
1775 LASSERT(atomic_read(&(*ppbuf)->pb_refcnt) == 1);
1776 lnet_ping_buffer_decref(*ppbuf);
1783 lnet_ping_md_unlink(struct lnet_ping_buffer *pbuf,
1784 struct lnet_handle_md *ping_mdh)
1786 LNetMDUnlink(*ping_mdh);
1787 LNetInvalidateMDHandle(ping_mdh);
1789 /* NB the MD could be busy; this just starts the unlink */
1790 wait_var_event_warning(&pbuf->pb_refcnt,
1791 atomic_read(&pbuf->pb_refcnt) <= 1,
1792 "Still waiting for ping data MD to unlink\n");
1796 lnet_ping_target_install_locked(struct lnet_ping_buffer *pbuf)
1799 struct lnet_net *net;
1800 struct lnet_ni_status *ns;
1805 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1806 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1807 LASSERT(i < pbuf->pb_nnis);
1809 ns = &pbuf->pb_info.pi_ni[i];
1811 ns->ns_nid = ni->ni_nid;
1814 ns->ns_status = (ni->ni_status != NULL) ?
1815 ni->ni_status->ns_status :
1824 * We (ab)use the ns_status of the loopback interface to
1825 * transmit the sequence number. The first interface listed
1826 * must be the loopback interface.
1828 rc = lnet_ping_info_validate(&pbuf->pb_info);
1830 LCONSOLE_EMERG("Invalid ping target: %d\n", rc);
1833 LNET_PING_BUFFER_SEQNO(pbuf) =
1834 atomic_inc_return(&the_lnet.ln_ping_target_seqno);
1838 lnet_ping_target_update(struct lnet_ping_buffer *pbuf,
1839 struct lnet_handle_md ping_mdh)
1841 struct lnet_ping_buffer *old_pbuf = NULL;
1842 struct lnet_handle_md old_ping_md;
1844 /* switch the NIs to point to the new ping info created */
1845 lnet_net_lock(LNET_LOCK_EX);
1847 if (!the_lnet.ln_routing)
1848 pbuf->pb_info.pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1849 if (!lnet_peer_discovery_disabled)
1850 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
1852 /* Ensure only known feature bits have been set. */
1853 LASSERT(pbuf->pb_info.pi_features & LNET_PING_FEAT_BITS);
1854 LASSERT(!(pbuf->pb_info.pi_features & ~LNET_PING_FEAT_BITS));
1856 lnet_ping_target_install_locked(pbuf);
1858 if (the_lnet.ln_ping_target) {
1859 old_pbuf = the_lnet.ln_ping_target;
1860 old_ping_md = the_lnet.ln_ping_target_md;
1862 the_lnet.ln_ping_target_md = ping_mdh;
1863 the_lnet.ln_ping_target = pbuf;
1865 lnet_net_unlock(LNET_LOCK_EX);
1868 /* unlink and free the old ping info */
1869 lnet_ping_md_unlink(old_pbuf, &old_ping_md);
1870 lnet_ping_buffer_decref(old_pbuf);
1873 lnet_push_update_to_peers(0);
1877 lnet_ping_target_fini(void)
1879 lnet_ping_md_unlink(the_lnet.ln_ping_target,
1880 &the_lnet.ln_ping_target_md);
1882 lnet_assert_handler_unused(the_lnet.ln_ping_target_handler);
1883 lnet_ping_target_destroy();
1886 /* Resize the push target. */
1887 int lnet_push_target_resize(void)
1889 struct lnet_handle_md mdh;
1890 struct lnet_handle_md old_mdh;
1891 struct lnet_ping_buffer *pbuf;
1892 struct lnet_ping_buffer *old_pbuf;
1897 nnis = the_lnet.ln_push_target_nnis;
1899 CDEBUG(D_NET, "Invalid nnis %d\n", nnis);
1903 /* NB: lnet_ping_buffer_alloc() sets pbuf refcount to 1. That ref is
1904 * dropped when we need to resize again (see "old_pbuf" below) or when
1905 * LNet is shutdown (see lnet_push_target_fini())
1907 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
1909 CDEBUG(D_NET, "Can't allocate pbuf for nnis %d\n", nnis);
1913 rc = lnet_push_target_post(pbuf, &mdh);
1915 CDEBUG(D_NET, "Failed to post push target: %d\n", rc);
1916 lnet_ping_buffer_decref(pbuf);
1920 lnet_net_lock(LNET_LOCK_EX);
1921 old_pbuf = the_lnet.ln_push_target;
1922 old_mdh = the_lnet.ln_push_target_md;
1923 the_lnet.ln_push_target = pbuf;
1924 the_lnet.ln_push_target_md = mdh;
1925 lnet_net_unlock(LNET_LOCK_EX);
1928 LNetMDUnlink(old_mdh);
1929 /* Drop ref set by lnet_ping_buffer_alloc() */
1930 lnet_ping_buffer_decref(old_pbuf);
1933 /* Received another push or reply that requires a larger buffer */
1934 if (nnis < the_lnet.ln_push_target_nnis)
1937 CDEBUG(D_NET, "nnis %d success\n", nnis);
1941 int lnet_push_target_post(struct lnet_ping_buffer *pbuf,
1942 struct lnet_handle_md *mdhp)
1944 struct lnet_process_id id = { LNET_NID_ANY, LNET_PID_ANY };
1945 struct lnet_md md = { NULL };
1949 me = LNetMEAttach(LNET_RESERVED_PORTAL, id,
1950 LNET_PROTO_PING_MATCHBITS, 0,
1951 LNET_UNLINK, LNET_INS_AFTER);
1954 CERROR("Can't create push target ME: %d\n", rc);
1958 pbuf->pb_needs_post = false;
1960 /* This reference is dropped by lnet_push_target_event_handler() */
1961 lnet_ping_buffer_addref(pbuf);
1963 /* initialize md content */
1964 md.start = &pbuf->pb_info;
1965 md.length = LNET_PING_INFO_SIZE(pbuf->pb_nnis);
1968 md.options = LNET_MD_OP_PUT | LNET_MD_TRUNCATE;
1970 md.handler = the_lnet.ln_push_target_handler;
1972 rc = LNetMDAttach(me, &md, LNET_UNLINK, mdhp);
1974 CERROR("Can't attach push MD: %d\n", rc);
1975 lnet_ping_buffer_decref(pbuf);
1976 pbuf->pb_needs_post = true;
1980 CDEBUG(D_NET, "posted push target %p\n", pbuf);
1985 static void lnet_push_target_event_handler(struct lnet_event *ev)
1987 struct lnet_ping_buffer *pbuf = ev->md_user_ptr;
1989 CDEBUG(D_NET, "type %d status %d unlinked %d\n", ev->type, ev->status,
1992 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
1993 lnet_swap_pinginfo(pbuf);
1995 if (ev->type == LNET_EVENT_UNLINK) {
1996 /* Drop ref added by lnet_push_target_post() */
1997 lnet_ping_buffer_decref(pbuf);
2001 lnet_peer_push_event(ev);
2003 /* Drop ref added by lnet_push_target_post */
2004 lnet_ping_buffer_decref(pbuf);
2007 /* Initialize the push target. */
2008 static int lnet_push_target_init(void)
2012 if (the_lnet.ln_push_target)
2015 the_lnet.ln_push_target_handler =
2016 lnet_push_target_event_handler;
2018 rc = LNetSetLazyPortal(LNET_RESERVED_PORTAL);
2021 /* Start at the required minimum, we'll enlarge if required. */
2022 the_lnet.ln_push_target_nnis = LNET_INTERFACES_MIN;
2024 rc = lnet_push_target_resize();
2027 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2028 the_lnet.ln_push_target_handler = NULL;
2034 /* Clean up the push target. */
2035 static void lnet_push_target_fini(void)
2037 if (!the_lnet.ln_push_target)
2040 /* Unlink and invalidate to prevent new references. */
2041 LNetMDUnlink(the_lnet.ln_push_target_md);
2042 LNetInvalidateMDHandle(&the_lnet.ln_push_target_md);
2044 /* Wait for the unlink to complete. */
2045 wait_var_event_warning(&the_lnet.ln_push_target->pb_refcnt,
2046 atomic_read(&the_lnet.ln_push_target->pb_refcnt) <= 1,
2047 "Still waiting for ping data MD to unlink\n");
2049 /* Drop ref set by lnet_ping_buffer_alloc() */
2050 lnet_ping_buffer_decref(the_lnet.ln_push_target);
2051 the_lnet.ln_push_target = NULL;
2052 the_lnet.ln_push_target_nnis = 0;
2054 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2055 lnet_assert_handler_unused(the_lnet.ln_push_target_handler);
2056 the_lnet.ln_push_target_handler = NULL;
2060 lnet_ni_tq_credits(struct lnet_ni *ni)
2064 LASSERT(ni->ni_ncpts >= 1);
2066 if (ni->ni_ncpts == 1)
2067 return ni->ni_net->net_tunables.lct_max_tx_credits;
2069 credits = ni->ni_net->net_tunables.lct_max_tx_credits / ni->ni_ncpts;
2070 credits = max(credits, 8 * ni->ni_net->net_tunables.lct_peer_tx_credits);
2071 credits = min(credits, ni->ni_net->net_tunables.lct_max_tx_credits);
2077 lnet_ni_unlink_locked(struct lnet_ni *ni)
2079 /* move it to zombie list and nobody can find it anymore */
2080 LASSERT(!list_empty(&ni->ni_netlist));
2081 list_move(&ni->ni_netlist, &ni->ni_net->net_ni_zombie);
2082 lnet_ni_decref_locked(ni, 0);
2086 lnet_clear_zombies_nis_locked(struct lnet_net *net)
2091 struct list_head *zombie_list = &net->net_ni_zombie;
2094 * Now wait for the NIs I just nuked to show up on the zombie
2095 * list and shut them down in guaranteed thread context
2098 while (!list_empty(zombie_list)) {
2102 ni = list_entry(zombie_list->next,
2103 struct lnet_ni, ni_netlist);
2104 list_del_init(&ni->ni_netlist);
2105 /* the ni should be in deleting state. If it's not it's
2107 LASSERT(ni->ni_state == LNET_NI_STATE_DELETING);
2108 cfs_percpt_for_each(ref, j, ni->ni_refs) {
2111 /* still busy, add it back to zombie list */
2112 list_add(&ni->ni_netlist, zombie_list);
2116 if (!list_empty(&ni->ni_netlist)) {
2117 lnet_net_unlock(LNET_LOCK_EX);
2119 if ((i & (-i)) == i) {
2121 "Waiting for zombie LNI %s\n",
2122 libcfs_nid2str(ni->ni_nid));
2124 schedule_timeout_uninterruptible(cfs_time_seconds(1));
2125 lnet_net_lock(LNET_LOCK_EX);
2129 lnet_net_unlock(LNET_LOCK_EX);
2131 islo = ni->ni_net->net_lnd->lnd_type == LOLND;
2133 LASSERT(!in_interrupt());
2134 /* Holding the mutex makes it safe for lnd_shutdown
2135 * to call module_put(). Module unload cannot finish
2136 * until lnet_unregister_lnd() completes, and that
2137 * requires the mutex.
2139 mutex_lock(&the_lnet.ln_lnd_mutex);
2140 (net->net_lnd->lnd_shutdown)(ni);
2141 mutex_unlock(&the_lnet.ln_lnd_mutex);
2144 CDEBUG(D_LNI, "Removed LNI %s\n",
2145 libcfs_nid2str(ni->ni_nid));
2149 lnet_net_lock(LNET_LOCK_EX);
2153 /* shutdown down the NI and release refcount */
2155 lnet_shutdown_lndni(struct lnet_ni *ni)
2158 struct lnet_net *net = ni->ni_net;
2160 lnet_net_lock(LNET_LOCK_EX);
2162 ni->ni_state = LNET_NI_STATE_DELETING;
2164 lnet_ni_unlink_locked(ni);
2165 lnet_incr_dlc_seq();
2166 lnet_net_unlock(LNET_LOCK_EX);
2168 /* clear messages for this NI on the lazy portal */
2169 for (i = 0; i < the_lnet.ln_nportals; i++)
2170 lnet_clear_lazy_portal(ni, i, "Shutting down NI");
2172 lnet_net_lock(LNET_LOCK_EX);
2173 lnet_clear_zombies_nis_locked(net);
2174 lnet_net_unlock(LNET_LOCK_EX);
2178 lnet_shutdown_lndnet(struct lnet_net *net)
2182 lnet_net_lock(LNET_LOCK_EX);
2184 list_del_init(&net->net_list);
2186 while (!list_empty(&net->net_ni_list)) {
2187 ni = list_entry(net->net_ni_list.next,
2188 struct lnet_ni, ni_netlist);
2189 lnet_net_unlock(LNET_LOCK_EX);
2190 lnet_shutdown_lndni(ni);
2191 lnet_net_lock(LNET_LOCK_EX);
2194 lnet_net_unlock(LNET_LOCK_EX);
2196 /* Do peer table cleanup for this net */
2197 lnet_peer_tables_cleanup(net);
2203 lnet_shutdown_lndnets(void)
2205 struct lnet_net *net;
2207 struct lnet_msg *msg, *tmp;
2209 /* NB called holding the global mutex */
2211 /* All quiet on the API front */
2212 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
2213 LASSERT(the_lnet.ln_refcount == 0);
2215 lnet_net_lock(LNET_LOCK_EX);
2216 the_lnet.ln_state = LNET_STATE_STOPPING;
2219 * move the nets to the zombie list to avoid them being
2220 * picked up for new work. LONET is also included in the
2221 * Nets that will be moved to the zombie list
2223 list_splice_init(&the_lnet.ln_nets, &the_lnet.ln_net_zombie);
2225 /* Drop the cached loopback Net. */
2226 if (the_lnet.ln_loni != NULL) {
2227 lnet_ni_decref_locked(the_lnet.ln_loni, 0);
2228 the_lnet.ln_loni = NULL;
2230 lnet_net_unlock(LNET_LOCK_EX);
2232 /* iterate through the net zombie list and delete each net */
2233 while (!list_empty(&the_lnet.ln_net_zombie)) {
2234 net = list_entry(the_lnet.ln_net_zombie.next,
2235 struct lnet_net, net_list);
2236 lnet_shutdown_lndnet(net);
2239 spin_lock(&the_lnet.ln_msg_resend_lock);
2240 list_splice(&the_lnet.ln_msg_resend, &resend);
2241 spin_unlock(&the_lnet.ln_msg_resend_lock);
2243 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
2244 list_del_init(&msg->msg_list);
2245 msg->msg_no_resend = true;
2246 lnet_finalize(msg, -ECANCELED);
2249 lnet_net_lock(LNET_LOCK_EX);
2250 the_lnet.ln_state = LNET_STATE_SHUTDOWN;
2251 lnet_net_unlock(LNET_LOCK_EX);
2255 lnet_startup_lndni(struct lnet_ni *ni, struct lnet_lnd_tunables *tun)
2258 struct lnet_tx_queue *tq;
2260 struct lnet_net *net = ni->ni_net;
2262 mutex_lock(&the_lnet.ln_lnd_mutex);
2265 memcpy(&ni->ni_lnd_tunables, tun, sizeof(*tun));
2266 ni->ni_lnd_tunables_set = true;
2269 rc = (net->net_lnd->lnd_startup)(ni);
2271 mutex_unlock(&the_lnet.ln_lnd_mutex);
2274 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s\n",
2275 rc, libcfs_lnd2str(net->net_lnd->lnd_type));
2280 ni->ni_state = LNET_NI_STATE_ACTIVE;
2283 /* We keep a reference on the loopback net through the loopback NI */
2284 if (net->net_lnd->lnd_type == LOLND) {
2286 LASSERT(the_lnet.ln_loni == NULL);
2287 the_lnet.ln_loni = ni;
2288 ni->ni_net->net_tunables.lct_peer_tx_credits = 0;
2289 ni->ni_net->net_tunables.lct_peer_rtr_credits = 0;
2290 ni->ni_net->net_tunables.lct_max_tx_credits = 0;
2291 ni->ni_net->net_tunables.lct_peer_timeout = 0;
2295 if (ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ||
2296 ni->ni_net->net_tunables.lct_max_tx_credits == 0) {
2297 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
2298 libcfs_lnd2str(net->net_lnd->lnd_type),
2299 ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ?
2301 /* shutdown the NI since if we get here then it must've already
2304 lnet_shutdown_lndni(ni);
2308 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
2309 tq->tq_credits_min =
2310 tq->tq_credits_max =
2311 tq->tq_credits = lnet_ni_tq_credits(ni);
2314 atomic_set(&ni->ni_tx_credits,
2315 lnet_ni_tq_credits(ni) * ni->ni_ncpts);
2316 atomic_set(&ni->ni_healthv, LNET_MAX_HEALTH_VALUE);
2318 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d/%d]\n",
2319 libcfs_nid2str(ni->ni_nid),
2320 ni->ni_net->net_tunables.lct_peer_tx_credits,
2321 lnet_ni_tq_credits(ni) * LNET_CPT_NUMBER,
2322 ni->ni_net->net_tunables.lct_peer_rtr_credits,
2323 ni->ni_net->net_tunables.lct_peer_timeout);
2332 lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
2335 struct lnet_net *net_l = NULL;
2336 LIST_HEAD(local_ni_list);
2340 const struct lnet_lnd *lnd;
2342 net->net_tunables.lct_peer_timeout;
2344 net->net_tunables.lct_max_tx_credits;
2345 int peerrtrcredits =
2346 net->net_tunables.lct_peer_rtr_credits;
2349 * make sure that this net is unique. If it isn't then
2350 * we are adding interfaces to an already existing network, and
2351 * 'net' is just a convenient way to pass in the list.
2352 * if it is unique we need to find the LND and load it if
2355 if (lnet_net_unique(net->net_id, &the_lnet.ln_nets, &net_l)) {
2356 lnd_type = LNET_NETTYP(net->net_id);
2358 mutex_lock(&the_lnet.ln_lnd_mutex);
2359 lnd = lnet_find_lnd_by_type(lnd_type);
2362 mutex_unlock(&the_lnet.ln_lnd_mutex);
2363 rc = request_module("%s", libcfs_lnd2modname(lnd_type));
2364 mutex_lock(&the_lnet.ln_lnd_mutex);
2366 lnd = lnet_find_lnd_by_type(lnd_type);
2368 mutex_unlock(&the_lnet.ln_lnd_mutex);
2369 CERROR("Can't load LND %s, module %s, rc=%d\n",
2370 libcfs_lnd2str(lnd_type),
2371 libcfs_lnd2modname(lnd_type), rc);
2372 #ifndef HAVE_MODULE_LOADING_SUPPORT
2373 LCONSOLE_ERROR_MSG(0x104, "Your kernel must be "
2374 "compiled with kernel module "
2375 "loading support.");
2384 mutex_unlock(&the_lnet.ln_lnd_mutex);
2390 * net_l: if the network being added is unique then net_l
2391 * will point to that network
2392 * if the network being added is not unique then
2393 * net_l points to the existing network.
2395 * When we enter the loop below, we'll pick NIs off he
2396 * network beign added and start them up, then add them to
2397 * a local ni list. Once we've successfully started all
2398 * the NIs then we join the local NI list (of started up
2399 * networks) with the net_l->net_ni_list, which should
2400 * point to the correct network to add the new ni list to
2402 * If any of the new NIs fail to start up, then we want to
2403 * iterate through the local ni list, which should include
2404 * any NIs which were successfully started up, and shut
2407 * After than we want to delete the network being added,
2408 * to avoid a memory leak.
2412 * When a network uses TCP bonding then all its interfaces
2413 * must be specified when the network is first defined: the
2414 * TCP bonding code doesn't allow for interfaces to be added
2417 if (net_l != net && net_l != NULL && use_tcp_bonding &&
2418 LNET_NETTYP(net_l->net_id) == SOCKLND) {
2423 while (!list_empty(&net->net_ni_added)) {
2424 ni = list_entry(net->net_ni_added.next, struct lnet_ni,
2426 list_del_init(&ni->ni_netlist);
2428 /* make sure that the the NI we're about to start
2429 * up is actually unique. if it's not fail. */
2430 if (!lnet_ni_unique_net(&net_l->net_ni_list,
2431 ni->ni_interfaces[0])) {
2436 /* adjust the pointer the parent network, just in case it
2437 * the net is a duplicate */
2440 rc = lnet_startup_lndni(ni, tun);
2446 list_add_tail(&ni->ni_netlist, &local_ni_list);
2451 lnet_net_lock(LNET_LOCK_EX);
2452 list_splice_tail(&local_ni_list, &net_l->net_ni_list);
2453 lnet_incr_dlc_seq();
2454 lnet_net_unlock(LNET_LOCK_EX);
2456 /* if the network is not unique then we don't want to keep
2457 * it around after we're done. Free it. Otherwise add that
2458 * net to the global the_lnet.ln_nets */
2459 if (net_l != net && net_l != NULL) {
2461 * TODO - note. currently the tunables can not be updated
2467 * restore tunables after it has been overwitten by the
2470 if (peer_timeout != -1)
2471 net->net_tunables.lct_peer_timeout = peer_timeout;
2472 if (maxtxcredits != -1)
2473 net->net_tunables.lct_max_tx_credits = maxtxcredits;
2474 if (peerrtrcredits != -1)
2475 net->net_tunables.lct_peer_rtr_credits = peerrtrcredits;
2477 lnet_net_lock(LNET_LOCK_EX);
2478 list_add_tail(&net->net_list, &the_lnet.ln_nets);
2479 lnet_net_unlock(LNET_LOCK_EX);
2482 /* update net count */
2483 lnet_current_net_count = lnet_get_net_count();
2489 * shutdown the new NIs that are being started up
2490 * free the NET being started
2492 while (!list_empty(&local_ni_list)) {
2493 ni = list_entry(local_ni_list.next, struct lnet_ni,
2496 lnet_shutdown_lndni(ni);
2506 lnet_startup_lndnets(struct list_head *netlist)
2508 struct lnet_net *net;
2513 * Change to running state before bringing up the LNDs. This
2514 * allows lnet_shutdown_lndnets() to assert that we've passed
2517 lnet_net_lock(LNET_LOCK_EX);
2518 the_lnet.ln_state = LNET_STATE_RUNNING;
2519 lnet_net_unlock(LNET_LOCK_EX);
2521 while (!list_empty(netlist)) {
2522 net = list_entry(netlist->next, struct lnet_net, net_list);
2523 list_del_init(&net->net_list);
2525 rc = lnet_startup_lndnet(net, NULL);
2535 lnet_shutdown_lndnets();
2541 * Initialize LNet library.
2543 * Automatically called at module loading time. Caller has to call
2544 * lnet_lib_exit() after a call to lnet_lib_init(), if and only if the
2545 * latter returned 0. It must be called exactly once.
2547 * \retval 0 on success
2548 * \retval -ve on failures.
2550 int lnet_lib_init(void)
2554 lnet_assert_wire_constants();
2556 /* refer to global cfs_cpt_table for now */
2557 the_lnet.ln_cpt_table = cfs_cpt_tab;
2558 the_lnet.ln_cpt_number = cfs_cpt_number(cfs_cpt_tab);
2560 LASSERT(the_lnet.ln_cpt_number > 0);
2561 if (the_lnet.ln_cpt_number > LNET_CPT_MAX) {
2562 /* we are under risk of consuming all lh_cookie */
2563 CERROR("Can't have %d CPTs for LNet (max allowed is %d), "
2564 "please change setting of CPT-table and retry\n",
2565 the_lnet.ln_cpt_number, LNET_CPT_MAX);
2569 while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number)
2570 the_lnet.ln_cpt_bits++;
2572 rc = lnet_create_locks();
2574 CERROR("Can't create LNet global locks: %d\n", rc);
2578 the_lnet.ln_refcount = 0;
2579 INIT_LIST_HEAD(&the_lnet.ln_net_zombie);
2580 INIT_LIST_HEAD(&the_lnet.ln_msg_resend);
2582 /* The hash table size is the number of bits it takes to express the set
2583 * ln_num_routes, minus 1 (better to under estimate than over so we
2584 * don't waste memory). */
2585 if (rnet_htable_size <= 0)
2586 rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
2587 else if (rnet_htable_size > LNET_REMOTE_NETS_HASH_MAX)
2588 rnet_htable_size = LNET_REMOTE_NETS_HASH_MAX;
2589 the_lnet.ln_remote_nets_hbits = max_t(int, 1,
2590 order_base_2(rnet_htable_size) - 1);
2592 /* All LNDs apart from the LOLND are in separate modules. They
2593 * register themselves when their module loads, and unregister
2594 * themselves when their module is unloaded. */
2595 lnet_register_lnd(&the_lolnd);
2600 * Finalize LNet library.
2602 * \pre lnet_lib_init() called with success.
2603 * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls.
2605 * As this happens at module-unload, all lnds must already be unloaded,
2606 * so they must already be unregistered.
2608 void lnet_lib_exit(void)
2612 LASSERT(the_lnet.ln_refcount == 0);
2613 lnet_unregister_lnd(&the_lolnd);
2614 for (i = 0; i < NUM_LNDS; i++)
2615 LASSERT(!the_lnet.ln_lnds[i]);
2616 lnet_destroy_locks();
2620 * Set LNet PID and start LNet interfaces, routing, and forwarding.
2622 * Users must call this function at least once before any other functions.
2623 * For each successful call there must be a corresponding call to
2624 * LNetNIFini(). For subsequent calls to LNetNIInit(), \a requested_pid is
2627 * The PID used by LNet may be different from the one requested.
2630 * \param requested_pid PID requested by the caller.
2632 * \return >= 0 on success, and < 0 error code on failures.
2635 LNetNIInit(lnet_pid_t requested_pid)
2637 int im_a_router = 0;
2640 struct lnet_ping_buffer *pbuf;
2641 struct lnet_handle_md ping_mdh;
2642 LIST_HEAD(net_head);
2643 struct lnet_net *net;
2645 mutex_lock(&the_lnet.ln_api_mutex);
2647 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
2649 if (the_lnet.ln_refcount > 0) {
2650 rc = the_lnet.ln_refcount++;
2651 mutex_unlock(&the_lnet.ln_api_mutex);
2655 rc = lnet_prepare(requested_pid);
2657 mutex_unlock(&the_lnet.ln_api_mutex);
2661 /* create a network for Loopback network */
2662 net = lnet_net_alloc(LNET_MKNET(LOLND, 0), &net_head);
2665 goto err_empty_list;
2668 /* Add in the loopback NI */
2669 if (lnet_ni_alloc(net, NULL, NULL) == NULL) {
2671 goto err_empty_list;
2674 /* If LNet is being initialized via DLC it is possible
2675 * that the user requests not to load module parameters (ones which
2676 * are supported by DLC) on initialization. Therefore, make sure not
2677 * to load networks, routes and forwarding from module parameters
2678 * in this case. On cleanup in case of failure only clean up
2679 * routes if it has been loaded */
2680 if (!the_lnet.ln_nis_from_mod_params) {
2681 rc = lnet_parse_networks(&net_head, lnet_get_networks(),
2684 goto err_empty_list;
2687 ni_count = lnet_startup_lndnets(&net_head);
2690 goto err_empty_list;
2693 if (!the_lnet.ln_nis_from_mod_params) {
2694 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
2696 goto err_shutdown_lndnis;
2698 rc = lnet_rtrpools_alloc(im_a_router);
2700 goto err_destroy_routes;
2703 rc = lnet_acceptor_start();
2705 goto err_destroy_routes;
2707 the_lnet.ln_refcount = 1;
2708 /* Now I may use my own API functions... */
2710 rc = lnet_ping_target_setup(&pbuf, &ping_mdh, ni_count, true);
2712 goto err_acceptor_stop;
2714 lnet_ping_target_update(pbuf, ping_mdh);
2716 the_lnet.ln_mt_handler = lnet_mt_event_handler;
2718 rc = lnet_push_target_init();
2722 rc = lnet_peer_discovery_start();
2724 goto err_destroy_push_target;
2726 rc = lnet_monitor_thr_start();
2728 goto err_stop_discovery_thr;
2731 lnet_router_debugfs_init();
2733 mutex_unlock(&the_lnet.ln_api_mutex);
2735 complete_all(&the_lnet.ln_started);
2737 /* wait for all routers to start */
2738 lnet_wait_router_start();
2742 err_stop_discovery_thr:
2743 lnet_peer_discovery_stop();
2744 err_destroy_push_target:
2745 lnet_push_target_fini();
2747 lnet_ping_target_fini();
2749 the_lnet.ln_refcount = 0;
2750 lnet_acceptor_stop();
2752 if (!the_lnet.ln_nis_from_mod_params)
2753 lnet_destroy_routes();
2754 err_shutdown_lndnis:
2755 lnet_shutdown_lndnets();
2759 mutex_unlock(&the_lnet.ln_api_mutex);
2760 while (!list_empty(&net_head)) {
2761 struct lnet_net *net;
2763 net = list_entry(net_head.next, struct lnet_net, net_list);
2764 list_del_init(&net->net_list);
2769 EXPORT_SYMBOL(LNetNIInit);
2772 * Stop LNet interfaces, routing, and forwarding.
2774 * Users must call this function once for each successful call to LNetNIInit().
2775 * Once the LNetNIFini() operation has been started, the results of pending
2776 * API operations are undefined.
2778 * \return always 0 for current implementation.
2783 mutex_lock(&the_lnet.ln_api_mutex);
2785 LASSERT(the_lnet.ln_refcount > 0);
2787 if (the_lnet.ln_refcount != 1) {
2788 the_lnet.ln_refcount--;
2790 LASSERT(!the_lnet.ln_niinit_self);
2794 lnet_router_debugfs_fini();
2795 lnet_monitor_thr_stop();
2796 lnet_peer_discovery_stop();
2797 lnet_push_target_fini();
2798 lnet_ping_target_fini();
2800 /* Teardown fns that use my own API functions BEFORE here */
2801 the_lnet.ln_refcount = 0;
2803 lnet_acceptor_stop();
2804 lnet_destroy_routes();
2805 lnet_shutdown_lndnets();
2809 mutex_unlock(&the_lnet.ln_api_mutex);
2812 EXPORT_SYMBOL(LNetNIFini);
2815 * Grabs the ni data from the ni structure and fills the out
2818 * \param[in] ni network interface structure
2819 * \param[out] cfg_ni NI config information
2820 * \param[out] tun network and LND tunables
2823 lnet_fill_ni_info(struct lnet_ni *ni, struct lnet_ioctl_config_ni *cfg_ni,
2824 struct lnet_ioctl_config_lnd_tunables *tun,
2825 struct lnet_ioctl_element_stats *stats,
2828 size_t min_size = 0;
2831 if (!ni || !cfg_ni || !tun)
2834 if (ni->ni_interfaces[0] != NULL) {
2835 for (i = 0; i < ARRAY_SIZE(ni->ni_interfaces); i++) {
2836 if (ni->ni_interfaces[i] != NULL) {
2837 strncpy(cfg_ni->lic_ni_intf[i],
2838 ni->ni_interfaces[i],
2839 sizeof(cfg_ni->lic_ni_intf[i]));
2844 cfg_ni->lic_nid = ni->ni_nid;
2845 if (ni->ni_nid == LNET_NID_LO_0)
2846 cfg_ni->lic_status = LNET_NI_STATUS_UP;
2848 cfg_ni->lic_status = ni->ni_status->ns_status;
2849 cfg_ni->lic_tcp_bonding = use_tcp_bonding;
2850 cfg_ni->lic_dev_cpt = ni->ni_dev_cpt;
2852 memcpy(&tun->lt_cmn, &ni->ni_net->net_tunables, sizeof(tun->lt_cmn));
2855 stats->iel_send_count = lnet_sum_stats(&ni->ni_stats,
2856 LNET_STATS_TYPE_SEND);
2857 stats->iel_recv_count = lnet_sum_stats(&ni->ni_stats,
2858 LNET_STATS_TYPE_RECV);
2859 stats->iel_drop_count = lnet_sum_stats(&ni->ni_stats,
2860 LNET_STATS_TYPE_DROP);
2864 * tun->lt_tun will always be present, but in order to be
2865 * backwards compatible, we need to deal with the cases when
2866 * tun->lt_tun is smaller than what the kernel has, because it
2867 * comes from an older version of a userspace program, then we'll
2868 * need to copy as much information as we have available space.
2870 min_size = tun_size - sizeof(tun->lt_cmn);
2871 memcpy(&tun->lt_tun, &ni->ni_lnd_tunables, min_size);
2873 /* copy over the cpts */
2874 if (ni->ni_ncpts == LNET_CPT_NUMBER &&
2875 ni->ni_cpts == NULL) {
2876 for (i = 0; i < ni->ni_ncpts; i++)
2877 cfg_ni->lic_cpts[i] = i;
2880 ni->ni_cpts != NULL && i < ni->ni_ncpts &&
2881 i < LNET_MAX_SHOW_NUM_CPT;
2883 cfg_ni->lic_cpts[i] = ni->ni_cpts[i];
2885 cfg_ni->lic_ncpts = ni->ni_ncpts;
2889 * NOTE: This is a legacy function left in the code to be backwards
2890 * compatible with older userspace programs. It should eventually be
2893 * Grabs the ni data from the ni structure and fills the out
2896 * \param[in] ni network interface structure
2897 * \param[out] config config information
2900 lnet_fill_ni_info_legacy(struct lnet_ni *ni,
2901 struct lnet_ioctl_config_data *config)
2903 struct lnet_ioctl_net_config *net_config;
2904 struct lnet_ioctl_config_lnd_tunables *lnd_cfg = NULL;
2905 size_t min_size, tunable_size = 0;
2911 net_config = (struct lnet_ioctl_net_config *) config->cfg_bulk;
2915 BUILD_BUG_ON(ARRAY_SIZE(ni->ni_interfaces) !=
2916 ARRAY_SIZE(net_config->ni_interfaces));
2918 for (i = 0; i < ARRAY_SIZE(ni->ni_interfaces); i++) {
2919 if (!ni->ni_interfaces[i])
2922 strncpy(net_config->ni_interfaces[i],
2923 ni->ni_interfaces[i],
2924 sizeof(net_config->ni_interfaces[i]));
2927 config->cfg_nid = ni->ni_nid;
2928 config->cfg_config_u.cfg_net.net_peer_timeout =
2929 ni->ni_net->net_tunables.lct_peer_timeout;
2930 config->cfg_config_u.cfg_net.net_max_tx_credits =
2931 ni->ni_net->net_tunables.lct_max_tx_credits;
2932 config->cfg_config_u.cfg_net.net_peer_tx_credits =
2933 ni->ni_net->net_tunables.lct_peer_tx_credits;
2934 config->cfg_config_u.cfg_net.net_peer_rtr_credits =
2935 ni->ni_net->net_tunables.lct_peer_rtr_credits;
2937 if (ni->ni_nid == LNET_NID_LO_0)
2938 net_config->ni_status = LNET_NI_STATUS_UP;
2940 net_config->ni_status = ni->ni_status->ns_status;
2943 int num_cpts = min(ni->ni_ncpts, LNET_MAX_SHOW_NUM_CPT);
2945 for (i = 0; i < num_cpts; i++)
2946 net_config->ni_cpts[i] = ni->ni_cpts[i];
2948 config->cfg_ncpts = num_cpts;
2952 * See if user land tools sent in a newer and larger version
2953 * of struct lnet_tunables than what the kernel uses.
2955 min_size = sizeof(*config) + sizeof(*net_config);
2957 if (config->cfg_hdr.ioc_len > min_size)
2958 tunable_size = config->cfg_hdr.ioc_len - min_size;
2960 /* Don't copy too much data to user space */
2961 min_size = min(tunable_size, sizeof(ni->ni_lnd_tunables));
2962 lnd_cfg = (struct lnet_ioctl_config_lnd_tunables *)net_config->cfg_bulk;
2964 if (lnd_cfg && min_size) {
2965 memcpy(&lnd_cfg->lt_tun, &ni->ni_lnd_tunables, min_size);
2966 config->cfg_config_u.cfg_net.net_interface_count = 1;
2968 /* Tell user land that kernel side has less data */
2969 if (tunable_size > sizeof(ni->ni_lnd_tunables)) {
2970 min_size = tunable_size - sizeof(ni->ni_lnd_tunables);
2971 config->cfg_hdr.ioc_len -= min_size;
2977 lnet_get_ni_idx_locked(int idx)
2980 struct lnet_net *net;
2982 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
2983 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
2993 lnet_get_next_ni_locked(struct lnet_net *mynet, struct lnet_ni *prev)
2996 struct lnet_net *net = mynet;
2999 * It is possible that the net has been cleaned out while there is
3000 * a message being sent. This function accessed the net without
3001 * checking if the list is empty
3005 net = list_entry(the_lnet.ln_nets.next, struct lnet_net,
3007 if (list_empty(&net->net_ni_list))
3009 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
3015 if (prev->ni_netlist.next == &prev->ni_net->net_ni_list) {
3016 /* if you reached the end of the ni list and the net is
3017 * specified, then there are no more nis in that net */
3021 /* we reached the end of this net ni list. move to the
3023 if (prev->ni_net->net_list.next == &the_lnet.ln_nets)
3024 /* no more nets and no more NIs. */
3027 /* get the next net */
3028 net = list_entry(prev->ni_net->net_list.next, struct lnet_net,
3030 if (list_empty(&net->net_ni_list))
3032 /* get the ni on it */
3033 ni = list_entry(net->net_ni_list.next, struct lnet_ni,
3039 if (list_empty(&prev->ni_netlist))
3042 /* there are more nis left */
3043 ni = list_entry(prev->ni_netlist.next, struct lnet_ni, ni_netlist);
3049 lnet_get_net_config(struct lnet_ioctl_config_data *config)
3054 int idx = config->cfg_count;
3056 cpt = lnet_net_lock_current();
3058 ni = lnet_get_ni_idx_locked(idx);
3063 lnet_fill_ni_info_legacy(ni, config);
3067 lnet_net_unlock(cpt);
3072 lnet_get_ni_config(struct lnet_ioctl_config_ni *cfg_ni,
3073 struct lnet_ioctl_config_lnd_tunables *tun,
3074 struct lnet_ioctl_element_stats *stats,
3081 if (!cfg_ni || !tun || !stats)
3084 cpt = lnet_net_lock_current();
3086 ni = lnet_get_ni_idx_locked(cfg_ni->lic_idx);
3091 lnet_fill_ni_info(ni, cfg_ni, tun, stats, tun_size);
3095 lnet_net_unlock(cpt);
3099 int lnet_get_ni_stats(struct lnet_ioctl_element_msg_stats *msg_stats)
3108 cpt = lnet_net_lock_current();
3110 ni = lnet_get_ni_idx_locked(msg_stats->im_idx);
3113 lnet_usr_translate_stats(msg_stats, &ni->ni_stats);
3117 lnet_net_unlock(cpt);
3122 static int lnet_add_net_common(struct lnet_net *net,
3123 struct lnet_ioctl_config_lnd_tunables *tun)
3126 struct lnet_ping_buffer *pbuf;
3127 struct lnet_handle_md ping_mdh;
3129 struct lnet_remotenet *rnet;
3132 lnet_net_lock(LNET_LOCK_EX);
3133 rnet = lnet_find_rnet_locked(net->net_id);
3134 lnet_net_unlock(LNET_LOCK_EX);
3136 * make sure that the net added doesn't invalidate the current
3137 * configuration LNet is keeping
3140 CERROR("Adding net %s will invalidate routing configuration\n",
3141 libcfs_net2str(net->net_id));
3147 * make sure you calculate the correct number of slots in the ping
3148 * buffer. Since the ping info is a flattened list of all the NIs,
3149 * we should allocate enough slots to accomodate the number of NIs
3150 * which will be added.
3152 * since ni hasn't been configured yet, use
3153 * lnet_get_net_ni_count_pre() which checks the net_ni_added list
3155 net_ni_count = lnet_get_net_ni_count_pre(net);
3157 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3158 net_ni_count + lnet_get_ni_count(),
3166 memcpy(&net->net_tunables,
3167 &tun->lt_cmn, sizeof(net->net_tunables));
3169 memset(&net->net_tunables, -1, sizeof(net->net_tunables));
3171 net_id = net->net_id;
3173 rc = lnet_startup_lndnet(net,
3174 (tun) ? &tun->lt_tun : NULL);
3178 lnet_net_lock(LNET_LOCK_EX);
3179 net = lnet_get_net_locked(net_id);
3180 lnet_net_unlock(LNET_LOCK_EX);
3185 * Start the acceptor thread if this is the first network
3186 * being added that requires the thread.
3188 if (net->net_lnd->lnd_accept) {
3189 rc = lnet_acceptor_start();
3191 /* shutdown the net that we just started */
3192 CERROR("Failed to start up acceptor thread\n");
3193 lnet_shutdown_lndnet(net);
3198 lnet_net_lock(LNET_LOCK_EX);
3199 lnet_peer_net_added(net);
3200 lnet_net_unlock(LNET_LOCK_EX);
3202 lnet_ping_target_update(pbuf, ping_mdh);
3207 lnet_ping_md_unlink(pbuf, &ping_mdh);
3208 lnet_ping_buffer_decref(pbuf);
3213 lnet_set_tune_defaults(struct lnet_ioctl_config_lnd_tunables *tun)
3216 if (!tun->lt_cmn.lct_peer_timeout)
3217 tun->lt_cmn.lct_peer_timeout = DEFAULT_PEER_TIMEOUT;
3218 if (!tun->lt_cmn.lct_peer_tx_credits)
3219 tun->lt_cmn.lct_peer_tx_credits = DEFAULT_PEER_CREDITS;
3220 if (!tun->lt_cmn.lct_max_tx_credits)
3221 tun->lt_cmn.lct_max_tx_credits = DEFAULT_CREDITS;
3225 static int lnet_handle_legacy_ip2nets(char *ip2nets,
3226 struct lnet_ioctl_config_lnd_tunables *tun)
3228 struct lnet_net *net;
3231 LIST_HEAD(net_head);
3233 rc = lnet_parse_ip2nets(&nets, ip2nets);
3237 rc = lnet_parse_networks(&net_head, nets, use_tcp_bonding);
3241 lnet_set_tune_defaults(tun);
3243 mutex_lock(&the_lnet.ln_api_mutex);
3244 while (!list_empty(&net_head)) {
3245 net = list_entry(net_head.next, struct lnet_net, net_list);
3246 list_del_init(&net->net_list);
3247 rc = lnet_add_net_common(net, tun);
3253 mutex_unlock(&the_lnet.ln_api_mutex);
3255 while (!list_empty(&net_head)) {
3256 net = list_entry(net_head.next, struct lnet_net, net_list);
3257 list_del_init(&net->net_list);
3263 int lnet_dyn_add_ni(struct lnet_ioctl_config_ni *conf)
3265 struct lnet_net *net;
3267 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
3269 __u32 net_id, lnd_type;
3271 /* get the tunables if they are available */
3272 if (conf->lic_cfg_hdr.ioc_len >=
3273 sizeof(*conf) + sizeof(*tun))
3274 tun = (struct lnet_ioctl_config_lnd_tunables *)
3277 /* handle legacy ip2nets from DLC */
3278 if (conf->lic_legacy_ip2nets[0] != '\0')
3279 return lnet_handle_legacy_ip2nets(conf->lic_legacy_ip2nets,
3282 net_id = LNET_NIDNET(conf->lic_nid);
3283 lnd_type = LNET_NETTYP(net_id);
3285 if (!libcfs_isknown_lnd(lnd_type)) {
3286 CERROR("No valid net and lnd information provided\n");
3290 net = lnet_net_alloc(net_id, NULL);
3294 for (i = 0; i < conf->lic_ncpts; i++) {
3295 if (conf->lic_cpts[i] >= LNET_CPT_NUMBER)
3299 ni = lnet_ni_alloc_w_cpt_array(net, conf->lic_cpts, conf->lic_ncpts,
3300 conf->lic_ni_intf[0]);
3304 lnet_set_tune_defaults(tun);
3306 mutex_lock(&the_lnet.ln_api_mutex);
3308 rc = lnet_add_net_common(net, tun);
3310 mutex_unlock(&the_lnet.ln_api_mutex);
3315 int lnet_dyn_del_ni(struct lnet_ioctl_config_ni *conf)
3317 struct lnet_net *net;
3319 __u32 net_id = LNET_NIDNET(conf->lic_nid);
3320 struct lnet_ping_buffer *pbuf;
3321 struct lnet_handle_md ping_mdh;
3326 /* don't allow userspace to shutdown the LOLND */
3327 if (LNET_NETTYP(net_id) == LOLND)
3330 mutex_lock(&the_lnet.ln_api_mutex);
3334 net = lnet_get_net_locked(net_id);
3336 CERROR("net %s not found\n",
3337 libcfs_net2str(net_id));
3342 addr = LNET_NIDADDR(conf->lic_nid);
3344 /* remove the entire net */
3345 net_count = lnet_get_net_ni_count_locked(net);
3349 /* create and link a new ping info, before removing the old one */
3350 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3351 lnet_get_ni_count() - net_count,
3354 goto unlock_api_mutex;
3356 lnet_shutdown_lndnet(net);
3358 lnet_acceptor_stop();
3360 lnet_ping_target_update(pbuf, ping_mdh);
3362 goto unlock_api_mutex;
3365 ni = lnet_nid2ni_locked(conf->lic_nid, 0);
3367 CERROR("nid %s not found\n",
3368 libcfs_nid2str(conf->lic_nid));
3373 net_count = lnet_get_net_ni_count_locked(net);
3377 /* create and link a new ping info, before removing the old one */
3378 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3379 lnet_get_ni_count() - 1, false);
3381 goto unlock_api_mutex;
3383 lnet_shutdown_lndni(ni);
3385 lnet_acceptor_stop();
3387 lnet_ping_target_update(pbuf, ping_mdh);
3389 /* check if the net is empty and remove it if it is */
3391 lnet_shutdown_lndnet(net);
3393 goto unlock_api_mutex;
3398 mutex_unlock(&the_lnet.ln_api_mutex);
3404 * lnet_dyn_add_net and lnet_dyn_del_net are now deprecated.
3405 * They are only expected to be called for unique networks.
3406 * That can be as a result of older DLC library
3407 * calls. Multi-Rail DLC and beyond no longer uses these APIs.
3410 lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
3412 struct lnet_net *net;
3413 LIST_HEAD(net_head);
3415 struct lnet_ioctl_config_lnd_tunables tun;
3416 const char *nets = conf->cfg_config_u.cfg_net.net_intf;
3418 /* Create a net/ni structures for the network string */
3419 rc = lnet_parse_networks(&net_head, nets, use_tcp_bonding);
3421 return rc == 0 ? -EINVAL : rc;
3423 mutex_lock(&the_lnet.ln_api_mutex);
3426 rc = -EINVAL; /* only add one network per call */
3427 goto out_unlock_clean;
3430 net = list_entry(net_head.next, struct lnet_net, net_list);
3431 list_del_init(&net->net_list);
3433 LASSERT(lnet_net_unique(net->net_id, &the_lnet.ln_nets, NULL));
3435 memset(&tun, 0, sizeof(tun));
3437 tun.lt_cmn.lct_peer_timeout =
3438 (!conf->cfg_config_u.cfg_net.net_peer_timeout) ? DEFAULT_PEER_TIMEOUT :
3439 conf->cfg_config_u.cfg_net.net_peer_timeout;
3440 tun.lt_cmn.lct_peer_tx_credits =
3441 (!conf->cfg_config_u.cfg_net.net_peer_tx_credits) ? DEFAULT_PEER_CREDITS :
3442 conf->cfg_config_u.cfg_net.net_peer_tx_credits;
3443 tun.lt_cmn.lct_peer_rtr_credits =
3444 conf->cfg_config_u.cfg_net.net_peer_rtr_credits;
3445 tun.lt_cmn.lct_max_tx_credits =
3446 (!conf->cfg_config_u.cfg_net.net_max_tx_credits) ? DEFAULT_CREDITS :
3447 conf->cfg_config_u.cfg_net.net_max_tx_credits;
3449 rc = lnet_add_net_common(net, &tun);
3452 mutex_unlock(&the_lnet.ln_api_mutex);
3453 while (!list_empty(&net_head)) {
3454 /* net_head list is empty in success case */
3455 net = list_entry(net_head.next, struct lnet_net, net_list);
3456 list_del_init(&net->net_list);
3463 lnet_dyn_del_net(__u32 net_id)
3465 struct lnet_net *net;
3466 struct lnet_ping_buffer *pbuf;
3467 struct lnet_handle_md ping_mdh;
3471 /* don't allow userspace to shutdown the LOLND */
3472 if (LNET_NETTYP(net_id) == LOLND)
3475 mutex_lock(&the_lnet.ln_api_mutex);
3479 net = lnet_get_net_locked(net_id);
3486 net_ni_count = lnet_get_net_ni_count_locked(net);
3490 /* create and link a new ping info, before removing the old one */
3491 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3492 lnet_get_ni_count() - net_ni_count, false);
3496 lnet_shutdown_lndnet(net);
3498 lnet_acceptor_stop();
3500 lnet_ping_target_update(pbuf, ping_mdh);
3503 mutex_unlock(&the_lnet.ln_api_mutex);
3508 void lnet_incr_dlc_seq(void)
3510 atomic_inc(&lnet_dlc_seq_no);
3513 __u32 lnet_get_dlc_seq_locked(void)
3515 return atomic_read(&lnet_dlc_seq_no);
3519 lnet_ni_set_healthv(lnet_nid_t nid, int value, bool all)
3521 struct lnet_net *net;
3524 lnet_net_lock(LNET_LOCK_EX);
3525 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3526 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3527 if (ni->ni_nid == nid || all) {
3528 atomic_set(&ni->ni_healthv, value);
3529 if (list_empty(&ni->ni_recovery) &&
3530 value < LNET_MAX_HEALTH_VALUE) {
3531 CERROR("manually adding local NI %s to recovery\n",
3532 libcfs_nid2str(ni->ni_nid));
3533 list_add_tail(&ni->ni_recovery,
3534 &the_lnet.ln_mt_localNIRecovq);
3535 lnet_ni_addref_locked(ni, 0);
3538 lnet_net_unlock(LNET_LOCK_EX);
3544 lnet_net_unlock(LNET_LOCK_EX);
3548 lnet_get_local_ni_hstats(struct lnet_ioctl_local_ni_hstats *stats)
3552 lnet_nid_t nid = stats->hlni_nid;
3554 cpt = lnet_net_lock_current();
3555 ni = lnet_nid2ni_locked(nid, cpt);
3562 stats->hlni_local_interrupt = atomic_read(&ni->ni_hstats.hlt_local_interrupt);
3563 stats->hlni_local_dropped = atomic_read(&ni->ni_hstats.hlt_local_dropped);
3564 stats->hlni_local_aborted = atomic_read(&ni->ni_hstats.hlt_local_aborted);
3565 stats->hlni_local_no_route = atomic_read(&ni->ni_hstats.hlt_local_no_route);
3566 stats->hlni_local_timeout = atomic_read(&ni->ni_hstats.hlt_local_timeout);
3567 stats->hlni_local_error = atomic_read(&ni->ni_hstats.hlt_local_error);
3568 stats->hlni_health_value = atomic_read(&ni->ni_healthv);
3571 lnet_net_unlock(cpt);
3577 lnet_get_local_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
3582 lnet_net_lock(LNET_LOCK_EX);
3583 list_for_each_entry(ni, &the_lnet.ln_mt_localNIRecovq, ni_recovery) {
3584 list->rlst_nid_array[i] = ni->ni_nid;
3586 if (i >= LNET_MAX_SHOW_NUM_NID)
3589 lnet_net_unlock(LNET_LOCK_EX);
3590 list->rlst_num_nids = i;
3596 lnet_get_peer_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
3598 struct lnet_peer_ni *lpni;
3601 lnet_net_lock(LNET_LOCK_EX);
3602 list_for_each_entry(lpni, &the_lnet.ln_mt_peerNIRecovq, lpni_recovery) {
3603 list->rlst_nid_array[i] = lpni->lpni_nid;
3605 if (i >= LNET_MAX_SHOW_NUM_NID)
3608 lnet_net_unlock(LNET_LOCK_EX);
3609 list->rlst_num_nids = i;
3615 * LNet ioctl handler.
3619 LNetCtl(unsigned int cmd, void *arg)
3621 struct libcfs_ioctl_data *data = arg;
3622 struct lnet_ioctl_config_data *config;
3623 struct lnet_process_id id = {0};
3627 BUILD_BUG_ON(sizeof(struct lnet_ioctl_net_config) +
3628 sizeof(struct lnet_ioctl_config_data) > LIBCFS_IOC_DATA_MAX);
3631 case IOC_LIBCFS_GET_NI:
3632 rc = LNetGetId(data->ioc_count, &id);
3633 data->ioc_nid = id.nid;
3636 case IOC_LIBCFS_FAIL_NID:
3637 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
3639 case IOC_LIBCFS_ADD_ROUTE: {
3640 /* default router sensitivity to 1 */
3641 unsigned int sensitivity = 1;
3644 if (config->cfg_hdr.ioc_len < sizeof(*config))
3647 if (config->cfg_config_u.cfg_route.rtr_sensitivity) {
3649 config->cfg_config_u.cfg_route.rtr_sensitivity;
3652 mutex_lock(&the_lnet.ln_api_mutex);
3653 rc = lnet_add_route(config->cfg_net,
3654 config->cfg_config_u.cfg_route.rtr_hop,
3656 config->cfg_config_u.cfg_route.
3657 rtr_priority, sensitivity);
3658 mutex_unlock(&the_lnet.ln_api_mutex);
3662 case IOC_LIBCFS_DEL_ROUTE:
3665 if (config->cfg_hdr.ioc_len < sizeof(*config))
3668 mutex_lock(&the_lnet.ln_api_mutex);
3669 rc = lnet_del_route(config->cfg_net, config->cfg_nid);
3670 mutex_unlock(&the_lnet.ln_api_mutex);
3673 case IOC_LIBCFS_GET_ROUTE:
3676 if (config->cfg_hdr.ioc_len < sizeof(*config))
3679 mutex_lock(&the_lnet.ln_api_mutex);
3680 rc = lnet_get_route(config->cfg_count,
3682 &config->cfg_config_u.cfg_route.rtr_hop,
3684 &config->cfg_config_u.cfg_route.rtr_flags,
3685 &config->cfg_config_u.cfg_route.
3687 &config->cfg_config_u.cfg_route.
3689 mutex_unlock(&the_lnet.ln_api_mutex);
3692 case IOC_LIBCFS_GET_LOCAL_NI: {
3693 struct lnet_ioctl_config_ni *cfg_ni;
3694 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
3695 struct lnet_ioctl_element_stats *stats;
3700 /* get the tunables if they are available */
3701 if (cfg_ni->lic_cfg_hdr.ioc_len <
3702 sizeof(*cfg_ni) + sizeof(*stats) + sizeof(*tun))
3705 stats = (struct lnet_ioctl_element_stats *)
3707 tun = (struct lnet_ioctl_config_lnd_tunables *)
3708 (cfg_ni->lic_bulk + sizeof(*stats));
3710 tun_size = cfg_ni->lic_cfg_hdr.ioc_len - sizeof(*cfg_ni) -
3713 mutex_lock(&the_lnet.ln_api_mutex);
3714 rc = lnet_get_ni_config(cfg_ni, tun, stats, tun_size);
3715 mutex_unlock(&the_lnet.ln_api_mutex);
3719 case IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS: {
3720 struct lnet_ioctl_element_msg_stats *msg_stats = arg;
3722 if (msg_stats->im_hdr.ioc_len != sizeof(*msg_stats))
3725 mutex_lock(&the_lnet.ln_api_mutex);
3726 rc = lnet_get_ni_stats(msg_stats);
3727 mutex_unlock(&the_lnet.ln_api_mutex);
3732 case IOC_LIBCFS_GET_NET: {
3733 size_t total = sizeof(*config) +
3734 sizeof(struct lnet_ioctl_net_config);
3737 if (config->cfg_hdr.ioc_len < total)
3740 mutex_lock(&the_lnet.ln_api_mutex);
3741 rc = lnet_get_net_config(config);
3742 mutex_unlock(&the_lnet.ln_api_mutex);
3746 case IOC_LIBCFS_GET_LNET_STATS:
3748 struct lnet_ioctl_lnet_stats *lnet_stats = arg;
3750 if (lnet_stats->st_hdr.ioc_len < sizeof(*lnet_stats))
3753 mutex_lock(&the_lnet.ln_api_mutex);
3754 rc = lnet_counters_get(&lnet_stats->st_cntrs);
3755 mutex_unlock(&the_lnet.ln_api_mutex);
3759 case IOC_LIBCFS_CONFIG_RTR:
3762 if (config->cfg_hdr.ioc_len < sizeof(*config))
3765 mutex_lock(&the_lnet.ln_api_mutex);
3766 if (config->cfg_config_u.cfg_buffers.buf_enable) {
3767 rc = lnet_rtrpools_enable();
3768 mutex_unlock(&the_lnet.ln_api_mutex);
3771 lnet_rtrpools_disable();
3772 mutex_unlock(&the_lnet.ln_api_mutex);
3775 case IOC_LIBCFS_ADD_BUF:
3778 if (config->cfg_hdr.ioc_len < sizeof(*config))
3781 mutex_lock(&the_lnet.ln_api_mutex);
3782 rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
3784 config->cfg_config_u.cfg_buffers.
3786 config->cfg_config_u.cfg_buffers.
3788 mutex_unlock(&the_lnet.ln_api_mutex);
3791 case IOC_LIBCFS_SET_NUMA_RANGE: {
3792 struct lnet_ioctl_set_value *numa;
3794 if (numa->sv_hdr.ioc_len != sizeof(*numa))
3796 lnet_net_lock(LNET_LOCK_EX);
3797 lnet_numa_range = numa->sv_value;
3798 lnet_net_unlock(LNET_LOCK_EX);
3802 case IOC_LIBCFS_GET_NUMA_RANGE: {
3803 struct lnet_ioctl_set_value *numa;
3805 if (numa->sv_hdr.ioc_len != sizeof(*numa))
3807 numa->sv_value = lnet_numa_range;
3811 case IOC_LIBCFS_GET_BUF: {
3812 struct lnet_ioctl_pool_cfg *pool_cfg;
3813 size_t total = sizeof(*config) + sizeof(*pool_cfg);
3817 if (config->cfg_hdr.ioc_len < total)
3820 pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
3822 mutex_lock(&the_lnet.ln_api_mutex);
3823 rc = lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
3824 mutex_unlock(&the_lnet.ln_api_mutex);
3828 case IOC_LIBCFS_GET_LOCAL_HSTATS: {
3829 struct lnet_ioctl_local_ni_hstats *stats = arg;
3831 if (stats->hlni_hdr.ioc_len < sizeof(*stats))
3834 mutex_lock(&the_lnet.ln_api_mutex);
3835 rc = lnet_get_local_ni_hstats(stats);
3836 mutex_unlock(&the_lnet.ln_api_mutex);
3841 case IOC_LIBCFS_GET_RECOVERY_QUEUE: {
3842 struct lnet_ioctl_recovery_list *list = arg;
3843 if (list->rlst_hdr.ioc_len < sizeof(*list))
3846 mutex_lock(&the_lnet.ln_api_mutex);
3847 if (list->rlst_type == LNET_HEALTH_TYPE_LOCAL_NI)
3848 rc = lnet_get_local_ni_recovery_list(list);
3850 rc = lnet_get_peer_ni_recovery_list(list);
3851 mutex_unlock(&the_lnet.ln_api_mutex);
3855 case IOC_LIBCFS_ADD_PEER_NI: {
3856 struct lnet_ioctl_peer_cfg *cfg = arg;
3858 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
3861 mutex_lock(&the_lnet.ln_api_mutex);
3862 rc = lnet_add_peer_ni(cfg->prcfg_prim_nid,
3865 mutex_unlock(&the_lnet.ln_api_mutex);
3869 case IOC_LIBCFS_DEL_PEER_NI: {
3870 struct lnet_ioctl_peer_cfg *cfg = arg;
3872 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
3875 mutex_lock(&the_lnet.ln_api_mutex);
3876 rc = lnet_del_peer_ni(cfg->prcfg_prim_nid,
3877 cfg->prcfg_cfg_nid);
3878 mutex_unlock(&the_lnet.ln_api_mutex);
3882 case IOC_LIBCFS_GET_PEER_INFO: {
3883 struct lnet_ioctl_peer *peer_info = arg;
3885 if (peer_info->pr_hdr.ioc_len < sizeof(*peer_info))
3888 mutex_lock(&the_lnet.ln_api_mutex);
3889 rc = lnet_get_peer_ni_info(
3890 peer_info->pr_count,
3892 peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
3893 &peer_info->pr_lnd_u.pr_peer_credits.cr_ncpt,
3894 &peer_info->pr_lnd_u.pr_peer_credits.cr_refcount,
3895 &peer_info->pr_lnd_u.pr_peer_credits.cr_ni_peer_tx_credits,
3896 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_credits,
3897 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_rtr_credits,
3898 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_min_tx_credits,
3899 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_qnob);
3900 mutex_unlock(&the_lnet.ln_api_mutex);
3904 case IOC_LIBCFS_GET_PEER_NI: {
3905 struct lnet_ioctl_peer_cfg *cfg = arg;
3907 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
3910 mutex_lock(&the_lnet.ln_api_mutex);
3911 rc = lnet_get_peer_info(cfg,
3912 (void __user *)cfg->prcfg_bulk);
3913 mutex_unlock(&the_lnet.ln_api_mutex);
3917 case IOC_LIBCFS_GET_PEER_LIST: {
3918 struct lnet_ioctl_peer_cfg *cfg = arg;
3920 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
3923 mutex_lock(&the_lnet.ln_api_mutex);
3924 rc = lnet_get_peer_list(&cfg->prcfg_count, &cfg->prcfg_size,
3925 (struct lnet_process_id __user *)cfg->prcfg_bulk);
3926 mutex_unlock(&the_lnet.ln_api_mutex);
3930 case IOC_LIBCFS_SET_HEALHV: {
3931 struct lnet_ioctl_reset_health_cfg *cfg = arg;
3933 if (cfg->rh_hdr.ioc_len < sizeof(*cfg))
3935 if (cfg->rh_value < 0 ||
3936 cfg->rh_value > LNET_MAX_HEALTH_VALUE)
3937 value = LNET_MAX_HEALTH_VALUE;
3939 value = cfg->rh_value;
3940 CDEBUG(D_NET, "Manually setting healthv to %d for %s:%s. all = %d\n",
3941 value, (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI) ?
3942 "local" : "peer", libcfs_nid2str(cfg->rh_nid), cfg->rh_all);
3943 mutex_lock(&the_lnet.ln_api_mutex);
3944 if (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI)
3945 lnet_ni_set_healthv(cfg->rh_nid, value,
3948 lnet_peer_ni_set_healthv(cfg->rh_nid, value,
3950 mutex_unlock(&the_lnet.ln_api_mutex);
3954 case IOC_LIBCFS_NOTIFY_ROUTER: {
3955 time64_t deadline = ktime_get_real_seconds() - data->ioc_u64[0];
3957 /* The deadline passed in by the user should be some time in
3958 * seconds in the future since the UNIX epoch. We have to map
3959 * that deadline to the wall clock.
3961 deadline += ktime_get_seconds();
3962 return lnet_notify(NULL, data->ioc_nid, data->ioc_flags, false,
3966 case IOC_LIBCFS_LNET_DIST:
3967 rc = LNetDist(data->ioc_nid, &data->ioc_nid, &data->ioc_u32[1]);
3968 if (rc < 0 && rc != -EHOSTUNREACH)
3971 data->ioc_u32[0] = rc;
3974 case IOC_LIBCFS_TESTPROTOCOMPAT:
3975 the_lnet.ln_testprotocompat = data->ioc_flags;
3978 case IOC_LIBCFS_LNET_FAULT:
3979 return lnet_fault_ctl(data->ioc_flags, data);
3981 case IOC_LIBCFS_PING: {
3982 signed long timeout;
3984 id.nid = data->ioc_nid;
3985 id.pid = data->ioc_u32[0];
3987 /* If timeout is negative then set default of 3 minutes */
3988 if (((s32)data->ioc_u32[1] <= 0) ||
3989 data->ioc_u32[1] > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
3990 timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
3992 timeout = nsecs_to_jiffies(data->ioc_u32[1] * NSEC_PER_MSEC);
3994 rc = lnet_ping(id, timeout, data->ioc_pbuf1,
3995 data->ioc_plen1 / sizeof(struct lnet_process_id));
4000 data->ioc_count = rc;
4004 case IOC_LIBCFS_PING_PEER: {
4005 struct lnet_ioctl_ping_data *ping = arg;
4006 struct lnet_peer *lp;
4007 signed long timeout;
4009 /* If timeout is negative then set default of 3 minutes */
4010 if (((s32)ping->op_param) <= 0 ||
4011 ping->op_param > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
4012 timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
4014 timeout = nsecs_to_jiffies(ping->op_param * NSEC_PER_MSEC);
4016 rc = lnet_ping(ping->ping_id, timeout,
4022 mutex_lock(&the_lnet.ln_api_mutex);
4023 lp = lnet_find_peer(ping->ping_id.nid);
4025 ping->ping_id.nid = lp->lp_primary_nid;
4026 ping->mr_info = lnet_peer_is_multi_rail(lp);
4027 lnet_peer_decref_locked(lp);
4029 mutex_unlock(&the_lnet.ln_api_mutex);
4031 ping->ping_count = rc;
4035 case IOC_LIBCFS_DISCOVER: {
4036 struct lnet_ioctl_ping_data *discover = arg;
4037 struct lnet_peer *lp;
4039 rc = lnet_discover(discover->ping_id, discover->op_param,
4041 discover->ping_count);
4045 mutex_lock(&the_lnet.ln_api_mutex);
4046 lp = lnet_find_peer(discover->ping_id.nid);
4048 discover->ping_id.nid = lp->lp_primary_nid;
4049 discover->mr_info = lnet_peer_is_multi_rail(lp);
4050 lnet_peer_decref_locked(lp);
4052 mutex_unlock(&the_lnet.ln_api_mutex);
4054 discover->ping_count = rc;
4059 ni = lnet_net2ni_addref(data->ioc_net);
4063 if (ni->ni_net->net_lnd->lnd_ctl == NULL)
4066 rc = ni->ni_net->net_lnd->lnd_ctl(ni, cmd, arg);
4073 EXPORT_SYMBOL(LNetCtl);
4075 void LNetDebugPeer(struct lnet_process_id id)
4077 lnet_debug_peer(id.nid);
4079 EXPORT_SYMBOL(LNetDebugPeer);
4082 * Determine if the specified peer \a nid is on the local node.
4084 * \param nid peer nid to check
4086 * \retval true If peer NID is on the local node.
4087 * \retval false If peer NID is not on the local node.
4089 bool LNetIsPeerLocal(lnet_nid_t nid)
4091 struct lnet_net *net;
4095 cpt = lnet_net_lock_current();
4096 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
4097 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
4098 if (ni->ni_nid == nid) {
4099 lnet_net_unlock(cpt);
4104 lnet_net_unlock(cpt);
4108 EXPORT_SYMBOL(LNetIsPeerLocal);
4111 * Retrieve the struct lnet_process_id ID of LNet interface at \a index.
4112 * Note that all interfaces share a same PID, as requested by LNetNIInit().
4114 * \param index Index of the interface to look up.
4115 * \param id On successful return, this location will hold the
4116 * struct lnet_process_id ID of the interface.
4118 * \retval 0 If an interface exists at \a index.
4119 * \retval -ENOENT If no interface has been found.
4122 LNetGetId(unsigned int index, struct lnet_process_id *id)
4125 struct lnet_net *net;
4129 LASSERT(the_lnet.ln_refcount > 0);
4131 cpt = lnet_net_lock_current();
4133 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
4134 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
4138 id->nid = ni->ni_nid;
4139 id->pid = the_lnet.ln_pid;
4145 lnet_net_unlock(cpt);
4148 EXPORT_SYMBOL(LNetGetId);
4153 struct lnet_handle_md mdh;
4154 struct completion completion;
4158 lnet_ping_event_handler(struct lnet_event *event)
4160 struct ping_data *pd = event->md_user_ptr;
4162 CDEBUG(D_NET, "ping event (%d %d)%s\n",
4163 event->type, event->status,
4164 event->unlinked ? " unlinked" : "");
4166 if (event->status) {
4168 pd->rc = event->status;
4169 } else if (event->type == LNET_EVENT_REPLY) {
4171 pd->rc = event->mlength;
4173 if (event->unlinked)
4174 complete(&pd->completion);
4177 static int lnet_ping(struct lnet_process_id id, signed long timeout,
4178 struct lnet_process_id __user *ids, int n_ids)
4180 struct lnet_md md = { NULL };
4181 struct ping_data pd = { 0 };
4182 struct lnet_ping_buffer *pbuf;
4183 struct lnet_process_id tmpid;
4189 /* n_ids limit is arbitrary */
4190 if (n_ids <= 0 || id.nid == LNET_NID_ANY)
4194 * if the user buffer has more space than the lnet_interfaces_max
4195 * then only fill it up to lnet_interfaces_max
4197 if (n_ids > lnet_interfaces_max)
4198 n_ids = lnet_interfaces_max;
4200 if (id.pid == LNET_PID_ANY)
4201 id.pid = LNET_PID_LUSTRE;
4203 pbuf = lnet_ping_buffer_alloc(n_ids, GFP_NOFS);
4207 /* initialize md content */
4208 md.start = &pbuf->pb_info;
4209 md.length = LNET_PING_INFO_SIZE(n_ids);
4210 md.threshold = 2; /* GET/REPLY */
4212 md.options = LNET_MD_TRUNCATE;
4214 md.handler = lnet_ping_event_handler;
4216 init_completion(&pd.completion);
4218 rc = LNetMDBind(&md, LNET_UNLINK, &pd.mdh);
4220 CERROR("Can't bind MD: %d\n", rc);
4221 goto fail_ping_buffer_decref;
4224 rc = LNetGet(LNET_NID_ANY, pd.mdh, id,
4225 LNET_RESERVED_PORTAL,
4226 LNET_PROTO_PING_MATCHBITS, 0, false);
4229 /* Don't CERROR; this could be deliberate! */
4230 rc2 = LNetMDUnlink(pd.mdh);
4233 /* NB must wait for the UNLINK event below... */
4236 if (wait_for_completion_timeout(&pd.completion, timeout) == 0) {
4237 /* Ensure completion in finite time... */
4238 LNetMDUnlink(pd.mdh);
4239 wait_for_completion(&pd.completion);
4243 goto fail_ping_buffer_decref;
4247 LASSERT(nob >= 0 && nob <= LNET_PING_INFO_SIZE(n_ids));
4249 rc = -EPROTO; /* if I can't parse... */
4252 CERROR("%s: ping info too short %d\n",
4253 libcfs_id2str(id), nob);
4254 goto fail_ping_buffer_decref;
4257 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) {
4258 lnet_swap_pinginfo(pbuf);
4259 } else if (pbuf->pb_info.pi_magic != LNET_PROTO_PING_MAGIC) {
4260 CERROR("%s: Unexpected magic %08x\n",
4261 libcfs_id2str(id), pbuf->pb_info.pi_magic);
4262 goto fail_ping_buffer_decref;
4265 if ((pbuf->pb_info.pi_features & LNET_PING_FEAT_NI_STATUS) == 0) {
4266 CERROR("%s: ping w/o NI status: 0x%x\n",
4267 libcfs_id2str(id), pbuf->pb_info.pi_features);
4268 goto fail_ping_buffer_decref;
4271 if (nob < LNET_PING_INFO_SIZE(0)) {
4272 CERROR("%s: Short reply %d(%d min)\n",
4274 nob, (int)LNET_PING_INFO_SIZE(0));
4275 goto fail_ping_buffer_decref;
4278 if (pbuf->pb_info.pi_nnis < n_ids)
4279 n_ids = pbuf->pb_info.pi_nnis;
4281 if (nob < LNET_PING_INFO_SIZE(n_ids)) {
4282 CERROR("%s: Short reply %d(%d expected)\n",
4284 nob, (int)LNET_PING_INFO_SIZE(n_ids));
4285 goto fail_ping_buffer_decref;
4288 rc = -EFAULT; /* if I segv in copy_to_user()... */
4290 memset(&tmpid, 0, sizeof(tmpid));
4291 for (i = 0; i < n_ids; i++) {
4292 tmpid.pid = pbuf->pb_info.pi_pid;
4293 tmpid.nid = pbuf->pb_info.pi_ni[i].ns_nid;
4294 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid)))
4295 goto fail_ping_buffer_decref;
4297 rc = pbuf->pb_info.pi_nnis;
4299 fail_ping_buffer_decref:
4300 lnet_ping_buffer_decref(pbuf);
4305 lnet_discover(struct lnet_process_id id, __u32 force,
4306 struct lnet_process_id __user *ids, int n_ids)
4308 struct lnet_peer_ni *lpni;
4309 struct lnet_peer_ni *p;
4310 struct lnet_peer *lp;
4311 struct lnet_process_id *buf;
4317 id.nid == LNET_NID_ANY)
4320 if (id.pid == LNET_PID_ANY)
4321 id.pid = LNET_PID_LUSTRE;
4324 * If the user buffer has more space than the lnet_interfaces_max,
4325 * then only fill it up to lnet_interfaces_max.
4327 if (n_ids > lnet_interfaces_max)
4328 n_ids = lnet_interfaces_max;
4330 CFS_ALLOC_PTR_ARRAY(buf, n_ids);
4334 cpt = lnet_net_lock_current();
4335 lpni = lnet_nid2peerni_locked(id.nid, LNET_NID_ANY, cpt);
4342 * Clearing the NIDS_UPTODATE flag ensures the peer will
4343 * be discovered, provided discovery has not been disabled.
4345 lp = lpni->lpni_peer_net->lpn_peer;
4346 spin_lock(&lp->lp_lock);
4347 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
4348 /* If the force flag is set, force a PING and PUSH as well. */
4350 lp->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH;
4351 spin_unlock(&lp->lp_lock);
4352 rc = lnet_discover_peer_locked(lpni, cpt, true);
4358 while ((p = lnet_get_next_peer_ni_locked(lp, NULL, p)) != NULL) {
4359 buf[i].pid = id.pid;
4360 buf[i].nid = p->lpni_nid;
4367 lnet_peer_ni_decref_locked(lpni);
4369 lnet_net_unlock(cpt);
4372 if (copy_to_user(ids, buf, rc * sizeof(*buf)))
4374 CFS_FREE_PTR_ARRAY(buf, n_ids);
4380 * Retrieve peer discovery status.
4382 * \retval 1 if lnet_peer_discovery_disabled is 0
4383 * \retval 0 if lnet_peer_discovery_disabled is 1
4386 LNetGetPeerDiscoveryStatus(void)
4388 return !lnet_peer_discovery_disabled;
4390 EXPORT_SYMBOL(LNetGetPeerDiscoveryStatus);