Whamcloud - gitweb
Landing the mds_lock_devel branch on the trunk. Notables:
[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)
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)
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)
71 {
72         struct ptlrpc_request *req = ev->mem_desc.user_ptr;
73         ENTRY;
74
75         if (req->rq_xid != ev->match_bits) {
76                 CERROR("Reply packet for wrong request\n");
77                 LBUG(); 
78         }
79
80         if (ev->type == PTL_EVENT_PUT) {
81                 req->rq_repmsg = ev->mem_desc.start + ev->offset;
82                 barrier();
83                 wake_up_interruptible(&req->rq_wait_for_rep);
84         } else {
85                 // XXX make sure we understand all events, including ACK's
86                 CERROR("Unknown event %d\n", ev->type);
87                 LBUG();
88         }
89
90         RETURN(1);
91 }
92
93 int request_in_callback(ptl_event_t *ev)
94 {
95         struct ptlrpc_service *service = ev->mem_desc.user_ptr;
96
97         if (ev->rlength != ev->mlength)
98                 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
99                        ev->mlength, ev->rlength);
100
101         if (ev->type == PTL_EVENT_PUT)
102                 wake_up(&service->srv_waitq);
103         else
104                 CERROR("Unexpected event type: %d\n", ev->type);
105
106         return 0;
107 }
108
109 static int bulk_source_callback(ptl_event_t *ev)
110 {
111         struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
112         struct ptlrpc_bulk_desc *desc = bulk->b_desc;
113         ENTRY;
114
115         if (ev->type == PTL_EVENT_SENT) {
116                 CDEBUG(D_NET, "got SENT event\n");
117         } else if (ev->type == PTL_EVENT_ACK) {
118                 CDEBUG(D_NET, "got ACK event\n");
119                 if (bulk->b_cb != NULL)
120                         bulk->b_cb(bulk);
121                 if (atomic_dec_and_test(&desc->b_pages_remaining)) {
122                         desc->b_flags |= PTL_BULK_FL_SENT;
123                         wake_up_interruptible(&desc->b_waitq);
124                         if (desc->b_cb != NULL)
125                                 desc->b_cb(desc, desc->b_cb_data);
126                 }
127         } else {
128                 CERROR("Unexpected event type!\n");
129                 LBUG();
130         }
131
132         RETURN(1);
133 }
134
135 static int bulk_sink_callback(ptl_event_t *ev)
136 {
137         struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
138         struct ptlrpc_bulk_desc *desc = bulk->b_desc;
139         ENTRY;
140
141         if (ev->type == PTL_EVENT_PUT) {
142                 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
143                         CERROR("bulkbuf != mem_desc -- why?\n");
144                 if (bulk->b_cb != NULL)
145                         bulk->b_cb(bulk);
146                 if (atomic_dec_and_test(&desc->b_pages_remaining)) {
147                         desc->b_flags |= PTL_BULK_FL_RCVD;
148                         wake_up_interruptible(&desc->b_waitq);
149                         if (desc->b_cb != NULL)
150                                 desc->b_cb(desc, desc->b_cb_data);
151                 }
152         } else {
153                 CERROR("Unexpected event type!\n");
154                 LBUG();
155         }
156
157         RETURN(1);
158 }
159
160 int ptlrpc_init_portals(void)
161 {
162         int rc;
163         ptl_handle_ni_t ni;
164
165         socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
166         qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
167         if (socknal_nip == NULL && qswnal_nip == NULL) {
168                 CERROR("get_ni failed: is a NAL module loaded?\n");
169                 return -EIO;
170         }
171
172         /* Use the qswnal if it's there */
173         if (qswnal_nip != NULL)
174                 ni = *qswnal_nip;
175         else
176                 ni = *socknal_nip;
177
178         rc = PtlEQAlloc(ni, 128, request_out_callback, &request_out_eq);
179         if (rc != PTL_OK)
180                 CERROR("PtlEQAlloc failed: %d\n", rc);
181
182         rc = PtlEQAlloc(ni, 128, reply_out_callback, &reply_out_eq);
183         if (rc != PTL_OK)
184                 CERROR("PtlEQAlloc failed: %d\n", rc);
185
186         rc = PtlEQAlloc(ni, 128, reply_in_callback, &reply_in_eq);
187         if (rc != PTL_OK)
188                 CERROR("PtlEQAlloc failed: %d\n", rc);
189
190         rc = PtlEQAlloc(ni, 128, bulk_source_callback, &bulk_source_eq);
191         if (rc != PTL_OK)
192                 CERROR("PtlEQAlloc failed: %d\n", rc);
193
194         rc = PtlEQAlloc(ni, 128, bulk_sink_callback, &bulk_sink_eq);
195         if (rc != PTL_OK)
196                 CERROR("PtlEQAlloc failed: %d\n", rc);
197
198         return rc;
199 }
200
201 void ptlrpc_exit_portals(void)
202 {
203         PtlEQFree(request_out_eq);
204         PtlEQFree(reply_out_eq);
205         PtlEQFree(reply_in_eq);
206         PtlEQFree(bulk_source_eq);
207         PtlEQFree(bulk_sink_eq);
208
209         if (qswnal_nip != NULL)
210                 inter_module_put("kqswnal_ni");
211         if (socknal_nip != NULL)
212                 inter_module_put("ksocknal_ni");
213 }