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