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;
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 int ptl_send_buf(struct ptlrpc_request *request, struct lustre_peer *peer,
68 int portal, int is_request)
71 ptl_process_id_t remote_id;
75 request->rq_req_md.start = request->rq_reqbuf;
76 request->rq_req_md.length = request->rq_reqlen;
78 request->rq_req_md.start = request->rq_repbuf;
79 request->rq_req_md.length = request->rq_replen;
81 request->rq_req_md.threshold = PTL_MD_THRESH_INF;
82 request->rq_req_md.options = PTL_MD_OP_PUT;
83 request->rq_req_md.user_ptr = request;
84 request->rq_req_md.eventq = req_eq;
86 rc = PtlMDBind(peer->peer_ni, request->rq_req_md, &md_h);
88 printk(__FUNCTION__ ": PtlMDBind failed: %d\n", rc);
92 remote_id.addr_kind = PTL_ADDR_NID;
93 remote_id.nid = peer->peer_nid;
96 rc = PtlPut(md_h, PTL_NOACK_REQ, remote_id, portal, 0, request->rq_xid,
99 printk(__FUNCTION__ ": PtlPut failed: %d\n", rc);
100 /* FIXME: tear down md */
106 int ptl_send_rpc(struct ptlrpc_request *request, struct lustre_peer *peer)
108 ptl_handle_md_t reply_md_h;
109 ptl_handle_me_t me_h;
110 ptl_process_id_t local_id;
115 request->rq_repbuf = kmalloc(request->rq_replen, GFP_KERNEL);
116 if (!request->rq_repbuf) {
121 local_id.addr_kind = PTL_ADDR_GID;
122 local_id.gid = PTL_ID_ANY;
123 local_id.rid = PTL_ID_ANY;
125 rc = PtlMEAttach(peer->peer_ni, request->rq_reply_portal, local_id,
126 request->rq_xid, 0, PTL_RETAIN, &me_h);
129 /* FIXME: tear down EQ, free reqbuf */
133 request->rq_reply_md.start = request->rq_repbuf;
134 request->rq_reply_md.length = request->rq_replen;
135 request->rq_reply_md.threshold = PTL_MD_THRESH_INF;
136 request->rq_reply_md.options = PTL_MD_OP_PUT;
137 request->rq_reply_md.user_ptr = request;
138 request->rq_reply_md.eventq = req_eq;
140 rc = PtlMDAttach(me_h, request->rq_reply_md, PTL_RETAIN, &reply_md_h);
146 return ptl_send_buf(request, peer, request->rq_req_portal, 1);
149 int rpc_register_service(struct ptlrpc_service *service, char *uuid)
151 struct lustre_peer peer;
154 rc = kportal_uuid_to_peer(uuid, &peer);
156 printk("Invalid uuid \"%s\"\n", uuid);
160 service->srv_buf = kmalloc(service->srv_buf_size, GFP_KERNEL);
161 if (service->srv_buf == NULL) {
162 printk(__FUNCTION__ ": no memory\n");
166 service->srv_id.addr_kind = PTL_ADDR_GID;
167 service->srv_id.gid = PTL_ID_ANY;
168 service->srv_id.rid = PTL_ID_ANY;
170 rc = PtlMEAttach(peer.peer_ni, service->srv_portal, service->srv_id,
171 0, ~0, PTL_RETAIN, &service->srv_me);
173 printk("PtlMEAttach failed: %d\n", rc);
177 rc = PtlEQAlloc(peer.peer_ni, 128, incoming_callback, service,
180 printk("PtlEQAlloc failed: %d\n", rc);
184 /* FIXME: Build an auto-unlinking MD and build a ring. */
185 /* FIXME: Make sure that these are reachable by DMA on well-known
187 service->srv_md.start = service->srv_buf;
188 service->srv_md.length = service->srv_buf_size;
189 service->srv_md.threshold = PTL_MD_THRESH_INF;
190 service->srv_md.options = PTL_MD_OP_PUT;
191 service->srv_md.user_ptr = service;
192 service->srv_md.eventq = service->srv_eq;
194 rc = PtlMDAttach(service->srv_me, service->srv_md,
195 PTL_RETAIN, &service->srv_md_h);
197 printk("PtlMDAttach failed: %d\n", rc);
198 /* FIXME: wow, we need to clean up. */
205 static int req_init_portals(void)
208 const ptl_handle_ni_t *nip;
211 nip = inter_module_get_request(LUSTRE_NAL "_ni", LUSTRE_NAL);
213 printk("get_ni failed: is the NAL module loaded?\n");
218 rc = PtlEQAlloc(ni, 128, request_callback, NULL, &req_eq);
220 printk("PtlEQAlloc failed: %d\n", rc);
225 static int __init req_init(void)
227 return req_init_portals();
230 static void __exit req_exit(void)
234 inter_module_put(LUSTRE_NAL "_ni");
239 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
240 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
241 MODULE_LICENSE("GPL");
243 module_init(req_init);
244 module_exit(req_exit);