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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2013, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
33 * Match Entry management routines
36 #define DEBUG_SUBSYSTEM S_LNET
38 #include <lnet/lib-lnet.h>
41 * Create and attach a match entry to the match list of \a portal. The new
42 * ME is empty, i.e. not associated with a memory descriptor. LNetMDAttach()
43 * can be used to attach a MD to an empty ME.
45 * \param portal The portal table index where the ME should be attached.
46 * \param match_id Specifies the match criteria for the process ID of
47 * the requester. The constants LNET_PID_ANY and LNET_NID_ANY can be
48 * used to wildcard either of the identifiers in the struct lnet_process_id
50 * \param match_bits,ignore_bits Specify the match criteria to apply
51 * to the match bits in the incoming request. The ignore bits are used
52 * to mask out insignificant bits in the incoming match bits. The resulting
53 * bits are then compared to the ME's match bits to determine if the
54 * incoming request meets the match criteria.
55 * \param unlink Indicates whether the ME should be unlinked when the memory
56 * descriptor associated with it is unlinked (Note that the check for
57 * unlinking a ME only occurs when the memory descriptor is unlinked.).
58 * Valid values are LNET_RETAIN and LNET_UNLINK.
59 * \param pos Indicates whether the new ME should be prepended or
60 * appended to the match list. Allowed constants: LNET_INS_BEFORE,
63 * \retval A handle to the newly created ME is returned on success
64 * \retval ERR_PTR(-EINVAL) If \a portal is invalid.
65 * \retval ERR_PTR(-ENOMEM) If new ME object cannot be allocated.
68 LNetMEAttach(unsigned int portal,
69 struct lnet_processid *match_id,
70 __u64 match_bits, __u64 ignore_bits,
71 enum lnet_unlink unlink, enum lnet_ins_pos pos)
73 struct lnet_match_table *mtable;
75 struct list_head *head;
77 LASSERT(the_lnet.ln_refcount > 0);
79 if ((int)portal >= the_lnet.ln_nportals)
80 return ERR_PTR(-EINVAL);
82 mtable = lnet_mt_of_attach(portal, match_id,
83 match_bits, ignore_bits, pos);
84 if (mtable == NULL) /* can't match portal type */
85 return ERR_PTR(-EPERM);
87 me = kmem_cache_zalloc(lnet_mes_cachep, GFP_NOFS);
89 CDEBUG(D_MALLOC, "failed to allocate 'me'\n");
90 return ERR_PTR(-ENOMEM);
92 LIBCFS_ALLOC_POST(me, sizeof(*me), "slab-alloced");
94 lnet_res_lock(mtable->mt_cpt);
96 me->me_portal = portal;
97 me->me_match_id = *match_id;
98 me->me_match_bits = match_bits;
99 me->me_ignore_bits = ignore_bits;
100 me->me_unlink = unlink;
103 me->me_cpt = mtable->mt_cpt;
105 if (ignore_bits != 0)
106 head = &mtable->mt_mhash[LNET_MT_HASH_IGNORE];
108 head = lnet_mt_match_head(mtable, match_id, match_bits);
110 me->me_pos = head - &mtable->mt_mhash[0];
111 if (pos == LNET_INS_AFTER || pos == LNET_INS_LOCAL)
112 list_add_tail(&me->me_list, head);
114 list_add(&me->me_list, head);
116 lnet_res_unlock(mtable->mt_cpt);
119 EXPORT_SYMBOL(LNetMEAttach);
121 /* call with lnet_res_lock please */
123 lnet_me_unlink(struct lnet_me *me)
125 list_del(&me->me_list);
127 if (me->me_md != NULL) {
128 struct lnet_libmd *md = me->me_md;
130 /* detach MD from portal of this ME */
131 lnet_ptl_detach_md(me, md);
135 LIBCFS_FREE_PRE(me, sizeof(*me), "slab-freed");
136 kmem_cache_free(lnet_mes_cachep, me);
141 lib_me_dump(struct lnet_me *me)
143 CWARN("Match Entry %p (%#llx)\n", me,
144 me->me_lh.lh_cookie);
146 CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
147 me->me_match_bits, me->me_ignore_bits);
149 CWARN("\tMD\t= %p\n", me->md);
150 CWARN("\tprev\t= %p\n",
151 list_entry(me->me_list.prev, struct lnet_me, me_list));
152 CWARN("\tnext\t= %p\n",
153 list_entry(me->me_list.next, struct lnet_me, me_list));