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