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 LASSERT ((ev->mem_desc.options & PTL_MD_IOV) == 0); /* requests always contiguous */
42 if (ev->type != PTL_EVENT_SENT) {
43 // XXX make sure we understand all events, including ACK's
44 CERROR("Unknown event %d\n", ev->type);
53 * Free the packet when it has gone out
55 static int reply_out_callback(ptl_event_t *ev)
59 LASSERT ((ev->mem_desc.options & PTL_MD_IOV) == 0); /* replies always contiguous */
61 if (ev->type == PTL_EVENT_SENT) {
62 OBD_FREE(ev->mem_desc.start, ev->mem_desc.length);
64 // XXX make sure we understand all events, including ACK's
65 CERROR("Unknown event %d\n", ev->type);
73 * Wake up the thread waiting for the reply once it comes in.
75 static int reply_in_callback(ptl_event_t *ev)
77 struct ptlrpc_request *req = ev->mem_desc.user_ptr;
80 LASSERT ((ev->mem_desc.options & PTL_MD_IOV) == 0); /* replies always contiguous */
82 if (req->rq_xid == 0x5a5a5a5a5a5a5a5a) {
83 CERROR("Reply received for freed request! Probably a missing "
88 if (req->rq_xid != ev->match_bits) {
89 CERROR("Reply packet for wrong request\n");
93 if (ev->type == PTL_EVENT_PUT) {
94 req->rq_repmsg = ev->mem_desc.start + ev->offset;
96 wake_up(&req->rq_wait_for_rep);
98 // XXX make sure we understand all events, including ACK's
99 CERROR("Unknown event %d\n", ev->type);
106 int request_in_callback(ptl_event_t *ev)
108 struct ptlrpc_request_buffer_desc *rqbd = ev->mem_desc.user_ptr;
109 struct ptlrpc_service *service = rqbd->rqbd_service;
111 LASSERT ((ev->mem_desc.options & PTL_MD_IOV) == 0); /* requests always contiguous */
113 if (ev->rlength != ev->mlength)
114 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
115 ev->mlength, ev->rlength);
117 if (ev->type == PTL_EVENT_PUT)
118 wake_up(&service->srv_waitq);
120 CERROR("Unexpected event type: %d\n", ev->type);
125 static int bulk_source_callback(ptl_event_t *ev)
127 struct ptlrpc_bulk_desc *desc = ev->mem_desc.user_ptr;
128 struct ptlrpc_bulk_page *bulk;
129 struct list_head *tmp;
130 struct list_head *next;
133 CDEBUG(D_NET, "got %s event %d\n",
134 (ev->type == PTL_EVENT_SENT) ? "SENT" :
135 (ev->type == PTL_EVENT_ACK) ? "ACK" : "UNEXPECTED", ev->type);
137 LASSERT (ev->type == PTL_EVENT_SENT ||
138 ev->type == PTL_EVENT_ACK);
140 LASSERT (atomic_read (&desc->bd_source_callback_count) > 0 &&
141 atomic_read (&desc->bd_source_callback_count) <= 2);
143 if (ev->mem_desc.niov != desc->bd_page_count)
145 int mdniov = ev->mem_desc.niov;
146 struct ptlrpc_bulk_desc desc_snapshot;
148 desc_snapshot = *desc;
150 printk ("ev(%p)->mem_desc.niov %d != desc(%p)->bd_page_count %d, snapshot %p\n",
151 ev, mdniov, desc, desc_snapshot.bd_page_count, &desc_snapshot);
154 /* 1 fragment for each page always */
155 LASSERT (ev->mem_desc.niov == desc->bd_page_count);
157 if (atomic_dec_and_test (&desc->bd_source_callback_count))
159 list_for_each_safe(tmp, next, &desc->bd_page_list) {
160 bulk = list_entry(tmp, struct ptlrpc_bulk_page,
163 if (bulk->bp_cb != NULL)
166 desc->bd_flags |= PTL_BULK_FL_SENT;
167 wake_up(&desc->bd_waitq);
168 if (desc->bd_cb != NULL)
169 desc->bd_cb(desc, desc->bd_cb_data);
175 static int bulk_sink_callback(ptl_event_t *ev)
177 struct ptlrpc_bulk_desc *desc = ev->mem_desc.user_ptr;
178 struct ptlrpc_bulk_page *bulk;
179 struct list_head *tmp;
180 struct list_head *next;
181 ptl_size_t total = 0;
184 if (ev->type == PTL_EVENT_PUT) {
185 /* put with zero offset */
186 LASSERT (ev->offset == 0);
188 LASSERT ((ev->mem_desc.options & PTL_MD_IOV) != 0);
189 /* 1 fragment for each page always */
190 LASSERT (ev->mem_desc.niov == desc->bd_page_count);
192 list_for_each_safe (tmp, next, &desc->bd_page_list) {
193 bulk = list_entry(tmp, struct ptlrpc_bulk_page,
196 total += bulk->bp_buflen;
198 if (bulk->bp_cb != NULL)
202 LASSERT (ev->mem_desc.length == total);
204 desc->bd_flags |= PTL_BULK_FL_RCVD;
205 wake_up(&desc->bd_waitq);
206 if (desc->bd_cb != NULL)
207 desc->bd_cb(desc, desc->bd_cb_data);
209 CERROR("Unexpected event type!\n");
216 int ptlrpc_init_portals(void)
221 socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
222 qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
223 if (socknal_nip == NULL && qswnal_nip == NULL) {
224 CERROR("get_ni failed: is a NAL module loaded?\n");
228 /* Use the qswnal if it's there */
229 if (qswnal_nip != NULL)
234 rc = PtlEQAlloc(ni, 1024, request_out_callback, &request_out_eq);
236 CERROR("PtlEQAlloc failed: %d\n", rc);
238 rc = PtlEQAlloc(ni, 1024, reply_out_callback, &reply_out_eq);
240 CERROR("PtlEQAlloc failed: %d\n", rc);
242 rc = PtlEQAlloc(ni, 1024, reply_in_callback, &reply_in_eq);
244 CERROR("PtlEQAlloc failed: %d\n", rc);
246 rc = PtlEQAlloc(ni, 1024, bulk_source_callback, &bulk_source_eq);
248 CERROR("PtlEQAlloc failed: %d\n", rc);
250 rc = PtlEQAlloc(ni, 1024, bulk_sink_callback, &bulk_sink_eq);
252 CERROR("PtlEQAlloc failed: %d\n", rc);
257 void ptlrpc_exit_portals(void)
259 PtlEQFree(request_out_eq);
260 PtlEQFree(reply_out_eq);
261 PtlEQFree(reply_in_eq);
262 PtlEQFree(bulk_source_eq);
263 PtlEQFree(bulk_sink_eq);
265 if (qswnal_nip != NULL)
266 inter_module_put("kqswnal_ni");
267 if (socknal_nip != NULL)
268 inter_module_put("ksocknal_ni");