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