4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
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
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_RPC
39 #include <liblustre.h>
41 #include <obd_support.h>
42 #include <lustre_net.h>
43 #include <lustre_lib.h>
45 #include <obd_class.h>
46 #include "ptlrpc_internal.h"
49 * Helper function. Sends \a len bytes from \a base at offset \a offset
50 * over \a conn connection to portal \a portal.
51 * Returns 0 on success or error code.
53 static int ptl_send_buf (lnet_handle_md_t *mdh, void *base, int len,
54 lnet_ack_req_t ack, struct ptlrpc_cb_id *cbid,
55 struct ptlrpc_connection *conn, int portal, __u64 xid,
62 LASSERT (portal != 0);
63 LASSERT (conn != NULL);
64 CDEBUG (D_INFO, "conn=%p id %s\n", conn, libcfs_id2str(conn->c_peer));
67 md.threshold = (ack == LNET_ACK_REQ) ? 2 : 1;
68 md.options = PTLRPC_MD_OPTIONS;
70 md.eq_handle = ptlrpc_eq_h;
72 if (unlikely(ack == LNET_ACK_REQ &&
73 OBD_FAIL_CHECK_ORSET(OBD_FAIL_PTLRPC_ACK, OBD_FAIL_ONCE))){
74 /* don't ask for the ack to simulate failing client */
78 rc = LNetMDBind (md, LNET_UNLINK, mdh);
79 if (unlikely(rc != 0)) {
80 CERROR ("LNetMDBind failed: %d\n", rc);
81 LASSERT (rc == -ENOMEM);
85 CDEBUG(D_NET, "Sending %d bytes to portal %d, xid "LPD64", offset %u\n",
86 len, portal, xid, offset);
88 rc = LNetPut (conn->c_self, *mdh, ack,
89 conn->c_peer, portal, xid, offset, 0);
90 if (unlikely(rc != 0)) {
92 /* We're going to get an UNLINK event when I unlink below,
93 * which will complete just like any other failed send, so
94 * I fall through and return success here! */
95 CERROR("LNetPut(%s, %d, "LPD64") failed: %d\n",
96 libcfs_id2str(conn->c_peer), portal, xid, rc);
97 rc2 = LNetMDUnlink(*mdh);
98 LASSERTF(rc2 == 0, "rc2 = %d\n", rc2);
104 #ifdef HAVE_SERVER_SUPPORT
106 * Prepare bulk descriptor for specified incoming request \a req that
107 * can fit \a npages * pages. \a type is bulk type. \a portal is where
108 * the bulk to be sent. Used on server-side after request was already
110 * Returns pointer to newly allocatrd initialized bulk descriptor or NULL on
113 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
114 int npages, int type, int portal)
116 struct obd_export *exp = req->rq_export;
117 struct ptlrpc_bulk_desc *desc;
120 LASSERT(type == BULK_PUT_SOURCE || type == BULK_GET_SINK);
122 desc = new_bulk(npages, type, portal);
126 desc->bd_export = class_export_get(exp);
129 desc->bd_cbid.cbid_fn = server_bulk_callback;
130 desc->bd_cbid.cbid_arg = desc;
132 /* NB we don't assign rq_bulk here; server-side requests are
133 * re-used, and the handler frees the bulk desc explicitly. */
137 EXPORT_SYMBOL(ptlrpc_prep_bulk_exp);
140 * Starts bulk transfer for descriptor \a desc
141 * Returns 0 on success or error code.
143 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc)
145 struct ptlrpc_connection *conn = desc->bd_export->exp_connection;
152 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_BULK_PUT_NET))
155 /* NB no locking required until desc is on the network */
156 LASSERT (!desc->bd_network_rw);
157 LASSERT (desc->bd_type == BULK_PUT_SOURCE ||
158 desc->bd_type == BULK_GET_SINK);
159 desc->bd_success = 0;
161 md.user_ptr = &desc->bd_cbid;
162 md.eq_handle = ptlrpc_eq_h;
163 md.threshold = 2; /* SENT and ACK/REPLY */
164 md.options = PTLRPC_MD_OPTIONS;
165 ptlrpc_fill_bulk_md(&md, desc);
167 LASSERT (desc->bd_cbid.cbid_fn == server_bulk_callback);
168 LASSERT (desc->bd_cbid.cbid_arg == desc);
170 /* NB total length may be 0 for a read past EOF, so we send a 0
171 * length bulk, since the client expects a bulk event. */
173 rc = LNetMDBind(md, LNET_UNLINK, &desc->bd_md_h);
175 CERROR("LNetMDBind failed: %d\n", rc);
176 LASSERT (rc == -ENOMEM);
180 /* Client's bulk and reply matchbits are the same */
181 xid = desc->bd_req->rq_xid;
182 CDEBUG(D_NET, "Transferring %u pages %u bytes via portal %d "
183 "id %s xid "LPX64"\n", desc->bd_iov_count,
184 desc->bd_nob, desc->bd_portal,
185 libcfs_id2str(conn->c_peer), xid);
187 /* Network is about to get at the memory */
188 desc->bd_network_rw = 1;
190 if (desc->bd_type == BULK_PUT_SOURCE)
191 rc = LNetPut (conn->c_self, desc->bd_md_h, LNET_ACK_REQ,
192 conn->c_peer, desc->bd_portal, xid, 0, 0);
194 rc = LNetGet (conn->c_self, desc->bd_md_h,
195 conn->c_peer, desc->bd_portal, xid, 0);
198 /* Can't send, so we unlink the MD bound above. The UNLINK
199 * event this creates will signal completion with failure,
200 * so we return SUCCESS here! */
201 CERROR("Transfer(%s, %d, "LPX64") failed: %d\n",
202 libcfs_id2str(conn->c_peer), desc->bd_portal, xid, rc);
203 rc2 = LNetMDUnlink(desc->bd_md_h);
209 EXPORT_SYMBOL(ptlrpc_start_bulk_transfer);
212 * Server side bulk abort. Idempotent. Not thread-safe (i.e. only
213 * serialises with completion callback)
215 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc)
217 struct l_wait_info lwi;
220 LASSERT(!cfs_in_interrupt()); /* might sleep */
222 if (!ptlrpc_server_bulk_active(desc)) /* completed or */
223 return; /* never started */
225 /* We used to poison the pages with 0xab here because we did not want to
226 * send any meaningful data over the wire for evicted clients (bug 9297)
227 * However, this is no longer safe now that we use the page cache on the
230 /* The unlink ensures the callback happens ASAP and is the last
231 * one. If it fails, it must be because completion just happened,
232 * but we must still l_wait_event() in this case, to give liblustre
233 * a chance to run server_bulk_callback()*/
235 LNetMDUnlink(desc->bd_md_h);
238 /* Network access will complete in finite time but the HUGE
239 * timeout lets us CWARN for visibility of sluggish NALs */
240 lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(LONG_UNLINK),
241 cfs_time_seconds(1), NULL, NULL);
242 rc = l_wait_event(desc->bd_waitq,
243 !ptlrpc_server_bulk_active(desc), &lwi);
247 LASSERT(rc == -ETIMEDOUT);
248 CWARN("Unexpectedly long timeout: desc %p\n", desc);
251 EXPORT_SYMBOL(ptlrpc_abort_bulk);
252 #endif /* HAVE_SERVER_SUPPORT */
255 * Register bulk for later transfer
256 * Returns 0 on success or error code.
258 int ptlrpc_register_bulk(struct ptlrpc_request *req)
260 struct ptlrpc_bulk_desc *desc = req->rq_bulk;
261 lnet_process_id_t peer;
264 lnet_handle_me_t me_h;
268 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_BULK_GET_NET))
271 /* NB no locking required until desc is on the network */
272 LASSERT (desc->bd_nob > 0);
273 LASSERT (!desc->bd_network_rw);
274 LASSERT (desc->bd_iov_count <= PTLRPC_MAX_BRW_PAGES);
275 LASSERT (desc->bd_req != NULL);
276 LASSERT (desc->bd_type == BULK_PUT_SINK ||
277 desc->bd_type == BULK_GET_SOURCE);
279 desc->bd_success = 0;
281 peer = desc->bd_import->imp_connection->c_peer;
283 md.user_ptr = &desc->bd_cbid;
284 md.eq_handle = ptlrpc_eq_h;
285 md.threshold = 1; /* PUT or GET */
286 md.options = PTLRPC_MD_OPTIONS |
287 ((desc->bd_type == BULK_GET_SOURCE) ?
288 LNET_MD_OP_GET : LNET_MD_OP_PUT);
289 ptlrpc_fill_bulk_md(&md, desc);
291 LASSERT (desc->bd_cbid.cbid_fn == client_bulk_callback);
292 LASSERT (desc->bd_cbid.cbid_arg == desc);
294 /* XXX Registering the same xid on retried bulk makes my head
295 * explode trying to understand how the original request's bulk
296 * might interfere with the retried request -eeb
297 * On the other hand replaying with the same xid is fine, since
298 * we are guaranteed old request have completed. -green */
299 LASSERTF(!(desc->bd_registered &&
300 req->rq_send_state != LUSTRE_IMP_REPLAY) ||
301 req->rq_xid != desc->bd_last_xid,
302 "registered: %d rq_xid: "LPU64" bd_last_xid: "LPU64"\n",
303 desc->bd_registered, req->rq_xid, desc->bd_last_xid);
304 desc->bd_registered = 1;
305 desc->bd_last_xid = req->rq_xid;
307 rc = LNetMEAttach(desc->bd_portal, peer,
308 req->rq_xid, 0, LNET_UNLINK, LNET_INS_AFTER, &me_h);
310 CERROR("LNetMEAttach failed: %d\n", rc);
311 LASSERT (rc == -ENOMEM);
315 /* About to let the network at it... */
316 desc->bd_network_rw = 1;
317 rc = LNetMDAttach(me_h, md, LNET_UNLINK, &desc->bd_md_h);
319 CERROR("LNetMDAttach failed: %d\n", rc);
320 LASSERT (rc == -ENOMEM);
321 desc->bd_network_rw = 0;
322 rc2 = LNetMEUnlink (me_h);
327 CDEBUG(D_NET, "Setup bulk %s buffers: %u pages %u bytes, xid "LPU64", "
329 desc->bd_type == BULK_GET_SOURCE ? "get-source" : "put-sink",
330 desc->bd_iov_count, desc->bd_nob,
331 req->rq_xid, desc->bd_portal);
334 EXPORT_SYMBOL(ptlrpc_register_bulk);
337 * Disconnect a bulk desc from the network. Idempotent. Not
338 * thread-safe (i.e. only interlocks with completion callback).
339 * Returns 1 on success or 0 if network unregistration failed for whatever
342 int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async)
344 struct ptlrpc_bulk_desc *desc = req->rq_bulk;
346 struct l_wait_info lwi;
350 LASSERT(!cfs_in_interrupt()); /* might sleep */
352 /* Let's setup deadline for reply unlink. */
353 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) &&
354 async && req->rq_bulk_deadline == 0)
355 req->rq_bulk_deadline = cfs_time_current_sec() + LONG_UNLINK;
357 if (!ptlrpc_client_bulk_active(req)) /* completed or */
358 RETURN(1); /* never registered */
360 LASSERT(desc->bd_req == req); /* bd_req NULL until registered */
362 /* the unlink ensures the callback happens ASAP and is the last
363 * one. If it fails, it must be because completion just happened,
364 * but we must still l_wait_event() in this case to give liblustre
365 * a chance to run client_bulk_callback() */
367 LNetMDUnlink(desc->bd_md_h);
369 if (!ptlrpc_client_bulk_active(req)) /* completed or */
370 RETURN(1); /* never registered */
372 /* Move to "Unregistering" phase as bulk was not unlinked yet. */
373 ptlrpc_rqphase_move(req, RQ_PHASE_UNREGISTERING);
375 /* Do not wait for unlink to finish. */
379 if (req->rq_set != NULL)
380 wq = &req->rq_set->set_waitq;
382 wq = &req->rq_reply_waitq;
385 /* Network access will complete in finite time but the HUGE
386 * timeout lets us CWARN for visibility of sluggish NALs */
387 lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(LONG_UNLINK),
388 cfs_time_seconds(1), NULL, NULL);
389 rc = l_wait_event(*wq, !ptlrpc_client_bulk_active(req), &lwi);
391 ptlrpc_rqphase_move(req, req->rq_next_phase);
395 LASSERT(rc == -ETIMEDOUT);
396 DEBUG_REQ(D_WARNING, req, "Unexpectedly long timeout: desc %p",
401 EXPORT_SYMBOL(ptlrpc_unregister_bulk);
403 static void ptlrpc_at_set_reply(struct ptlrpc_request *req, int flags)
405 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
406 struct ptlrpc_service *svc = svcpt->scp_service;
407 int service_time = max_t(int, cfs_time_current_sec() -
408 req->rq_arrival_time.tv_sec, 1);
410 if (!(flags & PTLRPC_REPLY_EARLY) &&
411 (req->rq_type != PTL_RPC_MSG_ERR) &&
412 (req->rq_reqmsg != NULL) &&
413 !(lustre_msg_get_flags(req->rq_reqmsg) &
414 (MSG_RESENT | MSG_REPLAY |
415 MSG_REQ_REPLAY_DONE | MSG_LOCK_REPLAY_DONE))) {
416 /* early replies, errors and recovery requests don't count
417 * toward our service time estimate */
418 int oldse = at_measured(&svcpt->scp_at_estimate, service_time);
421 DEBUG_REQ(D_ADAPTTO, req,
422 "svc %s changed estimate from %d to %d",
423 svc->srv_name, oldse,
424 at_get(&svcpt->scp_at_estimate));
427 /* Report actual service time for client latency calc */
428 lustre_msg_set_service_time(req->rq_repmsg, service_time);
429 /* Report service time estimate for future client reqs, but report 0
430 * (to be ignored by client) if it's a error reply during recovery.
432 if (req->rq_type == PTL_RPC_MSG_ERR &&
433 (req->rq_export == NULL || req->rq_export->exp_obd->obd_recovering))
434 lustre_msg_set_timeout(req->rq_repmsg, 0);
436 lustre_msg_set_timeout(req->rq_repmsg,
437 at_get(&svcpt->scp_at_estimate));
439 if (req->rq_reqmsg &&
440 !(lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)) {
441 CDEBUG(D_ADAPTTO, "No early reply support: flags=%#x "
442 "req_flags=%#x magic=%d:%x/%x len=%d\n",
443 flags, lustre_msg_get_flags(req->rq_reqmsg),
444 lustre_msg_is_v1(req->rq_reqmsg),
445 lustre_msg_get_magic(req->rq_reqmsg),
446 lustre_msg_get_magic(req->rq_repmsg), req->rq_replen);
451 * Send request reply from request \a req reply buffer.
452 * \a flags defines reply types
453 * Returns 0 on sucess or error code
455 int ptlrpc_send_reply(struct ptlrpc_request *req, int flags)
457 struct ptlrpc_reply_state *rs = req->rq_reply_state;
458 struct ptlrpc_connection *conn;
461 /* We must already have a reply buffer (only ptlrpc_error() may be
462 * called without one). The reply generated by sptlrpc layer (e.g.
463 * error notify, etc.) might have NULL rq->reqmsg; Otherwise we must
464 * have a request buffer which is either the actual (swabbed) incoming
465 * request, or a saved copy if this is a req saved in
466 * target_queue_final_reply().
468 LASSERT (req->rq_no_reply == 0);
469 LASSERT (req->rq_reqbuf != NULL);
470 LASSERT (rs != NULL);
471 LASSERT ((flags & PTLRPC_REPLY_MAYBE_DIFFICULT) || !rs->rs_difficult);
472 LASSERT (req->rq_repmsg != NULL);
473 LASSERT (req->rq_repmsg == rs->rs_msg);
474 LASSERT (rs->rs_cb_id.cbid_fn == reply_out_callback);
475 LASSERT (rs->rs_cb_id.cbid_arg == rs);
477 /* There may be no rq_export during failover */
479 if (unlikely(req->rq_export && req->rq_export->exp_obd &&
480 req->rq_export->exp_obd->obd_fail)) {
481 /* Failed obd's only send ENODEV */
482 req->rq_type = PTL_RPC_MSG_ERR;
483 req->rq_status = -ENODEV;
484 CDEBUG(D_HA, "sending ENODEV from failed obd %d\n",
485 req->rq_export->exp_obd->obd_minor);
488 /* In order to keep interoprability with the client (< 2.3) which
489 * doesn't have pb_jobid in ptlrpc_body, We have to shrink the
490 * ptlrpc_body in reply buffer to ptlrpc_body_v2, otherwise, the
491 * reply buffer on client will be overflow.
493 * XXX Remove this whenver we drop the interoprability with such client.
495 req->rq_replen = lustre_shrink_msg(req->rq_repmsg, 0,
496 sizeof(struct ptlrpc_body_v2), 1);
498 if (req->rq_type != PTL_RPC_MSG_ERR)
499 req->rq_type = PTL_RPC_MSG_REPLY;
501 lustre_msg_set_type(req->rq_repmsg, req->rq_type);
502 lustre_msg_set_status(req->rq_repmsg, req->rq_status);
503 lustre_msg_set_opc(req->rq_repmsg,
504 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : 0);
506 target_pack_pool_reply(req);
508 ptlrpc_at_set_reply(req, flags);
510 if (req->rq_export == NULL || req->rq_export->exp_connection == NULL)
511 conn = ptlrpc_connection_get(req->rq_peer, req->rq_self, NULL);
513 conn = ptlrpc_connection_addref(req->rq_export->exp_connection);
515 if (unlikely(conn == NULL)) {
516 CERROR("not replying on NULL connection\n"); /* bug 9635 */
519 ptlrpc_rs_addref(rs); /* +1 ref for the network */
521 rc = sptlrpc_svc_wrap_reply(req);
525 req->rq_sent = cfs_time_current_sec();
527 rc = ptl_send_buf (&rs->rs_md_h, rs->rs_repbuf, rs->rs_repdata_len,
528 (rs->rs_difficult && !rs->rs_no_ack) ?
529 LNET_ACK_REQ : LNET_NOACK_REQ,
531 ptlrpc_req2svc(req)->srv_rep_portal,
532 req->rq_xid, req->rq_reply_off);
534 if (unlikely(rc != 0))
535 ptlrpc_req_drop_rs(req);
536 ptlrpc_connection_put(conn);
539 EXPORT_SYMBOL(ptlrpc_send_reply);
541 int ptlrpc_reply (struct ptlrpc_request *req)
543 if (req->rq_no_reply)
546 return (ptlrpc_send_reply(req, 0));
548 EXPORT_SYMBOL(ptlrpc_reply);
551 * For request \a req send an error reply back. Create empty
552 * reply buffers if necessary.
554 int ptlrpc_send_error(struct ptlrpc_request *req, int may_be_difficult)
559 if (req->rq_no_reply)
562 if (!req->rq_repmsg) {
563 rc = lustre_pack_reply(req, 1, NULL, NULL);
568 if (req->rq_status != -ENOSPC && req->rq_status != -EACCES &&
569 req->rq_status != -EPERM && req->rq_status != -ENOENT &&
570 req->rq_status != -EINPROGRESS && req->rq_status != -EDQUOT)
571 req->rq_type = PTL_RPC_MSG_ERR;
573 rc = ptlrpc_send_reply(req, may_be_difficult);
576 EXPORT_SYMBOL(ptlrpc_send_error);
578 int ptlrpc_error(struct ptlrpc_request *req)
580 return ptlrpc_send_error(req, 0);
582 EXPORT_SYMBOL(ptlrpc_error);
585 * Send request \a request.
586 * if \a noreply is set, don't expect any reply back and don't set up
588 * Returns 0 on success or error code.
590 int ptl_send_rpc(struct ptlrpc_request *request, int noreply)
595 struct ptlrpc_connection *connection;
596 lnet_handle_me_t reply_me_h;
598 struct obd_device *obd = request->rq_import->imp_obd;
601 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_DROP_RPC))
604 LASSERT(request->rq_type == PTL_RPC_MSG_REQUEST);
605 LASSERT(request->rq_wait_ctx == 0);
607 /* If this is a re-transmit, we're required to have disengaged
608 * cleanly from the previous attempt */
609 LASSERT(!request->rq_receiving_reply);
611 if (request->rq_import->imp_obd &&
612 request->rq_import->imp_obd->obd_fail) {
613 CDEBUG(D_HA, "muting rpc for failed imp obd %s\n",
614 request->rq_import->imp_obd->obd_name);
615 /* this prevents us from waiting in ptlrpc_queue_wait */
617 request->rq_status = -ENODEV;
621 connection = request->rq_import->imp_connection;
623 lustre_msg_set_handle(request->rq_reqmsg,
624 &request->rq_import->imp_remote_handle);
625 lustre_msg_set_type(request->rq_reqmsg, PTL_RPC_MSG_REQUEST);
626 lustre_msg_set_conn_cnt(request->rq_reqmsg,
627 request->rq_import->imp_conn_cnt);
628 lustre_msghdr_set_flags(request->rq_reqmsg,
629 request->rq_import->imp_msghdr_flags);
631 if (request->rq_resend)
632 lustre_msg_add_flags(request->rq_reqmsg, MSG_RESENT);
634 if (request->rq_memalloc)
635 mpflag = cfs_memory_pressure_get_and_set();
637 rc = sptlrpc_cli_wrap_request(request);
641 /* bulk register should be done after wrap_request() */
642 if (request->rq_bulk != NULL) {
643 rc = ptlrpc_register_bulk (request);
649 LASSERT (request->rq_replen != 0);
650 if (request->rq_repbuf == NULL) {
651 LASSERT(request->rq_repdata == NULL);
652 LASSERT(request->rq_repmsg == NULL);
653 rc = sptlrpc_cli_alloc_repbuf(request,
656 /* this prevents us from looping in
657 * ptlrpc_queue_wait */
659 request->rq_status = rc;
660 GOTO(cleanup_bulk, rc);
663 request->rq_repdata = NULL;
664 request->rq_repmsg = NULL;
667 rc = LNetMEAttach(request->rq_reply_portal,/*XXX FIXME bug 249*/
668 connection->c_peer, request->rq_xid, 0,
669 LNET_UNLINK, LNET_INS_AFTER, &reply_me_h);
671 CERROR("LNetMEAttach failed: %d\n", rc);
672 LASSERT (rc == -ENOMEM);
673 GOTO(cleanup_bulk, rc = -ENOMEM);
677 spin_lock(&request->rq_lock);
678 /* If the MD attach succeeds, there _will_ be a reply_in callback */
679 request->rq_receiving_reply = !noreply;
680 /* We are responsible for unlinking the reply buffer */
681 request->rq_must_unlink = !noreply;
682 /* Clear any flags that may be present from previous sends. */
683 request->rq_replied = 0;
685 request->rq_timedout = 0;
686 request->rq_net_err = 0;
687 request->rq_resend = 0;
688 request->rq_restart = 0;
689 request->rq_reply_truncate = 0;
690 spin_unlock(&request->rq_lock);
693 reply_md.start = request->rq_repbuf;
694 reply_md.length = request->rq_repbuf_len;
695 /* Allow multiple early replies */
696 reply_md.threshold = LNET_MD_THRESH_INF;
697 /* Manage remote for early replies */
698 reply_md.options = PTLRPC_MD_OPTIONS | LNET_MD_OP_PUT |
699 LNET_MD_MANAGE_REMOTE |
700 LNET_MD_TRUNCATE; /* allow to make EOVERFLOW error */;
701 reply_md.user_ptr = &request->rq_reply_cbid;
702 reply_md.eq_handle = ptlrpc_eq_h;
704 /* We must see the unlink callback to unset rq_must_unlink,
705 so we can't auto-unlink */
706 rc = LNetMDAttach(reply_me_h, reply_md, LNET_RETAIN,
707 &request->rq_reply_md_h);
709 CERROR("LNetMDAttach failed: %d\n", rc);
710 LASSERT (rc == -ENOMEM);
711 spin_lock(&request->rq_lock);
712 /* ...but the MD attach didn't succeed... */
713 request->rq_receiving_reply = 0;
714 spin_unlock(&request->rq_lock);
715 GOTO(cleanup_me, rc = -ENOMEM);
718 CDEBUG(D_NET, "Setup reply buffer: %u bytes, xid "LPU64
720 request->rq_repbuf_len, request->rq_xid,
721 request->rq_reply_portal);
724 /* add references on request for request_out_callback */
725 ptlrpc_request_addref(request);
726 if (obd->obd_svc_stats != NULL)
727 lprocfs_counter_add(obd->obd_svc_stats, PTLRPC_REQACTIVE_CNTR,
728 cfs_atomic_read(&request->rq_import->imp_inflight));
730 OBD_FAIL_TIMEOUT(OBD_FAIL_PTLRPC_DELAY_SEND, request->rq_timeout + 5);
732 cfs_gettimeofday(&request->rq_arrival_time);
733 request->rq_sent = cfs_time_current_sec();
734 /* We give the server rq_timeout secs to process the req, and
735 add the network latency for our local timeout. */
736 request->rq_deadline = request->rq_sent + request->rq_timeout +
737 ptlrpc_at_get_net_latency(request);
739 ptlrpc_pinger_sending_on_import(request->rq_import);
741 DEBUG_REQ(D_INFO, request, "send flg=%x",
742 lustre_msg_get_flags(request->rq_reqmsg));
743 rc = ptl_send_buf(&request->rq_req_md_h,
744 request->rq_reqbuf, request->rq_reqdata_len,
745 LNET_NOACK_REQ, &request->rq_req_cbid,
747 request->rq_request_portal,
752 ptlrpc_req_finished(request);
757 /* MEUnlink is safe; the PUT didn't even get off the ground, and
758 * nobody apart from the PUT's target has the right nid+XID to
759 * access the reply buffer. */
760 rc2 = LNetMEUnlink(reply_me_h);
762 /* UNLINKED callback called synchronously */
763 LASSERT(!request->rq_receiving_reply);
766 /* We do sync unlink here as there was no real transfer here so
767 * the chance to have long unlink to sluggish net is smaller here. */
768 ptlrpc_unregister_bulk(request, 0);
770 if (request->rq_memalloc)
771 cfs_memory_pressure_restore(mpflag);
774 EXPORT_SYMBOL(ptl_send_rpc);
777 * Register request buffer descriptor for request receiving.
779 int ptlrpc_register_rqbd(struct ptlrpc_request_buffer_desc *rqbd)
781 struct ptlrpc_service *service = rqbd->rqbd_svcpt->scp_service;
782 static lnet_process_id_t match_id = {LNET_NID_ANY, LNET_PID_ANY};
785 lnet_handle_me_t me_h;
787 CDEBUG(D_NET, "LNetMEAttach: portal %d\n",
788 service->srv_req_portal);
790 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_RQBD))
793 /* NB: CPT affinity service should use new LNet flag LNET_INS_LOCAL,
794 * which means buffer can only be attached on local CPT, and LND
795 * threads can find it by grabbing a local lock */
796 rc = LNetMEAttach(service->srv_req_portal,
797 match_id, 0, ~0, LNET_UNLINK,
798 rqbd->rqbd_svcpt->scp_cpt >= 0 ?
799 LNET_INS_LOCAL : LNET_INS_AFTER, &me_h);
801 CERROR("LNetMEAttach failed: %d\n", rc);
805 LASSERT(rqbd->rqbd_refcount == 0);
806 rqbd->rqbd_refcount = 1;
808 md.start = rqbd->rqbd_buffer;
809 md.length = service->srv_buf_size;
810 md.max_size = service->srv_max_req_size;
811 md.threshold = LNET_MD_THRESH_INF;
812 md.options = PTLRPC_MD_OPTIONS | LNET_MD_OP_PUT | LNET_MD_MAX_SIZE;
813 md.user_ptr = &rqbd->rqbd_cbid;
814 md.eq_handle = ptlrpc_eq_h;
816 rc = LNetMDAttach(me_h, md, LNET_UNLINK, &rqbd->rqbd_md_h);
820 CERROR("LNetMDAttach failed: %d; \n", rc);
821 LASSERT (rc == -ENOMEM);
822 rc = LNetMEUnlink (me_h);
824 rqbd->rqbd_refcount = 0;