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.
23 #define DEBUG_SUBSYSTEM S_RPC
25 #include <linux/module.h>
26 #include <linux/lustre_net.h>
28 ptl_handle_eq_t request_out_eq, reply_in_eq, reply_out_eq, bulk_source_eq,
30 static const ptl_handle_ni_t *socknal_nip = NULL, *qswnal_nip = NULL;
33 * Free the packet when it has gone out
35 static int request_out_callback(ptl_event_t *ev, void *data)
39 if (ev->type != PTL_EVENT_SENT) {
40 // XXX make sure we understand all events, including ACK's
41 CERROR("Unknown event %d\n", ev->type);
50 * Free the packet when it has gone out
52 static int reply_out_callback(ptl_event_t *ev, void *data)
56 if (ev->type == PTL_EVENT_SENT) {
57 OBD_FREE(ev->mem_desc.start, ev->mem_desc.length);
59 // XXX make sure we understand all events, including ACK's
60 CERROR("Unknown event %d\n", ev->type);
68 * Wake up the thread waiting for the reply once it comes in.
70 static int reply_in_callback(ptl_event_t *ev, void *data)
72 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
75 if (ev->type == PTL_EVENT_PUT) {
76 rpc->rq_repmsg = ev->mem_desc.start + ev->offset;
78 wake_up_interruptible(&rpc->rq_wait_for_rep);
80 // XXX make sure we understand all events, including ACK's
81 CERROR("Unknown event %d\n", ev->type);
88 int request_in_callback(ptl_event_t *ev, void *data)
90 struct ptlrpc_service *service = data;
93 if (ev->rlength != ev->mlength)
94 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
95 ev->mlength, ev->rlength);
97 spin_lock(&service->srv_lock);
98 for (index = 0; index < service->srv_ring_length; index++)
99 if ( service->srv_buf[index] == ev->mem_desc.start)
102 if (index == service->srv_ring_length)
105 service->srv_ref_count[index]++;
107 if (ptl_is_valid_handle(&ev->unlinked_me)) {
110 for (idx = 0; idx < service->srv_ring_length; idx++)
111 if (service->srv_me_h[idx].handle_idx ==
112 ev->unlinked_me.handle_idx)
114 if (idx == service->srv_ring_length)
117 CDEBUG(D_NET, "unlinked %d\n", idx);
118 ptl_set_inv_handle(&(service->srv_me_h[idx]));
120 if (service->srv_ref_count[idx] == 0)
121 ptlrpc_link_svc_me(service, idx);
124 spin_unlock(&service->srv_lock);
125 if (ev->type == PTL_EVENT_PUT)
126 wake_up(&service->srv_waitq);
128 CERROR("Unexpected event type: %d\n", ev->type);
133 static int bulk_source_callback(ptl_event_t *ev, void *data)
135 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
136 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
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 desc->b_flags |= PTL_BULK_FL_SENT;
144 wake_up_interruptible(&desc->b_waitq);
146 CERROR("Unexpected event type!\n");
153 static int bulk_sink_callback(ptl_event_t *ev, void *data)
155 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
156 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
159 if (ev->type == PTL_EVENT_PUT) {
160 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
161 CERROR("bulkbuf != mem_desc -- why?\n");
162 desc->b_finished_count++;
163 if (bulk->b_cb != NULL)
165 if (desc->b_finished_count == desc->b_page_count) {
166 desc->b_flags |= PTL_BULK_FL_RCVD;
167 wake_up_interruptible(&desc->b_waitq);
168 if (desc->b_cb != NULL)
172 CERROR("Unexpected event type!\n");
179 int ptlrpc_init_portals(void)
184 socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
185 qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
186 if (socknal_nip == NULL && qswnal_nip == NULL) {
187 CERROR("get_ni failed: is a NAL module loaded?\n");
191 /* Use the qswnal if it's there */
192 if (qswnal_nip != NULL)
197 rc = PtlEQAlloc(ni, 128, request_out_callback, NULL, &request_out_eq);
199 CERROR("PtlEQAlloc failed: %d\n", rc);
201 rc = PtlEQAlloc(ni, 128, reply_out_callback, NULL, &reply_out_eq);
203 CERROR("PtlEQAlloc failed: %d\n", rc);
205 rc = PtlEQAlloc(ni, 128, reply_in_callback, NULL, &reply_in_eq);
207 CERROR("PtlEQAlloc failed: %d\n", rc);
209 rc = PtlEQAlloc(ni, 128, bulk_source_callback, NULL, &bulk_source_eq);
211 CERROR("PtlEQAlloc failed: %d\n", rc);
213 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, NULL, &bulk_sink_eq);
215 CERROR("PtlEQAlloc failed: %d\n", rc);
220 void ptlrpc_exit_portals(void)
222 PtlEQFree(request_out_eq);
223 PtlEQFree(reply_out_eq);
224 PtlEQFree(reply_in_eq);
225 PtlEQFree(bulk_source_eq);
226 PtlEQFree(bulk_sink_eq);
228 if (qswnal_nip != NULL)
229 inter_module_put("kqswnal_ni");
230 if (socknal_nip != NULL)
231 inter_module_put("ksocknal_ni");