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.
24 #define DEBUG_SUBSYSTEM S_RPC
26 #include <linux/module.h>
27 #include <linux/lustre_net.h>
29 ptl_handle_eq_t request_out_eq, reply_in_eq, reply_out_eq, bulk_source_eq,
31 static const ptl_handle_ni_t *socknal_nip = NULL, *qswnal_nip = NULL;
34 * Free the packet when it has gone out
36 static int request_out_callback(ptl_event_t *ev, void *data)
38 struct ptlrpc_request *req = ev->mem_desc.user_ptr;
39 struct ptlrpc_client *cl = req->rq_client;
43 if (ev->type == PTL_EVENT_SENT) {
44 spin_lock(&req->rq_client->cli_lock);
45 list_del(&req->rq_list);
46 list_add(&req->rq_list, &cl->cli_sent_head);
47 spin_unlock(&req->rq_client->cli_lock);
49 // XXX make sure we understand all events, including ACK's
50 CERROR("Unknown event %d\n", ev->type);
59 * Free the packet when it has gone out
61 static int reply_out_callback(ptl_event_t *ev, void *data)
65 if (ev->type == PTL_EVENT_SENT) {
66 OBD_FREE(ev->mem_desc.start, ev->mem_desc.length);
68 // XXX make sure we understand all events, including ACK's
69 CERROR("Unknown event %d\n", ev->type);
77 * Wake up the thread waiting for the reply once it comes in.
79 static int reply_in_callback(ptl_event_t *ev, void *data)
81 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
84 if (ev->type == PTL_EVENT_PUT) {
85 rpc->rq_repmsg = ev->mem_desc.start + ev->offset;
87 wake_up_interruptible(&rpc->rq_wait_for_rep);
89 // XXX make sure we understand all events, including ACK's
90 CERROR("Unknown event %d\n", ev->type);
97 int request_in_callback(ptl_event_t *ev, void *data)
99 struct ptlrpc_service *service = data;
102 if (ev->rlength != ev->mlength)
103 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
104 ev->mlength, ev->rlength);
106 spin_lock(&service->srv_lock);
107 for (index = 0; index < service->srv_ring_length; index++)
108 if ( service->srv_buf[index] == ev->mem_desc.start)
111 if (index == service->srv_ring_length)
114 service->srv_ref_count[index]++;
116 if (ptl_is_valid_handle(&ev->unlinked_me)) {
119 for (idx = 0; idx < service->srv_ring_length; idx++)
120 if (service->srv_me_h[idx].handle_idx ==
121 ev->unlinked_me.handle_idx)
123 if (idx == service->srv_ring_length)
126 CDEBUG(D_NET, "unlinked %d\n", idx);
127 ptl_set_inv_handle(&(service->srv_me_h[idx]));
129 if (service->srv_ref_count[idx] == 0)
130 ptlrpc_link_svc_me(service, idx);
133 spin_unlock(&service->srv_lock);
134 if (ev->type == PTL_EVENT_PUT)
135 wake_up(&service->srv_waitq);
137 CERROR("Unexpected event type: %d\n", ev->type);
142 static int bulk_source_callback(ptl_event_t *ev, void *data)
144 struct ptlrpc_bulk_desc *bulk = ev->mem_desc.user_ptr;
147 if (ev->type == PTL_EVENT_SENT) {
148 CDEBUG(D_NET, "got SENT event\n");
149 } else if (ev->type == PTL_EVENT_ACK) {
150 CDEBUG(D_NET, "got ACK event\n");
151 bulk->b_flags |= PTL_BULK_FL_SENT;
152 wake_up_interruptible(&bulk->b_waitq);
154 CERROR("Unexpected event type!\n");
161 static int bulk_sink_callback(ptl_event_t *ev, void *data)
163 struct ptlrpc_bulk_desc *bulk = ev->mem_desc.user_ptr;
166 if (ev->type == PTL_EVENT_PUT) {
167 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
168 CERROR("bulkbuf != mem_desc -- why?\n");
169 bulk->b_flags |= PTL_BULK_FL_RCVD;
170 if (bulk->b_cb != NULL)
171 bulk->b_cb(bulk, data);
172 wake_up_interruptible(&bulk->b_waitq);
174 CERROR("Unexpected event type!\n");
178 /* FIXME: This should happen unconditionally */
179 if (bulk->b_cb != NULL)
180 ptlrpc_free_bulk(bulk);
185 int ptlrpc_init_portals(void)
190 socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
191 qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
192 if (socknal_nip == NULL && qswnal_nip == NULL) {
193 CERROR("get_ni failed: is a NAL module loaded?\n");
197 /* Use the qswnal if it's there */
198 if (qswnal_nip != NULL)
203 rc = PtlEQAlloc(ni, 128, request_out_callback, NULL, &request_out_eq);
205 CERROR("PtlEQAlloc failed: %d\n", rc);
207 rc = PtlEQAlloc(ni, 128, reply_out_callback, NULL, &reply_out_eq);
209 CERROR("PtlEQAlloc failed: %d\n", rc);
211 rc = PtlEQAlloc(ni, 128, reply_in_callback, NULL, &reply_in_eq);
213 CERROR("PtlEQAlloc failed: %d\n", rc);
215 rc = PtlEQAlloc(ni, 128, bulk_source_callback, NULL, &bulk_source_eq);
217 CERROR("PtlEQAlloc failed: %d\n", rc);
219 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, NULL, &bulk_sink_eq);
221 CERROR("PtlEQAlloc failed: %d\n", rc);
226 void ptlrpc_exit_portals(void)
228 PtlEQFree(request_out_eq);
229 PtlEQFree(reply_out_eq);
230 PtlEQFree(reply_in_eq);
231 PtlEQFree(bulk_source_eq);
232 PtlEQFree(bulk_sink_eq);
234 if (qswnal_nip != NULL)
235 inter_module_put("kqswnal_ni");
236 if (socknal_nip != NULL)
237 inter_module_put("ksocknal_ni");