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 != ev->match_bits) {
76 CERROR("Reply packet for wrong request\n");
80 if (ev->type == PTL_EVENT_PUT) {
81 req->rq_repmsg = ev->mem_desc.start + ev->offset;
83 wake_up_interruptible(&req->rq_wait_for_rep);
85 // XXX make sure we understand all events, including ACK's
86 CERROR("Unknown event %d\n", ev->type);
93 int request_in_callback(ptl_event_t *ev)
95 struct ptlrpc_service *service = ev->mem_desc.user_ptr;
97 if (ev->rlength != ev->mlength)
98 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
99 ev->mlength, ev->rlength);
101 if (ev->type == PTL_EVENT_PUT)
102 wake_up(&service->srv_waitq);
104 CERROR("Unexpected event type: %d\n", ev->type);
109 static int bulk_source_callback(ptl_event_t *ev)
111 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
112 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
115 if (ev->type == PTL_EVENT_SENT) {
116 CDEBUG(D_NET, "got SENT event\n");
117 } else if (ev->type == PTL_EVENT_ACK) {
118 CDEBUG(D_NET, "got ACK event\n");
119 if (bulk->b_cb != NULL)
121 if (atomic_dec_and_test(&desc->b_pages_remaining)) {
122 desc->b_flags |= PTL_BULK_FL_SENT;
123 wake_up_interruptible(&desc->b_waitq);
124 if (desc->b_cb != NULL)
125 desc->b_cb(desc, desc->b_cb_data);
128 CERROR("Unexpected event type!\n");
135 static int bulk_sink_callback(ptl_event_t *ev)
137 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
138 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
141 if (ev->type == PTL_EVENT_PUT) {
142 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
143 CERROR("bulkbuf != mem_desc -- why?\n");
144 if (bulk->b_cb != NULL)
146 if (atomic_dec_and_test(&desc->b_pages_remaining)) {
147 desc->b_flags |= PTL_BULK_FL_RCVD;
148 wake_up_interruptible(&desc->b_waitq);
149 if (desc->b_cb != NULL)
150 desc->b_cb(desc, desc->b_cb_data);
153 CERROR("Unexpected event type!\n");
160 int ptlrpc_init_portals(void)
165 socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
166 qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
167 if (socknal_nip == NULL && qswnal_nip == NULL) {
168 CERROR("get_ni failed: is a NAL module loaded?\n");
172 /* Use the qswnal if it's there */
173 if (qswnal_nip != NULL)
178 rc = PtlEQAlloc(ni, 128, request_out_callback, &request_out_eq);
180 CERROR("PtlEQAlloc failed: %d\n", rc);
182 rc = PtlEQAlloc(ni, 128, reply_out_callback, &reply_out_eq);
184 CERROR("PtlEQAlloc failed: %d\n", rc);
186 rc = PtlEQAlloc(ni, 128, reply_in_callback, &reply_in_eq);
188 CERROR("PtlEQAlloc failed: %d\n", rc);
190 rc = PtlEQAlloc(ni, 128, bulk_source_callback, &bulk_source_eq);
192 CERROR("PtlEQAlloc failed: %d\n", rc);
194 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, &bulk_sink_eq);
196 CERROR("PtlEQAlloc failed: %d\n", rc);
201 void ptlrpc_exit_portals(void)
203 PtlEQFree(request_out_eq);
204 PtlEQFree(reply_out_eq);
205 PtlEQFree(reply_in_eq);
206 PtlEQFree(bulk_source_eq);
207 PtlEQFree(bulk_sink_eq);
209 if (qswnal_nip != NULL)
210 inter_module_put("kqswnal_ni");
211 if (socknal_nip != NULL)
212 inter_module_put("ksocknal_ni");