4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LNET
38 #include <lnet/lib-lnet.h>
39 #include <lnet/lib-dlc.h>
41 #include <linux/log2.h>
45 #define D_LNI D_CONSOLE
47 #define D_LNI D_CONFIG
50 lnet_t the_lnet; /* THE state of the network */
51 EXPORT_SYMBOL(the_lnet);
55 static char *ip2nets = "";
56 CFS_MODULE_PARM(ip2nets, "s", charp, 0444,
57 "LNET network <- IP table");
59 static char *networks = "";
60 CFS_MODULE_PARM(networks, "s", charp, 0444,
63 static char *routes = "";
64 CFS_MODULE_PARM(routes, "s", charp, 0444,
65 "routes to non-local networks");
67 static int rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
68 CFS_MODULE_PARM(rnet_htable_size, "i", int, 0444,
69 "size of remote network hash table");
71 static int lnet_ping(lnet_process_id_t id, int timeout_ms,
72 lnet_process_id_t *ids, int n_ids);
81 lnet_get_networks(void)
86 if (*networks != 0 && *ip2nets != 0) {
87 LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
88 "'ip2nets' but not both at once\n");
93 rc = lnet_parse_ip2nets(&nets, ip2nets);
94 return (rc == 0) ? nets : NULL;
104 lnet_init_locks(void)
106 spin_lock_init(&the_lnet.ln_eq_wait_lock);
107 init_waitqueue_head(&the_lnet.ln_eq_waitq);
108 mutex_init(&the_lnet.ln_lnd_mutex);
109 mutex_init(&the_lnet.ln_api_mutex);
113 lnet_fini_locks(void)
120 lnet_get_routes(void)
122 char *str = getenv("LNET_ROUTES");
124 return (str == NULL) ? "" : str;
128 lnet_get_networks (void)
130 static char default_networks[256];
131 char *networks = getenv("LNET_NETWORKS");
136 struct list_head *tmp;
138 if (networks != NULL)
141 /* In userland, the default 'networks=' is the list of known net types */
142 len = sizeof(default_networks);
143 str = default_networks;
147 list_for_each(tmp, &the_lnet.ln_lnds) {
148 lnd_t *lnd = list_entry(tmp, lnd_t, lnd_list);
150 nob = snprintf(str, len, "%s%s", sep,
151 libcfs_lnd2str(lnd->lnd_type));
153 /* overflowed the string; leave it where it was */
162 return default_networks;
165 # ifndef HAVE_LIBPTHREAD
167 static void lnet_init_locks(void)
169 the_lnet.ln_eq_wait_lock = 0;
170 the_lnet.ln_lnd_mutex = 0;
171 the_lnet.ln_api_mutex = 0;
174 static void lnet_fini_locks(void)
176 LASSERT(the_lnet.ln_api_mutex == 0);
177 LASSERT(the_lnet.ln_lnd_mutex == 0);
178 LASSERT(the_lnet.ln_eq_wait_lock == 0);
183 static void lnet_init_locks(void)
185 pthread_cond_init(&the_lnet.ln_eq_cond, NULL);
186 pthread_mutex_init(&the_lnet.ln_eq_wait_lock, NULL);
187 pthread_mutex_init(&the_lnet.ln_lnd_mutex, NULL);
188 pthread_mutex_init(&the_lnet.ln_api_mutex, NULL);
191 static void lnet_fini_locks(void)
193 pthread_mutex_destroy(&the_lnet.ln_api_mutex);
194 pthread_mutex_destroy(&the_lnet.ln_lnd_mutex);
195 pthread_mutex_destroy(&the_lnet.ln_eq_wait_lock);
196 pthread_cond_destroy(&the_lnet.ln_eq_cond);
203 lnet_create_remote_nets_table(void)
206 struct list_head *hash;
208 LASSERT(the_lnet.ln_remote_nets_hash == NULL);
209 LASSERT(the_lnet.ln_remote_nets_hbits > 0);
210 LIBCFS_ALLOC(hash, LNET_REMOTE_NETS_HASH_SIZE * sizeof(*hash));
212 CERROR("Failed to create remote nets hash table\n");
216 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
217 INIT_LIST_HEAD(&hash[i]);
218 the_lnet.ln_remote_nets_hash = hash;
223 lnet_destroy_remote_nets_table(void)
227 if (the_lnet.ln_remote_nets_hash == NULL)
230 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
231 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
233 LIBCFS_FREE(the_lnet.ln_remote_nets_hash,
234 LNET_REMOTE_NETS_HASH_SIZE *
235 sizeof(the_lnet.ln_remote_nets_hash[0]));
236 the_lnet.ln_remote_nets_hash = NULL;
240 lnet_destroy_locks(void)
242 if (the_lnet.ln_res_lock != NULL) {
243 cfs_percpt_lock_free(the_lnet.ln_res_lock);
244 the_lnet.ln_res_lock = NULL;
247 if (the_lnet.ln_net_lock != NULL) {
248 cfs_percpt_lock_free(the_lnet.ln_net_lock);
249 the_lnet.ln_net_lock = NULL;
256 lnet_create_locks(void)
260 the_lnet.ln_res_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
261 if (the_lnet.ln_res_lock == NULL)
264 the_lnet.ln_net_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
265 if (the_lnet.ln_net_lock == NULL)
271 lnet_destroy_locks();
275 static void lnet_assert_wire_constants(void)
277 /* Wire protocol assertions generated by 'wirecheck'
278 * running on Linux robert.bartonsoftware.com 2.6.8-1.521
279 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux
280 * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) */
283 CLASSERT (LNET_PROTO_TCP_MAGIC == 0xeebc0ded);
284 CLASSERT (LNET_PROTO_TCP_VERSION_MAJOR == 1);
285 CLASSERT (LNET_PROTO_TCP_VERSION_MINOR == 0);
286 CLASSERT (LNET_MSG_ACK == 0);
287 CLASSERT (LNET_MSG_PUT == 1);
288 CLASSERT (LNET_MSG_GET == 2);
289 CLASSERT (LNET_MSG_REPLY == 3);
290 CLASSERT (LNET_MSG_HELLO == 4);
292 /* Checks for struct ptl_handle_wire_t */
293 CLASSERT ((int)sizeof(lnet_handle_wire_t) == 16);
294 CLASSERT ((int)offsetof(lnet_handle_wire_t, wh_interface_cookie) == 0);
295 CLASSERT ((int)sizeof(((lnet_handle_wire_t *)0)->wh_interface_cookie) == 8);
296 CLASSERT ((int)offsetof(lnet_handle_wire_t, wh_object_cookie) == 8);
297 CLASSERT ((int)sizeof(((lnet_handle_wire_t *)0)->wh_object_cookie) == 8);
299 /* Checks for struct lnet_magicversion_t */
300 CLASSERT ((int)sizeof(lnet_magicversion_t) == 8);
301 CLASSERT ((int)offsetof(lnet_magicversion_t, magic) == 0);
302 CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->magic) == 4);
303 CLASSERT ((int)offsetof(lnet_magicversion_t, version_major) == 4);
304 CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->version_major) == 2);
305 CLASSERT ((int)offsetof(lnet_magicversion_t, version_minor) == 6);
306 CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->version_minor) == 2);
308 /* Checks for struct lnet_hdr_t */
309 CLASSERT ((int)sizeof(lnet_hdr_t) == 72);
310 CLASSERT ((int)offsetof(lnet_hdr_t, dest_nid) == 0);
311 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->dest_nid) == 8);
312 CLASSERT ((int)offsetof(lnet_hdr_t, src_nid) == 8);
313 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->src_nid) == 8);
314 CLASSERT ((int)offsetof(lnet_hdr_t, dest_pid) == 16);
315 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->dest_pid) == 4);
316 CLASSERT ((int)offsetof(lnet_hdr_t, src_pid) == 20);
317 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->src_pid) == 4);
318 CLASSERT ((int)offsetof(lnet_hdr_t, type) == 24);
319 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->type) == 4);
320 CLASSERT ((int)offsetof(lnet_hdr_t, payload_length) == 28);
321 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->payload_length) == 4);
322 CLASSERT ((int)offsetof(lnet_hdr_t, msg) == 32);
323 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg) == 40);
326 CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.dst_wmd) == 32);
327 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.dst_wmd) == 16);
328 CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.match_bits) == 48);
329 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.match_bits) == 8);
330 CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.mlength) == 56);
331 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.mlength) == 4);
334 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.ack_wmd) == 32);
335 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.ack_wmd) == 16);
336 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.match_bits) == 48);
337 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.match_bits) == 8);
338 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.hdr_data) == 56);
339 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.hdr_data) == 8);
340 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.ptl_index) == 64);
341 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.ptl_index) == 4);
342 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.offset) == 68);
343 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.offset) == 4);
346 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.return_wmd) == 32);
347 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.return_wmd) == 16);
348 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.match_bits) == 48);
349 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.match_bits) == 8);
350 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.ptl_index) == 56);
351 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.ptl_index) == 4);
352 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.src_offset) == 60);
353 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.src_offset) == 4);
354 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.sink_length) == 64);
355 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.sink_length) == 4);
358 CLASSERT ((int)offsetof(lnet_hdr_t, msg.reply.dst_wmd) == 32);
359 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.reply.dst_wmd) == 16);
362 CLASSERT ((int)offsetof(lnet_hdr_t, msg.hello.incarnation) == 32);
363 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.hello.incarnation) == 8);
364 CLASSERT ((int)offsetof(lnet_hdr_t, msg.hello.type) == 40);
365 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.hello.type) == 4);
369 lnet_find_lnd_by_type (int type)
372 struct list_head *tmp;
374 /* holding lnd mutex */
375 list_for_each(tmp, &the_lnet.ln_lnds) {
376 lnd = list_entry(tmp, lnd_t, lnd_list);
378 if ((int)lnd->lnd_type == type)
385 lnet_register_lnd (lnd_t *lnd)
387 LNET_MUTEX_LOCK(&the_lnet.ln_lnd_mutex);
389 LASSERT(the_lnet.ln_init);
390 LASSERT(libcfs_isknown_lnd(lnd->lnd_type));
391 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
393 list_add_tail(&lnd->lnd_list, &the_lnet.ln_lnds);
394 lnd->lnd_refcount = 0;
396 CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type));
398 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
400 EXPORT_SYMBOL(lnet_register_lnd);
403 lnet_unregister_lnd (lnd_t *lnd)
405 LNET_MUTEX_LOCK(&the_lnet.ln_lnd_mutex);
407 LASSERT(the_lnet.ln_init);
408 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
409 LASSERT(lnd->lnd_refcount == 0);
411 list_del(&lnd->lnd_list);
412 CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type));
414 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
416 EXPORT_SYMBOL(lnet_unregister_lnd);
419 lnet_counters_get(lnet_counters_t *counters)
421 lnet_counters_t *ctr;
424 memset(counters, 0, sizeof(*counters));
426 lnet_net_lock(LNET_LOCK_EX);
428 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
429 counters->msgs_max += ctr->msgs_max;
430 counters->msgs_alloc += ctr->msgs_alloc;
431 counters->errors += ctr->errors;
432 counters->send_count += ctr->send_count;
433 counters->recv_count += ctr->recv_count;
434 counters->route_count += ctr->route_count;
435 counters->drop_count += ctr->drop_count;
436 counters->send_length += ctr->send_length;
437 counters->recv_length += ctr->recv_length;
438 counters->route_length += ctr->route_length;
439 counters->drop_length += ctr->drop_length;
442 lnet_net_unlock(LNET_LOCK_EX);
444 EXPORT_SYMBOL(lnet_counters_get);
447 lnet_counters_reset(void)
449 lnet_counters_t *counters;
452 lnet_net_lock(LNET_LOCK_EX);
454 cfs_percpt_for_each(counters, i, the_lnet.ln_counters)
455 memset(counters, 0, sizeof(lnet_counters_t));
457 lnet_net_unlock(LNET_LOCK_EX);
459 EXPORT_SYMBOL(lnet_counters_reset);
461 #ifdef LNET_USE_LIB_FREELIST
464 lnet_freelist_init(lnet_freelist_t *fl, int n, int size)
470 size += offsetof (lnet_freeobj_t, fo_contents);
472 LIBCFS_ALLOC(space, n * size);
476 INIT_LIST_HEAD(&fl->fl_list);
479 fl->fl_objsize = size;
482 list_add((struct list_head *)space, &fl->fl_list);
490 lnet_freelist_fini(lnet_freelist_t *fl)
492 struct list_head *el;
495 if (fl->fl_nobjs == 0)
499 for (el = fl->fl_list.next; el != &fl->fl_list; el = el->next)
502 LASSERT (count == fl->fl_nobjs);
504 LIBCFS_FREE(fl->fl_objs, fl->fl_nobjs * fl->fl_objsize);
505 memset (fl, 0, sizeof (*fl));
508 #endif /* LNET_USE_LIB_FREELIST */
510 static __u64 lnet_create_interface_cookie(void)
512 /* NB the interface cookie in wire handles guards against delayed
513 * replies and ACKs appearing valid after reboot. Initialisation time,
514 * even if it's only implemented to millisecond resolution is probably
515 * easily good enough. */
519 int rc = gettimeofday (&tv, NULL);
522 do_gettimeofday(&tv);
526 cookie += tv.tv_usec;
531 lnet_res_type2str(int type)
536 case LNET_COOKIE_TYPE_MD:
538 case LNET_COOKIE_TYPE_ME:
540 case LNET_COOKIE_TYPE_EQ:
546 lnet_res_container_cleanup(struct lnet_res_container *rec)
550 if (rec->rec_type == 0) /* not set yet, it's uninitialized */
553 while (!list_empty(&rec->rec_active)) {
554 struct list_head *e = rec->rec_active.next;
557 if (rec->rec_type == LNET_COOKIE_TYPE_EQ) {
558 lnet_eq_free(list_entry(e, lnet_eq_t, eq_list));
560 } else if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
561 lnet_md_free(list_entry(e, lnet_libmd_t, md_list));
563 } else { /* NB: Active MEs should be attached on portals */
570 /* Found alive MD/ME/EQ, user really should unlink/free
571 * all of them before finalize LNet, but if someone didn't,
572 * we have to recycle garbage for him */
573 CERROR("%d active elements on exit of %s container\n",
574 count, lnet_res_type2str(rec->rec_type));
577 #ifdef LNET_USE_LIB_FREELIST
578 lnet_freelist_fini(&rec->rec_freelist);
580 if (rec->rec_lh_hash != NULL) {
581 LIBCFS_FREE(rec->rec_lh_hash,
582 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
583 rec->rec_lh_hash = NULL;
586 rec->rec_type = 0; /* mark it as finalized */
590 lnet_res_container_setup(struct lnet_res_container *rec,
591 int cpt, int type, int objnum, int objsz)
596 LASSERT(rec->rec_type == 0);
598 rec->rec_type = type;
599 INIT_LIST_HEAD(&rec->rec_active);
601 #ifdef LNET_USE_LIB_FREELIST
602 memset(&rec->rec_freelist, 0, sizeof(rec->rec_freelist));
603 rc = lnet_freelist_init(&rec->rec_freelist, objnum, objsz);
607 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type;
609 /* Arbitrary choice of hash table size */
610 LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt,
611 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
612 if (rec->rec_lh_hash == NULL) {
617 for (i = 0; i < LNET_LH_HASH_SIZE; i++)
618 INIT_LIST_HEAD(&rec->rec_lh_hash[i]);
623 CERROR("Failed to setup %s resource container\n",
624 lnet_res_type2str(type));
625 lnet_res_container_cleanup(rec);
630 lnet_res_containers_destroy(struct lnet_res_container **recs)
632 struct lnet_res_container *rec;
635 cfs_percpt_for_each(rec, i, recs)
636 lnet_res_container_cleanup(rec);
638 cfs_percpt_free(recs);
641 static struct lnet_res_container **
642 lnet_res_containers_create(int type, int objnum, int objsz)
644 struct lnet_res_container **recs;
645 struct lnet_res_container *rec;
649 recs = cfs_percpt_alloc(lnet_cpt_table(), sizeof(*rec));
651 CERROR("Failed to allocate %s resource containers\n",
652 lnet_res_type2str(type));
656 cfs_percpt_for_each(rec, i, recs) {
657 rc = lnet_res_container_setup(rec, i, type, objnum, objsz);
659 lnet_res_containers_destroy(recs);
668 lnet_res_lh_lookup(struct lnet_res_container *rec, __u64 cookie)
670 /* ALWAYS called with lnet_res_lock held */
671 struct list_head *head;
672 lnet_libhandle_t *lh;
675 if ((cookie & LNET_COOKIE_MASK) != rec->rec_type)
678 hash = cookie >> (LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS);
679 head = &rec->rec_lh_hash[hash & LNET_LH_HASH_MASK];
681 list_for_each_entry(lh, head, lh_hash_chain) {
682 if (lh->lh_cookie == cookie)
690 lnet_res_lh_initialize(struct lnet_res_container *rec, lnet_libhandle_t *lh)
692 /* ALWAYS called with lnet_res_lock held */
693 unsigned int ibits = LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS;
696 lh->lh_cookie = rec->rec_lh_cookie;
697 rec->rec_lh_cookie += 1 << ibits;
699 hash = (lh->lh_cookie >> ibits) & LNET_LH_HASH_MASK;
701 list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
706 * Reserved API - do not use.
707 * Temporary workaround to allow uOSS and test programs force server
708 * mode in userspace. See comments near ln_server_mode_flag in
709 * lnet/lib-types.h */
713 the_lnet.ln_server_mode_flag = 1;
717 static int lnet_unprepare(void);
720 lnet_prepare(lnet_pid_t requested_pid)
722 /* Prepare to bring up the network */
723 struct lnet_res_container **recs;
726 if (requested_pid == LNET_PID_ANY) {
727 /* Don't instantiate LNET just for me */
731 LASSERT (the_lnet.ln_refcount == 0);
733 the_lnet.ln_routing = 0;
736 LASSERT ((requested_pid & LNET_PID_USERFLAG) == 0);
737 the_lnet.ln_pid = requested_pid;
739 if (the_lnet.ln_server_mode_flag) {/* server case (uOSS) */
740 LASSERT ((requested_pid & LNET_PID_USERFLAG) == 0);
742 if (current_uid() != 0) /* Only root can run user-space server */
744 the_lnet.ln_pid = requested_pid;
746 } else {/* client case (liblustre) */
748 /* My PID must be unique on this node and flag I'm userspace */
749 the_lnet.ln_pid = getpid() | LNET_PID_USERFLAG;
753 INIT_LIST_HEAD(&the_lnet.ln_test_peers);
754 INIT_LIST_HEAD(&the_lnet.ln_nis);
755 INIT_LIST_HEAD(&the_lnet.ln_nis_cpt);
756 INIT_LIST_HEAD(&the_lnet.ln_nis_zombie);
757 INIT_LIST_HEAD(&the_lnet.ln_routers);
758 INIT_LIST_HEAD(&the_lnet.ln_drop_rules);
759 INIT_LIST_HEAD(&the_lnet.ln_delay_rules);
761 rc = lnet_create_remote_nets_table();
765 the_lnet.ln_interface_cookie = lnet_create_interface_cookie();
767 the_lnet.ln_counters = cfs_percpt_alloc(lnet_cpt_table(),
768 sizeof(lnet_counters_t));
769 if (the_lnet.ln_counters == NULL) {
770 CERROR("Failed to allocate counters for LNet\n");
775 rc = lnet_peer_tables_create();
779 rc = lnet_msg_containers_create();
783 rc = lnet_res_container_setup(&the_lnet.ln_eq_container, 0,
784 LNET_COOKIE_TYPE_EQ, LNET_FL_MAX_EQS,
789 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_ME, LNET_FL_MAX_MES,
794 the_lnet.ln_me_containers = recs;
796 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD, LNET_FL_MAX_MDS,
797 sizeof(lnet_libmd_t));
801 the_lnet.ln_md_containers = recs;
803 rc = lnet_portals_create();
805 CERROR("Failed to create portals for LNet: %d\n", rc);
817 lnet_unprepare (void)
819 /* NB no LNET_LOCK since this is the last reference. All LND instances
820 * have shut down already, so it is safe to unlink and free all
821 * descriptors, even those that appear committed to a network op (eg MD
822 * with non-zero pending count) */
824 lnet_fail_nid(LNET_NID_ANY, 0);
826 LASSERT(the_lnet.ln_refcount == 0);
827 LASSERT(list_empty(&the_lnet.ln_test_peers));
828 LASSERT(list_empty(&the_lnet.ln_nis));
829 LASSERT(list_empty(&the_lnet.ln_nis_cpt));
830 LASSERT(list_empty(&the_lnet.ln_nis_zombie));
832 lnet_portals_destroy();
834 if (the_lnet.ln_md_containers != NULL) {
835 lnet_res_containers_destroy(the_lnet.ln_md_containers);
836 the_lnet.ln_md_containers = NULL;
839 if (the_lnet.ln_me_containers != NULL) {
840 lnet_res_containers_destroy(the_lnet.ln_me_containers);
841 the_lnet.ln_me_containers = NULL;
844 lnet_res_container_cleanup(&the_lnet.ln_eq_container);
846 lnet_msg_containers_destroy();
847 lnet_peer_tables_destroy();
848 lnet_rtrpools_free(0);
850 if (the_lnet.ln_counters != NULL) {
851 cfs_percpt_free(the_lnet.ln_counters);
852 the_lnet.ln_counters = NULL;
854 lnet_destroy_remote_nets_table();
860 lnet_net2ni_locked(__u32 net, int cpt)
862 struct list_head *tmp;
865 LASSERT(cpt != LNET_LOCK_EX);
867 list_for_each(tmp, &the_lnet.ln_nis) {
868 ni = list_entry(tmp, lnet_ni_t, ni_list);
870 if (LNET_NIDNET(ni->ni_nid) == net) {
871 lnet_ni_addref_locked(ni, cpt);
880 lnet_net2ni(__u32 net)
885 ni = lnet_net2ni_locked(net, 0);
890 EXPORT_SYMBOL(lnet_net2ni);
893 lnet_nid_cpt_hash(lnet_nid_t nid, unsigned int number)
898 LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
903 val = hash_long(key, LNET_CPT_BITS);
904 /* NB: LNET_CP_NUMBER doesn't have to be PO2 */
908 return (unsigned int)(key + val + (val >> 1)) % number;
912 lnet_cpt_of_nid_locked(lnet_nid_t nid)
916 /* must called with hold of lnet_net_lock */
917 if (LNET_CPT_NUMBER == 1)
918 return 0; /* the only one */
920 /* take lnet_net_lock(any) would be OK */
921 if (!list_empty(&the_lnet.ln_nis_cpt)) {
922 list_for_each_entry(ni, &the_lnet.ln_nis_cpt, ni_cptlist) {
923 if (LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid))
926 LASSERT(ni->ni_cpts != NULL);
927 return ni->ni_cpts[lnet_nid_cpt_hash
928 (nid, ni->ni_ncpts)];
932 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
936 lnet_cpt_of_nid(lnet_nid_t nid)
941 if (LNET_CPT_NUMBER == 1)
942 return 0; /* the only one */
944 if (list_empty(&the_lnet.ln_nis_cpt))
945 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
947 cpt = lnet_net_lock_current();
948 cpt2 = lnet_cpt_of_nid_locked(nid);
949 lnet_net_unlock(cpt);
953 EXPORT_SYMBOL(lnet_cpt_of_nid);
956 lnet_islocalnet(__u32 net)
961 cpt = lnet_net_lock_current();
963 ni = lnet_net2ni_locked(net, cpt);
965 lnet_ni_decref_locked(ni, cpt);
967 lnet_net_unlock(cpt);
973 lnet_nid2ni_locked(lnet_nid_t nid, int cpt)
976 struct list_head *tmp;
978 LASSERT(cpt != LNET_LOCK_EX);
980 list_for_each(tmp, &the_lnet.ln_nis) {
981 ni = list_entry(tmp, lnet_ni_t, ni_list);
983 if (ni->ni_nid == nid) {
984 lnet_ni_addref_locked(ni, cpt);
993 lnet_islocalnid(lnet_nid_t nid)
998 cpt = lnet_net_lock_current();
999 ni = lnet_nid2ni_locked(nid, cpt);
1001 lnet_ni_decref_locked(ni, cpt);
1002 lnet_net_unlock(cpt);
1008 lnet_count_acceptor_nis (void)
1010 /* Return the # of NIs that need the acceptor. */
1012 #if defined(__KERNEL__) || defined(HAVE_LIBPTHREAD)
1013 struct list_head *tmp;
1017 cpt = lnet_net_lock_current();
1018 list_for_each(tmp, &the_lnet.ln_nis) {
1019 ni = list_entry(tmp, lnet_ni_t, ni_list);
1021 if (ni->ni_lnd->lnd_accept != NULL)
1025 lnet_net_unlock(cpt);
1027 #endif /* defined(__KERNEL__) || defined(HAVE_LIBPTHREAD) */
1031 static lnet_ping_info_t *
1032 lnet_ping_info_create(int num_ni)
1034 lnet_ping_info_t *ping_info;
1035 unsigned int infosz;
1037 infosz = offsetof(lnet_ping_info_t, pi_ni[num_ni]);
1038 LIBCFS_ALLOC(ping_info, infosz);
1039 if (ping_info == NULL) {
1040 CERROR("Can't allocate ping info[%d]\n", num_ni);
1044 ping_info->pi_nnis = num_ni;
1045 ping_info->pi_pid = the_lnet.ln_pid;
1046 ping_info->pi_magic = LNET_PROTO_PING_MAGIC;
1047 ping_info->pi_features = LNET_PING_FEAT_NI_STATUS;
1053 lnet_get_ni_count(void)
1060 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list)
1069 lnet_ping_info_free(lnet_ping_info_t *pinfo)
1072 offsetof(lnet_ping_info_t,
1073 pi_ni[pinfo->pi_nnis]));
1077 lnet_ping_info_destroy(void)
1081 lnet_net_lock(LNET_LOCK_EX);
1083 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
1085 ni->ni_status = NULL;
1089 lnet_ping_info_free(the_lnet.ln_ping_info);
1090 the_lnet.ln_ping_info = NULL;
1092 lnet_net_unlock(LNET_LOCK_EX);
1096 lnet_ping_event_handler(lnet_event_t *event)
1098 lnet_ping_info_t *pinfo = event->md.user_ptr;
1100 if (event->unlinked)
1101 pinfo->pi_features = LNET_PING_FEAT_INVAL;
1105 lnet_ping_info_setup(lnet_ping_info_t **ppinfo, lnet_handle_md_t *md_handle,
1106 int ni_count, bool set_eq)
1108 lnet_handle_me_t me_handle;
1109 lnet_process_id_t id = {LNET_NID_ANY, LNET_PID_ANY};
1110 lnet_md_t md = {NULL};
1114 rc = LNetEQAlloc(0, lnet_ping_event_handler,
1115 &the_lnet.ln_ping_target_eq);
1117 CERROR("Can't allocate ping EQ: %d\n", rc);
1122 *ppinfo = lnet_ping_info_create(ni_count);
1123 if (*ppinfo == NULL) {
1128 rc = LNetMEAttach(LNET_RESERVED_PORTAL, id,
1129 LNET_PROTO_PING_MATCHBITS, 0,
1130 LNET_UNLINK, LNET_INS_AFTER,
1133 CERROR("Can't create ping ME: %d\n", rc);
1137 /* initialize md content */
1139 md.length = offsetof(lnet_ping_info_t,
1140 pi_ni[(*ppinfo)->pi_nnis]);
1141 md.threshold = LNET_MD_THRESH_INF;
1143 md.options = LNET_MD_OP_GET | LNET_MD_TRUNCATE |
1144 LNET_MD_MANAGE_REMOTE;
1146 md.eq_handle = the_lnet.ln_ping_target_eq;
1147 md.user_ptr = *ppinfo;
1149 rc = LNetMDAttach(me_handle, md, LNET_RETAIN, md_handle);
1151 CERROR("Can't attach ping MD: %d\n", rc);
1158 rc2 = LNetMEUnlink(me_handle);
1161 lnet_ping_info_free(*ppinfo);
1165 LNetEQFree(the_lnet.ln_ping_target_eq);
1170 lnet_ping_md_unlink(lnet_ping_info_t *pinfo, lnet_handle_md_t *md_handle)
1172 sigset_t blocked = cfs_block_allsigs();
1174 LNetMDUnlink(*md_handle);
1175 LNetInvalidateHandle(md_handle);
1177 /* NB md could be busy; this just starts the unlink */
1178 while (pinfo->pi_features != LNET_PING_FEAT_INVAL) {
1179 CDEBUG(D_NET, "Still waiting for ping MD to unlink\n");
1180 cfs_pause(cfs_time_seconds(1));
1183 cfs_restore_sigs(blocked);
1187 lnet_ping_info_install_locked(lnet_ping_info_t *ping_info)
1191 lnet_ni_status_t *ns;
1194 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
1195 LASSERT(i < ping_info->pi_nnis);
1197 ns = &ping_info->pi_ni[i];
1199 ns->ns_nid = ni->ni_nid;
1202 ns->ns_status = (ni->ni_status != NULL) ?
1203 ni->ni_status->ns_status : LNET_NI_STATUS_UP;
1212 lnet_ping_target_update(lnet_ping_info_t *pinfo, lnet_handle_md_t md_handle)
1214 lnet_ping_info_t *old_pinfo = NULL;
1215 lnet_handle_md_t old_md;
1217 /* switch the NIs to point to the new ping info created */
1218 lnet_net_lock(LNET_LOCK_EX);
1220 if (!the_lnet.ln_routing)
1221 pinfo->pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1222 lnet_ping_info_install_locked(pinfo);
1224 if (the_lnet.ln_ping_info != NULL) {
1225 old_pinfo = the_lnet.ln_ping_info;
1226 old_md = the_lnet.ln_ping_target_md;
1228 the_lnet.ln_ping_target_md = md_handle;
1229 the_lnet.ln_ping_info = pinfo;
1231 lnet_net_unlock(LNET_LOCK_EX);
1233 if (old_pinfo != NULL) {
1234 /* unlink the old ping info */
1235 lnet_ping_md_unlink(old_pinfo, &old_md);
1236 lnet_ping_info_free(old_pinfo);
1241 lnet_ping_target_fini(void)
1245 lnet_ping_md_unlink(the_lnet.ln_ping_info,
1246 &the_lnet.ln_ping_target_md);
1248 rc = LNetEQFree(the_lnet.ln_ping_target_eq);
1251 lnet_ping_info_destroy();
1255 lnet_ni_tq_credits(lnet_ni_t *ni)
1259 LASSERT(ni->ni_ncpts >= 1);
1261 if (ni->ni_ncpts == 1)
1262 return ni->ni_maxtxcredits;
1264 credits = ni->ni_maxtxcredits / ni->ni_ncpts;
1265 credits = max(credits, 8 * ni->ni_peertxcredits);
1266 credits = min(credits, ni->ni_maxtxcredits);
1272 lnet_ni_unlink_locked(lnet_ni_t *ni)
1274 if (!list_empty(&ni->ni_cptlist)) {
1275 list_del_init(&ni->ni_cptlist);
1276 lnet_ni_decref_locked(ni, 0);
1279 /* move it to zombie list and nobody can find it anymore */
1280 LASSERT(!list_empty(&ni->ni_list));
1281 list_move(&ni->ni_list, &the_lnet.ln_nis_zombie);
1282 lnet_ni_decref_locked(ni, 0); /* drop ln_nis' ref */
1286 lnet_clear_zombies_nis_locked(void)
1292 /* Now wait for the NI's I just nuked to show up on ln_zombie_nis
1293 * and shut them down in guaranteed thread context */
1295 while (!list_empty(&the_lnet.ln_nis_zombie)) {
1299 ni = list_entry(the_lnet.ln_nis_zombie.next,
1300 lnet_ni_t, ni_list);
1301 list_del_init(&ni->ni_list);
1302 cfs_percpt_for_each(ref, j, ni->ni_refs) {
1305 /* still busy, add it back to zombie list */
1306 list_add(&ni->ni_list, &the_lnet.ln_nis_zombie);
1310 if (!list_empty(&ni->ni_list)) {
1311 lnet_net_unlock(LNET_LOCK_EX);
1313 if ((i & (-i)) == i) {
1315 "Waiting for zombie LNI %s\n",
1316 libcfs_nid2str(ni->ni_nid));
1318 cfs_pause(cfs_time_seconds(1));
1319 lnet_net_lock(LNET_LOCK_EX);
1323 ni->ni_lnd->lnd_refcount--;
1324 lnet_net_unlock(LNET_LOCK_EX);
1326 islo = ni->ni_lnd->lnd_type == LOLND;
1328 LASSERT(!in_interrupt());
1329 (ni->ni_lnd->lnd_shutdown)(ni);
1331 /* can't deref lnd anymore now; it might have unregistered
1335 CDEBUG(D_LNI, "Removed LNI %s\n",
1336 libcfs_nid2str(ni->ni_nid));
1340 lnet_net_lock(LNET_LOCK_EX);
1345 lnet_shutdown_lndnis(void)
1350 /* NB called holding the global mutex */
1352 /* All quiet on the API front */
1353 LASSERT(!the_lnet.ln_shutdown);
1354 LASSERT(the_lnet.ln_refcount == 0);
1355 LASSERT(list_empty(&the_lnet.ln_nis_zombie));
1357 lnet_net_lock(LNET_LOCK_EX);
1358 the_lnet.ln_shutdown = 1; /* flag shutdown */
1360 /* Unlink NIs from the global table */
1361 while (!list_empty(&the_lnet.ln_nis)) {
1362 ni = list_entry(the_lnet.ln_nis.next,
1363 lnet_ni_t, ni_list);
1364 lnet_ni_unlink_locked(ni);
1367 /* Drop the cached eqwait NI. */
1368 if (the_lnet.ln_eq_waitni != NULL) {
1369 lnet_ni_decref_locked(the_lnet.ln_eq_waitni, 0);
1370 the_lnet.ln_eq_waitni = NULL;
1373 /* Drop the cached loopback NI. */
1374 if (the_lnet.ln_loni != NULL) {
1375 lnet_ni_decref_locked(the_lnet.ln_loni, 0);
1376 the_lnet.ln_loni = NULL;
1379 lnet_net_unlock(LNET_LOCK_EX);
1381 /* Clear lazy portals and drop delayed messages which hold refs
1382 * on their lnet_msg_t::msg_rxpeer */
1383 for (i = 0; i < the_lnet.ln_nportals; i++)
1384 LNetClearLazyPortal(i);
1386 /* Clear the peer table and wait for all peers to go (they hold refs on
1388 lnet_peer_tables_cleanup(NULL);
1390 lnet_net_lock(LNET_LOCK_EX);
1392 lnet_clear_zombies_nis_locked();
1393 the_lnet.ln_shutdown = 0;
1394 lnet_net_unlock(LNET_LOCK_EX);
1397 /* shutdown down the NI and release refcount */
1399 lnet_shutdown_lndni(struct lnet_ni *ni)
1401 lnet_net_lock(LNET_LOCK_EX);
1402 lnet_ni_unlink_locked(ni);
1403 lnet_net_unlock(LNET_LOCK_EX);
1405 /* Do peer table cleanup for this ni */
1406 lnet_peer_tables_cleanup(ni);
1408 lnet_net_lock(LNET_LOCK_EX);
1409 lnet_clear_zombies_nis_locked();
1410 lnet_net_unlock(LNET_LOCK_EX);
1414 lnet_startup_lndni(struct lnet_ni *ni, __s32 peer_timeout,
1415 __s32 peer_cr, __s32 peer_buf_cr, __s32 credits)
1420 struct lnet_tx_queue *tq;
1423 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
1425 LASSERT(libcfs_isknown_lnd(lnd_type));
1427 if (lnd_type == CIBLND || lnd_type == OPENIBLND ||
1428 lnd_type == IIBLND || lnd_type == VIBLND) {
1429 CERROR("LND %s obsoleted\n", libcfs_lnd2str(lnd_type));
1433 /* Make sure this new NI is unique. */
1434 lnet_net_lock(LNET_LOCK_EX);
1435 if (!lnet_net_unique(LNET_NIDNET(ni->ni_nid), &the_lnet.ln_nis)) {
1436 if (lnd_type == LOLND) {
1437 lnet_net_unlock(LNET_LOCK_EX);
1441 lnet_net_unlock(LNET_LOCK_EX);
1443 CERROR("Net %s is not unique\n",
1444 libcfs_net2str(LNET_NIDNET(ni->ni_nid)));
1447 lnet_net_unlock(LNET_LOCK_EX);
1449 LNET_MUTEX_LOCK(&the_lnet.ln_lnd_mutex);
1450 lnd = lnet_find_lnd_by_type(lnd_type);
1454 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
1455 rc = request_module("%s",
1456 libcfs_lnd2modname(lnd_type));
1457 LNET_MUTEX_LOCK(&the_lnet.ln_lnd_mutex);
1459 lnd = lnet_find_lnd_by_type(lnd_type);
1461 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
1462 CERROR("Can't load LND %s, module %s, rc=%d\n",
1463 libcfs_lnd2str(lnd_type),
1464 libcfs_lnd2modname(lnd_type), rc);
1465 #ifndef HAVE_MODULE_LOADING_SUPPORT
1466 LCONSOLE_ERROR_MSG(0x104, "Your kernel must be "
1467 "compiled with kernel module "
1468 "loading support.");
1475 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
1476 CERROR("LND %s not supported\n",
1477 libcfs_lnd2str(lnd_type));
1482 lnet_net_lock(LNET_LOCK_EX);
1483 lnd->lnd_refcount++;
1484 lnet_net_unlock(LNET_LOCK_EX);
1488 rc = (lnd->lnd_startup)(ni);
1490 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
1493 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s\n",
1494 rc, libcfs_lnd2str(lnd->lnd_type));
1495 lnet_net_lock(LNET_LOCK_EX);
1496 lnd->lnd_refcount--;
1497 lnet_net_unlock(LNET_LOCK_EX);
1501 /* If given some LND tunable parameters, parse those now to
1502 * override the values in the NI structure. */
1503 if (peer_buf_cr >= 0)
1504 ni->ni_peerrtrcredits = peer_buf_cr;
1505 if (peer_timeout >= 0)
1506 ni->ni_peertimeout = peer_timeout;
1509 * Note: For now, don't allow the user to change
1510 * peertxcredits as this number is used in the
1511 * IB LND to control queue depth.
1512 * if (peer_cr != -1)
1513 * ni->ni_peertxcredits = peer_cr;
1516 ni->ni_maxtxcredits = credits;
1518 LASSERT(ni->ni_peertimeout <= 0 || lnd->lnd_query != NULL);
1520 lnet_net_lock(LNET_LOCK_EX);
1521 /* refcount for ln_nis */
1522 lnet_ni_addref_locked(ni, 0);
1523 list_add_tail(&ni->ni_list, &the_lnet.ln_nis);
1524 if (ni->ni_cpts != NULL) {
1525 lnet_ni_addref_locked(ni, 0);
1526 list_add_tail(&ni->ni_cptlist, &the_lnet.ln_nis_cpt);
1529 lnet_net_unlock(LNET_LOCK_EX);
1531 if (lnd->lnd_type == LOLND) {
1533 LASSERT(the_lnet.ln_loni == NULL);
1534 the_lnet.ln_loni = ni;
1539 if (lnd->lnd_wait != NULL) {
1540 if (the_lnet.ln_eq_waitni == NULL) {
1542 the_lnet.ln_eq_waitni = ni;
1545 # ifndef HAVE_LIBPTHREAD
1546 LCONSOLE_ERROR_MSG(0x106, "LND %s not supported in a "
1547 "single-threaded runtime\n",
1548 libcfs_lnd2str(lnd_type));
1549 /* shutdown the NI since if we get here then it must've already
1552 lnet_shutdown_lndni(ni);
1557 if (ni->ni_peertxcredits == 0 || ni->ni_maxtxcredits == 0) {
1558 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
1559 libcfs_lnd2str(lnd->lnd_type),
1560 ni->ni_peertxcredits == 0 ?
1562 /* shutdown the NI since if we get here then it must've already
1565 lnet_shutdown_lndni(ni);
1569 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
1570 tq->tq_credits_min =
1571 tq->tq_credits_max =
1572 tq->tq_credits = lnet_ni_tq_credits(ni);
1575 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d/%d]\n",
1576 libcfs_nid2str(ni->ni_nid), ni->ni_peertxcredits,
1577 lnet_ni_tq_credits(ni) * LNET_CPT_NUMBER,
1578 ni->ni_peerrtrcredits, ni->ni_peertimeout);
1587 lnet_startup_lndnis(struct list_head *nilist)
1594 while (!list_empty(nilist)) {
1595 ni = list_entry(nilist->next, lnet_ni_t, ni_list);
1596 list_del(&ni->ni_list);
1597 rc = lnet_startup_lndni(ni, -1, -1, -1, -1);
1605 if (the_lnet.ln_eq_waitni != NULL && ni_count > 1) {
1606 lnd_type = the_lnet.ln_eq_waitni->ni_lnd->lnd_type;
1607 LCONSOLE_ERROR_MSG(0x109, "LND %s can only run single-network"
1609 libcfs_lnd2str(lnd_type));
1616 lnet_shutdown_lndnis();
1622 * Initialize LNet library.
1624 * Only userspace program needs to call this function - it's automatically
1625 * called in the kernel at module loading time. Caller has to call LNetFini()
1626 * after a call to LNetInit(), if and only if the latter returned 0. It must
1627 * be called exactly once.
1629 * \return 0 on success, and -ve on failures.
1636 lnet_assert_wire_constants();
1637 LASSERT(!the_lnet.ln_init);
1639 memset(&the_lnet, 0, sizeof(the_lnet));
1641 /* refer to global cfs_cpt_table for now */
1642 the_lnet.ln_cpt_table = cfs_cpt_table;
1643 the_lnet.ln_cpt_number = cfs_cpt_number(cfs_cpt_table);
1645 LASSERT(the_lnet.ln_cpt_number > 0);
1646 if (the_lnet.ln_cpt_number > LNET_CPT_MAX) {
1647 /* we are under risk of consuming all lh_cookie */
1648 CERROR("Can't have %d CPTs for LNet (max allowed is %d), "
1649 "please change setting of CPT-table and retry\n",
1650 the_lnet.ln_cpt_number, LNET_CPT_MAX);
1654 while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number)
1655 the_lnet.ln_cpt_bits++;
1657 rc = lnet_create_locks();
1659 CERROR("Can't create LNet global locks: %d\n", rc);
1663 the_lnet.ln_refcount = 0;
1664 the_lnet.ln_init = 1;
1665 LNetInvalidateHandle(&the_lnet.ln_rc_eqh);
1666 INIT_LIST_HEAD(&the_lnet.ln_lnds);
1667 INIT_LIST_HEAD(&the_lnet.ln_rcd_zombie);
1668 INIT_LIST_HEAD(&the_lnet.ln_rcd_deathrow);
1671 /* The hash table size is the number of bits it takes to express the set
1672 * ln_num_routes, minus 1 (better to under estimate than over so we
1673 * don't waste memory). */
1674 if (rnet_htable_size <= 0)
1675 rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
1676 else if (rnet_htable_size > LNET_REMOTE_NETS_HASH_MAX)
1677 rnet_htable_size = LNET_REMOTE_NETS_HASH_MAX;
1678 the_lnet.ln_remote_nets_hbits = max_t(int, 1,
1679 order_base_2(rnet_htable_size) - 1);
1681 /* All LNDs apart from the LOLND are in separate modules. They
1682 * register themselves when their module loads, and unregister
1683 * themselves when their module is unloaded. */
1685 the_lnet.ln_remote_nets_hbits = 8;
1688 * NB the order here determines default 'networks=' order */
1689 # ifdef HAVE_LIBPTHREAD
1690 LNET_REGISTER_ULND(the_tcplnd);
1693 lnet_register_lnd(&the_lolnd);
1696 EXPORT_SYMBOL(LNetInit);
1699 * Finalize LNet library.
1701 * Only userspace program needs to call this function. It can be called
1704 * \pre LNetInit() called with success.
1705 * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls.
1710 LASSERT(the_lnet.ln_init);
1711 LASSERT(the_lnet.ln_refcount == 0);
1713 while (!list_empty(&the_lnet.ln_lnds))
1714 lnet_unregister_lnd(list_entry(the_lnet.ln_lnds.next,
1716 lnet_destroy_locks();
1718 the_lnet.ln_init = 0;
1720 EXPORT_SYMBOL(LNetFini);
1723 * Set LNet PID and start LNet interfaces, routing, and forwarding.
1725 * Userspace program should call this after a successful call to LNetInit().
1726 * Users must call this function at least once before any other functions.
1727 * For each successful call there must be a corresponding call to
1728 * LNetNIFini(). For subsequent calls to LNetNIInit(), \a requested_pid is
1731 * The PID used by LNet may be different from the one requested.
1734 * \param requested_pid PID requested by the caller.
1736 * \return >= 0 on success, and < 0 error code on failures.
1739 LNetNIInit(lnet_pid_t requested_pid)
1741 int im_a_router = 0;
1744 lnet_ping_info_t *pinfo;
1745 lnet_handle_md_t md_handle;
1746 struct list_head net_head;
1748 INIT_LIST_HEAD(&net_head);
1750 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
1752 LASSERT(the_lnet.ln_init);
1753 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
1755 if (the_lnet.ln_refcount > 0) {
1756 rc = the_lnet.ln_refcount++;
1757 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
1761 rc = lnet_prepare(requested_pid);
1763 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
1767 /* Add in the loopback network */
1768 if (lnet_ni_alloc(LNET_MKNET(LOLND, 0), NULL, &net_head) == NULL) {
1773 /* If LNet is being initialized via DLC it is possible
1774 * that the user requests not to load module parameters (ones which
1775 * are supported by DLC) on initialization. Therefore, make sure not
1776 * to load networks, routes and forwarding from module parameters
1777 * in this case. On cleanup in case of failure only clean up
1778 * routes if it has been loaded */
1779 if (!the_lnet.ln_nis_from_mod_params) {
1780 rc = lnet_parse_networks(&net_head,
1781 lnet_get_networks());
1786 ni_count = lnet_startup_lndnis(&net_head);
1792 if (!the_lnet.ln_nis_from_mod_params) {
1793 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
1797 rc = lnet_check_routes();
1801 rc = lnet_rtrpools_alloc(im_a_router);
1806 rc = lnet_acceptor_start();
1809 the_lnet.ln_refcount = 1;
1810 /* Now I may use my own API functions... */
1812 rc = lnet_ping_info_setup(&pinfo, &md_handle, ni_count, true);
1816 lnet_ping_target_update(pinfo, md_handle);
1818 rc = lnet_router_checker_start();
1825 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
1830 lnet_ping_md_unlink(pinfo, &md_handle);
1831 lnet_ping_info_free(pinfo);
1832 rc2 = LNetEQFree(the_lnet.ln_ping_target_eq);
1835 the_lnet.ln_refcount = 0;
1836 lnet_acceptor_stop();
1838 if (!the_lnet.ln_nis_from_mod_params)
1839 lnet_destroy_routes();
1841 lnet_shutdown_lndnis();
1845 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
1846 while (!list_empty(&net_head)) {
1848 ni = list_entry(net_head.next, struct lnet_ni, ni_list);
1849 list_del_init(&ni->ni_list);
1854 EXPORT_SYMBOL(LNetNIInit);
1857 * Stop LNet interfaces, routing, and forwarding.
1859 * Users must call this function once for each successful call to LNetNIInit().
1860 * Once the LNetNIFini() operation has been started, the results of pending
1861 * API operations are undefined.
1863 * \return always 0 for current implementation.
1868 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
1870 LASSERT (the_lnet.ln_init);
1871 LASSERT (the_lnet.ln_refcount > 0);
1873 if (the_lnet.ln_refcount != 1) {
1874 the_lnet.ln_refcount--;
1876 LASSERT(!the_lnet.ln_niinit_self);
1881 lnet_router_checker_stop();
1882 lnet_ping_target_fini();
1884 /* Teardown fns that use my own API functions BEFORE here */
1885 the_lnet.ln_refcount = 0;
1887 lnet_acceptor_stop();
1888 lnet_destroy_routes();
1889 lnet_shutdown_lndnis();
1893 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
1896 EXPORT_SYMBOL(LNetNIFini);
1899 * Grabs the ni data from the ni structure and fills the out
1902 * \param[in] ni network interface structure
1903 * \param[out] cpt_count the number of cpts the ni is on
1904 * \param[out] nid Network Interface ID
1905 * \param[out] peer_timeout NI peer timeout
1906 * \param[out] peer_tx_crdits NI peer transmit credits
1907 * \param[out] peer_rtr_credits NI peer router credits
1908 * \param[out] max_tx_credits NI max transmit credit
1909 * \param[out] net_config Network configuration
1912 lnet_fill_ni_info(struct lnet_ni *ni, __u32 *cpt_count, __u64 *nid,
1913 int *peer_timeout, int *peer_tx_credits,
1914 int *peer_rtr_credits, int *max_tx_credits,
1915 struct lnet_ioctl_net_config *net_config)
1922 if (net_config == NULL)
1925 CLASSERT(ARRAY_SIZE(ni->ni_interfaces) ==
1926 ARRAY_SIZE(net_config->ni_interfaces));
1928 if (ni->ni_interfaces[0] != NULL) {
1929 for (i = 0; i < ARRAY_SIZE(ni->ni_interfaces); i++) {
1930 if (ni->ni_interfaces[i] != NULL) {
1931 strncpy(net_config->ni_interfaces[i],
1932 ni->ni_interfaces[i],
1933 sizeof(net_config->ni_interfaces[i]));
1939 *peer_timeout = ni->ni_peertimeout;
1940 *peer_tx_credits = ni->ni_peertxcredits;
1941 *peer_rtr_credits = ni->ni_peerrtrcredits;
1942 *max_tx_credits = ni->ni_maxtxcredits;
1944 net_config->ni_status = ni->ni_status->ns_status;
1947 ni->ni_cpts != NULL && i < ni->ni_ncpts &&
1948 i < LNET_MAX_SHOW_NUM_CPT;
1950 net_config->ni_cpts[i] = ni->ni_cpts[i];
1952 *cpt_count = ni->ni_ncpts;
1956 lnet_get_net_config(int idx, __u32 *cpt_count, __u64 *nid, int *peer_timeout,
1957 int *peer_tx_credits, int *peer_rtr_credits,
1958 int *max_tx_credits,
1959 struct lnet_ioctl_net_config *net_config)
1962 struct list_head *tmp;
1966 cpt = lnet_net_lock_current();
1968 list_for_each(tmp, &the_lnet.ln_nis) {
1969 ni = list_entry(tmp, lnet_ni_t, ni_list);
1973 lnet_fill_ni_info(ni, cpt_count, nid, peer_timeout,
1974 peer_tx_credits, peer_rtr_credits,
1975 max_tx_credits, net_config);
1981 lnet_net_unlock(cpt);
1986 lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
1987 __s32 peer_timeout, __s32 peer_cr, __s32 peer_buf_cr,
1990 lnet_ping_info_t *pinfo;
1991 lnet_handle_md_t md_handle;
1993 struct list_head net_head;
1996 INIT_LIST_HEAD(&net_head);
1998 /* Create a ni structure for the network string */
1999 rc = lnet_parse_networks(&net_head, nets);
2001 return rc == 0 ? -EINVAL : rc;
2003 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2006 rc = -EINVAL; /* only add one interface per call */
2010 rc = lnet_ping_info_setup(&pinfo, &md_handle, 1 + lnet_get_ni_count(),
2015 ni = list_entry(net_head.next, struct lnet_ni, ni_list);
2016 list_del_init(&ni->ni_list);
2018 rc = lnet_startup_lndni(ni, peer_timeout, peer_cr,
2019 peer_buf_cr, credits);
2023 lnet_ping_target_update(pinfo, md_handle);
2024 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2029 lnet_ping_md_unlink(pinfo, &md_handle);
2030 lnet_ping_info_free(pinfo);
2032 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2033 while (!list_empty(&net_head)) {
2034 ni = list_entry(net_head.next, struct lnet_ni, ni_list);
2035 list_del_init(&ni->ni_list);
2042 lnet_dyn_del_ni(__u32 net)
2045 lnet_ping_info_t *pinfo;
2046 lnet_handle_md_t md_handle;
2049 /* don't allow userspace to shutdown the LOLND */
2050 if (LNET_NETTYP(net) == LOLND)
2053 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2054 /* create and link a new ping info, before removing the old one */
2055 rc = lnet_ping_info_setup(&pinfo, &md_handle,
2056 lnet_get_ni_count() - 1, false);
2060 ni = lnet_net2ni(net);
2066 /* decrement the reference counter taken by lnet_net2ni() */
2067 lnet_ni_decref_locked(ni, 0);
2069 lnet_shutdown_lndni(ni);
2070 lnet_ping_target_update(pinfo, md_handle);
2073 lnet_ping_md_unlink(pinfo, &md_handle);
2074 lnet_ping_info_free(pinfo);
2076 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2082 * This is an ugly hack to export IOC_LIBCFS_DEBUG_PEER and
2083 * IOC_LIBCFS_PORTALS_COMPATIBILITY commands to users, by tweaking the LNet
2084 * internal ioctl handler.
2086 * IOC_LIBCFS_PORTALS_COMPATIBILITY is now deprecated, don't use it.
2088 * \param cmd IOC_LIBCFS_DEBUG_PEER to print debugging data about a peer.
2089 * The data will be printed to system console. Don't use it excessively.
2090 * \param arg A pointer to lnet_process_id_t, process ID of the peer.
2092 * \return Always return 0 when called by users directly (i.e., not via ioctl).
2095 LNetCtl(unsigned int cmd, void *arg)
2097 struct libcfs_ioctl_data *data = arg;
2098 struct lnet_ioctl_config_data *config;
2099 lnet_process_id_t id = {0};
2103 CLASSERT(LIBCFS_IOC_DATA_MAX >= sizeof(struct lnet_ioctl_net_config) +
2104 sizeof(struct lnet_ioctl_config_data));
2105 LASSERT(the_lnet.ln_init);
2108 case IOC_LIBCFS_GET_NI:
2109 rc = LNetGetId(data->ioc_count, &id);
2110 data->ioc_nid = id.nid;
2113 case IOC_LIBCFS_FAIL_NID:
2114 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
2116 case IOC_LIBCFS_ADD_ROUTE:
2119 if (config->cfg_hdr.ioc_len < sizeof(*config))
2122 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2123 rc = lnet_add_route(config->cfg_net,
2124 config->cfg_config_u.cfg_route.rtr_hop,
2126 config->cfg_config_u.cfg_route.
2128 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2129 return (rc != 0) ? rc : lnet_check_routes();
2131 case IOC_LIBCFS_DEL_ROUTE:
2134 if (config->cfg_hdr.ioc_len < sizeof(*config))
2137 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2138 rc = lnet_del_route(config->cfg_net, config->cfg_nid);
2139 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2142 case IOC_LIBCFS_GET_ROUTE:
2145 if (config->cfg_hdr.ioc_len < sizeof(*config))
2148 return lnet_get_route(config->cfg_count,
2150 &config->cfg_config_u.cfg_route.rtr_hop,
2152 &config->cfg_config_u.cfg_route.rtr_flags,
2153 &config->cfg_config_u.cfg_route.
2156 case IOC_LIBCFS_GET_NET: {
2157 struct lnet_ioctl_net_config *net_config;
2158 size_t total = sizeof(*config) + sizeof(*net_config);
2162 if (config->cfg_hdr.ioc_len < total)
2165 net_config = (struct lnet_ioctl_net_config *)
2167 if (config == NULL || net_config == NULL)
2170 return lnet_get_net_config(config->cfg_count,
2173 &config->cfg_config_u.
2174 cfg_net.net_peer_timeout,
2175 &config->cfg_config_u.cfg_net.
2176 net_peer_tx_credits,
2177 &config->cfg_config_u.cfg_net.
2178 net_peer_rtr_credits,
2179 &config->cfg_config_u.cfg_net.
2184 case IOC_LIBCFS_GET_LNET_STATS:
2186 struct lnet_ioctl_lnet_stats *lnet_stats = arg;
2188 if (lnet_stats->st_hdr.ioc_len < sizeof(*lnet_stats))
2191 lnet_counters_get(&lnet_stats->st_cntrs);
2195 #if defined(__KERNEL__) && defined(LNET_ROUTER)
2196 case IOC_LIBCFS_CONFIG_RTR:
2199 if (config->cfg_hdr.ioc_len < sizeof(*config))
2202 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2203 if (config->cfg_config_u.cfg_buffers.buf_enable) {
2204 rc = lnet_rtrpools_enable();
2205 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2208 lnet_rtrpools_disable();
2209 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2212 case IOC_LIBCFS_ADD_BUF:
2215 if (config->cfg_hdr.ioc_len < sizeof(*config))
2218 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2219 rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
2221 config->cfg_config_u.cfg_buffers.
2223 config->cfg_config_u.cfg_buffers.
2225 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2229 case IOC_LIBCFS_GET_BUF: {
2230 struct lnet_ioctl_pool_cfg *pool_cfg;
2231 size_t total = sizeof(*config) + sizeof(*pool_cfg);
2235 if (config->cfg_hdr.ioc_len < total)
2238 pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
2239 return lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
2242 case IOC_LIBCFS_GET_PEER_INFO: {
2243 struct lnet_ioctl_peer *peer_info = arg;
2245 if (peer_info->pr_hdr.ioc_len < sizeof(*peer_info))
2248 return lnet_get_peer_info(
2249 peer_info->pr_count,
2251 peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
2252 &peer_info->pr_lnd_u.pr_peer_credits.cr_ncpt,
2253 &peer_info->pr_lnd_u.pr_peer_credits.cr_refcount,
2254 &peer_info->pr_lnd_u.pr_peer_credits.cr_ni_peer_tx_credits,
2255 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_credits,
2256 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_rtr_credits,
2257 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_min_rtr_credits,
2258 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_qnob);
2261 case IOC_LIBCFS_NOTIFY_ROUTER:
2262 return lnet_notify(NULL, data->ioc_nid, data->ioc_flags,
2263 cfs_time_current() -
2264 cfs_time_seconds(cfs_time_current_sec() -
2265 (time_t)data->ioc_u64[0]));
2267 case IOC_LIBCFS_PORTALS_COMPATIBILITY:
2268 /* This can be removed once lustre stops calling it */
2271 case IOC_LIBCFS_LNET_DIST:
2272 rc = LNetDist(data->ioc_nid, &data->ioc_nid, &data->ioc_u32[1]);
2273 if (rc < 0 && rc != -EHOSTUNREACH)
2276 data->ioc_u32[0] = rc;
2279 case IOC_LIBCFS_TESTPROTOCOMPAT:
2280 lnet_net_lock(LNET_LOCK_EX);
2281 the_lnet.ln_testprotocompat = data->ioc_flags;
2282 lnet_net_unlock(LNET_LOCK_EX);
2285 case IOC_LIBCFS_LNET_FAULT:
2286 return lnet_fault_ctl(data->ioc_flags, data);
2288 case IOC_LIBCFS_PING:
2289 id.nid = data->ioc_nid;
2290 id.pid = data->ioc_u32[0];
2291 rc = lnet_ping(id, data->ioc_u32[1], /* timeout */
2292 (lnet_process_id_t __user *)data->ioc_pbuf1,
2293 data->ioc_plen1/sizeof(lnet_process_id_t));
2296 data->ioc_count = rc;
2299 case IOC_LIBCFS_DEBUG_PEER: {
2300 /* CAVEAT EMPTOR: this one designed for calling directly; not
2302 id = *((lnet_process_id_t *) arg);
2304 lnet_debug_peer(id.nid);
2306 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2308 CDEBUG(D_WARNING, "No NI for %s\n", libcfs_id2str(id));
2310 if (ni->ni_lnd->lnd_ctl == NULL) {
2311 CDEBUG(D_WARNING, "No ctl for %s\n",
2314 (void)ni->ni_lnd->lnd_ctl(ni, cmd, arg);
2323 ni = lnet_net2ni(data->ioc_net);
2327 if (ni->ni_lnd->lnd_ctl == NULL)
2330 rc = ni->ni_lnd->lnd_ctl(ni, cmd, arg);
2337 EXPORT_SYMBOL(LNetCtl);
2340 * Retrieve the lnet_process_id_t ID of LNet interface at \a index. Note that
2341 * all interfaces share a same PID, as requested by LNetNIInit().
2343 * \param index Index of the interface to look up.
2344 * \param id On successful return, this location will hold the
2345 * lnet_process_id_t ID of the interface.
2347 * \retval 0 If an interface exists at \a index.
2348 * \retval -ENOENT If no interface has been found.
2351 LNetGetId(unsigned int index, lnet_process_id_t *id)
2354 struct list_head *tmp;
2358 LASSERT(the_lnet.ln_init);
2359 LASSERT(the_lnet.ln_refcount > 0);
2361 cpt = lnet_net_lock_current();
2363 list_for_each(tmp, &the_lnet.ln_nis) {
2367 ni = list_entry(tmp, lnet_ni_t, ni_list);
2369 id->nid = ni->ni_nid;
2370 id->pid = the_lnet.ln_pid;
2375 lnet_net_unlock(cpt);
2378 EXPORT_SYMBOL(LNetGetId);
2381 * Print a string representation of handle \a h into buffer \a str of
2385 LNetSnprintHandle(char *str, int len, lnet_handle_any_t h)
2387 snprintf(str, len, LPX64, h.cookie);
2389 EXPORT_SYMBOL(LNetSnprintHandle);
2392 lnet_ping(lnet_process_id_t id, int timeout_ms, lnet_process_id_t __user *ids,
2395 lnet_handle_eq_t eqh;
2396 lnet_handle_md_t mdh;
2398 lnet_md_t md = { NULL };
2402 const int a_long_time = 60000; /* mS */
2404 lnet_ping_info_t *info;
2405 lnet_process_id_t tmpid;
2412 infosz = offsetof(lnet_ping_info_t, pi_ni[n_ids]);
2415 id.nid == LNET_NID_ANY ||
2416 timeout_ms > 500000 || /* arbitrary limit! */
2417 n_ids > 20) /* arbitrary limit! */
2420 if (id.pid == LNET_PID_ANY)
2421 id.pid = LNET_PID_LUSTRE;
2423 LIBCFS_ALLOC(info, infosz);
2427 /* NB 2 events max (including any unlink event) */
2428 rc = LNetEQAlloc(2, LNET_EQ_HANDLER_NONE, &eqh);
2430 CERROR("Can't allocate EQ: %d\n", rc);
2434 /* initialize md content */
2437 md.threshold = 2; /*GET/REPLY*/
2439 md.options = LNET_MD_TRUNCATE;
2443 rc = LNetMDBind(md, LNET_UNLINK, &mdh);
2445 CERROR("Can't bind MD: %d\n", rc);
2449 rc = LNetGet(LNET_NID_ANY, mdh, id,
2450 LNET_RESERVED_PORTAL,
2451 LNET_PROTO_PING_MATCHBITS, 0);
2454 /* Don't CERROR; this could be deliberate! */
2456 rc2 = LNetMDUnlink(mdh);
2459 /* NB must wait for the UNLINK event below... */
2461 timeout_ms = a_long_time;
2465 /* MUST block for unlink to complete */
2467 blocked = cfs_block_allsigs();
2469 rc2 = LNetEQPoll(&eqh, 1, timeout_ms, &event, &which);
2472 cfs_restore_sigs(blocked);
2474 CDEBUG(D_NET, "poll %d(%d %d)%s\n", rc2,
2475 (rc2 <= 0) ? -1 : event.type,
2476 (rc2 <= 0) ? -1 : event.status,
2477 (rc2 > 0 && event.unlinked) ? " unlinked" : "");
2479 LASSERT(rc2 != -EOVERFLOW); /* can't miss anything */
2481 if (rc2 <= 0 || event.status != 0) {
2482 /* timeout or error */
2483 if (!replied && rc == 0)
2484 rc = (rc2 < 0) ? rc2 :
2485 (rc2 == 0) ? -ETIMEDOUT :
2489 /* Ensure completion in finite time... */
2491 /* No assertion (racing with network) */
2493 timeout_ms = a_long_time;
2494 } else if (rc2 == 0) {
2495 /* timed out waiting for unlink */
2496 CWARN("ping %s: late network completion\n",
2499 } else if (event.type == LNET_EVENT_REPLY) {
2504 } while (rc2 <= 0 || !event.unlinked);
2508 CWARN("%s: Unexpected rc >= 0 but no reply!\n",
2515 LASSERT(nob >= 0 && nob <= infosz);
2517 rc = -EPROTO; /* if I can't parse... */
2520 /* can't check magic/version */
2521 CERROR("%s: ping info too short %d\n",
2522 libcfs_id2str(id), nob);
2526 if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) {
2527 lnet_swap_pinginfo(info);
2528 } else if (info->pi_magic != LNET_PROTO_PING_MAGIC) {
2529 CERROR("%s: Unexpected magic %08x\n",
2530 libcfs_id2str(id), info->pi_magic);
2534 if ((info->pi_features & LNET_PING_FEAT_NI_STATUS) == 0) {
2535 CERROR("%s: ping w/o NI status: 0x%x\n",
2536 libcfs_id2str(id), info->pi_features);
2540 if (nob < offsetof(lnet_ping_info_t, pi_ni[0])) {
2541 CERROR("%s: Short reply %d(%d min)\n", libcfs_id2str(id),
2542 nob, (int)offsetof(lnet_ping_info_t, pi_ni[0]));
2546 if (info->pi_nnis < n_ids)
2547 n_ids = info->pi_nnis;
2549 if (nob < offsetof(lnet_ping_info_t, pi_ni[n_ids])) {
2550 CERROR("%s: Short reply %d(%d expected)\n", libcfs_id2str(id),
2551 nob, (int)offsetof(lnet_ping_info_t, pi_ni[n_ids]));
2555 rc = -EFAULT; /* If I SEGV... */
2557 for (i = 0; i < n_ids; i++) {
2558 tmpid.pid = info->pi_pid;
2559 tmpid.nid = info->pi_ni[i].ns_nid;
2560 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid)))
2566 rc2 = LNetEQFree(eqh);
2568 CERROR("rc2 %d\n", rc2);
2572 LIBCFS_FREE(info, infosz);