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.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
36 * Match Entry management routines
39 #define DEBUG_SUBSYSTEM S_LNET
41 #include <lnet/lib-lnet.h>
44 * Create and attach a match entry to the match list of \a portal. The new
45 * ME is empty, i.e. not associated with a memory descriptor. LNetMDAttach()
46 * can be used to attach a MD to an empty ME.
48 * \param portal The portal table index where the ME should be attached.
49 * \param match_id Specifies the match criteria for the process ID of
50 * the requester. The constants LNET_PID_ANY and LNET_NID_ANY can be
51 * used to wildcard either of the identifiers in the lnet_process_id_t
53 * \param match_bits,ignore_bits Specify the match criteria to apply
54 * to the match bits in the incoming request. The ignore bits are used
55 * to mask out insignificant bits in the incoming match bits. The resulting
56 * bits are then compared to the ME's match bits to determine if the
57 * incoming request meets the match criteria.
58 * \param unlink Indicates whether the ME should be unlinked when the memory
59 * descriptor associated with it is unlinked (Note that the check for
60 * unlinking a ME only occurs when the memory descriptor is unlinked.).
61 * Valid values are LNET_RETAIN and LNET_UNLINK.
62 * \param pos Indicates whether the new ME should be prepended or
63 * appended to the match list. Allowed constants: LNET_INS_BEFORE,
65 * \param handle On successful returns, a handle to the newly created ME
66 * object is saved here. This handle can be used later in LNetMEInsert(),
67 * LNetMEUnlink(), or LNetMDAttach() functions.
69 * \retval 0 On success.
70 * \retval -EINVAL If \a portal is invalid.
71 * \retval -ENOMEM If new ME object cannot be allocated.
74 LNetMEAttach(unsigned int portal,
75 lnet_process_id_t match_id,
76 __u64 match_bits, __u64 ignore_bits,
77 lnet_unlink_t unlink, lnet_ins_pos_t pos,
78 lnet_handle_me_t *handle)
80 struct lnet_match_table *mtable;
84 LASSERT (the_lnet.ln_init);
85 LASSERT (the_lnet.ln_refcount > 0);
87 if ((int)portal >= the_lnet.ln_nportals)
90 mtable = lnet_mt_of_attach(portal, match_id,
91 match_bits, ignore_bits, pos);
92 if (mtable == NULL) /* can't match portal type */
101 me->me_portal = portal;
102 me->me_match_id = match_id;
103 me->me_match_bits = match_bits;
104 me->me_ignore_bits = ignore_bits;
105 me->me_unlink = unlink;
108 lnet_res_lh_initialize(&the_lnet.ln_me_container, &me->me_lh);
109 head = lnet_mt_match_head(mtable, match_id, match_bits);
110 LASSERT (head != NULL);
112 if (pos == LNET_INS_AFTER)
113 cfs_list_add_tail(&me->me_list, head);
115 cfs_list_add(&me->me_list, head);
117 lnet_me2handle(handle, me);
125 * Create and a match entry and insert it before or after the ME pointed to by
126 * \a current_meh. The new ME is empty, i.e. not associated with a memory
127 * descriptor. LNetMDAttach() can be used to attach a MD to an empty ME.
129 * This function is identical to LNetMEAttach() except for the position
130 * where the new ME is inserted.
132 * \param current_meh A handle for a ME. The new ME will be inserted
133 * immediately before or immediately after this ME.
134 * \param match_id,match_bits,ignore_bits,unlink,pos,handle See the discussion
135 * for LNetMEAttach().
137 * \retval 0 On success.
138 * \retval -ENOMEM If new ME object cannot be allocated.
139 * \retval -ENOENT If \a current_meh does not point to a valid match entry.
142 LNetMEInsert(lnet_handle_me_t current_meh,
143 lnet_process_id_t match_id,
144 __u64 match_bits, __u64 ignore_bits,
145 lnet_unlink_t unlink, lnet_ins_pos_t pos,
146 lnet_handle_me_t *handle)
148 lnet_me_t *current_me;
152 LASSERT (the_lnet.ln_init);
153 LASSERT (the_lnet.ln_refcount > 0);
155 new_me = lnet_me_alloc();
161 current_me = lnet_handle2me(¤t_meh);
162 if (current_me == NULL) {
163 lnet_me_free_locked(new_me);
169 LASSERT (current_me->me_portal < the_lnet.ln_nportals);
171 ptl = the_lnet.ln_portals[current_me->me_portal];
172 if (lnet_ptl_is_unique(ptl)) {
173 /* nosense to insertion on unique portal */
174 lnet_me_free_locked(new_me);
179 new_me->me_portal = current_me->me_portal;
180 new_me->me_match_id = match_id;
181 new_me->me_match_bits = match_bits;
182 new_me->me_ignore_bits = ignore_bits;
183 new_me->me_unlink = unlink;
184 new_me->me_md = NULL;
186 lnet_res_lh_initialize(&the_lnet.ln_me_container, &new_me->me_lh);
188 if (pos == LNET_INS_AFTER)
189 cfs_list_add(&new_me->me_list, ¤t_me->me_list);
191 cfs_list_add_tail(&new_me->me_list, ¤t_me->me_list);
193 lnet_me2handle(handle, new_me);
201 * Unlink a match entry from its match list.
203 * This operation also releases any resources associated with the ME. If a
204 * memory descriptor is attached to the ME, then it will be unlinked as well
205 * and an unlink event will be generated. It is an error to use the ME handle
206 * after calling LNetMEUnlink().
208 * \param meh A handle for the ME to be unlinked.
210 * \retval 0 On success.
211 * \retval -ENOENT If \a meh does not point to a valid ME.
212 * \see LNetMDUnlink() for the discussion on delivering unlink event.
215 LNetMEUnlink(lnet_handle_me_t meh)
221 LASSERT (the_lnet.ln_init);
222 LASSERT (the_lnet.ln_refcount > 0);
226 me = lnet_handle2me(&meh);
235 md->md_refcount == 0) {
236 lnet_build_unlink_event(md, &ev);
237 lnet_eq_enqueue_event(md->md_eq, &ev);
246 /* call with LNET_LOCK please */
248 lnet_me_unlink(lnet_me_t *me)
250 cfs_list_del(&me->me_list);
252 if (me->me_md != NULL) {
253 lnet_libmd_t *md = me->me_md;
255 /* detach MD from portal of this ME */
256 lnet_ptl_detach_md(me, md);
260 lnet_res_lh_invalidate(&me->me_lh);
261 lnet_me_free_locked(me);
266 lib_me_dump(lnet_me_t *me)
268 CWARN("Match Entry %p ("LPX64")\n", me,
269 me->me_lh.lh_cookie);
271 CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
272 me->me_match_bits, me->me_ignore_bits);
274 CWARN("\tMD\t= %p\n", me->md);
275 CWARN("\tprev\t= %p\n",
276 cfs_list_entry(me->me_list.prev, lnet_me_t, me_list));
277 CWARN("\tnext\t= %p\n",
278 cfs_list_entry(me->me_list.next, lnet_me_t, me_list));