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 atomic_set (&desc->bd_source_callback_count, 2);
135 list_for_each_safe(tmp, next, &desc->bd_page_list) {
136 struct ptlrpc_bulk_page *bulk;
137 bulk = list_entry(tmp, struct ptlrpc_bulk_page, bp_link);
139 LASSERT (desc->bd_md.niov < desc->bd_page_count);
141 if (desc->bd_md.niov == 0)
143 LASSERT (xid == bulk->bp_xid); /* should all be the same */
145 iov[desc->bd_md.niov].iov_base = bulk->bp_buf;
146 iov[desc->bd_md.niov].iov_len = bulk->bp_buflen;
148 desc->bd_md.length += bulk->bp_buflen;
151 LASSERT (desc->bd_md.niov == desc->bd_page_count);
152 LASSERT (desc->bd_md.niov != 0);
154 rc = PtlMDBind(desc->bd_connection->c_peer.peer_ni, desc->bd_md,
157 ptlrpc_put_bulk_iov (desc, iov); /* move down to reduce latency to send */
160 CERROR("PtlMDBind failed: %d\n", rc);
165 remote_id.nid = desc->bd_connection->c_peer.peer_nid;
168 CDEBUG(D_NET, "Sending %u pages %u bytes to portal %d nid %Lx pid %d xid %d\n",
169 desc->bd_md.niov, desc->bd_md.length,
170 desc->bd_portal, remote_id.nid, remote_id.pid, xid);
172 rc = PtlPut(desc->bd_md_h, PTL_ACK_REQ, remote_id,
173 desc->bd_portal, 0, xid, 0, 0);
175 CERROR("PtlPut(%Lu, %d, %d) failed: %d\n",
176 remote_id.nid, desc->bd_portal, xid, rc);
177 PtlMDUnlink(desc->bd_md_h);
185 int ptlrpc_register_bulk(struct ptlrpc_bulk_desc *desc)
187 struct list_head *tmp, *next;
191 ptl_process_id_t source_id;
194 iov = ptlrpc_get_bulk_iov (desc);
198 desc->bd_md.start = iov;
199 desc->bd_md.niov = 0;
200 desc->bd_md.length = 0;
201 desc->bd_md.threshold = 1;
202 desc->bd_md.options = PTL_MD_OP_PUT | PTL_MD_IOV;
203 desc->bd_md.user_ptr = desc;
204 desc->bd_md.eventq = bulk_sink_eq;
206 list_for_each_safe(tmp, next, &desc->bd_page_list) {
207 struct ptlrpc_bulk_page *bulk;
208 bulk = list_entry(tmp, struct ptlrpc_bulk_page, bp_link);
210 LASSERT (desc->bd_md.niov < desc->bd_page_count);
212 if (desc->bd_md.niov == 0)
214 LASSERT (xid == bulk->bp_xid); /* should all be the same */
216 iov[desc->bd_md.niov].iov_base = bulk->bp_buf;
217 iov[desc->bd_md.niov].iov_len = bulk->bp_buflen;
219 desc->bd_md.length += bulk->bp_buflen;
222 LASSERT (desc->bd_md.niov == desc->bd_page_count);
223 LASSERT (desc->bd_md.niov != 0);
225 source_id.nid = desc->bd_connection->c_peer.peer_nid;
226 source_id.pid = PTL_PID_ANY;
228 rc = PtlMEAttach(desc->bd_connection->c_peer.peer_ni,
229 desc->bd_portal, source_id, xid, 0,
230 PTL_UNLINK, PTL_INS_AFTER, &desc->bd_me_h);
232 ptlrpc_put_bulk_iov (desc, iov);
235 CERROR("PtlMEAttach failed: %d\n", rc);
240 rc = PtlMDAttach(desc->bd_me_h, desc->bd_md, PTL_UNLINK,
243 CERROR("PtlMDAttach failed: %d\n", rc);
248 CDEBUG(D_NET, "Setup bulk sink buffers: %u pages %u bytes, xid %u, "
249 "portal %u\n", desc->bd_md.niov, desc->bd_md.length,
250 xid, desc->bd_portal);
255 ptlrpc_abort_bulk(desc);
260 int ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc)
262 /* This should be safe: these handles are initialized to be
263 * invalid in ptlrpc_prep_bulk() */
264 PtlMDUnlink(desc->bd_md_h);
265 PtlMEUnlink(desc->bd_me_h);
270 int ptlrpc_reply(struct ptlrpc_service *svc, struct ptlrpc_request *req)
272 if (req->rq_repmsg == NULL) {
273 CERROR("bad: someone called ptlrpc_reply when they meant "
278 /* FIXME: we need to increment the count of handled events */
279 if (req->rq_type != PTL_RPC_MSG_ERR)
280 req->rq_type = PTL_RPC_MSG_REPLY;
281 //req->rq_repmsg->conn = req->rq_connection->c_remote_conn;
282 //req->rq_repmsg->token = req->rq_connection->c_remote_token;
283 req->rq_repmsg->status = HTON__u32(req->rq_status);
284 return ptl_send_buf(req, req->rq_connection, svc->srv_rep_portal);
287 int ptlrpc_error(struct ptlrpc_service *svc, struct ptlrpc_request *req)
292 if (req->rq_repmsg) {
293 CERROR("req already has repmsg\n");
297 rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
301 req->rq_repmsg->type = HTON__u32(PTL_RPC_MSG_ERR);
303 rc = ptlrpc_reply(svc, req);
307 int ptl_send_rpc(struct ptlrpc_request *request)
311 ptl_process_id_t source_id;
315 if (request->rq_type != PTL_RPC_MSG_REQUEST) {
316 CERROR("wrong packet type sent %d\n",
317 NTOH__u32(request->rq_reqmsg->type));
321 if (request->rq_replen == 0) {
322 CERROR("request->rq_replen is 0!\n");
326 /* request->rq_repmsg is set only when the reply comes in, in
327 * client_packet_callback() */
328 if (request->rq_reply_md.start)
329 OBD_FREE(request->rq_reply_md.start, request->rq_replen);
331 OBD_ALLOC(repbuf, request->rq_replen);
337 // down(&request->rq_client->cli_rpc_sem);
339 source_id.nid = request->rq_connection->c_peer.peer_nid;
340 source_id.pid = PTL_PID_ANY;
342 rc = PtlMEAttach(request->rq_connection->c_peer.peer_ni,
343 request->rq_import->imp_client->cli_reply_portal,
344 source_id, request->rq_xid, 0, PTL_UNLINK,
345 PTL_INS_AFTER, &request->rq_reply_me_h);
347 CERROR("PtlMEAttach failed: %d\n", rc);
352 request->rq_reply_md.start = repbuf;
353 request->rq_reply_md.length = request->rq_replen;
354 request->rq_reply_md.threshold = 1;
355 request->rq_reply_md.options = PTL_MD_OP_PUT;
356 request->rq_reply_md.user_ptr = request;
357 request->rq_reply_md.eventq = reply_in_eq;
359 rc = PtlMDAttach(request->rq_reply_me_h, request->rq_reply_md,
360 PTL_UNLINK, &request->rq_reply_md_h);
362 CERROR("PtlMDAttach failed: %d\n", rc);
367 CDEBUG(D_NET, "Setup reply buffer: %u bytes, xid %Lu, portal %u\n",
368 request->rq_replen, request->rq_xid,
369 request->rq_import->imp_client->cli_reply_portal);
371 rc = ptl_send_buf(request, request->rq_connection,
372 request->rq_import->imp_client->cli_request_portal);
376 PtlMEUnlink(request->rq_reply_me_h);
378 OBD_FREE(repbuf, request->rq_replen);
379 // up(&request->rq_client->cli_rpc_sem);
384 void ptlrpc_link_svc_me(struct ptlrpc_request_buffer_desc *rqbd)
386 struct ptlrpc_service *service = rqbd->rqbd_service;
387 static ptl_process_id_t match_id = {PTL_NID_ANY, PTL_PID_ANY};
390 ptl_handle_md_t md_h;
392 /* Attach the leading ME on which we build the ring */
393 rc = PtlMEAttach(service->srv_self.peer_ni, service->srv_req_portal,
395 PTL_UNLINK, PTL_INS_AFTER, &rqbd->rqbd_me_h);
397 CERROR("PtlMEAttach failed: %d\n", rc);
401 dummy.start = rqbd->rqbd_buffer;
402 dummy.length = service->srv_buf_size;
403 dummy.max_offset = service->srv_buf_size;
405 dummy.options = PTL_MD_OP_PUT;
406 dummy.user_ptr = rqbd;
407 dummy.eventq = service->srv_eq_h;
409 rc = PtlMDAttach(rqbd->rqbd_me_h, dummy, PTL_UNLINK, &md_h);
412 CERROR("PtlMDAttach failed: %d\n", rc);