blob: fc49193e12c433c5edc51b21965d76f97b6759d0 [file] [log] [blame]
David Howells08e0e7c2007-04-26 15:55:03 -07001/* Maintain an RxRPC server socket to do AFS communications through
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010013#include <linux/sched/signal.h>
14
David Howells08e0e7c2007-04-26 15:55:03 -070015#include <net/sock.h>
16#include <net/af_rxrpc.h>
David Howells08e0e7c2007-04-26 15:55:03 -070017#include "internal.h"
18#include "afs_cm.h"
19
David Howellsf044c882017-11-02 15:27:45 +000020struct workqueue_struct *afs_async_calls;
David Howells08e0e7c2007-04-26 15:55:03 -070021
David Howellsd0016482016-08-30 20:42:14 +010022static void afs_wake_up_call_waiter(struct sock *, struct rxrpc_call *, unsigned long);
David Howells08e0e7c2007-04-26 15:55:03 -070023static int afs_wait_for_call_to_complete(struct afs_call *);
David Howellsd0016482016-08-30 20:42:14 +010024static void afs_wake_up_async_call(struct sock *, struct rxrpc_call *, unsigned long);
David Howellsd0016482016-08-30 20:42:14 +010025static void afs_process_async_call(struct work_struct *);
David Howells00e90712016-09-08 11:10:12 +010026static void afs_rx_new_call(struct sock *, struct rxrpc_call *, unsigned long);
27static void afs_rx_discard_new_call(struct rxrpc_call *, unsigned long);
David Howellsd0016482016-08-30 20:42:14 +010028static int afs_deliver_cm_op_id(struct afs_call *);
David Howells08e0e7c2007-04-26 15:55:03 -070029
David Howells08e0e7c2007-04-26 15:55:03 -070030/* asynchronous incoming call initial processing */
31static const struct afs_call_type afs_RXCMxxxx = {
David Howells00d3b7a2007-04-26 15:57:07 -070032 .name = "CB.xxxx",
David Howells08e0e7c2007-04-26 15:55:03 -070033 .deliver = afs_deliver_cm_op_id,
David Howells08e0e7c2007-04-26 15:55:03 -070034};
35
David Howells08e0e7c2007-04-26 15:55:03 -070036/*
37 * open an RxRPC socket and bind it to be a server for callback notifications
38 * - the socket is left in blocking mode and non-blocking ops use MSG_DONTWAIT
39 */
David Howellsf044c882017-11-02 15:27:45 +000040int afs_open_socket(struct afs_net *net)
David Howells08e0e7c2007-04-26 15:55:03 -070041{
42 struct sockaddr_rxrpc srx;
43 struct socket *socket;
44 int ret;
45
46 _enter("");
47
David Howells3838d3e2017-11-02 15:27:47 +000048 ret = sock_create_kern(&init_net, AF_RXRPC, SOCK_DGRAM, PF_INET6, &socket);
David Howells0e119b42016-06-10 22:30:37 +010049 if (ret < 0)
50 goto error_1;
David Howells08e0e7c2007-04-26 15:55:03 -070051
52 socket->sk->sk_allocation = GFP_NOFS;
53
54 /* bind the callback manager's address to make this a server socket */
David Howells3838d3e2017-11-02 15:27:47 +000055 memset(&srx, 0, sizeof(srx));
David Howells08e0e7c2007-04-26 15:55:03 -070056 srx.srx_family = AF_RXRPC;
57 srx.srx_service = CM_SERVICE;
58 srx.transport_type = SOCK_DGRAM;
David Howells3838d3e2017-11-02 15:27:47 +000059 srx.transport_len = sizeof(srx.transport.sin6);
60 srx.transport.sin6.sin6_family = AF_INET6;
61 srx.transport.sin6.sin6_port = htons(AFS_CM_PORT);
David Howells08e0e7c2007-04-26 15:55:03 -070062
63 ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx));
David Howells0e119b42016-06-10 22:30:37 +010064 if (ret < 0)
65 goto error_2;
66
David Howells00e90712016-09-08 11:10:12 +010067 rxrpc_kernel_new_call_notification(socket, afs_rx_new_call,
68 afs_rx_discard_new_call);
David Howellsd0016482016-08-30 20:42:14 +010069
David Howells0e119b42016-06-10 22:30:37 +010070 ret = kernel_listen(socket, INT_MAX);
71 if (ret < 0)
72 goto error_2;
David Howells08e0e7c2007-04-26 15:55:03 -070073
David Howellsf044c882017-11-02 15:27:45 +000074 net->socket = socket;
75 afs_charge_preallocation(&net->charge_preallocation_work);
David Howells08e0e7c2007-04-26 15:55:03 -070076 _leave(" = 0");
77 return 0;
David Howells0e119b42016-06-10 22:30:37 +010078
79error_2:
80 sock_release(socket);
81error_1:
David Howells0e119b42016-06-10 22:30:37 +010082 _leave(" = %d", ret);
83 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -070084}
85
86/*
87 * close the RxRPC socket AFS was using
88 */
David Howellsf044c882017-11-02 15:27:45 +000089void afs_close_socket(struct afs_net *net)
David Howells08e0e7c2007-04-26 15:55:03 -070090{
91 _enter("");
92
David Howellsf044c882017-11-02 15:27:45 +000093 kernel_listen(net->socket, 0);
David Howells341f7412017-01-05 10:38:36 +000094 flush_workqueue(afs_async_calls);
95
David Howellsf044c882017-11-02 15:27:45 +000096 if (net->spare_incoming_call) {
97 afs_put_call(net->spare_incoming_call);
98 net->spare_incoming_call = NULL;
David Howells00e90712016-09-08 11:10:12 +010099 }
100
David Howellsf044c882017-11-02 15:27:45 +0000101 _debug("outstanding %u", atomic_read(&net->nr_outstanding_calls));
102 wait_on_atomic_t(&net->nr_outstanding_calls, atomic_t_wait,
David Howells2f02f7a2016-04-07 17:23:03 +0100103 TASK_UNINTERRUPTIBLE);
104 _debug("no outstanding calls");
105
David Howellsf044c882017-11-02 15:27:45 +0000106 kernel_sock_shutdown(net->socket, SHUT_RDWR);
David Howells248f2192016-09-08 11:10:12 +0100107 flush_workqueue(afs_async_calls);
David Howellsf044c882017-11-02 15:27:45 +0000108 sock_release(net->socket);
David Howells08e0e7c2007-04-26 15:55:03 -0700109
110 _debug("dework");
David Howells08e0e7c2007-04-26 15:55:03 -0700111 _leave("");
112}
113
114/*
David Howells341f7412017-01-05 10:38:36 +0000115 * Allocate a call.
David Howells00d3b7a2007-04-26 15:57:07 -0700116 */
David Howellsf044c882017-11-02 15:27:45 +0000117static struct afs_call *afs_alloc_call(struct afs_net *net,
118 const struct afs_call_type *type,
David Howells341f7412017-01-05 10:38:36 +0000119 gfp_t gfp)
David Howells00d3b7a2007-04-26 15:57:07 -0700120{
David Howells341f7412017-01-05 10:38:36 +0000121 struct afs_call *call;
122 int o;
David Howells00d3b7a2007-04-26 15:57:07 -0700123
David Howells341f7412017-01-05 10:38:36 +0000124 call = kzalloc(sizeof(*call), gfp);
125 if (!call)
126 return NULL;
David Howells00d3b7a2007-04-26 15:57:07 -0700127
David Howells341f7412017-01-05 10:38:36 +0000128 call->type = type;
David Howellsf044c882017-11-02 15:27:45 +0000129 call->net = net;
David Howells341f7412017-01-05 10:38:36 +0000130 atomic_set(&call->usage, 1);
131 INIT_WORK(&call->async_work, afs_process_async_call);
132 init_waitqueue_head(&call->waitq);
David Howells2f02f7a2016-04-07 17:23:03 +0100133
David Howellsf044c882017-11-02 15:27:45 +0000134 o = atomic_inc_return(&net->nr_outstanding_calls);
David Howells341f7412017-01-05 10:38:36 +0000135 trace_afs_call(call, afs_call_trace_alloc, 1, o,
136 __builtin_return_address(0));
137 return call;
David Howells00d3b7a2007-04-26 15:57:07 -0700138}
139
140/*
David Howells341f7412017-01-05 10:38:36 +0000141 * Dispose of a reference on a call.
David Howells6c67c7c2014-05-21 14:48:05 +0100142 */
David Howells341f7412017-01-05 10:38:36 +0000143void afs_put_call(struct afs_call *call)
David Howells6c67c7c2014-05-21 14:48:05 +0100144{
David Howellsf044c882017-11-02 15:27:45 +0000145 struct afs_net *net = call->net;
David Howells341f7412017-01-05 10:38:36 +0000146 int n = atomic_dec_return(&call->usage);
David Howellsf044c882017-11-02 15:27:45 +0000147 int o = atomic_read(&net->nr_outstanding_calls);
David Howells341f7412017-01-05 10:38:36 +0000148
149 trace_afs_call(call, afs_call_trace_put, n + 1, o,
150 __builtin_return_address(0));
151
152 ASSERTCMP(n, >=, 0);
153 if (n == 0) {
154 ASSERT(!work_pending(&call->async_work));
155 ASSERT(call->type->name != NULL);
156
157 if (call->rxcall) {
David Howellsf044c882017-11-02 15:27:45 +0000158 rxrpc_kernel_end_call(net->socket, call->rxcall);
David Howells341f7412017-01-05 10:38:36 +0000159 call->rxcall = NULL;
160 }
161 if (call->type->destructor)
162 call->type->destructor(call);
163
164 kfree(call->request);
165 kfree(call);
166
David Howellsf044c882017-11-02 15:27:45 +0000167 o = atomic_dec_return(&net->nr_outstanding_calls);
David Howells341f7412017-01-05 10:38:36 +0000168 trace_afs_call(call, afs_call_trace_free, 0, o,
169 __builtin_return_address(0));
170 if (o == 0)
David Howellsf044c882017-11-02 15:27:45 +0000171 wake_up_atomic_t(&net->nr_outstanding_calls);
David Howells6c67c7c2014-05-21 14:48:05 +0100172 }
Nathaniel Wesley Filardo6cf12862014-05-21 16:04:11 +0100173}
174
175/*
David Howells341f7412017-01-05 10:38:36 +0000176 * Queue the call for actual work. Returns 0 unconditionally for convenience.
Nathaniel Wesley Filardo6cf12862014-05-21 16:04:11 +0100177 */
David Howells341f7412017-01-05 10:38:36 +0000178int afs_queue_call_work(struct afs_call *call)
Nathaniel Wesley Filardo6cf12862014-05-21 16:04:11 +0100179{
David Howells341f7412017-01-05 10:38:36 +0000180 int u = atomic_inc_return(&call->usage);
181
182 trace_afs_call(call, afs_call_trace_work, u,
David Howellsf044c882017-11-02 15:27:45 +0000183 atomic_read(&call->net->nr_outstanding_calls),
David Howells341f7412017-01-05 10:38:36 +0000184 __builtin_return_address(0));
185
186 INIT_WORK(&call->work, call->type->work);
187
188 if (!queue_work(afs_wq, &call->work))
189 afs_put_call(call);
190 return 0;
David Howells6c67c7c2014-05-21 14:48:05 +0100191}
192
193/*
David Howells08e0e7c2007-04-26 15:55:03 -0700194 * allocate a call with flat request and reply buffers
195 */
David Howellsf044c882017-11-02 15:27:45 +0000196struct afs_call *afs_alloc_flat_call(struct afs_net *net,
197 const struct afs_call_type *type,
David Howellsd0016482016-08-30 20:42:14 +0100198 size_t request_size, size_t reply_max)
David Howells08e0e7c2007-04-26 15:55:03 -0700199{
200 struct afs_call *call;
201
David Howellsf044c882017-11-02 15:27:45 +0000202 call = afs_alloc_call(net, type, GFP_NOFS);
David Howells08e0e7c2007-04-26 15:55:03 -0700203 if (!call)
204 goto nomem_call;
205
David Howells00d3b7a2007-04-26 15:57:07 -0700206 if (request_size) {
David Howells341f7412017-01-05 10:38:36 +0000207 call->request_size = request_size;
David Howells00d3b7a2007-04-26 15:57:07 -0700208 call->request = kmalloc(request_size, GFP_NOFS);
209 if (!call->request)
210 goto nomem_free;
211 }
212
David Howellsd0016482016-08-30 20:42:14 +0100213 if (reply_max) {
David Howells341f7412017-01-05 10:38:36 +0000214 call->reply_max = reply_max;
David Howellsd0016482016-08-30 20:42:14 +0100215 call->buffer = kmalloc(reply_max, GFP_NOFS);
David Howells00d3b7a2007-04-26 15:57:07 -0700216 if (!call->buffer)
217 goto nomem_free;
218 }
219
David Howells08e0e7c2007-04-26 15:55:03 -0700220 init_waitqueue_head(&call->waitq);
David Howells08e0e7c2007-04-26 15:55:03 -0700221 return call;
222
David Howells00d3b7a2007-04-26 15:57:07 -0700223nomem_free:
David Howells341f7412017-01-05 10:38:36 +0000224 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700225nomem_call:
226 return NULL;
227}
228
229/*
230 * clean up a call with flat buffer
231 */
232void afs_flat_call_destructor(struct afs_call *call)
233{
234 _enter("");
235
236 kfree(call->request);
237 call->request = NULL;
238 kfree(call->buffer);
239 call->buffer = NULL;
240}
241
David Howells2f5705a2017-03-16 16:27:46 +0000242#define AFS_BVEC_MAX 8
243
244/*
245 * Load the given bvec with the next few pages.
246 */
247static void afs_load_bvec(struct afs_call *call, struct msghdr *msg,
248 struct bio_vec *bv, pgoff_t first, pgoff_t last,
249 unsigned offset)
250{
251 struct page *pages[AFS_BVEC_MAX];
252 unsigned int nr, n, i, to, bytes = 0;
253
254 nr = min_t(pgoff_t, last - first + 1, AFS_BVEC_MAX);
255 n = find_get_pages_contig(call->mapping, first, nr, pages);
256 ASSERTCMP(n, ==, nr);
257
258 msg->msg_flags |= MSG_MORE;
259 for (i = 0; i < nr; i++) {
260 to = PAGE_SIZE;
261 if (first + i >= last) {
262 to = call->last_to;
263 msg->msg_flags &= ~MSG_MORE;
264 }
265 bv[i].bv_page = pages[i];
266 bv[i].bv_len = to - offset;
267 bv[i].bv_offset = offset;
268 bytes += to - offset;
269 offset = 0;
270 }
271
272 iov_iter_bvec(&msg->msg_iter, WRITE | ITER_BVEC, bv, nr, bytes);
273}
274
David Howells08e0e7c2007-04-26 15:55:03 -0700275/*
David Howellse8332512017-08-29 10:18:56 +0100276 * Advance the AFS call state when the RxRPC call ends the transmit phase.
277 */
278static void afs_notify_end_request_tx(struct sock *sock,
279 struct rxrpc_call *rxcall,
280 unsigned long call_user_ID)
281{
282 struct afs_call *call = (struct afs_call *)call_user_ID;
283
284 if (call->state == AFS_CALL_REQUESTING)
285 call->state = AFS_CALL_AWAIT_REPLY;
286}
287
288/*
David Howells31143d52007-05-09 02:33:46 -0700289 * attach the data from a bunch of pages on an inode to a call
290 */
Al Viro39c6ace2016-01-09 20:36:51 -0500291static int afs_send_pages(struct afs_call *call, struct msghdr *msg)
David Howells31143d52007-05-09 02:33:46 -0700292{
David Howells2f5705a2017-03-16 16:27:46 +0000293 struct bio_vec bv[AFS_BVEC_MAX];
294 unsigned int bytes, nr, loop, offset;
David Howells31143d52007-05-09 02:33:46 -0700295 pgoff_t first = call->first, last = call->last;
296 int ret;
297
David Howells31143d52007-05-09 02:33:46 -0700298 offset = call->first_offset;
299 call->first_offset = 0;
300
301 do {
David Howells2f5705a2017-03-16 16:27:46 +0000302 afs_load_bvec(call, msg, bv, first, last, offset);
303 offset = 0;
304 bytes = msg->msg_iter.count;
305 nr = msg->msg_iter.nr_segs;
David Howells31143d52007-05-09 02:33:46 -0700306
David Howellsf044c882017-11-02 15:27:45 +0000307 ret = rxrpc_kernel_send_data(call->net->socket, call->rxcall, msg,
David Howellse8332512017-08-29 10:18:56 +0100308 bytes, afs_notify_end_request_tx);
David Howells2f5705a2017-03-16 16:27:46 +0000309 for (loop = 0; loop < nr; loop++)
310 put_page(bv[loop].bv_page);
David Howells31143d52007-05-09 02:33:46 -0700311 if (ret < 0)
312 break;
David Howells2f5705a2017-03-16 16:27:46 +0000313
314 first += nr;
David Howells5bbf5d32007-05-10 03:15:23 -0700315 } while (first <= last);
David Howells31143d52007-05-09 02:33:46 -0700316
David Howells31143d52007-05-09 02:33:46 -0700317 return ret;
318}
319
320/*
David Howells08e0e7c2007-04-26 15:55:03 -0700321 * initiate a call
322 */
David Howells4d9df982017-11-02 15:27:47 +0000323int afs_make_call(struct sockaddr_rxrpc *srx, struct afs_call *call,
324 gfp_t gfp, bool async)
David Howells08e0e7c2007-04-26 15:55:03 -0700325{
David Howells08e0e7c2007-04-26 15:55:03 -0700326 struct rxrpc_call *rxcall;
327 struct msghdr msg;
328 struct kvec iov[1];
David Howells70af0e32017-03-16 16:27:47 +0000329 size_t offset;
David Howellse754eba2017-06-07 12:40:03 +0100330 s64 tx_total_len;
David Howells70af0e32017-03-16 16:27:47 +0000331 u32 abort_code;
David Howells08e0e7c2007-04-26 15:55:03 -0700332 int ret;
333
David Howells4d9df982017-11-02 15:27:47 +0000334 _enter(",{%pISp},", &srx->transport);
David Howells08e0e7c2007-04-26 15:55:03 -0700335
David Howells00d3b7a2007-04-26 15:57:07 -0700336 ASSERT(call->type != NULL);
337 ASSERT(call->type->name != NULL);
338
David Howells31143d52007-05-09 02:33:46 -0700339 _debug("____MAKE %p{%s,%x} [%d]____",
340 call, call->type->name, key_serial(call->key),
David Howellsf044c882017-11-02 15:27:45 +0000341 atomic_read(&call->net->nr_outstanding_calls));
David Howells00d3b7a2007-04-26 15:57:07 -0700342
David Howells56ff9c82017-01-05 10:38:36 +0000343 call->async = async;
David Howells08e0e7c2007-04-26 15:55:03 -0700344
David Howellse754eba2017-06-07 12:40:03 +0100345 /* Work out the length we're going to transmit. This is awkward for
346 * calls such as FS.StoreData where there's an extra injection of data
347 * after the initial fixed part.
348 */
349 tx_total_len = call->request_size;
350 if (call->send_pages) {
351 tx_total_len += call->last_to - call->first_offset;
352 tx_total_len += (call->last - call->first) * PAGE_SIZE;
353 }
354
David Howells08e0e7c2007-04-26 15:55:03 -0700355 /* create a call */
David Howells4d9df982017-11-02 15:27:47 +0000356 rxcall = rxrpc_kernel_begin_call(call->net->socket, srx, call->key,
David Howellse754eba2017-06-07 12:40:03 +0100357 (unsigned long)call,
358 tx_total_len, gfp,
David Howells56ff9c82017-01-05 10:38:36 +0000359 (async ?
360 afs_wake_up_async_call :
David Howellsa68f4a22017-10-18 11:36:39 +0100361 afs_wake_up_call_waiter),
362 call->upgrade);
David Howells00d3b7a2007-04-26 15:57:07 -0700363 call->key = NULL;
David Howells08e0e7c2007-04-26 15:55:03 -0700364 if (IS_ERR(rxcall)) {
365 ret = PTR_ERR(rxcall);
366 goto error_kill_call;
367 }
368
369 call->rxcall = rxcall;
370
371 /* send the request */
372 iov[0].iov_base = call->request;
373 iov[0].iov_len = call->request_size;
374
375 msg.msg_name = NULL;
376 msg.msg_namelen = 0;
Al Viro2e90b1c2014-11-27 21:50:31 -0500377 iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, iov, 1,
Al Viroc0371da2014-11-24 10:42:55 -0500378 call->request_size);
David Howells08e0e7c2007-04-26 15:55:03 -0700379 msg.msg_control = NULL;
380 msg.msg_controllen = 0;
David Howellsbc5e3a52017-10-18 11:07:31 +0100381 msg.msg_flags = MSG_WAITALL | (call->send_pages ? MSG_MORE : 0);
David Howells08e0e7c2007-04-26 15:55:03 -0700382
David Howells70af0e32017-03-16 16:27:47 +0000383 /* We have to change the state *before* sending the last packet as
384 * rxrpc might give us the reply before it returns from sending the
385 * request. Further, if the send fails, we may already have been given
386 * a notification and may have collected it.
387 */
David Howells31143d52007-05-09 02:33:46 -0700388 if (!call->send_pages)
389 call->state = AFS_CALL_AWAIT_REPLY;
David Howellsf044c882017-11-02 15:27:45 +0000390 ret = rxrpc_kernel_send_data(call->net->socket, rxcall,
David Howellse8332512017-08-29 10:18:56 +0100391 &msg, call->request_size,
392 afs_notify_end_request_tx);
David Howells08e0e7c2007-04-26 15:55:03 -0700393 if (ret < 0)
394 goto error_do_abort;
395
David Howells31143d52007-05-09 02:33:46 -0700396 if (call->send_pages) {
Al Viro39c6ace2016-01-09 20:36:51 -0500397 ret = afs_send_pages(call, &msg);
David Howells31143d52007-05-09 02:33:46 -0700398 if (ret < 0)
399 goto error_do_abort;
400 }
401
David Howells08e0e7c2007-04-26 15:55:03 -0700402 /* at this point, an async call may no longer exist as it may have
403 * already completed */
David Howells56ff9c82017-01-05 10:38:36 +0000404 if (call->async)
405 return -EINPROGRESS;
406
407 return afs_wait_for_call_to_complete(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700408
409error_do_abort:
David Howells70af0e32017-03-16 16:27:47 +0000410 call->state = AFS_CALL_COMPLETE;
411 if (ret != -ECONNABORTED) {
David Howellsf044c882017-11-02 15:27:45 +0000412 rxrpc_kernel_abort_call(call->net->socket, rxcall,
413 RX_USER_ABORT, ret, "KSD");
David Howells70af0e32017-03-16 16:27:47 +0000414 } else {
415 abort_code = 0;
416 offset = 0;
David Howellsf044c882017-11-02 15:27:45 +0000417 rxrpc_kernel_recv_data(call->net->socket, rxcall, NULL,
418 0, &offset, false, &abort_code,
419 &call->service_id);
David Howellsf780c8e2017-11-02 15:27:48 +0000420 ret = afs_abort_to_error(abort_code);
David Howells70af0e32017-03-16 16:27:47 +0000421 }
David Howells08e0e7c2007-04-26 15:55:03 -0700422error_kill_call:
David Howells341f7412017-01-05 10:38:36 +0000423 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700424 _leave(" = %d", ret);
425 return ret;
426}
427
428/*
David Howells08e0e7c2007-04-26 15:55:03 -0700429 * deliver messages to a call
430 */
431static void afs_deliver_to_call(struct afs_call *call)
432{
David Howells08e0e7c2007-04-26 15:55:03 -0700433 u32 abort_code;
434 int ret;
435
David Howellsd0016482016-08-30 20:42:14 +0100436 _enter("%s", call->type->name);
David Howells08e0e7c2007-04-26 15:55:03 -0700437
David Howellsd0016482016-08-30 20:42:14 +0100438 while (call->state == AFS_CALL_AWAIT_REPLY ||
439 call->state == AFS_CALL_AWAIT_OP_ID ||
440 call->state == AFS_CALL_AWAIT_REQUEST ||
441 call->state == AFS_CALL_AWAIT_ACK
442 ) {
443 if (call->state == AFS_CALL_AWAIT_ACK) {
444 size_t offset = 0;
David Howellsf044c882017-11-02 15:27:45 +0000445 ret = rxrpc_kernel_recv_data(call->net->socket,
446 call->rxcall,
David Howellsd0016482016-08-30 20:42:14 +0100447 NULL, 0, &offset, false,
David Howellsa68f4a22017-10-18 11:36:39 +0100448 &call->abort_code,
449 &call->service_id);
David Howells8e8d7f12017-01-05 10:38:34 +0000450 trace_afs_recv_data(call, 0, offset, false, ret);
451
David Howellsd0016482016-08-30 20:42:14 +0100452 if (ret == -EINPROGRESS || ret == -EAGAIN)
453 return;
David Howells9008f992016-10-06 08:11:50 +0100454 if (ret == 1 || ret < 0) {
David Howellsd0016482016-08-30 20:42:14 +0100455 call->state = AFS_CALL_COMPLETE;
456 goto done;
David Howells08e0e7c2007-04-26 15:55:03 -0700457 }
David Howellsd0016482016-08-30 20:42:14 +0100458 return;
David Howells08e0e7c2007-04-26 15:55:03 -0700459 }
460
David Howellsd0016482016-08-30 20:42:14 +0100461 ret = call->type->deliver(call);
462 switch (ret) {
463 case 0:
464 if (call->state == AFS_CALL_AWAIT_REPLY)
465 call->state = AFS_CALL_COMPLETE;
466 goto done;
467 case -EINPROGRESS:
468 case -EAGAIN:
469 goto out;
David Howells70af0e32017-03-16 16:27:47 +0000470 case -ECONNABORTED:
471 goto call_complete;
David Howellsd0016482016-08-30 20:42:14 +0100472 case -ENOTCONN:
473 abort_code = RX_CALL_DEAD;
David Howellsf044c882017-11-02 15:27:45 +0000474 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
David Howells3a927892017-04-06 10:11:56 +0100475 abort_code, ret, "KNC");
David Howells70af0e32017-03-16 16:27:47 +0000476 goto save_error;
David Howellsd0016482016-08-30 20:42:14 +0100477 case -ENOTSUPP:
David Howells1157f152017-03-16 16:27:47 +0000478 abort_code = RXGEN_OPCODE;
David Howellsf044c882017-11-02 15:27:45 +0000479 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
David Howells3a927892017-04-06 10:11:56 +0100480 abort_code, ret, "KIV");
David Howells70af0e32017-03-16 16:27:47 +0000481 goto save_error;
David Howellsd0016482016-08-30 20:42:14 +0100482 case -ENODATA:
483 case -EBADMSG:
484 case -EMSGSIZE:
485 default:
486 abort_code = RXGEN_CC_UNMARSHAL;
487 if (call->state != AFS_CALL_AWAIT_REPLY)
488 abort_code = RXGEN_SS_UNMARSHAL;
David Howellsf044c882017-11-02 15:27:45 +0000489 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
David Howells3a927892017-04-06 10:11:56 +0100490 abort_code, -EBADMSG, "KUM");
David Howells70af0e32017-03-16 16:27:47 +0000491 goto save_error;
David Howellsd0016482016-08-30 20:42:14 +0100492 }
David Howells08e0e7c2007-04-26 15:55:03 -0700493 }
494
David Howellsd0016482016-08-30 20:42:14 +0100495done:
496 if (call->state == AFS_CALL_COMPLETE && call->incoming)
David Howells341f7412017-01-05 10:38:36 +0000497 afs_put_call(call);
David Howellsd0016482016-08-30 20:42:14 +0100498out:
David Howells08e0e7c2007-04-26 15:55:03 -0700499 _leave("");
David Howellsd0016482016-08-30 20:42:14 +0100500 return;
501
David Howells70af0e32017-03-16 16:27:47 +0000502save_error:
David Howellsd0016482016-08-30 20:42:14 +0100503 call->error = ret;
David Howells70af0e32017-03-16 16:27:47 +0000504call_complete:
David Howellsd0016482016-08-30 20:42:14 +0100505 call->state = AFS_CALL_COMPLETE;
506 goto done;
David Howells08e0e7c2007-04-26 15:55:03 -0700507}
508
509/*
510 * wait synchronously for a call to complete
511 */
512static int afs_wait_for_call_to_complete(struct afs_call *call)
513{
David Howellsbc5e3a52017-10-18 11:07:31 +0100514 signed long rtt2, timeout;
David Howells08e0e7c2007-04-26 15:55:03 -0700515 int ret;
David Howellsbc5e3a52017-10-18 11:07:31 +0100516 u64 rtt;
517 u32 life, last_life;
David Howells08e0e7c2007-04-26 15:55:03 -0700518
519 DECLARE_WAITQUEUE(myself, current);
520
521 _enter("");
522
David Howellsf044c882017-11-02 15:27:45 +0000523 rtt = rxrpc_kernel_get_rtt(call->net->socket, call->rxcall);
David Howellsbc5e3a52017-10-18 11:07:31 +0100524 rtt2 = nsecs_to_jiffies64(rtt) * 2;
525 if (rtt2 < 2)
526 rtt2 = 2;
527
528 timeout = rtt2;
David Howellsf044c882017-11-02 15:27:45 +0000529 last_life = rxrpc_kernel_check_life(call->net->socket, call->rxcall);
David Howellsbc5e3a52017-10-18 11:07:31 +0100530
David Howells08e0e7c2007-04-26 15:55:03 -0700531 add_wait_queue(&call->waitq, &myself);
532 for (;;) {
David Howellsbc5e3a52017-10-18 11:07:31 +0100533 set_current_state(TASK_UNINTERRUPTIBLE);
David Howells08e0e7c2007-04-26 15:55:03 -0700534
535 /* deliver any messages that are in the queue */
David Howellsd0016482016-08-30 20:42:14 +0100536 if (call->state < AFS_CALL_COMPLETE && call->need_attention) {
537 call->need_attention = false;
David Howells08e0e7c2007-04-26 15:55:03 -0700538 __set_current_state(TASK_RUNNING);
539 afs_deliver_to_call(call);
540 continue;
541 }
542
David Howellsbc5e3a52017-10-18 11:07:31 +0100543 if (call->state == AFS_CALL_COMPLETE)
David Howells08e0e7c2007-04-26 15:55:03 -0700544 break;
David Howellsbc5e3a52017-10-18 11:07:31 +0100545
David Howellsf044c882017-11-02 15:27:45 +0000546 life = rxrpc_kernel_check_life(call->net->socket, call->rxcall);
David Howellsbc5e3a52017-10-18 11:07:31 +0100547 if (timeout == 0 &&
548 life == last_life && signal_pending(current))
549 break;
550
551 if (life != last_life) {
552 timeout = rtt2;
553 last_life = life;
554 }
555
556 timeout = schedule_timeout(timeout);
David Howells08e0e7c2007-04-26 15:55:03 -0700557 }
558
559 remove_wait_queue(&call->waitq, &myself);
560 __set_current_state(TASK_RUNNING);
561
David Howells954cd6d2017-03-16 16:27:49 +0000562 /* Kill off the call if it's still live. */
David Howells08e0e7c2007-04-26 15:55:03 -0700563 if (call->state < AFS_CALL_COMPLETE) {
David Howells954cd6d2017-03-16 16:27:49 +0000564 _debug("call interrupted");
David Howellsf044c882017-11-02 15:27:45 +0000565 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
David Howells954cd6d2017-03-16 16:27:49 +0000566 RX_USER_ABORT, -EINTR, "KWI");
David Howells08e0e7c2007-04-26 15:55:03 -0700567 }
568
David Howells954cd6d2017-03-16 16:27:49 +0000569 ret = call->error;
David Howells08e0e7c2007-04-26 15:55:03 -0700570 _debug("call complete");
David Howells341f7412017-01-05 10:38:36 +0000571 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700572 _leave(" = %d", ret);
573 return ret;
574}
575
576/*
577 * wake up a waiting call
578 */
David Howellsd0016482016-08-30 20:42:14 +0100579static void afs_wake_up_call_waiter(struct sock *sk, struct rxrpc_call *rxcall,
580 unsigned long call_user_ID)
David Howells08e0e7c2007-04-26 15:55:03 -0700581{
David Howellsd0016482016-08-30 20:42:14 +0100582 struct afs_call *call = (struct afs_call *)call_user_ID;
583
584 call->need_attention = true;
David Howells08e0e7c2007-04-26 15:55:03 -0700585 wake_up(&call->waitq);
586}
587
588/*
589 * wake up an asynchronous call
590 */
David Howellsd0016482016-08-30 20:42:14 +0100591static void afs_wake_up_async_call(struct sock *sk, struct rxrpc_call *rxcall,
592 unsigned long call_user_ID)
David Howells08e0e7c2007-04-26 15:55:03 -0700593{
David Howellsd0016482016-08-30 20:42:14 +0100594 struct afs_call *call = (struct afs_call *)call_user_ID;
David Howells341f7412017-01-05 10:38:36 +0000595 int u;
David Howellsd0016482016-08-30 20:42:14 +0100596
David Howells8e8d7f12017-01-05 10:38:34 +0000597 trace_afs_notify_call(rxcall, call);
David Howellsd0016482016-08-30 20:42:14 +0100598 call->need_attention = true;
David Howells341f7412017-01-05 10:38:36 +0000599
600 u = __atomic_add_unless(&call->usage, 1, 0);
601 if (u != 0) {
602 trace_afs_call(call, afs_call_trace_wake, u,
David Howellsf044c882017-11-02 15:27:45 +0000603 atomic_read(&call->net->nr_outstanding_calls),
David Howells341f7412017-01-05 10:38:36 +0000604 __builtin_return_address(0));
605
606 if (!queue_work(afs_async_calls, &call->async_work))
607 afs_put_call(call);
608 }
David Howells08e0e7c2007-04-26 15:55:03 -0700609}
610
611/*
David Howells341f7412017-01-05 10:38:36 +0000612 * Delete an asynchronous call. The work item carries a ref to the call struct
613 * that we need to release.
David Howells08e0e7c2007-04-26 15:55:03 -0700614 */
David Howellsd0016482016-08-30 20:42:14 +0100615static void afs_delete_async_call(struct work_struct *work)
David Howells08e0e7c2007-04-26 15:55:03 -0700616{
David Howellsd0016482016-08-30 20:42:14 +0100617 struct afs_call *call = container_of(work, struct afs_call, async_work);
618
David Howells08e0e7c2007-04-26 15:55:03 -0700619 _enter("");
620
David Howells341f7412017-01-05 10:38:36 +0000621 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700622
623 _leave("");
624}
625
626/*
David Howells341f7412017-01-05 10:38:36 +0000627 * Perform I/O processing on an asynchronous call. The work item carries a ref
628 * to the call struct that we either need to release or to pass on.
David Howells08e0e7c2007-04-26 15:55:03 -0700629 */
David Howellsd0016482016-08-30 20:42:14 +0100630static void afs_process_async_call(struct work_struct *work)
David Howells08e0e7c2007-04-26 15:55:03 -0700631{
David Howellsd0016482016-08-30 20:42:14 +0100632 struct afs_call *call = container_of(work, struct afs_call, async_work);
633
David Howells08e0e7c2007-04-26 15:55:03 -0700634 _enter("");
635
David Howellsd0016482016-08-30 20:42:14 +0100636 if (call->state < AFS_CALL_COMPLETE && call->need_attention) {
637 call->need_attention = false;
David Howells08e0e7c2007-04-26 15:55:03 -0700638 afs_deliver_to_call(call);
David Howellsd0016482016-08-30 20:42:14 +0100639 }
David Howells08e0e7c2007-04-26 15:55:03 -0700640
David Howells56ff9c82017-01-05 10:38:36 +0000641 if (call->state == AFS_CALL_COMPLETE) {
David Howells97e30432017-11-02 15:27:48 +0000642 call->reply[0] = NULL;
David Howells08e0e7c2007-04-26 15:55:03 -0700643
David Howells341f7412017-01-05 10:38:36 +0000644 /* We have two refs to release - one from the alloc and one
645 * queued with the work item - and we can't just deallocate the
646 * call because the work item may be queued again.
647 */
David Howellsd0016482016-08-30 20:42:14 +0100648 call->async_work.func = afs_delete_async_call;
David Howells341f7412017-01-05 10:38:36 +0000649 if (!queue_work(afs_async_calls, &call->async_work))
650 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700651 }
652
David Howells341f7412017-01-05 10:38:36 +0000653 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700654 _leave("");
655}
656
David Howells00e90712016-09-08 11:10:12 +0100657static void afs_rx_attach(struct rxrpc_call *rxcall, unsigned long user_call_ID)
658{
659 struct afs_call *call = (struct afs_call *)user_call_ID;
660
661 call->rxcall = rxcall;
662}
663
664/*
665 * Charge the incoming call preallocation.
666 */
David Howellsf044c882017-11-02 15:27:45 +0000667void afs_charge_preallocation(struct work_struct *work)
David Howells00e90712016-09-08 11:10:12 +0100668{
David Howellsf044c882017-11-02 15:27:45 +0000669 struct afs_net *net =
670 container_of(work, struct afs_net, charge_preallocation_work);
671 struct afs_call *call = net->spare_incoming_call;
David Howells00e90712016-09-08 11:10:12 +0100672
673 for (;;) {
674 if (!call) {
David Howellsf044c882017-11-02 15:27:45 +0000675 call = afs_alloc_call(net, &afs_RXCMxxxx, GFP_KERNEL);
David Howells00e90712016-09-08 11:10:12 +0100676 if (!call)
677 break;
678
David Howells56ff9c82017-01-05 10:38:36 +0000679 call->async = true;
David Howells00e90712016-09-08 11:10:12 +0100680 call->state = AFS_CALL_AWAIT_OP_ID;
David Howells56ff9c82017-01-05 10:38:36 +0000681 init_waitqueue_head(&call->waitq);
David Howells00e90712016-09-08 11:10:12 +0100682 }
683
David Howellsf044c882017-11-02 15:27:45 +0000684 if (rxrpc_kernel_charge_accept(net->socket,
David Howells00e90712016-09-08 11:10:12 +0100685 afs_wake_up_async_call,
686 afs_rx_attach,
687 (unsigned long)call,
688 GFP_KERNEL) < 0)
689 break;
690 call = NULL;
691 }
David Howellsf044c882017-11-02 15:27:45 +0000692 net->spare_incoming_call = call;
David Howells00e90712016-09-08 11:10:12 +0100693}
694
695/*
696 * Discard a preallocated call when a socket is shut down.
697 */
698static void afs_rx_discard_new_call(struct rxrpc_call *rxcall,
699 unsigned long user_call_ID)
700{
701 struct afs_call *call = (struct afs_call *)user_call_ID;
702
David Howells00e90712016-09-08 11:10:12 +0100703 call->rxcall = NULL;
David Howells341f7412017-01-05 10:38:36 +0000704 afs_put_call(call);
David Howells00e90712016-09-08 11:10:12 +0100705}
706
David Howells08e0e7c2007-04-26 15:55:03 -0700707/*
David Howellsd0016482016-08-30 20:42:14 +0100708 * Notification of an incoming call.
709 */
David Howells00e90712016-09-08 11:10:12 +0100710static void afs_rx_new_call(struct sock *sk, struct rxrpc_call *rxcall,
711 unsigned long user_call_ID)
David Howellsd0016482016-08-30 20:42:14 +0100712{
David Howellsf044c882017-11-02 15:27:45 +0000713 struct afs_net *net = afs_sock2net(sk);
714
715 queue_work(afs_wq, &net->charge_preallocation_work);
David Howellsd0016482016-08-30 20:42:14 +0100716}
717
718/*
David Howells372ee162016-08-03 14:11:40 +0100719 * Grab the operation ID from an incoming cache manager call. The socket
720 * buffer is discarded on error or if we don't yet have sufficient data.
David Howells08e0e7c2007-04-26 15:55:03 -0700721 */
David Howellsd0016482016-08-30 20:42:14 +0100722static int afs_deliver_cm_op_id(struct afs_call *call)
David Howells08e0e7c2007-04-26 15:55:03 -0700723{
David Howellsd0016482016-08-30 20:42:14 +0100724 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700725
David Howellsd0016482016-08-30 20:42:14 +0100726 _enter("{%zu}", call->offset);
David Howells08e0e7c2007-04-26 15:55:03 -0700727
728 ASSERTCMP(call->offset, <, 4);
729
730 /* the operation ID forms the first four bytes of the request data */
David Howells50a2c952016-10-13 08:27:10 +0100731 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howellsd0016482016-08-30 20:42:14 +0100732 if (ret < 0)
733 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700734
David Howells50a2c952016-10-13 08:27:10 +0100735 call->operation_ID = ntohl(call->tmp);
David Howells08e0e7c2007-04-26 15:55:03 -0700736 call->state = AFS_CALL_AWAIT_REQUEST;
David Howellsd0016482016-08-30 20:42:14 +0100737 call->offset = 0;
David Howells08e0e7c2007-04-26 15:55:03 -0700738
739 /* ask the cache manager to route the call (it'll change the call type
740 * if successful) */
741 if (!afs_cm_incoming_call(call))
742 return -ENOTSUPP;
743
David Howells8e8d7f12017-01-05 10:38:34 +0000744 trace_afs_cb_call(call);
745
David Howells08e0e7c2007-04-26 15:55:03 -0700746 /* pass responsibility for the remainer of this message off to the
747 * cache manager op */
David Howellsd0016482016-08-30 20:42:14 +0100748 return call->type->deliver(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700749}
750
751/*
David Howellse8332512017-08-29 10:18:56 +0100752 * Advance the AFS call state when an RxRPC service call ends the transmit
753 * phase.
754 */
755static void afs_notify_end_reply_tx(struct sock *sock,
756 struct rxrpc_call *rxcall,
757 unsigned long call_user_ID)
758{
759 struct afs_call *call = (struct afs_call *)call_user_ID;
760
761 if (call->state == AFS_CALL_REPLYING)
762 call->state = AFS_CALL_AWAIT_ACK;
763}
764
765/*
David Howells08e0e7c2007-04-26 15:55:03 -0700766 * send an empty reply
767 */
768void afs_send_empty_reply(struct afs_call *call)
769{
David Howellsf044c882017-11-02 15:27:45 +0000770 struct afs_net *net = call->net;
David Howells08e0e7c2007-04-26 15:55:03 -0700771 struct msghdr msg;
David Howells08e0e7c2007-04-26 15:55:03 -0700772
773 _enter("");
774
David Howellsf044c882017-11-02 15:27:45 +0000775 rxrpc_kernel_set_tx_length(net->socket, call->rxcall, 0);
David Howellse754eba2017-06-07 12:40:03 +0100776
David Howells08e0e7c2007-04-26 15:55:03 -0700777 msg.msg_name = NULL;
778 msg.msg_namelen = 0;
David Howellsbfd4e952015-04-01 16:03:46 +0100779 iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, NULL, 0, 0);
David Howells08e0e7c2007-04-26 15:55:03 -0700780 msg.msg_control = NULL;
781 msg.msg_controllen = 0;
782 msg.msg_flags = 0;
783
784 call->state = AFS_CALL_AWAIT_ACK;
David Howellsf044c882017-11-02 15:27:45 +0000785 switch (rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, 0,
David Howellse8332512017-08-29 10:18:56 +0100786 afs_notify_end_reply_tx)) {
David Howells08e0e7c2007-04-26 15:55:03 -0700787 case 0:
788 _leave(" [replied]");
789 return;
790
791 case -ENOMEM:
792 _debug("oom");
David Howellsf044c882017-11-02 15:27:45 +0000793 rxrpc_kernel_abort_call(net->socket, call->rxcall,
David Howells3a927892017-04-06 10:11:56 +0100794 RX_USER_ABORT, -ENOMEM, "KOO");
David Howells08e0e7c2007-04-26 15:55:03 -0700795 default:
David Howells08e0e7c2007-04-26 15:55:03 -0700796 _leave(" [error]");
797 return;
798 }
799}
800
801/*
David Howellsb908fe62007-04-26 15:58:17 -0700802 * send a simple reply
803 */
804void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len)
805{
David Howellsf044c882017-11-02 15:27:45 +0000806 struct afs_net *net = call->net;
David Howellsb908fe62007-04-26 15:58:17 -0700807 struct msghdr msg;
Al Viro2e90b1c2014-11-27 21:50:31 -0500808 struct kvec iov[1];
David Howellsbd6dc742007-07-20 10:59:41 +0100809 int n;
David Howellsb908fe62007-04-26 15:58:17 -0700810
811 _enter("");
812
David Howellsf044c882017-11-02 15:27:45 +0000813 rxrpc_kernel_set_tx_length(net->socket, call->rxcall, len);
David Howellse754eba2017-06-07 12:40:03 +0100814
David Howellsb908fe62007-04-26 15:58:17 -0700815 iov[0].iov_base = (void *) buf;
816 iov[0].iov_len = len;
817 msg.msg_name = NULL;
818 msg.msg_namelen = 0;
Al Viro2e90b1c2014-11-27 21:50:31 -0500819 iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, iov, 1, len);
David Howellsb908fe62007-04-26 15:58:17 -0700820 msg.msg_control = NULL;
821 msg.msg_controllen = 0;
822 msg.msg_flags = 0;
823
824 call->state = AFS_CALL_AWAIT_ACK;
David Howellsf044c882017-11-02 15:27:45 +0000825 n = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, len,
David Howellse8332512017-08-29 10:18:56 +0100826 afs_notify_end_reply_tx);
David Howellsbd6dc742007-07-20 10:59:41 +0100827 if (n >= 0) {
David Howells6c67c7c2014-05-21 14:48:05 +0100828 /* Success */
David Howellsb908fe62007-04-26 15:58:17 -0700829 _leave(" [replied]");
830 return;
David Howellsbd6dc742007-07-20 10:59:41 +0100831 }
David Howells6c67c7c2014-05-21 14:48:05 +0100832
David Howellsbd6dc742007-07-20 10:59:41 +0100833 if (n == -ENOMEM) {
David Howellsb908fe62007-04-26 15:58:17 -0700834 _debug("oom");
David Howellsf044c882017-11-02 15:27:45 +0000835 rxrpc_kernel_abort_call(net->socket, call->rxcall,
David Howells3a927892017-04-06 10:11:56 +0100836 RX_USER_ABORT, -ENOMEM, "KOO");
David Howellsb908fe62007-04-26 15:58:17 -0700837 }
David Howellsbd6dc742007-07-20 10:59:41 +0100838 _leave(" [error]");
David Howellsb908fe62007-04-26 15:58:17 -0700839}
840
841/*
David Howells372ee162016-08-03 14:11:40 +0100842 * Extract a piece of data from the received data socket buffers.
David Howells08e0e7c2007-04-26 15:55:03 -0700843 */
David Howellsd0016482016-08-30 20:42:14 +0100844int afs_extract_data(struct afs_call *call, void *buf, size_t count,
845 bool want_more)
David Howells08e0e7c2007-04-26 15:55:03 -0700846{
David Howellsf044c882017-11-02 15:27:45 +0000847 struct afs_net *net = call->net;
David Howellsd0016482016-08-30 20:42:14 +0100848 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700849
David Howellsd0016482016-08-30 20:42:14 +0100850 _enter("{%s,%zu},,%zu,%d",
851 call->type->name, call->offset, count, want_more);
David Howells08e0e7c2007-04-26 15:55:03 -0700852
David Howellsd0016482016-08-30 20:42:14 +0100853 ASSERTCMP(call->offset, <=, count);
David Howells08e0e7c2007-04-26 15:55:03 -0700854
David Howellsf044c882017-11-02 15:27:45 +0000855 ret = rxrpc_kernel_recv_data(net->socket, call->rxcall,
David Howellsd0016482016-08-30 20:42:14 +0100856 buf, count, &call->offset,
David Howellsa68f4a22017-10-18 11:36:39 +0100857 want_more, &call->abort_code,
858 &call->service_id);
David Howells8e8d7f12017-01-05 10:38:34 +0000859 trace_afs_recv_data(call, count, call->offset, want_more, ret);
David Howellsd0016482016-08-30 20:42:14 +0100860 if (ret == 0 || ret == -EAGAIN)
861 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700862
David Howellsd0016482016-08-30 20:42:14 +0100863 if (ret == 1) {
864 switch (call->state) {
865 case AFS_CALL_AWAIT_REPLY:
866 call->state = AFS_CALL_COMPLETE;
867 break;
868 case AFS_CALL_AWAIT_REQUEST:
869 call->state = AFS_CALL_REPLYING;
870 break;
871 default:
872 break;
873 }
874 return 0;
David Howells08e0e7c2007-04-26 15:55:03 -0700875 }
David Howellsd0016482016-08-30 20:42:14 +0100876
877 if (ret == -ECONNABORTED)
David Howellsf780c8e2017-11-02 15:27:48 +0000878 call->error = afs_abort_to_error(call->abort_code);
David Howellsd0016482016-08-30 20:42:14 +0100879 else
880 call->error = ret;
881 call->state = AFS_CALL_COMPLETE;
882 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700883}