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 request->rq_repbuf = kmalloc(request->rq_replen, GFP_KERNEL);
167 if (!request->rq_repbuf) {
172 local_id.addr_kind = PTL_ADDR_GID;
173 local_id.gid = PTL_ID_ANY;
174 local_id.rid = PTL_ID_ANY;
176 rc = PtlMEAttach(peer->peer_ni, request->rq_reply_portal, local_id,
177 request->rq_xid, 0, PTL_UNLINK, &me_h);
180 /* FIXME: tear down EQ, free reqbuf */
184 request->rq_reply_md.start = request->rq_repbuf;
185 request->rq_reply_md.length = request->rq_replen;
186 request->rq_reply_md.threshold = 1;
187 request->rq_reply_md.options = PTL_MD_OP_PUT;
188 request->rq_reply_md.user_ptr = request;
189 request->rq_reply_md.eventq = req_eq;
191 rc = PtlMDAttach(me_h, request->rq_reply_md, PTL_UNLINK,
192 &request->rq_reply_md_h);
198 if (request->rq_bulklen != 0) {
199 rc = PtlMEAttach(peer->peer_ni, request->rq_bulk_portal,
200 local_id, request->rq_xid, 0, PTL_UNLINK,
207 request->rq_bulk_md.start = request->rq_bulkbuf;
208 request->rq_bulk_md.length = request->rq_bulklen;
209 request->rq_bulk_md.threshold = 1;
210 request->rq_bulk_md.options = PTL_MD_OP_PUT;
211 request->rq_bulk_md.user_ptr = request;
212 request->rq_bulk_md.eventq = bulk_sink_eq;
214 rc = PtlMDAttach(bulk_me_h, request->rq_bulk_md, PTL_UNLINK,
215 &request->rq_bulk_md_h);
222 return ptl_send_buf(request, peer, request->rq_req_portal, 1);
225 int rpc_register_service(struct ptlrpc_service *service, char *uuid)
227 struct lustre_peer peer;
230 rc = kportal_uuid_to_peer(uuid, &peer);
232 printk("Invalid uuid \"%s\"\n", uuid);
236 service->srv_buf = kmalloc(service->srv_buf_size, GFP_KERNEL);
237 if (service->srv_buf == NULL) {
238 printk(__FUNCTION__ ": no memory\n");
242 service->srv_id.addr_kind = PTL_ADDR_GID;
243 service->srv_id.gid = PTL_ID_ANY;
244 service->srv_id.rid = PTL_ID_ANY;
246 rc = PtlMEAttach(peer.peer_ni, service->srv_portal, service->srv_id,
247 0, ~0, PTL_RETAIN, &service->srv_me_h);
249 printk("PtlMEAttach failed: %d\n", rc);
253 rc = PtlEQAlloc(peer.peer_ni, 128, incoming_callback, service,
256 printk("PtlEQAlloc failed: %d\n", rc);
260 /* FIXME: Build an auto-unlinking MD and build a ring. */
261 /* FIXME: Make sure that these are reachable by DMA on well-known
263 service->srv_md.start = service->srv_buf;
264 service->srv_md.length = service->srv_buf_size;
265 service->srv_md.threshold = PTL_MD_THRESH_INF;
266 service->srv_md.options = PTL_MD_OP_PUT;
267 service->srv_md.user_ptr = service;
268 service->srv_md.eventq = service->srv_eq_h;
270 rc = PtlMDAttach(service->srv_me_h, service->srv_md,
271 PTL_RETAIN, &service->srv_md_h);
273 printk("PtlMDAttach failed: %d\n", rc);
274 /* FIXME: wow, we need to clean up. */
281 int rpc_unregister_service(struct ptlrpc_service *service)
285 rc = PtlMDUnlink(service->srv_md_h);
287 printk(__FUNCTION__ ": PtlMDUnlink failed: %d\n", rc);
288 rc = PtlEQFree(service->srv_eq_h);
290 printk(__FUNCTION__ ": PtlEQFree failed: %d\n", rc);
291 rc = PtlMEUnlink(service->srv_me_h);
293 printk(__FUNCTION__ ": PtlMEUnlink failed: %d\n", rc);
295 kfree(service->srv_buf);
298 static int req_init_portals(void)
301 const ptl_handle_ni_t *nip;
304 nip = inter_module_get_request(LUSTRE_NAL "_ni", LUSTRE_NAL);
306 printk("get_ni failed: is the NAL module loaded?\n");
311 rc = PtlEQAlloc(ni, 128, request_callback, NULL, &req_eq);
313 printk("PtlEQAlloc failed: %d\n", rc);
315 rc = PtlEQAlloc(ni, 128, bulk_source_callback, NULL, &bulk_source_eq);
317 printk("PtlEQAlloc failed: %d\n", rc);
319 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, NULL, &bulk_sink_eq);
321 printk("PtlEQAlloc failed: %d\n", rc);
326 static int init_module(void)
328 return req_init_portals();
331 static void cleanup_module(void)
335 inter_module_put(LUSTRE_NAL "_ni");
340 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
341 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
342 MODULE_LICENSE("GPL");