]>
Commit | Line | Data |
---|---|---|
d7e09d03 PT |
1 | /* |
2 | * GPL HEADER START | |
3 | * | |
4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
5 | * | |
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. | |
9 | * | |
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). | |
15 | * | |
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 | |
19 | * | |
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 | |
22 | * have any questions. | |
23 | * | |
24 | * GPL HEADER END | |
25 | */ | |
26 | /* | |
27 | * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | * | |
1dc563a6 | 30 | * Copyright (c) 2011, 2015, Intel Corporation. |
d7e09d03 PT |
31 | */ |
32 | /* | |
33 | * This file is part of Lustre, http://www.lustre.org/ | |
34 | * Lustre is a trademark of Sun Microsystems, Inc. | |
35 | * | |
36 | * lnet/lnet/lib-move.c | |
37 | * | |
38 | * Data movement routines | |
39 | */ | |
40 | ||
41 | #define DEBUG_SUBSYSTEM S_LNET | |
42 | ||
9fdaf8c0 | 43 | #include "../../include/linux/lnet/lib-lnet.h" |
d7e09d03 PT |
44 | |
45 | static int local_nid_dist_zero = 1; | |
8cc7b4b9 PT |
46 | module_param(local_nid_dist_zero, int, 0444); |
47 | MODULE_PARM_DESC(local_nid_dist_zero, "Reserved"); | |
d7e09d03 PT |
48 | |
49 | int | |
af66a6e2 | 50 | lnet_fail_nid(lnet_nid_t nid, unsigned int threshold) |
d7e09d03 | 51 | { |
7e7ab095 MS |
52 | lnet_test_peer_t *tp; |
53 | struct list_head *el; | |
54 | struct list_head *next; | |
55 | struct list_head cull; | |
d7e09d03 | 56 | |
af66a6e2 | 57 | LASSERT(the_lnet.ln_init); |
d7e09d03 PT |
58 | |
59 | /* NB: use lnet_net_lock(0) to serialize operations on test peers */ | |
60 | if (threshold != 0) { | |
61 | /* Adding a new entry */ | |
62 | LIBCFS_ALLOC(tp, sizeof(*tp)); | |
63 | if (tp == NULL) | |
64 | return -ENOMEM; | |
65 | ||
66 | tp->tp_nid = nid; | |
67 | tp->tp_threshold = threshold; | |
68 | ||
69 | lnet_net_lock(0); | |
70 | list_add_tail(&tp->tp_list, &the_lnet.ln_test_peers); | |
71 | lnet_net_unlock(0); | |
72 | return 0; | |
73 | } | |
74 | ||
75 | /* removing entries */ | |
76 | INIT_LIST_HEAD(&cull); | |
77 | ||
78 | lnet_net_lock(0); | |
79 | ||
af66a6e2 LN |
80 | list_for_each_safe(el, next, &the_lnet.ln_test_peers) { |
81 | tp = list_entry(el, lnet_test_peer_t, tp_list); | |
d7e09d03 PT |
82 | |
83 | if (tp->tp_threshold == 0 || /* needs culling anyway */ | |
84 | nid == LNET_NID_ANY || /* removing all entries */ | |
9b79ca85 | 85 | tp->tp_nid == nid) { /* matched this one */ |
af66a6e2 LN |
86 | list_del(&tp->tp_list); |
87 | list_add(&tp->tp_list, &cull); | |
d7e09d03 PT |
88 | } |
89 | } | |
90 | ||
91 | lnet_net_unlock(0); | |
92 | ||
af66a6e2 LN |
93 | while (!list_empty(&cull)) { |
94 | tp = list_entry(cull.next, lnet_test_peer_t, tp_list); | |
d7e09d03 | 95 | |
af66a6e2 LN |
96 | list_del(&tp->tp_list); |
97 | LIBCFS_FREE(tp, sizeof(*tp)); | |
d7e09d03 PT |
98 | } |
99 | return 0; | |
100 | } | |
101 | ||
102 | static int | |
af66a6e2 | 103 | fail_peer(lnet_nid_t nid, int outgoing) |
d7e09d03 PT |
104 | { |
105 | lnet_test_peer_t *tp; | |
7e7ab095 MS |
106 | struct list_head *el; |
107 | struct list_head *next; | |
108 | struct list_head cull; | |
109 | int fail = 0; | |
d7e09d03 | 110 | |
af66a6e2 | 111 | INIT_LIST_HEAD(&cull); |
d7e09d03 PT |
112 | |
113 | /* NB: use lnet_net_lock(0) to serialize operations on test peers */ | |
114 | lnet_net_lock(0); | |
115 | ||
af66a6e2 LN |
116 | list_for_each_safe(el, next, &the_lnet.ln_test_peers) { |
117 | tp = list_entry(el, lnet_test_peer_t, tp_list); | |
d7e09d03 PT |
118 | |
119 | if (tp->tp_threshold == 0) { | |
120 | /* zombie entry */ | |
121 | if (outgoing) { | |
4420cfd3 JS |
122 | /* |
123 | * only cull zombies on outgoing tests, | |
d7e09d03 | 124 | * since we may be at interrupt priority on |
4420cfd3 JS |
125 | * incoming messages. |
126 | */ | |
af66a6e2 LN |
127 | list_del(&tp->tp_list); |
128 | list_add(&tp->tp_list, &cull); | |
d7e09d03 PT |
129 | } |
130 | continue; | |
131 | } | |
132 | ||
133 | if (tp->tp_nid == LNET_NID_ANY || /* fail every peer */ | |
134 | nid == tp->tp_nid) { /* fail this peer */ | |
135 | fail = 1; | |
136 | ||
137 | if (tp->tp_threshold != LNET_MD_THRESH_INF) { | |
138 | tp->tp_threshold--; | |
139 | if (outgoing && | |
140 | tp->tp_threshold == 0) { | |
141 | /* see above */ | |
af66a6e2 LN |
142 | list_del(&tp->tp_list); |
143 | list_add(&tp->tp_list, &cull); | |
d7e09d03 PT |
144 | } |
145 | } | |
146 | break; | |
147 | } | |
148 | } | |
149 | ||
150 | lnet_net_unlock(0); | |
151 | ||
af66a6e2 LN |
152 | while (!list_empty(&cull)) { |
153 | tp = list_entry(cull.next, lnet_test_peer_t, tp_list); | |
154 | list_del(&tp->tp_list); | |
d7e09d03 | 155 | |
af66a6e2 | 156 | LIBCFS_FREE(tp, sizeof(*tp)); |
d7e09d03 PT |
157 | } |
158 | ||
2b5f2e44 | 159 | return fail; |
d7e09d03 PT |
160 | } |
161 | ||
162 | unsigned int | |
f351bad2 | 163 | lnet_iov_nob(unsigned int niov, struct kvec *iov) |
d7e09d03 PT |
164 | { |
165 | unsigned int nob = 0; | |
166 | ||
167 | while (niov-- > 0) | |
168 | nob += (iov++)->iov_len; | |
169 | ||
2b5f2e44 | 170 | return nob; |
d7e09d03 PT |
171 | } |
172 | EXPORT_SYMBOL(lnet_iov_nob); | |
173 | ||
174 | void | |
f351bad2 | 175 | lnet_copy_iov2iov(unsigned int ndiov, struct kvec *diov, unsigned int doffset, |
c314c319 JS |
176 | unsigned int nsiov, struct kvec *siov, unsigned int soffset, |
177 | unsigned int nob) | |
d7e09d03 PT |
178 | { |
179 | /* NB diov, siov are READ-ONLY */ | |
7e7ab095 | 180 | unsigned int this_nob; |
d7e09d03 PT |
181 | |
182 | if (nob == 0) | |
183 | return; | |
184 | ||
185 | /* skip complete frags before 'doffset' */ | |
af66a6e2 | 186 | LASSERT(ndiov > 0); |
d7e09d03 PT |
187 | while (doffset >= diov->iov_len) { |
188 | doffset -= diov->iov_len; | |
189 | diov++; | |
190 | ndiov--; | |
af66a6e2 | 191 | LASSERT(ndiov > 0); |
d7e09d03 PT |
192 | } |
193 | ||
194 | /* skip complete frags before 'soffset' */ | |
af66a6e2 | 195 | LASSERT(nsiov > 0); |
d7e09d03 PT |
196 | while (soffset >= siov->iov_len) { |
197 | soffset -= siov->iov_len; | |
198 | siov++; | |
199 | nsiov--; | |
af66a6e2 | 200 | LASSERT(nsiov > 0); |
d7e09d03 PT |
201 | } |
202 | ||
203 | do { | |
af66a6e2 LN |
204 | LASSERT(ndiov > 0); |
205 | LASSERT(nsiov > 0); | |
0c575417 | 206 | this_nob = min(diov->iov_len - doffset, |
d7e09d03 | 207 | siov->iov_len - soffset); |
0c575417 | 208 | this_nob = min(this_nob, nob); |
d7e09d03 | 209 | |
af66a6e2 | 210 | memcpy((char *)diov->iov_base + doffset, |
c314c319 | 211 | (char *)siov->iov_base + soffset, this_nob); |
d7e09d03 PT |
212 | nob -= this_nob; |
213 | ||
214 | if (diov->iov_len > doffset + this_nob) { | |
215 | doffset += this_nob; | |
216 | } else { | |
217 | diov++; | |
218 | ndiov--; | |
219 | doffset = 0; | |
220 | } | |
221 | ||
222 | if (siov->iov_len > soffset + this_nob) { | |
223 | soffset += this_nob; | |
224 | } else { | |
225 | siov++; | |
226 | nsiov--; | |
227 | soffset = 0; | |
228 | } | |
229 | } while (nob > 0); | |
230 | } | |
231 | EXPORT_SYMBOL(lnet_copy_iov2iov); | |
232 | ||
233 | int | |
f351bad2 | 234 | lnet_extract_iov(int dst_niov, struct kvec *dst, |
c314c319 JS |
235 | int src_niov, struct kvec *src, |
236 | unsigned int offset, unsigned int len) | |
d7e09d03 | 237 | { |
4420cfd3 JS |
238 | /* |
239 | * Initialise 'dst' to the subset of 'src' starting at 'offset', | |
d7e09d03 | 240 | * for exactly 'len' bytes, and return the number of entries. |
4420cfd3 JS |
241 | * NB not destructive to 'src' |
242 | */ | |
7e7ab095 MS |
243 | unsigned int frag_len; |
244 | unsigned int niov; | |
d7e09d03 PT |
245 | |
246 | if (len == 0) /* no data => */ | |
2b5f2e44 | 247 | return 0; /* no frags */ |
d7e09d03 | 248 | |
af66a6e2 | 249 | LASSERT(src_niov > 0); |
d7e09d03 PT |
250 | while (offset >= src->iov_len) { /* skip initial frags */ |
251 | offset -= src->iov_len; | |
252 | src_niov--; | |
253 | src++; | |
af66a6e2 | 254 | LASSERT(src_niov > 0); |
d7e09d03 PT |
255 | } |
256 | ||
257 | niov = 1; | |
258 | for (;;) { | |
af66a6e2 LN |
259 | LASSERT(src_niov > 0); |
260 | LASSERT((int)niov <= dst_niov); | |
d7e09d03 PT |
261 | |
262 | frag_len = src->iov_len - offset; | |
263 | dst->iov_base = ((char *)src->iov_base) + offset; | |
264 | ||
265 | if (len <= frag_len) { | |
266 | dst->iov_len = len; | |
2b5f2e44 | 267 | return niov; |
d7e09d03 PT |
268 | } |
269 | ||
270 | dst->iov_len = frag_len; | |
271 | ||
272 | len -= frag_len; | |
273 | dst++; | |
274 | src++; | |
275 | niov++; | |
276 | src_niov--; | |
277 | offset = 0; | |
278 | } | |
279 | } | |
280 | EXPORT_SYMBOL(lnet_extract_iov); | |
281 | ||
d7e09d03 | 282 | unsigned int |
af66a6e2 | 283 | lnet_kiov_nob(unsigned int niov, lnet_kiov_t *kiov) |
d7e09d03 | 284 | { |
7e7ab095 | 285 | unsigned int nob = 0; |
d7e09d03 PT |
286 | |
287 | while (niov-- > 0) | |
288 | nob += (kiov++)->kiov_len; | |
289 | ||
2b5f2e44 | 290 | return nob; |
d7e09d03 PT |
291 | } |
292 | EXPORT_SYMBOL(lnet_kiov_nob); | |
293 | ||
294 | void | |
af66a6e2 | 295 | lnet_copy_kiov2kiov(unsigned int ndiov, lnet_kiov_t *diov, unsigned int doffset, |
ae4003f0 LN |
296 | unsigned int nsiov, lnet_kiov_t *siov, unsigned int soffset, |
297 | unsigned int nob) | |
d7e09d03 PT |
298 | { |
299 | /* NB diov, siov are READ-ONLY */ | |
7e7ab095 MS |
300 | unsigned int this_nob; |
301 | char *daddr = NULL; | |
302 | char *saddr = NULL; | |
d7e09d03 PT |
303 | |
304 | if (nob == 0) | |
305 | return; | |
306 | ||
af66a6e2 | 307 | LASSERT(!in_interrupt()); |
d7e09d03 | 308 | |
af66a6e2 | 309 | LASSERT(ndiov > 0); |
d7e09d03 PT |
310 | while (doffset >= diov->kiov_len) { |
311 | doffset -= diov->kiov_len; | |
312 | diov++; | |
313 | ndiov--; | |
af66a6e2 | 314 | LASSERT(ndiov > 0); |
d7e09d03 PT |
315 | } |
316 | ||
af66a6e2 | 317 | LASSERT(nsiov > 0); |
d7e09d03 PT |
318 | while (soffset >= siov->kiov_len) { |
319 | soffset -= siov->kiov_len; | |
320 | siov++; | |
321 | nsiov--; | |
af66a6e2 | 322 | LASSERT(nsiov > 0); |
d7e09d03 PT |
323 | } |
324 | ||
325 | do { | |
af66a6e2 LN |
326 | LASSERT(ndiov > 0); |
327 | LASSERT(nsiov > 0); | |
0c575417 | 328 | this_nob = min(diov->kiov_len - doffset, |
d7e09d03 | 329 | siov->kiov_len - soffset); |
0c575417 | 330 | this_nob = min(this_nob, nob); |
d7e09d03 PT |
331 | |
332 | if (daddr == NULL) | |
333 | daddr = ((char *)kmap(diov->kiov_page)) + | |
334 | diov->kiov_offset + doffset; | |
335 | if (saddr == NULL) | |
336 | saddr = ((char *)kmap(siov->kiov_page)) + | |
337 | siov->kiov_offset + soffset; | |
338 | ||
4420cfd3 JS |
339 | /* |
340 | * Vanishing risk of kmap deadlock when mapping 2 pages. | |
d7e09d03 | 341 | * However in practice at least one of the kiovs will be mapped |
4420cfd3 JS |
342 | * kernel pages and the map/unmap will be NOOPs |
343 | */ | |
af66a6e2 | 344 | memcpy(daddr, saddr, this_nob); |
d7e09d03 PT |
345 | nob -= this_nob; |
346 | ||
347 | if (diov->kiov_len > doffset + this_nob) { | |
348 | daddr += this_nob; | |
349 | doffset += this_nob; | |
350 | } else { | |
351 | kunmap(diov->kiov_page); | |
352 | daddr = NULL; | |
353 | diov++; | |
354 | ndiov--; | |
355 | doffset = 0; | |
356 | } | |
357 | ||
358 | if (siov->kiov_len > soffset + this_nob) { | |
359 | saddr += this_nob; | |
360 | soffset += this_nob; | |
361 | } else { | |
362 | kunmap(siov->kiov_page); | |
363 | saddr = NULL; | |
364 | siov++; | |
365 | nsiov--; | |
366 | soffset = 0; | |
367 | } | |
368 | } while (nob > 0); | |
369 | ||
370 | if (daddr != NULL) | |
371 | kunmap(diov->kiov_page); | |
372 | if (saddr != NULL) | |
373 | kunmap(siov->kiov_page); | |
374 | } | |
375 | EXPORT_SYMBOL(lnet_copy_kiov2kiov); | |
376 | ||
377 | void | |
f351bad2 | 378 | lnet_copy_kiov2iov(unsigned int niov, struct kvec *iov, unsigned int iovoffset, |
ae4003f0 LN |
379 | unsigned int nkiov, lnet_kiov_t *kiov, |
380 | unsigned int kiovoffset, unsigned int nob) | |
d7e09d03 PT |
381 | { |
382 | /* NB iov, kiov are READ-ONLY */ | |
7e7ab095 MS |
383 | unsigned int this_nob; |
384 | char *addr = NULL; | |
d7e09d03 PT |
385 | |
386 | if (nob == 0) | |
387 | return; | |
388 | ||
af66a6e2 | 389 | LASSERT(!in_interrupt()); |
d7e09d03 | 390 | |
af66a6e2 | 391 | LASSERT(niov > 0); |
d7e09d03 PT |
392 | while (iovoffset >= iov->iov_len) { |
393 | iovoffset -= iov->iov_len; | |
394 | iov++; | |
395 | niov--; | |
af66a6e2 | 396 | LASSERT(niov > 0); |
d7e09d03 PT |
397 | } |
398 | ||
af66a6e2 | 399 | LASSERT(nkiov > 0); |
d7e09d03 PT |
400 | while (kiovoffset >= kiov->kiov_len) { |
401 | kiovoffset -= kiov->kiov_len; | |
402 | kiov++; | |
403 | nkiov--; | |
af66a6e2 | 404 | LASSERT(nkiov > 0); |
d7e09d03 PT |
405 | } |
406 | ||
407 | do { | |
af66a6e2 LN |
408 | LASSERT(niov > 0); |
409 | LASSERT(nkiov > 0); | |
fce6ad22 JM |
410 | this_nob = min(iov->iov_len - iovoffset, |
411 | (__kernel_size_t) kiov->kiov_len - kiovoffset); | |
0c575417 | 412 | this_nob = min(this_nob, nob); |
d7e09d03 PT |
413 | |
414 | if (addr == NULL) | |
415 | addr = ((char *)kmap(kiov->kiov_page)) + | |
416 | kiov->kiov_offset + kiovoffset; | |
417 | ||
af66a6e2 | 418 | memcpy((char *)iov->iov_base + iovoffset, addr, this_nob); |
d7e09d03 PT |
419 | nob -= this_nob; |
420 | ||
421 | if (iov->iov_len > iovoffset + this_nob) { | |
422 | iovoffset += this_nob; | |
423 | } else { | |
424 | iov++; | |
425 | niov--; | |
426 | iovoffset = 0; | |
427 | } | |
428 | ||
429 | if (kiov->kiov_len > kiovoffset + this_nob) { | |
430 | addr += this_nob; | |
431 | kiovoffset += this_nob; | |
432 | } else { | |
433 | kunmap(kiov->kiov_page); | |
434 | addr = NULL; | |
435 | kiov++; | |
436 | nkiov--; | |
437 | kiovoffset = 0; | |
438 | } | |
439 | ||
440 | } while (nob > 0); | |
441 | ||
442 | if (addr != NULL) | |
443 | kunmap(kiov->kiov_page); | |
444 | } | |
445 | EXPORT_SYMBOL(lnet_copy_kiov2iov); | |
446 | ||
447 | void | |
ae4003f0 LN |
448 | lnet_copy_iov2kiov(unsigned int nkiov, lnet_kiov_t *kiov, |
449 | unsigned int kiovoffset, unsigned int niov, | |
f351bad2 | 450 | struct kvec *iov, unsigned int iovoffset, |
ae4003f0 | 451 | unsigned int nob) |
d7e09d03 PT |
452 | { |
453 | /* NB kiov, iov are READ-ONLY */ | |
7e7ab095 MS |
454 | unsigned int this_nob; |
455 | char *addr = NULL; | |
d7e09d03 PT |
456 | |
457 | if (nob == 0) | |
458 | return; | |
459 | ||
af66a6e2 | 460 | LASSERT(!in_interrupt()); |
d7e09d03 | 461 | |
af66a6e2 | 462 | LASSERT(nkiov > 0); |
d7e09d03 PT |
463 | while (kiovoffset >= kiov->kiov_len) { |
464 | kiovoffset -= kiov->kiov_len; | |
465 | kiov++; | |
466 | nkiov--; | |
af66a6e2 | 467 | LASSERT(nkiov > 0); |
d7e09d03 PT |
468 | } |
469 | ||
af66a6e2 | 470 | LASSERT(niov > 0); |
d7e09d03 PT |
471 | while (iovoffset >= iov->iov_len) { |
472 | iovoffset -= iov->iov_len; | |
473 | iov++; | |
474 | niov--; | |
af66a6e2 | 475 | LASSERT(niov > 0); |
d7e09d03 PT |
476 | } |
477 | ||
478 | do { | |
af66a6e2 LN |
479 | LASSERT(nkiov > 0); |
480 | LASSERT(niov > 0); | |
fce6ad22 | 481 | this_nob = min((__kernel_size_t) kiov->kiov_len - kiovoffset, |
d7e09d03 | 482 | iov->iov_len - iovoffset); |
0c575417 | 483 | this_nob = min(this_nob, nob); |
d7e09d03 PT |
484 | |
485 | if (addr == NULL) | |
486 | addr = ((char *)kmap(kiov->kiov_page)) + | |
487 | kiov->kiov_offset + kiovoffset; | |
488 | ||
af66a6e2 | 489 | memcpy(addr, (char *)iov->iov_base + iovoffset, this_nob); |
d7e09d03 PT |
490 | nob -= this_nob; |
491 | ||
492 | if (kiov->kiov_len > kiovoffset + this_nob) { | |
493 | addr += this_nob; | |
494 | kiovoffset += this_nob; | |
495 | } else { | |
496 | kunmap(kiov->kiov_page); | |
497 | addr = NULL; | |
498 | kiov++; | |
499 | nkiov--; | |
500 | kiovoffset = 0; | |
501 | } | |
502 | ||
503 | if (iov->iov_len > iovoffset + this_nob) { | |
504 | iovoffset += this_nob; | |
505 | } else { | |
506 | iov++; | |
507 | niov--; | |
508 | iovoffset = 0; | |
509 | } | |
510 | } while (nob > 0); | |
511 | ||
512 | if (addr != NULL) | |
513 | kunmap(kiov->kiov_page); | |
514 | } | |
515 | EXPORT_SYMBOL(lnet_copy_iov2kiov); | |
516 | ||
517 | int | |
af66a6e2 | 518 | lnet_extract_kiov(int dst_niov, lnet_kiov_t *dst, |
c314c319 JS |
519 | int src_niov, lnet_kiov_t *src, |
520 | unsigned int offset, unsigned int len) | |
d7e09d03 | 521 | { |
4420cfd3 JS |
522 | /* |
523 | * Initialise 'dst' to the subset of 'src' starting at 'offset', | |
d7e09d03 | 524 | * for exactly 'len' bytes, and return the number of entries. |
4420cfd3 JS |
525 | * NB not destructive to 'src' |
526 | */ | |
7e7ab095 MS |
527 | unsigned int frag_len; |
528 | unsigned int niov; | |
d7e09d03 PT |
529 | |
530 | if (len == 0) /* no data => */ | |
2b5f2e44 | 531 | return 0; /* no frags */ |
d7e09d03 | 532 | |
af66a6e2 | 533 | LASSERT(src_niov > 0); |
d7e09d03 PT |
534 | while (offset >= src->kiov_len) { /* skip initial frags */ |
535 | offset -= src->kiov_len; | |
536 | src_niov--; | |
537 | src++; | |
af66a6e2 | 538 | LASSERT(src_niov > 0); |
d7e09d03 PT |
539 | } |
540 | ||
541 | niov = 1; | |
542 | for (;;) { | |
af66a6e2 LN |
543 | LASSERT(src_niov > 0); |
544 | LASSERT((int)niov <= dst_niov); | |
d7e09d03 PT |
545 | |
546 | frag_len = src->kiov_len - offset; | |
547 | dst->kiov_page = src->kiov_page; | |
548 | dst->kiov_offset = src->kiov_offset + offset; | |
549 | ||
550 | if (len <= frag_len) { | |
551 | dst->kiov_len = len; | |
ae4003f0 | 552 | LASSERT(dst->kiov_offset + dst->kiov_len |
c314c319 | 553 | <= PAGE_CACHE_SIZE); |
2b5f2e44 | 554 | return niov; |
d7e09d03 PT |
555 | } |
556 | ||
557 | dst->kiov_len = frag_len; | |
af66a6e2 | 558 | LASSERT(dst->kiov_offset + dst->kiov_len <= PAGE_CACHE_SIZE); |
d7e09d03 PT |
559 | |
560 | len -= frag_len; | |
561 | dst++; | |
562 | src++; | |
563 | niov++; | |
564 | src_niov--; | |
565 | offset = 0; | |
566 | } | |
567 | } | |
568 | EXPORT_SYMBOL(lnet_extract_kiov); | |
569 | ||
f526b20a | 570 | static void |
d7e09d03 PT |
571 | lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed, |
572 | unsigned int offset, unsigned int mlen, unsigned int rlen) | |
573 | { | |
7e7ab095 | 574 | unsigned int niov = 0; |
f351bad2 | 575 | struct kvec *iov = NULL; |
7e7ab095 MS |
576 | lnet_kiov_t *kiov = NULL; |
577 | int rc; | |
d7e09d03 | 578 | |
af66a6e2 LN |
579 | LASSERT(!in_interrupt()); |
580 | LASSERT(mlen == 0 || msg != NULL); | |
d7e09d03 PT |
581 | |
582 | if (msg != NULL) { | |
583 | LASSERT(msg->msg_receiving); | |
584 | LASSERT(!msg->msg_sending); | |
585 | LASSERT(rlen == msg->msg_len); | |
586 | LASSERT(mlen <= msg->msg_len); | |
587 | LASSERT(msg->msg_offset == offset); | |
588 | LASSERT(msg->msg_wanted == mlen); | |
589 | ||
590 | msg->msg_receiving = 0; | |
591 | ||
592 | if (mlen != 0) { | |
593 | niov = msg->msg_niov; | |
594 | iov = msg->msg_iov; | |
595 | kiov = msg->msg_kiov; | |
596 | ||
af66a6e2 LN |
597 | LASSERT(niov > 0); |
598 | LASSERT((iov == NULL) != (kiov == NULL)); | |
d7e09d03 PT |
599 | } |
600 | } | |
601 | ||
602 | rc = (ni->ni_lnd->lnd_recv)(ni, private, msg, delayed, | |
603 | niov, iov, kiov, offset, mlen, rlen); | |
604 | if (rc < 0) | |
605 | lnet_finalize(ni, msg, rc); | |
606 | } | |
607 | ||
f526b20a | 608 | static void |
d7e09d03 PT |
609 | lnet_setpayloadbuffer(lnet_msg_t *msg) |
610 | { | |
611 | lnet_libmd_t *md = msg->msg_md; | |
612 | ||
af66a6e2 LN |
613 | LASSERT(msg->msg_len > 0); |
614 | LASSERT(!msg->msg_routing); | |
615 | LASSERT(md != NULL); | |
616 | LASSERT(msg->msg_niov == 0); | |
617 | LASSERT(msg->msg_iov == NULL); | |
618 | LASSERT(msg->msg_kiov == NULL); | |
d7e09d03 PT |
619 | |
620 | msg->msg_niov = md->md_niov; | |
621 | if ((md->md_options & LNET_MD_KIOV) != 0) | |
622 | msg->msg_kiov = md->md_iov.kiov; | |
623 | else | |
624 | msg->msg_iov = md->md_iov.iov; | |
625 | } | |
626 | ||
627 | void | |
628 | lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target, | |
629 | unsigned int offset, unsigned int len) | |
630 | { | |
631 | msg->msg_type = type; | |
632 | msg->msg_target = target; | |
633 | msg->msg_len = len; | |
634 | msg->msg_offset = offset; | |
635 | ||
636 | if (len != 0) | |
637 | lnet_setpayloadbuffer(msg); | |
638 | ||
af66a6e2 | 639 | memset(&msg->msg_hdr, 0, sizeof(msg->msg_hdr)); |
d7e09d03 PT |
640 | msg->msg_hdr.type = cpu_to_le32(type); |
641 | msg->msg_hdr.dest_nid = cpu_to_le64(target.nid); | |
642 | msg->msg_hdr.dest_pid = cpu_to_le32(target.pid); | |
643 | /* src_nid will be set later */ | |
644 | msg->msg_hdr.src_pid = cpu_to_le32(the_lnet.ln_pid); | |
645 | msg->msg_hdr.payload_length = cpu_to_le32(len); | |
646 | } | |
647 | ||
f526b20a | 648 | static void |
d7e09d03 PT |
649 | lnet_ni_send(lnet_ni_t *ni, lnet_msg_t *msg) |
650 | { | |
7e7ab095 MS |
651 | void *priv = msg->msg_private; |
652 | int rc; | |
d7e09d03 | 653 | |
af66a6e2 LN |
654 | LASSERT(!in_interrupt()); |
655 | LASSERT(LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND || | |
c314c319 | 656 | (msg->msg_txcredit && msg->msg_peertxcredit)); |
d7e09d03 PT |
657 | |
658 | rc = (ni->ni_lnd->lnd_send)(ni, priv, msg); | |
659 | if (rc < 0) | |
660 | lnet_finalize(ni, msg, rc); | |
661 | } | |
662 | ||
f526b20a | 663 | static int |
d7e09d03 PT |
664 | lnet_ni_eager_recv(lnet_ni_t *ni, lnet_msg_t *msg) |
665 | { | |
7e7ab095 | 666 | int rc; |
d7e09d03 PT |
667 | |
668 | LASSERT(!msg->msg_sending); | |
669 | LASSERT(msg->msg_receiving); | |
670 | LASSERT(!msg->msg_rx_ready_delay); | |
671 | LASSERT(ni->ni_lnd->lnd_eager_recv != NULL); | |
672 | ||
673 | msg->msg_rx_ready_delay = 1; | |
674 | rc = (ni->ni_lnd->lnd_eager_recv)(ni, msg->msg_private, msg, | |
675 | &msg->msg_private); | |
676 | if (rc != 0) { | |
2d00bd17 | 677 | CERROR("recv from %s / send to %s aborted: eager_recv failed %d\n", |
d7e09d03 PT |
678 | libcfs_nid2str(msg->msg_rxpeer->lp_nid), |
679 | libcfs_id2str(msg->msg_target), rc); | |
680 | LASSERT(rc < 0); /* required by my callers */ | |
681 | } | |
682 | ||
683 | return rc; | |
684 | } | |
685 | ||
686 | /* NB: caller shall hold a ref on 'lp' as I'd drop lnet_net_lock */ | |
f526b20a | 687 | static void |
d7e09d03 PT |
688 | lnet_ni_query_locked(lnet_ni_t *ni, lnet_peer_t *lp) |
689 | { | |
a649ad1d | 690 | unsigned long last_alive = 0; |
d7e09d03 PT |
691 | |
692 | LASSERT(lnet_peer_aliveness_enabled(lp)); | |
693 | LASSERT(ni->ni_lnd->lnd_query != NULL); | |
694 | ||
695 | lnet_net_unlock(lp->lp_cpt); | |
696 | (ni->ni_lnd->lnd_query)(ni, lp->lp_nid, &last_alive); | |
697 | lnet_net_lock(lp->lp_cpt); | |
698 | ||
699 | lp->lp_last_query = cfs_time_current(); | |
700 | ||
701 | if (last_alive != 0) /* NI has updated timestamp */ | |
702 | lp->lp_last_alive = last_alive; | |
703 | } | |
704 | ||
705 | /* NB: always called with lnet_net_lock held */ | |
706 | static inline int | |
a649ad1d | 707 | lnet_peer_is_alive(lnet_peer_t *lp, unsigned long now) |
d7e09d03 | 708 | { |
7e7ab095 | 709 | int alive; |
a649ad1d | 710 | unsigned long deadline; |
d7e09d03 | 711 | |
af66a6e2 | 712 | LASSERT(lnet_peer_aliveness_enabled(lp)); |
d7e09d03 PT |
713 | |
714 | /* Trust lnet_notify() if it has more recent aliveness news, but | |
715 | * ignore the initial assumed death (see lnet_peers_start_down()). | |
716 | */ | |
717 | if (!lp->lp_alive && lp->lp_alive_count > 0 && | |
718 | cfs_time_aftereq(lp->lp_timestamp, lp->lp_last_alive)) | |
719 | return 0; | |
720 | ||
721 | deadline = cfs_time_add(lp->lp_last_alive, | |
722 | cfs_time_seconds(lp->lp_ni->ni_peertimeout)); | |
723 | alive = cfs_time_after(deadline, now); | |
724 | ||
725 | /* Update obsolete lp_alive except for routers assumed to be dead | |
726 | * initially, because router checker would update aliveness in this | |
727 | * case, and moreover lp_last_alive at peer creation is assumed. | |
728 | */ | |
729 | if (alive && !lp->lp_alive && | |
730 | !(lnet_isrouter(lp) && lp->lp_alive_count == 0)) | |
731 | lnet_notify_locked(lp, 0, 1, lp->lp_last_alive); | |
732 | ||
733 | return alive; | |
734 | } | |
735 | ||
4420cfd3 JS |
736 | /* |
737 | * NB: returns 1 when alive, 0 when dead, negative when error; | |
738 | * may drop the lnet_net_lock | |
739 | */ | |
f526b20a | 740 | static int |
af66a6e2 | 741 | lnet_peer_alive_locked(lnet_peer_t *lp) |
d7e09d03 | 742 | { |
a649ad1d | 743 | unsigned long now = cfs_time_current(); |
d7e09d03 PT |
744 | |
745 | if (!lnet_peer_aliveness_enabled(lp)) | |
746 | return -ENODEV; | |
747 | ||
748 | if (lnet_peer_is_alive(lp, now)) | |
749 | return 1; | |
750 | ||
4420cfd3 JS |
751 | /* |
752 | * Peer appears dead, but we should avoid frequent NI queries (at | |
753 | * most once per lnet_queryinterval seconds). | |
754 | */ | |
d7e09d03 PT |
755 | if (lp->lp_last_query != 0) { |
756 | static const int lnet_queryinterval = 1; | |
757 | ||
a649ad1d | 758 | unsigned long next_query = |
d7e09d03 PT |
759 | cfs_time_add(lp->lp_last_query, |
760 | cfs_time_seconds(lnet_queryinterval)); | |
761 | ||
699503bc | 762 | if (time_before(now, next_query)) { |
d7e09d03 | 763 | if (lp->lp_alive) |
2d00bd17 | 764 | CWARN("Unexpected aliveness of peer %s: %d < %d (%d/%d)\n", |
d7e09d03 PT |
765 | libcfs_nid2str(lp->lp_nid), |
766 | (int)now, (int)next_query, | |
767 | lnet_queryinterval, | |
768 | lp->lp_ni->ni_peertimeout); | |
769 | return 0; | |
770 | } | |
771 | } | |
772 | ||
773 | /* query NI for latest aliveness news */ | |
774 | lnet_ni_query_locked(lp->lp_ni, lp); | |
775 | ||
776 | if (lnet_peer_is_alive(lp, now)) | |
777 | return 1; | |
778 | ||
779 | lnet_notify_locked(lp, 0, 0, lp->lp_last_alive); | |
780 | return 0; | |
781 | } | |
782 | ||
dee2857e IH |
783 | /** |
784 | * \param msg The message to be sent. | |
785 | * \param do_send True if lnet_ni_send() should be called in this function. | |
786 | * lnet_send() is going to lnet_net_unlock immediately after this, so | |
787 | * it sets do_send FALSE and I don't do the unlock/send/lock bit. | |
788 | * | |
789 | * \retval 0 If \a msg sent or OK to send. | |
790 | * \retval EAGAIN If \a msg blocked for credit. | |
791 | * \retval EHOSTUNREACH If the next hop of the message appears dead. | |
792 | * \retval ECANCELED If the MD of the message has been unlinked. | |
793 | */ | |
794 | static int | |
d7e09d03 PT |
795 | lnet_post_send_locked(lnet_msg_t *msg, int do_send) |
796 | { | |
7e7ab095 MS |
797 | lnet_peer_t *lp = msg->msg_txpeer; |
798 | lnet_ni_t *ni = lp->lp_ni; | |
799 | int cpt = msg->msg_tx_cpt; | |
800 | struct lnet_tx_queue *tq = ni->ni_tx_queues[cpt]; | |
d7e09d03 PT |
801 | |
802 | /* non-lnet_send() callers have checked before */ | |
803 | LASSERT(!do_send || msg->msg_tx_delayed); | |
804 | LASSERT(!msg->msg_receiving); | |
805 | LASSERT(msg->msg_tx_committed); | |
806 | ||
d7e09d03 PT |
807 | /* NB 'lp' is always the next hop */ |
808 | if ((msg->msg_target.pid & LNET_PID_USERFLAG) == 0 && | |
809 | lnet_peer_alive_locked(lp) == 0) { | |
810 | the_lnet.ln_counters[cpt]->drop_count++; | |
811 | the_lnet.ln_counters[cpt]->drop_length += msg->msg_len; | |
812 | lnet_net_unlock(cpt); | |
813 | ||
814 | CNETERR("Dropping message for %s: peer not alive\n", | |
815 | libcfs_id2str(msg->msg_target)); | |
816 | if (do_send) | |
817 | lnet_finalize(ni, msg, -EHOSTUNREACH); | |
818 | ||
819 | lnet_net_lock(cpt); | |
820 | return EHOSTUNREACH; | |
821 | } | |
822 | ||
dee2857e IH |
823 | if (msg->msg_md != NULL && |
824 | (msg->msg_md->md_flags & LNET_MD_FLAG_ABORTED) != 0) { | |
825 | lnet_net_unlock(cpt); | |
826 | ||
2d00bd17 | 827 | CNETERR("Aborting message for %s: LNetM[DE]Unlink() already called on the MD/ME.\n", |
dee2857e IH |
828 | libcfs_id2str(msg->msg_target)); |
829 | if (do_send) | |
830 | lnet_finalize(ni, msg, -ECANCELED); | |
831 | ||
832 | lnet_net_lock(cpt); | |
833 | return ECANCELED; | |
834 | } | |
835 | ||
d7e09d03 | 836 | if (!msg->msg_peertxcredit) { |
af66a6e2 | 837 | LASSERT((lp->lp_txcredits < 0) == |
c314c319 | 838 | !list_empty(&lp->lp_txq)); |
d7e09d03 PT |
839 | |
840 | msg->msg_peertxcredit = 1; | |
841 | lp->lp_txqnob += msg->msg_len + sizeof(lnet_hdr_t); | |
842 | lp->lp_txcredits--; | |
843 | ||
844 | if (lp->lp_txcredits < lp->lp_mintxcredits) | |
845 | lp->lp_mintxcredits = lp->lp_txcredits; | |
846 | ||
847 | if (lp->lp_txcredits < 0) { | |
848 | msg->msg_tx_delayed = 1; | |
849 | list_add_tail(&msg->msg_list, &lp->lp_txq); | |
850 | return EAGAIN; | |
851 | } | |
852 | } | |
853 | ||
854 | if (!msg->msg_txcredit) { | |
855 | LASSERT((tq->tq_credits < 0) == | |
856 | !list_empty(&tq->tq_delayed)); | |
857 | ||
858 | msg->msg_txcredit = 1; | |
859 | tq->tq_credits--; | |
860 | ||
861 | if (tq->tq_credits < tq->tq_credits_min) | |
862 | tq->tq_credits_min = tq->tq_credits; | |
863 | ||
864 | if (tq->tq_credits < 0) { | |
865 | msg->msg_tx_delayed = 1; | |
866 | list_add_tail(&msg->msg_list, &tq->tq_delayed); | |
867 | return EAGAIN; | |
868 | } | |
869 | } | |
870 | ||
871 | if (do_send) { | |
872 | lnet_net_unlock(cpt); | |
873 | lnet_ni_send(ni, msg); | |
874 | lnet_net_lock(cpt); | |
875 | } | |
876 | return 0; | |
877 | } | |
878 | ||
f526b20a | 879 | static lnet_rtrbufpool_t * |
d7e09d03 PT |
880 | lnet_msg2bufpool(lnet_msg_t *msg) |
881 | { | |
7e7ab095 MS |
882 | lnet_rtrbufpool_t *rbp; |
883 | int cpt; | |
d7e09d03 PT |
884 | |
885 | LASSERT(msg->msg_rx_committed); | |
886 | ||
887 | cpt = msg->msg_rx_cpt; | |
888 | rbp = &the_lnet.ln_rtrpools[cpt][0]; | |
889 | ||
890 | LASSERT(msg->msg_len <= LNET_MTU); | |
891 | while (msg->msg_len > (unsigned int)rbp->rbp_npages * PAGE_CACHE_SIZE) { | |
892 | rbp++; | |
893 | LASSERT(rbp < &the_lnet.ln_rtrpools[cpt][LNET_NRBPOOLS]); | |
894 | } | |
895 | ||
896 | return rbp; | |
897 | } | |
898 | ||
f526b20a | 899 | static int |
af66a6e2 | 900 | lnet_post_routed_recv_locked(lnet_msg_t *msg, int do_recv) |
d7e09d03 | 901 | { |
4420cfd3 JS |
902 | /* |
903 | * lnet_parse is going to lnet_net_unlock immediately after this, so it | |
d7e09d03 | 904 | * sets do_recv FALSE and I don't do the unlock/send/lock bit. I |
4420cfd3 JS |
905 | * return EAGAIN if msg blocked and 0 if received or OK to receive |
906 | */ | |
7e7ab095 MS |
907 | lnet_peer_t *lp = msg->msg_rxpeer; |
908 | lnet_rtrbufpool_t *rbp; | |
909 | lnet_rtrbuf_t *rb; | |
d7e09d03 | 910 | |
af66a6e2 LN |
911 | LASSERT(msg->msg_iov == NULL); |
912 | LASSERT(msg->msg_kiov == NULL); | |
913 | LASSERT(msg->msg_niov == 0); | |
914 | LASSERT(msg->msg_routing); | |
915 | LASSERT(msg->msg_receiving); | |
916 | LASSERT(!msg->msg_sending); | |
d7e09d03 PT |
917 | |
918 | /* non-lnet_parse callers only receive delayed messages */ | |
919 | LASSERT(!do_recv || msg->msg_rx_delayed); | |
920 | ||
921 | if (!msg->msg_peerrtrcredit) { | |
af66a6e2 | 922 | LASSERT((lp->lp_rtrcredits < 0) == |
c314c319 | 923 | !list_empty(&lp->lp_rtrq)); |
d7e09d03 PT |
924 | |
925 | msg->msg_peerrtrcredit = 1; | |
926 | lp->lp_rtrcredits--; | |
927 | if (lp->lp_rtrcredits < lp->lp_minrtrcredits) | |
928 | lp->lp_minrtrcredits = lp->lp_rtrcredits; | |
929 | ||
930 | if (lp->lp_rtrcredits < 0) { | |
931 | /* must have checked eager_recv before here */ | |
932 | LASSERT(msg->msg_rx_ready_delay); | |
933 | msg->msg_rx_delayed = 1; | |
934 | list_add_tail(&msg->msg_list, &lp->lp_rtrq); | |
935 | return EAGAIN; | |
936 | } | |
937 | } | |
938 | ||
939 | rbp = lnet_msg2bufpool(msg); | |
940 | ||
941 | if (!msg->msg_rtrcredit) { | |
af66a6e2 | 942 | LASSERT((rbp->rbp_credits < 0) == |
d7e09d03 PT |
943 | !list_empty(&rbp->rbp_msgs)); |
944 | ||
945 | msg->msg_rtrcredit = 1; | |
946 | rbp->rbp_credits--; | |
947 | if (rbp->rbp_credits < rbp->rbp_mincredits) | |
948 | rbp->rbp_mincredits = rbp->rbp_credits; | |
949 | ||
950 | if (rbp->rbp_credits < 0) { | |
951 | /* must have checked eager_recv before here */ | |
952 | LASSERT(msg->msg_rx_ready_delay); | |
953 | msg->msg_rx_delayed = 1; | |
954 | list_add_tail(&msg->msg_list, &rbp->rbp_msgs); | |
955 | return EAGAIN; | |
956 | } | |
957 | } | |
958 | ||
af66a6e2 | 959 | LASSERT(!list_empty(&rbp->rbp_bufs)); |
d7e09d03 PT |
960 | rb = list_entry(rbp->rbp_bufs.next, lnet_rtrbuf_t, rb_list); |
961 | list_del(&rb->rb_list); | |
962 | ||
963 | msg->msg_niov = rbp->rbp_npages; | |
964 | msg->msg_kiov = &rb->rb_kiov[0]; | |
965 | ||
966 | if (do_recv) { | |
967 | int cpt = msg->msg_rx_cpt; | |
968 | ||
969 | lnet_net_unlock(cpt); | |
970 | lnet_ni_recv(lp->lp_ni, msg->msg_private, msg, 1, | |
971 | 0, msg->msg_len, msg->msg_len); | |
972 | lnet_net_lock(cpt); | |
973 | } | |
974 | return 0; | |
975 | } | |
976 | ||
977 | void | |
978 | lnet_return_tx_credits_locked(lnet_msg_t *msg) | |
979 | { | |
7e7ab095 MS |
980 | lnet_peer_t *txpeer = msg->msg_txpeer; |
981 | lnet_msg_t *msg2; | |
d7e09d03 PT |
982 | |
983 | if (msg->msg_txcredit) { | |
7e7ab095 | 984 | struct lnet_ni *ni = txpeer->lp_ni; |
d7e09d03 PT |
985 | struct lnet_tx_queue *tq = ni->ni_tx_queues[msg->msg_tx_cpt]; |
986 | ||
987 | /* give back NI txcredits */ | |
988 | msg->msg_txcredit = 0; | |
989 | ||
990 | LASSERT((tq->tq_credits < 0) == | |
991 | !list_empty(&tq->tq_delayed)); | |
992 | ||
993 | tq->tq_credits++; | |
994 | if (tq->tq_credits <= 0) { | |
995 | msg2 = list_entry(tq->tq_delayed.next, | |
c314c319 | 996 | lnet_msg_t, msg_list); |
d7e09d03 PT |
997 | list_del(&msg2->msg_list); |
998 | ||
999 | LASSERT(msg2->msg_txpeer->lp_ni == ni); | |
1000 | LASSERT(msg2->msg_tx_delayed); | |
1001 | ||
1002 | (void) lnet_post_send_locked(msg2, 1); | |
1003 | } | |
1004 | } | |
1005 | ||
1006 | if (msg->msg_peertxcredit) { | |
1007 | /* give back peer txcredits */ | |
1008 | msg->msg_peertxcredit = 0; | |
1009 | ||
1010 | LASSERT((txpeer->lp_txcredits < 0) == | |
1011 | !list_empty(&txpeer->lp_txq)); | |
1012 | ||
1013 | txpeer->lp_txqnob -= msg->msg_len + sizeof(lnet_hdr_t); | |
af66a6e2 | 1014 | LASSERT(txpeer->lp_txqnob >= 0); |
d7e09d03 PT |
1015 | |
1016 | txpeer->lp_txcredits++; | |
1017 | if (txpeer->lp_txcredits <= 0) { | |
1018 | msg2 = list_entry(txpeer->lp_txq.next, | |
c314c319 | 1019 | lnet_msg_t, msg_list); |
d7e09d03 PT |
1020 | list_del(&msg2->msg_list); |
1021 | ||
1022 | LASSERT(msg2->msg_txpeer == txpeer); | |
1023 | LASSERT(msg2->msg_tx_delayed); | |
1024 | ||
1025 | (void) lnet_post_send_locked(msg2, 1); | |
1026 | } | |
1027 | } | |
1028 | ||
1029 | if (txpeer != NULL) { | |
1030 | msg->msg_txpeer = NULL; | |
1031 | lnet_peer_decref_locked(txpeer); | |
1032 | } | |
1033 | } | |
1034 | ||
1035 | void | |
1036 | lnet_return_rx_credits_locked(lnet_msg_t *msg) | |
1037 | { | |
7e7ab095 MS |
1038 | lnet_peer_t *rxpeer = msg->msg_rxpeer; |
1039 | lnet_msg_t *msg2; | |
d7e09d03 PT |
1040 | |
1041 | if (msg->msg_rtrcredit) { | |
1042 | /* give back global router credits */ | |
7e7ab095 | 1043 | lnet_rtrbuf_t *rb; |
d7e09d03 PT |
1044 | lnet_rtrbufpool_t *rbp; |
1045 | ||
4420cfd3 JS |
1046 | /* |
1047 | * NB If a msg ever blocks for a buffer in rbp_msgs, it stays | |
d7e09d03 | 1048 | * there until it gets one allocated, or aborts the wait |
4420cfd3 JS |
1049 | * itself |
1050 | */ | |
af66a6e2 | 1051 | LASSERT(msg->msg_kiov != NULL); |
d7e09d03 PT |
1052 | |
1053 | rb = list_entry(msg->msg_kiov, lnet_rtrbuf_t, rb_kiov[0]); | |
1054 | rbp = rb->rb_pool; | |
af66a6e2 | 1055 | LASSERT(rbp == lnet_msg2bufpool(msg)); |
d7e09d03 PT |
1056 | |
1057 | msg->msg_kiov = NULL; | |
1058 | msg->msg_rtrcredit = 0; | |
1059 | ||
1060 | LASSERT((rbp->rbp_credits < 0) == | |
1061 | !list_empty(&rbp->rbp_msgs)); | |
1062 | LASSERT((rbp->rbp_credits > 0) == | |
1063 | !list_empty(&rbp->rbp_bufs)); | |
1064 | ||
1065 | list_add(&rb->rb_list, &rbp->rbp_bufs); | |
1066 | rbp->rbp_credits++; | |
1067 | if (rbp->rbp_credits <= 0) { | |
1068 | msg2 = list_entry(rbp->rbp_msgs.next, | |
c314c319 | 1069 | lnet_msg_t, msg_list); |
d7e09d03 PT |
1070 | list_del(&msg2->msg_list); |
1071 | ||
1072 | (void) lnet_post_routed_recv_locked(msg2, 1); | |
1073 | } | |
1074 | } | |
1075 | ||
1076 | if (msg->msg_peerrtrcredit) { | |
1077 | /* give back peer router credits */ | |
1078 | msg->msg_peerrtrcredit = 0; | |
1079 | ||
1080 | LASSERT((rxpeer->lp_rtrcredits < 0) == | |
1081 | !list_empty(&rxpeer->lp_rtrq)); | |
1082 | ||
1083 | rxpeer->lp_rtrcredits++; | |
1084 | if (rxpeer->lp_rtrcredits <= 0) { | |
1085 | msg2 = list_entry(rxpeer->lp_rtrq.next, | |
c314c319 | 1086 | lnet_msg_t, msg_list); |
d7e09d03 PT |
1087 | list_del(&msg2->msg_list); |
1088 | ||
1089 | (void) lnet_post_routed_recv_locked(msg2, 1); | |
1090 | } | |
1091 | } | |
1092 | if (rxpeer != NULL) { | |
1093 | msg->msg_rxpeer = NULL; | |
1094 | lnet_peer_decref_locked(rxpeer); | |
1095 | } | |
1096 | } | |
1097 | ||
1098 | static int | |
1099 | lnet_compare_routes(lnet_route_t *r1, lnet_route_t *r2) | |
1100 | { | |
1101 | lnet_peer_t *p1 = r1->lr_gateway; | |
1102 | lnet_peer_t *p2 = r2->lr_gateway; | |
1103 | ||
e75fb87f DO |
1104 | if (r1->lr_priority < r2->lr_priority) |
1105 | return 1; | |
1106 | ||
1107 | if (r1->lr_priority > r2->lr_priority) | |
1108 | return -1; | |
1109 | ||
d7e09d03 PT |
1110 | if (r1->lr_hops < r2->lr_hops) |
1111 | return 1; | |
1112 | ||
1113 | if (r1->lr_hops > r2->lr_hops) | |
1114 | return -1; | |
1115 | ||
1116 | if (p1->lp_txqnob < p2->lp_txqnob) | |
1117 | return 1; | |
1118 | ||
1119 | if (p1->lp_txqnob > p2->lp_txqnob) | |
1120 | return -1; | |
1121 | ||
1122 | if (p1->lp_txcredits > p2->lp_txcredits) | |
1123 | return 1; | |
1124 | ||
1125 | if (p1->lp_txcredits < p2->lp_txcredits) | |
1126 | return -1; | |
1127 | ||
1128 | if (r1->lr_seq - r2->lr_seq <= 0) | |
1129 | return 1; | |
1130 | ||
1131 | return -1; | |
1132 | } | |
1133 | ||
1134 | static lnet_peer_t * | |
1135 | lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid) | |
1136 | { | |
7e7ab095 MS |
1137 | lnet_remotenet_t *rnet; |
1138 | lnet_route_t *rtr; | |
1139 | lnet_route_t *rtr_best; | |
1140 | lnet_route_t *rtr_last; | |
1141 | struct lnet_peer *lp_best; | |
1142 | struct lnet_peer *lp; | |
1143 | int rc; | |
d7e09d03 | 1144 | |
4420cfd3 JS |
1145 | /* |
1146 | * If @rtr_nid is not LNET_NID_ANY, return the gateway with | |
1147 | * rtr_nid nid, otherwise find the best gateway I can use | |
1148 | */ | |
d7e09d03 PT |
1149 | rnet = lnet_find_net_locked(LNET_NIDNET(target)); |
1150 | if (rnet == NULL) | |
1151 | return NULL; | |
1152 | ||
1153 | lp_best = NULL; | |
1154 | rtr_best = rtr_last = NULL; | |
1155 | list_for_each_entry(rtr, &rnet->lrn_routes, lr_list) { | |
1156 | lp = rtr->lr_gateway; | |
1157 | ||
1158 | if (!lp->lp_alive || /* gateway is down */ | |
1159 | ((lp->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0 && | |
1160 | rtr->lr_downis != 0)) /* NI to target is down */ | |
1161 | continue; | |
1162 | ||
1163 | if (ni != NULL && lp->lp_ni != ni) | |
1164 | continue; | |
1165 | ||
1166 | if (lp->lp_nid == rtr_nid) /* it's pre-determined router */ | |
1167 | return lp; | |
1168 | ||
1169 | if (lp_best == NULL) { | |
1170 | rtr_best = rtr_last = rtr; | |
1171 | lp_best = lp; | |
1172 | continue; | |
1173 | } | |
1174 | ||
1175 | /* no protection on below fields, but it's harmless */ | |
1176 | if (rtr_last->lr_seq - rtr->lr_seq < 0) | |
1177 | rtr_last = rtr; | |
1178 | ||
1179 | rc = lnet_compare_routes(rtr, rtr_best); | |
1180 | if (rc < 0) | |
1181 | continue; | |
1182 | ||
1183 | rtr_best = rtr; | |
1184 | lp_best = lp; | |
1185 | } | |
1186 | ||
4420cfd3 JS |
1187 | /* |
1188 | * set sequence number on the best router to the latest sequence + 1 | |
d7e09d03 | 1189 | * so we can round-robin all routers, it's race and inaccurate but |
4420cfd3 JS |
1190 | * harmless and functional |
1191 | */ | |
d7e09d03 PT |
1192 | if (rtr_best != NULL) |
1193 | rtr_best->lr_seq = rtr_last->lr_seq + 1; | |
1194 | return lp_best; | |
1195 | } | |
1196 | ||
1197 | int | |
1198 | lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg, lnet_nid_t rtr_nid) | |
1199 | { | |
7e7ab095 MS |
1200 | lnet_nid_t dst_nid = msg->msg_target.nid; |
1201 | struct lnet_ni *src_ni; | |
1202 | struct lnet_ni *local_ni; | |
1203 | struct lnet_peer *lp; | |
1204 | int cpt; | |
1205 | int cpt2; | |
1206 | int rc; | |
d7e09d03 | 1207 | |
4420cfd3 JS |
1208 | /* |
1209 | * NB: rtr_nid is set to LNET_NID_ANY for all current use-cases, | |
d7e09d03 | 1210 | * but we might want to use pre-determined router for ACK/REPLY |
4420cfd3 JS |
1211 | * in the future |
1212 | */ | |
d7e09d03 | 1213 | /* NB: ni != NULL == interface pre-determined (ACK/REPLY) */ |
af66a6e2 LN |
1214 | LASSERT(msg->msg_txpeer == NULL); |
1215 | LASSERT(!msg->msg_sending); | |
1216 | LASSERT(!msg->msg_target_is_router); | |
1217 | LASSERT(!msg->msg_receiving); | |
d7e09d03 PT |
1218 | |
1219 | msg->msg_sending = 1; | |
1220 | ||
1221 | LASSERT(!msg->msg_tx_committed); | |
1222 | cpt = lnet_cpt_of_nid(rtr_nid == LNET_NID_ANY ? dst_nid : rtr_nid); | |
1223 | again: | |
1224 | lnet_net_lock(cpt); | |
1225 | ||
1226 | if (the_lnet.ln_shutdown) { | |
1227 | lnet_net_unlock(cpt); | |
1228 | return -ESHUTDOWN; | |
1229 | } | |
1230 | ||
1231 | if (src_nid == LNET_NID_ANY) { | |
1232 | src_ni = NULL; | |
1233 | } else { | |
1234 | src_ni = lnet_nid2ni_locked(src_nid, cpt); | |
1235 | if (src_ni == NULL) { | |
1236 | lnet_net_unlock(cpt); | |
2d00bd17 JP |
1237 | LCONSOLE_WARN("Can't send to %s: src %s is not a local nid\n", |
1238 | libcfs_nid2str(dst_nid), | |
d7e09d03 PT |
1239 | libcfs_nid2str(src_nid)); |
1240 | return -EINVAL; | |
1241 | } | |
af66a6e2 | 1242 | LASSERT(!msg->msg_routing); |
d7e09d03 PT |
1243 | } |
1244 | ||
1245 | /* Is this for someone on a local network? */ | |
1246 | local_ni = lnet_net2ni_locked(LNET_NIDNET(dst_nid), cpt); | |
1247 | ||
1248 | if (local_ni != NULL) { | |
1249 | if (src_ni == NULL) { | |
1250 | src_ni = local_ni; | |
1251 | src_nid = src_ni->ni_nid; | |
1252 | } else if (src_ni == local_ni) { | |
1253 | lnet_ni_decref_locked(local_ni, cpt); | |
1254 | } else { | |
1255 | lnet_ni_decref_locked(local_ni, cpt); | |
1256 | lnet_ni_decref_locked(src_ni, cpt); | |
1257 | lnet_net_unlock(cpt); | |
1258 | LCONSOLE_WARN("No route to %s via from %s\n", | |
1259 | libcfs_nid2str(dst_nid), | |
1260 | libcfs_nid2str(src_nid)); | |
1261 | return -EINVAL; | |
1262 | } | |
1263 | ||
1264 | LASSERT(src_nid != LNET_NID_ANY); | |
1265 | lnet_msg_commit(msg, cpt); | |
1266 | ||
1267 | if (!msg->msg_routing) | |
1268 | msg->msg_hdr.src_nid = cpu_to_le64(src_nid); | |
1269 | ||
1270 | if (src_ni == the_lnet.ln_loni) { | |
1271 | /* No send credit hassles with LOLND */ | |
1272 | lnet_net_unlock(cpt); | |
1273 | lnet_ni_send(src_ni, msg); | |
1274 | ||
1275 | lnet_net_lock(cpt); | |
1276 | lnet_ni_decref_locked(src_ni, cpt); | |
1277 | lnet_net_unlock(cpt); | |
1278 | return 0; | |
1279 | } | |
1280 | ||
1281 | rc = lnet_nid2peer_locked(&lp, dst_nid, cpt); | |
1282 | /* lp has ref on src_ni; lose mine */ | |
1283 | lnet_ni_decref_locked(src_ni, cpt); | |
1284 | if (rc != 0) { | |
1285 | lnet_net_unlock(cpt); | |
1286 | LCONSOLE_WARN("Error %d finding peer %s\n", rc, | |
1287 | libcfs_nid2str(dst_nid)); | |
1288 | /* ENOMEM or shutting down */ | |
1289 | return rc; | |
1290 | } | |
af66a6e2 | 1291 | LASSERT(lp->lp_ni == src_ni); |
d7e09d03 PT |
1292 | } else { |
1293 | /* sending to a remote network */ | |
1294 | lp = lnet_find_route_locked(src_ni, dst_nid, rtr_nid); | |
1295 | if (lp == NULL) { | |
1296 | if (src_ni != NULL) | |
1297 | lnet_ni_decref_locked(src_ni, cpt); | |
1298 | lnet_net_unlock(cpt); | |
1299 | ||
2d00bd17 | 1300 | LCONSOLE_WARN("No route to %s via %s (all routers down)\n", |
d7e09d03 PT |
1301 | libcfs_id2str(msg->msg_target), |
1302 | libcfs_nid2str(src_nid)); | |
1303 | return -EHOSTUNREACH; | |
1304 | } | |
1305 | ||
4420cfd3 JS |
1306 | /* |
1307 | * rtr_nid is LNET_NID_ANY or NID of pre-determined router, | |
d7e09d03 PT |
1308 | * it's possible that rtr_nid isn't LNET_NID_ANY and lp isn't |
1309 | * pre-determined router, this can happen if router table | |
4420cfd3 JS |
1310 | * was changed when we release the lock |
1311 | */ | |
d7e09d03 PT |
1312 | if (rtr_nid != lp->lp_nid) { |
1313 | cpt2 = lnet_cpt_of_nid_locked(lp->lp_nid); | |
1314 | if (cpt2 != cpt) { | |
1315 | if (src_ni != NULL) | |
1316 | lnet_ni_decref_locked(src_ni, cpt); | |
1317 | lnet_net_unlock(cpt); | |
1318 | ||
1319 | rtr_nid = lp->lp_nid; | |
1320 | cpt = cpt2; | |
1321 | goto again; | |
1322 | } | |
1323 | } | |
1324 | ||
1325 | CDEBUG(D_NET, "Best route to %s via %s for %s %d\n", | |
1326 | libcfs_nid2str(dst_nid), libcfs_nid2str(lp->lp_nid), | |
1327 | lnet_msgtyp2str(msg->msg_type), msg->msg_len); | |
1328 | ||
1329 | if (src_ni == NULL) { | |
1330 | src_ni = lp->lp_ni; | |
1331 | src_nid = src_ni->ni_nid; | |
1332 | } else { | |
af66a6e2 | 1333 | LASSERT(src_ni == lp->lp_ni); |
d7e09d03 PT |
1334 | lnet_ni_decref_locked(src_ni, cpt); |
1335 | } | |
1336 | ||
1337 | lnet_peer_addref_locked(lp); | |
1338 | ||
1339 | LASSERT(src_nid != LNET_NID_ANY); | |
1340 | lnet_msg_commit(msg, cpt); | |
1341 | ||
1342 | if (!msg->msg_routing) { | |
1343 | /* I'm the source and now I know which NI to send on */ | |
1344 | msg->msg_hdr.src_nid = cpu_to_le64(src_nid); | |
1345 | } | |
1346 | ||
1347 | msg->msg_target_is_router = 1; | |
1348 | msg->msg_target.nid = lp->lp_nid; | |
1349 | msg->msg_target.pid = LUSTRE_SRV_LNET_PID; | |
1350 | } | |
1351 | ||
1352 | /* 'lp' is our best choice of peer */ | |
1353 | ||
af66a6e2 LN |
1354 | LASSERT(!msg->msg_peertxcredit); |
1355 | LASSERT(!msg->msg_txcredit); | |
1356 | LASSERT(msg->msg_txpeer == NULL); | |
d7e09d03 PT |
1357 | |
1358 | msg->msg_txpeer = lp; /* msg takes my ref on lp */ | |
1359 | ||
1360 | rc = lnet_post_send_locked(msg, 0); | |
1361 | lnet_net_unlock(cpt); | |
1362 | ||
dee2857e IH |
1363 | if (rc == EHOSTUNREACH || rc == ECANCELED) |
1364 | return -rc; | |
d7e09d03 PT |
1365 | |
1366 | if (rc == 0) | |
1367 | lnet_ni_send(src_ni, msg); | |
1368 | ||
dee2857e | 1369 | return 0; /* rc == 0 or EAGAIN */ |
d7e09d03 PT |
1370 | } |
1371 | ||
1372 | static void | |
1373 | lnet_drop_message(lnet_ni_t *ni, int cpt, void *private, unsigned int nob) | |
1374 | { | |
1375 | lnet_net_lock(cpt); | |
1376 | the_lnet.ln_counters[cpt]->drop_count++; | |
1377 | the_lnet.ln_counters[cpt]->drop_length += nob; | |
1378 | lnet_net_unlock(cpt); | |
1379 | ||
1380 | lnet_ni_recv(ni, private, NULL, 0, 0, 0, nob); | |
1381 | } | |
1382 | ||
1383 | static void | |
1384 | lnet_recv_put(lnet_ni_t *ni, lnet_msg_t *msg) | |
1385 | { | |
7e7ab095 | 1386 | lnet_hdr_t *hdr = &msg->msg_hdr; |
d7e09d03 PT |
1387 | |
1388 | if (msg->msg_wanted != 0) | |
1389 | lnet_setpayloadbuffer(msg); | |
1390 | ||
1391 | lnet_build_msg_event(msg, LNET_EVENT_PUT); | |
1392 | ||
4420cfd3 JS |
1393 | /* |
1394 | * Must I ACK? If so I'll grab the ack_wmd out of the header and put | |
1395 | * it back into the ACK during lnet_finalize() | |
1396 | */ | |
d7e09d03 PT |
1397 | msg->msg_ack = (!lnet_is_wire_handle_none(&hdr->msg.put.ack_wmd) && |
1398 | (msg->msg_md->md_options & LNET_MD_ACK_DISABLE) == 0); | |
1399 | ||
1400 | lnet_ni_recv(ni, msg->msg_private, msg, msg->msg_rx_delayed, | |
1401 | msg->msg_offset, msg->msg_wanted, hdr->payload_length); | |
1402 | } | |
1403 | ||
1404 | static int | |
1405 | lnet_parse_put(lnet_ni_t *ni, lnet_msg_t *msg) | |
1406 | { | |
7e7ab095 MS |
1407 | lnet_hdr_t *hdr = &msg->msg_hdr; |
1408 | struct lnet_match_info info; | |
1409 | int rc; | |
d7e09d03 PT |
1410 | |
1411 | /* Convert put fields to host byte order */ | |
1412 | hdr->msg.put.match_bits = le64_to_cpu(hdr->msg.put.match_bits); | |
1413 | hdr->msg.put.ptl_index = le32_to_cpu(hdr->msg.put.ptl_index); | |
1414 | hdr->msg.put.offset = le32_to_cpu(hdr->msg.put.offset); | |
1415 | ||
1416 | info.mi_id.nid = hdr->src_nid; | |
1417 | info.mi_id.pid = hdr->src_pid; | |
1418 | info.mi_opc = LNET_MD_OP_PUT; | |
1419 | info.mi_portal = hdr->msg.put.ptl_index; | |
1420 | info.mi_rlength = hdr->payload_length; | |
1421 | info.mi_roffset = hdr->msg.put.offset; | |
1422 | info.mi_mbits = hdr->msg.put.match_bits; | |
1423 | ||
1424 | msg->msg_rx_ready_delay = ni->ni_lnd->lnd_eager_recv == NULL; | |
1425 | ||
1426 | again: | |
1427 | rc = lnet_ptl_match_md(&info, msg); | |
1428 | switch (rc) { | |
1429 | default: | |
1430 | LBUG(); | |
1431 | ||
1432 | case LNET_MATCHMD_OK: | |
1433 | lnet_recv_put(ni, msg); | |
1434 | return 0; | |
1435 | ||
1436 | case LNET_MATCHMD_NONE: | |
1437 | if (msg->msg_rx_delayed) /* attached on delayed list */ | |
1438 | return 0; | |
1439 | ||
1440 | rc = lnet_ni_eager_recv(ni, msg); | |
1441 | if (rc == 0) | |
1442 | goto again; | |
1443 | /* fall through */ | |
1444 | ||
1445 | case LNET_MATCHMD_DROP: | |
b0f5aad5 | 1446 | CNETERR("Dropping PUT from %s portal %d match %llu offset %d length %d: %d\n", |
d7e09d03 PT |
1447 | libcfs_id2str(info.mi_id), info.mi_portal, |
1448 | info.mi_mbits, info.mi_roffset, info.mi_rlength, rc); | |
1449 | ||
1450 | return ENOENT; /* +ve: OK but no match */ | |
1451 | } | |
1452 | } | |
1453 | ||
1454 | static int | |
1455 | lnet_parse_get(lnet_ni_t *ni, lnet_msg_t *msg, int rdma_get) | |
1456 | { | |
7e7ab095 MS |
1457 | struct lnet_match_info info; |
1458 | lnet_hdr_t *hdr = &msg->msg_hdr; | |
1459 | lnet_handle_wire_t reply_wmd; | |
1460 | int rc; | |
d7e09d03 PT |
1461 | |
1462 | /* Convert get fields to host byte order */ | |
7e7ab095 MS |
1463 | hdr->msg.get.match_bits = le64_to_cpu(hdr->msg.get.match_bits); |
1464 | hdr->msg.get.ptl_index = le32_to_cpu(hdr->msg.get.ptl_index); | |
1465 | hdr->msg.get.sink_length = le32_to_cpu(hdr->msg.get.sink_length); | |
1466 | hdr->msg.get.src_offset = le32_to_cpu(hdr->msg.get.src_offset); | |
1467 | ||
1468 | info.mi_id.nid = hdr->src_nid; | |
1469 | info.mi_id.pid = hdr->src_pid; | |
1470 | info.mi_opc = LNET_MD_OP_GET; | |
1471 | info.mi_portal = hdr->msg.get.ptl_index; | |
1472 | info.mi_rlength = hdr->msg.get.sink_length; | |
1473 | info.mi_roffset = hdr->msg.get.src_offset; | |
1474 | info.mi_mbits = hdr->msg.get.match_bits; | |
d7e09d03 PT |
1475 | |
1476 | rc = lnet_ptl_match_md(&info, msg); | |
1477 | if (rc == LNET_MATCHMD_DROP) { | |
b0f5aad5 | 1478 | CNETERR("Dropping GET from %s portal %d match %llu offset %d length %d\n", |
d7e09d03 PT |
1479 | libcfs_id2str(info.mi_id), info.mi_portal, |
1480 | info.mi_mbits, info.mi_roffset, info.mi_rlength); | |
1481 | return ENOENT; /* +ve: OK but no match */ | |
1482 | } | |
1483 | ||
1484 | LASSERT(rc == LNET_MATCHMD_OK); | |
1485 | ||
1486 | lnet_build_msg_event(msg, LNET_EVENT_GET); | |
1487 | ||
1488 | reply_wmd = hdr->msg.get.return_wmd; | |
1489 | ||
1490 | lnet_prep_send(msg, LNET_MSG_REPLY, info.mi_id, | |
1491 | msg->msg_offset, msg->msg_wanted); | |
1492 | ||
1493 | msg->msg_hdr.msg.reply.dst_wmd = reply_wmd; | |
1494 | ||
1495 | if (rdma_get) { | |
1496 | /* The LND completes the REPLY from her recv procedure */ | |
1497 | lnet_ni_recv(ni, msg->msg_private, msg, 0, | |
1498 | msg->msg_offset, msg->msg_len, msg->msg_len); | |
1499 | return 0; | |
1500 | } | |
1501 | ||
1502 | lnet_ni_recv(ni, msg->msg_private, NULL, 0, 0, 0, 0); | |
1503 | msg->msg_receiving = 0; | |
1504 | ||
1505 | rc = lnet_send(ni->ni_nid, msg, LNET_NID_ANY); | |
1506 | if (rc < 0) { | |
1507 | /* didn't get as far as lnet_ni_send() */ | |
1508 | CERROR("%s: Unable to send REPLY for GET from %s: %d\n", | |
1509 | libcfs_nid2str(ni->ni_nid), | |
1510 | libcfs_id2str(info.mi_id), rc); | |
1511 | ||
1512 | lnet_finalize(ni, msg, rc); | |
1513 | } | |
1514 | ||
1515 | return 0; | |
1516 | } | |
1517 | ||
1518 | static int | |
1519 | lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg) | |
1520 | { | |
7e7ab095 MS |
1521 | void *private = msg->msg_private; |
1522 | lnet_hdr_t *hdr = &msg->msg_hdr; | |
d7e09d03 | 1523 | lnet_process_id_t src = {0}; |
7e7ab095 MS |
1524 | lnet_libmd_t *md; |
1525 | int rlength; | |
1526 | int mlength; | |
1527 | int cpt; | |
d7e09d03 PT |
1528 | |
1529 | cpt = lnet_cpt_of_cookie(hdr->msg.reply.dst_wmd.wh_object_cookie); | |
1530 | lnet_res_lock(cpt); | |
1531 | ||
1532 | src.nid = hdr->src_nid; | |
1533 | src.pid = hdr->src_pid; | |
1534 | ||
1535 | /* NB handles only looked up by creator (no flips) */ | |
1536 | md = lnet_wire_handle2md(&hdr->msg.reply.dst_wmd); | |
1537 | if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) { | |
55f5a824 | 1538 | CNETERR("%s: Dropping REPLY from %s for %s MD %#llx.%#llx\n", |
d7e09d03 PT |
1539 | libcfs_nid2str(ni->ni_nid), libcfs_id2str(src), |
1540 | (md == NULL) ? "invalid" : "inactive", | |
1541 | hdr->msg.reply.dst_wmd.wh_interface_cookie, | |
1542 | hdr->msg.reply.dst_wmd.wh_object_cookie); | |
1543 | if (md != NULL && md->md_me != NULL) | |
1544 | CERROR("REPLY MD also attached to portal %d\n", | |
1545 | md->md_me->me_portal); | |
1546 | ||
1547 | lnet_res_unlock(cpt); | |
1548 | return ENOENT; /* +ve: OK but no match */ | |
1549 | } | |
1550 | ||
af66a6e2 | 1551 | LASSERT(md->md_offset == 0); |
d7e09d03 PT |
1552 | |
1553 | rlength = hdr->payload_length; | |
005b23d6 | 1554 | mlength = min_t(uint, rlength, md->md_length); |
d7e09d03 PT |
1555 | |
1556 | if (mlength < rlength && | |
1557 | (md->md_options & LNET_MD_TRUNCATE) == 0) { | |
55f5a824 | 1558 | CNETERR("%s: Dropping REPLY from %s length %d for MD %#llx would overflow (%d)\n", |
d7e09d03 PT |
1559 | libcfs_nid2str(ni->ni_nid), libcfs_id2str(src), |
1560 | rlength, hdr->msg.reply.dst_wmd.wh_object_cookie, | |
1561 | mlength); | |
1562 | lnet_res_unlock(cpt); | |
1563 | return ENOENT; /* +ve: OK but no match */ | |
1564 | } | |
1565 | ||
55f5a824 | 1566 | CDEBUG(D_NET, "%s: Reply from %s of length %d/%d into md %#llx\n", |
d7e09d03 PT |
1567 | libcfs_nid2str(ni->ni_nid), libcfs_id2str(src), |
1568 | mlength, rlength, hdr->msg.reply.dst_wmd.wh_object_cookie); | |
1569 | ||
1570 | lnet_msg_attach_md(msg, md, 0, mlength); | |
1571 | ||
1572 | if (mlength != 0) | |
1573 | lnet_setpayloadbuffer(msg); | |
1574 | ||
1575 | lnet_res_unlock(cpt); | |
1576 | ||
1577 | lnet_build_msg_event(msg, LNET_EVENT_REPLY); | |
1578 | ||
1579 | lnet_ni_recv(ni, private, msg, 0, 0, mlength, rlength); | |
1580 | return 0; | |
1581 | } | |
1582 | ||
1583 | static int | |
1584 | lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg) | |
1585 | { | |
7e7ab095 | 1586 | lnet_hdr_t *hdr = &msg->msg_hdr; |
d7e09d03 | 1587 | lnet_process_id_t src = {0}; |
7e7ab095 MS |
1588 | lnet_libmd_t *md; |
1589 | int cpt; | |
d7e09d03 PT |
1590 | |
1591 | src.nid = hdr->src_nid; | |
1592 | src.pid = hdr->src_pid; | |
1593 | ||
1594 | /* Convert ack fields to host byte order */ | |
1595 | hdr->msg.ack.match_bits = le64_to_cpu(hdr->msg.ack.match_bits); | |
1596 | hdr->msg.ack.mlength = le32_to_cpu(hdr->msg.ack.mlength); | |
1597 | ||
1598 | cpt = lnet_cpt_of_cookie(hdr->msg.ack.dst_wmd.wh_object_cookie); | |
1599 | lnet_res_lock(cpt); | |
1600 | ||
1601 | /* NB handles only looked up by creator (no flips) */ | |
1602 | md = lnet_wire_handle2md(&hdr->msg.ack.dst_wmd); | |
1603 | if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) { | |
1604 | /* Don't moan; this is expected */ | |
1605 | CDEBUG(D_NET, | |
55f5a824 | 1606 | "%s: Dropping ACK from %s to %s MD %#llx.%#llx\n", |
d7e09d03 PT |
1607 | libcfs_nid2str(ni->ni_nid), libcfs_id2str(src), |
1608 | (md == NULL) ? "invalid" : "inactive", | |
1609 | hdr->msg.ack.dst_wmd.wh_interface_cookie, | |
1610 | hdr->msg.ack.dst_wmd.wh_object_cookie); | |
1611 | if (md != NULL && md->md_me != NULL) | |
1612 | CERROR("Source MD also attached to portal %d\n", | |
1613 | md->md_me->me_portal); | |
1614 | ||
1615 | lnet_res_unlock(cpt); | |
1616 | return ENOENT; /* +ve! */ | |
1617 | } | |
1618 | ||
55f5a824 | 1619 | CDEBUG(D_NET, "%s: ACK from %s into md %#llx\n", |
d7e09d03 PT |
1620 | libcfs_nid2str(ni->ni_nid), libcfs_id2str(src), |
1621 | hdr->msg.ack.dst_wmd.wh_object_cookie); | |
1622 | ||
1623 | lnet_msg_attach_md(msg, md, 0, 0); | |
1624 | ||
1625 | lnet_res_unlock(cpt); | |
1626 | ||
1627 | lnet_build_msg_event(msg, LNET_EVENT_ACK); | |
1628 | ||
1629 | lnet_ni_recv(ni, msg->msg_private, msg, 0, 0, 0, msg->msg_len); | |
1630 | return 0; | |
1631 | } | |
1632 | ||
1633 | static int | |
1634 | lnet_parse_forward_locked(lnet_ni_t *ni, lnet_msg_t *msg) | |
1635 | { | |
7e7ab095 | 1636 | int rc = 0; |
d7e09d03 PT |
1637 | |
1638 | if (msg->msg_rxpeer->lp_rtrcredits <= 0 || | |
1639 | lnet_msg2bufpool(msg)->rbp_credits <= 0) { | |
1640 | if (ni->ni_lnd->lnd_eager_recv == NULL) { | |
1641 | msg->msg_rx_ready_delay = 1; | |
1642 | } else { | |
1643 | lnet_net_unlock(msg->msg_rx_cpt); | |
1644 | rc = lnet_ni_eager_recv(ni, msg); | |
1645 | lnet_net_lock(msg->msg_rx_cpt); | |
1646 | } | |
1647 | } | |
1648 | ||
1649 | if (rc == 0) | |
1650 | rc = lnet_post_routed_recv_locked(msg, 0); | |
1651 | return rc; | |
1652 | } | |
1653 | ||
1654 | char * | |
af66a6e2 | 1655 | lnet_msgtyp2str(int type) |
d7e09d03 PT |
1656 | { |
1657 | switch (type) { | |
1658 | case LNET_MSG_ACK: | |
2b5f2e44 | 1659 | return "ACK"; |
d7e09d03 | 1660 | case LNET_MSG_PUT: |
2b5f2e44 | 1661 | return "PUT"; |
d7e09d03 | 1662 | case LNET_MSG_GET: |
2b5f2e44 | 1663 | return "GET"; |
d7e09d03 | 1664 | case LNET_MSG_REPLY: |
2b5f2e44 | 1665 | return "REPLY"; |
d7e09d03 | 1666 | case LNET_MSG_HELLO: |
2b5f2e44 | 1667 | return "HELLO"; |
d7e09d03 | 1668 | default: |
2b5f2e44 | 1669 | return "<UNKNOWN>"; |
d7e09d03 PT |
1670 | } |
1671 | } | |
d7e09d03 PT |
1672 | |
1673 | void | |
51f01fab | 1674 | lnet_print_hdr(lnet_hdr_t *hdr) |
d7e09d03 PT |
1675 | { |
1676 | lnet_process_id_t src = {0}; | |
1677 | lnet_process_id_t dst = {0}; | |
af66a6e2 | 1678 | char *type_str = lnet_msgtyp2str(hdr->type); |
d7e09d03 PT |
1679 | |
1680 | src.nid = hdr->src_nid; | |
1681 | src.pid = hdr->src_pid; | |
1682 | ||
1683 | dst.nid = hdr->dest_nid; | |
1684 | dst.pid = hdr->dest_pid; | |
1685 | ||
1686 | CWARN("P3 Header at %p of type %s\n", hdr, type_str); | |
1687 | CWARN(" From %s\n", libcfs_id2str(src)); | |
1688 | CWARN(" To %s\n", libcfs_id2str(dst)); | |
1689 | ||
1690 | switch (hdr->type) { | |
1691 | default: | |
1692 | break; | |
1693 | ||
1694 | case LNET_MSG_PUT: | |
2d00bd17 | 1695 | CWARN(" Ptl index %d, ack md %#llx.%#llx, match bits %llu\n", |
d7e09d03 PT |
1696 | hdr->msg.put.ptl_index, |
1697 | hdr->msg.put.ack_wmd.wh_interface_cookie, | |
1698 | hdr->msg.put.ack_wmd.wh_object_cookie, | |
1699 | hdr->msg.put.match_bits); | |
55f5a824 | 1700 | CWARN(" Length %d, offset %d, hdr data %#llx\n", |
d7e09d03 PT |
1701 | hdr->payload_length, hdr->msg.put.offset, |
1702 | hdr->msg.put.hdr_data); | |
1703 | break; | |
1704 | ||
1705 | case LNET_MSG_GET: | |
2d00bd17 JP |
1706 | CWARN(" Ptl index %d, return md %#llx.%#llx, match bits %llu\n", |
1707 | hdr->msg.get.ptl_index, | |
d7e09d03 PT |
1708 | hdr->msg.get.return_wmd.wh_interface_cookie, |
1709 | hdr->msg.get.return_wmd.wh_object_cookie, | |
1710 | hdr->msg.get.match_bits); | |
1711 | CWARN(" Length %d, src offset %d\n", | |
1712 | hdr->msg.get.sink_length, | |
1713 | hdr->msg.get.src_offset); | |
1714 | break; | |
1715 | ||
1716 | case LNET_MSG_ACK: | |
2d00bd17 | 1717 | CWARN(" dst md %#llx.%#llx, manipulated length %d\n", |
d7e09d03 PT |
1718 | hdr->msg.ack.dst_wmd.wh_interface_cookie, |
1719 | hdr->msg.ack.dst_wmd.wh_object_cookie, | |
1720 | hdr->msg.ack.mlength); | |
1721 | break; | |
1722 | ||
1723 | case LNET_MSG_REPLY: | |
2d00bd17 | 1724 | CWARN(" dst md %#llx.%#llx, length %d\n", |
d7e09d03 PT |
1725 | hdr->msg.reply.dst_wmd.wh_interface_cookie, |
1726 | hdr->msg.reply.dst_wmd.wh_object_cookie, | |
1727 | hdr->payload_length); | |
1728 | } | |
1729 | ||
1730 | } | |
1731 | ||
1732 | int | |
1733 | lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid, | |
1734 | void *private, int rdma_req) | |
1735 | { | |
7e7ab095 MS |
1736 | int rc = 0; |
1737 | int cpt; | |
1738 | int for_me; | |
1739 | struct lnet_msg *msg; | |
1740 | lnet_pid_t dest_pid; | |
1741 | lnet_nid_t dest_nid; | |
1742 | lnet_nid_t src_nid; | |
1743 | __u32 payload_length; | |
1744 | __u32 type; | |
d7e09d03 | 1745 | |
af66a6e2 | 1746 | LASSERT(!in_interrupt()); |
d7e09d03 PT |
1747 | |
1748 | type = le32_to_cpu(hdr->type); | |
1749 | src_nid = le64_to_cpu(hdr->src_nid); | |
1750 | dest_nid = le64_to_cpu(hdr->dest_nid); | |
1751 | dest_pid = le32_to_cpu(hdr->dest_pid); | |
1752 | payload_length = le32_to_cpu(hdr->payload_length); | |
1753 | ||
1754 | for_me = (ni->ni_nid == dest_nid); | |
1755 | cpt = lnet_cpt_of_nid(from_nid); | |
1756 | ||
1757 | switch (type) { | |
1758 | case LNET_MSG_ACK: | |
1759 | case LNET_MSG_GET: | |
1760 | if (payload_length > 0) { | |
1761 | CERROR("%s, src %s: bad %s payload %d (0 expected)\n", | |
1762 | libcfs_nid2str(from_nid), | |
1763 | libcfs_nid2str(src_nid), | |
1764 | lnet_msgtyp2str(type), payload_length); | |
1765 | return -EPROTO; | |
1766 | } | |
1767 | break; | |
1768 | ||
1769 | case LNET_MSG_PUT: | |
1770 | case LNET_MSG_REPLY: | |
ae4003f0 LN |
1771 | if (payload_length > |
1772 | (__u32)(for_me ? LNET_MAX_PAYLOAD : LNET_MTU)) { | |
2d00bd17 | 1773 | CERROR("%s, src %s: bad %s payload %d (%d max expected)\n", |
d7e09d03 PT |
1774 | libcfs_nid2str(from_nid), |
1775 | libcfs_nid2str(src_nid), | |
1776 | lnet_msgtyp2str(type), | |
1777 | payload_length, | |
1778 | for_me ? LNET_MAX_PAYLOAD : LNET_MTU); | |
1779 | return -EPROTO; | |
1780 | } | |
1781 | break; | |
1782 | ||
1783 | default: | |
1784 | CERROR("%s, src %s: Bad message type 0x%x\n", | |
1785 | libcfs_nid2str(from_nid), | |
1786 | libcfs_nid2str(src_nid), type); | |
1787 | return -EPROTO; | |
1788 | } | |
1789 | ||
1790 | if (the_lnet.ln_routing && | |
ec0067d1 | 1791 | ni->ni_last_alive != ktime_get_real_seconds()) { |
d7e09d03 PT |
1792 | lnet_ni_lock(ni); |
1793 | ||
1794 | /* NB: so far here is the only place to set NI status to "up */ | |
ec0067d1 | 1795 | ni->ni_last_alive = ktime_get_real_seconds(); |
d7e09d03 PT |
1796 | if (ni->ni_status != NULL && |
1797 | ni->ni_status->ns_status == LNET_NI_STATUS_DOWN) | |
1798 | ni->ni_status->ns_status = LNET_NI_STATUS_UP; | |
1799 | lnet_ni_unlock(ni); | |
1800 | } | |
1801 | ||
4420cfd3 JS |
1802 | /* |
1803 | * Regard a bad destination NID as a protocol error. Senders should | |
d7e09d03 | 1804 | * know what they're doing; if they don't they're misconfigured, buggy |
4420cfd3 JS |
1805 | * or malicious so we chop them off at the knees :) |
1806 | */ | |
d7e09d03 PT |
1807 | if (!for_me) { |
1808 | if (LNET_NIDNET(dest_nid) == LNET_NIDNET(ni->ni_nid)) { | |
1809 | /* should have gone direct */ | |
2d00bd17 JP |
1810 | CERROR("%s, src %s: Bad dest nid %s (should have been sent direct)\n", |
1811 | libcfs_nid2str(from_nid), | |
1812 | libcfs_nid2str(src_nid), | |
1813 | libcfs_nid2str(dest_nid)); | |
d7e09d03 PT |
1814 | return -EPROTO; |
1815 | } | |
1816 | ||
1817 | if (lnet_islocalnid(dest_nid)) { | |
4420cfd3 JS |
1818 | /* |
1819 | * dest is another local NI; sender should have used | |
1820 | * this node's NID on its own network | |
1821 | */ | |
2d00bd17 JP |
1822 | CERROR("%s, src %s: Bad dest nid %s (it's my nid but on a different network)\n", |
1823 | libcfs_nid2str(from_nid), | |
1824 | libcfs_nid2str(src_nid), | |
1825 | libcfs_nid2str(dest_nid)); | |
d7e09d03 PT |
1826 | return -EPROTO; |
1827 | } | |
1828 | ||
1829 | if (rdma_req && type == LNET_MSG_GET) { | |
2d00bd17 JP |
1830 | CERROR("%s, src %s: Bad optimized GET for %s (final destination must be me)\n", |
1831 | libcfs_nid2str(from_nid), | |
1832 | libcfs_nid2str(src_nid), | |
1833 | libcfs_nid2str(dest_nid)); | |
d7e09d03 PT |
1834 | return -EPROTO; |
1835 | } | |
1836 | ||
1837 | if (!the_lnet.ln_routing) { | |
2d00bd17 JP |
1838 | CERROR("%s, src %s: Dropping message for %s (routing not enabled)\n", |
1839 | libcfs_nid2str(from_nid), | |
1840 | libcfs_nid2str(src_nid), | |
1841 | libcfs_nid2str(dest_nid)); | |
d7e09d03 PT |
1842 | goto drop; |
1843 | } | |
1844 | } | |
1845 | ||
4420cfd3 JS |
1846 | /* |
1847 | * Message looks OK; we're not going to return an error, so we MUST | |
1848 | * call back lnd_recv() come what may... | |
1849 | */ | |
af66a6e2 | 1850 | if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */ |
9b79ca85 | 1851 | fail_peer(src_nid, 0)) { /* shall we now? */ |
d7e09d03 PT |
1852 | CERROR("%s, src %s: Dropping %s to simulate failure\n", |
1853 | libcfs_nid2str(from_nid), libcfs_nid2str(src_nid), | |
1854 | lnet_msgtyp2str(type)); | |
1855 | goto drop; | |
1856 | } | |
1857 | ||
1858 | msg = lnet_msg_alloc(); | |
1859 | if (msg == NULL) { | |
1860 | CERROR("%s, src %s: Dropping %s (out of memory)\n", | |
1861 | libcfs_nid2str(from_nid), libcfs_nid2str(src_nid), | |
1862 | lnet_msgtyp2str(type)); | |
1863 | goto drop; | |
1864 | } | |
1865 | ||
ae4003f0 LN |
1866 | /* msg zeroed in lnet_msg_alloc; |
1867 | * i.e. flags all clear, pointers NULL etc | |
1868 | */ | |
d7e09d03 PT |
1869 | |
1870 | msg->msg_type = type; | |
1871 | msg->msg_private = private; | |
1872 | msg->msg_receiving = 1; | |
1873 | msg->msg_len = msg->msg_wanted = payload_length; | |
1874 | msg->msg_offset = 0; | |
1875 | msg->msg_hdr = *hdr; | |
1876 | /* for building message event */ | |
1877 | msg->msg_from = from_nid; | |
1878 | if (!for_me) { | |
1879 | msg->msg_target.pid = dest_pid; | |
1880 | msg->msg_target.nid = dest_nid; | |
1881 | msg->msg_routing = 1; | |
1882 | ||
1883 | } else { | |
1884 | /* convert common msg->hdr fields to host byteorder */ | |
1885 | msg->msg_hdr.type = type; | |
1886 | msg->msg_hdr.src_nid = src_nid; | |
1887 | msg->msg_hdr.src_pid = le32_to_cpu(msg->msg_hdr.src_pid); | |
1888 | msg->msg_hdr.dest_nid = dest_nid; | |
1889 | msg->msg_hdr.dest_pid = dest_pid; | |
1890 | msg->msg_hdr.payload_length = payload_length; | |
1891 | } | |
1892 | ||
1893 | lnet_net_lock(cpt); | |
1894 | rc = lnet_nid2peer_locked(&msg->msg_rxpeer, from_nid, cpt); | |
1895 | if (rc != 0) { | |
1896 | lnet_net_unlock(cpt); | |
2d00bd17 | 1897 | CERROR("%s, src %s: Dropping %s (error %d looking up sender)\n", |
d7e09d03 PT |
1898 | libcfs_nid2str(from_nid), libcfs_nid2str(src_nid), |
1899 | lnet_msgtyp2str(type), rc); | |
1900 | lnet_msg_free(msg); | |
1901 | goto drop; | |
1902 | } | |
1903 | ||
af3fa7c7 LZ |
1904 | if (lnet_isrouter(msg->msg_rxpeer)) { |
1905 | lnet_peer_set_alive(msg->msg_rxpeer); | |
1906 | if (avoid_asym_router_failure && | |
1907 | LNET_NIDNET(src_nid) != LNET_NIDNET(from_nid)) { | |
1908 | /* received a remote message from router, update | |
1909 | * remote NI status on this router. | |
1910 | * NB: multi-hop routed message will be ignored. | |
1911 | */ | |
1912 | lnet_router_ni_update_locked(msg->msg_rxpeer, | |
1913 | LNET_NIDNET(src_nid)); | |
1914 | } | |
1915 | } | |
1916 | ||
d7e09d03 PT |
1917 | lnet_msg_commit(msg, cpt); |
1918 | ||
1919 | if (!for_me) { | |
1920 | rc = lnet_parse_forward_locked(ni, msg); | |
1921 | lnet_net_unlock(cpt); | |
1922 | ||
1923 | if (rc < 0) | |
1924 | goto free_drop; | |
1925 | if (rc == 0) { | |
1926 | lnet_ni_recv(ni, msg->msg_private, msg, 0, | |
1927 | 0, payload_length, payload_length); | |
1928 | } | |
1929 | return 0; | |
1930 | } | |
1931 | ||
1932 | lnet_net_unlock(cpt); | |
1933 | ||
1934 | switch (type) { | |
1935 | case LNET_MSG_ACK: | |
1936 | rc = lnet_parse_ack(ni, msg); | |
1937 | break; | |
1938 | case LNET_MSG_PUT: | |
1939 | rc = lnet_parse_put(ni, msg); | |
1940 | break; | |
1941 | case LNET_MSG_GET: | |
1942 | rc = lnet_parse_get(ni, msg, rdma_req); | |
1943 | break; | |
1944 | case LNET_MSG_REPLY: | |
1945 | rc = lnet_parse_reply(ni, msg); | |
1946 | break; | |
1947 | default: | |
1948 | LASSERT(0); | |
1949 | rc = -EPROTO; | |
1950 | goto free_drop; /* prevent an unused label if !kernel */ | |
1951 | } | |
1952 | ||
1953 | if (rc == 0) | |
1954 | return 0; | |
1955 | ||
af66a6e2 | 1956 | LASSERT(rc == ENOENT); |
d7e09d03 PT |
1957 | |
1958 | free_drop: | |
1959 | LASSERT(msg->msg_md == NULL); | |
1960 | lnet_finalize(ni, msg, rc); | |
1961 | ||
1962 | drop: | |
1963 | lnet_drop_message(ni, cpt, private, payload_length); | |
1964 | return 0; | |
1965 | } | |
1966 | EXPORT_SYMBOL(lnet_parse); | |
1967 | ||
1968 | void | |
1969 | lnet_drop_delayed_msg_list(struct list_head *head, char *reason) | |
1970 | { | |
1971 | while (!list_empty(head)) { | |
7e7ab095 MS |
1972 | lnet_process_id_t id = {0}; |
1973 | lnet_msg_t *msg; | |
d7e09d03 PT |
1974 | |
1975 | msg = list_entry(head->next, lnet_msg_t, msg_list); | |
1976 | list_del(&msg->msg_list); | |
1977 | ||
1978 | id.nid = msg->msg_hdr.src_nid; | |
1979 | id.pid = msg->msg_hdr.src_pid; | |
1980 | ||
1981 | LASSERT(msg->msg_md == NULL); | |
1982 | LASSERT(msg->msg_rx_delayed); | |
1983 | LASSERT(msg->msg_rxpeer != NULL); | |
1984 | LASSERT(msg->msg_hdr.type == LNET_MSG_PUT); | |
1985 | ||
b0f5aad5 | 1986 | CWARN("Dropping delayed PUT from %s portal %d match %llu offset %d length %d: %s\n", |
d7e09d03 PT |
1987 | libcfs_id2str(id), |
1988 | msg->msg_hdr.msg.put.ptl_index, | |
1989 | msg->msg_hdr.msg.put.match_bits, | |
1990 | msg->msg_hdr.msg.put.offset, | |
1991 | msg->msg_hdr.payload_length, reason); | |
1992 | ||
4420cfd3 JS |
1993 | /* |
1994 | * NB I can't drop msg's ref on msg_rxpeer until after I've | |
d7e09d03 | 1995 | * called lnet_drop_message(), so I just hang onto msg as well |
4420cfd3 JS |
1996 | * until that's done |
1997 | */ | |
d7e09d03 PT |
1998 | lnet_drop_message(msg->msg_rxpeer->lp_ni, |
1999 | msg->msg_rxpeer->lp_cpt, | |
2000 | msg->msg_private, msg->msg_len); | |
2001 | /* | |
2002 | * NB: message will not generate event because w/o attached MD, | |
2003 | * but we still should give error code so lnet_msg_decommit() | |
2004 | * can skip counters operations and other checks. | |
2005 | */ | |
2006 | lnet_finalize(msg->msg_rxpeer->lp_ni, msg, -ENOENT); | |
2007 | } | |
2008 | } | |
2009 | ||
2010 | void | |
2011 | lnet_recv_delayed_msg_list(struct list_head *head) | |
2012 | { | |
2013 | while (!list_empty(head)) { | |
7e7ab095 MS |
2014 | lnet_msg_t *msg; |
2015 | lnet_process_id_t id; | |
d7e09d03 PT |
2016 | |
2017 | msg = list_entry(head->next, lnet_msg_t, msg_list); | |
2018 | list_del(&msg->msg_list); | |
2019 | ||
4420cfd3 JS |
2020 | /* |
2021 | * md won't disappear under me, since each msg | |
2022 | * holds a ref on it | |
2023 | */ | |
d7e09d03 PT |
2024 | id.nid = msg->msg_hdr.src_nid; |
2025 | id.pid = msg->msg_hdr.src_pid; | |
2026 | ||
2027 | LASSERT(msg->msg_rx_delayed); | |
2028 | LASSERT(msg->msg_md != NULL); | |
2029 | LASSERT(msg->msg_rxpeer != NULL); | |
2030 | LASSERT(msg->msg_hdr.type == LNET_MSG_PUT); | |
2031 | ||
2d00bd17 JP |
2032 | CDEBUG(D_NET, "Resuming delayed PUT from %s portal %d match %llu offset %d length %d.\n", |
2033 | libcfs_id2str(id), msg->msg_hdr.msg.put.ptl_index, | |
2034 | msg->msg_hdr.msg.put.match_bits, | |
2035 | msg->msg_hdr.msg.put.offset, | |
2036 | msg->msg_hdr.payload_length); | |
d7e09d03 PT |
2037 | |
2038 | lnet_recv_put(msg->msg_rxpeer->lp_ni, msg); | |
2039 | } | |
2040 | } | |
2041 | ||
2042 | /** | |
2043 | * Initiate an asynchronous PUT operation. | |
2044 | * | |
2045 | * There are several events associated with a PUT: completion of the send on | |
2046 | * the initiator node (LNET_EVENT_SEND), and when the send completes | |
2047 | * successfully, the receipt of an acknowledgment (LNET_EVENT_ACK) indicating | |
2048 | * that the operation was accepted by the target. The event LNET_EVENT_PUT is | |
2049 | * used at the target node to indicate the completion of incoming data | |
2050 | * delivery. | |
2051 | * | |
2052 | * The local events will be logged in the EQ associated with the MD pointed to | |
2053 | * by \a mdh handle. Using a MD without an associated EQ results in these | |
2054 | * events being discarded. In this case, the caller must have another | |
2055 | * mechanism (e.g., a higher level protocol) for determining when it is safe | |
2056 | * to modify the memory region associated with the MD. | |
2057 | * | |
2058 | * Note that LNet does not guarantee the order of LNET_EVENT_SEND and | |
2059 | * LNET_EVENT_ACK, though intuitively ACK should happen after SEND. | |
2060 | * | |
2061 | * \param self Indicates the NID of a local interface through which to send | |
2062 | * the PUT request. Use LNET_NID_ANY to let LNet choose one by itself. | |
2063 | * \param mdh A handle for the MD that describes the memory to be sent. The MD | |
2064 | * must be "free floating" (See LNetMDBind()). | |
2065 | * \param ack Controls whether an acknowledgment is requested. | |
2066 | * Acknowledgments are only sent when they are requested by the initiating | |
2067 | * process and the target MD enables them. | |
2068 | * \param target A process identifier for the target process. | |
2069 | * \param portal The index in the \a target's portal table. | |
2070 | * \param match_bits The match bits to use for MD selection at the target | |
2071 | * process. | |
2072 | * \param offset The offset into the target MD (only used when the target | |
2073 | * MD has the LNET_MD_MANAGE_REMOTE option set). | |
2074 | * \param hdr_data 64 bits of user data that can be included in the message | |
2075 | * header. This data is written to an event queue entry at the target if an | |
2076 | * EQ is present on the matching MD. | |
2077 | * | |
2078 | * \retval 0 Success, and only in this case events will be generated | |
2079 | * and logged to EQ (if it exists). | |
2080 | * \retval -EIO Simulated failure. | |
2081 | * \retval -ENOMEM Memory allocation failure. | |
2082 | * \retval -ENOENT Invalid MD object. | |
2083 | * | |
2084 | * \see lnet_event_t::hdr_data and lnet_event_kind_t. | |
2085 | */ | |
2086 | int | |
2087 | LNetPut(lnet_nid_t self, lnet_handle_md_t mdh, lnet_ack_req_t ack, | |
2088 | lnet_process_id_t target, unsigned int portal, | |
2089 | __u64 match_bits, unsigned int offset, | |
2090 | __u64 hdr_data) | |
2091 | { | |
7e7ab095 MS |
2092 | struct lnet_msg *msg; |
2093 | struct lnet_libmd *md; | |
2094 | int cpt; | |
2095 | int rc; | |
d7e09d03 | 2096 | |
af66a6e2 LN |
2097 | LASSERT(the_lnet.ln_init); |
2098 | LASSERT(the_lnet.ln_refcount > 0); | |
d7e09d03 | 2099 | |
af66a6e2 | 2100 | if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */ |
9b79ca85 | 2101 | fail_peer(target.nid, 1)) { /* shall we now? */ |
d7e09d03 PT |
2102 | CERROR("Dropping PUT to %s: simulated failure\n", |
2103 | libcfs_id2str(target)); | |
2104 | return -EIO; | |
2105 | } | |
2106 | ||
2107 | msg = lnet_msg_alloc(); | |
2108 | if (msg == NULL) { | |
2109 | CERROR("Dropping PUT to %s: ENOMEM on lnet_msg_t\n", | |
2110 | libcfs_id2str(target)); | |
2111 | return -ENOMEM; | |
2112 | } | |
2113 | msg->msg_vmflush = !!memory_pressure_get(); | |
2114 | ||
2115 | cpt = lnet_cpt_of_cookie(mdh.cookie); | |
2116 | lnet_res_lock(cpt); | |
2117 | ||
2118 | md = lnet_handle2md(&mdh); | |
2119 | if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) { | |
b0f5aad5 | 2120 | CERROR("Dropping PUT (%llu:%d:%s): MD (%d) invalid\n", |
d7e09d03 PT |
2121 | match_bits, portal, libcfs_id2str(target), |
2122 | md == NULL ? -1 : md->md_threshold); | |
2123 | if (md != NULL && md->md_me != NULL) | |
2124 | CERROR("Source MD also attached to portal %d\n", | |
2125 | md->md_me->me_portal); | |
2126 | lnet_res_unlock(cpt); | |
2127 | ||
2128 | lnet_msg_free(msg); | |
2129 | return -ENOENT; | |
2130 | } | |
2131 | ||
2132 | CDEBUG(D_NET, "LNetPut -> %s\n", libcfs_id2str(target)); | |
2133 | ||
2134 | lnet_msg_attach_md(msg, md, 0, 0); | |
2135 | ||
2136 | lnet_prep_send(msg, LNET_MSG_PUT, target, 0, md->md_length); | |
2137 | ||
2138 | msg->msg_hdr.msg.put.match_bits = cpu_to_le64(match_bits); | |
2139 | msg->msg_hdr.msg.put.ptl_index = cpu_to_le32(portal); | |
2140 | msg->msg_hdr.msg.put.offset = cpu_to_le32(offset); | |
2141 | msg->msg_hdr.msg.put.hdr_data = hdr_data; | |
2142 | ||
2143 | /* NB handles only looked up by creator (no flips) */ | |
2144 | if (ack == LNET_ACK_REQ) { | |
2145 | msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie = | |
2146 | the_lnet.ln_interface_cookie; | |
2147 | msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie = | |
2148 | md->md_lh.lh_cookie; | |
2149 | } else { | |
2150 | msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie = | |
2151 | LNET_WIRE_HANDLE_COOKIE_NONE; | |
2152 | msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie = | |
2153 | LNET_WIRE_HANDLE_COOKIE_NONE; | |
2154 | } | |
2155 | ||
2156 | lnet_res_unlock(cpt); | |
2157 | ||
2158 | lnet_build_msg_event(msg, LNET_EVENT_SEND); | |
2159 | ||
2160 | rc = lnet_send(self, msg, LNET_NID_ANY); | |
2161 | if (rc != 0) { | |
af66a6e2 | 2162 | CNETERR("Error sending PUT to %s: %d\n", |
c314c319 | 2163 | libcfs_id2str(target), rc); |
af66a6e2 | 2164 | lnet_finalize(NULL, msg, rc); |
d7e09d03 PT |
2165 | } |
2166 | ||
2167 | /* completion will be signalled by an event */ | |
2168 | return 0; | |
2169 | } | |
2170 | EXPORT_SYMBOL(LNetPut); | |
2171 | ||
2172 | lnet_msg_t * | |
af66a6e2 | 2173 | lnet_create_reply_msg(lnet_ni_t *ni, lnet_msg_t *getmsg) |
d7e09d03 | 2174 | { |
4420cfd3 JS |
2175 | /* |
2176 | * The LND can DMA direct to the GET md (i.e. no REPLY msg). This | |
d7e09d03 PT |
2177 | * returns a msg for the LND to pass to lnet_finalize() when the sink |
2178 | * data has been received. | |
2179 | * | |
2180 | * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when | |
4420cfd3 JS |
2181 | * lnet_finalize() is called on it, so the LND must call this first |
2182 | */ | |
7e7ab095 MS |
2183 | struct lnet_msg *msg = lnet_msg_alloc(); |
2184 | struct lnet_libmd *getmd = getmsg->msg_md; | |
2185 | lnet_process_id_t peer_id = getmsg->msg_target; | |
2186 | int cpt; | |
d7e09d03 PT |
2187 | |
2188 | LASSERT(!getmsg->msg_target_is_router); | |
2189 | LASSERT(!getmsg->msg_routing); | |
2190 | ||
2191 | cpt = lnet_cpt_of_cookie(getmd->md_lh.lh_cookie); | |
2192 | lnet_res_lock(cpt); | |
2193 | ||
af66a6e2 | 2194 | LASSERT(getmd->md_refcount > 0); |
d7e09d03 PT |
2195 | |
2196 | if (msg == NULL) { | |
af66a6e2 | 2197 | CERROR("%s: Dropping REPLY from %s: can't allocate msg\n", |
c314c319 | 2198 | libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id)); |
d7e09d03 PT |
2199 | goto drop; |
2200 | } | |
2201 | ||
2202 | if (getmd->md_threshold == 0) { | |
af66a6e2 | 2203 | CERROR("%s: Dropping REPLY from %s for inactive MD %p\n", |
c314c319 JS |
2204 | libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id), |
2205 | getmd); | |
d7e09d03 PT |
2206 | lnet_res_unlock(cpt); |
2207 | goto drop; | |
2208 | } | |
2209 | ||
2210 | LASSERT(getmd->md_offset == 0); | |
2211 | ||
2212 | CDEBUG(D_NET, "%s: Reply from %s md %p\n", | |
2213 | libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id), getmd); | |
2214 | ||
2215 | /* setup information for lnet_build_msg_event */ | |
2216 | msg->msg_from = peer_id.nid; | |
2217 | msg->msg_type = LNET_MSG_GET; /* flag this msg as an "optimized" GET */ | |
2218 | msg->msg_hdr.src_nid = peer_id.nid; | |
2219 | msg->msg_hdr.payload_length = getmd->md_length; | |
2220 | msg->msg_receiving = 1; /* required by lnet_msg_attach_md */ | |
2221 | ||
2222 | lnet_msg_attach_md(msg, getmd, getmd->md_offset, getmd->md_length); | |
2223 | lnet_res_unlock(cpt); | |
2224 | ||
2225 | cpt = lnet_cpt_of_nid(peer_id.nid); | |
2226 | ||
2227 | lnet_net_lock(cpt); | |
2228 | lnet_msg_commit(msg, cpt); | |
2229 | lnet_net_unlock(cpt); | |
2230 | ||
2231 | lnet_build_msg_event(msg, LNET_EVENT_REPLY); | |
2232 | ||
2233 | return msg; | |
2234 | ||
2235 | drop: | |
2236 | cpt = lnet_cpt_of_nid(peer_id.nid); | |
2237 | ||
2238 | lnet_net_lock(cpt); | |
2239 | the_lnet.ln_counters[cpt]->drop_count++; | |
2240 | the_lnet.ln_counters[cpt]->drop_length += getmd->md_length; | |
2241 | lnet_net_unlock(cpt); | |
2242 | ||
2243 | if (msg != NULL) | |
2244 | lnet_msg_free(msg); | |
2245 | ||
2246 | return NULL; | |
2247 | } | |
2248 | EXPORT_SYMBOL(lnet_create_reply_msg); | |
2249 | ||
2250 | void | |
2251 | lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *reply, unsigned int len) | |
2252 | { | |
4420cfd3 JS |
2253 | /* |
2254 | * Set the REPLY length, now the RDMA that elides the REPLY message has | |
2255 | * completed and I know it. | |
2256 | */ | |
af66a6e2 LN |
2257 | LASSERT(reply != NULL); |
2258 | LASSERT(reply->msg_type == LNET_MSG_GET); | |
2259 | LASSERT(reply->msg_ev.type == LNET_EVENT_REPLY); | |
d7e09d03 | 2260 | |
4420cfd3 JS |
2261 | /* |
2262 | * NB I trusted my peer to RDMA. If she tells me she's written beyond | |
2263 | * the end of my buffer, I might as well be dead. | |
2264 | */ | |
af66a6e2 | 2265 | LASSERT(len <= reply->msg_ev.mlength); |
d7e09d03 PT |
2266 | |
2267 | reply->msg_ev.mlength = len; | |
2268 | } | |
2269 | EXPORT_SYMBOL(lnet_set_reply_msg_len); | |
2270 | ||
2271 | /** | |
2272 | * Initiate an asynchronous GET operation. | |
2273 | * | |
2274 | * On the initiator node, an LNET_EVENT_SEND is logged when the GET request | |
2275 | * is sent, and an LNET_EVENT_REPLY is logged when the data returned from | |
2276 | * the target node in the REPLY has been written to local MD. | |
2277 | * | |
2278 | * On the target node, an LNET_EVENT_GET is logged when the GET request | |
2279 | * arrives and is accepted into a MD. | |
2280 | * | |
2281 | * \param self,target,portal,match_bits,offset See the discussion in LNetPut(). | |
2282 | * \param mdh A handle for the MD that describes the memory into which the | |
ae4003f0 LN |
2283 | * requested data will be received. The MD must be "free floating" |
2284 | * (See LNetMDBind()). | |
d7e09d03 PT |
2285 | * |
2286 | * \retval 0 Success, and only in this case events will be generated | |
2287 | * and logged to EQ (if it exists) of the MD. | |
2288 | * \retval -EIO Simulated failure. | |
2289 | * \retval -ENOMEM Memory allocation failure. | |
2290 | * \retval -ENOENT Invalid MD object. | |
2291 | */ | |
2292 | int | |
2293 | LNetGet(lnet_nid_t self, lnet_handle_md_t mdh, | |
2294 | lnet_process_id_t target, unsigned int portal, | |
2295 | __u64 match_bits, unsigned int offset) | |
2296 | { | |
7e7ab095 MS |
2297 | struct lnet_msg *msg; |
2298 | struct lnet_libmd *md; | |
2299 | int cpt; | |
2300 | int rc; | |
d7e09d03 | 2301 | |
af66a6e2 LN |
2302 | LASSERT(the_lnet.ln_init); |
2303 | LASSERT(the_lnet.ln_refcount > 0); | |
d7e09d03 | 2304 | |
af66a6e2 | 2305 | if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */ |
9b79ca85 | 2306 | fail_peer(target.nid, 1)) { /* shall we now? */ |
d7e09d03 PT |
2307 | CERROR("Dropping GET to %s: simulated failure\n", |
2308 | libcfs_id2str(target)); | |
2309 | return -EIO; | |
2310 | } | |
2311 | ||
2312 | msg = lnet_msg_alloc(); | |
2313 | if (msg == NULL) { | |
2314 | CERROR("Dropping GET to %s: ENOMEM on lnet_msg_t\n", | |
2315 | libcfs_id2str(target)); | |
2316 | return -ENOMEM; | |
2317 | } | |
2318 | ||
2319 | cpt = lnet_cpt_of_cookie(mdh.cookie); | |
2320 | lnet_res_lock(cpt); | |
2321 | ||
2322 | md = lnet_handle2md(&mdh); | |
2323 | if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) { | |
b0f5aad5 | 2324 | CERROR("Dropping GET (%llu:%d:%s): MD (%d) invalid\n", |
d7e09d03 PT |
2325 | match_bits, portal, libcfs_id2str(target), |
2326 | md == NULL ? -1 : md->md_threshold); | |
2327 | if (md != NULL && md->md_me != NULL) | |
2328 | CERROR("REPLY MD also attached to portal %d\n", | |
2329 | md->md_me->me_portal); | |
2330 | ||
2331 | lnet_res_unlock(cpt); | |
2332 | ||
2333 | lnet_msg_free(msg); | |
d7e09d03 PT |
2334 | return -ENOENT; |
2335 | } | |
2336 | ||
2337 | CDEBUG(D_NET, "LNetGet -> %s\n", libcfs_id2str(target)); | |
2338 | ||
2339 | lnet_msg_attach_md(msg, md, 0, 0); | |
2340 | ||
2341 | lnet_prep_send(msg, LNET_MSG_GET, target, 0, 0); | |
2342 | ||
2343 | msg->msg_hdr.msg.get.match_bits = cpu_to_le64(match_bits); | |
2344 | msg->msg_hdr.msg.get.ptl_index = cpu_to_le32(portal); | |
2345 | msg->msg_hdr.msg.get.src_offset = cpu_to_le32(offset); | |
2346 | msg->msg_hdr.msg.get.sink_length = cpu_to_le32(md->md_length); | |
2347 | ||
2348 | /* NB handles only looked up by creator (no flips) */ | |
2349 | msg->msg_hdr.msg.get.return_wmd.wh_interface_cookie = | |
2350 | the_lnet.ln_interface_cookie; | |
2351 | msg->msg_hdr.msg.get.return_wmd.wh_object_cookie = | |
2352 | md->md_lh.lh_cookie; | |
2353 | ||
2354 | lnet_res_unlock(cpt); | |
2355 | ||
2356 | lnet_build_msg_event(msg, LNET_EVENT_SEND); | |
2357 | ||
2358 | rc = lnet_send(self, msg, LNET_NID_ANY); | |
2359 | if (rc < 0) { | |
af66a6e2 | 2360 | CNETERR("Error sending GET to %s: %d\n", |
c314c319 | 2361 | libcfs_id2str(target), rc); |
af66a6e2 | 2362 | lnet_finalize(NULL, msg, rc); |
d7e09d03 PT |
2363 | } |
2364 | ||
2365 | /* completion will be signalled by an event */ | |
2366 | return 0; | |
2367 | } | |
2368 | EXPORT_SYMBOL(LNetGet); | |
2369 | ||
2370 | /** | |
2371 | * Calculate distance to node at \a dstnid. | |
2372 | * | |
2373 | * \param dstnid Target NID. | |
2374 | * \param srcnidp If not NULL, NID of the local interface to reach \a dstnid | |
2375 | * is saved here. | |
2376 | * \param orderp If not NULL, order of the route to reach \a dstnid is saved | |
2377 | * here. | |
2378 | * | |
2379 | * \retval 0 If \a dstnid belongs to a local interface, and reserved option | |
2380 | * local_nid_dist_zero is set, which is the default. | |
2381 | * \retval positives Distance to target NID, i.e. number of hops plus one. | |
2382 | * \retval -EHOSTUNREACH If \a dstnid is not reachable. | |
2383 | */ | |
2384 | int | |
2385 | LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp) | |
2386 | { | |
7e7ab095 MS |
2387 | struct list_head *e; |
2388 | struct lnet_ni *ni; | |
2389 | lnet_remotenet_t *rnet; | |
2390 | __u32 dstnet = LNET_NIDNET(dstnid); | |
2391 | int hops; | |
2392 | int cpt; | |
2393 | __u32 order = 2; | |
2394 | struct list_head *rn_list; | |
d7e09d03 | 2395 | |
4420cfd3 JS |
2396 | /* |
2397 | * if !local_nid_dist_zero, I don't return a distance of 0 ever | |
d7e09d03 PT |
2398 | * (when lustre sees a distance of 0, it substitutes 0@lo), so I |
2399 | * keep order 0 free for 0@lo and order 1 free for a local NID | |
4420cfd3 JS |
2400 | * match |
2401 | */ | |
af66a6e2 LN |
2402 | LASSERT(the_lnet.ln_init); |
2403 | LASSERT(the_lnet.ln_refcount > 0); | |
d7e09d03 PT |
2404 | |
2405 | cpt = lnet_net_lock_current(); | |
2406 | ||
af66a6e2 | 2407 | list_for_each(e, &the_lnet.ln_nis) { |
d7e09d03 PT |
2408 | ni = list_entry(e, lnet_ni_t, ni_list); |
2409 | ||
2410 | if (ni->ni_nid == dstnid) { | |
2411 | if (srcnidp != NULL) | |
2412 | *srcnidp = dstnid; | |
2413 | if (orderp != NULL) { | |
2414 | if (LNET_NETTYP(LNET_NIDNET(dstnid)) == LOLND) | |
2415 | *orderp = 0; | |
2416 | else | |
2417 | *orderp = 1; | |
2418 | } | |
2419 | lnet_net_unlock(cpt); | |
2420 | ||
2421 | return local_nid_dist_zero ? 0 : 1; | |
2422 | } | |
2423 | ||
2424 | if (LNET_NIDNET(ni->ni_nid) == dstnet) { | |
2425 | if (srcnidp != NULL) | |
2426 | *srcnidp = ni->ni_nid; | |
2427 | if (orderp != NULL) | |
2428 | *orderp = order; | |
2429 | lnet_net_unlock(cpt); | |
2430 | return 1; | |
2431 | } | |
2432 | ||
2433 | order++; | |
2434 | } | |
2435 | ||
2436 | rn_list = lnet_net2rnethash(dstnet); | |
2437 | list_for_each(e, rn_list) { | |
2438 | rnet = list_entry(e, lnet_remotenet_t, lrn_list); | |
2439 | ||
2440 | if (rnet->lrn_net == dstnet) { | |
2441 | lnet_route_t *route; | |
2442 | lnet_route_t *shortest = NULL; | |
2443 | ||
af66a6e2 | 2444 | LASSERT(!list_empty(&rnet->lrn_routes)); |
d7e09d03 PT |
2445 | |
2446 | list_for_each_entry(route, &rnet->lrn_routes, | |
c314c319 | 2447 | lr_list) { |
d7e09d03 PT |
2448 | if (shortest == NULL || |
2449 | route->lr_hops < shortest->lr_hops) | |
2450 | shortest = route; | |
2451 | } | |
2452 | ||
af66a6e2 | 2453 | LASSERT(shortest != NULL); |
d7e09d03 PT |
2454 | hops = shortest->lr_hops; |
2455 | if (srcnidp != NULL) | |
2456 | *srcnidp = shortest->lr_gateway->lp_ni->ni_nid; | |
2457 | if (orderp != NULL) | |
2458 | *orderp = order; | |
2459 | lnet_net_unlock(cpt); | |
2460 | return hops + 1; | |
2461 | } | |
2462 | order++; | |
2463 | } | |
2464 | ||
2465 | lnet_net_unlock(cpt); | |
2466 | return -EHOSTUNREACH; | |
2467 | } | |
2468 | EXPORT_SYMBOL(LNetDist); |