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, *toenal_nip = NULL,
32 *qswnal_nip = NULL, *gmnal_nip = NULL;
35 * Free the packet when it has gone out
37 static int request_out_callback(ptl_event_t *ev)
39 struct ptlrpc_request *req = ev->mem_desc.user_ptr;
42 LASSERT ((ev->mem_desc.options & PTL_MD_IOV) == 0); /* requests always contiguous */
44 if (ev->type != PTL_EVENT_SENT) {
45 // XXX make sure we understand all events, including ACK's
46 CERROR("Unknown event %d\n", ev->type);
50 /* this balances the atomic_inc in ptl_send_rpc */
51 ptlrpc_req_finished(req);
57 * Free the packet when it has gone out
59 static int reply_out_callback(ptl_event_t *ev)
63 LASSERT ((ev->mem_desc.options & PTL_MD_IOV) == 0); /* replies always contiguous */
65 if (ev->type == PTL_EVENT_SENT) {
66 OBD_FREE(ev->mem_desc.start, ev->mem_desc.length);
68 // XXX make sure we understand all events, including ACK's
69 CERROR("Unknown event %d\n", ev->type);
77 * Wake up the thread waiting for the reply once it comes in.
79 static int reply_in_callback(ptl_event_t *ev)
81 struct ptlrpc_request *req = ev->mem_desc.user_ptr;
84 LASSERT ((ev->mem_desc.options & PTL_MD_IOV) == 0); /* replies always contiguous */
86 if (req->rq_xid == 0x5a5a5a5a5a5a5a5a) {
87 CERROR("Reply received for freed request! Probably a missing "
92 if (req->rq_xid != ev->match_bits) {
93 CERROR("Reply packet for wrong request\n");
97 if (ev->type == PTL_EVENT_PUT) {
98 req->rq_repmsg = ev->mem_desc.start + ev->offset;
100 wake_up(&req->rq_wait_for_rep);
102 // XXX make sure we understand all events, including ACK's
103 CERROR("Unknown event %d\n", ev->type);
110 int request_in_callback(ptl_event_t *ev)
112 struct ptlrpc_request_buffer_desc *rqbd = ev->mem_desc.user_ptr;
113 struct ptlrpc_service *service = rqbd->rqbd_service;
115 LASSERT ((ev->mem_desc.options & PTL_MD_IOV) == 0); /* requests always contiguous */
116 LASSERT (ev->type == PTL_EVENT_PUT); /* we only enable puts */
117 LASSERT (atomic_read (&service->srv_nrqbds_receiving) > 0);
118 LASSERT (atomic_read (&rqbd->rqbd_refcount) > 0);
120 if (ev->rlength != ev->mlength)
121 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
122 ev->mlength, ev->rlength);
124 if (ptl_is_valid_handle (&ev->unlinked_me))
126 /* This is the last request to be received into this
127 * request buffer. We don't bump the refcount, since the
128 * thread servicing this event is effectively taking over
129 * portals' reference.
131 #warning ev->unlinked_me.nal_idx is not set properly in a callback
132 LASSERT (ev->unlinked_me.handle_idx == rqbd->rqbd_me_h.handle_idx);
134 if (atomic_dec_and_test (&service->srv_nrqbds_receiving)) /* we're off-air */
136 CERROR ("All request buffers busy\n");
137 /* we'll probably start dropping packets in portals soon */
141 atomic_inc (&rqbd->rqbd_refcount); /* +1 ref for service thread */
143 wake_up(&service->srv_waitq);
148 static int bulk_source_callback(ptl_event_t *ev)
150 struct ptlrpc_bulk_desc *desc = ev->mem_desc.user_ptr;
151 struct ptlrpc_bulk_page *bulk;
152 struct list_head *tmp;
153 struct list_head *next;
156 CDEBUG(D_NET, "got %s event %d\n",
157 (ev->type == PTL_EVENT_SENT) ? "SENT" :
158 (ev->type == PTL_EVENT_ACK) ? "ACK" : "UNEXPECTED", ev->type);
160 LASSERT (ev->type == PTL_EVENT_SENT || ev->type == PTL_EVENT_ACK);
162 LASSERT (atomic_read (&desc->bd_source_callback_count) > 0 &&
163 atomic_read (&desc->bd_source_callback_count) <= 2);
165 /* 1 fragment for each page always */
166 LASSERT (ev->mem_desc.niov == desc->bd_page_count);
168 if (atomic_dec_and_test (&desc->bd_source_callback_count)) {
169 list_for_each_safe(tmp, next, &desc->bd_page_list) {
170 bulk = list_entry(tmp, struct ptlrpc_bulk_page,
173 if (bulk->bp_cb != NULL)
176 desc->bd_flags |= PTL_BULK_FL_SENT;
177 wake_up(&desc->bd_waitq);
178 if (desc->bd_cb != NULL)
179 desc->bd_cb(desc, desc->bd_cb_data);
185 static int bulk_sink_callback(ptl_event_t *ev)
187 struct ptlrpc_bulk_desc *desc = ev->mem_desc.user_ptr;
188 struct ptlrpc_bulk_page *bulk;
189 struct list_head *tmp;
190 struct list_head *next;
191 ptl_size_t total = 0;
194 if (ev->type == PTL_EVENT_PUT) {
195 /* put with zero offset */
196 LASSERT (ev->offset == 0);
198 LASSERT ((ev->mem_desc.options & PTL_MD_IOV) != 0);
199 /* 1 fragment for each page always */
200 LASSERT (ev->mem_desc.niov == desc->bd_page_count);
202 list_for_each_safe (tmp, next, &desc->bd_page_list) {
203 bulk = list_entry(tmp, struct ptlrpc_bulk_page,
206 total += bulk->bp_buflen;
208 if (bulk->bp_cb != NULL)
212 LASSERT (ev->mem_desc.length == total);
214 desc->bd_flags |= PTL_BULK_FL_RCVD;
215 wake_up(&desc->bd_waitq);
216 if (desc->bd_cb != NULL)
217 desc->bd_cb(desc, desc->bd_cb_data);
219 CERROR("Unexpected event type!\n");
226 int ptlrpc_init_portals(void)
231 /* Use the qswnal if it's there */
232 if ((qswnal_nip = inter_module_get("kqswnal_ni")) != NULL)
234 else if ((gmnal_nip = inter_module_get("kgmnal_ni")) != NULL)
236 else if ((socknal_nip = inter_module_get("ksocknal_ni")) != NULL)
238 else if ((toenal_nip = inter_module_get("ktoenal_ni")) != NULL)
241 CERROR("get_ni failed: is a NAL module loaded?\n");
245 rc = PtlEQAlloc(ni, 1024, request_out_callback, &request_out_eq);
247 CERROR("PtlEQAlloc failed: %d\n", rc);
249 rc = PtlEQAlloc(ni, 1024, reply_out_callback, &reply_out_eq);
251 CERROR("PtlEQAlloc failed: %d\n", rc);
253 rc = PtlEQAlloc(ni, 1024, reply_in_callback, &reply_in_eq);
255 CERROR("PtlEQAlloc failed: %d\n", rc);
257 rc = PtlEQAlloc(ni, 1024, bulk_source_callback, &bulk_source_eq);
259 CERROR("PtlEQAlloc failed: %d\n", rc);
261 rc = PtlEQAlloc(ni, 1024, bulk_sink_callback, &bulk_sink_eq);
263 CERROR("PtlEQAlloc failed: %d\n", rc);
268 void ptlrpc_exit_portals(void)
270 PtlEQFree(request_out_eq);
271 PtlEQFree(reply_out_eq);
272 PtlEQFree(reply_in_eq);
273 PtlEQFree(bulk_source_eq);
274 PtlEQFree(bulk_sink_eq);
276 if (qswnal_nip != NULL)
277 inter_module_put("kqswnal_ni");
278 if (socknal_nip != NULL)
279 inter_module_put("ksocknal_ni");
280 if (gmnal_nip != NULL)
281 inter_module_put("kgmnal_ni");