1 // SPDX-License-Identifier: GPL-2.0
3 /* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Use is subject to license terms.
6 * Copyright (c) 2011, 2017, Intel Corporation.
9 /* This file is part of Lustre, http://www.lustre.org/ */
11 #define DEBUG_SUBSYSTEM S_LNET
13 #include <linux/ctype.h>
14 #include <linux/generic-radix-tree.h>
15 #include <linux/log2.h>
16 #include <linux/ktime.h>
17 #include <linux/moduleparam.h>
18 #include <linux/uaccess.h>
19 #ifdef HAVE_SCHED_HEADERS
20 #include <linux/sched/signal.h>
22 #include <net/genetlink.h>
24 #include <libcfs/linux/linux-net.h>
25 #include <lnet/udsp.h>
26 #include <lnet/lib-lnet.h>
28 #define D_LNI D_CONSOLE
31 * initialize ln_api_mutex statically, since it needs to be used in
32 * discovery_set callback. That module parameter callback can be called
33 * before module init completes. The mutex needs to be ready for use then.
35 struct lnet the_lnet = {
36 .ln_api_mutex = __MUTEX_INITIALIZER(the_lnet.ln_api_mutex),
37 }; /* THE state of the network */
38 EXPORT_SYMBOL(the_lnet);
40 static char *ip2nets = "";
41 module_param(ip2nets, charp, 0444);
42 MODULE_PARM_DESC(ip2nets, "LNET network <- IP table");
44 static char *networks = "";
45 module_param(networks, charp, 0444);
46 MODULE_PARM_DESC(networks, "local networks");
48 static char *routes = "";
49 module_param(routes, charp, 0444);
50 MODULE_PARM_DESC(routes, "routes to non-local networks");
52 static int rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
53 module_param(rnet_htable_size, int, 0444);
54 MODULE_PARM_DESC(rnet_htable_size, "size of remote network hash table");
56 static int use_tcp_bonding;
57 module_param(use_tcp_bonding, int, 0444);
58 MODULE_PARM_DESC(use_tcp_bonding,
59 "use_tcp_bonding parameter has been removed");
61 unsigned int lnet_numa_range = 0;
62 module_param(lnet_numa_range, uint, 0444);
63 MODULE_PARM_DESC(lnet_numa_range,
64 "NUMA range to consider during Multi-Rail selection");
67 * lnet_health_sensitivity determines by how much we decrement the health
68 * value on sending error. The value defaults to 100, which means health
69 * interface health is decremented by 100 points every failure.
71 unsigned int lnet_health_sensitivity = 100;
72 static int sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp);
73 #ifdef HAVE_KERNEL_PARAM_OPS
74 static struct kernel_param_ops param_ops_health_sensitivity = {
75 .set = sensitivity_set,
78 #define param_check_health_sensitivity(name, p) \
79 __param_check(name, p, int)
80 module_param(lnet_health_sensitivity, health_sensitivity, S_IRUGO|S_IWUSR);
82 module_param_call(lnet_health_sensitivity, sensitivity_set, param_get_int,
83 &lnet_health_sensitivity, S_IRUGO|S_IWUSR);
85 MODULE_PARM_DESC(lnet_health_sensitivity,
86 "Value to decrement the health value by on error");
89 * lnet_recovery_interval determines how often we should perform recovery
90 * on unhealthy interfaces.
92 unsigned int lnet_recovery_interval = 1;
93 static int recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp);
94 #ifdef HAVE_KERNEL_PARAM_OPS
95 static struct kernel_param_ops param_ops_recovery_interval = {
96 .set = recovery_interval_set,
99 #define param_check_recovery_interval(name, p) \
100 __param_check(name, p, int)
101 module_param(lnet_recovery_interval, recovery_interval, S_IRUGO|S_IWUSR);
103 module_param_call(lnet_recovery_interval, recovery_interval_set, param_get_int,
104 &lnet_recovery_interval, S_IRUGO|S_IWUSR);
106 MODULE_PARM_DESC(lnet_recovery_interval,
107 "DEPRECATED - Interval to recover unhealthy interfaces in seconds");
109 unsigned int lnet_recovery_limit;
110 module_param(lnet_recovery_limit, uint, 0644);
111 MODULE_PARM_DESC(lnet_recovery_limit,
112 "How long to attempt recovery of unhealthy peer interfaces in seconds. Set to 0 to allow indefinite recovery");
114 unsigned int lnet_max_recovery_ping_interval = 900;
115 unsigned int lnet_max_recovery_ping_count = 9;
116 static int max_recovery_ping_interval_set(const char *val,
117 cfs_kernel_param_arg_t *kp);
119 #define param_check_max_recovery_ping_interval(name, p) \
120 __param_check(name, p, int)
122 #ifdef HAVE_KERNEL_PARAM_OPS
123 static struct kernel_param_ops param_ops_max_recovery_ping_interval = {
124 .set = max_recovery_ping_interval_set,
125 .get = param_get_int,
127 module_param(lnet_max_recovery_ping_interval, max_recovery_ping_interval, 0644);
129 module_param_call(lnet_max_recovery_ping_interval, max_recovery_ping_interval,
130 param_get_int, &lnet_max_recovery_ping_interval, 0644);
132 MODULE_PARM_DESC(lnet_max_recovery_ping_interval,
133 "The max interval between LNet recovery pings, in seconds");
135 static int lnet_interfaces_max = LNET_INTERFACES_MAX_DEFAULT;
136 static int intf_max_set(const char *val, cfs_kernel_param_arg_t *kp);
138 static struct kernel_param_ops param_ops_interfaces_max = {
140 .get = param_get_int,
143 #define param_check_interfaces_max(name, p) \
144 __param_check(name, p, int)
146 #ifdef HAVE_KERNEL_PARAM_OPS
147 module_param(lnet_interfaces_max, interfaces_max, 0644);
149 module_param_call(lnet_interfaces_max, intf_max_set, param_get_int,
150 ¶m_ops_interfaces_max, 0644);
152 MODULE_PARM_DESC(lnet_interfaces_max,
153 "Maximum number of interfaces in a node.");
155 unsigned lnet_peer_discovery_disabled = 0;
156 static int discovery_set(const char *val, cfs_kernel_param_arg_t *kp);
158 static struct kernel_param_ops param_ops_discovery_disabled = {
159 .set = discovery_set,
160 .get = param_get_int,
163 #define param_check_discovery_disabled(name, p) \
164 __param_check(name, p, int)
165 #ifdef HAVE_KERNEL_PARAM_OPS
166 module_param(lnet_peer_discovery_disabled, discovery_disabled, 0644);
168 module_param_call(lnet_peer_discovery_disabled, discovery_set, param_get_int,
169 ¶m_ops_discovery_disabled, 0644);
171 MODULE_PARM_DESC(lnet_peer_discovery_disabled,
172 "Set to 1 to disable peer discovery on this node.");
174 unsigned int lnet_drop_asym_route;
175 static int drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp);
177 static struct kernel_param_ops param_ops_drop_asym_route = {
178 .set = drop_asym_route_set,
179 .get = param_get_int,
182 #define param_check_drop_asym_route(name, p) \
183 __param_check(name, p, int)
184 #ifdef HAVE_KERNEL_PARAM_OPS
185 module_param(lnet_drop_asym_route, drop_asym_route, 0644);
187 module_param_call(lnet_drop_asym_route, drop_asym_route_set, param_get_int,
188 ¶m_ops_drop_asym_route, 0644);
190 MODULE_PARM_DESC(lnet_drop_asym_route,
191 "Set to 1 to drop asymmetrical route messages.");
193 #define LNET_TRANSACTION_TIMEOUT_DEFAULT 150
194 unsigned int lnet_transaction_timeout = LNET_TRANSACTION_TIMEOUT_DEFAULT;
195 static int transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp);
196 #ifdef HAVE_KERNEL_PARAM_OPS
197 static struct kernel_param_ops param_ops_transaction_timeout = {
198 .set = transaction_to_set,
199 .get = param_get_int,
202 #define param_check_transaction_timeout(name, p) \
203 __param_check(name, p, int)
204 module_param(lnet_transaction_timeout, transaction_timeout, S_IRUGO|S_IWUSR);
206 module_param_call(lnet_transaction_timeout, transaction_to_set, param_get_int,
207 &lnet_transaction_timeout, S_IRUGO|S_IWUSR);
209 MODULE_PARM_DESC(lnet_transaction_timeout,
210 "Maximum number of seconds to wait for a peer response.");
212 #define LNET_RETRY_COUNT_DEFAULT 2
213 unsigned int lnet_retry_count = LNET_RETRY_COUNT_DEFAULT;
214 static int retry_count_set(const char *val, cfs_kernel_param_arg_t *kp);
215 #ifdef HAVE_KERNEL_PARAM_OPS
216 static struct kernel_param_ops param_ops_retry_count = {
217 .set = retry_count_set,
218 .get = param_get_int,
221 #define param_check_retry_count(name, p) \
222 __param_check(name, p, int)
223 module_param(lnet_retry_count, retry_count, S_IRUGO|S_IWUSR);
225 module_param_call(lnet_retry_count, retry_count_set, param_get_int,
226 &lnet_retry_count, S_IRUGO|S_IWUSR);
228 MODULE_PARM_DESC(lnet_retry_count,
229 "Maximum number of times to retry transmitting a message");
231 unsigned int lnet_response_tracking = 3;
232 static int response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp);
234 #ifdef HAVE_KERNEL_PARAM_OPS
235 static struct kernel_param_ops param_ops_response_tracking = {
236 .set = response_tracking_set,
237 .get = param_get_int,
240 #define param_check_response_tracking(name, p) \
241 __param_check(name, p, int)
242 module_param(lnet_response_tracking, response_tracking, 0644);
244 module_param_call(lnet_response_tracking, response_tracking_set, param_get_int,
245 &lnet_response_tracking, 0644);
247 MODULE_PARM_DESC(lnet_response_tracking,
248 "(0|1|2|3) LNet Internal Only|GET Reply only|PUT ACK only|Full Tracking (default)");
250 int lock_prim_nid = 1;
251 module_param(lock_prim_nid, int, 0444);
252 MODULE_PARM_DESC(lock_prim_nid,
253 "Whether nid passed down by Lustre is locked as primary");
255 #define LNET_LND_TIMEOUT_DEFAULT ((LNET_TRANSACTION_TIMEOUT_DEFAULT - 1) / \
256 (LNET_RETRY_COUNT_DEFAULT + 1))
257 unsigned int lnet_lnd_timeout = LNET_LND_TIMEOUT_DEFAULT;
258 static void lnet_set_lnd_timeout(void)
260 lnet_lnd_timeout = max((lnet_transaction_timeout - 1) /
261 (lnet_retry_count + 1), 1U);
265 * This sequence number keeps track of how many times DLC was used to
266 * update the local NIs. It is incremented when a NI is added or
267 * removed and checked when sending a message to determine if there is
268 * a need to re-run the selection algorithm. See lnet_select_pathway()
269 * for more details on its usage.
271 static atomic_t lnet_dlc_seq_no = ATOMIC_INIT(0);
273 struct lnet_fail_ping {
274 struct lnet_processid lfp_id;
279 struct lnet_genl_ping_list {
280 unsigned int lgpl_index;
281 unsigned int lgpl_list_count;
282 unsigned int lgpl_failed_count;
283 signed long lgpl_timeout;
284 struct lnet_nid lgpl_src_nid;
285 GENRADIX(struct lnet_fail_ping) lgpl_failed;
286 GENRADIX(struct lnet_processid) lgpl_list;
289 static int lnet_ping(struct lnet_processid *id, struct lnet_nid *src_nid,
290 signed long timeout, struct lnet_genl_ping_list *plist,
293 static int lnet_discover(struct lnet_processid *id, u32 force,
294 struct lnet_genl_ping_list *dlists);
297 sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
300 unsigned *sensitivity = (unsigned *)kp->arg;
303 rc = kstrtoul(val, 0, &value);
305 CERROR("Invalid module parameter value for 'lnet_health_sensitivity'\n");
310 * The purpose of locking the api_mutex here is to ensure that
311 * the correct value ends up stored properly.
313 mutex_lock(&the_lnet.ln_api_mutex);
315 if (value > LNET_MAX_HEALTH_VALUE) {
316 mutex_unlock(&the_lnet.ln_api_mutex);
317 CERROR("Invalid health value. Maximum: %d value = %lu\n",
318 LNET_MAX_HEALTH_VALUE, value);
322 if (*sensitivity != 0 && value == 0 && lnet_retry_count != 0) {
323 lnet_retry_count = 0;
324 lnet_set_lnd_timeout();
327 *sensitivity = value;
329 mutex_unlock(&the_lnet.ln_api_mutex);
335 recovery_interval_set(const char *val, cfs_kernel_param_arg_t *kp)
337 CWARN("'lnet_recovery_interval' has been deprecated\n");
343 max_recovery_ping_interval_set(const char *val, cfs_kernel_param_arg_t *kp)
348 rc = kstrtoul(val, 0, &value);
350 CERROR("Invalid module parameter value for 'lnet_max_recovery_ping_interval'\n");
355 CERROR("Invalid max ping timeout. Must be strictly positive\n");
359 /* The purpose of locking the api_mutex here is to ensure that
360 * the correct value ends up stored properly.
362 mutex_lock(&the_lnet.ln_api_mutex);
363 lnet_max_recovery_ping_interval = value;
364 lnet_max_recovery_ping_count = 0;
367 lnet_max_recovery_ping_count++;
370 mutex_unlock(&the_lnet.ln_api_mutex);
376 discovery_set(const char *val, cfs_kernel_param_arg_t *kp)
379 unsigned *discovery_off = (unsigned *)kp->arg;
381 struct lnet_ping_buffer *pbuf;
383 rc = kstrtoul(val, 0, &value);
385 CERROR("Invalid module parameter value for 'lnet_peer_discovery_disabled'\n");
389 value = (value) ? 1 : 0;
392 * The purpose of locking the api_mutex here is to ensure that
393 * the correct value ends up stored properly.
395 mutex_lock(&the_lnet.ln_api_mutex);
397 if (value == *discovery_off) {
398 mutex_unlock(&the_lnet.ln_api_mutex);
403 * We still want to set the discovery value even when LNet is not
404 * running. This is the case when LNet is being loaded and we want
405 * the module parameters to take effect. Otherwise if we're
406 * changing the value dynamically, we want to set it after
409 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
410 *discovery_off = value;
411 mutex_unlock(&the_lnet.ln_api_mutex);
415 /* tell peers that discovery setting has changed */
416 lnet_net_lock(LNET_LOCK_EX);
417 pbuf = the_lnet.ln_ping_target;
419 pbuf->pb_info.pi_features &= ~LNET_PING_FEAT_DISCOVERY;
421 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
422 lnet_net_unlock(LNET_LOCK_EX);
424 /* only send a push when we're turning off discovery */
425 if (*discovery_off <= 0 && value > 0)
426 lnet_push_update_to_peers(1);
427 *discovery_off = value;
429 mutex_unlock(&the_lnet.ln_api_mutex);
435 drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp)
438 unsigned int *drop_asym_route = (unsigned int *)kp->arg;
441 rc = kstrtoul(val, 0, &value);
443 CERROR("Invalid module parameter value for "
444 "'lnet_drop_asym_route'\n");
449 * The purpose of locking the api_mutex here is to ensure that
450 * the correct value ends up stored properly.
452 mutex_lock(&the_lnet.ln_api_mutex);
454 if (value == *drop_asym_route) {
455 mutex_unlock(&the_lnet.ln_api_mutex);
459 *drop_asym_route = value;
461 mutex_unlock(&the_lnet.ln_api_mutex);
467 transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp)
470 unsigned *transaction_to = (unsigned *)kp->arg;
473 rc = kstrtoul(val, 0, &value);
475 CERROR("Invalid module parameter value for 'lnet_transaction_timeout'\n");
480 * The purpose of locking the api_mutex here is to ensure that
481 * the correct value ends up stored properly.
483 mutex_lock(&the_lnet.ln_api_mutex);
485 if (value <= lnet_retry_count || value == 0) {
486 mutex_unlock(&the_lnet.ln_api_mutex);
487 CERROR("Invalid value for lnet_transaction_timeout (%lu). "
488 "Has to be greater than lnet_retry_count (%u)\n",
489 value, lnet_retry_count);
493 if (value == *transaction_to) {
494 mutex_unlock(&the_lnet.ln_api_mutex);
498 *transaction_to = value;
499 /* Update the lnet_lnd_timeout now that we've modified the
500 * transaction timeout
502 lnet_set_lnd_timeout();
504 mutex_unlock(&the_lnet.ln_api_mutex);
510 retry_count_set(const char *val, cfs_kernel_param_arg_t *kp)
513 unsigned *retry_count = (unsigned *)kp->arg;
516 rc = kstrtoul(val, 0, &value);
518 CERROR("Invalid module parameter value for 'lnet_retry_count'\n");
523 * The purpose of locking the api_mutex here is to ensure that
524 * the correct value ends up stored properly.
526 mutex_lock(&the_lnet.ln_api_mutex);
528 if (lnet_health_sensitivity == 0 && value > 0) {
529 mutex_unlock(&the_lnet.ln_api_mutex);
530 CERROR("Can not set lnet_retry_count when health feature is turned off\n");
534 if (value > lnet_transaction_timeout) {
535 mutex_unlock(&the_lnet.ln_api_mutex);
536 CERROR("Invalid value for lnet_retry_count (%lu). "
537 "Has to be smaller than lnet_transaction_timeout (%u)\n",
538 value, lnet_transaction_timeout);
542 *retry_count = value;
544 /* Update the lnet_lnd_timeout now that we've modified the
547 lnet_set_lnd_timeout();
549 mutex_unlock(&the_lnet.ln_api_mutex);
555 intf_max_set(const char *val, cfs_kernel_param_arg_t *kp)
559 rc = kstrtoint(val, 0, &value);
561 CERROR("Invalid module parameter value for 'lnet_interfaces_max'\n");
565 if (value < LNET_INTERFACES_MIN) {
566 CWARN("max interfaces provided are too small, setting to %d\n",
567 LNET_INTERFACES_MAX_DEFAULT);
568 value = LNET_INTERFACES_MAX_DEFAULT;
571 *(int *)kp->arg = value;
577 response_tracking_set(const char *val, cfs_kernel_param_arg_t *kp)
580 unsigned long new_value;
582 rc = kstrtoul(val, 0, &new_value);
584 CERROR("Invalid value for 'lnet_response_tracking'\n");
588 if (new_value < 0 || new_value > 3) {
589 CWARN("Invalid value (%lu) for 'lnet_response_tracking'\n",
594 lnet_response_tracking = new_value;
600 lnet_get_routes(void)
606 lnet_get_networks(void)
611 if (*networks != 0 && *ip2nets != 0) {
612 LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
613 "'ip2nets' but not both at once\n");
618 rc = lnet_parse_ip2nets(&nets, ip2nets);
619 return (rc == 0) ? nets : NULL;
629 lnet_init_locks(void)
631 spin_lock_init(&the_lnet.ln_eq_wait_lock);
632 spin_lock_init(&the_lnet.ln_msg_resend_lock);
633 init_completion(&the_lnet.ln_mt_wait_complete);
634 mutex_init(&the_lnet.ln_lnd_mutex);
637 struct kmem_cache *lnet_mes_cachep; /* MEs kmem_cache */
638 struct kmem_cache *lnet_small_mds_cachep; /* <= LNET_SMALL_MD_SIZE bytes
640 struct kmem_cache *lnet_udsp_cachep; /* udsp cache */
641 struct kmem_cache *lnet_rspt_cachep; /* response tracker cache */
642 struct kmem_cache *lnet_msg_cachep;
645 lnet_slab_setup(void)
647 /* create specific kmem_cache for MEs and small MDs (i.e., originally
648 * allocated in <size-xxx> kmem_cache).
650 lnet_mes_cachep = kmem_cache_create("lnet_MEs", sizeof(struct lnet_me),
652 if (!lnet_mes_cachep)
655 lnet_small_mds_cachep = kmem_cache_create("lnet_small_MDs",
656 LNET_SMALL_MD_SIZE, 0, 0,
658 if (!lnet_small_mds_cachep)
661 lnet_udsp_cachep = kmem_cache_create("lnet_udsp",
662 sizeof(struct lnet_udsp),
664 if (!lnet_udsp_cachep)
667 lnet_rspt_cachep = kmem_cache_create("lnet_rspt", sizeof(struct lnet_rsp_tracker),
669 if (!lnet_rspt_cachep)
672 lnet_msg_cachep = kmem_cache_create("lnet_msg", sizeof(struct lnet_msg),
674 if (!lnet_msg_cachep)
681 lnet_slab_cleanup(void)
683 if (lnet_msg_cachep) {
684 kmem_cache_destroy(lnet_msg_cachep);
685 lnet_msg_cachep = NULL;
688 if (lnet_rspt_cachep) {
689 kmem_cache_destroy(lnet_rspt_cachep);
690 lnet_rspt_cachep = NULL;
693 if (lnet_udsp_cachep) {
694 kmem_cache_destroy(lnet_udsp_cachep);
695 lnet_udsp_cachep = NULL;
698 if (lnet_small_mds_cachep) {
699 kmem_cache_destroy(lnet_small_mds_cachep);
700 lnet_small_mds_cachep = NULL;
703 if (lnet_mes_cachep) {
704 kmem_cache_destroy(lnet_mes_cachep);
705 lnet_mes_cachep = NULL;
710 lnet_create_remote_nets_table(void)
713 struct list_head *hash;
715 LASSERT(the_lnet.ln_remote_nets_hash == NULL);
716 LASSERT(the_lnet.ln_remote_nets_hbits > 0);
717 CFS_ALLOC_PTR_ARRAY(hash, LNET_REMOTE_NETS_HASH_SIZE);
719 CERROR("Failed to create remote nets hash table\n");
723 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
724 INIT_LIST_HEAD(&hash[i]);
725 the_lnet.ln_remote_nets_hash = hash;
730 lnet_destroy_remote_nets_table(void)
734 if (the_lnet.ln_remote_nets_hash == NULL)
737 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
738 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
740 CFS_FREE_PTR_ARRAY(the_lnet.ln_remote_nets_hash,
741 LNET_REMOTE_NETS_HASH_SIZE);
742 the_lnet.ln_remote_nets_hash = NULL;
746 lnet_destroy_locks(void)
748 if (the_lnet.ln_res_lock != NULL) {
749 cfs_percpt_lock_free(the_lnet.ln_res_lock);
750 the_lnet.ln_res_lock = NULL;
753 if (the_lnet.ln_net_lock != NULL) {
754 cfs_percpt_lock_free(the_lnet.ln_net_lock);
755 the_lnet.ln_net_lock = NULL;
760 lnet_create_locks(void)
764 the_lnet.ln_res_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
765 if (the_lnet.ln_res_lock == NULL)
768 the_lnet.ln_net_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
769 if (the_lnet.ln_net_lock == NULL)
775 lnet_destroy_locks();
779 static void lnet_assert_wire_constants(void)
781 /* Wire protocol assertions generated by 'wirecheck'
782 * running on Linux robert.bartonsoftware.com 2.6.8-1.521
783 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux
784 * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
788 BUILD_BUG_ON(LNET_PROTO_TCP_MAGIC != 0xeebc0ded);
789 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MAJOR != 1);
790 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MINOR != 0);
791 BUILD_BUG_ON(LNET_MSG_ACK != 0);
792 BUILD_BUG_ON(LNET_MSG_PUT != 1);
793 BUILD_BUG_ON(LNET_MSG_GET != 2);
794 BUILD_BUG_ON(LNET_MSG_REPLY != 3);
795 BUILD_BUG_ON(LNET_MSG_HELLO != 4);
797 BUILD_BUG_ON((int)sizeof(lnet_nid_t) != 8);
798 BUILD_BUG_ON((int)sizeof(lnet_pid_t) != 4);
800 /* Checks for struct lnet_nid */
801 BUILD_BUG_ON((int)sizeof(struct lnet_nid) != 20);
802 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_size) != 0);
803 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_size) != 1);
804 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_type) != 1);
805 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_type) != 1);
806 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_num) != 2);
807 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_num) != 2);
808 BUILD_BUG_ON((int)offsetof(struct lnet_nid, nid_addr) != 4);
809 BUILD_BUG_ON((int)sizeof(((struct lnet_nid *)0)->nid_addr) != 16);
811 /* Checks for struct lnet_process_id_packed */
812 BUILD_BUG_ON((int)sizeof(struct lnet_process_id_packed) != 12);
813 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, nid) != 0);
814 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->nid) != 8);
815 BUILD_BUG_ON((int)offsetof(struct lnet_process_id_packed, pid) != 8);
816 BUILD_BUG_ON((int)sizeof(((struct lnet_process_id_packed *)0)->pid) != 4);
818 /* Checks for struct lnet_handle_wire */
819 BUILD_BUG_ON((int)sizeof(struct lnet_handle_wire) != 16);
820 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
821 wh_interface_cookie) != 0);
822 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_interface_cookie) != 8);
823 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire,
824 wh_object_cookie) != 8);
825 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_object_cookie) != 8);
827 /* Checks for struct struct lnet_magicversion */
828 BUILD_BUG_ON((int)sizeof(struct lnet_magicversion) != 8);
829 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, magic) != 0);
830 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->magic) != 4);
831 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, version_major) != 4);
832 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_major) != 2);
833 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion,
834 version_minor) != 6);
835 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_minor) != 2);
837 /* Checks for struct _lnet_hdr_nid4 */
838 BUILD_BUG_ON((int)sizeof(struct _lnet_hdr_nid4) != 72);
839 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, dest_nid) != 0);
840 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->dest_nid) != 8);
841 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, src_nid) != 8);
842 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->src_nid) != 8);
843 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, dest_pid) != 16);
844 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->dest_pid) != 4);
845 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, src_pid) != 20);
846 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->src_pid) != 4);
847 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, type) != 24);
848 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->type) != 4);
849 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, payload_length) != 28);
850 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->payload_length) != 4);
851 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg) != 32);
852 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg) != 40);
855 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.dst_wmd) != 32);
856 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.dst_wmd) != 16);
857 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.match_bits) != 48);
858 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.match_bits) != 8);
859 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.ack.mlength) != 56);
860 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.ack.mlength) != 4);
863 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.ack_wmd) != 32);
864 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.ack_wmd) != 16);
865 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.match_bits) != 48);
866 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.match_bits) != 8);
867 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.hdr_data) != 56);
868 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.hdr_data) != 8);
869 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.ptl_index) != 64);
870 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.ptl_index) != 4);
871 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.put.offset) != 68);
872 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.put.offset) != 4);
875 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.return_wmd) != 32);
876 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.return_wmd) != 16);
877 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.match_bits) != 48);
878 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.match_bits) != 8);
879 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.ptl_index) != 56);
880 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.ptl_index) != 4);
881 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.src_offset) != 60);
882 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.src_offset) != 4);
883 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.get.sink_length) != 64);
884 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.get.sink_length) != 4);
887 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.reply.dst_wmd) != 32);
888 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.reply.dst_wmd) != 16);
891 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.hello.incarnation) != 32);
892 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.hello.incarnation) != 8);
893 BUILD_BUG_ON((int)offsetof(struct _lnet_hdr_nid4, msg.hello.type) != 40);
894 BUILD_BUG_ON((int)sizeof(((struct _lnet_hdr_nid4 *)0)->msg.hello.type) != 4);
896 /* Checks for struct lnet_ni_status and related constants */
897 BUILD_BUG_ON(LNET_NI_STATUS_INVALID != 0x00000000);
898 BUILD_BUG_ON(LNET_NI_STATUS_UP != 0x15aac0de);
899 BUILD_BUG_ON(LNET_NI_STATUS_DOWN != 0xdeadface);
901 /* Checks for struct lnet_ni_status */
902 BUILD_BUG_ON((int)sizeof(struct lnet_ni_status) != 16);
903 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_nid) != 0);
904 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_nid) != 8);
905 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_status) != 8);
906 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_status) != 4);
907 BUILD_BUG_ON((int)offsetof(struct lnet_ni_status, ns_msg_size) != 12);
908 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_status *)0)->ns_msg_size) != 4);
910 /* Checks for struct lnet_ni_large_status */
911 BUILD_BUG_ON((int)sizeof(struct lnet_ni_large_status) != 24);
912 BUILD_BUG_ON((int)offsetof(struct lnet_ni_large_status, ns_status) != 0);
913 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_large_status *)0)->ns_status) != 4);
914 BUILD_BUG_ON((int)offsetof(struct lnet_ni_large_status, ns_nid) != 4);
915 BUILD_BUG_ON((int)sizeof(((struct lnet_ni_large_status *)0)->ns_nid) != 20);
917 /* Checks for struct lnet_ping_info and related constants */
918 BUILD_BUG_ON(LNET_PROTO_PING_MAGIC != 0x70696E67);
919 BUILD_BUG_ON(LNET_PING_FEAT_INVAL != 0);
920 BUILD_BUG_ON(LNET_PING_FEAT_BASE != 1);
921 BUILD_BUG_ON(LNET_PING_FEAT_NI_STATUS != 2);
922 BUILD_BUG_ON(LNET_PING_FEAT_RTE_DISABLED != 4);
923 BUILD_BUG_ON(LNET_PING_FEAT_MULTI_RAIL != 8);
924 BUILD_BUG_ON(LNET_PING_FEAT_DISCOVERY != 16);
925 BUILD_BUG_ON(LNET_PING_FEAT_LARGE_ADDR != 32);
926 BUILD_BUG_ON(LNET_PING_FEAT_PRIMARY_LARGE != 64);
927 BUILD_BUG_ON(LNET_PING_FEAT_BITS != 127);
929 /* Checks for struct lnet_ping_info */
930 BUILD_BUG_ON((int)sizeof(struct lnet_ping_info) != 16);
931 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_magic) != 0);
932 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_magic) != 4);
933 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_features) != 4);
934 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_features) != 4);
935 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_pid) != 8);
936 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_pid) != 4);
937 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_nnis) != 12);
938 BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_nnis) != 4);
939 BUILD_BUG_ON((int)offsetof(struct lnet_ping_info, pi_ni) != 16);
940 BUILD_BUG_ON(offsetof(struct lnet_ping_info, pi_ni) != sizeof(struct lnet_ping_info));
942 /* Acceptor connection request */
943 BUILD_BUG_ON(LNET_PROTO_ACCEPTOR_VERSION != 1);
945 /* Checks for struct lnet_acceptor_connreq */
946 BUILD_BUG_ON((int)sizeof(struct lnet_acceptor_connreq) != 16);
947 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_magic) != 0);
948 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_magic) != 4);
949 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_version) != 4);
950 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_version) != 4);
951 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq, acr_nid) != 8);
952 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq *)0)->acr_nid) != 8);
954 /* Checks for struct lnet_acceptor_connreq_v2 */
955 BUILD_BUG_ON((int)sizeof(struct lnet_acceptor_connreq_v2) != 28);
956 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_magic) != 0);
957 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_magic) != 4);
958 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_version) != 4);
959 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_version) != 4);
960 BUILD_BUG_ON((int)offsetof(struct lnet_acceptor_connreq_v2, acr_nid) != 8);
961 BUILD_BUG_ON((int)sizeof(((struct lnet_acceptor_connreq_v2 *)0)->acr_nid) != 20);
963 /* Checks for struct lnet_counters_common */
964 BUILD_BUG_ON((int)sizeof(struct lnet_counters_common) != 60);
965 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_alloc) != 0);
966 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_alloc) != 4);
967 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_msgs_max) != 4);
968 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_msgs_max) != 4);
969 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_errors) != 8);
970 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_errors) != 4);
971 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_count) != 12);
972 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_count) != 4);
973 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_count) != 16);
974 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_count) != 4);
975 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_count) != 20);
976 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_count) != 4);
977 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_count) != 24);
978 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_count) != 4);
979 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_send_length) != 28);
980 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_send_length) != 8);
981 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_recv_length) != 36);
982 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_recv_length) != 8);
983 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_route_length) != 44);
984 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_route_length) != 8);
985 BUILD_BUG_ON((int)offsetof(struct lnet_counters_common, lcc_drop_length) != 52);
986 BUILD_BUG_ON((int)sizeof(((struct lnet_counters_common *)0)->lcc_drop_length) != 8);
989 static const struct lnet_lnd *lnet_find_lnd_by_type(__u32 type)
991 const struct lnet_lnd *lnd;
993 /* holding lnd mutex */
994 if (type >= NUM_LNDS)
996 lnd = the_lnet.ln_lnds[type];
997 LASSERT(!lnd || lnd->lnd_type == type);
1003 lnet_get_lnd_timeout(void)
1005 return lnet_lnd_timeout;
1007 EXPORT_SYMBOL(lnet_get_lnd_timeout);
1010 lnet_register_lnd(const struct lnet_lnd *lnd)
1012 mutex_lock(&the_lnet.ln_lnd_mutex);
1014 LASSERT(libcfs_isknown_lnd(lnd->lnd_type));
1015 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
1017 the_lnet.ln_lnds[lnd->lnd_type] = lnd;
1019 CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type));
1021 mutex_unlock(&the_lnet.ln_lnd_mutex);
1023 EXPORT_SYMBOL(lnet_register_lnd);
1026 lnet_unregister_lnd(const struct lnet_lnd *lnd)
1028 mutex_lock(&the_lnet.ln_lnd_mutex);
1030 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
1032 the_lnet.ln_lnds[lnd->lnd_type] = NULL;
1033 CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type));
1035 mutex_unlock(&the_lnet.ln_lnd_mutex);
1037 EXPORT_SYMBOL(lnet_unregister_lnd);
1040 lnet_counters_get_common_locked(struct lnet_counters_common *common)
1042 struct lnet_counters *ctr;
1045 /* FIXME !!! Their is no assert_lnet_net_locked() to ensure this
1046 * actually called under the protection of the lnet_net_lock.
1048 memset(common, 0, sizeof(*common));
1050 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
1051 common->lcc_msgs_max += ctr->lct_common.lcc_msgs_max;
1052 common->lcc_msgs_alloc += ctr->lct_common.lcc_msgs_alloc;
1053 common->lcc_errors += ctr->lct_common.lcc_errors;
1054 common->lcc_send_count += ctr->lct_common.lcc_send_count;
1055 common->lcc_recv_count += ctr->lct_common.lcc_recv_count;
1056 common->lcc_route_count += ctr->lct_common.lcc_route_count;
1057 common->lcc_drop_count += ctr->lct_common.lcc_drop_count;
1058 common->lcc_send_length += ctr->lct_common.lcc_send_length;
1059 common->lcc_recv_length += ctr->lct_common.lcc_recv_length;
1060 common->lcc_route_length += ctr->lct_common.lcc_route_length;
1061 common->lcc_drop_length += ctr->lct_common.lcc_drop_length;
1066 lnet_counters_get_common(struct lnet_counters_common *common)
1068 lnet_net_lock(LNET_LOCK_EX);
1069 lnet_counters_get_common_locked(common);
1070 lnet_net_unlock(LNET_LOCK_EX);
1072 EXPORT_SYMBOL(lnet_counters_get_common);
1075 lnet_counters_get(struct lnet_counters *counters)
1077 struct lnet_counters *ctr;
1078 struct lnet_counters_health *health = &counters->lct_health;
1081 memset(counters, 0, sizeof(*counters));
1083 lnet_net_lock(LNET_LOCK_EX);
1085 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1086 GOTO(out_unlock, rc = -ENODEV);
1088 lnet_counters_get_common_locked(&counters->lct_common);
1090 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
1091 health->lch_rst_alloc += ctr->lct_health.lch_rst_alloc;
1092 health->lch_resend_count += ctr->lct_health.lch_resend_count;
1093 health->lch_response_timeout_count +=
1094 ctr->lct_health.lch_response_timeout_count;
1095 health->lch_local_interrupt_count +=
1096 ctr->lct_health.lch_local_interrupt_count;
1097 health->lch_local_dropped_count +=
1098 ctr->lct_health.lch_local_dropped_count;
1099 health->lch_local_aborted_count +=
1100 ctr->lct_health.lch_local_aborted_count;
1101 health->lch_local_no_route_count +=
1102 ctr->lct_health.lch_local_no_route_count;
1103 health->lch_local_timeout_count +=
1104 ctr->lct_health.lch_local_timeout_count;
1105 health->lch_local_error_count +=
1106 ctr->lct_health.lch_local_error_count;
1107 health->lch_remote_dropped_count +=
1108 ctr->lct_health.lch_remote_dropped_count;
1109 health->lch_remote_error_count +=
1110 ctr->lct_health.lch_remote_error_count;
1111 health->lch_remote_timeout_count +=
1112 ctr->lct_health.lch_remote_timeout_count;
1113 health->lch_network_timeout_count +=
1114 ctr->lct_health.lch_network_timeout_count;
1117 lnet_net_unlock(LNET_LOCK_EX);
1120 EXPORT_SYMBOL(lnet_counters_get);
1123 lnet_counters_reset(void)
1125 struct lnet_counters *counters;
1128 lnet_net_lock(LNET_LOCK_EX);
1130 if (the_lnet.ln_state != LNET_STATE_RUNNING)
1133 cfs_percpt_for_each(counters, i, the_lnet.ln_counters)
1134 memset(counters, 0, sizeof(struct lnet_counters));
1136 lnet_net_unlock(LNET_LOCK_EX);
1140 lnet_res_type2str(int type)
1145 case LNET_COOKIE_TYPE_MD:
1147 case LNET_COOKIE_TYPE_ME:
1149 case LNET_COOKIE_TYPE_EQ:
1155 lnet_res_container_cleanup(struct lnet_res_container *rec)
1159 if (rec->rec_type == 0) /* not set yet, it's uninitialized */
1162 while (!list_empty(&rec->rec_active)) {
1163 struct list_head *e = rec->rec_active.next;
1166 if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
1167 lnet_md_free(list_entry(e, struct lnet_libmd, md_list));
1169 } else { /* NB: Active MEs should be attached on portals */
1176 /* Found alive MD/ME/EQ, user really should unlink/free
1177 * all of them before finalize LNet, but if someone didn't,
1178 * we have to recycle garbage for him */
1179 CERROR("%d active elements on exit of %s container\n",
1180 count, lnet_res_type2str(rec->rec_type));
1183 if (rec->rec_lh_hash != NULL) {
1184 CFS_FREE_PTR_ARRAY(rec->rec_lh_hash, LNET_LH_HASH_SIZE);
1185 rec->rec_lh_hash = NULL;
1188 rec->rec_type = 0; /* mark it as finalized */
1192 lnet_res_container_setup(struct lnet_res_container *rec, int cpt, int type)
1197 LASSERT(rec->rec_type == 0);
1199 rec->rec_type = type;
1200 INIT_LIST_HEAD(&rec->rec_active);
1202 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type;
1204 /* Arbitrary choice of hash table size */
1205 LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt,
1206 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
1207 if (rec->rec_lh_hash == NULL) {
1212 for (i = 0; i < LNET_LH_HASH_SIZE; i++)
1213 INIT_LIST_HEAD(&rec->rec_lh_hash[i]);
1218 CERROR("Failed to setup %s resource container\n",
1219 lnet_res_type2str(type));
1220 lnet_res_container_cleanup(rec);
1225 lnet_res_containers_destroy(struct lnet_res_container **recs)
1227 struct lnet_res_container *rec;
1230 cfs_percpt_for_each(rec, i, recs)
1231 lnet_res_container_cleanup(rec);
1233 cfs_percpt_free(recs);
1236 static struct lnet_res_container **
1237 lnet_res_containers_create(int type)
1239 struct lnet_res_container **recs;
1240 struct lnet_res_container *rec;
1244 recs = cfs_percpt_alloc(lnet_cpt_table(), sizeof(*rec));
1246 CERROR("Failed to allocate %s resource containers\n",
1247 lnet_res_type2str(type));
1251 cfs_percpt_for_each(rec, i, recs) {
1252 rc = lnet_res_container_setup(rec, i, type);
1254 lnet_res_containers_destroy(recs);
1262 struct lnet_libhandle *
1263 lnet_res_lh_lookup(struct lnet_res_container *rec, __u64 cookie)
1265 /* ALWAYS called with lnet_res_lock held */
1266 struct list_head *head;
1267 struct lnet_libhandle *lh;
1270 if ((cookie & LNET_COOKIE_MASK) != rec->rec_type)
1273 hash = cookie >> (LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS);
1274 head = &rec->rec_lh_hash[hash & LNET_LH_HASH_MASK];
1276 list_for_each_entry(lh, head, lh_hash_chain) {
1277 if (lh->lh_cookie == cookie)
1285 lnet_res_lh_initialize(struct lnet_res_container *rec,
1286 struct lnet_libhandle *lh)
1288 /* ALWAYS called with lnet_res_lock held */
1289 unsigned int ibits = LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS;
1292 lh->lh_cookie = rec->rec_lh_cookie;
1293 rec->rec_lh_cookie += 1 << ibits;
1295 hash = (lh->lh_cookie >> ibits) & LNET_LH_HASH_MASK;
1297 list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
1301 lnet_create_array_of_queues(void)
1303 struct list_head **qs;
1304 struct list_head *q;
1307 qs = cfs_percpt_alloc(lnet_cpt_table(),
1308 sizeof(struct list_head));
1310 CERROR("Failed to allocate queues\n");
1314 cfs_percpt_for_each(q, i, qs)
1320 static int lnet_unprepare(void);
1323 lnet_prepare(lnet_pid_t requested_pid)
1325 /* Prepare to bring up the network */
1326 struct lnet_res_container **recs;
1329 if (requested_pid == LNET_PID_ANY) {
1330 /* Don't instantiate LNET just for me */
1334 LASSERT(the_lnet.ln_refcount == 0);
1336 the_lnet.ln_routing = 0;
1338 LASSERT((requested_pid & LNET_PID_USERFLAG) == 0);
1339 the_lnet.ln_pid = requested_pid;
1341 INIT_LIST_HEAD(&the_lnet.ln_test_peers);
1342 INIT_LIST_HEAD(&the_lnet.ln_remote_peer_ni_list);
1343 INIT_LIST_HEAD(&the_lnet.ln_nets);
1344 INIT_LIST_HEAD(&the_lnet.ln_routers);
1345 INIT_LIST_HEAD(&the_lnet.ln_drop_rules);
1346 INIT_LIST_HEAD(&the_lnet.ln_delay_rules);
1347 INIT_LIST_HEAD(&the_lnet.ln_dc_request);
1348 INIT_LIST_HEAD(&the_lnet.ln_dc_working);
1349 INIT_LIST_HEAD(&the_lnet.ln_dc_expired);
1350 INIT_LIST_HEAD(&the_lnet.ln_mt_localNIRecovq);
1351 INIT_LIST_HEAD(&the_lnet.ln_mt_peerNIRecovq);
1352 INIT_LIST_HEAD(&the_lnet.ln_udsp_list);
1353 init_waitqueue_head(&the_lnet.ln_dc_waitq);
1354 the_lnet.ln_mt_handler = NULL;
1355 init_completion(&the_lnet.ln_started);
1356 atomic_set(&the_lnet.ln_late_msg_count, 0);
1357 atomic64_set(&the_lnet.ln_late_msg_nsecs, 0);
1359 rc = lnet_slab_setup();
1363 rc = lnet_create_remote_nets_table();
1368 * NB the interface cookie in wire handles guards against delayed
1369 * replies and ACKs appearing valid after reboot.
1371 the_lnet.ln_interface_cookie = ktime_get_real_ns();
1373 the_lnet.ln_counters = cfs_percpt_alloc(lnet_cpt_table(),
1374 sizeof(struct lnet_counters));
1375 if (the_lnet.ln_counters == NULL) {
1376 CERROR("Failed to allocate counters for LNet\n");
1381 rc = lnet_peer_tables_create();
1385 rc = lnet_msg_containers_create();
1389 rc = lnet_res_container_setup(&the_lnet.ln_eq_container, 0,
1390 LNET_COOKIE_TYPE_EQ);
1394 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD);
1400 the_lnet.ln_md_containers = recs;
1402 rc = lnet_portals_create();
1404 CERROR("Failed to create portals for LNet: %d\n", rc);
1408 the_lnet.ln_mt_zombie_rstqs = lnet_create_array_of_queues();
1409 if (!the_lnet.ln_mt_zombie_rstqs) {
1422 lnet_unprepare(void)
1424 /* NB no LNET_LOCK since this is the last reference. All LND instances
1425 * have shut down already, so it is safe to unlink and free all
1426 * descriptors, even those that appear committed to a network op (eg MD
1427 * with non-zero pending count) */
1429 lnet_fail_nid(LNET_NID_ANY, 0);
1431 LASSERT(the_lnet.ln_refcount == 0);
1432 LASSERT(list_empty(&the_lnet.ln_test_peers));
1433 LASSERT(list_empty(&the_lnet.ln_nets));
1435 if (the_lnet.ln_mt_zombie_rstqs) {
1436 lnet_clean_zombie_rstqs();
1437 the_lnet.ln_mt_zombie_rstqs = NULL;
1440 lnet_assert_handler_unused(the_lnet.ln_mt_handler, true);
1441 the_lnet.ln_mt_handler = NULL;
1443 lnet_portals_destroy();
1445 if (the_lnet.ln_md_containers != NULL) {
1446 lnet_res_containers_destroy(the_lnet.ln_md_containers);
1447 the_lnet.ln_md_containers = NULL;
1450 lnet_res_container_cleanup(&the_lnet.ln_eq_container);
1452 lnet_msg_containers_destroy();
1454 lnet_rtrpools_free(0);
1456 if (the_lnet.ln_counters != NULL) {
1457 cfs_percpt_free(the_lnet.ln_counters);
1458 the_lnet.ln_counters = NULL;
1460 lnet_destroy_remote_nets_table();
1461 lnet_udsp_destroy(true);
1462 lnet_slab_cleanup();
1468 lnet_net2ni_locked(__u32 net_id, int cpt)
1471 struct lnet_net *net;
1473 LASSERT(cpt != LNET_LOCK_EX);
1475 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1476 if (net->net_id == net_id) {
1477 ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
1487 lnet_net2ni_addref(__u32 net)
1492 ni = lnet_net2ni_locked(net, 0);
1494 lnet_ni_addref_locked(ni, 0);
1499 EXPORT_SYMBOL(lnet_net2ni_addref);
1502 lnet_get_net_locked(__u32 net_id)
1504 struct lnet_net *net;
1506 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1507 if (net->net_id == net_id)
1515 lnet_net_clr_pref_rtrs(struct lnet_net *net)
1517 struct list_head zombies;
1518 struct lnet_nid_list *ne;
1519 struct lnet_nid_list *tmp;
1521 INIT_LIST_HEAD(&zombies);
1523 lnet_net_lock(LNET_LOCK_EX);
1524 list_splice_init(&net->net_rtr_pref_nids, &zombies);
1525 lnet_net_unlock(LNET_LOCK_EX);
1527 list_for_each_entry_safe(ne, tmp, &zombies, nl_list) {
1528 list_del_init(&ne->nl_list);
1529 LIBCFS_FREE(ne, sizeof(*ne));
1534 lnet_net_add_pref_rtr(struct lnet_net *net,
1535 struct lnet_nid *gw_nid)
1536 __must_hold(&the_lnet.ln_api_mutex)
1538 struct lnet_nid_list *ne;
1540 /* This function is called with api_mutex held. When the api_mutex
1541 * is held the list can not be modified, as it is only modified as
1542 * a result of applying a UDSP and that happens under api_mutex
1545 list_for_each_entry(ne, &net->net_rtr_pref_nids, nl_list) {
1546 if (nid_same(&ne->nl_nid, gw_nid))
1550 LIBCFS_ALLOC(ne, sizeof(*ne));
1554 ne->nl_nid = *gw_nid;
1556 /* Lock the cpt to protect against addition and checks in the
1557 * selection algorithm
1559 lnet_net_lock(LNET_LOCK_EX);
1560 list_add(&ne->nl_list, &net->net_rtr_pref_nids);
1561 lnet_net_unlock(LNET_LOCK_EX);
1567 lnet_nid4_cpt_hash(lnet_nid_t nid, unsigned int number)
1570 __u16 lnd = LNET_NETTYP(LNET_NIDNET(nid));
1573 if (lnd == KFILND || lnd == GNILND) {
1574 cpt = hash_long(key, LNET_CPT_BITS);
1576 /* NB: The number of CPTs needn't be a power of 2 */
1578 cpt = (key + cpt + (cpt >> 1)) % number;
1580 __u64 pair_bits = 0x0001000100010001LLU;
1581 __u64 mask = pair_bits * 0xFF;
1583 /* For ipv4 NIDs, use (sum-by-multiplication of nid bytes) mod
1584 * (number of CPTs) to match nid to a CPT.
1586 pair_sum = (key & mask) + ((key >> 8) & mask);
1587 pair_sum = (pair_sum * pair_bits) >> 48;
1588 cpt = (unsigned int)(pair_sum) % number;
1591 CDEBUG(D_NET, "Match nid %s to cpt %u\n",
1592 libcfs_nid2str(nid), cpt);
1598 lnet_nid_cpt_hash(struct lnet_nid *nid, unsigned int number)
1604 LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
1609 if (nid_is_nid4(nid))
1610 return lnet_nid4_cpt_hash(lnet_nid_to_nid4(nid), number);
1612 for (i = 0; i < 4; i++)
1613 h = cfs_hash_32(nid->nid_addr[i]^h, 32);
1614 val = cfs_hash_32(LNET_NID_NET(nid) ^ h, LNET_CPT_BITS);
1617 return (unsigned int)(h + val + (val >> 1)) % number;
1621 lnet_cpt_of_nid_locked(struct lnet_nid *nid, struct lnet_ni *ni)
1623 struct lnet_net *net;
1625 /* must called with hold of lnet_net_lock */
1626 if (LNET_CPT_NUMBER == 1)
1627 return 0; /* the only one */
1630 * If NI is provided then use the CPT identified in the NI cpt
1631 * list if one exists. If one doesn't exist, then that NI is
1632 * associated with all CPTs and it follows that the net it belongs
1633 * to is implicitly associated with all CPTs, so just hash the nid
1637 if (ni->ni_cpts != NULL)
1638 return ni->ni_cpts[lnet_nid_cpt_hash(nid,
1641 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1644 /* no NI provided so look at the net */
1645 net = lnet_get_net_locked(LNET_NID_NET(nid));
1647 if (net != NULL && net->net_cpts != NULL) {
1648 return net->net_cpts[lnet_nid_cpt_hash(nid, net->net_ncpts)];
1651 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
1655 lnet_nid2cpt(struct lnet_nid *nid, struct lnet_ni *ni)
1660 if (LNET_CPT_NUMBER == 1)
1661 return 0; /* the only one */
1663 cpt = lnet_net_lock_current();
1665 cpt2 = lnet_cpt_of_nid_locked(nid, ni);
1667 lnet_net_unlock(cpt);
1671 EXPORT_SYMBOL(lnet_nid2cpt);
1674 lnet_cpt_of_nid(lnet_nid_t nid4, struct lnet_ni *ni)
1676 struct lnet_nid nid;
1678 if (LNET_CPT_NUMBER == 1)
1679 return 0; /* the only one */
1681 lnet_nid4_to_nid(nid4, &nid);
1682 return lnet_nid2cpt(&nid, ni);
1684 EXPORT_SYMBOL(lnet_cpt_of_nid);
1687 lnet_islocalnet_locked(__u32 net_id)
1689 struct lnet_net *net;
1692 net = lnet_get_net_locked(net_id);
1694 local = net != NULL;
1700 lnet_islocalnet(__u32 net_id)
1705 cpt = lnet_net_lock_current();
1707 local = lnet_islocalnet_locked(net_id);
1709 lnet_net_unlock(cpt);
1715 lnet_nid_to_ni_locked(struct lnet_nid *nid, int cpt)
1717 struct lnet_net *net;
1720 LASSERT(cpt != LNET_LOCK_EX);
1722 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1723 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1724 if (nid_same(&ni->ni_nid, nid))
1733 lnet_nid_to_ni_addref(struct lnet_nid *nid)
1738 ni = lnet_nid_to_ni_locked(nid, 0);
1740 lnet_ni_addref_locked(ni, 0);
1745 EXPORT_SYMBOL(lnet_nid_to_ni_addref);
1748 lnet_islocalnid(struct lnet_nid *nid)
1753 cpt = lnet_net_lock_current();
1754 ni = lnet_nid_to_ni_locked(nid, cpt);
1755 lnet_net_unlock(cpt);
1761 lnet_count_acceptor_nets(void)
1763 /* Return the # of NIs that need the acceptor. */
1765 struct lnet_net *net;
1768 cpt = lnet_net_lock_current();
1769 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1770 /* all socklnd type networks should have the acceptor
1772 if (net->net_lnd->lnd_accept != NULL)
1776 lnet_net_unlock(cpt);
1781 struct lnet_ping_buffer *
1782 lnet_ping_buffer_alloc(int nbytes, gfp_t gfp)
1784 struct lnet_ping_buffer *pbuf;
1786 LIBCFS_ALLOC_GFP(pbuf, LNET_PING_BUFFER_SIZE(nbytes), gfp);
1788 pbuf->pb_nbytes = nbytes; /* sizeof of pb_info */
1789 pbuf->pb_needs_post = false;
1790 atomic_set(&pbuf->pb_refcnt, 1);
1797 lnet_ping_buffer_free(struct lnet_ping_buffer *pbuf)
1799 LASSERT(atomic_read(&pbuf->pb_refcnt) == 0);
1800 LIBCFS_FREE(pbuf, LNET_PING_BUFFER_SIZE(pbuf->pb_nbytes));
1803 static struct lnet_ping_buffer *
1804 lnet_ping_target_create(int nbytes)
1806 struct lnet_ping_buffer *pbuf;
1808 pbuf = lnet_ping_buffer_alloc(nbytes, GFP_NOFS);
1810 CERROR("Can't allocate ping source [%d]\n", nbytes);
1814 pbuf->pb_info.pi_nnis = 0;
1815 pbuf->pb_info.pi_pid = the_lnet.ln_pid;
1816 pbuf->pb_info.pi_magic = LNET_PROTO_PING_MAGIC;
1817 pbuf->pb_info.pi_features =
1818 LNET_PING_FEAT_NI_STATUS | LNET_PING_FEAT_MULTI_RAIL;
1824 lnet_get_net_ni_bytes_locked(struct lnet_net *net)
1829 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1830 bytes += lnet_ping_sts_size(&ni->ni_nid);
1836 lnet_get_ni_bytes(void)
1839 struct lnet_net *net;
1844 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1845 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1846 bytes += lnet_ping_sts_size(&ni->ni_nid);
1855 lnet_swap_pinginfo(struct lnet_ping_buffer *pbuf)
1857 struct lnet_ni_large_status *lstat, *lend;
1858 struct lnet_ni_status *stat, *end;
1862 __swab32s(&pbuf->pb_info.pi_magic);
1863 __swab32s(&pbuf->pb_info.pi_features);
1864 __swab32s(&pbuf->pb_info.pi_pid);
1865 __swab32s(&pbuf->pb_info.pi_nnis);
1866 nnis = pbuf->pb_info.pi_nnis;
1867 stat = &pbuf->pb_info.pi_ni[0];
1868 end = (void *)&pbuf->pb_info + pbuf->pb_nbytes;
1869 for (i = 0; i < nnis && stat + 1 <= end; i++, stat++) {
1870 __swab64s(&stat->ns_nid);
1871 __swab32s(&stat->ns_status);
1873 /* Might be total size */
1874 __swab32s(&stat->ns_msg_size);
1876 if (!(pbuf->pb_info.pi_features & LNET_PING_FEAT_LARGE_ADDR))
1879 lstat = (struct lnet_ni_large_status *)stat;
1881 while (lstat + 1 <= lend) {
1882 __swab32s(&lstat->ns_status);
1883 /* struct lnet_nid never needs to be swabed */
1884 lstat = lnet_ping_sts_next(lstat);
1889 lnet_ping_info_validate(struct lnet_ping_info *pinfo)
1893 if (pinfo->pi_magic != LNET_PROTO_PING_MAGIC)
1895 if (!(pinfo->pi_features & LNET_PING_FEAT_NI_STATUS))
1897 /* Loopback is guaranteed to be present */
1898 if (pinfo->pi_nnis < 1 || pinfo->pi_nnis > lnet_interfaces_max)
1900 if (LNET_PING_INFO_LONI(pinfo) != LNET_NID_LO_0)
1906 lnet_ping_target_destroy(void)
1908 struct lnet_net *net;
1911 lnet_net_lock(LNET_LOCK_EX);
1913 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1914 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1916 ni->ni_status = NULL;
1921 lnet_ping_buffer_decref(the_lnet.ln_ping_target);
1922 the_lnet.ln_ping_target = NULL;
1924 lnet_net_unlock(LNET_LOCK_EX);
1928 lnet_ping_target_event_handler(struct lnet_event *event)
1930 struct lnet_ping_buffer *pbuf = event->md_user_ptr;
1932 if (event->unlinked)
1933 lnet_ping_buffer_decref(pbuf);
1937 lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
1938 struct lnet_handle_md *ping_mdh,
1939 int ni_bytes, bool set_eq)
1941 struct lnet_processid id = {
1942 .nid = LNET_ANY_NID,
1946 struct lnet_md md = { NULL };
1950 the_lnet.ln_ping_target_handler =
1951 lnet_ping_target_event_handler;
1953 *ppbuf = lnet_ping_target_create(ni_bytes);
1954 if (*ppbuf == NULL) {
1959 /* Ping target ME/MD */
1960 me = LNetMEAttach(LNET_RESERVED_PORTAL, &id,
1961 LNET_PROTO_PING_MATCHBITS, 0,
1962 LNET_UNLINK, LNET_INS_AFTER);
1965 CERROR("Can't create ping target ME: %d\n", rc);
1966 goto fail_decref_ping_buffer;
1969 /* initialize md content */
1970 md.start = &(*ppbuf)->pb_info;
1971 md.length = (*ppbuf)->pb_nbytes;
1972 md.threshold = LNET_MD_THRESH_INF;
1974 md.options = LNET_MD_OP_GET | LNET_MD_TRUNCATE |
1975 LNET_MD_MANAGE_REMOTE;
1976 md.handler = the_lnet.ln_ping_target_handler;
1977 md.user_ptr = *ppbuf;
1979 rc = LNetMDAttach(me, &md, LNET_RETAIN, ping_mdh);
1981 CERROR("Can't attach ping target MD: %d\n", rc);
1982 goto fail_decref_ping_buffer;
1984 lnet_ping_buffer_addref(*ppbuf);
1988 fail_decref_ping_buffer:
1989 LASSERT(atomic_read(&(*ppbuf)->pb_refcnt) == 1);
1990 lnet_ping_buffer_decref(*ppbuf);
1997 lnet_ping_md_unlink(struct lnet_ping_buffer *pbuf,
1998 struct lnet_handle_md *ping_mdh)
2000 LNetMDUnlink(*ping_mdh);
2001 LNetInvalidateMDHandle(ping_mdh);
2003 /* NB the MD could be busy; this just starts the unlink */
2004 wait_var_event_warning(&pbuf->pb_refcnt,
2005 atomic_read(&pbuf->pb_refcnt) <= 1,
2006 "Still waiting for ping data MD to unlink\n");
2010 lnet_ping_target_install_locked(struct lnet_ping_buffer *pbuf)
2013 struct lnet_net *net;
2014 struct lnet_ni_status *ns, *end;
2015 struct lnet_ni_large_status *lns, *lend;
2018 pbuf->pb_info.pi_nnis = 0;
2019 ns = &pbuf->pb_info.pi_ni[0];
2020 end = (void *)&pbuf->pb_info + pbuf->pb_nbytes;
2021 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
2022 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
2023 if (!nid_is_nid4(&ni->ni_nid)) {
2024 if (ns == &pbuf->pb_info.pi_ni[1]) {
2025 /* This is primary, and it is long */
2026 pbuf->pb_info.pi_features |=
2027 LNET_PING_FEAT_PRIMARY_LARGE;
2031 LASSERT(ns + 1 <= end);
2032 ns->ns_nid = lnet_nid_to_nid4(&ni->ni_nid);
2035 ns->ns_status = lnet_ni_get_status_locked(ni);
2036 ni->ni_status = &ns->ns_status;
2039 pbuf->pb_info.pi_nnis++;
2046 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
2047 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
2048 if (nid_is_nid4(&ni->ni_nid))
2050 LASSERT(lns + 1 <= lend);
2052 lns->ns_nid = ni->ni_nid;
2055 lns->ns_status = lnet_ni_get_status_locked(ni);
2056 ni->ni_status = &lns->ns_status;
2059 lns = lnet_ping_sts_next(lns);
2062 if ((void *)lns > (void *)ns) {
2063 /* Record total info size */
2064 pbuf->pb_info.pi_ni[0].ns_msg_size =
2065 (void *)lns - (void *)&pbuf->pb_info;
2066 pbuf->pb_info.pi_features |= LNET_PING_FEAT_LARGE_ADDR;
2069 /* We (ab)use the ns_status of the loopback interface to
2070 * transmit the sequence number. The first interface listed
2071 * must be the loopback interface.
2073 rc = lnet_ping_info_validate(&pbuf->pb_info);
2075 LCONSOLE_EMERG("Invalid ping target: %d\n", rc);
2078 LNET_PING_BUFFER_SEQNO(pbuf) =
2079 atomic_inc_return(&the_lnet.ln_ping_target_seqno);
2083 lnet_ping_target_update(struct lnet_ping_buffer *pbuf,
2084 struct lnet_handle_md ping_mdh)
2085 __must_hold(&the_lnet.ln_api_mutex)
2087 struct lnet_ping_buffer *old_pbuf = NULL;
2088 struct lnet_handle_md old_ping_md;
2090 /* switch the NIs to point to the new ping info created */
2091 lnet_net_lock(LNET_LOCK_EX);
2093 if (!the_lnet.ln_routing)
2094 pbuf->pb_info.pi_features |= LNET_PING_FEAT_RTE_DISABLED;
2095 if (!lnet_peer_discovery_disabled)
2096 pbuf->pb_info.pi_features |= LNET_PING_FEAT_DISCOVERY;
2098 /* Ensure only known feature bits have been set. */
2099 LASSERT(pbuf->pb_info.pi_features & LNET_PING_FEAT_BITS);
2100 LASSERT(!(pbuf->pb_info.pi_features & ~LNET_PING_FEAT_BITS));
2102 lnet_ping_target_install_locked(pbuf);
2104 if (the_lnet.ln_ping_target) {
2105 old_pbuf = the_lnet.ln_ping_target;
2106 old_ping_md = the_lnet.ln_ping_target_md;
2108 the_lnet.ln_ping_target_md = ping_mdh;
2109 the_lnet.ln_ping_target = pbuf;
2111 lnet_net_unlock(LNET_LOCK_EX);
2114 /* unlink and free the old ping info.
2115 * There may be outstanding traffic on this MD, and
2116 * ln_api_mutex may be required to finalize that
2117 * traffic. Release ln_api_mutex while we wait for
2118 * refs on this ping buffer to drop
2120 mutex_unlock(&the_lnet.ln_api_mutex);
2121 lnet_ping_md_unlink(old_pbuf, &old_ping_md);
2122 mutex_lock(&the_lnet.ln_api_mutex);
2123 lnet_ping_buffer_decref(old_pbuf);
2126 lnet_push_update_to_peers(0);
2130 lnet_ping_target_fini(void)
2132 lnet_ping_md_unlink(the_lnet.ln_ping_target,
2133 &the_lnet.ln_ping_target_md);
2135 lnet_assert_handler_unused(the_lnet.ln_ping_target_handler, true);
2136 lnet_ping_target_destroy();
2139 /* Resize the push target. */
2140 int lnet_push_target_resize(void)
2142 struct lnet_handle_md mdh;
2143 struct lnet_handle_md old_mdh;
2144 struct lnet_ping_buffer *pbuf;
2145 struct lnet_ping_buffer *old_pbuf;
2150 nbytes = the_lnet.ln_push_target_nbytes;
2152 CDEBUG(D_NET, "Invalid nbytes %d\n", nbytes);
2156 /* NB: lnet_ping_buffer_alloc() sets pbuf refcount to 1. That ref is
2157 * dropped when we need to resize again (see "old_pbuf" below) or when
2158 * LNet is shutdown (see lnet_push_target_fini())
2160 pbuf = lnet_ping_buffer_alloc(nbytes, GFP_NOFS);
2162 CDEBUG(D_NET, "Can't allocate pbuf for nbytes %d\n", nbytes);
2166 rc = lnet_push_target_post(pbuf, &mdh);
2168 CDEBUG(D_NET, "Failed to post push target: %d\n", rc);
2169 lnet_ping_buffer_decref(pbuf);
2173 lnet_net_lock(LNET_LOCK_EX);
2174 old_pbuf = the_lnet.ln_push_target;
2175 old_mdh = the_lnet.ln_push_target_md;
2176 the_lnet.ln_push_target = pbuf;
2177 the_lnet.ln_push_target_md = mdh;
2178 lnet_net_unlock(LNET_LOCK_EX);
2181 LNetMDUnlink(old_mdh);
2182 /* Drop ref set by lnet_ping_buffer_alloc() */
2183 lnet_ping_buffer_decref(old_pbuf);
2186 /* Received another push or reply that requires a larger buffer */
2187 if (nbytes < the_lnet.ln_push_target_nbytes)
2190 CDEBUG(D_NET, "nbytes %d success\n", nbytes);
2194 int lnet_push_target_post(struct lnet_ping_buffer *pbuf,
2195 struct lnet_handle_md *mdhp)
2197 struct lnet_processid id = { LNET_ANY_NID, LNET_PID_ANY };
2198 struct lnet_md md = { NULL };
2202 me = LNetMEAttach(LNET_RESERVED_PORTAL, &id,
2203 LNET_PROTO_PING_MATCHBITS, 0,
2204 LNET_UNLINK, LNET_INS_AFTER);
2207 CERROR("Can't create push target ME: %d\n", rc);
2211 pbuf->pb_needs_post = false;
2213 /* This reference is dropped by lnet_push_target_event_handler() */
2214 lnet_ping_buffer_addref(pbuf);
2216 /* initialize md content */
2217 md.start = &pbuf->pb_info;
2218 md.length = pbuf->pb_nbytes;
2221 md.options = LNET_MD_OP_PUT | LNET_MD_TRUNCATE;
2223 md.handler = the_lnet.ln_push_target_handler;
2225 rc = LNetMDAttach(me, &md, LNET_UNLINK, mdhp);
2227 CERROR("Can't attach push MD: %d\n", rc);
2228 lnet_ping_buffer_decref(pbuf);
2229 pbuf->pb_needs_post = true;
2233 CDEBUG(D_NET, "posted push target %p\n", pbuf);
2238 static void lnet_push_target_event_handler(struct lnet_event *ev)
2240 struct lnet_ping_buffer *pbuf = ev->md_user_ptr;
2242 CDEBUG(D_NET, "type %d status %d unlinked %d\n", ev->type, ev->status,
2245 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
2246 lnet_swap_pinginfo(pbuf);
2248 if (ev->type == LNET_EVENT_UNLINK) {
2249 /* Drop ref added by lnet_push_target_post() */
2250 lnet_ping_buffer_decref(pbuf);
2254 lnet_peer_push_event(ev);
2256 /* Drop ref added by lnet_push_target_post */
2257 lnet_ping_buffer_decref(pbuf);
2260 /* Initialize the push target. */
2261 static int lnet_push_target_init(void)
2265 if (the_lnet.ln_push_target)
2268 the_lnet.ln_push_target_handler =
2269 lnet_push_target_event_handler;
2271 rc = LNetSetLazyPortal(LNET_RESERVED_PORTAL);
2274 /* Start at the required minimum, we'll enlarge if required. */
2275 the_lnet.ln_push_target_nbytes = LNET_PING_INFO_MIN_SIZE;
2277 rc = lnet_push_target_resize();
2279 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2280 the_lnet.ln_push_target_handler = NULL;
2286 /* Clean up the push target. */
2287 static void lnet_push_target_fini(void)
2289 if (!the_lnet.ln_push_target)
2292 /* Unlink and invalidate to prevent new references. */
2293 LNetMDUnlink(the_lnet.ln_push_target_md);
2294 LNetInvalidateMDHandle(&the_lnet.ln_push_target_md);
2296 /* Wait for the unlink to complete. */
2297 wait_var_event_warning(&the_lnet.ln_push_target->pb_refcnt,
2298 atomic_read(&the_lnet.ln_push_target->pb_refcnt) <= 1,
2299 "Still waiting for ping data MD to unlink\n");
2301 /* Drop ref set by lnet_ping_buffer_alloc() */
2302 lnet_ping_buffer_decref(the_lnet.ln_push_target);
2303 the_lnet.ln_push_target = NULL;
2304 the_lnet.ln_push_target_nbytes = 0;
2306 LNetClearLazyPortal(LNET_RESERVED_PORTAL);
2307 lnet_assert_handler_unused(the_lnet.ln_push_target_handler, true);
2308 the_lnet.ln_push_target_handler = NULL;
2312 lnet_ni_tq_credits(struct lnet_ni *ni)
2316 LASSERT(ni->ni_ncpts >= 1);
2318 if (ni->ni_ncpts == 1)
2319 return ni->ni_net->net_tunables.lct_max_tx_credits;
2321 credits = ni->ni_net->net_tunables.lct_max_tx_credits / ni->ni_ncpts;
2322 credits = max(credits, 8 * ni->ni_net->net_tunables.lct_peer_tx_credits);
2323 credits = min(credits, ni->ni_net->net_tunables.lct_max_tx_credits);
2329 lnet_ni_unlink_locked(struct lnet_ni *ni)
2331 /* move it to zombie list and nobody can find it anymore */
2332 LASSERT(!list_empty(&ni->ni_netlist));
2333 list_move(&ni->ni_netlist, &ni->ni_net->net_ni_zombie);
2334 lnet_ni_decref_locked(ni, 0);
2338 lnet_clear_zombies_nis_locked(struct lnet_net *net)
2343 struct list_head *zombie_list = &net->net_ni_zombie;
2346 * Now wait for the NIs I just nuked to show up on the zombie
2347 * list and shut them down in guaranteed thread context
2350 while ((ni = list_first_entry_or_null(zombie_list,
2352 ni_netlist)) != NULL) {
2356 list_del_init(&ni->ni_netlist);
2357 /* the ni should be in deleting state. If it's not it's
2359 LASSERT(ni->ni_state == LNET_NI_STATE_DELETING);
2360 cfs_percpt_for_each(ref, j, ni->ni_refs) {
2363 /* still busy, add it back to zombie list */
2364 list_add(&ni->ni_netlist, zombie_list);
2368 if (!list_empty(&ni->ni_netlist)) {
2369 /* Unlock mutex while waiting to allow other
2370 * threads to read the LNet state and fall through
2373 lnet_net_unlock(LNET_LOCK_EX);
2374 mutex_unlock(&the_lnet.ln_api_mutex);
2377 if ((i & (-i)) == i) {
2379 "Waiting for zombie LNI %s\n",
2380 libcfs_nidstr(&ni->ni_nid));
2382 schedule_timeout_uninterruptible(cfs_time_seconds(1));
2384 mutex_lock(&the_lnet.ln_api_mutex);
2385 lnet_net_lock(LNET_LOCK_EX);
2389 lnet_net_unlock(LNET_LOCK_EX);
2391 islo = ni->ni_net->net_lnd->lnd_type == LOLND;
2393 LASSERT(!in_interrupt());
2394 /* Holding the LND mutex makes it safe for lnd_shutdown
2395 * to call module_put(). Module unload cannot finish
2396 * until lnet_unregister_lnd() completes, and that
2397 * requires the LND mutex.
2399 mutex_unlock(&the_lnet.ln_api_mutex);
2400 mutex_lock(&the_lnet.ln_lnd_mutex);
2401 (net->net_lnd->lnd_shutdown)(ni);
2402 mutex_unlock(&the_lnet.ln_lnd_mutex);
2403 mutex_lock(&the_lnet.ln_api_mutex);
2406 CDEBUG(D_LNI, "Removed LNI %s\n",
2407 libcfs_nidstr(&ni->ni_nid));
2411 lnet_net_lock(LNET_LOCK_EX);
2415 /* shutdown down the NI and release refcount */
2417 lnet_shutdown_lndni(struct lnet_ni *ni)
2420 struct lnet_net *net = ni->ni_net;
2422 lnet_net_lock(LNET_LOCK_EX);
2424 ni->ni_state = LNET_NI_STATE_DELETING;
2426 lnet_ni_unlink_locked(ni);
2427 lnet_incr_dlc_seq();
2428 lnet_net_unlock(LNET_LOCK_EX);
2430 /* clear messages for this NI on the lazy portal */
2431 for (i = 0; i < the_lnet.ln_nportals; i++)
2432 lnet_clear_lazy_portal(ni, i, "Shutting down NI");
2434 lnet_net_lock(LNET_LOCK_EX);
2435 lnet_clear_zombies_nis_locked(net);
2436 lnet_net_unlock(LNET_LOCK_EX);
2440 lnet_shutdown_lndnet(struct lnet_net *net)
2444 lnet_net_lock(LNET_LOCK_EX);
2446 list_del_init(&net->net_list);
2448 while ((ni = list_first_entry_or_null(&net->net_ni_list,
2450 ni_netlist)) != NULL) {
2451 lnet_net_unlock(LNET_LOCK_EX);
2452 lnet_shutdown_lndni(ni);
2453 lnet_net_lock(LNET_LOCK_EX);
2456 lnet_net_unlock(LNET_LOCK_EX);
2458 /* Do peer table cleanup for this net */
2459 lnet_peer_tables_cleanup(net);
2465 lnet_shutdown_lndnets(void)
2467 struct lnet_net *net;
2469 struct lnet_msg *msg, *tmp;
2471 /* NB called holding the global mutex */
2473 /* All quiet on the API front */
2474 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING ||
2475 the_lnet.ln_state == LNET_STATE_STOPPING);
2476 LASSERT(the_lnet.ln_refcount == 0);
2478 lnet_net_lock(LNET_LOCK_EX);
2479 the_lnet.ln_state = LNET_STATE_STOPPING;
2482 * move the nets to the zombie list to avoid them being
2483 * picked up for new work. LONET is also included in the
2484 * Nets that will be moved to the zombie list
2486 list_splice_init(&the_lnet.ln_nets, &the_lnet.ln_net_zombie);
2488 /* Drop the cached loopback Net. */
2489 if (the_lnet.ln_loni != NULL) {
2490 lnet_ni_decref_locked(the_lnet.ln_loni, 0);
2491 the_lnet.ln_loni = NULL;
2493 lnet_net_unlock(LNET_LOCK_EX);
2495 /* iterate through the net zombie list and delete each net */
2496 while ((net = list_first_entry_or_null(&the_lnet.ln_net_zombie,
2499 lnet_shutdown_lndnet(net);
2501 spin_lock(&the_lnet.ln_msg_resend_lock);
2502 list_splice(&the_lnet.ln_msg_resend, &resend);
2503 spin_unlock(&the_lnet.ln_msg_resend_lock);
2505 list_for_each_entry_safe(msg, tmp, &resend, msg_list) {
2506 list_del_init(&msg->msg_list);
2507 msg->msg_no_resend = true;
2508 lnet_finalize(msg, -ECANCELED);
2511 lnet_net_lock(LNET_LOCK_EX);
2512 the_lnet.ln_state = LNET_STATE_SHUTDOWN;
2513 lnet_net_unlock(LNET_LOCK_EX);
2517 lnet_startup_lndni(struct lnet_ni *ni, struct lnet_lnd_tunables *tun)
2520 struct lnet_tx_queue *tq;
2522 struct lnet_net *net = ni->ni_net;
2524 mutex_lock(&the_lnet.ln_lnd_mutex);
2527 memcpy(&ni->ni_lnd_tunables, tun, sizeof(*tun));
2528 ni->ni_lnd_tunables_set = true;
2531 rc = (net->net_lnd->lnd_startup)(ni);
2533 mutex_unlock(&the_lnet.ln_lnd_mutex);
2536 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s\n",
2537 rc, libcfs_lnd2str(net->net_lnd->lnd_type));
2541 /* We keep a reference on the loopback net through the loopback NI */
2542 if (net->net_lnd->lnd_type == LOLND) {
2544 LASSERT(the_lnet.ln_loni == NULL);
2545 the_lnet.ln_loni = ni;
2546 ni->ni_net->net_tunables.lct_peer_tx_credits = 0;
2547 ni->ni_net->net_tunables.lct_peer_rtr_credits = 0;
2548 ni->ni_net->net_tunables.lct_max_tx_credits = 0;
2549 ni->ni_net->net_tunables.lct_peer_timeout = 0;
2553 if (ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ||
2554 ni->ni_net->net_tunables.lct_max_tx_credits == 0) {
2555 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
2556 libcfs_lnd2str(net->net_lnd->lnd_type),
2557 ni->ni_net->net_tunables.lct_peer_tx_credits == 0 ?
2559 /* shutdown the NI since if we get here then it must've already
2562 lnet_shutdown_lndni(ni);
2566 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
2567 tq->tq_credits_min =
2568 tq->tq_credits_max =
2569 tq->tq_credits = lnet_ni_tq_credits(ni);
2572 atomic_set(&ni->ni_tx_credits,
2573 lnet_ni_tq_credits(ni) * ni->ni_ncpts);
2574 atomic_set(&ni->ni_healthv, LNET_MAX_HEALTH_VALUE);
2576 /* Nodes with small feet have little entropy. The NID for this
2577 * node gives the most entropy in the low bits.
2579 add_device_randomness(&ni->ni_nid, sizeof(ni->ni_nid));
2581 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d/%d]\n",
2582 libcfs_nidstr(&ni->ni_nid),
2583 ni->ni_net->net_tunables.lct_peer_tx_credits,
2584 lnet_ni_tq_credits(ni) * LNET_CPT_NUMBER,
2585 ni->ni_net->net_tunables.lct_peer_rtr_credits,
2586 ni->ni_net->net_tunables.lct_peer_timeout);
2594 static const struct lnet_lnd *lnet_load_lnd(u32 lnd_type)
2596 const struct lnet_lnd *lnd;
2599 mutex_lock(&the_lnet.ln_lnd_mutex);
2600 lnd = lnet_find_lnd_by_type(lnd_type);
2602 mutex_unlock(&the_lnet.ln_lnd_mutex);
2603 rc = request_module("%s", libcfs_lnd2modname(lnd_type));
2604 mutex_lock(&the_lnet.ln_lnd_mutex);
2606 lnd = lnet_find_lnd_by_type(lnd_type);
2608 mutex_unlock(&the_lnet.ln_lnd_mutex);
2609 CERROR("Can't load LND %s, module %s, rc=%d\n",
2610 libcfs_lnd2str(lnd_type),
2611 libcfs_lnd2modname(lnd_type), rc);
2612 #ifndef HAVE_MODULE_LOADING_SUPPORT
2613 LCONSOLE_ERROR_MSG(0x104,
2614 "Your kernel must be compiled with kernel module loading support.");
2616 return ERR_PTR(-EINVAL);
2619 mutex_unlock(&the_lnet.ln_lnd_mutex);
2625 lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
2628 struct lnet_net *net_l = NULL;
2629 LIST_HEAD(local_ni_list);
2633 const struct lnet_lnd *lnd;
2635 net->net_tunables.lct_peer_timeout;
2637 net->net_tunables.lct_max_tx_credits;
2638 int peerrtrcredits =
2639 net->net_tunables.lct_peer_rtr_credits;
2642 * make sure that this net is unique. If it isn't then
2643 * we are adding interfaces to an already existing network, and
2644 * 'net' is just a convenient way to pass in the list.
2645 * if it is unique we need to find the LND and load it if
2648 if (lnet_net_unique(net->net_id, &the_lnet.ln_nets, &net_l)) {
2649 lnd_type = LNET_NETTYP(net->net_id);
2651 lnd = lnet_load_lnd(lnd_type);
2657 mutex_lock(&the_lnet.ln_lnd_mutex);
2659 mutex_unlock(&the_lnet.ln_lnd_mutex);
2665 * net_l: if the network being added is unique then net_l
2666 * will point to that network
2667 * if the network being added is not unique then
2668 * net_l points to the existing network.
2670 * When we enter the loop below, we'll pick NIs off he
2671 * network beign added and start them up, then add them to
2672 * a local ni list. Once we've successfully started all
2673 * the NIs then we join the local NI list (of started up
2674 * networks) with the net_l->net_ni_list, which should
2675 * point to the correct network to add the new ni list to
2677 * If any of the new NIs fail to start up, then we want to
2678 * iterate through the local ni list, which should include
2679 * any NIs which were successfully started up, and shut
2682 * After than we want to delete the network being added,
2683 * to avoid a memory leak.
2685 while ((ni = list_first_entry_or_null(&net->net_ni_added,
2687 ni_netlist)) != NULL) {
2688 list_del_init(&ni->ni_netlist);
2690 /* make sure that the the NI we're about to start
2691 * up is actually unique. if it's not fail. */
2692 if (!lnet_ni_unique_net(&net_l->net_ni_list,
2693 ni->ni_interface)) {
2698 /* adjust the pointer the parent network, just in case it
2699 * the net is a duplicate */
2702 rc = lnet_startup_lndni(ni, tun);
2708 list_add_tail(&ni->ni_netlist, &local_ni_list);
2713 lnet_net_lock(LNET_LOCK_EX);
2714 list_splice_tail(&local_ni_list, &net_l->net_ni_list);
2715 lnet_incr_dlc_seq();
2717 list_for_each_entry(ni, &net_l->net_ni_list, ni_netlist) {
2721 ni->ni_state = LNET_NI_STATE_ACTIVE;
2724 lnet_net_unlock(LNET_LOCK_EX);
2726 /* if the network is not unique then we don't want to keep
2727 * it around after we're done. Free it. Otherwise add that
2728 * net to the global the_lnet.ln_nets */
2729 if (net_l != net && net_l != NULL) {
2731 * TODO - note. currently the tunables can not be updated
2737 * restore tunables after it has been overwitten by the
2740 if (peer_timeout != -1)
2741 net->net_tunables.lct_peer_timeout = peer_timeout;
2742 if (maxtxcredits != -1)
2743 net->net_tunables.lct_max_tx_credits = maxtxcredits;
2744 if (peerrtrcredits != -1)
2745 net->net_tunables.lct_peer_rtr_credits = peerrtrcredits;
2747 lnet_net_lock(LNET_LOCK_EX);
2748 list_add_tail(&net->net_list, &the_lnet.ln_nets);
2749 lnet_net_unlock(LNET_LOCK_EX);
2756 * shutdown the new NIs that are being started up
2757 * free the NET being started
2759 while ((ni = list_first_entry_or_null(&local_ni_list,
2761 ni_netlist)) != NULL)
2762 lnet_shutdown_lndni(ni);
2771 lnet_startup_lndnets(struct list_head *netlist)
2773 struct lnet_net *net;
2778 * Change to running state before bringing up the LNDs. This
2779 * allows lnet_shutdown_lndnets() to assert that we've passed
2782 lnet_net_lock(LNET_LOCK_EX);
2783 the_lnet.ln_state = LNET_STATE_RUNNING;
2784 lnet_net_unlock(LNET_LOCK_EX);
2786 while ((net = list_first_entry_or_null(netlist,
2788 net_list)) != NULL) {
2789 list_del_init(&net->net_list);
2791 rc = lnet_startup_lndnet(net, NULL);
2801 lnet_shutdown_lndnets();
2806 static int lnet_genl_parse_list(struct sk_buff *msg,
2807 const struct ln_key_list *data[], u16 idx)
2809 const struct ln_key_list *list = data[idx];
2810 const struct ln_key_props *props;
2811 struct nlattr *node;
2817 if (!list->lkl_maxattr)
2820 props = list->lkl_list;
2824 node = nla_nest_start(msg, LN_SCALAR_ATTR_LIST);
2828 for (count = 1; count <= list->lkl_maxattr; count++) {
2829 struct nlattr *key = nla_nest_start(msg, count);
2835 nla_put_u16(msg, LN_SCALAR_ATTR_LIST_SIZE,
2838 nla_put_u16(msg, LN_SCALAR_ATTR_INDEX, count);
2839 if (props[count].lkp_value)
2840 nla_put_string(msg, LN_SCALAR_ATTR_VALUE,
2841 props[count].lkp_value);
2842 if (props[count].lkp_key_format)
2843 nla_put_u16(msg, LN_SCALAR_ATTR_KEY_FORMAT,
2844 props[count].lkp_key_format);
2845 nla_put_u16(msg, LN_SCALAR_ATTR_NLA_TYPE,
2846 props[count].lkp_data_type);
2847 if (props[count].lkp_data_type == NLA_NESTED) {
2850 rc = lnet_genl_parse_list(msg, data, ++idx);
2856 nla_nest_end(msg, key);
2859 nla_nest_end(msg, node);
2863 int lnet_genl_send_scalar_list(struct sk_buff *msg, u32 portid, u32 seq,
2864 const struct genl_family *family, int flags,
2865 u8 cmd, const struct ln_key_list *data[])
2873 hdr = genlmsg_put(msg, portid, seq, family, flags, cmd);
2875 GOTO(canceled, rc = -EMSGSIZE);
2877 rc = lnet_genl_parse_list(msg, data, 0);
2881 genlmsg_end(msg, hdr);
2884 genlmsg_cancel(msg, hdr);
2885 return rc > 0 ? 0 : rc;
2887 EXPORT_SYMBOL(lnet_genl_send_scalar_list);
2889 static struct genl_family lnet_family;
2892 * Initialize LNet library.
2894 * Automatically called at module loading time. Caller has to call
2895 * lnet_lib_exit() after a call to lnet_lib_init(), if and only if the
2896 * latter returned 0. It must be called exactly once.
2898 * \retval 0 on success
2899 * \retval -ve on failures.
2901 int lnet_lib_init(void)
2905 lnet_assert_wire_constants();
2907 /* refer to global cfs_cpt_table for now */
2908 the_lnet.ln_cpt_table = cfs_cpt_tab;
2909 the_lnet.ln_cpt_number = cfs_cpt_number(cfs_cpt_tab);
2911 LASSERT(the_lnet.ln_cpt_number > 0);
2912 if (the_lnet.ln_cpt_number > LNET_CPT_MAX) {
2913 /* we are under risk of consuming all lh_cookie */
2914 CERROR("Can't have %d CPTs for LNet (max allowed is %d), "
2915 "please change setting of CPT-table and retry\n",
2916 the_lnet.ln_cpt_number, LNET_CPT_MAX);
2920 while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number)
2921 the_lnet.ln_cpt_bits++;
2923 rc = lnet_create_locks();
2925 CERROR("Can't create LNet global locks: %d\n", rc);
2929 rc = genl_register_family(&lnet_family);
2931 lnet_destroy_locks();
2932 CERROR("Can't register LNet netlink family: %d\n", rc);
2936 the_lnet.ln_refcount = 0;
2937 INIT_LIST_HEAD(&the_lnet.ln_net_zombie);
2938 INIT_LIST_HEAD(&the_lnet.ln_msg_resend);
2940 /* The hash table size is the number of bits it takes to express the set
2941 * ln_num_routes, minus 1 (better to under estimate than over so we
2942 * don't waste memory). */
2943 if (rnet_htable_size <= 0)
2944 rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
2945 else if (rnet_htable_size > LNET_REMOTE_NETS_HASH_MAX)
2946 rnet_htable_size = LNET_REMOTE_NETS_HASH_MAX;
2947 the_lnet.ln_remote_nets_hbits = max_t(int, 1,
2948 order_base_2(rnet_htable_size) - 1);
2950 /* All LNDs apart from the LOLND are in separate modules. They
2951 * register themselves when their module loads, and unregister
2952 * themselves when their module is unloaded. */
2953 lnet_register_lnd(&the_lolnd);
2958 * Finalize LNet library.
2960 * \pre lnet_lib_init() called with success.
2961 * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls.
2963 * As this happens at module-unload, all lnds must already be unloaded,
2964 * so they must already be unregistered.
2966 void lnet_lib_exit(void)
2970 LASSERT(the_lnet.ln_refcount == 0);
2971 lnet_unregister_lnd(&the_lolnd);
2972 for (i = 0; i < NUM_LNDS; i++)
2973 LASSERT(!the_lnet.ln_lnds[i]);
2974 lnet_destroy_locks();
2975 genl_unregister_family(&lnet_family);
2979 * Set LNet PID and start LNet interfaces, routing, and forwarding.
2981 * Users must call this function at least once before any other functions.
2982 * For each successful call there must be a corresponding call to
2983 * LNetNIFini(). For subsequent calls to LNetNIInit(), \a requested_pid is
2986 * The PID used by LNet may be different from the one requested.
2989 * \param requested_pid PID requested by the caller.
2991 * \return >= 0 on success, and < 0 error code on failures.
2994 LNetNIInit(lnet_pid_t requested_pid)
2996 int im_a_router = 0;
2999 struct lnet_ping_buffer *pbuf;
3000 struct lnet_handle_md ping_mdh;
3001 LIST_HEAD(net_head);
3002 struct lnet_net *net;
3004 mutex_lock(&the_lnet.ln_api_mutex);
3006 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
3008 if (the_lnet.ln_state == LNET_STATE_STOPPING) {
3009 mutex_unlock(&the_lnet.ln_api_mutex);
3013 if (the_lnet.ln_refcount > 0) {
3014 rc = the_lnet.ln_refcount++;
3015 mutex_unlock(&the_lnet.ln_api_mutex);
3019 rc = lnet_prepare(requested_pid);
3021 mutex_unlock(&the_lnet.ln_api_mutex);
3025 /* create a network for Loopback network */
3026 net = lnet_net_alloc(LNET_MKNET(LOLND, 0), &net_head);
3029 goto err_empty_list;
3032 /* Add in the loopback NI */
3033 if (lnet_ni_alloc(net, NULL, NULL) == NULL) {
3035 goto err_empty_list;
3038 if (use_tcp_bonding)
3039 CWARN("use_tcp_bonding has been removed. Use Multi-Rail and Dynamic Discovery instead, see LU-13641\n");
3041 /* If LNet is being initialized via DLC it is possible
3042 * that the user requests not to load module parameters (ones which
3043 * are supported by DLC) on initialization. Therefore, make sure not
3044 * to load networks, routes and forwarding from module parameters
3045 * in this case. On cleanup in case of failure only clean up
3046 * routes if it has been loaded */
3047 if (!the_lnet.ln_nis_from_mod_params) {
3048 rc = lnet_parse_networks(&net_head, lnet_get_networks());
3050 goto err_empty_list;
3053 rc = lnet_startup_lndnets(&net_head);
3055 goto err_empty_list;
3057 if (!the_lnet.ln_nis_from_mod_params) {
3058 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
3060 goto err_shutdown_lndnis;
3062 rc = lnet_rtrpools_alloc(im_a_router);
3064 goto err_destroy_routes;
3067 rc = lnet_acceptor_start();
3069 goto err_destroy_routes;
3071 the_lnet.ln_refcount = 1;
3072 /* Now I may use my own API functions... */
3074 ni_bytes = LNET_PING_INFO_HDR_SIZE;
3075 list_for_each_entry(net, &the_lnet.ln_nets, net_list)
3076 ni_bytes += lnet_get_net_ni_bytes_locked(net);
3078 rc = lnet_ping_target_setup(&pbuf, &ping_mdh, ni_bytes, true);
3080 goto err_acceptor_stop;
3082 lnet_ping_target_update(pbuf, ping_mdh);
3084 the_lnet.ln_mt_handler = lnet_mt_event_handler;
3086 rc = lnet_push_target_init();
3090 rc = lnet_monitor_thr_start();
3092 goto err_destroy_push_target;
3094 rc = lnet_peer_discovery_start();
3096 goto err_stop_monitor_thr;
3099 lnet_router_debugfs_init();
3101 mutex_unlock(&the_lnet.ln_api_mutex);
3103 complete_all(&the_lnet.ln_started);
3105 /* wait for all routers to start */
3106 lnet_wait_router_start();
3110 err_stop_monitor_thr:
3111 lnet_monitor_thr_stop();
3112 err_destroy_push_target:
3113 lnet_push_target_fini();
3115 lnet_ping_target_fini();
3117 the_lnet.ln_refcount = 0;
3118 lnet_acceptor_stop();
3120 if (!the_lnet.ln_nis_from_mod_params)
3121 lnet_destroy_routes();
3122 err_shutdown_lndnis:
3123 lnet_shutdown_lndnets();
3127 mutex_unlock(&the_lnet.ln_api_mutex);
3128 while ((net = list_first_entry_or_null(&net_head,
3130 net_list)) != NULL) {
3131 list_del_init(&net->net_list);
3136 EXPORT_SYMBOL(LNetNIInit);
3139 * Stop LNet interfaces, routing, and forwarding.
3141 * Users must call this function once for each successful call to LNetNIInit().
3142 * Once the LNetNIFini() operation has been started, the results of pending
3143 * API operations are undefined.
3145 * \return always 0 for current implementation.
3150 mutex_lock(&the_lnet.ln_api_mutex);
3152 LASSERT(the_lnet.ln_refcount > 0);
3154 if (the_lnet.ln_refcount != 1) {
3155 the_lnet.ln_refcount--;
3157 LASSERT(!the_lnet.ln_niinit_self);
3159 lnet_net_lock(LNET_LOCK_EX);
3160 the_lnet.ln_state = LNET_STATE_STOPPING;
3161 lnet_net_unlock(LNET_LOCK_EX);
3165 lnet_router_debugfs_fini();
3166 lnet_peer_discovery_stop();
3167 lnet_monitor_thr_stop();
3168 lnet_push_target_fini();
3169 lnet_ping_target_fini();
3171 /* Teardown fns that use my own API functions BEFORE here */
3172 the_lnet.ln_refcount = 0;
3174 lnet_acceptor_stop();
3175 lnet_destroy_routes();
3176 lnet_shutdown_lndnets();
3180 mutex_unlock(&the_lnet.ln_api_mutex);
3183 EXPORT_SYMBOL(LNetNIFini);
3186 * Grabs the ni data from the ni structure and fills the out
3189 * \param[in] ni network interface structure
3190 * \param[out] cfg_ni NI config information
3191 * \param[out] tun network and LND tunables
3194 lnet_fill_ni_info(struct lnet_ni *ni, struct lnet_ioctl_config_ni *cfg_ni,
3195 struct lnet_ioctl_config_lnd_tunables *tun,
3196 struct lnet_ioctl_element_stats *stats,
3199 size_t min_size = 0;
3202 if (!ni || !cfg_ni || !tun || !nid_is_nid4(&ni->ni_nid))
3205 if (ni->ni_interface != NULL) {
3206 strncpy(cfg_ni->lic_ni_intf,
3208 sizeof(cfg_ni->lic_ni_intf));
3211 cfg_ni->lic_nid = lnet_nid_to_nid4(&ni->ni_nid);
3212 cfg_ni->lic_status = lnet_ni_get_status_locked(ni);
3213 cfg_ni->lic_dev_cpt = ni->ni_dev_cpt;
3215 memcpy(&tun->lt_cmn, &ni->ni_net->net_tunables, sizeof(tun->lt_cmn));
3218 stats->iel_send_count = lnet_sum_stats(&ni->ni_stats,
3219 LNET_STATS_TYPE_SEND);
3220 stats->iel_recv_count = lnet_sum_stats(&ni->ni_stats,
3221 LNET_STATS_TYPE_RECV);
3222 stats->iel_drop_count = lnet_sum_stats(&ni->ni_stats,
3223 LNET_STATS_TYPE_DROP);
3227 * tun->lt_tun will always be present, but in order to be
3228 * backwards compatible, we need to deal with the cases when
3229 * tun->lt_tun is smaller than what the kernel has, because it
3230 * comes from an older version of a userspace program, then we'll
3231 * need to copy as much information as we have available space.
3233 min_size = tun_size - sizeof(tun->lt_cmn);
3234 memcpy(&tun->lt_tun, &ni->ni_lnd_tunables, min_size);
3236 /* copy over the cpts */
3237 if (ni->ni_ncpts == LNET_CPT_NUMBER &&
3238 ni->ni_cpts == NULL) {
3239 for (i = 0; i < ni->ni_ncpts; i++)
3240 cfg_ni->lic_cpts[i] = i;
3243 ni->ni_cpts != NULL && i < ni->ni_ncpts &&
3244 i < LNET_MAX_SHOW_NUM_CPT;
3246 cfg_ni->lic_cpts[i] = ni->ni_cpts[i];
3248 cfg_ni->lic_ncpts = ni->ni_ncpts;
3252 * NOTE: This is a legacy function left in the code to be backwards
3253 * compatible with older userspace programs. It should eventually be
3256 * Grabs the ni data from the ni structure and fills the out
3259 * \param[in] ni network interface structure
3260 * \param[out] config config information
3263 lnet_fill_ni_info_legacy(struct lnet_ni *ni,
3264 struct lnet_ioctl_config_data *config)
3266 struct lnet_ioctl_net_config *net_config;
3267 struct lnet_ioctl_config_lnd_tunables *lnd_cfg = NULL;
3268 size_t min_size, tunable_size = 0;
3271 if (!ni || !config || !nid_is_nid4(&ni->ni_nid))
3274 net_config = (struct lnet_ioctl_net_config *) config->cfg_bulk;
3278 if (!ni->ni_interface)
3281 strncpy(net_config->ni_interface,
3283 sizeof(net_config->ni_interface));
3285 config->cfg_nid = lnet_nid_to_nid4(&ni->ni_nid);
3286 config->cfg_config_u.cfg_net.net_peer_timeout =
3287 ni->ni_net->net_tunables.lct_peer_timeout;
3288 config->cfg_config_u.cfg_net.net_max_tx_credits =
3289 ni->ni_net->net_tunables.lct_max_tx_credits;
3290 config->cfg_config_u.cfg_net.net_peer_tx_credits =
3291 ni->ni_net->net_tunables.lct_peer_tx_credits;
3292 config->cfg_config_u.cfg_net.net_peer_rtr_credits =
3293 ni->ni_net->net_tunables.lct_peer_rtr_credits;
3295 net_config->ni_status = lnet_ni_get_status_locked(ni);
3298 int num_cpts = min(ni->ni_ncpts, LNET_MAX_SHOW_NUM_CPT);
3300 for (i = 0; i < num_cpts; i++)
3301 net_config->ni_cpts[i] = ni->ni_cpts[i];
3303 config->cfg_ncpts = num_cpts;
3307 * See if user land tools sent in a newer and larger version
3308 * of struct lnet_tunables than what the kernel uses.
3310 min_size = sizeof(*config) + sizeof(*net_config);
3312 if (config->cfg_hdr.ioc_len > min_size)
3313 tunable_size = config->cfg_hdr.ioc_len - min_size;
3315 /* Don't copy too much data to user space */
3316 min_size = min(tunable_size, sizeof(ni->ni_lnd_tunables));
3317 lnd_cfg = (struct lnet_ioctl_config_lnd_tunables *)net_config->cfg_bulk;
3319 if (lnd_cfg && min_size) {
3320 memcpy(&lnd_cfg->lt_tun, &ni->ni_lnd_tunables, min_size);
3321 config->cfg_config_u.cfg_net.net_interface_count = 1;
3323 /* Tell user land that kernel side has less data */
3324 if (tunable_size > sizeof(ni->ni_lnd_tunables)) {
3325 min_size = tunable_size - sizeof(ni->ni_lnd_tunables);
3326 config->cfg_hdr.ioc_len -= min_size;
3332 lnet_get_ni_idx_locked(int idx)
3335 struct lnet_net *net;
3337 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3338 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3347 int lnet_get_net_healthv_locked(struct lnet_net *net)
3350 int best_healthv = 0;
3351 int healthv, ni_fatal;
3353 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3354 healthv = atomic_read(&ni->ni_healthv);
3355 ni_fatal = atomic_read(&ni->ni_fatal_error_on);
3356 if (!ni_fatal && healthv > best_healthv)
3357 best_healthv = healthv;
3360 return best_healthv;
3364 lnet_get_next_ni_locked(struct lnet_net *mynet, struct lnet_ni *prev)
3367 struct lnet_net *net = mynet;
3370 * It is possible that the net has been cleaned out while there is
3371 * a message being sent. This function accessed the net without
3372 * checking if the list is empty
3376 net = list_first_entry(&the_lnet.ln_nets,
3379 if (list_empty(&net->net_ni_list))
3381 ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
3387 if (prev->ni_netlist.next == &prev->ni_net->net_ni_list) {
3388 /* if you reached the end of the ni list and the net is
3389 * specified, then there are no more nis in that net */
3393 /* we reached the end of this net ni list. move to the
3395 if (prev->ni_net->net_list.next == &the_lnet.ln_nets)
3396 /* no more nets and no more NIs. */
3399 /* get the next net */
3400 net = list_first_entry(&prev->ni_net->net_list, struct lnet_net,
3402 if (list_empty(&net->net_ni_list))
3404 /* get the ni on it */
3405 ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
3411 if (list_empty(&prev->ni_netlist))
3414 /* there are more nis left */
3415 ni = list_first_entry(&prev->ni_netlist, struct lnet_ni, ni_netlist);
3421 lnet_get_net_config(struct lnet_ioctl_config_data *config)
3426 int idx = config->cfg_count;
3428 cpt = lnet_net_lock_current();
3430 ni = lnet_get_ni_idx_locked(idx);
3435 lnet_fill_ni_info_legacy(ni, config);
3439 lnet_net_unlock(cpt);
3444 lnet_get_ni_config(struct lnet_ioctl_config_ni *cfg_ni,
3445 struct lnet_ioctl_config_lnd_tunables *tun,
3446 struct lnet_ioctl_element_stats *stats,
3453 if (!cfg_ni || !tun || !stats)
3456 cpt = lnet_net_lock_current();
3458 ni = lnet_get_ni_idx_locked(cfg_ni->lic_idx);
3463 lnet_fill_ni_info(ni, cfg_ni, tun, stats, tun_size);
3467 lnet_net_unlock(cpt);
3471 static int lnet_get_ni_stats(struct lnet_ioctl_element_msg_stats *msg_stats)
3479 ni = lnet_get_ni_idx_locked(msg_stats->im_idx);
3482 lnet_usr_translate_stats(msg_stats, &ni->ni_stats);
3489 static int lnet_add_net_common(struct lnet_net *net,
3490 struct lnet_ioctl_config_lnd_tunables *tun)
3492 struct lnet_handle_md ping_mdh;
3493 struct lnet_ping_buffer *pbuf;
3494 struct lnet_remotenet *rnet;
3499 lnet_net_lock(LNET_LOCK_EX);
3500 rnet = lnet_find_rnet_locked(net->net_id);
3501 lnet_net_unlock(LNET_LOCK_EX);
3503 * make sure that the net added doesn't invalidate the current
3504 * configuration LNet is keeping
3507 CERROR("Adding net %s will invalidate routing configuration\n",
3508 libcfs_net2str(net->net_id));
3514 memcpy(&net->net_tunables,
3515 &tun->lt_cmn, sizeof(net->net_tunables));
3517 memset(&net->net_tunables, -1, sizeof(net->net_tunables));
3519 net_id = net->net_id;
3521 rc = lnet_startup_lndnet(net,
3522 (tun) ? &tun->lt_tun : NULL);
3526 /* make sure you calculate the correct number of slots in the ping
3527 * buffer. Since the ping info is a flattened list of all the NIs,
3528 * we should allocate enough slots to accomodate the number of NIs
3529 * which will be added.
3531 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3532 LNET_PING_INFO_HDR_SIZE +
3533 lnet_get_ni_bytes(),
3536 lnet_shutdown_lndnet(net);
3540 lnet_net_lock(LNET_LOCK_EX);
3541 net = lnet_get_net_locked(net_id);
3544 /* apply the UDSPs */
3545 rc = lnet_udsp_apply_policies_on_net(net);
3547 CERROR("Failed to apply UDSPs on local net %s\n",
3548 libcfs_net2str(net->net_id));
3550 /* At this point we lost track of which NI was just added, so we
3551 * just re-apply the policies on all of the NIs on this net
3553 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3554 rc = lnet_udsp_apply_policies_on_ni(ni);
3556 CERROR("Failed to apply UDSPs on ni %s\n",
3557 libcfs_nidstr(&ni->ni_nid));
3559 lnet_net_unlock(LNET_LOCK_EX);
3562 * Start the acceptor thread if this is the first network
3563 * being added that requires the thread.
3565 if (net->net_lnd->lnd_accept) {
3566 rc = lnet_acceptor_start();
3568 /* shutdown the net that we just started */
3569 CERROR("Failed to start up acceptor thread\n");
3570 lnet_shutdown_lndnet(net);
3575 lnet_net_lock(LNET_LOCK_EX);
3576 lnet_peer_net_added(net);
3577 lnet_net_unlock(LNET_LOCK_EX);
3579 lnet_ping_target_update(pbuf, ping_mdh);
3584 lnet_ping_md_unlink(pbuf, &ping_mdh);
3585 lnet_ping_buffer_decref(pbuf);
3590 lnet_set_tune_defaults(struct lnet_ioctl_config_lnd_tunables *tun)
3593 if (tun->lt_cmn.lct_peer_timeout < 0)
3594 tun->lt_cmn.lct_peer_timeout = DEFAULT_PEER_TIMEOUT;
3595 if (!tun->lt_cmn.lct_peer_tx_credits)
3596 tun->lt_cmn.lct_peer_tx_credits = DEFAULT_PEER_CREDITS;
3597 if (!tun->lt_cmn.lct_max_tx_credits)
3598 tun->lt_cmn.lct_max_tx_credits = DEFAULT_CREDITS;
3602 static int lnet_handle_legacy_ip2nets(char *ip2nets,
3603 struct lnet_ioctl_config_lnd_tunables *tun)
3605 struct lnet_net *net;
3608 LIST_HEAD(net_head);
3610 rc = lnet_parse_ip2nets(&nets, ip2nets);
3614 rc = lnet_parse_networks(&net_head, nets);
3618 lnet_set_tune_defaults(tun);
3620 mutex_lock(&the_lnet.ln_api_mutex);
3621 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3626 while ((net = list_first_entry_or_null(&net_head,
3628 net_list)) != NULL) {
3629 list_del_init(&net->net_list);
3630 rc = lnet_add_net_common(net, tun);
3636 mutex_unlock(&the_lnet.ln_api_mutex);
3638 while ((net = list_first_entry_or_null(&net_head,
3640 net_list)) != NULL) {
3641 list_del_init(&net->net_list);
3647 int lnet_dyn_add_ni(struct lnet_ioctl_config_ni *conf, u32 net_id,
3648 struct lnet_nid *nid,
3649 struct lnet_ioctl_config_lnd_tunables *tun)
3651 struct lnet_net *net;
3656 /* handle legacy ip2nets from DLC */
3657 if (conf->lic_legacy_ip2nets[0] != '\0')
3658 return lnet_handle_legacy_ip2nets(conf->lic_legacy_ip2nets,
3661 lnd_type = LNET_NETTYP(net_id);
3663 if (!libcfs_isknown_lnd(lnd_type)) {
3664 CERROR("No valid net and lnd information provided\n");
3668 net = lnet_net_alloc(net_id, NULL);
3672 for (i = 0; i < conf->lic_ncpts; i++) {
3673 if (conf->lic_cpts[i] >= LNET_CPT_NUMBER) {
3679 ni = lnet_ni_alloc_w_cpt_array(net, nid, conf->lic_cpts,
3680 conf->lic_ncpts, conf->lic_ni_intf);
3686 lnet_set_tune_defaults(tun);
3688 mutex_lock(&the_lnet.ln_api_mutex);
3689 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3693 rc = lnet_add_net_common(net, tun);
3696 mutex_unlock(&the_lnet.ln_api_mutex);
3698 /* If NI already exist delete this new unused copy */
3705 int lnet_dyn_del_ni(struct lnet_nid *nid)
3707 struct lnet_net *net;
3709 u32 net_id = LNET_NID_NET(nid);
3710 struct lnet_ping_buffer *pbuf;
3711 struct lnet_handle_md ping_mdh;
3715 /* don't allow userspace to shutdown the LOLND */
3716 if (LNET_NETTYP(net_id) == LOLND)
3719 mutex_lock(&the_lnet.ln_api_mutex);
3720 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3722 goto unlock_api_mutex;
3727 net = lnet_get_net_locked(net_id);
3729 CERROR("net %s not found\n",
3730 libcfs_net2str(net_id));
3735 if (!nid_addr_is_set(nid)) {
3736 /* remove the entire net */
3737 net_bytes = lnet_get_net_ni_bytes_locked(net);
3741 /* create and link a new ping info, before removing the old one */
3742 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3743 LNET_PING_INFO_HDR_SIZE +
3744 lnet_get_ni_bytes() - net_bytes,
3747 goto unlock_api_mutex;
3749 lnet_shutdown_lndnet(net);
3751 lnet_acceptor_stop();
3753 lnet_ping_target_update(pbuf, ping_mdh);
3755 goto unlock_api_mutex;
3758 ni = lnet_nid_to_ni_locked(nid, 0);
3760 CERROR("nid %s not found\n", libcfs_nidstr(nid));
3765 net_bytes = lnet_get_net_ni_bytes_locked(net);
3766 net_empty = list_is_singular(&net->net_ni_list);
3770 /* create and link a new ping info, before removing the old one */
3771 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3772 (LNET_PING_INFO_HDR_SIZE +
3773 lnet_get_ni_bytes() -
3774 lnet_ping_sts_size(&ni->ni_nid)),
3777 goto unlock_api_mutex;
3779 lnet_shutdown_lndni(ni);
3781 lnet_acceptor_stop();
3783 lnet_ping_target_update(pbuf, ping_mdh);
3785 /* check if the net is empty and remove it if it is */
3787 lnet_shutdown_lndnet(net);
3789 goto unlock_api_mutex;
3794 mutex_unlock(&the_lnet.ln_api_mutex);
3800 * lnet_dyn_add_net and lnet_dyn_del_net are now deprecated.
3801 * They are only expected to be called for unique networks.
3802 * That can be as a result of older DLC library
3803 * calls. Multi-Rail DLC and beyond no longer uses these APIs.
3806 lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
3808 struct lnet_net *net;
3809 LIST_HEAD(net_head);
3811 struct lnet_ioctl_config_lnd_tunables tun;
3812 const char *nets = conf->cfg_config_u.cfg_net.net_intf;
3814 /* Create a net/ni structures for the network string */
3815 rc = lnet_parse_networks(&net_head, nets);
3817 return rc == 0 ? -EINVAL : rc;
3819 mutex_lock(&the_lnet.ln_api_mutex);
3820 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3822 goto out_unlock_clean;
3826 rc = -EINVAL; /* only add one network per call */
3827 goto out_unlock_clean;
3830 net = list_first_entry(&net_head, struct lnet_net, net_list);
3831 list_del_init(&net->net_list);
3833 LASSERT(lnet_net_unique(net->net_id, &the_lnet.ln_nets, NULL));
3835 memset(&tun, 0, sizeof(tun));
3837 tun.lt_cmn.lct_peer_timeout =
3838 (!conf->cfg_config_u.cfg_net.net_peer_timeout) ? DEFAULT_PEER_TIMEOUT :
3839 conf->cfg_config_u.cfg_net.net_peer_timeout;
3840 tun.lt_cmn.lct_peer_tx_credits =
3841 (!conf->cfg_config_u.cfg_net.net_peer_tx_credits) ? DEFAULT_PEER_CREDITS :
3842 conf->cfg_config_u.cfg_net.net_peer_tx_credits;
3843 tun.lt_cmn.lct_peer_rtr_credits =
3844 conf->cfg_config_u.cfg_net.net_peer_rtr_credits;
3845 tun.lt_cmn.lct_max_tx_credits =
3846 (!conf->cfg_config_u.cfg_net.net_max_tx_credits) ? DEFAULT_CREDITS :
3847 conf->cfg_config_u.cfg_net.net_max_tx_credits;
3849 rc = lnet_add_net_common(net, &tun);
3852 mutex_unlock(&the_lnet.ln_api_mutex);
3853 /* net_head list is empty in success case */
3854 while ((net = list_first_entry_or_null(&net_head,
3856 net_list)) != NULL) {
3857 list_del_init(&net->net_list);
3864 lnet_dyn_del_net(u32 net_id)
3866 struct lnet_net *net;
3867 struct lnet_ping_buffer *pbuf;
3868 struct lnet_handle_md ping_mdh;
3869 int net_ni_bytes, rc;
3871 /* don't allow userspace to shutdown the LOLND */
3872 if (LNET_NETTYP(net_id) == LOLND)
3875 mutex_lock(&the_lnet.ln_api_mutex);
3876 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
3883 net = lnet_get_net_locked(net_id);
3890 net_ni_bytes = lnet_get_net_ni_bytes_locked(net);
3894 /* create and link a new ping info, before removing the old one */
3895 rc = lnet_ping_target_setup(&pbuf, &ping_mdh,
3896 LNET_PING_INFO_HDR_SIZE +
3897 lnet_get_ni_bytes() - net_ni_bytes,
3902 lnet_shutdown_lndnet(net);
3904 lnet_acceptor_stop();
3906 lnet_ping_target_update(pbuf, ping_mdh);
3909 mutex_unlock(&the_lnet.ln_api_mutex);
3914 void lnet_mark_ping_buffer_for_update(void)
3916 if (the_lnet.ln_routing)
3919 atomic_set(&the_lnet.ln_update_ping_buf, 1);
3920 complete(&the_lnet.ln_mt_wait_complete);
3922 EXPORT_SYMBOL(lnet_mark_ping_buffer_for_update);
3924 void lnet_update_ping_buffer(struct work_struct *work)
3926 struct lnet_ping_buffer *pbuf;
3927 struct lnet_handle_md ping_mdh;
3929 mutex_lock(&the_lnet.ln_api_mutex);
3931 atomic_set(&the_lnet.ln_pb_update_ready, 1);
3933 if ((the_lnet.ln_state == LNET_STATE_RUNNING) &&
3934 !lnet_ping_target_setup(&pbuf, &ping_mdh,
3935 LNET_PING_INFO_HDR_SIZE +
3936 lnet_get_ni_bytes(),
3938 lnet_ping_target_update(pbuf, ping_mdh);
3941 mutex_unlock(&the_lnet.ln_api_mutex);
3945 void lnet_queue_ping_buffer_update(void)
3947 /* don't queue pb update if it is not needed */
3948 if (atomic_dec_if_positive(&the_lnet.ln_update_ping_buf) < 0)
3951 /* don't queue pb update if already queued and not processed */
3952 if (atomic_dec_if_positive(&the_lnet.ln_pb_update_ready) < 0)
3955 INIT_WORK(&the_lnet.ln_pb_update_work, lnet_update_ping_buffer);
3956 queue_work(the_lnet.ln_pb_update_wq, &the_lnet.ln_pb_update_work);
3959 void lnet_incr_dlc_seq(void)
3961 atomic_inc(&lnet_dlc_seq_no);
3964 __u32 lnet_get_dlc_seq_locked(void)
3966 return atomic_read(&lnet_dlc_seq_no);
3970 lnet_ni_set_healthv(struct lnet_nid *nid, int value)
3972 bool all = nid_same(nid, &LNET_ANY_NID);
3973 struct lnet_net *net;
3976 lnet_net_lock(LNET_LOCK_EX);
3977 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
3978 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
3979 if (!all && !nid_same(&ni->ni_nid, nid))
3982 atomic_set(&ni->ni_healthv, value);
3983 if (list_empty(&ni->ni_recovery) &&
3984 value < LNET_MAX_HEALTH_VALUE) {
3985 CERROR("manually adding local NI %s to recovery\n",
3986 libcfs_nidstr(&ni->ni_nid));
3987 list_add_tail(&ni->ni_recovery,
3988 &the_lnet.ln_mt_localNIRecovq);
3989 lnet_ni_addref_locked(ni, 0);
3992 lnet_net_unlock(LNET_LOCK_EX);
3997 lnet_net_unlock(LNET_LOCK_EX);
4001 lnet_ni_set_conns_per_peer(lnet_nid_t nid, int value, bool all)
4003 struct lnet_net *net;
4006 lnet_net_lock(LNET_LOCK_EX);
4007 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
4008 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
4009 if (lnet_nid_to_nid4(&ni->ni_nid) != nid && !all)
4011 if (LNET_NETTYP(net->net_id) == SOCKLND)
4012 ni->ni_lnd_tunables.lnd_tun_u.lnd_sock.lnd_conns_per_peer = value;
4013 else if (LNET_NETTYP(net->net_id) == O2IBLND)
4014 ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = value;
4016 lnet_net_unlock(LNET_LOCK_EX);
4021 lnet_net_unlock(LNET_LOCK_EX);
4025 lnet_get_local_ni_hstats(struct lnet_ioctl_local_ni_hstats *stats)
4029 struct lnet_nid nid;
4031 lnet_nid4_to_nid(stats->hlni_nid, &nid);
4032 cpt = lnet_net_lock_current();
4033 ni = lnet_nid_to_ni_locked(&nid, cpt);
4039 stats->hlni_local_interrupt = atomic_read(&ni->ni_hstats.hlt_local_interrupt);
4040 stats->hlni_local_dropped = atomic_read(&ni->ni_hstats.hlt_local_dropped);
4041 stats->hlni_local_aborted = atomic_read(&ni->ni_hstats.hlt_local_aborted);
4042 stats->hlni_local_no_route = atomic_read(&ni->ni_hstats.hlt_local_no_route);
4043 stats->hlni_local_timeout = atomic_read(&ni->ni_hstats.hlt_local_timeout);
4044 stats->hlni_local_error = atomic_read(&ni->ni_hstats.hlt_local_error);
4045 stats->hlni_fatal_error = atomic_read(&ni->ni_fatal_error_on);
4046 stats->hlni_health_value = atomic_read(&ni->ni_healthv);
4047 stats->hlni_ping_count = ni->ni_ping_count;
4048 stats->hlni_next_ping = ni->ni_next_ping;
4051 lnet_net_unlock(cpt);
4057 lnet_get_local_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
4062 lnet_net_lock(LNET_LOCK_EX);
4063 list_for_each_entry(ni, &the_lnet.ln_mt_localNIRecovq, ni_recovery) {
4064 if (!nid_is_nid4(&ni->ni_nid))
4066 list->rlst_nid_array[i] = lnet_nid_to_nid4(&ni->ni_nid);
4068 if (i >= LNET_MAX_SHOW_NUM_NID)
4071 lnet_net_unlock(LNET_LOCK_EX);
4072 list->rlst_num_nids = i;
4078 lnet_get_peer_ni_recovery_list(struct lnet_ioctl_recovery_list *list)
4080 struct lnet_peer_ni *lpni;
4083 lnet_net_lock(LNET_LOCK_EX);
4084 list_for_each_entry(lpni, &the_lnet.ln_mt_peerNIRecovq, lpni_recovery) {
4085 list->rlst_nid_array[i] = lnet_nid_to_nid4(&lpni->lpni_nid);
4087 if (i >= LNET_MAX_SHOW_NUM_NID)
4090 lnet_net_unlock(LNET_LOCK_EX);
4091 list->rlst_num_nids = i;
4097 * LNet ioctl handler.
4101 LNetCtl(unsigned int cmd, void *arg)
4103 struct libcfs_ioctl_data *data = arg;
4104 struct lnet_ioctl_config_data *config;
4106 struct lnet_nid nid;
4109 BUILD_BUG_ON(sizeof(struct lnet_ioctl_net_config) +
4110 sizeof(struct lnet_ioctl_config_data) > LIBCFS_IOC_DATA_MAX);
4113 case IOC_LIBCFS_GET_NI: {
4114 struct lnet_processid id = {};
4116 rc = LNetGetId(data->ioc_count, &id, false);
4117 data->ioc_nid = lnet_nid_to_nid4(&id.nid);
4120 case IOC_LIBCFS_FAIL_NID:
4121 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
4123 case IOC_LIBCFS_ADD_ROUTE: {
4124 /* default router sensitivity to 1 */
4125 unsigned int sensitivity = 1;
4128 if (config->cfg_hdr.ioc_len < sizeof(*config))
4131 if (config->cfg_config_u.cfg_route.rtr_sensitivity) {
4133 config->cfg_config_u.cfg_route.rtr_sensitivity;
4136 lnet_nid4_to_nid(config->cfg_nid, &nid);
4137 mutex_lock(&the_lnet.ln_api_mutex);
4138 rc = lnet_add_route(config->cfg_net,
4139 config->cfg_config_u.cfg_route.rtr_hop,
4141 config->cfg_config_u.cfg_route.
4142 rtr_priority, sensitivity);
4143 mutex_unlock(&the_lnet.ln_api_mutex);
4147 case IOC_LIBCFS_DEL_ROUTE:
4150 if (config->cfg_hdr.ioc_len < sizeof(*config))
4153 lnet_nid4_to_nid(config->cfg_nid, &nid);
4154 mutex_lock(&the_lnet.ln_api_mutex);
4155 rc = lnet_del_route(config->cfg_net, &nid);
4156 mutex_unlock(&the_lnet.ln_api_mutex);
4159 case IOC_LIBCFS_GET_ROUTE:
4162 if (config->cfg_hdr.ioc_len < sizeof(*config))
4165 mutex_lock(&the_lnet.ln_api_mutex);
4166 rc = lnet_get_route(config->cfg_count,
4168 &config->cfg_config_u.cfg_route.rtr_hop,
4170 &config->cfg_config_u.cfg_route.rtr_flags,
4171 &config->cfg_config_u.cfg_route.
4173 &config->cfg_config_u.cfg_route.
4175 mutex_unlock(&the_lnet.ln_api_mutex);
4178 case IOC_LIBCFS_GET_LOCAL_NI: {
4179 struct lnet_ioctl_config_ni *cfg_ni;
4180 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
4181 struct lnet_ioctl_element_stats *stats;
4186 /* get the tunables if they are available */
4187 if (cfg_ni->lic_cfg_hdr.ioc_len <
4188 sizeof(*cfg_ni) + sizeof(*stats) + sizeof(*tun))
4191 stats = (struct lnet_ioctl_element_stats *)
4193 tun = (struct lnet_ioctl_config_lnd_tunables *)
4194 (cfg_ni->lic_bulk + sizeof(*stats));
4196 tun_size = cfg_ni->lic_cfg_hdr.ioc_len - sizeof(*cfg_ni) -
4199 mutex_lock(&the_lnet.ln_api_mutex);
4200 rc = lnet_get_ni_config(cfg_ni, tun, stats, tun_size);
4201 mutex_unlock(&the_lnet.ln_api_mutex);
4205 case IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS: {
4206 struct lnet_ioctl_element_msg_stats *msg_stats = arg;
4209 if (msg_stats->im_hdr.ioc_len != sizeof(*msg_stats))
4212 mutex_lock(&the_lnet.ln_api_mutex);
4214 cpt = lnet_net_lock_current();
4215 rc = lnet_get_ni_stats(msg_stats);
4216 lnet_net_unlock(cpt);
4218 mutex_unlock(&the_lnet.ln_api_mutex);
4223 case IOC_LIBCFS_GET_NET: {
4224 size_t total = sizeof(*config) +
4225 sizeof(struct lnet_ioctl_net_config);
4228 if (config->cfg_hdr.ioc_len < total)
4231 mutex_lock(&the_lnet.ln_api_mutex);
4232 rc = lnet_get_net_config(config);
4233 mutex_unlock(&the_lnet.ln_api_mutex);
4237 case IOC_LIBCFS_GET_LNET_STATS:
4239 struct lnet_ioctl_lnet_stats *lnet_stats = arg;
4241 if (lnet_stats->st_hdr.ioc_len < sizeof(*lnet_stats))
4244 mutex_lock(&the_lnet.ln_api_mutex);
4245 rc = lnet_counters_get(&lnet_stats->st_cntrs);
4246 mutex_unlock(&the_lnet.ln_api_mutex);
4250 case IOC_LIBCFS_RESET_LNET_STATS:
4252 mutex_lock(&the_lnet.ln_api_mutex);
4253 lnet_counters_reset();
4254 mutex_unlock(&the_lnet.ln_api_mutex);
4258 case IOC_LIBCFS_CONFIG_RTR:
4261 if (config->cfg_hdr.ioc_len < sizeof(*config))
4264 mutex_lock(&the_lnet.ln_api_mutex);
4265 if (config->cfg_config_u.cfg_buffers.buf_enable) {
4266 rc = lnet_rtrpools_enable();
4267 mutex_unlock(&the_lnet.ln_api_mutex);
4270 lnet_rtrpools_disable();
4271 mutex_unlock(&the_lnet.ln_api_mutex);
4274 case IOC_LIBCFS_ADD_BUF:
4277 if (config->cfg_hdr.ioc_len < sizeof(*config))
4280 mutex_lock(&the_lnet.ln_api_mutex);
4281 rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
4283 config->cfg_config_u.cfg_buffers.
4285 config->cfg_config_u.cfg_buffers.
4287 mutex_unlock(&the_lnet.ln_api_mutex);
4290 case IOC_LIBCFS_SET_NUMA_RANGE: {
4291 struct lnet_ioctl_set_value *numa;
4293 if (numa->sv_hdr.ioc_len != sizeof(*numa))
4295 lnet_net_lock(LNET_LOCK_EX);
4296 lnet_numa_range = numa->sv_value;
4297 lnet_net_unlock(LNET_LOCK_EX);
4301 case IOC_LIBCFS_GET_NUMA_RANGE: {
4302 struct lnet_ioctl_set_value *numa;
4304 if (numa->sv_hdr.ioc_len != sizeof(*numa))
4306 numa->sv_value = lnet_numa_range;
4310 case IOC_LIBCFS_GET_BUF: {
4311 struct lnet_ioctl_pool_cfg *pool_cfg;
4312 size_t total = sizeof(*config) + sizeof(*pool_cfg);
4316 if (config->cfg_hdr.ioc_len < total)
4319 pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
4321 mutex_lock(&the_lnet.ln_api_mutex);
4322 rc = lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
4323 mutex_unlock(&the_lnet.ln_api_mutex);
4327 case IOC_LIBCFS_GET_LOCAL_HSTATS: {
4328 struct lnet_ioctl_local_ni_hstats *stats = arg;
4330 if (stats->hlni_hdr.ioc_len < sizeof(*stats))
4333 mutex_lock(&the_lnet.ln_api_mutex);
4334 rc = lnet_get_local_ni_hstats(stats);
4335 mutex_unlock(&the_lnet.ln_api_mutex);
4340 case IOC_LIBCFS_GET_RECOVERY_QUEUE: {
4341 struct lnet_ioctl_recovery_list *list = arg;
4342 if (list->rlst_hdr.ioc_len < sizeof(*list))
4345 mutex_lock(&the_lnet.ln_api_mutex);
4346 if (list->rlst_type == LNET_HEALTH_TYPE_LOCAL_NI)
4347 rc = lnet_get_local_ni_recovery_list(list);
4349 rc = lnet_get_peer_ni_recovery_list(list);
4350 mutex_unlock(&the_lnet.ln_api_mutex);
4354 case IOC_LIBCFS_ADD_PEER_NI: {
4355 struct lnet_ioctl_peer_cfg *cfg = arg;
4356 struct lnet_nid prim_nid;
4358 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4361 mutex_lock(&the_lnet.ln_api_mutex);
4362 lnet_nid4_to_nid(cfg->prcfg_prim_nid, &prim_nid);
4363 lnet_nid4_to_nid(cfg->prcfg_cfg_nid, &nid);
4364 rc = lnet_user_add_peer_ni(&prim_nid, &nid, cfg->prcfg_mr,
4365 cfg->prcfg_count == 1);
4366 mutex_unlock(&the_lnet.ln_api_mutex);
4370 case IOC_LIBCFS_DEL_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_del_peer_ni(&prim_nid,
4383 mutex_unlock(&the_lnet.ln_api_mutex);
4387 case IOC_LIBCFS_GET_PEER_INFO: {
4388 struct lnet_ioctl_peer *peer_info = arg;
4390 if (peer_info->pr_hdr.ioc_len < sizeof(*peer_info))
4393 mutex_lock(&the_lnet.ln_api_mutex);
4394 rc = lnet_get_peer_ni_info(
4395 peer_info->pr_count,
4397 peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
4398 &peer_info->pr_lnd_u.pr_peer_credits.cr_ncpt,
4399 &peer_info->pr_lnd_u.pr_peer_credits.cr_refcount,
4400 &peer_info->pr_lnd_u.pr_peer_credits.cr_ni_peer_tx_credits,
4401 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_credits,
4402 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_rtr_credits,
4403 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_min_tx_credits,
4404 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_qnob);
4405 mutex_unlock(&the_lnet.ln_api_mutex);
4409 case IOC_LIBCFS_GET_PEER_NI: {
4410 struct lnet_ioctl_peer_cfg *cfg = arg;
4412 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4415 mutex_lock(&the_lnet.ln_api_mutex);
4416 rc = lnet_get_peer_info(cfg,
4417 (void __user *)cfg->prcfg_bulk);
4418 mutex_unlock(&the_lnet.ln_api_mutex);
4422 case IOC_LIBCFS_GET_PEER_LIST: {
4423 struct lnet_ioctl_peer_cfg *cfg = arg;
4425 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4428 mutex_lock(&the_lnet.ln_api_mutex);
4429 rc = lnet_get_peer_list(&cfg->prcfg_count, &cfg->prcfg_size,
4430 (struct lnet_process_id __user *)cfg->prcfg_bulk);
4431 mutex_unlock(&the_lnet.ln_api_mutex);
4435 case IOC_LIBCFS_SET_HEALHV: {
4436 struct lnet_ioctl_reset_health_cfg *cfg = arg;
4439 if (cfg->rh_hdr.ioc_len < sizeof(*cfg))
4441 if (cfg->rh_value < 0 ||
4442 cfg->rh_value > LNET_MAX_HEALTH_VALUE)
4443 value = LNET_MAX_HEALTH_VALUE;
4445 value = cfg->rh_value;
4446 CDEBUG(D_NET, "Manually setting healthv to %d for %s:%s. all = %d\n",
4447 value, (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI) ?
4448 "local" : "peer", libcfs_nid2str(cfg->rh_nid), cfg->rh_all);
4449 lnet_nid4_to_nid(cfg->rh_nid, &nid);
4450 mutex_lock(&the_lnet.ln_api_mutex);
4451 if (cfg->rh_type == LNET_HEALTH_TYPE_LOCAL_NI) {
4454 lnet_ni_set_healthv(&nid, value);
4456 lnet_peer_ni_set_healthv(&nid, value, cfg->rh_all);
4458 mutex_unlock(&the_lnet.ln_api_mutex);
4462 case IOC_LIBCFS_SET_PEER: {
4463 struct lnet_ioctl_peer_cfg *cfg = arg;
4464 struct lnet_peer *lp;
4466 if (cfg->prcfg_hdr.ioc_len < sizeof(*cfg))
4469 mutex_lock(&the_lnet.ln_api_mutex);
4470 lnet_nid4_to_nid(cfg->prcfg_prim_nid, &nid);
4471 lp = lnet_find_peer(&nid);
4473 mutex_unlock(&the_lnet.ln_api_mutex);
4476 spin_lock(&lp->lp_lock);
4477 lp->lp_state = cfg->prcfg_state;
4478 spin_unlock(&lp->lp_lock);
4479 lnet_peer_decref_locked(lp);
4480 mutex_unlock(&the_lnet.ln_api_mutex);
4481 CDEBUG(D_NET, "Set peer %s state to %u\n",
4482 libcfs_nid2str(cfg->prcfg_prim_nid), cfg->prcfg_state);
4486 case IOC_LIBCFS_SET_CONNS_PER_PEER: {
4487 struct lnet_ioctl_reset_conns_per_peer_cfg *cfg = arg;
4490 if (cfg->rcpp_hdr.ioc_len < sizeof(*cfg))
4492 if (cfg->rcpp_value < 0)
4495 value = cfg->rcpp_value;
4497 "Setting conns_per_peer to %d for %s. all = %d\n",
4498 value, libcfs_nid2str(cfg->rcpp_nid), cfg->rcpp_all);
4499 mutex_lock(&the_lnet.ln_api_mutex);
4500 lnet_ni_set_conns_per_peer(cfg->rcpp_nid, value, cfg->rcpp_all);
4501 mutex_unlock(&the_lnet.ln_api_mutex);
4505 case IOC_LIBCFS_NOTIFY_ROUTER: {
4506 /* Convert the user-supplied real time to monotonic.
4507 * NB: "when" is always in the past
4509 time64_t when = ktime_get_seconds() -
4510 (ktime_get_real_seconds() - data->ioc_u64[0]);
4512 lnet_nid4_to_nid(data->ioc_nid, &nid);
4513 return lnet_notify(NULL, &nid, data->ioc_flags, false, when);
4516 case IOC_LIBCFS_LNET_DIST:
4517 lnet_nid4_to_nid(data->ioc_nid, &nid);
4518 rc = LNetDist(&nid, &nid, &data->ioc_u32[1]);
4519 if (rc < 0 && rc != -EHOSTUNREACH)
4522 data->ioc_nid = lnet_nid_to_nid4(&nid);
4523 data->ioc_u32[0] = rc;
4526 case IOC_LIBCFS_TESTPROTOCOMPAT:
4527 the_lnet.ln_testprotocompat = data->ioc_flags;
4530 case IOC_LIBCFS_LNET_FAULT:
4531 return lnet_fault_ctl(data->ioc_flags, data);
4533 case IOC_LIBCFS_PING_PEER: {
4534 struct lnet_ioctl_ping_data *ping = arg;
4535 struct lnet_process_id __user *ids = ping->ping_buf;
4536 struct lnet_nid src_nid = LNET_ANY_NID;
4537 struct lnet_genl_ping_list plist;
4538 struct lnet_processid id;
4539 struct lnet_peer *lp;
4540 signed long timeout;
4543 /* Check if the supplied ping data supports source nid
4544 * NB: This check is sufficient if lnet_ioctl_ping_data has
4545 * additional fields added, but if they are re-ordered or
4546 * fields removed then this will break. It is expected that
4547 * these ioctls will be replaced with netlink implementation, so
4548 * it is probably not worth coming up with a more robust version
4549 * compatibility scheme.
4551 if (ping->ping_hdr.ioc_len >= sizeof(struct lnet_ioctl_ping_data))
4552 lnet_nid4_to_nid(ping->ping_src, &src_nid);
4554 /* If timeout is negative then set default of 3 minutes */
4555 if (((s32)ping->op_param) <= 0 ||
4556 ping->op_param > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
4557 timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
4559 timeout = nsecs_to_jiffies(ping->op_param * NSEC_PER_MSEC);
4561 id.pid = ping->ping_id.pid;
4562 lnet_nid4_to_nid(ping->ping_id.nid, &id.nid);
4563 rc = lnet_ping(&id, &src_nid, timeout, &plist,
4566 goto report_ping_err;
4570 for (i = 0; i < count; i++) {
4571 struct lnet_processid *result;
4572 struct lnet_process_id tmpid;
4574 result = genradix_ptr(&plist.lgpl_list, i);
4575 memset(&tmpid, 0, sizeof(tmpid));
4576 tmpid.pid = result->pid;
4577 tmpid.nid = lnet_nid_to_nid4(&result->nid);
4578 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid))) {
4580 goto report_ping_err;
4584 mutex_lock(&the_lnet.ln_api_mutex);
4585 lp = lnet_find_peer(&id.nid);
4588 lnet_nid_to_nid4(&lp->lp_primary_nid);
4589 ping->mr_info = lnet_peer_is_multi_rail(lp);
4590 lnet_peer_decref_locked(lp);
4592 mutex_unlock(&the_lnet.ln_api_mutex);
4594 ping->ping_count = count;
4596 genradix_free(&plist.lgpl_list);
4600 case IOC_LIBCFS_DISCOVER: {
4601 struct lnet_ioctl_ping_data *discover = arg;
4602 struct lnet_process_id __user *ids;
4603 struct lnet_genl_ping_list dlists;
4604 struct lnet_processid id;
4605 struct lnet_peer *lp;
4608 if (discover->ping_count <= 0)
4611 genradix_init(&dlists.lgpl_list);
4612 /* If the user buffer has more space than the lnet_interfaces_max,
4613 * then only fill it up to lnet_interfaces_max.
4615 if (discover->ping_count > lnet_interfaces_max)
4616 discover->ping_count = lnet_interfaces_max;
4618 id.pid = discover->ping_id.pid;
4619 lnet_nid4_to_nid(discover->ping_id.nid, &id.nid);
4620 rc = lnet_discover(&id, discover->op_param, &dlists);
4622 goto report_discover_err;
4625 ids = discover->ping_buf;
4626 for (i = 0; i < count; i++) {
4627 struct lnet_processid *result;
4628 struct lnet_process_id tmpid;
4630 result = genradix_ptr(&dlists.lgpl_list, i);
4631 memset(&tmpid, 0, sizeof(tmpid));
4632 tmpid.pid = result->pid;
4633 tmpid.nid = lnet_nid_to_nid4(&result->nid);
4634 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid))) {
4636 goto report_discover_err;
4639 if (i >= discover->ping_count)
4644 mutex_lock(&the_lnet.ln_api_mutex);
4645 lp = lnet_find_peer(&id.nid);
4647 discover->ping_id.nid =
4648 lnet_nid_to_nid4(&lp->lp_primary_nid);
4649 discover->mr_info = lnet_peer_is_multi_rail(lp);
4650 lnet_peer_decref_locked(lp);
4652 mutex_unlock(&the_lnet.ln_api_mutex);
4654 discover->ping_count = count;
4655 report_discover_err:
4656 genradix_free(&dlists.lgpl_list);
4660 case IOC_LIBCFS_ADD_UDSP: {
4661 struct lnet_ioctl_udsp *ioc_udsp = arg;
4662 __u32 bulk_size = ioc_udsp->iou_hdr.ioc_len;
4664 mutex_lock(&the_lnet.ln_api_mutex);
4665 rc = lnet_udsp_demarshal_add(arg, bulk_size);
4667 rc = lnet_udsp_apply_policies(NULL, false);
4668 CDEBUG(D_NET, "policy application returned %d\n", rc);
4671 mutex_unlock(&the_lnet.ln_api_mutex);
4676 case IOC_LIBCFS_DEL_UDSP: {
4677 struct lnet_ioctl_udsp *ioc_udsp = arg;
4678 int idx = ioc_udsp->iou_idx;
4680 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4683 mutex_lock(&the_lnet.ln_api_mutex);
4684 rc = lnet_udsp_del_policy(idx);
4685 mutex_unlock(&the_lnet.ln_api_mutex);
4690 case IOC_LIBCFS_GET_UDSP_SIZE: {
4691 struct lnet_ioctl_udsp *ioc_udsp = arg;
4692 struct lnet_udsp *udsp;
4694 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4699 mutex_lock(&the_lnet.ln_api_mutex);
4700 udsp = lnet_udsp_get_policy(ioc_udsp->iou_idx);
4704 /* coming in iou_idx will hold the idx of the udsp
4705 * to get the size of. going out the iou_idx will
4706 * hold the size of the UDSP found at the passed
4709 ioc_udsp->iou_idx = lnet_get_udsp_size(udsp);
4710 if (ioc_udsp->iou_idx < 0)
4713 mutex_unlock(&the_lnet.ln_api_mutex);
4718 case IOC_LIBCFS_GET_UDSP: {
4719 struct lnet_ioctl_udsp *ioc_udsp = arg;
4720 struct lnet_udsp *udsp;
4722 if (ioc_udsp->iou_hdr.ioc_len < sizeof(*ioc_udsp))
4727 mutex_lock(&the_lnet.ln_api_mutex);
4728 udsp = lnet_udsp_get_policy(ioc_udsp->iou_idx);
4732 rc = lnet_udsp_marshal(udsp, ioc_udsp);
4733 mutex_unlock(&the_lnet.ln_api_mutex);
4738 case IOC_LIBCFS_GET_CONST_UDSP_INFO: {
4739 struct lnet_ioctl_construct_udsp_info *info = arg;
4741 if (info->cud_hdr.ioc_len < sizeof(*info))
4744 CDEBUG(D_NET, "GET_UDSP_INFO for %s\n",
4745 libcfs_nid2str(info->cud_nid));
4747 lnet_nid4_to_nid(info->cud_nid, &nid);
4748 mutex_lock(&the_lnet.ln_api_mutex);
4750 lnet_udsp_get_construct_info(info, &nid);
4752 mutex_unlock(&the_lnet.ln_api_mutex);
4758 ni = lnet_net2ni_addref(data->ioc_net);
4762 if (ni->ni_net->net_lnd->lnd_ctl == NULL)
4765 rc = ni->ni_net->net_lnd->lnd_ctl(ni, cmd, arg);
4768 return rc <= 0 ? rc : 0;
4772 EXPORT_SYMBOL(LNetCtl);
4774 static int lnet_net_conf_cmd(struct sk_buff *skb, struct genl_info *info)
4778 if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
4779 /* NLM_F_EXCL means ignore module parameters */
4780 if (info->nlhdr->nlmsg_flags & NLM_F_EXCL)
4781 the_lnet.ln_nis_from_mod_params = true;
4783 if (info->nlhdr->nlmsg_flags & NLM_F_REPLACE)
4784 the_lnet.ln_nis_use_large_nids = true;
4786 rc = lnet_configure(NULL);
4789 GENL_SET_ERR_MSG(info,
4793 GENL_SET_ERR_MSG(info,
4794 "LNET is currently not loaded");
4797 GENL_SET_ERR_MSG(info, "LNET busy");
4803 rc = lnet_unconfigure();
4809 struct lnet_nid_cpt {
4810 struct lnet_nid lnc_nid;
4811 unsigned int lnc_cpt;
4814 struct lnet_genl_nid_cpt_list {
4815 unsigned int lgncl_index;
4816 unsigned int lgncl_list_count;
4817 GENRADIX(struct lnet_nid_cpt) lgncl_lnc_list;
4820 static inline struct lnet_genl_nid_cpt_list *
4821 lnet_cpt_of_nid_dump_ctx(struct netlink_callback *cb)
4823 return (struct lnet_genl_nid_cpt_list *)cb->args[0];
4826 static int lnet_cpt_of_nid_show_done(struct netlink_callback *cb)
4828 struct lnet_genl_nid_cpt_list *lgncl;
4830 lgncl = lnet_cpt_of_nid_dump_ctx(cb);
4833 genradix_free(&lgncl->lgncl_lnc_list);
4834 LIBCFS_FREE(lgncl, sizeof(*lgncl));
4841 static int lnet_cpt_of_nid_show_start(struct netlink_callback *cb)
4843 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
4844 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
4845 struct netlink_ext_ack *extack = NULL;
4847 struct lnet_genl_nid_cpt_list *lgncl;
4848 int msg_len = genlmsg_len(gnlh);
4849 struct nlattr *params, *top;
4852 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
4853 extack = cb->extack;
4856 mutex_lock(&the_lnet.ln_api_mutex);
4857 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
4858 NL_SET_ERR_MSG(extack, "Network is down");
4859 mutex_unlock(&the_lnet.ln_api_mutex);
4863 msg_len = genlmsg_len(gnlh);
4865 NL_SET_ERR_MSG(extack, "Missing NID argument(s)");
4866 mutex_unlock(&the_lnet.ln_api_mutex);
4870 LIBCFS_ALLOC(lgncl, sizeof(*lgncl));
4872 mutex_unlock(&the_lnet.ln_api_mutex);
4876 genradix_init(&lgncl->lgncl_lnc_list);
4877 lgncl->lgncl_list_count = 0;
4878 cb->args[0] = (long)lgncl;
4880 params = genlmsg_data(gnlh);
4881 nla_for_each_attr(top, params, msg_len, rem) {
4882 struct nlattr *nids;
4885 switch (nla_type(top)) {
4886 case LN_SCALAR_ATTR_LIST:
4887 nla_for_each_nested(nids, top, rem2) {
4888 char nidstr[LNET_NIDSTR_SIZE + 1];
4889 struct lnet_nid_cpt *lnc;
4891 if (nla_type(nids) != LN_SCALAR_ATTR_VALUE)
4894 memset(nidstr, 0, sizeof(nidstr));
4895 rc = nla_strscpy(nidstr, nids, sizeof(nidstr));
4897 NL_SET_ERR_MSG(extack,
4898 "failed to get NID");
4899 GOTO(report_err, rc);
4902 lnc = genradix_ptr_alloc(&lgncl->lgncl_lnc_list,
4903 lgncl->lgncl_list_count++,
4906 NL_SET_ERR_MSG(extack,
4907 "failed to allocate NID");
4908 GOTO(report_err, rc = -ENOMEM);
4911 rc = libcfs_strnid(&lnc->lnc_nid,
4914 NL_SET_ERR_MSG(extack, "invalid NID");
4915 GOTO(report_err, rc);
4918 CDEBUG(D_NET, "nid: %s\n",
4919 libcfs_nidstr(&lnc->lnc_nid));
4927 mutex_unlock(&the_lnet.ln_api_mutex);
4930 lnet_cpt_of_nid_show_done(cb);
4935 static const struct ln_key_list cpt_of_nid_props_list = {
4936 .lkl_maxattr = LNET_CPT_OF_NID_ATTR_MAX,
4938 [LNET_CPT_OF_NID_ATTR_HDR] = {
4939 .lkp_value = "cpt-of-nid",
4940 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
4941 .lkp_data_type = NLA_NUL_STRING,
4943 [LNET_CPT_OF_NID_ATTR_NID] = {
4945 .lkp_data_type = NLA_STRING,
4947 [LNET_CPT_OF_NID_ATTR_CPT] = {
4949 .lkp_data_type = NLA_U32,
4954 static int lnet_cpt_of_nid_show_dump(struct sk_buff *msg,
4955 struct netlink_callback *cb)
4957 struct lnet_genl_nid_cpt_list *lgncl;
4958 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
4959 struct netlink_ext_ack *extack = NULL;
4961 int portid = NETLINK_CB(cb->skb).portid;
4962 int seq = cb->nlh->nlmsg_seq;
4965 bool need_hdr = true;
4967 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
4968 extack = cb->extack;
4971 mutex_lock(&the_lnet.ln_api_mutex);
4972 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
4973 NL_SET_ERR_MSG(extack, "Network is down");
4974 GOTO(send_error, rc = -ENETDOWN);
4977 lgncl = lnet_cpt_of_nid_dump_ctx(cb);
4978 idx = lgncl->lgncl_index;
4980 if (!lgncl->lgncl_index) {
4981 const struct ln_key_list *all[] = {
4982 &cpt_of_nid_props_list, NULL, NULL
4985 rc = lnet_genl_send_scalar_list(msg, portid, seq, &lnet_family,
4986 NLM_F_CREATE | NLM_F_MULTI,
4987 LNET_CMD_CPT_OF_NID, all);
4989 NL_SET_ERR_MSG(extack, "failed to send key table");
4990 GOTO(send_error, rc);
4994 while (idx < lgncl->lgncl_list_count) {
4995 struct lnet_nid_cpt *lnc;
4999 lnc = genradix_ptr(&lgncl->lgncl_lnc_list, idx++);
5001 cpt = lnet_nid_cpt_hash(&lnc->lnc_nid, LNET_CPT_NUMBER);
5003 CDEBUG(D_NET, "nid: %s cpt: %d\n", libcfs_nidstr(&lnc->lnc_nid), cpt);
5004 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
5005 NLM_F_MULTI, LNET_CMD_CPT_OF_NID);
5007 NL_SET_ERR_MSG(extack, "failed to send values");
5008 genlmsg_cancel(msg, hdr);
5009 GOTO(send_error, rc = -EMSGSIZE);
5013 nla_put_string(msg, LNET_CPT_OF_NID_ATTR_HDR, "");
5017 nla_put_string(msg, LNET_CPT_OF_NID_ATTR_NID,
5018 libcfs_nidstr(&lnc->lnc_nid));
5019 nla_put_u32(msg, LNET_CPT_OF_NID_ATTR_CPT, cpt);
5021 genlmsg_end(msg, hdr);
5024 genradix_free(&lgncl->lgncl_lnc_list);
5026 lgncl->lgncl_index = idx;
5029 mutex_unlock(&the_lnet.ln_api_mutex);
5031 return lnet_nl_send_error(cb->skb, portid, seq, rc);
5034 #ifndef HAVE_NETLINK_CALLBACK_START
5035 static int lnet_old_cpt_of_nid_show_dump(struct sk_buff *msg,
5036 struct netlink_callback *cb)
5039 int rc = lnet_cpt_of_nid_show_start(cb);
5042 return lnet_nl_send_error(cb->skb,
5043 NETLINK_CB(cb->skb).portid,
5048 return lnet_cpt_of_nid_show_dump(msg, cb);
5052 /* This is the keys for the UDSP info which is used by many
5055 static const struct ln_key_list udsp_info_list = {
5056 .lkl_maxattr = LNET_UDSP_INFO_ATTR_MAX,
5058 [LNET_UDSP_INFO_ATTR_NET_PRIORITY] = {
5059 .lkp_value = "net priority",
5060 .lkp_data_type = NLA_S32
5062 [LNET_UDSP_INFO_ATTR_NID_PRIORITY] = {
5063 .lkp_value = "nid priority",
5064 .lkp_data_type = NLA_S32
5066 [LNET_UDSP_INFO_ATTR_PREF_RTR_NIDS_LIST] = {
5067 .lkp_value = "Preferred gateway NIDs",
5068 .lkp_key_format = LNKF_MAPPING,
5069 .lkp_data_type = NLA_NESTED,
5071 [LNET_UDSP_INFO_ATTR_PREF_NIDS_LIST] = {
5072 .lkp_value = "Preferred source NIDs",
5073 .lkp_key_format = LNKF_MAPPING,
5074 .lkp_data_type = NLA_NESTED,
5079 static const struct ln_key_list udsp_info_pref_nids_list = {
5080 .lkl_maxattr = LNET_UDSP_INFO_PREF_NIDS_ATTR_MAX,
5082 [LNET_UDSP_INFO_PREF_NIDS_ATTR_INDEX] = {
5083 .lkp_value = "NID-0",
5084 .lkp_data_type = NLA_NUL_STRING,
5086 [LNET_UDSP_INFO_PREF_NIDS_ATTR_NID] = {
5087 .lkp_value = "0@lo",
5088 .lkp_data_type = NLA_STRING,
5093 static int lnet_udsp_info_send(struct sk_buff *msg, int attr,
5094 struct lnet_nid *nid, bool remote)
5096 struct lnet_ioctl_construct_udsp_info *udsp;
5097 struct nlattr *udsp_attr, *udsp_info;
5098 struct nlattr *udsp_list_attr;
5099 struct nlattr *udsp_list_info;
5102 CFS_ALLOC_PTR(udsp);
5106 udsp->cud_peer = remote;
5107 lnet_udsp_get_construct_info(udsp, nid);
5109 udsp_info = nla_nest_start(msg, attr);
5110 udsp_attr = nla_nest_start(msg, 0);
5111 nla_put_s32(msg, LNET_UDSP_INFO_ATTR_NET_PRIORITY,
5112 udsp->cud_net_priority);
5113 nla_put_s32(msg, LNET_UDSP_INFO_ATTR_NID_PRIORITY,
5114 udsp->cud_nid_priority);
5116 if (udsp->cud_pref_rtr_nid[0] == 0)
5119 udsp_list_info = nla_nest_start(msg,
5120 LNET_UDSP_INFO_ATTR_PREF_RTR_NIDS_LIST);
5121 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
5122 char tmp[8]; /* NID-"3 number"\0 */
5124 if (udsp->cud_pref_rtr_nid[i] == 0)
5127 udsp_list_attr = nla_nest_start(msg, i);
5128 snprintf(tmp, sizeof(tmp), "NID-%d", i);
5129 nla_put_string(msg, LNET_UDSP_INFO_PREF_NIDS_ATTR_INDEX,
5131 nla_put_string(msg, LNET_UDSP_INFO_PREF_NIDS_ATTR_NID,
5132 libcfs_nid2str(udsp->cud_pref_rtr_nid[i]));
5133 nla_nest_end(msg, udsp_list_attr);
5135 nla_nest_end(msg, udsp_list_info);
5137 nla_nest_end(msg, udsp_attr);
5138 nla_nest_end(msg, udsp_info);
5139 LIBCFS_FREE(udsp, sizeof(*udsp));
5144 /* LNet NI handling */
5145 static const struct ln_key_list net_props_list = {
5146 .lkl_maxattr = LNET_NET_ATTR_MAX,
5148 [LNET_NET_ATTR_HDR] = {
5150 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
5151 .lkp_data_type = NLA_NUL_STRING,
5153 [LNET_NET_ATTR_TYPE] = {
5154 .lkp_value = "net type",
5155 .lkp_data_type = NLA_STRING
5157 [LNET_NET_ATTR_LOCAL] = {
5158 .lkp_value = "local NI(s)",
5159 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
5160 .lkp_data_type = NLA_NESTED
5165 static struct ln_key_list local_ni_list = {
5166 .lkl_maxattr = LNET_NET_LOCAL_NI_ATTR_MAX,
5168 [LNET_NET_LOCAL_NI_ATTR_NID] = {
5170 .lkp_data_type = NLA_STRING
5172 [LNET_NET_LOCAL_NI_ATTR_STATUS] = {
5173 .lkp_value = "status",
5174 .lkp_data_type = NLA_STRING
5176 [LNET_NET_LOCAL_NI_ATTR_INTERFACE] = {
5177 .lkp_value = "interfaces",
5178 .lkp_key_format = LNKF_MAPPING,
5179 .lkp_data_type = NLA_NESTED
5181 [LNET_NET_LOCAL_NI_ATTR_STATS] = {
5182 .lkp_value = "statistics",
5183 .lkp_key_format = LNKF_MAPPING,
5184 .lkp_data_type = NLA_NESTED
5186 [LNET_NET_LOCAL_NI_ATTR_UDSP_INFO] = {
5187 .lkp_value = "udsp info",
5188 .lkp_key_format = LNKF_MAPPING,
5189 .lkp_data_type = NLA_NESTED
5191 [LNET_NET_LOCAL_NI_ATTR_SEND_STATS] = {
5192 .lkp_value = "sent_stats",
5193 .lkp_key_format = LNKF_MAPPING,
5194 .lkp_data_type = NLA_NESTED
5196 [LNET_NET_LOCAL_NI_ATTR_RECV_STATS] = {
5197 .lkp_value = "received_stats",
5198 .lkp_key_format = LNKF_MAPPING,
5199 .lkp_data_type = NLA_NESTED
5201 [LNET_NET_LOCAL_NI_ATTR_DROPPED_STATS] = {
5202 .lkp_value = "dropped_stats",
5203 .lkp_key_format = LNKF_MAPPING,
5204 .lkp_data_type = NLA_NESTED
5207 [LNET_NET_LOCAL_NI_ATTR_HEALTH_STATS] = {
5208 .lkp_value = "health stats",
5209 .lkp_key_format = LNKF_MAPPING,
5210 .lkp_data_type = NLA_NESTED
5212 [LNET_NET_LOCAL_NI_ATTR_TUNABLES] = {
5213 .lkp_value = "tunables",
5214 .lkp_key_format = LNKF_MAPPING,
5215 .lkp_data_type = NLA_NESTED
5217 [LNET_NET_LOCAL_NI_ATTR_LND_TUNABLES] = {
5218 .lkp_value = "lnd tunables",
5219 .lkp_key_format = LNKF_MAPPING,
5220 .lkp_data_type = NLA_NESTED
5222 [LNET_NET_LOCAL_NI_DEV_CPT] = {
5223 .lkp_value = "dev cpt",
5224 .lkp_data_type = NLA_S32,
5226 [LNET_NET_LOCAL_NI_CPTS] = {
5228 .lkp_data_type = NLA_STRING,
5233 static const struct ln_key_list local_ni_interfaces_list = {
5234 .lkl_maxattr = LNET_NET_LOCAL_NI_INTF_ATTR_MAX,
5236 [LNET_NET_LOCAL_NI_INTF_ATTR_TYPE] = {
5238 .lkp_data_type = NLA_STRING
5243 static const struct ln_key_list local_ni_stats_list = {
5244 .lkl_maxattr = LNET_NET_LOCAL_NI_STATS_ATTR_MAX,
5246 [LNET_NET_LOCAL_NI_STATS_ATTR_SEND_COUNT] = {
5247 .lkp_value = "send_count",
5248 .lkp_data_type = NLA_U32
5250 [LNET_NET_LOCAL_NI_STATS_ATTR_RECV_COUNT] = {
5251 .lkp_value = "recv_count",
5252 .lkp_data_type = NLA_U32
5254 [LNET_NET_LOCAL_NI_STATS_ATTR_DROP_COUNT] = {
5255 .lkp_value = "drop_count",
5256 .lkp_data_type = NLA_U32
5261 static const struct ln_key_list local_ni_msg_stats_list = {
5262 .lkl_maxattr = LNET_NET_LOCAL_NI_MSG_STATS_ATTR_MAX,
5264 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT] = {
5266 .lkp_data_type = NLA_U32
5268 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT] = {
5270 .lkp_data_type = NLA_U32
5272 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT] = {
5273 .lkp_value = "reply",
5274 .lkp_data_type = NLA_U32
5276 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT] = {
5278 .lkp_data_type = NLA_U32
5280 [LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT] = {
5281 .lkp_value = "hello",
5282 .lkp_data_type = NLA_U32
5287 static const struct ln_key_list local_ni_health_stats_list = {
5288 .lkl_maxattr = LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_MAX,
5290 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_FATAL_ERRORS] = {
5291 .lkp_value = "fatal_error",
5292 .lkp_data_type = NLA_S32
5294 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_LEVEL] = {
5295 .lkp_value = "health value",
5296 .lkp_data_type = NLA_S32
5298 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_INTERRUPTS] = {
5299 .lkp_value = "interrupts",
5300 .lkp_data_type = NLA_U32
5302 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_DROPPED] = {
5303 .lkp_value = "dropped",
5304 .lkp_data_type = NLA_U32
5306 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ABORTED] = {
5307 .lkp_value = "aborted",
5308 .lkp_data_type = NLA_U32
5310 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NO_ROUTE] = {
5311 .lkp_value = "no route",
5312 .lkp_data_type = NLA_U32
5314 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_TIMEOUTS] = {
5315 .lkp_value = "timeouts",
5316 .lkp_data_type = NLA_U32
5318 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ERROR] = {
5319 .lkp_value = "error",
5320 .lkp_data_type = NLA_U32
5322 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PING_COUNT] = {
5323 .lkp_value = "ping_count",
5324 .lkp_data_type = NLA_U32,
5326 [LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NEXT_PING] = {
5327 .lkp_value = "next_ping",
5328 .lkp_data_type = NLA_U64
5333 static const struct ln_key_list local_ni_tunables_list = {
5334 .lkl_maxattr = LNET_NET_LOCAL_NI_TUNABLES_ATTR_MAX,
5336 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT] = {
5337 .lkp_value = "peer_timeout",
5338 .lkp_data_type = NLA_S32
5340 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS] = {
5341 .lkp_value = "peer_credits",
5342 .lkp_data_type = NLA_S32
5344 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS] = {
5345 .lkp_value = "peer_buffer_credits",
5346 .lkp_data_type = NLA_S32
5348 [LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS] = {
5349 .lkp_value = "credits",
5350 .lkp_data_type = NLA_S32
5355 /* Use an index since the traversal is across LNet nets and ni collections */
5356 struct lnet_genl_net_list {
5357 unsigned int lngl_net_id;
5358 unsigned int lngl_idx;
5361 static inline struct lnet_genl_net_list *
5362 lnet_net_dump_ctx(struct netlink_callback *cb)
5364 return (struct lnet_genl_net_list *)cb->args[0];
5367 static int lnet_net_show_done(struct netlink_callback *cb)
5369 struct lnet_genl_net_list *nlist = lnet_net_dump_ctx(cb);
5372 LIBCFS_FREE(nlist, sizeof(*nlist));
5379 /* LNet net ->start() handler for GET requests */
5380 static int lnet_net_show_start(struct netlink_callback *cb)
5382 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
5383 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
5384 struct netlink_ext_ack *extack = NULL;
5386 struct lnet_genl_net_list *nlist;
5387 int msg_len = genlmsg_len(gnlh);
5388 struct nlattr *params, *top;
5391 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
5392 extack = cb->extack;
5394 if (the_lnet.ln_refcount == 0) {
5395 NL_SET_ERR_MSG(extack, "LNet stack down");
5399 LIBCFS_ALLOC(nlist, sizeof(*nlist));
5403 nlist->lngl_net_id = LNET_NET_ANY;
5404 nlist->lngl_idx = 0;
5405 cb->args[0] = (long)nlist;
5407 cb->min_dump_alloc = U16_MAX;
5411 params = genlmsg_data(gnlh);
5412 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
5413 NL_SET_ERR_MSG(extack, "invalid configuration");
5417 nla_for_each_nested(top, params, rem) {
5421 nla_for_each_nested(net, top, rem2) {
5422 char filter[LNET_NIDSTR_SIZE];
5424 if (nla_type(net) != LN_SCALAR_ATTR_VALUE ||
5425 nla_strcmp(net, "net type") != 0)
5428 net = nla_next(net, &rem2);
5429 if (nla_type(net) != LN_SCALAR_ATTR_VALUE) {
5430 NL_SET_ERR_MSG(extack, "invalid config param");
5431 GOTO(report_err, rc = -EINVAL);
5434 rc = nla_strscpy(filter, net, sizeof(filter));
5436 NL_SET_ERR_MSG(extack, "failed to get param");
5437 GOTO(report_err, rc);
5441 nlist->lngl_net_id = libcfs_str2net(filter);
5442 if (nlist->lngl_net_id == LNET_NET_ANY) {
5443 NL_SET_ERR_MSG(extack, "cannot parse net");
5444 GOTO(report_err, rc = -ENOENT);
5450 lnet_net_show_done(cb);
5455 static const struct ln_key_list net_update_props_list = {
5456 .lkl_maxattr = LNET_NET_ATTR_MAX,
5458 [LNET_NET_ATTR_HDR] = {
5460 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
5461 .lkp_data_type = NLA_NUL_STRING,
5463 [LNET_NET_ATTR_TYPE] = {
5464 .lkp_value = "net type",
5465 .lkp_data_type = NLA_STRING
5467 [LNET_NET_ATTR_LOCAL] = {
5468 .lkp_value = "local NI(s)",
5469 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
5470 .lkp_data_type = NLA_NESTED
5475 static int lnet_net_show_dump(struct sk_buff *msg,
5476 struct netlink_callback *cb)
5478 struct lnet_genl_net_list *nlist = lnet_net_dump_ctx(cb);
5479 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
5480 struct netlink_ext_ack *extack = NULL;
5482 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
5483 int portid = NETLINK_CB(cb->skb).portid;
5484 bool found = false, started = false;
5485 const struct lnet_lnd *lnd = NULL;
5486 int idx = nlist->lngl_idx, rc = 0;
5487 int seq = cb->nlh->nlmsg_seq;
5488 struct lnet_net *net;
5491 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
5492 extack = cb->extack;
5494 lnet_net_lock(LNET_LOCK_EX);
5496 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
5497 struct nlattr *local_ni, *ni_attr;
5501 if (nlist->lngl_net_id != LNET_NET_ANY &&
5502 nlist->lngl_net_id != net->net_id)
5505 if (cb->nlh->nlmsg_flags & NLM_F_DUMP_FILTERED &&
5506 LNET_NETTYP(net->net_id) == LOLND)
5509 if (gnlh->version && LNET_NETTYP(net->net_id) != LOLND) {
5510 if (!net->net_lnd) {
5511 NL_SET_ERR_MSG(extack,
5512 "LND not setup for NI");
5513 GOTO(net_unlock, rc = -ENODEV);
5515 if (net->net_lnd != lnd)
5521 /* We need to resend the key table every time the base LND
5525 const struct ln_key_list *all[] = {
5526 &net_props_list, &local_ni_list,
5527 &local_ni_interfaces_list,
5528 &local_ni_stats_list,
5530 &udsp_info_pref_nids_list,
5531 &udsp_info_pref_nids_list,
5532 &local_ni_msg_stats_list,
5533 &local_ni_msg_stats_list,
5534 &local_ni_msg_stats_list,
5535 &local_ni_health_stats_list,
5536 &local_ni_tunables_list,
5537 NULL, /* lnd tunables */
5540 int flags = NLM_F_CREATE | NLM_F_MULTI;
5543 all[ARRAY_SIZE(all) - 2] = lnd->lnd_keys;
5545 all[0] = &net_update_props_list;
5546 flags |= NLM_F_REPLACE;
5550 rc = lnet_genl_send_scalar_list(msg, portid, seq,
5551 &lnet_family, flags,
5552 LNET_CMD_NETS, all);
5554 NL_SET_ERR_MSG(extack, "failed to send key table");
5555 GOTO(net_unlock, rc);
5560 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
5561 NLM_F_MULTI, LNET_CMD_NETS);
5563 NL_SET_ERR_MSG(extack, "failed to send values");
5564 GOTO(net_unlock, rc = -EMSGSIZE);
5568 nla_put_string(msg, LNET_NET_ATTR_HDR, "");
5572 nla_put_string(msg, LNET_NET_ATTR_TYPE,
5573 libcfs_net2str(net->net_id));
5575 local_ni = nla_nest_start(msg, LNET_NET_ATTR_LOCAL);
5576 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
5577 char *status = "up";
5579 if (idx++ < nlist->lngl_idx)
5582 ni_attr = nla_nest_start(msg, dev++);
5585 if (!(cb->nlh->nlmsg_flags & NLM_F_DUMP_FILTERED)) {
5586 nla_put_string(msg, LNET_NET_LOCAL_NI_ATTR_NID,
5587 libcfs_nidstr(&ni->ni_nid));
5588 if (!nid_is_lo0(&ni->ni_nid) &&
5589 lnet_ni_get_status_locked(ni) != LNET_NI_STATUS_UP)
5591 nla_put_string(msg, LNET_NET_LOCAL_NI_ATTR_STATUS,
5595 if (!nid_is_lo0(&ni->ni_nid) && ni->ni_interface) {
5596 struct nlattr *intf_nest, *intf_attr;
5598 intf_nest = nla_nest_start(msg,
5599 LNET_NET_LOCAL_NI_ATTR_INTERFACE);
5600 intf_attr = nla_nest_start(msg, 0);
5602 LNET_NET_LOCAL_NI_INTF_ATTR_TYPE,
5604 nla_nest_end(msg, intf_attr);
5605 nla_nest_end(msg, intf_nest);
5608 if (gnlh->version) {
5609 char cpts[LNET_MAX_SHOW_NUM_CPT * 4 + 4], *cpt;
5610 struct lnet_ioctl_element_msg_stats msg_stats;
5611 struct lnet_ioctl_element_stats stats;
5612 size_t buf_len = sizeof(cpts), len;
5613 struct nlattr *health_attr, *health_stats;
5614 struct nlattr *send_attr, *send_stats;
5615 struct nlattr *recv_attr, *recv_stats;
5616 struct nlattr *drop_attr, *drop_stats;
5617 struct nlattr *stats_attr, *ni_stats;
5618 struct nlattr *tun_attr, *ni_tun;
5621 if (cb->nlh->nlmsg_flags & NLM_F_DUMP_FILTERED) {
5623 goto skip_msg_stats;
5626 stats.iel_send_count = lnet_sum_stats(&ni->ni_stats,
5627 LNET_STATS_TYPE_SEND);
5628 stats.iel_recv_count = lnet_sum_stats(&ni->ni_stats,
5629 LNET_STATS_TYPE_RECV);
5630 stats.iel_drop_count = lnet_sum_stats(&ni->ni_stats,
5631 LNET_STATS_TYPE_DROP);
5634 stats_attr = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_STATS);
5635 ni_stats = nla_nest_start(msg, 0);
5636 nla_put_u32(msg, LNET_NET_LOCAL_NI_STATS_ATTR_SEND_COUNT,
5637 stats.iel_send_count);
5638 nla_put_u32(msg, LNET_NET_LOCAL_NI_STATS_ATTR_RECV_COUNT,
5639 stats.iel_recv_count);
5640 nla_put_u32(msg, LNET_NET_LOCAL_NI_STATS_ATTR_DROP_COUNT,
5641 stats.iel_drop_count);
5642 nla_nest_end(msg, ni_stats);
5643 nla_nest_end(msg, stats_attr);
5645 if (gnlh->version < 4)
5649 rc = lnet_udsp_info_send(msg, LNET_NET_LOCAL_NI_ATTR_UDSP_INFO,
5650 &ni->ni_nid, false);
5652 NL_SET_ERR_MSG(extack,
5653 "Failed to get udsp info");
5654 genlmsg_cancel(msg, hdr);
5655 GOTO(net_unlock, rc = -ENOMEM);
5658 if (gnlh->version < 2)
5659 goto skip_msg_stats;
5661 msg_stats.im_idx = idx - 1;
5662 rc = lnet_get_ni_stats(&msg_stats);
5664 NL_SET_ERR_MSG(extack,
5665 "failed to get msg stats");
5666 genlmsg_cancel(msg, hdr);
5667 GOTO(net_unlock, rc = -ENOMEM);
5670 send_stats = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_SEND_STATS);
5671 send_attr = nla_nest_start(msg, 0);
5672 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT,
5673 msg_stats.im_send_stats.ico_get_count);
5674 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT,
5675 msg_stats.im_send_stats.ico_put_count);
5676 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT,
5677 msg_stats.im_send_stats.ico_reply_count);
5678 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT,
5679 msg_stats.im_send_stats.ico_ack_count);
5680 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT,
5681 msg_stats.im_send_stats.ico_hello_count);
5682 nla_nest_end(msg, send_attr);
5683 nla_nest_end(msg, send_stats);
5685 recv_stats = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_RECV_STATS);
5686 recv_attr = nla_nest_start(msg, 0);
5687 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT,
5688 msg_stats.im_recv_stats.ico_get_count);
5689 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT,
5690 msg_stats.im_recv_stats.ico_put_count);
5691 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT,
5692 msg_stats.im_recv_stats.ico_reply_count);
5693 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT,
5694 msg_stats.im_recv_stats.ico_ack_count);
5695 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT,
5696 msg_stats.im_recv_stats.ico_hello_count);
5697 nla_nest_end(msg, recv_attr);
5698 nla_nest_end(msg, recv_stats);
5700 drop_stats = nla_nest_start(msg,
5701 LNET_NET_LOCAL_NI_ATTR_DROPPED_STATS);
5702 drop_attr = nla_nest_start(msg, 0);
5703 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT,
5704 msg_stats.im_drop_stats.ico_get_count);
5705 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT,
5706 msg_stats.im_drop_stats.ico_put_count);
5707 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT,
5708 msg_stats.im_drop_stats.ico_reply_count);
5709 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT,
5710 msg_stats.im_drop_stats.ico_ack_count);
5711 nla_put_u32(msg, LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT,
5712 msg_stats.im_drop_stats.ico_hello_count);
5713 nla_nest_end(msg, drop_attr);
5714 nla_nest_end(msg, drop_stats);
5717 health_stats = nla_nest_start(msg,
5718 LNET_NET_LOCAL_NI_ATTR_HEALTH_STATS);
5719 health_attr = nla_nest_start(msg, 0);
5720 nla_put_s32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_FATAL_ERRORS,
5721 atomic_read(&ni->ni_fatal_error_on));
5722 nla_put_s32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_LEVEL,
5723 atomic_read(&ni->ni_healthv));
5724 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_INTERRUPTS,
5725 atomic_read(&ni->ni_hstats.hlt_local_interrupt));
5726 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_DROPPED,
5727 atomic_read(&ni->ni_hstats.hlt_local_dropped));
5728 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ABORTED,
5729 atomic_read(&ni->ni_hstats.hlt_local_aborted));
5730 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NO_ROUTE,
5731 atomic_read(&ni->ni_hstats.hlt_local_no_route));
5732 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_TIMEOUTS,
5733 atomic_read(&ni->ni_hstats.hlt_local_timeout));
5734 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ERROR,
5735 atomic_read(&ni->ni_hstats.hlt_local_error));
5736 nla_put_u32(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PING_COUNT,
5738 nla_put_u64_64bit(msg, LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NEXT_PING,
5740 LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PAD);
5741 nla_nest_end(msg, health_attr);
5742 nla_nest_end(msg, health_stats);
5744 /* Report net tunables */
5745 tun_attr = nla_nest_start(msg, LNET_NET_LOCAL_NI_ATTR_TUNABLES);
5746 ni_tun = nla_nest_start(msg, 0);
5747 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT,
5748 ni->ni_net->net_tunables.lct_peer_timeout);
5749 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS,
5750 ni->ni_net->net_tunables.lct_peer_tx_credits);
5751 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS,
5752 ni->ni_net->net_tunables.lct_peer_rtr_credits);
5753 nla_put_s32(msg, LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS,
5754 ni->ni_net->net_tunables.lct_max_tx_credits);
5755 nla_nest_end(msg, ni_tun);
5757 nla_nest_end(msg, tun_attr);
5759 if (lnd && lnd->lnd_nl_get && lnd->lnd_keys) {
5760 struct nlattr *lnd_tun_attr, *lnd_ni_tun;
5762 lnd_tun_attr = nla_nest_start(msg,
5763 LNET_NET_LOCAL_NI_ATTR_LND_TUNABLES);
5764 lnd_ni_tun = nla_nest_start(msg, 0);
5765 rc = lnd->lnd_nl_get(LNET_CMD_NETS, msg,
5766 LNET_NET_LOCAL_NI_ATTR_LND_TUNABLES,
5769 NL_SET_ERR_MSG(extack,
5770 "failed to get lnd tunables");
5771 genlmsg_cancel(msg, hdr);
5772 GOTO(net_unlock, rc);
5774 nla_nest_end(msg, lnd_ni_tun);
5775 nla_nest_end(msg, lnd_tun_attr);
5778 if (!(cb->nlh->nlmsg_flags & NLM_F_DUMP_FILTERED))
5779 nla_put_s32(msg, LNET_NET_LOCAL_NI_DEV_CPT,
5782 /* Report cpts. We could send this as a nested list
5783 * of integers but older versions of the tools
5784 * except a string. The new versions can handle
5785 * both formats so in the future we can change
5786 * this to a nested list.
5788 len = snprintf(cpts, buf_len, "\"[");
5792 if (ni->ni_ncpts == LNET_CPT_NUMBER && !ni->ni_cpts) {
5793 for (j = 0; j < ni->ni_ncpts; j++) {
5794 len = snprintf(cpt, buf_len, "%d,", j);
5800 ni->ni_cpts && j < ni->ni_ncpts &&
5801 j < LNET_MAX_SHOW_NUM_CPT; j++) {
5802 len = snprintf(cpt, buf_len, "%d,",
5808 snprintf(cpt - 1, sizeof(cpts), "]\"");
5810 nla_put_string(msg, LNET_NET_LOCAL_NI_CPTS, cpts);
5814 nla_nest_end(msg, ni_attr);
5816 nla_nest_end(msg, local_ni);
5818 genlmsg_end(msg, hdr);
5822 struct nlmsghdr *nlh = nlmsg_hdr(msg);
5824 nlmsg_cancel(msg, nlh);
5825 NL_SET_ERR_MSG(extack, "Network is down");
5828 nlist->lngl_idx = idx;
5830 lnet_net_unlock(LNET_LOCK_EX);
5832 return lnet_nl_send_error(cb->skb, portid, seq, rc);
5835 #ifndef HAVE_NETLINK_CALLBACK_START
5836 static int lnet_old_net_show_dump(struct sk_buff *msg,
5837 struct netlink_callback *cb)
5840 int rc = lnet_net_show_start(cb);
5843 return lnet_nl_send_error(cb->skb,
5844 NETLINK_CB(cb->skb).portid,
5849 return lnet_net_show_dump(msg, cb);
5853 static int lnet_genl_parse_tunables(struct nlattr *settings,
5854 struct lnet_ioctl_config_lnd_tunables *tun)
5856 struct nlattr *param;
5859 nla_for_each_nested(param, settings, rem) {
5860 int type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_UNSPEC;
5863 if (nla_type(param) != LN_SCALAR_ATTR_VALUE)
5866 if (nla_strcmp(param, "peer_timeout") == 0)
5867 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT;
5868 else if (nla_strcmp(param, "peer_credits") == 0)
5869 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS;
5870 else if (nla_strcmp(param, "peer_buffer_credits") == 0)
5871 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS;
5872 else if (nla_strcmp(param, "credits") == 0)
5873 type = LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS;
5875 param = nla_next(param, &rem);
5876 if (nla_type(param) != LN_SCALAR_ATTR_INT_VALUE)
5879 num = nla_get_s64(param);
5881 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT:
5883 tun->lt_cmn.lct_peer_timeout = num;
5885 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS:
5887 tun->lt_cmn.lct_peer_tx_credits = num;
5889 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS:
5891 tun->lt_cmn.lct_peer_rtr_credits = num;
5893 case LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS:
5895 tun->lt_cmn.lct_max_tx_credits = num;
5905 static int lnet_genl_parse_lnd_tunables(struct nlattr *settings,
5906 struct lnet_lnd_tunables *tun,
5907 const struct lnet_lnd *lnd)
5909 const struct ln_key_list *list = lnd->lnd_keys;
5910 struct nlattr *param;
5914 /* silently ignore these setting if the LND driver doesn't
5915 * support any LND tunables
5917 if (!list || !lnd->lnd_nl_set || !list->lkl_maxattr)
5920 nla_for_each_nested(param, settings, rem) {
5921 if (nla_type(param) != LN_SCALAR_ATTR_VALUE)
5924 for (i = 1; i <= list->lkl_maxattr; i++) {
5925 if (!list->lkl_list[i].lkp_value ||
5926 nla_strcmp(param, list->lkl_list[i].lkp_value) != 0)
5929 param = nla_next(param, &rem);
5930 rc = lnd->lnd_nl_set(LNET_CMD_NETS, param, i, tun);
5940 lnet_genl_init_tunables(const struct lnet_lnd *lnd,
5941 struct lnet_ioctl_config_lnd_tunables *tun)
5943 const struct ln_key_list *list = lnd ? lnd->lnd_keys : NULL;
5946 tun->lt_cmn.lct_peer_timeout = -1;
5947 tun->lt_cmn.lct_peer_tx_credits = -1;
5948 tun->lt_cmn.lct_peer_rtr_credits = -1;
5949 tun->lt_cmn.lct_max_tx_credits = -1;
5951 if (!list || !lnd->lnd_nl_set || !list->lkl_maxattr)
5954 /* init lnd tunables with default values */
5955 for (i = 1; i <= list->lkl_maxattr; i++)
5956 lnd->lnd_nl_set(LNET_CMD_NETS, NULL, i, &tun->lt_tun);
5960 lnet_genl_parse_local_ni(struct nlattr *entry, struct genl_info *info,
5961 int net_id, struct lnet_ioctl_config_ni *conf,
5964 struct lnet_ioctl_config_lnd_tunables *tun;
5965 struct lnet_nid nid = LNET_ANY_NID;
5966 const struct lnet_lnd *lnd = NULL;
5967 struct nlattr *settings;
5971 if (net_id != LNET_NET_ANY) {
5972 lnd = lnet_load_lnd(LNET_NETTYP(net_id));
5974 GENL_SET_ERR_MSG(info, "LND type not supported");
5975 RETURN(PTR_ERR(lnd));
5979 LIBCFS_ALLOC(tun, sizeof(struct lnet_ioctl_config_lnd_tunables));
5981 GENL_SET_ERR_MSG(info, "cannot allocate memory for tunables");
5982 GOTO(out, rc = -ENOMEM);
5985 /* Use LND defaults */
5986 lnet_genl_init_tunables(lnd, tun);
5987 conf->lic_ncpts = 0;
5989 nla_for_each_nested(settings, entry, rem3) {
5990 if (nla_type(settings) != LN_SCALAR_ATTR_VALUE)
5993 if (nla_strcmp(settings, "interfaces") == 0) {
5994 struct nlattr *intf;
5997 settings = nla_next(settings, &rem3);
5998 if (nla_type(settings) !=
5999 LN_SCALAR_ATTR_LIST) {
6000 GENL_SET_ERR_MSG(info,
6001 "invalid interfaces");
6002 GOTO(out, rc = -EINVAL);
6005 nla_for_each_nested(intf, settings, rem4) {
6006 intf = nla_next(intf, &rem4);
6007 if (nla_type(intf) !=
6008 LN_SCALAR_ATTR_VALUE) {
6009 GENL_SET_ERR_MSG(info,
6010 "cannot parse interface");
6011 GOTO(out, rc = -EINVAL);
6014 rc = nla_strscpy(conf->lic_ni_intf, intf,
6015 sizeof(conf->lic_ni_intf));
6017 GENL_SET_ERR_MSG(info,
6018 "failed to parse interfaces");
6023 } else if (nla_strcmp(settings, "nid") == 0 &&
6024 net_id != LNET_NET_ANY) {
6025 char nidstr[LNET_NIDSTR_SIZE];
6027 settings = nla_next(settings, &rem3);
6028 if (nla_type(settings) != LN_SCALAR_ATTR_VALUE) {
6029 GENL_SET_ERR_MSG(info, "cannot parse NID");
6030 GOTO(out, rc = -EINVAL);
6033 rc = nla_strscpy(nidstr, settings, sizeof(nidstr));
6035 GENL_SET_ERR_MSG(info,
6036 "failed to parse NID");
6040 CDEBUG(D_NET, "Requested NID %s\n", nidstr);
6041 rc = libcfs_strnid(&nid, strim(nidstr));
6043 GENL_SET_ERR_MSG(info, "unsupported NID");
6047 if (!(info->nlhdr->nlmsg_flags & NLM_F_REPLACE) &&
6048 nid_same(&nid, &LNET_ANY_NID)) {
6049 GENL_SET_ERR_MSG(info, "any NID not supported");
6050 GOTO(out, rc = -EINVAL);
6053 } else if (nla_strcmp(settings, "health stats") == 0 &&
6054 info->nlhdr->nlmsg_flags & NLM_F_REPLACE) {
6055 struct nlattr *health;
6058 settings = nla_next(settings, &rem3);
6059 if (nla_type(settings) != LN_SCALAR_ATTR_LIST) {
6060 GENL_SET_ERR_MSG(info,
6061 "cannot parse health stats");
6062 GOTO(out, rc = -EINVAL);
6065 nla_for_each_nested(health, settings, rem4) {
6066 if (nla_type(health) != LN_SCALAR_ATTR_VALUE ||
6067 nla_strcmp(health, "health value") != 0) {
6068 GENL_SET_ERR_MSG(info,
6069 "wrong health config format");
6070 GOTO(out, rc = -EINVAL);
6073 health = nla_next(health, &rem4);
6074 if (nla_type(health) !=
6075 LN_SCALAR_ATTR_INT_VALUE) {
6076 GENL_SET_ERR_MSG(info,
6077 "invalid health config format");
6078 GOTO(out, rc = -EINVAL);
6081 healthv = nla_get_s64(health);
6082 clamp_t(s64, healthv, 0, LNET_MAX_HEALTH_VALUE);
6084 } else if (nla_strcmp(settings, "tunables") == 0) {
6085 settings = nla_next(settings, &rem3);
6086 if (nla_type(settings) !=
6087 LN_SCALAR_ATTR_LIST) {
6088 GENL_SET_ERR_MSG(info,
6089 "invalid tunables");
6090 GOTO(out, rc = -EINVAL);
6093 rc = lnet_genl_parse_tunables(settings, tun);
6095 GENL_SET_ERR_MSG(info,
6096 "failed to parse tunables");
6099 } else if ((nla_strcmp(settings, "lnd tunables") == 0)) {
6100 settings = nla_next(settings, &rem3);
6101 if (nla_type(settings) !=
6102 LN_SCALAR_ATTR_LIST) {
6103 GENL_SET_ERR_MSG(info,
6104 "lnd tunables should be list\n");
6105 GOTO(out, rc = -EINVAL);
6108 if (info->nlhdr->nlmsg_flags & NLM_F_REPLACE &&
6109 net_id == LNET_NET_ANY) {
6110 struct lnet_net *net;
6112 lnet_net_lock(LNET_LOCK_EX);
6113 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
6119 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
6120 if (!nid_same(&nid, &LNET_ANY_NID) &&
6121 !nid_same(&nid, &ni->ni_nid))
6124 rc = lnet_genl_parse_lnd_tunables(settings,
6125 &ni->ni_lnd_tunables,
6128 GENL_SET_ERR_MSG(info,
6129 "failed to parse lnd tunables");
6130 lnet_net_unlock(LNET_LOCK_EX);
6135 lnet_net_unlock(LNET_LOCK_EX);
6137 lnd = lnet_load_lnd(LNET_NETTYP(net_id));
6139 GENL_SET_ERR_MSG(info,
6140 "LND type not supported");
6141 GOTO(out, rc = PTR_ERR(lnd));
6144 rc = lnet_genl_parse_lnd_tunables(settings,
6147 GENL_SET_ERR_MSG(info,
6148 "failed to parse lnd tunables");
6152 } else if (nla_strcmp(settings, "CPT") == 0) {
6156 settings = nla_next(settings, &rem3);
6157 if (nla_type(settings) != LN_SCALAR_ATTR_LIST) {
6158 GENL_SET_ERR_MSG(info,
6159 "CPT should be list");
6160 GOTO(out, rc = -EINVAL);
6163 nla_for_each_nested(cpt, settings, rem4) {
6166 if (nla_type(cpt) !=
6167 LN_SCALAR_ATTR_INT_VALUE) {
6168 GENL_SET_ERR_MSG(info,
6169 "invalid CPT config");
6170 GOTO(out, rc = -EINVAL);
6173 core = nla_get_s64(cpt);
6174 if (core >= LNET_CPT_NUMBER) {
6175 GENL_SET_ERR_MSG(info,
6176 "invalid CPT value");
6177 GOTO(out, rc = -ERANGE);
6180 conf->lic_cpts[conf->lic_ncpts] = core;
6186 if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
6187 if (nid_same(&nid, &LNET_ANY_NID) &&
6188 !strlen(conf->lic_ni_intf)) {
6189 GENL_SET_ERR_MSG(info,
6190 "interface / NID is missing");
6194 rc = lnet_dyn_add_ni(conf, net_id, &nid, tun);
6197 GENL_SET_ERR_MSG(info,
6198 "cannot parse net");
6201 GENL_SET_ERR_MSG(info,
6205 GENL_SET_ERR_MSG(info,
6206 "cannot add LNet NI");
6210 } else if (info->nlhdr->nlmsg_flags & NLM_F_REPLACE && healthv != -1) {
6211 lnet_ni_set_healthv(&nid, healthv);
6212 } else if (!(info->nlhdr->nlmsg_flags & (NLM_F_CREATE | NLM_F_REPLACE))) {
6217 if (!strlen(conf->lic_ni_intf) &&
6218 nid_same(&nid, &LNET_ANY_NID)) {
6219 GENL_SET_ERR_MSG(info,
6220 "interface / NID is missing");
6224 if (nid_same(&nid, &LNET_ANY_NID)) {
6225 struct lnet_net *net;
6228 lnet_net_lock(LNET_LOCK_EX);
6229 net = lnet_get_net_locked(net_id);
6231 GENL_SET_ERR_MSG(info,
6232 "LNet net doesn't exist");
6233 lnet_net_unlock(LNET_LOCK_EX);
6237 list_for_each_entry(ni, &net->net_ni_list,
6239 if (!ni->ni_interface ||
6240 strcmp(ni->ni_interface,
6241 conf->lic_ni_intf) != 0)
6245 lnet_net_unlock(LNET_LOCK_EX);
6246 rc = lnet_dyn_del_ni(&ni->ni_nid);
6250 if (rc < 0 && !found) { /* will be -ENODEV */
6251 GENL_SET_ERR_MSG(info,
6252 "interface invalid for deleting LNet NI");
6253 lnet_net_unlock(LNET_LOCK_EX);
6256 rc = lnet_dyn_del_ni(&nid);
6260 GENL_SET_ERR_MSG(info,
6261 "cannot del LNet NI");
6267 LIBCFS_FREE(tun, sizeof(struct lnet_ioctl_config_lnd_tunables));
6272 static int lnet_net_cmd(struct sk_buff *skb, struct genl_info *info)
6274 struct nlmsghdr *nlh = nlmsg_hdr(skb);
6275 struct genlmsghdr *gnlh = nlmsg_data(nlh);
6276 struct nlattr *params = genlmsg_data(gnlh);
6277 int msg_len, rem, rc = 0;
6278 struct nlattr *attr;
6280 msg_len = genlmsg_len(gnlh);
6282 GENL_SET_ERR_MSG(info, "no configuration");
6286 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
6287 GENL_SET_ERR_MSG(info, "invalid configuration");
6291 nla_for_each_nested(attr, params, rem) {
6292 bool ni_list = false, ipnets = false;
6293 struct lnet_ioctl_config_ni conf;
6294 u32 net_id = LNET_NET_ANY;
6295 struct nlattr *entry;
6298 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
6301 nla_for_each_nested(entry, attr, rem2) {
6302 switch (nla_type(entry)) {
6303 case LN_SCALAR_ATTR_VALUE: {
6306 memset(&conf, 0, sizeof(conf));
6307 if (nla_strcmp(entry, "ip2net") == 0) {
6308 entry = nla_next(entry, &rem2);
6309 if (nla_type(entry) !=
6310 LN_SCALAR_ATTR_VALUE) {
6311 GENL_SET_ERR_MSG(info,
6312 "ip2net has invalid key");
6313 GOTO(out, rc = -EINVAL);
6316 len = nla_strscpy(conf.lic_legacy_ip2nets,
6318 sizeof(conf.lic_legacy_ip2nets));
6320 GENL_SET_ERR_MSG(info,
6321 "ip2net key string is invalid");
6322 GOTO(out, rc = len);
6326 } else if (nla_strcmp(entry, "net type") == 0) {
6327 char tmp[LNET_NIDSTR_SIZE];
6329 entry = nla_next(entry, &rem2);
6330 if (nla_type(entry) !=
6331 LN_SCALAR_ATTR_VALUE) {
6332 GENL_SET_ERR_MSG(info,
6333 "net type has invalid key");
6334 GOTO(out, rc = -EINVAL);
6337 len = nla_strscpy(tmp, entry,
6340 GENL_SET_ERR_MSG(info,
6341 "net type key string is invalid");
6342 GOTO(out, rc = len);
6345 net_id = libcfs_str2net(tmp);
6347 GENL_SET_ERR_MSG(info,
6348 "cannot parse net");
6349 GOTO(out, rc = -ENODEV);
6351 if (LNET_NETTYP(net_id) == LOLND) {
6352 GENL_SET_ERR_MSG(info,
6353 "setting @lo not allowed");
6354 GOTO(out, rc = -ENODEV);
6356 conf.lic_legacy_ip2nets[0] = '\0';
6357 conf.lic_ni_intf[0] = '\0';
6364 case LN_SCALAR_ATTR_LIST: {
6365 struct nlattr *interface;
6369 nla_for_each_nested(interface, entry, rem3) {
6370 rc = lnet_genl_parse_local_ni(interface, info,
6378 /* it is possible a newer version of the user land send
6379 * values older kernels doesn't handle. So silently
6380 * ignore these values
6387 /* Handle case of just sent NET with no list of NIDs */
6388 if (!(info->nlhdr->nlmsg_flags & (NLM_F_CREATE | NLM_F_REPLACE)) &&
6390 rc = lnet_dyn_del_net(net_id);
6392 GENL_SET_ERR_MSG(info,
6393 "cannot del network");
6395 } else if ((info->nlhdr->nlmsg_flags & NLM_F_CREATE) &&
6396 ipnets && ni_list) {
6397 rc = lnet_handle_legacy_ip2nets(conf.lic_legacy_ip2nets,
6400 GENL_SET_ERR_MSG(info,
6401 "cannot setup ip2nets");
6408 /* Called with ln_api_mutex */
6409 static int lnet_parse_peer_nis(struct nlattr *rlist, struct genl_info *info,
6410 struct lnet_nid *pnid, bool mr,
6413 struct lnet_nid snid = LNET_ANY_NID;
6414 struct nlattr *props;
6418 nla_for_each_nested(props, rlist, rem) {
6419 if (nla_type(props) != LN_SCALAR_ATTR_VALUE)
6422 if (nla_strcmp(props, "nid") == 0) {
6423 char nidstr[LNET_NIDSTR_SIZE];
6425 props = nla_next(props, &rem);
6426 if (nla_type(props) != LN_SCALAR_ATTR_VALUE) {
6427 GENL_SET_ERR_MSG(info,
6428 "invalid secondary NID");
6429 GOTO(report_err, rc = -EINVAL);
6432 rc = nla_strscpy(nidstr, props, sizeof(nidstr));
6434 GENL_SET_ERR_MSG(info,
6435 "failed to get secondary NID");
6436 GOTO(report_err, rc);
6439 rc = libcfs_strnid(&snid, strim(nidstr));
6441 GENL_SET_ERR_MSG(info, "unsupported secondary NID");
6442 GOTO(report_err, rc);
6445 if (LNET_NID_IS_ANY(&snid) || nid_same(&snid, pnid))
6446 *create_some = false;
6447 } else if (nla_strcmp(props, "health stats") == 0) {
6448 struct nlattr *health;
6451 props = nla_next(props, &rem);
6452 if (nla_type(props) !=
6453 LN_SCALAR_ATTR_LIST) {
6454 GENL_SET_ERR_MSG(info,
6455 "invalid health configuration");
6456 GOTO(report_err, rc = -EINVAL);
6459 nla_for_each_nested(health, props, rem2) {
6460 if (nla_type(health) != LN_SCALAR_ATTR_VALUE ||
6461 nla_strcmp(health, "health value") != 0) {
6462 GENL_SET_ERR_MSG(info,
6463 "wrong health config format");
6464 GOTO(report_err, rc = -EINVAL);
6467 health = nla_next(health, &rem2);
6468 if (nla_type(health) !=
6469 LN_SCALAR_ATTR_INT_VALUE) {
6470 GENL_SET_ERR_MSG(info,
6471 "invalid health config format");
6472 GOTO(report_err, rc = -EINVAL);
6475 num = nla_get_s64(health);
6476 clamp_t(s64, num, 0, LNET_MAX_HEALTH_VALUE);
6481 if (info->nlhdr->nlmsg_flags & NLM_F_REPLACE && num != -1) {
6482 lnet_peer_ni_set_healthv(pnid, num, !*create_some);
6483 } else if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
6484 bool lock_prim = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6486 rc = lnet_user_add_peer_ni(pnid, &snid, mr, lock_prim);
6488 GENL_SET_ERR_MSG(info,
6489 "failed to add peer");
6490 } else if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE) && *create_some) {
6491 bool force = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6493 rc = lnet_del_peer_ni(pnid, &snid, force);
6495 GENL_SET_ERR_MSG(info,
6496 "failed to del peer");
6502 static int lnet_peer_ni_cmd(struct sk_buff *skb, struct genl_info *info)
6504 struct nlmsghdr *nlh = nlmsg_hdr(skb);
6505 struct genlmsghdr *gnlh = nlmsg_data(nlh);
6506 struct nlattr *params = genlmsg_data(gnlh);
6507 int msg_len, rem, rc = 0;
6508 struct lnet_nid pnid;
6509 struct nlattr *attr;
6511 mutex_lock(&the_lnet.ln_api_mutex);
6512 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
6513 GENL_SET_ERR_MSG(info, "Network is down");
6514 mutex_unlock(&the_lnet.ln_api_mutex);
6518 msg_len = genlmsg_len(gnlh);
6520 GENL_SET_ERR_MSG(info, "no configuration");
6521 mutex_unlock(&the_lnet.ln_api_mutex);
6525 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
6526 GENL_SET_ERR_MSG(info, "invalid configuration");
6527 mutex_unlock(&the_lnet.ln_api_mutex);
6531 nla_for_each_nested(attr, params, rem) {
6532 bool parse_peer_nis = false;
6533 struct nlattr *pnid_prop;
6536 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
6539 pnid = LNET_ANY_NID;
6540 nla_for_each_nested(pnid_prop, attr, rem2) {
6543 if (nla_type(pnid_prop) != LN_SCALAR_ATTR_VALUE)
6546 if (nla_strcmp(pnid_prop, "primary nid") == 0) {
6547 char nidstr[LNET_NIDSTR_SIZE];
6549 pnid_prop = nla_next(pnid_prop, &rem2);
6550 if (nla_type(pnid_prop) !=
6551 LN_SCALAR_ATTR_VALUE) {
6552 GENL_SET_ERR_MSG(info,
6553 "invalid primary NID type");
6554 GOTO(report_err, rc = -EINVAL);
6557 rc = nla_strscpy(nidstr, pnid_prop,
6560 GENL_SET_ERR_MSG(info,
6561 "failed to get primary NID");
6562 GOTO(report_err, rc);
6565 rc = libcfs_strnid(&pnid, strim(nidstr));
6567 GENL_SET_ERR_MSG(info,
6568 "unsupported primary NID");
6569 GOTO(report_err, rc);
6572 /* we must create primary NID for peer ni
6575 if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
6578 lock_prim = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6579 rc = lnet_user_add_peer_ni(&pnid,
6583 GENL_SET_ERR_MSG(info,
6584 "failed to add primary peer");
6585 GOTO(report_err, rc);
6588 } else if (nla_strcmp(pnid_prop, "Multi-Rail") == 0) {
6589 pnid_prop = nla_next(pnid_prop, &rem2);
6590 if (nla_type(pnid_prop) !=
6591 LN_SCALAR_ATTR_INT_VALUE) {
6592 GENL_SET_ERR_MSG(info,
6593 "invalid MR flag param");
6594 GOTO(report_err, rc = -EINVAL);
6597 if (nla_get_s64(pnid_prop) == 0)
6599 } else if (nla_strcmp(pnid_prop, "peer state") == 0) {
6600 struct lnet_peer_ni *lpni;
6601 struct lnet_peer *lp;
6603 pnid_prop = nla_next(pnid_prop, &rem2);
6604 if (nla_type(pnid_prop) !=
6605 LN_SCALAR_ATTR_INT_VALUE) {
6606 GENL_SET_ERR_MSG(info,
6607 "invalid peer state param");
6608 GOTO(report_err, rc = -EINVAL);
6611 lpni = lnet_peer_ni_find_locked(&pnid);
6613 GENL_SET_ERR_MSG(info,
6614 "invalid peer state param");
6615 GOTO(report_err, rc = -ENOENT);
6617 lnet_peer_ni_decref_locked(lpni);
6618 lp = lpni->lpni_peer_net->lpn_peer;
6619 lp->lp_state = nla_get_s64(pnid_prop);
6620 } else if (nla_strcmp(pnid_prop, "peer ni") == 0) {
6621 struct nlattr *rlist;
6624 if (!(info->nlhdr->nlmsg_flags & NLM_F_REPLACE) &&
6625 LNET_NID_IS_ANY(&pnid)) {
6626 GENL_SET_ERR_MSG(info,
6627 "missing required primary NID");
6628 GOTO(report_err, rc);
6631 pnid_prop = nla_next(pnid_prop, &rem2);
6632 if (nla_type(pnid_prop) !=
6633 LN_SCALAR_ATTR_LIST) {
6634 GENL_SET_ERR_MSG(info,
6635 "invalid NIDs list");
6636 GOTO(report_err, rc = -EINVAL);
6639 parse_peer_nis = true;
6640 nla_for_each_nested(rlist, pnid_prop, rem3) {
6641 rc = lnet_parse_peer_nis(rlist, info,
6645 GOTO(report_err, rc);
6650 /* If we have remote peer ni's we already add /del peers */
6654 if (LNET_NID_IS_ANY(&pnid)) {
6655 GENL_SET_ERR_MSG(info, "missing primary NID");
6656 GOTO(report_err, rc);
6659 if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE)) {
6660 bool force = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
6662 rc = lnet_del_peer_ni(&pnid, &LNET_ANY_NID,
6665 GENL_SET_ERR_MSG(info,
6666 "failed to del primary peer");
6667 GOTO(report_err, rc);
6672 /* If we failed on creation and encounter a latter error then
6673 * delete the primary nid.
6675 if (rc < 0 && info->nlhdr->nlmsg_flags & NLM_F_CREATE &&
6676 !LNET_NID_IS_ANY(&pnid))
6677 lnet_del_peer_ni(&pnid, &LNET_ANY_NID,
6678 info->nlhdr->nlmsg_flags & NLM_F_EXCL);
6679 mutex_unlock(&the_lnet.ln_api_mutex);
6684 /** LNet route handling */
6686 /* We can't use struct lnet_ioctl_config_data since it lacks
6687 * support for large NIDS
6689 struct lnet_route_properties {
6690 struct lnet_nid lrp_gateway;
6695 u32 lrp_sensitivity;
6698 struct lnet_genl_route_list {
6699 unsigned int lgrl_index;
6700 unsigned int lgrl_count;
6701 GENRADIX(struct lnet_route_properties) lgrl_list;
6704 static inline struct lnet_genl_route_list *
6705 lnet_route_dump_ctx(struct netlink_callback *cb)
6707 return (struct lnet_genl_route_list *)cb->args[0];
6710 static int lnet_route_show_done(struct netlink_callback *cb)
6712 struct lnet_genl_route_list *rlist = lnet_route_dump_ctx(cb);
6715 genradix_free(&rlist->lgrl_list);
6716 CFS_FREE_PTR(rlist);
6723 static int lnet_scan_route(struct lnet_genl_route_list *rlist,
6724 struct lnet_route_properties *settings)
6726 struct lnet_remotenet *rnet;
6727 struct list_head *rn_list;
6728 struct lnet_route *route;
6731 cpt = lnet_net_lock_current();
6733 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
6734 rn_list = &the_lnet.ln_remote_nets_hash[i];
6735 list_for_each_entry(rnet, rn_list, lrn_list) {
6736 if (settings->lrp_net != LNET_NET_ANY &&
6737 settings->lrp_net != rnet->lrn_net)
6740 list_for_each_entry(route, &rnet->lrn_routes,
6742 struct lnet_route_properties *prop;
6744 if (!LNET_NID_IS_ANY(&settings->lrp_gateway) &&
6745 !nid_same(&settings->lrp_gateway,
6750 if (settings->lrp_hop != -1 &&
6751 settings->lrp_hop != route->lr_hops)
6754 if (settings->lrp_priority != -1 &&
6755 settings->lrp_priority != route->lr_priority)
6758 if (settings->lrp_sensitivity != -1 &&
6759 settings->lrp_sensitivity !=
6760 route->lr_gateway->lp_health_sensitivity)
6763 prop = genradix_ptr_alloc(&rlist->lgrl_list,
6764 rlist->lgrl_count++,
6767 GOTO(failed_alloc, rc = -ENOMEM);
6769 prop->lrp_net = rnet->lrn_net;
6770 prop->lrp_gateway = route->lr_nid;
6771 prop->lrp_hop = route->lr_hops;
6772 prop->lrp_priority = route->lr_priority;
6773 prop->lrp_sensitivity =
6774 route->lr_gateway->lp_health_sensitivity;
6775 if (lnet_is_route_alive(route))
6776 prop->lrp_flags |= LNET_RT_ALIVE;
6778 prop->lrp_flags &= ~LNET_RT_ALIVE;
6779 if (route->lr_single_hop)
6780 prop->lrp_flags &= ~LNET_RT_MULTI_HOP;
6782 prop->lrp_flags |= LNET_RT_MULTI_HOP;
6788 lnet_net_unlock(cpt);
6792 /* LNet route ->start() handler for GET requests */
6793 static int lnet_route_show_start(struct netlink_callback *cb)
6795 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
6796 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
6797 struct netlink_ext_ack *extack = NULL;
6799 struct lnet_genl_route_list *rlist;
6800 int msg_len = genlmsg_len(gnlh);
6803 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
6804 extack = cb->extack;
6806 if (the_lnet.ln_refcount == 0 ||
6807 the_lnet.ln_state != LNET_STATE_RUNNING) {
6808 NL_SET_ERR_MSG(extack, "Network is down");
6812 CFS_ALLOC_PTR(rlist);
6814 NL_SET_ERR_MSG(extack, "No memory for route list");
6818 genradix_init(&rlist->lgrl_list);
6819 rlist->lgrl_count = 0;
6820 rlist->lgrl_index = 0;
6821 cb->args[0] = (long)rlist;
6823 mutex_lock(&the_lnet.ln_api_mutex);
6825 struct lnet_route_properties tmp = {
6826 .lrp_gateway = LNET_ANY_NID,
6827 .lrp_net = LNET_NET_ANY,
6830 .lrp_sensitivity = -1,
6833 rc = lnet_scan_route(rlist, &tmp);
6835 NL_SET_ERR_MSG(extack,
6836 "failed to allocate router data");
6837 GOTO(report_err, rc);
6840 struct nlattr *params = genlmsg_data(gnlh);
6841 struct nlattr *attr;
6844 nla_for_each_nested(attr, params, rem) {
6845 struct lnet_route_properties tmp = {
6846 .lrp_gateway = LNET_ANY_NID,
6847 .lrp_net = LNET_NET_ANY,
6850 .lrp_sensitivity = -1,
6852 struct nlattr *route;
6855 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
6858 nla_for_each_nested(route, attr, rem2) {
6859 if (nla_type(route) != LN_SCALAR_ATTR_VALUE)
6862 if (nla_strcmp(route, "net") == 0) {
6863 char nw[LNET_NIDSTR_SIZE];
6865 route = nla_next(route, &rem2);
6866 if (nla_type(route) !=
6867 LN_SCALAR_ATTR_VALUE) {
6868 NL_SET_ERR_MSG(extack,
6869 "invalid net param");
6870 GOTO(report_err, rc = -EINVAL);
6873 rc = nla_strscpy(nw, route, sizeof(nw));
6875 NL_SET_ERR_MSG(extack,
6876 "failed to get route param");
6877 GOTO(report_err, rc);
6880 tmp.lrp_net = libcfs_str2net(strim(nw));
6881 } else if (nla_strcmp(route, "gateway") == 0) {
6882 char gw[LNET_NIDSTR_SIZE];
6884 route = nla_next(route, &rem2);
6885 if (nla_type(route) !=
6886 LN_SCALAR_ATTR_VALUE) {
6887 NL_SET_ERR_MSG(extack,
6888 "invalid gateway param");
6889 GOTO(report_err, rc = -EINVAL);
6892 rc = nla_strscpy(gw, route, sizeof(gw));
6894 NL_SET_ERR_MSG(extack,
6895 "failed to get route param");
6896 GOTO(report_err, rc);
6899 rc = libcfs_strnid(&tmp.lrp_gateway, strim(gw));
6901 NL_SET_ERR_MSG(extack,
6902 "cannot parse gateway");
6903 GOTO(report_err, rc = -ENODEV);
6906 } else if (nla_strcmp(route, "hop") == 0) {
6907 route = nla_next(route, &rem2);
6908 if (nla_type(route) !=
6909 LN_SCALAR_ATTR_INT_VALUE) {
6910 NL_SET_ERR_MSG(extack,
6911 "invalid hop param");
6912 GOTO(report_err, rc = -EINVAL);
6915 tmp.lrp_hop = nla_get_s64(route);
6916 if (tmp.lrp_hop != -1)
6917 clamp_t(s32, tmp.lrp_hop, 1, 127);
6918 } else if (nla_strcmp(route, "priority") == 0) {
6919 route = nla_next(route, &rem2);
6920 if (nla_type(route) !=
6921 LN_SCALAR_ATTR_INT_VALUE) {
6922 NL_SET_ERR_MSG(extack,
6923 "invalid priority param");
6924 GOTO(report_err, rc = -EINVAL);
6927 tmp.lrp_priority = nla_get_s64(route);
6931 rc = lnet_scan_route(rlist, &tmp);
6933 NL_SET_ERR_MSG(extack,
6934 "failed to allocate router data");
6935 GOTO(report_err, rc);
6940 mutex_unlock(&the_lnet.ln_api_mutex);
6943 lnet_route_show_done(cb);
6948 static const struct ln_key_list route_props_list = {
6949 .lkl_maxattr = LNET_ROUTE_ATTR_MAX,
6951 [LNET_ROUTE_ATTR_HDR] = {
6952 .lkp_value = "route",
6953 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
6954 .lkp_data_type = NLA_NUL_STRING,
6956 [LNET_ROUTE_ATTR_NET] = {
6958 .lkp_data_type = NLA_STRING
6960 [LNET_ROUTE_ATTR_GATEWAY] = {
6961 .lkp_value = "gateway",
6962 .lkp_data_type = NLA_STRING
6964 [LNET_ROUTE_ATTR_HOP] = {
6966 .lkp_data_type = NLA_S32
6968 [LNET_ROUTE_ATTR_PRIORITY] = {
6969 .lkp_value = "priority",
6970 .lkp_data_type = NLA_U32
6972 [LNET_ROUTE_ATTR_HEALTH_SENSITIVITY] = {
6973 .lkp_value = "health_sensitivity",
6974 .lkp_data_type = NLA_U32
6976 [LNET_ROUTE_ATTR_STATE] = {
6977 .lkp_value = "state",
6978 .lkp_data_type = NLA_STRING,
6980 [LNET_ROUTE_ATTR_TYPE] = {
6981 .lkp_value = "type",
6982 .lkp_data_type = NLA_STRING,
6988 static int lnet_route_show_dump(struct sk_buff *msg,
6989 struct netlink_callback *cb)
6991 struct lnet_genl_route_list *rlist = lnet_route_dump_ctx(cb);
6992 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
6993 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
6994 struct netlink_ext_ack *extack = NULL;
6996 int portid = NETLINK_CB(cb->skb).portid;
6997 int seq = cb->nlh->nlmsg_seq;
6998 int idx = rlist->lgrl_index;
6999 int msg_len = genlmsg_len(gnlh);
7002 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
7003 extack = cb->extack;
7005 if (!rlist->lgrl_count) {
7006 NL_SET_ERR_MSG(extack, "No routes found");
7007 GOTO(send_error, rc = msg_len ? -ENOENT : 0);
7011 const struct ln_key_list *all[] = {
7012 &route_props_list, NULL
7015 rc = lnet_genl_send_scalar_list(msg, portid, seq,
7017 NLM_F_CREATE | NLM_F_MULTI,
7018 LNET_CMD_ROUTES, all);
7020 NL_SET_ERR_MSG(extack, "failed to send key table");
7021 GOTO(send_error, rc);
7025 while (idx < rlist->lgrl_count) {
7026 struct lnet_route_properties *prop;
7029 prop = genradix_ptr(&rlist->lgrl_list, idx++);
7031 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
7032 NLM_F_MULTI, LNET_CMD_ROUTES);
7034 NL_SET_ERR_MSG(extack, "failed to send values");
7035 genlmsg_cancel(msg, hdr);
7036 GOTO(send_error, rc = -EMSGSIZE);
7040 nla_put_string(msg, LNET_ROUTE_ATTR_HDR, "");
7042 nla_put_string(msg, LNET_ROUTE_ATTR_NET,
7043 libcfs_net2str(prop->lrp_net));
7044 nla_put_string(msg, LNET_ROUTE_ATTR_GATEWAY,
7045 libcfs_nidstr(&prop->lrp_gateway));
7046 if (gnlh->version) {
7047 nla_put_s32(msg, LNET_ROUTE_ATTR_HOP, prop->lrp_hop);
7048 nla_put_u32(msg, LNET_ROUTE_ATTR_PRIORITY, prop->lrp_priority);
7049 nla_put_u32(msg, LNET_ROUTE_ATTR_HEALTH_SENSITIVITY,
7050 prop->lrp_sensitivity);
7052 if (!(cb->nlh->nlmsg_flags & NLM_F_DUMP_FILTERED)) {
7053 nla_put_string(msg, LNET_ROUTE_ATTR_STATE,
7054 prop->lrp_flags & LNET_RT_ALIVE ?
7056 nla_put_string(msg, LNET_ROUTE_ATTR_TYPE,
7057 prop->lrp_flags & LNET_RT_MULTI_HOP ?
7058 "multi-hop" : "single-hop");
7061 genlmsg_end(msg, hdr);
7063 rlist->lgrl_index = idx;
7065 return lnet_nl_send_error(cb->skb, portid, seq, rc);
7068 #ifndef HAVE_NETLINK_CALLBACK_START
7069 static int lnet_old_route_show_dump(struct sk_buff *msg,
7070 struct netlink_callback *cb)
7073 int rc = lnet_route_show_start(cb);
7076 return lnet_nl_send_error(cb->skb,
7077 NETLINK_CB(cb->skb).portid,
7082 return lnet_route_show_dump(msg, cb);
7084 #endif /* !HAVE_NETLINK_CALLBACK_START */
7086 /** LNet peer handling */
7087 struct lnet_genl_processid_list {
7088 unsigned int lgpl_index;
7089 unsigned int lgpl_count;
7090 GENRADIX(struct lnet_processid) lgpl_list;
7093 static inline struct lnet_genl_processid_list *
7094 lnet_peer_dump_ctx(struct netlink_callback *cb)
7096 return (struct lnet_genl_processid_list *)cb->args[0];
7099 static int lnet_peer_ni_show_done(struct netlink_callback *cb)
7101 struct lnet_genl_processid_list *plist = lnet_peer_dump_ctx(cb);
7104 genradix_free(&plist->lgpl_list);
7105 CFS_FREE_PTR(plist);
7112 /* LNet peer ->start() handler for GET requests */
7113 static int lnet_peer_ni_show_start(struct netlink_callback *cb)
7115 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
7116 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
7117 struct netlink_ext_ack *extack = NULL;
7119 struct lnet_genl_processid_list *plist;
7120 int msg_len = genlmsg_len(gnlh);
7123 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
7124 extack = cb->extack;
7126 mutex_lock(&the_lnet.ln_api_mutex);
7127 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
7128 NL_SET_ERR_MSG(extack, "Network is down");
7129 mutex_unlock(&the_lnet.ln_api_mutex);
7133 CFS_ALLOC_PTR(plist);
7135 NL_SET_ERR_MSG(extack, "No memory for peer list");
7136 mutex_unlock(&the_lnet.ln_api_mutex);
7140 genradix_init(&plist->lgpl_list);
7141 plist->lgpl_count = 0;
7142 plist->lgpl_index = 0;
7143 cb->args[0] = (long)plist;
7146 struct lnet_peer_table *ptable;
7149 cfs_percpt_for_each(ptable, cpt, the_lnet.ln_peer_tables) {
7150 struct lnet_peer *lp;
7152 list_for_each_entry(lp, &ptable->pt_peer_list,
7154 struct lnet_processid *lpi;
7156 lpi = genradix_ptr_alloc(&plist->lgpl_list,
7157 plist->lgpl_count++,
7160 NL_SET_ERR_MSG(extack,
7161 "failed to allocate NID");
7162 GOTO(report_err, rc = -ENOMEM);
7165 lpi->pid = LNET_PID_LUSTRE;
7166 lpi->nid = lp->lp_primary_nid;
7170 struct nlattr *params = genlmsg_data(gnlh);
7171 struct nlattr *attr;
7174 nla_for_each_nested(attr, params, rem) {
7178 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
7181 nla_for_each_nested(nid, attr, rem2) {
7182 char addr[LNET_NIDSTR_SIZE];
7183 struct lnet_processid *id;
7185 if (nla_type(nid) != LN_SCALAR_ATTR_VALUE ||
7186 nla_strcmp(nid, "primary nid") != 0)
7189 nid = nla_next(nid, &rem2);
7190 if (nla_type(nid) != LN_SCALAR_ATTR_VALUE) {
7191 NL_SET_ERR_MSG(extack,
7192 "invalid primary nid param");
7193 GOTO(report_err, rc = -EINVAL);
7196 rc = nla_strscpy(addr, nid, sizeof(addr));
7198 NL_SET_ERR_MSG(extack,
7199 "failed to get primary nid param");
7200 GOTO(report_err, rc);
7203 id = genradix_ptr_alloc(&plist->lgpl_list,
7204 plist->lgpl_count++,
7207 NL_SET_ERR_MSG(extack, "failed to allocate NID");
7208 GOTO(report_err, rc = -ENOMEM);
7211 rc = libcfs_strid(id, strim(addr));
7213 NL_SET_ERR_MSG(extack, "invalid NID");
7214 GOTO(report_err, rc);
7221 mutex_unlock(&the_lnet.ln_api_mutex);
7224 lnet_peer_ni_show_done(cb);
7229 static const struct ln_key_list lnet_peer_ni_keys = {
7230 .lkl_maxattr = LNET_PEER_NI_ATTR_MAX,
7232 [LNET_PEER_NI_ATTR_HDR] = {
7233 .lkp_value = "peer",
7234 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
7235 .lkp_data_type = NLA_NUL_STRING,
7237 [LNET_PEER_NI_ATTR_PRIMARY_NID] = {
7238 .lkp_value = "primary nid",
7239 .lkp_data_type = NLA_STRING,
7241 [LNET_PEER_NI_ATTR_MULTIRAIL] = {
7242 .lkp_value = "Multi-Rail",
7243 .lkp_data_type = NLA_FLAG
7245 [LNET_PEER_NI_ATTR_STATE] = {
7246 .lkp_value = "peer state",
7247 .lkp_data_type = NLA_U32
7249 [LNET_PEER_NI_ATTR_PEER_NI_LIST] = {
7250 .lkp_value = "peer ni",
7251 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
7252 .lkp_data_type = NLA_NESTED,
7257 static const struct ln_key_list lnet_peer_ni_list = {
7258 .lkl_maxattr = LNET_PEER_NI_LIST_ATTR_MAX,
7260 [LNET_PEER_NI_LIST_ATTR_NID] = {
7262 .lkp_data_type = NLA_STRING,
7264 [LNET_PEER_NI_LIST_ATTR_UDSP_INFO] = {
7265 .lkp_value = "udsp info",
7266 .lkp_key_format = LNKF_MAPPING,
7267 .lkp_data_type = NLA_NESTED,
7269 [LNET_PEER_NI_LIST_ATTR_STATE] = {
7270 .lkp_value = "state",
7271 .lkp_data_type = NLA_STRING,
7273 [LNET_PEER_NI_LIST_ATTR_MAX_TX_CREDITS] = {
7274 .lkp_value = "max_ni_tx_credits",
7275 .lkp_data_type = NLA_U32,
7277 [LNET_PEER_NI_LIST_ATTR_CUR_TX_CREDITS] = {
7278 .lkp_value = "available_tx_credits",
7279 .lkp_data_type = NLA_U32,
7281 [LNET_PEER_NI_LIST_ATTR_MIN_TX_CREDITS] = {
7282 .lkp_value = "min_tx_credits",
7283 .lkp_data_type = NLA_U32,
7285 [LNET_PEER_NI_LIST_ATTR_QUEUE_BUF_COUNT] = {
7286 .lkp_value = "tx_q_num_of_buf",
7287 .lkp_data_type = NLA_U32,
7289 [LNET_PEER_NI_LIST_ATTR_CUR_RTR_CREDITS] = {
7290 .lkp_value = "available_rtr_credits",
7291 .lkp_data_type = NLA_U32,
7293 [LNET_PEER_NI_LIST_ATTR_MIN_RTR_CREDITS] = {
7294 .lkp_value = "min_rtr_credits",
7295 .lkp_data_type = NLA_U32,
7297 [LNET_PEER_NI_LIST_ATTR_REFCOUNT] = {
7298 .lkp_value = "refcount",
7299 .lkp_data_type = NLA_U32,
7301 [LNET_PEER_NI_LIST_ATTR_STATS_COUNT] = {
7302 .lkp_value = "statistics",
7303 .lkp_key_format = LNKF_MAPPING,
7304 .lkp_data_type = NLA_NESTED
7306 [LNET_PEER_NI_LIST_ATTR_SENT_STATS] = {
7307 .lkp_value = "sent_stats",
7308 .lkp_key_format = LNKF_MAPPING,
7309 .lkp_data_type = NLA_NESTED
7311 [LNET_PEER_NI_LIST_ATTR_RECV_STATS] = {
7312 .lkp_value = "received_stats",
7313 .lkp_key_format = LNKF_MAPPING,
7314 .lkp_data_type = NLA_NESTED
7316 [LNET_PEER_NI_LIST_ATTR_DROP_STATS] = {
7317 .lkp_value = "dropped_stats",
7318 .lkp_key_format = LNKF_MAPPING,
7319 .lkp_data_type = NLA_NESTED
7321 [LNET_PEER_NI_LIST_ATTR_HEALTH_STATS] = {
7322 .lkp_value = "health stats",
7323 .lkp_key_format = LNKF_MAPPING,
7324 .lkp_data_type = NLA_NESTED
7329 static const struct ln_key_list lnet_peer_ni_list_stats_count = {
7330 .lkl_maxattr = LNET_PEER_NI_LIST_STATS_COUNT_ATTR_MAX,
7332 [LNET_PEER_NI_LIST_STATS_COUNT_ATTR_SEND_COUNT] = {
7333 .lkp_value = "send_count",
7334 .lkp_data_type = NLA_U32,
7336 [LNET_PEER_NI_LIST_STATS_COUNT_ATTR_RECV_COUNT] = {
7337 .lkp_value = "recv_count",
7338 .lkp_data_type = NLA_U32,
7340 [LNET_PEER_NI_LIST_STATS_COUNT_ATTR_DROP_COUNT] = {
7341 .lkp_value = "drop_count",
7342 .lkp_data_type = NLA_U32,
7347 static const struct ln_key_list lnet_peer_ni_list_stats = {
7348 .lkl_maxattr = LNET_PEER_NI_LIST_STATS_ATTR_MAX,
7350 [LNET_PEER_NI_LIST_STATS_ATTR_PUT] = {
7352 .lkp_data_type = NLA_U32,
7354 [LNET_PEER_NI_LIST_STATS_ATTR_GET] = {
7356 .lkp_data_type = NLA_U32,
7358 [LNET_PEER_NI_LIST_STATS_ATTR_REPLY] = {
7359 .lkp_value = "reply",
7360 .lkp_data_type = NLA_U32,
7362 [LNET_PEER_NI_LIST_STATS_ATTR_ACK] = {
7364 .lkp_data_type = NLA_U32,
7366 [LNET_PEER_NI_LIST_STATS_ATTR_HELLO] = {
7367 .lkp_value = "hello",
7368 .lkp_data_type = NLA_U32,
7373 static const struct ln_key_list lnet_peer_ni_list_health = {
7374 .lkl_maxattr = LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_MAX,
7376 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_VALUE] = {
7377 .lkp_value = "health value",
7378 .lkp_data_type = NLA_S32,
7380 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_DROPPED] = {
7381 .lkp_value = "dropped",
7382 .lkp_data_type = NLA_U32,
7384 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_TIMEOUT] = {
7385 .lkp_value = "timeout",
7386 .lkp_data_type = NLA_U32,
7388 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_ERROR] = {
7389 .lkp_value = "error",
7390 .lkp_data_type = NLA_U32,
7392 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NETWORK_TIMEOUT] = {
7393 .lkp_value = "network timeout",
7394 .lkp_data_type = NLA_U32,
7396 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PING_COUNT] = {
7397 .lkp_value = "ping_count",
7398 .lkp_data_type = NLA_U32,
7400 [LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NEXT_PING] = {
7401 .lkp_value = "next_ping",
7402 .lkp_data_type = NLA_S64,
7407 static int lnet_peer_ni_show_dump(struct sk_buff *msg,
7408 struct netlink_callback *cb)
7410 struct lnet_genl_processid_list *plist = lnet_peer_dump_ctx(cb);
7411 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
7412 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
7413 struct netlink_ext_ack *extack = NULL;
7415 int portid = NETLINK_CB(cb->skb).portid;
7416 int seq = cb->nlh->nlmsg_seq;
7417 int idx = plist->lgpl_index;
7418 int msg_len = genlmsg_len(gnlh);
7421 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
7422 extack = cb->extack;
7424 if (!plist->lgpl_count) {
7425 NL_SET_ERR_MSG(extack, "No peers found");
7426 GOTO(send_error, rc = msg_len ? -ENOENT : 0);
7430 const struct ln_key_list *all[] = {
7431 &lnet_peer_ni_keys, &lnet_peer_ni_list,
7432 &udsp_info_list, &udsp_info_pref_nids_list,
7433 &udsp_info_pref_nids_list,
7434 &lnet_peer_ni_list_stats_count,
7435 &lnet_peer_ni_list_stats, /* send_stats */
7436 &lnet_peer_ni_list_stats, /* recv_stats */
7437 &lnet_peer_ni_list_stats, /* drop stats */
7438 &lnet_peer_ni_list_health,
7442 rc = lnet_genl_send_scalar_list(msg, portid, seq,
7444 NLM_F_CREATE | NLM_F_MULTI,
7445 LNET_CMD_PEERS, all);
7447 NL_SET_ERR_MSG(extack, "failed to send key table");
7448 GOTO(send_error, rc);
7452 mutex_lock(&the_lnet.ln_api_mutex);
7453 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
7454 NL_SET_ERR_MSG(extack, "Network is down");
7455 GOTO(unlock_api_mutex, rc = -ENETDOWN);
7458 while (idx < plist->lgpl_count) {
7459 struct lnet_processid *id;
7460 struct lnet_peer_ni *lpni = NULL;
7461 struct nlattr *nid_list;
7462 struct lnet_peer *lp;
7466 id = genradix_ptr(&plist->lgpl_list, idx++);
7467 if (nid_is_lo0(&id->nid))
7470 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
7471 NLM_F_MULTI, LNET_CMD_PEERS);
7473 NL_SET_ERR_MSG(extack, "failed to send values");
7474 genlmsg_cancel(msg, hdr);
7475 GOTO(unlock_api_mutex, rc = -EMSGSIZE);
7478 lp = lnet_find_peer(&id->nid);
7480 NL_SET_ERR_MSG(extack, "cannot find peer");
7481 GOTO(unlock_api_mutex, rc = -ENOENT);
7485 nla_put_string(msg, LNET_PEER_NI_ATTR_HDR, "");
7487 nla_put_string(msg, LNET_PEER_NI_ATTR_PRIMARY_NID,
7488 libcfs_nidstr(&lp->lp_primary_nid));
7489 if (lnet_peer_is_multi_rail(lp))
7490 nla_put_flag(msg, LNET_PEER_NI_ATTR_MULTIRAIL);
7492 if (gnlh->version >= 3)
7493 nla_put_u32(msg, LNET_PEER_NI_ATTR_STATE, lp->lp_state);
7495 nid_list = nla_nest_start(msg, LNET_PEER_NI_ATTR_PEER_NI_LIST);
7496 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL) {
7497 struct nlattr *peer_nid = nla_nest_start(msg, count++);
7499 nla_put_string(msg, LNET_PEER_NI_LIST_ATTR_NID,
7500 libcfs_nidstr(&lpni->lpni_nid));
7502 if (gnlh->version >= 4) {
7503 rc = lnet_udsp_info_send(msg,
7504 LNET_PEER_NI_LIST_ATTR_UDSP_INFO,
7505 &lpni->lpni_nid, true);
7507 lnet_peer_decref_locked(lp);
7508 NL_SET_ERR_MSG(extack,
7509 "failed to get UDSP info");
7510 GOTO(unlock_api_mutex, rc);
7514 if (cb->nlh->nlmsg_flags & NLM_F_DUMP_FILTERED)
7517 if (lnet_isrouter(lpni) ||
7518 lnet_peer_aliveness_enabled(lpni)) {
7519 nla_put_string(msg, LNET_PEER_NI_LIST_ATTR_STATE,
7520 lnet_is_peer_ni_alive(lpni) ?
7523 nla_put_string(msg, LNET_PEER_NI_LIST_ATTR_STATE,
7527 if (gnlh->version) {
7528 struct lnet_ioctl_element_msg_stats lpni_msg_stats;
7529 struct nlattr *send_stats_list, *send_stats;
7530 struct nlattr *recv_stats_list, *recv_stats;
7531 struct nlattr *drop_stats_list, *drop_stats;
7532 struct nlattr *health_list, *health_stats;
7533 struct lnet_ioctl_element_stats stats;
7534 struct nlattr *stats_attr, *ni_stats;
7537 LNET_PEER_NI_LIST_ATTR_MAX_TX_CREDITS,
7539 lpni->lpni_net->net_tunables.lct_peer_tx_credits : 0);
7541 LNET_PEER_NI_LIST_ATTR_CUR_TX_CREDITS,
7542 lpni->lpni_txcredits);
7544 LNET_PEER_NI_LIST_ATTR_MIN_TX_CREDITS,
7545 lpni->lpni_mintxcredits);
7547 LNET_PEER_NI_LIST_ATTR_QUEUE_BUF_COUNT,
7550 LNET_PEER_NI_LIST_ATTR_CUR_RTR_CREDITS,
7551 lpni->lpni_rtrcredits);
7553 LNET_PEER_NI_LIST_ATTR_MIN_RTR_CREDITS,
7554 lpni->lpni_minrtrcredits);
7556 LNET_PEER_NI_LIST_ATTR_REFCOUNT,
7557 kref_read(&lpni->lpni_kref));
7559 memset(&stats, 0, sizeof(stats));
7560 stats.iel_send_count = lnet_sum_stats(&lpni->lpni_stats,
7561 LNET_STATS_TYPE_SEND);
7562 stats.iel_recv_count = lnet_sum_stats(&lpni->lpni_stats,
7563 LNET_STATS_TYPE_RECV);
7564 stats.iel_drop_count = lnet_sum_stats(&lpni->lpni_stats,
7565 LNET_STATS_TYPE_DROP);
7567 stats_attr = nla_nest_start(msg,
7568 LNET_PEER_NI_LIST_ATTR_STATS_COUNT);
7569 ni_stats = nla_nest_start(msg, 0);
7571 LNET_PEER_NI_LIST_STATS_COUNT_ATTR_SEND_COUNT,
7572 stats.iel_send_count);
7574 LNET_PEER_NI_LIST_STATS_COUNT_ATTR_RECV_COUNT,
7575 stats.iel_recv_count);
7577 LNET_PEER_NI_LIST_STATS_COUNT_ATTR_DROP_COUNT,
7578 stats.iel_drop_count);
7579 nla_nest_end(msg, ni_stats);
7580 nla_nest_end(msg, stats_attr);
7582 if (gnlh->version < 2)
7583 goto skip_msg_stats;
7585 lnet_usr_translate_stats(&lpni_msg_stats, &lpni->lpni_stats);
7587 send_stats_list = nla_nest_start(msg,
7588 LNET_PEER_NI_LIST_ATTR_SENT_STATS);
7589 send_stats = nla_nest_start(msg, 0);
7591 LNET_PEER_NI_LIST_STATS_ATTR_PUT,
7592 lpni_msg_stats.im_send_stats.ico_put_count);
7594 LNET_PEER_NI_LIST_STATS_ATTR_GET,
7595 lpni_msg_stats.im_send_stats.ico_get_count);
7597 LNET_PEER_NI_LIST_STATS_ATTR_REPLY,
7598 lpni_msg_stats.im_send_stats.ico_reply_count);
7600 LNET_PEER_NI_LIST_STATS_ATTR_ACK,
7601 lpni_msg_stats.im_send_stats.ico_ack_count);
7603 LNET_PEER_NI_LIST_STATS_ATTR_HELLO,
7604 lpni_msg_stats.im_send_stats.ico_hello_count);
7605 nla_nest_end(msg, send_stats);
7606 nla_nest_end(msg, send_stats_list);
7608 recv_stats_list = nla_nest_start(msg,
7609 LNET_PEER_NI_LIST_ATTR_RECV_STATS);
7610 recv_stats = nla_nest_start(msg, 0);
7612 LNET_PEER_NI_LIST_STATS_ATTR_PUT,
7613 lpni_msg_stats.im_recv_stats.ico_put_count);
7615 LNET_PEER_NI_LIST_STATS_ATTR_GET,
7616 lpni_msg_stats.im_recv_stats.ico_get_count);
7618 LNET_PEER_NI_LIST_STATS_ATTR_REPLY,
7619 lpni_msg_stats.im_recv_stats.ico_reply_count);
7621 LNET_PEER_NI_LIST_STATS_ATTR_ACK,
7622 lpni_msg_stats.im_recv_stats.ico_ack_count);
7624 LNET_PEER_NI_LIST_STATS_ATTR_HELLO,
7625 lpni_msg_stats.im_recv_stats.ico_hello_count);
7626 nla_nest_end(msg, recv_stats);
7627 nla_nest_end(msg, recv_stats_list);
7629 drop_stats_list = nla_nest_start(msg,
7630 LNET_PEER_NI_LIST_ATTR_DROP_STATS);
7631 drop_stats = nla_nest_start(msg, 0);
7633 LNET_PEER_NI_LIST_STATS_ATTR_PUT,
7634 lpni_msg_stats.im_drop_stats.ico_put_count);
7636 LNET_PEER_NI_LIST_STATS_ATTR_GET,
7637 lpni_msg_stats.im_drop_stats.ico_get_count);
7639 LNET_PEER_NI_LIST_STATS_ATTR_REPLY,
7640 lpni_msg_stats.im_drop_stats.ico_reply_count);
7642 LNET_PEER_NI_LIST_STATS_ATTR_ACK,
7643 lpni_msg_stats.im_drop_stats.ico_ack_count);
7645 LNET_PEER_NI_LIST_STATS_ATTR_HELLO,
7646 lpni_msg_stats.im_drop_stats.ico_hello_count);
7647 nla_nest_end(msg, drop_stats);
7648 nla_nest_end(msg, drop_stats_list);
7650 health_list = nla_nest_start(msg,
7651 LNET_PEER_NI_LIST_ATTR_HEALTH_STATS);
7652 health_stats = nla_nest_start(msg, 0);
7654 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_VALUE,
7655 atomic_read(&lpni->lpni_healthv));
7657 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_DROPPED,
7658 atomic_read(&lpni->lpni_hstats.hlt_remote_dropped));
7660 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_TIMEOUT,
7661 atomic_read(&lpni->lpni_hstats.hlt_remote_timeout));
7663 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_ERROR,
7664 atomic_read(&lpni->lpni_hstats.hlt_remote_error));
7666 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NETWORK_TIMEOUT,
7667 atomic_read(&lpni->lpni_hstats.hlt_network_timeout));
7669 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PING_COUNT,
7670 lpni->lpni_ping_count);
7672 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NEXT_PING,
7673 lpni->lpni_next_ping,
7674 LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PAD);
7675 nla_nest_end(msg, health_stats);
7676 nla_nest_end(msg, health_list);
7679 nla_nest_end(msg, peer_nid);
7681 nla_nest_end(msg, nid_list);
7683 genlmsg_end(msg, hdr);
7684 lnet_peer_decref_locked(lp);
7686 plist->lgpl_index = idx;
7688 mutex_unlock(&the_lnet.ln_api_mutex);
7690 return lnet_nl_send_error(cb->skb, portid, seq, rc);
7693 #ifndef HAVE_NETLINK_CALLBACK_START
7694 static int lnet_old_peer_ni_show_dump(struct sk_buff *msg,
7695 struct netlink_callback *cb)
7698 int rc = lnet_peer_ni_show_start(cb);
7701 return lnet_nl_send_error(cb->skb,
7702 NETLINK_CB(cb->skb).portid,
7707 return lnet_peer_ni_show_dump(msg, cb);
7711 static int lnet_route_cmd(struct sk_buff *skb, struct genl_info *info)
7713 struct nlmsghdr *nlh = nlmsg_hdr(skb);
7714 struct genlmsghdr *gnlh = nlmsg_data(nlh);
7715 struct nlattr *params = genlmsg_data(gnlh);
7716 int msg_len, rem, rc = 0;
7717 struct nlattr *attr;
7719 mutex_lock(&the_lnet.ln_api_mutex);
7720 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
7721 GENL_SET_ERR_MSG(info, "Network is down");
7722 mutex_unlock(&the_lnet.ln_api_mutex);
7726 msg_len = genlmsg_len(gnlh);
7728 GENL_SET_ERR_MSG(info, "no configuration");
7729 mutex_unlock(&the_lnet.ln_api_mutex);
7733 if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
7734 GENL_SET_ERR_MSG(info, "invalid configuration");
7735 mutex_unlock(&the_lnet.ln_api_mutex);
7739 nla_for_each_nested(attr, params, rem) {
7740 u32 net_id = LNET_NET_ANY, hops = LNET_UNDEFINED_HOPS;
7741 u32 priority = 0, sensitivity = 1;
7742 struct lnet_nid gw_nid = LNET_ANY_NID;
7743 struct nlattr *route_prop;
7748 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
7751 nla_for_each_nested(route_prop, attr, rem2) {
7752 char tmp[LNET_NIDSTR_SIZE];
7756 if (nla_type(route_prop) != LN_SCALAR_ATTR_VALUE)
7759 if (nla_strcmp(route_prop, "net") == 0) {
7760 route_prop = nla_next(route_prop, &rem2);
7761 if (nla_type(route_prop) !=
7762 LN_SCALAR_ATTR_VALUE) {
7763 GENL_SET_ERR_MSG(info,
7764 "net is invalid key");
7765 GOTO(report_err, rc = -EINVAL);
7768 len = nla_strscpy(tmp, route_prop, sizeof(tmp));
7770 GENL_SET_ERR_MSG(info,
7771 "net key string is invalid");
7772 GOTO(report_err, rc = len);
7775 net_id = libcfs_str2net(tmp);
7777 GENL_SET_ERR_MSG(info,
7778 "cannot parse remote net");
7779 GOTO(report_err, rc = -ENODEV);
7782 if (LNET_NETTYP(net_id) == LOLND) {
7783 GENL_SET_ERR_MSG(info,
7784 "setting @lo not allowed");
7785 GOTO(report_err, rc = -EACCES);
7788 if (net_id == LNET_NET_ANY) {
7789 GENL_SET_ERR_MSG(info,
7790 "setting LNET_NET_ANY not allowed");
7791 GOTO(report_err, rc = -ENXIO);
7793 } else if (nla_strcmp(route_prop, "gateway") == 0) {
7794 route_prop = nla_next(route_prop, &rem2);
7795 if (nla_type(route_prop) !=
7796 LN_SCALAR_ATTR_VALUE) {
7797 GENL_SET_ERR_MSG(info,
7798 "gateway is invalid key");
7799 GOTO(report_err, rc = -EINVAL);
7802 len = nla_strscpy(tmp, route_prop, sizeof(tmp));
7804 GENL_SET_ERR_MSG(info,
7805 "gateway string is invalid");
7806 GOTO(report_err, rc = len);
7809 rc = libcfs_strnid(&gw_nid, strim(tmp));
7811 GENL_SET_ERR_MSG(info,
7812 "cannot parse gateway");
7813 GOTO(report_err, rc = -ENODEV);
7815 } else if (nla_strcmp(route_prop, "state") == 0) {
7816 route_prop = nla_next(route_prop, &rem2);
7817 if (nla_type(route_prop) !=
7818 LN_SCALAR_ATTR_VALUE) {
7819 GENL_SET_ERR_MSG(info,
7820 "state is invalid key");
7821 GOTO(report_err, rc = -EINVAL);
7824 if (nla_strcmp(route_prop, "down") == 0) {
7826 } else if (nla_strcmp(route_prop, "up") == 0) {
7829 GENL_SET_ERR_MSG(info,
7830 "status string bad value");
7831 GOTO(report_err, rc = -EINVAL);
7833 } else if (nla_strcmp(route_prop, "notify_time") == 0) {
7834 route_prop = nla_next(route_prop, &rem2);
7835 if (nla_type(route_prop) !=
7836 LN_SCALAR_ATTR_INT_VALUE) {
7837 GENL_SET_ERR_MSG(info,
7838 "notify_time is invalid key");
7839 GOTO(report_err, rc = -EINVAL);
7842 when = nla_get_s64(route_prop);
7843 if (ktime_get_real_seconds() < when) {
7844 GENL_SET_ERR_MSG(info,
7845 "notify_time is in the future");
7846 GOTO(report_err, rc = -EINVAL);
7848 } else if (nla_strcmp(route_prop, "hop") == 0) {
7849 route_prop = nla_next(route_prop, &rem2);
7850 if (nla_type(route_prop) !=
7851 LN_SCALAR_ATTR_INT_VALUE) {
7852 GENL_SET_ERR_MSG(info,
7853 "hop has invalid key");
7854 GOTO(report_err, rc = -EINVAL);
7857 hops = nla_get_s64(route_prop);
7858 if ((hops < 1 || hops > 255) && hops != -1) {
7859 GENL_SET_ERR_MSG(info,
7860 "invalid hop count must be between 1 and 255");
7861 GOTO(report_err, rc = -EINVAL);
7863 } else if (nla_strcmp(route_prop, "priority") == 0) {
7864 route_prop = nla_next(route_prop, &rem2);
7865 if (nla_type(route_prop) !=
7866 LN_SCALAR_ATTR_INT_VALUE) {
7867 GENL_SET_ERR_MSG(info,
7868 "priority has invalid key");
7869 GOTO(report_err, rc = -EINVAL);
7872 num = nla_get_s64(route_prop);
7874 GENL_SET_ERR_MSG(info,
7875 "invalid priority, must not be negative");
7876 GOTO(report_err, rc = -EINVAL);
7879 } else if (nla_strcmp(route_prop,
7880 "health_sensitivity") == 0) {
7881 route_prop = nla_next(route_prop, &rem2);
7882 if (nla_type(route_prop) !=
7883 LN_SCALAR_ATTR_INT_VALUE) {
7884 GENL_SET_ERR_MSG(info,
7885 "sensitivity has invalid key");
7886 GOTO(report_err, rc = -EINVAL);
7889 num = nla_get_s64(route_prop);
7891 GENL_SET_ERR_MSG(info,
7892 "invalid health sensitivity, must be 1 or greater");
7893 GOTO(report_err, rc = -EINVAL);
7899 if (net_id == LNET_NET_ANY) {
7900 GENL_SET_ERR_MSG(info,
7901 "missing mandatory parameter: network");
7902 GOTO(report_err, rc = -ENODEV);
7905 if (LNET_NID_IS_ANY(&gw_nid)) {
7906 GENL_SET_ERR_MSG(info,
7907 "missing mandatory parameter: gateway");
7908 GOTO(report_err, rc = -ENODEV);
7911 if (info->nlhdr->nlmsg_flags & NLM_F_REPLACE) {
7912 /* Convert the user-supplied real time to monotonic.
7913 * NB: "when" is always in the past
7915 when = ktime_get_seconds() -
7916 (ktime_get_real_seconds() - when);
7918 mutex_unlock(&the_lnet.ln_api_mutex);
7919 rc = lnet_notify(NULL, &gw_nid, alive, false, when);
7920 mutex_lock(&the_lnet.ln_api_mutex);
7922 GOTO(report_err, rc);
7923 else if (the_lnet.ln_state != LNET_STATE_RUNNING)
7924 GOTO(report_err, rc = -ENETDOWN);
7925 } else if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
7926 rc = lnet_add_route(net_id, hops, &gw_nid, priority,
7931 GENL_SET_ERR_MSG(info,
7932 "invalid settings for route creation");
7935 GENL_SET_ERR_MSG(info,
7936 "No interface configured on the same net as gateway");
7939 GENL_SET_ERR_MSG(info,
7943 GENL_SET_ERR_MSG(info,
7944 "Route already exists or the specified network is local");
7947 GENL_SET_ERR_MSG(info,
7948 "failed to create route");
7951 GOTO(report_err, rc);
7953 } else if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE)) {
7954 rc = lnet_del_route(net_id, &gw_nid);
7956 GENL_SET_ERR_MSG(info,
7957 "failed to delete route");
7958 GOTO(report_err, rc);
7963 mutex_unlock(&the_lnet.ln_api_mutex);
7968 static inline struct lnet_genl_ping_list *
7969 lnet_ping_dump_ctx(struct netlink_callback *cb)
7971 return (struct lnet_genl_ping_list *)cb->args[0];
7974 static int lnet_ping_show_done(struct netlink_callback *cb)
7976 struct lnet_genl_ping_list *plist = lnet_ping_dump_ctx(cb);
7979 genradix_free(&plist->lgpl_failed);
7980 genradix_free(&plist->lgpl_list);
7981 LIBCFS_FREE(plist, sizeof(*plist));
7988 /* LNet ping ->start() handler for GET requests */
7989 static int lnet_ping_show_start(struct netlink_callback *cb)
7991 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
7992 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
7993 struct netlink_ext_ack *extack = NULL;
7995 struct lnet_genl_ping_list *plist;
7996 int msg_len = genlmsg_len(gnlh);
7997 struct nlattr *params, *top;
8000 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
8001 extack = cb->extack;
8003 if (the_lnet.ln_refcount == 0) {
8004 NL_SET_ERR_MSG(extack, "Network is down");
8009 NL_SET_ERR_MSG(extack, "Ping needs NID targets");
8013 LIBCFS_ALLOC(plist, sizeof(*plist));
8015 NL_SET_ERR_MSG(extack, "failed to setup ping list");
8018 genradix_init(&plist->lgpl_list);
8019 plist->lgpl_timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
8020 plist->lgpl_src_nid = LNET_ANY_NID;
8021 plist->lgpl_index = 0;
8022 plist->lgpl_list_count = 0;
8023 cb->args[0] = (long)plist;
8025 params = genlmsg_data(gnlh);
8026 nla_for_each_attr(top, params, msg_len, rem) {
8027 struct nlattr *nids;
8030 switch (nla_type(top)) {
8031 case LN_SCALAR_ATTR_VALUE:
8032 if (nla_strcmp(top, "timeout") == 0) {
8035 top = nla_next(top, &rem);
8036 if (nla_type(top) != LN_SCALAR_ATTR_INT_VALUE) {
8037 NL_SET_ERR_MSG(extack,
8038 "invalid timeout param");
8039 GOTO(report_err, rc = -EINVAL);
8042 /* If timeout is negative then set default of
8045 timeout = nla_get_s64(top);
8047 timeout < (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
8048 plist->lgpl_timeout =
8049 nsecs_to_jiffies(timeout * NSEC_PER_MSEC);
8050 } else if (nla_strcmp(top, "source") == 0) {
8051 char nidstr[LNET_NIDSTR_SIZE + 1];
8053 top = nla_next(top, &rem);
8054 if (nla_type(top) != LN_SCALAR_ATTR_VALUE) {
8055 NL_SET_ERR_MSG(extack,
8056 "invalid source param");
8057 GOTO(report_err, rc = -EINVAL);
8060 rc = nla_strscpy(nidstr, top, sizeof(nidstr));
8062 NL_SET_ERR_MSG(extack,
8063 "failed to parse source nid");
8064 GOTO(report_err, rc);
8067 rc = libcfs_strnid(&plist->lgpl_src_nid,
8070 NL_SET_ERR_MSG(extack,
8071 "invalid source nid");
8072 GOTO(report_err, rc);
8077 case LN_SCALAR_ATTR_LIST:
8078 nla_for_each_nested(nids, top, rem2) {
8079 char nid[LNET_NIDSTR_SIZE + 1];
8080 struct lnet_processid *id;
8082 if (nla_type(nids) != LN_SCALAR_ATTR_VALUE)
8085 memset(nid, 0, sizeof(nid));
8086 rc = nla_strscpy(nid, nids, sizeof(nid));
8088 NL_SET_ERR_MSG(extack,
8089 "failed to get NID");
8090 GOTO(report_err, rc);
8093 id = genradix_ptr_alloc(&plist->lgpl_list,
8094 plist->lgpl_list_count++,
8097 NL_SET_ERR_MSG(extack,
8098 "failed to allocate NID");
8099 GOTO(report_err, rc = -ENOMEM);
8102 rc = libcfs_strid(id, strim(nid));
8104 NL_SET_ERR_MSG(extack, "cannot parse NID");
8105 GOTO(report_err, rc);
8116 lnet_ping_show_done(cb);
8121 static const struct ln_key_list ping_err_props_list = {
8122 .lkl_maxattr = LNET_ERR_ATTR_MAX,
8124 [LNET_ERR_ATTR_HDR] = {
8125 .lkp_value = "manage",
8126 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
8127 .lkp_data_type = NLA_NUL_STRING,
8129 [LNET_ERR_ATTR_TYPE] = {
8130 .lkp_value = "ping",
8131 .lkp_data_type = NLA_STRING,
8133 [LNET_ERR_ATTR_ERRNO] = {
8134 .lkp_value = "errno",
8135 .lkp_data_type = NLA_S16,
8137 [LNET_ERR_ATTR_DESCR] = {
8138 .lkp_value = "descr",
8139 .lkp_data_type = NLA_STRING,
8144 static const struct ln_key_list ping_props_list = {
8145 .lkl_maxattr = LNET_PING_ATTR_MAX,
8147 [LNET_PING_ATTR_HDR] = {
8148 .lkp_value = "ping",
8149 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
8150 .lkp_data_type = NLA_NUL_STRING,
8152 [LNET_PING_ATTR_PRIMARY_NID] = {
8153 .lkp_value = "primary nid",
8154 .lkp_data_type = NLA_STRING
8156 [LNET_PING_ATTR_ERRNO] = {
8157 .lkp_value = "errno",
8158 .lkp_data_type = NLA_S16
8160 [LNET_PING_ATTR_MULTIRAIL] = {
8161 .lkp_value = "Multi-Rail",
8162 .lkp_data_type = NLA_FLAG
8164 [LNET_PING_ATTR_PEER_NI_LIST] = {
8165 .lkp_value = "peer_ni",
8166 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
8167 .lkp_data_type = NLA_NESTED
8172 static const struct ln_key_list ping_peer_ni_list = {
8173 .lkl_maxattr = LNET_PING_PEER_NI_ATTR_MAX,
8175 [LNET_PING_PEER_NI_ATTR_NID] = {
8177 .lkp_data_type = NLA_STRING
8182 static int lnet_ping_show_dump(struct sk_buff *msg,
8183 struct netlink_callback *cb)
8185 struct lnet_genl_ping_list *plist = lnet_ping_dump_ctx(cb);
8186 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
8187 struct netlink_ext_ack *extack = NULL;
8189 int portid = NETLINK_CB(cb->skb).portid;
8190 int seq = cb->nlh->nlmsg_seq;
8191 int idx = plist->lgpl_index;
8194 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
8195 extack = cb->extack;
8197 if (!plist->lgpl_index) {
8198 const struct ln_key_list *all[] = {
8199 &ping_props_list, &ping_peer_ni_list, NULL
8202 rc = lnet_genl_send_scalar_list(msg, portid, seq,
8204 NLM_F_CREATE | NLM_F_MULTI,
8205 LNET_CMD_PING, all);
8207 NL_SET_ERR_MSG(extack, "failed to send key table");
8208 GOTO(send_error, rc);
8211 genradix_init(&plist->lgpl_failed);
8214 while (idx < plist->lgpl_list_count) {
8215 struct lnet_nid primary_nid = LNET_ANY_NID;
8216 struct lnet_genl_ping_list peers;
8217 struct lnet_processid *id;
8218 struct nlattr *nid_list;
8219 struct lnet_peer *lp;
8220 bool mr_flag = false;
8224 id = genradix_ptr(&plist->lgpl_list, idx++);
8226 rc = lnet_ping(id, &plist->lgpl_src_nid, plist->lgpl_timeout,
8227 &peers, lnet_interfaces_max);
8229 struct lnet_fail_ping *fail;
8231 fail = genradix_ptr_alloc(&plist->lgpl_failed,
8232 plist->lgpl_failed_count++,
8235 NL_SET_ERR_MSG(extack,
8236 "failed to allocate failed NID");
8237 GOTO(send_error, rc);
8239 memset(fail->lfp_msg, '\0', sizeof(fail->lfp_msg));
8240 snprintf(fail->lfp_msg, sizeof(fail->lfp_msg),
8241 "failed to ping %s",
8242 libcfs_nidstr(&id->nid));
8244 fail->lfp_errno = rc;
8248 mutex_lock(&the_lnet.ln_api_mutex);
8249 lp = lnet_find_peer(&id->nid);
8251 primary_nid = lp->lp_primary_nid;
8252 mr_flag = lnet_peer_is_multi_rail(lp);
8253 lnet_peer_decref_locked(lp);
8255 mutex_unlock(&the_lnet.ln_api_mutex);
8257 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
8258 NLM_F_MULTI, LNET_CMD_PING);
8260 NL_SET_ERR_MSG(extack, "failed to send values");
8261 genlmsg_cancel(msg, hdr);
8262 GOTO(send_error, rc = -EMSGSIZE);
8266 nla_put_string(msg, LNET_PING_ATTR_HDR, "");
8268 nla_put_string(msg, LNET_PING_ATTR_PRIMARY_NID,
8269 libcfs_nidstr(&primary_nid));
8271 nla_put_flag(msg, LNET_PING_ATTR_MULTIRAIL);
8273 nid_list = nla_nest_start(msg, LNET_PING_ATTR_PEER_NI_LIST);
8274 for (count = 0; count < rc; count++) {
8275 struct lnet_processid *result;
8276 struct nlattr *nid_attr;
8279 result = genradix_ptr(&peers.lgpl_list, count);
8280 if (nid_is_lo0(&result->nid))
8283 nid_attr = nla_nest_start(msg, count + 1);
8284 if (id->pid == LNET_PID_LUSTRE)
8285 idstr = libcfs_nidstr(&result->nid);
8287 idstr = libcfs_idstr(result);
8288 nla_put_string(msg, LNET_PING_PEER_NI_ATTR_NID, idstr);
8289 nla_nest_end(msg, nid_attr);
8291 nla_nest_end(msg, nid_list);
8292 genlmsg_end(msg, hdr);
8294 genradix_free(&peers.lgpl_list);
8297 if (plist->lgpl_failed_count) {
8298 int flags = NLM_F_CREATE | NLM_F_REPLACE | NLM_F_MULTI;
8299 const struct ln_key_list *fail[] = {
8300 &ping_err_props_list, NULL
8303 rc = lnet_genl_send_scalar_list(msg, portid, seq, &lnet_family,
8304 flags, LNET_CMD_PING, fail);
8306 NL_SET_ERR_MSG(extack,
8307 "failed to send new key table");
8308 GOTO(send_error, rc);
8311 for (i = 0; i < plist->lgpl_failed_count; i++) {
8312 struct lnet_fail_ping *fail;
8315 fail = genradix_ptr(&plist->lgpl_failed, i);
8317 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
8318 NLM_F_MULTI, LNET_CMD_PING);
8320 NL_SET_ERR_MSG(extack,
8321 "failed to send failed values");
8322 genlmsg_cancel(msg, hdr);
8323 GOTO(send_error, rc = -EMSGSIZE);
8327 nla_put_string(msg, LNET_ERR_ATTR_HDR, "");
8329 nla_put_string(msg, LNET_ERR_ATTR_TYPE, "\n");
8330 nla_put_s16(msg, LNET_ERR_ATTR_ERRNO,
8332 nla_put_string(msg, LNET_ERR_ATTR_DESCR,
8334 genlmsg_end(msg, hdr);
8337 genradix_free(&plist->lgpl_list);
8338 rc = 0; /* don't treat it as an error */
8340 plist->lgpl_index = idx;
8342 return lnet_nl_send_error(cb->skb, portid, seq, rc);
8345 #ifndef HAVE_NETLINK_CALLBACK_START
8346 static int lnet_old_ping_show_dump(struct sk_buff *msg,
8347 struct netlink_callback *cb)
8350 int rc = lnet_ping_show_start(cb);
8353 return lnet_nl_send_error(cb->skb,
8354 NETLINK_CB(cb->skb).portid,
8359 return lnet_ping_show_dump(msg, cb);
8363 static const struct ln_key_list discover_err_props_list = {
8364 .lkl_maxattr = LNET_ERR_ATTR_MAX,
8366 [LNET_ERR_ATTR_HDR] = {
8367 .lkp_value = "manage",
8368 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
8369 .lkp_data_type = NLA_NUL_STRING,
8371 [LNET_ERR_ATTR_TYPE] = {
8372 .lkp_value = "discover",
8373 .lkp_data_type = NLA_STRING,
8375 [LNET_ERR_ATTR_ERRNO] = {
8376 .lkp_value = "errno",
8377 .lkp_data_type = NLA_S16,
8379 [LNET_ERR_ATTR_DESCR] = {
8380 .lkp_value = "descr",
8381 .lkp_data_type = NLA_STRING,
8386 static const struct ln_key_list discover_props_list = {
8387 .lkl_maxattr = LNET_PING_ATTR_MAX,
8389 [LNET_PING_ATTR_HDR] = {
8390 .lkp_value = "discover",
8391 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
8392 .lkp_data_type = NLA_NUL_STRING,
8394 [LNET_PING_ATTR_PRIMARY_NID] = {
8395 .lkp_value = "primary nid",
8396 .lkp_data_type = NLA_STRING
8398 [LNET_PING_ATTR_ERRNO] = {
8399 .lkp_value = "errno",
8400 .lkp_data_type = NLA_S16
8402 [LNET_PING_ATTR_MULTIRAIL] = {
8403 .lkp_value = "Multi-Rail",
8404 .lkp_data_type = NLA_FLAG
8406 [LNET_PING_ATTR_PEER_NI_LIST] = {
8407 .lkp_value = "peer_ni",
8408 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
8409 .lkp_data_type = NLA_NESTED
8414 static int lnet_ping_cmd(struct sk_buff *skb, struct genl_info *info)
8416 const struct ln_key_list *all[] = {
8417 &discover_props_list, &ping_peer_ni_list, NULL
8419 struct nlmsghdr *nlh = nlmsg_hdr(skb);
8420 struct genlmsghdr *gnlh = nlmsg_data(nlh);
8421 struct nlattr *params = genlmsg_data(gnlh);
8422 struct lnet_genl_ping_list dlists;
8423 int msg_len, rem, rc = 0, i;
8424 bool clear_hdr = false;
8425 struct sk_buff *reply;
8426 struct nlattr *attr;
8429 msg_len = genlmsg_len(gnlh);
8431 GENL_SET_ERR_MSG(info, "no configuration");
8435 if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE)) {
8436 GENL_SET_ERR_MSG(info, "only NLM_F_CREATE setting is allowed");
8440 reply = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
8442 GENL_SET_ERR_MSG(info,
8443 "fail to allocate reply");
8447 genradix_init(&dlists.lgpl_failed);
8448 dlists.lgpl_failed_count = 0;
8449 genradix_init(&dlists.lgpl_list);
8450 dlists.lgpl_list_count = 0;
8452 rc = lnet_genl_send_scalar_list(reply, info->snd_portid,
8453 info->snd_seq, &lnet_family,
8454 NLM_F_CREATE | NLM_F_MULTI,
8455 LNET_CMD_PING, all);
8457 GENL_SET_ERR_MSG(info,
8458 "failed to send key table");
8459 GOTO(report_err, rc);
8462 nla_for_each_attr(attr, params, msg_len, rem) {
8463 struct nlattr *nids;
8466 /* We only care about the NID list to discover with */
8467 if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
8470 nla_for_each_nested(nids, attr, rem2) {
8471 char nid[LNET_NIDSTR_SIZE + 1];
8472 struct lnet_processid id;
8473 struct nlattr *nid_list;
8474 struct lnet_peer *lp;
8477 if (nla_type(nids) != LN_SCALAR_ATTR_VALUE)
8480 memset(nid, 0, sizeof(nid));
8481 rc = nla_strscpy(nid, nids, sizeof(nid));
8483 GENL_SET_ERR_MSG(info,
8484 "failed to get NID");
8485 GOTO(report_err, rc);
8488 len = libcfs_strid(&id, strim(nid));
8490 struct lnet_fail_ping *fail;
8492 fail = genradix_ptr_alloc(&dlists.lgpl_failed,
8493 dlists.lgpl_failed_count++,
8496 GENL_SET_ERR_MSG(info,
8497 "failed to allocate improper NID");
8498 GOTO(report_err, rc = -ENOMEM);
8500 memset(fail->lfp_msg, '\0', sizeof(fail->lfp_msg));
8501 snprintf(fail->lfp_msg, sizeof(fail->lfp_msg),
8502 "cannot parse NID '%s'", strim(nid));
8504 fail->lfp_errno = len;
8508 if (LNET_NID_IS_ANY(&id.nid))
8511 rc = lnet_discover(&id,
8512 info->nlhdr->nlmsg_flags & NLM_F_EXCL,
8515 struct lnet_fail_ping *fail;
8517 fail = genradix_ptr_alloc(&dlists.lgpl_failed,
8518 dlists.lgpl_failed_count++,
8521 GENL_SET_ERR_MSG(info,
8522 "failed to allocate failed NID");
8523 GOTO(report_err, rc = -ENOMEM);
8525 memset(fail->lfp_msg, '\0', sizeof(fail->lfp_msg));
8526 snprintf(fail->lfp_msg, sizeof(fail->lfp_msg),
8527 "failed to discover %s",
8528 libcfs_nidstr(&id.nid));
8530 fail->lfp_errno = rc;
8534 /* create the genetlink message header */
8535 hdr = genlmsg_put(reply, info->snd_portid, info->snd_seq,
8536 &lnet_family, NLM_F_MULTI, LNET_CMD_PING);
8538 GENL_SET_ERR_MSG(info,
8539 "failed to allocate hdr");
8540 GOTO(report_err, rc = -ENOMEM);
8544 nla_put_string(reply, LNET_PING_ATTR_HDR, "");
8548 lp = lnet_find_peer(&id.nid);
8550 nla_put_string(reply, LNET_PING_ATTR_PRIMARY_NID,
8551 libcfs_nidstr(&lp->lp_primary_nid));
8552 if (lnet_peer_is_multi_rail(lp))
8553 nla_put_flag(reply, LNET_PING_ATTR_MULTIRAIL);
8554 lnet_peer_decref_locked(lp);
8557 nid_list = nla_nest_start(reply, LNET_PING_ATTR_PEER_NI_LIST);
8558 for (i = 0; i < dlists.lgpl_list_count; i++) {
8559 struct lnet_processid *found;
8560 struct nlattr *nid_attr;
8563 found = genradix_ptr(&dlists.lgpl_list, i);
8564 if (nid_is_lo0(&found->nid))
8567 nid_attr = nla_nest_start(reply, i + 1);
8568 if (id.pid == LNET_PID_LUSTRE)
8569 idstr = libcfs_nidstr(&found->nid);
8571 idstr = libcfs_idstr(found);
8572 nla_put_string(reply, LNET_PING_PEER_NI_ATTR_NID, idstr);
8573 nla_nest_end(reply, nid_attr);
8575 nla_nest_end(reply, nid_list);
8577 genlmsg_end(reply, hdr);
8581 if (dlists.lgpl_failed_count) {
8582 int flags = NLM_F_CREATE | NLM_F_REPLACE | NLM_F_MULTI;
8583 const struct ln_key_list *fail[] = {
8584 &discover_err_props_list, NULL
8587 rc = lnet_genl_send_scalar_list(reply, info->snd_portid,
8588 info->snd_seq, &lnet_family,
8589 flags, LNET_CMD_PING, fail);
8591 GENL_SET_ERR_MSG(info,
8592 "failed to send new key table");
8593 GOTO(report_err, rc);
8596 for (i = 0; i < dlists.lgpl_failed_count; i++) {
8597 struct lnet_fail_ping *fail;
8599 hdr = genlmsg_put(reply, info->snd_portid, info->snd_seq,
8600 &lnet_family, NLM_F_MULTI, LNET_CMD_PING);
8602 GENL_SET_ERR_MSG(info,
8603 "failed to send failed values");
8604 GOTO(report_err, rc = -ENOMSG);
8607 fail = genradix_ptr(&dlists.lgpl_failed, i);
8609 nla_put_string(reply, LNET_ERR_ATTR_HDR, "");
8611 nla_put_string(reply, LNET_ERR_ATTR_TYPE, "\n");
8612 nla_put_s16(reply, LNET_ERR_ATTR_ERRNO,
8614 nla_put_string(reply, LNET_ERR_ATTR_DESCR,
8616 genlmsg_end(reply, hdr);
8620 nlh = nlmsg_put(reply, info->snd_portid, info->snd_seq, NLMSG_DONE, 0,
8623 genlmsg_cancel(reply, hdr);
8624 GENL_SET_ERR_MSG(info,
8625 "failed to finish message");
8626 GOTO(report_err, rc = -EMSGSIZE);
8630 genradix_free(&dlists.lgpl_failed);
8631 genradix_free(&dlists.lgpl_list);
8634 genlmsg_cancel(reply, hdr);
8637 rc = genlmsg_reply(reply, info);
8643 #define lnet_peer_dist_show_done lnet_peer_ni_show_done
8645 static int lnet_peer_dist_show_start(struct netlink_callback *cb)
8647 struct genlmsghdr *gnlh = nlmsg_data(cb->nlh);
8648 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
8649 struct netlink_ext_ack *extack = NULL;
8651 struct lnet_genl_processid_list *plist;
8652 int msg_len = genlmsg_len(gnlh);
8653 struct nlattr *params, *top;
8656 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
8657 extack = cb->extack;
8659 mutex_lock(&the_lnet.ln_api_mutex);
8660 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
8661 NL_SET_ERR_MSG(extack, "Network is down");
8662 mutex_unlock(&the_lnet.ln_api_mutex);
8666 msg_len = genlmsg_len(gnlh);
8668 NL_SET_ERR_MSG(extack, "Missing NID argument(s)");
8669 mutex_unlock(&the_lnet.ln_api_mutex);
8673 CFS_ALLOC_PTR(plist);
8675 NL_SET_ERR_MSG(extack, "No memory for peer NID list");
8676 mutex_unlock(&the_lnet.ln_api_mutex);
8680 genradix_init(&plist->lgpl_list);
8681 plist->lgpl_count = 0;
8682 plist->lgpl_index = 0;
8683 cb->args[0] = (long)plist;
8685 params = genlmsg_data(gnlh);
8686 nla_for_each_attr(top, params, msg_len, rem) {
8687 struct nlattr *nids;
8690 if (nla_type(top) != LN_SCALAR_ATTR_LIST)
8693 nla_for_each_nested(nids, top, rem2) {
8694 char nidstr[LNET_NIDSTR_SIZE + 1];
8695 struct lnet_processid *id;
8697 if (nla_type(nids) != LN_SCALAR_ATTR_VALUE)
8700 memset(nidstr, 0, sizeof(nidstr));
8701 rc = nla_strscpy(nidstr, nids, sizeof(nidstr));
8703 NL_SET_ERR_MSG(extack,
8704 "failed to get NID");
8705 GOTO(report_err, rc);
8708 id = genradix_ptr_alloc(&plist->lgpl_list,
8709 plist->lgpl_count++,
8712 NL_SET_ERR_MSG(extack, "failed to allocate NID");
8713 GOTO(report_err, rc = -ENOMEM);
8716 rc = libcfs_strid(id, strim(nidstr));
8718 NL_SET_ERR_MSG(extack, "invalid NID");
8719 GOTO(report_err, rc);
8725 mutex_unlock(&the_lnet.ln_api_mutex);
8728 lnet_peer_dist_show_done(cb);
8733 static const struct ln_key_list peer_dist_props_list = {
8734 .lkl_maxattr = LNET_PEER_DIST_ATTR_MAX,
8736 [LNET_PEER_DIST_ATTR_HDR] = {
8737 .lkp_value = "peer",
8738 .lkp_key_format = LNKF_SEQUENCE | LNKF_MAPPING,
8739 .lkp_data_type = NLA_NUL_STRING,
8741 [LNET_PEER_DIST_ATTR_NID] = {
8743 .lkp_data_type = NLA_STRING
8745 [LNET_PEER_DIST_ATTR_DIST] = {
8746 .lkp_value = "distance",
8747 .lkp_data_type = NLA_U32
8749 [LNET_PEER_DIST_ATTR_ORDER] = {
8750 .lkp_value = "order",
8751 .lkp_data_type = NLA_U32
8756 static int lnet_peer_dist_show_dump(struct sk_buff *msg,
8757 struct netlink_callback *cb)
8759 struct lnet_genl_processid_list *plist = lnet_peer_dump_ctx(cb);
8760 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
8761 struct netlink_ext_ack *extack = NULL;
8763 int portid = NETLINK_CB(cb->skb).portid;
8764 int seq = cb->nlh->nlmsg_seq;
8765 int idx = plist->lgpl_index;
8768 #ifdef HAVE_NL_DUMP_WITH_EXT_ACK
8769 extack = cb->extack;
8772 const struct ln_key_list *all[] = {
8773 &peer_dist_props_list, NULL
8776 rc = lnet_genl_send_scalar_list(msg, portid, seq,
8778 NLM_F_CREATE | NLM_F_MULTI,
8779 LNET_CMD_PEER_DIST, all);
8781 NL_SET_ERR_MSG(extack, "failed to send key table");
8782 GOTO(send_error, rc);
8786 while (idx < plist->lgpl_count) {
8787 struct lnet_processid *id;
8792 id = genradix_ptr(&plist->lgpl_list, idx++);
8793 if (nid_is_lo0(&id->nid))
8796 dist = LNetDist(&id->nid, &id->nid, &order);
8798 if (dist == -EHOSTUNREACH)
8805 hdr = genlmsg_put(msg, portid, seq, &lnet_family,
8806 NLM_F_MULTI, LNET_CMD_PEER_DIST);
8808 NL_SET_ERR_MSG(extack, "failed to send values");
8809 genlmsg_cancel(msg, hdr);
8810 GOTO(send_error, rc = -EMSGSIZE);
8814 nla_put_string(msg, LNET_PEER_DIST_ATTR_HDR, "");
8816 nla_put_string(msg, LNET_PEER_DIST_ATTR_NID,
8817 libcfs_nidstr(&id->nid));
8818 nla_put_u32(msg, LNET_PEER_DIST_ATTR_DIST, dist);
8819 nla_put_u32(msg, LNET_PEER_DIST_ATTR_ORDER, order);
8821 genlmsg_end(msg, hdr);
8824 plist->lgpl_index = idx;
8826 return lnet_nl_send_error(cb->skb, portid, seq, rc);
8829 #ifndef HAVE_NETLINK_CALLBACK_START
8830 static int lnet_old_peer_dist_show_dump(struct sk_buff *msg,
8831 struct netlink_callback *cb)
8834 int rc = lnet_peer_dist_show_start(cb);
8837 return lnet_nl_send_error(cb->skb,
8838 NETLINK_CB(cb->skb).portid,
8843 return lnet_peer_dist_show_dump(msg, cb);
8847 static const struct genl_multicast_group lnet_mcast_grps[] = {
8848 { .name = "ip2net", },
8850 { .name = "peer", },
8851 { .name = "route", },
8852 { .name = "ping", },
8853 { .name = "discover", },
8854 { .name = "cpt-of-nid", },
8857 static const struct genl_ops lnet_genl_ops[] = {
8859 .cmd = LNET_CMD_CONFIGURE,
8860 .flags = GENL_ADMIN_PERM,
8861 .doit = lnet_net_conf_cmd,
8864 .cmd = LNET_CMD_NETS,
8865 .flags = GENL_ADMIN_PERM,
8866 #ifdef HAVE_NETLINK_CALLBACK_START
8867 .start = lnet_net_show_start,
8868 .dumpit = lnet_net_show_dump,
8870 .dumpit = lnet_old_net_show_dump,
8872 .done = lnet_net_show_done,
8873 .doit = lnet_net_cmd,
8876 .cmd = LNET_CMD_PEERS,
8877 .flags = GENL_ADMIN_PERM,
8878 #ifdef HAVE_NETLINK_CALLBACK_START
8879 .start = lnet_peer_ni_show_start,
8880 .dumpit = lnet_peer_ni_show_dump,
8882 .dumpit = lnet_old_peer_ni_show_dump,
8884 .done = lnet_peer_ni_show_done,
8885 .doit = lnet_peer_ni_cmd,
8888 .cmd = LNET_CMD_ROUTES,
8889 .flags = GENL_ADMIN_PERM,
8890 #ifdef HAVE_NETLINK_CALLBACK_START
8891 .start = lnet_route_show_start,
8892 .dumpit = lnet_route_show_dump,
8894 .dumpit = lnet_old_route_show_dump,
8896 .done = lnet_route_show_done,
8897 .doit = lnet_route_cmd,
8900 .cmd = LNET_CMD_PING,
8901 .flags = GENL_ADMIN_PERM,
8902 #ifdef HAVE_NETLINK_CALLBACK_START
8903 .start = lnet_ping_show_start,
8904 .dumpit = lnet_ping_show_dump,
8906 .dumpit = lnet_old_ping_show_dump,
8908 .done = lnet_ping_show_done,
8909 .doit = lnet_ping_cmd,
8912 .cmd = LNET_CMD_CPT_OF_NID,
8913 #ifdef HAVE_NETLINK_CALLBACK_START
8914 .start = lnet_cpt_of_nid_show_start,
8915 .dumpit = lnet_cpt_of_nid_show_dump,
8917 .dumpit = lnet_old_cpt_of_nid_show_dump,
8919 .done = lnet_cpt_of_nid_show_done,
8922 .cmd = LNET_CMD_PEER_DIST,
8923 #ifdef HAVE_NETLINK_CALLBACK_START
8924 .start = lnet_peer_dist_show_start,
8925 .dumpit = lnet_peer_dist_show_dump,
8927 .dumpit = lnet_old_peer_dist_show_dump,
8929 .done = lnet_peer_dist_show_done,
8933 static struct genl_family lnet_family = {
8934 .name = LNET_GENL_NAME,
8935 .version = LNET_GENL_VERSION,
8936 .module = THIS_MODULE,
8937 .parallel_ops = true,
8939 .ops = lnet_genl_ops,
8940 .n_ops = ARRAY_SIZE(lnet_genl_ops),
8941 .mcgrps = lnet_mcast_grps,
8942 .n_mcgrps = ARRAY_SIZE(lnet_mcast_grps),
8943 #ifdef GENL_FAMILY_HAS_RESV_START_OP
8944 .resv_start_op = __LNET_CMD_MAX_PLUS_ONE,
8948 void LNetDebugPeer(struct lnet_processid *id)
8950 lnet_debug_peer(&id->nid);
8952 EXPORT_SYMBOL(LNetDebugPeer);
8955 * Determine if the specified peer \a nid is on the local node.
8957 * \param nid peer nid to check
8959 * \retval true If peer NID is on the local node.
8960 * \retval false If peer NID is not on the local node.
8962 bool LNetIsPeerLocal(struct lnet_nid *nid)
8964 struct lnet_net *net;
8968 cpt = lnet_net_lock_current();
8969 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
8970 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
8971 if (nid_same(&ni->ni_nid, nid)) {
8972 lnet_net_unlock(cpt);
8977 lnet_net_unlock(cpt);
8981 EXPORT_SYMBOL(LNetIsPeerLocal);
8984 * Retrieve the struct lnet_process_id ID of LNet interface at \a index.
8985 * Note that all interfaces share a same PID, as requested by LNetNIInit().
8987 * @index Index of the interface to look up.
8988 * @id On successful return, this location will hold the
8989 * struct lnet_process_id ID of the interface.
8990 * @large_nids Report large NIDs if this is true.
8992 * RETURN 0 If an interface exists at \a index.
8993 * -ENOENT If no interface has been found.
8996 LNetGetId(unsigned int index, struct lnet_processid *id, bool large_nids)
8999 struct lnet_net *net;
9003 LASSERT(the_lnet.ln_refcount > 0);
9005 cpt = lnet_net_lock_current();
9007 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
9008 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
9009 if (!large_nids && !nid_is_nid4(&ni->ni_nid))
9015 id->nid = ni->ni_nid;
9016 id->pid = the_lnet.ln_pid;
9022 lnet_net_unlock(cpt);
9025 EXPORT_SYMBOL(LNetGetId);
9031 struct lnet_handle_md mdh;
9032 struct completion completion;
9036 lnet_ping_event_handler(struct lnet_event *event)
9038 struct ping_data *pd = event->md_user_ptr;
9040 CDEBUG(D_NET, "ping event (%d %d)%s\n",
9041 event->type, event->status,
9042 event->unlinked ? " unlinked" : "");
9044 if (event->status) {
9046 pd->rc = event->status;
9047 } else if (event->type == LNET_EVENT_REPLY) {
9049 pd->rc = event->mlength;
9052 if (event->unlinked)
9053 pd->pd_unlinked = 1;
9055 if (event->unlinked ||
9056 (event->type == LNET_EVENT_SEND && event->status))
9057 complete(&pd->completion);
9060 /* Max buffer we allow to be sent. Larger values will cause IB failures */
9061 #define LNET_PING_BUFFER_MAX 3960
9063 static int lnet_ping(struct lnet_processid *id, struct lnet_nid *src_nid,
9064 signed long timeout, struct lnet_genl_ping_list *plist,
9067 int id_bytes = sizeof(struct lnet_ni_status); /* For 0@lo */
9068 struct lnet_md md = { NULL };
9069 struct ping_data pd = { 0 };
9070 struct lnet_ping_buffer *pbuf;
9071 struct lnet_processid pid;
9072 struct lnet_ping_iter pi;
9079 genradix_init(&plist->lgpl_list);
9081 /* n_ids limit is arbitrary */
9082 if (n_ids <= 0 || LNET_NID_IS_ANY(&id->nid))
9085 /* if the user buffer has more space than the lnet_interfaces_max
9086 * then only fill it up to lnet_interfaces_max
9088 if (n_ids > lnet_interfaces_max)
9089 n_ids = lnet_interfaces_max;
9091 if (id->pid == LNET_PID_ANY)
9092 id->pid = LNET_PID_LUSTRE;
9094 /* Allocate maximum possible NID size */
9095 id_bytes += lnet_ping_sts_size(&LNET_ANY_NID) * n_ids;
9096 if (id_bytes > LNET_PING_BUFFER_MAX)
9097 id_bytes = LNET_PING_BUFFER_MAX;
9099 pbuf = lnet_ping_buffer_alloc(id_bytes, GFP_NOFS);
9103 /* initialize md content */
9104 md.start = &pbuf->pb_info;
9105 md.length = id_bytes;
9106 md.threshold = 2; /* GET/REPLY */
9108 md.options = LNET_MD_TRUNCATE;
9110 md.handler = lnet_ping_event_handler;
9112 init_completion(&pd.completion);
9114 rc = LNetMDBind(&md, LNET_UNLINK, &pd.mdh);
9116 CERROR("Can't bind MD: %d\n", rc);
9117 goto fail_ping_buffer_decref;
9120 rc = LNetGet(src_nid, pd.mdh, id, LNET_RESERVED_PORTAL,
9121 LNET_PROTO_PING_MATCHBITS, 0, false);
9123 /* Don't CERROR; this could be deliberate! */
9124 rc2 = LNetMDUnlink(pd.mdh);
9127 /* NB must wait for the UNLINK event below... */
9130 /* Ensure completion in finite time... */
9131 wait_for_completion_timeout(&pd.completion, timeout);
9132 if (!pd.pd_unlinked) {
9133 LNetMDUnlink(pd.mdh);
9134 wait_for_completion(&pd.completion);
9139 goto fail_ping_buffer_decref;
9143 LASSERT(nob >= 0 && nob <= id_bytes);
9145 rc = -EPROTO; /* if I can't parse... */
9147 if (nob < LNET_PING_INFO_HDR_SIZE) {
9148 CERROR("%s: ping info too short %d\n",
9149 libcfs_idstr(id), nob);
9150 goto fail_ping_buffer_decref;
9153 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) {
9154 lnet_swap_pinginfo(pbuf);
9155 } else if (pbuf->pb_info.pi_magic != LNET_PROTO_PING_MAGIC) {
9156 CERROR("%s: Unexpected magic %08x\n",
9157 libcfs_idstr(id), pbuf->pb_info.pi_magic);
9158 goto fail_ping_buffer_decref;
9161 if ((pbuf->pb_info.pi_features & LNET_PING_FEAT_NI_STATUS) == 0) {
9162 CERROR("%s: ping w/o NI status: 0x%x\n",
9163 libcfs_idstr(id), pbuf->pb_info.pi_features);
9164 goto fail_ping_buffer_decref;
9167 /* Test if smaller than lnet_pinginfo with just one pi_ni status info.
9168 * That one might contain size when large nids are used.
9170 if (nob < offsetof(struct lnet_ping_info, pi_ni[1])) {
9171 CERROR("%s: Short reply %d(%lu min)\n",
9172 libcfs_idstr(id), nob,
9173 offsetof(struct lnet_ping_info, pi_ni[1]));
9174 goto fail_ping_buffer_decref;
9177 if (ping_info_count_entries(pbuf) < n_ids) {
9178 n_ids = ping_info_count_entries(pbuf);
9179 id_bytes = lnet_ping_info_size(&pbuf->pb_info);
9182 if (nob < id_bytes) {
9183 CERROR("%s: Short reply %d(%d expected)\n",
9184 libcfs_idstr(id), nob, id_bytes);
9185 goto fail_ping_buffer_decref;
9188 for (st = ping_iter_first(&pi, pbuf, &pid.nid);
9190 st = ping_iter_next(&pi, &pid.nid)) {
9191 id = genradix_ptr_alloc(&plist->lgpl_list, i++, GFP_KERNEL);
9194 goto fail_ping_buffer_decref;
9197 id->pid = pbuf->pb_info.pi_pid;
9201 fail_ping_buffer_decref:
9202 lnet_ping_buffer_decref(pbuf);
9207 lnet_discover(struct lnet_processid *pid, u32 force,
9208 struct lnet_genl_ping_list *dlist)
9210 struct lnet_peer_ni *lpni;
9211 struct lnet_peer_ni *p;
9212 struct lnet_peer *lp;
9216 if (LNET_NID_IS_ANY(&pid->nid))
9219 if (pid->pid == LNET_PID_ANY)
9220 pid->pid = LNET_PID_LUSTRE;
9222 cpt = lnet_net_lock_current();
9223 lpni = lnet_peerni_by_nid_locked(&pid->nid, NULL, cpt);
9230 * Clearing the NIDS_UPTODATE flag ensures the peer will
9231 * be discovered, provided discovery has not been disabled.
9233 lp = lpni->lpni_peer_net->lpn_peer;
9234 spin_lock(&lp->lp_lock);
9235 lp->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
9236 /* If the force flag is set, force a PING and PUSH as well. */
9238 lp->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH;
9239 spin_unlock(&lp->lp_lock);
9240 rc = lnet_discover_peer_locked(lpni, cpt, true);
9244 /* The lpni (or lp) for this NID may have changed and our ref is
9245 * the only thing keeping the old one around. Release the ref
9246 * and lookup the lpni again
9248 lnet_peer_ni_decref_locked(lpni);
9249 lpni = lnet_peer_ni_find_locked(&pid->nid);
9254 lp = lpni->lpni_peer_net->lpn_peer;
9256 dlist->lgpl_list_count = 0;
9258 while ((p = lnet_get_next_peer_ni_locked(lp, NULL, p)) != NULL) {
9259 struct lnet_processid *id;
9261 id = genradix_ptr_alloc(&dlist->lgpl_list,
9262 dlist->lgpl_list_count++, GFP_ATOMIC);
9268 id->nid = p->lpni_nid;
9270 rc = dlist->lgpl_list_count;
9273 lnet_peer_ni_decref_locked(lpni);
9275 lnet_net_unlock(cpt);
9281 * Retrieve peer discovery status.
9283 * \retval 1 if lnet_peer_discovery_disabled is 0
9284 * \retval 0 if lnet_peer_discovery_disabled is 1
9287 LNetGetPeerDiscoveryStatus(void)
9289 return !lnet_peer_discovery_disabled;
9291 EXPORT_SYMBOL(LNetGetPeerDiscoveryStatus);