Whamcloud - gitweb
65591d35eca77ef89ad0f6724f59f4c9edb1d366
[fs/lustre-release.git] / lnet / include / lnet / lib-lnet.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lnet/include/lnet/lib-lnet.h
37  *
38  * Top level include for library side routines
39  */
40
41 #ifndef __LNET_LIB_LNET_H__
42 #define __LNET_LIB_LNET_H__
43
44 #if defined(__linux__)
45 #include <lnet/linux/lib-lnet.h>
46 #elif defined(__APPLE__)
47 #include <lnet/darwin/lib-lnet.h>
48 #elif defined(__WINNT__)
49 #include <lnet/winnt/lib-lnet.h>
50 #else
51 #error Unsupported Operating System
52 #endif
53
54 #include <libcfs/libcfs.h>
55 #include <lnet/types.h>
56 #include <lnet/lnet.h>
57 #include <lnet/lib-types.h>
58
59 extern lnet_t  the_lnet;                        /* THE network */
60
61 static inline int lnet_is_wire_handle_none (lnet_handle_wire_t *wh)
62 {
63         return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_COOKIE_NONE &&
64                 wh->wh_object_cookie == LNET_WIRE_HANDLE_COOKIE_NONE);
65 }
66
67 static inline int lnet_md_exhausted (lnet_libmd_t *md)
68 {
69         return (md->md_threshold == 0 ||
70                 ((md->md_options & LNET_MD_MAX_SIZE) != 0 &&
71                  md->md_offset + md->md_max_size > md->md_length));
72 }
73
74 static inline int lnet_md_unlinkable (lnet_libmd_t *md)
75 {
76         /* Should unlink md when its refcount is 0 and either:
77          *  - md has been flagged for deletion (by auto unlink or LNetM[DE]Unlink,
78          *    in the latter case md may not be exhausted).
79          *  - auto unlink is on and md is exhausted.
80          */
81         if (md->md_refcount != 0)
82                 return 0;
83
84         if ((md->md_flags & LNET_MD_FLAG_ZOMBIE) != 0)
85                 return 1;
86
87         return ((md->md_flags & LNET_MD_FLAG_AUTO_UNLINK) != 0 &&
88                 lnet_md_exhausted(md));
89 }
90
91 #ifdef __KERNEL__
92 #define LNET_LOCK()        cfs_spin_lock(&the_lnet.ln_lock)
93 #define LNET_UNLOCK()      cfs_spin_unlock(&the_lnet.ln_lock)
94 #define LNET_MUTEX_DOWN(m) cfs_mutex_down(m)
95 #define LNET_MUTEX_UP(m)   cfs_mutex_up(m)
96 #else
97 # ifndef HAVE_PTHREAD
98 #define LNET_SINGLE_THREADED_LOCK(l)            \
99 do {                                            \
100         LASSERT ((l) == 0);                     \
101         (l) = 1;                                \
102 } while (0)
103
104 #define LNET_SINGLE_THREADED_UNLOCK(l)          \
105 do {                                            \
106         LASSERT ((l) == 1);                     \
107         (l) = 0;                                \
108 } while (0)
109
110 #define LNET_LOCK()        LNET_SINGLE_THREADED_LOCK(the_lnet.ln_lock)
111 #define LNET_UNLOCK()      LNET_SINGLE_THREADED_UNLOCK(the_lnet.ln_lock)
112 #define LNET_MUTEX_DOWN(m) LNET_SINGLE_THREADED_LOCK(*(m))
113 #define LNET_MUTEX_UP(m)   LNET_SINGLE_THREADED_UNLOCK(*(m))
114 # else
115 #define LNET_LOCK()        pthread_mutex_lock(&the_lnet.ln_lock)
116 #define LNET_UNLOCK()      pthread_mutex_unlock(&the_lnet.ln_lock)
117 #define LNET_MUTEX_DOWN(m) pthread_mutex_lock(m)
118 #define LNET_MUTEX_UP(m)   pthread_mutex_unlock(m)
119 # endif
120 #endif
121
122 #define MAX_PORTALS     64
123
124 #ifdef LNET_USE_LIB_FREELIST
125
126 #define MAX_MES         2048
127 #define MAX_MDS         2048
128 #define MAX_MSGS        2048    /* Outstanding messages */
129 #define MAX_EQS         512
130
131 static inline void *
132 lnet_freelist_alloc (lnet_freelist_t *fl)
133 {
134         /* ALWAYS called with liblock held */
135         lnet_freeobj_t *o;
136
137         if (cfs_list_empty (&fl->fl_list))
138                 return (NULL);
139
140         o = cfs_list_entry (fl->fl_list.next, lnet_freeobj_t, fo_list);
141         cfs_list_del (&o->fo_list);
142         return ((void *)&o->fo_contents);
143 }
144
145 static inline void
146 lnet_freelist_free (lnet_freelist_t *fl, void *obj)
147 {
148         /* ALWAYS called with liblock held */
149         lnet_freeobj_t *o = cfs_list_entry (obj, lnet_freeobj_t, fo_contents);
150
151         cfs_list_add (&o->fo_list, &fl->fl_list);
152 }
153
154
155 static inline lnet_eq_t *
156 lnet_eq_alloc (void)
157 {
158         /* NEVER called with liblock held */
159         lnet_eq_t     *eq;
160
161         LNET_LOCK();
162         eq = (lnet_eq_t *)lnet_freelist_alloc(&the_lnet.ln_free_eqs);
163         LNET_UNLOCK();
164
165         return (eq);
166 }
167
168 static inline void
169 lnet_eq_free (lnet_eq_t *eq)
170 {
171         /* ALWAYS called with liblock held */
172         lnet_freelist_free(&the_lnet.ln_free_eqs, eq);
173 }
174
175 static inline lnet_libmd_t *
176 lnet_md_alloc (lnet_md_t *umd)
177 {
178         /* NEVER called with liblock held */
179         lnet_libmd_t  *md;
180
181         LNET_LOCK();
182         md = (lnet_libmd_t *)lnet_freelist_alloc(&the_lnet.ln_free_mds);
183         LNET_UNLOCK();
184
185         if (md != NULL)
186                 CFS_INIT_LIST_HEAD(&md->md_list);
187
188         return (md);
189 }
190
191 static inline void
192 lnet_md_free (lnet_libmd_t *md)
193 {
194         /* ALWAYS called with liblock held */
195         lnet_freelist_free (&the_lnet.ln_free_mds, md);
196 }
197
198 static inline lnet_me_t *
199 lnet_me_alloc (void)
200 {
201         /* NEVER called with liblock held */
202         lnet_me_t     *me;
203
204         LNET_LOCK();
205         me = (lnet_me_t *)lnet_freelist_alloc(&the_lnet.ln_free_mes);
206         LNET_UNLOCK();
207
208         return (me);
209 }
210
211 static inline void
212 lnet_me_free (lnet_me_t *me)
213 {
214         /* ALWAYS called with liblock held */
215         lnet_freelist_free (&the_lnet.ln_free_mes, me);
216 }
217
218 static inline lnet_msg_t *
219 lnet_msg_alloc (void)
220 {
221         /* NEVER called with liblock held */
222         lnet_msg_t    *msg;
223
224         LNET_LOCK();
225         msg = (lnet_msg_t *)lnet_freelist_alloc(&the_lnet.ln_free_msgs);
226         LNET_UNLOCK();
227
228         if (msg != NULL) {
229                 /* NULL pointers, clear flags etc */
230                 memset (msg, 0, sizeof (*msg));
231 #ifdef CRAY_XT3
232                 msg->msg_ev.uid = LNET_UID_ANY;
233 #endif
234         }
235         return(msg);
236 }
237
238 static inline void
239 lnet_msg_free (lnet_msg_t *msg)
240 {
241         /* ALWAYS called with liblock held */
242         LASSERT (!msg->msg_onactivelist);
243         lnet_freelist_free(&the_lnet.ln_free_msgs, msg);
244 }
245
246 #else
247
248 static inline lnet_eq_t *
249 lnet_eq_alloc (void)
250 {
251         /* NEVER called with liblock held */
252         lnet_eq_t *eq;
253
254         LIBCFS_ALLOC(eq, sizeof(*eq));
255         return (eq);
256 }
257
258 static inline void
259 lnet_eq_free (lnet_eq_t *eq)
260 {
261         /* ALWAYS called with liblock held */
262         LIBCFS_FREE(eq, sizeof(*eq));
263 }
264
265 static inline lnet_libmd_t *
266 lnet_md_alloc (lnet_md_t *umd)
267 {
268         /* NEVER called with liblock held */
269         lnet_libmd_t *md;
270         unsigned int  size;
271         unsigned int  niov;
272
273         if ((umd->options & LNET_MD_KIOV) != 0) {
274                 niov = umd->length;
275                 size = offsetof(lnet_libmd_t, md_iov.kiov[niov]);
276         } else {
277                 niov = ((umd->options & LNET_MD_IOVEC) != 0) ?
278                        umd->length : 1;
279                 size = offsetof(lnet_libmd_t, md_iov.iov[niov]);
280         }
281
282         LIBCFS_ALLOC(md, size);
283
284         if (md != NULL) {
285                 /* Set here in case of early free */
286                 md->md_options = umd->options;
287                 md->md_niov = niov;
288                 CFS_INIT_LIST_HEAD(&md->md_list);
289         }
290
291         return (md);
292 }
293
294 static inline void
295 lnet_md_free (lnet_libmd_t *md)
296 {
297         /* ALWAYS called with liblock held */
298         unsigned int  size;
299
300         if ((md->md_options & LNET_MD_KIOV) != 0)
301                 size = offsetof(lnet_libmd_t, md_iov.kiov[md->md_niov]);
302         else
303                 size = offsetof(lnet_libmd_t, md_iov.iov[md->md_niov]);
304
305         LIBCFS_FREE(md, size);
306 }
307
308 static inline lnet_me_t *
309 lnet_me_alloc (void)
310 {
311         /* NEVER called with liblock held */
312         lnet_me_t *me;
313
314         LIBCFS_ALLOC(me, sizeof(*me));
315         return (me);
316 }
317
318 static inline void
319 lnet_me_free(lnet_me_t *me)
320 {
321         /* ALWAYS called with liblock held */
322         LIBCFS_FREE(me, sizeof(*me));
323 }
324
325 static inline lnet_msg_t *
326 lnet_msg_alloc(void)
327 {
328         /* NEVER called with liblock held */
329         lnet_msg_t *msg;
330
331         LIBCFS_ALLOC(msg, sizeof(*msg));
332
333         if (msg != NULL) {
334                 /* NULL pointers, clear flags etc */
335                 memset (msg, 0, sizeof (*msg));
336 #ifdef CRAY_XT3
337                 msg->msg_ev.uid = LNET_UID_ANY;
338 #endif
339         }
340         return (msg);
341 }
342
343 static inline void
344 lnet_msg_free(lnet_msg_t *msg)
345 {
346         /* ALWAYS called with liblock held */
347         LASSERT (!msg->msg_onactivelist);
348         LIBCFS_FREE(msg, sizeof(*msg));
349 }
350 #endif
351
352 extern lnet_libhandle_t *lnet_lookup_cookie (__u64 cookie, int type);
353 extern void lnet_initialise_handle (lnet_libhandle_t *lh, int type);
354 extern void lnet_invalidate_handle (lnet_libhandle_t *lh);
355
356 static inline void
357 lnet_eq2handle (lnet_handle_eq_t *handle, lnet_eq_t *eq)
358 {
359         if (eq == NULL) {
360                 LNetInvalidateHandle(handle);
361                 return;
362         }
363
364         handle->cookie = eq->eq_lh.lh_cookie;
365 }
366
367 static inline lnet_eq_t *
368 lnet_handle2eq (lnet_handle_eq_t *handle)
369 {
370         /* ALWAYS called with liblock held */
371         lnet_libhandle_t *lh = lnet_lookup_cookie(handle->cookie,
372                                                   LNET_COOKIE_TYPE_EQ);
373         if (lh == NULL)
374                 return (NULL);
375
376         return (lh_entry (lh, lnet_eq_t, eq_lh));
377 }
378
379 static inline void
380 lnet_md2handle (lnet_handle_md_t *handle, lnet_libmd_t *md)
381 {
382         handle->cookie = md->md_lh.lh_cookie;
383 }
384
385 static inline lnet_libmd_t *
386 lnet_handle2md (lnet_handle_md_t *handle)
387 {
388         /* ALWAYS called with liblock held */
389         lnet_libhandle_t *lh = lnet_lookup_cookie(handle->cookie,
390                                                   LNET_COOKIE_TYPE_MD);
391         if (lh == NULL)
392                 return (NULL);
393
394         return (lh_entry (lh, lnet_libmd_t, md_lh));
395 }
396
397 static inline lnet_libmd_t *
398 lnet_wire_handle2md (lnet_handle_wire_t *wh)
399 {
400         /* ALWAYS called with liblock held */
401         lnet_libhandle_t *lh;
402
403         if (wh->wh_interface_cookie != the_lnet.ln_interface_cookie)
404                 return (NULL);
405
406         lh = lnet_lookup_cookie(wh->wh_object_cookie,
407                                 LNET_COOKIE_TYPE_MD);
408         if (lh == NULL)
409                 return (NULL);
410
411         return (lh_entry (lh, lnet_libmd_t, md_lh));
412 }
413
414 static inline void
415 lnet_me2handle (lnet_handle_me_t *handle, lnet_me_t *me)
416 {
417         handle->cookie = me->me_lh.lh_cookie;
418 }
419
420 static inline lnet_me_t *
421 lnet_handle2me (lnet_handle_me_t *handle)
422 {
423         /* ALWAYS called with liblock held */
424         lnet_libhandle_t *lh = lnet_lookup_cookie(handle->cookie,
425                                                   LNET_COOKIE_TYPE_ME);
426         if (lh == NULL)
427                 return (NULL);
428
429         return (lh_entry (lh, lnet_me_t, me_lh));
430 }
431
432 static inline void
433 lnet_peer_addref_locked(lnet_peer_t *lp)
434 {
435         LASSERT (lp->lp_refcount > 0);
436         lp->lp_refcount++;
437 }
438
439 extern void lnet_destroy_peer_locked(lnet_peer_t *lp);
440
441 static inline void
442 lnet_peer_decref_locked(lnet_peer_t *lp)
443 {
444         LASSERT (lp->lp_refcount > 0);
445         lp->lp_refcount--;
446         if (lp->lp_refcount == 0)
447                 lnet_destroy_peer_locked(lp);
448 }
449
450 static inline int
451 lnet_isrouter(lnet_peer_t *lp)
452 {
453         return lp->lp_rtr_refcount != 0;
454 }
455
456 static inline void
457 lnet_ni_addref_locked(lnet_ni_t *ni)
458 {
459         LASSERT (ni->ni_refcount > 0);
460         ni->ni_refcount++;
461 }
462
463 static inline void
464 lnet_ni_addref(lnet_ni_t *ni)
465 {
466         LNET_LOCK();
467         lnet_ni_addref_locked(ni);
468         LNET_UNLOCK();
469 }
470
471 static inline void
472 lnet_ni_decref_locked(lnet_ni_t *ni)
473 {
474         LASSERT (ni->ni_refcount > 0);
475         ni->ni_refcount--;
476         if (ni->ni_refcount == 0)
477                 cfs_list_add_tail(&ni->ni_list, &the_lnet.ln_zombie_nis);
478 }
479
480 static inline void
481 lnet_ni_decref(lnet_ni_t *ni)
482 {
483         LNET_LOCK();
484         lnet_ni_decref_locked(ni);
485         LNET_UNLOCK();
486 }
487
488 static inline cfs_list_t *
489 lnet_nid2peerhash (lnet_nid_t nid)
490 {
491         unsigned int idx = LNET_NIDADDR(nid) % LNET_PEER_HASHSIZE;
492
493         return &the_lnet.ln_peer_hash[idx];
494 }
495
496 extern lnd_t the_lolnd;
497
498 #ifndef __KERNEL__
499 /* unconditional registration */
500 #define LNET_REGISTER_ULND(lnd)                 \
501 do {                                            \
502         extern lnd_t lnd;                       \
503                                                 \
504         lnet_register_lnd(&(lnd));              \
505 } while (0)
506
507 /* conditional registration */
508 #define LNET_REGISTER_ULND_IF_PRESENT(lnd)                              \
509 do {                                                                    \
510         extern lnd_t lnd __attribute__ ((weak, alias("the_lolnd")));    \
511                                                                         \
512         if (&(lnd) != &the_lolnd)                                       \
513                 lnet_register_lnd(&(lnd));                              \
514 } while (0)
515 #endif
516
517 #ifdef CRAY_XT3
518 inline static void
519 lnet_set_msg_uid(lnet_ni_t *ni, lnet_msg_t *msg, lnet_uid_t uid)
520 {
521         LASSERT (msg->msg_ev.uid == LNET_UID_ANY);
522         msg->msg_ev.uid = uid;
523 }
524 #endif
525
526 extern lnet_ni_t *lnet_nid2ni_locked (lnet_nid_t nid);
527 extern lnet_ni_t *lnet_net2ni_locked (__u32 net);
528 static inline lnet_ni_t *
529 lnet_net2ni (__u32 net)
530 {
531         lnet_ni_t *ni;
532
533         LNET_LOCK();
534         ni = lnet_net2ni_locked(net);
535         LNET_UNLOCK();
536
537         return ni;
538 }
539
540 int lnet_notify(lnet_ni_t *ni, lnet_nid_t peer, int alive, cfs_time_t when);
541 void lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, cfs_time_t when);
542 int lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway_nid);
543 int lnet_check_routes(void);
544 int lnet_del_route(__u32 net, lnet_nid_t gw_nid);
545 void lnet_destroy_routes(void);
546 int lnet_get_route(int idx, __u32 *net, __u32 *hops,
547                    lnet_nid_t *gateway, __u32 *alive);
548 void lnet_proc_init(void);
549 void lnet_proc_fini(void);
550 void lnet_init_rtrpools(void);
551 int  lnet_alloc_rtrpools(int im_a_router);
552 void lnet_free_rtrpools(void);
553 lnet_remotenet_t *lnet_find_net_locked (__u32 net);
554
555 int lnet_islocalnid(lnet_nid_t nid);
556 int lnet_islocalnet(__u32 net);
557
558 void lnet_build_unlink_event(lnet_libmd_t *md, lnet_event_t *ev);
559 void lnet_enq_event_locked(lnet_eq_t *eq, lnet_event_t *ev);
560 void lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
561                     unsigned int offset, unsigned int len);
562 int lnet_send(lnet_nid_t nid, lnet_msg_t *msg);
563 void lnet_return_credits_locked (lnet_msg_t *msg);
564 void lnet_match_blocked_msg(lnet_libmd_t *md);
565 int lnet_parse (lnet_ni_t *ni, lnet_hdr_t *hdr,
566                 lnet_nid_t fromnid, void *private, int rdma_req);
567 void lnet_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
568                unsigned int offset, unsigned int mlen, unsigned int rlen);
569 lnet_msg_t *lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *get_msg);
570 void lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *msg, unsigned int len);
571 void lnet_finalize(lnet_ni_t *ni, lnet_msg_t *msg, int rc);
572
573 char *lnet_msgtyp2str (int type);
574 void lnet_print_hdr (lnet_hdr_t * hdr);
575 int lnet_fail_nid(lnet_nid_t nid, unsigned int threshold);
576
577 unsigned int lnet_iov_nob (unsigned int niov, struct iovec *iov);
578 int lnet_extract_iov (int dst_niov, struct iovec *dst,
579                       int src_niov, struct iovec *src,
580                       unsigned int offset, unsigned int len);
581
582 unsigned int lnet_kiov_nob (unsigned int niov, lnet_kiov_t *iov);
583 int lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
584                       int src_niov, lnet_kiov_t *src,
585                       unsigned int offset, unsigned int len);
586
587 void lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov,
588                         unsigned int doffset,
589                         unsigned int nsiov, struct iovec *siov,
590                         unsigned int soffset, unsigned int nob);
591 void lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov,
592                          unsigned int iovoffset,
593                          unsigned int nkiov, lnet_kiov_t *kiov,
594                          unsigned int kiovoffset, unsigned int nob);
595 void lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov,
596                          unsigned int kiovoffset,
597                          unsigned int niov, struct iovec *iov,
598                          unsigned int iovoffset, unsigned int nob);
599 void lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov,
600                           unsigned int doffset,
601                           unsigned int nskiov, lnet_kiov_t *skiov,
602                           unsigned int soffset, unsigned int nob);
603
604 static inline void
605 lnet_copy_iov2flat(int dlen, void *dest, unsigned int doffset,
606                    unsigned int nsiov, struct iovec *siov, unsigned int soffset,
607                    unsigned int nob)
608 {
609         struct iovec diov = {/*.iov_base = */ dest, /*.iov_len = */ dlen};
610
611         lnet_copy_iov2iov(1, &diov, doffset,
612                           nsiov, siov, soffset, nob);
613 }
614
615 static inline void
616 lnet_copy_kiov2flat(int dlen, void *dest, unsigned int doffset,
617                     unsigned int nsiov, lnet_kiov_t *skiov, unsigned int soffset,
618                     unsigned int nob)
619 {
620         struct iovec diov = {/* .iov_base = */ dest, /* .iov_len = */ dlen};
621
622         lnet_copy_kiov2iov(1, &diov, doffset,
623                            nsiov, skiov, soffset, nob);
624 }
625
626 static inline void
627 lnet_copy_flat2iov(unsigned int ndiov, struct iovec *diov, unsigned int doffset,
628                    int slen, void *src, unsigned int soffset, unsigned int nob)
629 {
630         struct iovec siov = {/*.iov_base = */ src, /*.iov_len = */slen};
631         lnet_copy_iov2iov(ndiov, diov, doffset,
632                           1, &siov, soffset, nob);
633 }
634
635 static inline void
636 lnet_copy_flat2kiov(unsigned int ndiov, lnet_kiov_t *dkiov, unsigned int doffset,
637                     int slen, void *src, unsigned int soffset, unsigned int nob)
638 {
639         struct iovec siov = {/* .iov_base = */ src, /* .iov_len = */ slen};
640         lnet_copy_iov2kiov(ndiov, dkiov, doffset,
641                            1, &siov, soffset, nob);
642 }
643
644 void lnet_me_unlink(lnet_me_t *me);
645
646 void lnet_md_unlink(lnet_libmd_t *md);
647 void lnet_md_deconstruct(lnet_libmd_t *lmd, lnet_md_t *umd);
648
649 void lnet_register_lnd(lnd_t *lnd);
650 void lnet_unregister_lnd(lnd_t *lnd);
651 int lnet_set_ip_niaddr (lnet_ni_t *ni);
652
653 #ifdef __KERNEL__
654 int lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
655                  __u32 local_ip, __u32 peer_ip, int peer_port);
656 void lnet_connect_console_error(int rc, lnet_nid_t peer_nid,
657                                 __u32 peer_ip, int port);
658 int lnet_count_acceptor_nis(void);
659 int lnet_acceptor_timeout(void);
660 int lnet_acceptor_port(void);
661 #else
662 void lnet_router_checker(void);
663 #endif
664
665 #ifdef HAVE_PTHREAD
666 int lnet_count_acceptor_nis(void);
667 int lnet_acceptor_port(void);
668 #endif
669
670 int lnet_acceptor_start(void);
671 void lnet_acceptor_stop(void);
672
673 void lnet_get_tunables(void);
674 int lnet_peers_start_down(void);
675 int lnet_peer_buffer_credits(lnet_ni_t *ni);
676
677 int lnet_router_checker_start(void);
678 void lnet_router_checker_stop(void);
679 void lnet_swap_pinginfo(lnet_ping_info_t *info);
680 int lnet_router_down_ni(lnet_peer_t *rtr, __u32 net);
681
682 int lnet_ping_target_init(void);
683 void lnet_ping_target_fini(void);
684 int lnet_ping(lnet_process_id_t id, int timeout_ms,
685               lnet_process_id_t *ids, int n_ids);
686
687 int lnet_parse_ip2nets (char **networksp, char *ip2nets);
688 int lnet_parse_routes (char *route_str, int *im_a_router);
689 int lnet_parse_networks (cfs_list_t *nilist, char *networks);
690
691 int lnet_nid2peer_locked(lnet_peer_t **lpp, lnet_nid_t nid);
692 lnet_peer_t *lnet_find_peer_locked (lnet_nid_t nid);
693 void lnet_clear_peer_table(void);
694 void lnet_destroy_peer_table(void);
695 int lnet_create_peer_table(void);
696 void lnet_debug_peer(lnet_nid_t nid);
697
698 #ifndef __KERNEL__
699 static inline int
700 lnet_parse_int_tunable(int *value, char *name)
701 {
702         char    *env = getenv(name);
703         char    *end;
704
705         if (env == NULL)
706                 return 0;
707
708         *value = strtoull(env, &end, 0);
709         if (*end == 0)
710                 return 0;
711
712         CERROR("Can't parse tunable %s=%s\n", name, env);
713         return -EINVAL;
714 }
715 #endif
716
717 #endif