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 lnet_me_match_portal(lnet_portal_t *ptl, lnet_process_id_t id,
45 __u64 match_bits, __u64 ignore_bits)
47 cfs_list_t *mhash = NULL;
50 LASSERT (!(lnet_portal_is_unique(ptl) &&
51 lnet_portal_is_wildcard(ptl)));
53 /* prefer to check w/o any lock */
54 unique = lnet_match_is_unique(id, match_bits, ignore_bits);
55 if (likely(lnet_portal_is_unique(ptl) ||
56 lnet_portal_is_wildcard(ptl)))
59 /* unset, new portal */
61 mhash = lnet_portal_mhash_alloc();
67 if (lnet_portal_is_unique(ptl) ||
68 lnet_portal_is_wildcard(ptl)) {
69 /* someone set it before me */
71 lnet_portal_mhash_free(mhash);
77 LASSERT (ptl->ptl_mhash == NULL);
79 ptl->ptl_mhash = mhash;
80 lnet_portal_setopt(ptl, LNET_PTL_MATCH_UNIQUE);
82 lnet_portal_setopt(ptl, LNET_PTL_MATCH_WILDCARD);
88 if (lnet_portal_is_unique(ptl) && !unique)
91 if (lnet_portal_is_wildcard(ptl) && unique)
98 * Create and attach a match entry to the match list of \a portal. The new
99 * ME is empty, i.e. not associated with a memory descriptor. LNetMDAttach()
100 * can be used to attach a MD to an empty ME.
102 * \param portal The portal table index where the ME should be attached.
103 * \param match_id Specifies the match criteria for the process ID of
104 * the requester. The constants LNET_PID_ANY and LNET_NID_ANY can be
105 * used to wildcard either of the identifiers in the lnet_process_id_t
107 * \param match_bits,ignore_bits Specify the match criteria to apply
108 * to the match bits in the incoming request. The ignore bits are used
109 * to mask out insignificant bits in the incoming match bits. The resulting
110 * bits are then compared to the ME's match bits to determine if the
111 * incoming request meets the match criteria.
112 * \param unlink Indicates whether the ME should be unlinked when the memory
113 * descriptor associated with it is unlinked (Note that the check for
114 * unlinking a ME only occurs when the memory descriptor is unlinked.).
115 * Valid values are LNET_RETAIN and LNET_UNLINK.
116 * \param pos Indicates whether the new ME should be prepended or
117 * appended to the match list. Allowed constants: LNET_INS_BEFORE,
119 * \param handle On successful returns, a handle to the newly created ME
120 * object is saved here. This handle can be used later in LNetMEInsert(),
121 * LNetMEUnlink(), or LNetMDAttach() functions.
123 * \retval 0 On success.
124 * \retval -EINVAL If \a portal is invalid.
125 * \retval -ENOMEM If new ME object cannot be allocated.
128 LNetMEAttach(unsigned int portal,
129 lnet_process_id_t match_id,
130 __u64 match_bits, __u64 ignore_bits,
131 lnet_unlink_t unlink, lnet_ins_pos_t pos,
132 lnet_handle_me_t *handle)
139 LASSERT (the_lnet.ln_init);
140 LASSERT (the_lnet.ln_refcount > 0);
142 if ((int)portal >= the_lnet.ln_nportals)
145 ptl = &the_lnet.ln_portals[portal];
146 rc = lnet_me_match_portal(ptl, match_id, match_bits, ignore_bits);
150 me = lnet_me_alloc();
156 me->me_portal = portal;
157 me->me_match_id = match_id;
158 me->me_match_bits = match_bits;
159 me->me_ignore_bits = ignore_bits;
160 me->me_unlink = unlink;
163 lnet_initialise_handle (&me->me_lh, LNET_COOKIE_TYPE_ME);
164 head = lnet_portal_me_head(portal, match_id, match_bits);
165 LASSERT (head != NULL);
167 if (pos == LNET_INS_AFTER)
168 cfs_list_add_tail(&me->me_list, head);
170 cfs_list_add(&me->me_list, head);
172 lnet_me2handle(handle, me);
180 * Create and a match entry and insert it before or after the ME pointed to by
181 * \a current_meh. The new ME is empty, i.e. not associated with a memory
182 * descriptor. LNetMDAttach() can be used to attach a MD to an empty ME.
184 * This function is identical to LNetMEAttach() except for the position
185 * where the new ME is inserted.
187 * \param current_meh A handle for a ME. The new ME will be inserted
188 * immediately before or immediately after this ME.
189 * \param match_id,match_bits,ignore_bits,unlink,pos,handle See the discussion
190 * for LNetMEAttach().
192 * \retval 0 On success.
193 * \retval -ENOMEM If new ME object cannot be allocated.
194 * \retval -ENOENT If \a current_meh does not point to a valid match entry.
197 LNetMEInsert(lnet_handle_me_t current_meh,
198 lnet_process_id_t match_id,
199 __u64 match_bits, __u64 ignore_bits,
200 lnet_unlink_t unlink, lnet_ins_pos_t pos,
201 lnet_handle_me_t *handle)
203 lnet_me_t *current_me;
207 LASSERT (the_lnet.ln_init);
208 LASSERT (the_lnet.ln_refcount > 0);
210 new_me = lnet_me_alloc();
216 current_me = lnet_handle2me(¤t_meh);
217 if (current_me == NULL) {
218 lnet_me_free (new_me);
224 LASSERT (current_me->me_portal < the_lnet.ln_nportals);
226 ptl = &the_lnet.ln_portals[current_me->me_portal];
227 if (lnet_portal_is_unique(ptl)) {
228 /* nosense to insertion on unique portal */
229 lnet_me_free (new_me);
234 new_me->me_portal = current_me->me_portal;
235 new_me->me_match_id = match_id;
236 new_me->me_match_bits = match_bits;
237 new_me->me_ignore_bits = ignore_bits;
238 new_me->me_unlink = unlink;
239 new_me->me_md = NULL;
241 lnet_initialise_handle (&new_me->me_lh, LNET_COOKIE_TYPE_ME);
243 if (pos == LNET_INS_AFTER)
244 cfs_list_add(&new_me->me_list, ¤t_me->me_list);
246 cfs_list_add_tail(&new_me->me_list, ¤t_me->me_list);
248 lnet_me2handle(handle, new_me);
256 * Unlink a match entry from its match list.
258 * This operation also releases any resources associated with the ME. If a
259 * memory descriptor is attached to the ME, then it will be unlinked as well
260 * and an unlink event will be generated. It is an error to use the ME handle
261 * after calling LNetMEUnlink().
263 * \param meh A handle for the ME to be unlinked.
265 * \retval 0 On success.
266 * \retval -ENOENT If \a meh does not point to a valid ME.
267 * \see LNetMDUnlink() for the discussion on delivering unlink event.
270 LNetMEUnlink(lnet_handle_me_t meh)
276 LASSERT (the_lnet.ln_init);
277 LASSERT (the_lnet.ln_refcount > 0);
281 me = lnet_handle2me(&meh);
290 md->md_refcount == 0) {
291 lnet_build_unlink_event(md, &ev);
292 lnet_enq_event_locked(md->md_eq, &ev);
301 /* call with LNET_LOCK please */
303 lnet_me_unlink(lnet_me_t *me)
305 cfs_list_del (&me->me_list);
307 if (me->me_md != NULL) {
308 me->me_md->md_me = NULL;
309 lnet_md_unlink(me->me_md);
312 lnet_invalidate_handle (&me->me_lh);
318 lib_me_dump(lnet_me_t *me)
320 CWARN("Match Entry %p ("LPX64")\n", me,
321 me->me_lh.lh_cookie);
323 CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
324 me->me_match_bits, me->me_ignore_bits);
326 CWARN("\tMD\t= %p\n", me->md);
327 CWARN("\tprev\t= %p\n",
328 cfs_list_entry(me->me_list.prev, lnet_me_t, me_list));
329 CWARN("\tnext\t= %p\n",
330 cfs_list_entry(me->me_list.next, lnet_me_t, me_list));