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/obd_support.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)
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)
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)
73 struct ptlrpc_request *req = ev->mem_desc.user_ptr;
76 if (req->rq_xid == 0x5a5a5a5a5a5a5a5a) {
77 CERROR("Reply received for freed request! Probably a missing "
82 if (req->rq_xid != ev->match_bits) {
83 CERROR("Reply packet for wrong request\n");
87 if (ev->type == PTL_EVENT_PUT) {
88 req->rq_repmsg = ev->mem_desc.start + ev->offset;
90 wake_up(&req->rq_wait_for_rep);
92 // XXX make sure we understand all events, including ACK's
93 CERROR("Unknown event %d\n", ev->type);
100 int request_in_callback(ptl_event_t *ev)
102 struct ptlrpc_service *service = ev->mem_desc.user_ptr;
104 if (ev->rlength != ev->mlength)
105 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
106 ev->mlength, ev->rlength);
108 if (ev->type == PTL_EVENT_PUT)
109 wake_up(&service->srv_waitq);
111 CERROR("Unexpected event type: %d\n", ev->type);
116 static int bulk_source_callback(ptl_event_t *ev)
118 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
119 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
122 if (ev->type == PTL_EVENT_SENT) {
123 CDEBUG(D_NET, "got SENT event\n");
124 } else if (ev->type == PTL_EVENT_ACK) {
125 CDEBUG(D_NET, "got ACK event\n");
126 if (bulk->b_cb != NULL)
128 if (atomic_dec_and_test(&desc->b_pages_remaining)) {
129 desc->b_flags |= PTL_BULK_FL_SENT;
130 wake_up(&desc->b_waitq);
131 if (desc->b_cb != NULL)
132 desc->b_cb(desc, desc->b_cb_data);
135 CERROR("Unexpected event type!\n");
142 static int bulk_sink_callback(ptl_event_t *ev)
144 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
145 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
148 if (ev->type == PTL_EVENT_PUT) {
149 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
150 CERROR("bulkbuf != mem_desc -- why?\n");
151 if (bulk->b_cb != NULL)
153 if (atomic_dec_and_test(&desc->b_pages_remaining)) {
154 desc->b_flags |= PTL_BULK_FL_RCVD;
155 wake_up(&desc->b_waitq);
156 if (desc->b_cb != NULL)
157 desc->b_cb(desc, desc->b_cb_data);
160 CERROR("Unexpected event type!\n");
167 int ptlrpc_init_portals(void)
172 socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
173 qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
174 if (socknal_nip == NULL && qswnal_nip == NULL) {
175 CERROR("get_ni failed: is a NAL module loaded?\n");
179 /* Use the qswnal if it's there */
180 if (qswnal_nip != NULL)
185 rc = PtlEQAlloc(ni, 128, request_out_callback, &request_out_eq);
187 CERROR("PtlEQAlloc failed: %d\n", rc);
189 rc = PtlEQAlloc(ni, 128, reply_out_callback, &reply_out_eq);
191 CERROR("PtlEQAlloc failed: %d\n", rc);
193 rc = PtlEQAlloc(ni, 128, reply_in_callback, &reply_in_eq);
195 CERROR("PtlEQAlloc failed: %d\n", rc);
197 rc = PtlEQAlloc(ni, 128, bulk_source_callback, &bulk_source_eq);
199 CERROR("PtlEQAlloc failed: %d\n", rc);
201 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, &bulk_sink_eq);
203 CERROR("PtlEQAlloc failed: %d\n", rc);
208 void ptlrpc_exit_portals(void)
210 PtlEQFree(request_out_eq);
211 PtlEQFree(reply_out_eq);
212 PtlEQFree(reply_in_eq);
213 PtlEQFree(bulk_source_eq);
214 PtlEQFree(bulk_sink_eq);
216 if (qswnal_nip != NULL)
217 inter_module_put("kqswnal_ni");
218 if (socknal_nip != NULL)
219 inter_module_put("ksocknal_ni");