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 #define DEBUG_SUBSYSTEM S_RPC
31 #include <linux/obd_support.h>
32 #include <linux/obd_class.h>
33 #include <linux/lustre_net.h>
35 ptl_handle_eq_t sent_pkt_eq, rcvd_rep_eq, bulk_source_eq, bulk_sink_eq;
36 static const ptl_handle_ni_t *socknal_nip = NULL, *qswnal_nip = NULL;
39 * Free the packet when it has gone out
41 static int sent_packet_callback(ptl_event_t *ev, void *data)
45 if (ev->type == PTL_EVENT_SENT) {
46 OBD_FREE(ev->mem_desc.start, ev->mem_desc.length);
48 // XXX make sure we understand all events, including ACK's
49 CERROR("Unknown event %d\n", ev->type);
58 * Wake up the thread waiting for the reply once it comes in.
60 static int rcvd_reply_callback(ptl_event_t *ev, void *data)
62 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
65 if (ev->type == PTL_EVENT_PUT) {
66 rpc->rq_repbuf = ev->mem_desc.start + ev->offset;
68 wake_up_interruptible(&rpc->rq_wait_for_rep);
70 // XXX make sure we understand all events, including ACK's
71 CERROR("Unknown event %d\n", ev->type);
79 int server_request_callback(ptl_event_t *ev, void *data)
81 struct ptlrpc_service *service = data;
84 if (ev->rlength != ev->mlength)
85 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
86 ev->mlength, ev->rlength);
88 spin_lock(&service->srv_lock);
89 for (index = 0; index < service->srv_ring_length; index++)
90 if ( service->srv_buf[index] == ev->mem_desc.start)
93 if (index == service->srv_ring_length)
96 service->srv_ref_count[index]++;
98 if (ev->unlinked_me != -1) {
101 for (idx = 0; idx < service->srv_ring_length; idx++)
102 if (service->srv_me_h[idx] == ev->unlinked_me)
104 if (idx == service->srv_ring_length)
107 CDEBUG(D_NET, "unlinked %d\n", idx);
108 service->srv_me_h[idx] = 0;
110 if (service->srv_ref_count[idx] == 0)
111 ptlrpc_link_svc_me(service, idx);
114 spin_unlock(&service->srv_lock);
115 if (ev->type == PTL_EVENT_PUT)
116 wake_up(&service->srv_waitq);
118 CERROR("Unexpected event type: %d\n", ev->type);
123 static int bulk_source_callback(ptl_event_t *ev, void *data)
125 struct ptlrpc_bulk_desc *bulk = ev->mem_desc.user_ptr;
129 if (ev->type == PTL_EVENT_SENT) {
130 CDEBUG(D_NET, "got SENT event\n");
131 } else if (ev->type == PTL_EVENT_ACK) {
132 CDEBUG(D_NET, "got ACK event\n");
133 bulk->b_flags = PTL_BULK_SENT;
134 wake_up_interruptible(&bulk->b_waitq);
136 CERROR("Unexpected event type!\n");
144 static int bulk_sink_callback(ptl_event_t *ev, void *data)
146 struct ptlrpc_bulk_desc *bulk = ev->mem_desc.user_ptr;
150 if (ev->type == PTL_EVENT_PUT) {
151 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
152 CERROR("bulkbuf != mem_desc -- why?\n");
153 bulk->b_flags = PTL_BULK_RCVD;
154 if (bulk->b_cb != NULL)
155 bulk->b_cb(bulk, data);
156 wake_up_interruptible(&bulk->b_waitq);
158 CERROR("Unexpected event type!\n");
162 /* FIXME: This should happen unconditionally */
163 if (bulk->b_cb != NULL)
164 OBD_FREE(bulk, sizeof(*bulk));
170 int ptlrpc_init_portals(void)
175 socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
176 qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
177 if (socknal_nip == NULL && qswnal_nip == NULL) {
178 CERROR("get_ni failed: is a NAL module loaded?\n");
182 /* Use the qswnal if it's there */
183 if (qswnal_nip != NULL)
188 rc = PtlEQAlloc(ni, 128, sent_packet_callback, NULL, &sent_pkt_eq);
190 CERROR("PtlEQAlloc failed: %d\n", rc);
192 rc = PtlEQAlloc(ni, 128, rcvd_reply_callback, NULL, &rcvd_rep_eq);
194 CERROR("PtlEQAlloc failed: %d\n", rc);
196 rc = PtlEQAlloc(ni, 128, bulk_source_callback, NULL, &bulk_source_eq);
198 CERROR("PtlEQAlloc failed: %d\n", rc);
200 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, NULL, &bulk_sink_eq);
202 CERROR("PtlEQAlloc failed: %d\n", rc);
207 void ptlrpc_exit_portals(void)
209 PtlEQFree(sent_pkt_eq);
210 PtlEQFree(rcvd_rep_eq);
211 PtlEQFree(bulk_source_eq);
212 PtlEQFree(bulk_sink_eq);
214 if (qswnal_nip != NULL)
215 inter_module_put("kqswnal_ni");
216 if (socknal_nip != NULL)
217 inter_module_put("ksocknal_ni");