1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
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>
41 #define D_LNI D_CONSOLE
43 #define D_LNI D_CONFIG
46 lnet_t the_lnet; /* THE state of the network */
50 static char *ip2nets = "";
51 CFS_MODULE_PARM(ip2nets, "s", charp, 0444,
52 "LNET network <- IP table");
54 static char *networks = "";
55 CFS_MODULE_PARM(networks, "s", charp, 0444,
58 static char *routes = "";
59 CFS_MODULE_PARM(routes, "s", charp, 0444,
60 "routes to non-local networks");
62 static char *portals_compatibility = "none";
63 CFS_MODULE_PARM(portals_compatibility, "s", charp, 0444,
64 "wire protocol compatibility: 'strong'|'weak'|'none'");
73 lnet_get_networks(void)
78 if (*networks != 0 && *ip2nets != 0) {
79 LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
80 "'ip2nets' but not both at once\n");
85 rc = lnet_parse_ip2nets(&nets, ip2nets);
86 return (rc == 0) ? nets : NULL;
96 lnet_get_portals_compatibility(void)
98 if (!strcmp(portals_compatibility, "none")) {
102 if (!strcmp(portals_compatibility, "weak")) {
104 LCONSOLE_WARN("Starting in weak portals-compatible mode\n");
107 if (!strcmp(portals_compatibility, "strong")) {
109 LCONSOLE_WARN("Starting in strong portals-compatible mode\n");
112 LCONSOLE_ERROR_MSG(0x102, "portals_compatibility=\"%s\" not supported\n",
113 portals_compatibility);
118 lnet_init_locks(void)
120 spin_lock_init (&the_lnet.ln_lock);
121 cfs_waitq_init (&the_lnet.ln_waitq);
122 init_mutex(&the_lnet.ln_lnd_mutex);
123 init_mutex(&the_lnet.ln_api_mutex);
127 lnet_fini_locks(void)
134 lnet_get_routes(void)
136 char *str = getenv("LNET_ROUTES");
138 return (str == NULL) ? "" : str;
142 lnet_get_networks (void)
144 static char default_networks[256];
145 char *networks = getenv ("LNET_NETWORKS");
146 char *ip2nets = getenv ("LNET_IP2NETS");
152 struct list_head *tmp;
155 if (networks != NULL && ip2nets != NULL) {
156 LCONSOLE_ERROR_MSG(0x103, "Please set EITHER 'LNET_NETWORKS' or"
157 " 'LNET_IP2NETS' but not both at once\n");
161 if (ip2nets != NULL) {
162 rc = lnet_parse_ip2nets(&networks, ip2nets);
163 return (rc == 0) ? networks : NULL;
169 if (networks != NULL)
172 /* In userland, the default 'networks=' is the list of known net types */
174 len = sizeof(default_networks);
175 str = default_networks;
179 list_for_each (tmp, &the_lnet.ln_lnds) {
180 lnd_t *lnd = list_entry(tmp, lnd_t, lnd_list);
182 nob = snprintf(str, len, "%s%s", sep,
183 libcfs_lnd2str(lnd->lnd_type));
186 /* overflowed the string; leave it where it was */
195 return default_networks;
199 lnet_get_portals_compatibility(void)
204 # ifndef HAVE_LIBPTHREAD
206 void lnet_init_locks(void)
208 the_lnet.ln_lock = 0;
209 the_lnet.ln_lnd_mutex = 0;
210 the_lnet.ln_api_mutex = 0;
213 void lnet_fini_locks(void)
215 LASSERT (the_lnet.ln_api_mutex == 0);
216 LASSERT (the_lnet.ln_lnd_mutex == 0);
217 LASSERT (the_lnet.ln_lock == 0);
222 void lnet_init_locks(void)
224 pthread_cond_init(&the_lnet.ln_cond, NULL);
225 pthread_mutex_init(&the_lnet.ln_lock, NULL);
226 pthread_mutex_init(&the_lnet.ln_lnd_mutex, NULL);
227 pthread_mutex_init(&the_lnet.ln_api_mutex, NULL);
230 void lnet_fini_locks(void)
232 pthread_mutex_destroy(&the_lnet.ln_api_mutex);
233 pthread_mutex_destroy(&the_lnet.ln_lnd_mutex);
234 pthread_mutex_destroy(&the_lnet.ln_lock);
235 pthread_cond_destroy(&the_lnet.ln_cond);
241 void lnet_assert_wire_constants (void)
243 /* Wire protocol assertions generated by 'wirecheck'
244 * running on Linux robert.bartonsoftware.com 2.6.8-1.521
245 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux
246 * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) */
249 CLASSERT (LNET_PROTO_TCP_MAGIC == 0xeebc0ded);
250 CLASSERT (LNET_PROTO_TCP_VERSION_MAJOR == 1);
251 CLASSERT (LNET_PROTO_TCP_VERSION_MINOR == 0);
252 CLASSERT (LNET_MSG_ACK == 0);
253 CLASSERT (LNET_MSG_PUT == 1);
254 CLASSERT (LNET_MSG_GET == 2);
255 CLASSERT (LNET_MSG_REPLY == 3);
256 CLASSERT (LNET_MSG_HELLO == 4);
258 /* Checks for struct ptl_handle_wire_t */
259 CLASSERT ((int)sizeof(lnet_handle_wire_t) == 16);
260 CLASSERT ((int)offsetof(lnet_handle_wire_t, wh_interface_cookie) == 0);
261 CLASSERT ((int)sizeof(((lnet_handle_wire_t *)0)->wh_interface_cookie) == 8);
262 CLASSERT ((int)offsetof(lnet_handle_wire_t, wh_object_cookie) == 8);
263 CLASSERT ((int)sizeof(((lnet_handle_wire_t *)0)->wh_object_cookie) == 8);
265 /* Checks for struct lnet_magicversion_t */
266 CLASSERT ((int)sizeof(lnet_magicversion_t) == 8);
267 CLASSERT ((int)offsetof(lnet_magicversion_t, magic) == 0);
268 CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->magic) == 4);
269 CLASSERT ((int)offsetof(lnet_magicversion_t, version_major) == 4);
270 CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->version_major) == 2);
271 CLASSERT ((int)offsetof(lnet_magicversion_t, version_minor) == 6);
272 CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->version_minor) == 2);
274 /* Checks for struct lnet_hdr_t */
275 CLASSERT ((int)sizeof(lnet_hdr_t) == 72);
276 CLASSERT ((int)offsetof(lnet_hdr_t, dest_nid) == 0);
277 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->dest_nid) == 8);
278 CLASSERT ((int)offsetof(lnet_hdr_t, src_nid) == 8);
279 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->src_nid) == 8);
280 CLASSERT ((int)offsetof(lnet_hdr_t, dest_pid) == 16);
281 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->dest_pid) == 4);
282 CLASSERT ((int)offsetof(lnet_hdr_t, src_pid) == 20);
283 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->src_pid) == 4);
284 CLASSERT ((int)offsetof(lnet_hdr_t, type) == 24);
285 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->type) == 4);
286 CLASSERT ((int)offsetof(lnet_hdr_t, payload_length) == 28);
287 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->payload_length) == 4);
288 CLASSERT ((int)offsetof(lnet_hdr_t, msg) == 32);
289 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg) == 40);
292 CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.dst_wmd) == 32);
293 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.dst_wmd) == 16);
294 CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.match_bits) == 48);
295 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.match_bits) == 8);
296 CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.mlength) == 56);
297 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.mlength) == 4);
300 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.ack_wmd) == 32);
301 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.ack_wmd) == 16);
302 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.match_bits) == 48);
303 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.match_bits) == 8);
304 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.hdr_data) == 56);
305 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.hdr_data) == 8);
306 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.ptl_index) == 64);
307 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.ptl_index) == 4);
308 CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.offset) == 68);
309 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.offset) == 4);
312 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.return_wmd) == 32);
313 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.return_wmd) == 16);
314 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.match_bits) == 48);
315 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.match_bits) == 8);
316 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.ptl_index) == 56);
317 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.ptl_index) == 4);
318 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.src_offset) == 60);
319 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.src_offset) == 4);
320 CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.sink_length) == 64);
321 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.sink_length) == 4);
324 CLASSERT ((int)offsetof(lnet_hdr_t, msg.reply.dst_wmd) == 32);
325 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.reply.dst_wmd) == 16);
328 CLASSERT ((int)offsetof(lnet_hdr_t, msg.hello.incarnation) == 32);
329 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.hello.incarnation) == 8);
330 CLASSERT ((int)offsetof(lnet_hdr_t, msg.hello.type) == 40);
331 CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.hello.type) == 4);
335 lnet_find_lnd_by_type (int type)
338 struct list_head *tmp;
340 /* holding lnd mutex */
341 list_for_each (tmp, &the_lnet.ln_lnds) {
342 lnd = list_entry(tmp, lnd_t, lnd_list);
344 if (lnd->lnd_type == type)
352 lnet_register_lnd (lnd_t *lnd)
354 LNET_MUTEX_DOWN(&the_lnet.ln_lnd_mutex);
356 LASSERT (the_lnet.ln_init);
357 LASSERT (libcfs_isknown_lnd(lnd->lnd_type));
358 LASSERT (lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
360 list_add_tail (&lnd->lnd_list, &the_lnet.ln_lnds);
361 lnd->lnd_refcount = 0;
363 CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type));
365 LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);
369 lnet_unregister_lnd (lnd_t *lnd)
371 LNET_MUTEX_DOWN(&the_lnet.ln_lnd_mutex);
373 LASSERT (the_lnet.ln_init);
374 LASSERT (lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
375 LASSERT (lnd->lnd_refcount == 0);
377 list_del (&lnd->lnd_list);
378 CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type));
380 LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);
383 #ifndef LNET_USE_LIB_FREELIST
386 lnet_descriptor_setup (void)
392 lnet_descriptor_cleanup (void)
399 lnet_freelist_init (lnet_freelist_t *fl, int n, int size)
405 size += offsetof (lnet_freeobj_t, fo_contents);
407 LIBCFS_ALLOC(space, n * size);
411 CFS_INIT_LIST_HEAD (&fl->fl_list);
414 fl->fl_objsize = size;
418 memset (space, 0, size);
419 list_add ((struct list_head *)space, &fl->fl_list);
427 lnet_freelist_fini (lnet_freelist_t *fl)
429 struct list_head *el;
432 if (fl->fl_nobjs == 0)
436 for (el = fl->fl_list.next; el != &fl->fl_list; el = el->next)
439 LASSERT (count == fl->fl_nobjs);
441 LIBCFS_FREE(fl->fl_objs, fl->fl_nobjs * fl->fl_objsize);
442 memset (fl, 0, sizeof (*fl));
446 lnet_descriptor_setup (void)
448 /* NB on failure caller must still call lnet_descriptor_cleanup */
452 memset (&the_lnet.ln_free_mes, 0, sizeof (the_lnet.ln_free_mes));
453 memset (&the_lnet.ln_free_msgs, 0, sizeof (the_lnet.ln_free_msgs));
454 memset (&the_lnet.ln_free_mds, 0, sizeof (the_lnet.ln_free_mds));
455 memset (&the_lnet.ln_free_eqs, 0, sizeof (the_lnet.ln_free_eqs));
457 rc = lnet_freelist_init(&the_lnet.ln_free_mes,
458 MAX_MES, sizeof (lnet_me_t));
462 rc = lnet_freelist_init(&the_lnet.ln_free_msgs,
463 MAX_MSGS, sizeof (lnet_msg_t));
467 rc = lnet_freelist_init(&the_lnet.ln_free_mds,
468 MAX_MDS, sizeof (lnet_libmd_t));
472 rc = lnet_freelist_init(&the_lnet.ln_free_eqs,
473 MAX_EQS, sizeof (lnet_eq_t));
478 lnet_descriptor_cleanup (void)
480 lnet_freelist_fini (&the_lnet.ln_free_mes);
481 lnet_freelist_fini (&the_lnet.ln_free_msgs);
482 lnet_freelist_fini (&the_lnet.ln_free_mds);
483 lnet_freelist_fini (&the_lnet.ln_free_eqs);
489 lnet_create_interface_cookie (void)
491 /* NB the interface cookie in wire handles guards against delayed
492 * replies and ACKs appearing valid after reboot. Initialisation time,
493 * even if it's only implemented to millisecond resolution is probably
494 * easily good enough. */
498 int rc = gettimeofday (&tv, NULL);
501 do_gettimeofday(&tv);
505 cookie += tv.tv_usec;
510 lnet_setup_handle_hash (void)
514 /* Arbitrary choice of hash table size */
516 the_lnet.ln_lh_hash_size = CFS_PAGE_SIZE / sizeof (struct list_head);
518 the_lnet.ln_lh_hash_size = (MAX_MES + MAX_MDS + MAX_EQS)/4;
520 LIBCFS_ALLOC(the_lnet.ln_lh_hash_table,
521 the_lnet.ln_lh_hash_size * sizeof (struct list_head));
522 if (the_lnet.ln_lh_hash_table == NULL)
525 for (i = 0; i < the_lnet.ln_lh_hash_size; i++)
526 CFS_INIT_LIST_HEAD (&the_lnet.ln_lh_hash_table[i]);
528 the_lnet.ln_next_object_cookie = LNET_COOKIE_TYPES;
534 lnet_cleanup_handle_hash (void)
536 if (the_lnet.ln_lh_hash_table == NULL)
539 LIBCFS_FREE(the_lnet.ln_lh_hash_table,
540 the_lnet.ln_lh_hash_size * sizeof (struct list_head));
544 lnet_lookup_cookie (__u64 cookie, int type)
546 /* ALWAYS called with LNET_LOCK held */
547 struct list_head *list;
548 struct list_head *el;
551 if ((cookie & (LNET_COOKIE_TYPES - 1)) != type)
554 hash = ((unsigned int)cookie) % the_lnet.ln_lh_hash_size;
555 list = &the_lnet.ln_lh_hash_table[hash];
557 list_for_each (el, list) {
558 lnet_libhandle_t *lh = list_entry (el, lnet_libhandle_t,
561 if (lh->lh_cookie == cookie)
569 lnet_initialise_handle (lnet_libhandle_t *lh, int type)
571 /* ALWAYS called with LNET_LOCK held */
574 LASSERT (type >= 0 && type < LNET_COOKIE_TYPES);
575 lh->lh_cookie = the_lnet.ln_next_object_cookie | type;
576 the_lnet.ln_next_object_cookie += LNET_COOKIE_TYPES;
578 hash = ((unsigned int)lh->lh_cookie) % the_lnet.ln_lh_hash_size;
579 list_add (&lh->lh_hash_chain, &the_lnet.ln_lh_hash_table[hash]);
583 lnet_invalidate_handle (lnet_libhandle_t *lh)
585 /* ALWAYS called with LNET_LOCK held */
586 list_del (&lh->lh_hash_chain);
590 lnet_init_finalizers(void)
595 the_lnet.ln_nfinalizers = num_online_cpus();
597 LIBCFS_ALLOC(the_lnet.ln_finalizers,
598 the_lnet.ln_nfinalizers *
599 sizeof(*the_lnet.ln_finalizers));
600 if (the_lnet.ln_finalizers == NULL) {
601 CERROR("Can't allocate ln_finalizers\n");
605 for (i = 0; i < the_lnet.ln_nfinalizers; i++)
606 the_lnet.ln_finalizers[i] = NULL;
608 the_lnet.ln_finalizing = 0;
611 CFS_INIT_LIST_HEAD(&the_lnet.ln_finalizeq);
616 lnet_fini_finalizers(void)
621 for (i = 0; i < the_lnet.ln_nfinalizers; i++)
622 LASSERT (the_lnet.ln_finalizers[i] == NULL);
624 LIBCFS_FREE(the_lnet.ln_finalizers,
625 the_lnet.ln_nfinalizers *
626 sizeof(*the_lnet.ln_finalizers));
628 LASSERT (!the_lnet.ln_finalizing);
630 LASSERT (list_empty(&the_lnet.ln_finalizeq));
634 /* Temporary workaround to allow uOSS and test programs force server
635 * mode in userspace. See comments near ln_server_mode_flag in
636 * lnet/lib-types.h */
640 the_lnet.ln_server_mode_flag = 1;
645 lnet_prepare(lnet_pid_t requested_pid)
647 /* Prepare to bring up the network */
651 LASSERT (the_lnet.ln_refcount == 0);
653 the_lnet.ln_routing = 0;
656 LASSERT ((requested_pid & LNET_PID_USERFLAG) == 0);
657 the_lnet.ln_pid = requested_pid;
659 if (the_lnet.ln_server_mode_flag) {/* server case (uOSS) */
660 LASSERT ((requested_pid & LNET_PID_USERFLAG) == 0);
662 if (cfs_curproc_uid())/* Only root can run user-space server */
664 the_lnet.ln_pid = requested_pid;
666 } else {/* client case (liblustre) */
668 /* My PID must be unique on this node and flag I'm userspace */
669 the_lnet.ln_pid = getpid() | LNET_PID_USERFLAG;
673 rc = lnet_descriptor_setup();
677 memset(&the_lnet.ln_counters, 0,
678 sizeof(the_lnet.ln_counters));
680 CFS_INIT_LIST_HEAD (&the_lnet.ln_active_msgs);
681 CFS_INIT_LIST_HEAD (&the_lnet.ln_active_mds);
682 CFS_INIT_LIST_HEAD (&the_lnet.ln_active_eqs);
683 CFS_INIT_LIST_HEAD (&the_lnet.ln_test_peers);
684 CFS_INIT_LIST_HEAD (&the_lnet.ln_nis);
685 CFS_INIT_LIST_HEAD (&the_lnet.ln_zombie_nis);
686 CFS_INIT_LIST_HEAD (&the_lnet.ln_remote_nets);
687 CFS_INIT_LIST_HEAD (&the_lnet.ln_routers);
689 the_lnet.ln_interface_cookie = lnet_create_interface_cookie();
691 lnet_init_rtrpools();
693 rc = lnet_setup_handle_hash ();
697 rc = lnet_create_peer_table();
701 rc = lnet_init_finalizers();
705 the_lnet.ln_nportals = MAX_PORTALS;
706 LIBCFS_ALLOC(the_lnet.ln_portals,
707 the_lnet.ln_nportals *
708 sizeof(*the_lnet.ln_portals));
709 if (the_lnet.ln_portals == NULL) {
714 for (i = 0; i < the_lnet.ln_nportals; i++) {
715 CFS_INIT_LIST_HEAD(&(the_lnet.ln_portals[i].ptl_ml));
716 CFS_INIT_LIST_HEAD(&(the_lnet.ln_portals[i].ptl_msgq));
717 the_lnet.ln_portals[i].ptl_options = 0;
723 lnet_fini_finalizers();
725 lnet_destroy_peer_table();
727 lnet_cleanup_handle_hash();
729 lnet_descriptor_cleanup();
734 lnet_unprepare (void)
738 /* NB no LNET_LOCK since this is the last reference. All LND instances
739 * have shut down already, so it is safe to unlink and free all
740 * descriptors, even those that appear committed to a network op (eg MD
741 * with non-zero pending count) */
743 lnet_fail_nid(LNET_NID_ANY, 0);
745 LASSERT (list_empty(&the_lnet.ln_test_peers));
746 LASSERT (the_lnet.ln_refcount == 0);
747 LASSERT (list_empty(&the_lnet.ln_nis));
748 LASSERT (list_empty(&the_lnet.ln_zombie_nis));
749 LASSERT (the_lnet.ln_nzombie_nis == 0);
751 for (idx = 0; idx < the_lnet.ln_nportals; idx++) {
752 LASSERT (list_empty(&the_lnet.ln_portals[idx].ptl_msgq));
754 while (!list_empty (&the_lnet.ln_portals[idx].ptl_ml)) {
755 lnet_me_t *me = list_entry (the_lnet.ln_portals[idx].ptl_ml.next,
758 CERROR ("Active me %p on exit\n", me);
759 list_del (&me->me_list);
764 while (!list_empty (&the_lnet.ln_active_mds)) {
765 lnet_libmd_t *md = list_entry (the_lnet.ln_active_mds.next,
766 lnet_libmd_t, md_list);
768 CERROR ("Active md %p on exit\n", md);
769 list_del_init (&md->md_list);
773 while (!list_empty (&the_lnet.ln_active_eqs)) {
774 lnet_eq_t *eq = list_entry (the_lnet.ln_active_eqs.next,
777 CERROR ("Active eq %p on exit\n", eq);
778 list_del (&eq->eq_list);
782 while (!list_empty (&the_lnet.ln_active_msgs)) {
783 lnet_msg_t *msg = list_entry (the_lnet.ln_active_msgs.next,
784 lnet_msg_t, msg_activelist);
786 CERROR ("Active msg %p on exit\n", msg);
787 LASSERT (msg->msg_onactivelist);
788 msg->msg_onactivelist = 0;
789 list_del (&msg->msg_activelist);
793 LIBCFS_FREE(the_lnet.ln_portals,
794 the_lnet.ln_nportals * sizeof(*the_lnet.ln_portals));
796 lnet_free_rtrpools();
797 lnet_fini_finalizers();
798 lnet_destroy_peer_table();
799 lnet_cleanup_handle_hash();
800 lnet_descriptor_cleanup();
806 lnet_net2ni_locked (__u32 net)
808 struct list_head *tmp;
811 list_for_each (tmp, &the_lnet.ln_nis) {
812 ni = list_entry(tmp, lnet_ni_t, ni_list);
814 if (lnet_ptlcompat_matchnet(LNET_NIDNET(ni->ni_nid), net)) {
815 lnet_ni_addref_locked(ni);
824 lnet_islocalnet (__u32 net)
829 ni = lnet_net2ni_locked(net);
831 lnet_ni_decref_locked(ni);
838 lnet_nid2ni_locked (lnet_nid_t nid)
840 struct list_head *tmp;
843 list_for_each (tmp, &the_lnet.ln_nis) {
844 ni = list_entry(tmp, lnet_ni_t, ni_list);
846 if (lnet_ptlcompat_matchnid(ni->ni_nid, nid)) {
847 lnet_ni_addref_locked(ni);
856 lnet_islocalnid (lnet_nid_t nid)
861 ni = lnet_nid2ni_locked(nid);
863 lnet_ni_decref_locked(ni);
870 lnet_count_acceptor_nis (lnet_ni_t **first_ni)
872 /* Return the # of NIs that need the acceptor. Return the first one in
873 * *first_ni so the acceptor can pass it connections "blind" to retain
874 * binary compatibility. */
876 #if defined(__KERNEL__) || defined(HAVE_LIBPTHREAD)
877 struct list_head *tmp;
881 list_for_each (tmp, &the_lnet.ln_nis) {
882 ni = list_entry(tmp, lnet_ni_t, ni_list);
884 if (ni->ni_lnd->lnd_accept != NULL) {
885 /* This LND uses the acceptor */
886 if (count == 0 && first_ni != NULL) {
887 lnet_ni_addref_locked(ni);
896 #endif /* defined(__KERNEL__) || defined(HAVE_LIBPTHREAD) */
901 lnet_shutdown_lndnis (void)
907 /* NB called holding the global mutex */
909 /* All quiet on the API front */
910 LASSERT (!the_lnet.ln_shutdown);
911 LASSERT (the_lnet.ln_refcount == 0);
912 LASSERT (list_empty(&the_lnet.ln_zombie_nis));
913 LASSERT (the_lnet.ln_nzombie_nis == 0);
914 LASSERT (list_empty(&the_lnet.ln_remote_nets));
917 the_lnet.ln_shutdown = 1; /* flag shutdown */
919 /* Unlink NIs from the global table */
920 while (!list_empty(&the_lnet.ln_nis)) {
921 ni = list_entry(the_lnet.ln_nis.next,
923 list_del (&ni->ni_list);
925 the_lnet.ln_nzombie_nis++;
926 lnet_ni_decref_locked(ni); /* drop apini's ref */
929 /* Drop the cached eqwait NI. */
930 if (the_lnet.ln_eqwaitni != NULL) {
931 lnet_ni_decref_locked(the_lnet.ln_eqwaitni);
932 the_lnet.ln_eqwaitni = NULL;
935 /* Drop the cached loopback NI. */
936 if (the_lnet.ln_loni != NULL) {
937 lnet_ni_decref_locked(the_lnet.ln_loni);
938 the_lnet.ln_loni = NULL;
943 /* Clear lazy portals and drop delayed messages which hold refs
944 * on their lnet_msg_t::msg_rxpeer */
945 for (i = 0; i < the_lnet.ln_nportals; i++)
946 LNetClearLazyPortal(i);
948 /* Clear the peer table and wait for all peers to go (they hold refs on
950 lnet_clear_peer_table();
953 /* Now wait for the NI's I just nuked to show up on apini_zombie_nis
954 * and shut them down in guaranteed thread context */
956 while (the_lnet.ln_nzombie_nis != 0) {
958 while (list_empty(&the_lnet.ln_zombie_nis)) {
962 CDEBUG(D_WARNING,"Waiting for %d zombie NIs\n",
963 the_lnet.ln_nzombie_nis);
964 cfs_pause(cfs_time_seconds(1));
968 ni = list_entry(the_lnet.ln_zombie_nis.next,
970 list_del(&ni->ni_list);
971 ni->ni_lnd->lnd_refcount--;
975 islo = ni->ni_lnd->lnd_type == LOLND;
977 LASSERT (!in_interrupt ());
978 (ni->ni_lnd->lnd_shutdown)(ni);
980 /* can't deref lnd anymore now; it might have unregistered
984 CDEBUG(D_LNI, "Removed LNI %s\n",
985 libcfs_nid2str(ni->ni_nid));
987 LIBCFS_FREE(ni, sizeof(*ni));
990 the_lnet.ln_nzombie_nis--;
993 the_lnet.ln_shutdown = 0;
996 if (the_lnet.ln_network_tokens != NULL) {
997 LIBCFS_FREE(the_lnet.ln_network_tokens,
998 the_lnet.ln_network_tokens_nob);
999 the_lnet.ln_network_tokens = NULL;
1004 lnet_startup_lndnis (void)
1008 struct list_head nilist;
1012 char *nets = lnet_get_networks();
1014 CFS_INIT_LIST_HEAD(&nilist);
1019 rc = lnet_parse_networks(&nilist, nets);
1023 while (!list_empty(&nilist)) {
1024 ni = list_entry(nilist.next, lnet_ni_t, ni_list);
1025 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
1027 LASSERT (libcfs_isknown_lnd(lnd_type));
1029 LNET_MUTEX_DOWN(&the_lnet.ln_lnd_mutex);
1030 lnd = lnet_find_lnd_by_type(lnd_type);
1034 LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);
1035 rc = request_module("%s", libcfs_lnd2modname(lnd_type));
1036 LNET_MUTEX_DOWN(&the_lnet.ln_lnd_mutex);
1038 lnd = lnet_find_lnd_by_type(lnd_type);
1040 LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);
1041 CERROR("Can't load LND %s, module %s, rc=%d\n",
1042 libcfs_lnd2str(lnd_type),
1043 libcfs_lnd2modname(lnd_type), rc);
1045 LCONSOLE_ERROR_MSG(0x104, "Your kernel must be "
1046 "compiled with CONFIG_KMOD set for "
1047 "automatic module loading.");
1054 LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);
1055 CERROR("LND %s not supported\n",
1056 libcfs_lnd2str(lnd_type));
1061 ni->ni_refcount = 1;
1064 lnd->lnd_refcount++;
1069 rc = (lnd->lnd_startup)(ni);
1071 LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);
1074 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s"
1076 rc, libcfs_lnd2str(lnd->lnd_type));
1078 lnd->lnd_refcount--;
1083 LASSERT (ni->ni_peertimeout <= 0 || lnd->lnd_query != NULL);
1085 list_del(&ni->ni_list);
1088 list_add_tail(&ni->ni_list, &the_lnet.ln_nis);
1091 if (lnd->lnd_type == LOLND) {
1093 LASSERT (the_lnet.ln_loni == NULL);
1094 the_lnet.ln_loni = ni;
1099 if (lnd->lnd_wait != NULL) {
1100 if (the_lnet.ln_eqwaitni == NULL) {
1102 the_lnet.ln_eqwaitni = ni;
1105 # ifndef HAVE_LIBPTHREAD
1106 LCONSOLE_ERROR_MSG(0x106, "LND %s not supported in a "
1107 "single-threaded runtime\n",
1108 libcfs_lnd2str(lnd_type));
1113 if (ni->ni_peertxcredits == 0 ||
1114 ni->ni_maxtxcredits == 0) {
1115 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
1116 libcfs_lnd2str(lnd->lnd_type),
1117 ni->ni_peertxcredits == 0 ?
1122 ni->ni_txcredits = ni->ni_mintxcredits = ni->ni_maxtxcredits;
1124 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d]\n",
1125 libcfs_nid2str(ni->ni_nid),
1126 ni->ni_peertxcredits, ni->ni_txcredits,
1127 ni->ni_peertimeout);
1129 /* Handle nidstrings for network 0 just like this one */
1130 if (the_lnet.ln_ptlcompat > 0) {
1132 LCONSOLE_ERROR_MSG(0x108, "Can't run > 1 "
1133 "network when portals_compatibility is "
1137 libcfs_setnet0alias(lnd->lnd_type);
1143 if (the_lnet.ln_eqwaitni != NULL && nicount > 1) {
1144 lnd_type = the_lnet.ln_eqwaitni->ni_lnd->lnd_type;
1145 LCONSOLE_ERROR_MSG(0x109, "LND %s can only run single-network"
1147 libcfs_lnd2str(lnd_type));
1154 lnet_shutdown_lndnis();
1156 while (!list_empty(&nilist)) {
1157 ni = list_entry(nilist.next, lnet_ni_t, ni_list);
1158 list_del(&ni->ni_list);
1159 LIBCFS_FREE(ni, sizeof(*ni));
1170 lnet_assert_wire_constants ();
1171 LASSERT (!the_lnet.ln_init);
1173 memset(&the_lnet, 0, sizeof(the_lnet));
1175 rc = lnet_get_portals_compatibility();
1180 CFS_INIT_LIST_HEAD(&the_lnet.ln_lnds);
1181 the_lnet.ln_ptlcompat = rc;
1182 the_lnet.ln_refcount = 0;
1183 the_lnet.ln_init = 1;
1186 /* All LNDs apart from the LOLND are in separate modules. They
1187 * register themselves when their module loads, and unregister
1188 * themselves when their module is unloaded. */
1191 * NB the order here determines default 'networks=' order */
1193 LNET_REGISTER_ULND(the_ptllnd);
1195 # ifdef HAVE_LIBPTHREAD
1196 LNET_REGISTER_ULND(the_tcplnd);
1199 lnet_register_lnd(&the_lolnd);
1206 LASSERT (the_lnet.ln_init);
1207 LASSERT (the_lnet.ln_refcount == 0);
1209 while (!list_empty(&the_lnet.ln_lnds))
1210 lnet_unregister_lnd(list_entry(the_lnet.ln_lnds.next,
1214 the_lnet.ln_init = 0;
1218 LNetNIInit(lnet_pid_t requested_pid)
1220 int im_a_router = 0;
1223 LNET_MUTEX_DOWN(&the_lnet.ln_api_mutex);
1225 LASSERT (the_lnet.ln_init);
1226 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
1228 if (the_lnet.ln_refcount > 0) {
1229 rc = the_lnet.ln_refcount++;
1233 if (requested_pid == LNET_PID_ANY) {
1234 /* Don't instantiate LNET just for me */
1239 rc = lnet_prepare(requested_pid);
1243 rc = lnet_startup_lndnis();
1247 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
1251 rc = lnet_check_routes();
1255 rc = lnet_alloc_rtrpools(im_a_router);
1259 rc = lnet_acceptor_start();
1263 the_lnet.ln_refcount = 1;
1264 /* Now I may use my own API functions... */
1266 rc = lnet_router_checker_start();
1270 rc = lnet_ping_target_init();
1278 lnet_router_checker_stop();
1280 the_lnet.ln_refcount = 0;
1281 lnet_acceptor_stop();
1283 lnet_destroy_routes();
1284 lnet_shutdown_lndnis();
1290 LNET_MUTEX_UP(&the_lnet.ln_api_mutex);
1297 LNET_MUTEX_DOWN(&the_lnet.ln_api_mutex);
1299 LASSERT (the_lnet.ln_init);
1300 LASSERT (the_lnet.ln_refcount > 0);
1302 if (the_lnet.ln_refcount != 1) {
1303 the_lnet.ln_refcount--;
1305 LASSERT (!the_lnet.ln_niinit_self);
1308 lnet_ping_target_fini();
1309 lnet_router_checker_stop();
1311 /* Teardown fns that use my own API functions BEFORE here */
1312 the_lnet.ln_refcount = 0;
1314 lnet_acceptor_stop();
1315 lnet_destroy_routes();
1316 lnet_shutdown_lndnis();
1320 LNET_MUTEX_UP(&the_lnet.ln_api_mutex);
1325 LNetCtl(unsigned int cmd, void *arg)
1327 struct libcfs_ioctl_data *data = arg;
1328 lnet_process_id_t id;
1332 LASSERT (the_lnet.ln_init);
1333 LASSERT (the_lnet.ln_refcount > 0);
1336 case IOC_LIBCFS_GET_NI:
1337 rc = LNetGetId(data->ioc_count, &id);
1338 data->ioc_nid = id.nid;
1341 case IOC_LIBCFS_FAIL_NID:
1342 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
1344 case IOC_LIBCFS_ADD_ROUTE:
1345 rc = lnet_add_route(data->ioc_net, data->ioc_count,
1347 return (rc != 0) ? rc : lnet_check_routes();
1349 case IOC_LIBCFS_DEL_ROUTE:
1350 return lnet_del_route(data->ioc_net, data->ioc_nid);
1352 case IOC_LIBCFS_GET_ROUTE:
1353 return lnet_get_route(data->ioc_count,
1354 &data->ioc_net, &data->ioc_count,
1355 &data->ioc_nid, &data->ioc_flags);
1356 case IOC_LIBCFS_NOTIFY_ROUTER:
1357 return lnet_notify(NULL, data->ioc_nid, data->ioc_flags,
1358 (time_t)data->ioc_u64[0]);
1360 case IOC_LIBCFS_PORTALS_COMPATIBILITY:
1361 return the_lnet.ln_ptlcompat;
1363 case IOC_LIBCFS_LNET_DIST:
1364 rc = LNetDist(data->ioc_nid, &data->ioc_nid, &data->ioc_u32[1]);
1365 if (rc < 0 && rc != -EHOSTUNREACH)
1368 data->ioc_u32[0] = rc;
1371 case IOC_LIBCFS_TESTPROTOCOMPAT:
1373 the_lnet.ln_testprotocompat = data->ioc_flags;
1377 case IOC_LIBCFS_PING:
1378 rc = lnet_ping((lnet_process_id_t) {.nid = data->ioc_nid,
1379 .pid = data->ioc_u32[0]},
1380 data->ioc_u32[1], /* timeout */
1381 (lnet_process_id_t *)data->ioc_pbuf1,
1382 data->ioc_plen1/sizeof(lnet_process_id_t));
1385 data->ioc_count = rc;
1388 case IOC_LIBCFS_DEBUG_PEER: {
1389 /* CAVEAT EMPTOR: this one designed for calling directly; not
1391 lnet_process_id_t *id = arg;
1393 lnet_debug_peer(id->nid);
1395 ni = lnet_net2ni(LNET_NIDNET(id->nid));
1397 CDEBUG(D_WARNING, "No NI for %s\n", libcfs_id2str(*id));
1399 if (ni->ni_lnd->lnd_ctl == NULL) {
1400 CDEBUG(D_WARNING, "No ctl for %s\n",
1401 libcfs_id2str(*id));
1403 (void)ni->ni_lnd->lnd_ctl(ni, cmd, arg);
1412 ni = lnet_net2ni(data->ioc_net);
1416 if (ni->ni_lnd->lnd_ctl == NULL)
1419 rc = ni->ni_lnd->lnd_ctl(ni, cmd, arg);
1428 LNetGetId(unsigned int index, lnet_process_id_t *id)
1431 struct list_head *tmp;
1434 LASSERT (the_lnet.ln_init);
1435 LASSERT (the_lnet.ln_refcount > 0);
1439 list_for_each(tmp, &the_lnet.ln_nis) {
1443 ni = list_entry(tmp, lnet_ni_t, ni_list);
1445 id->nid = ni->ni_nid;
1446 id->pid = the_lnet.ln_pid;
1457 LNetSnprintHandle(char *str, int len, lnet_handle_any_t h)
1459 snprintf(str, len, LPX64, h.cookie);
1464 lnet_ping_target_init(void)
1466 lnet_handle_me_t meh;
1467 lnet_process_id_t id;
1474 for (n = 0; ; n++) {
1475 rc = LNetGetId(n, &id);
1482 infosz = offsetof(lnet_ping_info_t, pi_nid[n]);
1483 LIBCFS_ALLOC(the_lnet.ln_ping_info, infosz);
1484 if (the_lnet.ln_ping_info == NULL) {
1485 CERROR("Can't allocate ping info[%d]\n", n);
1489 the_lnet.ln_ping_info->pi_magic = LNET_PROTO_PING_MAGIC;
1490 the_lnet.ln_ping_info->pi_version = LNET_PROTO_PING_VERSION;
1491 the_lnet.ln_ping_info->pi_pid = the_lnet.ln_pid;
1492 the_lnet.ln_ping_info->pi_nnids = n;
1494 for (i = 0; i < n; i++) {
1495 rc = LNetGetId(i, &id);
1497 the_lnet.ln_ping_info->pi_nid[i] = id.nid;
1500 /* We can have a tiny EQ since we only need to see the unlink event on
1501 * teardown, which by definition is the last one! */
1502 rc = LNetEQAlloc(2, LNET_EQ_HANDLER_NONE, &the_lnet.ln_ping_target_eq);
1504 CERROR("Can't allocate ping EQ: %d\n", rc);
1508 rc = LNetMEAttach(LNET_RESERVED_PORTAL,
1509 (lnet_process_id_t){.nid = LNET_NID_ANY,
1510 .pid = LNET_PID_ANY},
1511 LNET_PROTO_PING_MATCHBITS, 0LL,
1512 LNET_UNLINK, LNET_INS_AFTER,
1515 CERROR("Can't create ping ME: %d\n", rc);
1519 rc = LNetMDAttach(meh,
1520 (lnet_md_t){.start = the_lnet.ln_ping_info,
1522 .threshold = LNET_MD_THRESH_INF,
1523 .options = (LNET_MD_OP_GET |
1525 LNET_MD_MANAGE_REMOTE),
1526 .eq_handle = the_lnet.ln_ping_target_eq},
1528 &the_lnet.ln_ping_target_md);
1530 CERROR("Can't attach ping MD: %d\n", rc);
1537 rc2 = LNetMEUnlink(meh);
1540 rc2 = LNetEQFree(the_lnet.ln_ping_target_eq);
1543 LIBCFS_FREE(the_lnet.ln_ping_info, infosz);
1549 lnet_ping_target_fini(void)
1554 int timeout_ms = 1000;
1555 cfs_sigset_t blocked = cfs_block_allsigs();
1557 LNetMDUnlink(the_lnet.ln_ping_target_md);
1558 /* NB md could be busy; this just starts the unlink */
1561 rc = LNetEQPoll(&the_lnet.ln_ping_target_eq, 1,
1562 timeout_ms, &event, &which);
1564 /* I expect overflow... */
1565 LASSERT (rc >= 0 || rc == -EOVERFLOW);
1568 /* timed out: provide a diagnostic */
1569 CWARN("Still waiting for ping MD to unlink\n");
1574 /* Got a valid event */
1579 rc = LNetEQFree(the_lnet.ln_ping_target_eq);
1582 LIBCFS_FREE(the_lnet.ln_ping_info,
1583 offsetof(lnet_ping_info_t,
1584 pi_nid[the_lnet.ln_ping_info->pi_nnids]));
1586 cfs_restore_sigs(blocked);
1590 lnet_ping (lnet_process_id_t id, int timeout_ms, lnet_process_id_t *ids, int n_ids)
1592 lnet_handle_eq_t eqh;
1593 lnet_handle_md_t mdh;
1598 const int a_long_time = 60000; /* mS */
1599 int infosz = offsetof(lnet_ping_info_t, pi_nid[n_ids]);
1600 lnet_ping_info_t *info;
1601 lnet_process_id_t tmpid;
1606 cfs_sigset_t blocked;
1609 id.nid == LNET_NID_ANY ||
1610 timeout_ms > 500000 || /* arbitrary limit! */
1611 n_ids > 20) /* arbitrary limit! */
1614 if (id.pid == LNET_PID_ANY)
1615 id.pid = LUSTRE_SRV_LNET_PID;
1617 LIBCFS_ALLOC(info, infosz);
1621 /* NB 2 events max (including any unlink event) */
1622 rc = LNetEQAlloc(2, LNET_EQ_HANDLER_NONE, &eqh);
1624 CERROR("Can't allocate EQ: %d\n", rc);
1628 rc = LNetMDBind((lnet_md_t){.start = info,
1630 .threshold = 2, /* GET/REPLY */
1631 .options = LNET_MD_TRUNCATE,
1636 CERROR("Can't bind MD: %d\n", rc);
1640 rc = LNetGet(LNET_NID_ANY, mdh, id,
1641 LNET_RESERVED_PORTAL,
1642 LNET_PROTO_PING_MATCHBITS, 0);
1645 /* Don't CERROR; this could be deliberate! */
1647 rc2 = LNetMDUnlink(mdh);
1650 /* NB must wait for the UNLINK event below... */
1652 timeout_ms = a_long_time;
1656 /* MUST block for unlink to complete */
1658 blocked = cfs_block_allsigs();
1660 rc2 = LNetEQPoll(&eqh, 1, timeout_ms, &event, &which);
1663 cfs_restore_sigs(blocked);
1665 CDEBUG(D_NET, "poll %d(%d %d)%s\n", rc2,
1666 (rc2 <= 0) ? -1 : event.type,
1667 (rc2 <= 0) ? -1 : event.status,
1668 (rc2 > 0 && event.unlinked) ? " unlinked" : "");
1670 LASSERT (rc2 != -EOVERFLOW); /* can't miss anything */
1672 if (rc2 <= 0 || event.status != 0) {
1673 /* timeout or error */
1674 if (!replied && rc == 0)
1675 rc = (rc2 < 0) ? rc2 :
1676 (rc2 == 0) ? -ETIMEDOUT :
1680 /* Ensure completion in finite time... */
1682 /* No assertion (racing with network) */
1684 timeout_ms = a_long_time;
1685 } else if (rc2 == 0) {
1686 /* timed out waiting for unlink */
1687 CWARN("ping %s: late network completion\n",
1691 } else if (event.type == LNET_EVENT_REPLY) {
1696 } while (rc2 <= 0 || !event.unlinked);
1700 CWARN("%s: Unexpected rc >= 0 but no reply!\n",
1707 LASSERT (nob >= 0 && nob <= infosz);
1709 rc = -EPROTO; /* if I can't parse... */
1712 /* can't check magic/version */
1713 CERROR("%s: ping info too short %d\n",
1714 libcfs_id2str(id), nob);
1718 if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) {
1719 /* NB I might be swabbing garbage until I check below, but it
1721 __swab32s(&info->pi_version);
1722 __swab32s(&info->pi_pid);
1723 __swab32s(&info->pi_nnids);
1724 for (i = 0; i < info->pi_nnids && i < n_ids; i++)
1725 __swab64s(&info->pi_nid[i]);
1727 } else if (info->pi_magic != LNET_PROTO_PING_MAGIC) {
1728 CERROR("%s: Unexpected magic %08x\n",
1729 libcfs_id2str(id), info->pi_magic);
1733 if (info->pi_version != LNET_PROTO_PING_VERSION) {
1734 CERROR("%s: Unexpected version 0x%x\n",
1735 libcfs_id2str(id), info->pi_version);
1739 if (nob < offsetof(lnet_ping_info_t, pi_nid[0])) {
1740 CERROR("%s: Short reply %d(%d min)\n", libcfs_id2str(id),
1741 nob, (int)offsetof(lnet_ping_info_t, pi_nid[0]));
1745 if (info->pi_nnids < n_ids)
1746 n_ids = info->pi_nnids;
1748 if (nob < offsetof(lnet_ping_info_t, pi_nid[n_ids])) {
1749 CERROR("%s: Short reply %d(%d expected)\n", libcfs_id2str(id),
1750 nob, (int)offsetof(lnet_ping_info_t, pi_nid[n_ids]));
1754 rc = -EFAULT; /* If I SEGV... */
1756 for (i = 0; i < n_ids; i++) {
1757 tmpid.pid = info->pi_pid;
1758 tmpid.nid = info->pi_nid[i];
1760 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid)))
1766 rc = info->pi_nnids;
1769 rc2 = LNetEQFree(eqh);
1771 CERROR("rc2 %d\n", rc2);
1775 LIBCFS_FREE(info, infosz);