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_desc *bulk = ev->mem_desc.user_ptr;
139 if (ev->type == PTL_EVENT_SENT) {
140 CDEBUG(D_NET, "got SENT event\n");
141 } else if (ev->type == PTL_EVENT_ACK) {
142 CDEBUG(D_NET, "got ACK event\n");
143 bulk->b_flags |= PTL_BULK_FL_SENT;
144 wake_up_interruptible(&bulk->b_waitq);
146 CERROR("Unexpected event type!\n");
153 static int bulk_sink_callback(ptl_event_t *ev, void *data)
155 struct ptlrpc_bulk_desc *bulk = ev->mem_desc.user_ptr;
158 if (ev->type == PTL_EVENT_PUT) {
159 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
160 CERROR("bulkbuf != mem_desc -- why?\n");
161 bulk->b_flags |= PTL_BULK_FL_RCVD;
162 if (bulk->b_cb != NULL)
163 bulk->b_cb(bulk, data);
164 wake_up_interruptible(&bulk->b_waitq);
166 CERROR("Unexpected event type!\n");
170 /* FIXME: This should happen unconditionally */
171 if (bulk->b_cb != NULL)
172 ptlrpc_free_bulk(bulk);
177 int ptlrpc_init_portals(void)
182 socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
183 qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
184 if (socknal_nip == NULL && qswnal_nip == NULL) {
185 CERROR("get_ni failed: is a NAL module loaded?\n");
189 /* Use the qswnal if it's there */
190 if (qswnal_nip != NULL)
195 rc = PtlEQAlloc(ni, 128, request_out_callback, NULL, &request_out_eq);
197 CERROR("PtlEQAlloc failed: %d\n", rc);
199 rc = PtlEQAlloc(ni, 128, reply_out_callback, NULL, &reply_out_eq);
201 CERROR("PtlEQAlloc failed: %d\n", rc);
203 rc = PtlEQAlloc(ni, 128, reply_in_callback, NULL, &reply_in_eq);
205 CERROR("PtlEQAlloc failed: %d\n", rc);
207 rc = PtlEQAlloc(ni, 128, bulk_source_callback, NULL, &bulk_source_eq);
209 CERROR("PtlEQAlloc failed: %d\n", rc);
211 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, NULL, &bulk_sink_eq);
213 CERROR("PtlEQAlloc failed: %d\n", rc);
218 void ptlrpc_exit_portals(void)
220 PtlEQFree(request_out_eq);
221 PtlEQFree(reply_out_eq);
222 PtlEQFree(reply_in_eq);
223 PtlEQFree(bulk_source_eq);
224 PtlEQFree(bulk_sink_eq);
226 if (qswnal_nip != NULL)
227 inter_module_put("kqswnal_ni");
228 if (socknal_nip != NULL)
229 inter_module_put("ksocknal_ni");