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