1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * Match Entry management routines
41 #define DEBUG_SUBSYSTEM S_LNET
43 #include <lnet/lib-lnet.h>
46 lnet_me_match_portal(lnet_portal_t *ptl, lnet_process_id_t id,
47 __u64 match_bits, __u64 ignore_bits)
49 struct list_head *mhash = NULL;
52 LASSERT (!(lnet_portal_is_unique(ptl) &&
53 lnet_portal_is_wildcard(ptl)));
55 /* prefer to check w/o any lock */
56 unique = lnet_match_is_unique(id, match_bits, ignore_bits);
57 if (likely(lnet_portal_is_unique(ptl) ||
58 lnet_portal_is_wildcard(ptl)))
61 /* unset, new portal */
63 mhash = lnet_portal_mhash_alloc();
69 if (lnet_portal_is_unique(ptl) ||
70 lnet_portal_is_wildcard(ptl)) {
71 /* someone set it before me */
73 lnet_portal_mhash_free(mhash);
79 LASSERT (ptl->ptl_mhash == NULL);
81 ptl->ptl_mhash = mhash;
82 lnet_portal_setopt(ptl, LNET_PTL_MATCH_UNIQUE);
84 lnet_portal_setopt(ptl, LNET_PTL_MATCH_WILDCARD);
90 if (lnet_portal_is_unique(ptl) && !unique)
93 if (lnet_portal_is_wildcard(ptl) && unique)
100 LNetMEAttach(unsigned int portal,
101 lnet_process_id_t match_id,
102 __u64 match_bits, __u64 ignore_bits,
103 lnet_unlink_t unlink, lnet_ins_pos_t pos,
104 lnet_handle_me_t *handle)
108 struct list_head *head;
111 LASSERT (the_lnet.ln_init);
112 LASSERT (the_lnet.ln_refcount > 0);
114 if (portal >= the_lnet.ln_nportals)
117 ptl = &the_lnet.ln_portals[portal];
118 rc = lnet_me_match_portal(ptl, match_id, match_bits, ignore_bits);
122 me = lnet_me_alloc();
128 me->me_portal = portal;
129 me->me_match_id = match_id;
130 me->me_match_bits = match_bits;
131 me->me_ignore_bits = ignore_bits;
132 me->me_unlink = unlink;
135 lnet_initialise_handle (&me->me_lh, LNET_COOKIE_TYPE_ME);
137 head = lnet_portal_me_head(portal, match_id, match_bits);
138 LASSERT (head != NULL);
140 if (pos == LNET_INS_AFTER)
141 list_add_tail(&me->me_list, head);
143 list_add(&me->me_list, head);
145 lnet_me2handle(handle, me);
153 LNetMEInsert(lnet_handle_me_t current_meh,
154 lnet_process_id_t match_id,
155 __u64 match_bits, __u64 ignore_bits,
156 lnet_unlink_t unlink, lnet_ins_pos_t pos,
157 lnet_handle_me_t *handle)
159 lnet_me_t *current_me;
163 LASSERT (the_lnet.ln_init);
164 LASSERT (the_lnet.ln_refcount > 0);
166 new_me = lnet_me_alloc();
172 current_me = lnet_handle2me(¤t_meh);
173 if (current_me == NULL) {
174 lnet_me_free (new_me);
180 LASSERT (current_me->me_portal < the_lnet.ln_nportals);
182 ptl = &the_lnet.ln_portals[current_me->me_portal];
183 if (lnet_portal_is_unique(ptl)) {
184 /* nosense to insertion on unique portal */
185 lnet_me_free (new_me);
190 new_me->me_portal = current_me->me_portal;
191 new_me->me_match_id = match_id;
192 new_me->me_match_bits = match_bits;
193 new_me->me_ignore_bits = ignore_bits;
194 new_me->me_unlink = unlink;
195 new_me->me_md = NULL;
197 lnet_initialise_handle (&new_me->me_lh, LNET_COOKIE_TYPE_ME);
199 if (pos == LNET_INS_AFTER)
200 list_add(&new_me->me_list, ¤t_me->me_list);
202 list_add_tail(&new_me->me_list, ¤t_me->me_list);
204 lnet_me2handle(handle, new_me);
212 LNetMEUnlink(lnet_handle_me_t meh)
218 LASSERT (the_lnet.ln_init);
219 LASSERT (the_lnet.ln_refcount > 0);
223 me = lnet_handle2me(&meh);
232 md->md_refcount == 0) {
233 lnet_build_unlink_event(md, &ev);
234 lnet_enq_event_locked(md->md_eq, &ev);
243 /* call with LNET_LOCK please */
245 lnet_me_unlink(lnet_me_t *me)
247 list_del (&me->me_list);
249 if (me->me_md != NULL) {
250 me->me_md->md_me = NULL;
251 lnet_md_unlink(me->me_md);
254 lnet_invalidate_handle (&me->me_lh);
260 lib_me_dump(lnet_me_t *me)
262 CWARN("Match Entry %p ("LPX64")\n", me,
263 me->me_lh.lh_cookie);
265 CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
266 me->me_match_bits, me->me_ignore_bits);
268 CWARN("\tMD\t= %p\n", me->md);
269 CWARN("\tprev\t= %p\n",
270 list_entry(me->me_list.prev, lnet_me_t, me_list));
271 CWARN("\tnext\t= %p\n",
272 list_entry(me->me_list.next, lnet_me_t, me_list));