blob: 656ceb285b85106cbc84aa683a7afd4c75ed1ad2 [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,
34 .abort_to_error = afs_abort_to_error,
35};
36
David Howells08e0e7c2007-04-26 15:55:03 -070037/*
38 * open an RxRPC socket and bind it to be a server for callback notifications
39 * - the socket is left in blocking mode and non-blocking ops use MSG_DONTWAIT
40 */
David Howellsf044c882017-11-02 15:27:45 +000041int afs_open_socket(struct afs_net *net)
David Howells08e0e7c2007-04-26 15:55:03 -070042{
43 struct sockaddr_rxrpc srx;
44 struct socket *socket;
45 int ret;
46
47 _enter("");
48
Eric W. Biedermaneeb1bd52015-05-08 21:08:05 -050049 ret = sock_create_kern(&init_net, AF_RXRPC, SOCK_DGRAM, PF_INET, &socket);
David Howells0e119b42016-06-10 22:30:37 +010050 if (ret < 0)
51 goto error_1;
David Howells08e0e7c2007-04-26 15:55:03 -070052
53 socket->sk->sk_allocation = GFP_NOFS;
54
55 /* bind the callback manager's address to make this a server socket */
56 srx.srx_family = AF_RXRPC;
57 srx.srx_service = CM_SERVICE;
58 srx.transport_type = SOCK_DGRAM;
59 srx.transport_len = sizeof(srx.transport.sin);
60 srx.transport.sin.sin_family = AF_INET;
61 srx.transport.sin.sin_port = htons(AFS_CM_PORT);
62 memset(&srx.transport.sin.sin_addr, 0,
63 sizeof(srx.transport.sin.sin_addr));
64
65 ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx));
David Howells0e119b42016-06-10 22:30:37 +010066 if (ret < 0)
67 goto error_2;
68
David Howells00e90712016-09-08 11:10:12 +010069 rxrpc_kernel_new_call_notification(socket, afs_rx_new_call,
70 afs_rx_discard_new_call);
David Howellsd0016482016-08-30 20:42:14 +010071
David Howells0e119b42016-06-10 22:30:37 +010072 ret = kernel_listen(socket, INT_MAX);
73 if (ret < 0)
74 goto error_2;
David Howells08e0e7c2007-04-26 15:55:03 -070075
David Howellsf044c882017-11-02 15:27:45 +000076 net->socket = socket;
77 afs_charge_preallocation(&net->charge_preallocation_work);
David Howells08e0e7c2007-04-26 15:55:03 -070078 _leave(" = 0");
79 return 0;
David Howells0e119b42016-06-10 22:30:37 +010080
81error_2:
82 sock_release(socket);
83error_1:
David Howells0e119b42016-06-10 22:30:37 +010084 _leave(" = %d", ret);
85 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -070086}
87
88/*
89 * close the RxRPC socket AFS was using
90 */
David Howellsf044c882017-11-02 15:27:45 +000091void afs_close_socket(struct afs_net *net)
David Howells08e0e7c2007-04-26 15:55:03 -070092{
93 _enter("");
94
David Howellsf044c882017-11-02 15:27:45 +000095 kernel_listen(net->socket, 0);
David Howells341f7412017-01-05 10:38:36 +000096 flush_workqueue(afs_async_calls);
97
David Howellsf044c882017-11-02 15:27:45 +000098 if (net->spare_incoming_call) {
99 afs_put_call(net->spare_incoming_call);
100 net->spare_incoming_call = NULL;
David Howells00e90712016-09-08 11:10:12 +0100101 }
102
David Howellsf044c882017-11-02 15:27:45 +0000103 _debug("outstanding %u", atomic_read(&net->nr_outstanding_calls));
104 wait_on_atomic_t(&net->nr_outstanding_calls, atomic_t_wait,
David Howells2f02f7a2016-04-07 17:23:03 +0100105 TASK_UNINTERRUPTIBLE);
106 _debug("no outstanding calls");
107
David Howellsf044c882017-11-02 15:27:45 +0000108 kernel_sock_shutdown(net->socket, SHUT_RDWR);
David Howells248f2192016-09-08 11:10:12 +0100109 flush_workqueue(afs_async_calls);
David Howellsf044c882017-11-02 15:27:45 +0000110 sock_release(net->socket);
David Howells08e0e7c2007-04-26 15:55:03 -0700111
112 _debug("dework");
David Howells08e0e7c2007-04-26 15:55:03 -0700113 _leave("");
114}
115
116/*
David Howells341f7412017-01-05 10:38:36 +0000117 * Allocate a call.
David Howells00d3b7a2007-04-26 15:57:07 -0700118 */
David Howellsf044c882017-11-02 15:27:45 +0000119static struct afs_call *afs_alloc_call(struct afs_net *net,
120 const struct afs_call_type *type,
David Howells341f7412017-01-05 10:38:36 +0000121 gfp_t gfp)
David Howells00d3b7a2007-04-26 15:57:07 -0700122{
David Howells341f7412017-01-05 10:38:36 +0000123 struct afs_call *call;
124 int o;
David Howells00d3b7a2007-04-26 15:57:07 -0700125
David Howells341f7412017-01-05 10:38:36 +0000126 call = kzalloc(sizeof(*call), gfp);
127 if (!call)
128 return NULL;
David Howells00d3b7a2007-04-26 15:57:07 -0700129
David Howells341f7412017-01-05 10:38:36 +0000130 call->type = type;
David Howellsf044c882017-11-02 15:27:45 +0000131 call->net = net;
David Howells341f7412017-01-05 10:38:36 +0000132 atomic_set(&call->usage, 1);
133 INIT_WORK(&call->async_work, afs_process_async_call);
134 init_waitqueue_head(&call->waitq);
David Howells2f02f7a2016-04-07 17:23:03 +0100135
David Howellsf044c882017-11-02 15:27:45 +0000136 o = atomic_inc_return(&net->nr_outstanding_calls);
David Howells341f7412017-01-05 10:38:36 +0000137 trace_afs_call(call, afs_call_trace_alloc, 1, o,
138 __builtin_return_address(0));
139 return call;
David Howells00d3b7a2007-04-26 15:57:07 -0700140}
141
142/*
David Howells341f7412017-01-05 10:38:36 +0000143 * Dispose of a reference on a call.
David Howells6c67c7c2014-05-21 14:48:05 +0100144 */
David Howells341f7412017-01-05 10:38:36 +0000145void afs_put_call(struct afs_call *call)
David Howells6c67c7c2014-05-21 14:48:05 +0100146{
David Howellsf044c882017-11-02 15:27:45 +0000147 struct afs_net *net = call->net;
David Howells341f7412017-01-05 10:38:36 +0000148 int n = atomic_dec_return(&call->usage);
David Howellsf044c882017-11-02 15:27:45 +0000149 int o = atomic_read(&net->nr_outstanding_calls);
David Howells341f7412017-01-05 10:38:36 +0000150
151 trace_afs_call(call, afs_call_trace_put, n + 1, o,
152 __builtin_return_address(0));
153
154 ASSERTCMP(n, >=, 0);
155 if (n == 0) {
156 ASSERT(!work_pending(&call->async_work));
157 ASSERT(call->type->name != NULL);
158
159 if (call->rxcall) {
David Howellsf044c882017-11-02 15:27:45 +0000160 rxrpc_kernel_end_call(net->socket, call->rxcall);
David Howells341f7412017-01-05 10:38:36 +0000161 call->rxcall = NULL;
162 }
163 if (call->type->destructor)
164 call->type->destructor(call);
165
166 kfree(call->request);
167 kfree(call);
168
David Howellsf044c882017-11-02 15:27:45 +0000169 o = atomic_dec_return(&net->nr_outstanding_calls);
David Howells341f7412017-01-05 10:38:36 +0000170 trace_afs_call(call, afs_call_trace_free, 0, o,
171 __builtin_return_address(0));
172 if (o == 0)
David Howellsf044c882017-11-02 15:27:45 +0000173 wake_up_atomic_t(&net->nr_outstanding_calls);
David Howells6c67c7c2014-05-21 14:48:05 +0100174 }
Nathaniel Wesley Filardo6cf12862014-05-21 16:04:11 +0100175}
176
177/*
David Howells341f7412017-01-05 10:38:36 +0000178 * Queue the call for actual work. Returns 0 unconditionally for convenience.
Nathaniel Wesley Filardo6cf12862014-05-21 16:04:11 +0100179 */
David Howells341f7412017-01-05 10:38:36 +0000180int afs_queue_call_work(struct afs_call *call)
Nathaniel Wesley Filardo6cf12862014-05-21 16:04:11 +0100181{
David Howells341f7412017-01-05 10:38:36 +0000182 int u = atomic_inc_return(&call->usage);
183
184 trace_afs_call(call, afs_call_trace_work, u,
David Howellsf044c882017-11-02 15:27:45 +0000185 atomic_read(&call->net->nr_outstanding_calls),
David Howells341f7412017-01-05 10:38:36 +0000186 __builtin_return_address(0));
187
188 INIT_WORK(&call->work, call->type->work);
189
190 if (!queue_work(afs_wq, &call->work))
191 afs_put_call(call);
192 return 0;
David Howells6c67c7c2014-05-21 14:48:05 +0100193}
194
195/*
David Howells08e0e7c2007-04-26 15:55:03 -0700196 * allocate a call with flat request and reply buffers
197 */
David Howellsf044c882017-11-02 15:27:45 +0000198struct afs_call *afs_alloc_flat_call(struct afs_net *net,
199 const struct afs_call_type *type,
David Howellsd0016482016-08-30 20:42:14 +0100200 size_t request_size, size_t reply_max)
David Howells08e0e7c2007-04-26 15:55:03 -0700201{
202 struct afs_call *call;
203
David Howellsf044c882017-11-02 15:27:45 +0000204 call = afs_alloc_call(net, type, GFP_NOFS);
David Howells08e0e7c2007-04-26 15:55:03 -0700205 if (!call)
206 goto nomem_call;
207
David Howells00d3b7a2007-04-26 15:57:07 -0700208 if (request_size) {
David Howells341f7412017-01-05 10:38:36 +0000209 call->request_size = request_size;
David Howells00d3b7a2007-04-26 15:57:07 -0700210 call->request = kmalloc(request_size, GFP_NOFS);
211 if (!call->request)
212 goto nomem_free;
213 }
214
David Howellsd0016482016-08-30 20:42:14 +0100215 if (reply_max) {
David Howells341f7412017-01-05 10:38:36 +0000216 call->reply_max = reply_max;
David Howellsd0016482016-08-30 20:42:14 +0100217 call->buffer = kmalloc(reply_max, GFP_NOFS);
David Howells00d3b7a2007-04-26 15:57:07 -0700218 if (!call->buffer)
219 goto nomem_free;
220 }
221
David Howells08e0e7c2007-04-26 15:55:03 -0700222 init_waitqueue_head(&call->waitq);
David Howells08e0e7c2007-04-26 15:55:03 -0700223 return call;
224
David Howells00d3b7a2007-04-26 15:57:07 -0700225nomem_free:
David Howells341f7412017-01-05 10:38:36 +0000226 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700227nomem_call:
228 return NULL;
229}
230
231/*
232 * clean up a call with flat buffer
233 */
234void afs_flat_call_destructor(struct afs_call *call)
235{
236 _enter("");
237
238 kfree(call->request);
239 call->request = NULL;
240 kfree(call->buffer);
241 call->buffer = NULL;
242}
243
David Howells2f5705a2017-03-16 16:27:46 +0000244#define AFS_BVEC_MAX 8
245
246/*
247 * Load the given bvec with the next few pages.
248 */
249static void afs_load_bvec(struct afs_call *call, struct msghdr *msg,
250 struct bio_vec *bv, pgoff_t first, pgoff_t last,
251 unsigned offset)
252{
253 struct page *pages[AFS_BVEC_MAX];
254 unsigned int nr, n, i, to, bytes = 0;
255
256 nr = min_t(pgoff_t, last - first + 1, AFS_BVEC_MAX);
257 n = find_get_pages_contig(call->mapping, first, nr, pages);
258 ASSERTCMP(n, ==, nr);
259
260 msg->msg_flags |= MSG_MORE;
261 for (i = 0; i < nr; i++) {
262 to = PAGE_SIZE;
263 if (first + i >= last) {
264 to = call->last_to;
265 msg->msg_flags &= ~MSG_MORE;
266 }
267 bv[i].bv_page = pages[i];
268 bv[i].bv_len = to - offset;
269 bv[i].bv_offset = offset;
270 bytes += to - offset;
271 offset = 0;
272 }
273
274 iov_iter_bvec(&msg->msg_iter, WRITE | ITER_BVEC, bv, nr, bytes);
275}
276
David Howells08e0e7c2007-04-26 15:55:03 -0700277/*
David Howellse8332512017-08-29 10:18:56 +0100278 * Advance the AFS call state when the RxRPC call ends the transmit phase.
279 */
280static void afs_notify_end_request_tx(struct sock *sock,
281 struct rxrpc_call *rxcall,
282 unsigned long call_user_ID)
283{
284 struct afs_call *call = (struct afs_call *)call_user_ID;
285
286 if (call->state == AFS_CALL_REQUESTING)
287 call->state = AFS_CALL_AWAIT_REPLY;
288}
289
290/*
David Howells31143d52007-05-09 02:33:46 -0700291 * attach the data from a bunch of pages on an inode to a call
292 */
Al Viro39c6ace2016-01-09 20:36:51 -0500293static int afs_send_pages(struct afs_call *call, struct msghdr *msg)
David Howells31143d52007-05-09 02:33:46 -0700294{
David Howells2f5705a2017-03-16 16:27:46 +0000295 struct bio_vec bv[AFS_BVEC_MAX];
296 unsigned int bytes, nr, loop, offset;
David Howells31143d52007-05-09 02:33:46 -0700297 pgoff_t first = call->first, last = call->last;
298 int ret;
299
David Howells31143d52007-05-09 02:33:46 -0700300 offset = call->first_offset;
301 call->first_offset = 0;
302
303 do {
David Howells2f5705a2017-03-16 16:27:46 +0000304 afs_load_bvec(call, msg, bv, first, last, offset);
305 offset = 0;
306 bytes = msg->msg_iter.count;
307 nr = msg->msg_iter.nr_segs;
David Howells31143d52007-05-09 02:33:46 -0700308
David Howellsf044c882017-11-02 15:27:45 +0000309 ret = rxrpc_kernel_send_data(call->net->socket, call->rxcall, msg,
David Howellse8332512017-08-29 10:18:56 +0100310 bytes, afs_notify_end_request_tx);
David Howells2f5705a2017-03-16 16:27:46 +0000311 for (loop = 0; loop < nr; loop++)
312 put_page(bv[loop].bv_page);
David Howells31143d52007-05-09 02:33:46 -0700313 if (ret < 0)
314 break;
David Howells2f5705a2017-03-16 16:27:46 +0000315
316 first += nr;
David Howells5bbf5d32007-05-10 03:15:23 -0700317 } while (first <= last);
David Howells31143d52007-05-09 02:33:46 -0700318
David Howells31143d52007-05-09 02:33:46 -0700319 return ret;
320}
321
322/*
David Howells08e0e7c2007-04-26 15:55:03 -0700323 * initiate a call
324 */
325int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp,
David Howells56ff9c82017-01-05 10:38:36 +0000326 bool async)
David Howells08e0e7c2007-04-26 15:55:03 -0700327{
328 struct sockaddr_rxrpc srx;
329 struct rxrpc_call *rxcall;
330 struct msghdr msg;
331 struct kvec iov[1];
David Howells70af0e32017-03-16 16:27:47 +0000332 size_t offset;
David Howellse754eba2017-06-07 12:40:03 +0100333 s64 tx_total_len;
David Howells70af0e32017-03-16 16:27:47 +0000334 u32 abort_code;
David Howells08e0e7c2007-04-26 15:55:03 -0700335 int ret;
336
337 _enter("%x,{%d},", addr->s_addr, ntohs(call->port));
338
David Howells00d3b7a2007-04-26 15:57:07 -0700339 ASSERT(call->type != NULL);
340 ASSERT(call->type->name != NULL);
341
David Howells31143d52007-05-09 02:33:46 -0700342 _debug("____MAKE %p{%s,%x} [%d]____",
343 call, call->type->name, key_serial(call->key),
David Howellsf044c882017-11-02 15:27:45 +0000344 atomic_read(&call->net->nr_outstanding_calls));
David Howells00d3b7a2007-04-26 15:57:07 -0700345
David Howells56ff9c82017-01-05 10:38:36 +0000346 call->async = async;
David Howells08e0e7c2007-04-26 15:55:03 -0700347
348 memset(&srx, 0, sizeof(srx));
349 srx.srx_family = AF_RXRPC;
350 srx.srx_service = call->service_id;
351 srx.transport_type = SOCK_DGRAM;
352 srx.transport_len = sizeof(srx.transport.sin);
353 srx.transport.sin.sin_family = AF_INET;
354 srx.transport.sin.sin_port = call->port;
355 memcpy(&srx.transport.sin.sin_addr, addr, 4);
356
David Howellse754eba2017-06-07 12:40:03 +0100357 /* Work out the length we're going to transmit. This is awkward for
358 * calls such as FS.StoreData where there's an extra injection of data
359 * after the initial fixed part.
360 */
361 tx_total_len = call->request_size;
362 if (call->send_pages) {
363 tx_total_len += call->last_to - call->first_offset;
364 tx_total_len += (call->last - call->first) * PAGE_SIZE;
365 }
366
David Howells08e0e7c2007-04-26 15:55:03 -0700367 /* create a call */
David Howellsf044c882017-11-02 15:27:45 +0000368 rxcall = rxrpc_kernel_begin_call(call->net->socket, &srx, call->key,
David Howellse754eba2017-06-07 12:40:03 +0100369 (unsigned long)call,
370 tx_total_len, gfp,
David Howells56ff9c82017-01-05 10:38:36 +0000371 (async ?
372 afs_wake_up_async_call :
David Howellsa68f4a22017-10-18 11:36:39 +0100373 afs_wake_up_call_waiter),
374 call->upgrade);
David Howells00d3b7a2007-04-26 15:57:07 -0700375 call->key = NULL;
David Howells08e0e7c2007-04-26 15:55:03 -0700376 if (IS_ERR(rxcall)) {
377 ret = PTR_ERR(rxcall);
378 goto error_kill_call;
379 }
380
381 call->rxcall = rxcall;
382
383 /* send the request */
384 iov[0].iov_base = call->request;
385 iov[0].iov_len = call->request_size;
386
387 msg.msg_name = NULL;
388 msg.msg_namelen = 0;
Al Viro2e90b1c2014-11-27 21:50:31 -0500389 iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, iov, 1,
Al Viroc0371da2014-11-24 10:42:55 -0500390 call->request_size);
David Howells08e0e7c2007-04-26 15:55:03 -0700391 msg.msg_control = NULL;
392 msg.msg_controllen = 0;
David Howellsbc5e3a52017-10-18 11:07:31 +0100393 msg.msg_flags = MSG_WAITALL | (call->send_pages ? MSG_MORE : 0);
David Howells08e0e7c2007-04-26 15:55:03 -0700394
David Howells70af0e32017-03-16 16:27:47 +0000395 /* We have to change the state *before* sending the last packet as
396 * rxrpc might give us the reply before it returns from sending the
397 * request. Further, if the send fails, we may already have been given
398 * a notification and may have collected it.
399 */
David Howells31143d52007-05-09 02:33:46 -0700400 if (!call->send_pages)
401 call->state = AFS_CALL_AWAIT_REPLY;
David Howellsf044c882017-11-02 15:27:45 +0000402 ret = rxrpc_kernel_send_data(call->net->socket, rxcall,
David Howellse8332512017-08-29 10:18:56 +0100403 &msg, call->request_size,
404 afs_notify_end_request_tx);
David Howells08e0e7c2007-04-26 15:55:03 -0700405 if (ret < 0)
406 goto error_do_abort;
407
David Howells31143d52007-05-09 02:33:46 -0700408 if (call->send_pages) {
Al Viro39c6ace2016-01-09 20:36:51 -0500409 ret = afs_send_pages(call, &msg);
David Howells31143d52007-05-09 02:33:46 -0700410 if (ret < 0)
411 goto error_do_abort;
412 }
413
David Howells08e0e7c2007-04-26 15:55:03 -0700414 /* at this point, an async call may no longer exist as it may have
415 * already completed */
David Howells56ff9c82017-01-05 10:38:36 +0000416 if (call->async)
417 return -EINPROGRESS;
418
419 return afs_wait_for_call_to_complete(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700420
421error_do_abort:
David Howells70af0e32017-03-16 16:27:47 +0000422 call->state = AFS_CALL_COMPLETE;
423 if (ret != -ECONNABORTED) {
David Howellsf044c882017-11-02 15:27:45 +0000424 rxrpc_kernel_abort_call(call->net->socket, rxcall,
425 RX_USER_ABORT, ret, "KSD");
David Howells70af0e32017-03-16 16:27:47 +0000426 } else {
427 abort_code = 0;
428 offset = 0;
David Howellsf044c882017-11-02 15:27:45 +0000429 rxrpc_kernel_recv_data(call->net->socket, rxcall, NULL,
430 0, &offset, false, &abort_code,
431 &call->service_id);
David Howells70af0e32017-03-16 16:27:47 +0000432 ret = call->type->abort_to_error(abort_code);
433 }
David Howells08e0e7c2007-04-26 15:55:03 -0700434error_kill_call:
David Howells341f7412017-01-05 10:38:36 +0000435 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700436 _leave(" = %d", ret);
437 return ret;
438}
439
440/*
David Howells08e0e7c2007-04-26 15:55:03 -0700441 * deliver messages to a call
442 */
443static void afs_deliver_to_call(struct afs_call *call)
444{
David Howells08e0e7c2007-04-26 15:55:03 -0700445 u32 abort_code;
446 int ret;
447
David Howellsd0016482016-08-30 20:42:14 +0100448 _enter("%s", call->type->name);
David Howells08e0e7c2007-04-26 15:55:03 -0700449
David Howellsd0016482016-08-30 20:42:14 +0100450 while (call->state == AFS_CALL_AWAIT_REPLY ||
451 call->state == AFS_CALL_AWAIT_OP_ID ||
452 call->state == AFS_CALL_AWAIT_REQUEST ||
453 call->state == AFS_CALL_AWAIT_ACK
454 ) {
455 if (call->state == AFS_CALL_AWAIT_ACK) {
456 size_t offset = 0;
David Howellsf044c882017-11-02 15:27:45 +0000457 ret = rxrpc_kernel_recv_data(call->net->socket,
458 call->rxcall,
David Howellsd0016482016-08-30 20:42:14 +0100459 NULL, 0, &offset, false,
David Howellsa68f4a22017-10-18 11:36:39 +0100460 &call->abort_code,
461 &call->service_id);
David Howells8e8d7f12017-01-05 10:38:34 +0000462 trace_afs_recv_data(call, 0, offset, false, ret);
463
David Howellsd0016482016-08-30 20:42:14 +0100464 if (ret == -EINPROGRESS || ret == -EAGAIN)
465 return;
David Howells9008f992016-10-06 08:11:50 +0100466 if (ret == 1 || ret < 0) {
David Howellsd0016482016-08-30 20:42:14 +0100467 call->state = AFS_CALL_COMPLETE;
468 goto done;
David Howells08e0e7c2007-04-26 15:55:03 -0700469 }
David Howellsd0016482016-08-30 20:42:14 +0100470 return;
David Howells08e0e7c2007-04-26 15:55:03 -0700471 }
472
David Howellsd0016482016-08-30 20:42:14 +0100473 ret = call->type->deliver(call);
474 switch (ret) {
475 case 0:
476 if (call->state == AFS_CALL_AWAIT_REPLY)
477 call->state = AFS_CALL_COMPLETE;
478 goto done;
479 case -EINPROGRESS:
480 case -EAGAIN:
481 goto out;
David Howells70af0e32017-03-16 16:27:47 +0000482 case -ECONNABORTED:
483 goto call_complete;
David Howellsd0016482016-08-30 20:42:14 +0100484 case -ENOTCONN:
485 abort_code = RX_CALL_DEAD;
David Howellsf044c882017-11-02 15:27:45 +0000486 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
David Howells3a927892017-04-06 10:11:56 +0100487 abort_code, ret, "KNC");
David Howells70af0e32017-03-16 16:27:47 +0000488 goto save_error;
David Howellsd0016482016-08-30 20:42:14 +0100489 case -ENOTSUPP:
David Howells1157f152017-03-16 16:27:47 +0000490 abort_code = RXGEN_OPCODE;
David Howellsf044c882017-11-02 15:27:45 +0000491 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
David Howells3a927892017-04-06 10:11:56 +0100492 abort_code, ret, "KIV");
David Howells70af0e32017-03-16 16:27:47 +0000493 goto save_error;
David Howellsd0016482016-08-30 20:42:14 +0100494 case -ENODATA:
495 case -EBADMSG:
496 case -EMSGSIZE:
497 default:
498 abort_code = RXGEN_CC_UNMARSHAL;
499 if (call->state != AFS_CALL_AWAIT_REPLY)
500 abort_code = RXGEN_SS_UNMARSHAL;
David Howellsf044c882017-11-02 15:27:45 +0000501 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
David Howells3a927892017-04-06 10:11:56 +0100502 abort_code, -EBADMSG, "KUM");
David Howells70af0e32017-03-16 16:27:47 +0000503 goto save_error;
David Howellsd0016482016-08-30 20:42:14 +0100504 }
David Howells08e0e7c2007-04-26 15:55:03 -0700505 }
506
David Howellsd0016482016-08-30 20:42:14 +0100507done:
508 if (call->state == AFS_CALL_COMPLETE && call->incoming)
David Howells341f7412017-01-05 10:38:36 +0000509 afs_put_call(call);
David Howellsd0016482016-08-30 20:42:14 +0100510out:
David Howells08e0e7c2007-04-26 15:55:03 -0700511 _leave("");
David Howellsd0016482016-08-30 20:42:14 +0100512 return;
513
David Howells70af0e32017-03-16 16:27:47 +0000514save_error:
David Howellsd0016482016-08-30 20:42:14 +0100515 call->error = ret;
David Howells70af0e32017-03-16 16:27:47 +0000516call_complete:
David Howellsd0016482016-08-30 20:42:14 +0100517 call->state = AFS_CALL_COMPLETE;
518 goto done;
David Howells08e0e7c2007-04-26 15:55:03 -0700519}
520
521/*
522 * wait synchronously for a call to complete
523 */
524static int afs_wait_for_call_to_complete(struct afs_call *call)
525{
David Howellsbc5e3a52017-10-18 11:07:31 +0100526 signed long rtt2, timeout;
David Howells08e0e7c2007-04-26 15:55:03 -0700527 int ret;
David Howellsbc5e3a52017-10-18 11:07:31 +0100528 u64 rtt;
529 u32 life, last_life;
David Howells08e0e7c2007-04-26 15:55:03 -0700530
531 DECLARE_WAITQUEUE(myself, current);
532
533 _enter("");
534
David Howellsf044c882017-11-02 15:27:45 +0000535 rtt = rxrpc_kernel_get_rtt(call->net->socket, call->rxcall);
David Howellsbc5e3a52017-10-18 11:07:31 +0100536 rtt2 = nsecs_to_jiffies64(rtt) * 2;
537 if (rtt2 < 2)
538 rtt2 = 2;
539
540 timeout = rtt2;
David Howellsf044c882017-11-02 15:27:45 +0000541 last_life = rxrpc_kernel_check_life(call->net->socket, call->rxcall);
David Howellsbc5e3a52017-10-18 11:07:31 +0100542
David Howells08e0e7c2007-04-26 15:55:03 -0700543 add_wait_queue(&call->waitq, &myself);
544 for (;;) {
David Howellsbc5e3a52017-10-18 11:07:31 +0100545 set_current_state(TASK_UNINTERRUPTIBLE);
David Howells08e0e7c2007-04-26 15:55:03 -0700546
547 /* deliver any messages that are in the queue */
David Howellsd0016482016-08-30 20:42:14 +0100548 if (call->state < AFS_CALL_COMPLETE && call->need_attention) {
549 call->need_attention = false;
David Howells08e0e7c2007-04-26 15:55:03 -0700550 __set_current_state(TASK_RUNNING);
551 afs_deliver_to_call(call);
552 continue;
553 }
554
David Howellsbc5e3a52017-10-18 11:07:31 +0100555 if (call->state == AFS_CALL_COMPLETE)
David Howells08e0e7c2007-04-26 15:55:03 -0700556 break;
David Howellsbc5e3a52017-10-18 11:07:31 +0100557
David Howellsf044c882017-11-02 15:27:45 +0000558 life = rxrpc_kernel_check_life(call->net->socket, call->rxcall);
David Howellsbc5e3a52017-10-18 11:07:31 +0100559 if (timeout == 0 &&
560 life == last_life && signal_pending(current))
561 break;
562
563 if (life != last_life) {
564 timeout = rtt2;
565 last_life = life;
566 }
567
568 timeout = schedule_timeout(timeout);
David Howells08e0e7c2007-04-26 15:55:03 -0700569 }
570
571 remove_wait_queue(&call->waitq, &myself);
572 __set_current_state(TASK_RUNNING);
573
David Howells954cd6d2017-03-16 16:27:49 +0000574 /* Kill off the call if it's still live. */
David Howells08e0e7c2007-04-26 15:55:03 -0700575 if (call->state < AFS_CALL_COMPLETE) {
David Howells954cd6d2017-03-16 16:27:49 +0000576 _debug("call interrupted");
David Howellsf044c882017-11-02 15:27:45 +0000577 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
David Howells954cd6d2017-03-16 16:27:49 +0000578 RX_USER_ABORT, -EINTR, "KWI");
David Howells08e0e7c2007-04-26 15:55:03 -0700579 }
580
David Howells954cd6d2017-03-16 16:27:49 +0000581 ret = call->error;
David Howells08e0e7c2007-04-26 15:55:03 -0700582 _debug("call complete");
David Howells341f7412017-01-05 10:38:36 +0000583 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700584 _leave(" = %d", ret);
585 return ret;
586}
587
588/*
589 * wake up a waiting call
590 */
David Howellsd0016482016-08-30 20:42:14 +0100591static void afs_wake_up_call_waiter(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;
595
596 call->need_attention = true;
David Howells08e0e7c2007-04-26 15:55:03 -0700597 wake_up(&call->waitq);
598}
599
600/*
601 * wake up an asynchronous call
602 */
David Howellsd0016482016-08-30 20:42:14 +0100603static void afs_wake_up_async_call(struct sock *sk, struct rxrpc_call *rxcall,
604 unsigned long call_user_ID)
David Howells08e0e7c2007-04-26 15:55:03 -0700605{
David Howellsd0016482016-08-30 20:42:14 +0100606 struct afs_call *call = (struct afs_call *)call_user_ID;
David Howells341f7412017-01-05 10:38:36 +0000607 int u;
David Howellsd0016482016-08-30 20:42:14 +0100608
David Howells8e8d7f12017-01-05 10:38:34 +0000609 trace_afs_notify_call(rxcall, call);
David Howellsd0016482016-08-30 20:42:14 +0100610 call->need_attention = true;
David Howells341f7412017-01-05 10:38:36 +0000611
612 u = __atomic_add_unless(&call->usage, 1, 0);
613 if (u != 0) {
614 trace_afs_call(call, afs_call_trace_wake, u,
David Howellsf044c882017-11-02 15:27:45 +0000615 atomic_read(&call->net->nr_outstanding_calls),
David Howells341f7412017-01-05 10:38:36 +0000616 __builtin_return_address(0));
617
618 if (!queue_work(afs_async_calls, &call->async_work))
619 afs_put_call(call);
620 }
David Howells08e0e7c2007-04-26 15:55:03 -0700621}
622
623/*
David Howells341f7412017-01-05 10:38:36 +0000624 * Delete an asynchronous call. The work item carries a ref to the call struct
625 * that we need to release.
David Howells08e0e7c2007-04-26 15:55:03 -0700626 */
David Howellsd0016482016-08-30 20:42:14 +0100627static void afs_delete_async_call(struct work_struct *work)
David Howells08e0e7c2007-04-26 15:55:03 -0700628{
David Howellsd0016482016-08-30 20:42:14 +0100629 struct afs_call *call = container_of(work, struct afs_call, async_work);
630
David Howells08e0e7c2007-04-26 15:55:03 -0700631 _enter("");
632
David Howells341f7412017-01-05 10:38:36 +0000633 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700634
635 _leave("");
636}
637
638/*
David Howells341f7412017-01-05 10:38:36 +0000639 * Perform I/O processing on an asynchronous call. The work item carries a ref
640 * to the call struct that we either need to release or to pass on.
David Howells08e0e7c2007-04-26 15:55:03 -0700641 */
David Howellsd0016482016-08-30 20:42:14 +0100642static void afs_process_async_call(struct work_struct *work)
David Howells08e0e7c2007-04-26 15:55:03 -0700643{
David Howellsd0016482016-08-30 20:42:14 +0100644 struct afs_call *call = container_of(work, struct afs_call, async_work);
645
David Howells08e0e7c2007-04-26 15:55:03 -0700646 _enter("");
647
David Howellsd0016482016-08-30 20:42:14 +0100648 if (call->state < AFS_CALL_COMPLETE && call->need_attention) {
649 call->need_attention = false;
David Howells08e0e7c2007-04-26 15:55:03 -0700650 afs_deliver_to_call(call);
David Howellsd0016482016-08-30 20:42:14 +0100651 }
David Howells08e0e7c2007-04-26 15:55:03 -0700652
David Howells56ff9c82017-01-05 10:38:36 +0000653 if (call->state == AFS_CALL_COMPLETE) {
David Howells08e0e7c2007-04-26 15:55:03 -0700654 call->reply = NULL;
655
David Howells341f7412017-01-05 10:38:36 +0000656 /* We have two refs to release - one from the alloc and one
657 * queued with the work item - and we can't just deallocate the
658 * call because the work item may be queued again.
659 */
David Howellsd0016482016-08-30 20:42:14 +0100660 call->async_work.func = afs_delete_async_call;
David Howells341f7412017-01-05 10:38:36 +0000661 if (!queue_work(afs_async_calls, &call->async_work))
662 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700663 }
664
David Howells341f7412017-01-05 10:38:36 +0000665 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700666 _leave("");
667}
668
David Howells00e90712016-09-08 11:10:12 +0100669static void afs_rx_attach(struct rxrpc_call *rxcall, unsigned long user_call_ID)
670{
671 struct afs_call *call = (struct afs_call *)user_call_ID;
672
673 call->rxcall = rxcall;
674}
675
676/*
677 * Charge the incoming call preallocation.
678 */
David Howellsf044c882017-11-02 15:27:45 +0000679void afs_charge_preallocation(struct work_struct *work)
David Howells00e90712016-09-08 11:10:12 +0100680{
David Howellsf044c882017-11-02 15:27:45 +0000681 struct afs_net *net =
682 container_of(work, struct afs_net, charge_preallocation_work);
683 struct afs_call *call = net->spare_incoming_call;
David Howells00e90712016-09-08 11:10:12 +0100684
685 for (;;) {
686 if (!call) {
David Howellsf044c882017-11-02 15:27:45 +0000687 call = afs_alloc_call(net, &afs_RXCMxxxx, GFP_KERNEL);
David Howells00e90712016-09-08 11:10:12 +0100688 if (!call)
689 break;
690
David Howells56ff9c82017-01-05 10:38:36 +0000691 call->async = true;
David Howells00e90712016-09-08 11:10:12 +0100692 call->state = AFS_CALL_AWAIT_OP_ID;
David Howells56ff9c82017-01-05 10:38:36 +0000693 init_waitqueue_head(&call->waitq);
David Howells00e90712016-09-08 11:10:12 +0100694 }
695
David Howellsf044c882017-11-02 15:27:45 +0000696 if (rxrpc_kernel_charge_accept(net->socket,
David Howells00e90712016-09-08 11:10:12 +0100697 afs_wake_up_async_call,
698 afs_rx_attach,
699 (unsigned long)call,
700 GFP_KERNEL) < 0)
701 break;
702 call = NULL;
703 }
David Howellsf044c882017-11-02 15:27:45 +0000704 net->spare_incoming_call = call;
David Howells00e90712016-09-08 11:10:12 +0100705}
706
707/*
708 * Discard a preallocated call when a socket is shut down.
709 */
710static void afs_rx_discard_new_call(struct rxrpc_call *rxcall,
711 unsigned long user_call_ID)
712{
713 struct afs_call *call = (struct afs_call *)user_call_ID;
714
David Howells00e90712016-09-08 11:10:12 +0100715 call->rxcall = NULL;
David Howells341f7412017-01-05 10:38:36 +0000716 afs_put_call(call);
David Howells00e90712016-09-08 11:10:12 +0100717}
718
David Howells08e0e7c2007-04-26 15:55:03 -0700719/*
David Howellsd0016482016-08-30 20:42:14 +0100720 * Notification of an incoming call.
721 */
David Howells00e90712016-09-08 11:10:12 +0100722static void afs_rx_new_call(struct sock *sk, struct rxrpc_call *rxcall,
723 unsigned long user_call_ID)
David Howellsd0016482016-08-30 20:42:14 +0100724{
David Howellsf044c882017-11-02 15:27:45 +0000725 struct afs_net *net = afs_sock2net(sk);
726
727 queue_work(afs_wq, &net->charge_preallocation_work);
David Howellsd0016482016-08-30 20:42:14 +0100728}
729
730/*
David Howells372ee162016-08-03 14:11:40 +0100731 * Grab the operation ID from an incoming cache manager call. The socket
732 * buffer is discarded on error or if we don't yet have sufficient data.
David Howells08e0e7c2007-04-26 15:55:03 -0700733 */
David Howellsd0016482016-08-30 20:42:14 +0100734static int afs_deliver_cm_op_id(struct afs_call *call)
David Howells08e0e7c2007-04-26 15:55:03 -0700735{
David Howellsd0016482016-08-30 20:42:14 +0100736 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700737
David Howellsd0016482016-08-30 20:42:14 +0100738 _enter("{%zu}", call->offset);
David Howells08e0e7c2007-04-26 15:55:03 -0700739
740 ASSERTCMP(call->offset, <, 4);
741
742 /* the operation ID forms the first four bytes of the request data */
David Howells50a2c952016-10-13 08:27:10 +0100743 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howellsd0016482016-08-30 20:42:14 +0100744 if (ret < 0)
745 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700746
David Howells50a2c952016-10-13 08:27:10 +0100747 call->operation_ID = ntohl(call->tmp);
David Howells08e0e7c2007-04-26 15:55:03 -0700748 call->state = AFS_CALL_AWAIT_REQUEST;
David Howellsd0016482016-08-30 20:42:14 +0100749 call->offset = 0;
David Howells08e0e7c2007-04-26 15:55:03 -0700750
751 /* ask the cache manager to route the call (it'll change the call type
752 * if successful) */
753 if (!afs_cm_incoming_call(call))
754 return -ENOTSUPP;
755
David Howells8e8d7f12017-01-05 10:38:34 +0000756 trace_afs_cb_call(call);
757
David Howells08e0e7c2007-04-26 15:55:03 -0700758 /* pass responsibility for the remainer of this message off to the
759 * cache manager op */
David Howellsd0016482016-08-30 20:42:14 +0100760 return call->type->deliver(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700761}
762
763/*
David Howellse8332512017-08-29 10:18:56 +0100764 * Advance the AFS call state when an RxRPC service call ends the transmit
765 * phase.
766 */
767static void afs_notify_end_reply_tx(struct sock *sock,
768 struct rxrpc_call *rxcall,
769 unsigned long call_user_ID)
770{
771 struct afs_call *call = (struct afs_call *)call_user_ID;
772
773 if (call->state == AFS_CALL_REPLYING)
774 call->state = AFS_CALL_AWAIT_ACK;
775}
776
777/*
David Howells08e0e7c2007-04-26 15:55:03 -0700778 * send an empty reply
779 */
780void afs_send_empty_reply(struct afs_call *call)
781{
David Howellsf044c882017-11-02 15:27:45 +0000782 struct afs_net *net = call->net;
David Howells08e0e7c2007-04-26 15:55:03 -0700783 struct msghdr msg;
David Howells08e0e7c2007-04-26 15:55:03 -0700784
785 _enter("");
786
David Howellsf044c882017-11-02 15:27:45 +0000787 rxrpc_kernel_set_tx_length(net->socket, call->rxcall, 0);
David Howellse754eba2017-06-07 12:40:03 +0100788
David Howells08e0e7c2007-04-26 15:55:03 -0700789 msg.msg_name = NULL;
790 msg.msg_namelen = 0;
David Howellsbfd4e952015-04-01 16:03:46 +0100791 iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, NULL, 0, 0);
David Howells08e0e7c2007-04-26 15:55:03 -0700792 msg.msg_control = NULL;
793 msg.msg_controllen = 0;
794 msg.msg_flags = 0;
795
796 call->state = AFS_CALL_AWAIT_ACK;
David Howellsf044c882017-11-02 15:27:45 +0000797 switch (rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, 0,
David Howellse8332512017-08-29 10:18:56 +0100798 afs_notify_end_reply_tx)) {
David Howells08e0e7c2007-04-26 15:55:03 -0700799 case 0:
800 _leave(" [replied]");
801 return;
802
803 case -ENOMEM:
804 _debug("oom");
David Howellsf044c882017-11-02 15:27:45 +0000805 rxrpc_kernel_abort_call(net->socket, call->rxcall,
David Howells3a927892017-04-06 10:11:56 +0100806 RX_USER_ABORT, -ENOMEM, "KOO");
David Howells08e0e7c2007-04-26 15:55:03 -0700807 default:
David Howells08e0e7c2007-04-26 15:55:03 -0700808 _leave(" [error]");
809 return;
810 }
811}
812
813/*
David Howellsb908fe62007-04-26 15:58:17 -0700814 * send a simple reply
815 */
816void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len)
817{
David Howellsf044c882017-11-02 15:27:45 +0000818 struct afs_net *net = call->net;
David Howellsb908fe62007-04-26 15:58:17 -0700819 struct msghdr msg;
Al Viro2e90b1c2014-11-27 21:50:31 -0500820 struct kvec iov[1];
David Howellsbd6dc742007-07-20 10:59:41 +0100821 int n;
David Howellsb908fe62007-04-26 15:58:17 -0700822
823 _enter("");
824
David Howellsf044c882017-11-02 15:27:45 +0000825 rxrpc_kernel_set_tx_length(net->socket, call->rxcall, len);
David Howellse754eba2017-06-07 12:40:03 +0100826
David Howellsb908fe62007-04-26 15:58:17 -0700827 iov[0].iov_base = (void *) buf;
828 iov[0].iov_len = len;
829 msg.msg_name = NULL;
830 msg.msg_namelen = 0;
Al Viro2e90b1c2014-11-27 21:50:31 -0500831 iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, iov, 1, len);
David Howellsb908fe62007-04-26 15:58:17 -0700832 msg.msg_control = NULL;
833 msg.msg_controllen = 0;
834 msg.msg_flags = 0;
835
836 call->state = AFS_CALL_AWAIT_ACK;
David Howellsf044c882017-11-02 15:27:45 +0000837 n = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, len,
David Howellse8332512017-08-29 10:18:56 +0100838 afs_notify_end_reply_tx);
David Howellsbd6dc742007-07-20 10:59:41 +0100839 if (n >= 0) {
David Howells6c67c7c2014-05-21 14:48:05 +0100840 /* Success */
David Howellsb908fe62007-04-26 15:58:17 -0700841 _leave(" [replied]");
842 return;
David Howellsbd6dc742007-07-20 10:59:41 +0100843 }
David Howells6c67c7c2014-05-21 14:48:05 +0100844
David Howellsbd6dc742007-07-20 10:59:41 +0100845 if (n == -ENOMEM) {
David Howellsb908fe62007-04-26 15:58:17 -0700846 _debug("oom");
David Howellsf044c882017-11-02 15:27:45 +0000847 rxrpc_kernel_abort_call(net->socket, call->rxcall,
David Howells3a927892017-04-06 10:11:56 +0100848 RX_USER_ABORT, -ENOMEM, "KOO");
David Howellsb908fe62007-04-26 15:58:17 -0700849 }
David Howellsbd6dc742007-07-20 10:59:41 +0100850 _leave(" [error]");
David Howellsb908fe62007-04-26 15:58:17 -0700851}
852
853/*
David Howells372ee162016-08-03 14:11:40 +0100854 * Extract a piece of data from the received data socket buffers.
David Howells08e0e7c2007-04-26 15:55:03 -0700855 */
David Howellsd0016482016-08-30 20:42:14 +0100856int afs_extract_data(struct afs_call *call, void *buf, size_t count,
857 bool want_more)
David Howells08e0e7c2007-04-26 15:55:03 -0700858{
David Howellsf044c882017-11-02 15:27:45 +0000859 struct afs_net *net = call->net;
David Howellsd0016482016-08-30 20:42:14 +0100860 int ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700861
David Howellsd0016482016-08-30 20:42:14 +0100862 _enter("{%s,%zu},,%zu,%d",
863 call->type->name, call->offset, count, want_more);
David Howells08e0e7c2007-04-26 15:55:03 -0700864
David Howellsd0016482016-08-30 20:42:14 +0100865 ASSERTCMP(call->offset, <=, count);
David Howells08e0e7c2007-04-26 15:55:03 -0700866
David Howellsf044c882017-11-02 15:27:45 +0000867 ret = rxrpc_kernel_recv_data(net->socket, call->rxcall,
David Howellsd0016482016-08-30 20:42:14 +0100868 buf, count, &call->offset,
David Howellsa68f4a22017-10-18 11:36:39 +0100869 want_more, &call->abort_code,
870 &call->service_id);
David Howells8e8d7f12017-01-05 10:38:34 +0000871 trace_afs_recv_data(call, count, call->offset, want_more, ret);
David Howellsd0016482016-08-30 20:42:14 +0100872 if (ret == 0 || ret == -EAGAIN)
873 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700874
David Howellsd0016482016-08-30 20:42:14 +0100875 if (ret == 1) {
876 switch (call->state) {
877 case AFS_CALL_AWAIT_REPLY:
878 call->state = AFS_CALL_COMPLETE;
879 break;
880 case AFS_CALL_AWAIT_REQUEST:
881 call->state = AFS_CALL_REPLYING;
882 break;
883 default:
884 break;
885 }
886 return 0;
David Howells08e0e7c2007-04-26 15:55:03 -0700887 }
David Howellsd0016482016-08-30 20:42:14 +0100888
889 if (ret == -ECONNABORTED)
890 call->error = call->type->abort_to_error(call->abort_code);
891 else
892 call->error = ret;
893 call->state = AFS_CALL_COMPLETE;
894 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700895}