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")) {
103 LCONSOLE_WARN("Starting in weak portals-compatible mode\n");
107 if (!strcmp(portals_compatibility, "strong")) {
108 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_portal_mhash_alloc(void)
592 struct list_head *mhash;
595 LIBCFS_ALLOC(mhash, sizeof(struct list_head) * LNET_PORTAL_HASH_SIZE);
599 for (i = 0; i < LNET_PORTAL_HASH_SIZE; i++)
600 CFS_INIT_LIST_HEAD(&mhash[i]);
606 lnet_portal_mhash_free(struct list_head *mhash)
610 for (i = 0; i < LNET_PORTAL_HASH_SIZE; i++) {
611 while (!list_empty(&mhash[i])) {
612 lnet_me_t *me = list_entry (mhash[i].next,
614 CERROR ("Active ME %p on exit portal mhash\n", me);
615 list_del (&me->me_list);
619 LIBCFS_FREE(mhash, sizeof(struct list_head) * LNET_PORTAL_HASH_SIZE);
623 lnet_init_finalizers(void)
628 the_lnet.ln_nfinalizers = num_online_cpus();
630 LIBCFS_ALLOC(the_lnet.ln_finalizers,
631 the_lnet.ln_nfinalizers *
632 sizeof(*the_lnet.ln_finalizers));
633 if (the_lnet.ln_finalizers == NULL) {
634 CERROR("Can't allocate ln_finalizers\n");
638 for (i = 0; i < the_lnet.ln_nfinalizers; i++)
639 the_lnet.ln_finalizers[i] = NULL;
641 the_lnet.ln_finalizing = 0;
644 CFS_INIT_LIST_HEAD(&the_lnet.ln_finalizeq);
649 lnet_fini_finalizers(void)
654 for (i = 0; i < the_lnet.ln_nfinalizers; i++)
655 LASSERT (the_lnet.ln_finalizers[i] == NULL);
657 LIBCFS_FREE(the_lnet.ln_finalizers,
658 the_lnet.ln_nfinalizers *
659 sizeof(*the_lnet.ln_finalizers));
661 LASSERT (!the_lnet.ln_finalizing);
663 LASSERT (list_empty(&the_lnet.ln_finalizeq));
667 /* Temporary workaround to allow uOSS and test programs force server
668 * mode in userspace. See comments near ln_server_mode_flag in
669 * lnet/lib-types.h */
673 the_lnet.ln_server_mode_flag = 1;
678 lnet_prepare(lnet_pid_t requested_pid)
680 /* Prepare to bring up the network */
684 LASSERT (the_lnet.ln_refcount == 0);
686 the_lnet.ln_routing = 0;
689 LASSERT ((requested_pid & LNET_PID_USERFLAG) == 0);
690 the_lnet.ln_pid = requested_pid;
692 if (the_lnet.ln_server_mode_flag) {/* server case (uOSS) */
693 LASSERT ((requested_pid & LNET_PID_USERFLAG) == 0);
695 if (cfs_curproc_uid())/* Only root can run user-space server */
697 the_lnet.ln_pid = requested_pid;
699 } else {/* client case (liblustre) */
701 /* My PID must be unique on this node and flag I'm userspace */
702 the_lnet.ln_pid = getpid() | LNET_PID_USERFLAG;
706 rc = lnet_descriptor_setup();
710 memset(&the_lnet.ln_counters, 0,
711 sizeof(the_lnet.ln_counters));
713 CFS_INIT_LIST_HEAD (&the_lnet.ln_active_msgs);
714 CFS_INIT_LIST_HEAD (&the_lnet.ln_active_mds);
715 CFS_INIT_LIST_HEAD (&the_lnet.ln_active_eqs);
716 CFS_INIT_LIST_HEAD (&the_lnet.ln_test_peers);
717 CFS_INIT_LIST_HEAD (&the_lnet.ln_nis);
718 CFS_INIT_LIST_HEAD (&the_lnet.ln_zombie_nis);
719 CFS_INIT_LIST_HEAD (&the_lnet.ln_remote_nets);
720 CFS_INIT_LIST_HEAD (&the_lnet.ln_routers);
722 the_lnet.ln_interface_cookie = lnet_create_interface_cookie();
724 lnet_init_rtrpools();
726 rc = lnet_setup_handle_hash ();
730 rc = lnet_create_peer_table();
734 rc = lnet_init_finalizers();
738 the_lnet.ln_nportals = MAX_PORTALS;
739 LIBCFS_ALLOC(the_lnet.ln_portals,
740 the_lnet.ln_nportals *
741 sizeof(*the_lnet.ln_portals));
742 if (the_lnet.ln_portals == NULL) {
747 for (i = 0; i < the_lnet.ln_nportals; i++) {
748 CFS_INIT_LIST_HEAD(&(the_lnet.ln_portals[i].ptl_mlist));
749 CFS_INIT_LIST_HEAD(&(the_lnet.ln_portals[i].ptl_msgq));
750 the_lnet.ln_portals[i].ptl_options = 0;
756 lnet_fini_finalizers();
758 lnet_destroy_peer_table();
760 lnet_cleanup_handle_hash();
762 lnet_descriptor_cleanup();
767 lnet_unprepare (void)
771 /* NB no LNET_LOCK since this is the last reference. All LND instances
772 * have shut down already, so it is safe to unlink and free all
773 * descriptors, even those that appear committed to a network op (eg MD
774 * with non-zero pending count) */
776 lnet_fail_nid(LNET_NID_ANY, 0);
778 LASSERT (list_empty(&the_lnet.ln_test_peers));
779 LASSERT (the_lnet.ln_refcount == 0);
780 LASSERT (list_empty(&the_lnet.ln_nis));
781 LASSERT (list_empty(&the_lnet.ln_zombie_nis));
782 LASSERT (the_lnet.ln_nzombie_nis == 0);
784 for (idx = 0; idx < the_lnet.ln_nportals; idx++) {
785 LASSERT (list_empty(&the_lnet.ln_portals[idx].ptl_msgq));
787 while (!list_empty (&the_lnet.ln_portals[idx].ptl_mlist)) {
788 lnet_me_t *me = list_entry (the_lnet.ln_portals[idx].ptl_mlist.next,
791 CERROR ("Active ME %p on exit\n", me);
792 list_del (&me->me_list);
796 if (the_lnet.ln_portals[idx].ptl_mhash != NULL) {
797 LASSERT (lnet_portal_is_unique(&the_lnet.ln_portals[idx]));
798 lnet_portal_mhash_free(the_lnet.ln_portals[idx].ptl_mhash);
802 while (!list_empty (&the_lnet.ln_active_mds)) {
803 lnet_libmd_t *md = list_entry (the_lnet.ln_active_mds.next,
804 lnet_libmd_t, md_list);
806 CERROR ("Active MD %p on exit\n", md);
807 list_del_init (&md->md_list);
811 while (!list_empty (&the_lnet.ln_active_eqs)) {
812 lnet_eq_t *eq = list_entry (the_lnet.ln_active_eqs.next,
815 CERROR ("Active EQ %p on exit\n", eq);
816 list_del (&eq->eq_list);
820 while (!list_empty (&the_lnet.ln_active_msgs)) {
821 lnet_msg_t *msg = list_entry (the_lnet.ln_active_msgs.next,
822 lnet_msg_t, msg_activelist);
824 CERROR ("Active msg %p on exit\n", msg);
825 LASSERT (msg->msg_onactivelist);
826 msg->msg_onactivelist = 0;
827 list_del (&msg->msg_activelist);
831 LIBCFS_FREE(the_lnet.ln_portals,
832 the_lnet.ln_nportals * sizeof(*the_lnet.ln_portals));
834 lnet_free_rtrpools();
835 lnet_fini_finalizers();
836 lnet_destroy_peer_table();
837 lnet_cleanup_handle_hash();
838 lnet_descriptor_cleanup();
844 lnet_net2ni_locked (__u32 net)
846 struct list_head *tmp;
849 list_for_each (tmp, &the_lnet.ln_nis) {
850 ni = list_entry(tmp, lnet_ni_t, ni_list);
852 if (lnet_ptlcompat_matchnet(LNET_NIDNET(ni->ni_nid), net)) {
853 lnet_ni_addref_locked(ni);
862 lnet_islocalnet (__u32 net)
867 ni = lnet_net2ni_locked(net);
869 lnet_ni_decref_locked(ni);
876 lnet_nid2ni_locked (lnet_nid_t nid)
878 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 (lnet_ptlcompat_matchnid(ni->ni_nid, nid)) {
885 lnet_ni_addref_locked(ni);
894 lnet_islocalnid (lnet_nid_t nid)
899 ni = lnet_nid2ni_locked(nid);
901 lnet_ni_decref_locked(ni);
908 lnet_count_acceptor_nis (lnet_ni_t **first_ni)
910 /* Return the # of NIs that need the acceptor. Return the first one in
911 * *first_ni so the acceptor can pass it connections "blind" to retain
912 * binary compatibility. */
914 #if defined(__KERNEL__) || defined(HAVE_LIBPTHREAD)
915 struct list_head *tmp;
919 list_for_each (tmp, &the_lnet.ln_nis) {
920 ni = list_entry(tmp, lnet_ni_t, ni_list);
922 if (ni->ni_lnd->lnd_accept != NULL) {
923 /* This LND uses the acceptor */
924 if (count == 0 && first_ni != NULL) {
925 lnet_ni_addref_locked(ni);
934 #endif /* defined(__KERNEL__) || defined(HAVE_LIBPTHREAD) */
939 lnet_shutdown_lndnis (void)
945 /* NB called holding the global mutex */
947 /* All quiet on the API front */
948 LASSERT (!the_lnet.ln_shutdown);
949 LASSERT (the_lnet.ln_refcount == 0);
950 LASSERT (list_empty(&the_lnet.ln_zombie_nis));
951 LASSERT (the_lnet.ln_nzombie_nis == 0);
952 LASSERT (list_empty(&the_lnet.ln_remote_nets));
955 the_lnet.ln_shutdown = 1; /* flag shutdown */
957 /* Unlink NIs from the global table */
958 while (!list_empty(&the_lnet.ln_nis)) {
959 ni = list_entry(the_lnet.ln_nis.next,
961 list_del (&ni->ni_list);
963 the_lnet.ln_nzombie_nis++;
964 lnet_ni_decref_locked(ni); /* drop apini's ref */
967 /* Drop the cached eqwait NI. */
968 if (the_lnet.ln_eqwaitni != NULL) {
969 lnet_ni_decref_locked(the_lnet.ln_eqwaitni);
970 the_lnet.ln_eqwaitni = NULL;
973 /* Drop the cached loopback NI. */
974 if (the_lnet.ln_loni != NULL) {
975 lnet_ni_decref_locked(the_lnet.ln_loni);
976 the_lnet.ln_loni = NULL;
981 /* Clear lazy portals and drop delayed messages which hold refs
982 * on their lnet_msg_t::msg_rxpeer */
983 for (i = 0; i < the_lnet.ln_nportals; i++)
984 LNetClearLazyPortal(i);
986 /* Clear the peer table and wait for all peers to go (they hold refs on
988 lnet_clear_peer_table();
991 /* Now wait for the NI's I just nuked to show up on apini_zombie_nis
992 * and shut them down in guaranteed thread context */
994 while (the_lnet.ln_nzombie_nis != 0) {
996 while (list_empty(&the_lnet.ln_zombie_nis)) {
1000 CDEBUG(D_WARNING,"Waiting for %d zombie NIs\n",
1001 the_lnet.ln_nzombie_nis);
1002 cfs_pause(cfs_time_seconds(1));
1006 ni = list_entry(the_lnet.ln_zombie_nis.next,
1007 lnet_ni_t, ni_list);
1008 list_del(&ni->ni_list);
1009 ni->ni_lnd->lnd_refcount--;
1013 islo = ni->ni_lnd->lnd_type == LOLND;
1015 LASSERT (!in_interrupt ());
1016 (ni->ni_lnd->lnd_shutdown)(ni);
1018 /* can't deref lnd anymore now; it might have unregistered
1022 CDEBUG(D_LNI, "Removed LNI %s\n",
1023 libcfs_nid2str(ni->ni_nid));
1025 LIBCFS_FREE(ni, sizeof(*ni));
1028 the_lnet.ln_nzombie_nis--;
1031 the_lnet.ln_shutdown = 0;
1034 if (the_lnet.ln_network_tokens != NULL) {
1035 LIBCFS_FREE(the_lnet.ln_network_tokens,
1036 the_lnet.ln_network_tokens_nob);
1037 the_lnet.ln_network_tokens = NULL;
1042 lnet_startup_lndnis (void)
1046 struct list_head nilist;
1050 char *nets = lnet_get_networks();
1052 CFS_INIT_LIST_HEAD(&nilist);
1057 rc = lnet_parse_networks(&nilist, nets);
1061 while (!list_empty(&nilist)) {
1062 ni = list_entry(nilist.next, lnet_ni_t, ni_list);
1063 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
1065 LASSERT (libcfs_isknown_lnd(lnd_type));
1067 LNET_MUTEX_DOWN(&the_lnet.ln_lnd_mutex);
1068 lnd = lnet_find_lnd_by_type(lnd_type);
1072 LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);
1073 rc = request_module("%s", libcfs_lnd2modname(lnd_type));
1074 LNET_MUTEX_DOWN(&the_lnet.ln_lnd_mutex);
1076 lnd = lnet_find_lnd_by_type(lnd_type);
1078 LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);
1079 CERROR("Can't load LND %s, module %s, rc=%d\n",
1080 libcfs_lnd2str(lnd_type),
1081 libcfs_lnd2modname(lnd_type), rc);
1083 LCONSOLE_ERROR_MSG(0x104, "Your kernel must be "
1084 "compiled with CONFIG_KMOD set for "
1085 "automatic module loading.");
1092 LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);
1093 CERROR("LND %s not supported\n",
1094 libcfs_lnd2str(lnd_type));
1099 ni->ni_refcount = 1;
1102 lnd->lnd_refcount++;
1107 rc = (lnd->lnd_startup)(ni);
1109 LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);
1112 LCONSOLE_ERROR_MSG(0x105, "Error %d starting up LNI %s"
1114 rc, libcfs_lnd2str(lnd->lnd_type));
1116 lnd->lnd_refcount--;
1121 LASSERT (ni->ni_peertimeout <= 0 || lnd->lnd_query != NULL);
1123 list_del(&ni->ni_list);
1126 list_add_tail(&ni->ni_list, &the_lnet.ln_nis);
1129 if (lnd->lnd_type == LOLND) {
1131 LASSERT (the_lnet.ln_loni == NULL);
1132 the_lnet.ln_loni = ni;
1137 if (lnd->lnd_wait != NULL) {
1138 if (the_lnet.ln_eqwaitni == NULL) {
1140 the_lnet.ln_eqwaitni = ni;
1143 # ifndef HAVE_LIBPTHREAD
1144 LCONSOLE_ERROR_MSG(0x106, "LND %s not supported in a "
1145 "single-threaded runtime\n",
1146 libcfs_lnd2str(lnd_type));
1151 if (ni->ni_peertxcredits == 0 ||
1152 ni->ni_maxtxcredits == 0) {
1153 LCONSOLE_ERROR_MSG(0x107, "LNI %s has no %scredits\n",
1154 libcfs_lnd2str(lnd->lnd_type),
1155 ni->ni_peertxcredits == 0 ?
1160 ni->ni_txcredits = ni->ni_mintxcredits = ni->ni_maxtxcredits;
1162 CDEBUG(D_LNI, "Added LNI %s [%d/%d/%d/%d]\n",
1163 libcfs_nid2str(ni->ni_nid),
1164 ni->ni_peertxcredits, ni->ni_txcredits,
1165 ni->ni_peerrtrcredits, ni->ni_peertimeout);
1167 /* Handle nidstrings for network 0 just like this one */
1168 if (the_lnet.ln_ptlcompat > 0) {
1170 LCONSOLE_ERROR_MSG(0x108, "Can't run > 1 "
1171 "network when portals_compatibility is "
1175 libcfs_setnet0alias(lnd->lnd_type);
1181 if (the_lnet.ln_eqwaitni != NULL && nicount > 1) {
1182 lnd_type = the_lnet.ln_eqwaitni->ni_lnd->lnd_type;
1183 LCONSOLE_ERROR_MSG(0x109, "LND %s can only run single-network"
1185 libcfs_lnd2str(lnd_type));
1192 lnet_shutdown_lndnis();
1194 while (!list_empty(&nilist)) {
1195 ni = list_entry(nilist.next, lnet_ni_t, ni_list);
1196 list_del(&ni->ni_list);
1197 LIBCFS_FREE(ni, sizeof(*ni));
1208 lnet_assert_wire_constants ();
1209 LASSERT (!the_lnet.ln_init);
1211 memset(&the_lnet, 0, sizeof(the_lnet));
1213 rc = lnet_get_portals_compatibility();
1218 the_lnet.ln_ptlcompat = rc;
1219 the_lnet.ln_refcount = 0;
1220 the_lnet.ln_init = 1;
1221 the_lnet.ln_rc_eqh = LNET_EQ_NONE;
1222 CFS_INIT_LIST_HEAD(&the_lnet.ln_lnds);
1223 CFS_INIT_LIST_HEAD(&the_lnet.ln_zombie_rcd);
1226 /* All LNDs apart from the LOLND are in separate modules. They
1227 * register themselves when their module loads, and unregister
1228 * themselves when their module is unloaded. */
1231 * NB the order here determines default 'networks=' order */
1233 LNET_REGISTER_ULND(the_ptllnd);
1235 # ifdef HAVE_LIBPTHREAD
1236 LNET_REGISTER_ULND(the_tcplnd);
1239 lnet_register_lnd(&the_lolnd);
1246 LASSERT (the_lnet.ln_init);
1247 LASSERT (the_lnet.ln_refcount == 0);
1249 while (!list_empty(&the_lnet.ln_lnds))
1250 lnet_unregister_lnd(list_entry(the_lnet.ln_lnds.next,
1254 the_lnet.ln_init = 0;
1258 LNetNIInit(lnet_pid_t requested_pid)
1260 int im_a_router = 0;
1263 LNET_MUTEX_DOWN(&the_lnet.ln_api_mutex);
1265 LASSERT (the_lnet.ln_init);
1266 CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
1268 if (the_lnet.ln_refcount > 0) {
1269 rc = the_lnet.ln_refcount++;
1273 lnet_get_tunables();
1275 if (requested_pid == LNET_PID_ANY) {
1276 /* Don't instantiate LNET just for me */
1281 rc = lnet_prepare(requested_pid);
1285 rc = lnet_startup_lndnis();
1289 rc = lnet_parse_routes(lnet_get_routes(), &im_a_router);
1293 rc = lnet_check_routes();
1297 rc = lnet_alloc_rtrpools(im_a_router);
1301 rc = lnet_acceptor_start();
1305 the_lnet.ln_refcount = 1;
1306 /* Now I may use my own API functions... */
1308 /* NB router checker needs the_lnet.ln_ping_info in
1309 * lnet_router_checker -> lnet_update_ni_status */
1310 rc = lnet_ping_target_init();
1314 rc = lnet_router_checker_start();
1322 lnet_ping_target_fini();
1324 the_lnet.ln_refcount = 0;
1325 lnet_acceptor_stop();
1327 lnet_destroy_routes();
1328 lnet_shutdown_lndnis();
1334 LNET_MUTEX_UP(&the_lnet.ln_api_mutex);
1341 LNET_MUTEX_DOWN(&the_lnet.ln_api_mutex);
1343 LASSERT (the_lnet.ln_init);
1344 LASSERT (the_lnet.ln_refcount > 0);
1346 if (the_lnet.ln_refcount != 1) {
1347 the_lnet.ln_refcount--;
1349 LASSERT (!the_lnet.ln_niinit_self);
1352 lnet_router_checker_stop();
1353 lnet_ping_target_fini();
1355 /* Teardown fns that use my own API functions BEFORE here */
1356 the_lnet.ln_refcount = 0;
1358 lnet_acceptor_stop();
1359 lnet_destroy_routes();
1360 lnet_shutdown_lndnis();
1364 LNET_MUTEX_UP(&the_lnet.ln_api_mutex);
1369 LNetCtl(unsigned int cmd, void *arg)
1371 struct libcfs_ioctl_data *data = arg;
1372 lnet_process_id_t id;
1376 LASSERT (the_lnet.ln_init);
1377 LASSERT (the_lnet.ln_refcount > 0);
1380 case IOC_LIBCFS_GET_NI:
1381 rc = LNetGetId(data->ioc_count, &id);
1382 data->ioc_nid = id.nid;
1385 case IOC_LIBCFS_FAIL_NID:
1386 return lnet_fail_nid(data->ioc_nid, data->ioc_count);
1388 case IOC_LIBCFS_ADD_ROUTE:
1389 rc = lnet_add_route(data->ioc_net, data->ioc_count,
1391 return (rc != 0) ? rc : lnet_check_routes();
1393 case IOC_LIBCFS_DEL_ROUTE:
1394 return lnet_del_route(data->ioc_net, data->ioc_nid);
1396 case IOC_LIBCFS_GET_ROUTE:
1397 return lnet_get_route(data->ioc_count,
1398 &data->ioc_net, &data->ioc_count,
1399 &data->ioc_nid, &data->ioc_flags);
1400 case IOC_LIBCFS_NOTIFY_ROUTER:
1401 return lnet_notify(NULL, data->ioc_nid, data->ioc_flags,
1402 cfs_time_current() -
1403 cfs_time_seconds(cfs_time_current_sec() -
1404 (time_t)data->ioc_u64[0]));
1406 case IOC_LIBCFS_PORTALS_COMPATIBILITY:
1407 return the_lnet.ln_ptlcompat;
1409 case IOC_LIBCFS_LNET_DIST:
1410 rc = LNetDist(data->ioc_nid, &data->ioc_nid, &data->ioc_u32[1]);
1411 if (rc < 0 && rc != -EHOSTUNREACH)
1414 data->ioc_u32[0] = rc;
1417 case IOC_LIBCFS_TESTPROTOCOMPAT:
1419 the_lnet.ln_testprotocompat = data->ioc_flags;
1423 case IOC_LIBCFS_PING:
1424 rc = lnet_ping((lnet_process_id_t) {.nid = data->ioc_nid,
1425 .pid = data->ioc_u32[0]},
1426 data->ioc_u32[1], /* timeout */
1427 (lnet_process_id_t *)data->ioc_pbuf1,
1428 data->ioc_plen1/sizeof(lnet_process_id_t));
1431 data->ioc_count = rc;
1434 case IOC_LIBCFS_DEBUG_PEER: {
1435 /* CAVEAT EMPTOR: this one designed for calling directly; not
1437 lnet_process_id_t *id = arg;
1439 lnet_debug_peer(id->nid);
1441 ni = lnet_net2ni(LNET_NIDNET(id->nid));
1443 CDEBUG(D_WARNING, "No NI for %s\n", libcfs_id2str(*id));
1445 if (ni->ni_lnd->lnd_ctl == NULL) {
1446 CDEBUG(D_WARNING, "No ctl for %s\n",
1447 libcfs_id2str(*id));
1449 (void)ni->ni_lnd->lnd_ctl(ni, cmd, arg);
1458 ni = lnet_net2ni(data->ioc_net);
1462 if (ni->ni_lnd->lnd_ctl == NULL)
1465 rc = ni->ni_lnd->lnd_ctl(ni, cmd, arg);
1474 LNetGetId(unsigned int index, lnet_process_id_t *id)
1477 struct list_head *tmp;
1480 LASSERT (the_lnet.ln_init);
1481 LASSERT (the_lnet.ln_refcount > 0);
1485 list_for_each(tmp, &the_lnet.ln_nis) {
1489 ni = list_entry(tmp, lnet_ni_t, ni_list);
1491 id->nid = ni->ni_nid;
1492 id->pid = the_lnet.ln_pid;
1503 LNetSnprintHandle(char *str, int len, lnet_handle_any_t h)
1505 snprintf(str, len, LPX64, h.cookie);
1509 lnet_create_ping_info(void)
1516 lnet_process_id_t id;
1517 lnet_ping_info_t *pinfo;
1519 for (n = 0; ; n++) {
1520 rc = LNetGetId(n, &id);
1527 infosz = offsetof(lnet_ping_info_t, pi_ni[n]);
1528 LIBCFS_ALLOC(pinfo, infosz);
1529 if (pinfo == NULL) {
1530 CERROR("Can't allocate ping info[%d]\n", n);
1535 pinfo->pi_pid = the_lnet.ln_pid;
1536 pinfo->pi_magic = LNET_PROTO_PING_MAGIC;
1537 pinfo->pi_version = LNET_PROTO_PING_VERSION;
1539 for (i = 0; i < n; i++) {
1540 lnet_ni_status_t *ns = &pinfo->pi_ni[i];
1542 rc = LNetGetId(i, &id);
1545 ns->ns_nid = id.nid;
1546 ns->ns_status = LNET_NI_STATUS_UP;
1550 ni = lnet_nid2ni_locked(id.nid);
1551 LASSERT (ni != NULL);
1552 LASSERT (ni->ni_status == NULL);
1554 lnet_ni_decref_locked(ni);
1559 the_lnet.ln_ping_info = pinfo;
1564 lnet_destroy_ping_info(void)
1570 list_for_each_entry (ni, &the_lnet.ln_nis, ni_list) {
1571 ni->ni_status = NULL;
1576 LIBCFS_FREE(the_lnet.ln_ping_info,
1577 offsetof(lnet_ping_info_t,
1578 pi_ni[the_lnet.ln_ping_info->pi_nnis]));
1579 the_lnet.ln_ping_info = NULL;
1584 lnet_ping_target_init(void)
1586 lnet_handle_me_t meh;
1591 rc = lnet_create_ping_info();
1595 /* We can have a tiny EQ since we only need to see the unlink event on
1596 * teardown, which by definition is the last one! */
1597 rc = LNetEQAlloc(2, LNET_EQ_HANDLER_NONE, &the_lnet.ln_ping_target_eq);
1599 CERROR("Can't allocate ping EQ: %d\n", rc);
1603 rc = LNetMEAttach(LNET_RESERVED_PORTAL,
1604 (lnet_process_id_t){.nid = LNET_NID_ANY,
1605 .pid = LNET_PID_ANY},
1606 LNET_PROTO_PING_MATCHBITS, 0LL,
1607 LNET_UNLINK, LNET_INS_AFTER,
1610 CERROR("Can't create ping ME: %d\n", rc);
1614 infosz = offsetof(lnet_ping_info_t,
1615 pi_ni[the_lnet.ln_ping_info->pi_nnis]);
1616 rc = LNetMDAttach(meh,
1617 (lnet_md_t){.start = the_lnet.ln_ping_info,
1619 .threshold = LNET_MD_THRESH_INF,
1620 .options = (LNET_MD_OP_GET |
1622 LNET_MD_MANAGE_REMOTE),
1623 .eq_handle = the_lnet.ln_ping_target_eq},
1625 &the_lnet.ln_ping_target_md);
1627 CERROR("Can't attach ping MD: %d\n", rc);
1634 rc2 = LNetMEUnlink(meh);
1637 rc2 = LNetEQFree(the_lnet.ln_ping_target_eq);
1640 lnet_destroy_ping_info();
1645 lnet_ping_target_fini(void)
1650 int timeout_ms = 1000;
1651 cfs_sigset_t blocked = cfs_block_allsigs();
1653 LNetMDUnlink(the_lnet.ln_ping_target_md);
1654 /* NB md could be busy; this just starts the unlink */
1657 rc = LNetEQPoll(&the_lnet.ln_ping_target_eq, 1,
1658 timeout_ms, &event, &which);
1660 /* I expect overflow... */
1661 LASSERT (rc >= 0 || rc == -EOVERFLOW);
1664 /* timed out: provide a diagnostic */
1665 CWARN("Still waiting for ping MD to unlink\n");
1670 /* Got a valid event */
1675 rc = LNetEQFree(the_lnet.ln_ping_target_eq);
1677 lnet_destroy_ping_info();
1678 cfs_restore_sigs(blocked);
1682 lnet_ping (lnet_process_id_t id, int timeout_ms, lnet_process_id_t *ids, int n_ids)
1684 lnet_handle_eq_t eqh;
1685 lnet_handle_md_t mdh;
1690 const int a_long_time = 60000; /* mS */
1691 int infosz = offsetof(lnet_ping_info_t, pi_ni[n_ids]);
1692 lnet_ping_info_t *info;
1693 lnet_process_id_t tmpid;
1698 cfs_sigset_t blocked;
1701 id.nid == LNET_NID_ANY ||
1702 timeout_ms > 500000 || /* arbitrary limit! */
1703 n_ids > 20) /* arbitrary limit! */
1706 if (id.pid == LNET_PID_ANY)
1707 id.pid = LUSTRE_SRV_LNET_PID;
1709 LIBCFS_ALLOC(info, infosz);
1713 /* NB 2 events max (including any unlink event) */
1714 rc = LNetEQAlloc(2, LNET_EQ_HANDLER_NONE, &eqh);
1716 CERROR("Can't allocate EQ: %d\n", rc);
1720 rc = LNetMDBind((lnet_md_t){.start = info,
1722 .threshold = 2, /* GET/REPLY */
1723 .options = LNET_MD_TRUNCATE,
1728 CERROR("Can't bind MD: %d\n", rc);
1732 rc = LNetGet(LNET_NID_ANY, mdh, id,
1733 LNET_RESERVED_PORTAL,
1734 LNET_PROTO_PING_MATCHBITS, 0);
1737 /* Don't CERROR; this could be deliberate! */
1739 rc2 = LNetMDUnlink(mdh);
1742 /* NB must wait for the UNLINK event below... */
1744 timeout_ms = a_long_time;
1748 /* MUST block for unlink to complete */
1750 blocked = cfs_block_allsigs();
1752 rc2 = LNetEQPoll(&eqh, 1, timeout_ms, &event, &which);
1755 cfs_restore_sigs(blocked);
1757 CDEBUG(D_NET, "poll %d(%d %d)%s\n", rc2,
1758 (rc2 <= 0) ? -1 : event.type,
1759 (rc2 <= 0) ? -1 : event.status,
1760 (rc2 > 0 && event.unlinked) ? " unlinked" : "");
1762 LASSERT (rc2 != -EOVERFLOW); /* can't miss anything */
1764 if (rc2 <= 0 || event.status != 0) {
1765 /* timeout or error */
1766 if (!replied && rc == 0)
1767 rc = (rc2 < 0) ? rc2 :
1768 (rc2 == 0) ? -ETIMEDOUT :
1772 /* Ensure completion in finite time... */
1774 /* No assertion (racing with network) */
1776 timeout_ms = a_long_time;
1777 } else if (rc2 == 0) {
1778 /* timed out waiting for unlink */
1779 CWARN("ping %s: late network completion\n",
1782 } else if (event.type == LNET_EVENT_REPLY) {
1787 } while (rc2 <= 0 || !event.unlinked);
1791 CWARN("%s: Unexpected rc >= 0 but no reply!\n",
1798 LASSERT (nob >= 0 && nob <= infosz);
1800 rc = -EPROTO; /* if I can't parse... */
1803 /* can't check magic/version */
1804 CERROR("%s: ping info too short %d\n",
1805 libcfs_id2str(id), nob);
1809 if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) {
1810 lnet_swap_pinginfo(info);
1811 } else if (info->pi_magic != LNET_PROTO_PING_MAGIC) {
1812 CERROR("%s: Unexpected magic %08x\n",
1813 libcfs_id2str(id), info->pi_magic);
1817 if (info->pi_version != LNET_PROTO_PING_VERSION) {
1818 CERROR("%s: Unexpected version 0x%x\n",
1819 libcfs_id2str(id), info->pi_version);
1823 if (nob < offsetof(lnet_ping_info_t, pi_ni[0])) {
1824 CERROR("%s: Short reply %d(%d min)\n", libcfs_id2str(id),
1825 nob, (int)offsetof(lnet_ping_info_t, pi_ni[0]));
1829 if (info->pi_nnis < n_ids)
1830 n_ids = info->pi_nnis;
1832 if (nob < offsetof(lnet_ping_info_t, pi_ni[n_ids])) {
1833 CERROR("%s: Short reply %d(%d expected)\n", libcfs_id2str(id),
1834 nob, (int)offsetof(lnet_ping_info_t, pi_ni[n_ids]));
1838 rc = -EFAULT; /* If I SEGV... */
1840 for (i = 0; i < n_ids; i++) {
1841 tmpid.pid = info->pi_pid;
1842 tmpid.nid = info->pi_ni[i].ns_nid;
1844 if (copy_to_user(&ids[i], &tmpid, sizeof(tmpid)))
1853 rc2 = LNetEQFree(eqh);
1855 CERROR("rc2 %d\n", rc2);
1859 LIBCFS_FREE(info, infosz);