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 */
99 lnet_res_lock(mtable->mt_cpt);
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_containers[mtable->mt_cpt],
110 head = lnet_mt_match_head(mtable, match_id, match_bits);
112 if (pos == LNET_INS_AFTER || pos == LNET_INS_LOCAL)
113 cfs_list_add_tail(&me->me_list, head);
115 cfs_list_add(&me->me_list, head);
117 lnet_me2handle(handle, me);
119 lnet_res_unlock(mtable->mt_cpt);
124 * Create and a match entry and insert it before or after the ME pointed to by
125 * \a current_meh. The new ME is empty, i.e. not associated with a memory
126 * descriptor. LNetMDAttach() can be used to attach a MD to an empty ME.
128 * This function is identical to LNetMEAttach() except for the position
129 * where the new ME is inserted.
131 * \param current_meh A handle for a ME. The new ME will be inserted
132 * immediately before or immediately after this ME.
133 * \param match_id,match_bits,ignore_bits,unlink,pos,handle See the discussion
134 * for LNetMEAttach().
136 * \retval 0 On success.
137 * \retval -ENOMEM If new ME object cannot be allocated.
138 * \retval -ENOENT If \a current_meh does not point to a valid match entry.
141 LNetMEInsert(lnet_handle_me_t current_meh,
142 lnet_process_id_t match_id,
143 __u64 match_bits, __u64 ignore_bits,
144 lnet_unlink_t unlink, lnet_ins_pos_t pos,
145 lnet_handle_me_t *handle)
147 struct lnet_me *current_me;
148 struct lnet_me *new_me;
149 struct lnet_portal *ptl;
152 LASSERT(the_lnet.ln_init);
153 LASSERT(the_lnet.ln_refcount > 0);
155 if (pos == LNET_INS_LOCAL)
158 new_me = lnet_me_alloc();
162 cpt = lnet_cpt_of_cookie(current_meh.cookie);
166 current_me = lnet_handle2me(¤t_meh);
167 if (current_me == NULL) {
168 lnet_me_free_locked(new_me);
170 lnet_res_unlock(cpt);
174 LASSERT(current_me->me_portal < the_lnet.ln_nportals);
176 ptl = the_lnet.ln_portals[current_me->me_portal];
177 if (lnet_ptl_is_unique(ptl)) {
178 /* nosense to insertion on unique portal */
179 lnet_me_free_locked(new_me);
180 lnet_res_unlock(cpt);
184 new_me->me_portal = current_me->me_portal;
185 new_me->me_match_id = match_id;
186 new_me->me_match_bits = match_bits;
187 new_me->me_ignore_bits = ignore_bits;
188 new_me->me_unlink = unlink;
189 new_me->me_md = NULL;
191 lnet_res_lh_initialize(the_lnet.ln_me_containers[cpt], &new_me->me_lh);
193 if (pos == LNET_INS_AFTER)
194 cfs_list_add(&new_me->me_list, ¤t_me->me_list);
196 cfs_list_add_tail(&new_me->me_list, ¤t_me->me_list);
198 lnet_me2handle(handle, new_me);
200 lnet_res_unlock(cpt);
206 * Unlink a match entry from its match list.
208 * This operation also releases any resources associated with the ME. If a
209 * memory descriptor is attached to the ME, then it will be unlinked as well
210 * and an unlink event will be generated. It is an error to use the ME handle
211 * after calling LNetMEUnlink().
213 * \param meh A handle for the ME to be unlinked.
215 * \retval 0 On success.
216 * \retval -ENOENT If \a meh does not point to a valid ME.
217 * \see LNetMDUnlink() for the discussion on delivering unlink event.
220 LNetMEUnlink(lnet_handle_me_t meh)
227 LASSERT(the_lnet.ln_init);
228 LASSERT(the_lnet.ln_refcount > 0);
230 cpt = lnet_cpt_of_cookie(meh.cookie);
233 me = lnet_handle2me(&meh);
235 lnet_res_unlock(cpt);
242 md->md_refcount == 0) {
243 lnet_build_unlink_event(md, &ev);
244 lnet_eq_enqueue_event(md->md_eq, &ev);
249 lnet_res_unlock(cpt);
253 /* call with lnet_res_lock please */
255 lnet_me_unlink(lnet_me_t *me)
257 cfs_list_del(&me->me_list);
259 if (me->me_md != NULL) {
260 lnet_libmd_t *md = me->me_md;
262 /* detach MD from portal of this ME */
263 lnet_ptl_detach_md(me, md);
267 lnet_res_lh_invalidate(&me->me_lh);
268 lnet_me_free_locked(me);
273 lib_me_dump(lnet_me_t *me)
275 CWARN("Match Entry %p ("LPX64")\n", me,
276 me->me_lh.lh_cookie);
278 CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
279 me->me_match_bits, me->me_ignore_bits);
281 CWARN("\tMD\t= %p\n", me->md);
282 CWARN("\tprev\t= %p\n",
283 cfs_list_entry(me->me_list.prev, lnet_me_t, me_list));
284 CWARN("\tnext\t= %p\n",
285 cfs_list_entry(me->me_list.next, lnet_me_t, me_list));