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