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)
85 LASSERT (the_lnet.ln_init);
86 LASSERT (the_lnet.ln_refcount > 0);
88 if ((int)portal >= the_lnet.ln_nportals)
91 ptl = the_lnet.ln_portals[portal];
92 rc = lnet_ptl_type_match(ptl, match_id, match_bits, ignore_bits);
102 me->me_portal = portal;
103 me->me_match_id = match_id;
104 me->me_match_bits = match_bits;
105 me->me_ignore_bits = ignore_bits;
106 me->me_unlink = unlink;
109 lnet_res_lh_initialize(&the_lnet.ln_me_container, &me->me_lh);
110 head = lnet_ptl_me_head(portal, match_id, match_bits);
111 LASSERT (head != NULL);
113 if (pos == LNET_INS_AFTER)
114 cfs_list_add_tail(&me->me_list, head);
116 cfs_list_add(&me->me_list, head);
118 lnet_me2handle(handle, me);
126 * Create and a match entry and insert it before or after the ME pointed to by
127 * \a current_meh. The new ME is empty, i.e. not associated with a memory
128 * descriptor. LNetMDAttach() can be used to attach a MD to an empty ME.
130 * This function is identical to LNetMEAttach() except for the position
131 * where the new ME is inserted.
133 * \param current_meh A handle for a ME. The new ME will be inserted
134 * immediately before or immediately after this ME.
135 * \param match_id,match_bits,ignore_bits,unlink,pos,handle See the discussion
136 * for LNetMEAttach().
138 * \retval 0 On success.
139 * \retval -ENOMEM If new ME object cannot be allocated.
140 * \retval -ENOENT If \a current_meh does not point to a valid match entry.
143 LNetMEInsert(lnet_handle_me_t current_meh,
144 lnet_process_id_t match_id,
145 __u64 match_bits, __u64 ignore_bits,
146 lnet_unlink_t unlink, lnet_ins_pos_t pos,
147 lnet_handle_me_t *handle)
149 lnet_me_t *current_me;
153 LASSERT (the_lnet.ln_init);
154 LASSERT (the_lnet.ln_refcount > 0);
156 new_me = lnet_me_alloc();
162 current_me = lnet_handle2me(¤t_meh);
163 if (current_me == NULL) {
164 lnet_me_free_locked(new_me);
170 LASSERT (current_me->me_portal < the_lnet.ln_nportals);
172 ptl = the_lnet.ln_portals[current_me->me_portal];
173 if (lnet_ptl_is_unique(ptl)) {
174 /* nosense to insertion on unique portal */
175 lnet_me_free_locked(new_me);
180 new_me->me_portal = current_me->me_portal;
181 new_me->me_match_id = match_id;
182 new_me->me_match_bits = match_bits;
183 new_me->me_ignore_bits = ignore_bits;
184 new_me->me_unlink = unlink;
185 new_me->me_md = NULL;
187 lnet_res_lh_initialize(&the_lnet.ln_me_container, &new_me->me_lh);
189 if (pos == LNET_INS_AFTER)
190 cfs_list_add(&new_me->me_list, ¤t_me->me_list);
192 cfs_list_add_tail(&new_me->me_list, ¤t_me->me_list);
194 lnet_me2handle(handle, new_me);
202 * Unlink a match entry from its match list.
204 * This operation also releases any resources associated with the ME. If a
205 * memory descriptor is attached to the ME, then it will be unlinked as well
206 * and an unlink event will be generated. It is an error to use the ME handle
207 * after calling LNetMEUnlink().
209 * \param meh A handle for the ME to be unlinked.
211 * \retval 0 On success.
212 * \retval -ENOENT If \a meh does not point to a valid ME.
213 * \see LNetMDUnlink() for the discussion on delivering unlink event.
216 LNetMEUnlink(lnet_handle_me_t meh)
222 LASSERT (the_lnet.ln_init);
223 LASSERT (the_lnet.ln_refcount > 0);
227 me = lnet_handle2me(&meh);
236 md->md_refcount == 0) {
237 lnet_build_unlink_event(md, &ev);
238 lnet_eq_enqueue_event(md->md_eq, &ev);
247 /* call with LNET_LOCK please */
249 lnet_me_unlink(lnet_me_t *me)
251 cfs_list_del (&me->me_list);
253 if (me->me_md != NULL) {
254 me->me_md->md_me = NULL;
255 lnet_md_unlink(me->me_md);
258 lnet_res_lh_invalidate(&me->me_lh);
259 lnet_me_free_locked(me);
264 lib_me_dump(lnet_me_t *me)
266 CWARN("Match Entry %p ("LPX64")\n", me,
267 me->me_lh.lh_cookie);
269 CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
270 me->me_match_bits, me->me_ignore_bits);
272 CWARN("\tMD\t= %p\n", me->md);
273 CWARN("\tprev\t= %p\n",
274 cfs_list_entry(me->me_list.prev, lnet_me_t, me_list));
275 CWARN("\tnext\t= %p\n",
276 cfs_list_entry(me->me_list.next, lnet_me_t, me_list));