4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
32 #define DEBUG_SUBSYSTEM S_LNET
34 #include <linux/ctype.h>
35 #include <linux/generic-radix-tree.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>
43 #include <net/genetlink.h>
45 #include <libcfs/linux/linux-net.h>
46 #include <lnet/udsp.h>
47 #include <lnet/lib-lnet.h>
49 #define D_LNI D_CONSOLE
52 * initialize ln_api_mutex statically, since it needs to be used in
53 * discovery_set callback. That module parameter callback can be called
54 * before module init completes. The mutex needs to be ready for use then.
56 struct lnet the_lnet = {
57 .ln_api_mutex = __MUTEX_INITIALIZER(the_lnet.ln_api_mutex),
58 }; /* THE state of the network */
59 EXPORT_SYMBOL(the_lnet);
61 static char *ip2nets = "";
62 module_param(ip2nets, charp, 0444);
63 MODULE_PARM_DESC(ip2nets, "LNET network <- IP table");
65 static char *networks = "";
66 module_param(networks, charp, 0444);
67 MODULE_PARM_DESC(networks, "local networks");
69 static char *routes = "";
70 module_param(routes, charp, 0444);
71 MODULE_PARM_DESC(routes, "routes to non-local networks");
73 static int rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
74 module_param(rnet_htable_size, int, 0444);
75 MODULE_PARM_DESC(rnet_htable_size, "size of remote network hash table");
77 static int use_tcp_bonding;
78 module_param(use_tcp_bonding, int, 0444);
79 MODULE_PARM_DESC(use_tcp_bonding,
80 "use_tcp_bonding parameter has been removed");
82 unsigned int lnet_numa_range = 0;
83 module_param(lnet_numa_range, uint, 0444);
84 MODULE_PARM_DESC(lnet_numa_range,
85 "NUMA range to consider during Multi-Rail selection");
88 * lnet_health_sensitivity determines by how much we decrement the health
89 * value on sending error. The value defaults to 100, which means health
90 * interface health is decremented by 100 points every failure.
92 unsigned int lnet_health_sensitivity = 100;
93 static int sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp);
94 #ifdef HAVE_KERNEL_PARAM_OPS
95 static struct kernel_param_ops param_ops_health_sensitivity = {
96 .set = sensitivity_set,
99 #define param_check_health_sensitivity(name, p) \
100 __param_check(name, p, int)
101 module_param(lnet_health_sensitivity, health_sensitivity, S_IRUGO|S_IWUSR);
103 module_param_call(lnet_health_sensitivity, sensitivity_set, param_get_int,
104 &lnet_health_sensitivity, S_IRUGO|S_IWUSR);
106 MODULE_PARM_DESC(lnet_health_sensitivity,
107 "Value to decrement the health value by on error");
110 * lnet_recovery_interval determines how often we should perform recovery
111 * on unhealthy interfaces.
113 unsigned int lnet_recovery_interval = 1;
114 static int recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp);
115 #ifdef HAVE_KERNEL_PARAM_OPS
116 static struct kernel_param_ops param_ops_recovery_interval = {
117 .set = recovery_interval_set,
118 .get = param_get_int,
120 #define param_check_recovery_interval(name, p) \
121 __param_check(name, p, int)
122 module_param(lnet_recovery_interval, recovery_interval, S_IRUGO|S_IWUSR);
124 module_param_call(lnet_recovery_interval, recovery_interval_set, param_get_int,
125 &lnet_recovery_interval, S_IRUGO|S_IWUSR);
127 MODULE_PARM_DESC(lnet_recovery_interval,
128 "DEPRECATED - Interval to recover unhealthy interfaces in seconds");
130 unsigned int lnet_recovery_limit;
131 module_param(lnet_recovery_limit, uint, 0644);
132 MODULE_PARM_DESC(lnet_recovery_limit,
133 "How long to attempt recovery of unhealthy peer interfaces in seconds. Set to 0 to allow indefinite recovery");
135 unsigned int lnet_max_recovery_ping_interval = 900;
136 unsigned int lnet_max_recovery_ping_count = 9;
137 static int max_recovery_ping_interval_set(const char *val,
138 cfs_kernel_param_arg_t *kp);
140 #define param_check_max_recovery_ping_interval(name, p) \
141 __param_check(name, p, int)
143 #ifdef HAVE_KERNEL_PARAM_OPS
144 static struct kernel_param_ops param_ops_max_recovery_ping_interval = {
145 .set = max_recovery_ping_interval_set,
146 .get = param_get_int,
148 module_param(lnet_max_recovery_ping_interval, max_recovery_ping_interval, 0644);
150 module_param_call(lnet_max_recovery_ping_interval, max_recovery_ping_interval,
151 param_get_int, &lnet_max_recovery_ping_interval, 0644);
153 MODULE_PARM_DESC(lnet_max_recovery_ping_interval,
154 "The max interval between LNet recovery pings, in seconds");
156 static int lnet_interfaces_max = LNET_INTERFACES_MAX_DEFAULT;
157 static int intf_max_set(const char *val, cfs_kernel_param_arg_t *kp);
159 static struct kernel_param_ops param_ops_interfaces_max = {
161 .get = param_get_int,
164 #define param_check_interfaces_max(name, p) \
165 __param_check(name, p, int)
167 #ifdef HAVE_KERNEL_PARAM_OPS
168 module_param(lnet_interfaces_max, interfaces_max, 0644);
170 module_param_call(lnet_interfaces_max, intf_max_set, param_get_int,
171 ¶m_ops_interfaces_max, 0644);
173 MODULE_PARM_DESC(lnet_interfaces_max,
174 "Maximum number of interfaces in a node.");
176 unsigned lnet_peer_discovery_disabled = 0;
177 static int discovery_set(const char *val, cfs_kernel_param_arg_t *kp);
179 static struct kernel_param_ops param_ops_discovery_disabled = {
180 .set = discovery_set,
181 .get = param_get_int,
184 #define param_check_discovery_disabled(name, p) \
185 __param_check(name, p, int)
186 #ifdef HAVE_KERNEL_PARAM_OPS
187 module_param(lnet_peer_discovery_disabled, discovery_disabled, 0644);
189 module_param_call(lnet_peer_discovery_disabled, discovery_set, param_get_int,
190 ¶m_ops_discovery_disabled, 0644);
192 MODULE_PARM_DESC(lnet_peer_discovery_disabled,
193 "Set to 1 to disable peer discovery on this node.");
195 unsigned int lnet_drop_asym_route;
196 static int drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp);
198 static struct kernel_param_ops param_ops_drop_asym_route = {
199 .set = drop_asym_route_set,
200 .get = param_get_int,
203 #define param_check_drop_asym_route(name, p) \
204 __param_check(name, p, int)
205 #ifdef HAVE_KERNEL_PARAM_OPS
206 module_param(lnet_drop_asym_route, drop_asym_route, 0644);
208 module_param_call(lnet_drop_asym_route, drop_asym_route_set, param_get_int,
209 ¶m_ops_drop_asym_route, 0644);
211 MODULE_PARM_DESC(lnet_drop_asym_route,
212 "Set to 1 to drop asymmetrical route messages.");
214 #define LNET_TRANSACTION_TIMEOUT_DEFAULT 150
215 unsigned int lnet_transaction_timeout = LNET_TRANSACTION_TIMEOUT_DEFAULT;
216 static int transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp);
217 #ifdef HAVE_KERNEL_PARAM_OPS
218 static struct kernel_param_ops param_ops_transaction_timeout = {
219 .set = transaction_to_set,
220 .get = param_get_int,
223 #define param_check_transaction_timeout(name, p) \
224 __param_check(name, p, int)
225 module_param(lnet_transaction_timeout, transaction_timeout, S_IRUGO|S_IWUSR);
227 module_param_call(lnet_transaction_timeout, transaction_to_set, param_get_int,
228 &lnet_transaction_timeout, S_IRUGO|S_IWUSR);
230 MODULE_PARM_DESC(lnet_transaction_timeout,
231 "Maximum number of seconds to wait for a peer response.");
233 #define LNET_RETRY_COUNT_DEFAULT 2
234 unsigned int lnet_retry_count = LNET_RETRY_COUNT_DEFAULT;
235 static int retry_count_set(const char *val, cfs_kernel_param_arg_t *kp);
236 #ifdef HAVE_KERNEL_PARAM_OPS
237 static struct kernel_param_ops param_ops_retry_count = {
238 .set = retry_count_set,
239 .get = param_get_int,
242 #define param_check_retry_count(name, p) \
243 __param_check(name, p, int)
244 module_param(lnet_retry_count, retry_count, S_IRUGO|S_IWUSR);
246 module_param_call(lnet_retry_count, retry_count_set, param_get_int,
247 &lnet_retry_count, S_IRUGO|S_IWUSR);
249 MODULE_PARM_DESC(lnet_retry_count,
250 "Maximum number of times to retry transmitting a message");
252 unsigned int lnet_response_tracking = 3;
253 static int response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp);
255 #ifdef HAVE_KERNEL_PARAM_OPS
256 static struct kernel_param_ops param_ops_response_tracking = {
257 .set = response_tracking_set,
258 .get = param_get_int,
261 #define param_check_response_tracking(name, p) \
262 __param_check(name, p, int)
263 module_param(lnet_response_tracking, response_tracking, 0644);
265 module_param_call(lnet_response_tracking, response_tracking_set, param_get_int,
266 &lnet_response_tracking, 0644);
268 MODULE_PARM_DESC(lnet_response_tracking,
269 "(0|1|2|3) LNet Internal Only|GET Reply only|PUT ACK only|Full Tracking (default)");
271 int lock_prim_nid = 1;
272 module_param(lock_prim_nid, int, 0444);
273 MODULE_PARM_DESC(lock_prim_nid,
274 "Whether nid passed down by Lustre is locked as primary");
276 #define LNET_LND_TIMEOUT_DEFAULT ((LNET_TRANSACTION_TIMEOUT_DEFAULT - 1) / \
277 (LNET_RETRY_COUNT_DEFAULT + 1))
278 unsigned int lnet_lnd_timeout = LNET_LND_TIMEOUT_DEFAULT;
279 static void lnet_set_lnd_timeout(void)
281 lnet_lnd_timeout = max((lnet_transaction_timeout - 1) /
282 (lnet_retry_count + 1), 1U);
286 * This sequence number keeps track of how many times DLC was used to
287 * update the local NIs. It is incremented when a NI is added or
288 * removed and checked when sending a message to determine if there is
289 * a need to re-run the selection algorithm. See lnet_select_pathway()
290 * for more details on its usage.
292 static atomic_t lnet_dlc_seq_no = ATOMIC_INIT(0);
294 struct lnet_fail_ping {
295 struct lnet_processid lfp_id;
299 struct lnet_genl_ping_list {
300 unsigned int lgpl_index;
301 unsigned int lgpl_list_count;
302 unsigned int lgpl_failed_count;
303 signed long lgpl_timeout;
304 struct lnet_nid lgpl_src_nid;
305 GENRADIX(struct lnet_fail_ping) lgpl_failed;
306 GENRADIX(struct lnet_processid) lgpl_list;
309 static int lnet_ping(struct lnet_processid *id, struct lnet_nid *src_nid,
310 signed long timeout, struct lnet_genl_ping_list *plist,
313 static int lnet_discover(struct lnet_process_id id, __u32 force,
314 struct lnet_process_id __user *ids, int n_ids);
317 sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
320 unsigned *sensitivity = (unsigned *)kp->arg;
323 rc = kstrtoul(val, 0, &value);
325 CERROR("Invalid module parameter value for 'lnet_health_sensitivity'\n");
330 * The purpose of locking the api_mutex here is to ensure that
331 * the correct value ends up stored properly.
333 mutex_lock(&the_lnet.ln_api_mutex);
335 if (value > LNET_MAX_HEALTH_VALUE) {
336 mutex_unlock(&the_lnet.ln_api_mutex);
337 CERROR("Invalid health value. Maximum: %d value = %lu\n",
338 LNET_MAX_HEALTH_VALUE, value);
342 if (*sensitivity != 0 && value == 0 && lnet_retry_count != 0) {
343 lnet_retry_count = 0;
344 lnet_set_lnd_timeout();
347 *sensitivity = value;
349 mutex_unlock(&the_lnet.ln_api_mutex);
355 recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp)
357 CWARN("'lnet_recovery_interval' has been deprecated\n");
363 max_recovery_ping_interval_set(const char *val, cfs_kernel_param_arg_t *kp)
368 rc = kstrtoul(val, 0, &value);
370 CERROR("Invalid module parameter value for 'lnet_max_recovery_ping_interval'\n");
375 CERROR("Invalid max ping timeout. Must be strictly positive\n");
379 /* The purpose of locking the api_mutex here is to ensure that
380 * the correct value ends up stored properly.
382 mutex_lock(&the_lnet.ln_api_mutex);
383 lnet_max_recovery_ping_interval = value;
384 lnet_max_recovery_ping_count = 0;
387 lnet_max_recovery_ping_count++;
390 mutex_unlock(&the_lnet.ln_api_mutex);
396 discovery_set(const char *val, cfs_kernel_param_arg_t *kp)
399 unsigned *discovery_off = (unsigned *)kp->arg;
401 struct lnet_ping_buffer *pbuf;
403 rc = kstrtoul(val, 0, &value);
405 CERROR("Invalid module parameter value for 'lnet_peer_discovery_disabled'\n");
409 value = (value) ? 1 : 0;
412 * The purpose of locking the api_mutex here is to ensure that
413 * the correct value ends up stored properly.
415 mutex_lock(&the_lnet.ln_api_mutex);
417 if (value == *discovery_off) {
418 mutex_unlock(&the_lnet.ln_api_mutex);
423 * We still want to set the discovery value even when LNet is not
424 * running. This is the case when LNet is being loaded and we want
425 * the module parameters to take effect. Otherwise if we're
426 * changing the value dynamically, we want to set it after
429 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
430 *discovery_off = value;
431 mutex_unlock(&the_lnet.ln_api_mutex);
435 /* tell peers that discovery setting has changed */
436 lnet_net_lock(LNET_LOCK_EX);
437 pbuf = the_lnet.ln_ping_target;
439 pbuf->pb_info.pi_features &= ~LNET_PING_FEAT_DISCOVERY;
441 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
442 lnet_net_unlock(LNET_LOCK_EX);
444 /* only send a push when we're turning off discovery */
445 if (*discovery_off <= 0 && value > 0)
446 lnet_push_update_to_peers(1);
447 *discovery_off = value;
449 mutex_unlock(&the_lnet.ln_api_mutex);
455 drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp)
458 unsigned int *drop_asym_route = (unsigned int *)kp->arg;
461 rc = kstrtoul(val, 0, &value);
463 CERROR("Invalid module parameter value for "
464 "'lnet_drop_asym_route'\n");
469 * The purpose of locking the api_mutex here is to ensure that
470 * the correct value ends up stored properly.
472 mutex_lock(&the_lnet.ln_api_mutex);
474 if (value == *drop_asym_route) {
475 mutex_unlock(&the_lnet.ln_api_mutex);
479 *drop_asym_route = value;
481 mutex_unlock(&the_lnet.ln_api_mutex);
487 transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp)
490 unsigned *transaction_to = (unsigned *)kp->arg;
493 rc = kstrtoul(val, 0, &value);
495 CERROR("Invalid module parameter value for 'lnet_transaction_timeout'\n");
500 * The purpose of locking the api_mutex here is to ensure that
501 * the correct value ends up stored properly.
503 mutex_lock(&the_lnet.ln_api_mutex);
505 if (value <= lnet_retry_count || value == 0) {
506 mutex_unlock(&the_lnet.ln_api_mutex);
507 CERROR("Invalid value for lnet_transaction_timeout (%lu). "
508 "Has to be greater than lnet_retry_count (%u)\n",
509 value, lnet_retry_count);
513 if (value == *transaction_to) {
514 mutex_unlock(&the_lnet.ln_api_mutex);
518 *transaction_to = value;
519 /* Update the lnet_lnd_timeout now that we've modified the
520 * transaction timeout
522 lnet_set_lnd_timeout();
524 mutex_unlock(&the_lnet.ln_api_mutex);
530 retry_count_set(const char *val, cfs_kernel_param_arg_t *kp)
533 unsigned *retry_count = (unsigned *)kp->arg;
536 rc = kstrtoul(val, 0, &value);
538 CERROR("Invalid module parameter value for 'lnet_retry_count'\n");
543 * The purpose of locking the api_mutex here is to ensure that
544 * the correct value ends up stored properly.
546 mutex_lock(&the_lnet.ln_api_mutex);
548 if (lnet_health_sensitivity == 0 && value > 0) {
549 mutex_unlock(&the_lnet.ln_api_mutex);
550 CERROR("Can not set lnet_retry_count when health feature is turned off\n");
554 if (value > lnet_transaction_timeout) {
555 mutex_unlock(&the_lnet.ln_api_mutex);
556 CERROR("Invalid value for lnet_retry_count (%lu). "
557 "Has to be smaller than lnet_transaction_timeout (%u)\n",
558 value, lnet_transaction_timeout);
562 *retry_count = value;
564 /* Update the lnet_lnd_timeout now that we've modified the
567 lnet_set_lnd_timeout();
569 mutex_unlock(&the_lnet.ln_api_mutex);
575 intf_max_set(const char *val, cfs_kernel_param_arg_t *kp)
579 rc = kstrtoint(val, 0, &value);
581 CERROR("Invalid module parameter value for 'lnet_interfaces_max'\n");
585 if (value < LNET_INTERFACES_MIN) {
586 CWARN("max interfaces provided are too small, setting to %d\n",
587 LNET_INTERFACES_MAX_DEFAULT);
588 value = LNET_INTERFACES_MAX_DEFAULT;
591 *(int *)kp->arg = value;
597 response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp)
600 unsigned long new_value;
602 rc = kstrtoul(val, 0, &new_value);
604 CERROR("Invalid value for 'lnet_response_tracking'\n");
608 if (new_value < 0 || new_value > 3) {
609 CWARN("Invalid value (%lu) for 'lnet_response_tracking'\n",
614 lnet_response_tracking = new_value;
620 lnet_get_routes(void)
626 lnet_get_networks(void)
631 if (*networks != 0 && *ip2nets != 0) {
632 LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
633 "'ip2nets' but not both at once\n");
638 rc = lnet_parse_ip2nets(&nets, ip2nets);
639 return (rc == 0) ? nets : NULL;
649 lnet_init_locks(void)
651 spin_lock_init(&the_lnet.ln_eq_wait_lock);
652 spin_lock_init(&the_lnet.ln_msg_resend_lock);
653 init_completion(&the_lnet.ln_mt_wait_complete);
654 mutex_init(&the_lnet.ln_lnd_mutex);
657 struct kmem_cache *lnet_mes_cachep; /* MEs kmem_cache */
658 struct kmem_cache *lnet_small_mds_cachep; /* <= LNET_SMALL_MD_SIZE bytes
660 struct kmem_cache *lnet_udsp_cachep; /* udsp cache */
661 struct kmem_cache *lnet_rspt_cachep; /* response tracker cache */
662 struct kmem_cache *lnet_msg_cachep;
665 lnet_slab_setup(void)
667 /* create specific kmem_cache for MEs and small MDs (i.e., originally
668 * allocated in <size-xxx> kmem_cache).
670 lnet_mes_cachep = kmem_cache_create("lnet_MEs", sizeof(struct lnet_me),
672 if (!lnet_mes_cachep)
675 lnet_small_mds_cachep = kmem_cache_create("lnet_small_MDs",
676 LNET_SMALL_MD_SIZE, 0, 0,
678 if (!lnet_small_mds_cachep)
681 lnet_udsp_cachep = kmem_cache_create("lnet_udsp",
682 sizeof(struct lnet_udsp),
684 if (!lnet_udsp_cachep)
687 lnet_rspt_cachep = kmem_cache_create("lnet_rspt", sizeof(struct lnet_rsp_tracker),
689 if (!lnet_rspt_cachep)
692 lnet_msg_cachep = kmem_cache_create("lnet_msg", sizeof(struct lnet_msg),
694 if (!lnet_msg_cachep)
701 lnet_slab_cleanup(void)
703 if (lnet_msg_cachep) {
704 kmem_cache_destroy(lnet_msg_cachep);
705 lnet_msg_cachep = NULL;
708 if (lnet_rspt_cachep) {
709 kmem_cache_destroy(lnet_rspt_cachep);
710 lnet_rspt_cachep = NULL;
713 if (lnet_udsp_cachep) {
714 kmem_cache_destroy(lnet_udsp_cachep);
715 lnet_udsp_cachep = NULL;
718 if (lnet_small_mds_cachep) {
719 kmem_cache_destroy(lnet_small_mds_cachep);
720 lnet_small_mds_cachep = NULL;
723 if (lnet_mes_cachep) {
724 kmem_cache_destroy(lnet_mes_cachep);
725 lnet_mes_cachep = NULL;
730 lnet_create_remote_nets_table(void)
733 struct list_head *hash;
735 LASSERT(the_lnet.ln_remote_nets_hash == NULL);
736 LASSERT(the_lnet.ln_remote_nets_hbits > 0);
737 CFS_ALLOC_PTR_ARRAY(hash, LNET_REMOTE_NETS_HASH_SIZE);
739 CERROR("Failed to create remote nets hash table\n");
743 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
744 INIT_LIST_HEAD(&hash[i]);
745 the_lnet.ln_remote_nets_hash = hash;
750 lnet_destroy_remote_nets_table(void)
754 if (the_lnet.ln_remote_nets_hash == NULL)
757 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
758 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
760 CFS_FREE_PTR_ARRAY(the_lnet.ln_remote_nets_hash,
761 LNET_REMOTE_NETS_HASH_SIZE);
762 the_lnet.ln_remote_nets_hash = NULL;
766 lnet_destroy_locks(void)
768 if (the_lnet.ln_res_lock != NULL) {
769 cfs_percpt_lock_free(the_lnet.ln_res_lock);
770 the_lnet.ln_res_lock = NULL;
773 if (the_lnet.ln_net_lock != NULL) {
774 cfs_percpt_lock_free(the_lnet.ln_net_lock);
775 the_lnet.ln_net_lock = NULL;
780 lnet_create_locks(void)
784 the_lnet.ln_res_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
785 if (the_lnet.ln_res_lock == NULL)
788 the_lnet.ln_net_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
789 if (the_lnet.ln_net_lock == NULL)
795 lnet_destroy_locks();
799 static void lnet_assert_wire_constants(void)
801 /* Wire protocol assertions generated by 'wirecheck'
802 * running on Linux robert.bartonsoftware.com 2.6.8-1.521
803 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux
804 * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
808 BUILD_BUG_ON(LNET_PROTO_TCP_MAGIC != 0xeebc0ded);
809 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MAJOR != 1);
810 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MINOR != 0);
811 BUILD_BUG_ON(LNET_MSG_ACK != 0);
812 BUILD_BUG_ON(LNET_MSG_PUT != 1);
813 BUILD_BUG_ON(LNET_MSG_GET != 2);
814 BUILD_BUG_ON(LNET_MSG_REPLY != 3);
815 BUILD_BUG_ON(LNET_MSG_HELLO != 4);
817 BUILD_BUG_ON((int)sizeof(lnet_nid_t) != 8);
818 BUILD_BUG_ON((int)sizeof(lnet_pid_t) != 4);
820 /* Checks for struct lnet_nid */
821 BUILD_BUG_ON((int)sizeof(struct lnet_nid) != 20);
822 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_size) != 0);
823 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_size) != 1);
824 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_type) != 1);
825 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_type) != 1);
826 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_num) != 2);
827 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_num) != 2);
828 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_addr) != 4);
829 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_addr) != 16);
831 /* Checks for struct lnet_process_id_packed */
832 BUILD_BUG_ON((int)sizeof(struct lnet_process_id_packed) != 12);
833 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, nid) != 0);
834 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->nid) != 8);
835 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, pid) != 8);
836 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->pid) != 4);
838 /* Checks for struct lnet_handle_wire */
839 BUILD_BUG_ON((int)sizeof(struct lnet_handle_wire) != 16);
840 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
841 wh_interface_cookie) != 0);
842 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_interface_cookie) != 8);
843 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
844 wh_object_cookie) != 8);
845 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_object_cookie) != 8);
847 /* Checks for struct struct lnet_magicversion */
848 BUILD_BUG_ON((int)sizeof(struct lnet_magicversion) != 8);
849 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, magic) != 0);
850 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->magic) != 4);
851 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, version_major) != 4);
852 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_major) != 2);
853 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion,
854 version_minor) != 6);
855 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_minor) != 2);
857 /* Checks for struct _lnet_hdr_nid4 */
858 BUILD_BUG_ON((int)sizeof(struct _lnet_hdr_nid4) != 72);
859 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, dest_nid) != 0);
860 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->dest_nid) != 8);
861 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, src_nid) != 8);
862 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->src_nid) != 8);
863 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, dest_pid) != 16);
864 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->dest_pid) != 4);
865 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, src_pid) != 20);
866 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->src_pid) != 4);
867 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, type) != 24);
868 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->type) != 4);
869 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, payload_length) != 28);
870 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->payload_length) != 4);
871 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg) != 32);
872 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg) != 40);
875 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.dst_wmd) != 32);
876 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.dst_wmd) != 16);
877 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.match_bits) != 48);
878 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.match_bits) != 8);
879 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.mlength) != 56);
880 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.mlength) != 4);
883 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.ack_wmd) != 32);
884 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.ack_wmd) != 16);
885 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.match_bits) != 48);
886 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.match_bits) != 8);
887 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.hdr_data) != 56);
888 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.hdr_data) != 8);
889 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.ptl_index) != 64);
890 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.ptl_index) != 4);
891 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.offset) != 68);
892 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.offset) != 4);
895 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.return_wmd) != 32);
896 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.return_wmd) != 16);
897 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.match_bits) != 48);
898 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.match_bits) != 8);
899 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.ptl_index) != 56);
900 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.ptl_index) != 4);
901 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.src_offset) != 60);
902 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.src_offset) != 4);
903 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.sink_length) != 64);
904 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.sink_length) != 4);
907 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.reply.dst_wmd) != 32);
908 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.reply.dst_wmd) != 16);
911 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.hello.incarnation) != 32);
912 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.hello.incarnation) != 8);
913 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.hello.type) != 40);
914 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.hello.type) != 4);
916 /* Checks for struct lnet_ni_status and related constants */
917 BUILD_BUG_ON(LNET_NI_STATUS_INVALID != 0x00000000);
918 BUILD_BUG_ON(LNET_NI_STATUS_UP != 0x15aac0de);
919 BUILD_BUG_ON(LNET_NI_STATUS_DOWN != 0xdeadface);
921 /* Checks for struct lnet_ni_status */
922 BUILD_BUG_ON((int)sizeof(struct lnet_ni_status) != 16);
923 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_nid) != 0);
924 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_nid) != 8);
925 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_status) != 8);
926 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_status) != 4);
927 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_msg_size) != 12);
928 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_msg_size) != 4);
930 /* Checks for struct lnet_ni_large_status */
931 BUILD_BUG_ON((int)sizeof(struct lnet_ni_large_status) != 24);
932 BUILD_BUG_ON((int)offsetof(struct lnet_ni_large_status, ns_status) != 0);
933 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_large_status *)0)->ns_status) != 4);
934 BUILD_BUG_ON((int)offsetof(struct lnet_ni_large_status, ns_nid) != 4);
935 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_large_status *)0)->ns_nid) != 20);
937 /* Checks for struct lnet_ping_info and related constants */
938 BUILD_BUG_ON(LNET_PROTO_PING_MAGIC != 0x70696E67);
939 BUILD_BUG_ON(LNET_PING_FEAT_INVAL != 0);
940 BUILD_BUG_ON(LNET_PING_FEAT_BASE != 1);
941 BUILD_BUG_ON(LNET_PING_FEAT_NI_STATUS != 2);
942 BUILD_BUG_ON(LNET_PING_FEAT_RTE_DISABLED != 4);
943 BUILD_BUG_ON(LNET_PING_FEAT_MULTI_RAIL != 8);
944 BUILD_BUG_ON(LNET_PING_FEAT_DISCOVERY != 16);
945 BUILD_BUG_ON(LNET_PING_FEAT_LARGE_ADDR != 32);
946 BUILD_BUG_ON(LNET_PING_FEAT_PRIMARY_LARGE != 64);
947 BUILD_BUG_ON(LNET_PING_FEAT_BITS != 127);
949 /* Checks for struct lnet_ping_info */
950 BUILD_BUG_ON((int)sizeof(struct lnet_ping_info) != 16);
951 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_magic) != 0);
952 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_magic) != 4);
953 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_features) != 4);
954 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_features) != 4);
955 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_pid) != 8);
956 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_pid) != 4);
957 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_nnis) != 12);
958 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_nnis) != 4);
959 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_ni) != 16);
960 BUILD_BUG_ON(offsetof(struct lnet_ping_info, pi_ni) != sizeof(struct lnet_ping_info));
962 /* Acceptor connection request */
963 BUILD_BUG_ON(LNET_PROTO_ACCEPTOR_VERSION != 1);
965 /* Checks for struct lnet_acceptor_connreq */
966 BUILD_BUG_ON((int)sizeof(struct lnet_acceptor_connreq) != 16);
967 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_magic) != 0);
968 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_magic) != 4);
969 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_version) != 4);
970 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_version) != 4);
971 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_nid) != 8);
972 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_nid) != 8);
974 /* Checks for struct lnet_acceptor_connreq_v2 */
975 BUILD_BUG_ON((int)sizeof(struct lnet_acceptor_connreq_v2) != 28);
976 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_magic) != 0);
977 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_magic) != 4);
978 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_version) != 4);
979 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_version) != 4);
980 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_nid) != 8);
981 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_nid) != 20);
983 /* Checks for struct lnet_counters_common */
984 BUILD_BUG_ON((int)sizeof(struct lnet_counters_common) != 60);
985 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_alloc) != 0);
986 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_alloc) != 4);
987 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_max) != 4);
988 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_max) != 4);
989 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_errors) != 8);
990 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_errors) != 4);
991 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_count) != 12);
992 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_count) != 4);
993 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_count) != 16);
994 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_count) != 4);
995 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_count) != 20);
996 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_count) != 4);
997 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_count) != 24);
998 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_count) != 4);
999 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_length) != 28);
1000 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_length) != 8);
1001 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_length) != 36);
1002 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_length) != 8);
1003 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_length) != 44);
1004 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_length) != 8);
1005 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_length) != 52);
1006 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_length) != 8);
1009 static const struct lnet_lnd *lnet_find_lnd_by_type(__u32 type)
1011 const struct lnet_lnd *lnd;
1013 /* holding lnd mutex */
1014 if (type >= NUM_LNDS)
1016 lnd = the_lnet.ln_lnds[type];
1017 LASSERT(!lnd || lnd->lnd_type == type);
1023 lnet_get_lnd_timeout(void)
1025 return lnet_lnd_timeout;
1027 EXPORT_SYMBOL(lnet_get_lnd_timeout);
1030 lnet_register_lnd(const struct lnet_lnd *lnd)
1032 mutex_lock(&the_lnet.ln_lnd_mutex);
1034 LASSERT(libcfs_isknown_lnd(lnd->lnd_type));
1035 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
1037 the_lnet.ln_lnds[lnd->lnd_type] = lnd;
1039 CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type));
1041 mutex_unlock(&the_lnet.ln_lnd_mutex);
1043 EXPORT_SYMBOL(lnet_register_lnd);
1046 lnet_unregister_lnd(const struct lnet_lnd *lnd)
1048 mutex_lock(&the_lnet.ln_lnd_mutex);
1050 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
1052 the_lnet.ln_lnds[lnd->lnd_type] = NULL;
1053 CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type));
1055 mutex_unlock(&the_lnet.ln_lnd_mutex);
1057 EXPORT_SYMBOL(lnet_unregister_lnd);
1060 lnet_counters_get_common_locked(struct lnet_counters_common *common)
1062 struct lnet_counters *ctr;
1065 /* FIXME !!! Their is no assert_lnet_net_locked() to ensure this
1066 * actually called under the protection of the lnet_net_lock.
1068 memset(common, 0, sizeof(*common));
1070 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
1071 common->lcc_msgs_max += ctr->lct_common.lcc_msgs_max;
1072 common->lcc_msgs_alloc += ctr->lct_common.lcc_msgs_alloc;
1073 common->lcc_errors += ctr->lct_common.lcc_errors;
1074 common->lcc_send_count += ctr->lct_common.lcc_send_count;
1075 common->lcc_recv_count += ctr->lct_common.lcc_recv_count;
1076 common->lcc_route_count += ctr->lct_common.lcc_route_count;
1077 common->lcc_drop_count += ctr->lct_common.lcc_drop_count;
1078 common->lcc_send_length += ctr->lct_common.lcc_send_length;
1079 common->lcc_recv_length += ctr->lct_common.lcc_recv_length;
1080 common->lcc_route_length += ctr->lct_common.lcc_route_length;
1081 common->lcc_drop_length += ctr->lct_common.lcc_drop_length;
1086 lnet_counters_get_common(struct lnet_counters_common *common)
1088 lnet_net_lock(LNET_LOCK_EX);
1089 lnet_counters_get_common_locked(common);
1090 lnet_net_unlock(LNET_LOCK_EX);
1092 EXPORT_SYMBOL(lnet_counters_get_common);
1095 lnet_counters_get(struct lnet_counters *counters)
1097 struct lnet_counters *ctr;
1098 struct lnet_counters_health *health = &counters->lct_health;
1101 memset(counters, 0, sizeof(*counters));
1103 lnet_net_lock(LNET_LOCK_EX);
1105 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1106 GOTO(out_unlock, rc = -ENODEV);
1108 lnet_counters_get_common_locked(&counters->lct_common);
1110 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
1111 health->lch_rst_alloc += ctr->lct_health.lch_rst_alloc;
1112 health->lch_resend_count += ctr->lct_health.lch_resend_count;
1113 health->lch_response_timeout_count +=
1114 ctr->lct_health.lch_response_timeout_count;
1115 health->lch_local_interrupt_count +=
1116 ctr->lct_health.lch_local_interrupt_count;
1117 health->lch_local_dropped_count +=
1118 ctr->lct_health.lch_local_dropped_count;
1119 health->lch_local_aborted_count +=
1120 ctr->lct_health.lch_local_aborted_count;
1121 health->lch_local_no_route_count +=
1122 ctr->lct_health.lch_local_no_route_count;
1123 health->lch_local_timeout_count +=
1124 ctr->lct_health.lch_local_timeout_count;
1125 health->lch_local_error_count +=
1126 ctr->lct_health.lch_local_error_count;
1127 health->lch_remote_dropped_count +=
1128 ctr->lct_health.lch_remote_dropped_count;
1129 health->lch_remote_error_count +=
1130 ctr->lct_health.lch_remote_error_count;
1131 health->lch_remote_timeout_count +=
1132 ctr->lct_health.lch_remote_timeout_count;
1133 health->lch_network_timeout_count +=
1134 ctr->lct_health.lch_network_timeout_count;
1137 lnet_net_unlock(LNET_LOCK_EX);
1140 EXPORT_SYMBOL(lnet_counters_get);
1143 lnet_counters_reset(void)
1145 struct lnet_counters *counters;
1148 lnet_net_lock(LNET_LOCK_EX);
1150 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1153 cfs_percpt_for_each(counters, i, the_lnet.ln_counters)
1154 memset(counters, 0, sizeof(struct lnet_counters));
1156 lnet_net_unlock(LNET_LOCK_EX);
1160 lnet_res_type2str(int type)
1165 case LNET_COOKIE_TYPE_MD:
1167 case LNET_COOKIE_TYPE_ME:
1169 case LNET_COOKIE_TYPE_EQ:
1175 lnet_res_container_cleanup(struct lnet_res_container *rec)
1179 if (rec->rec_type == 0) /* not set yet, it's uninitialized */
1182 while (!list_empty(&rec->rec_active)) {
1183 struct list_head *e = rec->rec_active.next;
1186 if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
1187 lnet_md_free(list_entry(e, struct lnet_libmd, md_list));
1189 } else { /* NB: Active MEs should be attached on portals */
1196 /* Found alive MD/ME/EQ, user really should unlink/free
1197 * all of them before finalize LNet, but if someone didn't,
1198 * we have to recycle garbage for him */
1199 CERROR("%d active elements on exit of %s container\n",
1200 count, lnet_res_type2str(rec->rec_type));
1203 if (rec->rec_lh_hash != NULL) {
1204 CFS_FREE_PTR_ARRAY(rec->rec_lh_hash, LNET_LH_HASH_SIZE);
1205 rec->rec_lh_hash = NULL;
1208 rec->rec_type = 0; /* mark it as finalized */
1212 lnet_res_container_setup(struct lnet_res_container *rec, int cpt, int type)
1217 LASSERT(rec->rec_type == 0);
1219 rec->rec_type = type;
1220 INIT_LIST_HEAD(&rec->rec_active);
1222 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type;
1224 /* Arbitrary choice of hash table size */
1225 LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt,
1226 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
1227 if (rec->rec_lh_hash == NULL) {
1232 for (i = 0; i < LNET_LH_HASH_SIZE; i++)
1233 INIT_LIST_HEAD(&rec->rec_lh_hash[i]);
1238 CERROR("Failed to setup %s resource container\n",
1239 lnet_res_type2str(type));
1240 lnet_res_container_cleanup(rec);
1245 lnet_res_containers_destroy(struct lnet_res_container **recs)
1247 struct lnet_res_container *rec;
1250 cfs_percpt_for_each(rec, i, recs)
1251 lnet_res_container_cleanup(rec);
1253 cfs_percpt_free(recs);
1256 static struct lnet_res_container **
1257 lnet_res_containers_create(int type)
1259 struct lnet_res_container **recs;
1260 struct lnet_res_container *rec;
1264 recs = cfs_percpt_alloc(lnet_cpt_table(), sizeof(*rec));
1266 CERROR("Failed to allocate %s resource containers\n",
1267 lnet_res_type2str(type));
1271 cfs_percpt_for_each(rec, i, recs) {
1272 rc = lnet_res_container_setup(rec, i, type);
1274 lnet_res_containers_destroy(recs);
1282 struct lnet_libhandle *
1283 lnet_res_lh_lookup(struct lnet_res_container *rec, __u64 cookie)
1285 /* ALWAYS called with lnet_res_lock held */
1286 struct list_head *head;
1287 struct lnet_libhandle *lh;
1290 if ((cookie & LNET_COOKIE_MASK) != rec->rec_type)
1293 hash = cookie >> (LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS);
1294 head = &rec->rec_lh_hash[hash & LNET_LH_HASH_MASK];
1296 list_for_each_entry(lh, head, lh_hash_chain) {
1297 if (lh->lh_cookie == cookie)
1305 lnet_res_lh_initialize(struct lnet_res_container *rec,
1306 struct lnet_libhandle *lh)
1308 /* ALWAYS called with lnet_res_lock held */
1309 unsigned int ibits = LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS;
1312 lh->lh_cookie = rec->rec_lh_cookie;
1313 rec->rec_lh_cookie += 1 << ibits;
1315 hash = (lh->lh_cookie >> ibits) & LNET_LH_HASH_MASK;
1317 list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
1321 lnet_create_array_of_queues(void)
1323 struct list_head **qs;
1324 struct list_head *q;
1327 qs = cfs_percpt_alloc(lnet_cpt_table(),
1328 sizeof(struct list_head));
1330 CERROR("Failed to allocate queues\n");
1334 cfs_percpt_for_each(q, i, qs)
1340 static int lnet_unprepare(void);
1343 lnet_prepare(lnet_pid_t requested_pid)
1345 /* Prepare to bring up the network */
1346 struct lnet_res_container **recs;
1349 if (requested_pid == LNET_PID_ANY) {
1350 /* Don't instantiate LNET just for me */
1354 LASSERT(the_lnet.ln_refcount == 0);
1356 the_lnet.ln_routing = 0;
1358 LASSERT((requested_pid & LNET_PID_USERFLAG) == 0);
1359 the_lnet.ln_pid = requested_pid;
1361 INIT_LIST_HEAD(&the_lnet.ln_test_peers);
1362 INIT_LIST_HEAD(&the_lnet.ln_remote_peer_ni_list);
1363 INIT_LIST_HEAD(&the_lnet.ln_nets);
1364 INIT_LIST_HEAD(&the_lnet.ln_routers);
1365 INIT_LIST_HEAD(&the_lnet.ln_drop_rules);
1366 INIT_LIST_HEAD(&the_lnet.ln_delay_rules);
1367 INIT_LIST_HEAD(&the_lnet.ln_dc_request);
1368 INIT_LIST_HEAD(&the_lnet.ln_dc_working);
1369 INIT_LIST_HEAD(&the_lnet.ln_dc_expired);
1370 INIT_LIST_HEAD(&the_lnet.ln_mt_localNIRecovq);
1371 INIT_LIST_HEAD(&the_lnet.ln_mt_peerNIRecovq);
1372 INIT_LIST_HEAD(&the_lnet.ln_udsp_list);
1373 init_waitqueue_head(&the_lnet.ln_dc_waitq);
1374 the_lnet.ln_mt_handler = NULL;
1375 init_completion(&the_lnet.ln_started);
1376 atomic_set(&the_lnet.ln_late_msg_count, 0);
1377 atomic64_set(&the_lnet.ln_late_msg_nsecs, 0);
1379 rc = lnet_slab_setup();
1383 rc = lnet_create_remote_nets_table();
1388 * NB the interface cookie in wire handles guards against delayed
1389 * replies and ACKs appearing valid after reboot.
1391 the_lnet.ln_interface_cookie = ktime_get_real_ns();
1393 the_lnet.ln_counters = cfs_percpt_alloc(lnet_cpt_table(),
1394 sizeof(struct lnet_counters));
1395 if (the_lnet.ln_counters == NULL) {
1396 CERROR("Failed to allocate counters for LNet\n");
1401 rc = lnet_peer_tables_create();
1405 rc = lnet_msg_containers_create();
1409 rc = lnet_res_container_setup(&the_lnet.ln_eq_container, 0,
1410 LNET_COOKIE_TYPE_EQ);
1414 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD);
1420 the_lnet.ln_md_containers = recs;
1422 rc = lnet_portals_create();
1424 CERROR("Failed to create portals for LNet: %d\n", rc);
1428 the_lnet.ln_mt_zombie_rstqs = lnet_create_array_of_queues();
1429 if (!the_lnet.ln_mt_zombie_rstqs) {
1442 lnet_unprepare(void)
1444 /* NB no LNET_LOCK since this is the last reference. All LND instances
1445 * have shut down already, so it is safe to unlink and free all
1446 * descriptors, even those that appear committed to a network op (eg MD
1447 * with non-zero pending count) */
1449 lnet_fail_nid(LNET_NID_ANY, 0);
1451 LASSERT(the_lnet.ln_refcount == 0);
1452 LASSERT(list_empty(&the_lnet.ln_test_peers));
1453 LASSERT(list_empty(&the_lnet.ln_nets));
1455 if (the_lnet.ln_mt_zombie_rstqs) {
1456 lnet_clean_zombie_rstqs();
1457 the_lnet.ln_mt_zombie_rstqs = NULL;
1460 lnet_assert_handler_unused(the_lnet.ln_mt_handler);
1461 the_lnet.ln_mt_handler = NULL;
1463 lnet_portals_destroy();
1465 if (the_lnet.ln_md_containers != NULL) {
1466 lnet_res_containers_destroy(the_lnet.ln_md_containers);
1467 the_lnet.ln_md_containers = NULL;
1470 lnet_res_container_cleanup(&the_lnet.ln_eq_container);
1472 lnet_msg_containers_destroy();
1474 lnet_rtrpools_free(0);
1476 if (the_lnet.ln_counters != NULL) {
1477 cfs_percpt_free(the_lnet.ln_counters);
1478 the_lnet.ln_counters = NULL;
1480 lnet_destroy_remote_nets_table();
1481 lnet_udsp_destroy(true);
1482 lnet_slab_cleanup();
1488 lnet_net2ni_locked(__u32 net_id, int cpt)
1491 struct lnet_net *net;
1493 LASSERT(cpt != LNET_LOCK_EX);
1495 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1496 if (net->net_id == net_id) {
1497 ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
1507 lnet_net2ni_addref(__u32 net)
1512 ni = lnet_net2ni_locked(net, 0);
1514 lnet_ni_addref_locked(ni, 0);
1519 EXPORT_SYMBOL(lnet_net2ni_addref);
1522 lnet_get_net_locked(__u32 net_id)
1524 struct lnet_net *net;
1526 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1527 if (net->net_id == net_id)
1535 lnet_net_clr_pref_rtrs(struct lnet_net *net)
1537 struct list_head zombies;
1538 struct lnet_nid_list *ne;
1539 struct lnet_nid_list *tmp;
1541 INIT_LIST_HEAD(&zombies);
1543 lnet_net_lock(LNET_LOCK_EX);
1544 list_splice_init(&net->net_rtr_pref_nids, &zombies);
1545 lnet_net_unlock(LNET_LOCK_EX);
1547 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1548 list_del_init(&ne->nl_list);
1549 LIBCFS_FREE(ne, sizeof(*ne));
1554 lnet_net_add_pref_rtr(struct lnet_net *net,
1555 struct lnet_nid *gw_nid)
1556 __must_hold(&the_lnet.ln_api_mutex)
1558 struct lnet_nid_list *ne;
1560 /* This function is called with api_mutex held. When the api_mutex
1561 * is held the list can not be modified, as it is only modified as
1562 * a result of applying a UDSP and that happens under api_mutex
1565 list_for_each_entry(ne, &net->net_rtr_pref_nids, nl_list) {
1566 if (nid_same(&ne->nl_nid, gw_nid))
1570 LIBCFS_ALLOC(ne, sizeof(*ne));
1574 ne->nl_nid = *gw_nid;
1576 /* Lock the cpt to protect against addition and checks in the
1577 * selection algorithm
1579 lnet_net_lock(LNET_LOCK_EX);
1580 list_add(&ne->nl_list, &net->net_rtr_pref_nids);
1581 lnet_net_unlock(LNET_LOCK_EX);
1587 lnet_nid4_cpt_hash(lnet_nid_t nid, unsigned int number)
1590 __u16 lnd = LNET_NETTYP(LNET_NIDNET(nid));
1593 if (lnd == KFILND || lnd == GNILND) {
1594 cpt = hash_long(key, LNET_CPT_BITS);
1596 /* NB: The number of CPTs needn't be a power of 2 */
1598 cpt = (key + cpt + (cpt >> 1)) % number;
1600 __u64 pair_bits = 0x0001000100010001LLU;
1601 __u64 mask = pair_bits * 0xFF;
1603 /* For ipv4 NIDs, use (sum-by-multiplication of nid bytes) mod
1604 * (number of CPTs) to match nid to a CPT.
1606 pair_sum = (key & mask) + ((key >> 8) & mask);
1607 pair_sum = (pair_sum * pair_bits) >> 48;
1608 cpt = (unsigned int)(pair_sum) % number;
1611 CDEBUG(D_NET, "Match nid %s to cpt %u\n",
1612 libcfs_nid2str(nid), cpt);
1618 lnet_nid_cpt_hash(struct lnet_nid *nid, unsigned int number)
1624 LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
1629 if (nid_is_nid4(nid))
1630 return lnet_nid4_cpt_hash(lnet_nid_to_nid4(nid), number);
1632 for (i = 0; i < 4; i++)
1633 h = cfs_hash_32(nid->nid_addr[i]^h, 32);
1634 val = cfs_hash_32(LNET_NID_NET(nid) ^ h, LNET_CPT_BITS);
1637 return (unsigned int)(h + val + (val >> 1)) % number;
1641 lnet_cpt_of_nid_locked(struct lnet_nid *nid, struct lnet_ni *ni)
1643 struct lnet_net *net;
1645 /* must called with hold of lnet_net_lock */
1646 if (LNET_CPT_NUMBER == 1)
1647 return 0; /* the only one */
1650 * If NI is provided then use the CPT identified in the NI cpt
1651 * list if one exists. If one doesn't exist, then that NI is
1652 * associated with all CPTs and it follows that the net it belongs
1653 * to is implicitly associated with all CPTs, so just hash the nid
1657 if (ni->ni_cpts != NULL)
1658 return ni->ni_cpts[lnet_nid_cpt_hash(nid,
1661 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1664 /* no NI provided so look at the net */
1665 net = lnet_get_net_locked(LNET_NID_NET(nid));
1667 if (net != NULL && net->net_cpts != NULL) {
1668 return net->net_cpts[lnet_nid_cpt_hash(nid, net->net_ncpts)];
1671 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1675 lnet_nid2cpt(struct lnet_nid *nid, struct lnet_ni *ni)
1680 if (LNET_CPT_NUMBER == 1)
1681 return 0; /* the only one */
1683 cpt = lnet_net_lock_current();
1685 cpt2 = lnet_cpt_of_nid_locked(nid, ni);
1687 lnet_net_unlock(cpt);
1691 EXPORT_SYMBOL(lnet_nid2cpt);
1694 lnet_cpt_of_nid(lnet_nid_t nid4, struct lnet_ni *ni)
1696 struct lnet_nid nid;
1698 if (LNET_CPT_NUMBER == 1)
1699 return 0; /* the only one */
1701 lnet_nid4_to_nid(nid4, &nid);
1702 return lnet_nid2cpt(&nid, ni);
1704 EXPORT_SYMBOL(lnet_cpt_of_nid);
1707 lnet_islocalnet_locked(__u32 net_id)
1709 struct lnet_net *net;
1712 net = lnet_get_net_locked(net_id);
1714 local = net != NULL;
1720 lnet_islocalnet(__u32 net_id)
1725 cpt = lnet_net_lock_current();
1727 local = lnet_islocalnet_locked(net_id);
1729 lnet_net_unlock(cpt);
1735 lnet_nid_to_ni_locked(struct lnet_nid *nid, int cpt)
1737 struct lnet_net *net;
1740 LASSERT(cpt != LNET_LOCK_EX);
1742 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1743 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1744 if (nid_same(&ni->ni_nid, nid))
1753 lnet_nid_to_ni_addref(struct lnet_nid *nid)
1758 ni = lnet_nid_to_ni_locked(nid, 0);
1760 lnet_ni_addref_locked(ni, 0);
1765 EXPORT_SYMBOL(lnet_nid_to_ni_addref);
1768 lnet_islocalnid(struct lnet_nid *nid)
1773 cpt = lnet_net_lock_current();
1774 ni = lnet_nid_to_ni_locked(nid, cpt);
1775 lnet_net_unlock(cpt);
1781 lnet_count_acceptor_nets(void)
1783 /* Return the # of NIs that need the acceptor. */
1785 struct lnet_net *net;
1788 cpt = lnet_net_lock_current();
1789 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1790 /* all socklnd type networks should have the acceptor
1792 if (net->net_lnd->lnd_accept != NULL)
1796 lnet_net_unlock(cpt);
1801 struct lnet_ping_buffer *
1802 lnet_ping_buffer_alloc(int nbytes, gfp_t gfp)
1804 struct lnet_ping_buffer *pbuf;
1806 LIBCFS_ALLOC_GFP(pbuf, LNET_PING_BUFFER_SIZE(nbytes), gfp);
1808 pbuf->pb_nbytes = nbytes; /* sizeof of pb_info */
1809 pbuf->pb_needs_post = false;
1810 atomic_set(&pbuf->pb_refcnt, 1);
1817 lnet_ping_buffer_free(struct lnet_ping_buffer *pbuf)
1819 LASSERT(atomic_read(&pbuf->pb_refcnt) == 0);
1820 LIBCFS_FREE(pbuf, LNET_PING_BUFFER_SIZE(pbuf->pb_nbytes));
1823 static struct lnet_ping_buffer *
1824 lnet_ping_target_create(int nbytes)
1826 struct lnet_ping_buffer *pbuf;
1828 pbuf = lnet_ping_buffer_alloc(nbytes, GFP_NOFS);
1830 CERROR("Can't allocate ping source [%d]\n", nbytes);
1834 pbuf->pb_info.pi_nnis = 0;
1835 pbuf->pb_info.pi_pid = the_lnet.ln_pid;
1836 pbuf->pb_info.pi_magic = LNET_PROTO_PING_MAGIC;
1837 pbuf->pb_info.pi_features =
1838 LNET_PING_FEAT_NI_STATUS | LNET_PING_FEAT_MULTI_RAIL;
1844 lnet_get_net_ni_bytes_locked(struct lnet_net *net)
1849 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1850 bytes += lnet_ping_sts_size(&ni->ni_nid);
1856 lnet_get_ni_bytes(void)
1859 struct lnet_net *net;
1864 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1865 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1866 bytes += lnet_ping_sts_size(&ni->ni_nid);
1875 lnet_swap_pinginfo(struct lnet_ping_buffer *pbuf)
1877 struct lnet_ni_large_status *lstat, *lend;
1878 struct lnet_ni_status *stat, *end;
1882 __swab32s(&pbuf->pb_info.pi_magic);
1883 __swab32s(&pbuf->pb_info.pi_features);
1884 __swab32s(&pbuf->pb_info.pi_pid);
1885 __swab32s(&pbuf->pb_info.pi_nnis);
1886 nnis = pbuf->pb_info.pi_nnis;
1887 stat = &pbuf->pb_info.pi_ni[0];
1888 end = (void *)&pbuf->pb_info + pbuf->pb_nbytes;
1889 for (i = 0; i < nnis && stat + 1 <= end; i++, stat++) {
1890 __swab64s(&stat->ns_nid);
1891 __swab32s(&stat->ns_status);
1893 /* Might be total size */
1894 __swab32s(&stat->ns_msg_size);
1896 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_LARGE_ADDR))
1899 lstat = (struct lnet_ni_large_status *)stat;
1901 while (lstat + 1 <= lend) {
1902 __swab32s(&lstat->ns_status);
1903 /* struct lnet_nid never needs to be swabed */
1904 lstat = lnet_ping_sts_next(lstat);
1909 lnet_ping_info_validate(struct lnet_ping_info *pinfo)
1913 if (pinfo->pi_magic != LNET_PROTO_PING_MAGIC)
1915 if (!(pinfo->pi_features & LNET_PING_FEAT_NI_STATUS))
1917 /* Loopback is guaranteed to be present */
1918 if (pinfo->pi_nnis < 1 || pinfo->pi_nnis > lnet_interfaces_max)
1920 if (LNET_PING_INFO_LONI(pinfo) != LNET_NID_LO_0)
1926 lnet_ping_target_destroy(void)
1928 struct lnet_net *net;
1931 lnet_net_lock(LNET_LOCK_EX);
1933 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1934 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1936 ni->ni_status = NULL;
1941 lnet_ping_buffer_decref(the_lnet.ln_ping_target);
1942 the_lnet.ln_ping_target = NULL;
1944 lnet_net_unlock(LNET_LOCK_EX);
1948 lnet_ping_target_event_handler(struct lnet_event *event)
1950 struct lnet_ping_buffer *pbuf = event->md_user_ptr;
1952 if (event->unlinked)
1953 lnet_ping_buffer_decref(pbuf);
1957 lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
1958 struct lnet_handle_md *ping_mdh,
1959 int ni_bytes, bool set_eq)
1961 struct lnet_processid id = {
1962 .nid = LNET_ANY_NID,
1966 struct lnet_md md = { NULL };
1970 the_lnet.ln_ping_target_handler =
1971 lnet_ping_target_event_handler;
1973 *ppbuf = lnet_ping_target_create(ni_bytes);
1974 if (*ppbuf == NULL) {
1979 /* Ping target ME/MD */
1980 me = LNetMEAttach(LNET_RESERVED_PORTAL, &id,
1981 LNET_PROTO_PING_MATCHBITS, 0,
1982 LNET_UNLINK, LNET_INS_AFTER);
1985 CERROR("Can't create ping target ME: %d\n", rc);
1986 goto fail_decref_ping_buffer;
1989 /* initialize md content */
1990 md.start = &(*ppbuf)->pb_info;
1991 md.length = (*ppbuf)->pb_nbytes;
1992 md.threshold = LNET_MD_THRESH_INF;
1994 md.options = LNET_MD_OP_GET | LNET_MD_TRUNCATE |
1995 LNET_MD_MANAGE_REMOTE;
1996 md.handler = the_lnet.ln_ping_target_handler;
1997 md.user_ptr = *ppbuf;
1999 rc = LNetMDAttach(me, &md, LNET_RETAIN, ping_mdh);
2001 CERROR("Can't attach ping target MD: %d\n", rc);
2002 goto fail_decref_ping_buffer;
2004 lnet_ping_buffer_addref(*ppbuf);
2008 fail_decref_ping_buffer:
2009 LASSERT(atomic_read(&(*ppbuf)->pb_refcnt) == 1);
2010 lnet_ping_buffer_decref(*ppbuf);
2017 lnet_ping_md_unlink(struct lnet_ping_buffer *pbuf,
2018 struct lnet_handle_md *ping_mdh)
2020 LNetMDUnlink(*ping_mdh);
2021 LNetInvalidateMDHandle(ping_mdh);
2023 /* NB the MD could be busy; this just starts the unlink */
2024 wait_var_event_warning(&pbuf->pb_refcnt,
2025 atomic_read(&pbuf->pb_refcnt) <= 1,
2026 "Still waiting for ping data MD to unlink\n");
2030 lnet_ping_target_install_locked(struct lnet_ping_buffer *pbuf)
2033 struct lnet_net *net;
2034 struct lnet_ni_status *ns, *end;
2035 struct lnet_ni_large_status *lns, *lend;
2038 pbuf->pb_info.pi_nnis = 0;
2039 ns = &pbuf->pb_info.pi_ni[0];
2040 end = (void *)&pbuf->pb_info + pbuf->pb_nbytes;
2041 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
2042 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
2043 if (!nid_is_nid4(&ni->ni_nid)) {
2044 if (ns == &pbuf->pb_info.pi_ni[1]) {
2045 /* This is primary, and it is long */
2046 pbuf->pb_info.pi_features |=
2047 LNET_PING_FEAT_PRIMARY_LARGE;
2051 LASSERT(ns + 1 <= end);
2052 ns->ns_nid = lnet_nid_to_nid4(&ni->ni_nid);
2055 ns->ns_status = lnet_ni_get_status_locked(ni);
2056 ni->ni_status = &ns->ns_status;
2059 pbuf->pb_info.pi_nnis++;
2066 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
2067 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
2068 if (nid_is_nid4(&ni->ni_nid))
2070 LASSERT(lns + 1 <= lend);
2072 lns->ns_nid = ni->ni_nid;
2075 ns->ns_status = lnet_ni_get_status_locked(ni);
2076 ni->ni_status = &lns->ns_status;
2079 lns = lnet_ping_sts_next(lns);
2082 if ((void *)lns > (void *)ns) {
2083 /* Record total info size */
2084 pbuf->pb_info.pi_ni[0].ns_msg_size =
2085 (void *)lns - (void *)&pbuf->pb_info;
2086 pbuf->pb_info.pi_features |= LNET_PING_FEAT_LARGE_ADDR;
2089 /* We (ab)use the ns_status of the loopback interface to
2090 * transmit the sequence number. The first interface listed
2091 * must be the loopback interface.
2093 rc = lnet_ping_info_validate(&pbuf->pb_info);
2095 LCONSOLE_EMERG("Invalid ping target: %d\n", rc);
2098 LNET_PING_BUFFER_SEQNO(pbuf) =
2099 atomic_inc_return(&the_lnet.ln_ping_target_seqno);
2103 lnet_ping_target_update(struct lnet_ping_buffer *pbuf,
2104 struct lnet_handle_md ping_mdh)
2105 __must_hold(&the_lnet.ln_api_mutex)
2107 struct lnet_ping_buffer *old_pbuf = NULL;
2108 struct lnet_handle_md old_ping_md;
2110 /* switch the NIs to point to the new ping info created */
2111 lnet_net_lock(LNET_LOCK_EX);
2113 if (!the_lnet.ln_routing)
2114 pbuf->pb_info.pi_features |= LNET_PING_FEAT_RTE_DISABLED;
2115 if (!lnet_peer_discovery_disabled)
2116 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
2118 /* Ensure only known feature bits have been set. */
2119 LASSERT(pbuf->pb_info.pi_features & LNET_PING_FEAT_BITS);
2120 LASSERT(!(pbuf->pb_info.pi_features & ~LNET_PING_FEAT_BITS));
2122 lnet_ping_target_install_locked(pbuf);
2124 if (the_lnet.ln_ping_target) {
2125 old_pbuf = the_lnet.ln_ping_target;
2126 old_ping_md = the_lnet.ln_ping_target_md;
2128 the_lnet.ln_ping_target_md = ping_mdh;
2129 the_lnet.ln_ping_target = pbuf;
2131 lnet_net_unlock(LNET_LOCK_EX);
2134 /* unlink and free the old ping info.
2135 * There may be outstanding traffic on this MD, and
2136 * ln_api_mutex may be required to finalize that
2137 * traffic. Release ln_api_mutex while we wait for
2138 * refs on this ping buffer to drop
2140 mutex_unlock(&the_lnet.ln_api_mutex);
2141 lnet_ping_md_unlink(old_pbuf, &old_ping_md);
2142 mutex_lock(&the_lnet.ln_api_mutex);
2143 lnet_ping_buffer_decref(old_pbuf);
2146 lnet_push_update_to_peers(0);
2150 lnet_ping_target_fini(void)
2152 lnet_ping_md_unlink(the_lnet.ln_ping_target,
2153 &the_lnet.ln_ping_target_md);
2155 lnet_assert_handler_unused(the_lnet.ln_ping_target_handler);
2156 lnet_ping_target_destroy();
2159 /* Resize the push target. */
2160 int lnet_push_target_resize(void)
2162 struct lnet_handle_md mdh;
2163 struct lnet_handle_md old_mdh;
2164 struct lnet_ping_buffer *pbuf;
2165 struct lnet_ping_buffer *old_pbuf;
2170 nbytes = the_lnet.ln_push_target_nbytes;
2172 CDEBUG(D_NET, "Invalid nbytes %d\n", nbytes);
2176 /* NB: lnet_ping_buffer_alloc() sets pbuf refcount to 1. That ref is
2177 * dropped when we need to resize again (see "old_pbuf" below) or when
2178 * LNet is shutdown (see lnet_push_target_fini())
2180 pbuf = lnet_ping_buffer_alloc(nbytes, GFP_NOFS);
2182 CDEBUG(D_NET, "Can't allocate pbuf for nbytes %d\n", nbytes);
2186 rc = lnet_push_target_post(pbuf, &mdh);
2188 CDEBUG(D_NET, "Failed to post push target: %d\n", rc);
2189 lnet_ping_buffer_decref(pbuf);
2193 lnet_net_lock(LNET_LOCK_EX);
2194 old_pbuf = the_lnet.ln_push_target;
2195 old_mdh = the_lnet.ln_push_target_md;
2196 the_lnet.ln_push_target = pbuf;
2197 the_lnet.ln_push_target_md = mdh;
2198 lnet_net_unlock(LNET_LOCK_EX);
2201 LNetMDUnlink(old_mdh);
2202 /* Drop ref set by lnet_ping_buffer_alloc() */
2203 lnet_ping_buffer_decref(old_pbuf);
2206 /* Received another push or reply that requires a larger buffer */
2207 if (nbytes < the_lnet.ln_push_target_nbytes)
2210 CDEBUG(D_NET, "nbytes %d success\n", nbytes);
2214 int lnet_push_target_post(struct lnet_ping_buffer *pbuf,
2215 struct lnet_handle_md *mdhp)
2217 struct lnet_processid id = { LNET_ANY_NID, LNET_PID_ANY };
2218 struct lnet_md md = { NULL };
2222 me = LNetMEAttach(LNET_RESERVED_PORTAL, &id,
2223 LNET_PROTO_PING_MATCHBITS, 0,
2224 LNET_UNLINK, LNET_INS_AFTER);
2227 CERROR("Can't create push target ME: %d\n", rc);
2231 pbuf->pb_needs_post = false;
2233 /* This reference is dropped by lnet_push_target_event_handler() */
2234 lnet_ping_buffer_addref(pbuf);
2236 /* initialize md content */
2237 md.start = &pbuf->pb_info;
2238 md.length = pbuf->pb_nbytes;
2241 md.options = LNET_MD_OP_PUT | LNET_MD_TRUNCATE;
2243 md.handler = the_lnet.ln_push_target_handler;
2245 rc = LNetMDAttach(me, &md, LNET_UNLINK, mdhp);
2247 CERROR("Can't attach push MD: %d\n", rc);
2248 lnet_ping_buffer_decref(pbuf);
2249 pbuf->pb_needs_post = true;
2253 CDEBUG(D_NET, "posted push target %p\n", pbuf);
2258 static void lnet_push_target_event_handler(struct lnet_event *ev)
2260 struct lnet_ping_buffer *pbuf = ev->md_user_ptr;
2262 CDEBUG(D_NET, "type %d status %d unlinked %d\n", ev->type, ev->status,
2265 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
2266 lnet_swap_pinginfo(pbuf);
2268 if (ev->type == LNET_EVENT_UNLINK) {
2269 /* Drop ref added by lnet_push_target_post() */
2270 lnet_ping_buffer_decref(pbuf);
2274 lnet_peer_push_event(ev);
2276 /* Drop ref added by lnet_push_target_post */
2277 lnet_ping_buffer_decref(pbuf);
2280 /* Initialize the push target. */
2281 static int lnet_push_target_init(void)
2285 if (the_lnet.ln_push_target)
2288 the_lnet.ln_push_target_handler =
2289 lnet_push_target_event_handler;
2291 rc = LNetSetLazyPortal(LNET_RESERVED_PORTAL);
2294 /* Start at the required minimum, we'll enlarge if required. */
2295 the_lnet.ln_push_target_nbytes = LNET_PING_INFO_MIN_SIZE;
2297 rc = lnet_push_target_resize();
2299 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2300 the_lnet.ln_push_target_handler = NULL;
2306 /* Clean up the push target. */
2307 static void lnet_push_target_fini(void)
2309 if (!the_lnet.ln_push_target)
2312 /* Unlink and invalidate to prevent new references. */
2313 LNetMDUnlink(the_lnet.ln_push_target_md);
2314 LNetInvalidateMDHandle(&the_lnet.ln_push_target_md);
2316 /* Wait for the unlink to complete. */
2317 wait_var_event_warning(&the_lnet.ln_push_target->pb_refcnt,
2318 atomic_read(&the_lnet.ln_push_target->pb_refcnt) <= 1,
2319 "Still waiting for ping data MD to unlink\n");
2321 /* Drop ref set by lnet_ping_buffer_alloc() */
2322 lnet_ping_buffer_decref(the_lnet.ln_push_target);
2323 the_lnet.ln_push_target = NULL;
2324 the_lnet.ln_push_target_nbytes = 0;
2326 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2327 lnet_assert_handler_unused(the_lnet.ln_push_target_handler);
2328 the_lnet.ln_push_target_handler = NULL;
2332 lnet_ni_tq_credits(struct lnet_ni *ni)
2336 LASSERT(ni->ni_ncpts >= 1);
2338 if (ni->ni_ncpts == 1)
2339 return ni->ni_net->net_tunables.lct_max_tx_credits;
2341 credits = ni->ni_net->net_tunables.lct_max_tx_credits / ni->ni_ncpts;
2342 credits = max(credits, 8 * ni->ni_net->net_tunables.lct_peer_tx_credits);
2343 credits = min(credits, ni->ni_net->net_tunables.lct_max_tx_credits);
2349 lnet_ni_unlink_locked(struct lnet_ni *ni)
2351 /* move it to zombie list and nobody can find it anymore */
2352 LASSERT(!list_empty(&ni->ni_netlist));
2353 list_move(&ni->ni_netlist, &ni->ni_net->net_ni_zombie);
2354 lnet_ni_decref_locked(ni, 0);
2358 lnet_clear_zombies_nis_locked(struct lnet_net *net)
2363 struct list_head *zombie_list = &net->net_ni_zombie;
2366 * Now wait for the NIs I just nuked to show up on the zombie
2367 * list and shut them down in guaranteed thread context
2370 while ((ni = list_first_entry_or_null(zombie_list,
2372 ni_netlist)) != NULL) {
2376 list_del_init(&ni->ni_netlist);
2377 /* the ni should be in deleting state. If it's not it's
2379 LASSERT(ni->ni_state == LNET_NI_STATE_DELETING);
2380 cfs_percpt_for_each(ref, j, ni->ni_refs) {
2383 /* still busy, add it back to zombie list */
2384 list_add(&ni->ni_netlist, zombie_list);
2388 if (!list_empty(&ni->ni_netlist)) {
2389 /* Unlock mutex while waiting to allow other
2390 * threads to read the LNet state and fall through
2393 lnet_net_unlock(LNET_LOCK_EX);
2394 mutex_unlock(&the_lnet.ln_api_mutex);
2397 if ((i & (-i)) == i) {
2399 "Waiting for zombie LNI %s\n",
2400 libcfs_nidstr(&ni->ni_nid));
2402 schedule_timeout_uninterruptible(cfs_time_seconds(1));
2404 mutex_lock(&the_lnet.ln_api_mutex);
2405 lnet_net_lock(LNET_LOCK_EX);
2409 lnet_net_unlock(LNET_LOCK_EX);
2411 islo = ni->ni_net->net_lnd->lnd_type == LOLND;
2413 LASSERT(!in_interrupt());
2414 /* Holding the LND mutex makes it safe for lnd_shutdown
2415 * to call module_put(). Module unload cannot finish
2416 * until lnet_unregister_lnd() completes, and that
2417 * requires the LND mutex.
2419 mutex_unlock(&the_lnet.ln_api_mutex);
2420 mutex_lock(&the_lnet.ln_lnd_mutex);
2421 (net->net_lnd->lnd_shutdown)(ni);
2422 mutex_unlock(&the_lnet.ln_lnd_mutex);
2423 mutex_lock(&the_lnet.ln_api_mutex);
2426 CDEBUG(D_LNI, "Removed LNI %s\n",
2427 libcfs_nidstr(&ni->ni_nid));
2431 lnet_net_lock(LNET_LOCK_EX);
2435 /* shutdown down the NI and release refcount */
2437 lnet_shutdown_lndni(struct lnet_ni *ni)
2440 struct lnet_net *net = ni->ni_net;
2442 lnet_net_lock(LNET_LOCK_EX);
2444 ni->ni_state = LNET_NI_STATE_DELETING;
2446 lnet_ni_unlink_locked(ni);
2447 lnet_incr_dlc_seq();
2448 lnet_net_unlock(LNET_LOCK_EX);
2450 /* clear messages for this NI on the lazy portal */
2451 for (i = 0; i < the_lnet.ln_nportals; i++)
2452 lnet_clear_lazy_portal(ni, i, "Shutting down NI");
2454 lnet_net_lock(LNET_LOCK_EX);
2455 lnet_clear_zombies_nis_locked(net);
2456 lnet_net_unlock(LNET_LOCK_EX);
2460 lnet_shutdown_lndnet(struct lnet_net *net)
2464 lnet_net_lock(LNET_LOCK_EX);
2466 list_del_init(&net->net_list);
2468 while ((ni = list_first_entry_or_null(&net->net_ni_list,
2470 ni_netlist)) != NULL) {
2471 lnet_net_unlock(LNET_LOCK_EX);
2472 lnet_shutdown_lndni(ni);
2473 lnet_net_lock(LNET_LOCK_EX);
2476 lnet_net_unlock(LNET_LOCK_EX);
2478 /* Do peer table cleanup for this net */
2479 lnet_peer_tables_cleanup(net);
2485 lnet_shutdown_lndnets(void)
2487 struct lnet_net *net;
2489 struct lnet_msg *msg, *tmp;
2491 /* NB called holding the global mutex */
2493 /* All quiet on the API front */
2494 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING ||
2495 the_lnet.ln_state == LNET_STATE_STOPPING);
2496 LASSERT(the_lnet.ln_refcount == 0);
2498 lnet_net_lock(LNET_LOCK_EX);
2499 the_lnet.ln_state = LNET_STATE_STOPPING;
2502 * move the nets to the zombie list to avoid them being
2503 * picked up for new work. LONET is also included in the
2504 * Nets that will be moved to the zombie list
2506 list_splice_init(&the_lnet.ln_nets, &the_lnet.ln_net_zombie);
2508 /* Drop the cached loopback Net. */
2509 if (the_lnet.ln_loni != NULL) {
2510 lnet_ni_decref_locked(the_lnet.ln_loni, 0);
2511 the_lnet.ln_loni = NULL;
2513 lnet_net_unlock(LNET_LOCK_EX);
2515 /* iterate through the net zombie list and delete each net */
2516 while ((net = list_first_entry_or_null(&the_lnet.ln_net_zombie,
2519 lnet_shutdown_lndnet(net);
2521 spin_lock(&the_lnet.ln_msg_resend_lock);
2522 list_splice(&the_lnet.ln_msg_resend, &resend);
2523 spin_unlock(&the_lnet.ln_msg_resend_lock);
2525 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
2526 list_del_init(&msg->msg_list);
2527 msg->msg_no_resend = true;
2528 lnet_finalize(msg, -ECANCELED);
2531 lnet_net_lock(LNET_LOCK_EX);
2532 the_lnet.ln_state = LNET_STATE_SHUTDOWN;
2533 lnet_net_unlock(LNET_LOCK_EX);
2537 lnet_startup_lndni(struct lnet_ni *ni, struct lnet_lnd_tunables *tun)
2540 struct lnet_tx_queue *tq;
2542 struct lnet_net *net = ni->ni_net;
2544 mutex_lock(&the_lnet.ln_lnd_mutex);
2547 memcpy(&ni->ni_lnd_tunables, tun, sizeof(*tun));
2548 ni->ni_lnd_tunables_set = true;
2551 rc = (net->net_lnd->lnd_startup)(ni);
2553 mutex_unlock(&the_lnet.ln_lnd_mutex);
2556 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s\n",
2557 rc, libcfs_lnd2str(net->net_lnd->lnd_type));
2561 /* We keep a reference on the loopback net through the loopback NI */
2562 if (net->net_lnd->lnd_type == LOLND) {
2564 LASSERT(the_lnet.ln_loni == NULL);
2565 the_lnet.ln_loni = ni;
2566 ni->ni_net->net_tunables.lct_peer_tx_credits = 0;
2567 ni->ni_net->net_tunables.lct_peer_rtr_credits = 0;
2568 ni->ni_net->net_tunables.lct_max_tx_credits = 0;
2569 ni->ni_net->net_tunables.lct_peer_timeout = 0;
2573 if (ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ||
2574 ni->ni_net->net_tunables.lct_max_tx_credits == 0) {
2575 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
2576 libcfs_lnd2str(net->net_lnd->lnd_type),
2577 ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ?
2579 /* shutdown the NI since if we get here then it must've already
2582 lnet_shutdown_lndni(ni);
2586 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
2587 tq->tq_credits_min =
2588 tq->tq_credits_max =
2589 tq->tq_credits = lnet_ni_tq_credits(ni);
2592 atomic_set(&ni->ni_tx_credits,
2593 lnet_ni_tq_credits(ni) * ni->ni_ncpts);
2594 atomic_set(&ni->ni_healthv, LNET_MAX_HEALTH_VALUE);
2596 /* Nodes with small feet have little entropy. The NID for this
2597 * node gives the most entropy in the low bits.
2599 add_device_randomness(&ni->ni_nid, sizeof(ni->ni_nid));
2601 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d/%d]\n",
2602 libcfs_nidstr(&ni->ni_nid),
2603 ni->ni_net->net_tunables.lct_peer_tx_credits,
2604 lnet_ni_tq_credits(ni) * LNET_CPT_NUMBER,
2605 ni->ni_net->net_tunables.lct_peer_rtr_credits,
2606 ni->ni_net->net_tunables.lct_peer_timeout);
2614 static const struct lnet_lnd *lnet_load_lnd(u32 lnd_type)
2616 const struct lnet_lnd *lnd;
2619 mutex_lock(&the_lnet.ln_lnd_mutex);
2620 lnd = lnet_find_lnd_by_type(lnd_type);
2622 mutex_unlock(&the_lnet.ln_lnd_mutex);
2623 rc = request_module("%s", libcfs_lnd2modname(lnd_type));
2624 mutex_lock(&the_lnet.ln_lnd_mutex);
2626 lnd = lnet_find_lnd_by_type(lnd_type);
2628 mutex_unlock(&the_lnet.ln_lnd_mutex);
2629 CERROR("Can't load LND %s, module %s, rc=%d\n",
2630 libcfs_lnd2str(lnd_type),
2631 libcfs_lnd2modname(lnd_type), rc);
2632 #ifndef HAVE_MODULE_LOADING_SUPPORT
2633 LCONSOLE_ERROR_MSG(0x104,
2634 "Your kernel must be compiled with kernel module loading support.");
2636 return ERR_PTR(-EINVAL);
2639 mutex_unlock(&the_lnet.ln_lnd_mutex);
2645 lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
2648 struct lnet_net *net_l = NULL;
2649 LIST_HEAD(local_ni_list);
2653 const struct lnet_lnd *lnd;
2655 net->net_tunables.lct_peer_timeout;
2657 net->net_tunables.lct_max_tx_credits;
2658 int peerrtrcredits =
2659 net->net_tunables.lct_peer_rtr_credits;
2662 * make sure that this net is unique. If it isn't then
2663 * we are adding interfaces to an already existing network, and
2664 * 'net' is just a convenient way to pass in the list.
2665 * if it is unique we need to find the LND and load it if
2668 if (lnet_net_unique(net->net_id, &the_lnet.ln_nets, &net_l)) {
2669 lnd_type = LNET_NETTYP(net->net_id);
2671 lnd = lnet_load_lnd(lnd_type);
2677 mutex_lock(&the_lnet.ln_lnd_mutex);
2679 mutex_unlock(&the_lnet.ln_lnd_mutex);
2685 * net_l: if the network being added is unique then net_l
2686 * will point to that network
2687 * if the network being added is not unique then
2688 * net_l points to the existing network.
2690 * When we enter the loop below, we'll pick NIs off he
2691 * network beign added and start them up, then add them to
2692 * a local ni list. Once we've successfully started all
2693 * the NIs then we join the local NI list (of started up
2694 * networks) with the net_l->net_ni_list, which should
2695 * point to the correct network to add the new ni list to
2697 * If any of the new NIs fail to start up, then we want to
2698 * iterate through the local ni list, which should include
2699 * any NIs which were successfully started up, and shut
2702 * After than we want to delete the network being added,
2703 * to avoid a memory leak.
2705 while ((ni = list_first_entry_or_null(&net->net_ni_added,
2707 ni_netlist)) != NULL) {
2708 list_del_init(&ni->ni_netlist);
2710 /* make sure that the the NI we're about to start
2711 * up is actually unique. if it's not fail. */
2712 if (!lnet_ni_unique_net(&net_l->net_ni_list,
2713 ni->ni_interface)) {
2718 /* adjust the pointer the parent network, just in case it
2719 * the net is a duplicate */
2722 rc = lnet_startup_lndni(ni, tun);
2728 list_add_tail(&ni->ni_netlist, &local_ni_list);
2733 lnet_net_lock(LNET_LOCK_EX);
2734 list_splice_tail(&local_ni_list, &net_l->net_ni_list);
2735 lnet_incr_dlc_seq();
2737 list_for_each_entry(ni, &net_l->net_ni_list, ni_netlist) {
2741 ni->ni_state = LNET_NI_STATE_ACTIVE;
2744 lnet_net_unlock(LNET_LOCK_EX);
2746 /* if the network is not unique then we don't want to keep
2747 * it around after we're done. Free it. Otherwise add that
2748 * net to the global the_lnet.ln_nets */
2749 if (net_l != net && net_l != NULL) {
2751 * TODO - note. currently the tunables can not be updated
2757 * restore tunables after it has been overwitten by the
2760 if (peer_timeout != -1)
2761 net->net_tunables.lct_peer_timeout = peer_timeout;
2762 if (maxtxcredits != -1)
2763 net->net_tunables.lct_max_tx_credits = maxtxcredits;
2764 if (peerrtrcredits != -1)
2765 net->net_tunables.lct_peer_rtr_credits = peerrtrcredits;
2767 lnet_net_lock(LNET_LOCK_EX);
2768 list_add_tail(&net->net_list, &the_lnet.ln_nets);
2769 lnet_net_unlock(LNET_LOCK_EX);
2776 * shutdown the new NIs that are being started up
2777 * free the NET being started
2779 while ((ni = list_first_entry_or_null(&local_ni_list,
2781 ni_netlist)) != NULL)
2782 lnet_shutdown_lndni(ni);
2791 lnet_startup_lndnets(struct list_head *netlist)
2793 struct lnet_net *net;
2798 * Change to running state before bringing up the LNDs. This
2799 * allows lnet_shutdown_lndnets() to assert that we've passed
2802 lnet_net_lock(LNET_LOCK_EX);
2803 the_lnet.ln_state = LNET_STATE_RUNNING;
2804 lnet_net_unlock(LNET_LOCK_EX);
2806 while ((net = list_first_entry_or_null(netlist,
2808 net_list)) != NULL) {
2809 list_del_init(&net->net_list);
2811 rc = lnet_startup_lndnet(net, NULL);
2821 lnet_shutdown_lndnets();
2826 static int lnet_genl_parse_list(struct sk_buff *msg,
2827 const struct ln_key_list *data[], u16 idx)
2829 const struct ln_key_list *list = data[idx];
2830 const struct ln_key_props *props;
2831 struct nlattr *node;
2837 if (!list->lkl_maxattr)
2840 props = list->lkl_list;
2844 node = nla_nest_start(msg, LN_SCALAR_ATTR_LIST);
2848 for (count = 1; count <= list->lkl_maxattr; count++) {
2849 struct nlattr *key = nla_nest_start(msg, count);
2852 nla_put_u16(msg, LN_SCALAR_ATTR_LIST_SIZE,
2855 nla_put_u16(msg, LN_SCALAR_ATTR_INDEX, count);
2856 if (props[count].lkp_value)
2857 nla_put_string(msg, LN_SCALAR_ATTR_VALUE,
2858 props[count].lkp_value);
2859 if (props[count].lkp_key_format)
2860 nla_put_u16(msg, LN_SCALAR_ATTR_KEY_FORMAT,
2861 props[count].lkp_key_format);
2862 nla_put_u16(msg, LN_SCALAR_ATTR_NLA_TYPE,
2863 props[count].lkp_data_type);
2864 if (props[count].lkp_data_type == NLA_NESTED) {
2867 rc = lnet_genl_parse_list(msg, data, ++idx);
2873 nla_nest_end(msg, key);
2876 nla_nest_end(msg, node);
2880 int lnet_genl_send_scalar_list(struct sk_buff *msg, u32 portid, u32 seq,
2881 const struct genl_family *family, int flags,
2882 u8 cmd, const struct ln_key_list *data[])
2890 hdr = genlmsg_put(msg, portid, seq, family, flags, cmd);
2892 GOTO(canceled, rc = -EMSGSIZE);
2894 rc = lnet_genl_parse_list(msg, data, 0);
2898 genlmsg_end(msg, hdr);
2901 genlmsg_cancel(msg, hdr);
2902 return rc > 0 ? 0 : rc;
2904 EXPORT_SYMBOL(lnet_genl_send_scalar_list);
2906 static struct genl_family lnet_family;
2909 * Initialize LNet library.
2911 * Automatically called at module loading time. Caller has to call
2912 * lnet_lib_exit() after a call to lnet_lib_init(), if and only if the
2913 * latter returned 0. It must be called exactly once.
2915 * \retval 0 on success
2916 * \retval -ve on failures.
2918 int lnet_lib_init(void)
2922 lnet_assert_wire_constants();
2924 /* refer to global cfs_cpt_table for now */
2925 the_lnet.ln_cpt_table = cfs_cpt_tab;
2926 the_lnet.ln_cpt_number = cfs_cpt_number(cfs_cpt_tab);
2928 LASSERT(the_lnet.ln_cpt_number > 0);
2929 if (the_lnet.ln_cpt_number > LNET_CPT_MAX) {
2930 /* we are under risk of consuming all lh_cookie */
2931 CERROR("Can't have %d CPTs for LNet (max allowed is %d), "
2932 "please change setting of CPT-table and retry\n",
2933 the_lnet.ln_cpt_number, LNET_CPT_MAX);
2937 while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number)
2938 the_lnet.ln_cpt_bits++;
2940 rc = lnet_create_locks();
2942 CERROR("Can't create LNet global locks: %d\n", rc);
2946 rc = genl_register_family(&lnet_family);
2948 lnet_destroy_locks();
2949 CERROR("Can't register LNet netlink family: %d\n", rc);
2953 the_lnet.ln_refcount = 0;
2954 INIT_LIST_HEAD(&the_lnet.ln_net_zombie);
2955 INIT_LIST_HEAD(&the_lnet.ln_msg_resend);
2957 /* The hash table size is the number of bits it takes to express the set
2958 * ln_num_routes, minus 1 (better to under estimate than over so we
2959 * don't waste memory). */
2960 if (rnet_htable_size <= 0)
2961 rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
2962 else if (rnet_htable_size > LNET_REMOTE_NETS_HASH_MAX)
2963 rnet_htable_size = LNET_REMOTE_NETS_HASH_MAX;
2964 the_lnet.ln_remote_nets_hbits = max_t(int, 1,
2965 order_base_2(rnet_htable_size) - 1);
2967 /* All LNDs apart from the LOLND are in separate modules. They
2968 * register themselves when their module loads, and unregister
2969 * themselves when their module is unloaded. */
2970 lnet_register_lnd(&the_lolnd);
2975 * Finalize LNet library.
2977 * \pre lnet_lib_init() called with success.
2978 * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls.
2980 * As this happens at module-unload, all lnds must already be unloaded,
2981 * so they must already be unregistered.
2983 void lnet_lib_exit(void)
2987 LASSERT(the_lnet.ln_refcount == 0);
2988 lnet_unregister_lnd(&the_lolnd);
2989 for (i = 0; i < NUM_LNDS; i++)
2990 LASSERT(!the_lnet.ln_lnds[i]);
2991 lnet_destroy_locks();
2992 genl_unregister_family(&lnet_family);
2996 * Set LNet PID and start LNet interfaces, routing, and forwarding.
2998 * Users must call this function at least once before any other functions.
2999 * For each successful call there must be a corresponding call to
3000 * LNetNIFini(). For subsequent calls to LNetNIInit(), \a requested_pid is
3003 * The PID used by LNet may be different from the one requested.
3006 * \param requested_pid PID requested by the caller.
3008 * \return >= 0 on success, and < 0 error code on failures.
3011 LNetNIInit(lnet_pid_t requested_pid)
3013 int im_a_router = 0;
3016 struct lnet_ping_buffer *pbuf;
3017 struct lnet_handle_md ping_mdh;
3018 LIST_HEAD(net_head);
3019 struct lnet_net *net;
3021 mutex_lock(&the_lnet.ln_api_mutex);
3023 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
3025 if (the_lnet.ln_state == LNET_STATE_STOPPING) {
3026 mutex_unlock(&the_lnet.ln_api_mutex);
3030 if (the_lnet.ln_refcount > 0) {
3031 rc = the_lnet.ln_refcount++;
3032 mutex_unlock(&the_lnet.ln_api_mutex);
3036 rc = lnet_prepare(requested_pid);
3038 mutex_unlock(&the_lnet.ln_api_mutex);
3042 /* create a network for Loopback network */
3043 net = lnet_net_alloc(LNET_MKNET(LOLND, 0), &net_head);
3046 goto err_empty_list;
3049 /* Add in the loopback NI */
3050 if (lnet_ni_alloc(net, NULL, NULL) == NULL) {
3052 goto err_empty_list;
3055 if (use_tcp_bonding)
3056 CWARN("use_tcp_bonding has been removed. Use Multi-Rail and Dynamic Discovery instead, see LU-13641\n");
3058 /* If LNet is being initialized via DLC it is possible
3059 * that the user requests not to load module parameters (ones which
3060 * are supported by DLC) on initialization. Therefore, make sure not
3061 * to load networks, routes and forwarding from module parameters
3062 * in this case. On cleanup in case of failure only clean up
3063 * routes if it has been loaded */
3064 if (!the_lnet.ln_nis_from_mod_params) {
3065 rc = lnet_parse_networks(&net_head, lnet_get_networks());
3067 goto err_empty_list;
3070 rc = lnet_startup_lndnets(&net_head);
3072 goto err_empty_list;
3074 if (!the_lnet.ln_nis_from_mod_params) {
3075 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
3077 goto err_shutdown_lndnis;
3079 rc = lnet_rtrpools_alloc(im_a_router);
3081 goto err_destroy_routes;
3084 rc = lnet_acceptor_start();
3086 goto err_destroy_routes;
3088 the_lnet.ln_refcount = 1;
3089 /* Now I may use my own API functions... */
3091 ni_bytes = LNET_PING_INFO_HDR_SIZE;
3092 list_for_each_entry(net, &the_lnet.ln_nets, net_list)
3093 ni_bytes += lnet_get_net_ni_bytes_locked(net);
3095 rc = lnet_ping_target_setup(&pbuf, &ping_mdh, ni_bytes, true);
3097 goto err_acceptor_stop;
3099 lnet_ping_target_update(pbuf, ping_mdh);
3101 the_lnet.ln_mt_handler = lnet_mt_event_handler;
3103 rc = lnet_push_target_init();
3107 rc = lnet_peer_discovery_start();
3109 goto err_destroy_push_target;
3111 rc = lnet_monitor_thr_start();
3113 goto err_stop_discovery_thr;
3116 lnet_router_debugfs_init();
3118 mutex_unlock(&the_lnet.ln_api_mutex);
3120 complete_all(&the_lnet.ln_started);
3122 /* wait for all routers to start */
3123 lnet_wait_router_start();
3127 err_stop_discovery_thr:
3128 lnet_peer_discovery_stop();
3129 err_destroy_push_target:
3130 lnet_push_target_fini();
3132 lnet_ping_target_fini();
3134 the_lnet.ln_refcount = 0;
3135 lnet_acceptor_stop();
3137 if (!the_lnet.ln_nis_from_mod_params)
3138 lnet_destroy_routes();
3139 err_shutdown_lndnis:
3140 lnet_shutdown_lndnets();
3144 mutex_unlock(&the_lnet.ln_api_mutex);
3145 while ((net = list_first_entry_or_null(&net_head,
3147 net_list)) != NULL) {
3148 list_del_init(&net->net_list);
3153 EXPORT_SYMBOL(LNetNIInit);
3156 * Stop LNet interfaces, routing, and forwarding.
3158 * Users must call this function once for each successful call to LNetNIInit().
3159 * Once the LNetNIFini() operation has been started, the results of pending
3160 * API operations are undefined.
3162 * \return always 0 for current implementation.
3167 mutex_lock(&the_lnet.ln_api_mutex);
3169 LASSERT(the_lnet.ln_refcount > 0);
3171 if (the_lnet.ln_refcount != 1) {
3172 the_lnet.ln_refcount--;
3174 LASSERT(!the_lnet.ln_niinit_self);
3176 lnet_net_lock(LNET_LOCK_EX);
3177 the_lnet.ln_state = LNET_STATE_STOPPING;
3178 lnet_net_unlock(LNET_LOCK_EX);
3182 lnet_router_debugfs_fini();
3183 lnet_monitor_thr_stop();
3184 lnet_peer_discovery_stop();
3185 lnet_push_target_fini();
3186 lnet_ping_target_fini();
3188 /* Teardown fns that use my own API functions BEFORE here */
3189 the_lnet.ln_refcount = 0;
3191 lnet_acceptor_stop();
3192 lnet_destroy_routes();
3193 lnet_shutdown_lndnets();
3197 mutex_unlock(&the_lnet.ln_api_mutex);
3200 EXPORT_SYMBOL(LNetNIFini);
3203 * Grabs the ni data from the ni structure and fills the out
3206 * \param[in] ni network interface structure
3207 * \param[out] cfg_ni NI config information
3208 * \param[out] tun network and LND tunables
3211 lnet_fill_ni_info(struct lnet_ni *ni, struct lnet_ioctl_config_ni *cfg_ni,
3212 struct lnet_ioctl_config_lnd_tunables *tun,
3213 struct lnet_ioctl_element_stats *stats,
3216 size_t min_size = 0;
3219 if (!ni || !cfg_ni || !tun || !nid_is_nid4(&ni->ni_nid))
3222 if (ni->ni_interface != NULL) {
3223 strncpy(cfg_ni->lic_ni_intf,
3225 sizeof(cfg_ni->lic_ni_intf));
3228 cfg_ni->lic_nid = lnet_nid_to_nid4(&ni->ni_nid);
3229 cfg_ni->lic_status = lnet_ni_get_status_locked(ni);
3230 cfg_ni->lic_dev_cpt = ni->ni_dev_cpt;
3232 memcpy(&tun->lt_cmn, &ni->ni_net->net_tunables, sizeof(tun->lt_cmn));
3235 stats->iel_send_count = lnet_sum_stats(&ni->ni_stats,
3236 LNET_STATS_TYPE_SEND);
3237 stats->iel_recv_count = lnet_sum_stats(&ni->ni_stats,
3238 LNET_STATS_TYPE_RECV);
3239 stats->iel_drop_count = lnet_sum_stats(&ni->ni_stats,
3240 LNET_STATS_TYPE_DROP);
3244 * tun->lt_tun will always be present, but in order to be
3245 * backwards compatible, we need to deal with the cases when
3246 * tun->lt_tun is smaller than what the kernel has, because it
3247 * comes from an older version of a userspace program, then we'll
3248 * need to copy as much information as we have available space.
3250 min_size = tun_size - sizeof(tun->lt_cmn);
3251 memcpy(&tun->lt_tun, &ni->ni_lnd_tunables, min_size);
3253 /* copy over the cpts */
3254 if (ni->ni_ncpts == LNET_CPT_NUMBER &&
3255 ni->ni_cpts == NULL) {
3256 for (i = 0; i < ni->ni_ncpts; i++)
3257 cfg_ni->lic_cpts[i] = i;
3260 ni->ni_cpts != NULL && i < ni->ni_ncpts &&
3261 i < LNET_MAX_SHOW_NUM_CPT;
3263 cfg_ni->lic_cpts[i] = ni->ni_cpts[i];
3265 cfg_ni->lic_ncpts = ni->ni_ncpts;
3269 * NOTE: This is a legacy function left in the code to be backwards
3270 * compatible with older userspace programs. It should eventually be
3273 * Grabs the ni data from the ni structure and fills the out
3276 * \param[in] ni network interface structure
3277 * \param[out] config config information
3280 lnet_fill_ni_info_legacy(struct lnet_ni *ni,
3281 struct lnet_ioctl_config_data *config)
3283 struct lnet_ioctl_net_config *net_config;
3284 struct lnet_ioctl_config_lnd_tunables *lnd_cfg = NULL;
3285 size_t min_size, tunable_size = 0;
3288 if (!ni || !config || !nid_is_nid4(&ni->ni_nid))
3291 net_config = (struct lnet_ioctl_net_config *) config->cfg_bulk;
3295 if (!ni->ni_interface)
3298 strncpy(net_config->ni_interface,
3300 sizeof(net_config->ni_interface));
3302 config->cfg_nid = lnet_nid_to_nid4(&ni->ni_nid);
3303 config->cfg_config_u.cfg_net.net_peer_timeout =
3304 ni->ni_net->net_tunables.lct_peer_timeout;
3305 config->cfg_config_u.cfg_net.net_max_tx_credits =
3306 ni->ni_net->net_tunables.lct_max_tx_credits;
3307 config->cfg_config_u.cfg_net.net_peer_tx_credits =
3308 ni->ni_net->net_tunables.lct_peer_tx_credits;
3309 config->cfg_config_u.cfg_net.net_peer_rtr_credits =
3310 ni->ni_net->net_tunables.lct_peer_rtr_credits;
3312 net_config->ni_status = lnet_ni_get_status_locked(ni);
3315 int num_cpts = min(ni->ni_ncpts, LNET_MAX_SHOW_NUM_CPT);
3317 for (i = 0; i < num_cpts; i++)
3318 net_config->ni_cpts[i] = ni->ni_cpts[i];
3320 config->cfg_ncpts = num_cpts;
3324 * See if user land tools sent in a newer and larger version
3325 * of struct lnet_tunables than what the kernel uses.
3327 min_size = sizeof(*config) + sizeof(*net_config);
3329 if (config->cfg_hdr.ioc_len > min_size)
3330 tunable_size = config->cfg_hdr.ioc_len - min_size;
3332 /* Don't copy too much data to user space */
3333 min_size = min(tunable_size, sizeof(ni->ni_lnd_tunables));
3334 lnd_cfg = (struct lnet_ioctl_config_lnd_tunables *)net_config->cfg_bulk;
3336 if (lnd_cfg && min_size) {
3337 memcpy(&lnd_cfg->lt_tun, &ni->ni_lnd_tunables, min_size);
3338 config->cfg_config_u.cfg_net.net_interface_count = 1;
3340 /* Tell user land that kernel side has less data */
3341 if (tunable_size > sizeof(ni->ni_lnd_tunables)) {
3342 min_size = tunable_size - sizeof(ni->ni_lnd_tunables);
3343 config->cfg_hdr.ioc_len -= min_size;
3349 lnet_get_ni_idx_locked(int idx)
3352 struct lnet_net *net;
3354 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3355 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3364 int lnet_get_net_healthv_locked(struct lnet_net *net)
3367 int best_healthv = 0;
3368 int healthv, ni_fatal;
3370 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3371 healthv = atomic_read(&ni->ni_healthv);
3372 ni_fatal = atomic_read(&ni->ni_fatal_error_on);
3373 if (!ni_fatal && healthv > best_healthv)
3374 best_healthv = healthv;
3377 return best_healthv;
3381 lnet_get_next_ni_locked(struct lnet_net *mynet, struct lnet_ni *prev)
3384 struct lnet_net *net = mynet;
3387 * It is possible that the net has been cleaned out while there is
3388 * a message being sent. This function accessed the net without
3389 * checking if the list is empty
3393 net = list_first_entry(&the_lnet.ln_nets,
3396 if (list_empty(&net->net_ni_list))
3398 ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
3404 if (prev->ni_netlist.next == &prev->ni_net->net_ni_list) {
3405 /* if you reached the end of the ni list and the net is
3406 * specified, then there are no more nis in that net */
3410 /* we reached the end of this net ni list. move to the
3412 if (prev->ni_net->net_list.next == &the_lnet.ln_nets)
3413 /* no more nets and no more NIs. */
3416 /* get the next net */
3417 net = list_first_entry(&prev->ni_net->net_list, struct lnet_net,
3419 if (list_empty(&net->net_ni_list))
3421 /* get the ni on it */
3422 ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
3428 if (list_empty(&prev->ni_netlist))
3431 /* there are more nis left */
3432 ni = list_first_entry(&prev->ni_netlist, struct lnet_ni, ni_netlist);
3438 lnet_get_net_config(struct lnet_ioctl_config_data *config)
3443 int idx = config->cfg_count;
3445 cpt = lnet_net_lock_current();
3447 ni = lnet_get_ni_idx_locked(idx);
3452 lnet_fill_ni_info_legacy(ni, config);
3456 lnet_net_unlock(cpt);
3461 lnet_get_ni_config(struct lnet_ioctl_config_ni *cfg_ni,
3462 struct lnet_ioctl_config_lnd_tunables *tun,
3463 struct lnet_ioctl_element_stats *stats,
3470 if (!cfg_ni || !tun || !stats)
3473 cpt = lnet_net_lock_current();
3475 ni = lnet_get_ni_idx_locked(cfg_ni->lic_idx);
3480 lnet_fill_ni_info(ni, cfg_ni, tun, stats, tun_size);
3484 lnet_net_unlock(cpt);
3488 static int lnet_get_ni_stats(struct lnet_ioctl_element_msg_stats *msg_stats)
3496 ni = lnet_get_ni_idx_locked(msg_stats->im_idx);
3499 lnet_usr_translate_stats(msg_stats, &ni->ni_stats);
3506 static int lnet_add_net_common(struct lnet_net *net,
3507 struct lnet_ioctl_config_lnd_tunables *tun)
3509 struct lnet_handle_md ping_mdh;
3510 struct lnet_ping_buffer *pbuf;
3511 struct lnet_remotenet *rnet;
3516 lnet_net_lock(LNET_LOCK_EX);
3517 rnet = lnet_find_rnet_locked(net->net_id);
3518 lnet_net_unlock(LNET_LOCK_EX);
3520 * make sure that the net added doesn't invalidate the current
3521 * configuration LNet is keeping
3524 CERROR("Adding net %s will invalidate routing configuration\n",
3525 libcfs_net2str(net->net_id));
3531 memcpy(&net->net_tunables,
3532 &tun->lt_cmn, sizeof(net->net_tunables));
3534 memset(&net->net_tunables, -1, sizeof(net->net_tunables));
3536 net_id = net->net_id;
3538 rc = lnet_startup_lndnet(net,
3539 (tun) ? &tun->lt_tun : NULL);
3543 /* make sure you calculate the correct number of slots in the ping
3544 * buffer. Since the ping info is a flattened list of all the NIs,
3545 * we should allocate enough slots to accomodate the number of NIs
3546 * which will be added.
3548 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3549 LNET_PING_INFO_HDR_SIZE +
3550 lnet_get_ni_bytes(),
3553 lnet_shutdown_lndnet(net);
3557 lnet_net_lock(LNET_LOCK_EX);
3558 net = lnet_get_net_locked(net_id);
3561 /* apply the UDSPs */
3562 rc = lnet_udsp_apply_policies_on_net(net);
3564 CERROR("Failed to apply UDSPs on local net %s\n",
3565 libcfs_net2str(net->net_id));
3567 /* At this point we lost track of which NI was just added, so we
3568 * just re-apply the policies on all of the NIs on this net
3570 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3571 rc = lnet_udsp_apply_policies_on_ni(ni);
3573 CERROR("Failed to apply UDSPs on ni %s\n",
3574 libcfs_nidstr(&ni->ni_nid));
3576 lnet_net_unlock(LNET_LOCK_EX);
3579 * Start the acceptor thread if this is the first network
3580 * being added that requires the thread.
3582 if (net->net_lnd->lnd_accept) {
3583 rc = lnet_acceptor_start();
3585 /* shutdown the net that we just started */
3586 CERROR("Failed to start up acceptor thread\n");
3587 lnet_shutdown_lndnet(net);
3592 lnet_net_lock(LNET_LOCK_EX);
3593 lnet_peer_net_added(net);
3594 lnet_net_unlock(LNET_LOCK_EX);
3596 lnet_ping_target_update(pbuf, ping_mdh);
3601 lnet_ping_md_unlink(pbuf, &ping_mdh);
3602 lnet_ping_buffer_decref(pbuf);
3607 lnet_set_tune_defaults(struct lnet_ioctl_config_lnd_tunables *tun)
3610 if (tun->lt_cmn.lct_peer_timeout < 0)
3611 tun->lt_cmn.lct_peer_timeout = DEFAULT_PEER_TIMEOUT;
3612 if (!tun->lt_cmn.lct_peer_tx_credits)
3613 tun->lt_cmn.lct_peer_tx_credits = DEFAULT_PEER_CREDITS;
3614 if (!tun->lt_cmn.lct_max_tx_credits)
3615 tun->lt_cmn.lct_max_tx_credits = DEFAULT_CREDITS;
3619 static int lnet_handle_legacy_ip2nets(char *ip2nets,
3620 struct lnet_ioctl_config_lnd_tunables *tun)
3622 struct lnet_net *net;
3625 LIST_HEAD(net_head);
3627 rc = lnet_parse_ip2nets(&nets, ip2nets);
3631 rc = lnet_parse_networks(&net_head, nets);
3635 lnet_set_tune_defaults(tun);
3637 mutex_lock(&the_lnet.ln_api_mutex);
3638 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3643 while ((net = list_first_entry_or_null(&net_head,
3645 net_list)) != NULL) {
3646 list_del_init(&net->net_list);
3647 rc = lnet_add_net_common(net, tun);
3653 mutex_unlock(&the_lnet.ln_api_mutex);
3655 while ((net = list_first_entry_or_null(&net_head,
3657 net_list)) != NULL) {
3658 list_del_init(&net->net_list);
3664 int lnet_dyn_add_ni(struct lnet_ioctl_config_ni *conf, u32 net_id,
3665 struct lnet_ioctl_config_lnd_tunables *tun)
3667 struct lnet_net *net;
3672 /* handle legacy ip2nets from DLC */
3673 if (conf->lic_legacy_ip2nets[0] != '\0')
3674 return lnet_handle_legacy_ip2nets(conf->lic_legacy_ip2nets,
3677 lnd_type = LNET_NETTYP(net_id);
3679 if (!libcfs_isknown_lnd(lnd_type)) {
3680 CERROR("No valid net and lnd information provided\n");
3684 net = lnet_net_alloc(net_id, NULL);
3688 for (i = 0; i < conf->lic_ncpts; i++) {
3689 if (conf->lic_cpts[i] >= LNET_CPT_NUMBER) {
3695 ni = lnet_ni_alloc_w_cpt_array(net, conf->lic_cpts, conf->lic_ncpts,
3702 lnet_set_tune_defaults(tun);
3704 mutex_lock(&the_lnet.ln_api_mutex);
3705 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3709 rc = lnet_add_net_common(net, tun);
3712 mutex_unlock(&the_lnet.ln_api_mutex);
3714 /* If NI already exist delete this new unused copy */
3721 int lnet_dyn_del_ni(struct lnet_nid *nid)
3723 struct lnet_net *net;
3725 u32 net_id = LNET_NID_NET(nid);
3726 struct lnet_ping_buffer *pbuf;
3727 struct lnet_handle_md ping_mdh;
3731 /* don't allow userspace to shutdown the LOLND */
3732 if (LNET_NETTYP(net_id) == LOLND)
3735 mutex_lock(&the_lnet.ln_api_mutex);
3736 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3738 goto unlock_api_mutex;
3743 net = lnet_get_net_locked(net_id);
3745 CERROR("net %s not found\n",
3746 libcfs_net2str(net_id));
3751 if (!nid_addr_is_set(nid)) {
3752 /* remove the entire net */
3753 net_bytes = lnet_get_net_ni_bytes_locked(net);
3757 /* create and link a new ping info, before removing the old one */
3758 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3759 LNET_PING_INFO_HDR_SIZE +
3760 lnet_get_ni_bytes() - net_bytes,
3763 goto unlock_api_mutex;
3765 lnet_shutdown_lndnet(net);
3767 lnet_acceptor_stop();
3769 lnet_ping_target_update(pbuf, ping_mdh);
3771 goto unlock_api_mutex;
3774 ni = lnet_nid_to_ni_locked(nid, 0);
3776 CERROR("nid %s not found\n", libcfs_nidstr(nid));
3781 net_bytes = lnet_get_net_ni_bytes_locked(net);
3782 net_empty = list_is_singular(&net->net_ni_list);
3786 /* create and link a new ping info, before removing the old one */
3787 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3788 (LNET_PING_INFO_HDR_SIZE +
3789 lnet_get_ni_bytes() -
3790 lnet_ping_sts_size(&ni->ni_nid)),
3793 goto unlock_api_mutex;
3795 lnet_shutdown_lndni(ni);
3797 lnet_acceptor_stop();
3799 lnet_ping_target_update(pbuf, ping_mdh);
3801 /* check if the net is empty and remove it if it is */
3803 lnet_shutdown_lndnet(net);
3805 goto unlock_api_mutex;
3810 mutex_unlock(&the_lnet.ln_api_mutex);
3816 * lnet_dyn_add_net and lnet_dyn_del_net are now deprecated.
3817 * They are only expected to be called for unique networks.
3818 * That can be as a result of older DLC library
3819 * calls. Multi-Rail DLC and beyond no longer uses these APIs.
3822 lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
3824 struct lnet_net *net;
3825 LIST_HEAD(net_head);
3827 struct lnet_ioctl_config_lnd_tunables tun;
3828 const char *nets = conf->cfg_config_u.cfg_net.net_intf;
3830 /* Create a net/ni structures for the network string */
3831 rc = lnet_parse_networks(&net_head, nets);
3833 return rc == 0 ? -EINVAL : rc;
3835 mutex_lock(&the_lnet.ln_api_mutex);
3836 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3838 goto out_unlock_clean;
3842 rc = -EINVAL; /* only add one network per call */
3843 goto out_unlock_clean;
3846 net = list_first_entry(&net_head, struct lnet_net, net_list);
3847 list_del_init(&net->net_list);
3849 LASSERT(lnet_net_unique(net->net_id, &the_lnet.ln_nets, NULL));
3851 memset(&tun, 0, sizeof(tun));
3853 tun.lt_cmn.lct_peer_timeout =
3854 (!conf->cfg_config_u.cfg_net.net_peer_timeout) ? DEFAULT_PEER_TIMEOUT :
3855 conf->cfg_config_u.cfg_net.net_peer_timeout;
3856 tun.lt_cmn.lct_peer_tx_credits =
3857 (!conf->cfg_config_u.cfg_net.net_peer_tx_credits) ? DEFAULT_PEER_CREDITS :
3858 conf->cfg_config_u.cfg_net.net_peer_tx_credits;
3859 tun.lt_cmn.lct_peer_rtr_credits =
3860 conf->cfg_config_u.cfg_net.net_peer_rtr_credits;
3861 tun.lt_cmn.lct_max_tx_credits =
3862 (!conf->cfg_config_u.cfg_net.net_max_tx_credits) ? DEFAULT_CREDITS :
3863 conf->cfg_config_u.cfg_net.net_max_tx_credits;
3865 rc = lnet_add_net_common(net, &tun);
3868 mutex_unlock(&the_lnet.ln_api_mutex);
3869 /* net_head list is empty in success case */
3870 while ((net = list_first_entry_or_null(&net_head,
3872 net_list)) != NULL) {
3873 list_del_init(&net->net_list);
3880 lnet_dyn_del_net(u32 net_id)
3882 struct lnet_net *net;
3883 struct lnet_ping_buffer *pbuf;
3884 struct lnet_handle_md ping_mdh;
3885 int net_ni_bytes, rc;
3887 /* don't allow userspace to shutdown the LOLND */
3888 if (LNET_NETTYP(net_id) == LOLND)
3891 mutex_lock(&the_lnet.ln_api_mutex);
3892 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3899 net = lnet_get_net_locked(net_id);
3906 net_ni_bytes = lnet_get_net_ni_bytes_locked(net);
3910 /* create and link a new ping info, before removing the old one */
3911 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3912 LNET_PING_INFO_HDR_SIZE +
3913 lnet_get_ni_bytes() - net_ni_bytes,
3918 lnet_shutdown_lndnet(net);
3920 lnet_acceptor_stop();
3922 lnet_ping_target_update(pbuf, ping_mdh);
3925 mutex_unlock(&the_lnet.ln_api_mutex);
3930 void lnet_mark_ping_buffer_for_update(void)
3932 if (the_lnet.ln_routing)
3935 atomic_set(&the_lnet.ln_update_ping_buf, 1);
3936 complete(&the_lnet.ln_mt_wait_complete);
3938 EXPORT_SYMBOL(lnet_mark_ping_buffer_for_update);
3940 void lnet_update_ping_buffer(struct work_struct *work)
3942 struct lnet_ping_buffer *pbuf;
3943 struct lnet_handle_md ping_mdh;
3945 mutex_lock(&the_lnet.ln_api_mutex);
3947 atomic_set(&the_lnet.ln_pb_update_ready, 1);
3949 if ((the_lnet.ln_state == LNET_STATE_RUNNING) &&
3950 !lnet_ping_target_setup(&pbuf, &ping_mdh,
3951 LNET_PING_INFO_HDR_SIZE +
3952 lnet_get_ni_bytes(),
3954 lnet_ping_target_update(pbuf, ping_mdh);
3957 mutex_unlock(&the_lnet.ln_api_mutex);
3961 void lnet_queue_ping_buffer_update(void)
3963 /* don't queue pb update if it is not needed */
3964 if (atomic_dec_if_positive(&the_lnet.ln_update_ping_buf) < 0)
3967 /* don't queue pb update if already queued and not processed */
3968 if (atomic_dec_if_positive(&the_lnet.ln_pb_update_ready) < 0)
3971 INIT_WORK(&the_lnet.ln_pb_update_work, lnet_update_ping_buffer);
3972 queue_work(the_lnet.ln_pb_update_wq, &the_lnet.ln_pb_update_work);
3975 void lnet_incr_dlc_seq(void)
3977 atomic_inc(&lnet_dlc_seq_no);
3980 __u32 lnet_get_dlc_seq_locked(void)
3982 return atomic_read(&lnet_dlc_seq_no);
3986 lnet_ni_set_healthv(lnet_nid_t nid, int value, bool all)
3988 struct lnet_net *net;
3991 lnet_net_lock(LNET_LOCK_EX);
3992 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3993 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3994 if (all || (nid_is_nid4(&ni->ni_nid) &&
3995 lnet_nid_to_nid4(&ni->ni_nid) == nid)) {
3996 atomic_set(&ni->ni_healthv, value);
3997 if (list_empty(&ni->ni_recovery) &&
3998 value < LNET_MAX_HEALTH_VALUE) {
3999 CERROR("manually adding local NI %s to recovery\n",
4000 libcfs_nidstr(&ni->ni_nid));
4001 list_add_tail(&ni->ni_recovery,
4002 &the_lnet.ln_mt_localNIRecovq);
4003 lnet_ni_addref_locked(ni, 0);
4006 lnet_net_unlock(LNET_LOCK_EX);
4012 lnet_net_unlock(LNET_LOCK_EX);
4016 lnet_ni_set_conns_per_peer(lnet_nid_t nid, int value, bool all)
4018 struct lnet_net *net;
4021 lnet_net_lock(LNET_LOCK_EX);
4022 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
4023 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
4024 if (lnet_nid_to_nid4(&ni->ni_nid) != nid && !all)
4026 if (LNET_NETTYP(net->net_id) == SOCKLND)
4027 ni->ni_lnd_tunables.lnd_tun_u.lnd_sock.lnd_conns_per_peer = value;
4028 else if (LNET_NETTYP(net->net_id) == O2IBLND)
4029 ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = value;
4031 lnet_net_unlock(LNET_LOCK_EX);
4036 lnet_net_unlock(LNET_LOCK_EX);
4040 lnet_get_local_ni_hstats(struct lnet_ioctl_local_ni_hstats *stats)
4044 struct lnet_nid nid;
4046 lnet_nid4_to_nid(stats->hlni_nid, &nid);
4047 cpt = lnet_net_lock_current();
4048 ni = lnet_nid_to_ni_locked(&nid, cpt);
4054 stats->hlni_local_interrupt = atomic_read(&ni->ni_hstats.hlt_local_interrupt);
4055 stats->hlni_local_dropped = atomic_read(&ni->ni_hstats.hlt_local_dropped);
4056 stats->hlni_local_aborted = atomic_read(&ni->ni_hstats.hlt_local_aborted);
4057 stats->hlni_local_no_route = atomic_read(&ni->ni_hstats.hlt_local_no_route);
4058 stats->hlni_local_timeout = atomic_read(&ni->ni_hstats.hlt_local_timeout);
4059 stats->hlni_local_error = atomic_read(&ni->ni_hstats.hlt_local_error);
4060 stats->hlni_fatal_error = atomic_read(&ni->ni_fatal_error_on);
4061 stats->hlni_health_value = atomic_read(&ni->ni_healthv);
4062 stats->hlni_ping_count = ni->ni_ping_count;
4063 stats->hlni_next_ping = ni->ni_next_ping;
4066 lnet_net_unlock(cpt);
4072 lnet_get_local_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
4077 lnet_net_lock(LNET_LOCK_EX);
4078 list_for_each_entry(ni, &the_lnet.ln_mt_localNIRecovq, ni_recovery) {
4079 if (!nid_is_nid4(&ni->ni_nid))
4081 list->rlst_nid_array[i] = lnet_nid_to_nid4(&ni->ni_nid);
4083 if (i >= LNET_MAX_SHOW_NUM_NID)
4086 lnet_net_unlock(LNET_LOCK_EX);
4087 list->rlst_num_nids = i;
4093 lnet_get_peer_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
4095 struct lnet_peer_ni *lpni;
4098 lnet_net_lock(LNET_LOCK_EX);
4099 list_for_each_entry(lpni, &the_lnet.ln_mt_peerNIRecovq, lpni_recovery) {
4100 list->rlst_nid_array[i] = lnet_nid_to_nid4(&lpni->lpni_nid);
4102 if (i >= LNET_MAX_SHOW_NUM_NID)
4105 lnet_net_unlock(LNET_LOCK_EX);
4106 list->rlst_num_nids = i;
4112 * LNet ioctl handler.
4116 LNetCtl(unsigned int cmd, void *arg)
4118 struct libcfs_ioctl_data *data = arg;
4119 struct lnet_ioctl_config_data *config;
4121 struct lnet_nid nid;
4124 BUILD_BUG_ON(sizeof(struct lnet_ioctl_net_config) +
4125 sizeof(struct lnet_ioctl_config_data) > LIBCFS_IOC_DATA_MAX);
4128 case IOC_LIBCFS_GET_NI: {
4129 struct lnet_processid id = {};
4131 rc = LNetGetId(data->ioc_count, &id, false);
4132 data->ioc_nid = lnet_nid_to_nid4(&id.nid);
4135 case IOC_LIBCFS_FAIL_NID:
4136 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
4138 case IOC_LIBCFS_ADD_ROUTE: {
4139 /* default router sensitivity to 1 */
4140 unsigned int sensitivity = 1;
4143 if (config->cfg_hdr.ioc_len < sizeof(*config))
4146 if (config->cfg_config_u.cfg_route.rtr_sensitivity) {
4148 config->cfg_config_u.cfg_route.rtr_sensitivity;
4151 lnet_nid4_to_nid(config->cfg_nid, &nid);
4152 mutex_lock(&the_lnet.ln_api_mutex);
4153 rc = lnet_add_route(config->cfg_net,
4154 config->cfg_config_u.cfg_route.rtr_hop,
4156 config->cfg_config_u.cfg_route.
4157 rtr_priority, sensitivity);
4158 mutex_unlock(&the_lnet.ln_api_mutex);
4162 case IOC_LIBCFS_DEL_ROUTE:
4165 if (config->cfg_hdr.ioc_len < sizeof(*config))
4168 lnet_nid4_to_nid(config->cfg_nid, &nid);
4169 mutex_lock(&the_lnet.ln_api_mutex);
4170 rc = lnet_del_route(config->cfg_net, &nid);
4171 mutex_unlock(&the_lnet.ln_api_mutex);
4174 case IOC_LIBCFS_GET_ROUTE:
4177 if (config->cfg_hdr.ioc_len < sizeof(*config))
4180 mutex_lock(&the_lnet.ln_api_mutex);
4181 rc = lnet_get_route(config->cfg_count,
4183 &config->cfg_config_u.cfg_route.rtr_hop,
4185 &config->cfg_config_u.cfg_route.rtr_flags,
4186 &config->cfg_config_u.cfg_route.
4188 &config->cfg_config_u.cfg_route.
4190 mutex_unlock(&the_lnet.ln_api_mutex);
4193 case IOC_LIBCFS_GET_LOCAL_NI: {
4194 struct lnet_ioctl_config_ni *cfg_ni;
4195 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
4196 struct lnet_ioctl_element_stats *stats;
4201 /* get the tunables if they are available */
4202 if (cfg_ni->lic_cfg_hdr.ioc_len <
4203 sizeof(*cfg_ni) + sizeof(*stats) + sizeof(*tun))
4206 stats = (struct lnet_ioctl_element_stats *)
4208 tun = (struct lnet_ioctl_config_lnd_tunables *)
4209 (cfg_ni->lic_bulk + sizeof(*stats));
4211 tun_size = cfg_ni->lic_cfg_hdr.ioc_len - sizeof(*cfg_ni) -
4214 mutex_lock(&the_lnet.ln_api_mutex);
4215 rc = lnet_get_ni_config(cfg_ni, tun, stats, tun_size);
4216 mutex_unlock(&the_lnet.ln_api_mutex);
4220 case IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS: {
4221 struct lnet_ioctl_element_msg_stats *msg_stats = arg;
4224 if (msg_stats->im_hdr.ioc_len != sizeof(*msg_stats))
4227 mutex_lock(&the_lnet.ln_api_mutex);
4229 cpt = lnet_net_lock_current();
4230 rc = lnet_get_ni_stats(msg_stats);
4231 lnet_net_unlock(cpt);
4233 mutex_unlock(&the_lnet.ln_api_mutex);
4238 case IOC_LIBCFS_GET_NET: {
4239 size_t total = sizeof(*config) +
4240 sizeof(struct lnet_ioctl_net_config);
4243 if (config->cfg_hdr.ioc_len < total)
4246 mutex_lock(&the_lnet.ln_api_mutex);
4247 rc = lnet_get_net_config(config);
4248 mutex_unlock(&the_lnet.ln_api_mutex);
4252 case IOC_LIBCFS_GET_LNET_STATS:
4254 struct lnet_ioctl_lnet_stats *lnet_stats = arg;
4256 if (lnet_stats->st_hdr.ioc_len < sizeof(*lnet_stats))
4259 mutex_lock(&the_lnet.ln_api_mutex);
4260 rc = lnet_counters_get(&lnet_stats->st_cntrs);
4261 mutex_unlock(&the_lnet.ln_api_mutex);
4265 case IOC_LIBCFS_RESET_LNET_STATS:
4267 mutex_lock(&the_lnet.ln_api_mutex);
4268 lnet_counters_reset();
4269 mutex_unlock(&the_lnet.ln_api_mutex);
4273 case IOC_LIBCFS_CONFIG_RTR:
4276 if (config->cfg_hdr.ioc_len < sizeof(*config))
4279 mutex_lock(&the_lnet.ln_api_mutex);
4280 if (config->cfg_config_u.cfg_buffers.buf_enable) {
4281 rc = lnet_rtrpools_enable();
4282 mutex_unlock(&the_lnet.ln_api_mutex);
4285 lnet_rtrpools_disable();
4286 mutex_unlock(&the_lnet.ln_api_mutex);
4289 case IOC_LIBCFS_ADD_BUF:
4292 if (config->cfg_hdr.ioc_len < sizeof(*config))
4295 mutex_lock(&the_lnet.ln_api_mutex);
4296 rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
4298 config->cfg_config_u.cfg_buffers.
4300 config->cfg_config_u.cfg_buffers.
4302 mutex_unlock(&the_lnet.ln_api_mutex);
4305 case IOC_LIBCFS_SET_NUMA_RANGE: {
4306 struct lnet_ioctl_set_value *numa;
4308 if (numa->sv_hdr.ioc_len != sizeof(*numa))
4310 lnet_net_lock(LNET_LOCK_EX);
4311 lnet_numa_range = numa->sv_value;
4312 lnet_net_unlock(LNET_LOCK_EX);
4316 case IOC_LIBCFS_GET_NUMA_RANGE: {
4317 struct lnet_ioctl_set_value *numa;
4319 if (numa->sv_hdr.ioc_len != sizeof(*numa))
4321 numa->sv_value = lnet_numa_range;
4325 case IOC_LIBCFS_GET_BUF: {
4326 struct lnet_ioctl_pool_cfg *pool_cfg;
4327 size_t total = sizeof(*config) + sizeof(*pool_cfg);
4331 if (config->cfg_hdr.ioc_len < total)
4334 pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
4336 mutex_lock(&the_lnet.ln_api_mutex);
4337 rc = lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
4338 mutex_unlock(&the_lnet.ln_api_mutex);
4342 case IOC_LIBCFS_GET_LOCAL_HSTATS: {
4343 struct lnet_ioctl_local_ni_hstats *stats = arg;
4345 if (stats->hlni_hdr.ioc_len < sizeof(*stats))
4348 mutex_lock(&the_lnet.ln_api_mutex);
4349 rc = lnet_get_local_ni_hstats(stats);
4350 mutex_unlock(&the_lnet.ln_api_mutex);
4355 case IOC_LIBCFS_GET_RECOVERY_QUEUE: {
4356 struct lnet_ioctl_recovery_list *list = arg;
4357 if (list->rlst_hdr.ioc_len < sizeof(*list))
4360 mutex_lock(&the_lnet.ln_api_mutex);
4361 if (list->rlst_type == LNET_HEALTH_TYPE_LOCAL_NI)
4362 rc = lnet_get_local_ni_recovery_list(list);
4364 rc = lnet_get_peer_ni_recovery_list(list);
4365 mutex_unlock(&the_lnet.ln_api_mutex);
4369 case IOC_LIBCFS_ADD_PEER_NI: {
4370 struct lnet_ioctl_peer_cfg *cfg = arg;
4371 struct lnet_nid prim_nid;
4373 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4376 mutex_lock(&the_lnet.ln_api_mutex);
4377 lnet_nid4_to_nid(cfg->prcfg_prim_nid, &prim_nid);
4378 lnet_nid4_to_nid(cfg->prcfg_cfg_nid, &nid);
4379 rc = lnet_user_add_peer_ni(&prim_nid, &nid, cfg->prcfg_mr,
4380 cfg->prcfg_count == 1);
4381 mutex_unlock(&the_lnet.ln_api_mutex);
4385 case IOC_LIBCFS_DEL_PEER_NI: {
4386 struct lnet_ioctl_peer_cfg *cfg = arg;
4387 struct lnet_nid prim_nid;
4389 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4392 mutex_lock(&the_lnet.ln_api_mutex);
4393 lnet_nid4_to_nid(cfg->prcfg_prim_nid, &prim_nid);
4394 lnet_nid4_to_nid(cfg->prcfg_cfg_nid, &nid);
4395 rc = lnet_del_peer_ni(&prim_nid,
4398 mutex_unlock(&the_lnet.ln_api_mutex);
4402 case IOC_LIBCFS_GET_PEER_INFO: {
4403 struct lnet_ioctl_peer *peer_info = arg;
4405 if (peer_info->pr_hdr.ioc_len < sizeof(*peer_info))
4408 mutex_lock(&the_lnet.ln_api_mutex);
4409 rc = lnet_get_peer_ni_info(
4410 peer_info->pr_count,
4412 peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
4413 &peer_info->pr_lnd_u.pr_peer_credits.cr_ncpt,
4414 &peer_info->pr_lnd_u.pr_peer_credits.cr_refcount,
4415 &peer_info->pr_lnd_u.pr_peer_credits.cr_ni_peer_tx_credits,
4416 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_credits,
4417 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_rtr_credits,
4418 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_min_tx_credits,
4419 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_qnob);
4420 mutex_unlock(&the_lnet.ln_api_mutex);
4424 case IOC_LIBCFS_GET_PEER_NI: {
4425 struct lnet_ioctl_peer_cfg *cfg = arg;
4427 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4430 mutex_lock(&the_lnet.ln_api_mutex);
4431 rc = lnet_get_peer_info(cfg,
4432 (void __user *)cfg->prcfg_bulk);
4433 mutex_unlock(&the_lnet.ln_api_mutex);
4437 case IOC_LIBCFS_GET_PEER_LIST: {
4438 struct lnet_ioctl_peer_cfg *cfg = arg;
4440 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4443 mutex_lock(&the_lnet.ln_api_mutex);
4444 rc = lnet_get_peer_list(&cfg->prcfg_count, &cfg->prcfg_size,
4445 (struct lnet_process_id __user *)cfg->prcfg_bulk);
4446 mutex_unlock(&the_lnet.ln_api_mutex);
4450 case IOC_LIBCFS_SET_HEALHV: {
4451 struct lnet_ioctl_reset_health_cfg *cfg = arg;
4454 if (cfg->rh_hdr.ioc_len < sizeof(*cfg))
4456 if (cfg->rh_value < 0 ||
4457 cfg->rh_value > LNET_MAX_HEALTH_VALUE)
4458 value = LNET_MAX_HEALTH_VALUE;
4460 value = cfg->rh_value;
4461 CDEBUG(D_NET, "Manually setting healthv to %d for %s:%s. all = %d\n",
4462 value, (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI) ?
4463 "local" : "peer", libcfs_nid2str(cfg->rh_nid), cfg->rh_all);
4464 lnet_nid4_to_nid(cfg->rh_nid, &nid);
4465 mutex_lock(&the_lnet.ln_api_mutex);
4466 if (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI)
4467 lnet_ni_set_healthv(cfg->rh_nid, value,
4470 lnet_peer_ni_set_healthv(&nid, value, cfg->rh_all);
4471 mutex_unlock(&the_lnet.ln_api_mutex);
4475 case IOC_LIBCFS_SET_PEER: {
4476 struct lnet_ioctl_peer_cfg *cfg = arg;
4477 struct lnet_peer *lp;
4479 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4482 mutex_lock(&the_lnet.ln_api_mutex);
4483 lnet_nid4_to_nid(cfg->prcfg_prim_nid, &nid);
4484 lp = lnet_find_peer(&nid);
4486 mutex_unlock(&the_lnet.ln_api_mutex);
4489 spin_lock(&lp->lp_lock);
4490 lp->lp_state = cfg->prcfg_state;
4491 spin_unlock(&lp->lp_lock);
4492 lnet_peer_decref_locked(lp);
4493 mutex_unlock(&the_lnet.ln_api_mutex);
4494 CDEBUG(D_NET, "Set peer %s state to %u\n",
4495 libcfs_nid2str(cfg->prcfg_prim_nid), cfg->prcfg_state);
4499 case IOC_LIBCFS_SET_CONNS_PER_PEER: {
4500 struct lnet_ioctl_reset_conns_per_peer_cfg *cfg = arg;
4503 if (cfg->rcpp_hdr.ioc_len < sizeof(*cfg))
4505 if (cfg->rcpp_value < 0)
4508 value = cfg->rcpp_value;
4510 "Setting conns_per_peer to %d for %s. all = %d\n",
4511 value, libcfs_nid2str(cfg->rcpp_nid), cfg->rcpp_all);
4512 mutex_lock(&the_lnet.ln_api_mutex);
4513 lnet_ni_set_conns_per_peer(cfg->rcpp_nid, value, cfg->rcpp_all);
4514 mutex_unlock(&the_lnet.ln_api_mutex);
4518 case IOC_LIBCFS_NOTIFY_ROUTER: {
4519 /* Convert the user-supplied real time to monotonic.
4520 * NB: "when" is always in the past
4522 time64_t when = ktime_get_seconds() -
4523 (ktime_get_real_seconds() - data->ioc_u64[0]);
4525 lnet_nid4_to_nid(data->ioc_nid, &nid);
4526 return lnet_notify(NULL, &nid, data->ioc_flags, false, when);
4529 case IOC_LIBCFS_LNET_DIST:
4530 lnet_nid4_to_nid(data->ioc_nid, &nid);
4531 rc = LNetDist(&nid, &nid, &data->ioc_u32[1]);
4532 if (rc < 0 && rc != -EHOSTUNREACH)
4535 data->ioc_nid = lnet_nid_to_nid4(&nid);
4536 data->ioc_u32[0] = rc;
4539 case IOC_LIBCFS_TESTPROTOCOMPAT:
4540 the_lnet.ln_testprotocompat = data->ioc_flags;
4543 case IOC_LIBCFS_LNET_FAULT:
4544 return lnet_fault_ctl(data->ioc_flags, data);
4546 case IOC_LIBCFS_PING_PEER: {
4547 struct lnet_ioctl_ping_data *ping = arg;
4548 struct lnet_process_id __user *ids = ping->ping_buf;
4549 struct lnet_nid src_nid = LNET_ANY_NID;
4550 struct lnet_genl_ping_list plist;
4551 struct lnet_processid id;
4552 struct lnet_peer *lp;
4553 signed long timeout;
4556 /* Check if the supplied ping data supports source nid
4557 * NB: This check is sufficient if lnet_ioctl_ping_data has
4558 * additional fields added, but if they are re-ordered or
4559 * fields removed then this will break. It is expected that
4560 * these ioctls will be replaced with netlink implementation, so
4561 * it is probably not worth coming up with a more robust version
4562 * compatibility scheme.
4564 if (ping->ping_hdr.ioc_len >= sizeof(struct lnet_ioctl_ping_data))
4565 lnet_nid4_to_nid(ping->ping_src, &src_nid);
4567 /* If timeout is negative then set default of 3 minutes */
4568 if (((s32)ping->op_param) <= 0 ||
4569 ping->op_param > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
4570 timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
4572 timeout = nsecs_to_jiffies(ping->op_param * NSEC_PER_MSEC);
4574 id.pid = ping->ping_id.pid;
4575 lnet_nid4_to_nid(ping->ping_id.nid, &id.nid);
4576 rc = lnet_ping(&id, &src_nid, timeout, &plist,
4579 goto report_ping_err;
4583 for (i = 0; i < count; i++) {
4584 struct lnet_processid *result;
4585 struct lnet_process_id tmpid;
4587 result = genradix_ptr(&plist.lgpl_list, i);
4588 memset(&tmpid, 0, sizeof(tmpid));
4589 tmpid.pid = result->pid;
4590 tmpid.nid = lnet_nid_to_nid4(&result->nid);
4591 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid))) {
4593 goto report_ping_err;
4597 mutex_lock(&the_lnet.ln_api_mutex);
4598 lp = lnet_find_peer(&id.nid);
4601 lnet_nid_to_nid4(&lp->lp_primary_nid);
4602 ping->mr_info = lnet_peer_is_multi_rail(lp);
4603 lnet_peer_decref_locked(lp);
4605 mutex_unlock(&the_lnet.ln_api_mutex);
4607 ping->ping_count = count;
4609 genradix_free(&plist.lgpl_list);
4613 case IOC_LIBCFS_DISCOVER: {
4614 struct lnet_ioctl_ping_data *discover = arg;
4615 struct lnet_peer *lp;
4617 rc = lnet_discover(discover->ping_id, discover->op_param,
4619 discover->ping_count);
4623 mutex_lock(&the_lnet.ln_api_mutex);
4624 lnet_nid4_to_nid(discover->ping_id.nid, &nid);
4625 lp = lnet_find_peer(&nid);
4627 discover->ping_id.nid =
4628 lnet_nid_to_nid4(&lp->lp_primary_nid);
4629 discover->mr_info = lnet_peer_is_multi_rail(lp);
4630 lnet_peer_decref_locked(lp);
4632 mutex_unlock(&the_lnet.ln_api_mutex);
4634 discover->ping_count = rc;
4638 case IOC_LIBCFS_ADD_UDSP: {
4639 struct lnet_ioctl_udsp *ioc_udsp = arg;
4640 __u32 bulk_size = ioc_udsp->iou_hdr.ioc_len;
4642 mutex_lock(&the_lnet.ln_api_mutex);
4643 rc = lnet_udsp_demarshal_add(arg, bulk_size);
4645 rc = lnet_udsp_apply_policies(NULL, false);
4646 CDEBUG(D_NET, "policy application returned %d\n", rc);
4649 mutex_unlock(&the_lnet.ln_api_mutex);
4654 case IOC_LIBCFS_DEL_UDSP: {
4655 struct lnet_ioctl_udsp *ioc_udsp = arg;
4656 int idx = ioc_udsp->iou_idx;
4658 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4661 mutex_lock(&the_lnet.ln_api_mutex);
4662 rc = lnet_udsp_del_policy(idx);
4663 mutex_unlock(&the_lnet.ln_api_mutex);
4668 case IOC_LIBCFS_GET_UDSP_SIZE: {
4669 struct lnet_ioctl_udsp *ioc_udsp = arg;
4670 struct lnet_udsp *udsp;
4672 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4677 mutex_lock(&the_lnet.ln_api_mutex);
4678 udsp = lnet_udsp_get_policy(ioc_udsp->iou_idx);
4682 /* coming in iou_idx will hold the idx of the udsp
4683 * to get the size of. going out the iou_idx will
4684 * hold the size of the UDSP found at the passed
4687 ioc_udsp->iou_idx = lnet_get_udsp_size(udsp);
4688 if (ioc_udsp->iou_idx < 0)
4691 mutex_unlock(&the_lnet.ln_api_mutex);
4696 case IOC_LIBCFS_GET_UDSP: {
4697 struct lnet_ioctl_udsp *ioc_udsp = arg;
4698 struct lnet_udsp *udsp;
4700 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4705 mutex_lock(&the_lnet.ln_api_mutex);
4706 udsp = lnet_udsp_get_policy(ioc_udsp->iou_idx);
4710 rc = lnet_udsp_marshal(udsp, ioc_udsp);
4711 mutex_unlock(&the_lnet.ln_api_mutex);
4716 case IOC_LIBCFS_GET_CONST_UDSP_INFO: {
4717 struct lnet_ioctl_construct_udsp_info *info = arg;
4719 if (info->cud_hdr.ioc_len < sizeof(*info))
4722 CDEBUG(D_NET, "GET_UDSP_INFO for %s\n",
4723 libcfs_nid2str(info->cud_nid));
4725 lnet_nid4_to_nid(info->cud_nid, &nid);
4726 mutex_lock(&the_lnet.ln_api_mutex);
4728 lnet_udsp_get_construct_info(info, &nid);
4730 mutex_unlock(&the_lnet.ln_api_mutex);
4736 ni = lnet_net2ni_addref(data->ioc_net);
4740 if (ni->ni_net->net_lnd->lnd_ctl == NULL)
4743 rc = ni->ni_net->net_lnd->lnd_ctl(ni, cmd, arg);
4746 return rc <= 0 ? rc : 0;
4750 EXPORT_SYMBOL(LNetCtl);
4752 /* This is the keys for the UDSP info which is used by many
4755 static const struct ln_key_list udsp_info_list = {
4756 .lkl_maxattr = LNET_UDSP_INFO_ATTR_MAX,
4758 [LNET_UDSP_INFO_ATTR_NET_PRIORITY] = {
4759 .lkp_value = "net priority",
4760 .lkp_data_type = NLA_S32
4762 [LNET_UDSP_INFO_ATTR_NID_PRIORITY] = {
4763 .lkp_value = "nid priority",
4764 .lkp_data_type = NLA_S32
4766 [LNET_UDSP_INFO_ATTR_PREF_RTR_NIDS_LIST] = {
4767 .lkp_value = "Preferred gateway NIDs",
4768 .lkp_key_format = LNKF_MAPPING,
4769 .lkp_data_type = NLA_NESTED,
4771 [LNET_UDSP_INFO_ATTR_PREF_NIDS_LIST] = {
4772 .lkp_value = "Preferred source NIDs",
4773 .lkp_key_format = LNKF_MAPPING,
4774 .lkp_data_type = NLA_NESTED,
4779 static const struct ln_key_list udsp_info_pref_nids_list = {
4780 .lkl_maxattr = LNET_UDSP_INFO_PREF_NIDS_ATTR_MAX,
4782 [LNET_UDSP_INFO_PREF_NIDS_ATTR_INDEX] = {
4783 .lkp_value = "NID-0",
4784 .lkp_data_type = NLA_NUL_STRING,
4786 [LNET_UDSP_INFO_PREF_NIDS_ATTR_NID] = {
4787 .lkp_value = "0@lo",
4788 .lkp_data_type = NLA_STRING,
4793 static int lnet_udsp_info_send(struct sk_buff *msg, int attr,
4794 struct lnet_nid *nid, bool remote)
4796 struct lnet_ioctl_construct_udsp_info *udsp;
4797 struct nlattr *udsp_attr, *udsp_info;
4798 struct nlattr *udsp_list_attr;
4799 struct nlattr *udsp_list_info;
4802 CFS_ALLOC_PTR(udsp);
4806 udsp->cud_peer = remote;
4807 lnet_udsp_get_construct_info(udsp, nid);
4809 udsp_info = nla_nest_start(msg, attr);
4810 udsp_attr = nla_nest_start(msg, 0);
4811 nla_put_s32(msg, LNET_UDSP_INFO_ATTR_NET_PRIORITY,
4812 udsp->cud_net_priority);
4813 nla_put_s32(msg, LNET_UDSP_INFO_ATTR_NID_PRIORITY,
4814 udsp->cud_nid_priority);
4816 if (udsp->cud_pref_rtr_nid[0] == 0)
4819 udsp_list_info = nla_nest_start(msg,
4820 LNET_UDSP_INFO_ATTR_PREF_RTR_NIDS_LIST);
4821 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
4822 char tmp[8]; /* NID-"3 number"\0 */
4824 if (udsp->cud_pref_rtr_nid[i] == 0)
4827 udsp_list_attr = nla_nest_start(msg, i);
4828 snprintf(tmp, sizeof(tmp), "NID-%d", i);
4829 nla_put_string(msg, LNET_UDSP_INFO_PREF_NIDS_ATTR_INDEX,
4831 nla_put_string(msg, LNET_UDSP_INFO_PREF_NIDS_ATTR_NID,
4832 libcfs_nid2str(udsp->cud_pref_rtr_nid[i]));
4833 nla_nest_end(msg, udsp_list_attr);
4835 nla_nest_end(msg, udsp_list_info);
4837 nla_nest_end(msg, udsp_attr);
4838 nla_nest_end(msg, udsp_info);
4839 LIBCFS_FREE(udsp, sizeof(*udsp));
4844 /* LNet NI handling */
4845 static const struct ln_key_list net_props_list = {
4846 .lkl_maxattr = LNET_NET_ATTR_MAX,
4848 [LNET_NET_ATTR_HDR] = {
4850 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
4851 .lkp_data_type = NLA_NUL_STRING,
4853 [LNET_NET_ATTR_TYPE] = {
4854 .lkp_value = "net type",
4855 .lkp_data_type = NLA_STRING
4857 [LNET_NET_ATTR_LOCAL] = {
4858 .lkp_value = "local NI(s)",
4859 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
4860 .lkp_data_type = NLA_NESTED
4865 static struct ln_key_list local_ni_list = {
4866 .lkl_maxattr = LNET_NET_LOCAL_NI_ATTR_MAX,
4868 [LNET_NET_LOCAL_NI_ATTR_NID] = {
4870 .lkp_data_type = NLA_STRING
4872 [LNET_NET_LOCAL_NI_ATTR_STATUS] = {
4873 .lkp_value = "status",
4874 .lkp_data_type = NLA_STRING
4876 [LNET_NET_LOCAL_NI_ATTR_INTERFACE] = {
4877 .lkp_value = "interfaces",
4878 .lkp_key_format = LNKF_MAPPING,
4879 .lkp_data_type = NLA_NESTED
4881 [LNET_NET_LOCAL_NI_ATTR_STATS] = {
4882 .lkp_value = "statistics",
4883 .lkp_key_format = LNKF_MAPPING,
4884 .lkp_data_type = NLA_NESTED
4886 [LNET_NET_LOCAL_NI_ATTR_UDSP_INFO] = {
4887 .lkp_value = "udsp info",
4888 .lkp_key_format = LNKF_MAPPING,
4889 .lkp_data_type = NLA_NESTED
4891 [LNET_NET_LOCAL_NI_ATTR_SEND_STATS] = {
4892 .lkp_value = "sent_stats",
4893 .lkp_key_format = LNKF_MAPPING,
4894 .lkp_data_type = NLA_NESTED
4896 [LNET_NET_LOCAL_NI_ATTR_RECV_STATS] = {
4897 .lkp_value = "received_stats",
4898 .lkp_key_format = LNKF_MAPPING,
4899 .lkp_data_type = NLA_NESTED
4901 [LNET_NET_LOCAL_NI_ATTR_DROPPED_STATS] = {
4902 .lkp_value = "dropped_stats",
4903 .lkp_key_format = LNKF_MAPPING,
4904 .lkp_data_type = NLA_NESTED
4907 [LNET_NET_LOCAL_NI_ATTR_HEALTH_STATS] = {
4908 .lkp_value = "health stats",
4909 .lkp_key_format = LNKF_MAPPING,
4910 .lkp_data_type = NLA_NESTED
4912 [LNET_NET_LOCAL_NI_ATTR_TUNABLES] = {
4913 .lkp_value = "tunables",
4914 .lkp_key_format = LNKF_MAPPING,
4915 .lkp_data_type = NLA_NESTED
4917 [LNET_NET_LOCAL_NI_ATTR_LND_TUNABLES] = {
4918 .lkp_value = "lnd tunables",
4919 .lkp_key_format = LNKF_MAPPING,
4920 .lkp_data_type = NLA_NESTED
4922 [LNET_NET_LOCAL_NI_DEV_CPT] = {
4923 .lkp_value = "dev cpt",
4924 .lkp_data_type = NLA_S32,
4926 [LNET_NET_LOCAL_NI_CPTS] = {
4928 .lkp_data_type = NLA_STRING,
4933 static const struct ln_key_list local_ni_interfaces_list = {
4934 .lkl_maxattr = LNET_NET_LOCAL_NI_INTF_ATTR_MAX,
4936 [LNET_NET_LOCAL_NI_INTF_ATTR_TYPE] = {
4938 .lkp_data_type = NLA_STRING
4943 static const struct ln_key_list local_ni_stats_list = {
4944 .lkl_maxattr = LNET_NET_LOCAL_NI_STATS_ATTR_MAX,
4946 [LNET_NET_LOCAL_NI_STATS_ATTR_SEND_COUNT] = {
4947 .lkp_value = "send_count",
4948 .lkp_data_type = NLA_U32
4950 [LNET_NET_LOCAL_NI_STATS_ATTR_RECV_COUNT] = {
4951 .lkp_value = "recv_count",
4952 .lkp_data_type = NLA_U32
4954 [LNET_NET_LOCAL_NI_STATS_ATTR_DROP_COUNT] = {
4955 .lkp_value = "drop_count",
4956 .lkp_data_type = NLA_U32
4961 static const struct ln_key_list local_ni_msg_stats_list = {
4962 .lkl_maxattr = LNET_NET_LOCAL_NI_MSG_STATS_ATTR_MAX,
4964 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT] = {
4966 .lkp_data_type = NLA_U32
4968 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT] = {
4970 .lkp_data_type = NLA_U32
4972 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT] = {
4973 .lkp_value = "reply",
4974 .lkp_data_type = NLA_U32
4976 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT] = {
4978 .lkp_data_type = NLA_U32
4980 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT] = {
4981 .lkp_value = "hello",
4982 .lkp_data_type = NLA_U32
4987 static const struct ln_key_list local_ni_health_stats_list = {
4988 .lkl_maxattr = LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_MAX,
4990 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_FATAL_ERRORS] = {
4991 .lkp_value = "fatal_error",
4992 .lkp_data_type = NLA_S32
4994 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_LEVEL] = {
4995 .lkp_value = "health value",
4996 .lkp_data_type = NLA_S32
4998 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_INTERRUPTS] = {
4999 .lkp_value = "interrupts",
5000 .lkp_data_type = NLA_U32
5002 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_DROPPED] = {
5003 .lkp_value = "dropped",
5004 .lkp_data_type = NLA_U32
5006 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ABORTED] = {
5007 .lkp_value = "aborted",
5008 .lkp_data_type = NLA_U32
5010 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NO_ROUTE] = {
5011 .lkp_value = "no route",
5012 .lkp_data_type = NLA_U32
5014 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_TIMEOUTS] = {
5015 .lkp_value = "timeouts",
5016 .lkp_data_type = NLA_U32
5018 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ERROR] = {
5019 .lkp_value = "error",
5020 .lkp_data_type = NLA_U32
5022 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PING_COUNT] = {
5023 .lkp_value = "ping_count",
5024 .lkp_data_type = NLA_U32,
5026 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NEXT_PING] = {
5027 .lkp_value = "next_ping",
5028 .lkp_data_type = NLA_U64
5033 static const struct ln_key_list local_ni_tunables_list = {
5034 .lkl_maxattr = LNET_NET_LOCAL_NI_TUNABLES_ATTR_MAX,
5036 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT] = {
5037 .lkp_value = "peer_timeout",
5038 .lkp_data_type = NLA_S32
5040 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS] = {
5041 .lkp_value = "peer_credits",
5042 .lkp_data_type = NLA_S32
5044 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS] = {
5045 .lkp_value = "peer_buffer_credits",
5046 .lkp_data_type = NLA_S32
5048 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS] = {
5049 .lkp_value = "credits",
5050 .lkp_data_type = NLA_S32
5055 /* Use an index since the traversal is across LNet nets and ni collections */
5056 struct lnet_genl_net_list {
5057 unsigned int lngl_net_id;
5058 unsigned int lngl_idx;
5061 static inline struct lnet_genl_net_list *
5062 lnet_net_dump_ctx(struct netlink_callback *cb)
5064 return (struct lnet_genl_net_list *)cb->args[0];
5067 static int lnet_net_show_done(struct netlink_callback *cb)
5069 struct lnet_genl_net_list *nlist = lnet_net_dump_ctx(cb);
5072 LIBCFS_FREE(nlist, sizeof(*nlist));
5079 /* LNet net ->start() handler for GET requests */
5080 static int lnet_net_show_start(struct netlink_callback *cb)
5082 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
5083 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
5084 struct netlink_ext_ack *extack = NULL;
5086 struct lnet_genl_net_list *nlist;
5087 int msg_len = genlmsg_len(gnlh);
5088 struct nlattr *params, *top;
5091 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
5092 extack = cb->extack;
5094 if (the_lnet.ln_refcount == 0) {
5095 NL_SET_ERR_MSG(extack, "LNet stack down");
5099 LIBCFS_ALLOC(nlist, sizeof(*nlist));
5103 nlist->lngl_net_id = LNET_NET_ANY;
5104 nlist->lngl_idx = 0;
5105 cb->args[0] = (long)nlist;
5110 params = genlmsg_data(gnlh);
5111 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
5112 NL_SET_ERR_MSG(extack, "invalid configuration");
5116 nla_for_each_nested(top, params, rem) {
5120 nla_for_each_nested(net, top, rem2) {
5121 char filter[LNET_NIDSTR_SIZE];
5123 if (nla_type(net) != LN_SCALAR_ATTR_VALUE ||
5124 nla_strcmp(net, "net type") != 0)
5127 net = nla_next(net, &rem2);
5128 if (nla_type(net) != LN_SCALAR_ATTR_VALUE) {
5129 NL_SET_ERR_MSG(extack, "invalid config param");
5130 GOTO(report_err, rc = -EINVAL);
5133 rc = nla_strscpy(filter, net, sizeof(filter));
5135 NL_SET_ERR_MSG(extack, "failed to get param");
5136 GOTO(report_err, rc);
5140 nlist->lngl_net_id = libcfs_str2net(filter);
5141 if (nlist->lngl_net_id == LNET_NET_ANY) {
5142 NL_SET_ERR_MSG(extack, "cannot parse net");
5143 GOTO(report_err, rc = -ENOENT);
5149 lnet_net_show_done(cb);
5154 static int lnet_net_show_dump(struct sk_buff *msg,
5155 struct netlink_callback *cb)
5157 struct lnet_genl_net_list *nlist = lnet_net_dump_ctx(cb);
5158 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
5159 struct netlink_ext_ack *extack = NULL;
5161 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
5162 int portid = NETLINK_CB(cb->skb).portid;
5163 bool found = false, started = true;
5164 const struct lnet_lnd *lnd = NULL;
5165 int idx = nlist->lngl_idx, rc = 0;
5166 int seq = cb->nlh->nlmsg_seq;
5167 struct lnet_net *net;
5170 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
5171 extack = cb->extack;
5173 lnet_net_lock(LNET_LOCK_EX);
5175 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
5176 struct nlattr *local_ni, *ni_attr;
5180 if (nlist->lngl_net_id != LNET_NET_ANY &&
5181 nlist->lngl_net_id != net->net_id)
5184 if (gnlh->version && LNET_NETTYP(net->net_id) != LOLND) {
5185 if (!net->net_lnd) {
5186 NL_SET_ERR_MSG(extack,
5187 "LND not setup for NI");
5188 GOTO(net_unlock, rc = -ENODEV);
5190 if (net->net_lnd != lnd)
5196 /* We need to resend the key table every time the base LND
5200 const struct ln_key_list *all[] = {
5201 &net_props_list, &local_ni_list,
5202 &local_ni_interfaces_list,
5203 &local_ni_stats_list,
5205 &udsp_info_pref_nids_list,
5206 &udsp_info_pref_nids_list,
5207 &local_ni_msg_stats_list,
5208 &local_ni_msg_stats_list,
5209 &local_ni_msg_stats_list,
5210 &local_ni_health_stats_list,
5211 &local_ni_tunables_list,
5212 NULL, /* lnd tunables */
5215 int flags = NLM_F_CREATE | NLM_F_MULTI;
5218 all[ARRAY_SIZE(all) - 2] = lnd->lnd_keys;
5220 flags |= NLM_F_REPLACE;
5224 rc = lnet_genl_send_scalar_list(msg, portid, seq,
5225 &lnet_family, flags,
5226 LNET_CMD_NETS, all);
5228 NL_SET_ERR_MSG(extack, "failed to send key table");
5229 GOTO(net_unlock, rc);
5233 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
5234 NLM_F_MULTI, LNET_CMD_NETS);
5236 NL_SET_ERR_MSG(extack, "failed to send values");
5237 GOTO(net_unlock, rc = -EMSGSIZE);
5241 nla_put_string(msg, LNET_NET_ATTR_HDR, "");
5245 nla_put_string(msg, LNET_NET_ATTR_TYPE,
5246 libcfs_net2str(net->net_id));
5248 local_ni = nla_nest_start(msg, LNET_NET_ATTR_LOCAL);
5249 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
5250 char *status = "up";
5252 if (idx++ < nlist->lngl_idx)
5255 ni_attr = nla_nest_start(msg, dev++);
5258 nla_put_string(msg, LNET_NET_LOCAL_NI_ATTR_NID,
5259 libcfs_nidstr(&ni->ni_nid));
5260 if (!nid_is_lo0(&ni->ni_nid) &&
5261 *ni->ni_status != LNET_NI_STATUS_UP)
5263 nla_put_string(msg, LNET_NET_LOCAL_NI_ATTR_STATUS,
5266 if (!nid_is_lo0(&ni->ni_nid) && ni->ni_interface) {
5267 struct nlattr *intf_nest, *intf_attr;
5269 intf_nest = nla_nest_start(msg,
5270 LNET_NET_LOCAL_NI_ATTR_INTERFACE);
5271 intf_attr = nla_nest_start(msg, 0);
5273 LNET_NET_LOCAL_NI_INTF_ATTR_TYPE,
5275 nla_nest_end(msg, intf_attr);
5276 nla_nest_end(msg, intf_nest);
5279 if (gnlh->version) {
5280 char cpts[LNET_MAX_SHOW_NUM_CPT * 4 + 4], *cpt;
5281 struct lnet_ioctl_element_msg_stats msg_stats;
5282 struct lnet_ioctl_element_stats stats;
5283 size_t buf_len = sizeof(cpts), len;
5284 struct nlattr *health_attr, *health_stats;
5285 struct nlattr *send_attr, *send_stats;
5286 struct nlattr *recv_attr, *recv_stats;
5287 struct nlattr *drop_attr, *drop_stats;
5288 struct nlattr *stats_attr, *ni_stats;
5289 struct nlattr *tun_attr, *ni_tun;
5292 stats.iel_send_count = lnet_sum_stats(&ni->ni_stats,
5293 LNET_STATS_TYPE_SEND);
5294 stats.iel_recv_count = lnet_sum_stats(&ni->ni_stats,
5295 LNET_STATS_TYPE_RECV);
5296 stats.iel_drop_count = lnet_sum_stats(&ni->ni_stats,
5297 LNET_STATS_TYPE_DROP);
5300 stats_attr = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_STATS);
5301 ni_stats = nla_nest_start(msg, 0);
5302 nla_put_u32(msg, LNET_NET_LOCAL_NI_STATS_ATTR_SEND_COUNT,
5303 stats.iel_send_count);
5304 nla_put_u32(msg, LNET_NET_LOCAL_NI_STATS_ATTR_RECV_COUNT,
5305 stats.iel_recv_count);
5306 nla_put_u32(msg, LNET_NET_LOCAL_NI_STATS_ATTR_DROP_COUNT,
5307 stats.iel_drop_count);
5308 nla_nest_end(msg, ni_stats);
5309 nla_nest_end(msg, stats_attr);
5311 if (gnlh->version < 4)
5315 rc = lnet_udsp_info_send(msg, LNET_NET_LOCAL_NI_ATTR_UDSP_INFO,
5316 &ni->ni_nid, false);
5318 NL_SET_ERR_MSG(extack,
5319 "Failed to get udsp info");
5320 genlmsg_cancel(msg, hdr);
5321 GOTO(net_unlock, rc = -ENOMEM);
5324 if (gnlh->version < 2)
5325 goto skip_msg_stats;
5327 msg_stats.im_idx = idx - 1;
5328 rc = lnet_get_ni_stats(&msg_stats);
5330 NL_SET_ERR_MSG(extack,
5331 "failed to get msg stats");
5332 genlmsg_cancel(msg, hdr);
5333 GOTO(net_unlock, rc = -ENOMEM);
5336 send_stats = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_SEND_STATS);
5337 send_attr = nla_nest_start(msg, 0);
5338 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT,
5339 msg_stats.im_send_stats.ico_get_count);
5340 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT,
5341 msg_stats.im_send_stats.ico_put_count);
5342 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT,
5343 msg_stats.im_send_stats.ico_reply_count);
5344 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT,
5345 msg_stats.im_send_stats.ico_ack_count);
5346 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT,
5347 msg_stats.im_send_stats.ico_hello_count);
5348 nla_nest_end(msg, send_attr);
5349 nla_nest_end(msg, send_stats);
5351 recv_stats = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_RECV_STATS);
5352 recv_attr = nla_nest_start(msg, 0);
5353 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT,
5354 msg_stats.im_recv_stats.ico_get_count);
5355 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT,
5356 msg_stats.im_recv_stats.ico_put_count);
5357 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT,
5358 msg_stats.im_recv_stats.ico_reply_count);
5359 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT,
5360 msg_stats.im_recv_stats.ico_ack_count);
5361 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT,
5362 msg_stats.im_recv_stats.ico_hello_count);
5363 nla_nest_end(msg, recv_attr);
5364 nla_nest_end(msg, recv_stats);
5366 drop_stats = nla_nest_start(msg,
5367 LNET_NET_LOCAL_NI_ATTR_DROPPED_STATS);
5368 drop_attr = nla_nest_start(msg, 0);
5369 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT,
5370 msg_stats.im_drop_stats.ico_get_count);
5371 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT,
5372 msg_stats.im_drop_stats.ico_put_count);
5373 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT,
5374 msg_stats.im_drop_stats.ico_reply_count);
5375 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT,
5376 msg_stats.im_drop_stats.ico_ack_count);
5377 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT,
5378 msg_stats.im_drop_stats.ico_hello_count);
5379 nla_nest_end(msg, drop_attr);
5380 nla_nest_end(msg, drop_stats);
5383 health_stats = nla_nest_start(msg,
5384 LNET_NET_LOCAL_NI_ATTR_HEALTH_STATS);
5385 health_attr = nla_nest_start(msg, 0);
5386 nla_put_s32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_FATAL_ERRORS,
5387 atomic_read(&ni->ni_fatal_error_on));
5388 nla_put_s32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_LEVEL,
5389 atomic_read(&ni->ni_healthv));
5390 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_INTERRUPTS,
5391 atomic_read(&ni->ni_hstats.hlt_local_interrupt));
5392 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_DROPPED,
5393 atomic_read(&ni->ni_hstats.hlt_local_dropped));
5394 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ABORTED,
5395 atomic_read(&ni->ni_hstats.hlt_local_aborted));
5396 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NO_ROUTE,
5397 atomic_read(&ni->ni_hstats.hlt_local_no_route));
5398 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_TIMEOUTS,
5399 atomic_read(&ni->ni_hstats.hlt_local_timeout));
5400 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ERROR,
5401 atomic_read(&ni->ni_hstats.hlt_local_error));
5402 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PING_COUNT,
5404 nla_put_u64_64bit(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NEXT_PING,
5406 LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PAD);
5407 nla_nest_end(msg, health_attr);
5408 nla_nest_end(msg, health_stats);
5410 /* Report net tunables */
5411 tun_attr = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_TUNABLES);
5412 ni_tun = nla_nest_start(msg, 0);
5413 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT,
5414 ni->ni_net->net_tunables.lct_peer_timeout);
5415 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS,
5416 ni->ni_net->net_tunables.lct_peer_tx_credits);
5417 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS,
5418 ni->ni_net->net_tunables.lct_peer_rtr_credits);
5419 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS,
5420 ni->ni_net->net_tunables.lct_max_tx_credits);
5421 nla_nest_end(msg, ni_tun);
5423 nla_nest_end(msg, tun_attr);
5425 if (lnd && lnd->lnd_nl_get && lnd->lnd_keys) {
5426 struct nlattr *lnd_tun_attr, *lnd_ni_tun;
5428 lnd_tun_attr = nla_nest_start(msg,
5429 LNET_NET_LOCAL_NI_ATTR_LND_TUNABLES);
5430 lnd_ni_tun = nla_nest_start(msg, 0);
5431 rc = lnd->lnd_nl_get(LNET_CMD_NETS, msg,
5432 LNET_NET_LOCAL_NI_ATTR_LND_TUNABLES,
5435 NL_SET_ERR_MSG(extack,
5436 "failed to get lnd tunables");
5437 genlmsg_cancel(msg, hdr);
5438 GOTO(net_unlock, rc);
5440 nla_nest_end(msg, lnd_ni_tun);
5441 nla_nest_end(msg, lnd_tun_attr);
5444 nla_put_s32(msg, LNET_NET_LOCAL_NI_DEV_CPT, ni->ni_dev_cpt);
5446 /* Report cpts. We could send this as a nested list
5447 * of integers but older versions of the tools
5448 * except a string. The new versions can handle
5449 * both formats so in the future we can change
5450 * this to a nested list.
5452 len = snprintf(cpts, buf_len, "\"[");
5456 if (ni->ni_ncpts == LNET_CPT_NUMBER && !ni->ni_cpts) {
5457 for (j = 0; j < ni->ni_ncpts; j++) {
5458 len = snprintf(cpt, buf_len, "%d,", j);
5464 ni->ni_cpts && j < ni->ni_ncpts &&
5465 j < LNET_MAX_SHOW_NUM_CPT; j++) {
5466 len = snprintf(cpt, buf_len, "%d,",
5472 snprintf(cpt - 1, sizeof(cpts), "]\"");
5474 nla_put_string(msg, LNET_NET_LOCAL_NI_CPTS, cpts);
5478 nla_nest_end(msg, ni_attr);
5480 nla_nest_end(msg, local_ni);
5482 genlmsg_end(msg, hdr);
5486 struct nlmsghdr *nlh = nlmsg_hdr(msg);
5488 nlmsg_cancel(msg, nlh);
5489 NL_SET_ERR_MSG(extack, "Network is down");
5492 nlist->lngl_idx = idx;
5494 lnet_net_unlock(LNET_LOCK_EX);
5496 return lnet_nl_send_error(cb->skb, portid, seq, rc);
5499 #ifndef HAVE_NETLINK_CALLBACK_START
5500 static int lnet_old_net_show_dump(struct sk_buff *msg,
5501 struct netlink_callback *cb)
5504 int rc = lnet_net_show_start(cb);
5510 return lnet_net_show_dump(msg, cb);
5514 static int lnet_genl_parse_tunables(struct nlattr *settings,
5515 struct lnet_ioctl_config_lnd_tunables *tun)
5517 struct nlattr *param;
5520 nla_for_each_nested(param, settings, rem) {
5521 int type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_UNSPEC;
5524 if (nla_type(param) != LN_SCALAR_ATTR_VALUE)
5527 if (nla_strcmp(param, "peer_timeout") == 0)
5528 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT;
5529 else if (nla_strcmp(param, "peer_credits") == 0)
5530 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS;
5531 else if (nla_strcmp(param, "peer_buffer_credits") == 0)
5532 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS;
5533 else if (nla_strcmp(param, "credits") == 0)
5534 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS;
5536 param = nla_next(param, &rem);
5537 if (nla_type(param) != LN_SCALAR_ATTR_INT_VALUE)
5540 num = nla_get_s64(param);
5542 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT:
5544 tun->lt_cmn.lct_peer_timeout = num;
5546 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS:
5548 tun->lt_cmn.lct_peer_tx_credits = num;
5550 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS:
5552 tun->lt_cmn.lct_peer_rtr_credits = num;
5554 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS:
5556 tun->lt_cmn.lct_max_tx_credits = num;
5566 static int lnet_genl_parse_lnd_tunables(struct nlattr *settings,
5567 struct lnet_lnd_tunables *tun,
5568 const struct lnet_lnd *lnd)
5570 const struct ln_key_list *list = lnd->lnd_keys;
5571 struct nlattr *param;
5575 /* silently ignore these setting if the LND driver doesn't
5576 * support any LND tunables
5578 if (!list || !lnd->lnd_nl_set || !list->lkl_maxattr)
5581 nla_for_each_nested(param, settings, rem) {
5582 if (nla_type(param) != LN_SCALAR_ATTR_VALUE)
5585 for (i = 1; i <= list->lkl_maxattr; i++) {
5586 if (!list->lkl_list[i].lkp_value ||
5587 nla_strcmp(param, list->lkl_list[i].lkp_value) != 0)
5590 param = nla_next(param, &rem);
5591 rc = lnd->lnd_nl_set(LNET_CMD_NETS, param, i, tun);
5601 lnet_genl_parse_local_ni(struct nlattr *entry, struct genl_info *info,
5602 int net_id, struct lnet_ioctl_config_ni *conf,
5605 bool create = info->nlhdr->nlmsg_flags & NLM_F_CREATE;
5606 struct lnet_ioctl_config_lnd_tunables *tun;
5607 struct nlattr *settings;
5610 LIBCFS_ALLOC(tun, sizeof(struct lnet_ioctl_config_lnd_tunables));
5612 GENL_SET_ERR_MSG(info, "cannot allocate memory for tunables");
5613 GOTO(out, rc = -ENOMEM);
5616 /* Use LND defaults */
5617 tun->lt_cmn.lct_peer_timeout = -1;
5618 tun->lt_cmn.lct_peer_tx_credits = -1;
5619 tun->lt_cmn.lct_peer_rtr_credits = -1;
5620 tun->lt_cmn.lct_max_tx_credits = -1;
5621 conf->lic_ncpts = 0;
5623 nla_for_each_nested(settings, entry, rem3) {
5624 if (nla_type(settings) != LN_SCALAR_ATTR_VALUE)
5627 if (nla_strcmp(settings, "interfaces") == 0) {
5628 struct nlattr *intf;
5631 settings = nla_next(settings, &rem3);
5632 if (nla_type(settings) !=
5633 LN_SCALAR_ATTR_LIST) {
5634 GENL_SET_ERR_MSG(info,
5635 "invalid interfaces");
5636 GOTO(out, rc = -EINVAL);
5639 nla_for_each_nested(intf, settings, rem4) {
5640 intf = nla_next(intf, &rem4);
5641 if (nla_type(intf) !=
5642 LN_SCALAR_ATTR_VALUE) {
5643 GENL_SET_ERR_MSG(info,
5644 "cannot parse interface");
5645 GOTO(out, rc = -EINVAL);
5648 rc = nla_strscpy(conf->lic_ni_intf, intf,
5649 sizeof(conf->lic_ni_intf));
5651 GENL_SET_ERR_MSG(info,
5652 "failed to parse interfaces");
5657 } else if (nla_strcmp(settings, "tunables") == 0) {
5658 settings = nla_next(settings, &rem3);
5659 if (nla_type(settings) !=
5660 LN_SCALAR_ATTR_LIST) {
5661 GENL_SET_ERR_MSG(info,
5662 "invalid tunables");
5663 GOTO(out, rc = -EINVAL);
5666 rc = lnet_genl_parse_tunables(settings, tun);
5668 GENL_SET_ERR_MSG(info,
5669 "failed to parse tunables");
5672 } else if ((nla_strcmp(settings, "lnd tunables") == 0)) {
5673 const struct lnet_lnd *lnd;
5675 lnd = lnet_load_lnd(LNET_NETTYP(net_id));
5677 GENL_SET_ERR_MSG(info,
5678 "LND type not supported");
5679 GOTO(out, rc = PTR_ERR(lnd));
5682 settings = nla_next(settings, &rem3);
5683 if (nla_type(settings) !=
5684 LN_SCALAR_ATTR_LIST) {
5685 GENL_SET_ERR_MSG(info,
5686 "lnd tunables should be list\n");
5687 GOTO(out, rc = -EINVAL);
5690 rc = lnet_genl_parse_lnd_tunables(settings,
5693 GENL_SET_ERR_MSG(info,
5694 "failed to parse lnd tunables");
5697 } else if (nla_strcmp(settings, "CPT") == 0) {
5701 settings = nla_next(settings, &rem3);
5702 if (nla_type(settings) != LN_SCALAR_ATTR_LIST) {
5703 GENL_SET_ERR_MSG(info,
5704 "CPT should be list");
5705 GOTO(out, rc = -EINVAL);
5708 nla_for_each_nested(cpt, settings, rem4) {
5711 if (nla_type(cpt) !=
5712 LN_SCALAR_ATTR_INT_VALUE) {
5713 GENL_SET_ERR_MSG(info,
5714 "invalid CPT config");
5715 GOTO(out, rc = -EINVAL);
5718 core = nla_get_s64(cpt);
5719 if (core >= LNET_CPT_NUMBER) {
5720 GENL_SET_ERR_MSG(info,
5721 "invalid CPT value");
5722 GOTO(out, rc = -ERANGE);
5725 conf->lic_cpts[conf->lic_ncpts] = core;
5732 struct lnet_net *net;
5736 if (!strlen(conf->lic_ni_intf)) {
5737 GENL_SET_ERR_MSG(info,
5738 "interface is missing");
5742 lnet_net_lock(LNET_LOCK_EX);
5743 net = lnet_get_net_locked(net_id);
5745 GENL_SET_ERR_MSG(info,
5746 "LNet net doesn't exist");
5747 lnet_net_unlock(LNET_LOCK_EX);
5751 list_for_each_entry(ni, &net->net_ni_list,
5753 if (!ni->ni_interface ||
5754 strcmp(ni->ni_interface,
5755 conf->lic_ni_intf) != 0)
5758 lnet_net_unlock(LNET_LOCK_EX);
5759 rc = lnet_dyn_del_ni(&ni->ni_nid);
5761 GENL_SET_ERR_MSG(info,
5762 "cannot del LNet NI");
5768 if (rc < 0) { /* will be -ENODEV */
5769 GENL_SET_ERR_MSG(info,
5770 "interface invalid for deleting LNet NI");
5771 lnet_net_unlock(LNET_LOCK_EX);
5774 if (!strlen(conf->lic_ni_intf)) {
5775 GENL_SET_ERR_MSG(info,
5776 "interface is missing");
5780 rc = lnet_dyn_add_ni(conf, net_id, tun);
5783 GENL_SET_ERR_MSG(info,
5784 "cannot parse net");
5787 GENL_SET_ERR_MSG(info,
5791 GENL_SET_ERR_MSG(info,
5792 "cannot add LNet NI");
5799 LIBCFS_FREE(tun, sizeof(struct lnet_ioctl_config_lnd_tunables));
5804 static int lnet_net_cmd(struct sk_buff *skb, struct genl_info *info)
5806 struct nlmsghdr *nlh = nlmsg_hdr(skb);
5807 struct genlmsghdr *gnlh = nlmsg_data(nlh);
5808 struct nlattr *params = genlmsg_data(gnlh);
5809 int msg_len, rem, rc = 0;
5810 struct nlattr *attr;
5812 msg_len = genlmsg_len(gnlh);
5814 GENL_SET_ERR_MSG(info, "no configuration");
5818 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
5819 GENL_SET_ERR_MSG(info, "invalid configuration");
5823 nla_for_each_nested(attr, params, rem) {
5824 bool ni_list = false, ipnets = false;
5825 struct lnet_ioctl_config_ni conf;
5826 u32 net_id = LNET_NET_ANY;
5827 struct nlattr *entry;
5830 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
5833 nla_for_each_nested(entry, attr, rem2) {
5834 switch (nla_type(entry)) {
5835 case LN_SCALAR_ATTR_VALUE: {
5838 memset(&conf, 0, sizeof(conf));
5839 if (nla_strcmp(entry, "ip2net") == 0) {
5840 entry = nla_next(entry, &rem2);
5841 if (nla_type(entry) !=
5842 LN_SCALAR_ATTR_VALUE) {
5843 GENL_SET_ERR_MSG(info,
5844 "ip2net has invalid key");
5845 GOTO(out, rc = -EINVAL);
5848 len = nla_strscpy(conf.lic_legacy_ip2nets,
5850 sizeof(conf.lic_legacy_ip2nets));
5852 GENL_SET_ERR_MSG(info,
5853 "ip2net key string is invalid");
5854 GOTO(out, rc = len);
5858 } else if (nla_strcmp(entry, "net type") == 0) {
5859 char tmp[LNET_NIDSTR_SIZE];
5861 entry = nla_next(entry, &rem2);
5862 if (nla_type(entry) !=
5863 LN_SCALAR_ATTR_VALUE) {
5864 GENL_SET_ERR_MSG(info,
5865 "net type has invalid key");
5866 GOTO(out, rc = -EINVAL);
5869 len = nla_strscpy(tmp, entry,
5872 GENL_SET_ERR_MSG(info,
5873 "net type key string is invalid");
5874 GOTO(out, rc = len);
5877 net_id = libcfs_str2net(tmp);
5879 GENL_SET_ERR_MSG(info,
5880 "cannot parse net");
5881 GOTO(out, rc = -ENODEV);
5883 if (LNET_NETTYP(net_id) == LOLND) {
5884 GENL_SET_ERR_MSG(info,
5885 "setting @lo not allowed");
5886 GOTO(out, rc = -ENODEV);
5888 conf.lic_legacy_ip2nets[0] = '\0';
5889 conf.lic_ni_intf[0] = '\0';
5896 case LN_SCALAR_ATTR_LIST: {
5897 struct nlattr *interface;
5901 nla_for_each_nested(interface, entry, rem3) {
5902 rc = lnet_genl_parse_local_ni(interface, info,
5910 /* it is possible a newer version of the user land send
5911 * values older kernels doesn't handle. So silently
5912 * ignore these values
5919 /* Handle case of just sent NET with no list of NIDs */
5920 if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE) && !ni_list) {
5921 rc = lnet_dyn_del_net(net_id);
5923 GENL_SET_ERR_MSG(info,
5924 "cannot del network");
5926 } else if ((info->nlhdr->nlmsg_flags & NLM_F_CREATE) &&
5927 ipnets && ni_list) {
5928 rc = lnet_handle_legacy_ip2nets(conf.lic_legacy_ip2nets,
5931 GENL_SET_ERR_MSG(info,
5932 "cannot setup ip2nets");
5939 /* Called with ln_api_mutex */
5940 static int lnet_parse_peer_nis(struct nlattr *rlist, struct lnet_nid *pnid,
5941 bool mr, struct genl_info *info)
5943 struct lnet_nid snid = LNET_ANY_NID;
5944 struct nlattr *props;
5949 nla_for_each_nested(props, rlist, rem) {
5950 if (nla_type(props) != LN_SCALAR_ATTR_VALUE)
5953 if (nla_strcmp(props, "nid") == 0) {
5954 char nidstr[LNET_NIDSTR_SIZE];
5956 props = nla_next(props, &rem);
5957 if (nla_type(props) != LN_SCALAR_ATTR_VALUE) {
5958 GENL_SET_ERR_MSG(info,
5959 "invalid secondary NID");
5960 GOTO(report_err, rc = -EINVAL);
5963 rc = nla_strscpy(nidstr, props, sizeof(nidstr));
5965 GENL_SET_ERR_MSG(info,
5966 "failed to get secondary NID");
5967 GOTO(report_err, rc);
5970 rc = libcfs_strnid(&snid, strim(nidstr));
5972 GENL_SET_ERR_MSG(info, "unsupported secondary NID");
5973 GOTO(report_err, rc);
5976 if (LNET_NID_IS_ANY(&snid))
5978 } else if (nla_strcmp(props, "health stats") == 0) {
5979 struct nlattr *health;
5982 props = nla_next(props, &rem);
5983 if (nla_type(props) !=
5984 LN_SCALAR_ATTR_LIST) {
5985 GENL_SET_ERR_MSG(info,
5986 "invalid health configuration");
5987 GOTO(report_err, rc = -EINVAL);
5990 nla_for_each_nested(health, props, rem2) {
5991 if (nla_type(health) != LN_SCALAR_ATTR_VALUE ||
5992 nla_strcmp(health, "health value") != 0) {
5993 GENL_SET_ERR_MSG(info,
5994 "wrong health config format");
5995 GOTO(report_err, rc = -EINVAL);
5998 health = nla_next(health, &rem2);
5999 if (nla_type(health) !=
6000 LN_SCALAR_ATTR_INT_VALUE) {
6001 GENL_SET_ERR_MSG(info,
6002 "invalid health config format");
6003 GOTO(report_err, rc = -EINVAL);
6006 num = nla_get_s64(health);
6007 clamp_t(s64, num, 0, LNET_MAX_HEALTH_VALUE);
6012 if (info->nlhdr->nlmsg_flags & NLM_F_REPLACE && num != -1) {
6013 lnet_peer_ni_set_healthv(pnid, num, all);
6014 } else if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
6015 bool lock_prim = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6017 rc = lnet_user_add_peer_ni(pnid, &snid, mr, lock_prim);
6019 GENL_SET_ERR_MSG(info,
6020 "failed to add peer");
6021 } else if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE)) {
6022 bool force = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6024 rc = lnet_del_peer_ni(pnid, &snid, force);
6026 GENL_SET_ERR_MSG(info,
6027 "failed to del peer");
6033 static int lnet_peer_ni_cmd(struct sk_buff *skb, struct genl_info *info)
6035 struct nlmsghdr *nlh = nlmsg_hdr(skb);
6036 struct genlmsghdr *gnlh = nlmsg_data(nlh);
6037 struct nlattr *params = genlmsg_data(gnlh);
6038 int msg_len, rem, rc = 0;
6039 struct nlattr *attr;
6041 mutex_lock(&the_lnet.ln_api_mutex);
6042 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
6043 GENL_SET_ERR_MSG(info, "Network is down");
6044 mutex_unlock(&the_lnet.ln_api_mutex);
6048 msg_len = genlmsg_len(gnlh);
6050 GENL_SET_ERR_MSG(info, "no configuration");
6051 mutex_unlock(&the_lnet.ln_api_mutex);
6055 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
6056 GENL_SET_ERR_MSG(info, "invalid configuration");
6057 mutex_unlock(&the_lnet.ln_api_mutex);
6061 nla_for_each_nested(attr, params, rem) {
6062 struct lnet_nid pnid = LNET_ANY_NID;
6063 bool parse_peer_nis = false;
6064 struct nlattr *pnid_prop;
6067 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
6070 nla_for_each_nested(pnid_prop, attr, rem2) {
6073 if (nla_type(pnid_prop) != LN_SCALAR_ATTR_VALUE)
6076 if (nla_strcmp(pnid_prop, "primary nid") == 0) {
6077 char nidstr[LNET_NIDSTR_SIZE];
6079 pnid_prop = nla_next(pnid_prop, &rem2);
6080 if (nla_type(pnid_prop) !=
6081 LN_SCALAR_ATTR_VALUE) {
6082 GENL_SET_ERR_MSG(info,
6083 "invalid primary NID type");
6084 GOTO(report_err, rc = -EINVAL);
6087 rc = nla_strscpy(nidstr, pnid_prop,
6090 GENL_SET_ERR_MSG(info,
6091 "failed to get primary NID");
6092 GOTO(report_err, rc);
6095 rc = libcfs_strnid(&pnid, strim(nidstr));
6097 GENL_SET_ERR_MSG(info,
6098 "unsupported primary NID");
6099 GOTO(report_err, rc);
6102 /* we must create primary NID for peer ni
6105 if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
6108 lock_prim = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6109 rc = lnet_user_add_peer_ni(&pnid,
6113 GENL_SET_ERR_MSG(info,
6114 "failed to add primary peer");
6115 GOTO(report_err, rc);
6118 } else if (nla_strcmp(pnid_prop, "Multi-Rail") == 0) {
6119 pnid_prop = nla_next(pnid_prop, &rem2);
6120 if (nla_type(pnid_prop) !=
6121 LN_SCALAR_ATTR_INT_VALUE) {
6122 GENL_SET_ERR_MSG(info,
6123 "invalid MR flag param");
6124 GOTO(report_err, rc = -EINVAL);
6127 if (nla_get_s64(pnid_prop) == 0)
6129 } else if (nla_strcmp(pnid_prop, "peer state") == 0) {
6130 struct lnet_peer_ni *lpni;
6131 struct lnet_peer *lp;
6133 pnid_prop = nla_next(pnid_prop, &rem2);
6134 if (nla_type(pnid_prop) !=
6135 LN_SCALAR_ATTR_INT_VALUE) {
6136 GENL_SET_ERR_MSG(info,
6137 "invalid peer state param");
6138 GOTO(report_err, rc = -EINVAL);
6141 lpni = lnet_peer_ni_find_locked(&pnid);
6143 GENL_SET_ERR_MSG(info,
6144 "invalid peer state param");
6145 GOTO(report_err, rc = -ENOENT);
6147 lnet_peer_ni_decref_locked(lpni);
6148 lp = lpni->lpni_peer_net->lpn_peer;
6149 lp->lp_state = nla_get_s64(pnid_prop);
6150 } else if (nla_strcmp(pnid_prop, "peer ni") == 0) {
6151 struct nlattr *rlist;
6154 if (LNET_NID_IS_ANY(&pnid)) {
6155 GENL_SET_ERR_MSG(info,
6156 "missing required primary NID");
6157 GOTO(report_err, rc);
6160 pnid_prop = nla_next(pnid_prop, &rem2);
6161 if (nla_type(pnid_prop) !=
6162 LN_SCALAR_ATTR_LIST) {
6163 GENL_SET_ERR_MSG(info,
6164 "invalid NIDs list");
6165 GOTO(report_err, rc = -EINVAL);
6168 nla_for_each_nested(rlist, pnid_prop, rem3) {
6169 rc = lnet_parse_peer_nis(rlist, &pnid,
6172 GOTO(report_err, rc);
6174 parse_peer_nis = true;
6178 /* If we have remote peer ni's we already add /del peers */
6182 if (LNET_NID_IS_ANY(&pnid)) {
6183 GENL_SET_ERR_MSG(info, "missing primary NID");
6184 GOTO(report_err, rc);
6187 if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE)) {
6188 bool force = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6190 rc = lnet_del_peer_ni(&pnid, &LNET_ANY_NID,
6193 GENL_SET_ERR_MSG(info,
6194 "failed to del peer");
6195 GOTO(report_err, rc);
6200 mutex_unlock(&the_lnet.ln_api_mutex);
6205 /** LNet route handling */
6207 /* We can't use struct lnet_ioctl_config_data since it lacks
6208 * support for large NIDS
6210 struct lnet_route_properties {
6211 struct lnet_nid lrp_gateway;
6216 u32 lrp_sensitivity;
6219 struct lnet_genl_route_list {
6220 unsigned int lgrl_index;
6221 unsigned int lgrl_count;
6222 GENRADIX(struct lnet_route_properties) lgrl_list;
6225 static inline struct lnet_genl_route_list *
6226 lnet_route_dump_ctx(struct netlink_callback *cb)
6228 return (struct lnet_genl_route_list *)cb->args[0];
6231 static int lnet_route_show_done(struct netlink_callback *cb)
6233 struct lnet_genl_route_list *rlist = lnet_route_dump_ctx(cb);
6236 genradix_free(&rlist->lgrl_list);
6237 CFS_FREE_PTR(rlist);
6244 static int lnet_scan_route(struct lnet_genl_route_list *rlist,
6245 struct lnet_route_properties *settings)
6247 struct lnet_remotenet *rnet;
6248 struct list_head *rn_list;
6249 struct lnet_route *route;
6252 cpt = lnet_net_lock_current();
6254 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
6255 rn_list = &the_lnet.ln_remote_nets_hash[i];
6256 list_for_each_entry(rnet, rn_list, lrn_list) {
6257 if (settings->lrp_net != LNET_NET_ANY &&
6258 settings->lrp_net != rnet->lrn_net)
6261 list_for_each_entry(route, &rnet->lrn_routes,
6263 struct lnet_route_properties *prop;
6265 if (!LNET_NID_IS_ANY(&settings->lrp_gateway) &&
6266 !nid_same(&settings->lrp_gateway,
6271 if (settings->lrp_hop != -1 &&
6272 settings->lrp_hop != route->lr_hops)
6275 if (settings->lrp_priority != -1 &&
6276 settings->lrp_priority != route->lr_priority)
6279 if (settings->lrp_sensitivity != -1 &&
6280 settings->lrp_sensitivity !=
6281 route->lr_gateway->lp_health_sensitivity)
6284 prop = genradix_ptr_alloc(&rlist->lgrl_list,
6285 rlist->lgrl_count++,
6288 GOTO(failed_alloc, rc = -ENOMEM);
6290 prop->lrp_net = rnet->lrn_net;
6291 prop->lrp_gateway = route->lr_nid;
6292 prop->lrp_hop = route->lr_hops;
6293 prop->lrp_priority = route->lr_priority;
6294 prop->lrp_sensitivity =
6295 route->lr_gateway->lp_health_sensitivity;
6296 if (lnet_is_route_alive(route))
6297 prop->lrp_flags |= LNET_RT_ALIVE;
6299 prop->lrp_flags &= ~LNET_RT_ALIVE;
6300 if (route->lr_single_hop)
6301 prop->lrp_flags &= ~LNET_RT_MULTI_HOP;
6303 prop->lrp_flags |= LNET_RT_MULTI_HOP;
6309 lnet_net_unlock(cpt);
6313 /* LNet route ->start() handler for GET requests */
6314 static int lnet_route_show_start(struct netlink_callback *cb)
6316 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
6317 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
6318 struct netlink_ext_ack *extack = NULL;
6320 struct lnet_genl_route_list *rlist;
6321 int msg_len = genlmsg_len(gnlh);
6324 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
6325 extack = cb->extack;
6327 if (the_lnet.ln_refcount == 0 ||
6328 the_lnet.ln_state != LNET_STATE_RUNNING) {
6329 NL_SET_ERR_MSG(extack, "Network is down");
6333 CFS_ALLOC_PTR(rlist);
6335 NL_SET_ERR_MSG(extack, "No memory for route list");
6339 genradix_init(&rlist->lgrl_list);
6340 rlist->lgrl_count = 0;
6341 rlist->lgrl_index = 0;
6342 cb->args[0] = (long)rlist;
6344 mutex_lock(&the_lnet.ln_api_mutex);
6346 struct lnet_route_properties tmp = {
6347 .lrp_gateway = LNET_ANY_NID,
6348 .lrp_net = LNET_NET_ANY,
6351 .lrp_sensitivity = -1,
6354 rc = lnet_scan_route(rlist, &tmp);
6356 NL_SET_ERR_MSG(extack,
6357 "failed to allocate router data");
6358 GOTO(report_err, rc);
6361 struct nlattr *params = genlmsg_data(gnlh);
6362 struct nlattr *attr;
6365 nla_for_each_nested(attr, params, rem) {
6366 struct lnet_route_properties tmp = {
6367 .lrp_gateway = LNET_ANY_NID,
6368 .lrp_net = LNET_NET_ANY,
6371 .lrp_sensitivity = -1,
6373 struct nlattr *route;
6376 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
6379 nla_for_each_nested(route, attr, rem2) {
6380 if (nla_type(route) != LN_SCALAR_ATTR_VALUE)
6383 if (nla_strcmp(route, "net") == 0) {
6384 char nw[LNET_NIDSTR_SIZE];
6386 route = nla_next(route, &rem2);
6387 if (nla_type(route) !=
6388 LN_SCALAR_ATTR_VALUE) {
6389 NL_SET_ERR_MSG(extack,
6390 "invalid net param");
6391 GOTO(report_err, rc = -EINVAL);
6394 rc = nla_strscpy(nw, route, sizeof(nw));
6396 NL_SET_ERR_MSG(extack,
6397 "failed to get route param");
6398 GOTO(report_err, rc);
6401 tmp.lrp_net = libcfs_str2net(strim(nw));
6402 } else if (nla_strcmp(route, "gateway") == 0) {
6403 char gw[LNET_NIDSTR_SIZE];
6405 route = nla_next(route, &rem2);
6406 if (nla_type(route) !=
6407 LN_SCALAR_ATTR_VALUE) {
6408 NL_SET_ERR_MSG(extack,
6409 "invalid gateway param");
6410 GOTO(report_err, rc = -EINVAL);
6413 rc = nla_strscpy(gw, route, sizeof(gw));
6415 NL_SET_ERR_MSG(extack,
6416 "failed to get route param");
6417 GOTO(report_err, rc);
6420 rc = libcfs_strnid(&tmp.lrp_gateway, strim(gw));
6422 NL_SET_ERR_MSG(extack,
6423 "cannot parse gateway");
6424 GOTO(report_err, rc = -ENODEV);
6427 } else if (nla_strcmp(route, "hop") == 0) {
6428 route = nla_next(route, &rem2);
6429 if (nla_type(route) !=
6430 LN_SCALAR_ATTR_INT_VALUE) {
6431 NL_SET_ERR_MSG(extack,
6432 "invalid hop param");
6433 GOTO(report_err, rc = -EINVAL);
6436 tmp.lrp_hop = nla_get_s64(route);
6437 if (tmp.lrp_hop != -1)
6438 clamp_t(s32, tmp.lrp_hop, 1, 127);
6439 } else if (nla_strcmp(route, "priority") == 0) {
6440 route = nla_next(route, &rem2);
6441 if (nla_type(route) !=
6442 LN_SCALAR_ATTR_INT_VALUE) {
6443 NL_SET_ERR_MSG(extack,
6444 "invalid priority param");
6445 GOTO(report_err, rc = -EINVAL);
6448 tmp.lrp_priority = nla_get_s64(route);
6452 rc = lnet_scan_route(rlist, &tmp);
6454 NL_SET_ERR_MSG(extack,
6455 "failed to allocate router data");
6456 GOTO(report_err, rc);
6461 mutex_unlock(&the_lnet.ln_api_mutex);
6464 lnet_route_show_done(cb);
6469 static const struct ln_key_list route_props_list = {
6470 .lkl_maxattr = LNET_ROUTE_ATTR_MAX,
6472 [LNET_ROUTE_ATTR_HDR] = {
6473 .lkp_value = "route",
6474 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
6475 .lkp_data_type = NLA_NUL_STRING,
6477 [LNET_ROUTE_ATTR_NET] = {
6479 .lkp_data_type = NLA_STRING
6481 [LNET_ROUTE_ATTR_GATEWAY] = {
6482 .lkp_value = "gateway",
6483 .lkp_data_type = NLA_STRING
6485 [LNET_ROUTE_ATTR_HOP] = {
6487 .lkp_data_type = NLA_S32
6489 [LNET_ROUTE_ATTR_PRIORITY] = {
6490 .lkp_value = "priority",
6491 .lkp_data_type = NLA_U32
6493 [LNET_ROUTE_ATTR_HEALTH_SENSITIVITY] = {
6494 .lkp_value = "health_sensitivity",
6495 .lkp_data_type = NLA_U32
6497 [LNET_ROUTE_ATTR_STATE] = {
6498 .lkp_value = "state",
6499 .lkp_data_type = NLA_STRING,
6501 [LNET_ROUTE_ATTR_TYPE] = {
6502 .lkp_value = "type",
6503 .lkp_data_type = NLA_STRING,
6509 static int lnet_route_show_dump(struct sk_buff *msg,
6510 struct netlink_callback *cb)
6512 struct lnet_genl_route_list *rlist = lnet_route_dump_ctx(cb);
6513 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
6514 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
6515 struct netlink_ext_ack *extack = NULL;
6517 int portid = NETLINK_CB(cb->skb).portid;
6518 int seq = cb->nlh->nlmsg_seq;
6519 int idx = rlist->lgrl_index;
6522 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
6523 extack = cb->extack;
6525 if (!rlist->lgrl_count) {
6526 NL_SET_ERR_MSG(extack, "No routes found");
6527 GOTO(send_error, rc = -ENOENT);
6531 const struct ln_key_list *all[] = {
6532 &route_props_list, NULL
6535 rc = lnet_genl_send_scalar_list(msg, portid, seq,
6537 NLM_F_CREATE | NLM_F_MULTI,
6538 LNET_CMD_ROUTES, all);
6540 NL_SET_ERR_MSG(extack, "failed to send key table");
6541 GOTO(send_error, rc);
6545 /* If not routes found send an empty message and not an error */
6546 if (!rlist->lgrl_count) {
6549 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
6550 NLM_F_MULTI, LNET_CMD_ROUTES);
6552 NL_SET_ERR_MSG(extack, "failed to send values");
6553 genlmsg_cancel(msg, hdr);
6554 GOTO(send_error, rc = -EMSGSIZE);
6556 genlmsg_end(msg, hdr);
6561 while (idx < rlist->lgrl_count) {
6562 struct lnet_route_properties *prop;
6565 prop = genradix_ptr(&rlist->lgrl_list, idx++);
6567 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
6568 NLM_F_MULTI, LNET_CMD_ROUTES);
6570 NL_SET_ERR_MSG(extack, "failed to send values");
6571 genlmsg_cancel(msg, hdr);
6572 GOTO(send_error, rc = -EMSGSIZE);
6576 nla_put_string(msg, LNET_ROUTE_ATTR_HDR, "");
6578 nla_put_string(msg, LNET_ROUTE_ATTR_NET,
6579 libcfs_net2str(prop->lrp_net));
6580 nla_put_string(msg, LNET_ROUTE_ATTR_GATEWAY,
6581 libcfs_nidstr(&prop->lrp_gateway));
6582 if (gnlh->version) {
6583 nla_put_s32(msg, LNET_ROUTE_ATTR_HOP, prop->lrp_hop);
6584 nla_put_u32(msg, LNET_ROUTE_ATTR_PRIORITY, prop->lrp_priority);
6585 nla_put_u32(msg, LNET_ROUTE_ATTR_HEALTH_SENSITIVITY,
6586 prop->lrp_sensitivity);
6588 nla_put_string(msg, LNET_ROUTE_ATTR_STATE,
6589 prop->lrp_flags & LNET_RT_ALIVE ?
6591 nla_put_string(msg, LNET_ROUTE_ATTR_TYPE,
6592 prop->lrp_flags & LNET_RT_MULTI_HOP ?
6593 "multi-hop" : "single-hop");
6595 genlmsg_end(msg, hdr);
6597 rlist->lgrl_index = idx;
6599 return lnet_nl_send_error(cb->skb, portid, seq, rc);
6602 #ifndef HAVE_NETLINK_CALLBACK_START
6603 static int lnet_old_route_show_dump(struct sk_buff *msg,
6604 struct netlink_callback *cb)
6607 int rc = lnet_route_show_start(cb);
6613 return lnet_route_show_dump(msg, cb);
6615 #endif /* !HAVE_NETLINK_CALLBACK_START */
6617 /** LNet peer handling */
6618 struct lnet_genl_processid_list {
6619 unsigned int lgpl_index;
6620 unsigned int lgpl_count;
6621 GENRADIX(struct lnet_processid) lgpl_list;
6624 static inline struct lnet_genl_processid_list *
6625 lnet_peer_dump_ctx(struct netlink_callback *cb)
6627 return (struct lnet_genl_processid_list *)cb->args[0];
6630 static int lnet_peer_ni_show_done(struct netlink_callback *cb)
6632 struct lnet_genl_processid_list *plist = lnet_peer_dump_ctx(cb);
6635 genradix_free(&plist->lgpl_list);
6636 CFS_FREE_PTR(plist);
6643 /* LNet peer ->start() handler for GET requests */
6644 static int lnet_peer_ni_show_start(struct netlink_callback *cb)
6646 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
6647 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
6648 struct netlink_ext_ack *extack = NULL;
6650 struct lnet_genl_processid_list *plist;
6651 int msg_len = genlmsg_len(gnlh);
6654 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
6655 extack = cb->extack;
6657 mutex_lock(&the_lnet.ln_api_mutex);
6658 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
6659 NL_SET_ERR_MSG(extack, "Network is down");
6660 mutex_unlock(&the_lnet.ln_api_mutex);
6664 CFS_ALLOC_PTR(plist);
6666 NL_SET_ERR_MSG(extack, "No memory for peer list");
6667 mutex_unlock(&the_lnet.ln_api_mutex);
6671 genradix_init(&plist->lgpl_list);
6672 plist->lgpl_count = 0;
6673 plist->lgpl_index = 0;
6674 cb->args[0] = (long)plist;
6677 struct lnet_peer_table *ptable;
6680 cfs_percpt_for_each(ptable, cpt, the_lnet.ln_peer_tables) {
6681 struct lnet_peer *lp;
6683 list_for_each_entry(lp, &ptable->pt_peer_list, lp_peer_list) {
6684 struct lnet_processid *lpi;
6686 lpi = genradix_ptr_alloc(&plist->lgpl_list,
6687 plist->lgpl_count++,
6690 NL_SET_ERR_MSG(extack, "failed to allocate NID");
6691 GOTO(report_err, rc = -ENOMEM);
6694 lpi->pid = LNET_PID_LUSTRE;
6695 lpi->nid = lp->lp_primary_nid;
6699 struct nlattr *params = genlmsg_data(gnlh);
6700 struct nlattr *attr;
6703 nla_for_each_nested(attr, params, rem) {
6707 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
6710 nla_for_each_nested(nid, attr, rem2) {
6711 char addr[LNET_NIDSTR_SIZE];
6712 struct lnet_processid *id;
6714 if (nla_type(nid) != LN_SCALAR_ATTR_VALUE ||
6715 nla_strcmp(nid, "primary nid") != 0)
6718 nid = nla_next(nid, &rem2);
6719 if (nla_type(nid) != LN_SCALAR_ATTR_VALUE) {
6720 NL_SET_ERR_MSG(extack,
6721 "invalid primary nid param");
6722 GOTO(report_err, rc = -EINVAL);
6725 rc = nla_strscpy(addr, nid, sizeof(addr));
6727 NL_SET_ERR_MSG(extack,
6728 "failed to get primary nid param");
6729 GOTO(report_err, rc);
6732 id = genradix_ptr_alloc(&plist->lgpl_list,
6733 plist->lgpl_count++,
6736 NL_SET_ERR_MSG(extack, "failed to allocate NID");
6737 GOTO(report_err, rc = -ENOMEM);
6740 rc = libcfs_strid(id, strim(addr));
6742 NL_SET_ERR_MSG(extack, "invalid NID");
6743 GOTO(report_err, rc);
6750 mutex_unlock(&the_lnet.ln_api_mutex);
6753 lnet_peer_ni_show_done(cb);
6758 static const struct ln_key_list lnet_peer_ni_keys = {
6759 .lkl_maxattr = LNET_PEER_NI_ATTR_MAX,
6761 [LNET_PEER_NI_ATTR_HDR] = {
6762 .lkp_value = "peer",
6763 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
6764 .lkp_data_type = NLA_NUL_STRING,
6766 [LNET_PEER_NI_ATTR_PRIMARY_NID] = {
6767 .lkp_value = "primary nid",
6768 .lkp_data_type = NLA_STRING,
6770 [LNET_PEER_NI_ATTR_MULTIRAIL] = {
6771 .lkp_value = "Multi-Rail",
6772 .lkp_data_type = NLA_FLAG
6774 [LNET_PEER_NI_ATTR_STATE] = {
6775 .lkp_value = "peer state",
6776 .lkp_data_type = NLA_U32
6778 [LNET_PEER_NI_ATTR_PEER_NI_LIST] = {
6779 .lkp_value = "peer ni",
6780 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
6781 .lkp_data_type = NLA_NESTED,
6786 static const struct ln_key_list lnet_peer_ni_list = {
6787 .lkl_maxattr = LNET_PEER_NI_LIST_ATTR_MAX,
6789 [LNET_PEER_NI_LIST_ATTR_NID] = {
6791 .lkp_data_type = NLA_STRING,
6793 [LNET_PEER_NI_LIST_ATTR_UDSP_INFO] = {
6794 .lkp_value = "udsp info",
6795 .lkp_key_format = LNKF_MAPPING,
6796 .lkp_data_type = NLA_NESTED,
6798 [LNET_PEER_NI_LIST_ATTR_STATE] = {
6799 .lkp_value = "state",
6800 .lkp_data_type = NLA_STRING,
6802 [LNET_PEER_NI_LIST_ATTR_MAX_TX_CREDITS] = {
6803 .lkp_value = "max_ni_tx_credits",
6804 .lkp_data_type = NLA_U32,
6806 [LNET_PEER_NI_LIST_ATTR_CUR_TX_CREDITS] = {
6807 .lkp_value = "available_tx_credits",
6808 .lkp_data_type = NLA_U32,
6810 [LNET_PEER_NI_LIST_ATTR_MIN_TX_CREDITS] = {
6811 .lkp_value = "min_tx_credits",
6812 .lkp_data_type = NLA_U32,
6814 [LNET_PEER_NI_LIST_ATTR_QUEUE_BUF_COUNT] = {
6815 .lkp_value = "tx_q_num_of_buf",
6816 .lkp_data_type = NLA_U32,
6818 [LNET_PEER_NI_LIST_ATTR_CUR_RTR_CREDITS] = {
6819 .lkp_value = "available_rtr_credits",
6820 .lkp_data_type = NLA_U32,
6822 [LNET_PEER_NI_LIST_ATTR_MIN_RTR_CREDITS] = {
6823 .lkp_value = "min_rtr_credits",
6824 .lkp_data_type = NLA_U32,
6826 [LNET_PEER_NI_LIST_ATTR_REFCOUNT] = {
6827 .lkp_value = "refcount",
6828 .lkp_data_type = NLA_U32,
6830 [LNET_PEER_NI_LIST_ATTR_STATS_COUNT] = {
6831 .lkp_value = "statistics",
6832 .lkp_key_format = LNKF_MAPPING,
6833 .lkp_data_type = NLA_NESTED
6835 [LNET_PEER_NI_LIST_ATTR_SENT_STATS] = {
6836 .lkp_value = "sent_stats",
6837 .lkp_key_format = LNKF_MAPPING,
6838 .lkp_data_type = NLA_NESTED
6840 [LNET_PEER_NI_LIST_ATTR_RECV_STATS] = {
6841 .lkp_value = "received_stats",
6842 .lkp_key_format = LNKF_MAPPING,
6843 .lkp_data_type = NLA_NESTED
6845 [LNET_PEER_NI_LIST_ATTR_DROP_STATS] = {
6846 .lkp_value = "dropped_stats",
6847 .lkp_key_format = LNKF_MAPPING,
6848 .lkp_data_type = NLA_NESTED
6850 [LNET_PEER_NI_LIST_ATTR_HEALTH_STATS] = {
6851 .lkp_value = "health stats",
6852 .lkp_key_format = LNKF_MAPPING,
6853 .lkp_data_type = NLA_NESTED
6858 static const struct ln_key_list lnet_peer_ni_list_stats_count = {
6859 .lkl_maxattr = LNET_PEER_NI_LIST_STATS_COUNT_ATTR_MAX,
6861 [LNET_PEER_NI_LIST_STATS_COUNT_ATTR_SEND_COUNT] = {
6862 .lkp_value = "send_count",
6863 .lkp_data_type = NLA_U32,
6865 [LNET_PEER_NI_LIST_STATS_COUNT_ATTR_RECV_COUNT] = {
6866 .lkp_value = "recv_count",
6867 .lkp_data_type = NLA_U32,
6869 [LNET_PEER_NI_LIST_STATS_COUNT_ATTR_DROP_COUNT] = {
6870 .lkp_value = "drop_count",
6871 .lkp_data_type = NLA_U32,
6876 static const struct ln_key_list lnet_peer_ni_list_stats = {
6877 .lkl_maxattr = LNET_PEER_NI_LIST_STATS_ATTR_MAX,
6879 [LNET_PEER_NI_LIST_STATS_ATTR_PUT] = {
6881 .lkp_data_type = NLA_U32,
6883 [LNET_PEER_NI_LIST_STATS_ATTR_GET] = {
6885 .lkp_data_type = NLA_U32,
6887 [LNET_PEER_NI_LIST_STATS_ATTR_REPLY] = {
6888 .lkp_value = "reply",
6889 .lkp_data_type = NLA_U32,
6891 [LNET_PEER_NI_LIST_STATS_ATTR_ACK] = {
6893 .lkp_data_type = NLA_U32,
6895 [LNET_PEER_NI_LIST_STATS_ATTR_HELLO] = {
6896 .lkp_value = "hello",
6897 .lkp_data_type = NLA_U32,
6902 static const struct ln_key_list lnet_peer_ni_list_health = {
6903 .lkl_maxattr = LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_MAX,
6905 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_VALUE] = {
6906 .lkp_value = "health value",
6907 .lkp_data_type = NLA_S32,
6909 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_DROPPED] = {
6910 .lkp_value = "dropped",
6911 .lkp_data_type = NLA_U32,
6913 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_TIMEOUT] = {
6914 .lkp_value = "timeout",
6915 .lkp_data_type = NLA_U32,
6917 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_ERROR] = {
6918 .lkp_value = "error",
6919 .lkp_data_type = NLA_U32,
6921 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NETWORK_TIMEOUT] = {
6922 .lkp_value = "network timeout",
6923 .lkp_data_type = NLA_U32,
6925 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PING_COUNT] = {
6926 .lkp_value = "ping_count",
6927 .lkp_data_type = NLA_U32,
6929 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NEXT_PING] = {
6930 .lkp_value = "next_ping",
6931 .lkp_data_type = NLA_S64,
6936 static int lnet_peer_ni_show_dump(struct sk_buff *msg,
6937 struct netlink_callback *cb)
6939 struct lnet_genl_processid_list *plist = lnet_peer_dump_ctx(cb);
6940 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
6941 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
6942 struct netlink_ext_ack *extack = NULL;
6944 int portid = NETLINK_CB(cb->skb).portid;
6945 int seq = cb->nlh->nlmsg_seq;
6946 int idx = plist->lgpl_index;
6949 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
6950 extack = cb->extack;
6952 if (!plist->lgpl_count) {
6953 NL_SET_ERR_MSG(extack, "No peers found");
6954 GOTO(send_error, rc = -ENOENT);
6958 const struct ln_key_list *all[] = {
6959 &lnet_peer_ni_keys, &lnet_peer_ni_list,
6960 &udsp_info_list, &udsp_info_pref_nids_list,
6961 &udsp_info_pref_nids_list,
6962 &lnet_peer_ni_list_stats_count,
6963 &lnet_peer_ni_list_stats, /* send_stats */
6964 &lnet_peer_ni_list_stats, /* recv_stats */
6965 &lnet_peer_ni_list_stats, /* drop stats */
6966 &lnet_peer_ni_list_health,
6970 rc = lnet_genl_send_scalar_list(msg, portid, seq,
6972 NLM_F_CREATE | NLM_F_MULTI,
6973 LNET_CMD_PEERS, all);
6975 NL_SET_ERR_MSG(extack, "failed to send key table");
6976 GOTO(send_error, rc);
6980 mutex_lock(&the_lnet.ln_api_mutex);
6981 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
6982 NL_SET_ERR_MSG(extack, "Network is down");
6983 GOTO(unlock_api_mutex, rc = -ENETDOWN);
6986 while (idx < plist->lgpl_count) {
6987 struct lnet_processid *id;
6988 struct lnet_peer_ni *lpni;
6989 struct nlattr *nid_list;
6990 struct lnet_peer *lp;
6994 id = genradix_ptr(&plist->lgpl_list, idx++);
6995 if (nid_is_lo0(&id->nid))
6998 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
6999 NLM_F_MULTI, LNET_CMD_PEERS);
7001 NL_SET_ERR_MSG(extack, "failed to send values");
7002 genlmsg_cancel(msg, hdr);
7003 GOTO(unlock_api_mutex, rc = -EMSGSIZE);
7006 lp = lnet_find_peer(&id->nid);
7008 NL_SET_ERR_MSG(extack, "cannot find peer");
7009 GOTO(unlock_api_mutex, rc = -ENOENT);
7013 nla_put_string(msg, LNET_PEER_NI_ATTR_HDR, "");
7015 nla_put_string(msg, LNET_PEER_NI_ATTR_PRIMARY_NID,
7016 libcfs_nidstr(&lp->lp_primary_nid));
7017 if (lnet_peer_is_multi_rail(lp))
7018 nla_put_flag(msg, LNET_PEER_NI_ATTR_MULTIRAIL);
7020 if (gnlh->version >= 3)
7021 nla_put_u32(msg, LNET_PEER_NI_ATTR_STATE, lp->lp_state);
7023 nid_list = nla_nest_start(msg, LNET_PEER_NI_ATTR_PEER_NI_LIST);
7024 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL) {
7025 struct nlattr *peer_nid = nla_nest_start(msg, count++);
7027 nla_put_string(msg, LNET_PEER_NI_LIST_ATTR_NID,
7028 libcfs_nidstr(&lpni->lpni_nid));
7030 if (gnlh->version >= 4) {
7031 rc = lnet_udsp_info_send(msg,
7032 LNET_PEER_NI_LIST_ATTR_UDSP_INFO,
7033 &lpni->lpni_nid, true);
7035 lnet_peer_decref_locked(lp);
7036 NL_SET_ERR_MSG(extack,
7037 "failed to get UDSP info");
7038 GOTO(unlock_api_mutex, rc);
7042 if (lnet_isrouter(lpni) ||
7043 lnet_peer_aliveness_enabled(lpni)) {
7044 nla_put_string(msg, LNET_PEER_NI_LIST_ATTR_STATE,
7045 lnet_is_peer_ni_alive(lpni) ?
7048 nla_put_string(msg, LNET_PEER_NI_LIST_ATTR_STATE,
7052 if (gnlh->version) {
7053 struct lnet_ioctl_element_msg_stats lpni_msg_stats;
7054 struct nlattr *send_stats_list, *send_stats;
7055 struct nlattr *recv_stats_list, *recv_stats;
7056 struct nlattr *drop_stats_list, *drop_stats;
7057 struct nlattr *health_list, *health_stats;
7058 struct lnet_ioctl_element_stats stats;
7059 struct nlattr *stats_attr, *ni_stats;
7062 LNET_PEER_NI_LIST_ATTR_MAX_TX_CREDITS,
7064 lpni->lpni_net->net_tunables.lct_peer_tx_credits : 0);
7066 LNET_PEER_NI_LIST_ATTR_CUR_TX_CREDITS,
7067 lpni->lpni_txcredits);
7069 LNET_PEER_NI_LIST_ATTR_MIN_TX_CREDITS,
7070 lpni->lpni_mintxcredits);
7072 LNET_PEER_NI_LIST_ATTR_QUEUE_BUF_COUNT,
7075 LNET_PEER_NI_LIST_ATTR_CUR_RTR_CREDITS,
7076 lpni->lpni_rtrcredits);
7078 LNET_PEER_NI_LIST_ATTR_MIN_RTR_CREDITS,
7079 lpni->lpni_minrtrcredits);
7081 LNET_PEER_NI_LIST_ATTR_REFCOUNT,
7082 kref_read(&lpni->lpni_kref));
7084 memset(&stats, 0, sizeof(stats));
7085 stats.iel_send_count = lnet_sum_stats(&lpni->lpni_stats,
7086 LNET_STATS_TYPE_SEND);
7087 stats.iel_recv_count = lnet_sum_stats(&lpni->lpni_stats,
7088 LNET_STATS_TYPE_RECV);
7089 stats.iel_drop_count = lnet_sum_stats(&lpni->lpni_stats,
7090 LNET_STATS_TYPE_DROP);
7092 stats_attr = nla_nest_start(msg,
7093 LNET_PEER_NI_LIST_ATTR_STATS_COUNT);
7094 ni_stats = nla_nest_start(msg, 0);
7096 LNET_PEER_NI_LIST_STATS_COUNT_ATTR_SEND_COUNT,
7097 stats.iel_send_count);
7099 LNET_PEER_NI_LIST_STATS_COUNT_ATTR_RECV_COUNT,
7100 stats.iel_recv_count);
7102 LNET_PEER_NI_LIST_STATS_COUNT_ATTR_DROP_COUNT,
7103 stats.iel_drop_count);
7104 nla_nest_end(msg, ni_stats);
7105 nla_nest_end(msg, stats_attr);
7107 if (gnlh->version < 2)
7108 goto skip_msg_stats;
7110 lnet_usr_translate_stats(&lpni_msg_stats, &lpni->lpni_stats);
7112 send_stats_list = nla_nest_start(msg,
7113 LNET_PEER_NI_LIST_ATTR_SENT_STATS);
7114 send_stats = nla_nest_start(msg, 0);
7116 LNET_PEER_NI_LIST_STATS_ATTR_PUT,
7117 lpni_msg_stats.im_send_stats.ico_put_count);
7119 LNET_PEER_NI_LIST_STATS_ATTR_GET,
7120 lpni_msg_stats.im_send_stats.ico_get_count);
7122 LNET_PEER_NI_LIST_STATS_ATTR_REPLY,
7123 lpni_msg_stats.im_send_stats.ico_reply_count);
7125 LNET_PEER_NI_LIST_STATS_ATTR_ACK,
7126 lpni_msg_stats.im_send_stats.ico_ack_count);
7128 LNET_PEER_NI_LIST_STATS_ATTR_HELLO,
7129 lpni_msg_stats.im_send_stats.ico_hello_count);
7130 nla_nest_end(msg, send_stats);
7131 nla_nest_end(msg, send_stats_list);
7133 recv_stats_list = nla_nest_start(msg,
7134 LNET_PEER_NI_LIST_ATTR_RECV_STATS);
7135 recv_stats = nla_nest_start(msg, 0);
7137 LNET_PEER_NI_LIST_STATS_ATTR_PUT,
7138 lpni_msg_stats.im_recv_stats.ico_put_count);
7140 LNET_PEER_NI_LIST_STATS_ATTR_GET,
7141 lpni_msg_stats.im_recv_stats.ico_get_count);
7143 LNET_PEER_NI_LIST_STATS_ATTR_REPLY,
7144 lpni_msg_stats.im_recv_stats.ico_reply_count);
7146 LNET_PEER_NI_LIST_STATS_ATTR_ACK,
7147 lpni_msg_stats.im_recv_stats.ico_ack_count);
7149 LNET_PEER_NI_LIST_STATS_ATTR_HELLO,
7150 lpni_msg_stats.im_recv_stats.ico_hello_count);
7151 nla_nest_end(msg, recv_stats);
7152 nla_nest_end(msg, recv_stats_list);
7154 drop_stats_list = nla_nest_start(msg,
7155 LNET_PEER_NI_LIST_ATTR_DROP_STATS);
7156 drop_stats = nla_nest_start(msg, 0);
7158 LNET_PEER_NI_LIST_STATS_ATTR_PUT,
7159 lpni_msg_stats.im_drop_stats.ico_put_count);
7161 LNET_PEER_NI_LIST_STATS_ATTR_GET,
7162 lpni_msg_stats.im_drop_stats.ico_get_count);
7164 LNET_PEER_NI_LIST_STATS_ATTR_REPLY,
7165 lpni_msg_stats.im_drop_stats.ico_reply_count);
7167 LNET_PEER_NI_LIST_STATS_ATTR_ACK,
7168 lpni_msg_stats.im_drop_stats.ico_ack_count);
7170 LNET_PEER_NI_LIST_STATS_ATTR_HELLO,
7171 lpni_msg_stats.im_drop_stats.ico_hello_count);
7172 nla_nest_end(msg, drop_stats);
7173 nla_nest_end(msg, drop_stats_list);
7175 health_list = nla_nest_start(msg,
7176 LNET_PEER_NI_LIST_ATTR_HEALTH_STATS);
7177 health_stats = nla_nest_start(msg, 0);
7179 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_VALUE,
7180 atomic_read(&lpni->lpni_healthv));
7182 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_DROPPED,
7183 atomic_read(&lpni->lpni_hstats.hlt_remote_dropped));
7185 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_TIMEOUT,
7186 atomic_read(&lpni->lpni_hstats.hlt_remote_timeout));
7188 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_ERROR,
7189 atomic_read(&lpni->lpni_hstats.hlt_remote_error));
7191 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NETWORK_TIMEOUT,
7192 atomic_read(&lpni->lpni_hstats.hlt_network_timeout));
7194 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PING_COUNT,
7195 lpni->lpni_ping_count);
7197 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NEXT_PING,
7198 lpni->lpni_next_ping,
7199 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PAD);
7200 nla_nest_end(msg, health_stats);
7201 nla_nest_end(msg, health_list);
7204 nla_nest_end(msg, peer_nid);
7206 nla_nest_end(msg, nid_list);
7208 genlmsg_end(msg, hdr);
7209 lnet_peer_decref_locked(lp);
7211 plist->lgpl_index = idx;
7213 mutex_unlock(&the_lnet.ln_api_mutex);
7215 return lnet_nl_send_error(cb->skb, portid, seq, rc);
7218 #ifndef HAVE_NETLINK_CALLBACK_START
7219 static int lnet_old_peer_ni_show_dump(struct sk_buff *msg,
7220 struct netlink_callback *cb)
7223 int rc = lnet_peer_ni_show_start(cb);
7229 return lnet_peer_ni_show_dump(msg, cb);
7233 static int lnet_route_cmd(struct sk_buff *skb, struct genl_info *info)
7235 struct nlmsghdr *nlh = nlmsg_hdr(skb);
7236 struct genlmsghdr *gnlh = nlmsg_data(nlh);
7237 struct nlattr *params = genlmsg_data(gnlh);
7238 int msg_len, rem, rc = 0;
7239 struct nlattr *attr;
7241 mutex_lock(&the_lnet.ln_api_mutex);
7242 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
7243 GENL_SET_ERR_MSG(info, "Network is down");
7244 mutex_unlock(&the_lnet.ln_api_mutex);
7248 msg_len = genlmsg_len(gnlh);
7250 GENL_SET_ERR_MSG(info, "no configuration");
7251 mutex_unlock(&the_lnet.ln_api_mutex);
7255 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
7256 GENL_SET_ERR_MSG(info, "invalid configuration");
7257 mutex_unlock(&the_lnet.ln_api_mutex);
7261 nla_for_each_nested(attr, params, rem) {
7262 u32 net_id = LNET_NET_ANY, hops = LNET_UNDEFINED_HOPS;
7263 u32 priority = 0, sensitivity = 1;
7264 struct lnet_nid gw_nid = LNET_ANY_NID;
7265 struct nlattr *route_prop;
7270 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
7273 nla_for_each_nested(route_prop, attr, rem2) {
7274 char tmp[LNET_NIDSTR_SIZE];
7278 if (nla_type(route_prop) != LN_SCALAR_ATTR_VALUE)
7281 if (nla_strcmp(route_prop, "net") == 0) {
7282 route_prop = nla_next(route_prop, &rem2);
7283 if (nla_type(route_prop) !=
7284 LN_SCALAR_ATTR_VALUE) {
7285 GENL_SET_ERR_MSG(info,
7286 "net is invalid key");
7287 GOTO(report_err, rc = -EINVAL);
7290 len = nla_strscpy(tmp, route_prop, sizeof(tmp));
7292 GENL_SET_ERR_MSG(info,
7293 "net key string is invalid");
7294 GOTO(report_err, rc = len);
7297 net_id = libcfs_str2net(tmp);
7299 GENL_SET_ERR_MSG(info,
7300 "cannot parse remote net");
7301 GOTO(report_err, rc = -ENODEV);
7304 if (LNET_NETTYP(net_id) == LOLND) {
7305 GENL_SET_ERR_MSG(info,
7306 "setting @lo not allowed");
7307 GOTO(report_err, rc = -EACCES);
7310 if (net_id == LNET_NET_ANY) {
7311 GENL_SET_ERR_MSG(info,
7312 "setting LNET_NET_ANY not allowed");
7313 GOTO(report_err, rc = -ENXIO);
7315 } else if (nla_strcmp(route_prop, "gateway") == 0) {
7316 route_prop = nla_next(route_prop, &rem2);
7317 if (nla_type(route_prop) !=
7318 LN_SCALAR_ATTR_VALUE) {
7319 GENL_SET_ERR_MSG(info,
7320 "gateway is invalid key");
7321 GOTO(report_err, rc = -EINVAL);
7324 len = nla_strscpy(tmp, route_prop, sizeof(tmp));
7326 GENL_SET_ERR_MSG(info,
7327 "gateway string is invalid");
7328 GOTO(report_err, rc = len);
7331 rc = libcfs_strnid(&gw_nid, strim(tmp));
7333 GENL_SET_ERR_MSG(info,
7334 "cannot parse gateway");
7335 GOTO(report_err, rc = -ENODEV);
7337 } else if (nla_strcmp(route_prop, "state") == 0) {
7338 route_prop = nla_next(route_prop, &rem2);
7339 if (nla_type(route_prop) !=
7340 LN_SCALAR_ATTR_VALUE) {
7341 GENL_SET_ERR_MSG(info,
7342 "state is invalid key");
7343 GOTO(report_err, rc = -EINVAL);
7346 if (nla_strcmp(route_prop, "down") == 0) {
7348 } else if (nla_strcmp(route_prop, "up") == 0) {
7351 GENL_SET_ERR_MSG(info,
7352 "status string bad value");
7353 GOTO(report_err, rc = -EINVAL);
7355 } else if (nla_strcmp(route_prop, "notify_time") == 0) {
7356 route_prop = nla_next(route_prop, &rem2);
7357 if (nla_type(route_prop) !=
7358 LN_SCALAR_ATTR_INT_VALUE) {
7359 GENL_SET_ERR_MSG(info,
7360 "notify_time is invalid key");
7361 GOTO(report_err, rc = -EINVAL);
7364 when = nla_get_s64(route_prop);
7365 if (ktime_get_real_seconds() < when) {
7366 GENL_SET_ERR_MSG(info,
7367 "notify_time is in the future");
7368 GOTO(report_err, rc = -EINVAL);
7370 } else if (nla_strcmp(route_prop, "hop") == 0) {
7371 route_prop = nla_next(route_prop, &rem2);
7372 if (nla_type(route_prop) !=
7373 LN_SCALAR_ATTR_INT_VALUE) {
7374 GENL_SET_ERR_MSG(info,
7375 "hop has invalid key");
7376 GOTO(report_err, rc = -EINVAL);
7379 hops = nla_get_s64(route_prop);
7380 if (hops < 1 || hops > 255) {
7381 GENL_SET_ERR_MSG(info,
7382 "invalid hop count must be between 1 and 255");
7383 GOTO(report_err, rc = -EINVAL);
7385 } else if (nla_strcmp(route_prop, "priority") == 0) {
7386 route_prop = nla_next(route_prop, &rem2);
7387 if (nla_type(route_prop) !=
7388 LN_SCALAR_ATTR_INT_VALUE) {
7389 GENL_SET_ERR_MSG(info,
7390 "priority has invalid key");
7391 GOTO(report_err, rc = -EINVAL);
7394 num = nla_get_s64(route_prop);
7396 GENL_SET_ERR_MSG(info,
7397 "invalid priority, must not be negative");
7398 GOTO(report_err, rc = -EINVAL);
7401 } else if (nla_strcmp(route_prop,
7402 "health_sensitivity") == 0) {
7403 route_prop = nla_next(route_prop, &rem2);
7404 if (nla_type(route_prop) !=
7405 LN_SCALAR_ATTR_INT_VALUE) {
7406 GENL_SET_ERR_MSG(info,
7407 "sensitivity has invalid key");
7408 GOTO(report_err, rc = -EINVAL);
7411 num = nla_get_s64(route_prop);
7413 GENL_SET_ERR_MSG(info,
7414 "invalid health sensitivity, must be 1 or greater");
7415 GOTO(report_err, rc = -EINVAL);
7421 if (net_id == LNET_NET_ANY) {
7422 GENL_SET_ERR_MSG(info,
7423 "missing mandatory parameter: network");
7424 GOTO(report_err, rc = -ENODEV);
7427 if (LNET_NID_IS_ANY(&gw_nid)) {
7428 GENL_SET_ERR_MSG(info,
7429 "missing mandatory parameter: gateway");
7430 GOTO(report_err, rc = -ENODEV);
7433 if (info->nlhdr->nlmsg_flags & NLM_F_REPLACE) {
7434 /* Convert the user-supplied real time to monotonic.
7435 * NB: "when" is always in the past
7437 when = ktime_get_seconds() -
7438 (ktime_get_real_seconds() - when);
7440 mutex_unlock(&the_lnet.ln_api_mutex);
7441 rc = lnet_notify(NULL, &gw_nid, alive, false, when);
7442 mutex_lock(&the_lnet.ln_api_mutex);
7444 GOTO(report_err, rc);
7445 else if (the_lnet.ln_state != LNET_STATE_RUNNING)
7446 GOTO(report_err, rc = -ENETDOWN);
7447 } else if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
7448 rc = lnet_add_route(net_id, hops, &gw_nid, priority,
7453 GENL_SET_ERR_MSG(info,
7454 "invalid settings for route creation");
7457 GENL_SET_ERR_MSG(info,
7458 "No interface configured on the same net as gateway");
7461 GENL_SET_ERR_MSG(info,
7465 GENL_SET_ERR_MSG(info,
7466 "Route already exists or the specified network is local");
7469 GENL_SET_ERR_MSG(info,
7470 "failed to create route");
7473 GOTO(report_err, rc);
7475 } else if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE)) {
7476 rc = lnet_del_route(net_id, &gw_nid);
7478 GENL_SET_ERR_MSG(info,
7479 "failed to delete route");
7480 GOTO(report_err, rc);
7485 mutex_unlock(&the_lnet.ln_api_mutex);
7490 static inline struct lnet_genl_ping_list *
7491 lnet_ping_dump_ctx(struct netlink_callback *cb)
7493 return (struct lnet_genl_ping_list *)cb->args[0];
7496 static int lnet_ping_show_done(struct netlink_callback *cb)
7498 struct lnet_genl_ping_list *plist = lnet_ping_dump_ctx(cb);
7501 genradix_free(&plist->lgpl_failed);
7502 genradix_free(&plist->lgpl_list);
7503 LIBCFS_FREE(plist, sizeof(*plist));
7510 /* LNet ping ->start() handler for GET requests */
7511 static int lnet_ping_show_start(struct netlink_callback *cb)
7513 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
7514 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
7515 struct netlink_ext_ack *extack = NULL;
7517 struct lnet_genl_ping_list *plist;
7518 int msg_len = genlmsg_len(gnlh);
7519 struct nlattr *params, *top;
7522 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
7523 extack = cb->extack;
7525 if (the_lnet.ln_refcount == 0) {
7526 NL_SET_ERR_MSG(extack, "Network is down");
7531 NL_SET_ERR_MSG(extack, "Ping needs NID targets");
7535 LIBCFS_ALLOC(plist, sizeof(*plist));
7537 NL_SET_ERR_MSG(extack, "failed to setup ping list");
7540 genradix_init(&plist->lgpl_list);
7541 plist->lgpl_timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
7542 plist->lgpl_src_nid = LNET_ANY_NID;
7543 plist->lgpl_index = 0;
7544 plist->lgpl_list_count = 0;
7545 cb->args[0] = (long)plist;
7547 params = genlmsg_data(gnlh);
7548 nla_for_each_attr(top, params, msg_len, rem) {
7549 struct nlattr *nids;
7552 switch (nla_type(top)) {
7553 case LN_SCALAR_ATTR_VALUE:
7554 if (nla_strcmp(top, "timeout") == 0) {
7557 top = nla_next(top, &rem);
7558 if (nla_type(top) != LN_SCALAR_ATTR_INT_VALUE) {
7559 NL_SET_ERR_MSG(extack,
7560 "invalid timeout param");
7561 GOTO(report_err, rc = -EINVAL);
7564 /* If timeout is negative then set default of
7567 timeout = nla_get_s64(top);
7569 timeout < (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
7570 plist->lgpl_timeout =
7571 nsecs_to_jiffies(timeout * NSEC_PER_MSEC);
7572 } else if (nla_strcmp(top, "source") == 0) {
7573 char nidstr[LNET_NIDSTR_SIZE + 1];
7575 top = nla_next(top, &rem);
7576 if (nla_type(top) != LN_SCALAR_ATTR_VALUE) {
7577 NL_SET_ERR_MSG(extack,
7578 "invalid source param");
7579 GOTO(report_err, rc = -EINVAL);
7582 rc = nla_strscpy(nidstr, top, sizeof(nidstr));
7584 NL_SET_ERR_MSG(extack,
7585 "failed to parse source nid");
7586 GOTO(report_err, rc);
7589 rc = libcfs_strnid(&plist->lgpl_src_nid,
7592 NL_SET_ERR_MSG(extack,
7593 "invalid source nid");
7594 GOTO(report_err, rc);
7599 case LN_SCALAR_ATTR_LIST:
7600 nla_for_each_nested(nids, top, rem2) {
7601 char nid[LNET_NIDSTR_SIZE + 1];
7602 struct lnet_processid *id;
7604 if (nla_type(nids) != LN_SCALAR_ATTR_VALUE)
7607 memset(nid, 0, sizeof(nid));
7608 rc = nla_strscpy(nid, nids, sizeof(nid));
7610 NL_SET_ERR_MSG(extack,
7611 "failed to get NID");
7612 GOTO(report_err, rc);
7615 id = genradix_ptr_alloc(&plist->lgpl_list,
7616 plist->lgpl_list_count++,
7619 NL_SET_ERR_MSG(extack,
7620 "failed to allocate NID");
7621 GOTO(report_err, rc = -ENOMEM);
7624 rc = libcfs_strid(id, strim(nid));
7626 NL_SET_ERR_MSG(extack, "invalid NID");
7627 GOTO(report_err, rc);
7638 lnet_ping_show_done(cb);
7643 static const struct ln_key_list ping_props_list = {
7644 .lkl_maxattr = LNET_PING_ATTR_MAX,
7646 [LNET_PING_ATTR_HDR] = {
7647 .lkp_value = "ping",
7648 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
7649 .lkp_data_type = NLA_NUL_STRING,
7651 [LNET_PING_ATTR_PRIMARY_NID] = {
7652 .lkp_value = "primary nid",
7653 .lkp_data_type = NLA_STRING
7655 [LNET_PING_ATTR_ERRNO] = {
7656 .lkp_value = "errno",
7657 .lkp_data_type = NLA_S16
7659 [LNET_PING_ATTR_MULTIRAIL] = {
7660 .lkp_value = "Multi-Rail",
7661 .lkp_data_type = NLA_FLAG
7663 [LNET_PING_ATTR_PEER_NI_LIST] = {
7664 .lkp_value = "peer_ni",
7665 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
7666 .lkp_data_type = NLA_NESTED
7671 static struct ln_key_list ping_peer_ni_list = {
7672 .lkl_maxattr = LNET_PING_PEER_NI_ATTR_MAX,
7674 [LNET_PING_PEER_NI_ATTR_NID] = {
7676 .lkp_data_type = NLA_STRING
7681 static int lnet_ping_show_dump(struct sk_buff *msg,
7682 struct netlink_callback *cb)
7684 struct lnet_genl_ping_list *plist = lnet_ping_dump_ctx(cb);
7685 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
7686 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
7687 struct netlink_ext_ack *extack = NULL;
7689 int portid = NETLINK_CB(cb->skb).portid;
7690 int seq = cb->nlh->nlmsg_seq;
7691 int idx = plist->lgpl_index;
7694 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
7695 extack = cb->extack;
7697 if (!plist->lgpl_index) {
7698 const struct ln_key_list *all[] = {
7699 &ping_props_list, &ping_peer_ni_list, NULL
7702 rc = lnet_genl_send_scalar_list(msg, portid, seq,
7704 NLM_F_CREATE | NLM_F_MULTI,
7705 LNET_CMD_PING, all);
7707 NL_SET_ERR_MSG(extack, "failed to send key table");
7708 GOTO(send_error, rc);
7711 genradix_init(&plist->lgpl_failed);
7714 while (idx < plist->lgpl_list_count) {
7715 struct lnet_nid primary_nid = LNET_ANY_NID;
7716 struct lnet_genl_ping_list peers;
7717 struct lnet_processid *id;
7718 struct nlattr *nid_list;
7719 struct lnet_peer *lp;
7720 bool mr_flag = false;
7724 id = genradix_ptr(&plist->lgpl_list, idx++);
7725 if (nid_is_lo0(&id->nid))
7728 rc = lnet_ping(id, &plist->lgpl_src_nid, plist->lgpl_timeout,
7729 &peers, lnet_interfaces_max);
7731 struct lnet_fail_ping *fail;
7733 fail = genradix_ptr_alloc(&plist->lgpl_failed,
7734 plist->lgpl_failed_count++,
7737 NL_SET_ERR_MSG(extack,
7738 "failed to allocate failed NID");
7739 GOTO(send_error, rc);
7742 fail->lfp_errno = rc;
7746 mutex_lock(&the_lnet.ln_api_mutex);
7747 lp = lnet_find_peer(&id->nid);
7749 primary_nid = lp->lp_primary_nid;
7750 mr_flag = lnet_peer_is_multi_rail(lp);
7751 lnet_peer_decref_locked(lp);
7753 mutex_unlock(&the_lnet.ln_api_mutex);
7755 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
7756 NLM_F_MULTI, LNET_CMD_PING);
7758 NL_SET_ERR_MSG(extack, "failed to send values");
7759 genlmsg_cancel(msg, hdr);
7760 GOTO(send_error, rc = -EMSGSIZE);
7764 nla_put_string(msg, LNET_PING_ATTR_HDR, "");
7766 nla_put_string(msg, LNET_PING_ATTR_PRIMARY_NID,
7767 libcfs_nidstr(&primary_nid));
7769 nla_put_flag(msg, LNET_PING_ATTR_MULTIRAIL);
7771 nid_list = nla_nest_start(msg, LNET_PING_ATTR_PEER_NI_LIST);
7772 for (count = 0; count < rc; count++) {
7773 struct lnet_processid *result;
7774 struct nlattr *nid_attr;
7777 result = genradix_ptr(&peers.lgpl_list, count);
7778 if (nid_is_lo0(&result->nid))
7781 nid_attr = nla_nest_start(msg, count + 1);
7782 if (gnlh->version == 1)
7783 idstr = libcfs_nidstr(&result->nid);
7785 idstr = libcfs_idstr(result);
7786 nla_put_string(msg, LNET_PING_PEER_NI_ATTR_NID, idstr);
7787 nla_nest_end(msg, nid_attr);
7789 nla_nest_end(msg, nid_list);
7790 genlmsg_end(msg, hdr);
7792 genradix_free(&peers.lgpl_list);
7795 for (i = 0; i < plist->lgpl_failed_count; i++) {
7796 struct lnet_fail_ping *fail;
7799 fail = genradix_ptr(&plist->lgpl_failed, i);
7801 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
7802 NLM_F_MULTI, LNET_CMD_PING);
7804 NL_SET_ERR_MSG(extack, "failed to send failed values");
7805 genlmsg_cancel(msg, hdr);
7806 GOTO(send_error, rc = -EMSGSIZE);
7810 nla_put_string(msg, LNET_PING_ATTR_HDR, "");
7812 nla_put_string(msg, LNET_PING_ATTR_PRIMARY_NID,
7813 libcfs_nidstr(&fail->lfp_id.nid));
7814 nla_put_s16(msg, LNET_PING_ATTR_ERRNO, fail->lfp_errno);
7815 genlmsg_end(msg, hdr);
7817 rc = 0; /* don't treat it as an error */
7819 plist->lgpl_index = idx;
7821 return lnet_nl_send_error(cb->skb, portid, seq, rc);
7824 #ifndef HAVE_NETLINK_CALLBACK_START
7825 static int lnet_old_ping_show_dump(struct sk_buff *msg,
7826 struct netlink_callback *cb)
7829 int rc = lnet_ping_show_start(cb);
7835 return lnet_ping_show_dump(msg, cb);
7839 static const struct genl_multicast_group lnet_mcast_grps[] = {
7840 { .name = "ip2net", },
7842 { .name = "peer", },
7843 { .name = "route", },
7844 { .name = "ping", },
7847 static const struct genl_ops lnet_genl_ops[] = {
7849 .cmd = LNET_CMD_NETS,
7850 .flags = GENL_ADMIN_PERM,
7851 #ifdef HAVE_NETLINK_CALLBACK_START
7852 .start = lnet_net_show_start,
7853 .dumpit = lnet_net_show_dump,
7855 .dumpit = lnet_old_net_show_dump,
7857 .done = lnet_net_show_done,
7858 .doit = lnet_net_cmd,
7861 .cmd = LNET_CMD_PEERS,
7862 .flags = GENL_ADMIN_PERM,
7863 #ifdef HAVE_NETLINK_CALLBACK_START
7864 .start = lnet_peer_ni_show_start,
7865 .dumpit = lnet_peer_ni_show_dump,
7867 .dumpit = lnet_old_peer_ni_show_dump,
7869 .done = lnet_peer_ni_show_done,
7870 .doit = lnet_peer_ni_cmd,
7873 .cmd = LNET_CMD_ROUTES,
7874 .flags = GENL_ADMIN_PERM,
7875 #ifdef HAVE_NETLINK_CALLBACK_START
7876 .start = lnet_route_show_start,
7877 .dumpit = lnet_route_show_dump,
7879 .dumpit = lnet_old_route_show_dump,
7881 .done = lnet_route_show_done,
7882 .doit = lnet_route_cmd,
7885 .cmd = LNET_CMD_PING,
7886 #ifdef HAVE_NETLINK_CALLBACK_START
7887 .start = lnet_ping_show_start,
7888 .dumpit = lnet_ping_show_dump,
7890 .dumpit = lnet_old_ping_show_dump,
7892 .done = lnet_ping_show_done,
7896 static struct genl_family lnet_family = {
7897 .name = LNET_GENL_NAME,
7898 .version = LNET_GENL_VERSION,
7899 .module = THIS_MODULE,
7901 .ops = lnet_genl_ops,
7902 .n_ops = ARRAY_SIZE(lnet_genl_ops),
7903 .mcgrps = lnet_mcast_grps,
7904 .n_mcgrps = ARRAY_SIZE(lnet_mcast_grps),
7905 #ifdef GENL_FAMILY_HAS_RESV_START_OP
7906 .resv_start_op = __LNET_CMD_MAX_PLUS_ONE,
7910 void LNetDebugPeer(struct lnet_processid *id)
7912 lnet_debug_peer(&id->nid);
7914 EXPORT_SYMBOL(LNetDebugPeer);
7917 * Determine if the specified peer \a nid is on the local node.
7919 * \param nid peer nid to check
7921 * \retval true If peer NID is on the local node.
7922 * \retval false If peer NID is not on the local node.
7924 bool LNetIsPeerLocal(struct lnet_nid *nid)
7926 struct lnet_net *net;
7930 cpt = lnet_net_lock_current();
7931 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
7932 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
7933 if (nid_same(&ni->ni_nid, nid)) {
7934 lnet_net_unlock(cpt);
7939 lnet_net_unlock(cpt);
7943 EXPORT_SYMBOL(LNetIsPeerLocal);
7946 * Retrieve the struct lnet_process_id ID of LNet interface at \a index.
7947 * Note that all interfaces share a same PID, as requested by LNetNIInit().
7949 * @index Index of the interface to look up.
7950 * @id On successful return, this location will hold the
7951 * struct lnet_process_id ID of the interface.
7952 * @large_nids Report large NIDs if this is true.
7954 * RETURN 0 If an interface exists at \a index.
7955 * -ENOENT If no interface has been found.
7958 LNetGetId(unsigned int index, struct lnet_processid *id, bool large_nids)
7961 struct lnet_net *net;
7965 LASSERT(the_lnet.ln_refcount > 0);
7967 cpt = lnet_net_lock_current();
7969 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
7970 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
7971 if (!large_nids && !nid_is_nid4(&ni->ni_nid))
7977 id->nid = ni->ni_nid;
7978 id->pid = the_lnet.ln_pid;
7984 lnet_net_unlock(cpt);
7987 EXPORT_SYMBOL(LNetGetId);
7993 struct lnet_handle_md mdh;
7994 struct completion completion;
7998 lnet_ping_event_handler(struct lnet_event *event)
8000 struct ping_data *pd = event->md_user_ptr;
8002 CDEBUG(D_NET, "ping event (%d %d)%s\n",
8003 event->type, event->status,
8004 event->unlinked ? " unlinked" : "");
8006 if (event->status) {
8008 pd->rc = event->status;
8009 } else if (event->type == LNET_EVENT_REPLY) {
8011 pd->rc = event->mlength;
8014 if (event->unlinked)
8015 pd->pd_unlinked = 1;
8017 if (event->unlinked ||
8018 (event->type == LNET_EVENT_SEND && event->status))
8019 complete(&pd->completion);
8022 static int lnet_ping(struct lnet_processid *id, struct lnet_nid *src_nid,
8023 signed long timeout, struct lnet_genl_ping_list *plist,
8026 int id_bytes = sizeof(struct lnet_ni_status); /* For 0@lo */
8027 struct lnet_md md = { NULL };
8028 struct ping_data pd = { 0 };
8029 struct lnet_ping_buffer *pbuf;
8030 struct lnet_processid pid;
8031 struct lnet_ping_iter pi;
8038 genradix_init(&plist->lgpl_list);
8040 /* n_ids limit is arbitrary */
8041 if (n_ids <= 0 || LNET_NID_IS_ANY(&id->nid))
8044 /* if the user buffer has more space than the lnet_interfaces_max
8045 * then only fill it up to lnet_interfaces_max
8047 if (n_ids > lnet_interfaces_max)
8048 n_ids = lnet_interfaces_max;
8050 if (id->pid == LNET_PID_ANY)
8051 id->pid = LNET_PID_LUSTRE;
8053 id_bytes += lnet_ping_sts_size(&id->nid) * n_ids;
8054 pbuf = lnet_ping_buffer_alloc(id_bytes, GFP_NOFS);
8058 /* initialize md content */
8059 md.start = &pbuf->pb_info;
8060 md.length = id_bytes;
8061 md.threshold = 2; /* GET/REPLY */
8063 md.options = LNET_MD_TRUNCATE;
8065 md.handler = lnet_ping_event_handler;
8067 init_completion(&pd.completion);
8069 rc = LNetMDBind(&md, LNET_UNLINK, &pd.mdh);
8071 CERROR("Can't bind MD: %d\n", rc);
8072 goto fail_ping_buffer_decref;
8075 rc = LNetGet(src_nid, pd.mdh, id, LNET_RESERVED_PORTAL,
8076 LNET_PROTO_PING_MATCHBITS, 0, false);
8078 /* Don't CERROR; this could be deliberate! */
8079 rc2 = LNetMDUnlink(pd.mdh);
8082 /* NB must wait for the UNLINK event below... */
8085 /* Ensure completion in finite time... */
8086 wait_for_completion_timeout(&pd.completion, timeout);
8087 if (!pd.pd_unlinked) {
8088 LNetMDUnlink(pd.mdh);
8089 wait_for_completion(&pd.completion);
8094 goto fail_ping_buffer_decref;
8098 LASSERT(nob >= 0 && nob <= id_bytes);
8100 rc = -EPROTO; /* if I can't parse... */
8102 if (nob < LNET_PING_INFO_HDR_SIZE) {
8103 CERROR("%s: ping info too short %d\n",
8104 libcfs_idstr(id), nob);
8105 goto fail_ping_buffer_decref;
8108 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) {
8109 lnet_swap_pinginfo(pbuf);
8110 } else if (pbuf->pb_info.pi_magic != LNET_PROTO_PING_MAGIC) {
8111 CERROR("%s: Unexpected magic %08x\n",
8112 libcfs_idstr(id), pbuf->pb_info.pi_magic);
8113 goto fail_ping_buffer_decref;
8116 if ((pbuf->pb_info.pi_features & LNET_PING_FEAT_NI_STATUS) == 0) {
8117 CERROR("%s: ping w/o NI status: 0x%x\n",
8118 libcfs_idstr(id), pbuf->pb_info.pi_features);
8119 goto fail_ping_buffer_decref;
8122 /* Test if smaller than lnet_pinginfo with just one pi_ni status info.
8123 * That one might contain size when large nids are used.
8125 if (nob < offsetof(struct lnet_ping_info, pi_ni[1])) {
8126 CERROR("%s: Short reply %d(%lu min)\n",
8127 libcfs_idstr(id), nob,
8128 offsetof(struct lnet_ping_info, pi_ni[1]));
8129 goto fail_ping_buffer_decref;
8132 if (ping_info_count_entries(pbuf) < n_ids) {
8133 n_ids = ping_info_count_entries(pbuf);
8134 id_bytes = lnet_ping_info_size(&pbuf->pb_info);
8137 if (nob < id_bytes) {
8138 CERROR("%s: Short reply %d(%d expected)\n",
8139 libcfs_idstr(id), nob, id_bytes);
8140 goto fail_ping_buffer_decref;
8143 for (st = ping_iter_first(&pi, pbuf, &pid.nid);
8145 st = ping_iter_next(&pi, &pid.nid)) {
8146 id = genradix_ptr_alloc(&plist->lgpl_list, i++, GFP_ATOMIC);
8149 goto fail_ping_buffer_decref;
8152 id->pid = pbuf->pb_info.pi_pid;
8156 fail_ping_buffer_decref:
8157 lnet_ping_buffer_decref(pbuf);
8162 lnet_discover(struct lnet_process_id id4, __u32 force,
8163 struct lnet_process_id __user *ids, int n_ids)
8165 struct lnet_peer_ni *lpni;
8166 struct lnet_peer_ni *p;
8167 struct lnet_peer *lp;
8168 struct lnet_process_id *buf;
8169 struct lnet_processid id;
8175 id4.nid == LNET_NID_ANY)
8178 lnet_pid4_to_pid(id4, &id);
8179 if (id.pid == LNET_PID_ANY)
8180 id.pid = LNET_PID_LUSTRE;
8183 * If the user buffer has more space than the lnet_interfaces_max,
8184 * then only fill it up to lnet_interfaces_max.
8186 if (n_ids > lnet_interfaces_max)
8187 n_ids = lnet_interfaces_max;
8189 CFS_ALLOC_PTR_ARRAY(buf, n_ids);
8193 cpt = lnet_net_lock_current();
8194 lpni = lnet_peerni_by_nid_locked(&id.nid, NULL, cpt);
8201 * Clearing the NIDS_UPTODATE flag ensures the peer will
8202 * be discovered, provided discovery has not been disabled.
8204 lp = lpni->lpni_peer_net->lpn_peer;
8205 spin_lock(&lp->lp_lock);
8206 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
8207 /* If the force flag is set, force a PING and PUSH as well. */
8209 lp->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH;
8210 spin_unlock(&lp->lp_lock);
8211 rc = lnet_discover_peer_locked(lpni, cpt, true);
8215 /* The lpni (or lp) for this NID may have changed and our ref is
8216 * the only thing keeping the old one around. Release the ref
8217 * and lookup the lpni again
8219 lnet_peer_ni_decref_locked(lpni);
8220 lpni = lnet_peer_ni_find_locked(&id.nid);
8225 lp = lpni->lpni_peer_net->lpn_peer;
8229 while ((p = lnet_get_next_peer_ni_locked(lp, NULL, p)) != NULL) {
8230 buf[i].pid = id.pid;
8231 buf[i].nid = lnet_nid_to_nid4(&p->lpni_nid);
8238 lnet_peer_ni_decref_locked(lpni);
8240 lnet_net_unlock(cpt);
8243 if (copy_to_user(ids, buf, rc * sizeof(*buf)))
8245 CFS_FREE_PTR_ARRAY(buf, n_ids);
8251 * Retrieve peer discovery status.
8253 * \retval 1 if lnet_peer_discovery_disabled is 0
8254 * \retval 0 if lnet_peer_discovery_disabled is 1
8257 LNetGetPeerDiscoveryStatus(void)
8259 return !lnet_peer_discovery_disabled;
8261 EXPORT_SYMBOL(LNetGetPeerDiscoveryStatus);