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