1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#define DEBUG_SUBSYSTEM S_LNET
38
39#include "../../include/linux/lnet/lib-lnet.h"
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71int
72LNetMEAttach(unsigned int portal,
73 lnet_process_id_t match_id,
74 __u64 match_bits, __u64 ignore_bits,
75 lnet_unlink_t unlink, lnet_ins_pos_t pos,
76 lnet_handle_me_t *handle)
77{
78 struct lnet_match_table *mtable;
79 struct lnet_me *me;
80 struct list_head *head;
81
82 LASSERT(the_lnet.ln_refcount > 0);
83
84 if ((int)portal >= the_lnet.ln_nportals)
85 return -EINVAL;
86
87 mtable = lnet_mt_of_attach(portal, match_id,
88 match_bits, ignore_bits, pos);
89 if (!mtable)
90 return -EPERM;
91
92 me = lnet_me_alloc();
93 if (!me)
94 return -ENOMEM;
95
96 lnet_res_lock(mtable->mt_cpt);
97
98 me->me_portal = portal;
99 me->me_match_id = match_id;
100 me->me_match_bits = match_bits;
101 me->me_ignore_bits = ignore_bits;
102 me->me_unlink = unlink;
103 me->me_md = NULL;
104
105 lnet_res_lh_initialize(the_lnet.ln_me_containers[mtable->mt_cpt],
106 &me->me_lh);
107 if (ignore_bits)
108 head = &mtable->mt_mhash[LNET_MT_HASH_IGNORE];
109 else
110 head = lnet_mt_match_head(mtable, match_id, match_bits);
111
112 me->me_pos = head - &mtable->mt_mhash[0];
113 if (pos == LNET_INS_AFTER || pos == LNET_INS_LOCAL)
114 list_add_tail(&me->me_list, head);
115 else
116 list_add(&me->me_list, head);
117
118 lnet_me2handle(handle, me);
119
120 lnet_res_unlock(mtable->mt_cpt);
121 return 0;
122}
123EXPORT_SYMBOL(LNetMEAttach);
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142int
143LNetMEInsert(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)
148{
149 struct lnet_me *current_me;
150 struct lnet_me *new_me;
151 struct lnet_portal *ptl;
152 int cpt;
153
154 LASSERT(the_lnet.ln_refcount > 0);
155
156 if (pos == LNET_INS_LOCAL)
157 return -EPERM;
158
159 new_me = lnet_me_alloc();
160 if (!new_me)
161 return -ENOMEM;
162
163 cpt = lnet_cpt_of_cookie(current_meh.cookie);
164
165 lnet_res_lock(cpt);
166
167 current_me = lnet_handle2me(¤t_meh);
168 if (!current_me) {
169 lnet_me_free(new_me);
170
171 lnet_res_unlock(cpt);
172 return -ENOENT;
173 }
174
175 LASSERT(current_me->me_portal < the_lnet.ln_nportals);
176
177 ptl = the_lnet.ln_portals[current_me->me_portal];
178 if (lnet_ptl_is_unique(ptl)) {
179
180 lnet_me_free(new_me);
181 lnet_res_unlock(cpt);
182 return -EPERM;
183 }
184
185 new_me->me_pos = current_me->me_pos;
186 new_me->me_portal = current_me->me_portal;
187 new_me->me_match_id = match_id;
188 new_me->me_match_bits = match_bits;
189 new_me->me_ignore_bits = ignore_bits;
190 new_me->me_unlink = unlink;
191 new_me->me_md = NULL;
192
193 lnet_res_lh_initialize(the_lnet.ln_me_containers[cpt], &new_me->me_lh);
194
195 if (pos == LNET_INS_AFTER)
196 list_add(&new_me->me_list, ¤t_me->me_list);
197 else
198 list_add_tail(&new_me->me_list, ¤t_me->me_list);
199
200 lnet_me2handle(handle, new_me);
201
202 lnet_res_unlock(cpt);
203
204 return 0;
205}
206EXPORT_SYMBOL(LNetMEInsert);
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222int
223LNetMEUnlink(lnet_handle_me_t meh)
224{
225 lnet_me_t *me;
226 lnet_libmd_t *md;
227 lnet_event_t ev;
228 int cpt;
229
230 LASSERT(the_lnet.ln_refcount > 0);
231
232 cpt = lnet_cpt_of_cookie(meh.cookie);
233 lnet_res_lock(cpt);
234
235 me = lnet_handle2me(&meh);
236 if (!me) {
237 lnet_res_unlock(cpt);
238 return -ENOENT;
239 }
240
241 md = me->me_md;
242 if (md) {
243 md->md_flags |= LNET_MD_FLAG_ABORTED;
244 if (md->md_eq && !md->md_refcount) {
245 lnet_build_unlink_event(md, &ev);
246 lnet_eq_enqueue_event(md->md_eq, &ev);
247 }
248 }
249
250 lnet_me_unlink(me);
251
252 lnet_res_unlock(cpt);
253 return 0;
254}
255EXPORT_SYMBOL(LNetMEUnlink);
256
257
258void
259lnet_me_unlink(lnet_me_t *me)
260{
261 list_del(&me->me_list);
262
263 if (me->me_md) {
264 lnet_libmd_t *md = me->me_md;
265
266
267 lnet_ptl_detach_md(me, md);
268 lnet_md_unlink(md);
269 }
270
271 lnet_res_lh_invalidate(&me->me_lh);
272 lnet_me_free(me);
273}
274
275#if 0
276static void
277lib_me_dump(lnet_me_t *me)
278{
279 CWARN("Match Entry %p (%#llx)\n", me,
280 me->me_lh.lh_cookie);
281
282 CWARN("\tMatch/Ignore\t= %016lx / %016lx\n",
283 me->me_match_bits, me->me_ignore_bits);
284
285 CWARN("\tMD\t= %p\n", me->md);
286 CWARN("\tprev\t= %p\n",
287 list_entry(me->me_list.prev, lnet_me_t, me_list));
288 CWARN("\tnext\t= %p\n",
289 list_entry(me->me_list.next, lnet_me_t, me_list));
290}
291#endif
292