Whamcloud - gitweb
Do lots of explicit EXPORT_SYMBOLs to see if this cures ia64 problems
[fs/lustre-release.git] / lustre / ptlrpc / events.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  *
21  */
22
23 #define DEBUG_SUBSYSTEM S_RPC
24
25 #include <linux/module.h>
26 #include <linux/lustre_net.h>
27
28 ptl_handle_eq_t request_out_eq, reply_in_eq, reply_out_eq, bulk_source_eq,
29         bulk_sink_eq;
30 static const ptl_handle_ni_t *socknal_nip = NULL, *qswnal_nip = NULL;
31
32 /*
33  *  Free the packet when it has gone out
34  */
35 static int request_out_callback(ptl_event_t *ev, void *data)
36 {
37         ENTRY;
38
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);
42                 LBUG();
43         }
44
45         RETURN(1);
46 }
47
48
49 /*
50  *  Free the packet when it has gone out
51  */
52 static int reply_out_callback(ptl_event_t *ev, void *data)
53 {
54         ENTRY;
55
56         if (ev->type == PTL_EVENT_SENT) {
57                 OBD_FREE(ev->mem_desc.start, ev->mem_desc.length);
58         } else {
59                 // XXX make sure we understand all events, including ACK's
60                 CERROR("Unknown event %d\n", ev->type);
61                 LBUG();
62         }
63
64         RETURN(1);
65 }
66
67 /*
68  * Wake up the thread waiting for the reply once it comes in.
69  */
70 static int reply_in_callback(ptl_event_t *ev, void *data)
71 {
72         struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
73         ENTRY;
74
75         if (ev->type == PTL_EVENT_PUT) {
76                 rpc->rq_repmsg = ev->mem_desc.start + ev->offset;
77                 barrier();
78                 wake_up_interruptible(&rpc->rq_wait_for_rep);
79         } else {
80                 // XXX make sure we understand all events, including ACK's
81                 CERROR("Unknown event %d\n", ev->type);
82                 LBUG();
83         }
84
85         RETURN(1);
86 }
87
88 int request_in_callback(ptl_event_t *ev, void *data)
89 {
90         struct ptlrpc_service *service = data;
91         int index;
92
93         if (ev->rlength != ev->mlength)
94                 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
95                        ev->mlength, ev->rlength);
96
97         spin_lock(&service->srv_lock);
98         for (index = 0; index < service->srv_ring_length; index++)
99                 if ( service->srv_buf[index] == ev->mem_desc.start)
100                         break;
101
102         if (index == service->srv_ring_length)
103                 LBUG();
104
105         service->srv_ref_count[index]++;
106
107         if (ptl_is_valid_handle(&ev->unlinked_me)) {
108                 int idx;
109
110                 for (idx = 0; idx < service->srv_ring_length; idx++)
111                         if (service->srv_me_h[idx].handle_idx ==
112                             ev->unlinked_me.handle_idx)
113                                 break;
114                 if (idx == service->srv_ring_length)
115                         LBUG();
116
117                 CDEBUG(D_NET, "unlinked %d\n", idx);
118                 ptl_set_inv_handle(&(service->srv_me_h[idx]));
119
120                 if (service->srv_ref_count[idx] == 0)
121                         ptlrpc_link_svc_me(service, idx);
122         }
123
124         spin_unlock(&service->srv_lock);
125         if (ev->type == PTL_EVENT_PUT)
126                 wake_up(&service->srv_waitq);
127         else
128                 CERROR("Unexpected event type: %d\n", ev->type);
129
130         return 0;
131 }
132
133 static int bulk_source_callback(ptl_event_t *ev, void *data)
134 {
135         struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
136         struct ptlrpc_bulk_desc *desc = bulk->b_desc;
137         ENTRY;
138
139         if (ev->type == PTL_EVENT_SENT) {
140                 CDEBUG(D_NET, "got SENT event\n");
141         } else if (ev->type == PTL_EVENT_ACK) {
142                 CDEBUG(D_NET, "got ACK event\n");
143                 desc->b_flags |= PTL_BULK_FL_SENT;
144                 wake_up_interruptible(&desc->b_waitq);
145         } else {
146                 CERROR("Unexpected event type!\n");
147                 LBUG();
148         }
149
150         RETURN(1);
151 }
152
153 static int bulk_sink_callback(ptl_event_t *ev, void *data)
154 {
155         struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
156         struct ptlrpc_bulk_desc *desc = bulk->b_desc;
157         ENTRY;
158
159         if (ev->type == PTL_EVENT_PUT) {
160                 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
161                         CERROR("bulkbuf != mem_desc -- why?\n");
162                 desc->b_finished_count++;
163                 if (bulk->b_cb != NULL)
164                         bulk->b_cb(bulk);
165                 if (desc->b_finished_count == desc->b_page_count) {
166                         desc->b_flags |= PTL_BULK_FL_RCVD;
167                         wake_up_interruptible(&desc->b_waitq);
168                         if (desc->b_cb != NULL)
169                                 desc->b_cb(desc);
170                 }
171         } else {
172                 CERROR("Unexpected event type!\n");
173                 LBUG();
174         }
175
176         RETURN(1);
177 }
178
179 int ptlrpc_init_portals(void)
180 {
181         int rc;
182         ptl_handle_ni_t ni;
183
184         socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
185         qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
186         if (socknal_nip == NULL && qswnal_nip == NULL) {
187                 CERROR("get_ni failed: is a NAL module loaded?\n");
188                 return -EIO;
189         }
190
191         /* Use the qswnal if it's there */
192         if (qswnal_nip != NULL)
193                 ni = *qswnal_nip;
194         else
195                 ni = *socknal_nip;
196
197         rc = PtlEQAlloc(ni, 128, request_out_callback, NULL, &request_out_eq);
198         if (rc != PTL_OK)
199                 CERROR("PtlEQAlloc failed: %d\n", rc);
200
201         rc = PtlEQAlloc(ni, 128, reply_out_callback, NULL, &reply_out_eq);
202         if (rc != PTL_OK)
203                 CERROR("PtlEQAlloc failed: %d\n", rc);
204
205         rc = PtlEQAlloc(ni, 128, reply_in_callback, NULL, &reply_in_eq);
206         if (rc != PTL_OK)
207                 CERROR("PtlEQAlloc failed: %d\n", rc);
208
209         rc = PtlEQAlloc(ni, 128, bulk_source_callback, NULL, &bulk_source_eq);
210         if (rc != PTL_OK)
211                 CERROR("PtlEQAlloc failed: %d\n", rc);
212
213         rc = PtlEQAlloc(ni, 128, bulk_sink_callback, NULL, &bulk_sink_eq);
214         if (rc != PTL_OK)
215                 CERROR("PtlEQAlloc failed: %d\n", rc);
216
217         return rc;
218 }
219
220 void ptlrpc_exit_portals(void)
221 {
222         PtlEQFree(request_out_eq);
223         PtlEQFree(reply_out_eq);
224         PtlEQFree(reply_in_eq);
225         PtlEQFree(bulk_source_eq);
226         PtlEQFree(bulk_sink_eq);
227
228         if (qswnal_nip != NULL)
229                 inter_module_put("kqswnal_ni");
230         if (socknal_nip != NULL)
231                 inter_module_put("ksocknal_ni");
232 }