~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/afs/rxrpc.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/afs/rxrpc.c (Version linux-6.12-rc7) and /fs/afs/rxrpc.c (Version linux-5.0.21)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php