1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define DEBUG_SUBSYSTEM S_RPC
25 #include <linux/obd_support.h>
26 #include <linux/lustre_net.h>
27 #include <linux/lustre_lib.h>
29 extern ptl_handle_eq_t request_out_eq, reply_in_eq, reply_out_eq,
30 bulk_source_eq, bulk_sink_eq;
32 static int ptl_send_buf(struct ptlrpc_request *request,
33 struct ptlrpc_connection *conn, int portal)
36 ptl_process_id_t remote_id;
39 request->rq_req_md.user_ptr = request;
41 switch (request->rq_type) {
42 case PTL_RPC_MSG_REQUEST:
43 request->rq_reqmsg->type = HTON__u32(request->rq_type);
44 request->rq_req_md.start = request->rq_reqmsg;
45 request->rq_req_md.length = request->rq_reqlen;
46 request->rq_req_md.eventq = request_out_eq;
48 case PTL_RPC_MSG_REPLY:
49 request->rq_repmsg->type = HTON__u32(request->rq_type);
50 request->rq_req_md.start = request->rq_repmsg;
51 request->rq_req_md.length = request->rq_replen;
52 request->rq_req_md.eventq = reply_out_eq;
56 return -1; /* notreached */
58 request->rq_req_md.threshold = 1;
59 request->rq_req_md.options = PTL_MD_OP_PUT;
60 request->rq_req_md.user_ptr = request;
62 rc = PtlMDBind(conn->c_peer.peer_ni, request->rq_req_md, &md_h);
64 CERROR("PtlMDBind failed: %d\n", rc);
69 remote_id.nid = conn->c_peer.peer_nid;
72 CDEBUG(D_NET, "Sending %d bytes to portal %d, xid %Ld\n",
73 request->rq_req_md.length, portal, request->rq_xid);
77 rc = PtlPut(md_h, PTL_NOACK_REQ, remote_id, portal, 0, request->rq_xid,
80 CERROR("PtlPut(%Lu, %d, %Ld) failed: %d\n", remote_id.nid,
81 portal, request->rq_xid, rc);
88 static inline struct iovec *
89 ptlrpc_get_bulk_iov (struct ptlrpc_bulk_desc *desc)
93 if (desc->bd_page_count <= sizeof (desc->bd_iov)/sizeof (struct iovec))
94 return (desc->bd_iov);
96 OBD_ALLOC (iov, desc->bd_page_count * sizeof (struct iovec));
104 ptlrpc_put_bulk_iov (struct ptlrpc_bulk_desc *desc, struct iovec *iov)
106 if (desc->bd_page_count <= sizeof (desc->bd_iov)/sizeof (struct iovec))
109 OBD_FREE (iov, desc->bd_page_count * sizeof (struct iovec));
112 int ptlrpc_send_bulk(struct ptlrpc_bulk_desc *desc)
115 struct list_head *tmp, *next;
116 ptl_process_id_t remote_id;
121 iov = ptlrpc_get_bulk_iov (desc);
125 desc->bd_md.start = iov;
126 desc->bd_md.niov = 0;
127 desc->bd_md.length = 0;
128 desc->bd_md.eventq = bulk_source_eq;
129 desc->bd_md.threshold = 2; /* SENT and ACK */
130 desc->bd_md.options = PTL_MD_OP_PUT | PTL_MD_IOV;
131 desc->bd_md.user_ptr = desc;
133 list_for_each_safe(tmp, next, &desc->bd_page_list) {
134 struct ptlrpc_bulk_page *bulk;
135 bulk = list_entry(tmp, struct ptlrpc_bulk_page, bp_link);
137 LASSERT (desc->bd_md.niov < desc->bd_page_count);
139 if (desc->bd_md.niov == 0)
141 LASSERT (xid == bulk->bp_xid); /* should all be the same */
143 iov[desc->bd_md.niov].iov_base = bulk->bp_buf;
144 iov[desc->bd_md.niov].iov_len = bulk->bp_buflen;
146 desc->bd_md.length += bulk->bp_buflen;
149 LASSERT (desc->bd_md.niov == desc->bd_page_count);
150 LASSERT (desc->bd_md.niov != 0);
152 rc = PtlMDBind(desc->bd_connection->c_peer.peer_ni, desc->bd_md,
155 ptlrpc_put_bulk_iov (desc, iov); /* move down to reduce latency to send */
158 CERROR("PtlMDBind failed: %d\n", rc);
163 remote_id.nid = desc->bd_connection->c_peer.peer_nid;
166 CDEBUG(D_NET, "Sending %u pages %u bytes to portal %d nid %Lx pid %d xid %d\n",
167 desc->bd_md.niov, desc->bd_md.length,
168 desc->bd_portal, remote_id.nid, remote_id.pid, xid);
170 rc = PtlPut(desc->bd_md_h, PTL_ACK_REQ, remote_id,
171 desc->bd_portal, 0, xid, 0, 0);
173 CERROR("PtlPut(%Lu, %d, %d) failed: %d\n",
174 remote_id.nid, desc->bd_portal, xid, rc);
175 PtlMDUnlink(desc->bd_md_h);
183 int ptlrpc_register_bulk(struct ptlrpc_bulk_desc *desc)
185 struct list_head *tmp, *next;
189 ptl_process_id_t source_id;
192 iov = ptlrpc_get_bulk_iov (desc);
196 desc->bd_md.start = iov;
197 desc->bd_md.niov = 0;
198 desc->bd_md.length = 0;
199 desc->bd_md.threshold = 1;
200 desc->bd_md.options = PTL_MD_OP_PUT | PTL_MD_IOV;
201 desc->bd_md.user_ptr = desc;
202 desc->bd_md.eventq = bulk_sink_eq;
204 list_for_each_safe(tmp, next, &desc->bd_page_list) {
205 struct ptlrpc_bulk_page *bulk;
206 bulk = list_entry(tmp, struct ptlrpc_bulk_page, bp_link);
208 LASSERT (desc->bd_md.niov < desc->bd_page_count);
210 if (desc->bd_md.niov == 0)
212 LASSERT (xid == bulk->bp_xid); /* should all be the same */
214 iov[desc->bd_md.niov].iov_base = bulk->bp_buf;
215 iov[desc->bd_md.niov].iov_len = bulk->bp_buflen;
217 desc->bd_md.length += bulk->bp_buflen;
220 LASSERT (desc->bd_md.niov == desc->bd_page_count);
221 LASSERT (desc->bd_md.niov != 0);
223 source_id.nid = desc->bd_connection->c_peer.peer_nid;
224 source_id.pid = PTL_PID_ANY;
226 rc = PtlMEAttach(desc->bd_connection->c_peer.peer_ni,
227 desc->bd_portal, source_id, xid, 0,
228 PTL_UNLINK, PTL_INS_AFTER, &desc->bd_me_h);
230 ptlrpc_put_bulk_iov (desc, iov);
233 CERROR("PtlMEAttach failed: %d\n", rc);
238 rc = PtlMDAttach(desc->bd_me_h, desc->bd_md, PTL_UNLINK,
241 CERROR("PtlMDAttach failed: %d\n", rc);
246 CDEBUG(D_NET, "Setup bulk sink buffers: %u pages %u bytes, xid %u, "
247 "portal %u\n", desc->bd_md.niov, desc->bd_md.length,
248 xid, desc->bd_portal);
253 ptlrpc_abort_bulk(desc);
258 int ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc)
260 /* This should be safe: these handles are initialized to be
261 * invalid in ptlrpc_prep_bulk() */
262 PtlMDUnlink(desc->bd_md_h);
263 PtlMEUnlink(desc->bd_me_h);
268 int ptlrpc_reply(struct ptlrpc_service *svc, struct ptlrpc_request *req)
270 if (req->rq_repmsg == NULL) {
271 CERROR("bad: someone called ptlrpc_reply when they meant "
276 /* FIXME: we need to increment the count of handled events */
277 if (req->rq_type != PTL_RPC_MSG_ERR)
278 req->rq_type = PTL_RPC_MSG_REPLY;
279 //req->rq_repmsg->conn = req->rq_connection->c_remote_conn;
280 //req->rq_repmsg->token = req->rq_connection->c_remote_token;
281 req->rq_repmsg->status = HTON__u32(req->rq_status);
282 return ptl_send_buf(req, req->rq_connection, svc->srv_rep_portal);
285 int ptlrpc_error(struct ptlrpc_service *svc, struct ptlrpc_request *req)
290 if (req->rq_repmsg) {
291 CERROR("req already has repmsg\n");
295 rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
299 req->rq_repmsg->type = HTON__u32(PTL_RPC_MSG_ERR);
301 rc = ptlrpc_reply(svc, req);
305 int ptl_send_rpc(struct ptlrpc_request *request)
309 ptl_process_id_t source_id;
313 if (request->rq_type != PTL_RPC_MSG_REQUEST) {
314 CERROR("wrong packet type sent %d\n",
315 NTOH__u32(request->rq_reqmsg->type));
319 if (request->rq_replen == 0) {
320 CERROR("request->rq_replen is 0!\n");
324 /* request->rq_repmsg is set only when the reply comes in, in
325 * client_packet_callback() */
326 if (request->rq_reply_md.start)
327 OBD_FREE(request->rq_reply_md.start, request->rq_replen);
329 OBD_ALLOC(repbuf, request->rq_replen);
335 // down(&request->rq_client->cli_rpc_sem);
337 source_id.nid = request->rq_connection->c_peer.peer_nid;
338 source_id.pid = PTL_PID_ANY;
340 rc = PtlMEAttach(request->rq_connection->c_peer.peer_ni,
341 request->rq_import->imp_client->cli_reply_portal,
342 source_id, request->rq_xid, 0, PTL_UNLINK,
343 PTL_INS_AFTER, &request->rq_reply_me_h);
345 CERROR("PtlMEAttach failed: %d\n", rc);
350 request->rq_reply_md.start = repbuf;
351 request->rq_reply_md.length = request->rq_replen;
352 request->rq_reply_md.threshold = 1;
353 request->rq_reply_md.options = PTL_MD_OP_PUT;
354 request->rq_reply_md.user_ptr = request;
355 request->rq_reply_md.eventq = reply_in_eq;
357 rc = PtlMDAttach(request->rq_reply_me_h, request->rq_reply_md,
358 PTL_UNLINK, &request->rq_reply_md_h);
360 CERROR("PtlMDAttach failed: %d\n", rc);
365 CDEBUG(D_NET, "Setup reply buffer: %u bytes, xid %Lu, portal %u\n",
366 request->rq_replen, request->rq_xid,
367 request->rq_import->imp_client->cli_reply_portal);
369 rc = ptl_send_buf(request, request->rq_connection,
370 request->rq_import->imp_client->cli_request_portal);
374 PtlMEUnlink(request->rq_reply_me_h);
376 OBD_FREE(repbuf, request->rq_replen);
377 // up(&request->rq_client->cli_rpc_sem);
382 void ptlrpc_link_svc_me(struct ptlrpc_request_buffer_desc *rqbd)
384 struct ptlrpc_service *service = rqbd->rqbd_service;
385 static ptl_process_id_t match_id = {PTL_NID_ANY, PTL_PID_ANY};
388 ptl_handle_md_t md_h;
390 /* Attach the leading ME on which we build the ring */
391 rc = PtlMEAttach(service->srv_self.peer_ni, service->srv_req_portal,
393 PTL_UNLINK, PTL_INS_AFTER, &rqbd->rqbd_me_h);
395 CERROR("PtlMEAttach failed: %d\n", rc);
399 dummy.start = rqbd->rqbd_buffer;
400 dummy.length = service->srv_buf_size;
401 dummy.max_offset = service->srv_buf_size;
403 dummy.options = PTL_MD_OP_PUT;
404 dummy.user_ptr = rqbd;
405 dummy.eventq = service->srv_eq_h;
407 rc = PtlMDAttach(rqbd->rqbd_me_h, dummy, PTL_UNLINK, &md_h);
410 CERROR("PtlMDAttach failed: %d\n", rc);