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 void lnet_ping_target_fini(void);
72 static int lnet_ping(lnet_process_id_t id, int timeout_ms,
73 lnet_process_id_t *ids, int n_ids);
82 lnet_get_networks(void)
87 if (*networks != 0 && *ip2nets != 0) {
88 LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
89 "'ip2nets' but not both at once\n");
94 rc = lnet_parse_ip2nets(&nets, ip2nets);
95 return (rc == 0) ? nets : NULL;
105 lnet_init_locks(void)
107 spin_lock_init(&the_lnet.ln_eq_wait_lock);
108 init_waitqueue_head(&the_lnet.ln_eq_waitq);
109 mutex_init(&the_lnet.ln_lnd_mutex);
110 mutex_init(&the_lnet.ln_api_mutex);
114 lnet_fini_locks(void)
121 lnet_get_routes(void)
123 char *str = getenv("LNET_ROUTES");
125 return (str == NULL) ? "" : str;
129 lnet_get_networks (void)
131 static char default_networks[256];
132 char *networks = getenv("LNET_NETWORKS");
137 struct list_head *tmp;
139 if (networks != NULL)
142 /* In userland, the default 'networks=' is the list of known net types */
143 len = sizeof(default_networks);
144 str = default_networks;
148 list_for_each(tmp, &the_lnet.ln_lnds) {
149 lnd_t *lnd = list_entry(tmp, lnd_t, lnd_list);
151 nob = snprintf(str, len, "%s%s", sep,
152 libcfs_lnd2str(lnd->lnd_type));
154 /* overflowed the string; leave it where it was */
163 return default_networks;
166 # ifndef HAVE_LIBPTHREAD
168 static void lnet_init_locks(void)
170 the_lnet.ln_eq_wait_lock = 0;
171 the_lnet.ln_lnd_mutex = 0;
172 the_lnet.ln_api_mutex = 0;
175 static void lnet_fini_locks(void)
177 LASSERT(the_lnet.ln_api_mutex == 0);
178 LASSERT(the_lnet.ln_lnd_mutex == 0);
179 LASSERT(the_lnet.ln_eq_wait_lock == 0);
184 static void lnet_init_locks(void)
186 pthread_cond_init(&the_lnet.ln_eq_cond, NULL);
187 pthread_mutex_init(&the_lnet.ln_eq_wait_lock, NULL);
188 pthread_mutex_init(&the_lnet.ln_lnd_mutex, NULL);
189 pthread_mutex_init(&the_lnet.ln_api_mutex, NULL);
192 static void lnet_fini_locks(void)
194 pthread_mutex_destroy(&the_lnet.ln_api_mutex);
195 pthread_mutex_destroy(&the_lnet.ln_lnd_mutex);
196 pthread_mutex_destroy(&the_lnet.ln_eq_wait_lock);
197 pthread_cond_destroy(&the_lnet.ln_eq_cond);
204 lnet_create_remote_nets_table(void)
207 struct list_head *hash;
209 LASSERT(the_lnet.ln_remote_nets_hash == NULL);
210 LASSERT(the_lnet.ln_remote_nets_hbits > 0);
211 LIBCFS_ALLOC(hash, LNET_REMOTE_NETS_HASH_SIZE * sizeof(*hash));
213 CERROR("Failed to create remote nets hash table\n");
217 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
218 INIT_LIST_HEAD(&hash[i]);
219 the_lnet.ln_remote_nets_hash = hash;
224 lnet_destroy_remote_nets_table(void)
228 if (the_lnet.ln_remote_nets_hash == NULL)
231 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
232 LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
234 LIBCFS_FREE(the_lnet.ln_remote_nets_hash,
235 LNET_REMOTE_NETS_HASH_SIZE *
236 sizeof(the_lnet.ln_remote_nets_hash[0]));
237 the_lnet.ln_remote_nets_hash = NULL;
241 lnet_destroy_locks(void)
243 if (the_lnet.ln_res_lock != NULL) {
244 cfs_percpt_lock_free(the_lnet.ln_res_lock);
245 the_lnet.ln_res_lock = NULL;
248 if (the_lnet.ln_net_lock != NULL) {
249 cfs_percpt_lock_free(the_lnet.ln_net_lock);
250 the_lnet.ln_net_lock = NULL;
257 lnet_create_locks(void)
261 the_lnet.ln_res_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
262 if (the_lnet.ln_res_lock == NULL)
265 the_lnet.ln_net_lock = cfs_percpt_lock_alloc(lnet_cpt_table());
266 if (the_lnet.ln_net_lock == NULL)
272 lnet_destroy_locks();
276 static void lnet_assert_wire_constants(void)
278 /* Wire protocol assertions generated by 'wirecheck'
279 * running on Linux robert.bartonsoftware.com 2.6.8-1.521
280 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux
281 * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) */
284 CLASSERT (LNET_PROTO_TCP_MAGIC == 0xeebc0ded);
285 CLASSERT (LNET_PROTO_TCP_VERSION_MAJOR == 1);
286 CLASSERT (LNET_PROTO_TCP_VERSION_MINOR == 0);
287 CLASSERT (LNET_MSG_ACK == 0);
288 CLASSERT (LNET_MSG_PUT == 1);
289 CLASSERT (LNET_MSG_GET == 2);
290 CLASSERT (LNET_MSG_REPLY == 3);
291 CLASSERT (LNET_MSG_HELLO == 4);
293 /* Checks for struct ptl_handle_wire_t */
294 CLASSERT ((int)sizeof(lnet_handle_wire_t) == 16);
295 CLASSERT ((int)offsetof(lnet_handle_wire_t, wh_interface_cookie) == 0);
296 CLASSERT ((int)sizeof(((lnet_handle_wire_t *)0)->wh_interface_cookie) == 8);
297 CLASSERT ((int)offsetof(lnet_handle_wire_t, wh_object_cookie) == 8);
298 CLASSERT ((int)sizeof(((lnet_handle_wire_t *)0)->wh_object_cookie) == 8);
300 /* Checks for struct lnet_magicversion_t */
301 CLASSERT ((int)sizeof(lnet_magicversion_t) == 8);
302 CLASSERT ((int)offsetof(lnet_magicversion_t, magic) == 0);
303 CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->magic) == 4);
304 CLASSERT ((int)offsetof(lnet_magicversion_t, version_major) == 4);
305 CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->version_major) == 2);
306 CLASSERT ((int)offsetof(lnet_magicversion_t, version_minor) == 6);
307 CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->version_minor) == 2);
309 /* Checks for struct lnet_hdr_t */
310 CLASSERT ((int)sizeof(lnet_hdr_t) == 72);
311 CLASSERT ((int)offsetof(lnet_hdr_t, dest_nid) == 0);
312 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->dest_nid) == 8);
313 CLASSERT ((int)offsetof(lnet_hdr_t, src_nid) == 8);
314 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->src_nid) == 8);
315 CLASSERT ((int)offsetof(lnet_hdr_t, dest_pid) == 16);
316 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->dest_pid) == 4);
317 CLASSERT ((int)offsetof(lnet_hdr_t, src_pid) == 20);
318 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->src_pid) == 4);
319 CLASSERT ((int)offsetof(lnet_hdr_t, type) == 24);
320 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->type) == 4);
321 CLASSERT ((int)offsetof(lnet_hdr_t, payload_length) == 28);
322 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->payload_length) == 4);
323 CLASSERT ((int)offsetof(lnet_hdr_t, msg) == 32);
324 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg) == 40);
327 CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.dst_wmd) == 32);
328 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.dst_wmd) == 16);
329 CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.match_bits) == 48);
330 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.match_bits) == 8);
331 CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.mlength) == 56);
332 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.mlength) == 4);
335 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.ack_wmd) == 32);
336 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.ack_wmd) == 16);
337 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.match_bits) == 48);
338 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.match_bits) == 8);
339 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.hdr_data) == 56);
340 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.hdr_data) == 8);
341 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.ptl_index) == 64);
342 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.ptl_index) == 4);
343 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.offset) == 68);
344 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.offset) == 4);
347 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.return_wmd) == 32);
348 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.return_wmd) == 16);
349 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.match_bits) == 48);
350 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.match_bits) == 8);
351 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.ptl_index) == 56);
352 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.ptl_index) == 4);
353 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.src_offset) == 60);
354 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.src_offset) == 4);
355 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.sink_length) == 64);
356 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.sink_length) == 4);
359 CLASSERT ((int)offsetof(lnet_hdr_t, msg.reply.dst_wmd) == 32);
360 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.reply.dst_wmd) == 16);
363 CLASSERT ((int)offsetof(lnet_hdr_t, msg.hello.incarnation) == 32);
364 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.hello.incarnation) == 8);
365 CLASSERT ((int)offsetof(lnet_hdr_t, msg.hello.type) == 40);
366 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.hello.type) == 4);
370 lnet_find_lnd_by_type (int type)
373 struct list_head *tmp;
375 /* holding lnd mutex */
376 list_for_each(tmp, &the_lnet.ln_lnds) {
377 lnd = list_entry(tmp, lnd_t, lnd_list);
379 if ((int)lnd->lnd_type == type)
386 lnet_register_lnd (lnd_t *lnd)
388 LNET_MUTEX_LOCK(&the_lnet.ln_lnd_mutex);
390 LASSERT(the_lnet.ln_init);
391 LASSERT(libcfs_isknown_lnd(lnd->lnd_type));
392 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
394 list_add_tail(&lnd->lnd_list, &the_lnet.ln_lnds);
395 lnd->lnd_refcount = 0;
397 CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type));
399 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
401 EXPORT_SYMBOL(lnet_register_lnd);
404 lnet_unregister_lnd (lnd_t *lnd)
406 LNET_MUTEX_LOCK(&the_lnet.ln_lnd_mutex);
408 LASSERT(the_lnet.ln_init);
409 LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
410 LASSERT(lnd->lnd_refcount == 0);
412 list_del(&lnd->lnd_list);
413 CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type));
415 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
417 EXPORT_SYMBOL(lnet_unregister_lnd);
420 lnet_counters_get(lnet_counters_t *counters)
422 lnet_counters_t *ctr;
425 memset(counters, 0, sizeof(*counters));
427 lnet_net_lock(LNET_LOCK_EX);
429 cfs_percpt_for_each(ctr, i, the_lnet.ln_counters) {
430 counters->msgs_max += ctr->msgs_max;
431 counters->msgs_alloc += ctr->msgs_alloc;
432 counters->errors += ctr->errors;
433 counters->send_count += ctr->send_count;
434 counters->recv_count += ctr->recv_count;
435 counters->route_count += ctr->route_count;
436 counters->drop_count += ctr->drop_count;
437 counters->send_length += ctr->send_length;
438 counters->recv_length += ctr->recv_length;
439 counters->route_length += ctr->route_length;
440 counters->drop_length += ctr->drop_length;
443 lnet_net_unlock(LNET_LOCK_EX);
445 EXPORT_SYMBOL(lnet_counters_get);
448 lnet_counters_reset(void)
450 lnet_counters_t *counters;
453 lnet_net_lock(LNET_LOCK_EX);
455 cfs_percpt_for_each(counters, i, the_lnet.ln_counters)
456 memset(counters, 0, sizeof(lnet_counters_t));
458 lnet_net_unlock(LNET_LOCK_EX);
460 EXPORT_SYMBOL(lnet_counters_reset);
462 #ifdef LNET_USE_LIB_FREELIST
465 lnet_freelist_init(lnet_freelist_t *fl, int n, int size)
471 size += offsetof (lnet_freeobj_t, fo_contents);
473 LIBCFS_ALLOC(space, n * size);
477 INIT_LIST_HEAD(&fl->fl_list);
480 fl->fl_objsize = size;
483 list_add((struct list_head *)space, &fl->fl_list);
491 lnet_freelist_fini(lnet_freelist_t *fl)
493 struct list_head *el;
496 if (fl->fl_nobjs == 0)
500 for (el = fl->fl_list.next; el != &fl->fl_list; el = el->next)
503 LASSERT (count == fl->fl_nobjs);
505 LIBCFS_FREE(fl->fl_objs, fl->fl_nobjs * fl->fl_objsize);
506 memset (fl, 0, sizeof (*fl));
509 #endif /* LNET_USE_LIB_FREELIST */
511 static __u64 lnet_create_interface_cookie(void)
513 /* NB the interface cookie in wire handles guards against delayed
514 * replies and ACKs appearing valid after reboot. Initialisation time,
515 * even if it's only implemented to millisecond resolution is probably
516 * easily good enough. */
520 int rc = gettimeofday (&tv, NULL);
523 do_gettimeofday(&tv);
527 cookie += tv.tv_usec;
532 lnet_res_type2str(int type)
537 case LNET_COOKIE_TYPE_MD:
539 case LNET_COOKIE_TYPE_ME:
541 case LNET_COOKIE_TYPE_EQ:
547 lnet_res_container_cleanup(struct lnet_res_container *rec)
551 if (rec->rec_type == 0) /* not set yet, it's uninitialized */
554 while (!list_empty(&rec->rec_active)) {
555 struct list_head *e = rec->rec_active.next;
558 if (rec->rec_type == LNET_COOKIE_TYPE_EQ) {
559 lnet_eq_free(list_entry(e, lnet_eq_t, eq_list));
561 } else if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
562 lnet_md_free(list_entry(e, lnet_libmd_t, md_list));
564 } else { /* NB: Active MEs should be attached on portals */
571 /* Found alive MD/ME/EQ, user really should unlink/free
572 * all of them before finalize LNet, but if someone didn't,
573 * we have to recycle garbage for him */
574 CERROR("%d active elements on exit of %s container\n",
575 count, lnet_res_type2str(rec->rec_type));
578 #ifdef LNET_USE_LIB_FREELIST
579 lnet_freelist_fini(&rec->rec_freelist);
581 if (rec->rec_lh_hash != NULL) {
582 LIBCFS_FREE(rec->rec_lh_hash,
583 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
584 rec->rec_lh_hash = NULL;
587 rec->rec_type = 0; /* mark it as finalized */
591 lnet_res_container_setup(struct lnet_res_container *rec,
592 int cpt, int type, int objnum, int objsz)
597 LASSERT(rec->rec_type == 0);
599 rec->rec_type = type;
600 INIT_LIST_HEAD(&rec->rec_active);
602 #ifdef LNET_USE_LIB_FREELIST
603 memset(&rec->rec_freelist, 0, sizeof(rec->rec_freelist));
604 rc = lnet_freelist_init(&rec->rec_freelist, objnum, objsz);
608 rec->rec_lh_cookie = (cpt << LNET_COOKIE_TYPE_BITS) | type;
610 /* Arbitrary choice of hash table size */
611 LIBCFS_CPT_ALLOC(rec->rec_lh_hash, lnet_cpt_table(), cpt,
612 LNET_LH_HASH_SIZE * sizeof(rec->rec_lh_hash[0]));
613 if (rec->rec_lh_hash == NULL) {
618 for (i = 0; i < LNET_LH_HASH_SIZE; i++)
619 INIT_LIST_HEAD(&rec->rec_lh_hash[i]);
624 CERROR("Failed to setup %s resource container\n",
625 lnet_res_type2str(type));
626 lnet_res_container_cleanup(rec);
631 lnet_res_containers_destroy(struct lnet_res_container **recs)
633 struct lnet_res_container *rec;
636 cfs_percpt_for_each(rec, i, recs)
637 lnet_res_container_cleanup(rec);
639 cfs_percpt_free(recs);
642 static struct lnet_res_container **
643 lnet_res_containers_create(int type, int objnum, int objsz)
645 struct lnet_res_container **recs;
646 struct lnet_res_container *rec;
650 recs = cfs_percpt_alloc(lnet_cpt_table(), sizeof(*rec));
652 CERROR("Failed to allocate %s resource containers\n",
653 lnet_res_type2str(type));
657 cfs_percpt_for_each(rec, i, recs) {
658 rc = lnet_res_container_setup(rec, i, type, objnum, objsz);
660 lnet_res_containers_destroy(recs);
669 lnet_res_lh_lookup(struct lnet_res_container *rec, __u64 cookie)
671 /* ALWAYS called with lnet_res_lock held */
672 struct list_head *head;
673 lnet_libhandle_t *lh;
676 if ((cookie & LNET_COOKIE_MASK) != rec->rec_type)
679 hash = cookie >> (LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS);
680 head = &rec->rec_lh_hash[hash & LNET_LH_HASH_MASK];
682 list_for_each_entry(lh, head, lh_hash_chain) {
683 if (lh->lh_cookie == cookie)
691 lnet_res_lh_initialize(struct lnet_res_container *rec, lnet_libhandle_t *lh)
693 /* ALWAYS called with lnet_res_lock held */
694 unsigned int ibits = LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS;
697 lh->lh_cookie = rec->rec_lh_cookie;
698 rec->rec_lh_cookie += 1 << ibits;
700 hash = (lh->lh_cookie >> ibits) & LNET_LH_HASH_MASK;
702 list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
707 * Reserved API - do not use.
708 * Temporary workaround to allow uOSS and test programs force server
709 * mode in userspace. See comments near ln_server_mode_flag in
710 * lnet/lib-types.h */
714 the_lnet.ln_server_mode_flag = 1;
718 static int lnet_unprepare(void);
721 lnet_prepare(lnet_pid_t requested_pid)
723 /* Prepare to bring up the network */
724 struct lnet_res_container **recs;
727 if (requested_pid == LNET_PID_ANY) {
728 /* Don't instantiate LNET just for me */
732 LASSERT (the_lnet.ln_refcount == 0);
734 the_lnet.ln_routing = 0;
737 LASSERT ((requested_pid & LNET_PID_USERFLAG) == 0);
738 the_lnet.ln_pid = requested_pid;
740 if (the_lnet.ln_server_mode_flag) {/* server case (uOSS) */
741 LASSERT ((requested_pid & LNET_PID_USERFLAG) == 0);
743 if (current_uid() != 0) /* Only root can run user-space server */
745 the_lnet.ln_pid = requested_pid;
747 } else {/* client case (liblustre) */
749 /* My PID must be unique on this node and flag I'm userspace */
750 the_lnet.ln_pid = getpid() | LNET_PID_USERFLAG;
754 INIT_LIST_HEAD(&the_lnet.ln_test_peers);
755 INIT_LIST_HEAD(&the_lnet.ln_nis);
756 INIT_LIST_HEAD(&the_lnet.ln_nis_cpt);
757 INIT_LIST_HEAD(&the_lnet.ln_nis_zombie);
758 INIT_LIST_HEAD(&the_lnet.ln_routers);
759 INIT_LIST_HEAD(&the_lnet.ln_drop_rules);
760 INIT_LIST_HEAD(&the_lnet.ln_delay_rules);
762 rc = lnet_create_remote_nets_table();
766 the_lnet.ln_interface_cookie = lnet_create_interface_cookie();
768 the_lnet.ln_counters = cfs_percpt_alloc(lnet_cpt_table(),
769 sizeof(lnet_counters_t));
770 if (the_lnet.ln_counters == NULL) {
771 CERROR("Failed to allocate counters for LNet\n");
776 rc = lnet_peer_tables_create();
780 rc = lnet_msg_containers_create();
784 rc = lnet_res_container_setup(&the_lnet.ln_eq_container, 0,
785 LNET_COOKIE_TYPE_EQ, LNET_FL_MAX_EQS,
790 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_ME, LNET_FL_MAX_MES,
795 the_lnet.ln_me_containers = recs;
797 recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD, LNET_FL_MAX_MDS,
798 sizeof(lnet_libmd_t));
802 the_lnet.ln_md_containers = recs;
804 rc = lnet_portals_create();
806 CERROR("Failed to create portals for LNet: %d\n", rc);
818 lnet_unprepare (void)
820 /* NB no LNET_LOCK since this is the last reference. All LND instances
821 * have shut down already, so it is safe to unlink and free all
822 * descriptors, even those that appear committed to a network op (eg MD
823 * with non-zero pending count) */
825 lnet_fail_nid(LNET_NID_ANY, 0);
827 LASSERT(the_lnet.ln_refcount == 0);
828 LASSERT(list_empty(&the_lnet.ln_test_peers));
829 LASSERT(list_empty(&the_lnet.ln_nis));
830 LASSERT(list_empty(&the_lnet.ln_nis_cpt));
831 LASSERT(list_empty(&the_lnet.ln_nis_zombie));
833 lnet_portals_destroy();
835 if (the_lnet.ln_md_containers != NULL) {
836 lnet_res_containers_destroy(the_lnet.ln_md_containers);
837 the_lnet.ln_md_containers = NULL;
840 if (the_lnet.ln_me_containers != NULL) {
841 lnet_res_containers_destroy(the_lnet.ln_me_containers);
842 the_lnet.ln_me_containers = NULL;
845 lnet_res_container_cleanup(&the_lnet.ln_eq_container);
847 lnet_msg_containers_destroy();
848 lnet_peer_tables_destroy();
849 lnet_rtrpools_free(0);
851 if (the_lnet.ln_counters != NULL) {
852 cfs_percpt_free(the_lnet.ln_counters);
853 the_lnet.ln_counters = NULL;
855 lnet_destroy_remote_nets_table();
861 lnet_net2ni_locked(__u32 net, int cpt)
863 struct list_head *tmp;
866 LASSERT(cpt != LNET_LOCK_EX);
868 list_for_each(tmp, &the_lnet.ln_nis) {
869 ni = list_entry(tmp, lnet_ni_t, ni_list);
871 if (LNET_NIDNET(ni->ni_nid) == net) {
872 lnet_ni_addref_locked(ni, cpt);
881 lnet_net2ni(__u32 net)
886 ni = lnet_net2ni_locked(net, 0);
891 EXPORT_SYMBOL(lnet_net2ni);
894 lnet_nid_cpt_hash(lnet_nid_t nid, unsigned int number)
899 LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
904 val = hash_long(key, LNET_CPT_BITS);
905 /* NB: LNET_CP_NUMBER doesn't have to be PO2 */
909 return (unsigned int)(key + val + (val >> 1)) % number;
913 lnet_cpt_of_nid_locked(lnet_nid_t nid)
917 /* must called with hold of lnet_net_lock */
918 if (LNET_CPT_NUMBER == 1)
919 return 0; /* the only one */
921 /* take lnet_net_lock(any) would be OK */
922 if (!list_empty(&the_lnet.ln_nis_cpt)) {
923 list_for_each_entry(ni, &the_lnet.ln_nis_cpt, ni_cptlist) {
924 if (LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid))
927 LASSERT(ni->ni_cpts != NULL);
928 return ni->ni_cpts[lnet_nid_cpt_hash
929 (nid, ni->ni_ncpts)];
933 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
937 lnet_cpt_of_nid(lnet_nid_t nid)
942 if (LNET_CPT_NUMBER == 1)
943 return 0; /* the only one */
945 if (list_empty(&the_lnet.ln_nis_cpt))
946 return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
948 cpt = lnet_net_lock_current();
949 cpt2 = lnet_cpt_of_nid_locked(nid);
950 lnet_net_unlock(cpt);
954 EXPORT_SYMBOL(lnet_cpt_of_nid);
957 lnet_islocalnet(__u32 net)
962 cpt = lnet_net_lock_current();
964 ni = lnet_net2ni_locked(net, cpt);
966 lnet_ni_decref_locked(ni, cpt);
968 lnet_net_unlock(cpt);
974 lnet_nid2ni_locked(lnet_nid_t nid, int cpt)
977 struct list_head *tmp;
979 LASSERT(cpt != LNET_LOCK_EX);
981 list_for_each(tmp, &the_lnet.ln_nis) {
982 ni = list_entry(tmp, lnet_ni_t, ni_list);
984 if (ni->ni_nid == nid) {
985 lnet_ni_addref_locked(ni, cpt);
994 lnet_islocalnid(lnet_nid_t nid)
999 cpt = lnet_net_lock_current();
1000 ni = lnet_nid2ni_locked(nid, cpt);
1002 lnet_ni_decref_locked(ni, cpt);
1003 lnet_net_unlock(cpt);
1009 lnet_count_acceptor_nis (void)
1011 /* Return the # of NIs that need the acceptor. */
1013 #if defined(__KERNEL__) || defined(HAVE_LIBPTHREAD)
1014 struct list_head *tmp;
1018 cpt = lnet_net_lock_current();
1019 list_for_each(tmp, &the_lnet.ln_nis) {
1020 ni = list_entry(tmp, lnet_ni_t, ni_list);
1022 if (ni->ni_lnd->lnd_accept != NULL)
1026 lnet_net_unlock(cpt);
1028 #endif /* defined(__KERNEL__) || defined(HAVE_LIBPTHREAD) */
1032 static lnet_ping_info_t *
1033 lnet_ping_info_create(int num_ni)
1035 lnet_ping_info_t *ping_info;
1036 unsigned int infosz;
1038 infosz = offsetof(lnet_ping_info_t, pi_ni[num_ni]);
1039 LIBCFS_ALLOC(ping_info, infosz);
1040 if (ping_info == NULL) {
1041 CERROR("Can't allocate ping info[%d]\n", num_ni);
1045 ping_info->pi_nnis = num_ni;
1046 ping_info->pi_pid = the_lnet.ln_pid;
1047 ping_info->pi_magic = LNET_PROTO_PING_MAGIC;
1048 ping_info->pi_features = LNET_PING_FEAT_NI_STATUS;
1054 lnet_get_ni_count(void)
1061 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list)
1070 lnet_ping_info_free(lnet_ping_info_t *pinfo)
1073 offsetof(lnet_ping_info_t,
1074 pi_ni[pinfo->pi_nnis]));
1078 lnet_ping_info_destroy(void)
1082 lnet_net_lock(LNET_LOCK_EX);
1084 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
1086 ni->ni_status = NULL;
1090 lnet_ping_info_free(the_lnet.ln_ping_info);
1091 the_lnet.ln_ping_info = NULL;
1093 lnet_net_unlock(LNET_LOCK_EX);
1097 lnet_ping_event_handler(lnet_event_t *event)
1099 lnet_ping_info_t *pinfo = event->md.user_ptr;
1101 if (event->unlinked)
1102 pinfo->pi_features = LNET_PING_FEAT_INVAL;
1106 lnet_ping_info_setup(lnet_ping_info_t **ppinfo, lnet_handle_md_t *md_handle,
1107 int ni_count, bool set_eq)
1109 lnet_handle_me_t me_handle;
1110 lnet_process_id_t id = {LNET_NID_ANY, LNET_PID_ANY};
1115 rc = LNetEQAlloc(0, lnet_ping_event_handler,
1116 &the_lnet.ln_ping_target_eq);
1118 CERROR("Can't allocate ping EQ: %d\n", rc);
1123 *ppinfo = lnet_ping_info_create(ni_count);
1124 if (*ppinfo == NULL) {
1129 rc = LNetMEAttach(LNET_RESERVED_PORTAL, id,
1130 LNET_PROTO_PING_MATCHBITS, 0,
1131 LNET_UNLINK, LNET_INS_AFTER,
1134 CERROR("Can't create ping ME: %d\n", rc);
1138 /* initialize md content */
1140 md.length = offsetof(lnet_ping_info_t,
1141 pi_ni[(*ppinfo)->pi_nnis]);
1142 md.threshold = LNET_MD_THRESH_INF;
1144 md.options = LNET_MD_OP_GET | LNET_MD_TRUNCATE |
1145 LNET_MD_MANAGE_REMOTE;
1147 md.eq_handle = the_lnet.ln_ping_target_eq;
1148 md.user_ptr = *ppinfo;
1150 rc = LNetMDAttach(me_handle, md, LNET_RETAIN, md_handle);
1152 CERROR("Can't attach ping MD: %d\n", rc);
1159 rc2 = LNetMEUnlink(me_handle);
1162 lnet_ping_info_free(*ppinfo);
1166 LNetEQFree(the_lnet.ln_ping_target_eq);
1171 lnet_ping_md_unlink(lnet_ping_info_t *pinfo, lnet_handle_md_t *md_handle)
1173 sigset_t blocked = cfs_block_allsigs();
1175 LNetMDUnlink(*md_handle);
1176 LNetInvalidateHandle(md_handle);
1178 /* NB md could be busy; this just starts the unlink */
1179 while (pinfo->pi_features != LNET_PING_FEAT_INVAL) {
1180 CDEBUG(D_NET, "Still waiting for ping MD to unlink\n");
1181 cfs_pause(cfs_time_seconds(1));
1184 cfs_restore_sigs(blocked);
1188 lnet_ping_info_install_locked(lnet_ping_info_t *ping_info)
1192 lnet_ni_status_t *ns;
1195 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
1196 LASSERT(i < ping_info->pi_nnis);
1198 ns = &ping_info->pi_ni[i];
1200 ns->ns_nid = ni->ni_nid;
1203 ns->ns_status = (ni->ni_status != NULL) ?
1204 ni->ni_status->ns_status : LNET_NI_STATUS_UP;
1213 lnet_ping_target_update(lnet_ping_info_t *pinfo, lnet_handle_md_t md_handle)
1215 lnet_ping_info_t *old_pinfo = NULL;
1216 lnet_handle_md_t old_md;
1218 /* switch the NIs to point to the new ping info created */
1219 lnet_net_lock(LNET_LOCK_EX);
1221 if (!the_lnet.ln_routing)
1222 pinfo->pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1223 lnet_ping_info_install_locked(pinfo);
1225 if (the_lnet.ln_ping_info != NULL) {
1226 old_pinfo = the_lnet.ln_ping_info;
1227 old_md = the_lnet.ln_ping_target_md;
1229 the_lnet.ln_ping_target_md = md_handle;
1230 the_lnet.ln_ping_info = pinfo;
1232 lnet_net_unlock(LNET_LOCK_EX);
1234 if (old_pinfo != NULL) {
1235 /* unlink the old ping info */
1236 lnet_ping_md_unlink(old_pinfo, &old_md);
1237 lnet_ping_info_free(old_pinfo);
1242 lnet_ping_target_fini(void)
1246 lnet_ping_md_unlink(the_lnet.ln_ping_info,
1247 &the_lnet.ln_ping_target_md);
1249 rc = LNetEQFree(the_lnet.ln_ping_target_eq);
1252 lnet_ping_info_destroy();
1256 lnet_ni_tq_credits(lnet_ni_t *ni)
1260 LASSERT(ni->ni_ncpts >= 1);
1262 if (ni->ni_ncpts == 1)
1263 return ni->ni_maxtxcredits;
1265 credits = ni->ni_maxtxcredits / ni->ni_ncpts;
1266 credits = max(credits, 8 * ni->ni_peertxcredits);
1267 credits = min(credits, ni->ni_maxtxcredits);
1273 lnet_ni_unlink_locked(lnet_ni_t *ni)
1275 if (!list_empty(&ni->ni_cptlist)) {
1276 list_del_init(&ni->ni_cptlist);
1277 lnet_ni_decref_locked(ni, 0);
1280 /* move it to zombie list and nobody can find it anymore */
1281 LASSERT(!list_empty(&ni->ni_list));
1282 list_move(&ni->ni_list, &the_lnet.ln_nis_zombie);
1283 lnet_ni_decref_locked(ni, 0); /* drop ln_nis' ref */
1287 lnet_clear_zombies_nis_locked(void)
1293 /* Now wait for the NI's I just nuked to show up on ln_zombie_nis
1294 * and shut them down in guaranteed thread context */
1296 while (!list_empty(&the_lnet.ln_nis_zombie)) {
1300 ni = list_entry(the_lnet.ln_nis_zombie.next,
1301 lnet_ni_t, ni_list);
1302 list_del_init(&ni->ni_list);
1303 cfs_percpt_for_each(ref, j, ni->ni_refs) {
1306 /* still busy, add it back to zombie list */
1307 list_add(&ni->ni_list, &the_lnet.ln_nis_zombie);
1311 if (!list_empty(&ni->ni_list)) {
1312 lnet_net_unlock(LNET_LOCK_EX);
1314 if ((i & (-i)) == i) {
1316 "Waiting for zombie LNI %s\n",
1317 libcfs_nid2str(ni->ni_nid));
1319 cfs_pause(cfs_time_seconds(1));
1320 lnet_net_lock(LNET_LOCK_EX);
1324 ni->ni_lnd->lnd_refcount--;
1325 lnet_net_unlock(LNET_LOCK_EX);
1327 islo = ni->ni_lnd->lnd_type == LOLND;
1329 LASSERT(!in_interrupt());
1330 (ni->ni_lnd->lnd_shutdown)(ni);
1332 /* can't deref lnd anymore now; it might have unregistered
1336 CDEBUG(D_LNI, "Removed LNI %s\n",
1337 libcfs_nid2str(ni->ni_nid));
1341 lnet_net_lock(LNET_LOCK_EX);
1346 lnet_shutdown_lndnis(void)
1351 /* NB called holding the global mutex */
1353 /* All quiet on the API front */
1354 LASSERT(!the_lnet.ln_shutdown);
1355 LASSERT(the_lnet.ln_refcount == 0);
1356 LASSERT(list_empty(&the_lnet.ln_nis_zombie));
1358 lnet_net_lock(LNET_LOCK_EX);
1359 the_lnet.ln_shutdown = 1; /* flag shutdown */
1361 /* Unlink NIs from the global table */
1362 while (!list_empty(&the_lnet.ln_nis)) {
1363 ni = list_entry(the_lnet.ln_nis.next,
1364 lnet_ni_t, ni_list);
1365 lnet_ni_unlink_locked(ni);
1368 /* Drop the cached eqwait NI. */
1369 if (the_lnet.ln_eq_waitni != NULL) {
1370 lnet_ni_decref_locked(the_lnet.ln_eq_waitni, 0);
1371 the_lnet.ln_eq_waitni = NULL;
1374 /* Drop the cached loopback NI. */
1375 if (the_lnet.ln_loni != NULL) {
1376 lnet_ni_decref_locked(the_lnet.ln_loni, 0);
1377 the_lnet.ln_loni = NULL;
1380 lnet_net_unlock(LNET_LOCK_EX);
1382 /* Clear lazy portals and drop delayed messages which hold refs
1383 * on their lnet_msg_t::msg_rxpeer */
1384 for (i = 0; i < the_lnet.ln_nportals; i++)
1385 LNetClearLazyPortal(i);
1387 /* Clear the peer table and wait for all peers to go (they hold refs on
1389 lnet_peer_tables_cleanup(NULL);
1391 lnet_net_lock(LNET_LOCK_EX);
1393 lnet_clear_zombies_nis_locked();
1394 the_lnet.ln_shutdown = 0;
1395 lnet_net_unlock(LNET_LOCK_EX);
1398 /* shutdown down the NI and release refcount */
1400 lnet_shutdown_lndni(struct lnet_ni *ni)
1402 lnet_net_lock(LNET_LOCK_EX);
1403 lnet_ni_unlink_locked(ni);
1404 lnet_net_unlock(LNET_LOCK_EX);
1406 /* Do peer table cleanup for this ni */
1407 lnet_peer_tables_cleanup(ni);
1409 lnet_net_lock(LNET_LOCK_EX);
1410 lnet_clear_zombies_nis_locked();
1411 lnet_net_unlock(LNET_LOCK_EX);
1415 lnet_startup_lndni(struct lnet_ni *ni, __s32 peer_timeout,
1416 __s32 peer_cr, __s32 peer_buf_cr, __s32 credits)
1421 struct lnet_tx_queue *tq;
1424 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
1426 LASSERT(libcfs_isknown_lnd(lnd_type));
1428 if (lnd_type == CIBLND || lnd_type == OPENIBLND ||
1429 lnd_type == IIBLND || lnd_type == VIBLND) {
1430 CERROR("LND %s obsoleted\n", libcfs_lnd2str(lnd_type));
1434 /* Make sure this new NI is unique. */
1435 lnet_net_lock(LNET_LOCK_EX);
1436 if (!lnet_net_unique(LNET_NIDNET(ni->ni_nid), &the_lnet.ln_nis)) {
1437 if (lnd_type == LOLND) {
1438 lnet_net_unlock(LNET_LOCK_EX);
1442 lnet_net_unlock(LNET_LOCK_EX);
1444 CERROR("Net %s is not unique\n",
1445 libcfs_net2str(LNET_NIDNET(ni->ni_nid)));
1448 lnet_net_unlock(LNET_LOCK_EX);
1450 LNET_MUTEX_LOCK(&the_lnet.ln_lnd_mutex);
1451 lnd = lnet_find_lnd_by_type(lnd_type);
1455 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
1456 rc = request_module("%s",
1457 libcfs_lnd2modname(lnd_type));
1458 LNET_MUTEX_LOCK(&the_lnet.ln_lnd_mutex);
1460 lnd = lnet_find_lnd_by_type(lnd_type);
1462 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
1463 CERROR("Can't load LND %s, module %s, rc=%d\n",
1464 libcfs_lnd2str(lnd_type),
1465 libcfs_lnd2modname(lnd_type), rc);
1466 #ifndef HAVE_MODULE_LOADING_SUPPORT
1467 LCONSOLE_ERROR_MSG(0x104, "Your kernel must be "
1468 "compiled with kernel module "
1469 "loading support.");
1476 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
1477 CERROR("LND %s not supported\n",
1478 libcfs_lnd2str(lnd_type));
1483 lnet_net_lock(LNET_LOCK_EX);
1484 lnd->lnd_refcount++;
1485 lnet_net_unlock(LNET_LOCK_EX);
1489 rc = (lnd->lnd_startup)(ni);
1491 LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
1494 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s\n",
1495 rc, libcfs_lnd2str(lnd->lnd_type));
1496 lnet_net_lock(LNET_LOCK_EX);
1497 lnd->lnd_refcount--;
1498 lnet_net_unlock(LNET_LOCK_EX);
1502 /* If given some LND tunable parameters, parse those now to
1503 * override the values in the NI structure. */
1504 if (peer_buf_cr >= 0)
1505 ni->ni_peerrtrcredits = peer_buf_cr;
1506 if (peer_timeout >= 0)
1507 ni->ni_peertimeout = peer_timeout;
1510 * Note: For now, don't allow the user to change
1511 * peertxcredits as this number is used in the
1512 * IB LND to control queue depth.
1513 * if (peer_cr != -1)
1514 * ni->ni_peertxcredits = peer_cr;
1517 ni->ni_maxtxcredits = credits;
1519 LASSERT(ni->ni_peertimeout <= 0 || lnd->lnd_query != NULL);
1521 lnet_net_lock(LNET_LOCK_EX);
1522 /* refcount for ln_nis */
1523 lnet_ni_addref_locked(ni, 0);
1524 list_add_tail(&ni->ni_list, &the_lnet.ln_nis);
1525 if (ni->ni_cpts != NULL) {
1526 lnet_ni_addref_locked(ni, 0);
1527 list_add_tail(&ni->ni_cptlist, &the_lnet.ln_nis_cpt);
1530 lnet_net_unlock(LNET_LOCK_EX);
1532 if (lnd->lnd_type == LOLND) {
1534 LASSERT(the_lnet.ln_loni == NULL);
1535 the_lnet.ln_loni = ni;
1540 if (lnd->lnd_wait != NULL) {
1541 if (the_lnet.ln_eq_waitni == NULL) {
1543 the_lnet.ln_eq_waitni = ni;
1546 # ifndef HAVE_LIBPTHREAD
1547 LCONSOLE_ERROR_MSG(0x106, "LND %s not supported in a "
1548 "single-threaded runtime\n",
1549 libcfs_lnd2str(lnd_type));
1550 /* shutdown the NI since if we get here then it must've already
1553 lnet_shutdown_lndni(ni);
1558 if (ni->ni_peertxcredits == 0 || ni->ni_maxtxcredits == 0) {
1559 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
1560 libcfs_lnd2str(lnd->lnd_type),
1561 ni->ni_peertxcredits == 0 ?
1563 /* shutdown the NI since if we get here then it must've already
1566 lnet_shutdown_lndni(ni);
1570 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
1571 tq->tq_credits_min =
1572 tq->tq_credits_max =
1573 tq->tq_credits = lnet_ni_tq_credits(ni);
1576 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d/%d]\n",
1577 libcfs_nid2str(ni->ni_nid), ni->ni_peertxcredits,
1578 lnet_ni_tq_credits(ni) * LNET_CPT_NUMBER,
1579 ni->ni_peerrtrcredits, ni->ni_peertimeout);
1588 lnet_startup_lndnis(struct list_head *nilist)
1595 while (!list_empty(nilist)) {
1596 ni = list_entry(nilist->next, lnet_ni_t, ni_list);
1597 list_del(&ni->ni_list);
1598 rc = lnet_startup_lndni(ni, -1, -1, -1, -1);
1606 if (the_lnet.ln_eq_waitni != NULL && ni_count > 1) {
1607 lnd_type = the_lnet.ln_eq_waitni->ni_lnd->lnd_type;
1608 LCONSOLE_ERROR_MSG(0x109, "LND %s can only run single-network"
1610 libcfs_lnd2str(lnd_type));
1617 lnet_shutdown_lndnis();
1623 * Initialize LNet library.
1625 * Only userspace program needs to call this function - it's automatically
1626 * called in the kernel at module loading time. Caller has to call LNetFini()
1627 * after a call to LNetInit(), if and only if the latter returned 0. It must
1628 * be called exactly once.
1630 * \return 0 on success, and -ve on failures.
1637 lnet_assert_wire_constants();
1638 LASSERT(!the_lnet.ln_init);
1640 memset(&the_lnet, 0, sizeof(the_lnet));
1642 /* refer to global cfs_cpt_table for now */
1643 the_lnet.ln_cpt_table = cfs_cpt_table;
1644 the_lnet.ln_cpt_number = cfs_cpt_number(cfs_cpt_table);
1646 LASSERT(the_lnet.ln_cpt_number > 0);
1647 if (the_lnet.ln_cpt_number > LNET_CPT_MAX) {
1648 /* we are under risk of consuming all lh_cookie */
1649 CERROR("Can't have %d CPTs for LNet (max allowed is %d), "
1650 "please change setting of CPT-table and retry\n",
1651 the_lnet.ln_cpt_number, LNET_CPT_MAX);
1655 while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number)
1656 the_lnet.ln_cpt_bits++;
1658 rc = lnet_create_locks();
1660 CERROR("Can't create LNet global locks: %d\n", rc);
1664 the_lnet.ln_refcount = 0;
1665 the_lnet.ln_init = 1;
1666 LNetInvalidateHandle(&the_lnet.ln_rc_eqh);
1667 INIT_LIST_HEAD(&the_lnet.ln_lnds);
1668 INIT_LIST_HEAD(&the_lnet.ln_rcd_zombie);
1669 INIT_LIST_HEAD(&the_lnet.ln_rcd_deathrow);
1672 /* The hash table size is the number of bits it takes to express the set
1673 * ln_num_routes, minus 1 (better to under estimate than over so we
1674 * don't waste memory). */
1675 if (rnet_htable_size <= 0)
1676 rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
1677 else if (rnet_htable_size > LNET_REMOTE_NETS_HASH_MAX)
1678 rnet_htable_size = LNET_REMOTE_NETS_HASH_MAX;
1679 the_lnet.ln_remote_nets_hbits = max_t(int, 1,
1680 order_base_2(rnet_htable_size) - 1);
1682 /* All LNDs apart from the LOLND are in separate modules. They
1683 * register themselves when their module loads, and unregister
1684 * themselves when their module is unloaded. */
1686 the_lnet.ln_remote_nets_hbits = 8;
1689 * NB the order here determines default 'networks=' order */
1690 # ifdef HAVE_LIBPTHREAD
1691 LNET_REGISTER_ULND(the_tcplnd);
1694 lnet_register_lnd(&the_lolnd);
1697 EXPORT_SYMBOL(LNetInit);
1700 * Finalize LNet library.
1702 * Only userspace program needs to call this function. It can be called
1705 * \pre LNetInit() called with success.
1706 * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls.
1711 LASSERT(the_lnet.ln_init);
1712 LASSERT(the_lnet.ln_refcount == 0);
1714 while (!list_empty(&the_lnet.ln_lnds))
1715 lnet_unregister_lnd(list_entry(the_lnet.ln_lnds.next,
1717 lnet_destroy_locks();
1719 the_lnet.ln_init = 0;
1721 EXPORT_SYMBOL(LNetFini);
1724 * Set LNet PID and start LNet interfaces, routing, and forwarding.
1726 * Userspace program should call this after a successful call to LNetInit().
1727 * Users must call this function at least once before any other functions.
1728 * For each successful call there must be a corresponding call to
1729 * LNetNIFini(). For subsequent calls to LNetNIInit(), \a requested_pid is
1732 * The PID used by LNet may be different from the one requested.
1735 * \param requested_pid PID requested by the caller.
1737 * \return >= 0 on success, and < 0 error code on failures.
1740 LNetNIInit(lnet_pid_t requested_pid)
1742 int im_a_router = 0;
1745 lnet_ping_info_t *pinfo;
1746 lnet_handle_md_t md_handle;
1747 struct list_head net_head;
1749 INIT_LIST_HEAD(&net_head);
1751 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
1753 LASSERT(the_lnet.ln_init);
1754 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
1756 if (the_lnet.ln_refcount > 0) {
1757 rc = the_lnet.ln_refcount++;
1758 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
1762 rc = lnet_prepare(requested_pid);
1764 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
1768 /* Add in the loopback network */
1769 if (lnet_ni_alloc(LNET_MKNET(LOLND, 0), NULL, &net_head) == NULL) {
1774 /* If LNet is being initialized via DLC it is possible
1775 * that the user requests not to load module parameters (ones which
1776 * are supported by DLC) on initialization. Therefore, make sure not
1777 * to load networks, routes and forwarding from module parameters
1778 * in this case. On cleanup in case of failure only clean up
1779 * routes if it has been loaded */
1780 if (!the_lnet.ln_nis_from_mod_params) {
1781 rc = lnet_parse_networks(&net_head,
1782 lnet_get_networks());
1787 ni_count = lnet_startup_lndnis(&net_head);
1793 if (!the_lnet.ln_nis_from_mod_params) {
1794 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
1798 rc = lnet_check_routes();
1802 rc = lnet_rtrpools_alloc(im_a_router);
1807 rc = lnet_acceptor_start();
1810 the_lnet.ln_refcount = 1;
1811 /* Now I may use my own API functions... */
1813 rc = lnet_ping_info_setup(&pinfo, &md_handle, ni_count, true);
1817 lnet_ping_target_update(pinfo, md_handle);
1819 rc = lnet_router_checker_start();
1826 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
1831 lnet_ping_md_unlink(pinfo, &md_handle);
1832 lnet_ping_info_free(pinfo);
1833 rc2 = LNetEQFree(the_lnet.ln_ping_target_eq);
1836 the_lnet.ln_refcount = 0;
1837 lnet_acceptor_stop();
1839 if (!the_lnet.ln_nis_from_mod_params)
1840 lnet_destroy_routes();
1842 lnet_shutdown_lndnis();
1846 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
1847 while (!list_empty(&net_head)) {
1849 ni = list_entry(net_head.next, struct lnet_ni, ni_list);
1850 list_del_init(&ni->ni_list);
1855 EXPORT_SYMBOL(LNetNIInit);
1858 * Stop LNet interfaces, routing, and forwarding.
1860 * Users must call this function once for each successful call to LNetNIInit().
1861 * Once the LNetNIFini() operation has been started, the results of pending
1862 * API operations are undefined.
1864 * \return always 0 for current implementation.
1869 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
1871 LASSERT (the_lnet.ln_init);
1872 LASSERT (the_lnet.ln_refcount > 0);
1874 if (the_lnet.ln_refcount != 1) {
1875 the_lnet.ln_refcount--;
1877 LASSERT(!the_lnet.ln_niinit_self);
1882 lnet_router_checker_stop();
1883 lnet_ping_target_fini();
1885 /* Teardown fns that use my own API functions BEFORE here */
1886 the_lnet.ln_refcount = 0;
1888 lnet_acceptor_stop();
1889 lnet_destroy_routes();
1890 lnet_shutdown_lndnis();
1894 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
1897 EXPORT_SYMBOL(LNetNIFini);
1900 * Grabs the ni data from the ni structure and fills the out
1903 * \param[in] ni network interface structure
1904 * \param[out] cpt_count the number of cpts the ni is on
1905 * \param[out] nid Network Interface ID
1906 * \param[out] peer_timeout NI peer timeout
1907 * \param[out] peer_tx_crdits NI peer transmit credits
1908 * \param[out] peer_rtr_credits NI peer router credits
1909 * \param[out] max_tx_credits NI max transmit credit
1910 * \param[out] net_config Network configuration
1913 lnet_fill_ni_info(struct lnet_ni *ni, __u32 *cpt_count, __u64 *nid,
1914 int *peer_timeout, int *peer_tx_credits,
1915 int *peer_rtr_credits, int *max_tx_credits,
1916 struct lnet_ioctl_net_config *net_config)
1923 if (net_config == NULL)
1926 CLASSERT(ARRAY_SIZE(ni->ni_interfaces) ==
1927 ARRAY_SIZE(net_config->ni_interfaces));
1929 if (ni->ni_interfaces[0] != NULL) {
1930 for (i = 0; i < ARRAY_SIZE(ni->ni_interfaces); i++) {
1931 if (ni->ni_interfaces[i] != NULL) {
1932 strncpy(net_config->ni_interfaces[i],
1933 ni->ni_interfaces[i],
1934 sizeof(net_config->ni_interfaces[i]));
1940 *peer_timeout = ni->ni_peertimeout;
1941 *peer_tx_credits = ni->ni_peertxcredits;
1942 *peer_rtr_credits = ni->ni_peerrtrcredits;
1943 *max_tx_credits = ni->ni_maxtxcredits;
1945 net_config->ni_status = ni->ni_status->ns_status;
1948 ni->ni_cpts != NULL && i < ni->ni_ncpts &&
1949 i < LNET_MAX_SHOW_NUM_CPT;
1951 net_config->ni_cpts[i] = ni->ni_cpts[i];
1953 *cpt_count = ni->ni_ncpts;
1957 lnet_get_net_config(int idx, __u32 *cpt_count, __u64 *nid, int *peer_timeout,
1958 int *peer_tx_credits, int *peer_rtr_credits,
1959 int *max_tx_credits,
1960 struct lnet_ioctl_net_config *net_config)
1963 struct list_head *tmp;
1967 cpt = lnet_net_lock_current();
1969 list_for_each(tmp, &the_lnet.ln_nis) {
1970 ni = list_entry(tmp, lnet_ni_t, ni_list);
1974 lnet_fill_ni_info(ni, cpt_count, nid, peer_timeout,
1975 peer_tx_credits, peer_rtr_credits,
1976 max_tx_credits, net_config);
1982 lnet_net_unlock(cpt);
1987 lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
1988 __s32 peer_timeout, __s32 peer_cr, __s32 peer_buf_cr,
1991 lnet_ping_info_t *pinfo;
1992 lnet_handle_md_t md_handle;
1994 struct list_head net_head;
1997 INIT_LIST_HEAD(&net_head);
1999 /* Create a ni structure for the network string */
2000 rc = lnet_parse_networks(&net_head, nets);
2002 return rc == 0 ? -EINVAL : rc;
2004 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2007 rc = -EINVAL; /* only add one interface per call */
2011 rc = lnet_ping_info_setup(&pinfo, &md_handle, 1 + lnet_get_ni_count(),
2016 ni = list_entry(net_head.next, struct lnet_ni, ni_list);
2017 list_del_init(&ni->ni_list);
2019 rc = lnet_startup_lndni(ni, peer_timeout, peer_cr,
2020 peer_buf_cr, credits);
2024 lnet_ping_target_update(pinfo, md_handle);
2025 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2030 lnet_ping_md_unlink(pinfo, &md_handle);
2031 lnet_ping_info_free(pinfo);
2033 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2034 while (!list_empty(&net_head)) {
2035 ni = list_entry(net_head.next, struct lnet_ni, ni_list);
2036 list_del_init(&ni->ni_list);
2043 lnet_dyn_del_ni(__u32 net)
2046 lnet_ping_info_t *pinfo;
2047 lnet_handle_md_t md_handle;
2050 /* don't allow userspace to shutdown the LOLND */
2051 if (LNET_NETTYP(net) == LOLND)
2054 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2055 /* create and link a new ping info, before removing the old one */
2056 rc = lnet_ping_info_setup(&pinfo, &md_handle,
2057 lnet_get_ni_count() - 1, false);
2061 ni = lnet_net2ni(net);
2067 /* decrement the reference counter taken by lnet_net2ni() */
2068 lnet_ni_decref_locked(ni, 0);
2070 lnet_shutdown_lndni(ni);
2071 lnet_ping_target_update(pinfo, md_handle);
2074 lnet_ping_md_unlink(pinfo, &md_handle);
2075 lnet_ping_info_free(pinfo);
2077 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2083 * This is an ugly hack to export IOC_LIBCFS_DEBUG_PEER and
2084 * IOC_LIBCFS_PORTALS_COMPATIBILITY commands to users, by tweaking the LNet
2085 * internal ioctl handler.
2087 * IOC_LIBCFS_PORTALS_COMPATIBILITY is now deprecated, don't use it.
2089 * \param cmd IOC_LIBCFS_DEBUG_PEER to print debugging data about a peer.
2090 * The data will be printed to system console. Don't use it excessively.
2091 * \param arg A pointer to lnet_process_id_t, process ID of the peer.
2093 * \return Always return 0 when called by users directly (i.e., not via ioctl).
2096 LNetCtl(unsigned int cmd, void *arg)
2098 struct libcfs_ioctl_data *data = arg;
2099 struct lnet_ioctl_config_data *config;
2100 lnet_process_id_t id = {0};
2104 CLASSERT(LIBCFS_IOC_DATA_MAX >= sizeof(struct lnet_ioctl_net_config) +
2105 sizeof(struct lnet_ioctl_config_data));
2106 LASSERT(the_lnet.ln_init);
2109 case IOC_LIBCFS_GET_NI:
2110 rc = LNetGetId(data->ioc_count, &id);
2111 data->ioc_nid = id.nid;
2114 case IOC_LIBCFS_FAIL_NID:
2115 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
2117 case IOC_LIBCFS_ADD_ROUTE:
2120 if (config->cfg_hdr.ioc_len < sizeof(*config))
2123 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2124 rc = lnet_add_route(config->cfg_net,
2125 config->cfg_config_u.cfg_route.rtr_hop,
2127 config->cfg_config_u.cfg_route.
2129 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2130 return (rc != 0) ? rc : lnet_check_routes();
2132 case IOC_LIBCFS_DEL_ROUTE:
2135 if (config->cfg_hdr.ioc_len < sizeof(*config))
2138 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2139 rc = lnet_del_route(config->cfg_net, config->cfg_nid);
2140 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2143 case IOC_LIBCFS_GET_ROUTE:
2146 if (config->cfg_hdr.ioc_len < sizeof(*config))
2149 return lnet_get_route(config->cfg_count,
2151 &config->cfg_config_u.cfg_route.rtr_hop,
2153 &config->cfg_config_u.cfg_route.rtr_flags,
2154 &config->cfg_config_u.cfg_route.
2157 case IOC_LIBCFS_GET_NET: {
2158 struct lnet_ioctl_net_config *net_config;
2159 size_t total = sizeof(*config) + sizeof(*net_config);
2163 if (config->cfg_hdr.ioc_len < total)
2166 net_config = (struct lnet_ioctl_net_config *)
2168 if (config == NULL || net_config == NULL)
2171 return lnet_get_net_config(config->cfg_count,
2174 &config->cfg_config_u.
2175 cfg_net.net_peer_timeout,
2176 &config->cfg_config_u.cfg_net.
2177 net_peer_tx_credits,
2178 &config->cfg_config_u.cfg_net.
2179 net_peer_rtr_credits,
2180 &config->cfg_config_u.cfg_net.
2185 case IOC_LIBCFS_GET_LNET_STATS:
2187 struct lnet_ioctl_lnet_stats *lnet_stats = arg;
2189 if (lnet_stats->st_hdr.ioc_len < sizeof(*lnet_stats))
2192 lnet_counters_get(&lnet_stats->st_cntrs);
2196 #if defined(__KERNEL__) && defined(LNET_ROUTER)
2197 case IOC_LIBCFS_CONFIG_RTR:
2200 if (config->cfg_hdr.ioc_len < sizeof(*config))
2203 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2204 if (config->cfg_config_u.cfg_buffers.buf_enable) {
2205 rc = lnet_rtrpools_enable();
2206 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2209 lnet_rtrpools_disable();
2210 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2213 case IOC_LIBCFS_ADD_BUF:
2216 if (config->cfg_hdr.ioc_len < sizeof(*config))
2219 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
2220 rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
2222 config->cfg_config_u.cfg_buffers.
2224 config->cfg_config_u.cfg_buffers.
2226 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
2230 case IOC_LIBCFS_GET_BUF: {
2231 struct lnet_ioctl_pool_cfg *pool_cfg;
2232 size_t total = sizeof(*config) + sizeof(*pool_cfg);
2236 if (config->cfg_hdr.ioc_len < total)
2239 pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
2240 return lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
2243 case IOC_LIBCFS_GET_PEER_INFO: {
2244 struct lnet_ioctl_peer *peer_info = arg;
2246 if (peer_info->pr_hdr.ioc_len < sizeof(*peer_info))
2249 return lnet_get_peer_info(
2250 peer_info->pr_count,
2252 peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
2253 &peer_info->pr_lnd_u.pr_peer_credits.cr_ncpt,
2254 &peer_info->pr_lnd_u.pr_peer_credits.cr_refcount,
2255 &peer_info->pr_lnd_u.pr_peer_credits.cr_ni_peer_tx_credits,
2256 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_credits,
2257 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_rtr_credits,
2258 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_min_rtr_credits,
2259 &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_qnob);
2262 case IOC_LIBCFS_NOTIFY_ROUTER:
2263 return lnet_notify(NULL, data->ioc_nid, data->ioc_flags,
2264 cfs_time_current() -
2265 cfs_time_seconds(cfs_time_current_sec() -
2266 (time_t)data->ioc_u64[0]));
2268 case IOC_LIBCFS_PORTALS_COMPATIBILITY:
2269 /* This can be removed once lustre stops calling it */
2272 case IOC_LIBCFS_LNET_DIST:
2273 rc = LNetDist(data->ioc_nid, &data->ioc_nid, &data->ioc_u32[1]);
2274 if (rc < 0 && rc != -EHOSTUNREACH)
2277 data->ioc_u32[0] = rc;
2280 case IOC_LIBCFS_TESTPROTOCOMPAT:
2281 lnet_net_lock(LNET_LOCK_EX);
2282 the_lnet.ln_testprotocompat = data->ioc_flags;
2283 lnet_net_unlock(LNET_LOCK_EX);
2286 case IOC_LIBCFS_LNET_FAULT:
2287 return lnet_fault_ctl(data->ioc_flags, data);
2289 case IOC_LIBCFS_PING:
2290 id.nid = data->ioc_nid;
2291 id.pid = data->ioc_u32[0];
2292 rc = lnet_ping(id, data->ioc_u32[1], /* timeout */
2293 (lnet_process_id_t __user *)data->ioc_pbuf1,
2294 data->ioc_plen1/sizeof(lnet_process_id_t));
2297 data->ioc_count = rc;
2300 case IOC_LIBCFS_DEBUG_PEER: {
2301 /* CAVEAT EMPTOR: this one designed for calling directly; not
2303 id = *((lnet_process_id_t *) arg);
2305 lnet_debug_peer(id.nid);
2307 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2309 CDEBUG(D_WARNING, "No NI for %s\n", libcfs_id2str(id));
2311 if (ni->ni_lnd->lnd_ctl == NULL) {
2312 CDEBUG(D_WARNING, "No ctl for %s\n",
2315 (void)ni->ni_lnd->lnd_ctl(ni, cmd, arg);
2324 ni = lnet_net2ni(data->ioc_net);
2328 if (ni->ni_lnd->lnd_ctl == NULL)
2331 rc = ni->ni_lnd->lnd_ctl(ni, cmd, arg);
2338 EXPORT_SYMBOL(LNetCtl);
2341 * Retrieve the lnet_process_id_t ID of LNet interface at \a index. Note that
2342 * all interfaces share a same PID, as requested by LNetNIInit().
2344 * \param index Index of the interface to look up.
2345 * \param id On successful return, this location will hold the
2346 * lnet_process_id_t ID of the interface.
2348 * \retval 0 If an interface exists at \a index.
2349 * \retval -ENOENT If no interface has been found.
2352 LNetGetId(unsigned int index, lnet_process_id_t *id)
2355 struct list_head *tmp;
2359 LASSERT(the_lnet.ln_init);
2360 LASSERT(the_lnet.ln_refcount > 0);
2362 cpt = lnet_net_lock_current();
2364 list_for_each(tmp, &the_lnet.ln_nis) {
2368 ni = list_entry(tmp, lnet_ni_t, ni_list);
2370 id->nid = ni->ni_nid;
2371 id->pid = the_lnet.ln_pid;
2376 lnet_net_unlock(cpt);
2379 EXPORT_SYMBOL(LNetGetId);
2382 * Print a string representation of handle \a h into buffer \a str of
2386 LNetSnprintHandle(char *str, int len, lnet_handle_any_t h)
2388 snprintf(str, len, LPX64, h.cookie);
2390 EXPORT_SYMBOL(LNetSnprintHandle);
2393 lnet_ping(lnet_process_id_t id, int timeout_ms, lnet_process_id_t __user *ids,
2396 lnet_handle_eq_t eqh;
2397 lnet_handle_md_t mdh;
2403 const int a_long_time = 60000; /* mS */
2405 lnet_ping_info_t *info;
2406 lnet_process_id_t tmpid;
2413 infosz = offsetof(lnet_ping_info_t, pi_ni[n_ids]);
2416 id.nid == LNET_NID_ANY ||
2417 timeout_ms > 500000 || /* arbitrary limit! */
2418 n_ids > 20) /* arbitrary limit! */
2421 if (id.pid == LNET_PID_ANY)
2422 id.pid = LNET_PID_LUSTRE;
2424 LIBCFS_ALLOC(info, infosz);
2428 /* NB 2 events max (including any unlink event) */
2429 rc = LNetEQAlloc(2, LNET_EQ_HANDLER_NONE, &eqh);
2431 CERROR("Can't allocate EQ: %d\n", rc);
2435 /* initialize md content */
2438 md.threshold = 2; /*GET/REPLY*/
2440 md.options = LNET_MD_TRUNCATE;
2444 rc = LNetMDBind(md, LNET_UNLINK, &mdh);
2446 CERROR("Can't bind MD: %d\n", rc);
2450 rc = LNetGet(LNET_NID_ANY, mdh, id,
2451 LNET_RESERVED_PORTAL,
2452 LNET_PROTO_PING_MATCHBITS, 0);
2455 /* Don't CERROR; this could be deliberate! */
2457 rc2 = LNetMDUnlink(mdh);
2460 /* NB must wait for the UNLINK event below... */
2462 timeout_ms = a_long_time;
2466 /* MUST block for unlink to complete */
2468 blocked = cfs_block_allsigs();
2470 rc2 = LNetEQPoll(&eqh, 1, timeout_ms, &event, &which);
2473 cfs_restore_sigs(blocked);
2475 CDEBUG(D_NET, "poll %d(%d %d)%s\n", rc2,
2476 (rc2 <= 0) ? -1 : event.type,
2477 (rc2 <= 0) ? -1 : event.status,
2478 (rc2 > 0 && event.unlinked) ? " unlinked" : "");
2480 LASSERT(rc2 != -EOVERFLOW); /* can't miss anything */
2482 if (rc2 <= 0 || event.status != 0) {
2483 /* timeout or error */
2484 if (!replied && rc == 0)
2485 rc = (rc2 < 0) ? rc2 :
2486 (rc2 == 0) ? -ETIMEDOUT :
2490 /* Ensure completion in finite time... */
2492 /* No assertion (racing with network) */
2494 timeout_ms = a_long_time;
2495 } else if (rc2 == 0) {
2496 /* timed out waiting for unlink */
2497 CWARN("ping %s: late network completion\n",
2500 } else if (event.type == LNET_EVENT_REPLY) {
2505 } while (rc2 <= 0 || !event.unlinked);
2509 CWARN("%s: Unexpected rc >= 0 but no reply!\n",
2516 LASSERT(nob >= 0 && nob <= infosz);
2518 rc = -EPROTO; /* if I can't parse... */
2521 /* can't check magic/version */
2522 CERROR("%s: ping info too short %d\n",
2523 libcfs_id2str(id), nob);
2527 if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) {
2528 lnet_swap_pinginfo(info);
2529 } else if (info->pi_magic != LNET_PROTO_PING_MAGIC) {
2530 CERROR("%s: Unexpected magic %08x\n",
2531 libcfs_id2str(id), info->pi_magic);
2535 if ((info->pi_features & LNET_PING_FEAT_NI_STATUS) == 0) {
2536 CERROR("%s: ping w/o NI status: 0x%x\n",
2537 libcfs_id2str(id), info->pi_features);
2541 if (nob < offsetof(lnet_ping_info_t, pi_ni[0])) {
2542 CERROR("%s: Short reply %d(%d min)\n", libcfs_id2str(id),
2543 nob, (int)offsetof(lnet_ping_info_t, pi_ni[0]));
2547 if (info->pi_nnis < n_ids)
2548 n_ids = info->pi_nnis;
2550 if (nob < offsetof(lnet_ping_info_t, pi_ni[n_ids])) {
2551 CERROR("%s: Short reply %d(%d expected)\n", libcfs_id2str(id),
2552 nob, (int)offsetof(lnet_ping_info_t, pi_ni[n_ids]));
2556 rc = -EFAULT; /* If I SEGV... */
2558 for (i = 0; i < n_ids; i++) {
2559 tmpid.pid = info->pi_pid;
2560 tmpid.nid = info->pi_ni[i].ns_nid;
2561 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid)))
2567 rc2 = LNetEQFree(eqh);
2569 CERROR("rc2 %d\n", rc2);
2573 LIBCFS_FREE(info, infosz);