Whamcloud - gitweb
b=16098
[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 [sun.com URL with a
20  * copy of GPLv2].
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_NONE.wh_interface_cookie &&
64                 wh->wh_object_cookie == LNET_WIRE_HANDLE_NONE.wh_object_cookie);
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()        spin_lock(&the_lnet.ln_lock)                 
93 #define LNET_UNLOCK()      spin_unlock(&the_lnet.ln_lock)               
94 #define LNET_MUTEX_DOWN(m) mutex_down(m)
95 #define LNET_MUTEX_UP(m)   mutex_up(m)
96 #else
97 # ifndef HAVE_LIBPTHREAD
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 (list_empty (&fl->fl_list))
138                 return (NULL);
139         
140         o = list_entry (fl->fl_list.next, lnet_freeobj_t, fo_list);
141         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 = list_entry (obj, lnet_freeobj_t, fo_contents);
150         
151         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         return (md);
186 }
187
188 static inline void
189 lnet_md_free (lnet_libmd_t *md)
190 {
191         /* ALWAYS called with liblock held */
192         lnet_freelist_free (&the_lnet.ln_free_mds, md);
193 }
194
195 static inline lnet_me_t *
196 lnet_me_alloc (void)
197 {
198         /* NEVER called with liblock held */
199         lnet_me_t     *me;
200         
201         LNET_LOCK();
202         me = (lnet_me_t *)lnet_freelist_alloc(&the_lnet.ln_free_mes);
203         LNET_UNLOCK();
204         
205         return (me);
206 }
207
208 static inline void
209 lnet_me_free (lnet_me_t *me)
210 {
211         /* ALWAYS called with liblock held */
212         lnet_freelist_free (&the_lnet.ln_free_mes, me);
213 }
214
215 static inline lnet_msg_t *
216 lnet_msg_alloc (void)
217 {
218         /* NEVER called with liblock held */
219         lnet_msg_t    *msg;
220         
221         LNET_LOCK();
222         msg = (lnet_msg_t *)lnet_freelist_alloc(&the_lnet.ln_free_msgs);
223         LNET_UNLOCK();
224
225         if (msg != NULL) {
226                 /* NULL pointers, clear flags etc */
227                 memset (msg, 0, sizeof (*msg));
228 #ifdef CRAY_XT3
229                 msg->msg_ev.uid = LNET_UID_ANY;
230 #endif
231         }
232         return(msg);
233 }
234
235 static inline void
236 lnet_msg_free (lnet_msg_t *msg)
237 {
238         /* ALWAYS called with liblock held */
239         LASSERT (!msg->msg_onactivelist);
240         lnet_freelist_free(&the_lnet.ln_free_msgs, msg);
241 }
242
243 #else
244
245 static inline lnet_eq_t *
246 lnet_eq_alloc (void)
247 {
248         /* NEVER called with liblock held */
249         lnet_eq_t *eq;
250
251         LIBCFS_ALLOC(eq, sizeof(*eq));
252         return (eq);
253 }
254
255 static inline void
256 lnet_eq_free (lnet_eq_t *eq)
257 {
258         /* ALWAYS called with liblock held */
259         LIBCFS_FREE(eq, sizeof(*eq));
260 }
261
262 static inline lnet_libmd_t *
263 lnet_md_alloc (lnet_md_t *umd)
264 {
265         /* NEVER called with liblock held */
266         lnet_libmd_t *md;
267         int           size;
268         unsigned int  niov;
269
270         if ((umd->options & LNET_MD_KIOV) != 0) {
271                 niov = umd->length;
272                 size = offsetof(lnet_libmd_t, md_iov.kiov[niov]);
273         } else {
274                 niov = ((umd->options & LNET_MD_IOVEC) != 0) ?
275                        umd->length : 1;
276                 size = offsetof(lnet_libmd_t, md_iov.iov[niov]);
277         }
278
279         LIBCFS_ALLOC(md, size);
280
281         if (md != NULL) {
282                 /* Set here in case of early free */
283                 md->md_options = umd->options;
284                 md->md_niov = niov;
285         }
286         
287         return (md);
288 }
289
290 static inline void 
291 lnet_md_free (lnet_libmd_t *md)
292 {
293         /* ALWAYS called with liblock held */
294         int       size;
295
296         if ((md->md_options & LNET_MD_KIOV) != 0)
297                 size = offsetof(lnet_libmd_t, md_iov.kiov[md->md_niov]);
298         else
299                 size = offsetof(lnet_libmd_t, md_iov.iov[md->md_niov]);
300
301         LIBCFS_FREE(md, size);
302 }
303
304 static inline lnet_me_t *
305 lnet_me_alloc (void)
306 {
307         /* NEVER called with liblock held */
308         lnet_me_t *me;
309
310         LIBCFS_ALLOC(me, sizeof(*me));
311         return (me);
312 }
313
314 static inline void 
315 lnet_me_free(lnet_me_t *me)
316 {
317         /* ALWAYS called with liblock held */
318         LIBCFS_FREE(me, sizeof(*me));
319 }
320
321 static inline lnet_msg_t *
322 lnet_msg_alloc(void)
323 {
324         /* NEVER called with liblock held */
325         lnet_msg_t *msg;
326
327         LIBCFS_ALLOC(msg, sizeof(*msg));
328
329         if (msg != NULL) {
330                 /* NULL pointers, clear flags etc */
331                 memset (msg, 0, sizeof (*msg));
332 #ifdef CRAY_XT3
333                 msg->msg_ev.uid = LNET_UID_ANY;
334 #endif
335         }
336         return (msg);
337 }
338
339 static inline void 
340 lnet_msg_free(lnet_msg_t *msg)
341 {
342         /* ALWAYS called with liblock held */
343         LASSERT (!msg->msg_onactivelist);
344         LIBCFS_FREE(msg, sizeof(*msg));
345 }
346 #endif
347
348 extern lnet_libhandle_t *lnet_lookup_cookie (__u64 cookie, int type);
349 extern void lnet_initialise_handle (lnet_libhandle_t *lh, int type);
350 extern void lnet_invalidate_handle (lnet_libhandle_t *lh);
351
352 static inline void
353 lnet_eq2handle (lnet_handle_eq_t *handle, lnet_eq_t *eq)
354 {
355         if (eq == NULL) {
356                 *handle = LNET_EQ_NONE;
357                 return;
358         }
359
360         handle->cookie = eq->eq_lh.lh_cookie;
361 }
362
363 static inline lnet_eq_t *
364 lnet_handle2eq (lnet_handle_eq_t *handle)
365 {
366         /* ALWAYS called with liblock held */
367         lnet_libhandle_t *lh = lnet_lookup_cookie(handle->cookie, 
368                                                   LNET_COOKIE_TYPE_EQ);
369         if (lh == NULL)
370                 return (NULL);
371
372         return (lh_entry (lh, lnet_eq_t, eq_lh));
373 }
374
375 static inline void
376 lnet_md2handle (lnet_handle_md_t *handle, lnet_libmd_t *md)
377 {
378         handle->cookie = md->md_lh.lh_cookie;
379 }
380
381 static inline lnet_libmd_t *
382 lnet_handle2md (lnet_handle_md_t *handle)
383 {
384         /* ALWAYS called with liblock held */
385         lnet_libhandle_t *lh = lnet_lookup_cookie(handle->cookie,
386                                                   LNET_COOKIE_TYPE_MD);
387         if (lh == NULL)
388                 return (NULL);
389
390         return (lh_entry (lh, lnet_libmd_t, md_lh));
391 }
392
393 static inline lnet_libmd_t *
394 lnet_wire_handle2md (lnet_handle_wire_t *wh)
395 {
396         /* ALWAYS called with liblock held */
397         lnet_libhandle_t *lh;
398         
399         if (wh->wh_interface_cookie != the_lnet.ln_interface_cookie)
400                 return (NULL);
401         
402         lh = lnet_lookup_cookie(wh->wh_object_cookie,
403                                 LNET_COOKIE_TYPE_MD);
404         if (lh == NULL)
405                 return (NULL);
406
407         return (lh_entry (lh, lnet_libmd_t, md_lh));
408 }
409
410 static inline void
411 lnet_me2handle (lnet_handle_me_t *handle, lnet_me_t *me)
412 {
413         handle->cookie = me->me_lh.lh_cookie;
414 }
415
416 static inline lnet_me_t *
417 lnet_handle2me (lnet_handle_me_t *handle)
418 {
419         /* ALWAYS called with liblock held */
420         lnet_libhandle_t *lh = lnet_lookup_cookie(handle->cookie,
421                                                   LNET_COOKIE_TYPE_ME);
422         if (lh == NULL)
423                 return (NULL);
424
425         return (lh_entry (lh, lnet_me_t, me_lh));
426 }
427
428 static inline void
429 lnet_peer_addref_locked(lnet_peer_t *lp)
430 {
431         LASSERT (lp->lp_refcount > 0);
432         lp->lp_refcount++;
433 }
434
435 extern void lnet_destroy_peer_locked(lnet_peer_t *lp);
436
437 static inline void
438 lnet_peer_decref_locked(lnet_peer_t *lp)
439 {
440         LASSERT (lp->lp_refcount > 0);
441         lp->lp_refcount--;
442         if (lp->lp_refcount == 0)
443                 lnet_destroy_peer_locked(lp);
444 }
445
446 static inline int
447 lnet_isrouter(lnet_peer_t *lp)
448 {
449         return lp->lp_rtr_refcount != 0;
450 }
451
452 static inline void
453 lnet_ni_addref_locked(lnet_ni_t *ni) 
454 {
455         LASSERT (ni->ni_refcount > 0);
456         ni->ni_refcount++;
457 }
458
459 static inline void
460 lnet_ni_addref(lnet_ni_t *ni) 
461 {
462         LNET_LOCK();
463         lnet_ni_addref_locked(ni);
464         LNET_UNLOCK();
465 }
466
467 static inline void
468 lnet_ni_decref_locked(lnet_ni_t *ni)
469 {
470         LASSERT (ni->ni_refcount > 0);
471         ni->ni_refcount--;
472         if (ni->ni_refcount == 0)
473                 list_add_tail(&ni->ni_list, &the_lnet.ln_zombie_nis);
474 }
475
476 static inline void
477 lnet_ni_decref(lnet_ni_t *ni)
478 {
479         LNET_LOCK();
480         lnet_ni_decref_locked(ni);
481         LNET_UNLOCK();
482 }
483
484 static inline lnet_nid_t
485 lnet_ptlcompat_srcnid(lnet_nid_t src, lnet_nid_t dst)
486 {
487         /* Give myself a portals srcnid if I'm sending to portals */
488         if (the_lnet.ln_ptlcompat > 0 &&   
489             LNET_NIDNET(dst) == 0)
490                 return LNET_MKNID(0, LNET_NIDADDR(src));
491         
492         return src;
493 }
494
495 static inline int
496 lnet_ptlcompat_matchnid(lnet_nid_t lnet_nid, lnet_nid_t ptl_nid) 
497 {
498         return ((ptl_nid == lnet_nid) ||
499                 (the_lnet.ln_ptlcompat > 0 &&
500                  LNET_NIDNET(ptl_nid) == 0 &&
501                  LNET_NETTYP(LNET_NIDNET(lnet_nid)) != LOLND &&
502                  LNET_NIDADDR(ptl_nid) == LNET_NIDADDR(lnet_nid)));
503 }
504
505 static inline int
506 lnet_ptlcompat_matchnet(__u32 lnet_net, __u32 ptl_net) 
507 {
508         return ((ptl_net == lnet_net) ||
509                 (the_lnet.ln_ptlcompat > 0 &&
510                  ptl_net == 0 &&
511                  LNET_NETTYP(lnet_net) != LOLND));
512 }
513
514 static inline struct list_head *
515 lnet_nid2peerhash (lnet_nid_t nid)
516 {
517         unsigned int idx = LNET_NIDADDR(nid) % LNET_PEER_HASHSIZE;
518
519         return &the_lnet.ln_peer_hash[idx];
520 }
521
522 extern lnd_t the_lolnd;
523
524 #ifndef __KERNEL__
525 /* unconditional registration */
526 #define LNET_REGISTER_ULND(lnd)                 \
527 do {                                            \
528         extern lnd_t lnd;                       \
529                                                 \
530         lnet_register_lnd(&(lnd));              \
531 } while (0)
532
533 /* conditional registration */
534 #define LNET_REGISTER_ULND_IF_PRESENT(lnd)                              \
535 do {                                                                    \
536         extern lnd_t lnd __attribute__ ((weak, alias("the_lolnd")));    \
537                                                                         \
538         if (&(lnd) != &the_lolnd)                                       \
539                 lnet_register_lnd(&(lnd));                              \
540 } while (0)
541 #endif
542
543 #ifdef CRAY_XT3
544 inline static void
545 lnet_set_msg_uid(lnet_ni_t *ni, lnet_msg_t *msg, lnet_uid_t uid)
546 {
547         LASSERT (msg->msg_ev.uid == LNET_UID_ANY);
548         msg->msg_ev.uid = uid;
549 }
550 #endif
551
552 extern lnet_ni_t *lnet_nid2ni_locked (lnet_nid_t nid);
553 extern lnet_ni_t *lnet_net2ni_locked (__u32 net);
554 static inline lnet_ni_t *
555 lnet_net2ni (__u32 net) 
556 {
557         lnet_ni_t *ni;
558
559         LNET_LOCK();
560         ni = lnet_net2ni_locked(net);
561         LNET_UNLOCK();
562
563         return ni;
564 }
565
566 int lnet_notify(lnet_ni_t *ni, lnet_nid_t peer, int alive, time_t when);
567 int lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway_nid);
568 int lnet_check_routes(void);
569 int lnet_del_route(__u32 net, lnet_nid_t gw_nid);
570 void lnet_destroy_routes(void);
571 int lnet_get_route(int idx, __u32 *net, __u32 *hops, 
572                    lnet_nid_t *gateway, __u32 *alive);
573 void lnet_proc_init(void);
574 void lnet_proc_fini(void);
575 void lnet_init_rtrpools(void);
576 int  lnet_alloc_rtrpools(int im_a_router);
577 void lnet_free_rtrpools(void);
578 lnet_remotenet_t *lnet_find_net_locked (__u32 net);
579
580 int lnet_islocalnid(lnet_nid_t nid);
581 int lnet_islocalnet(__u32 net);
582
583 void lnet_build_unlink_event(lnet_libmd_t *md, lnet_event_t *ev);
584 void lnet_enq_event_locked(lnet_eq_t *eq, lnet_event_t *ev);
585 void lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
586                     unsigned int offset, unsigned int len);
587 int lnet_send(lnet_nid_t nid, lnet_msg_t *msg);
588 void lnet_return_credits_locked (lnet_msg_t *msg);
589 void lnet_match_blocked_msg(lnet_libmd_t *md);
590 int lnet_parse (lnet_ni_t *ni, lnet_hdr_t *hdr,
591                 lnet_nid_t fromnid, void *private, int rdma_req);
592 void lnet_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
593                unsigned int offset, unsigned int mlen, unsigned int rlen);
594 lnet_msg_t *lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *get_msg);
595 void lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *msg, unsigned int len);
596 void lnet_finalize(lnet_ni_t *ni, lnet_msg_t *msg, int rc);
597
598 char *lnet_msgtyp2str (int type);
599 void lnet_print_hdr (lnet_hdr_t * hdr);
600 int lnet_fail_nid(lnet_nid_t nid, unsigned int threshold);
601
602 unsigned int lnet_iov_nob (unsigned int niov, struct iovec *iov);
603 int lnet_extract_iov (int dst_niov, struct iovec *dst,
604                       int src_niov, struct iovec *src,
605                       unsigned int offset, unsigned int len);
606
607 unsigned int lnet_kiov_nob (unsigned int niov, lnet_kiov_t *iov);
608 int lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst, 
609                       int src_niov, lnet_kiov_t *src,
610                       unsigned int offset, unsigned int len);
611
612 void lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov, 
613                         unsigned int doffset, 
614                         unsigned int nsiov, struct iovec *siov, 
615                         unsigned int soffset, unsigned int nob);
616 void lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, 
617                          unsigned int iovoffset,
618                          unsigned int nkiov, lnet_kiov_t *kiov, 
619                          unsigned int kiovoffset, unsigned int nob);
620 void lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, 
621                          unsigned int kiovoffset,
622                          unsigned int niov, struct iovec *iov, 
623                          unsigned int iovoffset, unsigned int nob);
624 void lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov, 
625                           unsigned int doffset, 
626                           unsigned int nskiov, lnet_kiov_t *skiov, 
627                           unsigned int soffset, unsigned int nob);
628
629 static inline void
630 lnet_copy_iov2flat(int dlen, void *dest, unsigned int doffset,
631                    unsigned int nsiov, struct iovec *siov, unsigned int soffset,
632                    unsigned int nob)
633 {
634         struct iovec diov = {/*.iov_base = */ dest, /*.iov_len = */ dlen};
635
636         lnet_copy_iov2iov(1, &diov, doffset,
637                           nsiov, siov, soffset, nob);
638 }
639
640 static inline void
641 lnet_copy_kiov2flat(int dlen, void *dest, unsigned int doffset,
642                     unsigned int nsiov, lnet_kiov_t *skiov, unsigned int soffset,
643                     unsigned int nob)
644 {
645         struct iovec diov = {/* .iov_base = */ dest, /* .iov_len = */ dlen};
646
647         lnet_copy_kiov2iov(1, &diov, doffset,
648                            nsiov, skiov, soffset, nob);
649 }
650
651 static inline void
652 lnet_copy_flat2iov(unsigned int ndiov, struct iovec *diov, unsigned int doffset,
653                    int slen, void *src, unsigned int soffset, unsigned int nob)
654 {
655         struct iovec siov = {/*.iov_base = */ src, /*.iov_len = */slen};
656         lnet_copy_iov2iov(ndiov, diov, doffset,
657                           1, &siov, soffset, nob);
658 }
659
660 static inline void
661 lnet_copy_flat2kiov(unsigned int ndiov, lnet_kiov_t *dkiov, unsigned int doffset,
662                     int slen, void *src, unsigned int soffset, unsigned int nob)
663 {
664         struct iovec siov = {/* .iov_base = */ src, /* .iov_len = */ slen};
665         lnet_copy_iov2kiov(ndiov, dkiov, doffset,
666                            1, &siov, soffset, nob);
667 }
668
669 void lnet_me_unlink(lnet_me_t *me);
670
671 void lnet_md_unlink(lnet_libmd_t *md);
672 void lnet_md_deconstruct(lnet_libmd_t *lmd, lnet_md_t *umd);
673
674 void lnet_register_lnd(lnd_t *lnd);
675 void lnet_unregister_lnd(lnd_t *lnd);
676 int lnet_set_ip_niaddr (lnet_ni_t *ni);
677
678 #ifdef __KERNEL__
679 int lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
680                  __u32 local_ip, __u32 peer_ip, int peer_port);
681 void lnet_connect_console_error(int rc, lnet_nid_t peer_nid,
682                                 __u32 peer_ip, int port);
683 int lnet_count_acceptor_nis(lnet_ni_t **first_ni);
684 int lnet_accept(lnet_ni_t *blind_ni, cfs_socket_t *sock, __u32 magic);
685 int lnet_acceptor_timeout(void);
686 int lnet_acceptor_port(void);
687 #endif
688
689 #ifdef HAVE_LIBPTHREAD
690 int lnet_count_acceptor_nis(lnet_ni_t **first_ni);
691 int lnet_acceptor_port(void);
692 #endif
693
694 int lnet_acceptor_start(void);
695 void lnet_acceptor_stop(void);
696
697 int lnet_peers_start_down(void);
698 int lnet_router_checker_start(void);
699 void lnet_router_checker_stop(void);
700
701 int lnet_ping_target_init(void);
702 void lnet_ping_target_fini(void);
703 int lnet_ping(lnet_process_id_t id, int timeout_ms,
704               lnet_process_id_t *ids, int n_ids);
705
706 int lnet_parse_ip2nets (char **networksp, char *ip2nets);
707 int lnet_parse_routes (char *route_str, int *im_a_router);
708 int lnet_parse_networks (struct list_head *nilist, char *networks);
709
710 int lnet_nid2peer_locked(lnet_peer_t **lpp, lnet_nid_t nid);
711 lnet_peer_t *lnet_find_peer_locked (lnet_nid_t nid);
712 void lnet_clear_peer_table(void);
713 void lnet_destroy_peer_table(void);
714 int lnet_create_peer_table(void);
715 void lnet_debug_peer(lnet_nid_t nid);
716
717 #endif