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