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