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 ptl_handle_ni_t LUSTRE_NI;
33 static ptl_handle_eq_t req_eq;
34 static int req_initialized = 0;
36 /* This seems silly now, but some day we'll have more than one NI */
37 int req_get_peer(__u32 nid, struct lustre_peer *peer)
39 peer->peer_ni = req_ni;
44 static int request_callback(ptl_event_t *ev, void *data)
46 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
50 if (ev->type == PTL_EVENT_SENT) {
51 kfree(rpc->rq_reqbuf);
52 } else if (ev->type == PTL_EVENT_PUT) {
53 struct ptlrpc_request *clnt_rpc = rpc->rq_reply_handle;
55 rpc->rq_repbuf = ev->mem_desc.start + ev->offset;
57 wake_up_interruptible(&clnt_rpc->rq_wait_for_rep);
64 int ptl_send_buf(struct ptlrpc_request *request, struct lustre_peer *peer,
68 ptl_process_id_t remote_id;
71 request->rq_req_md.start = request->rq_reqbuf;
72 request->rq_req_md.length = request->rq_reqlen;
73 request->rq_req_md.threshold = PTL_MD_THRESH_INF;
74 request->rq_req_md.options = PTL_MD_OP_PUT;
75 request->rq_req_md.user_ptr = request;
76 request->rq_req_md.eventq = PTL_EQ_NONE;
78 rc = PtlMDBind(peer->peer_ni, request->rq_req_md, &md_h);
80 printk(__FUNCTION__ ": PtlMDBind failed: %d\n", rc);
84 remote_id.addr_kind = PTL_ADDR_NID;
85 remote_id.nid = peer->peer_nid;
88 rc = PtlPut(md_h, PTL_NOACK_REQ, remote_id, portal, 0, 0, 0, 0);
90 printk(__FUNCTION__ ": PtlPut failed: %d\n", rc);
91 /* FIXME: tear down md */
97 int ptl_send_rpc(struct ptlrpc_request *request, struct lustre_peer *peer)
99 ptl_handle_md_t reply_md_h;
100 ptl_handle_me_t me_h;
101 ptl_process_id_t local_id;
106 request->rq_repbuf = kmalloc(request->rq_replen, GFP_KERNEL);
107 if (!request->rq_repbuf) {
112 local_id.addr_kind = PTL_ADDR_GID;
113 local_id.gid = PTL_ID_ANY;
114 local_id.rid = PTL_ID_ANY;
116 rc = PtlMEAttach(peer->peer_ni, request->rq_reply_portal, local_id,
117 0, ~0, PTL_RETAIN, &me_h);
120 /* FIXME: tear down EQ, free reqbuf */
124 request->rq_reply_md.start = request->rq_repbuf;
125 request->rq_reply_md.length = request->rq_replen;
126 request->rq_reply_md.threshold = PTL_MD_THRESH_INF;
127 request->rq_reply_md.options = PTL_MD_OP_PUT;
128 request->rq_reply_md.user_ptr = request;
129 request->rq_reply_md.eventq = req_eq;
131 rc = PtlMDAttach(me_h, request->rq_reply_md, PTL_RETAIN, &reply_md_h);
137 return ptl_send_buf(request, peer, request->rq_req_portal);
141 //int req_init_event_queue(struct lustre_peer *peer);
143 static int req_init_portals(void)
146 rc = PtlEQAlloc(req_ni, 128, request_callback, NULL, &req_eq);
149 return rc; /* FIXME: does this portals rc make sense? */
155 static int __init req_init(void)
157 return req_init_portals();
160 static void __exit req_exit(void)
162 if (req_initialized) {
164 inter_module_put(LUSTRE_NAL "_init");
168 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
169 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
170 MODULE_LICENSE("GPL");
172 module_init(req_init);
173 module_exit(req_exit);