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.
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
29 #define DEBUG_SUBSYSTEM S_RPC
31 #include <linux/obd_support.h>
32 #include <linux/obd_class.h>
33 #include <linux/lustre_net.h>
35 ptl_handle_eq_t sent_pkt_eq, rcvd_rep_eq, bulk_source_eq, bulk_sink_eq;
36 static const ptl_handle_ni_t *socknal_nip = NULL, *qswnal_nip = NULL;
39 * Free the packet when it has gone out
41 static int sent_packet_callback(ptl_event_t *ev, void *data)
45 if (ev->type == PTL_EVENT_SENT) {
46 OBD_FREE(ev->mem_desc.start, ev->mem_desc.length);
48 // XXX make sure we understand all events, including ACK's
49 CERROR("Unknown event %d\n", ev->type);
58 * Wake up the thread waiting for the reply once it comes in.
60 static int rcvd_reply_callback(ptl_event_t *ev, void *data)
62 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
65 if (ev->type == PTL_EVENT_PUT) {
66 rpc->rq_repbuf = ev->mem_desc.start + ev->offset;
68 wake_up_interruptible(&rpc->rq_wait_for_rep);
70 // XXX make sure we understand all events, including ACK's
71 CERROR("Unknown event %d\n", ev->type);
79 int server_request_callback(ptl_event_t *ev, void *data)
81 struct ptlrpc_service *service = data;
84 if (ev->rlength != ev->mlength)
85 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
86 ev->mlength, ev->rlength);
88 /* The ME is unlinked when there is less than 1024 bytes free
89 * on its MD. This ensures we are always able to handle the rpc,
90 * although the 1024 value is a guess as to the size of a
91 * large rpc (the known safe margin should be determined).
93 * NOTE: The portals API by default unlinks all MD's associated
94 * with an ME when it's unlinked. For now, this behavior
95 * has been commented out of the portals library so the
96 * MD can be unlinked when its ref count drops to zero.
97 * A new MD and ME will then be created that use the same
98 * kmalloc()'ed memory and inserted at the ring tail.
101 spin_lock(&service->srv_lock);
102 if ( ev->mem_desc.start !=
103 service->srv_md[service->srv_md_active].start ) {
107 service->srv_ref_count[service->srv_md_active]++;
108 CDEBUG(D_INODE, "event offset %d buf size %d\n",
109 ev->offset, service->srv_buf_size);
110 if (ev->offset >= (service->srv_buf_size - 1024)) {
111 CDEBUG(D_INODE, "Unlinking ME %d\n", service->srv_md_active);
113 rc = PtlMEUnlink(service->srv_me_h[service->srv_md_active]);
114 service->srv_me_h[service->srv_md_active] = 0;
117 CERROR("PtlMEUnlink failed - DROPPING soon: %d\n", rc);
119 spin_unlock(&service->srv_lock);
123 service->srv_md_active = (service->srv_md_active + 1) %
124 service->srv_ring_length;
126 if (service->srv_me_h[service->srv_md_active] == 0) {
127 CERROR("All %d ring ME's are unlinked!\n",
128 service->srv_ring_length);
133 spin_unlock(&service->srv_lock);
134 if (ev->type == PTL_EVENT_PUT) {
135 wake_up(&service->srv_waitq);
137 CERROR("Unexpected event type: %d\n", ev->type);
143 static int bulk_source_callback(ptl_event_t *ev, void *data)
145 struct ptlrpc_bulk_desc *bulk = ev->mem_desc.user_ptr;
149 if (ev->type == PTL_EVENT_SENT) {
150 CDEBUG(D_NET, "got SENT event\n");
151 } else if (ev->type == PTL_EVENT_ACK) {
152 CDEBUG(D_NET, "got ACK event\n");
153 bulk->b_flags = PTL_BULK_SENT;
154 wake_up_interruptible(&bulk->b_waitq);
156 CERROR("Unexpected event type!\n");
164 static int bulk_sink_callback(ptl_event_t *ev, void *data)
166 struct ptlrpc_bulk_desc *bulk = ev->mem_desc.user_ptr;
170 if (ev->type == PTL_EVENT_PUT) {
171 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
172 CERROR("bulkbuf != mem_desc -- why?\n");
173 bulk->b_flags = PTL_BULK_RCVD;
174 if (bulk->b_cb != NULL)
175 bulk->b_cb(bulk, data);
176 wake_up_interruptible(&bulk->b_waitq);
178 CERROR("Unexpected event type!\n");
182 /* FIXME: This should happen unconditionally */
183 if (bulk->b_cb != NULL) {
184 OBD_FREE(bulk, sizeof(*bulk));
191 int ptlrpc_init_portals(void)
196 socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
197 qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
198 if (socknal_nip == NULL && qswnal_nip == NULL) {
199 CERROR("get_ni failed: is a NAL module loaded?\n");
203 /* Use the qswnal if it's there */
204 if (qswnal_nip != NULL)
209 rc = PtlEQAlloc(ni, 128, sent_packet_callback, NULL, &sent_pkt_eq);
211 CERROR("PtlEQAlloc failed: %d\n", rc);
213 rc = PtlEQAlloc(ni, 128, rcvd_reply_callback, NULL, &rcvd_rep_eq);
215 CERROR("PtlEQAlloc failed: %d\n", rc);
217 rc = PtlEQAlloc(ni, 128, bulk_source_callback, NULL, &bulk_source_eq);
219 CERROR("PtlEQAlloc failed: %d\n", rc);
221 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, NULL, &bulk_sink_eq);
223 CERROR("PtlEQAlloc failed: %d\n", rc);
228 void ptlrpc_exit_portals(void)
230 PtlEQFree(sent_pkt_eq);
231 PtlEQFree(rcvd_rep_eq);
232 PtlEQFree(bulk_source_eq);
233 PtlEQFree(bulk_sink_eq);
235 if (qswnal_nip != NULL)
236 inter_module_put("kqswnal_ni");
237 if (socknal_nip != NULL)
238 inter_module_put("ksocknal_ni");