4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/include/lnet/lib-lnet.h
38 * Top level include for library side routines
41 #ifndef __LNET_LIB_LNET_H__
42 #define __LNET_LIB_LNET_H__
46 #include <libcfs/libcfs.h>
47 #include <lnet/types.h>
48 #include <lnet/lnet.h>
49 #include <lnet/lib-types.h>
50 #include <lnet/lib-dlc.h>
52 extern lnet_t the_lnet; /* THE network */
54 #if !defined(__KERNEL__) || defined(LNET_USE_LIB_FREELIST)
55 /* 1 CPT, simplify implementation... */
56 # define LNET_CPT_MAX_BITS 0
58 #else /* KERNEL and no freelist */
60 # if (BITS_PER_LONG == 32)
61 /* 2 CPTs, allowing more CPTs might make us under memory pressure */
62 # define LNET_CPT_MAX_BITS 1
64 # else /* 64-bit system */
66 * 256 CPTs for thousands of CPUs, allowing more CPTs might make us
67 * under risk of consuming all lh_cookie.
69 # define LNET_CPT_MAX_BITS 8
70 # endif /* BITS_PER_LONG == 32 */
73 /* max allowed CPT number */
74 #define LNET_CPT_MAX (1 << LNET_CPT_MAX_BITS)
76 #define LNET_CPT_NUMBER (the_lnet.ln_cpt_number)
77 #define LNET_CPT_BITS (the_lnet.ln_cpt_bits)
78 #define LNET_CPT_MASK ((1ULL << LNET_CPT_BITS) - 1)
81 #define LNET_LOCK_EX CFS_PERCPT_LOCK_EX
83 static inline int lnet_is_route_alive(lnet_route_t *route)
85 if (!route->lr_gateway->lp_alive)
86 return 0; /* gateway is down */
87 if ((route->lr_gateway->lp_ping_feats &
88 LNET_PING_FEAT_NI_STATUS) == 0)
89 return 1; /* no NI status, assume it's alive */
90 /* has NI status, check # down NIs */
91 return route->lr_downis == 0;
94 static inline int lnet_is_wire_handle_none (lnet_handle_wire_t *wh)
96 return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_COOKIE_NONE &&
97 wh->wh_object_cookie == LNET_WIRE_HANDLE_COOKIE_NONE);
100 static inline int lnet_md_exhausted (lnet_libmd_t *md)
102 return (md->md_threshold == 0 ||
103 ((md->md_options & LNET_MD_MAX_SIZE) != 0 &&
104 md->md_offset + md->md_max_size > md->md_length));
107 static inline int lnet_md_unlinkable (lnet_libmd_t *md)
109 /* Should unlink md when its refcount is 0 and either:
110 * - md has been flagged for deletion (by auto unlink or LNetM[DE]Unlink,
111 * in the latter case md may not be exhausted).
112 * - auto unlink is on and md is exhausted.
114 if (md->md_refcount != 0)
117 if ((md->md_flags & LNET_MD_FLAG_ZOMBIE) != 0)
120 return ((md->md_flags & LNET_MD_FLAG_AUTO_UNLINK) != 0 &&
121 lnet_md_exhausted(md));
124 #define lnet_cpt_table() (the_lnet.ln_cpt_table)
125 #define lnet_cpt_current() cfs_cpt_current(the_lnet.ln_cpt_table, 1)
128 lnet_cpt_of_cookie(__u64 cookie)
130 unsigned int cpt = (cookie >> LNET_COOKIE_TYPE_BITS) & LNET_CPT_MASK;
132 /* LNET_CPT_NUMBER doesn't have to be power2, which means we can
133 * get illegal cpt from it's invalid cookie */
134 return cpt < LNET_CPT_NUMBER ? cpt : cpt % LNET_CPT_NUMBER;
138 lnet_res_lock(int cpt)
140 cfs_percpt_lock(the_lnet.ln_res_lock, cpt);
144 lnet_res_unlock(int cpt)
146 cfs_percpt_unlock(the_lnet.ln_res_lock, cpt);
150 lnet_res_lock_current(void)
152 int cpt = lnet_cpt_current();
159 lnet_net_lock(int cpt)
161 cfs_percpt_lock(the_lnet.ln_net_lock, cpt);
165 lnet_net_unlock(int cpt)
167 cfs_percpt_unlock(the_lnet.ln_net_lock, cpt);
171 lnet_net_lock_current(void)
173 int cpt = lnet_cpt_current();
179 #define LNET_LOCK() lnet_net_lock(LNET_LOCK_EX)
180 #define LNET_UNLOCK() lnet_net_unlock(LNET_LOCK_EX)
184 #define lnet_ptl_lock(ptl) spin_lock(&(ptl)->ptl_lock)
185 #define lnet_ptl_unlock(ptl) spin_unlock(&(ptl)->ptl_lock)
186 #define lnet_eq_wait_lock() spin_lock(&the_lnet.ln_eq_wait_lock)
187 #define lnet_eq_wait_unlock() spin_unlock(&the_lnet.ln_eq_wait_lock)
188 #define lnet_ni_lock(ni) spin_lock(&(ni)->ni_lock)
189 #define lnet_ni_unlock(ni) spin_unlock(&(ni)->ni_lock)
190 #define LNET_MUTEX_LOCK(m) mutex_lock(m)
191 #define LNET_MUTEX_UNLOCK(m) mutex_unlock(m)
193 #else /* !__KERNEL__ */
195 # ifndef HAVE_LIBPTHREAD
196 #define LNET_SINGLE_THREADED_LOCK(l) \
198 LASSERT ((l) == 0); \
202 #define LNET_SINGLE_THREADED_UNLOCK(l) \
204 LASSERT ((l) == 1); \
208 #define LNET_MUTEX_LOCK(m) LNET_SINGLE_THREADED_LOCK(*(m))
209 #define LNET_MUTEX_UNLOCK(m) LNET_SINGLE_THREADED_UNLOCK(*(m))
211 #define lnet_ptl_lock(ptl) \
212 LNET_SINGLE_THREADED_LOCK((ptl)->ptl_lock)
213 #define lnet_ptl_unlock(ptl) \
214 LNET_SINGLE_THREADED_UNLOCK((ptl)->ptl_lock)
216 #define lnet_eq_wait_lock() \
217 LNET_SINGLE_THREADED_LOCK(the_lnet.ln_eq_wait_lock)
218 #define lnet_eq_wait_unlock() \
219 LNET_SINGLE_THREADED_UNLOCK(the_lnet.ln_eq_wait_lock)
221 #define lnet_ni_lock(ni) \
222 LNET_SINGLE_THREADED_LOCK((ni)->ni_lock)
223 #define lnet_ni_unlock(ni) \
224 LNET_SINGLE_THREADED_UNLOCK((ni)->ni_lock)
226 # else /* HAVE_LIBPTHREAD */
228 #define LNET_MUTEX_LOCK(m) pthread_mutex_lock(m)
229 #define LNET_MUTEX_UNLOCK(m) pthread_mutex_unlock(m)
231 #define lnet_ptl_lock(ptl) pthread_mutex_lock(&(ptl)->ptl_lock)
232 #define lnet_ptl_unlock(ptl) pthread_mutex_unlock(&(ptl)->ptl_lock)
234 #define lnet_eq_wait_lock() pthread_mutex_lock(&the_lnet.ln_eq_wait_lock)
235 #define lnet_eq_wait_unlock() pthread_mutex_unlock(&the_lnet.ln_eq_wait_lock)
237 #define lnet_ni_lock(ni) pthread_mutex_lock(&(ni)->ni_lock)
238 #define lnet_ni_unlock(ni) pthread_mutex_unlock(&(ni)->ni_lock)
240 # endif /* HAVE_LIBPTHREAD */
241 #endif /* __KERNEL__ */
243 #define MAX_PORTALS 64
245 /* these are only used by code with LNET_USE_LIB_FREELIST, but we still
246 * exported them to !LNET_USE_LIB_FREELIST for easy implemetation */
247 #define LNET_FL_MAX_MES 2048
248 #define LNET_FL_MAX_MDS 2048
249 #define LNET_FL_MAX_EQS 512
250 #define LNET_FL_MAX_MSGS 2048 /* Outstanding messages */
252 #ifdef LNET_USE_LIB_FREELIST
254 int lnet_freelist_init(lnet_freelist_t *fl, int n, int size);
255 void lnet_freelist_fini(lnet_freelist_t *fl);
258 lnet_freelist_alloc (lnet_freelist_t *fl)
260 /* ALWAYS called with liblock held */
263 if (list_empty(&fl->fl_list))
266 o = list_entry(fl->fl_list.next, lnet_freeobj_t, fo_list);
267 list_del(&o->fo_list);
268 return (void *)&o->fo_contents;
272 lnet_freelist_free (lnet_freelist_t *fl, void *obj)
274 /* ALWAYS called with liblock held */
275 lnet_freeobj_t *o = list_entry(obj, lnet_freeobj_t, fo_contents);
277 list_add(&o->fo_list, &fl->fl_list);
281 static inline lnet_eq_t *
284 /* NEVER called with resource lock held */
285 struct lnet_res_container *rec = &the_lnet.ln_eq_container;
288 LASSERT(LNET_CPT_NUMBER == 1);
291 eq = (lnet_eq_t *)lnet_freelist_alloc(&rec->rec_freelist);
298 lnet_eq_free_locked(lnet_eq_t *eq)
300 /* ALWAYS called with resource lock held */
301 struct lnet_res_container *rec = &the_lnet.ln_eq_container;
303 LASSERT(LNET_CPT_NUMBER == 1);
304 lnet_freelist_free(&rec->rec_freelist, eq);
308 lnet_eq_free(lnet_eq_t *eq)
311 lnet_eq_free_locked(eq);
315 static inline lnet_libmd_t *
316 lnet_md_alloc (lnet_md_t *umd)
318 /* NEVER called with resource lock held */
319 struct lnet_res_container *rec = the_lnet.ln_md_containers[0];
322 LASSERT(LNET_CPT_NUMBER == 1);
325 md = (lnet_libmd_t *)lnet_freelist_alloc(&rec->rec_freelist);
329 INIT_LIST_HEAD(&md->md_list);
335 lnet_md_free_locked(lnet_libmd_t *md)
337 /* ALWAYS called with resource lock held */
338 struct lnet_res_container *rec = the_lnet.ln_md_containers[0];
340 LASSERT(LNET_CPT_NUMBER == 1);
341 lnet_freelist_free(&rec->rec_freelist, md);
345 lnet_md_free(lnet_libmd_t *md)
348 lnet_md_free_locked(md);
352 static inline lnet_me_t *
355 /* NEVER called with resource lock held */
356 struct lnet_res_container *rec = the_lnet.ln_me_containers[0];
359 LASSERT(LNET_CPT_NUMBER == 1);
362 me = (lnet_me_t *)lnet_freelist_alloc(&rec->rec_freelist);
369 lnet_me_free_locked(lnet_me_t *me)
371 /* ALWAYS called with resource lock held */
372 struct lnet_res_container *rec = the_lnet.ln_me_containers[0];
374 LASSERT(LNET_CPT_NUMBER == 1);
375 lnet_freelist_free(&rec->rec_freelist, me);
379 lnet_me_free(lnet_me_t *me)
382 lnet_me_free_locked(me);
386 static inline lnet_msg_t *
387 lnet_msg_alloc (void)
389 /* NEVER called with network lock held */
390 struct lnet_msg_container *msc = the_lnet.ln_msg_containers[0];
393 LASSERT(LNET_CPT_NUMBER == 1);
396 msg = (lnet_msg_t *)lnet_freelist_alloc(&msc->msc_freelist);
400 /* NULL pointers, clear flags etc */
401 memset(msg, 0, sizeof(*msg));
407 lnet_msg_free_locked(lnet_msg_t *msg)
409 /* ALWAYS called with network lock held */
410 struct lnet_msg_container *msc = the_lnet.ln_msg_containers[0];
412 LASSERT(LNET_CPT_NUMBER == 1);
413 LASSERT(!msg->msg_onactivelist);
414 lnet_freelist_free(&msc->msc_freelist, msg);
418 lnet_msg_free (lnet_msg_t *msg)
421 lnet_msg_free_locked(msg);
425 #else /* !LNET_USE_LIB_FREELIST */
427 static inline lnet_eq_t *
430 /* NEVER called with liblock held */
433 LIBCFS_ALLOC(eq, sizeof(*eq));
438 lnet_eq_free(lnet_eq_t *eq)
440 /* ALWAYS called with resource lock held */
441 LIBCFS_FREE(eq, sizeof(*eq));
444 static inline lnet_libmd_t *
445 lnet_md_alloc (lnet_md_t *umd)
447 /* NEVER called with liblock held */
452 if ((umd->options & LNET_MD_KIOV) != 0) {
454 size = offsetof(lnet_libmd_t, md_iov.kiov[niov]);
456 niov = ((umd->options & LNET_MD_IOVEC) != 0) ?
458 size = offsetof(lnet_libmd_t, md_iov.iov[niov]);
461 LIBCFS_ALLOC(md, size);
464 /* Set here in case of early free */
465 md->md_options = umd->options;
467 INIT_LIST_HEAD(&md->md_list);
474 lnet_md_free(lnet_libmd_t *md)
476 /* ALWAYS called with resource lock held */
479 if ((md->md_options & LNET_MD_KIOV) != 0)
480 size = offsetof(lnet_libmd_t, md_iov.kiov[md->md_niov]);
482 size = offsetof(lnet_libmd_t, md_iov.iov[md->md_niov]);
484 LIBCFS_FREE(md, size);
487 static inline lnet_me_t *
490 /* NEVER called with liblock held */
493 LIBCFS_ALLOC(me, sizeof(*me));
498 lnet_me_free(lnet_me_t *me)
500 /* ALWAYS called with resource lock held */
501 LIBCFS_FREE(me, sizeof(*me));
504 static inline lnet_msg_t *
507 /* NEVER called with liblock held */
510 LIBCFS_ALLOC(msg, sizeof(*msg));
512 /* no need to zero, LIBCFS_ALLOC does for us */
517 lnet_msg_free(lnet_msg_t *msg)
519 /* ALWAYS called with network lock held */
520 LASSERT(!msg->msg_onactivelist);
521 LIBCFS_FREE(msg, sizeof(*msg));
524 #define lnet_eq_free_locked(eq) lnet_eq_free(eq)
525 #define lnet_md_free_locked(md) lnet_md_free(md)
526 #define lnet_me_free_locked(me) lnet_me_free(me)
527 #define lnet_msg_free_locked(msg) lnet_msg_free(msg)
529 #endif /* LNET_USE_LIB_FREELIST */
531 lnet_libhandle_t *lnet_res_lh_lookup(struct lnet_res_container *rec,
533 void lnet_res_lh_initialize(struct lnet_res_container *rec,
534 lnet_libhandle_t *lh);
536 lnet_res_lh_invalidate(lnet_libhandle_t *lh)
538 /* ALWAYS called with resource lock held */
539 /* NB: cookie is still useful, don't reset it */
540 list_del(&lh->lh_hash_chain);
544 lnet_eq2handle (lnet_handle_eq_t *handle, lnet_eq_t *eq)
547 LNetInvalidateHandle(handle);
551 handle->cookie = eq->eq_lh.lh_cookie;
554 static inline lnet_eq_t *
555 lnet_handle2eq(lnet_handle_eq_t *handle)
557 /* ALWAYS called with resource lock held */
558 lnet_libhandle_t *lh;
560 lh = lnet_res_lh_lookup(&the_lnet.ln_eq_container, handle->cookie);
564 return lh_entry(lh, lnet_eq_t, eq_lh);
568 lnet_md2handle (lnet_handle_md_t *handle, lnet_libmd_t *md)
570 handle->cookie = md->md_lh.lh_cookie;
573 static inline lnet_libmd_t *
574 lnet_handle2md(lnet_handle_md_t *handle)
576 /* ALWAYS called with resource lock held */
577 lnet_libhandle_t *lh;
580 cpt = lnet_cpt_of_cookie(handle->cookie);
581 lh = lnet_res_lh_lookup(the_lnet.ln_md_containers[cpt],
586 return lh_entry(lh, lnet_libmd_t, md_lh);
589 static inline lnet_libmd_t *
590 lnet_wire_handle2md(lnet_handle_wire_t *wh)
592 /* ALWAYS called with resource lock held */
593 lnet_libhandle_t *lh;
596 if (wh->wh_interface_cookie != the_lnet.ln_interface_cookie)
599 cpt = lnet_cpt_of_cookie(wh->wh_object_cookie);
600 lh = lnet_res_lh_lookup(the_lnet.ln_md_containers[cpt],
601 wh->wh_object_cookie);
605 return lh_entry(lh, lnet_libmd_t, md_lh);
609 lnet_me2handle (lnet_handle_me_t *handle, lnet_me_t *me)
611 handle->cookie = me->me_lh.lh_cookie;
614 static inline lnet_me_t *
615 lnet_handle2me(lnet_handle_me_t *handle)
617 /* ALWAYS called with resource lock held */
618 lnet_libhandle_t *lh;
621 cpt = lnet_cpt_of_cookie(handle->cookie);
622 lh = lnet_res_lh_lookup(the_lnet.ln_me_containers[cpt],
627 return lh_entry(lh, lnet_me_t, me_lh);
631 lnet_peer_addref_locked(lnet_peer_t *lp)
633 LASSERT (lp->lp_refcount > 0);
637 extern void lnet_destroy_peer_locked(lnet_peer_t *lp);
640 lnet_peer_decref_locked(lnet_peer_t *lp)
642 LASSERT (lp->lp_refcount > 0);
644 if (lp->lp_refcount == 0)
645 lnet_destroy_peer_locked(lp);
649 lnet_isrouter(lnet_peer_t *lp)
651 return lp->lp_rtr_refcount != 0;
655 lnet_ni_addref_locked(lnet_ni_t *ni, int cpt)
657 LASSERT(cpt >= 0 && cpt < LNET_CPT_NUMBER);
658 LASSERT(*ni->ni_refs[cpt] >= 0);
660 (*ni->ni_refs[cpt])++;
664 lnet_ni_addref(lnet_ni_t *ni)
667 lnet_ni_addref_locked(ni, 0);
672 lnet_ni_decref_locked(lnet_ni_t *ni, int cpt)
674 LASSERT(cpt >= 0 && cpt < LNET_CPT_NUMBER);
675 LASSERT(*ni->ni_refs[cpt] > 0);
677 (*ni->ni_refs[cpt])--;
681 lnet_ni_decref(lnet_ni_t *ni)
684 lnet_ni_decref_locked(ni, 0);
688 void lnet_ni_free(lnet_ni_t *ni);
691 lnet_nid2peerhash(lnet_nid_t nid)
693 return hash_long(nid, LNET_PEER_HASH_BITS);
696 static inline struct list_head *
697 lnet_net2rnethash(__u32 net)
699 return &the_lnet.ln_remote_nets_hash[(LNET_NETNUM(net) +
701 ((1U << the_lnet.ln_remote_nets_hbits) - 1)];
704 extern lnd_t the_lolnd;
705 extern int avoid_asym_router_failure;
708 /* unconditional registration */
709 #define LNET_REGISTER_ULND(lnd) \
713 lnet_register_lnd(&(lnd)); \
716 /* conditional registration */
717 #define LNET_REGISTER_ULND_IF_PRESENT(lnd) \
719 extern lnd_t lnd __attribute__ ((weak, alias("the_lolnd"))); \
721 if (&(lnd) != &the_lolnd) \
722 lnet_register_lnd(&(lnd)); \
726 extern int lnet_cpt_of_nid_locked(lnet_nid_t nid);
727 extern int lnet_cpt_of_nid(lnet_nid_t nid);
728 extern lnet_ni_t *lnet_nid2ni_locked(lnet_nid_t nid, int cpt);
729 extern lnet_ni_t *lnet_net2ni_locked(__u32 net, int cpt);
730 extern lnet_ni_t *lnet_net2ni(__u32 net);
732 int lnet_notify(lnet_ni_t *ni, lnet_nid_t peer, int alive, cfs_time_t when);
733 void lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, cfs_time_t when);
734 int lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway_nid,
735 unsigned int priority);
736 int lnet_check_routes(void);
737 int lnet_del_route(__u32 net, lnet_nid_t gw_nid);
738 void lnet_destroy_routes(void);
739 int lnet_get_route(int idx, __u32 *net, __u32 *hops,
740 lnet_nid_t *gateway, __u32 *alive, __u32 *priority);
741 int lnet_get_net_config(int idx,
745 int *peer_tx_credits,
748 struct lnet_ioctl_net_config *net_config);
749 int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg);
751 void lnet_proc_init(void);
752 void lnet_proc_fini(void);
753 int lnet_rtrpools_alloc(int im_a_router);
754 void lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages);
755 int lnet_rtrpools_adjust(int tiny, int small, int large);
756 int lnet_rtrpools_enable(void);
757 void lnet_rtrpools_disable(void);
758 void lnet_rtrpools_free(int keep_pools);
759 lnet_remotenet_t *lnet_find_net_locked (__u32 net);
760 int lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
761 __s32 peer_timeout, __s32 peer_cr, __s32 peer_buf_cr,
763 int lnet_dyn_del_ni(__u32 net);
765 int lnet_islocalnid(lnet_nid_t nid);
766 int lnet_islocalnet(__u32 net);
768 void lnet_msg_attach_md(lnet_msg_t *msg, lnet_libmd_t *md,
769 unsigned int offset, unsigned int mlen);
770 void lnet_msg_detach_md(lnet_msg_t *msg, int status);
771 void lnet_build_unlink_event(lnet_libmd_t *md, lnet_event_t *ev);
772 void lnet_build_msg_event(lnet_msg_t *msg, lnet_event_kind_t ev_type);
773 void lnet_msg_commit(lnet_msg_t *msg, int cpt);
774 void lnet_msg_decommit(lnet_msg_t *msg, int cpt, int status);
776 void lnet_eq_enqueue_event(lnet_eq_t *eq, lnet_event_t *ev);
777 void lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
778 unsigned int offset, unsigned int len);
779 int lnet_send(lnet_nid_t nid, lnet_msg_t *msg, lnet_nid_t rtr_nid);
780 void lnet_return_tx_credits_locked(lnet_msg_t *msg);
781 void lnet_return_rx_credits_locked(lnet_msg_t *msg);
782 void lnet_schedule_blocked_locked(lnet_rtrbufpool_t *rbp);
783 void lnet_drop_routed_msgs_locked(struct list_head *list, int cpt);
785 /* portals functions */
786 /* portals attributes */
788 lnet_ptl_is_lazy(lnet_portal_t *ptl)
790 return !!(ptl->ptl_options & LNET_PTL_LAZY);
794 lnet_ptl_is_unique(lnet_portal_t *ptl)
796 return !!(ptl->ptl_options & LNET_PTL_MATCH_UNIQUE);
800 lnet_ptl_is_wildcard(lnet_portal_t *ptl)
802 return !!(ptl->ptl_options & LNET_PTL_MATCH_WILDCARD);
806 lnet_ptl_setopt(lnet_portal_t *ptl, int opt)
808 ptl->ptl_options |= opt;
812 lnet_ptl_unsetopt(lnet_portal_t *ptl, int opt)
814 ptl->ptl_options &= ~opt;
817 /* match-table functions */
818 struct list_head *lnet_mt_match_head(struct lnet_match_table *mtable,
819 lnet_process_id_t id, __u64 mbits);
820 struct lnet_match_table *lnet_mt_of_attach(unsigned int index,
821 lnet_process_id_t id, __u64 mbits,
824 int lnet_mt_match_md(struct lnet_match_table *mtable,
825 struct lnet_match_info *info, struct lnet_msg *msg);
827 /* portals match/attach functions */
828 void lnet_ptl_attach_md(lnet_me_t *me, lnet_libmd_t *md,
829 struct list_head *matches, struct list_head *drops);
830 void lnet_ptl_detach_md(lnet_me_t *me, lnet_libmd_t *md);
831 int lnet_ptl_match_md(struct lnet_match_info *info, struct lnet_msg *msg);
833 /* initialized and finalize portals */
834 int lnet_portals_create(void);
835 void lnet_portals_destroy(void);
837 /* message functions */
838 int lnet_parse (lnet_ni_t *ni, lnet_hdr_t *hdr,
839 lnet_nid_t fromnid, void *private, int rdma_req);
840 int lnet_parse_local(lnet_ni_t *ni, lnet_msg_t *msg);
841 int lnet_parse_forward_locked(lnet_ni_t *ni, lnet_msg_t *msg);
843 void lnet_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
844 unsigned int offset, unsigned int mlen, unsigned int rlen);
845 void lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg,
846 int delayed, unsigned int offset,
847 unsigned int mlen, unsigned int rlen);
849 lnet_msg_t *lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *get_msg);
850 void lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *msg, unsigned int len);
852 void lnet_finalize(lnet_ni_t *ni, lnet_msg_t *msg, int rc);
854 void lnet_drop_message(lnet_ni_t *ni, int cpt, void *private,
856 void lnet_drop_delayed_msg_list(struct list_head *head, char *reason);
857 void lnet_recv_delayed_msg_list(struct list_head *head);
859 int lnet_msg_container_setup(struct lnet_msg_container *container, int cpt);
860 void lnet_msg_container_cleanup(struct lnet_msg_container *container);
861 void lnet_msg_containers_destroy(void);
862 int lnet_msg_containers_create(void);
864 char *lnet_msgtyp2str (int type);
865 void lnet_print_hdr (lnet_hdr_t * hdr);
866 int lnet_fail_nid(lnet_nid_t nid, unsigned int threshold);
868 /** \addtogroup lnet_fault_simulation @{ */
870 int lnet_fault_ctl(int cmd, struct libcfs_ioctl_data *data);
871 int lnet_fault_init(void);
872 void lnet_fault_fini(void);
874 bool lnet_drop_rule_match(lnet_hdr_t *hdr);
876 int lnet_delay_rule_add(struct lnet_fault_attr *attr);
877 int lnet_delay_rule_del(lnet_nid_t src, lnet_nid_t dst, bool shutdown);
878 int lnet_delay_rule_list(int pos, struct lnet_fault_attr *attr,
879 struct lnet_fault_stat *stat);
880 void lnet_delay_rule_reset(void);
881 void lnet_delay_rule_check(void);
882 bool lnet_delay_rule_match_locked(lnet_hdr_t *hdr, struct lnet_msg *msg);
884 /** @} lnet_fault_simulation */
886 void lnet_counters_get(lnet_counters_t *counters);
887 void lnet_counters_reset(void);
889 unsigned int lnet_iov_nob (unsigned int niov, struct iovec *iov);
890 int lnet_extract_iov (int dst_niov, struct iovec *dst,
891 int src_niov, struct iovec *src,
892 unsigned int offset, unsigned int len);
894 unsigned int lnet_kiov_nob (unsigned int niov, lnet_kiov_t *iov);
895 int lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
896 int src_niov, lnet_kiov_t *src,
897 unsigned int offset, unsigned int len);
899 void lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov,
900 unsigned int doffset,
901 unsigned int nsiov, struct iovec *siov,
902 unsigned int soffset, unsigned int nob);
903 void lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov,
904 unsigned int iovoffset,
905 unsigned int nkiov, lnet_kiov_t *kiov,
906 unsigned int kiovoffset, unsigned int nob);
907 void lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov,
908 unsigned int kiovoffset,
909 unsigned int niov, struct iovec *iov,
910 unsigned int iovoffset, unsigned int nob);
911 void lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov,
912 unsigned int doffset,
913 unsigned int nskiov, lnet_kiov_t *skiov,
914 unsigned int soffset, unsigned int nob);
917 lnet_copy_iov2flat(int dlen, __user void *dest, unsigned int doffset,
918 unsigned int nsiov, struct iovec *siov, unsigned int soffset,
921 struct iovec diov = {/*.iov_base = */ dest, /*.iov_len = */ dlen};
923 lnet_copy_iov2iov(1, &diov, doffset,
924 nsiov, siov, soffset, nob);
928 lnet_copy_kiov2flat(int dlen, void __user *dest, unsigned int doffset,
929 unsigned int nsiov, lnet_kiov_t *skiov,
930 unsigned int soffset, unsigned int nob)
932 struct iovec diov = {/* .iov_base = */ dest, /* .iov_len = */ dlen};
934 lnet_copy_kiov2iov(1, &diov, doffset,
935 nsiov, skiov, soffset, nob);
939 lnet_copy_flat2iov(unsigned int ndiov, struct iovec *diov, unsigned int doffset,
940 int slen, void __user *src, unsigned int soffset,
943 struct iovec siov = {/*.iov_base = */ src, /*.iov_len = */slen};
944 lnet_copy_iov2iov(ndiov, diov, doffset,
945 1, &siov, soffset, nob);
949 lnet_copy_flat2kiov(unsigned int ndiov, lnet_kiov_t *dkiov,
950 unsigned int doffset, int slen, void __user *src,
951 unsigned int soffset, unsigned int nob)
953 struct iovec siov = {/* .iov_base = */ src, /* .iov_len = */ slen};
954 lnet_copy_iov2kiov(ndiov, dkiov, doffset,
955 1, &siov, soffset, nob);
958 void lnet_me_unlink(lnet_me_t *me);
960 void lnet_md_unlink(lnet_libmd_t *md);
961 void lnet_md_deconstruct(lnet_libmd_t *lmd, lnet_md_t *umd);
963 void lnet_register_lnd(lnd_t *lnd);
964 void lnet_unregister_lnd(lnd_t *lnd);
965 int lnet_set_ip_niaddr (lnet_ni_t *ni);
968 int lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
969 __u32 local_ip, __u32 peer_ip, int peer_port);
970 void lnet_connect_console_error(int rc, lnet_nid_t peer_nid,
971 __u32 peer_ip, int port);
972 int lnet_count_acceptor_nis(void);
973 int lnet_acceptor_timeout(void);
974 int lnet_acceptor_port(void);
976 void lnet_router_checker(void);
979 #ifdef HAVE_LIBPTHREAD
980 int lnet_count_acceptor_nis(void);
981 int lnet_acceptor_port(void);
984 int lnet_acceptor_start(void);
985 void lnet_acceptor_stop(void);
987 void lnet_get_tunables(void);
988 int lnet_peers_start_down(void);
989 int lnet_peer_buffer_credits(lnet_ni_t *ni);
991 int lnet_router_checker_start(void);
992 void lnet_router_checker_stop(void);
993 void lnet_router_ni_update_locked(lnet_peer_t *gw, __u32 net);
994 void lnet_swap_pinginfo(lnet_ping_info_t *info);
996 int lnet_parse_ip2nets(char **networksp, char *ip2nets);
997 int lnet_parse_routes(char *route_str, int *im_a_router);
998 int lnet_parse_networks(struct list_head *nilist, char *networks);
999 int lnet_net_unique(__u32 net, struct list_head *nilist);
1001 int lnet_nid2peer_locked(lnet_peer_t **lpp, lnet_nid_t nid, int cpt);
1002 lnet_peer_t *lnet_find_peer_locked(struct lnet_peer_table *ptable,
1004 void lnet_peer_tables_cleanup(lnet_ni_t *ni);
1005 void lnet_peer_tables_destroy(void);
1006 int lnet_peer_tables_create(void);
1007 void lnet_debug_peer(lnet_nid_t nid);
1008 int lnet_get_peer_info(__u32 peer_index, __u64 *nid,
1009 char alivness[LNET_MAX_STR_LEN],
1010 __u32 *cpt_iter, __u32 *refcount,
1011 __u32 *ni_peer_tx_credits, __u32 *peer_tx_credits,
1012 __u32 *peer_rtr_credits, __u32 *peer_min_rtr_credtis,
1013 __u32 *peer_tx_qnob);
1016 lnet_peer_set_alive(lnet_peer_t *lp)
1018 lp->lp_last_alive = lp->lp_last_query = cfs_time_current();
1020 lnet_notify_locked(lp, 0, 1, lp->lp_last_alive);
1025 lnet_parse_int_tunable(int *value, char *name)
1027 char *env = getenv(name);
1033 *value = strtoull(env, &end, 0);
1037 CERROR("Can't parse tunable %s=%s\n", name, env);