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)
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)
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)
72 struct ptlrpc_request *req = ev->mem_desc.user_ptr;
75 if (req->rq_xid == 0x5a5a5a5a) {
76 CERROR("Reply received for freed request! Probably a missing "
81 if (req->rq_xid != ev->match_bits) {
82 CERROR("Reply packet for wrong request\n");
86 if (ev->type == PTL_EVENT_PUT) {
87 req->rq_repmsg = ev->mem_desc.start + ev->offset;
89 wake_up(&req->rq_wait_for_rep);
91 // XXX make sure we understand all events, including ACK's
92 CERROR("Unknown event %d\n", ev->type);
99 int request_in_callback(ptl_event_t *ev)
101 struct ptlrpc_service *service = ev->mem_desc.user_ptr;
103 if (ev->rlength != ev->mlength)
104 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
105 ev->mlength, ev->rlength);
107 if (ev->type == PTL_EVENT_PUT)
108 wake_up(&service->srv_waitq);
110 CERROR("Unexpected event type: %d\n", ev->type);
115 static int bulk_source_callback(ptl_event_t *ev)
117 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
118 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
121 if (ev->type == PTL_EVENT_SENT) {
122 CDEBUG(D_NET, "got SENT event\n");
123 } else if (ev->type == PTL_EVENT_ACK) {
124 CDEBUG(D_NET, "got ACK event\n");
125 if (bulk->b_cb != NULL)
127 if (atomic_dec_and_test(&desc->b_pages_remaining)) {
128 desc->b_flags |= PTL_BULK_FL_SENT;
129 wake_up(&desc->b_waitq);
130 if (desc->b_cb != NULL)
131 desc->b_cb(desc, desc->b_cb_data);
134 CERROR("Unexpected event type!\n");
141 static int bulk_sink_callback(ptl_event_t *ev)
143 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
144 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
147 if (ev->type == PTL_EVENT_PUT) {
148 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
149 CERROR("bulkbuf != mem_desc -- why?\n");
150 if (bulk->b_cb != NULL)
152 if (atomic_dec_and_test(&desc->b_pages_remaining)) {
153 desc->b_flags |= PTL_BULK_FL_RCVD;
154 wake_up(&desc->b_waitq);
155 if (desc->b_cb != NULL)
156 desc->b_cb(desc, desc->b_cb_data);
159 CERROR("Unexpected event type!\n");
166 int ptlrpc_init_portals(void)
171 socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
172 qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
173 if (socknal_nip == NULL && qswnal_nip == NULL) {
174 CERROR("get_ni failed: is a NAL module loaded?\n");
178 /* Use the qswnal if it's there */
179 if (qswnal_nip != NULL)
184 rc = PtlEQAlloc(ni, 128, request_out_callback, &request_out_eq);
186 CERROR("PtlEQAlloc failed: %d\n", rc);
188 rc = PtlEQAlloc(ni, 128, reply_out_callback, &reply_out_eq);
190 CERROR("PtlEQAlloc failed: %d\n", rc);
192 rc = PtlEQAlloc(ni, 128, reply_in_callback, &reply_in_eq);
194 CERROR("PtlEQAlloc failed: %d\n", rc);
196 rc = PtlEQAlloc(ni, 128, bulk_source_callback, &bulk_source_eq);
198 CERROR("PtlEQAlloc failed: %d\n", rc);
200 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, &bulk_sink_eq);
202 CERROR("PtlEQAlloc failed: %d\n", rc);
207 void ptlrpc_exit_portals(void)
209 PtlEQFree(request_out_eq);
210 PtlEQFree(reply_out_eq);
211 PtlEQFree(reply_in_eq);
212 PtlEQFree(bulk_source_eq);
213 PtlEQFree(bulk_sink_eq);
215 if (qswnal_nip != NULL)
216 inter_module_put("kqswnal_ni");
217 if (socknal_nip != NULL)
218 inter_module_put("ksocknal_ni");