]>
Commit | Line | Data |
---|---|---|
2874c5fd | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
08e0e7c8 DH |
2 | /* Maintain an RxRPC server socket to do AFS communications through |
3 | * | |
4 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. | |
5 | * Written by David Howells (dhowells@redhat.com) | |
08e0e7c8 DH |
6 | */ |
7 | ||
5a0e3ad6 | 8 | #include <linux/slab.h> |
174cd4b1 IM |
9 | #include <linux/sched/signal.h> |
10 | ||
08e0e7c8 DH |
11 | #include <net/sock.h> |
12 | #include <net/af_rxrpc.h> | |
08e0e7c8 DH |
13 | #include "internal.h" |
14 | #include "afs_cm.h" | |
35dbfba3 | 15 | #include "protocol_yfs.h" |
08e0e7c8 | 16 | |
f044c884 | 17 | struct workqueue_struct *afs_async_calls; |
08e0e7c8 | 18 | |
d001648e | 19 | static void afs_wake_up_call_waiter(struct sock *, struct rxrpc_call *, unsigned long); |
d001648e | 20 | static void afs_wake_up_async_call(struct sock *, struct rxrpc_call *, unsigned long); |
34fa4761 | 21 | static void afs_delete_async_call(struct work_struct *); |
d001648e | 22 | static void afs_process_async_call(struct work_struct *); |
00e90712 DH |
23 | static void afs_rx_new_call(struct sock *, struct rxrpc_call *, unsigned long); |
24 | static void afs_rx_discard_new_call(struct rxrpc_call *, unsigned long); | |
d001648e | 25 | static int afs_deliver_cm_op_id(struct afs_call *); |
08e0e7c8 | 26 | |
08e0e7c8 DH |
27 | /* asynchronous incoming call initial processing */ |
28 | static const struct afs_call_type afs_RXCMxxxx = { | |
00d3b7a4 | 29 | .name = "CB.xxxx", |
08e0e7c8 | 30 | .deliver = afs_deliver_cm_op_id, |
08e0e7c8 DH |
31 | }; |
32 | ||
08e0e7c8 DH |
33 | /* |
34 | * open an RxRPC socket and bind it to be a server for callback notifications | |
35 | * - the socket is left in blocking mode and non-blocking ops use MSG_DONTWAIT | |
36 | */ | |
f044c884 | 37 | int afs_open_socket(struct afs_net *net) |
08e0e7c8 DH |
38 | { |
39 | struct sockaddr_rxrpc srx; | |
40 | struct socket *socket; | |
4776cab4 | 41 | unsigned int min_level; |
08e0e7c8 DH |
42 | int ret; |
43 | ||
44 | _enter(""); | |
45 | ||
5b86d4ff | 46 | ret = sock_create_kern(net->net, AF_RXRPC, SOCK_DGRAM, PF_INET6, &socket); |
0e119b41 DH |
47 | if (ret < 0) |
48 | goto error_1; | |
08e0e7c8 DH |
49 | |
50 | socket->sk->sk_allocation = GFP_NOFS; | |
51 | ||
52 | /* bind the callback manager's address to make this a server socket */ | |
3838d3ec | 53 | memset(&srx, 0, sizeof(srx)); |
08e0e7c8 DH |
54 | srx.srx_family = AF_RXRPC; |
55 | srx.srx_service = CM_SERVICE; | |
56 | srx.transport_type = SOCK_DGRAM; | |
3838d3ec DH |
57 | srx.transport_len = sizeof(srx.transport.sin6); |
58 | srx.transport.sin6.sin6_family = AF_INET6; | |
59 | srx.transport.sin6.sin6_port = htons(AFS_CM_PORT); | |
08e0e7c8 | 60 | |
4776cab4 DH |
61 | min_level = RXRPC_SECURITY_ENCRYPT; |
62 | ret = kernel_setsockopt(socket, SOL_RXRPC, RXRPC_MIN_SECURITY_LEVEL, | |
63 | (void *)&min_level, sizeof(min_level)); | |
64 | if (ret < 0) | |
65 | goto error_2; | |
66 | ||
08e0e7c8 | 67 | ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx)); |
83732ec5 MD |
68 | if (ret == -EADDRINUSE) { |
69 | srx.transport.sin6.sin6_port = 0; | |
70 | ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx)); | |
71 | } | |
0e119b41 DH |
72 | if (ret < 0) |
73 | goto error_2; | |
74 | ||
35dbfba3 DH |
75 | srx.srx_service = YFS_CM_SERVICE; |
76 | ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx)); | |
77 | if (ret < 0) | |
78 | goto error_2; | |
79 | ||
3bf0fb6f DH |
80 | /* Ideally, we'd turn on service upgrade here, but we can't because |
81 | * OpenAFS is buggy and leaks the userStatus field from packet to | |
82 | * packet and between FS packets and CB packets - so if we try to do an | |
83 | * upgrade on an FS packet, OpenAFS will leak that into the CB packet | |
84 | * it sends back to us. | |
85 | */ | |
35dbfba3 | 86 | |
00e90712 DH |
87 | rxrpc_kernel_new_call_notification(socket, afs_rx_new_call, |
88 | afs_rx_discard_new_call); | |
d001648e | 89 | |
0e119b41 DH |
90 | ret = kernel_listen(socket, INT_MAX); |
91 | if (ret < 0) | |
92 | goto error_2; | |
08e0e7c8 | 93 | |
f044c884 DH |
94 | net->socket = socket; |
95 | afs_charge_preallocation(&net->charge_preallocation_work); | |
08e0e7c8 DH |
96 | _leave(" = 0"); |
97 | return 0; | |
0e119b41 DH |
98 | |
99 | error_2: | |
100 | sock_release(socket); | |
101 | error_1: | |
0e119b41 DH |
102 | _leave(" = %d", ret); |
103 | return ret; | |
08e0e7c8 DH |
104 | } |
105 | ||
106 | /* | |
107 | * close the RxRPC socket AFS was using | |
108 | */ | |
f044c884 | 109 | void afs_close_socket(struct afs_net *net) |
08e0e7c8 DH |
110 | { |
111 | _enter(""); | |
112 | ||
f044c884 | 113 | kernel_listen(net->socket, 0); |
341f741f DH |
114 | flush_workqueue(afs_async_calls); |
115 | ||
f044c884 DH |
116 | if (net->spare_incoming_call) { |
117 | afs_put_call(net->spare_incoming_call); | |
118 | net->spare_incoming_call = NULL; | |
00e90712 DH |
119 | } |
120 | ||
f044c884 | 121 | _debug("outstanding %u", atomic_read(&net->nr_outstanding_calls)); |
ab1fbe32 PZ |
122 | wait_var_event(&net->nr_outstanding_calls, |
123 | !atomic_read(&net->nr_outstanding_calls)); | |
2f02f7ae DH |
124 | _debug("no outstanding calls"); |
125 | ||
f044c884 | 126 | kernel_sock_shutdown(net->socket, SHUT_RDWR); |
d001648e | 127 | flush_workqueue(afs_async_calls); |
f044c884 | 128 | sock_release(net->socket); |
08e0e7c8 DH |
129 | |
130 | _debug("dework"); | |
08e0e7c8 DH |
131 | _leave(""); |
132 | } | |
133 | ||
00d3b7a4 | 134 | /* |
341f741f | 135 | * Allocate a call. |
00d3b7a4 | 136 | */ |
f044c884 DH |
137 | static struct afs_call *afs_alloc_call(struct afs_net *net, |
138 | const struct afs_call_type *type, | |
341f741f | 139 | gfp_t gfp) |
00d3b7a4 | 140 | { |
341f741f DH |
141 | struct afs_call *call; |
142 | int o; | |
00d3b7a4 | 143 | |
341f741f DH |
144 | call = kzalloc(sizeof(*call), gfp); |
145 | if (!call) | |
146 | return NULL; | |
00d3b7a4 | 147 | |
341f741f | 148 | call->type = type; |
f044c884 | 149 | call->net = net; |
a25e21f0 | 150 | call->debug_id = atomic_inc_return(&rxrpc_debug_id); |
341f741f DH |
151 | atomic_set(&call->usage, 1); |
152 | INIT_WORK(&call->async_work, afs_process_async_call); | |
153 | init_waitqueue_head(&call->waitq); | |
98bf40cd | 154 | spin_lock_init(&call->state_lock); |
fc276122 | 155 | call->iter = &call->def_iter; |
2f02f7ae | 156 | |
f044c884 | 157 | o = atomic_inc_return(&net->nr_outstanding_calls); |
341f741f DH |
158 | trace_afs_call(call, afs_call_trace_alloc, 1, o, |
159 | __builtin_return_address(0)); | |
160 | return call; | |
00d3b7a4 DH |
161 | } |
162 | ||
6c67c7c3 | 163 | /* |
341f741f | 164 | * Dispose of a reference on a call. |
6c67c7c3 | 165 | */ |
341f741f | 166 | void afs_put_call(struct afs_call *call) |
6c67c7c3 | 167 | { |
f044c884 | 168 | struct afs_net *net = call->net; |
341f741f | 169 | int n = atomic_dec_return(&call->usage); |
f044c884 | 170 | int o = atomic_read(&net->nr_outstanding_calls); |
341f741f DH |
171 | |
172 | trace_afs_call(call, afs_call_trace_put, n + 1, o, | |
173 | __builtin_return_address(0)); | |
174 | ||
175 | ASSERTCMP(n, >=, 0); | |
176 | if (n == 0) { | |
177 | ASSERT(!work_pending(&call->async_work)); | |
178 | ASSERT(call->type->name != NULL); | |
179 | ||
180 | if (call->rxcall) { | |
f044c884 | 181 | rxrpc_kernel_end_call(net->socket, call->rxcall); |
341f741f DH |
182 | call->rxcall = NULL; |
183 | } | |
184 | if (call->type->destructor) | |
185 | call->type->destructor(call); | |
186 | ||
45218193 | 187 | afs_put_server(call->net, call->server, afs_server_trace_put_call); |
d2ddc776 | 188 | afs_put_cb_interest(call->net, call->cbi); |
3bf0fb6f | 189 | afs_put_addrlist(call->alist); |
341f741f | 190 | kfree(call->request); |
341f741f | 191 | |
341f741f DH |
192 | trace_afs_call(call, afs_call_trace_free, 0, o, |
193 | __builtin_return_address(0)); | |
a25e21f0 DH |
194 | kfree(call); |
195 | ||
196 | o = atomic_dec_return(&net->nr_outstanding_calls); | |
341f741f | 197 | if (o == 0) |
ab1fbe32 | 198 | wake_up_var(&net->nr_outstanding_calls); |
6c67c7c3 | 199 | } |
6cf12869 NWF |
200 | } |
201 | ||
7a75b007 DH |
202 | static struct afs_call *afs_get_call(struct afs_call *call, |
203 | enum afs_call_trace why) | |
204 | { | |
205 | int u = atomic_inc_return(&call->usage); | |
206 | ||
207 | trace_afs_call(call, why, u, | |
208 | atomic_read(&call->net->nr_outstanding_calls), | |
209 | __builtin_return_address(0)); | |
210 | return call; | |
211 | } | |
212 | ||
6cf12869 | 213 | /* |
3bf0fb6f | 214 | * Queue the call for actual work. |
6cf12869 | 215 | */ |
3bf0fb6f | 216 | static void afs_queue_call_work(struct afs_call *call) |
6cf12869 | 217 | { |
3bf0fb6f | 218 | if (call->type->work) { |
3bf0fb6f | 219 | INIT_WORK(&call->work, call->type->work); |
341f741f | 220 | |
7a75b007 | 221 | afs_get_call(call, afs_call_trace_work); |
3bf0fb6f DH |
222 | if (!queue_work(afs_wq, &call->work)) |
223 | afs_put_call(call); | |
224 | } | |
6c67c7c3 DH |
225 | } |
226 | ||
08e0e7c8 DH |
227 | /* |
228 | * allocate a call with flat request and reply buffers | |
229 | */ | |
f044c884 DH |
230 | struct afs_call *afs_alloc_flat_call(struct afs_net *net, |
231 | const struct afs_call_type *type, | |
d001648e | 232 | size_t request_size, size_t reply_max) |
08e0e7c8 DH |
233 | { |
234 | struct afs_call *call; | |
235 | ||
f044c884 | 236 | call = afs_alloc_call(net, type, GFP_NOFS); |
08e0e7c8 DH |
237 | if (!call) |
238 | goto nomem_call; | |
239 | ||
240 | if (request_size) { | |
341f741f | 241 | call->request_size = request_size; |
08e0e7c8 DH |
242 | call->request = kmalloc(request_size, GFP_NOFS); |
243 | if (!call->request) | |
00d3b7a4 | 244 | goto nomem_free; |
08e0e7c8 DH |
245 | } |
246 | ||
d001648e | 247 | if (reply_max) { |
341f741f | 248 | call->reply_max = reply_max; |
d001648e | 249 | call->buffer = kmalloc(reply_max, GFP_NOFS); |
08e0e7c8 | 250 | if (!call->buffer) |
00d3b7a4 | 251 | goto nomem_free; |
08e0e7c8 DH |
252 | } |
253 | ||
12bdcf33 | 254 | afs_extract_to_buf(call, call->reply_max); |
025db80c | 255 | call->operation_ID = type->op; |
08e0e7c8 | 256 | init_waitqueue_head(&call->waitq); |
08e0e7c8 DH |
257 | return call; |
258 | ||
00d3b7a4 | 259 | nomem_free: |
341f741f | 260 | afs_put_call(call); |
08e0e7c8 DH |
261 | nomem_call: |
262 | return NULL; | |
263 | } | |
264 | ||
265 | /* | |
266 | * clean up a call with flat buffer | |
267 | */ | |
268 | void afs_flat_call_destructor(struct afs_call *call) | |
269 | { | |
270 | _enter(""); | |
271 | ||
272 | kfree(call->request); | |
273 | call->request = NULL; | |
274 | kfree(call->buffer); | |
275 | call->buffer = NULL; | |
276 | } | |
277 | ||
2f5705a5 DH |
278 | #define AFS_BVEC_MAX 8 |
279 | ||
280 | /* | |
281 | * Load the given bvec with the next few pages. | |
282 | */ | |
283 | static void afs_load_bvec(struct afs_call *call, struct msghdr *msg, | |
284 | struct bio_vec *bv, pgoff_t first, pgoff_t last, | |
285 | unsigned offset) | |
286 | { | |
287 | struct page *pages[AFS_BVEC_MAX]; | |
288 | unsigned int nr, n, i, to, bytes = 0; | |
289 | ||
290 | nr = min_t(pgoff_t, last - first + 1, AFS_BVEC_MAX); | |
291 | n = find_get_pages_contig(call->mapping, first, nr, pages); | |
292 | ASSERTCMP(n, ==, nr); | |
293 | ||
294 | msg->msg_flags |= MSG_MORE; | |
295 | for (i = 0; i < nr; i++) { | |
296 | to = PAGE_SIZE; | |
297 | if (first + i >= last) { | |
298 | to = call->last_to; | |
299 | msg->msg_flags &= ~MSG_MORE; | |
300 | } | |
301 | bv[i].bv_page = pages[i]; | |
302 | bv[i].bv_len = to - offset; | |
303 | bv[i].bv_offset = offset; | |
304 | bytes += to - offset; | |
305 | offset = 0; | |
306 | } | |
307 | ||
aa563d7b | 308 | iov_iter_bvec(&msg->msg_iter, WRITE, bv, nr, bytes); |
2f5705a5 DH |
309 | } |
310 | ||
e833251a DH |
311 | /* |
312 | * Advance the AFS call state when the RxRPC call ends the transmit phase. | |
313 | */ | |
314 | static void afs_notify_end_request_tx(struct sock *sock, | |
315 | struct rxrpc_call *rxcall, | |
316 | unsigned long call_user_ID) | |
317 | { | |
318 | struct afs_call *call = (struct afs_call *)call_user_ID; | |
319 | ||
98bf40cd | 320 | afs_set_call_state(call, AFS_CALL_CL_REQUESTING, AFS_CALL_CL_AWAIT_REPLY); |
e833251a DH |
321 | } |
322 | ||
31143d5d DH |
323 | /* |
324 | * attach the data from a bunch of pages on an inode to a call | |
325 | */ | |
39c6acea | 326 | static int afs_send_pages(struct afs_call *call, struct msghdr *msg) |
31143d5d | 327 | { |
2f5705a5 DH |
328 | struct bio_vec bv[AFS_BVEC_MAX]; |
329 | unsigned int bytes, nr, loop, offset; | |
31143d5d DH |
330 | pgoff_t first = call->first, last = call->last; |
331 | int ret; | |
332 | ||
31143d5d DH |
333 | offset = call->first_offset; |
334 | call->first_offset = 0; | |
335 | ||
336 | do { | |
2f5705a5 | 337 | afs_load_bvec(call, msg, bv, first, last, offset); |
2c099014 DH |
338 | trace_afs_send_pages(call, msg, first, last, offset); |
339 | ||
2f5705a5 DH |
340 | offset = 0; |
341 | bytes = msg->msg_iter.count; | |
342 | nr = msg->msg_iter.nr_segs; | |
343 | ||
f044c884 | 344 | ret = rxrpc_kernel_send_data(call->net->socket, call->rxcall, msg, |
e833251a | 345 | bytes, afs_notify_end_request_tx); |
2f5705a5 DH |
346 | for (loop = 0; loop < nr; loop++) |
347 | put_page(bv[loop].bv_page); | |
31143d5d DH |
348 | if (ret < 0) |
349 | break; | |
2f5705a5 DH |
350 | |
351 | first += nr; | |
5bbf5d39 | 352 | } while (first <= last); |
31143d5d | 353 | |
2c099014 | 354 | trace_afs_sent_pages(call, call->first, last, first, ret); |
31143d5d DH |
355 | return ret; |
356 | } | |
357 | ||
08e0e7c8 | 358 | /* |
0b9bf381 DH |
359 | * Initiate a call and synchronously queue up the parameters for dispatch. Any |
360 | * error is stored into the call struct, which the caller must check for. | |
08e0e7c8 | 361 | */ |
0b9bf381 | 362 | void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp) |
08e0e7c8 | 363 | { |
2feeaf84 | 364 | struct sockaddr_rxrpc *srx = &ac->alist->addrs[ac->index]; |
08e0e7c8 DH |
365 | struct rxrpc_call *rxcall; |
366 | struct msghdr msg; | |
367 | struct kvec iov[1]; | |
e754eba6 | 368 | s64 tx_total_len; |
08e0e7c8 DH |
369 | int ret; |
370 | ||
4d9df986 | 371 | _enter(",{%pISp},", &srx->transport); |
08e0e7c8 | 372 | |
00d3b7a4 DH |
373 | ASSERT(call->type != NULL); |
374 | ASSERT(call->type->name != NULL); | |
375 | ||
31143d5d DH |
376 | _debug("____MAKE %p{%s,%x} [%d]____", |
377 | call, call->type->name, key_serial(call->key), | |
f044c884 | 378 | atomic_read(&call->net->nr_outstanding_calls)); |
00d3b7a4 | 379 | |
3bf0fb6f DH |
380 | call->addr_ix = ac->index; |
381 | call->alist = afs_get_addrlist(ac->alist); | |
08e0e7c8 | 382 | |
e754eba6 DH |
383 | /* Work out the length we're going to transmit. This is awkward for |
384 | * calls such as FS.StoreData where there's an extra injection of data | |
385 | * after the initial fixed part. | |
386 | */ | |
387 | tx_total_len = call->request_size; | |
388 | if (call->send_pages) { | |
1199db60 DH |
389 | if (call->last == call->first) { |
390 | tx_total_len += call->last_to - call->first_offset; | |
391 | } else { | |
392 | /* It looks mathematically like you should be able to | |
393 | * combine the following lines with the ones above, but | |
394 | * unsigned arithmetic is fun when it wraps... | |
395 | */ | |
396 | tx_total_len += PAGE_SIZE - call->first_offset; | |
397 | tx_total_len += call->last_to; | |
398 | tx_total_len += (call->last - call->first - 1) * PAGE_SIZE; | |
399 | } | |
e754eba6 DH |
400 | } |
401 | ||
34fa4761 DH |
402 | /* If the call is going to be asynchronous, we need an extra ref for |
403 | * the call to hold itself so the caller need not hang on to its ref. | |
404 | */ | |
405 | if (call->async) | |
406 | afs_get_call(call, afs_call_trace_get); | |
407 | ||
08e0e7c8 | 408 | /* create a call */ |
4d9df986 | 409 | rxcall = rxrpc_kernel_begin_call(call->net->socket, srx, call->key, |
e754eba6 DH |
410 | (unsigned long)call, |
411 | tx_total_len, gfp, | |
0b9bf381 | 412 | (call->async ? |
56ff9c83 | 413 | afs_wake_up_async_call : |
a68f4a27 | 414 | afs_wake_up_call_waiter), |
a25e21f0 | 415 | call->upgrade, |
20b8391f | 416 | call->intr, |
a25e21f0 | 417 | call->debug_id); |
08e0e7c8 DH |
418 | if (IS_ERR(rxcall)) { |
419 | ret = PTR_ERR(rxcall); | |
3bf0fb6f | 420 | call->error = ret; |
08e0e7c8 DH |
421 | goto error_kill_call; |
422 | } | |
423 | ||
424 | call->rxcall = rxcall; | |
425 | ||
94f699c9 DH |
426 | if (call->max_lifespan) |
427 | rxrpc_kernel_set_max_life(call->net->socket, rxcall, | |
428 | call->max_lifespan); | |
429 | ||
08e0e7c8 DH |
430 | /* send the request */ |
431 | iov[0].iov_base = call->request; | |
432 | iov[0].iov_len = call->request_size; | |
433 | ||
434 | msg.msg_name = NULL; | |
435 | msg.msg_namelen = 0; | |
aa563d7b | 436 | iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, call->request_size); |
08e0e7c8 DH |
437 | msg.msg_control = NULL; |
438 | msg.msg_controllen = 0; | |
bc5e3a54 | 439 | msg.msg_flags = MSG_WAITALL | (call->send_pages ? MSG_MORE : 0); |
08e0e7c8 | 440 | |
f044c884 | 441 | ret = rxrpc_kernel_send_data(call->net->socket, rxcall, |
e833251a DH |
442 | &msg, call->request_size, |
443 | afs_notify_end_request_tx); | |
08e0e7c8 DH |
444 | if (ret < 0) |
445 | goto error_do_abort; | |
446 | ||
31143d5d | 447 | if (call->send_pages) { |
39c6acea | 448 | ret = afs_send_pages(call, &msg); |
31143d5d DH |
449 | if (ret < 0) |
450 | goto error_do_abort; | |
451 | } | |
452 | ||
34fa4761 DH |
453 | /* Note that at this point, we may have received the reply or an abort |
454 | * - and an asynchronous call may already have completed. | |
0b9bf381 DH |
455 | * |
456 | * afs_wait_for_call_to_complete(call, ac) | |
457 | * must be called to synchronously clean up. | |
34fa4761 | 458 | */ |
0b9bf381 | 459 | return; |
08e0e7c8 DH |
460 | |
461 | error_do_abort: | |
70af0e3b | 462 | if (ret != -ECONNABORTED) { |
f044c884 DH |
463 | rxrpc_kernel_abort_call(call->net->socket, rxcall, |
464 | RX_USER_ABORT, ret, "KSD"); | |
70af0e3b | 465 | } else { |
aa563d7b | 466 | iov_iter_kvec(&msg.msg_iter, READ, NULL, 0, 0); |
eb9950eb DH |
467 | rxrpc_kernel_recv_data(call->net->socket, rxcall, |
468 | &msg.msg_iter, false, | |
469 | &call->abort_code, &call->service_id); | |
d2ddc776 DH |
470 | ac->abort_code = call->abort_code; |
471 | ac->responded = true; | |
70af0e3b | 472 | } |
025db80c DH |
473 | call->error = ret; |
474 | trace_afs_call_done(call); | |
08e0e7c8 | 475 | error_kill_call: |
3bf0fb6f DH |
476 | if (call->type->done) |
477 | call->type->done(call); | |
34fa4761 DH |
478 | |
479 | /* We need to dispose of the extra ref we grabbed for an async call. | |
480 | * The call, however, might be queued on afs_async_calls and we need to | |
481 | * make sure we don't get any more notifications that might requeue it. | |
482 | */ | |
483 | if (call->rxcall) { | |
484 | rxrpc_kernel_end_call(call->net->socket, call->rxcall); | |
485 | call->rxcall = NULL; | |
486 | } | |
487 | if (call->async) { | |
488 | if (cancel_work_sync(&call->async_work)) | |
489 | afs_put_call(call); | |
490 | afs_put_call(call); | |
491 | } | |
492 | ||
d2ddc776 | 493 | ac->error = ret; |
34fa4761 | 494 | call->state = AFS_CALL_COMPLETE; |
08e0e7c8 | 495 | _leave(" = %d", ret); |
08e0e7c8 DH |
496 | } |
497 | ||
08e0e7c8 DH |
498 | /* |
499 | * deliver messages to a call | |
500 | */ | |
501 | static void afs_deliver_to_call(struct afs_call *call) | |
502 | { | |
98bf40cd DH |
503 | enum afs_call_state state; |
504 | u32 abort_code, remote_abort = 0; | |
08e0e7c8 DH |
505 | int ret; |
506 | ||
d001648e DH |
507 | _enter("%s", call->type->name); |
508 | ||
98bf40cd DH |
509 | while (state = READ_ONCE(call->state), |
510 | state == AFS_CALL_CL_AWAIT_REPLY || | |
511 | state == AFS_CALL_SV_AWAIT_OP_ID || | |
512 | state == AFS_CALL_SV_AWAIT_REQUEST || | |
513 | state == AFS_CALL_SV_AWAIT_ACK | |
d001648e | 514 | ) { |
98bf40cd | 515 | if (state == AFS_CALL_SV_AWAIT_ACK) { |
fc276122 | 516 | iov_iter_kvec(&call->def_iter, READ, NULL, 0, 0); |
f044c884 | 517 | ret = rxrpc_kernel_recv_data(call->net->socket, |
fc276122 | 518 | call->rxcall, &call->def_iter, |
12bdcf33 | 519 | false, &remote_abort, |
a68f4a27 | 520 | &call->service_id); |
fc276122 | 521 | trace_afs_receive_data(call, &call->def_iter, false, ret); |
8e8d7f13 | 522 | |
d001648e DH |
523 | if (ret == -EINPROGRESS || ret == -EAGAIN) |
524 | return; | |
98bf40cd DH |
525 | if (ret < 0 || ret == 1) { |
526 | if (ret == 1) | |
527 | ret = 0; | |
025db80c | 528 | goto call_complete; |
98bf40cd | 529 | } |
d001648e | 530 | return; |
08e0e7c8 DH |
531 | } |
532 | ||
4571577f | 533 | if (!call->have_reply_time && |
12d8e95a DH |
534 | rxrpc_kernel_get_reply_time(call->net->socket, |
535 | call->rxcall, | |
536 | &call->reply_time)) | |
4571577f | 537 | call->have_reply_time = true; |
12d8e95a | 538 | |
d001648e | 539 | ret = call->type->deliver(call); |
98bf40cd | 540 | state = READ_ONCE(call->state); |
d001648e DH |
541 | switch (ret) { |
542 | case 0: | |
3bf0fb6f | 543 | afs_queue_call_work(call); |
f2686b09 DH |
544 | if (state == AFS_CALL_CL_PROC_REPLY) { |
545 | if (call->cbi) | |
546 | set_bit(AFS_SERVER_FL_MAY_HAVE_CB, | |
547 | &call->cbi->server->flags); | |
025db80c | 548 | goto call_complete; |
f2686b09 | 549 | } |
98bf40cd | 550 | ASSERTCMP(state, >, AFS_CALL_CL_PROC_REPLY); |
d001648e DH |
551 | goto done; |
552 | case -EINPROGRESS: | |
553 | case -EAGAIN: | |
554 | goto out; | |
70af0e3b | 555 | case -ECONNABORTED: |
98bf40cd DH |
556 | ASSERTCMP(state, ==, AFS_CALL_COMPLETE); |
557 | goto done; | |
d001648e | 558 | case -ENOTSUPP: |
1157f153 | 559 | abort_code = RXGEN_OPCODE; |
f044c884 | 560 | rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
3a92789a | 561 | abort_code, ret, "KIV"); |
98bf40cd | 562 | goto local_abort; |
4ac15ea5 DH |
563 | case -EIO: |
564 | pr_err("kAFS: Call %u in bad state %u\n", | |
565 | call->debug_id, state); | |
566 | /* Fall through */ | |
d001648e DH |
567 | case -ENODATA: |
568 | case -EBADMSG: | |
569 | case -EMSGSIZE: | |
d001648e | 570 | abort_code = RXGEN_CC_UNMARSHAL; |
98bf40cd | 571 | if (state != AFS_CALL_CL_AWAIT_REPLY) |
d001648e | 572 | abort_code = RXGEN_SS_UNMARSHAL; |
f044c884 | 573 | rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
12bdcf33 | 574 | abort_code, ret, "KUM"); |
98bf40cd | 575 | goto local_abort; |
8022c4b9 DH |
576 | default: |
577 | abort_code = RX_USER_ABORT; | |
578 | rxrpc_kernel_abort_call(call->net->socket, call->rxcall, | |
579 | abort_code, ret, "KER"); | |
580 | goto local_abort; | |
d001648e | 581 | } |
08e0e7c8 DH |
582 | } |
583 | ||
d001648e | 584 | done: |
3bf0fb6f DH |
585 | if (call->type->done) |
586 | call->type->done(call); | |
98bf40cd | 587 | if (state == AFS_CALL_COMPLETE && call->incoming) |
341f741f | 588 | afs_put_call(call); |
d001648e | 589 | out: |
08e0e7c8 | 590 | _leave(""); |
d001648e DH |
591 | return; |
592 | ||
98bf40cd DH |
593 | local_abort: |
594 | abort_code = 0; | |
025db80c | 595 | call_complete: |
98bf40cd DH |
596 | afs_set_call_complete(call, ret, remote_abort); |
597 | state = AFS_CALL_COMPLETE; | |
d001648e | 598 | goto done; |
08e0e7c8 DH |
599 | } |
600 | ||
601 | /* | |
0b9bf381 | 602 | * Wait synchronously for a call to complete and clean up the call struct. |
08e0e7c8 | 603 | */ |
0b9bf381 DH |
604 | long afs_wait_for_call_to_complete(struct afs_call *call, |
605 | struct afs_addr_cursor *ac) | |
08e0e7c8 | 606 | { |
bc5e3a54 | 607 | signed long rtt2, timeout; |
33cd7f2b | 608 | long ret; |
7150ceaa | 609 | bool stalled = false; |
bc5e3a54 DH |
610 | u64 rtt; |
611 | u32 life, last_life; | |
f7f1dd31 | 612 | bool rxrpc_complete = false; |
08e0e7c8 DH |
613 | |
614 | DECLARE_WAITQUEUE(myself, current); | |
615 | ||
616 | _enter(""); | |
617 | ||
0b9bf381 DH |
618 | ret = call->error; |
619 | if (ret < 0) | |
620 | goto out; | |
621 | ||
f044c884 | 622 | rtt = rxrpc_kernel_get_rtt(call->net->socket, call->rxcall); |
bc5e3a54 DH |
623 | rtt2 = nsecs_to_jiffies64(rtt) * 2; |
624 | if (rtt2 < 2) | |
625 | rtt2 = 2; | |
626 | ||
627 | timeout = rtt2; | |
4611da30 | 628 | rxrpc_kernel_check_life(call->net->socket, call->rxcall, &last_life); |
bc5e3a54 | 629 | |
08e0e7c8 DH |
630 | add_wait_queue(&call->waitq, &myself); |
631 | for (;;) { | |
bc5e3a54 | 632 | set_current_state(TASK_UNINTERRUPTIBLE); |
08e0e7c8 DH |
633 | |
634 | /* deliver any messages that are in the queue */ | |
98bf40cd DH |
635 | if (!afs_check_call_state(call, AFS_CALL_COMPLETE) && |
636 | call->need_attention) { | |
d001648e | 637 | call->need_attention = false; |
08e0e7c8 DH |
638 | __set_current_state(TASK_RUNNING); |
639 | afs_deliver_to_call(call); | |
c74386d5 | 640 | timeout = rtt2; |
08e0e7c8 DH |
641 | continue; |
642 | } | |
643 | ||
98bf40cd | 644 | if (afs_check_call_state(call, AFS_CALL_COMPLETE)) |
08e0e7c8 | 645 | break; |
bc5e3a54 | 646 | |
f7f1dd31 MD |
647 | if (!rxrpc_kernel_check_life(call->net->socket, call->rxcall, &life)) { |
648 | /* rxrpc terminated the call. */ | |
649 | rxrpc_complete = true; | |
650 | break; | |
651 | } | |
652 | ||
20b8391f | 653 | if (call->intr && timeout == 0 && |
7150ceaa DH |
654 | life == last_life && signal_pending(current)) { |
655 | if (stalled) | |
bc5e3a54 | 656 | break; |
7150ceaa DH |
657 | __set_current_state(TASK_RUNNING); |
658 | rxrpc_kernel_probe_life(call->net->socket, call->rxcall); | |
659 | timeout = rtt2; | |
660 | stalled = true; | |
661 | continue; | |
662 | } | |
bc5e3a54 DH |
663 | |
664 | if (life != last_life) { | |
665 | timeout = rtt2; | |
666 | last_life = life; | |
7150ceaa | 667 | stalled = false; |
bc5e3a54 DH |
668 | } |
669 | ||
670 | timeout = schedule_timeout(timeout); | |
08e0e7c8 DH |
671 | } |
672 | ||
673 | remove_wait_queue(&call->waitq, &myself); | |
674 | __set_current_state(TASK_RUNNING); | |
675 | ||
98bf40cd | 676 | if (!afs_check_call_state(call, AFS_CALL_COMPLETE)) { |
f7f1dd31 MD |
677 | if (rxrpc_complete) { |
678 | afs_set_call_complete(call, call->error, call->abort_code); | |
679 | } else { | |
680 | /* Kill off the call if it's still live. */ | |
681 | _debug("call interrupted"); | |
682 | if (rxrpc_kernel_abort_call(call->net->socket, call->rxcall, | |
683 | RX_USER_ABORT, -EINTR, "KWI")) | |
684 | afs_set_call_complete(call, -EINTR, 0); | |
685 | } | |
08e0e7c8 DH |
686 | } |
687 | ||
98bf40cd | 688 | spin_lock_bh(&call->state_lock); |
d2ddc776 DH |
689 | ac->abort_code = call->abort_code; |
690 | ac->error = call->error; | |
98bf40cd | 691 | spin_unlock_bh(&call->state_lock); |
d2ddc776 DH |
692 | |
693 | ret = ac->error; | |
694 | switch (ret) { | |
695 | case 0: | |
ffba718e DH |
696 | ret = call->ret0; |
697 | call->ret0 = 0; | |
698 | ||
d2ddc776 DH |
699 | /* Fall through */ |
700 | case -ECONNABORTED: | |
701 | ac->responded = true; | |
702 | break; | |
33cd7f2b DH |
703 | } |
704 | ||
0b9bf381 | 705 | out: |
08e0e7c8 | 706 | _debug("call complete"); |
341f741f | 707 | afs_put_call(call); |
33cd7f2b | 708 | _leave(" = %p", (void *)ret); |
08e0e7c8 DH |
709 | return ret; |
710 | } | |
711 | ||
712 | /* | |
713 | * wake up a waiting call | |
714 | */ | |
d001648e DH |
715 | static void afs_wake_up_call_waiter(struct sock *sk, struct rxrpc_call *rxcall, |
716 | unsigned long call_user_ID) | |
08e0e7c8 | 717 | { |
d001648e DH |
718 | struct afs_call *call = (struct afs_call *)call_user_ID; |
719 | ||
720 | call->need_attention = true; | |
08e0e7c8 DH |
721 | wake_up(&call->waitq); |
722 | } | |
723 | ||
724 | /* | |
725 | * wake up an asynchronous call | |
726 | */ | |
d001648e DH |
727 | static void afs_wake_up_async_call(struct sock *sk, struct rxrpc_call *rxcall, |
728 | unsigned long call_user_ID) | |
08e0e7c8 | 729 | { |
d001648e | 730 | struct afs_call *call = (struct afs_call *)call_user_ID; |
341f741f | 731 | int u; |
d001648e | 732 | |
8e8d7f13 | 733 | trace_afs_notify_call(rxcall, call); |
d001648e | 734 | call->need_attention = true; |
341f741f | 735 | |
bfc18e38 | 736 | u = atomic_fetch_add_unless(&call->usage, 1, 0); |
341f741f DH |
737 | if (u != 0) { |
738 | trace_afs_call(call, afs_call_trace_wake, u, | |
f044c884 | 739 | atomic_read(&call->net->nr_outstanding_calls), |
341f741f DH |
740 | __builtin_return_address(0)); |
741 | ||
742 | if (!queue_work(afs_async_calls, &call->async_work)) | |
743 | afs_put_call(call); | |
744 | } | |
08e0e7c8 DH |
745 | } |
746 | ||
08e0e7c8 | 747 | /* |
341f741f DH |
748 | * Delete an asynchronous call. The work item carries a ref to the call struct |
749 | * that we need to release. | |
08e0e7c8 | 750 | */ |
d001648e | 751 | static void afs_delete_async_call(struct work_struct *work) |
08e0e7c8 | 752 | { |
d001648e DH |
753 | struct afs_call *call = container_of(work, struct afs_call, async_work); |
754 | ||
08e0e7c8 DH |
755 | _enter(""); |
756 | ||
341f741f | 757 | afs_put_call(call); |
08e0e7c8 DH |
758 | |
759 | _leave(""); | |
760 | } | |
761 | ||
762 | /* | |
341f741f DH |
763 | * Perform I/O processing on an asynchronous call. The work item carries a ref |
764 | * to the call struct that we either need to release or to pass on. | |
08e0e7c8 | 765 | */ |
d001648e | 766 | static void afs_process_async_call(struct work_struct *work) |
08e0e7c8 | 767 | { |
d001648e DH |
768 | struct afs_call *call = container_of(work, struct afs_call, async_work); |
769 | ||
08e0e7c8 DH |
770 | _enter(""); |
771 | ||
d001648e DH |
772 | if (call->state < AFS_CALL_COMPLETE && call->need_attention) { |
773 | call->need_attention = false; | |
08e0e7c8 | 774 | afs_deliver_to_call(call); |
d001648e | 775 | } |
08e0e7c8 | 776 | |
56ff9c83 | 777 | if (call->state == AFS_CALL_COMPLETE) { |
341f741f DH |
778 | /* We have two refs to release - one from the alloc and one |
779 | * queued with the work item - and we can't just deallocate the | |
780 | * call because the work item may be queued again. | |
781 | */ | |
d001648e | 782 | call->async_work.func = afs_delete_async_call; |
341f741f DH |
783 | if (!queue_work(afs_async_calls, &call->async_work)) |
784 | afs_put_call(call); | |
08e0e7c8 DH |
785 | } |
786 | ||
341f741f | 787 | afs_put_call(call); |
08e0e7c8 DH |
788 | _leave(""); |
789 | } | |
790 | ||
00e90712 DH |
791 | static void afs_rx_attach(struct rxrpc_call *rxcall, unsigned long user_call_ID) |
792 | { | |
793 | struct afs_call *call = (struct afs_call *)user_call_ID; | |
794 | ||
795 | call->rxcall = rxcall; | |
796 | } | |
797 | ||
798 | /* | |
799 | * Charge the incoming call preallocation. | |
800 | */ | |
f044c884 | 801 | void afs_charge_preallocation(struct work_struct *work) |
00e90712 | 802 | { |
f044c884 DH |
803 | struct afs_net *net = |
804 | container_of(work, struct afs_net, charge_preallocation_work); | |
805 | struct afs_call *call = net->spare_incoming_call; | |
00e90712 DH |
806 | |
807 | for (;;) { | |
808 | if (!call) { | |
f044c884 | 809 | call = afs_alloc_call(net, &afs_RXCMxxxx, GFP_KERNEL); |
00e90712 DH |
810 | if (!call) |
811 | break; | |
812 | ||
56ff9c83 | 813 | call->async = true; |
98bf40cd | 814 | call->state = AFS_CALL_SV_AWAIT_OP_ID; |
56ff9c83 | 815 | init_waitqueue_head(&call->waitq); |
12bdcf33 | 816 | afs_extract_to_tmp(call); |
00e90712 DH |
817 | } |
818 | ||
f044c884 | 819 | if (rxrpc_kernel_charge_accept(net->socket, |
00e90712 DH |
820 | afs_wake_up_async_call, |
821 | afs_rx_attach, | |
822 | (unsigned long)call, | |
a25e21f0 DH |
823 | GFP_KERNEL, |
824 | call->debug_id) < 0) | |
00e90712 DH |
825 | break; |
826 | call = NULL; | |
827 | } | |
f044c884 | 828 | net->spare_incoming_call = call; |
00e90712 DH |
829 | } |
830 | ||
831 | /* | |
832 | * Discard a preallocated call when a socket is shut down. | |
833 | */ | |
834 | static void afs_rx_discard_new_call(struct rxrpc_call *rxcall, | |
835 | unsigned long user_call_ID) | |
836 | { | |
837 | struct afs_call *call = (struct afs_call *)user_call_ID; | |
838 | ||
00e90712 | 839 | call->rxcall = NULL; |
341f741f | 840 | afs_put_call(call); |
00e90712 DH |
841 | } |
842 | ||
d001648e DH |
843 | /* |
844 | * Notification of an incoming call. | |
845 | */ | |
00e90712 DH |
846 | static void afs_rx_new_call(struct sock *sk, struct rxrpc_call *rxcall, |
847 | unsigned long user_call_ID) | |
d001648e | 848 | { |
f044c884 DH |
849 | struct afs_net *net = afs_sock2net(sk); |
850 | ||
851 | queue_work(afs_wq, &net->charge_preallocation_work); | |
d001648e DH |
852 | } |
853 | ||
08e0e7c8 | 854 | /* |
372ee163 DH |
855 | * Grab the operation ID from an incoming cache manager call. The socket |
856 | * buffer is discarded on error or if we don't yet have sufficient data. | |
08e0e7c8 | 857 | */ |
d001648e | 858 | static int afs_deliver_cm_op_id(struct afs_call *call) |
08e0e7c8 | 859 | { |
d001648e | 860 | int ret; |
08e0e7c8 | 861 | |
fc276122 | 862 | _enter("{%zu}", iov_iter_count(call->iter)); |
08e0e7c8 DH |
863 | |
864 | /* the operation ID forms the first four bytes of the request data */ | |
12bdcf33 | 865 | ret = afs_extract_data(call, true); |
d001648e DH |
866 | if (ret < 0) |
867 | return ret; | |
08e0e7c8 | 868 | |
50a2c953 | 869 | call->operation_ID = ntohl(call->tmp); |
98bf40cd | 870 | afs_set_call_state(call, AFS_CALL_SV_AWAIT_OP_ID, AFS_CALL_SV_AWAIT_REQUEST); |
08e0e7c8 DH |
871 | |
872 | /* ask the cache manager to route the call (it'll change the call type | |
873 | * if successful) */ | |
874 | if (!afs_cm_incoming_call(call)) | |
875 | return -ENOTSUPP; | |
876 | ||
8e8d7f13 DH |
877 | trace_afs_cb_call(call); |
878 | ||
08e0e7c8 DH |
879 | /* pass responsibility for the remainer of this message off to the |
880 | * cache manager op */ | |
d001648e | 881 | return call->type->deliver(call); |
08e0e7c8 DH |
882 | } |
883 | ||
e833251a DH |
884 | /* |
885 | * Advance the AFS call state when an RxRPC service call ends the transmit | |
886 | * phase. | |
887 | */ | |
888 | static void afs_notify_end_reply_tx(struct sock *sock, | |
889 | struct rxrpc_call *rxcall, | |
890 | unsigned long call_user_ID) | |
891 | { | |
892 | struct afs_call *call = (struct afs_call *)call_user_ID; | |
893 | ||
98bf40cd | 894 | afs_set_call_state(call, AFS_CALL_SV_REPLYING, AFS_CALL_SV_AWAIT_ACK); |
e833251a DH |
895 | } |
896 | ||
08e0e7c8 DH |
897 | /* |
898 | * send an empty reply | |
899 | */ | |
900 | void afs_send_empty_reply(struct afs_call *call) | |
901 | { | |
f044c884 | 902 | struct afs_net *net = call->net; |
08e0e7c8 | 903 | struct msghdr msg; |
08e0e7c8 DH |
904 | |
905 | _enter(""); | |
906 | ||
f044c884 | 907 | rxrpc_kernel_set_tx_length(net->socket, call->rxcall, 0); |
e754eba6 | 908 | |
08e0e7c8 DH |
909 | msg.msg_name = NULL; |
910 | msg.msg_namelen = 0; | |
aa563d7b | 911 | iov_iter_kvec(&msg.msg_iter, WRITE, NULL, 0, 0); |
08e0e7c8 DH |
912 | msg.msg_control = NULL; |
913 | msg.msg_controllen = 0; | |
914 | msg.msg_flags = 0; | |
915 | ||
f044c884 | 916 | switch (rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, 0, |
e833251a | 917 | afs_notify_end_reply_tx)) { |
08e0e7c8 DH |
918 | case 0: |
919 | _leave(" [replied]"); | |
920 | return; | |
921 | ||
922 | case -ENOMEM: | |
923 | _debug("oom"); | |
f044c884 | 924 | rxrpc_kernel_abort_call(net->socket, call->rxcall, |
3a92789a | 925 | RX_USER_ABORT, -ENOMEM, "KOO"); |
e690c9e3 | 926 | /* Fall through */ |
08e0e7c8 | 927 | default: |
08e0e7c8 DH |
928 | _leave(" [error]"); |
929 | return; | |
930 | } | |
931 | } | |
932 | ||
b908fe6b DH |
933 | /* |
934 | * send a simple reply | |
935 | */ | |
936 | void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len) | |
937 | { | |
f044c884 | 938 | struct afs_net *net = call->net; |
b908fe6b | 939 | struct msghdr msg; |
2e90b1c4 | 940 | struct kvec iov[1]; |
bd6dc742 | 941 | int n; |
b908fe6b DH |
942 | |
943 | _enter(""); | |
944 | ||
f044c884 | 945 | rxrpc_kernel_set_tx_length(net->socket, call->rxcall, len); |
e754eba6 | 946 | |
b908fe6b DH |
947 | iov[0].iov_base = (void *) buf; |
948 | iov[0].iov_len = len; | |
949 | msg.msg_name = NULL; | |
950 | msg.msg_namelen = 0; | |
aa563d7b | 951 | iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len); |
b908fe6b DH |
952 | msg.msg_control = NULL; |
953 | msg.msg_controllen = 0; | |
954 | msg.msg_flags = 0; | |
955 | ||
f044c884 | 956 | n = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, len, |
e833251a | 957 | afs_notify_end_reply_tx); |
bd6dc742 | 958 | if (n >= 0) { |
6c67c7c3 | 959 | /* Success */ |
b908fe6b DH |
960 | _leave(" [replied]"); |
961 | return; | |
bd6dc742 | 962 | } |
6c67c7c3 | 963 | |
bd6dc742 | 964 | if (n == -ENOMEM) { |
b908fe6b | 965 | _debug("oom"); |
f044c884 | 966 | rxrpc_kernel_abort_call(net->socket, call->rxcall, |
3a92789a | 967 | RX_USER_ABORT, -ENOMEM, "KOO"); |
b908fe6b | 968 | } |
bd6dc742 | 969 | _leave(" [error]"); |
b908fe6b DH |
970 | } |
971 | ||
08e0e7c8 | 972 | /* |
372ee163 | 973 | * Extract a piece of data from the received data socket buffers. |
08e0e7c8 | 974 | */ |
12bdcf33 | 975 | int afs_extract_data(struct afs_call *call, bool want_more) |
08e0e7c8 | 976 | { |
f044c884 | 977 | struct afs_net *net = call->net; |
fc276122 | 978 | struct iov_iter *iter = call->iter; |
98bf40cd | 979 | enum afs_call_state state; |
7888da95 | 980 | u32 remote_abort = 0; |
d001648e | 981 | int ret; |
08e0e7c8 | 982 | |
12bdcf33 | 983 | _enter("{%s,%zu},%d", call->type->name, iov_iter_count(iter), want_more); |
eb9950eb | 984 | |
12bdcf33 | 985 | ret = rxrpc_kernel_recv_data(net->socket, call->rxcall, iter, |
98bf40cd | 986 | want_more, &remote_abort, |
a68f4a27 | 987 | &call->service_id); |
d001648e DH |
988 | if (ret == 0 || ret == -EAGAIN) |
989 | return ret; | |
08e0e7c8 | 990 | |
98bf40cd | 991 | state = READ_ONCE(call->state); |
d001648e | 992 | if (ret == 1) { |
98bf40cd DH |
993 | switch (state) { |
994 | case AFS_CALL_CL_AWAIT_REPLY: | |
995 | afs_set_call_state(call, state, AFS_CALL_CL_PROC_REPLY); | |
d001648e | 996 | break; |
98bf40cd DH |
997 | case AFS_CALL_SV_AWAIT_REQUEST: |
998 | afs_set_call_state(call, state, AFS_CALL_SV_REPLYING); | |
d001648e | 999 | break; |
98bf40cd DH |
1000 | case AFS_CALL_COMPLETE: |
1001 | kdebug("prem complete %d", call->error); | |
f51375cd | 1002 | return afs_io_error(call, afs_io_error_extract); |
d001648e DH |
1003 | default: |
1004 | break; | |
1005 | } | |
1006 | return 0; | |
08e0e7c8 | 1007 | } |
d001648e | 1008 | |
98bf40cd | 1009 | afs_set_call_complete(call, ret, remote_abort); |
d001648e | 1010 | return ret; |
08e0e7c8 | 1011 | } |
5f702c8e DH |
1012 | |
1013 | /* | |
1014 | * Log protocol error production. | |
1015 | */ | |
160cb957 DH |
1016 | noinline int afs_protocol_error(struct afs_call *call, int error, |
1017 | enum afs_eproto_cause cause) | |
5f702c8e | 1018 | { |
160cb957 | 1019 | trace_afs_protocol_error(call, error, cause); |
5f702c8e DH |
1020 | return error; |
1021 | } |