David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 1 | /* 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Ingo Molnar | 174cd4b | 2017-02-02 19:15:33 +0100 | [diff] [blame] | 13 | #include <linux/sched/signal.h> |
| 14 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 15 | #include <net/sock.h> |
| 16 | #include <net/af_rxrpc.h> |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 17 | #include "internal.h" |
| 18 | #include "afs_cm.h" |
| 19 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 20 | struct workqueue_struct *afs_async_calls; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 21 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 22 | static void afs_wake_up_call_waiter(struct sock *, struct rxrpc_call *, unsigned long); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 23 | static long afs_wait_for_call_to_complete(struct afs_call *, struct afs_addr_cursor *); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 24 | static void afs_wake_up_async_call(struct sock *, struct rxrpc_call *, unsigned long); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 25 | static void afs_process_async_call(struct work_struct *); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 26 | static void afs_rx_new_call(struct sock *, struct rxrpc_call *, unsigned long); |
| 27 | static void afs_rx_discard_new_call(struct rxrpc_call *, unsigned long); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 28 | static int afs_deliver_cm_op_id(struct afs_call *); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 29 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 30 | /* asynchronous incoming call initial processing */ |
| 31 | static const struct afs_call_type afs_RXCMxxxx = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 32 | .name = "CB.xxxx", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 33 | .deliver = afs_deliver_cm_op_id, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 36 | /* |
| 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 Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 40 | int afs_open_socket(struct afs_net *net) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 41 | { |
| 42 | struct sockaddr_rxrpc srx; |
| 43 | struct socket *socket; |
David Howells | 4776cab | 2018-05-10 23:10:40 +0100 | [diff] [blame] | 44 | unsigned int min_level; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 45 | int ret; |
| 46 | |
| 47 | _enter(""); |
| 48 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 49 | ret = sock_create_kern(net->net, AF_RXRPC, SOCK_DGRAM, PF_INET6, &socket); |
David Howells | 0e119b4 | 2016-06-10 22:30:37 +0100 | [diff] [blame] | 50 | if (ret < 0) |
| 51 | goto error_1; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 52 | |
| 53 | socket->sk->sk_allocation = GFP_NOFS; |
| 54 | |
| 55 | /* bind the callback manager's address to make this a server socket */ |
David Howells | 3838d3e | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 56 | memset(&srx, 0, sizeof(srx)); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 57 | srx.srx_family = AF_RXRPC; |
| 58 | srx.srx_service = CM_SERVICE; |
| 59 | srx.transport_type = SOCK_DGRAM; |
David Howells | 3838d3e | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 60 | srx.transport_len = sizeof(srx.transport.sin6); |
| 61 | srx.transport.sin6.sin6_family = AF_INET6; |
| 62 | srx.transport.sin6.sin6_port = htons(AFS_CM_PORT); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 63 | |
David Howells | 4776cab | 2018-05-10 23:10:40 +0100 | [diff] [blame] | 64 | min_level = RXRPC_SECURITY_ENCRYPT; |
| 65 | ret = kernel_setsockopt(socket, SOL_RXRPC, RXRPC_MIN_SECURITY_LEVEL, |
| 66 | (void *)&min_level, sizeof(min_level)); |
| 67 | if (ret < 0) |
| 68 | goto error_2; |
| 69 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 70 | ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx)); |
Marc Dionne | 83732ec | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 71 | if (ret == -EADDRINUSE) { |
| 72 | srx.transport.sin6.sin6_port = 0; |
| 73 | ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx)); |
| 74 | } |
David Howells | 0e119b4 | 2016-06-10 22:30:37 +0100 | [diff] [blame] | 75 | if (ret < 0) |
| 76 | goto error_2; |
| 77 | |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 78 | rxrpc_kernel_new_call_notification(socket, afs_rx_new_call, |
| 79 | afs_rx_discard_new_call); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 80 | |
David Howells | 0e119b4 | 2016-06-10 22:30:37 +0100 | [diff] [blame] | 81 | ret = kernel_listen(socket, INT_MAX); |
| 82 | if (ret < 0) |
| 83 | goto error_2; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 84 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 85 | net->socket = socket; |
| 86 | afs_charge_preallocation(&net->charge_preallocation_work); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 87 | _leave(" = 0"); |
| 88 | return 0; |
David Howells | 0e119b4 | 2016-06-10 22:30:37 +0100 | [diff] [blame] | 89 | |
| 90 | error_2: |
| 91 | sock_release(socket); |
| 92 | error_1: |
David Howells | 0e119b4 | 2016-06-10 22:30:37 +0100 | [diff] [blame] | 93 | _leave(" = %d", ret); |
| 94 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* |
| 98 | * close the RxRPC socket AFS was using |
| 99 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 100 | void afs_close_socket(struct afs_net *net) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 101 | { |
| 102 | _enter(""); |
| 103 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 104 | kernel_listen(net->socket, 0); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 105 | flush_workqueue(afs_async_calls); |
| 106 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 107 | if (net->spare_incoming_call) { |
| 108 | afs_put_call(net->spare_incoming_call); |
| 109 | net->spare_incoming_call = NULL; |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 110 | } |
| 111 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 112 | _debug("outstanding %u", atomic_read(&net->nr_outstanding_calls)); |
Peter Zijlstra | ab1fbe3 | 2018-03-15 11:42:28 +0100 | [diff] [blame] | 113 | wait_var_event(&net->nr_outstanding_calls, |
| 114 | !atomic_read(&net->nr_outstanding_calls)); |
David Howells | 2f02f7a | 2016-04-07 17:23:03 +0100 | [diff] [blame] | 115 | _debug("no outstanding calls"); |
| 116 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 117 | kernel_sock_shutdown(net->socket, SHUT_RDWR); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 118 | flush_workqueue(afs_async_calls); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 119 | sock_release(net->socket); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 120 | |
| 121 | _debug("dework"); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 122 | _leave(""); |
| 123 | } |
| 124 | |
| 125 | /* |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 126 | * Allocate a call. |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 127 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 128 | static struct afs_call *afs_alloc_call(struct afs_net *net, |
| 129 | const struct afs_call_type *type, |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 130 | gfp_t gfp) |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 131 | { |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 132 | struct afs_call *call; |
| 133 | int o; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 134 | |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 135 | call = kzalloc(sizeof(*call), gfp); |
| 136 | if (!call) |
| 137 | return NULL; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 138 | |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 139 | call->type = type; |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 140 | call->net = net; |
David Howells | a25e21f | 2018-03-27 23:03:00 +0100 | [diff] [blame] | 141 | call->debug_id = atomic_inc_return(&rxrpc_debug_id); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 142 | atomic_set(&call->usage, 1); |
| 143 | INIT_WORK(&call->async_work, afs_process_async_call); |
| 144 | init_waitqueue_head(&call->waitq); |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 145 | spin_lock_init(&call->state_lock); |
David Howells | 2f02f7a | 2016-04-07 17:23:03 +0100 | [diff] [blame] | 146 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 147 | o = atomic_inc_return(&net->nr_outstanding_calls); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 148 | trace_afs_call(call, afs_call_trace_alloc, 1, o, |
| 149 | __builtin_return_address(0)); |
| 150 | return call; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 154 | * Dispose of a reference on a call. |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 155 | */ |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 156 | void afs_put_call(struct afs_call *call) |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 157 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 158 | struct afs_net *net = call->net; |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 159 | int n = atomic_dec_return(&call->usage); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 160 | int o = atomic_read(&net->nr_outstanding_calls); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 161 | |
| 162 | trace_afs_call(call, afs_call_trace_put, n + 1, o, |
| 163 | __builtin_return_address(0)); |
| 164 | |
| 165 | ASSERTCMP(n, >=, 0); |
| 166 | if (n == 0) { |
| 167 | ASSERT(!work_pending(&call->async_work)); |
| 168 | ASSERT(call->type->name != NULL); |
| 169 | |
| 170 | if (call->rxcall) { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 171 | rxrpc_kernel_end_call(net->socket, call->rxcall); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 172 | call->rxcall = NULL; |
| 173 | } |
| 174 | if (call->type->destructor) |
| 175 | call->type->destructor(call); |
| 176 | |
David Howells | d0676a1 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 177 | afs_put_server(call->net, call->cm_server); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 178 | afs_put_cb_interest(call->net, call->cbi); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 179 | kfree(call->request); |
David Howells | a25e21f | 2018-03-27 23:03:00 +0100 | [diff] [blame] | 180 | |
| 181 | trace_afs_call(call, afs_call_trace_free, 0, o, |
| 182 | __builtin_return_address(0)); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 183 | kfree(call); |
| 184 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 185 | o = atomic_dec_return(&net->nr_outstanding_calls); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 186 | if (o == 0) |
Peter Zijlstra | ab1fbe3 | 2018-03-15 11:42:28 +0100 | [diff] [blame] | 187 | wake_up_var(&net->nr_outstanding_calls); |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 188 | } |
Nathaniel Wesley Filardo | 6cf1286 | 2014-05-21 16:04:11 +0100 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /* |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 192 | * Queue the call for actual work. Returns 0 unconditionally for convenience. |
Nathaniel Wesley Filardo | 6cf1286 | 2014-05-21 16:04:11 +0100 | [diff] [blame] | 193 | */ |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 194 | int afs_queue_call_work(struct afs_call *call) |
Nathaniel Wesley Filardo | 6cf1286 | 2014-05-21 16:04:11 +0100 | [diff] [blame] | 195 | { |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 196 | int u = atomic_inc_return(&call->usage); |
| 197 | |
| 198 | trace_afs_call(call, afs_call_trace_work, u, |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 199 | atomic_read(&call->net->nr_outstanding_calls), |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 200 | __builtin_return_address(0)); |
| 201 | |
| 202 | INIT_WORK(&call->work, call->type->work); |
| 203 | |
| 204 | if (!queue_work(afs_wq, &call->work)) |
| 205 | afs_put_call(call); |
| 206 | return 0; |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 210 | * allocate a call with flat request and reply buffers |
| 211 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 212 | struct afs_call *afs_alloc_flat_call(struct afs_net *net, |
| 213 | const struct afs_call_type *type, |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 214 | size_t request_size, size_t reply_max) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 215 | { |
| 216 | struct afs_call *call; |
| 217 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 218 | call = afs_alloc_call(net, type, GFP_NOFS); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 219 | if (!call) |
| 220 | goto nomem_call; |
| 221 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 222 | if (request_size) { |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 223 | call->request_size = request_size; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 224 | call->request = kmalloc(request_size, GFP_NOFS); |
| 225 | if (!call->request) |
| 226 | goto nomem_free; |
| 227 | } |
| 228 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 229 | if (reply_max) { |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 230 | call->reply_max = reply_max; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 231 | call->buffer = kmalloc(reply_max, GFP_NOFS); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 232 | if (!call->buffer) |
| 233 | goto nomem_free; |
| 234 | } |
| 235 | |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 236 | call->operation_ID = type->op; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 237 | init_waitqueue_head(&call->waitq); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 238 | return call; |
| 239 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 240 | nomem_free: |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 241 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 242 | nomem_call: |
| 243 | return NULL; |
| 244 | } |
| 245 | |
| 246 | /* |
| 247 | * clean up a call with flat buffer |
| 248 | */ |
| 249 | void afs_flat_call_destructor(struct afs_call *call) |
| 250 | { |
| 251 | _enter(""); |
| 252 | |
| 253 | kfree(call->request); |
| 254 | call->request = NULL; |
| 255 | kfree(call->buffer); |
| 256 | call->buffer = NULL; |
| 257 | } |
| 258 | |
David Howells | 2f5705a | 2017-03-16 16:27:46 +0000 | [diff] [blame] | 259 | #define AFS_BVEC_MAX 8 |
| 260 | |
| 261 | /* |
| 262 | * Load the given bvec with the next few pages. |
| 263 | */ |
| 264 | static void afs_load_bvec(struct afs_call *call, struct msghdr *msg, |
| 265 | struct bio_vec *bv, pgoff_t first, pgoff_t last, |
| 266 | unsigned offset) |
| 267 | { |
| 268 | struct page *pages[AFS_BVEC_MAX]; |
| 269 | unsigned int nr, n, i, to, bytes = 0; |
| 270 | |
| 271 | nr = min_t(pgoff_t, last - first + 1, AFS_BVEC_MAX); |
| 272 | n = find_get_pages_contig(call->mapping, first, nr, pages); |
| 273 | ASSERTCMP(n, ==, nr); |
| 274 | |
| 275 | msg->msg_flags |= MSG_MORE; |
| 276 | for (i = 0; i < nr; i++) { |
| 277 | to = PAGE_SIZE; |
| 278 | if (first + i >= last) { |
| 279 | to = call->last_to; |
| 280 | msg->msg_flags &= ~MSG_MORE; |
| 281 | } |
| 282 | bv[i].bv_page = pages[i]; |
| 283 | bv[i].bv_len = to - offset; |
| 284 | bv[i].bv_offset = offset; |
| 285 | bytes += to - offset; |
| 286 | offset = 0; |
| 287 | } |
| 288 | |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame^] | 289 | iov_iter_bvec(&msg->msg_iter, WRITE, bv, nr, bytes); |
David Howells | 2f5705a | 2017-03-16 16:27:46 +0000 | [diff] [blame] | 290 | } |
| 291 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 292 | /* |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 293 | * Advance the AFS call state when the RxRPC call ends the transmit phase. |
| 294 | */ |
| 295 | static void afs_notify_end_request_tx(struct sock *sock, |
| 296 | struct rxrpc_call *rxcall, |
| 297 | unsigned long call_user_ID) |
| 298 | { |
| 299 | struct afs_call *call = (struct afs_call *)call_user_ID; |
| 300 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 301 | afs_set_call_state(call, AFS_CALL_CL_REQUESTING, AFS_CALL_CL_AWAIT_REPLY); |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /* |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 305 | * attach the data from a bunch of pages on an inode to a call |
| 306 | */ |
Al Viro | 39c6ace | 2016-01-09 20:36:51 -0500 | [diff] [blame] | 307 | static int afs_send_pages(struct afs_call *call, struct msghdr *msg) |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 308 | { |
David Howells | 2f5705a | 2017-03-16 16:27:46 +0000 | [diff] [blame] | 309 | struct bio_vec bv[AFS_BVEC_MAX]; |
| 310 | unsigned int bytes, nr, loop, offset; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 311 | pgoff_t first = call->first, last = call->last; |
| 312 | int ret; |
| 313 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 314 | offset = call->first_offset; |
| 315 | call->first_offset = 0; |
| 316 | |
| 317 | do { |
David Howells | 2f5705a | 2017-03-16 16:27:46 +0000 | [diff] [blame] | 318 | afs_load_bvec(call, msg, bv, first, last, offset); |
David Howells | 2c09901 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 319 | trace_afs_send_pages(call, msg, first, last, offset); |
| 320 | |
David Howells | 2f5705a | 2017-03-16 16:27:46 +0000 | [diff] [blame] | 321 | offset = 0; |
| 322 | bytes = msg->msg_iter.count; |
| 323 | nr = msg->msg_iter.nr_segs; |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 324 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 325 | ret = rxrpc_kernel_send_data(call->net->socket, call->rxcall, msg, |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 326 | bytes, afs_notify_end_request_tx); |
David Howells | 2f5705a | 2017-03-16 16:27:46 +0000 | [diff] [blame] | 327 | for (loop = 0; loop < nr; loop++) |
| 328 | put_page(bv[loop].bv_page); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 329 | if (ret < 0) |
| 330 | break; |
David Howells | 2f5705a | 2017-03-16 16:27:46 +0000 | [diff] [blame] | 331 | |
| 332 | first += nr; |
David Howells | 5bbf5d3 | 2007-05-10 03:15:23 -0700 | [diff] [blame] | 333 | } while (first <= last); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 334 | |
David Howells | 2c09901 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 335 | trace_afs_sent_pages(call, call->first, last, first, ret); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 336 | return ret; |
| 337 | } |
| 338 | |
| 339 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 340 | * initiate a call |
| 341 | */ |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 342 | long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, |
David Howells | 33cd7f2 | 2017-11-02 15:27:48 +0000 | [diff] [blame] | 343 | gfp_t gfp, bool async) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 344 | { |
David Howells | 8b2a464 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 345 | struct sockaddr_rxrpc *srx = ac->addr; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 346 | struct rxrpc_call *rxcall; |
| 347 | struct msghdr msg; |
| 348 | struct kvec iov[1]; |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 349 | s64 tx_total_len; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 350 | int ret; |
| 351 | |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 352 | _enter(",{%pISp},", &srx->transport); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 353 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 354 | ASSERT(call->type != NULL); |
| 355 | ASSERT(call->type->name != NULL); |
| 356 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 357 | _debug("____MAKE %p{%s,%x} [%d]____", |
| 358 | call, call->type->name, key_serial(call->key), |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 359 | atomic_read(&call->net->nr_outstanding_calls)); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 360 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 361 | call->async = async; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 362 | |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 363 | /* Work out the length we're going to transmit. This is awkward for |
| 364 | * calls such as FS.StoreData where there's an extra injection of data |
| 365 | * after the initial fixed part. |
| 366 | */ |
| 367 | tx_total_len = call->request_size; |
| 368 | if (call->send_pages) { |
David Howells | 1199db6 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 369 | if (call->last == call->first) { |
| 370 | tx_total_len += call->last_to - call->first_offset; |
| 371 | } else { |
| 372 | /* It looks mathematically like you should be able to |
| 373 | * combine the following lines with the ones above, but |
| 374 | * unsigned arithmetic is fun when it wraps... |
| 375 | */ |
| 376 | tx_total_len += PAGE_SIZE - call->first_offset; |
| 377 | tx_total_len += call->last_to; |
| 378 | tx_total_len += (call->last - call->first - 1) * PAGE_SIZE; |
| 379 | } |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 380 | } |
| 381 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 382 | /* create a call */ |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 383 | rxcall = rxrpc_kernel_begin_call(call->net->socket, srx, call->key, |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 384 | (unsigned long)call, |
| 385 | tx_total_len, gfp, |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 386 | (async ? |
| 387 | afs_wake_up_async_call : |
David Howells | a68f4a2 | 2017-10-18 11:36:39 +0100 | [diff] [blame] | 388 | afs_wake_up_call_waiter), |
David Howells | a25e21f | 2018-03-27 23:03:00 +0100 | [diff] [blame] | 389 | call->upgrade, |
| 390 | call->debug_id); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 391 | if (IS_ERR(rxcall)) { |
| 392 | ret = PTR_ERR(rxcall); |
| 393 | goto error_kill_call; |
| 394 | } |
| 395 | |
| 396 | call->rxcall = rxcall; |
| 397 | |
| 398 | /* send the request */ |
| 399 | iov[0].iov_base = call->request; |
| 400 | iov[0].iov_len = call->request_size; |
| 401 | |
| 402 | msg.msg_name = NULL; |
| 403 | msg.msg_namelen = 0; |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame^] | 404 | iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, call->request_size); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 405 | msg.msg_control = NULL; |
| 406 | msg.msg_controllen = 0; |
David Howells | bc5e3a5 | 2017-10-18 11:07:31 +0100 | [diff] [blame] | 407 | msg.msg_flags = MSG_WAITALL | (call->send_pages ? MSG_MORE : 0); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 408 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 409 | ret = rxrpc_kernel_send_data(call->net->socket, rxcall, |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 410 | &msg, call->request_size, |
| 411 | afs_notify_end_request_tx); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 412 | if (ret < 0) |
| 413 | goto error_do_abort; |
| 414 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 415 | if (call->send_pages) { |
Al Viro | 39c6ace | 2016-01-09 20:36:51 -0500 | [diff] [blame] | 416 | ret = afs_send_pages(call, &msg); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 417 | if (ret < 0) |
| 418 | goto error_do_abort; |
| 419 | } |
| 420 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 421 | /* at this point, an async call may no longer exist as it may have |
| 422 | * already completed */ |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 423 | if (call->async) |
| 424 | return -EINPROGRESS; |
| 425 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 426 | return afs_wait_for_call_to_complete(call, ac); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 427 | |
| 428 | error_do_abort: |
David Howells | 70af0e3 | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 429 | call->state = AFS_CALL_COMPLETE; |
| 430 | if (ret != -ECONNABORTED) { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 431 | rxrpc_kernel_abort_call(call->net->socket, rxcall, |
| 432 | RX_USER_ABORT, ret, "KSD"); |
David Howells | 70af0e3 | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 433 | } else { |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame^] | 434 | iov_iter_kvec(&msg.msg_iter, READ, NULL, 0, 0); |
David Howells | eb9950e | 2018-08-03 17:06:56 +0100 | [diff] [blame] | 435 | rxrpc_kernel_recv_data(call->net->socket, rxcall, |
| 436 | &msg.msg_iter, false, |
| 437 | &call->abort_code, &call->service_id); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 438 | ac->abort_code = call->abort_code; |
| 439 | ac->responded = true; |
David Howells | 70af0e3 | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 440 | } |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 441 | call->error = ret; |
| 442 | trace_afs_call_done(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 443 | error_kill_call: |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 444 | afs_put_call(call); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 445 | ac->error = ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 446 | _leave(" = %d", ret); |
| 447 | return ret; |
| 448 | } |
| 449 | |
| 450 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 451 | * deliver messages to a call |
| 452 | */ |
| 453 | static void afs_deliver_to_call(struct afs_call *call) |
| 454 | { |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 455 | enum afs_call_state state; |
| 456 | u32 abort_code, remote_abort = 0; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 457 | int ret; |
| 458 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 459 | _enter("%s", call->type->name); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 460 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 461 | while (state = READ_ONCE(call->state), |
| 462 | state == AFS_CALL_CL_AWAIT_REPLY || |
| 463 | state == AFS_CALL_SV_AWAIT_OP_ID || |
| 464 | state == AFS_CALL_SV_AWAIT_REQUEST || |
| 465 | state == AFS_CALL_SV_AWAIT_ACK |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 466 | ) { |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 467 | if (state == AFS_CALL_SV_AWAIT_ACK) { |
David Howells | eb9950e | 2018-08-03 17:06:56 +0100 | [diff] [blame] | 468 | struct iov_iter iter; |
| 469 | |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame^] | 470 | iov_iter_kvec(&iter, READ, NULL, 0, 0); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 471 | ret = rxrpc_kernel_recv_data(call->net->socket, |
David Howells | eb9950e | 2018-08-03 17:06:56 +0100 | [diff] [blame] | 472 | call->rxcall, &iter, false, |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 473 | &remote_abort, |
David Howells | a68f4a2 | 2017-10-18 11:36:39 +0100 | [diff] [blame] | 474 | &call->service_id); |
David Howells | eb9950e | 2018-08-03 17:06:56 +0100 | [diff] [blame] | 475 | trace_afs_recv_data(call, 0, 0, false, ret); |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 476 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 477 | if (ret == -EINPROGRESS || ret == -EAGAIN) |
| 478 | return; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 479 | if (ret < 0 || ret == 1) { |
| 480 | if (ret == 1) |
| 481 | ret = 0; |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 482 | goto call_complete; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 483 | } |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 484 | return; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 485 | } |
| 486 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 487 | ret = call->type->deliver(call); |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 488 | state = READ_ONCE(call->state); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 489 | switch (ret) { |
| 490 | case 0: |
David Howells | f2686b0 | 2018-05-10 14:12:50 +0100 | [diff] [blame] | 491 | if (state == AFS_CALL_CL_PROC_REPLY) { |
| 492 | if (call->cbi) |
| 493 | set_bit(AFS_SERVER_FL_MAY_HAVE_CB, |
| 494 | &call->cbi->server->flags); |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 495 | goto call_complete; |
David Howells | f2686b0 | 2018-05-10 14:12:50 +0100 | [diff] [blame] | 496 | } |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 497 | ASSERTCMP(state, >, AFS_CALL_CL_PROC_REPLY); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 498 | goto done; |
| 499 | case -EINPROGRESS: |
| 500 | case -EAGAIN: |
| 501 | goto out; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 502 | case -EIO: |
David Howells | 70af0e3 | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 503 | case -ECONNABORTED: |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 504 | ASSERTCMP(state, ==, AFS_CALL_COMPLETE); |
| 505 | goto done; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 506 | case -ENOTSUPP: |
David Howells | 1157f15 | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 507 | abort_code = RXGEN_OPCODE; |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 508 | rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
David Howells | 3a92789 | 2017-04-06 10:11:56 +0100 | [diff] [blame] | 509 | abort_code, ret, "KIV"); |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 510 | goto local_abort; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 511 | case -ENODATA: |
| 512 | case -EBADMSG: |
| 513 | case -EMSGSIZE: |
| 514 | default: |
| 515 | abort_code = RXGEN_CC_UNMARSHAL; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 516 | if (state != AFS_CALL_CL_AWAIT_REPLY) |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 517 | abort_code = RXGEN_SS_UNMARSHAL; |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 518 | rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
David Howells | 3a92789 | 2017-04-06 10:11:56 +0100 | [diff] [blame] | 519 | abort_code, -EBADMSG, "KUM"); |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 520 | goto local_abort; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 521 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 522 | } |
| 523 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 524 | done: |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 525 | if (state == AFS_CALL_COMPLETE && call->incoming) |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 526 | afs_put_call(call); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 527 | out: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 528 | _leave(""); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 529 | return; |
| 530 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 531 | local_abort: |
| 532 | abort_code = 0; |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 533 | call_complete: |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 534 | afs_set_call_complete(call, ret, remote_abort); |
| 535 | state = AFS_CALL_COMPLETE; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 536 | goto done; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* |
| 540 | * wait synchronously for a call to complete |
| 541 | */ |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 542 | static long afs_wait_for_call_to_complete(struct afs_call *call, |
| 543 | struct afs_addr_cursor *ac) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 544 | { |
David Howells | bc5e3a5 | 2017-10-18 11:07:31 +0100 | [diff] [blame] | 545 | signed long rtt2, timeout; |
David Howells | 33cd7f2 | 2017-11-02 15:27:48 +0000 | [diff] [blame] | 546 | long ret; |
David Howells | bc5e3a5 | 2017-10-18 11:07:31 +0100 | [diff] [blame] | 547 | u64 rtt; |
| 548 | u32 life, last_life; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 549 | |
| 550 | DECLARE_WAITQUEUE(myself, current); |
| 551 | |
| 552 | _enter(""); |
| 553 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 554 | rtt = rxrpc_kernel_get_rtt(call->net->socket, call->rxcall); |
David Howells | bc5e3a5 | 2017-10-18 11:07:31 +0100 | [diff] [blame] | 555 | rtt2 = nsecs_to_jiffies64(rtt) * 2; |
| 556 | if (rtt2 < 2) |
| 557 | rtt2 = 2; |
| 558 | |
| 559 | timeout = rtt2; |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 560 | last_life = rxrpc_kernel_check_life(call->net->socket, call->rxcall); |
David Howells | bc5e3a5 | 2017-10-18 11:07:31 +0100 | [diff] [blame] | 561 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 562 | add_wait_queue(&call->waitq, &myself); |
| 563 | for (;;) { |
David Howells | bc5e3a5 | 2017-10-18 11:07:31 +0100 | [diff] [blame] | 564 | set_current_state(TASK_UNINTERRUPTIBLE); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 565 | |
| 566 | /* deliver any messages that are in the queue */ |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 567 | if (!afs_check_call_state(call, AFS_CALL_COMPLETE) && |
| 568 | call->need_attention) { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 569 | call->need_attention = false; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 570 | __set_current_state(TASK_RUNNING); |
| 571 | afs_deliver_to_call(call); |
| 572 | continue; |
| 573 | } |
| 574 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 575 | if (afs_check_call_state(call, AFS_CALL_COMPLETE)) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 576 | break; |
David Howells | bc5e3a5 | 2017-10-18 11:07:31 +0100 | [diff] [blame] | 577 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 578 | life = rxrpc_kernel_check_life(call->net->socket, call->rxcall); |
David Howells | bc5e3a5 | 2017-10-18 11:07:31 +0100 | [diff] [blame] | 579 | if (timeout == 0 && |
| 580 | life == last_life && signal_pending(current)) |
| 581 | break; |
| 582 | |
| 583 | if (life != last_life) { |
| 584 | timeout = rtt2; |
| 585 | last_life = life; |
| 586 | } |
| 587 | |
| 588 | timeout = schedule_timeout(timeout); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | remove_wait_queue(&call->waitq, &myself); |
| 592 | __set_current_state(TASK_RUNNING); |
| 593 | |
David Howells | 954cd6d | 2017-03-16 16:27:49 +0000 | [diff] [blame] | 594 | /* Kill off the call if it's still live. */ |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 595 | if (!afs_check_call_state(call, AFS_CALL_COMPLETE)) { |
David Howells | 954cd6d | 2017-03-16 16:27:49 +0000 | [diff] [blame] | 596 | _debug("call interrupted"); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 597 | if (rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 598 | RX_USER_ABORT, -EINTR, "KWI")) |
| 599 | afs_set_call_complete(call, -EINTR, 0); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 600 | } |
| 601 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 602 | spin_lock_bh(&call->state_lock); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 603 | ac->abort_code = call->abort_code; |
| 604 | ac->error = call->error; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 605 | spin_unlock_bh(&call->state_lock); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 606 | |
| 607 | ret = ac->error; |
| 608 | switch (ret) { |
| 609 | case 0: |
| 610 | if (call->ret_reply0) { |
| 611 | ret = (long)call->reply[0]; |
| 612 | call->reply[0] = NULL; |
| 613 | } |
| 614 | /* Fall through */ |
| 615 | case -ECONNABORTED: |
| 616 | ac->responded = true; |
| 617 | break; |
David Howells | 33cd7f2 | 2017-11-02 15:27:48 +0000 | [diff] [blame] | 618 | } |
| 619 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 620 | _debug("call complete"); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 621 | afs_put_call(call); |
David Howells | 33cd7f2 | 2017-11-02 15:27:48 +0000 | [diff] [blame] | 622 | _leave(" = %p", (void *)ret); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 623 | return ret; |
| 624 | } |
| 625 | |
| 626 | /* |
| 627 | * wake up a waiting call |
| 628 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 629 | static void afs_wake_up_call_waiter(struct sock *sk, struct rxrpc_call *rxcall, |
| 630 | unsigned long call_user_ID) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 631 | { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 632 | struct afs_call *call = (struct afs_call *)call_user_ID; |
| 633 | |
| 634 | call->need_attention = true; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 635 | wake_up(&call->waitq); |
| 636 | } |
| 637 | |
| 638 | /* |
| 639 | * wake up an asynchronous call |
| 640 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 641 | static void afs_wake_up_async_call(struct sock *sk, struct rxrpc_call *rxcall, |
| 642 | unsigned long call_user_ID) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 643 | { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 644 | struct afs_call *call = (struct afs_call *)call_user_ID; |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 645 | int u; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 646 | |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 647 | trace_afs_notify_call(rxcall, call); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 648 | call->need_attention = true; |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 649 | |
Mark Rutland | bfc18e3 | 2018-06-21 13:13:04 +0100 | [diff] [blame] | 650 | u = atomic_fetch_add_unless(&call->usage, 1, 0); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 651 | if (u != 0) { |
| 652 | trace_afs_call(call, afs_call_trace_wake, u, |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 653 | atomic_read(&call->net->nr_outstanding_calls), |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 654 | __builtin_return_address(0)); |
| 655 | |
| 656 | if (!queue_work(afs_async_calls, &call->async_work)) |
| 657 | afs_put_call(call); |
| 658 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | /* |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 662 | * Delete an asynchronous call. The work item carries a ref to the call struct |
| 663 | * that we need to release. |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 664 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 665 | static void afs_delete_async_call(struct work_struct *work) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 666 | { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 667 | struct afs_call *call = container_of(work, struct afs_call, async_work); |
| 668 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 669 | _enter(""); |
| 670 | |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 671 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 672 | |
| 673 | _leave(""); |
| 674 | } |
| 675 | |
| 676 | /* |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 677 | * Perform I/O processing on an asynchronous call. The work item carries a ref |
| 678 | * to the call struct that we either need to release or to pass on. |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 679 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 680 | static void afs_process_async_call(struct work_struct *work) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 681 | { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 682 | struct afs_call *call = container_of(work, struct afs_call, async_work); |
| 683 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 684 | _enter(""); |
| 685 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 686 | if (call->state < AFS_CALL_COMPLETE && call->need_attention) { |
| 687 | call->need_attention = false; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 688 | afs_deliver_to_call(call); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 689 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 690 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 691 | if (call->state == AFS_CALL_COMPLETE) { |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 692 | /* We have two refs to release - one from the alloc and one |
| 693 | * queued with the work item - and we can't just deallocate the |
| 694 | * call because the work item may be queued again. |
| 695 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 696 | call->async_work.func = afs_delete_async_call; |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 697 | if (!queue_work(afs_async_calls, &call->async_work)) |
| 698 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 699 | } |
| 700 | |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 701 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 702 | _leave(""); |
| 703 | } |
| 704 | |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 705 | static void afs_rx_attach(struct rxrpc_call *rxcall, unsigned long user_call_ID) |
| 706 | { |
| 707 | struct afs_call *call = (struct afs_call *)user_call_ID; |
| 708 | |
| 709 | call->rxcall = rxcall; |
| 710 | } |
| 711 | |
| 712 | /* |
| 713 | * Charge the incoming call preallocation. |
| 714 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 715 | void afs_charge_preallocation(struct work_struct *work) |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 716 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 717 | struct afs_net *net = |
| 718 | container_of(work, struct afs_net, charge_preallocation_work); |
| 719 | struct afs_call *call = net->spare_incoming_call; |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 720 | |
| 721 | for (;;) { |
| 722 | if (!call) { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 723 | call = afs_alloc_call(net, &afs_RXCMxxxx, GFP_KERNEL); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 724 | if (!call) |
| 725 | break; |
| 726 | |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 727 | call->async = true; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 728 | call->state = AFS_CALL_SV_AWAIT_OP_ID; |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 729 | init_waitqueue_head(&call->waitq); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 730 | } |
| 731 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 732 | if (rxrpc_kernel_charge_accept(net->socket, |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 733 | afs_wake_up_async_call, |
| 734 | afs_rx_attach, |
| 735 | (unsigned long)call, |
David Howells | a25e21f | 2018-03-27 23:03:00 +0100 | [diff] [blame] | 736 | GFP_KERNEL, |
| 737 | call->debug_id) < 0) |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 738 | break; |
| 739 | call = NULL; |
| 740 | } |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 741 | net->spare_incoming_call = call; |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | /* |
| 745 | * Discard a preallocated call when a socket is shut down. |
| 746 | */ |
| 747 | static void afs_rx_discard_new_call(struct rxrpc_call *rxcall, |
| 748 | unsigned long user_call_ID) |
| 749 | { |
| 750 | struct afs_call *call = (struct afs_call *)user_call_ID; |
| 751 | |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 752 | call->rxcall = NULL; |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 753 | afs_put_call(call); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 754 | } |
| 755 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 756 | /* |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 757 | * Notification of an incoming call. |
| 758 | */ |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 759 | static void afs_rx_new_call(struct sock *sk, struct rxrpc_call *rxcall, |
| 760 | unsigned long user_call_ID) |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 761 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 762 | struct afs_net *net = afs_sock2net(sk); |
| 763 | |
| 764 | queue_work(afs_wq, &net->charge_preallocation_work); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | /* |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 768 | * Grab the operation ID from an incoming cache manager call. The socket |
| 769 | * buffer is discarded on error or if we don't yet have sufficient data. |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 770 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 771 | static int afs_deliver_cm_op_id(struct afs_call *call) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 772 | { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 773 | int ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 774 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 775 | _enter("{%zu}", call->offset); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 776 | |
| 777 | ASSERTCMP(call->offset, <, 4); |
| 778 | |
| 779 | /* the operation ID forms the first four bytes of the request data */ |
David Howells | 50a2c95 | 2016-10-13 08:27:10 +0100 | [diff] [blame] | 780 | ret = afs_extract_data(call, &call->tmp, 4, true); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 781 | if (ret < 0) |
| 782 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 783 | |
David Howells | 50a2c95 | 2016-10-13 08:27:10 +0100 | [diff] [blame] | 784 | call->operation_ID = ntohl(call->tmp); |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 785 | afs_set_call_state(call, AFS_CALL_SV_AWAIT_OP_ID, AFS_CALL_SV_AWAIT_REQUEST); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 786 | call->offset = 0; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 787 | |
| 788 | /* ask the cache manager to route the call (it'll change the call type |
| 789 | * if successful) */ |
| 790 | if (!afs_cm_incoming_call(call)) |
| 791 | return -ENOTSUPP; |
| 792 | |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 793 | trace_afs_cb_call(call); |
| 794 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 795 | /* pass responsibility for the remainer of this message off to the |
| 796 | * cache manager op */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 797 | return call->type->deliver(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | /* |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 801 | * Advance the AFS call state when an RxRPC service call ends the transmit |
| 802 | * phase. |
| 803 | */ |
| 804 | static void afs_notify_end_reply_tx(struct sock *sock, |
| 805 | struct rxrpc_call *rxcall, |
| 806 | unsigned long call_user_ID) |
| 807 | { |
| 808 | struct afs_call *call = (struct afs_call *)call_user_ID; |
| 809 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 810 | afs_set_call_state(call, AFS_CALL_SV_REPLYING, AFS_CALL_SV_AWAIT_ACK); |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 814 | * send an empty reply |
| 815 | */ |
| 816 | void afs_send_empty_reply(struct afs_call *call) |
| 817 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 818 | struct afs_net *net = call->net; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 819 | struct msghdr msg; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 820 | |
| 821 | _enter(""); |
| 822 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 823 | rxrpc_kernel_set_tx_length(net->socket, call->rxcall, 0); |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 824 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 825 | msg.msg_name = NULL; |
| 826 | msg.msg_namelen = 0; |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame^] | 827 | iov_iter_kvec(&msg.msg_iter, WRITE, NULL, 0, 0); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 828 | msg.msg_control = NULL; |
| 829 | msg.msg_controllen = 0; |
| 830 | msg.msg_flags = 0; |
| 831 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 832 | switch (rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, 0, |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 833 | afs_notify_end_reply_tx)) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 834 | case 0: |
| 835 | _leave(" [replied]"); |
| 836 | return; |
| 837 | |
| 838 | case -ENOMEM: |
| 839 | _debug("oom"); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 840 | rxrpc_kernel_abort_call(net->socket, call->rxcall, |
David Howells | 3a92789 | 2017-04-06 10:11:56 +0100 | [diff] [blame] | 841 | RX_USER_ABORT, -ENOMEM, "KOO"); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 842 | default: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 843 | _leave(" [error]"); |
| 844 | return; |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | /* |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 849 | * send a simple reply |
| 850 | */ |
| 851 | void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len) |
| 852 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 853 | struct afs_net *net = call->net; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 854 | struct msghdr msg; |
Al Viro | 2e90b1c | 2014-11-27 21:50:31 -0500 | [diff] [blame] | 855 | struct kvec iov[1]; |
David Howells | bd6dc74 | 2007-07-20 10:59:41 +0100 | [diff] [blame] | 856 | int n; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 857 | |
| 858 | _enter(""); |
| 859 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 860 | rxrpc_kernel_set_tx_length(net->socket, call->rxcall, len); |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 861 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 862 | iov[0].iov_base = (void *) buf; |
| 863 | iov[0].iov_len = len; |
| 864 | msg.msg_name = NULL; |
| 865 | msg.msg_namelen = 0; |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame^] | 866 | iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 867 | msg.msg_control = NULL; |
| 868 | msg.msg_controllen = 0; |
| 869 | msg.msg_flags = 0; |
| 870 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 871 | n = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, len, |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 872 | afs_notify_end_reply_tx); |
David Howells | bd6dc74 | 2007-07-20 10:59:41 +0100 | [diff] [blame] | 873 | if (n >= 0) { |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 874 | /* Success */ |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 875 | _leave(" [replied]"); |
| 876 | return; |
David Howells | bd6dc74 | 2007-07-20 10:59:41 +0100 | [diff] [blame] | 877 | } |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 878 | |
David Howells | bd6dc74 | 2007-07-20 10:59:41 +0100 | [diff] [blame] | 879 | if (n == -ENOMEM) { |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 880 | _debug("oom"); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 881 | rxrpc_kernel_abort_call(net->socket, call->rxcall, |
David Howells | 3a92789 | 2017-04-06 10:11:56 +0100 | [diff] [blame] | 882 | RX_USER_ABORT, -ENOMEM, "KOO"); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 883 | } |
David Howells | bd6dc74 | 2007-07-20 10:59:41 +0100 | [diff] [blame] | 884 | _leave(" [error]"); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | /* |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 888 | * Extract a piece of data from the received data socket buffers. |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 889 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 890 | int afs_extract_data(struct afs_call *call, void *buf, size_t count, |
| 891 | bool want_more) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 892 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 893 | struct afs_net *net = call->net; |
David Howells | eb9950e | 2018-08-03 17:06:56 +0100 | [diff] [blame] | 894 | struct iov_iter iter; |
| 895 | struct kvec iov; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 896 | enum afs_call_state state; |
Dan Carpenter | 7888da9 | 2018-01-02 10:02:19 +0000 | [diff] [blame] | 897 | u32 remote_abort = 0; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 898 | int ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 899 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 900 | _enter("{%s,%zu},,%zu,%d", |
| 901 | call->type->name, call->offset, count, want_more); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 902 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 903 | ASSERTCMP(call->offset, <=, count); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 904 | |
David Howells | eb9950e | 2018-08-03 17:06:56 +0100 | [diff] [blame] | 905 | iov.iov_base = buf + call->offset; |
| 906 | iov.iov_len = count - call->offset; |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame^] | 907 | iov_iter_kvec(&iter, READ, &iov, 1, count - call->offset); |
David Howells | eb9950e | 2018-08-03 17:06:56 +0100 | [diff] [blame] | 908 | |
| 909 | ret = rxrpc_kernel_recv_data(net->socket, call->rxcall, &iter, |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 910 | want_more, &remote_abort, |
David Howells | a68f4a2 | 2017-10-18 11:36:39 +0100 | [diff] [blame] | 911 | &call->service_id); |
David Howells | eb9950e | 2018-08-03 17:06:56 +0100 | [diff] [blame] | 912 | call->offset += (count - call->offset) - iov_iter_count(&iter); |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 913 | trace_afs_recv_data(call, count, call->offset, want_more, ret); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 914 | if (ret == 0 || ret == -EAGAIN) |
| 915 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 916 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 917 | state = READ_ONCE(call->state); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 918 | if (ret == 1) { |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 919 | switch (state) { |
| 920 | case AFS_CALL_CL_AWAIT_REPLY: |
| 921 | afs_set_call_state(call, state, AFS_CALL_CL_PROC_REPLY); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 922 | break; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 923 | case AFS_CALL_SV_AWAIT_REQUEST: |
| 924 | afs_set_call_state(call, state, AFS_CALL_SV_REPLYING); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 925 | break; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 926 | case AFS_CALL_COMPLETE: |
| 927 | kdebug("prem complete %d", call->error); |
| 928 | return -EIO; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 929 | default: |
| 930 | break; |
| 931 | } |
| 932 | return 0; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 933 | } |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 934 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 935 | afs_set_call_complete(call, ret, remote_abort); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 936 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 937 | } |
David Howells | 5f702c8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 938 | |
| 939 | /* |
| 940 | * Log protocol error production. |
| 941 | */ |
| 942 | noinline int afs_protocol_error(struct afs_call *call, int error) |
| 943 | { |
| 944 | trace_afs_protocol_error(call, error, __builtin_return_address(0)); |
| 945 | return error; |
| 946 | } |