Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 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 |
Oleg Drokin | 6a5b99a | 2016-06-14 23:33:40 -0400 | [diff] [blame] | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 19 | * |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 20 | * GPL HEADER END |
| 21 | */ |
| 22 | /* |
| 23 | * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
| 24 | * Use is subject to license terms. |
| 25 | * |
Andreas Dilger | 1dc563a | 2015-11-08 18:09:37 -0500 | [diff] [blame] | 26 | * Copyright (c) 2011, 2015, Intel Corporation. |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 27 | */ |
| 28 | /* |
| 29 | * This file is part of Lustre, http://www.lustre.org/ |
| 30 | * Lustre is a trademark of Sun Microsystems, Inc. |
| 31 | */ |
| 32 | |
| 33 | #define DEBUG_SUBSYSTEM S_RPC |
Greg Kroah-Hartman | e27db14 | 2014-07-11 22:29:36 -0700 | [diff] [blame] | 34 | #include "../include/obd_support.h" |
| 35 | #include "../include/lustre_net.h" |
| 36 | #include "../include/lustre_lib.h" |
| 37 | #include "../include/obd.h" |
| 38 | #include "../include/obd_class.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 39 | #include "ptlrpc_internal.h" |
| 40 | |
| 41 | /** |
| 42 | * Helper function. Sends \a len bytes from \a base at offset \a offset |
| 43 | * over \a conn connection to portal \a portal. |
| 44 | * Returns 0 on success or error code. |
| 45 | */ |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 46 | static int ptl_send_buf(lnet_handle_md_t *mdh, void *base, int len, |
| 47 | lnet_ack_req_t ack, struct ptlrpc_cb_id *cbid, |
| 48 | struct ptlrpc_connection *conn, int portal, __u64 xid, |
| 49 | unsigned int offset) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 50 | { |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 51 | int rc; |
| 52 | lnet_md_t md; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 53 | |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 54 | LASSERT(portal != 0); |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 55 | CDEBUG(D_INFO, "conn=%p id %s\n", conn, libcfs_id2str(conn->c_peer)); |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 56 | md.start = base; |
| 57 | md.length = len; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 58 | md.threshold = (ack == LNET_ACK_REQ) ? 2 : 1; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 59 | md.options = PTLRPC_MD_OPTIONS; |
| 60 | md.user_ptr = cbid; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 61 | md.eq_handle = ptlrpc_eq_h; |
| 62 | |
| 63 | if (unlikely(ack == LNET_ACK_REQ && |
Kristina Martsenko | cb68dd2 | 2013-11-11 21:34:59 +0200 | [diff] [blame] | 64 | OBD_FAIL_CHECK_ORSET(OBD_FAIL_PTLRPC_ACK, |
| 65 | OBD_FAIL_ONCE))) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 66 | /* don't ask for the ack to simulate failing client */ |
| 67 | ack = LNET_NOACK_REQ; |
| 68 | } |
| 69 | |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 70 | rc = LNetMDBind(md, LNET_UNLINK, mdh); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 71 | if (unlikely(rc != 0)) { |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 72 | CERROR("LNetMDBind failed: %d\n", rc); |
| 73 | LASSERT(rc == -ENOMEM); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 74 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 75 | } |
| 76 | |
Greg Kroah-Hartman | f537dd2 | 2014-07-12 18:41:09 -0700 | [diff] [blame] | 77 | CDEBUG(D_NET, "Sending %d bytes to portal %d, xid %lld, offset %u\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 78 | len, portal, xid, offset); |
| 79 | |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 80 | rc = LNetPut(conn->c_self, *mdh, ack, |
| 81 | conn->c_peer, portal, xid, offset, 0); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 82 | if (unlikely(rc != 0)) { |
| 83 | int rc2; |
| 84 | /* We're going to get an UNLINK event when I unlink below, |
| 85 | * which will complete just like any other failed send, so |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 86 | * I fall through and return success here! |
| 87 | */ |
Greg Kroah-Hartman | f537dd2 | 2014-07-12 18:41:09 -0700 | [diff] [blame] | 88 | CERROR("LNetPut(%s, %d, %lld) failed: %d\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 89 | libcfs_id2str(conn->c_peer), portal, xid, rc); |
| 90 | rc2 = LNetMDUnlink(*mdh); |
| 91 | LASSERTF(rc2 == 0, "rc2 = %d\n", rc2); |
| 92 | } |
| 93 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 94 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static void mdunlink_iterate_helper(lnet_handle_md_t *bd_mds, int count) |
| 98 | { |
| 99 | int i; |
| 100 | |
| 101 | for (i = 0; i < count; i++) |
| 102 | LNetMDUnlink(bd_mds[i]); |
| 103 | } |
| 104 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 105 | /** |
| 106 | * Register bulk at the sender for later transfer. |
| 107 | * Returns 0 on success or error code. |
| 108 | */ |
Shraddha Barke | 12d0be6 | 2015-10-04 13:00:13 +0530 | [diff] [blame] | 109 | static int ptlrpc_register_bulk(struct ptlrpc_request *req) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 110 | { |
| 111 | struct ptlrpc_bulk_desc *desc = req->rq_bulk; |
| 112 | lnet_process_id_t peer; |
| 113 | int rc = 0; |
| 114 | int rc2; |
| 115 | int posted_md; |
| 116 | int total_md; |
| 117 | __u64 xid; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 118 | lnet_handle_me_t me_h; |
| 119 | lnet_md_t md; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 120 | |
| 121 | if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_BULK_GET_NET)) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 122 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 123 | |
| 124 | /* NB no locking required until desc is on the network */ |
| 125 | LASSERT(desc->bd_nob > 0); |
| 126 | LASSERT(desc->bd_md_count == 0); |
| 127 | LASSERT(desc->bd_md_max_brw <= PTLRPC_BULK_OPS_COUNT); |
| 128 | LASSERT(desc->bd_iov_count <= PTLRPC_MAX_BRW_PAGES); |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 129 | LASSERT(desc->bd_req); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 130 | LASSERT(desc->bd_type == BULK_PUT_SINK || |
| 131 | desc->bd_type == BULK_GET_SOURCE); |
| 132 | |
| 133 | /* cleanup the state of the bulk for it will be reused */ |
| 134 | if (req->rq_resend || req->rq_send_state == LUSTRE_IMP_REPLAY) |
| 135 | desc->bd_nob_transferred = 0; |
| 136 | else |
| 137 | LASSERT(desc->bd_nob_transferred == 0); |
| 138 | |
| 139 | desc->bd_failure = 0; |
| 140 | |
| 141 | peer = desc->bd_import->imp_connection->c_peer; |
| 142 | |
| 143 | LASSERT(desc->bd_cbid.cbid_fn == client_bulk_callback); |
| 144 | LASSERT(desc->bd_cbid.cbid_arg == desc); |
| 145 | |
| 146 | /* An XID is only used for a single request from the client. |
| 147 | * For retried bulk transfers, a new XID will be allocated in |
| 148 | * in ptlrpc_check_set() if it needs to be resent, so it is not |
| 149 | * using the same RDMA match bits after an error. |
| 150 | * |
| 151 | * For multi-bulk RPCs, rq_xid is the last XID needed for bulks. The |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 152 | * first bulk XID is power-of-two aligned before rq_xid. LU-1431 |
| 153 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 154 | xid = req->rq_xid & ~((__u64)desc->bd_md_max_brw - 1); |
| 155 | LASSERTF(!(desc->bd_registered && |
| 156 | req->rq_send_state != LUSTRE_IMP_REPLAY) || |
| 157 | xid != desc->bd_last_xid, |
Greg Kroah-Hartman | b0f5aad | 2014-07-12 20:06:04 -0700 | [diff] [blame] | 158 | "registered: %d rq_xid: %llu bd_last_xid: %llu\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 159 | desc->bd_registered, xid, desc->bd_last_xid); |
| 160 | |
| 161 | total_md = (desc->bd_iov_count + LNET_MAX_IOV - 1) / LNET_MAX_IOV; |
| 162 | desc->bd_registered = 1; |
| 163 | desc->bd_last_xid = xid; |
| 164 | desc->bd_md_count = total_md; |
| 165 | md.user_ptr = &desc->bd_cbid; |
| 166 | md.eq_handle = ptlrpc_eq_h; |
| 167 | md.threshold = 1; /* PUT or GET */ |
| 168 | |
| 169 | for (posted_md = 0; posted_md < total_md; posted_md++, xid++) { |
| 170 | md.options = PTLRPC_MD_OPTIONS | |
| 171 | ((desc->bd_type == BULK_GET_SOURCE) ? |
| 172 | LNET_MD_OP_GET : LNET_MD_OP_PUT); |
| 173 | ptlrpc_fill_bulk_md(&md, desc, posted_md); |
| 174 | |
| 175 | rc = LNetMEAttach(desc->bd_portal, peer, xid, 0, |
| 176 | LNET_UNLINK, LNET_INS_AFTER, &me_h); |
| 177 | if (rc != 0) { |
Greg Kroah-Hartman | b0f5aad | 2014-07-12 20:06:04 -0700 | [diff] [blame] | 178 | CERROR("%s: LNetMEAttach failed x%llu/%d: rc = %d\n", |
Amir Shehata | 3c92a0b | 2013-12-03 21:58:47 +0800 | [diff] [blame] | 179 | desc->bd_import->imp_obd->obd_name, xid, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 180 | posted_md, rc); |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | /* About to let the network at it... */ |
| 185 | rc = LNetMDAttach(me_h, md, LNET_UNLINK, |
| 186 | &desc->bd_mds[posted_md]); |
| 187 | if (rc != 0) { |
Greg Kroah-Hartman | b0f5aad | 2014-07-12 20:06:04 -0700 | [diff] [blame] | 188 | CERROR("%s: LNetMDAttach failed x%llu/%d: rc = %d\n", |
Amir Shehata | 3c92a0b | 2013-12-03 21:58:47 +0800 | [diff] [blame] | 189 | desc->bd_import->imp_obd->obd_name, xid, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 190 | posted_md, rc); |
| 191 | rc2 = LNetMEUnlink(me_h); |
| 192 | LASSERT(rc2 == 0); |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | if (rc != 0) { |
| 198 | LASSERT(rc == -ENOMEM); |
| 199 | spin_lock(&desc->bd_lock); |
| 200 | desc->bd_md_count -= total_md - posted_md; |
| 201 | spin_unlock(&desc->bd_lock); |
| 202 | LASSERT(desc->bd_md_count >= 0); |
| 203 | mdunlink_iterate_helper(desc->bd_mds, desc->bd_md_max_brw); |
| 204 | req->rq_status = -ENOMEM; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 205 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /* Set rq_xid to matchbits of the final bulk so that server can |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 209 | * infer the number of bulks that were prepared |
| 210 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 211 | req->rq_xid = --xid; |
| 212 | LASSERTF(desc->bd_last_xid == (req->rq_xid & PTLRPC_BULK_OPS_MASK), |
Greg Kroah-Hartman | b0f5aad | 2014-07-12 20:06:04 -0700 | [diff] [blame] | 213 | "bd_last_xid = x%llu, rq_xid = x%llu\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 214 | desc->bd_last_xid, req->rq_xid); |
| 215 | |
| 216 | spin_lock(&desc->bd_lock); |
| 217 | /* Holler if peer manages to touch buffers before he knows the xid */ |
| 218 | if (desc->bd_md_count != total_md) |
| 219 | CWARN("%s: Peer %s touched %d buffers while I registered\n", |
Amir Shehata | 3c92a0b | 2013-12-03 21:58:47 +0800 | [diff] [blame] | 220 | desc->bd_import->imp_obd->obd_name, libcfs_id2str(peer), |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 221 | total_md - desc->bd_md_count); |
| 222 | spin_unlock(&desc->bd_lock); |
| 223 | |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 224 | CDEBUG(D_NET, "Setup %u bulk %s buffers: %u pages %u bytes, xid x%#llx-%#llx, portal %u\n", |
| 225 | desc->bd_md_count, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 226 | desc->bd_type == BULK_GET_SOURCE ? "get-source" : "put-sink", |
| 227 | desc->bd_iov_count, desc->bd_nob, |
| 228 | desc->bd_last_xid, req->rq_xid, desc->bd_portal); |
| 229 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 230 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 231 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * Disconnect a bulk desc from the network. Idempotent. Not |
| 235 | * thread-safe (i.e. only interlocks with completion callback). |
| 236 | * Returns 1 on success or 0 if network unregistration failed for whatever |
| 237 | * reason. |
| 238 | */ |
| 239 | int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async) |
| 240 | { |
| 241 | struct ptlrpc_bulk_desc *desc = req->rq_bulk; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 242 | wait_queue_head_t *wq; |
| 243 | struct l_wait_info lwi; |
| 244 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 245 | |
| 246 | LASSERT(!in_interrupt()); /* might sleep */ |
| 247 | |
| 248 | /* Let's setup deadline for reply unlink. */ |
| 249 | if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) && |
Vitaly Fertman | 81ea39e | 2016-06-20 16:55:34 -0400 | [diff] [blame] | 250 | async && req->rq_bulk_deadline == 0 && cfs_fail_val == 0) |
Arnd Bergmann | 219e6de | 2015-09-27 16:45:30 -0400 | [diff] [blame] | 251 | req->rq_bulk_deadline = ktime_get_real_seconds() + LONG_UNLINK; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 252 | |
| 253 | if (ptlrpc_client_bulk_active(req) == 0) /* completed or */ |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 254 | return 1; /* never registered */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 255 | |
| 256 | LASSERT(desc->bd_req == req); /* bd_req NULL until registered */ |
| 257 | |
| 258 | /* the unlink ensures the callback happens ASAP and is the last |
| 259 | * one. If it fails, it must be because completion just happened, |
| 260 | * but we must still l_wait_event() in this case to give liblustre |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 261 | * a chance to run client_bulk_callback() |
| 262 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 263 | mdunlink_iterate_helper(desc->bd_mds, desc->bd_md_max_brw); |
| 264 | |
| 265 | if (ptlrpc_client_bulk_active(req) == 0) /* completed or */ |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 266 | return 1; /* never registered */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 267 | |
| 268 | /* Move to "Unregistering" phase as bulk was not unlinked yet. */ |
Vitaly Fertman | 81ea39e | 2016-06-20 16:55:34 -0400 | [diff] [blame] | 269 | ptlrpc_rqphase_move(req, RQ_PHASE_UNREG_BULK); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 270 | |
| 271 | /* Do not wait for unlink to finish. */ |
| 272 | if (async) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 273 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 274 | |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 275 | if (req->rq_set) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 276 | wq = &req->rq_set->set_waitq; |
| 277 | else |
| 278 | wq = &req->rq_reply_waitq; |
| 279 | |
| 280 | for (;;) { |
| 281 | /* Network access will complete in finite time but the HUGE |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 282 | * timeout lets us CWARN for visibility of sluggish LNDs |
| 283 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 284 | lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(LONG_UNLINK), |
| 285 | cfs_time_seconds(1), NULL, NULL); |
| 286 | rc = l_wait_event(*wq, !ptlrpc_client_bulk_active(req), &lwi); |
| 287 | if (rc == 0) { |
| 288 | ptlrpc_rqphase_move(req, req->rq_next_phase); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 289 | return 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | LASSERT(rc == -ETIMEDOUT); |
| 293 | DEBUG_REQ(D_WARNING, req, "Unexpectedly long timeout: desc %p", |
| 294 | desc); |
| 295 | } |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 296 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 297 | } |
| 298 | EXPORT_SYMBOL(ptlrpc_unregister_bulk); |
| 299 | |
| 300 | static void ptlrpc_at_set_reply(struct ptlrpc_request *req, int flags) |
| 301 | { |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 302 | struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt; |
| 303 | struct ptlrpc_service *svc = svcpt->scp_service; |
Arnd Bergmann | 219e6de | 2015-09-27 16:45:30 -0400 | [diff] [blame] | 304 | int service_time = max_t(int, ktime_get_real_seconds() - |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 305 | req->rq_arrival_time.tv_sec, 1); |
| 306 | |
| 307 | if (!(flags & PTLRPC_REPLY_EARLY) && |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 308 | (req->rq_type != PTL_RPC_MSG_ERR) && req->rq_reqmsg && |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 309 | !(lustre_msg_get_flags(req->rq_reqmsg) & |
| 310 | (MSG_RESENT | MSG_REPLAY | |
| 311 | MSG_REQ_REPLAY_DONE | MSG_LOCK_REPLAY_DONE))) { |
| 312 | /* early replies, errors and recovery requests don't count |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 313 | * toward our service time estimate |
| 314 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 315 | int oldse = at_measured(&svcpt->scp_at_estimate, service_time); |
| 316 | |
| 317 | if (oldse != 0) { |
| 318 | DEBUG_REQ(D_ADAPTTO, req, |
| 319 | "svc %s changed estimate from %d to %d", |
| 320 | svc->srv_name, oldse, |
| 321 | at_get(&svcpt->scp_at_estimate)); |
| 322 | } |
| 323 | } |
| 324 | /* Report actual service time for client latency calc */ |
| 325 | lustre_msg_set_service_time(req->rq_repmsg, service_time); |
| 326 | /* Report service time estimate for future client reqs, but report 0 |
| 327 | * (to be ignored by client) if it's a error reply during recovery. |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 328 | * (bz15815) |
| 329 | */ |
Oleg Drokin | af3ec53 | 2015-09-28 23:44:09 -0400 | [diff] [blame] | 330 | if (req->rq_type == PTL_RPC_MSG_ERR && !req->rq_export) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 331 | lustre_msg_set_timeout(req->rq_repmsg, 0); |
| 332 | else |
| 333 | lustre_msg_set_timeout(req->rq_repmsg, |
| 334 | at_get(&svcpt->scp_at_estimate)); |
| 335 | |
| 336 | if (req->rq_reqmsg && |
| 337 | !(lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)) { |
Andreas Dilger | 2e4fe2b | 2015-09-14 18:41:21 -0400 | [diff] [blame] | 338 | CDEBUG(D_ADAPTTO, "No early reply support: flags=%#x req_flags=%#x magic=%x/%x len=%d\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 339 | flags, lustre_msg_get_flags(req->rq_reqmsg), |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 340 | lustre_msg_get_magic(req->rq_reqmsg), |
| 341 | lustre_msg_get_magic(req->rq_repmsg), req->rq_replen); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Send request reply from request \a req reply buffer. |
| 347 | * \a flags defines reply types |
Masanari Iida | b6da17f | 2014-02-08 00:30:40 +0900 | [diff] [blame] | 348 | * Returns 0 on success or error code |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 349 | */ |
| 350 | int ptlrpc_send_reply(struct ptlrpc_request *req, int flags) |
| 351 | { |
| 352 | struct ptlrpc_reply_state *rs = req->rq_reply_state; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 353 | struct ptlrpc_connection *conn; |
| 354 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 355 | |
| 356 | /* We must already have a reply buffer (only ptlrpc_error() may be |
| 357 | * called without one). The reply generated by sptlrpc layer (e.g. |
| 358 | * error notify, etc.) might have NULL rq->reqmsg; Otherwise we must |
| 359 | * have a request buffer which is either the actual (swabbed) incoming |
| 360 | * request, or a saved copy if this is a req saved in |
| 361 | * target_queue_final_reply(). |
| 362 | */ |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 363 | LASSERT(req->rq_no_reply == 0); |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 364 | LASSERT(req->rq_reqbuf); |
| 365 | LASSERT(rs); |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 366 | LASSERT((flags & PTLRPC_REPLY_MAYBE_DIFFICULT) || !rs->rs_difficult); |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 367 | LASSERT(req->rq_repmsg); |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 368 | LASSERT(req->rq_repmsg == rs->rs_msg); |
| 369 | LASSERT(rs->rs_cb_id.cbid_fn == reply_out_callback); |
| 370 | LASSERT(rs->rs_cb_id.cbid_arg == rs); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 371 | |
| 372 | /* There may be no rq_export during failover */ |
| 373 | |
| 374 | if (unlikely(req->rq_export && req->rq_export->exp_obd && |
| 375 | req->rq_export->exp_obd->obd_fail)) { |
| 376 | /* Failed obd's only send ENODEV */ |
| 377 | req->rq_type = PTL_RPC_MSG_ERR; |
| 378 | req->rq_status = -ENODEV; |
| 379 | CDEBUG(D_HA, "sending ENODEV from failed obd %d\n", |
| 380 | req->rq_export->exp_obd->obd_minor); |
| 381 | } |
| 382 | |
Haneen Mohammed | dfc1697 | 2015-03-16 20:14:56 +0300 | [diff] [blame] | 383 | /* In order to keep interoperability with the client (< 2.3) which |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 384 | * doesn't have pb_jobid in ptlrpc_body, We have to shrink the |
| 385 | * ptlrpc_body in reply buffer to ptlrpc_body_v2, otherwise, the |
| 386 | * reply buffer on client will be overflow. |
| 387 | * |
Jonathan Sid-Otmane | 71474cc | 2015-03-18 22:12:47 +0100 | [diff] [blame] | 388 | * XXX Remove this whenever we drop the interoperability with |
| 389 | * such client. |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 390 | */ |
| 391 | req->rq_replen = lustre_shrink_msg(req->rq_repmsg, 0, |
| 392 | sizeof(struct ptlrpc_body_v2), 1); |
| 393 | |
| 394 | if (req->rq_type != PTL_RPC_MSG_ERR) |
| 395 | req->rq_type = PTL_RPC_MSG_REPLY; |
| 396 | |
| 397 | lustre_msg_set_type(req->rq_repmsg, req->rq_type); |
Li Wei | 2d58de7 | 2013-07-23 00:06:32 +0800 | [diff] [blame] | 398 | lustre_msg_set_status(req->rq_repmsg, |
| 399 | ptlrpc_status_hton(req->rq_status)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 400 | lustre_msg_set_opc(req->rq_repmsg, |
| 401 | req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : 0); |
| 402 | |
| 403 | target_pack_pool_reply(req); |
| 404 | |
| 405 | ptlrpc_at_set_reply(req, flags); |
| 406 | |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 407 | if (!req->rq_export || !req->rq_export->exp_connection) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 408 | conn = ptlrpc_connection_get(req->rq_peer, req->rq_self, NULL); |
| 409 | else |
| 410 | conn = ptlrpc_connection_addref(req->rq_export->exp_connection); |
| 411 | |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 412 | if (unlikely(!conn)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 413 | CERROR("not replying on NULL connection\n"); /* bug 9635 */ |
| 414 | return -ENOTCONN; |
| 415 | } |
| 416 | ptlrpc_rs_addref(rs); /* +1 ref for the network */ |
| 417 | |
| 418 | rc = sptlrpc_svc_wrap_reply(req); |
| 419 | if (unlikely(rc)) |
| 420 | goto out; |
| 421 | |
Arnd Bergmann | 219e6de | 2015-09-27 16:45:30 -0400 | [diff] [blame] | 422 | req->rq_sent = ktime_get_real_seconds(); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 423 | |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 424 | rc = ptl_send_buf(&rs->rs_md_h, rs->rs_repbuf, rs->rs_repdata_len, |
| 425 | (rs->rs_difficult && !rs->rs_no_ack) ? |
| 426 | LNET_ACK_REQ : LNET_NOACK_REQ, |
| 427 | &rs->rs_cb_id, conn, |
| 428 | ptlrpc_req2svc(req)->srv_rep_portal, |
| 429 | req->rq_xid, req->rq_reply_off); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 430 | out: |
| 431 | if (unlikely(rc != 0)) |
| 432 | ptlrpc_req_drop_rs(req); |
| 433 | ptlrpc_connection_put(conn); |
| 434 | return rc; |
| 435 | } |
| 436 | EXPORT_SYMBOL(ptlrpc_send_reply); |
| 437 | |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 438 | int ptlrpc_reply(struct ptlrpc_request *req) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 439 | { |
| 440 | if (req->rq_no_reply) |
| 441 | return 0; |
Vaishali Thakkar | 5ce91a9 | 2014-09-23 19:22:41 +0530 | [diff] [blame] | 442 | return ptlrpc_send_reply(req, 0); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 443 | } |
| 444 | EXPORT_SYMBOL(ptlrpc_reply); |
| 445 | |
| 446 | /** |
| 447 | * For request \a req send an error reply back. Create empty |
| 448 | * reply buffers if necessary. |
| 449 | */ |
| 450 | int ptlrpc_send_error(struct ptlrpc_request *req, int may_be_difficult) |
| 451 | { |
| 452 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 453 | |
| 454 | if (req->rq_no_reply) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 455 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 456 | |
| 457 | if (!req->rq_repmsg) { |
| 458 | rc = lustre_pack_reply(req, 1, NULL, NULL); |
| 459 | if (rc) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 460 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | if (req->rq_status != -ENOSPC && req->rq_status != -EACCES && |
| 464 | req->rq_status != -EPERM && req->rq_status != -ENOENT && |
| 465 | req->rq_status != -EINPROGRESS && req->rq_status != -EDQUOT) |
| 466 | req->rq_type = PTL_RPC_MSG_ERR; |
| 467 | |
| 468 | rc = ptlrpc_send_reply(req, may_be_difficult); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 469 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 470 | } |
| 471 | EXPORT_SYMBOL(ptlrpc_send_error); |
| 472 | |
| 473 | int ptlrpc_error(struct ptlrpc_request *req) |
| 474 | { |
| 475 | return ptlrpc_send_error(req, 0); |
| 476 | } |
| 477 | EXPORT_SYMBOL(ptlrpc_error); |
| 478 | |
| 479 | /** |
| 480 | * Send request \a request. |
| 481 | * if \a noreply is set, don't expect any reply back and don't set up |
| 482 | * reply buffers. |
| 483 | * Returns 0 on success or error code. |
| 484 | */ |
| 485 | int ptl_send_rpc(struct ptlrpc_request *request, int noreply) |
| 486 | { |
| 487 | int rc; |
| 488 | int rc2; |
| 489 | int mpflag = 0; |
| 490 | struct ptlrpc_connection *connection; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 491 | lnet_handle_me_t reply_me_h; |
| 492 | lnet_md_t reply_md; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 493 | struct obd_device *obd = request->rq_import->imp_obd; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 494 | |
| 495 | if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_DROP_RPC)) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 496 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 497 | |
| 498 | LASSERT(request->rq_type == PTL_RPC_MSG_REQUEST); |
| 499 | LASSERT(request->rq_wait_ctx == 0); |
| 500 | |
| 501 | /* If this is a re-transmit, we're required to have disengaged |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 502 | * cleanly from the previous attempt |
| 503 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 504 | LASSERT(!request->rq_receiving_reply); |
Alexander.Boyko | 5c689e6 | 2014-06-22 21:32:12 -0400 | [diff] [blame] | 505 | LASSERT(!((lustre_msg_get_flags(request->rq_reqmsg) & MSG_REPLAY) && |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 506 | (request->rq_import->imp_state == LUSTRE_IMP_FULL))); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 507 | |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 508 | if (unlikely(obd && obd->obd_fail)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 509 | CDEBUG(D_HA, "muting rpc for failed imp obd %s\n", |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 510 | obd->obd_name); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 511 | /* this prevents us from waiting in ptlrpc_queue_wait */ |
Sebastien Buisson | 15c50cc | 2014-02-28 21:16:42 -0500 | [diff] [blame] | 512 | spin_lock(&request->rq_lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 513 | request->rq_err = 1; |
Sebastien Buisson | 15c50cc | 2014-02-28 21:16:42 -0500 | [diff] [blame] | 514 | spin_unlock(&request->rq_lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 515 | request->rq_status = -ENODEV; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 516 | return -ENODEV; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | connection = request->rq_import->imp_connection; |
| 520 | |
| 521 | lustre_msg_set_handle(request->rq_reqmsg, |
| 522 | &request->rq_import->imp_remote_handle); |
| 523 | lustre_msg_set_type(request->rq_reqmsg, PTL_RPC_MSG_REQUEST); |
| 524 | lustre_msg_set_conn_cnt(request->rq_reqmsg, |
| 525 | request->rq_import->imp_conn_cnt); |
| 526 | lustre_msghdr_set_flags(request->rq_reqmsg, |
| 527 | request->rq_import->imp_msghdr_flags); |
| 528 | |
| 529 | if (request->rq_resend) |
| 530 | lustre_msg_add_flags(request->rq_reqmsg, MSG_RESENT); |
| 531 | |
| 532 | if (request->rq_memalloc) |
| 533 | mpflag = cfs_memory_pressure_get_and_set(); |
| 534 | |
| 535 | rc = sptlrpc_cli_wrap_request(request); |
| 536 | if (rc) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 537 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 538 | |
| 539 | /* bulk register should be done after wrap_request() */ |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 540 | if (request->rq_bulk) { |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 541 | rc = ptlrpc_register_bulk(request); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 542 | if (rc != 0) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 543 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | if (!noreply) { |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 547 | LASSERT(request->rq_replen != 0); |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 548 | if (!request->rq_repbuf) { |
| 549 | LASSERT(!request->rq_repdata); |
| 550 | LASSERT(!request->rq_repmsg); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 551 | rc = sptlrpc_cli_alloc_repbuf(request, |
| 552 | request->rq_replen); |
| 553 | if (rc) { |
| 554 | /* this prevents us from looping in |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 555 | * ptlrpc_queue_wait |
| 556 | */ |
Sebastien Buisson | 15c50cc | 2014-02-28 21:16:42 -0500 | [diff] [blame] | 557 | spin_lock(&request->rq_lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 558 | request->rq_err = 1; |
Sebastien Buisson | 15c50cc | 2014-02-28 21:16:42 -0500 | [diff] [blame] | 559 | spin_unlock(&request->rq_lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 560 | request->rq_status = rc; |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 561 | goto cleanup_bulk; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 562 | } |
| 563 | } else { |
| 564 | request->rq_repdata = NULL; |
| 565 | request->rq_repmsg = NULL; |
| 566 | } |
| 567 | |
| 568 | rc = LNetMEAttach(request->rq_reply_portal,/*XXX FIXME bug 249*/ |
| 569 | connection->c_peer, request->rq_xid, 0, |
| 570 | LNET_UNLINK, LNET_INS_AFTER, &reply_me_h); |
| 571 | if (rc != 0) { |
| 572 | CERROR("LNetMEAttach failed: %d\n", rc); |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 573 | LASSERT(rc == -ENOMEM); |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 574 | rc = -ENOMEM; |
| 575 | goto cleanup_bulk; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | |
| 579 | spin_lock(&request->rq_lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 580 | /* We are responsible for unlinking the reply buffer */ |
Liang Zhen | 9faa2ad | 2016-06-20 16:55:31 -0400 | [diff] [blame] | 581 | request->rq_reply_unlinked = noreply; |
| 582 | request->rq_receiving_reply = !noreply; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 583 | /* Clear any flags that may be present from previous sends. */ |
Liang Zhen | 9faa2ad | 2016-06-20 16:55:31 -0400 | [diff] [blame] | 584 | request->rq_req_unlinked = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 585 | request->rq_replied = 0; |
| 586 | request->rq_err = 0; |
| 587 | request->rq_timedout = 0; |
| 588 | request->rq_net_err = 0; |
| 589 | request->rq_resend = 0; |
| 590 | request->rq_restart = 0; |
Liang Zhen | 9faa2ad | 2016-06-20 16:55:31 -0400 | [diff] [blame] | 591 | request->rq_reply_truncated = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 592 | spin_unlock(&request->rq_lock); |
| 593 | |
| 594 | if (!noreply) { |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 595 | reply_md.start = request->rq_repbuf; |
| 596 | reply_md.length = request->rq_repbuf_len; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 597 | /* Allow multiple early replies */ |
| 598 | reply_md.threshold = LNET_MD_THRESH_INF; |
| 599 | /* Manage remote for early replies */ |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 600 | reply_md.options = PTLRPC_MD_OPTIONS | LNET_MD_OP_PUT | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 601 | LNET_MD_MANAGE_REMOTE | |
Jayavant Kenjalkar | 7fb7027 | 2015-09-27 11:15:21 +0530 | [diff] [blame] | 602 | LNET_MD_TRUNCATE; /* allow to make EOVERFLOW error */ |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 603 | reply_md.user_ptr = &request->rq_reply_cbid; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 604 | reply_md.eq_handle = ptlrpc_eq_h; |
| 605 | |
Liang Zhen | 9faa2ad | 2016-06-20 16:55:31 -0400 | [diff] [blame] | 606 | /* We must see the unlink callback to set rq_reply_unlinked, |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 607 | * so we can't auto-unlink |
| 608 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 609 | rc = LNetMDAttach(reply_me_h, reply_md, LNET_RETAIN, |
| 610 | &request->rq_reply_md_h); |
| 611 | if (rc != 0) { |
| 612 | CERROR("LNetMDAttach failed: %d\n", rc); |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 613 | LASSERT(rc == -ENOMEM); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 614 | spin_lock(&request->rq_lock); |
| 615 | /* ...but the MD attach didn't succeed... */ |
| 616 | request->rq_receiving_reply = 0; |
| 617 | spin_unlock(&request->rq_lock); |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 618 | rc = -ENOMEM; |
| 619 | goto cleanup_me; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 620 | } |
| 621 | |
Greg Kroah-Hartman | b0f5aad | 2014-07-12 20:06:04 -0700 | [diff] [blame] | 622 | CDEBUG(D_NET, "Setup reply buffer: %u bytes, xid %llu, portal %u\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 623 | request->rq_repbuf_len, request->rq_xid, |
| 624 | request->rq_reply_portal); |
| 625 | } |
| 626 | |
| 627 | /* add references on request for request_out_callback */ |
| 628 | ptlrpc_request_addref(request); |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 629 | if (obd && obd->obd_svc_stats) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 630 | lprocfs_counter_add(obd->obd_svc_stats, PTLRPC_REQACTIVE_CNTR, |
| 631 | atomic_read(&request->rq_import->imp_inflight)); |
| 632 | |
| 633 | OBD_FAIL_TIMEOUT(OBD_FAIL_PTLRPC_DELAY_SEND, request->rq_timeout + 5); |
| 634 | |
Liang Zhen | 32c8728 | 2016-06-20 16:55:30 -0400 | [diff] [blame] | 635 | ktime_get_real_ts64(&request->rq_sent_tv); |
Arnd Bergmann | 219e6de | 2015-09-27 16:45:30 -0400 | [diff] [blame] | 636 | request->rq_sent = ktime_get_real_seconds(); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 637 | /* We give the server rq_timeout secs to process the req, and |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 638 | * add the network latency for our local timeout. |
| 639 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 640 | request->rq_deadline = request->rq_sent + request->rq_timeout + |
| 641 | ptlrpc_at_get_net_latency(request); |
| 642 | |
| 643 | ptlrpc_pinger_sending_on_import(request->rq_import); |
| 644 | |
| 645 | DEBUG_REQ(D_INFO, request, "send flg=%x", |
| 646 | lustre_msg_get_flags(request->rq_reqmsg)); |
| 647 | rc = ptl_send_buf(&request->rq_req_md_h, |
| 648 | request->rq_reqbuf, request->rq_reqdata_len, |
| 649 | LNET_NOACK_REQ, &request->rq_req_cbid, |
| 650 | connection, |
| 651 | request->rq_request_portal, |
| 652 | request->rq_xid, 0); |
Liang Zhen | 9faa2ad | 2016-06-20 16:55:31 -0400 | [diff] [blame] | 653 | if (likely(rc == 0)) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 654 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 655 | |
Liang Zhen | 9faa2ad | 2016-06-20 16:55:31 -0400 | [diff] [blame] | 656 | request->rq_req_unlinked = 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 657 | ptlrpc_req_finished(request); |
| 658 | if (noreply) |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 659 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 660 | |
| 661 | cleanup_me: |
| 662 | /* MEUnlink is safe; the PUT didn't even get off the ground, and |
| 663 | * nobody apart from the PUT's target has the right nid+XID to |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 664 | * access the reply buffer. |
| 665 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 666 | rc2 = LNetMEUnlink(reply_me_h); |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 667 | LASSERT(rc2 == 0); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 668 | /* UNLINKED callback called synchronously */ |
| 669 | LASSERT(!request->rq_receiving_reply); |
| 670 | |
| 671 | cleanup_bulk: |
| 672 | /* We do sync unlink here as there was no real transfer here so |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 673 | * the chance to have long unlink to sluggish net is smaller here. |
| 674 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 675 | ptlrpc_unregister_bulk(request, 0); |
| 676 | out: |
| 677 | if (request->rq_memalloc) |
| 678 | cfs_memory_pressure_restore(mpflag); |
| 679 | return rc; |
| 680 | } |
| 681 | EXPORT_SYMBOL(ptl_send_rpc); |
| 682 | |
| 683 | /** |
| 684 | * Register request buffer descriptor for request receiving. |
| 685 | */ |
| 686 | int ptlrpc_register_rqbd(struct ptlrpc_request_buffer_desc *rqbd) |
| 687 | { |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 688 | struct ptlrpc_service *service = rqbd->rqbd_svcpt->scp_service; |
| 689 | static lnet_process_id_t match_id = {LNET_NID_ANY, LNET_PID_ANY}; |
| 690 | int rc; |
| 691 | lnet_md_t md; |
| 692 | lnet_handle_me_t me_h; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 693 | |
| 694 | CDEBUG(D_NET, "LNetMEAttach: portal %d\n", |
| 695 | service->srv_req_portal); |
| 696 | |
| 697 | if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_RQBD)) |
Julia Lawall | fbe7c6c | 2014-08-26 22:00:33 +0200 | [diff] [blame] | 698 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 699 | |
| 700 | /* NB: CPT affinity service should use new LNet flag LNET_INS_LOCAL, |
| 701 | * which means buffer can only be attached on local CPT, and LND |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 702 | * threads can find it by grabbing a local lock |
| 703 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 704 | rc = LNetMEAttach(service->srv_req_portal, |
| 705 | match_id, 0, ~0, LNET_UNLINK, |
| 706 | rqbd->rqbd_svcpt->scp_cpt >= 0 ? |
| 707 | LNET_INS_LOCAL : LNET_INS_AFTER, &me_h); |
| 708 | if (rc != 0) { |
| 709 | CERROR("LNetMEAttach failed: %d\n", rc); |
Julia Lawall | fbe7c6c | 2014-08-26 22:00:33 +0200 | [diff] [blame] | 710 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | LASSERT(rqbd->rqbd_refcount == 0); |
| 714 | rqbd->rqbd_refcount = 1; |
| 715 | |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 716 | md.start = rqbd->rqbd_buffer; |
| 717 | md.length = service->srv_buf_size; |
| 718 | md.max_size = service->srv_max_req_size; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 719 | md.threshold = LNET_MD_THRESH_INF; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 720 | md.options = PTLRPC_MD_OPTIONS | LNET_MD_OP_PUT | LNET_MD_MAX_SIZE; |
| 721 | md.user_ptr = &rqbd->rqbd_cbid; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 722 | md.eq_handle = ptlrpc_eq_h; |
| 723 | |
| 724 | rc = LNetMDAttach(me_h, md, LNET_UNLINK, &rqbd->rqbd_md_h); |
| 725 | if (rc == 0) |
Julia Lawall | fbe7c6c | 2014-08-26 22:00:33 +0200 | [diff] [blame] | 726 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 727 | |
Kristina Martsenko | 998d276 | 2013-11-11 21:35:02 +0200 | [diff] [blame] | 728 | CERROR("LNetMDAttach failed: %d;\n", rc); |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 729 | LASSERT(rc == -ENOMEM); |
| 730 | rc = LNetMEUnlink(me_h); |
| 731 | LASSERT(rc == 0); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 732 | rqbd->rqbd_refcount = 0; |
| 733 | |
Julia Lawall | fbe7c6c | 2014-08-26 22:00:33 +0200 | [diff] [blame] | 734 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 735 | } |