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;
300 struct lnet_genl_ping_list {
301 unsigned int lgpl_index;
302 unsigned int lgpl_list_count;
303 unsigned int lgpl_failed_count;
304 signed long lgpl_timeout;
305 struct lnet_nid lgpl_src_nid;
306 GENRADIX(struct lnet_fail_ping) lgpl_failed;
307 GENRADIX(struct lnet_processid) lgpl_list;
310 static int lnet_ping(struct lnet_processid *id, struct lnet_nid *src_nid,
311 signed long timeout, struct lnet_genl_ping_list *plist,
314 static int lnet_discover(struct lnet_processid *id, u32 force,
315 struct lnet_genl_ping_list *dlists);
318 sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
321 unsigned *sensitivity = (unsigned *)kp->arg;
324 rc = kstrtoul(val, 0, &value);
326 CERROR("Invalid module parameter value for 'lnet_health_sensitivity'\n");
331 * The purpose of locking the api_mutex here is to ensure that
332 * the correct value ends up stored properly.
334 mutex_lock(&the_lnet.ln_api_mutex);
336 if (value > LNET_MAX_HEALTH_VALUE) {
337 mutex_unlock(&the_lnet.ln_api_mutex);
338 CERROR("Invalid health value. Maximum: %d value = %lu\n",
339 LNET_MAX_HEALTH_VALUE, value);
343 if (*sensitivity != 0 && value == 0 && lnet_retry_count != 0) {
344 lnet_retry_count = 0;
345 lnet_set_lnd_timeout();
348 *sensitivity = value;
350 mutex_unlock(&the_lnet.ln_api_mutex);
356 recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp)
358 CWARN("'lnet_recovery_interval' has been deprecated\n");
364 max_recovery_ping_interval_set(const char *val, cfs_kernel_param_arg_t *kp)
369 rc = kstrtoul(val, 0, &value);
371 CERROR("Invalid module parameter value for 'lnet_max_recovery_ping_interval'\n");
376 CERROR("Invalid max ping timeout. Must be strictly positive\n");
380 /* The purpose of locking the api_mutex here is to ensure that
381 * the correct value ends up stored properly.
383 mutex_lock(&the_lnet.ln_api_mutex);
384 lnet_max_recovery_ping_interval = value;
385 lnet_max_recovery_ping_count = 0;
388 lnet_max_recovery_ping_count++;
391 mutex_unlock(&the_lnet.ln_api_mutex);
397 discovery_set(const char *val, cfs_kernel_param_arg_t *kp)
400 unsigned *discovery_off = (unsigned *)kp->arg;
402 struct lnet_ping_buffer *pbuf;
404 rc = kstrtoul(val, 0, &value);
406 CERROR("Invalid module parameter value for 'lnet_peer_discovery_disabled'\n");
410 value = (value) ? 1 : 0;
413 * The purpose of locking the api_mutex here is to ensure that
414 * the correct value ends up stored properly.
416 mutex_lock(&the_lnet.ln_api_mutex);
418 if (value == *discovery_off) {
419 mutex_unlock(&the_lnet.ln_api_mutex);
424 * We still want to set the discovery value even when LNet is not
425 * running. This is the case when LNet is being loaded and we want
426 * the module parameters to take effect. Otherwise if we're
427 * changing the value dynamically, we want to set it after
430 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
431 *discovery_off = value;
432 mutex_unlock(&the_lnet.ln_api_mutex);
436 /* tell peers that discovery setting has changed */
437 lnet_net_lock(LNET_LOCK_EX);
438 pbuf = the_lnet.ln_ping_target;
440 pbuf->pb_info.pi_features &= ~LNET_PING_FEAT_DISCOVERY;
442 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
443 lnet_net_unlock(LNET_LOCK_EX);
445 /* only send a push when we're turning off discovery */
446 if (*discovery_off <= 0 && value > 0)
447 lnet_push_update_to_peers(1);
448 *discovery_off = value;
450 mutex_unlock(&the_lnet.ln_api_mutex);
456 drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp)
459 unsigned int *drop_asym_route = (unsigned int *)kp->arg;
462 rc = kstrtoul(val, 0, &value);
464 CERROR("Invalid module parameter value for "
465 "'lnet_drop_asym_route'\n");
470 * The purpose of locking the api_mutex here is to ensure that
471 * the correct value ends up stored properly.
473 mutex_lock(&the_lnet.ln_api_mutex);
475 if (value == *drop_asym_route) {
476 mutex_unlock(&the_lnet.ln_api_mutex);
480 *drop_asym_route = value;
482 mutex_unlock(&the_lnet.ln_api_mutex);
488 transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp)
491 unsigned *transaction_to = (unsigned *)kp->arg;
494 rc = kstrtoul(val, 0, &value);
496 CERROR("Invalid module parameter value for 'lnet_transaction_timeout'\n");
501 * The purpose of locking the api_mutex here is to ensure that
502 * the correct value ends up stored properly.
504 mutex_lock(&the_lnet.ln_api_mutex);
506 if (value <= lnet_retry_count || value == 0) {
507 mutex_unlock(&the_lnet.ln_api_mutex);
508 CERROR("Invalid value for lnet_transaction_timeout (%lu). "
509 "Has to be greater than lnet_retry_count (%u)\n",
510 value, lnet_retry_count);
514 if (value == *transaction_to) {
515 mutex_unlock(&the_lnet.ln_api_mutex);
519 *transaction_to = value;
520 /* Update the lnet_lnd_timeout now that we've modified the
521 * transaction timeout
523 lnet_set_lnd_timeout();
525 mutex_unlock(&the_lnet.ln_api_mutex);
531 retry_count_set(const char *val, cfs_kernel_param_arg_t *kp)
534 unsigned *retry_count = (unsigned *)kp->arg;
537 rc = kstrtoul(val, 0, &value);
539 CERROR("Invalid module parameter value for 'lnet_retry_count'\n");
544 * The purpose of locking the api_mutex here is to ensure that
545 * the correct value ends up stored properly.
547 mutex_lock(&the_lnet.ln_api_mutex);
549 if (lnet_health_sensitivity == 0 && value > 0) {
550 mutex_unlock(&the_lnet.ln_api_mutex);
551 CERROR("Can not set lnet_retry_count when health feature is turned off\n");
555 if (value > lnet_transaction_timeout) {
556 mutex_unlock(&the_lnet.ln_api_mutex);
557 CERROR("Invalid value for lnet_retry_count (%lu). "
558 "Has to be smaller than lnet_transaction_timeout (%u)\n",
559 value, lnet_transaction_timeout);
563 *retry_count = value;
565 /* Update the lnet_lnd_timeout now that we've modified the
568 lnet_set_lnd_timeout();
570 mutex_unlock(&the_lnet.ln_api_mutex);
576 intf_max_set(const char *val, cfs_kernel_param_arg_t *kp)
580 rc = kstrtoint(val, 0, &value);
582 CERROR("Invalid module parameter value for 'lnet_interfaces_max'\n");
586 if (value < LNET_INTERFACES_MIN) {
587 CWARN("max interfaces provided are too small, setting to %d\n",
588 LNET_INTERFACES_MAX_DEFAULT);
589 value = LNET_INTERFACES_MAX_DEFAULT;
592 *(int *)kp->arg = value;
598 response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp)
601 unsigned long new_value;
603 rc = kstrtoul(val, 0, &new_value);
605 CERROR("Invalid value for 'lnet_response_tracking'\n");
609 if (new_value < 0 || new_value > 3) {
610 CWARN("Invalid value (%lu) for 'lnet_response_tracking'\n",
615 lnet_response_tracking = new_value;
621 lnet_get_routes(void)
627 lnet_get_networks(void)
632 if (*networks != 0 && *ip2nets != 0) {
633 LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
634 "'ip2nets' but not both at once\n");
639 rc = lnet_parse_ip2nets(&nets, ip2nets);
640 return (rc == 0) ? nets : NULL;
650 lnet_init_locks(void)
652 spin_lock_init(&the_lnet.ln_eq_wait_lock);
653 spin_lock_init(&the_lnet.ln_msg_resend_lock);
654 init_completion(&the_lnet.ln_mt_wait_complete);
655 mutex_init(&the_lnet.ln_lnd_mutex);
658 struct kmem_cache *lnet_mes_cachep; /* MEs kmem_cache */
659 struct kmem_cache *lnet_small_mds_cachep; /* <= LNET_SMALL_MD_SIZE bytes
661 struct kmem_cache *lnet_udsp_cachep; /* udsp cache */
662 struct kmem_cache *lnet_rspt_cachep; /* response tracker cache */
663 struct kmem_cache *lnet_msg_cachep;
666 lnet_slab_setup(void)
668 /* create specific kmem_cache for MEs and small MDs (i.e., originally
669 * allocated in <size-xxx> kmem_cache).
671 lnet_mes_cachep = kmem_cache_create("lnet_MEs", sizeof(struct lnet_me),
673 if (!lnet_mes_cachep)
676 lnet_small_mds_cachep = kmem_cache_create("lnet_small_MDs",
677 LNET_SMALL_MD_SIZE, 0, 0,
679 if (!lnet_small_mds_cachep)
682 lnet_udsp_cachep = kmem_cache_create("lnet_udsp",
683 sizeof(struct lnet_udsp),
685 if (!lnet_udsp_cachep)
688 lnet_rspt_cachep = kmem_cache_create("lnet_rspt", sizeof(struct lnet_rsp_tracker),
690 if (!lnet_rspt_cachep)
693 lnet_msg_cachep = kmem_cache_create("lnet_msg", sizeof(struct lnet_msg),
695 if (!lnet_msg_cachep)
702 lnet_slab_cleanup(void)
704 if (lnet_msg_cachep) {
705 kmem_cache_destroy(lnet_msg_cachep);
706 lnet_msg_cachep = NULL;
709 if (lnet_rspt_cachep) {
710 kmem_cache_destroy(lnet_rspt_cachep);
711 lnet_rspt_cachep = NULL;
714 if (lnet_udsp_cachep) {
715 kmem_cache_destroy(lnet_udsp_cachep);
716 lnet_udsp_cachep = NULL;
719 if (lnet_small_mds_cachep) {
720 kmem_cache_destroy(lnet_small_mds_cachep);
721 lnet_small_mds_cachep = NULL;
724 if (lnet_mes_cachep) {
725 kmem_cache_destroy(lnet_mes_cachep);
726 lnet_mes_cachep = NULL;
731 lnet_create_remote_nets_table(void)
734 struct list_head *hash;
736 LASSERT(the_lnet.ln_remote_nets_hash == NULL);
737 LASSERT(the_lnet.ln_remote_nets_hbits > 0);
738 CFS_ALLOC_PTR_ARRAY(hash, LNET_REMOTE_NETS_HASH_SIZE);
740 CERROR("Failed to create remote nets hash table\n");
744 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
745 INIT_LIST_HEAD(&hash[i]);
746 the_lnet.ln_remote_nets_hash = hash;
751 lnet_destroy_remote_nets_table(void)
755 if (the_lnet.ln_remote_nets_hash == NULL)
758 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
759 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
761 CFS_FREE_PTR_ARRAY(the_lnet.ln_remote_nets_hash,
762 LNET_REMOTE_NETS_HASH_SIZE);
763 the_lnet.ln_remote_nets_hash = NULL;
767 lnet_destroy_locks(void)
769 if (the_lnet.ln_res_lock != NULL) {
770 cfs_percpt_lock_free(the_lnet.ln_res_lock);
771 the_lnet.ln_res_lock = NULL;
774 if (the_lnet.ln_net_lock != NULL) {
775 cfs_percpt_lock_free(the_lnet.ln_net_lock);
776 the_lnet.ln_net_lock = NULL;
781 lnet_create_locks(void)
785 the_lnet.ln_res_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
786 if (the_lnet.ln_res_lock == NULL)
789 the_lnet.ln_net_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
790 if (the_lnet.ln_net_lock == NULL)
796 lnet_destroy_locks();
800 static void lnet_assert_wire_constants(void)
802 /* Wire protocol assertions generated by 'wirecheck'
803 * running on Linux robert.bartonsoftware.com 2.6.8-1.521
804 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux
805 * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
809 BUILD_BUG_ON(LNET_PROTO_TCP_MAGIC != 0xeebc0ded);
810 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MAJOR != 1);
811 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MINOR != 0);
812 BUILD_BUG_ON(LNET_MSG_ACK != 0);
813 BUILD_BUG_ON(LNET_MSG_PUT != 1);
814 BUILD_BUG_ON(LNET_MSG_GET != 2);
815 BUILD_BUG_ON(LNET_MSG_REPLY != 3);
816 BUILD_BUG_ON(LNET_MSG_HELLO != 4);
818 BUILD_BUG_ON((int)sizeof(lnet_nid_t) != 8);
819 BUILD_BUG_ON((int)sizeof(lnet_pid_t) != 4);
821 /* Checks for struct lnet_nid */
822 BUILD_BUG_ON((int)sizeof(struct lnet_nid) != 20);
823 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_size) != 0);
824 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_size) != 1);
825 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_type) != 1);
826 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_type) != 1);
827 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_num) != 2);
828 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_num) != 2);
829 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_addr) != 4);
830 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_addr) != 16);
832 /* Checks for struct lnet_process_id_packed */
833 BUILD_BUG_ON((int)sizeof(struct lnet_process_id_packed) != 12);
834 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, nid) != 0);
835 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->nid) != 8);
836 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, pid) != 8);
837 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->pid) != 4);
839 /* Checks for struct lnet_handle_wire */
840 BUILD_BUG_ON((int)sizeof(struct lnet_handle_wire) != 16);
841 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
842 wh_interface_cookie) != 0);
843 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_interface_cookie) != 8);
844 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
845 wh_object_cookie) != 8);
846 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_object_cookie) != 8);
848 /* Checks for struct struct lnet_magicversion */
849 BUILD_BUG_ON((int)sizeof(struct lnet_magicversion) != 8);
850 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, magic) != 0);
851 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->magic) != 4);
852 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, version_major) != 4);
853 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_major) != 2);
854 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion,
855 version_minor) != 6);
856 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_minor) != 2);
858 /* Checks for struct _lnet_hdr_nid4 */
859 BUILD_BUG_ON((int)sizeof(struct _lnet_hdr_nid4) != 72);
860 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, dest_nid) != 0);
861 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->dest_nid) != 8);
862 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, src_nid) != 8);
863 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->src_nid) != 8);
864 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, dest_pid) != 16);
865 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->dest_pid) != 4);
866 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, src_pid) != 20);
867 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->src_pid) != 4);
868 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, type) != 24);
869 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->type) != 4);
870 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, payload_length) != 28);
871 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->payload_length) != 4);
872 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg) != 32);
873 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg) != 40);
876 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.dst_wmd) != 32);
877 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.dst_wmd) != 16);
878 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.match_bits) != 48);
879 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.match_bits) != 8);
880 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.mlength) != 56);
881 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.mlength) != 4);
884 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.ack_wmd) != 32);
885 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.ack_wmd) != 16);
886 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.match_bits) != 48);
887 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.match_bits) != 8);
888 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.hdr_data) != 56);
889 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.hdr_data) != 8);
890 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.ptl_index) != 64);
891 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.ptl_index) != 4);
892 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.offset) != 68);
893 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.offset) != 4);
896 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.return_wmd) != 32);
897 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.return_wmd) != 16);
898 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.match_bits) != 48);
899 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.match_bits) != 8);
900 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.ptl_index) != 56);
901 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.ptl_index) != 4);
902 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.src_offset) != 60);
903 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.src_offset) != 4);
904 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.sink_length) != 64);
905 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.sink_length) != 4);
908 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.reply.dst_wmd) != 32);
909 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.reply.dst_wmd) != 16);
912 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.hello.incarnation) != 32);
913 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.hello.incarnation) != 8);
914 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.hello.type) != 40);
915 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.hello.type) != 4);
917 /* Checks for struct lnet_ni_status and related constants */
918 BUILD_BUG_ON(LNET_NI_STATUS_INVALID != 0x00000000);
919 BUILD_BUG_ON(LNET_NI_STATUS_UP != 0x15aac0de);
920 BUILD_BUG_ON(LNET_NI_STATUS_DOWN != 0xdeadface);
922 /* Checks for struct lnet_ni_status */
923 BUILD_BUG_ON((int)sizeof(struct lnet_ni_status) != 16);
924 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_nid) != 0);
925 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_nid) != 8);
926 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_status) != 8);
927 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_status) != 4);
928 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_msg_size) != 12);
929 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_msg_size) != 4);
931 /* Checks for struct lnet_ni_large_status */
932 BUILD_BUG_ON((int)sizeof(struct lnet_ni_large_status) != 24);
933 BUILD_BUG_ON((int)offsetof(struct lnet_ni_large_status, ns_status) != 0);
934 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_large_status *)0)->ns_status) != 4);
935 BUILD_BUG_ON((int)offsetof(struct lnet_ni_large_status, ns_nid) != 4);
936 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_large_status *)0)->ns_nid) != 20);
938 /* Checks for struct lnet_ping_info and related constants */
939 BUILD_BUG_ON(LNET_PROTO_PING_MAGIC != 0x70696E67);
940 BUILD_BUG_ON(LNET_PING_FEAT_INVAL != 0);
941 BUILD_BUG_ON(LNET_PING_FEAT_BASE != 1);
942 BUILD_BUG_ON(LNET_PING_FEAT_NI_STATUS != 2);
943 BUILD_BUG_ON(LNET_PING_FEAT_RTE_DISABLED != 4);
944 BUILD_BUG_ON(LNET_PING_FEAT_MULTI_RAIL != 8);
945 BUILD_BUG_ON(LNET_PING_FEAT_DISCOVERY != 16);
946 BUILD_BUG_ON(LNET_PING_FEAT_LARGE_ADDR != 32);
947 BUILD_BUG_ON(LNET_PING_FEAT_PRIMARY_LARGE != 64);
948 BUILD_BUG_ON(LNET_PING_FEAT_BITS != 127);
950 /* Checks for struct lnet_ping_info */
951 BUILD_BUG_ON((int)sizeof(struct lnet_ping_info) != 16);
952 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_magic) != 0);
953 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_magic) != 4);
954 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_features) != 4);
955 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_features) != 4);
956 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_pid) != 8);
957 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_pid) != 4);
958 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_nnis) != 12);
959 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_nnis) != 4);
960 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_ni) != 16);
961 BUILD_BUG_ON(offsetof(struct lnet_ping_info, pi_ni) != sizeof(struct lnet_ping_info));
963 /* Acceptor connection request */
964 BUILD_BUG_ON(LNET_PROTO_ACCEPTOR_VERSION != 1);
966 /* Checks for struct lnet_acceptor_connreq */
967 BUILD_BUG_ON((int)sizeof(struct lnet_acceptor_connreq) != 16);
968 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_magic) != 0);
969 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_magic) != 4);
970 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_version) != 4);
971 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_version) != 4);
972 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_nid) != 8);
973 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_nid) != 8);
975 /* Checks for struct lnet_acceptor_connreq_v2 */
976 BUILD_BUG_ON((int)sizeof(struct lnet_acceptor_connreq_v2) != 28);
977 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_magic) != 0);
978 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_magic) != 4);
979 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_version) != 4);
980 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_version) != 4);
981 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_nid) != 8);
982 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_nid) != 20);
984 /* Checks for struct lnet_counters_common */
985 BUILD_BUG_ON((int)sizeof(struct lnet_counters_common) != 60);
986 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_alloc) != 0);
987 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_alloc) != 4);
988 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_max) != 4);
989 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_max) != 4);
990 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_errors) != 8);
991 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_errors) != 4);
992 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_count) != 12);
993 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_count) != 4);
994 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_count) != 16);
995 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_count) != 4);
996 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_count) != 20);
997 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_count) != 4);
998 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_count) != 24);
999 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_count) != 4);
1000 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_length) != 28);
1001 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_length) != 8);
1002 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_length) != 36);
1003 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_length) != 8);
1004 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_length) != 44);
1005 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_length) != 8);
1006 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_length) != 52);
1007 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_length) != 8);
1010 static const struct lnet_lnd *lnet_find_lnd_by_type(__u32 type)
1012 const struct lnet_lnd *lnd;
1014 /* holding lnd mutex */
1015 if (type >= NUM_LNDS)
1017 lnd = the_lnet.ln_lnds[type];
1018 LASSERT(!lnd || lnd->lnd_type == type);
1024 lnet_get_lnd_timeout(void)
1026 return lnet_lnd_timeout;
1028 EXPORT_SYMBOL(lnet_get_lnd_timeout);
1031 lnet_register_lnd(const struct lnet_lnd *lnd)
1033 mutex_lock(&the_lnet.ln_lnd_mutex);
1035 LASSERT(libcfs_isknown_lnd(lnd->lnd_type));
1036 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
1038 the_lnet.ln_lnds[lnd->lnd_type] = lnd;
1040 CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type));
1042 mutex_unlock(&the_lnet.ln_lnd_mutex);
1044 EXPORT_SYMBOL(lnet_register_lnd);
1047 lnet_unregister_lnd(const struct lnet_lnd *lnd)
1049 mutex_lock(&the_lnet.ln_lnd_mutex);
1051 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
1053 the_lnet.ln_lnds[lnd->lnd_type] = NULL;
1054 CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type));
1056 mutex_unlock(&the_lnet.ln_lnd_mutex);
1058 EXPORT_SYMBOL(lnet_unregister_lnd);
1061 lnet_counters_get_common_locked(struct lnet_counters_common *common)
1063 struct lnet_counters *ctr;
1066 /* FIXME !!! Their is no assert_lnet_net_locked() to ensure this
1067 * actually called under the protection of the lnet_net_lock.
1069 memset(common, 0, sizeof(*common));
1071 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
1072 common->lcc_msgs_max += ctr->lct_common.lcc_msgs_max;
1073 common->lcc_msgs_alloc += ctr->lct_common.lcc_msgs_alloc;
1074 common->lcc_errors += ctr->lct_common.lcc_errors;
1075 common->lcc_send_count += ctr->lct_common.lcc_send_count;
1076 common->lcc_recv_count += ctr->lct_common.lcc_recv_count;
1077 common->lcc_route_count += ctr->lct_common.lcc_route_count;
1078 common->lcc_drop_count += ctr->lct_common.lcc_drop_count;
1079 common->lcc_send_length += ctr->lct_common.lcc_send_length;
1080 common->lcc_recv_length += ctr->lct_common.lcc_recv_length;
1081 common->lcc_route_length += ctr->lct_common.lcc_route_length;
1082 common->lcc_drop_length += ctr->lct_common.lcc_drop_length;
1087 lnet_counters_get_common(struct lnet_counters_common *common)
1089 lnet_net_lock(LNET_LOCK_EX);
1090 lnet_counters_get_common_locked(common);
1091 lnet_net_unlock(LNET_LOCK_EX);
1093 EXPORT_SYMBOL(lnet_counters_get_common);
1096 lnet_counters_get(struct lnet_counters *counters)
1098 struct lnet_counters *ctr;
1099 struct lnet_counters_health *health = &counters->lct_health;
1102 memset(counters, 0, sizeof(*counters));
1104 lnet_net_lock(LNET_LOCK_EX);
1106 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1107 GOTO(out_unlock, rc = -ENODEV);
1109 lnet_counters_get_common_locked(&counters->lct_common);
1111 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
1112 health->lch_rst_alloc += ctr->lct_health.lch_rst_alloc;
1113 health->lch_resend_count += ctr->lct_health.lch_resend_count;
1114 health->lch_response_timeout_count +=
1115 ctr->lct_health.lch_response_timeout_count;
1116 health->lch_local_interrupt_count +=
1117 ctr->lct_health.lch_local_interrupt_count;
1118 health->lch_local_dropped_count +=
1119 ctr->lct_health.lch_local_dropped_count;
1120 health->lch_local_aborted_count +=
1121 ctr->lct_health.lch_local_aborted_count;
1122 health->lch_local_no_route_count +=
1123 ctr->lct_health.lch_local_no_route_count;
1124 health->lch_local_timeout_count +=
1125 ctr->lct_health.lch_local_timeout_count;
1126 health->lch_local_error_count +=
1127 ctr->lct_health.lch_local_error_count;
1128 health->lch_remote_dropped_count +=
1129 ctr->lct_health.lch_remote_dropped_count;
1130 health->lch_remote_error_count +=
1131 ctr->lct_health.lch_remote_error_count;
1132 health->lch_remote_timeout_count +=
1133 ctr->lct_health.lch_remote_timeout_count;
1134 health->lch_network_timeout_count +=
1135 ctr->lct_health.lch_network_timeout_count;
1138 lnet_net_unlock(LNET_LOCK_EX);
1141 EXPORT_SYMBOL(lnet_counters_get);
1144 lnet_counters_reset(void)
1146 struct lnet_counters *counters;
1149 lnet_net_lock(LNET_LOCK_EX);
1151 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1154 cfs_percpt_for_each(counters, i, the_lnet.ln_counters)
1155 memset(counters, 0, sizeof(struct lnet_counters));
1157 lnet_net_unlock(LNET_LOCK_EX);
1161 lnet_res_type2str(int type)
1166 case LNET_COOKIE_TYPE_MD:
1168 case LNET_COOKIE_TYPE_ME:
1170 case LNET_COOKIE_TYPE_EQ:
1176 lnet_res_container_cleanup(struct lnet_res_container *rec)
1180 if (rec->rec_type == 0) /* not set yet, it's uninitialized */
1183 while (!list_empty(&rec->rec_active)) {
1184 struct list_head *e = rec->rec_active.next;
1187 if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
1188 lnet_md_free(list_entry(e, struct lnet_libmd, md_list));
1190 } else { /* NB: Active MEs should be attached on portals */
1197 /* Found alive MD/ME/EQ, user really should unlink/free
1198 * all of them before finalize LNet, but if someone didn't,
1199 * we have to recycle garbage for him */
1200 CERROR("%d active elements on exit of %s container\n",
1201 count, lnet_res_type2str(rec->rec_type));
1204 if (rec->rec_lh_hash != NULL) {
1205 CFS_FREE_PTR_ARRAY(rec->rec_lh_hash, LNET_LH_HASH_SIZE);
1206 rec->rec_lh_hash = NULL;
1209 rec->rec_type = 0; /* mark it as finalized */
1213 lnet_res_container_setup(struct lnet_res_container *rec, int cpt, int type)
1218 LASSERT(rec->rec_type == 0);
1220 rec->rec_type = type;
1221 INIT_LIST_HEAD(&rec->rec_active);
1223 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type;
1225 /* Arbitrary choice of hash table size */
1226 LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt,
1227 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
1228 if (rec->rec_lh_hash == NULL) {
1233 for (i = 0; i < LNET_LH_HASH_SIZE; i++)
1234 INIT_LIST_HEAD(&rec->rec_lh_hash[i]);
1239 CERROR("Failed to setup %s resource container\n",
1240 lnet_res_type2str(type));
1241 lnet_res_container_cleanup(rec);
1246 lnet_res_containers_destroy(struct lnet_res_container **recs)
1248 struct lnet_res_container *rec;
1251 cfs_percpt_for_each(rec, i, recs)
1252 lnet_res_container_cleanup(rec);
1254 cfs_percpt_free(recs);
1257 static struct lnet_res_container **
1258 lnet_res_containers_create(int type)
1260 struct lnet_res_container **recs;
1261 struct lnet_res_container *rec;
1265 recs = cfs_percpt_alloc(lnet_cpt_table(), sizeof(*rec));
1267 CERROR("Failed to allocate %s resource containers\n",
1268 lnet_res_type2str(type));
1272 cfs_percpt_for_each(rec, i, recs) {
1273 rc = lnet_res_container_setup(rec, i, type);
1275 lnet_res_containers_destroy(recs);
1283 struct lnet_libhandle *
1284 lnet_res_lh_lookup(struct lnet_res_container *rec, __u64 cookie)
1286 /* ALWAYS called with lnet_res_lock held */
1287 struct list_head *head;
1288 struct lnet_libhandle *lh;
1291 if ((cookie & LNET_COOKIE_MASK) != rec->rec_type)
1294 hash = cookie >> (LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS);
1295 head = &rec->rec_lh_hash[hash & LNET_LH_HASH_MASK];
1297 list_for_each_entry(lh, head, lh_hash_chain) {
1298 if (lh->lh_cookie == cookie)
1306 lnet_res_lh_initialize(struct lnet_res_container *rec,
1307 struct lnet_libhandle *lh)
1309 /* ALWAYS called with lnet_res_lock held */
1310 unsigned int ibits = LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS;
1313 lh->lh_cookie = rec->rec_lh_cookie;
1314 rec->rec_lh_cookie += 1 << ibits;
1316 hash = (lh->lh_cookie >> ibits) & LNET_LH_HASH_MASK;
1318 list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
1322 lnet_create_array_of_queues(void)
1324 struct list_head **qs;
1325 struct list_head *q;
1328 qs = cfs_percpt_alloc(lnet_cpt_table(),
1329 sizeof(struct list_head));
1331 CERROR("Failed to allocate queues\n");
1335 cfs_percpt_for_each(q, i, qs)
1341 static int lnet_unprepare(void);
1344 lnet_prepare(lnet_pid_t requested_pid)
1346 /* Prepare to bring up the network */
1347 struct lnet_res_container **recs;
1350 if (requested_pid == LNET_PID_ANY) {
1351 /* Don't instantiate LNET just for me */
1355 LASSERT(the_lnet.ln_refcount == 0);
1357 the_lnet.ln_routing = 0;
1359 LASSERT((requested_pid & LNET_PID_USERFLAG) == 0);
1360 the_lnet.ln_pid = requested_pid;
1362 INIT_LIST_HEAD(&the_lnet.ln_test_peers);
1363 INIT_LIST_HEAD(&the_lnet.ln_remote_peer_ni_list);
1364 INIT_LIST_HEAD(&the_lnet.ln_nets);
1365 INIT_LIST_HEAD(&the_lnet.ln_routers);
1366 INIT_LIST_HEAD(&the_lnet.ln_drop_rules);
1367 INIT_LIST_HEAD(&the_lnet.ln_delay_rules);
1368 INIT_LIST_HEAD(&the_lnet.ln_dc_request);
1369 INIT_LIST_HEAD(&the_lnet.ln_dc_working);
1370 INIT_LIST_HEAD(&the_lnet.ln_dc_expired);
1371 INIT_LIST_HEAD(&the_lnet.ln_mt_localNIRecovq);
1372 INIT_LIST_HEAD(&the_lnet.ln_mt_peerNIRecovq);
1373 INIT_LIST_HEAD(&the_lnet.ln_udsp_list);
1374 init_waitqueue_head(&the_lnet.ln_dc_waitq);
1375 the_lnet.ln_mt_handler = NULL;
1376 init_completion(&the_lnet.ln_started);
1377 atomic_set(&the_lnet.ln_late_msg_count, 0);
1378 atomic64_set(&the_lnet.ln_late_msg_nsecs, 0);
1380 rc = lnet_slab_setup();
1384 rc = lnet_create_remote_nets_table();
1389 * NB the interface cookie in wire handles guards against delayed
1390 * replies and ACKs appearing valid after reboot.
1392 the_lnet.ln_interface_cookie = ktime_get_real_ns();
1394 the_lnet.ln_counters = cfs_percpt_alloc(lnet_cpt_table(),
1395 sizeof(struct lnet_counters));
1396 if (the_lnet.ln_counters == NULL) {
1397 CERROR("Failed to allocate counters for LNet\n");
1402 rc = lnet_peer_tables_create();
1406 rc = lnet_msg_containers_create();
1410 rc = lnet_res_container_setup(&the_lnet.ln_eq_container, 0,
1411 LNET_COOKIE_TYPE_EQ);
1415 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD);
1421 the_lnet.ln_md_containers = recs;
1423 rc = lnet_portals_create();
1425 CERROR("Failed to create portals for LNet: %d\n", rc);
1429 the_lnet.ln_mt_zombie_rstqs = lnet_create_array_of_queues();
1430 if (!the_lnet.ln_mt_zombie_rstqs) {
1443 lnet_unprepare(void)
1445 /* NB no LNET_LOCK since this is the last reference. All LND instances
1446 * have shut down already, so it is safe to unlink and free all
1447 * descriptors, even those that appear committed to a network op (eg MD
1448 * with non-zero pending count) */
1450 lnet_fail_nid(LNET_NID_ANY, 0);
1452 LASSERT(the_lnet.ln_refcount == 0);
1453 LASSERT(list_empty(&the_lnet.ln_test_peers));
1454 LASSERT(list_empty(&the_lnet.ln_nets));
1456 if (the_lnet.ln_mt_zombie_rstqs) {
1457 lnet_clean_zombie_rstqs();
1458 the_lnet.ln_mt_zombie_rstqs = NULL;
1461 lnet_assert_handler_unused(the_lnet.ln_mt_handler);
1462 the_lnet.ln_mt_handler = NULL;
1464 lnet_portals_destroy();
1466 if (the_lnet.ln_md_containers != NULL) {
1467 lnet_res_containers_destroy(the_lnet.ln_md_containers);
1468 the_lnet.ln_md_containers = NULL;
1471 lnet_res_container_cleanup(&the_lnet.ln_eq_container);
1473 lnet_msg_containers_destroy();
1475 lnet_rtrpools_free(0);
1477 if (the_lnet.ln_counters != NULL) {
1478 cfs_percpt_free(the_lnet.ln_counters);
1479 the_lnet.ln_counters = NULL;
1481 lnet_destroy_remote_nets_table();
1482 lnet_udsp_destroy(true);
1483 lnet_slab_cleanup();
1489 lnet_net2ni_locked(__u32 net_id, int cpt)
1492 struct lnet_net *net;
1494 LASSERT(cpt != LNET_LOCK_EX);
1496 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1497 if (net->net_id == net_id) {
1498 ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
1508 lnet_net2ni_addref(__u32 net)
1513 ni = lnet_net2ni_locked(net, 0);
1515 lnet_ni_addref_locked(ni, 0);
1520 EXPORT_SYMBOL(lnet_net2ni_addref);
1523 lnet_get_net_locked(__u32 net_id)
1525 struct lnet_net *net;
1527 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1528 if (net->net_id == net_id)
1536 lnet_net_clr_pref_rtrs(struct lnet_net *net)
1538 struct list_head zombies;
1539 struct lnet_nid_list *ne;
1540 struct lnet_nid_list *tmp;
1542 INIT_LIST_HEAD(&zombies);
1544 lnet_net_lock(LNET_LOCK_EX);
1545 list_splice_init(&net->net_rtr_pref_nids, &zombies);
1546 lnet_net_unlock(LNET_LOCK_EX);
1548 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1549 list_del_init(&ne->nl_list);
1550 LIBCFS_FREE(ne, sizeof(*ne));
1555 lnet_net_add_pref_rtr(struct lnet_net *net,
1556 struct lnet_nid *gw_nid)
1557 __must_hold(&the_lnet.ln_api_mutex)
1559 struct lnet_nid_list *ne;
1561 /* This function is called with api_mutex held. When the api_mutex
1562 * is held the list can not be modified, as it is only modified as
1563 * a result of applying a UDSP and that happens under api_mutex
1566 list_for_each_entry(ne, &net->net_rtr_pref_nids, nl_list) {
1567 if (nid_same(&ne->nl_nid, gw_nid))
1571 LIBCFS_ALLOC(ne, sizeof(*ne));
1575 ne->nl_nid = *gw_nid;
1577 /* Lock the cpt to protect against addition and checks in the
1578 * selection algorithm
1580 lnet_net_lock(LNET_LOCK_EX);
1581 list_add(&ne->nl_list, &net->net_rtr_pref_nids);
1582 lnet_net_unlock(LNET_LOCK_EX);
1588 lnet_nid4_cpt_hash(lnet_nid_t nid, unsigned int number)
1591 __u16 lnd = LNET_NETTYP(LNET_NIDNET(nid));
1594 if (lnd == KFILND || lnd == GNILND) {
1595 cpt = hash_long(key, LNET_CPT_BITS);
1597 /* NB: The number of CPTs needn't be a power of 2 */
1599 cpt = (key + cpt + (cpt >> 1)) % number;
1601 __u64 pair_bits = 0x0001000100010001LLU;
1602 __u64 mask = pair_bits * 0xFF;
1604 /* For ipv4 NIDs, use (sum-by-multiplication of nid bytes) mod
1605 * (number of CPTs) to match nid to a CPT.
1607 pair_sum = (key & mask) + ((key >> 8) & mask);
1608 pair_sum = (pair_sum * pair_bits) >> 48;
1609 cpt = (unsigned int)(pair_sum) % number;
1612 CDEBUG(D_NET, "Match nid %s to cpt %u\n",
1613 libcfs_nid2str(nid), cpt);
1619 lnet_nid_cpt_hash(struct lnet_nid *nid, unsigned int number)
1625 LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
1630 if (nid_is_nid4(nid))
1631 return lnet_nid4_cpt_hash(lnet_nid_to_nid4(nid), number);
1633 for (i = 0; i < 4; i++)
1634 h = cfs_hash_32(nid->nid_addr[i]^h, 32);
1635 val = cfs_hash_32(LNET_NID_NET(nid) ^ h, LNET_CPT_BITS);
1638 return (unsigned int)(h + val + (val >> 1)) % number;
1642 lnet_cpt_of_nid_locked(struct lnet_nid *nid, struct lnet_ni *ni)
1644 struct lnet_net *net;
1646 /* must called with hold of lnet_net_lock */
1647 if (LNET_CPT_NUMBER == 1)
1648 return 0; /* the only one */
1651 * If NI is provided then use the CPT identified in the NI cpt
1652 * list if one exists. If one doesn't exist, then that NI is
1653 * associated with all CPTs and it follows that the net it belongs
1654 * to is implicitly associated with all CPTs, so just hash the nid
1658 if (ni->ni_cpts != NULL)
1659 return ni->ni_cpts[lnet_nid_cpt_hash(nid,
1662 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1665 /* no NI provided so look at the net */
1666 net = lnet_get_net_locked(LNET_NID_NET(nid));
1668 if (net != NULL && net->net_cpts != NULL) {
1669 return net->net_cpts[lnet_nid_cpt_hash(nid, net->net_ncpts)];
1672 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1676 lnet_nid2cpt(struct lnet_nid *nid, struct lnet_ni *ni)
1681 if (LNET_CPT_NUMBER == 1)
1682 return 0; /* the only one */
1684 cpt = lnet_net_lock_current();
1686 cpt2 = lnet_cpt_of_nid_locked(nid, ni);
1688 lnet_net_unlock(cpt);
1692 EXPORT_SYMBOL(lnet_nid2cpt);
1695 lnet_cpt_of_nid(lnet_nid_t nid4, struct lnet_ni *ni)
1697 struct lnet_nid nid;
1699 if (LNET_CPT_NUMBER == 1)
1700 return 0; /* the only one */
1702 lnet_nid4_to_nid(nid4, &nid);
1703 return lnet_nid2cpt(&nid, ni);
1705 EXPORT_SYMBOL(lnet_cpt_of_nid);
1708 lnet_islocalnet_locked(__u32 net_id)
1710 struct lnet_net *net;
1713 net = lnet_get_net_locked(net_id);
1715 local = net != NULL;
1721 lnet_islocalnet(__u32 net_id)
1726 cpt = lnet_net_lock_current();
1728 local = lnet_islocalnet_locked(net_id);
1730 lnet_net_unlock(cpt);
1736 lnet_nid_to_ni_locked(struct lnet_nid *nid, int cpt)
1738 struct lnet_net *net;
1741 LASSERT(cpt != LNET_LOCK_EX);
1743 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1744 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1745 if (nid_same(&ni->ni_nid, nid))
1754 lnet_nid_to_ni_addref(struct lnet_nid *nid)
1759 ni = lnet_nid_to_ni_locked(nid, 0);
1761 lnet_ni_addref_locked(ni, 0);
1766 EXPORT_SYMBOL(lnet_nid_to_ni_addref);
1769 lnet_islocalnid(struct lnet_nid *nid)
1774 cpt = lnet_net_lock_current();
1775 ni = lnet_nid_to_ni_locked(nid, cpt);
1776 lnet_net_unlock(cpt);
1782 lnet_count_acceptor_nets(void)
1784 /* Return the # of NIs that need the acceptor. */
1786 struct lnet_net *net;
1789 cpt = lnet_net_lock_current();
1790 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1791 /* all socklnd type networks should have the acceptor
1793 if (net->net_lnd->lnd_accept != NULL)
1797 lnet_net_unlock(cpt);
1802 struct lnet_ping_buffer *
1803 lnet_ping_buffer_alloc(int nbytes, gfp_t gfp)
1805 struct lnet_ping_buffer *pbuf;
1807 LIBCFS_ALLOC_GFP(pbuf, LNET_PING_BUFFER_SIZE(nbytes), gfp);
1809 pbuf->pb_nbytes = nbytes; /* sizeof of pb_info */
1810 pbuf->pb_needs_post = false;
1811 atomic_set(&pbuf->pb_refcnt, 1);
1818 lnet_ping_buffer_free(struct lnet_ping_buffer *pbuf)
1820 LASSERT(atomic_read(&pbuf->pb_refcnt) == 0);
1821 LIBCFS_FREE(pbuf, LNET_PING_BUFFER_SIZE(pbuf->pb_nbytes));
1824 static struct lnet_ping_buffer *
1825 lnet_ping_target_create(int nbytes)
1827 struct lnet_ping_buffer *pbuf;
1829 pbuf = lnet_ping_buffer_alloc(nbytes, GFP_NOFS);
1831 CERROR("Can't allocate ping source [%d]\n", nbytes);
1835 pbuf->pb_info.pi_nnis = 0;
1836 pbuf->pb_info.pi_pid = the_lnet.ln_pid;
1837 pbuf->pb_info.pi_magic = LNET_PROTO_PING_MAGIC;
1838 pbuf->pb_info.pi_features =
1839 LNET_PING_FEAT_NI_STATUS | LNET_PING_FEAT_MULTI_RAIL;
1845 lnet_get_net_ni_bytes_locked(struct lnet_net *net)
1850 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1851 bytes += lnet_ping_sts_size(&ni->ni_nid);
1857 lnet_get_ni_bytes(void)
1860 struct lnet_net *net;
1865 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1866 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1867 bytes += lnet_ping_sts_size(&ni->ni_nid);
1876 lnet_swap_pinginfo(struct lnet_ping_buffer *pbuf)
1878 struct lnet_ni_large_status *lstat, *lend;
1879 struct lnet_ni_status *stat, *end;
1883 __swab32s(&pbuf->pb_info.pi_magic);
1884 __swab32s(&pbuf->pb_info.pi_features);
1885 __swab32s(&pbuf->pb_info.pi_pid);
1886 __swab32s(&pbuf->pb_info.pi_nnis);
1887 nnis = pbuf->pb_info.pi_nnis;
1888 stat = &pbuf->pb_info.pi_ni[0];
1889 end = (void *)&pbuf->pb_info + pbuf->pb_nbytes;
1890 for (i = 0; i < nnis && stat + 1 <= end; i++, stat++) {
1891 __swab64s(&stat->ns_nid);
1892 __swab32s(&stat->ns_status);
1894 /* Might be total size */
1895 __swab32s(&stat->ns_msg_size);
1897 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_LARGE_ADDR))
1900 lstat = (struct lnet_ni_large_status *)stat;
1902 while (lstat + 1 <= lend) {
1903 __swab32s(&lstat->ns_status);
1904 /* struct lnet_nid never needs to be swabed */
1905 lstat = lnet_ping_sts_next(lstat);
1910 lnet_ping_info_validate(struct lnet_ping_info *pinfo)
1914 if (pinfo->pi_magic != LNET_PROTO_PING_MAGIC)
1916 if (!(pinfo->pi_features & LNET_PING_FEAT_NI_STATUS))
1918 /* Loopback is guaranteed to be present */
1919 if (pinfo->pi_nnis < 1 || pinfo->pi_nnis > lnet_interfaces_max)
1921 if (LNET_PING_INFO_LONI(pinfo) != LNET_NID_LO_0)
1927 lnet_ping_target_destroy(void)
1929 struct lnet_net *net;
1932 lnet_net_lock(LNET_LOCK_EX);
1934 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1935 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1937 ni->ni_status = NULL;
1942 lnet_ping_buffer_decref(the_lnet.ln_ping_target);
1943 the_lnet.ln_ping_target = NULL;
1945 lnet_net_unlock(LNET_LOCK_EX);
1949 lnet_ping_target_event_handler(struct lnet_event *event)
1951 struct lnet_ping_buffer *pbuf = event->md_user_ptr;
1953 if (event->unlinked)
1954 lnet_ping_buffer_decref(pbuf);
1958 lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
1959 struct lnet_handle_md *ping_mdh,
1960 int ni_bytes, bool set_eq)
1962 struct lnet_processid id = {
1963 .nid = LNET_ANY_NID,
1967 struct lnet_md md = { NULL };
1971 the_lnet.ln_ping_target_handler =
1972 lnet_ping_target_event_handler;
1974 *ppbuf = lnet_ping_target_create(ni_bytes);
1975 if (*ppbuf == NULL) {
1980 /* Ping target ME/MD */
1981 me = LNetMEAttach(LNET_RESERVED_PORTAL, &id,
1982 LNET_PROTO_PING_MATCHBITS, 0,
1983 LNET_UNLINK, LNET_INS_AFTER);
1986 CERROR("Can't create ping target ME: %d\n", rc);
1987 goto fail_decref_ping_buffer;
1990 /* initialize md content */
1991 md.start = &(*ppbuf)->pb_info;
1992 md.length = (*ppbuf)->pb_nbytes;
1993 md.threshold = LNET_MD_THRESH_INF;
1995 md.options = LNET_MD_OP_GET | LNET_MD_TRUNCATE |
1996 LNET_MD_MANAGE_REMOTE;
1997 md.handler = the_lnet.ln_ping_target_handler;
1998 md.user_ptr = *ppbuf;
2000 rc = LNetMDAttach(me, &md, LNET_RETAIN, ping_mdh);
2002 CERROR("Can't attach ping target MD: %d\n", rc);
2003 goto fail_decref_ping_buffer;
2005 lnet_ping_buffer_addref(*ppbuf);
2009 fail_decref_ping_buffer:
2010 LASSERT(atomic_read(&(*ppbuf)->pb_refcnt) == 1);
2011 lnet_ping_buffer_decref(*ppbuf);
2018 lnet_ping_md_unlink(struct lnet_ping_buffer *pbuf,
2019 struct lnet_handle_md *ping_mdh)
2021 LNetMDUnlink(*ping_mdh);
2022 LNetInvalidateMDHandle(ping_mdh);
2024 /* NB the MD could be busy; this just starts the unlink */
2025 wait_var_event_warning(&pbuf->pb_refcnt,
2026 atomic_read(&pbuf->pb_refcnt) <= 1,
2027 "Still waiting for ping data MD to unlink\n");
2031 lnet_ping_target_install_locked(struct lnet_ping_buffer *pbuf)
2034 struct lnet_net *net;
2035 struct lnet_ni_status *ns, *end;
2036 struct lnet_ni_large_status *lns, *lend;
2039 pbuf->pb_info.pi_nnis = 0;
2040 ns = &pbuf->pb_info.pi_ni[0];
2041 end = (void *)&pbuf->pb_info + pbuf->pb_nbytes;
2042 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
2043 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
2044 if (!nid_is_nid4(&ni->ni_nid)) {
2045 if (ns == &pbuf->pb_info.pi_ni[1]) {
2046 /* This is primary, and it is long */
2047 pbuf->pb_info.pi_features |=
2048 LNET_PING_FEAT_PRIMARY_LARGE;
2052 LASSERT(ns + 1 <= end);
2053 ns->ns_nid = lnet_nid_to_nid4(&ni->ni_nid);
2056 ns->ns_status = lnet_ni_get_status_locked(ni);
2057 ni->ni_status = &ns->ns_status;
2060 pbuf->pb_info.pi_nnis++;
2067 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
2068 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
2069 if (nid_is_nid4(&ni->ni_nid))
2071 LASSERT(lns + 1 <= lend);
2073 lns->ns_nid = ni->ni_nid;
2076 lns->ns_status = lnet_ni_get_status_locked(ni);
2077 ni->ni_status = &lns->ns_status;
2080 lns = lnet_ping_sts_next(lns);
2083 if ((void *)lns > (void *)ns) {
2084 /* Record total info size */
2085 pbuf->pb_info.pi_ni[0].ns_msg_size =
2086 (void *)lns - (void *)&pbuf->pb_info;
2087 pbuf->pb_info.pi_features |= LNET_PING_FEAT_LARGE_ADDR;
2090 /* We (ab)use the ns_status of the loopback interface to
2091 * transmit the sequence number. The first interface listed
2092 * must be the loopback interface.
2094 rc = lnet_ping_info_validate(&pbuf->pb_info);
2096 LCONSOLE_EMERG("Invalid ping target: %d\n", rc);
2099 LNET_PING_BUFFER_SEQNO(pbuf) =
2100 atomic_inc_return(&the_lnet.ln_ping_target_seqno);
2104 lnet_ping_target_update(struct lnet_ping_buffer *pbuf,
2105 struct lnet_handle_md ping_mdh)
2106 __must_hold(&the_lnet.ln_api_mutex)
2108 struct lnet_ping_buffer *old_pbuf = NULL;
2109 struct lnet_handle_md old_ping_md;
2111 /* switch the NIs to point to the new ping info created */
2112 lnet_net_lock(LNET_LOCK_EX);
2114 if (!the_lnet.ln_routing)
2115 pbuf->pb_info.pi_features |= LNET_PING_FEAT_RTE_DISABLED;
2116 if (!lnet_peer_discovery_disabled)
2117 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
2119 /* Ensure only known feature bits have been set. */
2120 LASSERT(pbuf->pb_info.pi_features & LNET_PING_FEAT_BITS);
2121 LASSERT(!(pbuf->pb_info.pi_features & ~LNET_PING_FEAT_BITS));
2123 lnet_ping_target_install_locked(pbuf);
2125 if (the_lnet.ln_ping_target) {
2126 old_pbuf = the_lnet.ln_ping_target;
2127 old_ping_md = the_lnet.ln_ping_target_md;
2129 the_lnet.ln_ping_target_md = ping_mdh;
2130 the_lnet.ln_ping_target = pbuf;
2132 lnet_net_unlock(LNET_LOCK_EX);
2135 /* unlink and free the old ping info.
2136 * There may be outstanding traffic on this MD, and
2137 * ln_api_mutex may be required to finalize that
2138 * traffic. Release ln_api_mutex while we wait for
2139 * refs on this ping buffer to drop
2141 mutex_unlock(&the_lnet.ln_api_mutex);
2142 lnet_ping_md_unlink(old_pbuf, &old_ping_md);
2143 mutex_lock(&the_lnet.ln_api_mutex);
2144 lnet_ping_buffer_decref(old_pbuf);
2147 lnet_push_update_to_peers(0);
2151 lnet_ping_target_fini(void)
2153 lnet_ping_md_unlink(the_lnet.ln_ping_target,
2154 &the_lnet.ln_ping_target_md);
2156 lnet_assert_handler_unused(the_lnet.ln_ping_target_handler);
2157 lnet_ping_target_destroy();
2160 /* Resize the push target. */
2161 int lnet_push_target_resize(void)
2163 struct lnet_handle_md mdh;
2164 struct lnet_handle_md old_mdh;
2165 struct lnet_ping_buffer *pbuf;
2166 struct lnet_ping_buffer *old_pbuf;
2171 nbytes = the_lnet.ln_push_target_nbytes;
2173 CDEBUG(D_NET, "Invalid nbytes %d\n", nbytes);
2177 /* NB: lnet_ping_buffer_alloc() sets pbuf refcount to 1. That ref is
2178 * dropped when we need to resize again (see "old_pbuf" below) or when
2179 * LNet is shutdown (see lnet_push_target_fini())
2181 pbuf = lnet_ping_buffer_alloc(nbytes, GFP_NOFS);
2183 CDEBUG(D_NET, "Can't allocate pbuf for nbytes %d\n", nbytes);
2187 rc = lnet_push_target_post(pbuf, &mdh);
2189 CDEBUG(D_NET, "Failed to post push target: %d\n", rc);
2190 lnet_ping_buffer_decref(pbuf);
2194 lnet_net_lock(LNET_LOCK_EX);
2195 old_pbuf = the_lnet.ln_push_target;
2196 old_mdh = the_lnet.ln_push_target_md;
2197 the_lnet.ln_push_target = pbuf;
2198 the_lnet.ln_push_target_md = mdh;
2199 lnet_net_unlock(LNET_LOCK_EX);
2202 LNetMDUnlink(old_mdh);
2203 /* Drop ref set by lnet_ping_buffer_alloc() */
2204 lnet_ping_buffer_decref(old_pbuf);
2207 /* Received another push or reply that requires a larger buffer */
2208 if (nbytes < the_lnet.ln_push_target_nbytes)
2211 CDEBUG(D_NET, "nbytes %d success\n", nbytes);
2215 int lnet_push_target_post(struct lnet_ping_buffer *pbuf,
2216 struct lnet_handle_md *mdhp)
2218 struct lnet_processid id = { LNET_ANY_NID, LNET_PID_ANY };
2219 struct lnet_md md = { NULL };
2223 me = LNetMEAttach(LNET_RESERVED_PORTAL, &id,
2224 LNET_PROTO_PING_MATCHBITS, 0,
2225 LNET_UNLINK, LNET_INS_AFTER);
2228 CERROR("Can't create push target ME: %d\n", rc);
2232 pbuf->pb_needs_post = false;
2234 /* This reference is dropped by lnet_push_target_event_handler() */
2235 lnet_ping_buffer_addref(pbuf);
2237 /* initialize md content */
2238 md.start = &pbuf->pb_info;
2239 md.length = pbuf->pb_nbytes;
2242 md.options = LNET_MD_OP_PUT | LNET_MD_TRUNCATE;
2244 md.handler = the_lnet.ln_push_target_handler;
2246 rc = LNetMDAttach(me, &md, LNET_UNLINK, mdhp);
2248 CERROR("Can't attach push MD: %d\n", rc);
2249 lnet_ping_buffer_decref(pbuf);
2250 pbuf->pb_needs_post = true;
2254 CDEBUG(D_NET, "posted push target %p\n", pbuf);
2259 static void lnet_push_target_event_handler(struct lnet_event *ev)
2261 struct lnet_ping_buffer *pbuf = ev->md_user_ptr;
2263 CDEBUG(D_NET, "type %d status %d unlinked %d\n", ev->type, ev->status,
2266 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
2267 lnet_swap_pinginfo(pbuf);
2269 if (ev->type == LNET_EVENT_UNLINK) {
2270 /* Drop ref added by lnet_push_target_post() */
2271 lnet_ping_buffer_decref(pbuf);
2275 lnet_peer_push_event(ev);
2277 /* Drop ref added by lnet_push_target_post */
2278 lnet_ping_buffer_decref(pbuf);
2281 /* Initialize the push target. */
2282 static int lnet_push_target_init(void)
2286 if (the_lnet.ln_push_target)
2289 the_lnet.ln_push_target_handler =
2290 lnet_push_target_event_handler;
2292 rc = LNetSetLazyPortal(LNET_RESERVED_PORTAL);
2295 /* Start at the required minimum, we'll enlarge if required. */
2296 the_lnet.ln_push_target_nbytes = LNET_PING_INFO_MIN_SIZE;
2298 rc = lnet_push_target_resize();
2300 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2301 the_lnet.ln_push_target_handler = NULL;
2307 /* Clean up the push target. */
2308 static void lnet_push_target_fini(void)
2310 if (!the_lnet.ln_push_target)
2313 /* Unlink and invalidate to prevent new references. */
2314 LNetMDUnlink(the_lnet.ln_push_target_md);
2315 LNetInvalidateMDHandle(&the_lnet.ln_push_target_md);
2317 /* Wait for the unlink to complete. */
2318 wait_var_event_warning(&the_lnet.ln_push_target->pb_refcnt,
2319 atomic_read(&the_lnet.ln_push_target->pb_refcnt) <= 1,
2320 "Still waiting for ping data MD to unlink\n");
2322 /* Drop ref set by lnet_ping_buffer_alloc() */
2323 lnet_ping_buffer_decref(the_lnet.ln_push_target);
2324 the_lnet.ln_push_target = NULL;
2325 the_lnet.ln_push_target_nbytes = 0;
2327 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2328 lnet_assert_handler_unused(the_lnet.ln_push_target_handler);
2329 the_lnet.ln_push_target_handler = NULL;
2333 lnet_ni_tq_credits(struct lnet_ni *ni)
2337 LASSERT(ni->ni_ncpts >= 1);
2339 if (ni->ni_ncpts == 1)
2340 return ni->ni_net->net_tunables.lct_max_tx_credits;
2342 credits = ni->ni_net->net_tunables.lct_max_tx_credits / ni->ni_ncpts;
2343 credits = max(credits, 8 * ni->ni_net->net_tunables.lct_peer_tx_credits);
2344 credits = min(credits, ni->ni_net->net_tunables.lct_max_tx_credits);
2350 lnet_ni_unlink_locked(struct lnet_ni *ni)
2352 /* move it to zombie list and nobody can find it anymore */
2353 LASSERT(!list_empty(&ni->ni_netlist));
2354 list_move(&ni->ni_netlist, &ni->ni_net->net_ni_zombie);
2355 lnet_ni_decref_locked(ni, 0);
2359 lnet_clear_zombies_nis_locked(struct lnet_net *net)
2364 struct list_head *zombie_list = &net->net_ni_zombie;
2367 * Now wait for the NIs I just nuked to show up on the zombie
2368 * list and shut them down in guaranteed thread context
2371 while ((ni = list_first_entry_or_null(zombie_list,
2373 ni_netlist)) != NULL) {
2377 list_del_init(&ni->ni_netlist);
2378 /* the ni should be in deleting state. If it's not it's
2380 LASSERT(ni->ni_state == LNET_NI_STATE_DELETING);
2381 cfs_percpt_for_each(ref, j, ni->ni_refs) {
2384 /* still busy, add it back to zombie list */
2385 list_add(&ni->ni_netlist, zombie_list);
2389 if (!list_empty(&ni->ni_netlist)) {
2390 /* Unlock mutex while waiting to allow other
2391 * threads to read the LNet state and fall through
2394 lnet_net_unlock(LNET_LOCK_EX);
2395 mutex_unlock(&the_lnet.ln_api_mutex);
2398 if ((i & (-i)) == i) {
2400 "Waiting for zombie LNI %s\n",
2401 libcfs_nidstr(&ni->ni_nid));
2403 schedule_timeout_uninterruptible(cfs_time_seconds(1));
2405 mutex_lock(&the_lnet.ln_api_mutex);
2406 lnet_net_lock(LNET_LOCK_EX);
2410 lnet_net_unlock(LNET_LOCK_EX);
2412 islo = ni->ni_net->net_lnd->lnd_type == LOLND;
2414 LASSERT(!in_interrupt());
2415 /* Holding the LND mutex makes it safe for lnd_shutdown
2416 * to call module_put(). Module unload cannot finish
2417 * until lnet_unregister_lnd() completes, and that
2418 * requires the LND mutex.
2420 mutex_unlock(&the_lnet.ln_api_mutex);
2421 mutex_lock(&the_lnet.ln_lnd_mutex);
2422 (net->net_lnd->lnd_shutdown)(ni);
2423 mutex_unlock(&the_lnet.ln_lnd_mutex);
2424 mutex_lock(&the_lnet.ln_api_mutex);
2427 CDEBUG(D_LNI, "Removed LNI %s\n",
2428 libcfs_nidstr(&ni->ni_nid));
2432 lnet_net_lock(LNET_LOCK_EX);
2436 /* shutdown down the NI and release refcount */
2438 lnet_shutdown_lndni(struct lnet_ni *ni)
2441 struct lnet_net *net = ni->ni_net;
2443 lnet_net_lock(LNET_LOCK_EX);
2445 ni->ni_state = LNET_NI_STATE_DELETING;
2447 lnet_ni_unlink_locked(ni);
2448 lnet_incr_dlc_seq();
2449 lnet_net_unlock(LNET_LOCK_EX);
2451 /* clear messages for this NI on the lazy portal */
2452 for (i = 0; i < the_lnet.ln_nportals; i++)
2453 lnet_clear_lazy_portal(ni, i, "Shutting down NI");
2455 lnet_net_lock(LNET_LOCK_EX);
2456 lnet_clear_zombies_nis_locked(net);
2457 lnet_net_unlock(LNET_LOCK_EX);
2461 lnet_shutdown_lndnet(struct lnet_net *net)
2465 lnet_net_lock(LNET_LOCK_EX);
2467 list_del_init(&net->net_list);
2469 while ((ni = list_first_entry_or_null(&net->net_ni_list,
2471 ni_netlist)) != NULL) {
2472 lnet_net_unlock(LNET_LOCK_EX);
2473 lnet_shutdown_lndni(ni);
2474 lnet_net_lock(LNET_LOCK_EX);
2477 lnet_net_unlock(LNET_LOCK_EX);
2479 /* Do peer table cleanup for this net */
2480 lnet_peer_tables_cleanup(net);
2486 lnet_shutdown_lndnets(void)
2488 struct lnet_net *net;
2490 struct lnet_msg *msg, *tmp;
2492 /* NB called holding the global mutex */
2494 /* All quiet on the API front */
2495 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING ||
2496 the_lnet.ln_state == LNET_STATE_STOPPING);
2497 LASSERT(the_lnet.ln_refcount == 0);
2499 lnet_net_lock(LNET_LOCK_EX);
2500 the_lnet.ln_state = LNET_STATE_STOPPING;
2503 * move the nets to the zombie list to avoid them being
2504 * picked up for new work. LONET is also included in the
2505 * Nets that will be moved to the zombie list
2507 list_splice_init(&the_lnet.ln_nets, &the_lnet.ln_net_zombie);
2509 /* Drop the cached loopback Net. */
2510 if (the_lnet.ln_loni != NULL) {
2511 lnet_ni_decref_locked(the_lnet.ln_loni, 0);
2512 the_lnet.ln_loni = NULL;
2514 lnet_net_unlock(LNET_LOCK_EX);
2516 /* iterate through the net zombie list and delete each net */
2517 while ((net = list_first_entry_or_null(&the_lnet.ln_net_zombie,
2520 lnet_shutdown_lndnet(net);
2522 spin_lock(&the_lnet.ln_msg_resend_lock);
2523 list_splice(&the_lnet.ln_msg_resend, &resend);
2524 spin_unlock(&the_lnet.ln_msg_resend_lock);
2526 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
2527 list_del_init(&msg->msg_list);
2528 msg->msg_no_resend = true;
2529 lnet_finalize(msg, -ECANCELED);
2532 lnet_net_lock(LNET_LOCK_EX);
2533 the_lnet.ln_state = LNET_STATE_SHUTDOWN;
2534 lnet_net_unlock(LNET_LOCK_EX);
2538 lnet_startup_lndni(struct lnet_ni *ni, struct lnet_lnd_tunables *tun)
2541 struct lnet_tx_queue *tq;
2543 struct lnet_net *net = ni->ni_net;
2545 mutex_lock(&the_lnet.ln_lnd_mutex);
2548 memcpy(&ni->ni_lnd_tunables, tun, sizeof(*tun));
2549 ni->ni_lnd_tunables_set = true;
2552 rc = (net->net_lnd->lnd_startup)(ni);
2554 mutex_unlock(&the_lnet.ln_lnd_mutex);
2557 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s\n",
2558 rc, libcfs_lnd2str(net->net_lnd->lnd_type));
2562 /* We keep a reference on the loopback net through the loopback NI */
2563 if (net->net_lnd->lnd_type == LOLND) {
2565 LASSERT(the_lnet.ln_loni == NULL);
2566 the_lnet.ln_loni = ni;
2567 ni->ni_net->net_tunables.lct_peer_tx_credits = 0;
2568 ni->ni_net->net_tunables.lct_peer_rtr_credits = 0;
2569 ni->ni_net->net_tunables.lct_max_tx_credits = 0;
2570 ni->ni_net->net_tunables.lct_peer_timeout = 0;
2574 if (ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ||
2575 ni->ni_net->net_tunables.lct_max_tx_credits == 0) {
2576 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
2577 libcfs_lnd2str(net->net_lnd->lnd_type),
2578 ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ?
2580 /* shutdown the NI since if we get here then it must've already
2583 lnet_shutdown_lndni(ni);
2587 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
2588 tq->tq_credits_min =
2589 tq->tq_credits_max =
2590 tq->tq_credits = lnet_ni_tq_credits(ni);
2593 atomic_set(&ni->ni_tx_credits,
2594 lnet_ni_tq_credits(ni) * ni->ni_ncpts);
2595 atomic_set(&ni->ni_healthv, LNET_MAX_HEALTH_VALUE);
2597 /* Nodes with small feet have little entropy. The NID for this
2598 * node gives the most entropy in the low bits.
2600 add_device_randomness(&ni->ni_nid, sizeof(ni->ni_nid));
2602 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d/%d]\n",
2603 libcfs_nidstr(&ni->ni_nid),
2604 ni->ni_net->net_tunables.lct_peer_tx_credits,
2605 lnet_ni_tq_credits(ni) * LNET_CPT_NUMBER,
2606 ni->ni_net->net_tunables.lct_peer_rtr_credits,
2607 ni->ni_net->net_tunables.lct_peer_timeout);
2615 static const struct lnet_lnd *lnet_load_lnd(u32 lnd_type)
2617 const struct lnet_lnd *lnd;
2620 mutex_lock(&the_lnet.ln_lnd_mutex);
2621 lnd = lnet_find_lnd_by_type(lnd_type);
2623 mutex_unlock(&the_lnet.ln_lnd_mutex);
2624 rc = request_module("%s", libcfs_lnd2modname(lnd_type));
2625 mutex_lock(&the_lnet.ln_lnd_mutex);
2627 lnd = lnet_find_lnd_by_type(lnd_type);
2629 mutex_unlock(&the_lnet.ln_lnd_mutex);
2630 CERROR("Can't load LND %s, module %s, rc=%d\n",
2631 libcfs_lnd2str(lnd_type),
2632 libcfs_lnd2modname(lnd_type), rc);
2633 #ifndef HAVE_MODULE_LOADING_SUPPORT
2634 LCONSOLE_ERROR_MSG(0x104,
2635 "Your kernel must be compiled with kernel module loading support.");
2637 return ERR_PTR(-EINVAL);
2640 mutex_unlock(&the_lnet.ln_lnd_mutex);
2646 lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
2649 struct lnet_net *net_l = NULL;
2650 LIST_HEAD(local_ni_list);
2654 const struct lnet_lnd *lnd;
2656 net->net_tunables.lct_peer_timeout;
2658 net->net_tunables.lct_max_tx_credits;
2659 int peerrtrcredits =
2660 net->net_tunables.lct_peer_rtr_credits;
2663 * make sure that this net is unique. If it isn't then
2664 * we are adding interfaces to an already existing network, and
2665 * 'net' is just a convenient way to pass in the list.
2666 * if it is unique we need to find the LND and load it if
2669 if (lnet_net_unique(net->net_id, &the_lnet.ln_nets, &net_l)) {
2670 lnd_type = LNET_NETTYP(net->net_id);
2672 lnd = lnet_load_lnd(lnd_type);
2678 mutex_lock(&the_lnet.ln_lnd_mutex);
2680 mutex_unlock(&the_lnet.ln_lnd_mutex);
2686 * net_l: if the network being added is unique then net_l
2687 * will point to that network
2688 * if the network being added is not unique then
2689 * net_l points to the existing network.
2691 * When we enter the loop below, we'll pick NIs off he
2692 * network beign added and start them up, then add them to
2693 * a local ni list. Once we've successfully started all
2694 * the NIs then we join the local NI list (of started up
2695 * networks) with the net_l->net_ni_list, which should
2696 * point to the correct network to add the new ni list to
2698 * If any of the new NIs fail to start up, then we want to
2699 * iterate through the local ni list, which should include
2700 * any NIs which were successfully started up, and shut
2703 * After than we want to delete the network being added,
2704 * to avoid a memory leak.
2706 while ((ni = list_first_entry_or_null(&net->net_ni_added,
2708 ni_netlist)) != NULL) {
2709 list_del_init(&ni->ni_netlist);
2711 /* make sure that the the NI we're about to start
2712 * up is actually unique. if it's not fail. */
2713 if (!lnet_ni_unique_net(&net_l->net_ni_list,
2714 ni->ni_interface)) {
2719 /* adjust the pointer the parent network, just in case it
2720 * the net is a duplicate */
2723 rc = lnet_startup_lndni(ni, tun);
2729 list_add_tail(&ni->ni_netlist, &local_ni_list);
2734 lnet_net_lock(LNET_LOCK_EX);
2735 list_splice_tail(&local_ni_list, &net_l->net_ni_list);
2736 lnet_incr_dlc_seq();
2738 list_for_each_entry(ni, &net_l->net_ni_list, ni_netlist) {
2742 ni->ni_state = LNET_NI_STATE_ACTIVE;
2745 lnet_net_unlock(LNET_LOCK_EX);
2747 /* if the network is not unique then we don't want to keep
2748 * it around after we're done. Free it. Otherwise add that
2749 * net to the global the_lnet.ln_nets */
2750 if (net_l != net && net_l != NULL) {
2752 * TODO - note. currently the tunables can not be updated
2758 * restore tunables after it has been overwitten by the
2761 if (peer_timeout != -1)
2762 net->net_tunables.lct_peer_timeout = peer_timeout;
2763 if (maxtxcredits != -1)
2764 net->net_tunables.lct_max_tx_credits = maxtxcredits;
2765 if (peerrtrcredits != -1)
2766 net->net_tunables.lct_peer_rtr_credits = peerrtrcredits;
2768 lnet_net_lock(LNET_LOCK_EX);
2769 list_add_tail(&net->net_list, &the_lnet.ln_nets);
2770 lnet_net_unlock(LNET_LOCK_EX);
2777 * shutdown the new NIs that are being started up
2778 * free the NET being started
2780 while ((ni = list_first_entry_or_null(&local_ni_list,
2782 ni_netlist)) != NULL)
2783 lnet_shutdown_lndni(ni);
2792 lnet_startup_lndnets(struct list_head *netlist)
2794 struct lnet_net *net;
2799 * Change to running state before bringing up the LNDs. This
2800 * allows lnet_shutdown_lndnets() to assert that we've passed
2803 lnet_net_lock(LNET_LOCK_EX);
2804 the_lnet.ln_state = LNET_STATE_RUNNING;
2805 lnet_net_unlock(LNET_LOCK_EX);
2807 while ((net = list_first_entry_or_null(netlist,
2809 net_list)) != NULL) {
2810 list_del_init(&net->net_list);
2812 rc = lnet_startup_lndnet(net, NULL);
2822 lnet_shutdown_lndnets();
2827 static int lnet_genl_parse_list(struct sk_buff *msg,
2828 const struct ln_key_list *data[], u16 idx)
2830 const struct ln_key_list *list = data[idx];
2831 const struct ln_key_props *props;
2832 struct nlattr *node;
2838 if (!list->lkl_maxattr)
2841 props = list->lkl_list;
2845 node = nla_nest_start(msg, LN_SCALAR_ATTR_LIST);
2849 for (count = 1; count <= list->lkl_maxattr; count++) {
2850 struct nlattr *key = nla_nest_start(msg, count);
2853 nla_put_u16(msg, LN_SCALAR_ATTR_LIST_SIZE,
2856 nla_put_u16(msg, LN_SCALAR_ATTR_INDEX, count);
2857 if (props[count].lkp_value)
2858 nla_put_string(msg, LN_SCALAR_ATTR_VALUE,
2859 props[count].lkp_value);
2860 if (props[count].lkp_key_format)
2861 nla_put_u16(msg, LN_SCALAR_ATTR_KEY_FORMAT,
2862 props[count].lkp_key_format);
2863 nla_put_u16(msg, LN_SCALAR_ATTR_NLA_TYPE,
2864 props[count].lkp_data_type);
2865 if (props[count].lkp_data_type == NLA_NESTED) {
2868 rc = lnet_genl_parse_list(msg, data, ++idx);
2874 nla_nest_end(msg, key);
2877 nla_nest_end(msg, node);
2881 int lnet_genl_send_scalar_list(struct sk_buff *msg, u32 portid, u32 seq,
2882 const struct genl_family *family, int flags,
2883 u8 cmd, const struct ln_key_list *data[])
2891 hdr = genlmsg_put(msg, portid, seq, family, flags, cmd);
2893 GOTO(canceled, rc = -EMSGSIZE);
2895 rc = lnet_genl_parse_list(msg, data, 0);
2899 genlmsg_end(msg, hdr);
2902 genlmsg_cancel(msg, hdr);
2903 return rc > 0 ? 0 : rc;
2905 EXPORT_SYMBOL(lnet_genl_send_scalar_list);
2907 static struct genl_family lnet_family;
2910 * Initialize LNet library.
2912 * Automatically called at module loading time. Caller has to call
2913 * lnet_lib_exit() after a call to lnet_lib_init(), if and only if the
2914 * latter returned 0. It must be called exactly once.
2916 * \retval 0 on success
2917 * \retval -ve on failures.
2919 int lnet_lib_init(void)
2923 lnet_assert_wire_constants();
2925 /* refer to global cfs_cpt_table for now */
2926 the_lnet.ln_cpt_table = cfs_cpt_tab;
2927 the_lnet.ln_cpt_number = cfs_cpt_number(cfs_cpt_tab);
2929 LASSERT(the_lnet.ln_cpt_number > 0);
2930 if (the_lnet.ln_cpt_number > LNET_CPT_MAX) {
2931 /* we are under risk of consuming all lh_cookie */
2932 CERROR("Can't have %d CPTs for LNet (max allowed is %d), "
2933 "please change setting of CPT-table and retry\n",
2934 the_lnet.ln_cpt_number, LNET_CPT_MAX);
2938 while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number)
2939 the_lnet.ln_cpt_bits++;
2941 rc = lnet_create_locks();
2943 CERROR("Can't create LNet global locks: %d\n", rc);
2947 rc = genl_register_family(&lnet_family);
2949 lnet_destroy_locks();
2950 CERROR("Can't register LNet netlink family: %d\n", rc);
2954 the_lnet.ln_refcount = 0;
2955 INIT_LIST_HEAD(&the_lnet.ln_net_zombie);
2956 INIT_LIST_HEAD(&the_lnet.ln_msg_resend);
2958 /* The hash table size is the number of bits it takes to express the set
2959 * ln_num_routes, minus 1 (better to under estimate than over so we
2960 * don't waste memory). */
2961 if (rnet_htable_size <= 0)
2962 rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
2963 else if (rnet_htable_size > LNET_REMOTE_NETS_HASH_MAX)
2964 rnet_htable_size = LNET_REMOTE_NETS_HASH_MAX;
2965 the_lnet.ln_remote_nets_hbits = max_t(int, 1,
2966 order_base_2(rnet_htable_size) - 1);
2968 /* All LNDs apart from the LOLND are in separate modules. They
2969 * register themselves when their module loads, and unregister
2970 * themselves when their module is unloaded. */
2971 lnet_register_lnd(&the_lolnd);
2976 * Finalize LNet library.
2978 * \pre lnet_lib_init() called with success.
2979 * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls.
2981 * As this happens at module-unload, all lnds must already be unloaded,
2982 * so they must already be unregistered.
2984 void lnet_lib_exit(void)
2988 LASSERT(the_lnet.ln_refcount == 0);
2989 lnet_unregister_lnd(&the_lolnd);
2990 for (i = 0; i < NUM_LNDS; i++)
2991 LASSERT(!the_lnet.ln_lnds[i]);
2992 lnet_destroy_locks();
2993 genl_unregister_family(&lnet_family);
2997 * Set LNet PID and start LNet interfaces, routing, and forwarding.
2999 * Users must call this function at least once before any other functions.
3000 * For each successful call there must be a corresponding call to
3001 * LNetNIFini(). For subsequent calls to LNetNIInit(), \a requested_pid is
3004 * The PID used by LNet may be different from the one requested.
3007 * \param requested_pid PID requested by the caller.
3009 * \return >= 0 on success, and < 0 error code on failures.
3012 LNetNIInit(lnet_pid_t requested_pid)
3014 int im_a_router = 0;
3017 struct lnet_ping_buffer *pbuf;
3018 struct lnet_handle_md ping_mdh;
3019 LIST_HEAD(net_head);
3020 struct lnet_net *net;
3022 mutex_lock(&the_lnet.ln_api_mutex);
3024 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
3026 if (the_lnet.ln_state == LNET_STATE_STOPPING) {
3027 mutex_unlock(&the_lnet.ln_api_mutex);
3031 if (the_lnet.ln_refcount > 0) {
3032 rc = the_lnet.ln_refcount++;
3033 mutex_unlock(&the_lnet.ln_api_mutex);
3037 rc = lnet_prepare(requested_pid);
3039 mutex_unlock(&the_lnet.ln_api_mutex);
3043 /* create a network for Loopback network */
3044 net = lnet_net_alloc(LNET_MKNET(LOLND, 0), &net_head);
3047 goto err_empty_list;
3050 /* Add in the loopback NI */
3051 if (lnet_ni_alloc(net, NULL, NULL) == NULL) {
3053 goto err_empty_list;
3056 if (use_tcp_bonding)
3057 CWARN("use_tcp_bonding has been removed. Use Multi-Rail and Dynamic Discovery instead, see LU-13641\n");
3059 /* If LNet is being initialized via DLC it is possible
3060 * that the user requests not to load module parameters (ones which
3061 * are supported by DLC) on initialization. Therefore, make sure not
3062 * to load networks, routes and forwarding from module parameters
3063 * in this case. On cleanup in case of failure only clean up
3064 * routes if it has been loaded */
3065 if (!the_lnet.ln_nis_from_mod_params) {
3066 rc = lnet_parse_networks(&net_head, lnet_get_networks());
3068 goto err_empty_list;
3071 rc = lnet_startup_lndnets(&net_head);
3073 goto err_empty_list;
3075 if (!the_lnet.ln_nis_from_mod_params) {
3076 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
3078 goto err_shutdown_lndnis;
3080 rc = lnet_rtrpools_alloc(im_a_router);
3082 goto err_destroy_routes;
3085 rc = lnet_acceptor_start();
3087 goto err_destroy_routes;
3089 the_lnet.ln_refcount = 1;
3090 /* Now I may use my own API functions... */
3092 ni_bytes = LNET_PING_INFO_HDR_SIZE;
3093 list_for_each_entry(net, &the_lnet.ln_nets, net_list)
3094 ni_bytes += lnet_get_net_ni_bytes_locked(net);
3096 rc = lnet_ping_target_setup(&pbuf, &ping_mdh, ni_bytes, true);
3098 goto err_acceptor_stop;
3100 lnet_ping_target_update(pbuf, ping_mdh);
3102 the_lnet.ln_mt_handler = lnet_mt_event_handler;
3104 rc = lnet_push_target_init();
3108 rc = lnet_monitor_thr_start();
3110 goto err_destroy_push_target;
3112 rc = lnet_peer_discovery_start();
3114 goto err_stop_monitor_thr;
3117 lnet_router_debugfs_init();
3119 mutex_unlock(&the_lnet.ln_api_mutex);
3121 complete_all(&the_lnet.ln_started);
3123 /* wait for all routers to start */
3124 lnet_wait_router_start();
3128 err_stop_monitor_thr:
3129 lnet_monitor_thr_stop();
3130 err_destroy_push_target:
3131 lnet_push_target_fini();
3133 lnet_ping_target_fini();
3135 the_lnet.ln_refcount = 0;
3136 lnet_acceptor_stop();
3138 if (!the_lnet.ln_nis_from_mod_params)
3139 lnet_destroy_routes();
3140 err_shutdown_lndnis:
3141 lnet_shutdown_lndnets();
3145 mutex_unlock(&the_lnet.ln_api_mutex);
3146 while ((net = list_first_entry_or_null(&net_head,
3148 net_list)) != NULL) {
3149 list_del_init(&net->net_list);
3154 EXPORT_SYMBOL(LNetNIInit);
3157 * Stop LNet interfaces, routing, and forwarding.
3159 * Users must call this function once for each successful call to LNetNIInit().
3160 * Once the LNetNIFini() operation has been started, the results of pending
3161 * API operations are undefined.
3163 * \return always 0 for current implementation.
3168 mutex_lock(&the_lnet.ln_api_mutex);
3170 LASSERT(the_lnet.ln_refcount > 0);
3172 if (the_lnet.ln_refcount != 1) {
3173 the_lnet.ln_refcount--;
3175 LASSERT(!the_lnet.ln_niinit_self);
3177 lnet_net_lock(LNET_LOCK_EX);
3178 the_lnet.ln_state = LNET_STATE_STOPPING;
3179 lnet_net_unlock(LNET_LOCK_EX);
3183 lnet_router_debugfs_fini();
3184 lnet_peer_discovery_stop();
3185 lnet_monitor_thr_stop();
3186 lnet_push_target_fini();
3187 lnet_ping_target_fini();
3189 /* Teardown fns that use my own API functions BEFORE here */
3190 the_lnet.ln_refcount = 0;
3192 lnet_acceptor_stop();
3193 lnet_destroy_routes();
3194 lnet_shutdown_lndnets();
3198 mutex_unlock(&the_lnet.ln_api_mutex);
3201 EXPORT_SYMBOL(LNetNIFini);
3204 * Grabs the ni data from the ni structure and fills the out
3207 * \param[in] ni network interface structure
3208 * \param[out] cfg_ni NI config information
3209 * \param[out] tun network and LND tunables
3212 lnet_fill_ni_info(struct lnet_ni *ni, struct lnet_ioctl_config_ni *cfg_ni,
3213 struct lnet_ioctl_config_lnd_tunables *tun,
3214 struct lnet_ioctl_element_stats *stats,
3217 size_t min_size = 0;
3220 if (!ni || !cfg_ni || !tun || !nid_is_nid4(&ni->ni_nid))
3223 if (ni->ni_interface != NULL) {
3224 strncpy(cfg_ni->lic_ni_intf,
3226 sizeof(cfg_ni->lic_ni_intf));
3229 cfg_ni->lic_nid = lnet_nid_to_nid4(&ni->ni_nid);
3230 cfg_ni->lic_status = lnet_ni_get_status_locked(ni);
3231 cfg_ni->lic_dev_cpt = ni->ni_dev_cpt;
3233 memcpy(&tun->lt_cmn, &ni->ni_net->net_tunables, sizeof(tun->lt_cmn));
3236 stats->iel_send_count = lnet_sum_stats(&ni->ni_stats,
3237 LNET_STATS_TYPE_SEND);
3238 stats->iel_recv_count = lnet_sum_stats(&ni->ni_stats,
3239 LNET_STATS_TYPE_RECV);
3240 stats->iel_drop_count = lnet_sum_stats(&ni->ni_stats,
3241 LNET_STATS_TYPE_DROP);
3245 * tun->lt_tun will always be present, but in order to be
3246 * backwards compatible, we need to deal with the cases when
3247 * tun->lt_tun is smaller than what the kernel has, because it
3248 * comes from an older version of a userspace program, then we'll
3249 * need to copy as much information as we have available space.
3251 min_size = tun_size - sizeof(tun->lt_cmn);
3252 memcpy(&tun->lt_tun, &ni->ni_lnd_tunables, min_size);
3254 /* copy over the cpts */
3255 if (ni->ni_ncpts == LNET_CPT_NUMBER &&
3256 ni->ni_cpts == NULL) {
3257 for (i = 0; i < ni->ni_ncpts; i++)
3258 cfg_ni->lic_cpts[i] = i;
3261 ni->ni_cpts != NULL && i < ni->ni_ncpts &&
3262 i < LNET_MAX_SHOW_NUM_CPT;
3264 cfg_ni->lic_cpts[i] = ni->ni_cpts[i];
3266 cfg_ni->lic_ncpts = ni->ni_ncpts;
3270 * NOTE: This is a legacy function left in the code to be backwards
3271 * compatible with older userspace programs. It should eventually be
3274 * Grabs the ni data from the ni structure and fills the out
3277 * \param[in] ni network interface structure
3278 * \param[out] config config information
3281 lnet_fill_ni_info_legacy(struct lnet_ni *ni,
3282 struct lnet_ioctl_config_data *config)
3284 struct lnet_ioctl_net_config *net_config;
3285 struct lnet_ioctl_config_lnd_tunables *lnd_cfg = NULL;
3286 size_t min_size, tunable_size = 0;
3289 if (!ni || !config || !nid_is_nid4(&ni->ni_nid))
3292 net_config = (struct lnet_ioctl_net_config *) config->cfg_bulk;
3296 if (!ni->ni_interface)
3299 strncpy(net_config->ni_interface,
3301 sizeof(net_config->ni_interface));
3303 config->cfg_nid = lnet_nid_to_nid4(&ni->ni_nid);
3304 config->cfg_config_u.cfg_net.net_peer_timeout =
3305 ni->ni_net->net_tunables.lct_peer_timeout;
3306 config->cfg_config_u.cfg_net.net_max_tx_credits =
3307 ni->ni_net->net_tunables.lct_max_tx_credits;
3308 config->cfg_config_u.cfg_net.net_peer_tx_credits =
3309 ni->ni_net->net_tunables.lct_peer_tx_credits;
3310 config->cfg_config_u.cfg_net.net_peer_rtr_credits =
3311 ni->ni_net->net_tunables.lct_peer_rtr_credits;
3313 net_config->ni_status = lnet_ni_get_status_locked(ni);
3316 int num_cpts = min(ni->ni_ncpts, LNET_MAX_SHOW_NUM_CPT);
3318 for (i = 0; i < num_cpts; i++)
3319 net_config->ni_cpts[i] = ni->ni_cpts[i];
3321 config->cfg_ncpts = num_cpts;
3325 * See if user land tools sent in a newer and larger version
3326 * of struct lnet_tunables than what the kernel uses.
3328 min_size = sizeof(*config) + sizeof(*net_config);
3330 if (config->cfg_hdr.ioc_len > min_size)
3331 tunable_size = config->cfg_hdr.ioc_len - min_size;
3333 /* Don't copy too much data to user space */
3334 min_size = min(tunable_size, sizeof(ni->ni_lnd_tunables));
3335 lnd_cfg = (struct lnet_ioctl_config_lnd_tunables *)net_config->cfg_bulk;
3337 if (lnd_cfg && min_size) {
3338 memcpy(&lnd_cfg->lt_tun, &ni->ni_lnd_tunables, min_size);
3339 config->cfg_config_u.cfg_net.net_interface_count = 1;
3341 /* Tell user land that kernel side has less data */
3342 if (tunable_size > sizeof(ni->ni_lnd_tunables)) {
3343 min_size = tunable_size - sizeof(ni->ni_lnd_tunables);
3344 config->cfg_hdr.ioc_len -= min_size;
3350 lnet_get_ni_idx_locked(int idx)
3353 struct lnet_net *net;
3355 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3356 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3365 int lnet_get_net_healthv_locked(struct lnet_net *net)
3368 int best_healthv = 0;
3369 int healthv, ni_fatal;
3371 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3372 healthv = atomic_read(&ni->ni_healthv);
3373 ni_fatal = atomic_read(&ni->ni_fatal_error_on);
3374 if (!ni_fatal && healthv > best_healthv)
3375 best_healthv = healthv;
3378 return best_healthv;
3382 lnet_get_next_ni_locked(struct lnet_net *mynet, struct lnet_ni *prev)
3385 struct lnet_net *net = mynet;
3388 * It is possible that the net has been cleaned out while there is
3389 * a message being sent. This function accessed the net without
3390 * checking if the list is empty
3394 net = list_first_entry(&the_lnet.ln_nets,
3397 if (list_empty(&net->net_ni_list))
3399 ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
3405 if (prev->ni_netlist.next == &prev->ni_net->net_ni_list) {
3406 /* if you reached the end of the ni list and the net is
3407 * specified, then there are no more nis in that net */
3411 /* we reached the end of this net ni list. move to the
3413 if (prev->ni_net->net_list.next == &the_lnet.ln_nets)
3414 /* no more nets and no more NIs. */
3417 /* get the next net */
3418 net = list_first_entry(&prev->ni_net->net_list, struct lnet_net,
3420 if (list_empty(&net->net_ni_list))
3422 /* get the ni on it */
3423 ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
3429 if (list_empty(&prev->ni_netlist))
3432 /* there are more nis left */
3433 ni = list_first_entry(&prev->ni_netlist, struct lnet_ni, ni_netlist);
3439 lnet_get_net_config(struct lnet_ioctl_config_data *config)
3444 int idx = config->cfg_count;
3446 cpt = lnet_net_lock_current();
3448 ni = lnet_get_ni_idx_locked(idx);
3453 lnet_fill_ni_info_legacy(ni, config);
3457 lnet_net_unlock(cpt);
3462 lnet_get_ni_config(struct lnet_ioctl_config_ni *cfg_ni,
3463 struct lnet_ioctl_config_lnd_tunables *tun,
3464 struct lnet_ioctl_element_stats *stats,
3471 if (!cfg_ni || !tun || !stats)
3474 cpt = lnet_net_lock_current();
3476 ni = lnet_get_ni_idx_locked(cfg_ni->lic_idx);
3481 lnet_fill_ni_info(ni, cfg_ni, tun, stats, tun_size);
3485 lnet_net_unlock(cpt);
3489 static int lnet_get_ni_stats(struct lnet_ioctl_element_msg_stats *msg_stats)
3497 ni = lnet_get_ni_idx_locked(msg_stats->im_idx);
3500 lnet_usr_translate_stats(msg_stats, &ni->ni_stats);
3507 static int lnet_add_net_common(struct lnet_net *net,
3508 struct lnet_ioctl_config_lnd_tunables *tun)
3510 struct lnet_handle_md ping_mdh;
3511 struct lnet_ping_buffer *pbuf;
3512 struct lnet_remotenet *rnet;
3517 lnet_net_lock(LNET_LOCK_EX);
3518 rnet = lnet_find_rnet_locked(net->net_id);
3519 lnet_net_unlock(LNET_LOCK_EX);
3521 * make sure that the net added doesn't invalidate the current
3522 * configuration LNet is keeping
3525 CERROR("Adding net %s will invalidate routing configuration\n",
3526 libcfs_net2str(net->net_id));
3532 memcpy(&net->net_tunables,
3533 &tun->lt_cmn, sizeof(net->net_tunables));
3535 memset(&net->net_tunables, -1, sizeof(net->net_tunables));
3537 net_id = net->net_id;
3539 rc = lnet_startup_lndnet(net,
3540 (tun) ? &tun->lt_tun : NULL);
3544 /* make sure you calculate the correct number of slots in the ping
3545 * buffer. Since the ping info is a flattened list of all the NIs,
3546 * we should allocate enough slots to accomodate the number of NIs
3547 * which will be added.
3549 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3550 LNET_PING_INFO_HDR_SIZE +
3551 lnet_get_ni_bytes(),
3554 lnet_shutdown_lndnet(net);
3558 lnet_net_lock(LNET_LOCK_EX);
3559 net = lnet_get_net_locked(net_id);
3562 /* apply the UDSPs */
3563 rc = lnet_udsp_apply_policies_on_net(net);
3565 CERROR("Failed to apply UDSPs on local net %s\n",
3566 libcfs_net2str(net->net_id));
3568 /* At this point we lost track of which NI was just added, so we
3569 * just re-apply the policies on all of the NIs on this net
3571 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3572 rc = lnet_udsp_apply_policies_on_ni(ni);
3574 CERROR("Failed to apply UDSPs on ni %s\n",
3575 libcfs_nidstr(&ni->ni_nid));
3577 lnet_net_unlock(LNET_LOCK_EX);
3580 * Start the acceptor thread if this is the first network
3581 * being added that requires the thread.
3583 if (net->net_lnd->lnd_accept) {
3584 rc = lnet_acceptor_start();
3586 /* shutdown the net that we just started */
3587 CERROR("Failed to start up acceptor thread\n");
3588 lnet_shutdown_lndnet(net);
3593 lnet_net_lock(LNET_LOCK_EX);
3594 lnet_peer_net_added(net);
3595 lnet_net_unlock(LNET_LOCK_EX);
3597 lnet_ping_target_update(pbuf, ping_mdh);
3602 lnet_ping_md_unlink(pbuf, &ping_mdh);
3603 lnet_ping_buffer_decref(pbuf);
3608 lnet_set_tune_defaults(struct lnet_ioctl_config_lnd_tunables *tun)
3611 if (tun->lt_cmn.lct_peer_timeout < 0)
3612 tun->lt_cmn.lct_peer_timeout = DEFAULT_PEER_TIMEOUT;
3613 if (!tun->lt_cmn.lct_peer_tx_credits)
3614 tun->lt_cmn.lct_peer_tx_credits = DEFAULT_PEER_CREDITS;
3615 if (!tun->lt_cmn.lct_max_tx_credits)
3616 tun->lt_cmn.lct_max_tx_credits = DEFAULT_CREDITS;
3620 static int lnet_handle_legacy_ip2nets(char *ip2nets,
3621 struct lnet_ioctl_config_lnd_tunables *tun)
3623 struct lnet_net *net;
3626 LIST_HEAD(net_head);
3628 rc = lnet_parse_ip2nets(&nets, ip2nets);
3632 rc = lnet_parse_networks(&net_head, nets);
3636 lnet_set_tune_defaults(tun);
3638 mutex_lock(&the_lnet.ln_api_mutex);
3639 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3644 while ((net = list_first_entry_or_null(&net_head,
3646 net_list)) != NULL) {
3647 list_del_init(&net->net_list);
3648 rc = lnet_add_net_common(net, tun);
3654 mutex_unlock(&the_lnet.ln_api_mutex);
3656 while ((net = list_first_entry_or_null(&net_head,
3658 net_list)) != NULL) {
3659 list_del_init(&net->net_list);
3665 int lnet_dyn_add_ni(struct lnet_ioctl_config_ni *conf, u32 net_id,
3666 struct lnet_ioctl_config_lnd_tunables *tun)
3668 struct lnet_net *net;
3673 /* handle legacy ip2nets from DLC */
3674 if (conf->lic_legacy_ip2nets[0] != '\0')
3675 return lnet_handle_legacy_ip2nets(conf->lic_legacy_ip2nets,
3678 lnd_type = LNET_NETTYP(net_id);
3680 if (!libcfs_isknown_lnd(lnd_type)) {
3681 CERROR("No valid net and lnd information provided\n");
3685 net = lnet_net_alloc(net_id, NULL);
3689 for (i = 0; i < conf->lic_ncpts; i++) {
3690 if (conf->lic_cpts[i] >= LNET_CPT_NUMBER) {
3696 ni = lnet_ni_alloc_w_cpt_array(net, conf->lic_cpts, conf->lic_ncpts,
3703 lnet_set_tune_defaults(tun);
3705 mutex_lock(&the_lnet.ln_api_mutex);
3706 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3710 rc = lnet_add_net_common(net, tun);
3713 mutex_unlock(&the_lnet.ln_api_mutex);
3715 /* If NI already exist delete this new unused copy */
3722 int lnet_dyn_del_ni(struct lnet_nid *nid)
3724 struct lnet_net *net;
3726 u32 net_id = LNET_NID_NET(nid);
3727 struct lnet_ping_buffer *pbuf;
3728 struct lnet_handle_md ping_mdh;
3732 /* don't allow userspace to shutdown the LOLND */
3733 if (LNET_NETTYP(net_id) == LOLND)
3736 mutex_lock(&the_lnet.ln_api_mutex);
3737 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3739 goto unlock_api_mutex;
3744 net = lnet_get_net_locked(net_id);
3746 CERROR("net %s not found\n",
3747 libcfs_net2str(net_id));
3752 if (!nid_addr_is_set(nid)) {
3753 /* remove the entire net */
3754 net_bytes = lnet_get_net_ni_bytes_locked(net);
3758 /* create and link a new ping info, before removing the old one */
3759 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3760 LNET_PING_INFO_HDR_SIZE +
3761 lnet_get_ni_bytes() - net_bytes,
3764 goto unlock_api_mutex;
3766 lnet_shutdown_lndnet(net);
3768 lnet_acceptor_stop();
3770 lnet_ping_target_update(pbuf, ping_mdh);
3772 goto unlock_api_mutex;
3775 ni = lnet_nid_to_ni_locked(nid, 0);
3777 CERROR("nid %s not found\n", libcfs_nidstr(nid));
3782 net_bytes = lnet_get_net_ni_bytes_locked(net);
3783 net_empty = list_is_singular(&net->net_ni_list);
3787 /* create and link a new ping info, before removing the old one */
3788 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3789 (LNET_PING_INFO_HDR_SIZE +
3790 lnet_get_ni_bytes() -
3791 lnet_ping_sts_size(&ni->ni_nid)),
3794 goto unlock_api_mutex;
3796 lnet_shutdown_lndni(ni);
3798 lnet_acceptor_stop();
3800 lnet_ping_target_update(pbuf, ping_mdh);
3802 /* check if the net is empty and remove it if it is */
3804 lnet_shutdown_lndnet(net);
3806 goto unlock_api_mutex;
3811 mutex_unlock(&the_lnet.ln_api_mutex);
3817 * lnet_dyn_add_net and lnet_dyn_del_net are now deprecated.
3818 * They are only expected to be called for unique networks.
3819 * That can be as a result of older DLC library
3820 * calls. Multi-Rail DLC and beyond no longer uses these APIs.
3823 lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
3825 struct lnet_net *net;
3826 LIST_HEAD(net_head);
3828 struct lnet_ioctl_config_lnd_tunables tun;
3829 const char *nets = conf->cfg_config_u.cfg_net.net_intf;
3831 /* Create a net/ni structures for the network string */
3832 rc = lnet_parse_networks(&net_head, nets);
3834 return rc == 0 ? -EINVAL : rc;
3836 mutex_lock(&the_lnet.ln_api_mutex);
3837 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3839 goto out_unlock_clean;
3843 rc = -EINVAL; /* only add one network per call */
3844 goto out_unlock_clean;
3847 net = list_first_entry(&net_head, struct lnet_net, net_list);
3848 list_del_init(&net->net_list);
3850 LASSERT(lnet_net_unique(net->net_id, &the_lnet.ln_nets, NULL));
3852 memset(&tun, 0, sizeof(tun));
3854 tun.lt_cmn.lct_peer_timeout =
3855 (!conf->cfg_config_u.cfg_net.net_peer_timeout) ? DEFAULT_PEER_TIMEOUT :
3856 conf->cfg_config_u.cfg_net.net_peer_timeout;
3857 tun.lt_cmn.lct_peer_tx_credits =
3858 (!conf->cfg_config_u.cfg_net.net_peer_tx_credits) ? DEFAULT_PEER_CREDITS :
3859 conf->cfg_config_u.cfg_net.net_peer_tx_credits;
3860 tun.lt_cmn.lct_peer_rtr_credits =
3861 conf->cfg_config_u.cfg_net.net_peer_rtr_credits;
3862 tun.lt_cmn.lct_max_tx_credits =
3863 (!conf->cfg_config_u.cfg_net.net_max_tx_credits) ? DEFAULT_CREDITS :
3864 conf->cfg_config_u.cfg_net.net_max_tx_credits;
3866 rc = lnet_add_net_common(net, &tun);
3869 mutex_unlock(&the_lnet.ln_api_mutex);
3870 /* net_head list is empty in success case */
3871 while ((net = list_first_entry_or_null(&net_head,
3873 net_list)) != NULL) {
3874 list_del_init(&net->net_list);
3881 lnet_dyn_del_net(u32 net_id)
3883 struct lnet_net *net;
3884 struct lnet_ping_buffer *pbuf;
3885 struct lnet_handle_md ping_mdh;
3886 int net_ni_bytes, rc;
3888 /* don't allow userspace to shutdown the LOLND */
3889 if (LNET_NETTYP(net_id) == LOLND)
3892 mutex_lock(&the_lnet.ln_api_mutex);
3893 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3900 net = lnet_get_net_locked(net_id);
3907 net_ni_bytes = lnet_get_net_ni_bytes_locked(net);
3911 /* create and link a new ping info, before removing the old one */
3912 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3913 LNET_PING_INFO_HDR_SIZE +
3914 lnet_get_ni_bytes() - net_ni_bytes,
3919 lnet_shutdown_lndnet(net);
3921 lnet_acceptor_stop();
3923 lnet_ping_target_update(pbuf, ping_mdh);
3926 mutex_unlock(&the_lnet.ln_api_mutex);
3931 void lnet_mark_ping_buffer_for_update(void)
3933 if (the_lnet.ln_routing)
3936 atomic_set(&the_lnet.ln_update_ping_buf, 1);
3937 complete(&the_lnet.ln_mt_wait_complete);
3939 EXPORT_SYMBOL(lnet_mark_ping_buffer_for_update);
3941 void lnet_update_ping_buffer(struct work_struct *work)
3943 struct lnet_ping_buffer *pbuf;
3944 struct lnet_handle_md ping_mdh;
3946 mutex_lock(&the_lnet.ln_api_mutex);
3948 atomic_set(&the_lnet.ln_pb_update_ready, 1);
3950 if ((the_lnet.ln_state == LNET_STATE_RUNNING) &&
3951 !lnet_ping_target_setup(&pbuf, &ping_mdh,
3952 LNET_PING_INFO_HDR_SIZE +
3953 lnet_get_ni_bytes(),
3955 lnet_ping_target_update(pbuf, ping_mdh);
3958 mutex_unlock(&the_lnet.ln_api_mutex);
3962 void lnet_queue_ping_buffer_update(void)
3964 /* don't queue pb update if it is not needed */
3965 if (atomic_dec_if_positive(&the_lnet.ln_update_ping_buf) < 0)
3968 /* don't queue pb update if already queued and not processed */
3969 if (atomic_dec_if_positive(&the_lnet.ln_pb_update_ready) < 0)
3972 INIT_WORK(&the_lnet.ln_pb_update_work, lnet_update_ping_buffer);
3973 queue_work(the_lnet.ln_pb_update_wq, &the_lnet.ln_pb_update_work);
3976 void lnet_incr_dlc_seq(void)
3978 atomic_inc(&lnet_dlc_seq_no);
3981 __u32 lnet_get_dlc_seq_locked(void)
3983 return atomic_read(&lnet_dlc_seq_no);
3987 lnet_ni_set_healthv(lnet_nid_t nid, int value, bool all)
3989 struct lnet_net *net;
3992 lnet_net_lock(LNET_LOCK_EX);
3993 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3994 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3995 if (all || (nid_is_nid4(&ni->ni_nid) &&
3996 lnet_nid_to_nid4(&ni->ni_nid) == nid)) {
3997 atomic_set(&ni->ni_healthv, value);
3998 if (list_empty(&ni->ni_recovery) &&
3999 value < LNET_MAX_HEALTH_VALUE) {
4000 CERROR("manually adding local NI %s to recovery\n",
4001 libcfs_nidstr(&ni->ni_nid));
4002 list_add_tail(&ni->ni_recovery,
4003 &the_lnet.ln_mt_localNIRecovq);
4004 lnet_ni_addref_locked(ni, 0);
4007 lnet_net_unlock(LNET_LOCK_EX);
4013 lnet_net_unlock(LNET_LOCK_EX);
4017 lnet_ni_set_conns_per_peer(lnet_nid_t nid, int value, bool all)
4019 struct lnet_net *net;
4022 lnet_net_lock(LNET_LOCK_EX);
4023 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
4024 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
4025 if (lnet_nid_to_nid4(&ni->ni_nid) != nid && !all)
4027 if (LNET_NETTYP(net->net_id) == SOCKLND)
4028 ni->ni_lnd_tunables.lnd_tun_u.lnd_sock.lnd_conns_per_peer = value;
4029 else if (LNET_NETTYP(net->net_id) == O2IBLND)
4030 ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = value;
4032 lnet_net_unlock(LNET_LOCK_EX);
4037 lnet_net_unlock(LNET_LOCK_EX);
4041 lnet_get_local_ni_hstats(struct lnet_ioctl_local_ni_hstats *stats)
4045 struct lnet_nid nid;
4047 lnet_nid4_to_nid(stats->hlni_nid, &nid);
4048 cpt = lnet_net_lock_current();
4049 ni = lnet_nid_to_ni_locked(&nid, cpt);
4055 stats->hlni_local_interrupt = atomic_read(&ni->ni_hstats.hlt_local_interrupt);
4056 stats->hlni_local_dropped = atomic_read(&ni->ni_hstats.hlt_local_dropped);
4057 stats->hlni_local_aborted = atomic_read(&ni->ni_hstats.hlt_local_aborted);
4058 stats->hlni_local_no_route = atomic_read(&ni->ni_hstats.hlt_local_no_route);
4059 stats->hlni_local_timeout = atomic_read(&ni->ni_hstats.hlt_local_timeout);
4060 stats->hlni_local_error = atomic_read(&ni->ni_hstats.hlt_local_error);
4061 stats->hlni_fatal_error = atomic_read(&ni->ni_fatal_error_on);
4062 stats->hlni_health_value = atomic_read(&ni->ni_healthv);
4063 stats->hlni_ping_count = ni->ni_ping_count;
4064 stats->hlni_next_ping = ni->ni_next_ping;
4067 lnet_net_unlock(cpt);
4073 lnet_get_local_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
4078 lnet_net_lock(LNET_LOCK_EX);
4079 list_for_each_entry(ni, &the_lnet.ln_mt_localNIRecovq, ni_recovery) {
4080 if (!nid_is_nid4(&ni->ni_nid))
4082 list->rlst_nid_array[i] = lnet_nid_to_nid4(&ni->ni_nid);
4084 if (i >= LNET_MAX_SHOW_NUM_NID)
4087 lnet_net_unlock(LNET_LOCK_EX);
4088 list->rlst_num_nids = i;
4094 lnet_get_peer_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
4096 struct lnet_peer_ni *lpni;
4099 lnet_net_lock(LNET_LOCK_EX);
4100 list_for_each_entry(lpni, &the_lnet.ln_mt_peerNIRecovq, lpni_recovery) {
4101 list->rlst_nid_array[i] = lnet_nid_to_nid4(&lpni->lpni_nid);
4103 if (i >= LNET_MAX_SHOW_NUM_NID)
4106 lnet_net_unlock(LNET_LOCK_EX);
4107 list->rlst_num_nids = i;
4113 * LNet ioctl handler.
4117 LNetCtl(unsigned int cmd, void *arg)
4119 struct libcfs_ioctl_data *data = arg;
4120 struct lnet_ioctl_config_data *config;
4122 struct lnet_nid nid;
4125 BUILD_BUG_ON(sizeof(struct lnet_ioctl_net_config) +
4126 sizeof(struct lnet_ioctl_config_data) > LIBCFS_IOC_DATA_MAX);
4129 case IOC_LIBCFS_GET_NI: {
4130 struct lnet_processid id = {};
4132 rc = LNetGetId(data->ioc_count, &id, false);
4133 data->ioc_nid = lnet_nid_to_nid4(&id.nid);
4136 case IOC_LIBCFS_FAIL_NID:
4137 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
4139 case IOC_LIBCFS_ADD_ROUTE: {
4140 /* default router sensitivity to 1 */
4141 unsigned int sensitivity = 1;
4144 if (config->cfg_hdr.ioc_len < sizeof(*config))
4147 if (config->cfg_config_u.cfg_route.rtr_sensitivity) {
4149 config->cfg_config_u.cfg_route.rtr_sensitivity;
4152 lnet_nid4_to_nid(config->cfg_nid, &nid);
4153 mutex_lock(&the_lnet.ln_api_mutex);
4154 rc = lnet_add_route(config->cfg_net,
4155 config->cfg_config_u.cfg_route.rtr_hop,
4157 config->cfg_config_u.cfg_route.
4158 rtr_priority, sensitivity);
4159 mutex_unlock(&the_lnet.ln_api_mutex);
4163 case IOC_LIBCFS_DEL_ROUTE:
4166 if (config->cfg_hdr.ioc_len < sizeof(*config))
4169 lnet_nid4_to_nid(config->cfg_nid, &nid);
4170 mutex_lock(&the_lnet.ln_api_mutex);
4171 rc = lnet_del_route(config->cfg_net, &nid);
4172 mutex_unlock(&the_lnet.ln_api_mutex);
4175 case IOC_LIBCFS_GET_ROUTE:
4178 if (config->cfg_hdr.ioc_len < sizeof(*config))
4181 mutex_lock(&the_lnet.ln_api_mutex);
4182 rc = lnet_get_route(config->cfg_count,
4184 &config->cfg_config_u.cfg_route.rtr_hop,
4186 &config->cfg_config_u.cfg_route.rtr_flags,
4187 &config->cfg_config_u.cfg_route.
4189 &config->cfg_config_u.cfg_route.
4191 mutex_unlock(&the_lnet.ln_api_mutex);
4194 case IOC_LIBCFS_GET_LOCAL_NI: {
4195 struct lnet_ioctl_config_ni *cfg_ni;
4196 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
4197 struct lnet_ioctl_element_stats *stats;
4202 /* get the tunables if they are available */
4203 if (cfg_ni->lic_cfg_hdr.ioc_len <
4204 sizeof(*cfg_ni) + sizeof(*stats) + sizeof(*tun))
4207 stats = (struct lnet_ioctl_element_stats *)
4209 tun = (struct lnet_ioctl_config_lnd_tunables *)
4210 (cfg_ni->lic_bulk + sizeof(*stats));
4212 tun_size = cfg_ni->lic_cfg_hdr.ioc_len - sizeof(*cfg_ni) -
4215 mutex_lock(&the_lnet.ln_api_mutex);
4216 rc = lnet_get_ni_config(cfg_ni, tun, stats, tun_size);
4217 mutex_unlock(&the_lnet.ln_api_mutex);
4221 case IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS: {
4222 struct lnet_ioctl_element_msg_stats *msg_stats = arg;
4225 if (msg_stats->im_hdr.ioc_len != sizeof(*msg_stats))
4228 mutex_lock(&the_lnet.ln_api_mutex);
4230 cpt = lnet_net_lock_current();
4231 rc = lnet_get_ni_stats(msg_stats);
4232 lnet_net_unlock(cpt);
4234 mutex_unlock(&the_lnet.ln_api_mutex);
4239 case IOC_LIBCFS_GET_NET: {
4240 size_t total = sizeof(*config) +
4241 sizeof(struct lnet_ioctl_net_config);
4244 if (config->cfg_hdr.ioc_len < total)
4247 mutex_lock(&the_lnet.ln_api_mutex);
4248 rc = lnet_get_net_config(config);
4249 mutex_unlock(&the_lnet.ln_api_mutex);
4253 case IOC_LIBCFS_GET_LNET_STATS:
4255 struct lnet_ioctl_lnet_stats *lnet_stats = arg;
4257 if (lnet_stats->st_hdr.ioc_len < sizeof(*lnet_stats))
4260 mutex_lock(&the_lnet.ln_api_mutex);
4261 rc = lnet_counters_get(&lnet_stats->st_cntrs);
4262 mutex_unlock(&the_lnet.ln_api_mutex);
4266 case IOC_LIBCFS_RESET_LNET_STATS:
4268 mutex_lock(&the_lnet.ln_api_mutex);
4269 lnet_counters_reset();
4270 mutex_unlock(&the_lnet.ln_api_mutex);
4274 case IOC_LIBCFS_CONFIG_RTR:
4277 if (config->cfg_hdr.ioc_len < sizeof(*config))
4280 mutex_lock(&the_lnet.ln_api_mutex);
4281 if (config->cfg_config_u.cfg_buffers.buf_enable) {
4282 rc = lnet_rtrpools_enable();
4283 mutex_unlock(&the_lnet.ln_api_mutex);
4286 lnet_rtrpools_disable();
4287 mutex_unlock(&the_lnet.ln_api_mutex);
4290 case IOC_LIBCFS_ADD_BUF:
4293 if (config->cfg_hdr.ioc_len < sizeof(*config))
4296 mutex_lock(&the_lnet.ln_api_mutex);
4297 rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
4299 config->cfg_config_u.cfg_buffers.
4301 config->cfg_config_u.cfg_buffers.
4303 mutex_unlock(&the_lnet.ln_api_mutex);
4306 case IOC_LIBCFS_SET_NUMA_RANGE: {
4307 struct lnet_ioctl_set_value *numa;
4309 if (numa->sv_hdr.ioc_len != sizeof(*numa))
4311 lnet_net_lock(LNET_LOCK_EX);
4312 lnet_numa_range = numa->sv_value;
4313 lnet_net_unlock(LNET_LOCK_EX);
4317 case IOC_LIBCFS_GET_NUMA_RANGE: {
4318 struct lnet_ioctl_set_value *numa;
4320 if (numa->sv_hdr.ioc_len != sizeof(*numa))
4322 numa->sv_value = lnet_numa_range;
4326 case IOC_LIBCFS_GET_BUF: {
4327 struct lnet_ioctl_pool_cfg *pool_cfg;
4328 size_t total = sizeof(*config) + sizeof(*pool_cfg);
4332 if (config->cfg_hdr.ioc_len < total)
4335 pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
4337 mutex_lock(&the_lnet.ln_api_mutex);
4338 rc = lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
4339 mutex_unlock(&the_lnet.ln_api_mutex);
4343 case IOC_LIBCFS_GET_LOCAL_HSTATS: {
4344 struct lnet_ioctl_local_ni_hstats *stats = arg;
4346 if (stats->hlni_hdr.ioc_len < sizeof(*stats))
4349 mutex_lock(&the_lnet.ln_api_mutex);
4350 rc = lnet_get_local_ni_hstats(stats);
4351 mutex_unlock(&the_lnet.ln_api_mutex);
4356 case IOC_LIBCFS_GET_RECOVERY_QUEUE: {
4357 struct lnet_ioctl_recovery_list *list = arg;
4358 if (list->rlst_hdr.ioc_len < sizeof(*list))
4361 mutex_lock(&the_lnet.ln_api_mutex);
4362 if (list->rlst_type == LNET_HEALTH_TYPE_LOCAL_NI)
4363 rc = lnet_get_local_ni_recovery_list(list);
4365 rc = lnet_get_peer_ni_recovery_list(list);
4366 mutex_unlock(&the_lnet.ln_api_mutex);
4370 case IOC_LIBCFS_ADD_PEER_NI: {
4371 struct lnet_ioctl_peer_cfg *cfg = arg;
4372 struct lnet_nid prim_nid;
4374 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4377 mutex_lock(&the_lnet.ln_api_mutex);
4378 lnet_nid4_to_nid(cfg->prcfg_prim_nid, &prim_nid);
4379 lnet_nid4_to_nid(cfg->prcfg_cfg_nid, &nid);
4380 rc = lnet_user_add_peer_ni(&prim_nid, &nid, cfg->prcfg_mr,
4381 cfg->prcfg_count == 1);
4382 mutex_unlock(&the_lnet.ln_api_mutex);
4386 case IOC_LIBCFS_DEL_PEER_NI: {
4387 struct lnet_ioctl_peer_cfg *cfg = arg;
4388 struct lnet_nid prim_nid;
4390 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4393 mutex_lock(&the_lnet.ln_api_mutex);
4394 lnet_nid4_to_nid(cfg->prcfg_prim_nid, &prim_nid);
4395 lnet_nid4_to_nid(cfg->prcfg_cfg_nid, &nid);
4396 rc = lnet_del_peer_ni(&prim_nid,
4399 mutex_unlock(&the_lnet.ln_api_mutex);
4403 case IOC_LIBCFS_GET_PEER_INFO: {
4404 struct lnet_ioctl_peer *peer_info = arg;
4406 if (peer_info->pr_hdr.ioc_len < sizeof(*peer_info))
4409 mutex_lock(&the_lnet.ln_api_mutex);
4410 rc = lnet_get_peer_ni_info(
4411 peer_info->pr_count,
4413 peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
4414 &peer_info->pr_lnd_u.pr_peer_credits.cr_ncpt,
4415 &peer_info->pr_lnd_u.pr_peer_credits.cr_refcount,
4416 &peer_info->pr_lnd_u.pr_peer_credits.cr_ni_peer_tx_credits,
4417 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_credits,
4418 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_rtr_credits,
4419 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_min_tx_credits,
4420 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_qnob);
4421 mutex_unlock(&the_lnet.ln_api_mutex);
4425 case IOC_LIBCFS_GET_PEER_NI: {
4426 struct lnet_ioctl_peer_cfg *cfg = arg;
4428 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4431 mutex_lock(&the_lnet.ln_api_mutex);
4432 rc = lnet_get_peer_info(cfg,
4433 (void __user *)cfg->prcfg_bulk);
4434 mutex_unlock(&the_lnet.ln_api_mutex);
4438 case IOC_LIBCFS_GET_PEER_LIST: {
4439 struct lnet_ioctl_peer_cfg *cfg = arg;
4441 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4444 mutex_lock(&the_lnet.ln_api_mutex);
4445 rc = lnet_get_peer_list(&cfg->prcfg_count, &cfg->prcfg_size,
4446 (struct lnet_process_id __user *)cfg->prcfg_bulk);
4447 mutex_unlock(&the_lnet.ln_api_mutex);
4451 case IOC_LIBCFS_SET_HEALHV: {
4452 struct lnet_ioctl_reset_health_cfg *cfg = arg;
4455 if (cfg->rh_hdr.ioc_len < sizeof(*cfg))
4457 if (cfg->rh_value < 0 ||
4458 cfg->rh_value > LNET_MAX_HEALTH_VALUE)
4459 value = LNET_MAX_HEALTH_VALUE;
4461 value = cfg->rh_value;
4462 CDEBUG(D_NET, "Manually setting healthv to %d for %s:%s. all = %d\n",
4463 value, (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI) ?
4464 "local" : "peer", libcfs_nid2str(cfg->rh_nid), cfg->rh_all);
4465 lnet_nid4_to_nid(cfg->rh_nid, &nid);
4466 mutex_lock(&the_lnet.ln_api_mutex);
4467 if (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI)
4468 lnet_ni_set_healthv(cfg->rh_nid, value,
4471 lnet_peer_ni_set_healthv(&nid, value, cfg->rh_all);
4472 mutex_unlock(&the_lnet.ln_api_mutex);
4476 case IOC_LIBCFS_SET_PEER: {
4477 struct lnet_ioctl_peer_cfg *cfg = arg;
4478 struct lnet_peer *lp;
4480 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4483 mutex_lock(&the_lnet.ln_api_mutex);
4484 lnet_nid4_to_nid(cfg->prcfg_prim_nid, &nid);
4485 lp = lnet_find_peer(&nid);
4487 mutex_unlock(&the_lnet.ln_api_mutex);
4490 spin_lock(&lp->lp_lock);
4491 lp->lp_state = cfg->prcfg_state;
4492 spin_unlock(&lp->lp_lock);
4493 lnet_peer_decref_locked(lp);
4494 mutex_unlock(&the_lnet.ln_api_mutex);
4495 CDEBUG(D_NET, "Set peer %s state to %u\n",
4496 libcfs_nid2str(cfg->prcfg_prim_nid), cfg->prcfg_state);
4500 case IOC_LIBCFS_SET_CONNS_PER_PEER: {
4501 struct lnet_ioctl_reset_conns_per_peer_cfg *cfg = arg;
4504 if (cfg->rcpp_hdr.ioc_len < sizeof(*cfg))
4506 if (cfg->rcpp_value < 0)
4509 value = cfg->rcpp_value;
4511 "Setting conns_per_peer to %d for %s. all = %d\n",
4512 value, libcfs_nid2str(cfg->rcpp_nid), cfg->rcpp_all);
4513 mutex_lock(&the_lnet.ln_api_mutex);
4514 lnet_ni_set_conns_per_peer(cfg->rcpp_nid, value, cfg->rcpp_all);
4515 mutex_unlock(&the_lnet.ln_api_mutex);
4519 case IOC_LIBCFS_NOTIFY_ROUTER: {
4520 /* Convert the user-supplied real time to monotonic.
4521 * NB: "when" is always in the past
4523 time64_t when = ktime_get_seconds() -
4524 (ktime_get_real_seconds() - data->ioc_u64[0]);
4526 lnet_nid4_to_nid(data->ioc_nid, &nid);
4527 return lnet_notify(NULL, &nid, data->ioc_flags, false, when);
4530 case IOC_LIBCFS_LNET_DIST:
4531 lnet_nid4_to_nid(data->ioc_nid, &nid);
4532 rc = LNetDist(&nid, &nid, &data->ioc_u32[1]);
4533 if (rc < 0 && rc != -EHOSTUNREACH)
4536 data->ioc_nid = lnet_nid_to_nid4(&nid);
4537 data->ioc_u32[0] = rc;
4540 case IOC_LIBCFS_TESTPROTOCOMPAT:
4541 the_lnet.ln_testprotocompat = data->ioc_flags;
4544 case IOC_LIBCFS_LNET_FAULT:
4545 return lnet_fault_ctl(data->ioc_flags, data);
4547 case IOC_LIBCFS_PING_PEER: {
4548 struct lnet_ioctl_ping_data *ping = arg;
4549 struct lnet_process_id __user *ids = ping->ping_buf;
4550 struct lnet_nid src_nid = LNET_ANY_NID;
4551 struct lnet_genl_ping_list plist;
4552 struct lnet_processid id;
4553 struct lnet_peer *lp;
4554 signed long timeout;
4557 /* Check if the supplied ping data supports source nid
4558 * NB: This check is sufficient if lnet_ioctl_ping_data has
4559 * additional fields added, but if they are re-ordered or
4560 * fields removed then this will break. It is expected that
4561 * these ioctls will be replaced with netlink implementation, so
4562 * it is probably not worth coming up with a more robust version
4563 * compatibility scheme.
4565 if (ping->ping_hdr.ioc_len >= sizeof(struct lnet_ioctl_ping_data))
4566 lnet_nid4_to_nid(ping->ping_src, &src_nid);
4568 /* If timeout is negative then set default of 3 minutes */
4569 if (((s32)ping->op_param) <= 0 ||
4570 ping->op_param > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
4571 timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
4573 timeout = nsecs_to_jiffies(ping->op_param * NSEC_PER_MSEC);
4575 id.pid = ping->ping_id.pid;
4576 lnet_nid4_to_nid(ping->ping_id.nid, &id.nid);
4577 rc = lnet_ping(&id, &src_nid, timeout, &plist,
4580 goto report_ping_err;
4584 for (i = 0; i < count; i++) {
4585 struct lnet_processid *result;
4586 struct lnet_process_id tmpid;
4588 result = genradix_ptr(&plist.lgpl_list, i);
4589 memset(&tmpid, 0, sizeof(tmpid));
4590 tmpid.pid = result->pid;
4591 tmpid.nid = lnet_nid_to_nid4(&result->nid);
4592 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid))) {
4594 goto report_ping_err;
4598 mutex_lock(&the_lnet.ln_api_mutex);
4599 lp = lnet_find_peer(&id.nid);
4602 lnet_nid_to_nid4(&lp->lp_primary_nid);
4603 ping->mr_info = lnet_peer_is_multi_rail(lp);
4604 lnet_peer_decref_locked(lp);
4606 mutex_unlock(&the_lnet.ln_api_mutex);
4608 ping->ping_count = count;
4610 genradix_free(&plist.lgpl_list);
4614 case IOC_LIBCFS_DISCOVER: {
4615 struct lnet_ioctl_ping_data *discover = arg;
4616 struct lnet_process_id __user *ids;
4617 struct lnet_genl_ping_list dlists;
4618 struct lnet_processid id;
4619 struct lnet_peer *lp;
4622 if (discover->ping_count <= 0)
4625 genradix_init(&dlists.lgpl_list);
4626 /* If the user buffer has more space than the lnet_interfaces_max,
4627 * then only fill it up to lnet_interfaces_max.
4629 if (discover->ping_count > lnet_interfaces_max)
4630 discover->ping_count = lnet_interfaces_max;
4632 id.pid = discover->ping_id.pid;
4633 lnet_nid4_to_nid(discover->ping_id.nid, &id.nid);
4634 rc = lnet_discover(&id, discover->op_param, &dlists);
4636 goto report_discover_err;
4639 ids = discover->ping_buf;
4640 for (i = 0; i < count; i++) {
4641 struct lnet_processid *result;
4642 struct lnet_process_id tmpid;
4644 result = genradix_ptr(&dlists.lgpl_list, i);
4645 memset(&tmpid, 0, sizeof(tmpid));
4646 tmpid.pid = result->pid;
4647 tmpid.nid = lnet_nid_to_nid4(&result->nid);
4648 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid))) {
4650 goto report_discover_err;
4653 if (i >= discover->ping_count)
4658 mutex_lock(&the_lnet.ln_api_mutex);
4659 lp = lnet_find_peer(&id.nid);
4661 discover->ping_id.nid =
4662 lnet_nid_to_nid4(&lp->lp_primary_nid);
4663 discover->mr_info = lnet_peer_is_multi_rail(lp);
4664 lnet_peer_decref_locked(lp);
4666 mutex_unlock(&the_lnet.ln_api_mutex);
4668 discover->ping_count = count;
4669 report_discover_err:
4670 genradix_free(&dlists.lgpl_list);
4674 case IOC_LIBCFS_ADD_UDSP: {
4675 struct lnet_ioctl_udsp *ioc_udsp = arg;
4676 __u32 bulk_size = ioc_udsp->iou_hdr.ioc_len;
4678 mutex_lock(&the_lnet.ln_api_mutex);
4679 rc = lnet_udsp_demarshal_add(arg, bulk_size);
4681 rc = lnet_udsp_apply_policies(NULL, false);
4682 CDEBUG(D_NET, "policy application returned %d\n", rc);
4685 mutex_unlock(&the_lnet.ln_api_mutex);
4690 case IOC_LIBCFS_DEL_UDSP: {
4691 struct lnet_ioctl_udsp *ioc_udsp = arg;
4692 int idx = ioc_udsp->iou_idx;
4694 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4697 mutex_lock(&the_lnet.ln_api_mutex);
4698 rc = lnet_udsp_del_policy(idx);
4699 mutex_unlock(&the_lnet.ln_api_mutex);
4704 case IOC_LIBCFS_GET_UDSP_SIZE: {
4705 struct lnet_ioctl_udsp *ioc_udsp = arg;
4706 struct lnet_udsp *udsp;
4708 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4713 mutex_lock(&the_lnet.ln_api_mutex);
4714 udsp = lnet_udsp_get_policy(ioc_udsp->iou_idx);
4718 /* coming in iou_idx will hold the idx of the udsp
4719 * to get the size of. going out the iou_idx will
4720 * hold the size of the UDSP found at the passed
4723 ioc_udsp->iou_idx = lnet_get_udsp_size(udsp);
4724 if (ioc_udsp->iou_idx < 0)
4727 mutex_unlock(&the_lnet.ln_api_mutex);
4732 case IOC_LIBCFS_GET_UDSP: {
4733 struct lnet_ioctl_udsp *ioc_udsp = arg;
4734 struct lnet_udsp *udsp;
4736 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4741 mutex_lock(&the_lnet.ln_api_mutex);
4742 udsp = lnet_udsp_get_policy(ioc_udsp->iou_idx);
4746 rc = lnet_udsp_marshal(udsp, ioc_udsp);
4747 mutex_unlock(&the_lnet.ln_api_mutex);
4752 case IOC_LIBCFS_GET_CONST_UDSP_INFO: {
4753 struct lnet_ioctl_construct_udsp_info *info = arg;
4755 if (info->cud_hdr.ioc_len < sizeof(*info))
4758 CDEBUG(D_NET, "GET_UDSP_INFO for %s\n",
4759 libcfs_nid2str(info->cud_nid));
4761 lnet_nid4_to_nid(info->cud_nid, &nid);
4762 mutex_lock(&the_lnet.ln_api_mutex);
4764 lnet_udsp_get_construct_info(info, &nid);
4766 mutex_unlock(&the_lnet.ln_api_mutex);
4772 ni = lnet_net2ni_addref(data->ioc_net);
4776 if (ni->ni_net->net_lnd->lnd_ctl == NULL)
4779 rc = ni->ni_net->net_lnd->lnd_ctl(ni, cmd, arg);
4782 return rc <= 0 ? rc : 0;
4786 EXPORT_SYMBOL(LNetCtl);
4788 struct lnet_nid_cpt {
4789 struct lnet_nid lnc_nid;
4790 unsigned int lnc_cpt;
4793 struct lnet_genl_nid_cpt_list {
4794 unsigned int lgncl_index;
4795 unsigned int lgncl_list_count;
4796 GENRADIX(struct lnet_nid_cpt) lgncl_lnc_list;
4799 static inline struct lnet_genl_nid_cpt_list *
4800 lnet_cpt_of_nid_dump_ctx(struct netlink_callback *cb)
4802 return (struct lnet_genl_nid_cpt_list *)cb->args[0];
4805 static int lnet_cpt_of_nid_show_done(struct netlink_callback *cb)
4807 struct lnet_genl_nid_cpt_list *lgncl;
4809 lgncl = lnet_cpt_of_nid_dump_ctx(cb);
4812 genradix_free(&lgncl->lgncl_lnc_list);
4813 LIBCFS_FREE(lgncl, sizeof(*lgncl));
4820 static int lnet_cpt_of_nid_show_start(struct netlink_callback *cb)
4822 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
4823 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
4824 struct netlink_ext_ack *extack = NULL;
4826 struct lnet_genl_nid_cpt_list *lgncl;
4827 int msg_len = genlmsg_len(gnlh);
4828 struct nlattr *params, *top;
4831 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
4832 extack = cb->extack;
4835 mutex_lock(&the_lnet.ln_api_mutex);
4836 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
4837 NL_SET_ERR_MSG(extack, "Network is down");
4838 mutex_unlock(&the_lnet.ln_api_mutex);
4842 msg_len = genlmsg_len(gnlh);
4844 NL_SET_ERR_MSG(extack, "Missing NID argument(s)");
4845 mutex_unlock(&the_lnet.ln_api_mutex);
4849 LIBCFS_ALLOC(lgncl, sizeof(*lgncl));
4851 mutex_unlock(&the_lnet.ln_api_mutex);
4855 genradix_init(&lgncl->lgncl_lnc_list);
4856 lgncl->lgncl_list_count = 0;
4857 cb->args[0] = (long)lgncl;
4859 params = genlmsg_data(gnlh);
4860 nla_for_each_attr(top, params, msg_len, rem) {
4861 struct nlattr *nids;
4864 switch (nla_type(top)) {
4865 case LN_SCALAR_ATTR_LIST:
4866 nla_for_each_nested(nids, top, rem2) {
4867 char nidstr[LNET_NIDSTR_SIZE + 1];
4868 struct lnet_nid_cpt *lnc;
4870 if (nla_type(nids) != LN_SCALAR_ATTR_VALUE)
4873 memset(nidstr, 0, sizeof(nidstr));
4874 rc = nla_strscpy(nidstr, nids, sizeof(nidstr));
4876 NL_SET_ERR_MSG(extack,
4877 "failed to get NID");
4878 GOTO(report_err, rc);
4881 lnc = genradix_ptr_alloc(&lgncl->lgncl_lnc_list,
4882 lgncl->lgncl_list_count++,
4885 NL_SET_ERR_MSG(extack,
4886 "failed to allocate NID");
4887 GOTO(report_err, rc = -ENOMEM);
4890 rc = libcfs_strnid(&lnc->lnc_nid,
4893 NL_SET_ERR_MSG(extack, "invalid NID");
4894 GOTO(report_err, rc);
4897 CDEBUG(D_NET, "nid: %s\n",
4898 libcfs_nidstr(&lnc->lnc_nid));
4906 mutex_unlock(&the_lnet.ln_api_mutex);
4909 lnet_cpt_of_nid_show_done(cb);
4914 static const struct ln_key_list cpt_of_nid_props_list = {
4915 .lkl_maxattr = LNET_CPT_OF_NID_ATTR_MAX,
4917 [LNET_CPT_OF_NID_ATTR_HDR] = {
4918 .lkp_value = "cpt-of-nid",
4919 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
4920 .lkp_data_type = NLA_NUL_STRING,
4922 [LNET_CPT_OF_NID_ATTR_NID] = {
4924 .lkp_data_type = NLA_STRING,
4926 [LNET_CPT_OF_NID_ATTR_CPT] = {
4928 .lkp_data_type = NLA_U32,
4933 static int lnet_cpt_of_nid_show_dump(struct sk_buff *msg,
4934 struct netlink_callback *cb)
4936 struct lnet_genl_nid_cpt_list *lgncl;
4937 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
4938 struct netlink_ext_ack *extack = NULL;
4940 int portid = NETLINK_CB(cb->skb).portid;
4941 int seq = cb->nlh->nlmsg_seq;
4944 bool need_hdr = true;
4946 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
4947 extack = cb->extack;
4950 mutex_lock(&the_lnet.ln_api_mutex);
4951 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
4952 NL_SET_ERR_MSG(extack, "Network is down");
4953 GOTO(send_error, rc = -ENETDOWN);
4956 lgncl = lnet_cpt_of_nid_dump_ctx(cb);
4957 idx = lgncl->lgncl_index;
4959 if (!lgncl->lgncl_index) {
4960 const struct ln_key_list *all[] = {
4961 &cpt_of_nid_props_list, NULL, NULL
4964 rc = lnet_genl_send_scalar_list(msg, portid, seq, &lnet_family,
4965 NLM_F_CREATE | NLM_F_MULTI,
4966 LNET_CMD_CPT_OF_NID, all);
4968 NL_SET_ERR_MSG(extack, "failed to send key table");
4969 GOTO(send_error, rc);
4973 while (idx < lgncl->lgncl_list_count) {
4974 struct lnet_nid_cpt *lnc;
4978 lnc = genradix_ptr(&lgncl->lgncl_lnc_list, idx++);
4980 cpt = lnet_nid_cpt_hash(&lnc->lnc_nid, LNET_CPT_NUMBER);
4982 CDEBUG(D_NET, "nid: %s cpt: %d\n", libcfs_nidstr(&lnc->lnc_nid), cpt);
4983 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
4984 NLM_F_MULTI, LNET_CMD_CPT_OF_NID);
4986 NL_SET_ERR_MSG(extack, "failed to send values");
4987 genlmsg_cancel(msg, hdr);
4988 GOTO(send_error, rc = -EMSGSIZE);
4992 nla_put_string(msg, LNET_CPT_OF_NID_ATTR_HDR, "");
4996 nla_put_string(msg, LNET_CPT_OF_NID_ATTR_NID,
4997 libcfs_nidstr(&lnc->lnc_nid));
4998 nla_put_u32(msg, LNET_CPT_OF_NID_ATTR_CPT, cpt);
5000 genlmsg_end(msg, hdr);
5003 genradix_free(&lgncl->lgncl_lnc_list);
5005 lgncl->lgncl_index = idx;
5008 mutex_unlock(&the_lnet.ln_api_mutex);
5010 return lnet_nl_send_error(cb->skb, portid, seq, rc);
5013 #ifndef HAVE_NETLINK_CALLBACK_START
5014 static int lnet_old_cpt_of_nid_show_dump(struct sk_buff *msg,
5015 struct netlink_callback *cb)
5018 int rc = lnet_cpt_of_nid_show_start(cb);
5021 return lnet_nl_send_error(cb->skb,
5022 NETLINK_CB(cb->skb).portid,
5027 return lnet_cpt_of_nid_show_dump(msg, cb);
5031 /* This is the keys for the UDSP info which is used by many
5034 static const struct ln_key_list udsp_info_list = {
5035 .lkl_maxattr = LNET_UDSP_INFO_ATTR_MAX,
5037 [LNET_UDSP_INFO_ATTR_NET_PRIORITY] = {
5038 .lkp_value = "net priority",
5039 .lkp_data_type = NLA_S32
5041 [LNET_UDSP_INFO_ATTR_NID_PRIORITY] = {
5042 .lkp_value = "nid priority",
5043 .lkp_data_type = NLA_S32
5045 [LNET_UDSP_INFO_ATTR_PREF_RTR_NIDS_LIST] = {
5046 .lkp_value = "Preferred gateway NIDs",
5047 .lkp_key_format = LNKF_MAPPING,
5048 .lkp_data_type = NLA_NESTED,
5050 [LNET_UDSP_INFO_ATTR_PREF_NIDS_LIST] = {
5051 .lkp_value = "Preferred source NIDs",
5052 .lkp_key_format = LNKF_MAPPING,
5053 .lkp_data_type = NLA_NESTED,
5058 static const struct ln_key_list udsp_info_pref_nids_list = {
5059 .lkl_maxattr = LNET_UDSP_INFO_PREF_NIDS_ATTR_MAX,
5061 [LNET_UDSP_INFO_PREF_NIDS_ATTR_INDEX] = {
5062 .lkp_value = "NID-0",
5063 .lkp_data_type = NLA_NUL_STRING,
5065 [LNET_UDSP_INFO_PREF_NIDS_ATTR_NID] = {
5066 .lkp_value = "0@lo",
5067 .lkp_data_type = NLA_STRING,
5072 static int lnet_udsp_info_send(struct sk_buff *msg, int attr,
5073 struct lnet_nid *nid, bool remote)
5075 struct lnet_ioctl_construct_udsp_info *udsp;
5076 struct nlattr *udsp_attr, *udsp_info;
5077 struct nlattr *udsp_list_attr;
5078 struct nlattr *udsp_list_info;
5081 CFS_ALLOC_PTR(udsp);
5085 udsp->cud_peer = remote;
5086 lnet_udsp_get_construct_info(udsp, nid);
5088 udsp_info = nla_nest_start(msg, attr);
5089 udsp_attr = nla_nest_start(msg, 0);
5090 nla_put_s32(msg, LNET_UDSP_INFO_ATTR_NET_PRIORITY,
5091 udsp->cud_net_priority);
5092 nla_put_s32(msg, LNET_UDSP_INFO_ATTR_NID_PRIORITY,
5093 udsp->cud_nid_priority);
5095 if (udsp->cud_pref_rtr_nid[0] == 0)
5098 udsp_list_info = nla_nest_start(msg,
5099 LNET_UDSP_INFO_ATTR_PREF_RTR_NIDS_LIST);
5100 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
5101 char tmp[8]; /* NID-"3 number"\0 */
5103 if (udsp->cud_pref_rtr_nid[i] == 0)
5106 udsp_list_attr = nla_nest_start(msg, i);
5107 snprintf(tmp, sizeof(tmp), "NID-%d", i);
5108 nla_put_string(msg, LNET_UDSP_INFO_PREF_NIDS_ATTR_INDEX,
5110 nla_put_string(msg, LNET_UDSP_INFO_PREF_NIDS_ATTR_NID,
5111 libcfs_nid2str(udsp->cud_pref_rtr_nid[i]));
5112 nla_nest_end(msg, udsp_list_attr);
5114 nla_nest_end(msg, udsp_list_info);
5116 nla_nest_end(msg, udsp_attr);
5117 nla_nest_end(msg, udsp_info);
5118 LIBCFS_FREE(udsp, sizeof(*udsp));
5123 /* LNet NI handling */
5124 static const struct ln_key_list net_props_list = {
5125 .lkl_maxattr = LNET_NET_ATTR_MAX,
5127 [LNET_NET_ATTR_HDR] = {
5129 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
5130 .lkp_data_type = NLA_NUL_STRING,
5132 [LNET_NET_ATTR_TYPE] = {
5133 .lkp_value = "net type",
5134 .lkp_data_type = NLA_STRING
5136 [LNET_NET_ATTR_LOCAL] = {
5137 .lkp_value = "local NI(s)",
5138 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
5139 .lkp_data_type = NLA_NESTED
5144 static struct ln_key_list local_ni_list = {
5145 .lkl_maxattr = LNET_NET_LOCAL_NI_ATTR_MAX,
5147 [LNET_NET_LOCAL_NI_ATTR_NID] = {
5149 .lkp_data_type = NLA_STRING
5151 [LNET_NET_LOCAL_NI_ATTR_STATUS] = {
5152 .lkp_value = "status",
5153 .lkp_data_type = NLA_STRING
5155 [LNET_NET_LOCAL_NI_ATTR_INTERFACE] = {
5156 .lkp_value = "interfaces",
5157 .lkp_key_format = LNKF_MAPPING,
5158 .lkp_data_type = NLA_NESTED
5160 [LNET_NET_LOCAL_NI_ATTR_STATS] = {
5161 .lkp_value = "statistics",
5162 .lkp_key_format = LNKF_MAPPING,
5163 .lkp_data_type = NLA_NESTED
5165 [LNET_NET_LOCAL_NI_ATTR_UDSP_INFO] = {
5166 .lkp_value = "udsp info",
5167 .lkp_key_format = LNKF_MAPPING,
5168 .lkp_data_type = NLA_NESTED
5170 [LNET_NET_LOCAL_NI_ATTR_SEND_STATS] = {
5171 .lkp_value = "sent_stats",
5172 .lkp_key_format = LNKF_MAPPING,
5173 .lkp_data_type = NLA_NESTED
5175 [LNET_NET_LOCAL_NI_ATTR_RECV_STATS] = {
5176 .lkp_value = "received_stats",
5177 .lkp_key_format = LNKF_MAPPING,
5178 .lkp_data_type = NLA_NESTED
5180 [LNET_NET_LOCAL_NI_ATTR_DROPPED_STATS] = {
5181 .lkp_value = "dropped_stats",
5182 .lkp_key_format = LNKF_MAPPING,
5183 .lkp_data_type = NLA_NESTED
5186 [LNET_NET_LOCAL_NI_ATTR_HEALTH_STATS] = {
5187 .lkp_value = "health stats",
5188 .lkp_key_format = LNKF_MAPPING,
5189 .lkp_data_type = NLA_NESTED
5191 [LNET_NET_LOCAL_NI_ATTR_TUNABLES] = {
5192 .lkp_value = "tunables",
5193 .lkp_key_format = LNKF_MAPPING,
5194 .lkp_data_type = NLA_NESTED
5196 [LNET_NET_LOCAL_NI_ATTR_LND_TUNABLES] = {
5197 .lkp_value = "lnd tunables",
5198 .lkp_key_format = LNKF_MAPPING,
5199 .lkp_data_type = NLA_NESTED
5201 [LNET_NET_LOCAL_NI_DEV_CPT] = {
5202 .lkp_value = "dev cpt",
5203 .lkp_data_type = NLA_S32,
5205 [LNET_NET_LOCAL_NI_CPTS] = {
5207 .lkp_data_type = NLA_STRING,
5212 static const struct ln_key_list local_ni_interfaces_list = {
5213 .lkl_maxattr = LNET_NET_LOCAL_NI_INTF_ATTR_MAX,
5215 [LNET_NET_LOCAL_NI_INTF_ATTR_TYPE] = {
5217 .lkp_data_type = NLA_STRING
5222 static const struct ln_key_list local_ni_stats_list = {
5223 .lkl_maxattr = LNET_NET_LOCAL_NI_STATS_ATTR_MAX,
5225 [LNET_NET_LOCAL_NI_STATS_ATTR_SEND_COUNT] = {
5226 .lkp_value = "send_count",
5227 .lkp_data_type = NLA_U32
5229 [LNET_NET_LOCAL_NI_STATS_ATTR_RECV_COUNT] = {
5230 .lkp_value = "recv_count",
5231 .lkp_data_type = NLA_U32
5233 [LNET_NET_LOCAL_NI_STATS_ATTR_DROP_COUNT] = {
5234 .lkp_value = "drop_count",
5235 .lkp_data_type = NLA_U32
5240 static const struct ln_key_list local_ni_msg_stats_list = {
5241 .lkl_maxattr = LNET_NET_LOCAL_NI_MSG_STATS_ATTR_MAX,
5243 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT] = {
5245 .lkp_data_type = NLA_U32
5247 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT] = {
5249 .lkp_data_type = NLA_U32
5251 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT] = {
5252 .lkp_value = "reply",
5253 .lkp_data_type = NLA_U32
5255 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT] = {
5257 .lkp_data_type = NLA_U32
5259 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT] = {
5260 .lkp_value = "hello",
5261 .lkp_data_type = NLA_U32
5266 static const struct ln_key_list local_ni_health_stats_list = {
5267 .lkl_maxattr = LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_MAX,
5269 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_FATAL_ERRORS] = {
5270 .lkp_value = "fatal_error",
5271 .lkp_data_type = NLA_S32
5273 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_LEVEL] = {
5274 .lkp_value = "health value",
5275 .lkp_data_type = NLA_S32
5277 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_INTERRUPTS] = {
5278 .lkp_value = "interrupts",
5279 .lkp_data_type = NLA_U32
5281 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_DROPPED] = {
5282 .lkp_value = "dropped",
5283 .lkp_data_type = NLA_U32
5285 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ABORTED] = {
5286 .lkp_value = "aborted",
5287 .lkp_data_type = NLA_U32
5289 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NO_ROUTE] = {
5290 .lkp_value = "no route",
5291 .lkp_data_type = NLA_U32
5293 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_TIMEOUTS] = {
5294 .lkp_value = "timeouts",
5295 .lkp_data_type = NLA_U32
5297 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ERROR] = {
5298 .lkp_value = "error",
5299 .lkp_data_type = NLA_U32
5301 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PING_COUNT] = {
5302 .lkp_value = "ping_count",
5303 .lkp_data_type = NLA_U32,
5305 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NEXT_PING] = {
5306 .lkp_value = "next_ping",
5307 .lkp_data_type = NLA_U64
5312 static const struct ln_key_list local_ni_tunables_list = {
5313 .lkl_maxattr = LNET_NET_LOCAL_NI_TUNABLES_ATTR_MAX,
5315 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT] = {
5316 .lkp_value = "peer_timeout",
5317 .lkp_data_type = NLA_S32
5319 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS] = {
5320 .lkp_value = "peer_credits",
5321 .lkp_data_type = NLA_S32
5323 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS] = {
5324 .lkp_value = "peer_buffer_credits",
5325 .lkp_data_type = NLA_S32
5327 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS] = {
5328 .lkp_value = "credits",
5329 .lkp_data_type = NLA_S32
5334 /* Use an index since the traversal is across LNet nets and ni collections */
5335 struct lnet_genl_net_list {
5336 unsigned int lngl_net_id;
5337 unsigned int lngl_idx;
5340 static inline struct lnet_genl_net_list *
5341 lnet_net_dump_ctx(struct netlink_callback *cb)
5343 return (struct lnet_genl_net_list *)cb->args[0];
5346 static int lnet_net_show_done(struct netlink_callback *cb)
5348 struct lnet_genl_net_list *nlist = lnet_net_dump_ctx(cb);
5351 LIBCFS_FREE(nlist, sizeof(*nlist));
5358 /* LNet net ->start() handler for GET requests */
5359 static int lnet_net_show_start(struct netlink_callback *cb)
5361 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
5362 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
5363 struct netlink_ext_ack *extack = NULL;
5365 struct lnet_genl_net_list *nlist;
5366 int msg_len = genlmsg_len(gnlh);
5367 struct nlattr *params, *top;
5370 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
5371 extack = cb->extack;
5373 if (the_lnet.ln_refcount == 0) {
5374 NL_SET_ERR_MSG(extack, "LNet stack down");
5378 LIBCFS_ALLOC(nlist, sizeof(*nlist));
5382 nlist->lngl_net_id = LNET_NET_ANY;
5383 nlist->lngl_idx = 0;
5384 cb->args[0] = (long)nlist;
5389 params = genlmsg_data(gnlh);
5390 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
5391 NL_SET_ERR_MSG(extack, "invalid configuration");
5395 nla_for_each_nested(top, params, rem) {
5399 nla_for_each_nested(net, top, rem2) {
5400 char filter[LNET_NIDSTR_SIZE];
5402 if (nla_type(net) != LN_SCALAR_ATTR_VALUE ||
5403 nla_strcmp(net, "net type") != 0)
5406 net = nla_next(net, &rem2);
5407 if (nla_type(net) != LN_SCALAR_ATTR_VALUE) {
5408 NL_SET_ERR_MSG(extack, "invalid config param");
5409 GOTO(report_err, rc = -EINVAL);
5412 rc = nla_strscpy(filter, net, sizeof(filter));
5414 NL_SET_ERR_MSG(extack, "failed to get param");
5415 GOTO(report_err, rc);
5419 nlist->lngl_net_id = libcfs_str2net(filter);
5420 if (nlist->lngl_net_id == LNET_NET_ANY) {
5421 NL_SET_ERR_MSG(extack, "cannot parse net");
5422 GOTO(report_err, rc = -ENOENT);
5428 lnet_net_show_done(cb);
5433 static int lnet_net_show_dump(struct sk_buff *msg,
5434 struct netlink_callback *cb)
5436 struct lnet_genl_net_list *nlist = lnet_net_dump_ctx(cb);
5437 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
5438 struct netlink_ext_ack *extack = NULL;
5440 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
5441 int portid = NETLINK_CB(cb->skb).portid;
5442 bool found = false, started = true;
5443 const struct lnet_lnd *lnd = NULL;
5444 int idx = nlist->lngl_idx, rc = 0;
5445 int seq = cb->nlh->nlmsg_seq;
5446 struct lnet_net *net;
5449 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
5450 extack = cb->extack;
5452 lnet_net_lock(LNET_LOCK_EX);
5454 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
5455 struct nlattr *local_ni, *ni_attr;
5459 if (nlist->lngl_net_id != LNET_NET_ANY &&
5460 nlist->lngl_net_id != net->net_id)
5463 if (gnlh->version && LNET_NETTYP(net->net_id) != LOLND) {
5464 if (!net->net_lnd) {
5465 NL_SET_ERR_MSG(extack,
5466 "LND not setup for NI");
5467 GOTO(net_unlock, rc = -ENODEV);
5469 if (net->net_lnd != lnd)
5475 /* We need to resend the key table every time the base LND
5479 const struct ln_key_list *all[] = {
5480 &net_props_list, &local_ni_list,
5481 &local_ni_interfaces_list,
5482 &local_ni_stats_list,
5484 &udsp_info_pref_nids_list,
5485 &udsp_info_pref_nids_list,
5486 &local_ni_msg_stats_list,
5487 &local_ni_msg_stats_list,
5488 &local_ni_msg_stats_list,
5489 &local_ni_health_stats_list,
5490 &local_ni_tunables_list,
5491 NULL, /* lnd tunables */
5494 int flags = NLM_F_CREATE | NLM_F_MULTI;
5497 all[ARRAY_SIZE(all) - 2] = lnd->lnd_keys;
5499 flags |= NLM_F_REPLACE;
5503 rc = lnet_genl_send_scalar_list(msg, portid, seq,
5504 &lnet_family, flags,
5505 LNET_CMD_NETS, all);
5507 NL_SET_ERR_MSG(extack, "failed to send key table");
5508 GOTO(net_unlock, rc);
5512 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
5513 NLM_F_MULTI, LNET_CMD_NETS);
5515 NL_SET_ERR_MSG(extack, "failed to send values");
5516 GOTO(net_unlock, rc = -EMSGSIZE);
5520 nla_put_string(msg, LNET_NET_ATTR_HDR, "");
5524 nla_put_string(msg, LNET_NET_ATTR_TYPE,
5525 libcfs_net2str(net->net_id));
5527 local_ni = nla_nest_start(msg, LNET_NET_ATTR_LOCAL);
5528 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
5529 char *status = "up";
5531 if (idx++ < nlist->lngl_idx)
5534 ni_attr = nla_nest_start(msg, dev++);
5537 nla_put_string(msg, LNET_NET_LOCAL_NI_ATTR_NID,
5538 libcfs_nidstr(&ni->ni_nid));
5539 if (!nid_is_lo0(&ni->ni_nid) &&
5540 lnet_ni_get_status_locked(ni) != LNET_NI_STATUS_UP)
5542 nla_put_string(msg, LNET_NET_LOCAL_NI_ATTR_STATUS,
5545 if (!nid_is_lo0(&ni->ni_nid) && ni->ni_interface) {
5546 struct nlattr *intf_nest, *intf_attr;
5548 intf_nest = nla_nest_start(msg,
5549 LNET_NET_LOCAL_NI_ATTR_INTERFACE);
5550 intf_attr = nla_nest_start(msg, 0);
5552 LNET_NET_LOCAL_NI_INTF_ATTR_TYPE,
5554 nla_nest_end(msg, intf_attr);
5555 nla_nest_end(msg, intf_nest);
5558 if (gnlh->version) {
5559 char cpts[LNET_MAX_SHOW_NUM_CPT * 4 + 4], *cpt;
5560 struct lnet_ioctl_element_msg_stats msg_stats;
5561 struct lnet_ioctl_element_stats stats;
5562 size_t buf_len = sizeof(cpts), len;
5563 struct nlattr *health_attr, *health_stats;
5564 struct nlattr *send_attr, *send_stats;
5565 struct nlattr *recv_attr, *recv_stats;
5566 struct nlattr *drop_attr, *drop_stats;
5567 struct nlattr *stats_attr, *ni_stats;
5568 struct nlattr *tun_attr, *ni_tun;
5571 stats.iel_send_count = lnet_sum_stats(&ni->ni_stats,
5572 LNET_STATS_TYPE_SEND);
5573 stats.iel_recv_count = lnet_sum_stats(&ni->ni_stats,
5574 LNET_STATS_TYPE_RECV);
5575 stats.iel_drop_count = lnet_sum_stats(&ni->ni_stats,
5576 LNET_STATS_TYPE_DROP);
5579 stats_attr = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_STATS);
5580 ni_stats = nla_nest_start(msg, 0);
5581 nla_put_u32(msg, LNET_NET_LOCAL_NI_STATS_ATTR_SEND_COUNT,
5582 stats.iel_send_count);
5583 nla_put_u32(msg, LNET_NET_LOCAL_NI_STATS_ATTR_RECV_COUNT,
5584 stats.iel_recv_count);
5585 nla_put_u32(msg, LNET_NET_LOCAL_NI_STATS_ATTR_DROP_COUNT,
5586 stats.iel_drop_count);
5587 nla_nest_end(msg, ni_stats);
5588 nla_nest_end(msg, stats_attr);
5590 if (gnlh->version < 4)
5594 rc = lnet_udsp_info_send(msg, LNET_NET_LOCAL_NI_ATTR_UDSP_INFO,
5595 &ni->ni_nid, false);
5597 NL_SET_ERR_MSG(extack,
5598 "Failed to get udsp info");
5599 genlmsg_cancel(msg, hdr);
5600 GOTO(net_unlock, rc = -ENOMEM);
5603 if (gnlh->version < 2)
5604 goto skip_msg_stats;
5606 msg_stats.im_idx = idx - 1;
5607 rc = lnet_get_ni_stats(&msg_stats);
5609 NL_SET_ERR_MSG(extack,
5610 "failed to get msg stats");
5611 genlmsg_cancel(msg, hdr);
5612 GOTO(net_unlock, rc = -ENOMEM);
5615 send_stats = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_SEND_STATS);
5616 send_attr = nla_nest_start(msg, 0);
5617 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT,
5618 msg_stats.im_send_stats.ico_get_count);
5619 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT,
5620 msg_stats.im_send_stats.ico_put_count);
5621 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT,
5622 msg_stats.im_send_stats.ico_reply_count);
5623 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT,
5624 msg_stats.im_send_stats.ico_ack_count);
5625 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT,
5626 msg_stats.im_send_stats.ico_hello_count);
5627 nla_nest_end(msg, send_attr);
5628 nla_nest_end(msg, send_stats);
5630 recv_stats = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_RECV_STATS);
5631 recv_attr = nla_nest_start(msg, 0);
5632 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT,
5633 msg_stats.im_recv_stats.ico_get_count);
5634 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT,
5635 msg_stats.im_recv_stats.ico_put_count);
5636 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT,
5637 msg_stats.im_recv_stats.ico_reply_count);
5638 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT,
5639 msg_stats.im_recv_stats.ico_ack_count);
5640 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT,
5641 msg_stats.im_recv_stats.ico_hello_count);
5642 nla_nest_end(msg, recv_attr);
5643 nla_nest_end(msg, recv_stats);
5645 drop_stats = nla_nest_start(msg,
5646 LNET_NET_LOCAL_NI_ATTR_DROPPED_STATS);
5647 drop_attr = nla_nest_start(msg, 0);
5648 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT,
5649 msg_stats.im_drop_stats.ico_get_count);
5650 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT,
5651 msg_stats.im_drop_stats.ico_put_count);
5652 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT,
5653 msg_stats.im_drop_stats.ico_reply_count);
5654 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT,
5655 msg_stats.im_drop_stats.ico_ack_count);
5656 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT,
5657 msg_stats.im_drop_stats.ico_hello_count);
5658 nla_nest_end(msg, drop_attr);
5659 nla_nest_end(msg, drop_stats);
5662 health_stats = nla_nest_start(msg,
5663 LNET_NET_LOCAL_NI_ATTR_HEALTH_STATS);
5664 health_attr = nla_nest_start(msg, 0);
5665 nla_put_s32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_FATAL_ERRORS,
5666 atomic_read(&ni->ni_fatal_error_on));
5667 nla_put_s32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_LEVEL,
5668 atomic_read(&ni->ni_healthv));
5669 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_INTERRUPTS,
5670 atomic_read(&ni->ni_hstats.hlt_local_interrupt));
5671 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_DROPPED,
5672 atomic_read(&ni->ni_hstats.hlt_local_dropped));
5673 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ABORTED,
5674 atomic_read(&ni->ni_hstats.hlt_local_aborted));
5675 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NO_ROUTE,
5676 atomic_read(&ni->ni_hstats.hlt_local_no_route));
5677 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_TIMEOUTS,
5678 atomic_read(&ni->ni_hstats.hlt_local_timeout));
5679 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ERROR,
5680 atomic_read(&ni->ni_hstats.hlt_local_error));
5681 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PING_COUNT,
5683 nla_put_u64_64bit(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NEXT_PING,
5685 LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PAD);
5686 nla_nest_end(msg, health_attr);
5687 nla_nest_end(msg, health_stats);
5689 /* Report net tunables */
5690 tun_attr = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_TUNABLES);
5691 ni_tun = nla_nest_start(msg, 0);
5692 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT,
5693 ni->ni_net->net_tunables.lct_peer_timeout);
5694 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS,
5695 ni->ni_net->net_tunables.lct_peer_tx_credits);
5696 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS,
5697 ni->ni_net->net_tunables.lct_peer_rtr_credits);
5698 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS,
5699 ni->ni_net->net_tunables.lct_max_tx_credits);
5700 nla_nest_end(msg, ni_tun);
5702 nla_nest_end(msg, tun_attr);
5704 if (lnd && lnd->lnd_nl_get && lnd->lnd_keys) {
5705 struct nlattr *lnd_tun_attr, *lnd_ni_tun;
5707 lnd_tun_attr = nla_nest_start(msg,
5708 LNET_NET_LOCAL_NI_ATTR_LND_TUNABLES);
5709 lnd_ni_tun = nla_nest_start(msg, 0);
5710 rc = lnd->lnd_nl_get(LNET_CMD_NETS, msg,
5711 LNET_NET_LOCAL_NI_ATTR_LND_TUNABLES,
5714 NL_SET_ERR_MSG(extack,
5715 "failed to get lnd tunables");
5716 genlmsg_cancel(msg, hdr);
5717 GOTO(net_unlock, rc);
5719 nla_nest_end(msg, lnd_ni_tun);
5720 nla_nest_end(msg, lnd_tun_attr);
5723 nla_put_s32(msg, LNET_NET_LOCAL_NI_DEV_CPT, ni->ni_dev_cpt);
5725 /* Report cpts. We could send this as a nested list
5726 * of integers but older versions of the tools
5727 * except a string. The new versions can handle
5728 * both formats so in the future we can change
5729 * this to a nested list.
5731 len = snprintf(cpts, buf_len, "\"[");
5735 if (ni->ni_ncpts == LNET_CPT_NUMBER && !ni->ni_cpts) {
5736 for (j = 0; j < ni->ni_ncpts; j++) {
5737 len = snprintf(cpt, buf_len, "%d,", j);
5743 ni->ni_cpts && j < ni->ni_ncpts &&
5744 j < LNET_MAX_SHOW_NUM_CPT; j++) {
5745 len = snprintf(cpt, buf_len, "%d,",
5751 snprintf(cpt - 1, sizeof(cpts), "]\"");
5753 nla_put_string(msg, LNET_NET_LOCAL_NI_CPTS, cpts);
5757 nla_nest_end(msg, ni_attr);
5759 nla_nest_end(msg, local_ni);
5761 genlmsg_end(msg, hdr);
5765 struct nlmsghdr *nlh = nlmsg_hdr(msg);
5767 nlmsg_cancel(msg, nlh);
5768 NL_SET_ERR_MSG(extack, "Network is down");
5771 nlist->lngl_idx = idx;
5773 lnet_net_unlock(LNET_LOCK_EX);
5775 return lnet_nl_send_error(cb->skb, portid, seq, rc);
5778 #ifndef HAVE_NETLINK_CALLBACK_START
5779 static int lnet_old_net_show_dump(struct sk_buff *msg,
5780 struct netlink_callback *cb)
5783 int rc = lnet_net_show_start(cb);
5786 return lnet_nl_send_error(cb->skb,
5787 NETLINK_CB(cb->skb).portid,
5792 return lnet_net_show_dump(msg, cb);
5796 static int lnet_genl_parse_tunables(struct nlattr *settings,
5797 struct lnet_ioctl_config_lnd_tunables *tun)
5799 struct nlattr *param;
5802 nla_for_each_nested(param, settings, rem) {
5803 int type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_UNSPEC;
5806 if (nla_type(param) != LN_SCALAR_ATTR_VALUE)
5809 if (nla_strcmp(param, "peer_timeout") == 0)
5810 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT;
5811 else if (nla_strcmp(param, "peer_credits") == 0)
5812 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS;
5813 else if (nla_strcmp(param, "peer_buffer_credits") == 0)
5814 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS;
5815 else if (nla_strcmp(param, "credits") == 0)
5816 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS;
5818 param = nla_next(param, &rem);
5819 if (nla_type(param) != LN_SCALAR_ATTR_INT_VALUE)
5822 num = nla_get_s64(param);
5824 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT:
5826 tun->lt_cmn.lct_peer_timeout = num;
5828 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS:
5830 tun->lt_cmn.lct_peer_tx_credits = num;
5832 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS:
5834 tun->lt_cmn.lct_peer_rtr_credits = num;
5836 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS:
5838 tun->lt_cmn.lct_max_tx_credits = num;
5848 static int lnet_genl_parse_lnd_tunables(struct nlattr *settings,
5849 struct lnet_lnd_tunables *tun,
5850 const struct lnet_lnd *lnd)
5852 const struct ln_key_list *list = lnd->lnd_keys;
5853 struct nlattr *param;
5857 /* silently ignore these setting if the LND driver doesn't
5858 * support any LND tunables
5860 if (!list || !lnd->lnd_nl_set || !list->lkl_maxattr)
5863 nla_for_each_nested(param, settings, rem) {
5864 if (nla_type(param) != LN_SCALAR_ATTR_VALUE)
5867 for (i = 1; i <= list->lkl_maxattr; i++) {
5868 if (!list->lkl_list[i].lkp_value ||
5869 nla_strcmp(param, list->lkl_list[i].lkp_value) != 0)
5872 param = nla_next(param, &rem);
5873 rc = lnd->lnd_nl_set(LNET_CMD_NETS, param, i, tun);
5883 lnet_genl_parse_local_ni(struct nlattr *entry, struct genl_info *info,
5884 int net_id, struct lnet_ioctl_config_ni *conf,
5887 bool create = info->nlhdr->nlmsg_flags & NLM_F_CREATE;
5888 struct lnet_ioctl_config_lnd_tunables *tun;
5889 struct nlattr *settings;
5892 LIBCFS_ALLOC(tun, sizeof(struct lnet_ioctl_config_lnd_tunables));
5894 GENL_SET_ERR_MSG(info, "cannot allocate memory for tunables");
5895 GOTO(out, rc = -ENOMEM);
5898 /* Use LND defaults */
5899 tun->lt_cmn.lct_peer_timeout = -1;
5900 tun->lt_cmn.lct_peer_tx_credits = -1;
5901 tun->lt_cmn.lct_peer_rtr_credits = -1;
5902 tun->lt_cmn.lct_max_tx_credits = -1;
5903 conf->lic_ncpts = 0;
5905 nla_for_each_nested(settings, entry, rem3) {
5906 if (nla_type(settings) != LN_SCALAR_ATTR_VALUE)
5909 if (nla_strcmp(settings, "interfaces") == 0) {
5910 struct nlattr *intf;
5913 settings = nla_next(settings, &rem3);
5914 if (nla_type(settings) !=
5915 LN_SCALAR_ATTR_LIST) {
5916 GENL_SET_ERR_MSG(info,
5917 "invalid interfaces");
5918 GOTO(out, rc = -EINVAL);
5921 nla_for_each_nested(intf, settings, rem4) {
5922 intf = nla_next(intf, &rem4);
5923 if (nla_type(intf) !=
5924 LN_SCALAR_ATTR_VALUE) {
5925 GENL_SET_ERR_MSG(info,
5926 "cannot parse interface");
5927 GOTO(out, rc = -EINVAL);
5930 rc = nla_strscpy(conf->lic_ni_intf, intf,
5931 sizeof(conf->lic_ni_intf));
5933 GENL_SET_ERR_MSG(info,
5934 "failed to parse interfaces");
5939 } else if (nla_strcmp(settings, "tunables") == 0) {
5940 settings = nla_next(settings, &rem3);
5941 if (nla_type(settings) !=
5942 LN_SCALAR_ATTR_LIST) {
5943 GENL_SET_ERR_MSG(info,
5944 "invalid tunables");
5945 GOTO(out, rc = -EINVAL);
5948 rc = lnet_genl_parse_tunables(settings, tun);
5950 GENL_SET_ERR_MSG(info,
5951 "failed to parse tunables");
5954 } else if ((nla_strcmp(settings, "lnd tunables") == 0)) {
5955 const struct lnet_lnd *lnd;
5957 lnd = lnet_load_lnd(LNET_NETTYP(net_id));
5959 GENL_SET_ERR_MSG(info,
5960 "LND type not supported");
5961 GOTO(out, rc = PTR_ERR(lnd));
5964 settings = nla_next(settings, &rem3);
5965 if (nla_type(settings) !=
5966 LN_SCALAR_ATTR_LIST) {
5967 GENL_SET_ERR_MSG(info,
5968 "lnd tunables should be list\n");
5969 GOTO(out, rc = -EINVAL);
5972 rc = lnet_genl_parse_lnd_tunables(settings,
5975 GENL_SET_ERR_MSG(info,
5976 "failed to parse lnd tunables");
5979 } else if (nla_strcmp(settings, "CPT") == 0) {
5983 settings = nla_next(settings, &rem3);
5984 if (nla_type(settings) != LN_SCALAR_ATTR_LIST) {
5985 GENL_SET_ERR_MSG(info,
5986 "CPT should be list");
5987 GOTO(out, rc = -EINVAL);
5990 nla_for_each_nested(cpt, settings, rem4) {
5993 if (nla_type(cpt) !=
5994 LN_SCALAR_ATTR_INT_VALUE) {
5995 GENL_SET_ERR_MSG(info,
5996 "invalid CPT config");
5997 GOTO(out, rc = -EINVAL);
6000 core = nla_get_s64(cpt);
6001 if (core >= LNET_CPT_NUMBER) {
6002 GENL_SET_ERR_MSG(info,
6003 "invalid CPT value");
6004 GOTO(out, rc = -ERANGE);
6007 conf->lic_cpts[conf->lic_ncpts] = core;
6014 struct lnet_net *net;
6018 if (!strlen(conf->lic_ni_intf)) {
6019 GENL_SET_ERR_MSG(info,
6020 "interface is missing");
6024 lnet_net_lock(LNET_LOCK_EX);
6025 net = lnet_get_net_locked(net_id);
6027 GENL_SET_ERR_MSG(info,
6028 "LNet net doesn't exist");
6029 lnet_net_unlock(LNET_LOCK_EX);
6033 list_for_each_entry(ni, &net->net_ni_list,
6035 if (!ni->ni_interface ||
6036 strcmp(ni->ni_interface,
6037 conf->lic_ni_intf) != 0)
6040 lnet_net_unlock(LNET_LOCK_EX);
6041 rc = lnet_dyn_del_ni(&ni->ni_nid);
6043 GENL_SET_ERR_MSG(info,
6044 "cannot del LNet NI");
6050 if (rc < 0) { /* will be -ENODEV */
6051 GENL_SET_ERR_MSG(info,
6052 "interface invalid for deleting LNet NI");
6053 lnet_net_unlock(LNET_LOCK_EX);
6056 if (!strlen(conf->lic_ni_intf)) {
6057 GENL_SET_ERR_MSG(info,
6058 "interface is missing");
6062 rc = lnet_dyn_add_ni(conf, net_id, tun);
6065 GENL_SET_ERR_MSG(info,
6066 "cannot parse net");
6069 GENL_SET_ERR_MSG(info,
6073 GENL_SET_ERR_MSG(info,
6074 "cannot add LNet NI");
6081 LIBCFS_FREE(tun, sizeof(struct lnet_ioctl_config_lnd_tunables));
6086 static int lnet_net_cmd(struct sk_buff *skb, struct genl_info *info)
6088 struct nlmsghdr *nlh = nlmsg_hdr(skb);
6089 struct genlmsghdr *gnlh = nlmsg_data(nlh);
6090 struct nlattr *params = genlmsg_data(gnlh);
6091 int msg_len, rem, rc = 0;
6092 struct nlattr *attr;
6094 msg_len = genlmsg_len(gnlh);
6096 GENL_SET_ERR_MSG(info, "no configuration");
6100 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
6101 GENL_SET_ERR_MSG(info, "invalid configuration");
6105 nla_for_each_nested(attr, params, rem) {
6106 bool ni_list = false, ipnets = false;
6107 struct lnet_ioctl_config_ni conf;
6108 u32 net_id = LNET_NET_ANY;
6109 struct nlattr *entry;
6112 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
6115 nla_for_each_nested(entry, attr, rem2) {
6116 switch (nla_type(entry)) {
6117 case LN_SCALAR_ATTR_VALUE: {
6120 memset(&conf, 0, sizeof(conf));
6121 if (nla_strcmp(entry, "ip2net") == 0) {
6122 entry = nla_next(entry, &rem2);
6123 if (nla_type(entry) !=
6124 LN_SCALAR_ATTR_VALUE) {
6125 GENL_SET_ERR_MSG(info,
6126 "ip2net has invalid key");
6127 GOTO(out, rc = -EINVAL);
6130 len = nla_strscpy(conf.lic_legacy_ip2nets,
6132 sizeof(conf.lic_legacy_ip2nets));
6134 GENL_SET_ERR_MSG(info,
6135 "ip2net key string is invalid");
6136 GOTO(out, rc = len);
6140 } else if (nla_strcmp(entry, "net type") == 0) {
6141 char tmp[LNET_NIDSTR_SIZE];
6143 entry = nla_next(entry, &rem2);
6144 if (nla_type(entry) !=
6145 LN_SCALAR_ATTR_VALUE) {
6146 GENL_SET_ERR_MSG(info,
6147 "net type has invalid key");
6148 GOTO(out, rc = -EINVAL);
6151 len = nla_strscpy(tmp, entry,
6154 GENL_SET_ERR_MSG(info,
6155 "net type key string is invalid");
6156 GOTO(out, rc = len);
6159 net_id = libcfs_str2net(tmp);
6161 GENL_SET_ERR_MSG(info,
6162 "cannot parse net");
6163 GOTO(out, rc = -ENODEV);
6165 if (LNET_NETTYP(net_id) == LOLND) {
6166 GENL_SET_ERR_MSG(info,
6167 "setting @lo not allowed");
6168 GOTO(out, rc = -ENODEV);
6170 conf.lic_legacy_ip2nets[0] = '\0';
6171 conf.lic_ni_intf[0] = '\0';
6178 case LN_SCALAR_ATTR_LIST: {
6179 struct nlattr *interface;
6183 nla_for_each_nested(interface, entry, rem3) {
6184 rc = lnet_genl_parse_local_ni(interface, info,
6192 /* it is possible a newer version of the user land send
6193 * values older kernels doesn't handle. So silently
6194 * ignore these values
6201 /* Handle case of just sent NET with no list of NIDs */
6202 if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE) && !ni_list) {
6203 rc = lnet_dyn_del_net(net_id);
6205 GENL_SET_ERR_MSG(info,
6206 "cannot del network");
6208 } else if ((info->nlhdr->nlmsg_flags & NLM_F_CREATE) &&
6209 ipnets && ni_list) {
6210 rc = lnet_handle_legacy_ip2nets(conf.lic_legacy_ip2nets,
6213 GENL_SET_ERR_MSG(info,
6214 "cannot setup ip2nets");
6221 /* Called with ln_api_mutex */
6222 static int lnet_parse_peer_nis(struct nlattr *rlist, struct genl_info *info,
6223 struct lnet_nid *pnid, bool mr,
6226 struct lnet_nid snid = LNET_ANY_NID;
6227 struct nlattr *props;
6231 nla_for_each_nested(props, rlist, rem) {
6232 if (nla_type(props) != LN_SCALAR_ATTR_VALUE)
6235 if (nla_strcmp(props, "nid") == 0) {
6236 char nidstr[LNET_NIDSTR_SIZE];
6238 props = nla_next(props, &rem);
6239 if (nla_type(props) != LN_SCALAR_ATTR_VALUE) {
6240 GENL_SET_ERR_MSG(info,
6241 "invalid secondary NID");
6242 GOTO(report_err, rc = -EINVAL);
6245 rc = nla_strscpy(nidstr, props, sizeof(nidstr));
6247 GENL_SET_ERR_MSG(info,
6248 "failed to get secondary NID");
6249 GOTO(report_err, rc);
6252 rc = libcfs_strnid(&snid, strim(nidstr));
6254 GENL_SET_ERR_MSG(info, "unsupported secondary NID");
6255 GOTO(report_err, rc);
6258 if (LNET_NID_IS_ANY(&snid) || nid_same(&snid, pnid))
6259 *create_some = false;
6260 } else if (nla_strcmp(props, "health stats") == 0) {
6261 struct nlattr *health;
6264 props = nla_next(props, &rem);
6265 if (nla_type(props) !=
6266 LN_SCALAR_ATTR_LIST) {
6267 GENL_SET_ERR_MSG(info,
6268 "invalid health configuration");
6269 GOTO(report_err, rc = -EINVAL);
6272 nla_for_each_nested(health, props, rem2) {
6273 if (nla_type(health) != LN_SCALAR_ATTR_VALUE ||
6274 nla_strcmp(health, "health value") != 0) {
6275 GENL_SET_ERR_MSG(info,
6276 "wrong health config format");
6277 GOTO(report_err, rc = -EINVAL);
6280 health = nla_next(health, &rem2);
6281 if (nla_type(health) !=
6282 LN_SCALAR_ATTR_INT_VALUE) {
6283 GENL_SET_ERR_MSG(info,
6284 "invalid health config format");
6285 GOTO(report_err, rc = -EINVAL);
6288 num = nla_get_s64(health);
6289 clamp_t(s64, num, 0, LNET_MAX_HEALTH_VALUE);
6294 if (info->nlhdr->nlmsg_flags & NLM_F_REPLACE && num != -1) {
6295 lnet_peer_ni_set_healthv(pnid, num, !*create_some);
6296 } else if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
6297 bool lock_prim = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6299 rc = lnet_user_add_peer_ni(pnid, &snid, mr, lock_prim);
6301 GENL_SET_ERR_MSG(info,
6302 "failed to add peer");
6303 } else if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE) && *create_some) {
6304 bool force = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6306 rc = lnet_del_peer_ni(pnid, &snid, force);
6308 GENL_SET_ERR_MSG(info,
6309 "failed to del peer");
6315 static int lnet_peer_ni_cmd(struct sk_buff *skb, struct genl_info *info)
6317 struct nlmsghdr *nlh = nlmsg_hdr(skb);
6318 struct genlmsghdr *gnlh = nlmsg_data(nlh);
6319 struct nlattr *params = genlmsg_data(gnlh);
6320 int msg_len, rem, rc = 0;
6321 struct lnet_nid pnid;
6322 struct nlattr *attr;
6324 mutex_lock(&the_lnet.ln_api_mutex);
6325 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
6326 GENL_SET_ERR_MSG(info, "Network is down");
6327 mutex_unlock(&the_lnet.ln_api_mutex);
6331 msg_len = genlmsg_len(gnlh);
6333 GENL_SET_ERR_MSG(info, "no configuration");
6334 mutex_unlock(&the_lnet.ln_api_mutex);
6338 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
6339 GENL_SET_ERR_MSG(info, "invalid configuration");
6340 mutex_unlock(&the_lnet.ln_api_mutex);
6344 nla_for_each_nested(attr, params, rem) {
6345 bool parse_peer_nis = false;
6346 struct nlattr *pnid_prop;
6349 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
6352 pnid = LNET_ANY_NID;
6353 nla_for_each_nested(pnid_prop, attr, rem2) {
6356 if (nla_type(pnid_prop) != LN_SCALAR_ATTR_VALUE)
6359 if (nla_strcmp(pnid_prop, "primary nid") == 0) {
6360 char nidstr[LNET_NIDSTR_SIZE];
6362 pnid_prop = nla_next(pnid_prop, &rem2);
6363 if (nla_type(pnid_prop) !=
6364 LN_SCALAR_ATTR_VALUE) {
6365 GENL_SET_ERR_MSG(info,
6366 "invalid primary NID type");
6367 GOTO(report_err, rc = -EINVAL);
6370 rc = nla_strscpy(nidstr, pnid_prop,
6373 GENL_SET_ERR_MSG(info,
6374 "failed to get primary NID");
6375 GOTO(report_err, rc);
6378 rc = libcfs_strnid(&pnid, strim(nidstr));
6380 GENL_SET_ERR_MSG(info,
6381 "unsupported primary NID");
6382 GOTO(report_err, rc);
6385 /* we must create primary NID for peer ni
6388 if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
6391 lock_prim = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6392 rc = lnet_user_add_peer_ni(&pnid,
6396 GENL_SET_ERR_MSG(info,
6397 "failed to add primary peer");
6398 GOTO(report_err, rc);
6401 } else if (nla_strcmp(pnid_prop, "Multi-Rail") == 0) {
6402 pnid_prop = nla_next(pnid_prop, &rem2);
6403 if (nla_type(pnid_prop) !=
6404 LN_SCALAR_ATTR_INT_VALUE) {
6405 GENL_SET_ERR_MSG(info,
6406 "invalid MR flag param");
6407 GOTO(report_err, rc = -EINVAL);
6410 if (nla_get_s64(pnid_prop) == 0)
6412 } else if (nla_strcmp(pnid_prop, "peer state") == 0) {
6413 struct lnet_peer_ni *lpni;
6414 struct lnet_peer *lp;
6416 pnid_prop = nla_next(pnid_prop, &rem2);
6417 if (nla_type(pnid_prop) !=
6418 LN_SCALAR_ATTR_INT_VALUE) {
6419 GENL_SET_ERR_MSG(info,
6420 "invalid peer state param");
6421 GOTO(report_err, rc = -EINVAL);
6424 lpni = lnet_peer_ni_find_locked(&pnid);
6426 GENL_SET_ERR_MSG(info,
6427 "invalid peer state param");
6428 GOTO(report_err, rc = -ENOENT);
6430 lnet_peer_ni_decref_locked(lpni);
6431 lp = lpni->lpni_peer_net->lpn_peer;
6432 lp->lp_state = nla_get_s64(pnid_prop);
6433 } else if (nla_strcmp(pnid_prop, "peer ni") == 0) {
6434 struct nlattr *rlist;
6437 if (!(info->nlhdr->nlmsg_flags & NLM_F_REPLACE) &&
6438 LNET_NID_IS_ANY(&pnid)) {
6439 GENL_SET_ERR_MSG(info,
6440 "missing required primary NID");
6441 GOTO(report_err, rc);
6444 pnid_prop = nla_next(pnid_prop, &rem2);
6445 if (nla_type(pnid_prop) !=
6446 LN_SCALAR_ATTR_LIST) {
6447 GENL_SET_ERR_MSG(info,
6448 "invalid NIDs list");
6449 GOTO(report_err, rc = -EINVAL);
6452 parse_peer_nis = true;
6453 nla_for_each_nested(rlist, pnid_prop, rem3) {
6454 rc = lnet_parse_peer_nis(rlist, info,
6458 GOTO(report_err, rc);
6463 /* If we have remote peer ni's we already add /del peers */
6467 if (LNET_NID_IS_ANY(&pnid)) {
6468 GENL_SET_ERR_MSG(info, "missing primary NID");
6469 GOTO(report_err, rc);
6472 if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE)) {
6473 bool force = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6475 rc = lnet_del_peer_ni(&pnid, &LNET_ANY_NID,
6478 GENL_SET_ERR_MSG(info,
6479 "failed to del primary peer");
6480 GOTO(report_err, rc);
6485 /* If we failed on creation and encounter a latter error then
6486 * delete the primary nid.
6488 if (rc < 0 && info->nlhdr->nlmsg_flags & NLM_F_CREATE &&
6489 !LNET_NID_IS_ANY(&pnid))
6490 lnet_del_peer_ni(&pnid, &LNET_ANY_NID,
6491 info->nlhdr->nlmsg_flags & NLM_F_EXCL);
6492 mutex_unlock(&the_lnet.ln_api_mutex);
6497 /** LNet route handling */
6499 /* We can't use struct lnet_ioctl_config_data since it lacks
6500 * support for large NIDS
6502 struct lnet_route_properties {
6503 struct lnet_nid lrp_gateway;
6508 u32 lrp_sensitivity;
6511 struct lnet_genl_route_list {
6512 unsigned int lgrl_index;
6513 unsigned int lgrl_count;
6514 GENRADIX(struct lnet_route_properties) lgrl_list;
6517 static inline struct lnet_genl_route_list *
6518 lnet_route_dump_ctx(struct netlink_callback *cb)
6520 return (struct lnet_genl_route_list *)cb->args[0];
6523 static int lnet_route_show_done(struct netlink_callback *cb)
6525 struct lnet_genl_route_list *rlist = lnet_route_dump_ctx(cb);
6528 genradix_free(&rlist->lgrl_list);
6529 CFS_FREE_PTR(rlist);
6536 static int lnet_scan_route(struct lnet_genl_route_list *rlist,
6537 struct lnet_route_properties *settings)
6539 struct lnet_remotenet *rnet;
6540 struct list_head *rn_list;
6541 struct lnet_route *route;
6544 cpt = lnet_net_lock_current();
6546 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
6547 rn_list = &the_lnet.ln_remote_nets_hash[i];
6548 list_for_each_entry(rnet, rn_list, lrn_list) {
6549 if (settings->lrp_net != LNET_NET_ANY &&
6550 settings->lrp_net != rnet->lrn_net)
6553 list_for_each_entry(route, &rnet->lrn_routes,
6555 struct lnet_route_properties *prop;
6557 if (!LNET_NID_IS_ANY(&settings->lrp_gateway) &&
6558 !nid_same(&settings->lrp_gateway,
6563 if (settings->lrp_hop != -1 &&
6564 settings->lrp_hop != route->lr_hops)
6567 if (settings->lrp_priority != -1 &&
6568 settings->lrp_priority != route->lr_priority)
6571 if (settings->lrp_sensitivity != -1 &&
6572 settings->lrp_sensitivity !=
6573 route->lr_gateway->lp_health_sensitivity)
6576 prop = genradix_ptr_alloc(&rlist->lgrl_list,
6577 rlist->lgrl_count++,
6580 GOTO(failed_alloc, rc = -ENOMEM);
6582 prop->lrp_net = rnet->lrn_net;
6583 prop->lrp_gateway = route->lr_nid;
6584 prop->lrp_hop = route->lr_hops;
6585 prop->lrp_priority = route->lr_priority;
6586 prop->lrp_sensitivity =
6587 route->lr_gateway->lp_health_sensitivity;
6588 if (lnet_is_route_alive(route))
6589 prop->lrp_flags |= LNET_RT_ALIVE;
6591 prop->lrp_flags &= ~LNET_RT_ALIVE;
6592 if (route->lr_single_hop)
6593 prop->lrp_flags &= ~LNET_RT_MULTI_HOP;
6595 prop->lrp_flags |= LNET_RT_MULTI_HOP;
6601 lnet_net_unlock(cpt);
6605 /* LNet route ->start() handler for GET requests */
6606 static int lnet_route_show_start(struct netlink_callback *cb)
6608 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
6609 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
6610 struct netlink_ext_ack *extack = NULL;
6612 struct lnet_genl_route_list *rlist;
6613 int msg_len = genlmsg_len(gnlh);
6616 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
6617 extack = cb->extack;
6619 if (the_lnet.ln_refcount == 0 ||
6620 the_lnet.ln_state != LNET_STATE_RUNNING) {
6621 NL_SET_ERR_MSG(extack, "Network is down");
6625 CFS_ALLOC_PTR(rlist);
6627 NL_SET_ERR_MSG(extack, "No memory for route list");
6631 genradix_init(&rlist->lgrl_list);
6632 rlist->lgrl_count = 0;
6633 rlist->lgrl_index = 0;
6634 cb->args[0] = (long)rlist;
6636 mutex_lock(&the_lnet.ln_api_mutex);
6638 struct lnet_route_properties tmp = {
6639 .lrp_gateway = LNET_ANY_NID,
6640 .lrp_net = LNET_NET_ANY,
6643 .lrp_sensitivity = -1,
6646 rc = lnet_scan_route(rlist, &tmp);
6648 NL_SET_ERR_MSG(extack,
6649 "failed to allocate router data");
6650 GOTO(report_err, rc);
6653 struct nlattr *params = genlmsg_data(gnlh);
6654 struct nlattr *attr;
6657 nla_for_each_nested(attr, params, rem) {
6658 struct lnet_route_properties tmp = {
6659 .lrp_gateway = LNET_ANY_NID,
6660 .lrp_net = LNET_NET_ANY,
6663 .lrp_sensitivity = -1,
6665 struct nlattr *route;
6668 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
6671 nla_for_each_nested(route, attr, rem2) {
6672 if (nla_type(route) != LN_SCALAR_ATTR_VALUE)
6675 if (nla_strcmp(route, "net") == 0) {
6676 char nw[LNET_NIDSTR_SIZE];
6678 route = nla_next(route, &rem2);
6679 if (nla_type(route) !=
6680 LN_SCALAR_ATTR_VALUE) {
6681 NL_SET_ERR_MSG(extack,
6682 "invalid net param");
6683 GOTO(report_err, rc = -EINVAL);
6686 rc = nla_strscpy(nw, route, sizeof(nw));
6688 NL_SET_ERR_MSG(extack,
6689 "failed to get route param");
6690 GOTO(report_err, rc);
6693 tmp.lrp_net = libcfs_str2net(strim(nw));
6694 } else if (nla_strcmp(route, "gateway") == 0) {
6695 char gw[LNET_NIDSTR_SIZE];
6697 route = nla_next(route, &rem2);
6698 if (nla_type(route) !=
6699 LN_SCALAR_ATTR_VALUE) {
6700 NL_SET_ERR_MSG(extack,
6701 "invalid gateway param");
6702 GOTO(report_err, rc = -EINVAL);
6705 rc = nla_strscpy(gw, route, sizeof(gw));
6707 NL_SET_ERR_MSG(extack,
6708 "failed to get route param");
6709 GOTO(report_err, rc);
6712 rc = libcfs_strnid(&tmp.lrp_gateway, strim(gw));
6714 NL_SET_ERR_MSG(extack,
6715 "cannot parse gateway");
6716 GOTO(report_err, rc = -ENODEV);
6719 } else if (nla_strcmp(route, "hop") == 0) {
6720 route = nla_next(route, &rem2);
6721 if (nla_type(route) !=
6722 LN_SCALAR_ATTR_INT_VALUE) {
6723 NL_SET_ERR_MSG(extack,
6724 "invalid hop param");
6725 GOTO(report_err, rc = -EINVAL);
6728 tmp.lrp_hop = nla_get_s64(route);
6729 if (tmp.lrp_hop != -1)
6730 clamp_t(s32, tmp.lrp_hop, 1, 127);
6731 } else if (nla_strcmp(route, "priority") == 0) {
6732 route = nla_next(route, &rem2);
6733 if (nla_type(route) !=
6734 LN_SCALAR_ATTR_INT_VALUE) {
6735 NL_SET_ERR_MSG(extack,
6736 "invalid priority param");
6737 GOTO(report_err, rc = -EINVAL);
6740 tmp.lrp_priority = nla_get_s64(route);
6744 rc = lnet_scan_route(rlist, &tmp);
6746 NL_SET_ERR_MSG(extack,
6747 "failed to allocate router data");
6748 GOTO(report_err, rc);
6753 mutex_unlock(&the_lnet.ln_api_mutex);
6756 lnet_route_show_done(cb);
6761 static const struct ln_key_list route_props_list = {
6762 .lkl_maxattr = LNET_ROUTE_ATTR_MAX,
6764 [LNET_ROUTE_ATTR_HDR] = {
6765 .lkp_value = "route",
6766 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
6767 .lkp_data_type = NLA_NUL_STRING,
6769 [LNET_ROUTE_ATTR_NET] = {
6771 .lkp_data_type = NLA_STRING
6773 [LNET_ROUTE_ATTR_GATEWAY] = {
6774 .lkp_value = "gateway",
6775 .lkp_data_type = NLA_STRING
6777 [LNET_ROUTE_ATTR_HOP] = {
6779 .lkp_data_type = NLA_S32
6781 [LNET_ROUTE_ATTR_PRIORITY] = {
6782 .lkp_value = "priority",
6783 .lkp_data_type = NLA_U32
6785 [LNET_ROUTE_ATTR_HEALTH_SENSITIVITY] = {
6786 .lkp_value = "health_sensitivity",
6787 .lkp_data_type = NLA_U32
6789 [LNET_ROUTE_ATTR_STATE] = {
6790 .lkp_value = "state",
6791 .lkp_data_type = NLA_STRING,
6793 [LNET_ROUTE_ATTR_TYPE] = {
6794 .lkp_value = "type",
6795 .lkp_data_type = NLA_STRING,
6801 static int lnet_route_show_dump(struct sk_buff *msg,
6802 struct netlink_callback *cb)
6804 struct lnet_genl_route_list *rlist = lnet_route_dump_ctx(cb);
6805 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
6806 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
6807 struct netlink_ext_ack *extack = NULL;
6809 int portid = NETLINK_CB(cb->skb).portid;
6810 int seq = cb->nlh->nlmsg_seq;
6811 int idx = rlist->lgrl_index;
6812 int msg_len = genlmsg_len(gnlh);
6815 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
6816 extack = cb->extack;
6818 if (!rlist->lgrl_count) {
6819 NL_SET_ERR_MSG(extack, "No routes found");
6820 GOTO(send_error, rc = msg_len ? -ENOENT : 0);
6824 const struct ln_key_list *all[] = {
6825 &route_props_list, NULL
6828 rc = lnet_genl_send_scalar_list(msg, portid, seq,
6830 NLM_F_CREATE | NLM_F_MULTI,
6831 LNET_CMD_ROUTES, all);
6833 NL_SET_ERR_MSG(extack, "failed to send key table");
6834 GOTO(send_error, rc);
6838 while (idx < rlist->lgrl_count) {
6839 struct lnet_route_properties *prop;
6842 prop = genradix_ptr(&rlist->lgrl_list, idx++);
6844 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
6845 NLM_F_MULTI, LNET_CMD_ROUTES);
6847 NL_SET_ERR_MSG(extack, "failed to send values");
6848 genlmsg_cancel(msg, hdr);
6849 GOTO(send_error, rc = -EMSGSIZE);
6853 nla_put_string(msg, LNET_ROUTE_ATTR_HDR, "");
6855 nla_put_string(msg, LNET_ROUTE_ATTR_NET,
6856 libcfs_net2str(prop->lrp_net));
6857 nla_put_string(msg, LNET_ROUTE_ATTR_GATEWAY,
6858 libcfs_nidstr(&prop->lrp_gateway));
6859 if (gnlh->version) {
6860 nla_put_s32(msg, LNET_ROUTE_ATTR_HOP, prop->lrp_hop);
6861 nla_put_u32(msg, LNET_ROUTE_ATTR_PRIORITY, prop->lrp_priority);
6862 nla_put_u32(msg, LNET_ROUTE_ATTR_HEALTH_SENSITIVITY,
6863 prop->lrp_sensitivity);
6865 nla_put_string(msg, LNET_ROUTE_ATTR_STATE,
6866 prop->lrp_flags & LNET_RT_ALIVE ?
6868 nla_put_string(msg, LNET_ROUTE_ATTR_TYPE,
6869 prop->lrp_flags & LNET_RT_MULTI_HOP ?
6870 "multi-hop" : "single-hop");
6872 genlmsg_end(msg, hdr);
6874 rlist->lgrl_index = idx;
6876 return lnet_nl_send_error(cb->skb, portid, seq, rc);
6879 #ifndef HAVE_NETLINK_CALLBACK_START
6880 static int lnet_old_route_show_dump(struct sk_buff *msg,
6881 struct netlink_callback *cb)
6884 int rc = lnet_route_show_start(cb);
6887 return lnet_nl_send_error(cb->skb,
6888 NETLINK_CB(cb->skb).portid,
6893 return lnet_route_show_dump(msg, cb);
6895 #endif /* !HAVE_NETLINK_CALLBACK_START */
6897 /** LNet peer handling */
6898 struct lnet_genl_processid_list {
6899 unsigned int lgpl_index;
6900 unsigned int lgpl_count;
6901 GENRADIX(struct lnet_processid) lgpl_list;
6904 static inline struct lnet_genl_processid_list *
6905 lnet_peer_dump_ctx(struct netlink_callback *cb)
6907 return (struct lnet_genl_processid_list *)cb->args[0];
6910 static int lnet_peer_ni_show_done(struct netlink_callback *cb)
6912 struct lnet_genl_processid_list *plist = lnet_peer_dump_ctx(cb);
6915 genradix_free(&plist->lgpl_list);
6916 CFS_FREE_PTR(plist);
6923 /* LNet peer ->start() handler for GET requests */
6924 static int lnet_peer_ni_show_start(struct netlink_callback *cb)
6926 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
6927 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
6928 struct netlink_ext_ack *extack = NULL;
6930 struct lnet_genl_processid_list *plist;
6931 int msg_len = genlmsg_len(gnlh);
6934 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
6935 extack = cb->extack;
6937 mutex_lock(&the_lnet.ln_api_mutex);
6938 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
6939 NL_SET_ERR_MSG(extack, "Network is down");
6940 mutex_unlock(&the_lnet.ln_api_mutex);
6944 CFS_ALLOC_PTR(plist);
6946 NL_SET_ERR_MSG(extack, "No memory for peer list");
6947 mutex_unlock(&the_lnet.ln_api_mutex);
6951 genradix_init(&plist->lgpl_list);
6952 plist->lgpl_count = 0;
6953 plist->lgpl_index = 0;
6954 cb->args[0] = (long)plist;
6957 struct lnet_peer_table *ptable;
6960 cfs_percpt_for_each(ptable, cpt, the_lnet.ln_peer_tables) {
6961 struct lnet_peer *lp;
6963 list_for_each_entry(lp, &ptable->pt_peer_list,
6965 struct lnet_processid *lpi;
6967 lpi = genradix_ptr_alloc(&plist->lgpl_list,
6968 plist->lgpl_count++,
6971 NL_SET_ERR_MSG(extack,
6972 "failed to allocate NID");
6973 GOTO(report_err, rc = -ENOMEM);
6976 lpi->pid = LNET_PID_LUSTRE;
6977 lpi->nid = lp->lp_primary_nid;
6981 struct nlattr *params = genlmsg_data(gnlh);
6982 struct nlattr *attr;
6985 nla_for_each_nested(attr, params, rem) {
6989 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
6992 nla_for_each_nested(nid, attr, rem2) {
6993 char addr[LNET_NIDSTR_SIZE];
6994 struct lnet_processid *id;
6996 if (nla_type(nid) != LN_SCALAR_ATTR_VALUE ||
6997 nla_strcmp(nid, "primary nid") != 0)
7000 nid = nla_next(nid, &rem2);
7001 if (nla_type(nid) != LN_SCALAR_ATTR_VALUE) {
7002 NL_SET_ERR_MSG(extack,
7003 "invalid primary nid param");
7004 GOTO(report_err, rc = -EINVAL);
7007 rc = nla_strscpy(addr, nid, sizeof(addr));
7009 NL_SET_ERR_MSG(extack,
7010 "failed to get primary nid param");
7011 GOTO(report_err, rc);
7014 id = genradix_ptr_alloc(&plist->lgpl_list,
7015 plist->lgpl_count++,
7018 NL_SET_ERR_MSG(extack, "failed to allocate NID");
7019 GOTO(report_err, rc = -ENOMEM);
7022 rc = libcfs_strid(id, strim(addr));
7024 NL_SET_ERR_MSG(extack, "invalid NID");
7025 GOTO(report_err, rc);
7032 mutex_unlock(&the_lnet.ln_api_mutex);
7035 lnet_peer_ni_show_done(cb);
7040 static const struct ln_key_list lnet_peer_ni_keys = {
7041 .lkl_maxattr = LNET_PEER_NI_ATTR_MAX,
7043 [LNET_PEER_NI_ATTR_HDR] = {
7044 .lkp_value = "peer",
7045 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
7046 .lkp_data_type = NLA_NUL_STRING,
7048 [LNET_PEER_NI_ATTR_PRIMARY_NID] = {
7049 .lkp_value = "primary nid",
7050 .lkp_data_type = NLA_STRING,
7052 [LNET_PEER_NI_ATTR_MULTIRAIL] = {
7053 .lkp_value = "Multi-Rail",
7054 .lkp_data_type = NLA_FLAG
7056 [LNET_PEER_NI_ATTR_STATE] = {
7057 .lkp_value = "peer state",
7058 .lkp_data_type = NLA_U32
7060 [LNET_PEER_NI_ATTR_PEER_NI_LIST] = {
7061 .lkp_value = "peer ni",
7062 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
7063 .lkp_data_type = NLA_NESTED,
7068 static const struct ln_key_list lnet_peer_ni_list = {
7069 .lkl_maxattr = LNET_PEER_NI_LIST_ATTR_MAX,
7071 [LNET_PEER_NI_LIST_ATTR_NID] = {
7073 .lkp_data_type = NLA_STRING,
7075 [LNET_PEER_NI_LIST_ATTR_UDSP_INFO] = {
7076 .lkp_value = "udsp info",
7077 .lkp_key_format = LNKF_MAPPING,
7078 .lkp_data_type = NLA_NESTED,
7080 [LNET_PEER_NI_LIST_ATTR_STATE] = {
7081 .lkp_value = "state",
7082 .lkp_data_type = NLA_STRING,
7084 [LNET_PEER_NI_LIST_ATTR_MAX_TX_CREDITS] = {
7085 .lkp_value = "max_ni_tx_credits",
7086 .lkp_data_type = NLA_U32,
7088 [LNET_PEER_NI_LIST_ATTR_CUR_TX_CREDITS] = {
7089 .lkp_value = "available_tx_credits",
7090 .lkp_data_type = NLA_U32,
7092 [LNET_PEER_NI_LIST_ATTR_MIN_TX_CREDITS] = {
7093 .lkp_value = "min_tx_credits",
7094 .lkp_data_type = NLA_U32,
7096 [LNET_PEER_NI_LIST_ATTR_QUEUE_BUF_COUNT] = {
7097 .lkp_value = "tx_q_num_of_buf",
7098 .lkp_data_type = NLA_U32,
7100 [LNET_PEER_NI_LIST_ATTR_CUR_RTR_CREDITS] = {
7101 .lkp_value = "available_rtr_credits",
7102 .lkp_data_type = NLA_U32,
7104 [LNET_PEER_NI_LIST_ATTR_MIN_RTR_CREDITS] = {
7105 .lkp_value = "min_rtr_credits",
7106 .lkp_data_type = NLA_U32,
7108 [LNET_PEER_NI_LIST_ATTR_REFCOUNT] = {
7109 .lkp_value = "refcount",
7110 .lkp_data_type = NLA_U32,
7112 [LNET_PEER_NI_LIST_ATTR_STATS_COUNT] = {
7113 .lkp_value = "statistics",
7114 .lkp_key_format = LNKF_MAPPING,
7115 .lkp_data_type = NLA_NESTED
7117 [LNET_PEER_NI_LIST_ATTR_SENT_STATS] = {
7118 .lkp_value = "sent_stats",
7119 .lkp_key_format = LNKF_MAPPING,
7120 .lkp_data_type = NLA_NESTED
7122 [LNET_PEER_NI_LIST_ATTR_RECV_STATS] = {
7123 .lkp_value = "received_stats",
7124 .lkp_key_format = LNKF_MAPPING,
7125 .lkp_data_type = NLA_NESTED
7127 [LNET_PEER_NI_LIST_ATTR_DROP_STATS] = {
7128 .lkp_value = "dropped_stats",
7129 .lkp_key_format = LNKF_MAPPING,
7130 .lkp_data_type = NLA_NESTED
7132 [LNET_PEER_NI_LIST_ATTR_HEALTH_STATS] = {
7133 .lkp_value = "health stats",
7134 .lkp_key_format = LNKF_MAPPING,
7135 .lkp_data_type = NLA_NESTED
7140 static const struct ln_key_list lnet_peer_ni_list_stats_count = {
7141 .lkl_maxattr = LNET_PEER_NI_LIST_STATS_COUNT_ATTR_MAX,
7143 [LNET_PEER_NI_LIST_STATS_COUNT_ATTR_SEND_COUNT] = {
7144 .lkp_value = "send_count",
7145 .lkp_data_type = NLA_U32,
7147 [LNET_PEER_NI_LIST_STATS_COUNT_ATTR_RECV_COUNT] = {
7148 .lkp_value = "recv_count",
7149 .lkp_data_type = NLA_U32,
7151 [LNET_PEER_NI_LIST_STATS_COUNT_ATTR_DROP_COUNT] = {
7152 .lkp_value = "drop_count",
7153 .lkp_data_type = NLA_U32,
7158 static const struct ln_key_list lnet_peer_ni_list_stats = {
7159 .lkl_maxattr = LNET_PEER_NI_LIST_STATS_ATTR_MAX,
7161 [LNET_PEER_NI_LIST_STATS_ATTR_PUT] = {
7163 .lkp_data_type = NLA_U32,
7165 [LNET_PEER_NI_LIST_STATS_ATTR_GET] = {
7167 .lkp_data_type = NLA_U32,
7169 [LNET_PEER_NI_LIST_STATS_ATTR_REPLY] = {
7170 .lkp_value = "reply",
7171 .lkp_data_type = NLA_U32,
7173 [LNET_PEER_NI_LIST_STATS_ATTR_ACK] = {
7175 .lkp_data_type = NLA_U32,
7177 [LNET_PEER_NI_LIST_STATS_ATTR_HELLO] = {
7178 .lkp_value = "hello",
7179 .lkp_data_type = NLA_U32,
7184 static const struct ln_key_list lnet_peer_ni_list_health = {
7185 .lkl_maxattr = LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_MAX,
7187 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_VALUE] = {
7188 .lkp_value = "health value",
7189 .lkp_data_type = NLA_S32,
7191 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_DROPPED] = {
7192 .lkp_value = "dropped",
7193 .lkp_data_type = NLA_U32,
7195 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_TIMEOUT] = {
7196 .lkp_value = "timeout",
7197 .lkp_data_type = NLA_U32,
7199 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_ERROR] = {
7200 .lkp_value = "error",
7201 .lkp_data_type = NLA_U32,
7203 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NETWORK_TIMEOUT] = {
7204 .lkp_value = "network timeout",
7205 .lkp_data_type = NLA_U32,
7207 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PING_COUNT] = {
7208 .lkp_value = "ping_count",
7209 .lkp_data_type = NLA_U32,
7211 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NEXT_PING] = {
7212 .lkp_value = "next_ping",
7213 .lkp_data_type = NLA_S64,
7218 static int lnet_peer_ni_show_dump(struct sk_buff *msg,
7219 struct netlink_callback *cb)
7221 struct lnet_genl_processid_list *plist = lnet_peer_dump_ctx(cb);
7222 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
7223 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
7224 struct netlink_ext_ack *extack = NULL;
7226 int portid = NETLINK_CB(cb->skb).portid;
7227 int seq = cb->nlh->nlmsg_seq;
7228 int idx = plist->lgpl_index;
7229 int msg_len = genlmsg_len(gnlh);
7232 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
7233 extack = cb->extack;
7235 if (!plist->lgpl_count) {
7236 NL_SET_ERR_MSG(extack, "No peers found");
7237 GOTO(send_error, rc = msg_len ? -ENOENT : 0);
7241 const struct ln_key_list *all[] = {
7242 &lnet_peer_ni_keys, &lnet_peer_ni_list,
7243 &udsp_info_list, &udsp_info_pref_nids_list,
7244 &udsp_info_pref_nids_list,
7245 &lnet_peer_ni_list_stats_count,
7246 &lnet_peer_ni_list_stats, /* send_stats */
7247 &lnet_peer_ni_list_stats, /* recv_stats */
7248 &lnet_peer_ni_list_stats, /* drop stats */
7249 &lnet_peer_ni_list_health,
7253 rc = lnet_genl_send_scalar_list(msg, portid, seq,
7255 NLM_F_CREATE | NLM_F_MULTI,
7256 LNET_CMD_PEERS, all);
7258 NL_SET_ERR_MSG(extack, "failed to send key table");
7259 GOTO(send_error, rc);
7263 mutex_lock(&the_lnet.ln_api_mutex);
7264 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
7265 NL_SET_ERR_MSG(extack, "Network is down");
7266 GOTO(unlock_api_mutex, rc = -ENETDOWN);
7269 while (idx < plist->lgpl_count) {
7270 struct lnet_processid *id;
7271 struct lnet_peer_ni *lpni = NULL;
7272 struct nlattr *nid_list;
7273 struct lnet_peer *lp;
7277 id = genradix_ptr(&plist->lgpl_list, idx++);
7278 if (nid_is_lo0(&id->nid))
7281 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
7282 NLM_F_MULTI, LNET_CMD_PEERS);
7284 NL_SET_ERR_MSG(extack, "failed to send values");
7285 genlmsg_cancel(msg, hdr);
7286 GOTO(unlock_api_mutex, rc = -EMSGSIZE);
7289 lp = lnet_find_peer(&id->nid);
7291 NL_SET_ERR_MSG(extack, "cannot find peer");
7292 GOTO(unlock_api_mutex, rc = -ENOENT);
7296 nla_put_string(msg, LNET_PEER_NI_ATTR_HDR, "");
7298 nla_put_string(msg, LNET_PEER_NI_ATTR_PRIMARY_NID,
7299 libcfs_nidstr(&lp->lp_primary_nid));
7300 if (lnet_peer_is_multi_rail(lp))
7301 nla_put_flag(msg, LNET_PEER_NI_ATTR_MULTIRAIL);
7303 if (gnlh->version >= 3)
7304 nla_put_u32(msg, LNET_PEER_NI_ATTR_STATE, lp->lp_state);
7306 nid_list = nla_nest_start(msg, LNET_PEER_NI_ATTR_PEER_NI_LIST);
7307 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL) {
7308 struct nlattr *peer_nid = nla_nest_start(msg, count++);
7310 nla_put_string(msg, LNET_PEER_NI_LIST_ATTR_NID,
7311 libcfs_nidstr(&lpni->lpni_nid));
7313 if (gnlh->version >= 4) {
7314 rc = lnet_udsp_info_send(msg,
7315 LNET_PEER_NI_LIST_ATTR_UDSP_INFO,
7316 &lpni->lpni_nid, true);
7318 lnet_peer_decref_locked(lp);
7319 NL_SET_ERR_MSG(extack,
7320 "failed to get UDSP info");
7321 GOTO(unlock_api_mutex, rc);
7325 if (lnet_isrouter(lpni) ||
7326 lnet_peer_aliveness_enabled(lpni)) {
7327 nla_put_string(msg, LNET_PEER_NI_LIST_ATTR_STATE,
7328 lnet_is_peer_ni_alive(lpni) ?
7331 nla_put_string(msg, LNET_PEER_NI_LIST_ATTR_STATE,
7335 if (gnlh->version) {
7336 struct lnet_ioctl_element_msg_stats lpni_msg_stats;
7337 struct nlattr *send_stats_list, *send_stats;
7338 struct nlattr *recv_stats_list, *recv_stats;
7339 struct nlattr *drop_stats_list, *drop_stats;
7340 struct nlattr *health_list, *health_stats;
7341 struct lnet_ioctl_element_stats stats;
7342 struct nlattr *stats_attr, *ni_stats;
7345 LNET_PEER_NI_LIST_ATTR_MAX_TX_CREDITS,
7347 lpni->lpni_net->net_tunables.lct_peer_tx_credits : 0);
7349 LNET_PEER_NI_LIST_ATTR_CUR_TX_CREDITS,
7350 lpni->lpni_txcredits);
7352 LNET_PEER_NI_LIST_ATTR_MIN_TX_CREDITS,
7353 lpni->lpni_mintxcredits);
7355 LNET_PEER_NI_LIST_ATTR_QUEUE_BUF_COUNT,
7358 LNET_PEER_NI_LIST_ATTR_CUR_RTR_CREDITS,
7359 lpni->lpni_rtrcredits);
7361 LNET_PEER_NI_LIST_ATTR_MIN_RTR_CREDITS,
7362 lpni->lpni_minrtrcredits);
7364 LNET_PEER_NI_LIST_ATTR_REFCOUNT,
7365 kref_read(&lpni->lpni_kref));
7367 memset(&stats, 0, sizeof(stats));
7368 stats.iel_send_count = lnet_sum_stats(&lpni->lpni_stats,
7369 LNET_STATS_TYPE_SEND);
7370 stats.iel_recv_count = lnet_sum_stats(&lpni->lpni_stats,
7371 LNET_STATS_TYPE_RECV);
7372 stats.iel_drop_count = lnet_sum_stats(&lpni->lpni_stats,
7373 LNET_STATS_TYPE_DROP);
7375 stats_attr = nla_nest_start(msg,
7376 LNET_PEER_NI_LIST_ATTR_STATS_COUNT);
7377 ni_stats = nla_nest_start(msg, 0);
7379 LNET_PEER_NI_LIST_STATS_COUNT_ATTR_SEND_COUNT,
7380 stats.iel_send_count);
7382 LNET_PEER_NI_LIST_STATS_COUNT_ATTR_RECV_COUNT,
7383 stats.iel_recv_count);
7385 LNET_PEER_NI_LIST_STATS_COUNT_ATTR_DROP_COUNT,
7386 stats.iel_drop_count);
7387 nla_nest_end(msg, ni_stats);
7388 nla_nest_end(msg, stats_attr);
7390 if (gnlh->version < 2)
7391 goto skip_msg_stats;
7393 lnet_usr_translate_stats(&lpni_msg_stats, &lpni->lpni_stats);
7395 send_stats_list = nla_nest_start(msg,
7396 LNET_PEER_NI_LIST_ATTR_SENT_STATS);
7397 send_stats = nla_nest_start(msg, 0);
7399 LNET_PEER_NI_LIST_STATS_ATTR_PUT,
7400 lpni_msg_stats.im_send_stats.ico_put_count);
7402 LNET_PEER_NI_LIST_STATS_ATTR_GET,
7403 lpni_msg_stats.im_send_stats.ico_get_count);
7405 LNET_PEER_NI_LIST_STATS_ATTR_REPLY,
7406 lpni_msg_stats.im_send_stats.ico_reply_count);
7408 LNET_PEER_NI_LIST_STATS_ATTR_ACK,
7409 lpni_msg_stats.im_send_stats.ico_ack_count);
7411 LNET_PEER_NI_LIST_STATS_ATTR_HELLO,
7412 lpni_msg_stats.im_send_stats.ico_hello_count);
7413 nla_nest_end(msg, send_stats);
7414 nla_nest_end(msg, send_stats_list);
7416 recv_stats_list = nla_nest_start(msg,
7417 LNET_PEER_NI_LIST_ATTR_RECV_STATS);
7418 recv_stats = nla_nest_start(msg, 0);
7420 LNET_PEER_NI_LIST_STATS_ATTR_PUT,
7421 lpni_msg_stats.im_recv_stats.ico_put_count);
7423 LNET_PEER_NI_LIST_STATS_ATTR_GET,
7424 lpni_msg_stats.im_recv_stats.ico_get_count);
7426 LNET_PEER_NI_LIST_STATS_ATTR_REPLY,
7427 lpni_msg_stats.im_recv_stats.ico_reply_count);
7429 LNET_PEER_NI_LIST_STATS_ATTR_ACK,
7430 lpni_msg_stats.im_recv_stats.ico_ack_count);
7432 LNET_PEER_NI_LIST_STATS_ATTR_HELLO,
7433 lpni_msg_stats.im_recv_stats.ico_hello_count);
7434 nla_nest_end(msg, recv_stats);
7435 nla_nest_end(msg, recv_stats_list);
7437 drop_stats_list = nla_nest_start(msg,
7438 LNET_PEER_NI_LIST_ATTR_DROP_STATS);
7439 drop_stats = nla_nest_start(msg, 0);
7441 LNET_PEER_NI_LIST_STATS_ATTR_PUT,
7442 lpni_msg_stats.im_drop_stats.ico_put_count);
7444 LNET_PEER_NI_LIST_STATS_ATTR_GET,
7445 lpni_msg_stats.im_drop_stats.ico_get_count);
7447 LNET_PEER_NI_LIST_STATS_ATTR_REPLY,
7448 lpni_msg_stats.im_drop_stats.ico_reply_count);
7450 LNET_PEER_NI_LIST_STATS_ATTR_ACK,
7451 lpni_msg_stats.im_drop_stats.ico_ack_count);
7453 LNET_PEER_NI_LIST_STATS_ATTR_HELLO,
7454 lpni_msg_stats.im_drop_stats.ico_hello_count);
7455 nla_nest_end(msg, drop_stats);
7456 nla_nest_end(msg, drop_stats_list);
7458 health_list = nla_nest_start(msg,
7459 LNET_PEER_NI_LIST_ATTR_HEALTH_STATS);
7460 health_stats = nla_nest_start(msg, 0);
7462 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_VALUE,
7463 atomic_read(&lpni->lpni_healthv));
7465 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_DROPPED,
7466 atomic_read(&lpni->lpni_hstats.hlt_remote_dropped));
7468 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_TIMEOUT,
7469 atomic_read(&lpni->lpni_hstats.hlt_remote_timeout));
7471 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_ERROR,
7472 atomic_read(&lpni->lpni_hstats.hlt_remote_error));
7474 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NETWORK_TIMEOUT,
7475 atomic_read(&lpni->lpni_hstats.hlt_network_timeout));
7477 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PING_COUNT,
7478 lpni->lpni_ping_count);
7480 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NEXT_PING,
7481 lpni->lpni_next_ping,
7482 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PAD);
7483 nla_nest_end(msg, health_stats);
7484 nla_nest_end(msg, health_list);
7487 nla_nest_end(msg, peer_nid);
7489 nla_nest_end(msg, nid_list);
7491 genlmsg_end(msg, hdr);
7492 lnet_peer_decref_locked(lp);
7494 plist->lgpl_index = idx;
7496 mutex_unlock(&the_lnet.ln_api_mutex);
7498 return lnet_nl_send_error(cb->skb, portid, seq, rc);
7501 #ifndef HAVE_NETLINK_CALLBACK_START
7502 static int lnet_old_peer_ni_show_dump(struct sk_buff *msg,
7503 struct netlink_callback *cb)
7506 int rc = lnet_peer_ni_show_start(cb);
7509 return lnet_nl_send_error(cb->skb,
7510 NETLINK_CB(cb->skb).portid,
7515 return lnet_peer_ni_show_dump(msg, cb);
7519 static int lnet_route_cmd(struct sk_buff *skb, struct genl_info *info)
7521 struct nlmsghdr *nlh = nlmsg_hdr(skb);
7522 struct genlmsghdr *gnlh = nlmsg_data(nlh);
7523 struct nlattr *params = genlmsg_data(gnlh);
7524 int msg_len, rem, rc = 0;
7525 struct nlattr *attr;
7527 mutex_lock(&the_lnet.ln_api_mutex);
7528 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
7529 GENL_SET_ERR_MSG(info, "Network is down");
7530 mutex_unlock(&the_lnet.ln_api_mutex);
7534 msg_len = genlmsg_len(gnlh);
7536 GENL_SET_ERR_MSG(info, "no configuration");
7537 mutex_unlock(&the_lnet.ln_api_mutex);
7541 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
7542 GENL_SET_ERR_MSG(info, "invalid configuration");
7543 mutex_unlock(&the_lnet.ln_api_mutex);
7547 nla_for_each_nested(attr, params, rem) {
7548 u32 net_id = LNET_NET_ANY, hops = LNET_UNDEFINED_HOPS;
7549 u32 priority = 0, sensitivity = 1;
7550 struct lnet_nid gw_nid = LNET_ANY_NID;
7551 struct nlattr *route_prop;
7556 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
7559 nla_for_each_nested(route_prop, attr, rem2) {
7560 char tmp[LNET_NIDSTR_SIZE];
7564 if (nla_type(route_prop) != LN_SCALAR_ATTR_VALUE)
7567 if (nla_strcmp(route_prop, "net") == 0) {
7568 route_prop = nla_next(route_prop, &rem2);
7569 if (nla_type(route_prop) !=
7570 LN_SCALAR_ATTR_VALUE) {
7571 GENL_SET_ERR_MSG(info,
7572 "net is invalid key");
7573 GOTO(report_err, rc = -EINVAL);
7576 len = nla_strscpy(tmp, route_prop, sizeof(tmp));
7578 GENL_SET_ERR_MSG(info,
7579 "net key string is invalid");
7580 GOTO(report_err, rc = len);
7583 net_id = libcfs_str2net(tmp);
7585 GENL_SET_ERR_MSG(info,
7586 "cannot parse remote net");
7587 GOTO(report_err, rc = -ENODEV);
7590 if (LNET_NETTYP(net_id) == LOLND) {
7591 GENL_SET_ERR_MSG(info,
7592 "setting @lo not allowed");
7593 GOTO(report_err, rc = -EACCES);
7596 if (net_id == LNET_NET_ANY) {
7597 GENL_SET_ERR_MSG(info,
7598 "setting LNET_NET_ANY not allowed");
7599 GOTO(report_err, rc = -ENXIO);
7601 } else if (nla_strcmp(route_prop, "gateway") == 0) {
7602 route_prop = nla_next(route_prop, &rem2);
7603 if (nla_type(route_prop) !=
7604 LN_SCALAR_ATTR_VALUE) {
7605 GENL_SET_ERR_MSG(info,
7606 "gateway is invalid key");
7607 GOTO(report_err, rc = -EINVAL);
7610 len = nla_strscpy(tmp, route_prop, sizeof(tmp));
7612 GENL_SET_ERR_MSG(info,
7613 "gateway string is invalid");
7614 GOTO(report_err, rc = len);
7617 rc = libcfs_strnid(&gw_nid, strim(tmp));
7619 GENL_SET_ERR_MSG(info,
7620 "cannot parse gateway");
7621 GOTO(report_err, rc = -ENODEV);
7623 } else if (nla_strcmp(route_prop, "state") == 0) {
7624 route_prop = nla_next(route_prop, &rem2);
7625 if (nla_type(route_prop) !=
7626 LN_SCALAR_ATTR_VALUE) {
7627 GENL_SET_ERR_MSG(info,
7628 "state is invalid key");
7629 GOTO(report_err, rc = -EINVAL);
7632 if (nla_strcmp(route_prop, "down") == 0) {
7634 } else if (nla_strcmp(route_prop, "up") == 0) {
7637 GENL_SET_ERR_MSG(info,
7638 "status string bad value");
7639 GOTO(report_err, rc = -EINVAL);
7641 } else if (nla_strcmp(route_prop, "notify_time") == 0) {
7642 route_prop = nla_next(route_prop, &rem2);
7643 if (nla_type(route_prop) !=
7644 LN_SCALAR_ATTR_INT_VALUE) {
7645 GENL_SET_ERR_MSG(info,
7646 "notify_time is invalid key");
7647 GOTO(report_err, rc = -EINVAL);
7650 when = nla_get_s64(route_prop);
7651 if (ktime_get_real_seconds() < when) {
7652 GENL_SET_ERR_MSG(info,
7653 "notify_time is in the future");
7654 GOTO(report_err, rc = -EINVAL);
7656 } else if (nla_strcmp(route_prop, "hop") == 0) {
7657 route_prop = nla_next(route_prop, &rem2);
7658 if (nla_type(route_prop) !=
7659 LN_SCALAR_ATTR_INT_VALUE) {
7660 GENL_SET_ERR_MSG(info,
7661 "hop has invalid key");
7662 GOTO(report_err, rc = -EINVAL);
7665 hops = nla_get_s64(route_prop);
7666 if ((hops < 1 || hops > 255) && hops != -1) {
7667 GENL_SET_ERR_MSG(info,
7668 "invalid hop count must be between 1 and 255");
7669 GOTO(report_err, rc = -EINVAL);
7671 } else if (nla_strcmp(route_prop, "priority") == 0) {
7672 route_prop = nla_next(route_prop, &rem2);
7673 if (nla_type(route_prop) !=
7674 LN_SCALAR_ATTR_INT_VALUE) {
7675 GENL_SET_ERR_MSG(info,
7676 "priority has invalid key");
7677 GOTO(report_err, rc = -EINVAL);
7680 num = nla_get_s64(route_prop);
7682 GENL_SET_ERR_MSG(info,
7683 "invalid priority, must not be negative");
7684 GOTO(report_err, rc = -EINVAL);
7687 } else if (nla_strcmp(route_prop,
7688 "health_sensitivity") == 0) {
7689 route_prop = nla_next(route_prop, &rem2);
7690 if (nla_type(route_prop) !=
7691 LN_SCALAR_ATTR_INT_VALUE) {
7692 GENL_SET_ERR_MSG(info,
7693 "sensitivity has invalid key");
7694 GOTO(report_err, rc = -EINVAL);
7697 num = nla_get_s64(route_prop);
7699 GENL_SET_ERR_MSG(info,
7700 "invalid health sensitivity, must be 1 or greater");
7701 GOTO(report_err, rc = -EINVAL);
7707 if (net_id == LNET_NET_ANY) {
7708 GENL_SET_ERR_MSG(info,
7709 "missing mandatory parameter: network");
7710 GOTO(report_err, rc = -ENODEV);
7713 if (LNET_NID_IS_ANY(&gw_nid)) {
7714 GENL_SET_ERR_MSG(info,
7715 "missing mandatory parameter: gateway");
7716 GOTO(report_err, rc = -ENODEV);
7719 if (info->nlhdr->nlmsg_flags & NLM_F_REPLACE) {
7720 /* Convert the user-supplied real time to monotonic.
7721 * NB: "when" is always in the past
7723 when = ktime_get_seconds() -
7724 (ktime_get_real_seconds() - when);
7726 mutex_unlock(&the_lnet.ln_api_mutex);
7727 rc = lnet_notify(NULL, &gw_nid, alive, false, when);
7728 mutex_lock(&the_lnet.ln_api_mutex);
7730 GOTO(report_err, rc);
7731 else if (the_lnet.ln_state != LNET_STATE_RUNNING)
7732 GOTO(report_err, rc = -ENETDOWN);
7733 } else if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
7734 rc = lnet_add_route(net_id, hops, &gw_nid, priority,
7739 GENL_SET_ERR_MSG(info,
7740 "invalid settings for route creation");
7743 GENL_SET_ERR_MSG(info,
7744 "No interface configured on the same net as gateway");
7747 GENL_SET_ERR_MSG(info,
7751 GENL_SET_ERR_MSG(info,
7752 "Route already exists or the specified network is local");
7755 GENL_SET_ERR_MSG(info,
7756 "failed to create route");
7759 GOTO(report_err, rc);
7761 } else if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE)) {
7762 rc = lnet_del_route(net_id, &gw_nid);
7764 GENL_SET_ERR_MSG(info,
7765 "failed to delete route");
7766 GOTO(report_err, rc);
7771 mutex_unlock(&the_lnet.ln_api_mutex);
7776 static inline struct lnet_genl_ping_list *
7777 lnet_ping_dump_ctx(struct netlink_callback *cb)
7779 return (struct lnet_genl_ping_list *)cb->args[0];
7782 static int lnet_ping_show_done(struct netlink_callback *cb)
7784 struct lnet_genl_ping_list *plist = lnet_ping_dump_ctx(cb);
7787 genradix_free(&plist->lgpl_failed);
7788 genradix_free(&plist->lgpl_list);
7789 LIBCFS_FREE(plist, sizeof(*plist));
7796 /* LNet ping ->start() handler for GET requests */
7797 static int lnet_ping_show_start(struct netlink_callback *cb)
7799 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
7800 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
7801 struct netlink_ext_ack *extack = NULL;
7803 struct lnet_genl_ping_list *plist;
7804 int msg_len = genlmsg_len(gnlh);
7805 struct nlattr *params, *top;
7808 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
7809 extack = cb->extack;
7811 if (the_lnet.ln_refcount == 0) {
7812 NL_SET_ERR_MSG(extack, "Network is down");
7817 NL_SET_ERR_MSG(extack, "Ping needs NID targets");
7821 LIBCFS_ALLOC(plist, sizeof(*plist));
7823 NL_SET_ERR_MSG(extack, "failed to setup ping list");
7826 genradix_init(&plist->lgpl_list);
7827 plist->lgpl_timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
7828 plist->lgpl_src_nid = LNET_ANY_NID;
7829 plist->lgpl_index = 0;
7830 plist->lgpl_list_count = 0;
7831 cb->args[0] = (long)plist;
7833 params = genlmsg_data(gnlh);
7834 nla_for_each_attr(top, params, msg_len, rem) {
7835 struct nlattr *nids;
7838 switch (nla_type(top)) {
7839 case LN_SCALAR_ATTR_VALUE:
7840 if (nla_strcmp(top, "timeout") == 0) {
7843 top = nla_next(top, &rem);
7844 if (nla_type(top) != LN_SCALAR_ATTR_INT_VALUE) {
7845 NL_SET_ERR_MSG(extack,
7846 "invalid timeout param");
7847 GOTO(report_err, rc = -EINVAL);
7850 /* If timeout is negative then set default of
7853 timeout = nla_get_s64(top);
7855 timeout < (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
7856 plist->lgpl_timeout =
7857 nsecs_to_jiffies(timeout * NSEC_PER_MSEC);
7858 } else if (nla_strcmp(top, "source") == 0) {
7859 char nidstr[LNET_NIDSTR_SIZE + 1];
7861 top = nla_next(top, &rem);
7862 if (nla_type(top) != LN_SCALAR_ATTR_VALUE) {
7863 NL_SET_ERR_MSG(extack,
7864 "invalid source param");
7865 GOTO(report_err, rc = -EINVAL);
7868 rc = nla_strscpy(nidstr, top, sizeof(nidstr));
7870 NL_SET_ERR_MSG(extack,
7871 "failed to parse source nid");
7872 GOTO(report_err, rc);
7875 rc = libcfs_strnid(&plist->lgpl_src_nid,
7878 NL_SET_ERR_MSG(extack,
7879 "invalid source nid");
7880 GOTO(report_err, rc);
7885 case LN_SCALAR_ATTR_LIST:
7886 nla_for_each_nested(nids, top, rem2) {
7887 char nid[LNET_NIDSTR_SIZE + 1];
7888 struct lnet_processid *id;
7890 if (nla_type(nids) != LN_SCALAR_ATTR_VALUE)
7893 memset(nid, 0, sizeof(nid));
7894 rc = nla_strscpy(nid, nids, sizeof(nid));
7896 NL_SET_ERR_MSG(extack,
7897 "failed to get NID");
7898 GOTO(report_err, rc);
7901 id = genradix_ptr_alloc(&plist->lgpl_list,
7902 plist->lgpl_list_count++,
7905 NL_SET_ERR_MSG(extack,
7906 "failed to allocate NID");
7907 GOTO(report_err, rc = -ENOMEM);
7910 rc = libcfs_strid(id, strim(nid));
7912 NL_SET_ERR_MSG(extack, "cannot parse NID");
7913 GOTO(report_err, rc);
7924 lnet_ping_show_done(cb);
7929 static const struct ln_key_list ping_err_props_list = {
7930 .lkl_maxattr = LNET_ERR_ATTR_MAX,
7932 [LNET_ERR_ATTR_HDR] = {
7933 .lkp_value = "manage",
7934 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
7935 .lkp_data_type = NLA_NUL_STRING,
7937 [LNET_ERR_ATTR_TYPE] = {
7938 .lkp_value = "ping",
7939 .lkp_data_type = NLA_STRING,
7941 [LNET_ERR_ATTR_ERRNO] = {
7942 .lkp_value = "errno",
7943 .lkp_data_type = NLA_S16,
7945 [LNET_ERR_ATTR_DESCR] = {
7946 .lkp_value = "descr",
7947 .lkp_data_type = NLA_STRING,
7952 static const struct ln_key_list ping_props_list = {
7953 .lkl_maxattr = LNET_PING_ATTR_MAX,
7955 [LNET_PING_ATTR_HDR] = {
7956 .lkp_value = "ping",
7957 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
7958 .lkp_data_type = NLA_NUL_STRING,
7960 [LNET_PING_ATTR_PRIMARY_NID] = {
7961 .lkp_value = "primary nid",
7962 .lkp_data_type = NLA_STRING
7964 [LNET_PING_ATTR_ERRNO] = {
7965 .lkp_value = "errno",
7966 .lkp_data_type = NLA_S16
7968 [LNET_PING_ATTR_MULTIRAIL] = {
7969 .lkp_value = "Multi-Rail",
7970 .lkp_data_type = NLA_FLAG
7972 [LNET_PING_ATTR_PEER_NI_LIST] = {
7973 .lkp_value = "peer_ni",
7974 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
7975 .lkp_data_type = NLA_NESTED
7980 static const struct ln_key_list ping_peer_ni_list = {
7981 .lkl_maxattr = LNET_PING_PEER_NI_ATTR_MAX,
7983 [LNET_PING_PEER_NI_ATTR_NID] = {
7985 .lkp_data_type = NLA_STRING
7990 static int lnet_ping_show_dump(struct sk_buff *msg,
7991 struct netlink_callback *cb)
7993 struct lnet_genl_ping_list *plist = lnet_ping_dump_ctx(cb);
7994 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
7995 struct netlink_ext_ack *extack = NULL;
7997 int portid = NETLINK_CB(cb->skb).portid;
7998 int seq = cb->nlh->nlmsg_seq;
7999 int idx = plist->lgpl_index;
8002 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
8003 extack = cb->extack;
8005 if (!plist->lgpl_index) {
8006 const struct ln_key_list *all[] = {
8007 &ping_props_list, &ping_peer_ni_list, NULL
8010 rc = lnet_genl_send_scalar_list(msg, portid, seq,
8012 NLM_F_CREATE | NLM_F_MULTI,
8013 LNET_CMD_PING, all);
8015 NL_SET_ERR_MSG(extack, "failed to send key table");
8016 GOTO(send_error, rc);
8019 genradix_init(&plist->lgpl_failed);
8022 while (idx < plist->lgpl_list_count) {
8023 struct lnet_nid primary_nid = LNET_ANY_NID;
8024 struct lnet_genl_ping_list peers;
8025 struct lnet_processid *id;
8026 struct nlattr *nid_list;
8027 struct lnet_peer *lp;
8028 bool mr_flag = false;
8032 id = genradix_ptr(&plist->lgpl_list, idx++);
8034 rc = lnet_ping(id, &plist->lgpl_src_nid, plist->lgpl_timeout,
8035 &peers, lnet_interfaces_max);
8037 struct lnet_fail_ping *fail;
8039 fail = genradix_ptr_alloc(&plist->lgpl_failed,
8040 plist->lgpl_failed_count++,
8043 NL_SET_ERR_MSG(extack,
8044 "failed to allocate failed NID");
8045 GOTO(send_error, rc);
8047 memset(fail->lfp_msg, '\0', sizeof(fail->lfp_msg));
8048 snprintf(fail->lfp_msg, sizeof(fail->lfp_msg),
8049 "failed to ping %s",
8050 libcfs_nidstr(&id->nid));
8052 fail->lfp_errno = rc;
8056 mutex_lock(&the_lnet.ln_api_mutex);
8057 lp = lnet_find_peer(&id->nid);
8059 primary_nid = lp->lp_primary_nid;
8060 mr_flag = lnet_peer_is_multi_rail(lp);
8061 lnet_peer_decref_locked(lp);
8063 mutex_unlock(&the_lnet.ln_api_mutex);
8065 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
8066 NLM_F_MULTI, LNET_CMD_PING);
8068 NL_SET_ERR_MSG(extack, "failed to send values");
8069 genlmsg_cancel(msg, hdr);
8070 GOTO(send_error, rc = -EMSGSIZE);
8074 nla_put_string(msg, LNET_PING_ATTR_HDR, "");
8076 nla_put_string(msg, LNET_PING_ATTR_PRIMARY_NID,
8077 libcfs_nidstr(&primary_nid));
8079 nla_put_flag(msg, LNET_PING_ATTR_MULTIRAIL);
8081 nid_list = nla_nest_start(msg, LNET_PING_ATTR_PEER_NI_LIST);
8082 for (count = 0; count < rc; count++) {
8083 struct lnet_processid *result;
8084 struct nlattr *nid_attr;
8087 result = genradix_ptr(&peers.lgpl_list, count);
8088 if (nid_is_lo0(&result->nid))
8091 nid_attr = nla_nest_start(msg, count + 1);
8092 if (id->pid == LNET_PID_LUSTRE)
8093 idstr = libcfs_nidstr(&result->nid);
8095 idstr = libcfs_idstr(result);
8096 nla_put_string(msg, LNET_PING_PEER_NI_ATTR_NID, idstr);
8097 nla_nest_end(msg, nid_attr);
8099 nla_nest_end(msg, nid_list);
8100 genlmsg_end(msg, hdr);
8102 genradix_free(&peers.lgpl_list);
8105 if (plist->lgpl_failed_count) {
8106 int flags = NLM_F_CREATE | NLM_F_REPLACE | NLM_F_MULTI;
8107 const struct ln_key_list *fail[] = {
8108 &ping_err_props_list, NULL
8111 rc = lnet_genl_send_scalar_list(msg, portid, seq, &lnet_family,
8112 flags, LNET_CMD_PING, fail);
8114 NL_SET_ERR_MSG(extack,
8115 "failed to send new key table");
8116 GOTO(send_error, rc);
8119 for (i = 0; i < plist->lgpl_failed_count; i++) {
8120 struct lnet_fail_ping *fail;
8123 fail = genradix_ptr(&plist->lgpl_failed, i);
8125 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
8126 NLM_F_MULTI, LNET_CMD_PING);
8128 NL_SET_ERR_MSG(extack,
8129 "failed to send failed values");
8130 genlmsg_cancel(msg, hdr);
8131 GOTO(send_error, rc = -EMSGSIZE);
8135 nla_put_string(msg, LNET_ERR_ATTR_HDR, "");
8137 nla_put_string(msg, LNET_ERR_ATTR_TYPE, "\n");
8138 nla_put_s16(msg, LNET_ERR_ATTR_ERRNO,
8140 nla_put_string(msg, LNET_ERR_ATTR_DESCR,
8142 genlmsg_end(msg, hdr);
8145 genradix_free(&plist->lgpl_list);
8146 rc = 0; /* don't treat it as an error */
8148 plist->lgpl_index = idx;
8150 return lnet_nl_send_error(cb->skb, portid, seq, rc);
8153 #ifndef HAVE_NETLINK_CALLBACK_START
8154 static int lnet_old_ping_show_dump(struct sk_buff *msg,
8155 struct netlink_callback *cb)
8158 int rc = lnet_ping_show_start(cb);
8161 return lnet_nl_send_error(cb->skb,
8162 NETLINK_CB(cb->skb).portid,
8167 return lnet_ping_show_dump(msg, cb);
8171 static const struct ln_key_list discover_err_props_list = {
8172 .lkl_maxattr = LNET_ERR_ATTR_MAX,
8174 [LNET_ERR_ATTR_HDR] = {
8175 .lkp_value = "manage",
8176 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
8177 .lkp_data_type = NLA_NUL_STRING,
8179 [LNET_ERR_ATTR_TYPE] = {
8180 .lkp_value = "discover",
8181 .lkp_data_type = NLA_STRING,
8183 [LNET_ERR_ATTR_ERRNO] = {
8184 .lkp_value = "errno",
8185 .lkp_data_type = NLA_S16,
8187 [LNET_ERR_ATTR_DESCR] = {
8188 .lkp_value = "descr",
8189 .lkp_data_type = NLA_STRING,
8194 static const struct ln_key_list discover_props_list = {
8195 .lkl_maxattr = LNET_PING_ATTR_MAX,
8197 [LNET_PING_ATTR_HDR] = {
8198 .lkp_value = "discover",
8199 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
8200 .lkp_data_type = NLA_NUL_STRING,
8202 [LNET_PING_ATTR_PRIMARY_NID] = {
8203 .lkp_value = "primary nid",
8204 .lkp_data_type = NLA_STRING
8206 [LNET_PING_ATTR_ERRNO] = {
8207 .lkp_value = "errno",
8208 .lkp_data_type = NLA_S16
8210 [LNET_PING_ATTR_MULTIRAIL] = {
8211 .lkp_value = "Multi-Rail",
8212 .lkp_data_type = NLA_FLAG
8214 [LNET_PING_ATTR_PEER_NI_LIST] = {
8215 .lkp_value = "peer_ni",
8216 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
8217 .lkp_data_type = NLA_NESTED
8222 static int lnet_ping_cmd(struct sk_buff *skb, struct genl_info *info)
8224 const struct ln_key_list *all[] = {
8225 &discover_props_list, &ping_peer_ni_list, NULL
8227 struct nlmsghdr *nlh = nlmsg_hdr(skb);
8228 struct genlmsghdr *gnlh = nlmsg_data(nlh);
8229 struct nlattr *params = genlmsg_data(gnlh);
8230 struct lnet_genl_ping_list dlists;
8231 int msg_len, rem, rc = 0, i;
8232 bool clear_hdr = false;
8233 struct sk_buff *reply;
8234 struct nlattr *attr;
8237 msg_len = genlmsg_len(gnlh);
8239 GENL_SET_ERR_MSG(info, "no configuration");
8243 if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE)) {
8244 GENL_SET_ERR_MSG(info, "only NLM_F_CREATE setting is allowed");
8248 reply = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
8250 GENL_SET_ERR_MSG(info,
8251 "fail to allocate reply");
8255 genradix_init(&dlists.lgpl_failed);
8256 dlists.lgpl_failed_count = 0;
8257 genradix_init(&dlists.lgpl_list);
8258 dlists.lgpl_list_count = 0;
8260 rc = lnet_genl_send_scalar_list(reply, info->snd_portid,
8261 info->snd_seq, &lnet_family,
8262 NLM_F_CREATE | NLM_F_MULTI,
8263 LNET_CMD_PING, all);
8265 GENL_SET_ERR_MSG(info,
8266 "failed to send key table");
8267 GOTO(report_err, rc);
8270 nla_for_each_attr(attr, params, msg_len, rem) {
8271 struct nlattr *nids;
8274 /* We only care about the NID list to discover with */
8275 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
8278 nla_for_each_nested(nids, attr, rem2) {
8279 char nid[LNET_NIDSTR_SIZE + 1];
8280 struct lnet_processid id;
8281 struct nlattr *nid_list;
8282 struct lnet_peer *lp;
8285 if (nla_type(nids) != LN_SCALAR_ATTR_VALUE)
8288 memset(nid, 0, sizeof(nid));
8289 rc = nla_strscpy(nid, nids, sizeof(nid));
8291 GENL_SET_ERR_MSG(info,
8292 "failed to get NID");
8293 GOTO(report_err, rc);
8296 len = libcfs_strid(&id, strim(nid));
8298 struct lnet_fail_ping *fail;
8300 fail = genradix_ptr_alloc(&dlists.lgpl_failed,
8301 dlists.lgpl_failed_count++,
8304 GENL_SET_ERR_MSG(info,
8305 "failed to allocate improper NID");
8306 GOTO(report_err, rc = -ENOMEM);
8308 memset(fail->lfp_msg, '\0', sizeof(fail->lfp_msg));
8309 snprintf(fail->lfp_msg, sizeof(fail->lfp_msg),
8310 "cannot parse NID '%s'", strim(nid));
8312 fail->lfp_errno = len;
8316 if (LNET_NID_IS_ANY(&id.nid))
8319 rc = lnet_discover(&id,
8320 info->nlhdr->nlmsg_flags & NLM_F_EXCL,
8323 struct lnet_fail_ping *fail;
8325 fail = genradix_ptr_alloc(&dlists.lgpl_failed,
8326 dlists.lgpl_failed_count++,
8329 GENL_SET_ERR_MSG(info,
8330 "failed to allocate failed NID");
8331 GOTO(report_err, rc = -ENOMEM);
8333 memset(fail->lfp_msg, '\0', sizeof(fail->lfp_msg));
8334 snprintf(fail->lfp_msg, sizeof(fail->lfp_msg),
8335 "failed to discover %s",
8336 libcfs_nidstr(&id.nid));
8338 fail->lfp_errno = rc;
8342 /* create the genetlink message header */
8343 hdr = genlmsg_put(reply, info->snd_portid, info->snd_seq,
8344 &lnet_family, NLM_F_MULTI, LNET_CMD_PING);
8346 GENL_SET_ERR_MSG(info,
8347 "failed to allocate hdr");
8348 GOTO(report_err, rc = -ENOMEM);
8352 nla_put_string(reply, LNET_PING_ATTR_HDR, "");
8356 lp = lnet_find_peer(&id.nid);
8358 nla_put_string(reply, LNET_PING_ATTR_PRIMARY_NID,
8359 libcfs_nidstr(&lp->lp_primary_nid));
8360 if (lnet_peer_is_multi_rail(lp))
8361 nla_put_flag(reply, LNET_PING_ATTR_MULTIRAIL);
8362 lnet_peer_decref_locked(lp);
8365 nid_list = nla_nest_start(reply, LNET_PING_ATTR_PEER_NI_LIST);
8366 for (i = 0; i < dlists.lgpl_list_count; i++) {
8367 struct lnet_processid *found;
8368 struct nlattr *nid_attr;
8371 found = genradix_ptr(&dlists.lgpl_list, i);
8372 if (nid_is_lo0(&found->nid))
8375 nid_attr = nla_nest_start(reply, i + 1);
8376 if (id.pid == LNET_PID_LUSTRE)
8377 idstr = libcfs_nidstr(&found->nid);
8379 idstr = libcfs_idstr(found);
8380 nla_put_string(reply, LNET_PING_PEER_NI_ATTR_NID, idstr);
8381 nla_nest_end(reply, nid_attr);
8383 nla_nest_end(reply, nid_list);
8385 genlmsg_end(reply, hdr);
8389 if (dlists.lgpl_failed_count) {
8390 int flags = NLM_F_CREATE | NLM_F_REPLACE | NLM_F_MULTI;
8391 const struct ln_key_list *fail[] = {
8392 &discover_err_props_list, NULL
8395 rc = lnet_genl_send_scalar_list(reply, info->snd_portid,
8396 info->snd_seq, &lnet_family,
8397 flags, LNET_CMD_PING, fail);
8399 GENL_SET_ERR_MSG(info,
8400 "failed to send new key table");
8401 GOTO(report_err, rc);
8404 for (i = 0; i < dlists.lgpl_failed_count; i++) {
8405 struct lnet_fail_ping *fail;
8407 hdr = genlmsg_put(reply, info->snd_portid, info->snd_seq,
8408 &lnet_family, NLM_F_MULTI, LNET_CMD_PING);
8410 GENL_SET_ERR_MSG(info,
8411 "failed to send failed values");
8412 GOTO(report_err, rc = -ENOMSG);
8415 fail = genradix_ptr(&dlists.lgpl_failed, i);
8417 nla_put_string(reply, LNET_ERR_ATTR_HDR, "");
8419 nla_put_string(reply, LNET_ERR_ATTR_TYPE, "\n");
8420 nla_put_s16(reply, LNET_ERR_ATTR_ERRNO,
8422 nla_put_string(reply, LNET_ERR_ATTR_DESCR,
8424 genlmsg_end(reply, hdr);
8428 nlh = nlmsg_put(reply, info->snd_portid, info->snd_seq, NLMSG_DONE, 0,
8431 genlmsg_cancel(reply, hdr);
8432 GENL_SET_ERR_MSG(info,
8433 "failed to finish message");
8434 GOTO(report_err, rc = -EMSGSIZE);
8438 genradix_free(&dlists.lgpl_failed);
8439 genradix_free(&dlists.lgpl_list);
8442 genlmsg_cancel(reply, hdr);
8445 rc = genlmsg_reply(reply, info);
8451 #define lnet_peer_dist_show_done lnet_peer_ni_show_done
8453 static int lnet_peer_dist_show_start(struct netlink_callback *cb)
8455 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
8456 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
8457 struct netlink_ext_ack *extack = NULL;
8459 struct lnet_genl_processid_list *plist;
8460 int msg_len = genlmsg_len(gnlh);
8461 struct nlattr *params, *top;
8464 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
8465 extack = cb->extack;
8467 mutex_lock(&the_lnet.ln_api_mutex);
8468 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
8469 NL_SET_ERR_MSG(extack, "Network is down");
8470 mutex_unlock(&the_lnet.ln_api_mutex);
8474 msg_len = genlmsg_len(gnlh);
8476 NL_SET_ERR_MSG(extack, "Missing NID argument(s)");
8477 mutex_unlock(&the_lnet.ln_api_mutex);
8481 CFS_ALLOC_PTR(plist);
8483 NL_SET_ERR_MSG(extack, "No memory for peer NID list");
8484 mutex_unlock(&the_lnet.ln_api_mutex);
8488 genradix_init(&plist->lgpl_list);
8489 plist->lgpl_count = 0;
8490 plist->lgpl_index = 0;
8491 cb->args[0] = (long)plist;
8493 params = genlmsg_data(gnlh);
8494 nla_for_each_attr(top, params, msg_len, rem) {
8495 struct nlattr *nids;
8498 if (nla_type(top) != LN_SCALAR_ATTR_LIST)
8501 nla_for_each_nested(nids, top, rem2) {
8502 char nidstr[LNET_NIDSTR_SIZE + 1];
8503 struct lnet_processid *id;
8505 if (nla_type(nids) != LN_SCALAR_ATTR_VALUE)
8508 memset(nidstr, 0, sizeof(nidstr));
8509 rc = nla_strscpy(nidstr, nids, sizeof(nidstr));
8511 NL_SET_ERR_MSG(extack,
8512 "failed to get NID");
8513 GOTO(report_err, rc);
8516 id = genradix_ptr_alloc(&plist->lgpl_list,
8517 plist->lgpl_count++,
8520 NL_SET_ERR_MSG(extack, "failed to allocate NID");
8521 GOTO(report_err, rc = -ENOMEM);
8524 rc = libcfs_strid(id, strim(nidstr));
8526 NL_SET_ERR_MSG(extack, "invalid NID");
8527 GOTO(report_err, rc);
8533 mutex_unlock(&the_lnet.ln_api_mutex);
8536 lnet_peer_dist_show_done(cb);
8541 static const struct ln_key_list peer_dist_props_list = {
8542 .lkl_maxattr = LNET_PEER_DIST_ATTR_MAX,
8544 [LNET_PEER_DIST_ATTR_HDR] = {
8545 .lkp_value = "peer",
8546 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
8547 .lkp_data_type = NLA_NUL_STRING,
8549 [LNET_PEER_DIST_ATTR_NID] = {
8551 .lkp_data_type = NLA_STRING
8553 [LNET_PEER_DIST_ATTR_DIST] = {
8554 .lkp_value = "distance",
8555 .lkp_data_type = NLA_U32
8557 [LNET_PEER_DIST_ATTR_ORDER] = {
8558 .lkp_value = "order",
8559 .lkp_data_type = NLA_U32
8564 static int lnet_peer_dist_show_dump(struct sk_buff *msg,
8565 struct netlink_callback *cb)
8567 struct lnet_genl_processid_list *plist = lnet_peer_dump_ctx(cb);
8568 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
8569 struct netlink_ext_ack *extack = NULL;
8571 int portid = NETLINK_CB(cb->skb).portid;
8572 int seq = cb->nlh->nlmsg_seq;
8573 int idx = plist->lgpl_index;
8576 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
8577 extack = cb->extack;
8580 const struct ln_key_list *all[] = {
8581 &peer_dist_props_list, NULL
8584 rc = lnet_genl_send_scalar_list(msg, portid, seq,
8586 NLM_F_CREATE | NLM_F_MULTI,
8587 LNET_CMD_PEER_DIST, all);
8589 NL_SET_ERR_MSG(extack, "failed to send key table");
8590 GOTO(send_error, rc);
8594 while (idx < plist->lgpl_count) {
8595 struct lnet_processid *id;
8600 id = genradix_ptr(&plist->lgpl_list, idx++);
8601 if (nid_is_lo0(&id->nid))
8604 dist = LNetDist(&id->nid, &id->nid, &order);
8606 if (dist == -EHOSTUNREACH)
8613 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
8614 NLM_F_MULTI, LNET_CMD_PEER_DIST);
8616 NL_SET_ERR_MSG(extack, "failed to send values");
8617 genlmsg_cancel(msg, hdr);
8618 GOTO(send_error, rc = -EMSGSIZE);
8622 nla_put_string(msg, LNET_PEER_DIST_ATTR_HDR, "");
8624 nla_put_string(msg, LNET_PEER_DIST_ATTR_NID,
8625 libcfs_nidstr(&id->nid));
8626 nla_put_u32(msg, LNET_PEER_DIST_ATTR_DIST, dist);
8627 nla_put_u32(msg, LNET_PEER_DIST_ATTR_ORDER, order);
8629 genlmsg_end(msg, hdr);
8632 plist->lgpl_index = idx;
8634 return lnet_nl_send_error(cb->skb, portid, seq, rc);
8637 #ifndef HAVE_NETLINK_CALLBACK_START
8638 static int lnet_old_peer_dist_show_dump(struct sk_buff *msg,
8639 struct netlink_callback *cb)
8642 int rc = lnet_peer_dist_show_start(cb);
8645 return lnet_nl_send_error(cb->skb,
8646 NETLINK_CB(cb->skb).portid,
8651 return lnet_peer_dist_show_dump(msg, cb);
8655 static const struct genl_multicast_group lnet_mcast_grps[] = {
8656 { .name = "ip2net", },
8658 { .name = "peer", },
8659 { .name = "route", },
8660 { .name = "ping", },
8661 { .name = "discover", },
8662 { .name = "cpt-of-nid", },
8665 static const struct genl_ops lnet_genl_ops[] = {
8667 .cmd = LNET_CMD_NETS,
8668 .flags = GENL_ADMIN_PERM,
8669 #ifdef HAVE_NETLINK_CALLBACK_START
8670 .start = lnet_net_show_start,
8671 .dumpit = lnet_net_show_dump,
8673 .dumpit = lnet_old_net_show_dump,
8675 .done = lnet_net_show_done,
8676 .doit = lnet_net_cmd,
8679 .cmd = LNET_CMD_PEERS,
8680 .flags = GENL_ADMIN_PERM,
8681 #ifdef HAVE_NETLINK_CALLBACK_START
8682 .start = lnet_peer_ni_show_start,
8683 .dumpit = lnet_peer_ni_show_dump,
8685 .dumpit = lnet_old_peer_ni_show_dump,
8687 .done = lnet_peer_ni_show_done,
8688 .doit = lnet_peer_ni_cmd,
8691 .cmd = LNET_CMD_ROUTES,
8692 .flags = GENL_ADMIN_PERM,
8693 #ifdef HAVE_NETLINK_CALLBACK_START
8694 .start = lnet_route_show_start,
8695 .dumpit = lnet_route_show_dump,
8697 .dumpit = lnet_old_route_show_dump,
8699 .done = lnet_route_show_done,
8700 .doit = lnet_route_cmd,
8703 .cmd = LNET_CMD_PING,
8704 .flags = GENL_ADMIN_PERM,
8705 #ifdef HAVE_NETLINK_CALLBACK_START
8706 .start = lnet_ping_show_start,
8707 .dumpit = lnet_ping_show_dump,
8709 .dumpit = lnet_old_ping_show_dump,
8711 .done = lnet_ping_show_done,
8712 .doit = lnet_ping_cmd,
8715 .cmd = LNET_CMD_CPT_OF_NID,
8716 #ifdef HAVE_NETLINK_CALLBACK_START
8717 .start = lnet_cpt_of_nid_show_start,
8718 .dumpit = lnet_cpt_of_nid_show_dump,
8720 .dumpit = lnet_old_cpt_of_nid_show_dump,
8722 .done = lnet_cpt_of_nid_show_done,
8725 .cmd = LNET_CMD_PEER_DIST,
8726 #ifdef HAVE_NETLINK_CALLBACK_START
8727 .start = lnet_peer_dist_show_start,
8728 .dumpit = lnet_peer_dist_show_dump,
8730 .dumpit = lnet_old_peer_dist_show_dump,
8732 .done = lnet_peer_dist_show_done,
8736 static struct genl_family lnet_family = {
8737 .name = LNET_GENL_NAME,
8738 .version = LNET_GENL_VERSION,
8739 .module = THIS_MODULE,
8740 .parallel_ops = true,
8742 .ops = lnet_genl_ops,
8743 .n_ops = ARRAY_SIZE(lnet_genl_ops),
8744 .mcgrps = lnet_mcast_grps,
8745 .n_mcgrps = ARRAY_SIZE(lnet_mcast_grps),
8746 #ifdef GENL_FAMILY_HAS_RESV_START_OP
8747 .resv_start_op = __LNET_CMD_MAX_PLUS_ONE,
8751 void LNetDebugPeer(struct lnet_processid *id)
8753 lnet_debug_peer(&id->nid);
8755 EXPORT_SYMBOL(LNetDebugPeer);
8758 * Determine if the specified peer \a nid is on the local node.
8760 * \param nid peer nid to check
8762 * \retval true If peer NID is on the local node.
8763 * \retval false If peer NID is not on the local node.
8765 bool LNetIsPeerLocal(struct lnet_nid *nid)
8767 struct lnet_net *net;
8771 cpt = lnet_net_lock_current();
8772 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
8773 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
8774 if (nid_same(&ni->ni_nid, nid)) {
8775 lnet_net_unlock(cpt);
8780 lnet_net_unlock(cpt);
8784 EXPORT_SYMBOL(LNetIsPeerLocal);
8787 * Retrieve the struct lnet_process_id ID of LNet interface at \a index.
8788 * Note that all interfaces share a same PID, as requested by LNetNIInit().
8790 * @index Index of the interface to look up.
8791 * @id On successful return, this location will hold the
8792 * struct lnet_process_id ID of the interface.
8793 * @large_nids Report large NIDs if this is true.
8795 * RETURN 0 If an interface exists at \a index.
8796 * -ENOENT If no interface has been found.
8799 LNetGetId(unsigned int index, struct lnet_processid *id, bool large_nids)
8802 struct lnet_net *net;
8806 LASSERT(the_lnet.ln_refcount > 0);
8808 cpt = lnet_net_lock_current();
8810 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
8811 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
8812 if (!large_nids && !nid_is_nid4(&ni->ni_nid))
8818 id->nid = ni->ni_nid;
8819 id->pid = the_lnet.ln_pid;
8825 lnet_net_unlock(cpt);
8828 EXPORT_SYMBOL(LNetGetId);
8834 struct lnet_handle_md mdh;
8835 struct completion completion;
8839 lnet_ping_event_handler(struct lnet_event *event)
8841 struct ping_data *pd = event->md_user_ptr;
8843 CDEBUG(D_NET, "ping event (%d %d)%s\n",
8844 event->type, event->status,
8845 event->unlinked ? " unlinked" : "");
8847 if (event->status) {
8849 pd->rc = event->status;
8850 } else if (event->type == LNET_EVENT_REPLY) {
8852 pd->rc = event->mlength;
8855 if (event->unlinked)
8856 pd->pd_unlinked = 1;
8858 if (event->unlinked ||
8859 (event->type == LNET_EVENT_SEND && event->status))
8860 complete(&pd->completion);
8863 static int lnet_ping(struct lnet_processid *id, struct lnet_nid *src_nid,
8864 signed long timeout, struct lnet_genl_ping_list *plist,
8867 int id_bytes = sizeof(struct lnet_ni_status); /* For 0@lo */
8868 struct lnet_md md = { NULL };
8869 struct ping_data pd = { 0 };
8870 struct lnet_ping_buffer *pbuf;
8871 struct lnet_processid pid;
8872 struct lnet_ping_iter pi;
8879 genradix_init(&plist->lgpl_list);
8881 /* n_ids limit is arbitrary */
8882 if (n_ids <= 0 || LNET_NID_IS_ANY(&id->nid))
8885 /* if the user buffer has more space than the lnet_interfaces_max
8886 * then only fill it up to lnet_interfaces_max
8888 if (n_ids > lnet_interfaces_max)
8889 n_ids = lnet_interfaces_max;
8891 if (id->pid == LNET_PID_ANY)
8892 id->pid = LNET_PID_LUSTRE;
8894 id_bytes += n_ids * sizeof(struct lnet_nid);
8895 pbuf = lnet_ping_buffer_alloc(id_bytes, GFP_NOFS);
8899 /* initialize md content */
8900 md.start = &pbuf->pb_info;
8901 md.length = id_bytes;
8902 md.threshold = 2; /* GET/REPLY */
8904 md.options = LNET_MD_TRUNCATE;
8906 md.handler = lnet_ping_event_handler;
8908 init_completion(&pd.completion);
8910 rc = LNetMDBind(&md, LNET_UNLINK, &pd.mdh);
8912 CERROR("Can't bind MD: %d\n", rc);
8913 goto fail_ping_buffer_decref;
8916 rc = LNetGet(src_nid, pd.mdh, id, LNET_RESERVED_PORTAL,
8917 LNET_PROTO_PING_MATCHBITS, 0, false);
8919 /* Don't CERROR; this could be deliberate! */
8920 rc2 = LNetMDUnlink(pd.mdh);
8923 /* NB must wait for the UNLINK event below... */
8926 /* Ensure completion in finite time... */
8927 wait_for_completion_timeout(&pd.completion, timeout);
8928 if (!pd.pd_unlinked) {
8929 LNetMDUnlink(pd.mdh);
8930 wait_for_completion(&pd.completion);
8935 goto fail_ping_buffer_decref;
8939 LASSERT(nob >= 0 && nob <= id_bytes);
8941 rc = -EPROTO; /* if I can't parse... */
8943 if (nob < LNET_PING_INFO_HDR_SIZE) {
8944 CERROR("%s: ping info too short %d\n",
8945 libcfs_idstr(id), nob);
8946 goto fail_ping_buffer_decref;
8949 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) {
8950 lnet_swap_pinginfo(pbuf);
8951 } else if (pbuf->pb_info.pi_magic != LNET_PROTO_PING_MAGIC) {
8952 CERROR("%s: Unexpected magic %08x\n",
8953 libcfs_idstr(id), pbuf->pb_info.pi_magic);
8954 goto fail_ping_buffer_decref;
8957 if ((pbuf->pb_info.pi_features & LNET_PING_FEAT_NI_STATUS) == 0) {
8958 CERROR("%s: ping w/o NI status: 0x%x\n",
8959 libcfs_idstr(id), pbuf->pb_info.pi_features);
8960 goto fail_ping_buffer_decref;
8963 /* Test if smaller than lnet_pinginfo with just one pi_ni status info.
8964 * That one might contain size when large nids are used.
8966 if (nob < offsetof(struct lnet_ping_info, pi_ni[1])) {
8967 CERROR("%s: Short reply %d(%lu min)\n",
8968 libcfs_idstr(id), nob,
8969 offsetof(struct lnet_ping_info, pi_ni[1]));
8970 goto fail_ping_buffer_decref;
8973 if (ping_info_count_entries(pbuf) < n_ids) {
8974 n_ids = ping_info_count_entries(pbuf);
8975 id_bytes = lnet_ping_info_size(&pbuf->pb_info);
8978 if (nob < id_bytes) {
8979 CERROR("%s: Short reply %d(%d expected)\n",
8980 libcfs_idstr(id), nob, id_bytes);
8981 goto fail_ping_buffer_decref;
8984 for (st = ping_iter_first(&pi, pbuf, &pid.nid);
8986 st = ping_iter_next(&pi, &pid.nid)) {
8987 id = genradix_ptr_alloc(&plist->lgpl_list, i++, GFP_KERNEL);
8990 goto fail_ping_buffer_decref;
8993 id->pid = pbuf->pb_info.pi_pid;
8997 fail_ping_buffer_decref:
8998 lnet_ping_buffer_decref(pbuf);
9003 lnet_discover(struct lnet_processid *pid, u32 force,
9004 struct lnet_genl_ping_list *dlist)
9006 struct lnet_peer_ni *lpni;
9007 struct lnet_peer_ni *p;
9008 struct lnet_peer *lp;
9012 if (LNET_NID_IS_ANY(&pid->nid))
9015 if (pid->pid == LNET_PID_ANY)
9016 pid->pid = LNET_PID_LUSTRE;
9018 cpt = lnet_net_lock_current();
9019 lpni = lnet_peerni_by_nid_locked(&pid->nid, NULL, cpt);
9026 * Clearing the NIDS_UPTODATE flag ensures the peer will
9027 * be discovered, provided discovery has not been disabled.
9029 lp = lpni->lpni_peer_net->lpn_peer;
9030 spin_lock(&lp->lp_lock);
9031 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
9032 /* If the force flag is set, force a PING and PUSH as well. */
9034 lp->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH;
9035 spin_unlock(&lp->lp_lock);
9036 rc = lnet_discover_peer_locked(lpni, cpt, true);
9040 /* The lpni (or lp) for this NID may have changed and our ref is
9041 * the only thing keeping the old one around. Release the ref
9042 * and lookup the lpni again
9044 lnet_peer_ni_decref_locked(lpni);
9045 lpni = lnet_peer_ni_find_locked(&pid->nid);
9050 lp = lpni->lpni_peer_net->lpn_peer;
9052 dlist->lgpl_list_count = 0;
9054 while ((p = lnet_get_next_peer_ni_locked(lp, NULL, p)) != NULL) {
9055 struct lnet_processid *id;
9057 id = genradix_ptr_alloc(&dlist->lgpl_list,
9058 dlist->lgpl_list_count++, GFP_ATOMIC);
9064 id->nid = p->lpni_nid;
9066 rc = dlist->lgpl_list_count;
9069 lnet_peer_ni_decref_locked(lpni);
9071 lnet_net_unlock(cpt);
9077 * Retrieve peer discovery status.
9079 * \retval 1 if lnet_peer_discovery_disabled is 0
9080 * \retval 0 if lnet_peer_discovery_disabled is 1
9083 LNetGetPeerDiscoveryStatus(void)
9085 return !lnet_peer_discovery_disabled;
9087 EXPORT_SYMBOL(LNetGetPeerDiscoveryStatus);