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 /* This callback performs two functions:
36 * 1. Free the request buffer after it has gone out on the wire
37 * 2. Wake up the thread waiting for the reply once it comes in.
39 static int request_callback(ptl_event_t *ev, void *data)
41 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
45 if (ev->type == PTL_EVENT_SENT) {
46 kfree(ev->mem_desc.start);
47 } else if (ev->type == PTL_EVENT_PUT) {
48 rpc->rq_repbuf = ev->mem_desc.start + ev->offset;
49 wake_up_interruptible(&rpc->rq_wait_for_rep);
56 static int incoming_callback(ptl_event_t *ev, void *data)
58 struct ptlrpc_service *service = data;
62 if (ev->type == PTL_EVENT_PUT) {
63 wake_up(service->srv_wait_queue);
65 printk("Unexpected event type: %d\n", ev->type);
72 static int bulk_source_callback(ptl_event_t *ev, void *data)
74 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
78 if (ev->type == PTL_EVENT_SENT) {
80 } else if (ev->type == PTL_EVENT_ACK) {
81 wake_up_interruptible(&rpc->rq_wait_for_bulk);
83 printk("Unexpected event type in " __FUNCTION__ "!\n");
90 static int bulk_sink_callback(ptl_event_t *ev, void *data)
92 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
96 if (ev->type == PTL_EVENT_PUT) {
97 if (rpc->rq_bulkbuf != ev->mem_desc.start + ev->offset)
98 printk(__FUNCTION__ ": bulkbuf != mem_desc -- why?\n");
99 wake_up_interruptible(&rpc->rq_wait_for_bulk);
101 printk("Unexpected event type in " __FUNCTION__ "!\n");
108 int ptl_send_buf(struct ptlrpc_request *request, struct lustre_peer *peer,
109 int portal, int is_request)
112 ptl_process_id_t remote_id;
113 ptl_handle_md_t md_h;
115 /* FIXME: This is bad. */
116 if (request->rq_bulklen) {
117 request->rq_req_md.start = request->rq_bulkbuf;
118 request->rq_req_md.length = request->rq_bulklen;
119 request->rq_req_md.eventq = bulk_source_eq;
120 } else if (is_request) {
121 request->rq_req_md.start = request->rq_reqbuf;
122 request->rq_req_md.length = request->rq_reqlen;
123 request->rq_req_md.eventq = req_eq;
125 request->rq_req_md.start = request->rq_repbuf;
126 request->rq_req_md.length = request->rq_replen;
127 request->rq_req_md.eventq = req_eq;
129 request->rq_req_md.threshold = 1;
130 request->rq_req_md.options = PTL_MD_OP_PUT;
131 request->rq_req_md.user_ptr = request;
133 rc = PtlMDBind(peer->peer_ni, request->rq_req_md, &md_h);
135 printk(__FUNCTION__ ": PtlMDBind failed: %d\n", rc);
139 remote_id.addr_kind = PTL_ADDR_NID;
140 remote_id.nid = peer->peer_nid;
143 if (request->rq_bulklen) {
144 rc = PtlPut(md_h, PTL_ACK_REQ, remote_id, portal, 0,
145 request->rq_xid, 0, 0);
147 rc = PtlPut(md_h, PTL_NOACK_REQ, remote_id, portal, 0,
148 request->rq_xid, 0, 0);
151 printk(__FUNCTION__ ": PtlPut failed: %d\n", rc);
152 /* FIXME: tear down md */
158 int ptl_send_rpc(struct ptlrpc_request *request, struct lustre_peer *peer)
160 ptl_handle_me_t me_h, bulk_me_h;
161 ptl_process_id_t local_id;
166 if (request->rq_replen == 0) {
167 printk(__FUNCTION__ ": request->rq_replen is 0!\n");
172 request->rq_repbuf = kmalloc(request->rq_replen, GFP_KERNEL);
173 if (!request->rq_repbuf) {
178 local_id.addr_kind = PTL_ADDR_GID;
179 local_id.gid = PTL_ID_ANY;
180 local_id.rid = PTL_ID_ANY;
182 rc = PtlMEAttach(peer->peer_ni, request->rq_reply_portal, local_id,
183 request->rq_xid, 0, PTL_UNLINK, &me_h);
186 /* FIXME: tear down EQ, free reqbuf */
190 request->rq_reply_md.start = request->rq_repbuf;
191 request->rq_reply_md.length = request->rq_replen;
192 request->rq_reply_md.threshold = 1;
193 request->rq_reply_md.options = PTL_MD_OP_PUT;
194 request->rq_reply_md.user_ptr = request;
195 request->rq_reply_md.eventq = req_eq;
197 rc = PtlMDAttach(me_h, request->rq_reply_md, PTL_UNLINK,
198 &request->rq_reply_md_h);
204 if (request->rq_bulklen != 0) {
205 rc = PtlMEAttach(peer->peer_ni, request->rq_bulk_portal,
206 local_id, request->rq_xid, 0, PTL_UNLINK,
213 request->rq_bulk_md.start = request->rq_bulkbuf;
214 request->rq_bulk_md.length = request->rq_bulklen;
215 request->rq_bulk_md.threshold = 1;
216 request->rq_bulk_md.options = PTL_MD_OP_PUT;
217 request->rq_bulk_md.user_ptr = request;
218 request->rq_bulk_md.eventq = bulk_sink_eq;
220 rc = PtlMDAttach(bulk_me_h, request->rq_bulk_md, PTL_UNLINK,
221 &request->rq_bulk_md_h);
228 return ptl_send_buf(request, peer, request->rq_req_portal, 1);
231 int rpc_register_service(struct ptlrpc_service *service, char *uuid)
233 struct lustre_peer peer;
236 rc = kportal_uuid_to_peer(uuid, &peer);
238 printk("Invalid uuid \"%s\"\n", uuid);
242 service->srv_buf = kmalloc(service->srv_buf_size, GFP_KERNEL);
243 if (service->srv_buf == NULL) {
244 printk(__FUNCTION__ ": no memory\n");
248 service->srv_id.addr_kind = PTL_ADDR_GID;
249 service->srv_id.gid = PTL_ID_ANY;
250 service->srv_id.rid = PTL_ID_ANY;
252 rc = PtlMEAttach(peer.peer_ni, service->srv_portal, service->srv_id,
253 0, ~0, PTL_RETAIN, &service->srv_me_h);
255 printk("PtlMEAttach failed: %d\n", rc);
259 rc = PtlEQAlloc(peer.peer_ni, 128, incoming_callback, service,
262 printk("PtlEQAlloc failed: %d\n", rc);
266 /* FIXME: Build an auto-unlinking MD and build a ring. */
267 /* FIXME: Make sure that these are reachable by DMA on well-known
269 service->srv_md.start = service->srv_buf;
270 service->srv_md.length = service->srv_buf_size;
271 service->srv_md.threshold = PTL_MD_THRESH_INF;
272 service->srv_md.options = PTL_MD_OP_PUT;
273 service->srv_md.user_ptr = service;
274 service->srv_md.eventq = service->srv_eq_h;
276 rc = PtlMDAttach(service->srv_me_h, service->srv_md,
277 PTL_RETAIN, &service->srv_md_h);
279 printk("PtlMDAttach failed: %d\n", rc);
280 /* FIXME: wow, we need to clean up. */
287 int rpc_unregister_service(struct ptlrpc_service *service)
291 rc = PtlMDUnlink(service->srv_md_h);
293 printk(__FUNCTION__ ": PtlMDUnlink failed: %d\n", rc);
294 rc = PtlEQFree(service->srv_eq_h);
296 printk(__FUNCTION__ ": PtlEQFree failed: %d\n", rc);
297 rc = PtlMEUnlink(service->srv_me_h);
299 printk(__FUNCTION__ ": PtlMEUnlink failed: %d\n", rc);
301 kfree(service->srv_buf);
305 static int req_init_portals(void)
308 const ptl_handle_ni_t *nip;
311 nip = inter_module_get_request(LUSTRE_NAL "_ni", LUSTRE_NAL);
313 printk("get_ni failed: is the NAL module loaded?\n");
318 rc = PtlEQAlloc(ni, 128, request_callback, NULL, &req_eq);
320 printk("PtlEQAlloc failed: %d\n", rc);
322 rc = PtlEQAlloc(ni, 128, bulk_source_callback, NULL, &bulk_source_eq);
324 printk("PtlEQAlloc failed: %d\n", rc);
326 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, NULL, &bulk_sink_eq);
328 printk("PtlEQAlloc failed: %d\n", rc);
333 static int init_module(void)
335 return req_init_portals();
338 static void cleanup_module(void)
342 inter_module_put(LUSTRE_NAL "_ni");
347 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
348 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
349 MODULE_LICENSE("GPL");