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)
40 if (ev->type != PTL_EVENT_SENT) {
41 // XXX make sure we understand all events, including ACK's
42 CERROR("Unknown event %d\n", ev->type);
51 * Free the packet when it has gone out
53 static int reply_out_callback(ptl_event_t *ev, void *data)
57 if (ev->type == PTL_EVENT_SENT) {
58 OBD_FREE(ev->mem_desc.start, ev->mem_desc.length);
60 // XXX make sure we understand all events, including ACK's
61 CERROR("Unknown event %d\n", ev->type);
69 * Wake up the thread waiting for the reply once it comes in.
71 static int reply_in_callback(ptl_event_t *ev, void *data)
73 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
76 if (ev->type == PTL_EVENT_PUT) {
77 rpc->rq_repmsg = ev->mem_desc.start + ev->offset;
79 wake_up_interruptible(&rpc->rq_wait_for_rep);
81 // XXX make sure we understand all events, including ACK's
82 CERROR("Unknown event %d\n", ev->type);
89 int request_in_callback(ptl_event_t *ev, void *data)
91 struct ptlrpc_service *service = data;
94 if (ev->rlength != ev->mlength)
95 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
96 ev->mlength, ev->rlength);
98 spin_lock(&service->srv_lock);
99 for (index = 0; index < service->srv_ring_length; index++)
100 if ( service->srv_buf[index] == ev->mem_desc.start)
103 if (index == service->srv_ring_length)
106 service->srv_ref_count[index]++;
108 if (ptl_is_valid_handle(&ev->unlinked_me)) {
111 for (idx = 0; idx < service->srv_ring_length; idx++)
112 if (service->srv_me_h[idx].handle_idx ==
113 ev->unlinked_me.handle_idx)
115 if (idx == service->srv_ring_length)
118 CDEBUG(D_NET, "unlinked %d\n", idx);
119 ptl_set_inv_handle(&(service->srv_me_h[idx]));
121 if (service->srv_ref_count[idx] == 0)
122 ptlrpc_link_svc_me(service, idx);
125 spin_unlock(&service->srv_lock);
126 if (ev->type == PTL_EVENT_PUT)
127 wake_up(&service->srv_waitq);
129 CERROR("Unexpected event type: %d\n", ev->type);
134 static int bulk_source_callback(ptl_event_t *ev, void *data)
136 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
137 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
140 if (ev->type == PTL_EVENT_SENT) {
141 CDEBUG(D_NET, "got SENT event\n");
142 } else if (ev->type == PTL_EVENT_ACK) {
143 CDEBUG(D_NET, "got ACK event\n");
144 desc->b_flags |= PTL_BULK_FL_SENT;
145 wake_up_interruptible(&desc->b_waitq);
147 CERROR("Unexpected event type!\n");
154 static int bulk_sink_callback(ptl_event_t *ev, void *data)
156 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
157 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
160 if (ev->type == PTL_EVENT_PUT) {
161 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
162 CERROR("bulkbuf != mem_desc -- why?\n");
163 desc->b_finished_count++;
164 if (desc->b_finished_count == desc->b_page_count) {
165 desc->b_flags |= PTL_BULK_FL_RCVD;
166 wake_up_interruptible(&desc->b_waitq);
167 if (desc->b_cb != NULL)
170 if (bulk->b_cb != NULL)
173 CERROR("Unexpected event type!\n");
180 int ptlrpc_init_portals(void)
185 socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
186 qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
187 if (socknal_nip == NULL && qswnal_nip == NULL) {
188 CERROR("get_ni failed: is a NAL module loaded?\n");
192 /* Use the qswnal if it's there */
193 if (qswnal_nip != NULL)
198 rc = PtlEQAlloc(ni, 128, request_out_callback, NULL, &request_out_eq);
200 CERROR("PtlEQAlloc failed: %d\n", rc);
202 rc = PtlEQAlloc(ni, 128, reply_out_callback, NULL, &reply_out_eq);
204 CERROR("PtlEQAlloc failed: %d\n", rc);
206 rc = PtlEQAlloc(ni, 128, reply_in_callback, NULL, &reply_in_eq);
208 CERROR("PtlEQAlloc failed: %d\n", rc);
210 rc = PtlEQAlloc(ni, 128, bulk_source_callback, NULL, &bulk_source_eq);
212 CERROR("PtlEQAlloc failed: %d\n", rc);
214 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, NULL, &bulk_sink_eq);
216 CERROR("PtlEQAlloc failed: %d\n", rc);
221 void ptlrpc_exit_portals(void)
223 PtlEQFree(request_out_eq);
224 PtlEQFree(reply_out_eq);
225 PtlEQFree(reply_in_eq);
226 PtlEQFree(bulk_source_eq);
227 PtlEQFree(bulk_sink_eq);
229 if (qswnal_nip != NULL)
230 inter_module_put("kqswnal_ni");
231 if (socknal_nip != NULL)
232 inter_module_put("ksocknal_ni");