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.
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
29 #include <linux/obd_support.h>
30 #include <linux/lustre_net.h>
32 static ptl_handle_eq_t req_eq, bulk_source_eq, bulk_sink_eq;
34 static int request_callback(ptl_event_t *ev, void *data)
36 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
40 if (ev->type == PTL_EVENT_SENT) {
41 kfree(ev->mem_desc.start);
42 } else if (ev->type == PTL_EVENT_PUT) {
43 rpc->rq_repbuf = ev->mem_desc.start + ev->offset;
44 wake_up_interruptible(&rpc->rq_wait_for_rep);
51 static int incoming_callback(ptl_event_t *ev, void *data)
53 struct ptlrpc_service *service = data;
57 if (ev->type == PTL_EVENT_PUT) {
58 wake_up(service->srv_wait_queue);
60 printk("Unexpected event type: %d\n", ev->type);
67 static int bulk_source_callback(ptl_event_t *ev, void *data)
69 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
73 if (ev->type == PTL_EVENT_SENT) {
75 } else if (ev->type == PTL_EVENT_ACK) {
76 wake_up_interruptible(&rpc->rq_wait_for_bulk);
78 printk("Unexpected event type in " __FUNCTION__ "!\n");
85 static int bulk_sink_callback(ptl_event_t *ev, void *data)
87 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
91 if (ev->type == PTL_EVENT_PUT) {
92 if (rpc->rq_bulkbuf != ev->mem_desc.start + ev->offset)
93 printk(__FUNCTION__ ": bulkbuf != mem_desc -- why?\n");
94 wake_up_interruptible(&rpc->rq_wait_for_bulk);
96 printk("Unexpected event type in " __FUNCTION__ "!\n");
103 int ptl_send_buf(struct ptlrpc_request *request, struct lustre_peer *peer,
104 int portal, int is_request)
107 ptl_process_id_t remote_id;
108 ptl_handle_md_t md_h;
110 /* FIXME: This is bad. */
111 if (request->rq_bulklen) {
112 request->rq_req_md.start = request->rq_bulkbuf;
113 request->rq_req_md.length = request->rq_bulklen;
114 request->rq_req_md.eventq = bulk_source_eq;
115 } else if (is_request) {
116 request->rq_req_md.start = request->rq_reqbuf;
117 request->rq_req_md.length = request->rq_reqlen;
118 request->rq_req_md.eventq = req_eq;
120 request->rq_req_md.start = request->rq_repbuf;
121 request->rq_req_md.length = request->rq_replen;
122 request->rq_req_md.eventq = req_eq;
124 request->rq_req_md.threshold = 1;
125 request->rq_req_md.options = PTL_MD_OP_PUT;
126 request->rq_req_md.user_ptr = request;
128 rc = PtlMDBind(peer->peer_ni, request->rq_req_md, &md_h);
130 printk(__FUNCTION__ ": PtlMDBind failed: %d\n", rc);
134 remote_id.addr_kind = PTL_ADDR_NID;
135 remote_id.nid = peer->peer_nid;
138 if (request->rq_bulklen) {
139 rc = PtlPut(md_h, PTL_ACK_REQ, remote_id, portal, 0,
140 request->rq_xid, 0, 0);
142 rc = PtlPut(md_h, PTL_NOACK_REQ, remote_id, portal, 0,
143 request->rq_xid, 0, 0);
146 printk(__FUNCTION__ ": PtlPut failed: %d\n", rc);
147 /* FIXME: tear down md */
153 int ptl_send_rpc(struct ptlrpc_request *request, struct lustre_peer *peer)
155 ptl_handle_me_t me_h, bulk_me_h;
156 ptl_process_id_t local_id;
161 request->rq_repbuf = kmalloc(request->rq_replen, GFP_KERNEL);
162 if (!request->rq_repbuf) {
167 local_id.addr_kind = PTL_ADDR_GID;
168 local_id.gid = PTL_ID_ANY;
169 local_id.rid = PTL_ID_ANY;
171 rc = PtlMEAttach(peer->peer_ni, request->rq_reply_portal, local_id,
172 request->rq_xid, 0, PTL_UNLINK, &me_h);
175 /* FIXME: tear down EQ, free reqbuf */
179 request->rq_reply_md.start = request->rq_repbuf;
180 request->rq_reply_md.length = request->rq_replen;
181 request->rq_reply_md.threshold = 1;
182 request->rq_reply_md.options = PTL_MD_OP_PUT;
183 request->rq_reply_md.user_ptr = request;
184 request->rq_reply_md.eventq = req_eq;
186 rc = PtlMDAttach(me_h, request->rq_reply_md, PTL_UNLINK,
187 &request->rq_reply_md_h);
193 if (request->rq_bulklen != 0) {
194 rc = PtlMEAttach(peer->peer_ni, request->rq_bulk_portal,
195 local_id, request->rq_xid, 0, PTL_UNLINK,
202 request->rq_bulk_md.start = request->rq_bulkbuf;
203 request->rq_bulk_md.length = request->rq_bulklen;
204 request->rq_bulk_md.threshold = 1;
205 request->rq_bulk_md.options = PTL_MD_OP_PUT;
206 request->rq_bulk_md.user_ptr = request;
207 request->rq_bulk_md.eventq = bulk_sink_eq;
209 rc = PtlMDAttach(bulk_me_h, request->rq_bulk_md, PTL_UNLINK,
210 &request->rq_bulk_md_h);
217 return ptl_send_buf(request, peer, request->rq_req_portal, 1);
220 int rpc_register_service(struct ptlrpc_service *service, char *uuid)
222 struct lustre_peer peer;
225 rc = kportal_uuid_to_peer(uuid, &peer);
227 printk("Invalid uuid \"%s\"\n", uuid);
231 service->srv_buf = kmalloc(service->srv_buf_size, GFP_KERNEL);
232 if (service->srv_buf == NULL) {
233 printk(__FUNCTION__ ": no memory\n");
237 service->srv_id.addr_kind = PTL_ADDR_GID;
238 service->srv_id.gid = PTL_ID_ANY;
239 service->srv_id.rid = PTL_ID_ANY;
241 rc = PtlMEAttach(peer.peer_ni, service->srv_portal, service->srv_id,
242 0, ~0, PTL_RETAIN, &service->srv_me);
244 printk("PtlMEAttach failed: %d\n", rc);
248 rc = PtlEQAlloc(peer.peer_ni, 128, incoming_callback, service,
251 printk("PtlEQAlloc failed: %d\n", rc);
255 /* FIXME: Build an auto-unlinking MD and build a ring. */
256 /* FIXME: Make sure that these are reachable by DMA on well-known
258 service->srv_md.start = service->srv_buf;
259 service->srv_md.length = service->srv_buf_size;
260 service->srv_md.threshold = PTL_MD_THRESH_INF;
261 service->srv_md.options = PTL_MD_OP_PUT;
262 service->srv_md.user_ptr = service;
263 service->srv_md.eventq = service->srv_eq;
265 rc = PtlMDAttach(service->srv_me, service->srv_md,
266 PTL_RETAIN, &service->srv_md_h);
268 printk("PtlMDAttach failed: %d\n", rc);
269 /* FIXME: wow, we need to clean up. */
276 static int req_init_portals(void)
279 const ptl_handle_ni_t *nip;
282 nip = inter_module_get_request(LUSTRE_NAL "_ni", LUSTRE_NAL);
284 printk("get_ni failed: is the NAL module loaded?\n");
289 rc = PtlEQAlloc(ni, 128, request_callback, NULL, &req_eq);
291 printk("PtlEQAlloc failed: %d\n", rc);
293 rc = PtlEQAlloc(ni, 128, bulk_source_callback, NULL, &bulk_source_eq);
295 printk("PtlEQAlloc failed: %d\n", rc);
297 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, NULL, &bulk_sink_eq);
299 printk("PtlEQAlloc failed: %d\n", rc);
304 static int __init req_init(void)
306 return req_init_portals();
309 static void __exit req_exit(void)
313 inter_module_put(LUSTRE_NAL "_ni");
318 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
319 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
320 MODULE_LICENSE("GPL");
322 module_init(req_init);
323 module_exit(req_exit);