~ [ 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.1.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 !! 330  */
                                                   >> 331 static int afs_send_pages(struct afs_call *call, struct msghdr *msg)
                                                   >> 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
331  */                                               365  */
332 void afs_make_call(struct afs_call *call, gfp_ !! 366 long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,
                                                   >> 367                    gfp_t gfp, bool async)
333 {                                                 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:                  << 
577                 case -EFAULT:                  << 
578                         abort_code = RXGEN_CC_    575                         abort_code = RXGEN_CC_UNMARSHAL;
579                         if (state != AFS_CALL_    576                         if (state != AFS_CALL_CL_AWAIT_REPLY)
580                                 abort_code = R    577                                 abort_code = RXGEN_SS_UNMARSHAL;
581                         rxrpc_kernel_abort_cal    578                         rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
582                                                !! 579                                                 abort_code, ret, "KUM");
583                                                << 
584                         goto local_abort;         580                         goto local_abort;
585                 default:                          581                 default:
586                         abort_code = RX_CALL_D !! 582                         abort_code = RX_USER_ABORT;
587                         rxrpc_kernel_abort_cal    583                         rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
588                                                !! 584                                                 abort_code, ret, "KER");
589                                                << 
590                         goto local_abort;         585                         goto local_abort;
591                 }                                 586                 }
592         }                                         587         }
593                                                   588 
594 done:                                             589 done:
595         if (call->type->done)                     590         if (call->type->done)
596                 call->type->done(call);           591                 call->type->done(call);
                                                   >> 592         if (state == AFS_CALL_COMPLETE && call->incoming)
                                                   >> 593                 afs_put_call(call);
597 out:                                              594 out:
598         _leave("");                               595         _leave("");
599         return;                                   596         return;
600                                                   597 
601 local_abort:                                      598 local_abort:
602         abort_code = 0;                           599         abort_code = 0;
603 call_complete:                                    600 call_complete:
604         afs_set_call_complete(call, ret, remot    601         afs_set_call_complete(call, ret, remote_abort);
605         state = AFS_CALL_COMPLETE;                602         state = AFS_CALL_COMPLETE;
606         goto done;                                603         goto done;
607 }                                                 604 }
608                                                   605 
609 /*                                                606 /*
610  * Wait synchronously for a call to complete.  !! 607  * wait synchronously for a call to complete
611  */                                               608  */
612 void afs_wait_for_call_to_complete(struct afs_ !! 609 static long afs_wait_for_call_to_complete(struct afs_call *call,
                                                   >> 610                                           struct afs_addr_cursor *ac)
613 {                                                 611 {
                                                   >> 612         signed long rtt2, timeout;
                                                   >> 613         long ret;
                                                   >> 614         bool stalled = false;
                                                   >> 615         u64 rtt;
                                                   >> 616         u32 life, last_life;
614         bool rxrpc_complete = false;              617         bool rxrpc_complete = false;
615                                                   618 
                                                   >> 619         DECLARE_WAITQUEUE(myself, current);
                                                   >> 620 
616         _enter("");                               621         _enter("");
617                                                   622 
618         if (!afs_check_call_state(call, AFS_CA !! 623         rtt = rxrpc_kernel_get_rtt(call->net->socket, call->rxcall);
619                 DECLARE_WAITQUEUE(myself, curr !! 624         rtt2 = nsecs_to_jiffies64(rtt) * 2;
                                                   >> 625         if (rtt2 < 2)
                                                   >> 626                 rtt2 = 2;
620                                                   627 
621                 add_wait_queue(&call->waitq, & !! 628         timeout = rtt2;
622                 for (;;) {                     !! 629         rxrpc_kernel_check_life(call->net->socket, call->rxcall, &last_life);
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                                                   630 
634                         if (afs_check_call_sta !! 631         add_wait_queue(&call->waitq, &myself);
635                                 break;         !! 632         for (;;) {
                                                   >> 633                 set_current_state(TASK_UNINTERRUPTIBLE);
                                                   >> 634 
                                                   >> 635                 /* deliver any messages that are in the queue */
                                                   >> 636                 if (!afs_check_call_state(call, AFS_CALL_COMPLETE) &&
                                                   >> 637                     call->need_attention) {
                                                   >> 638                         call->need_attention = false;
                                                   >> 639                         __set_current_state(TASK_RUNNING);
                                                   >> 640                         afs_deliver_to_call(call);
                                                   >> 641                         continue;
                                                   >> 642                 }
636                                                   643 
637                         if (!rxrpc_kernel_chec !! 644                 if (afs_check_call_state(call, AFS_CALL_COMPLETE))
638                                 /* rxrpc termi !! 645                         break;
639                                 rxrpc_complete !! 646 
                                                   >> 647                 if (!rxrpc_kernel_check_life(call->net->socket, call->rxcall, &life)) {
                                                   >> 648                         /* rxrpc terminated the call. */
                                                   >> 649                         rxrpc_complete = true;
                                                   >> 650                         break;
                                                   >> 651                 }
                                                   >> 652 
                                                   >> 653                 if (timeout == 0 &&
                                                   >> 654                     life == last_life && signal_pending(current)) {
                                                   >> 655                         if (stalled)
640                                 break;            656                                 break;
641                         }                      !! 657                         __set_current_state(TASK_RUNNING);
                                                   >> 658                         rxrpc_kernel_probe_life(call->net->socket, call->rxcall);
                                                   >> 659                         timeout = rtt2;
                                                   >> 660                         stalled = true;
                                                   >> 661                         continue;
                                                   >> 662                 }
642                                                   663 
643                         schedule();            !! 664                 if (life != last_life) {
                                                   >> 665                         timeout = rtt2;
                                                   >> 666                         last_life = life;
                                                   >> 667                         stalled = false;
644                 }                                 668                 }
645                                                   669 
646                 remove_wait_queue(&call->waitq !! 670                 timeout = schedule_timeout(timeout);
647                 __set_current_state(TASK_RUNNI << 
648         }                                         671         }
649                                                   672 
                                                   >> 673         remove_wait_queue(&call->waitq, &myself);
                                                   >> 674         __set_current_state(TASK_RUNNING);
                                                   >> 675 
650         if (!afs_check_call_state(call, AFS_CA    676         if (!afs_check_call_state(call, AFS_CALL_COMPLETE)) {
651                 if (rxrpc_complete) {             677                 if (rxrpc_complete) {
652                         afs_set_call_complete(    678                         afs_set_call_complete(call, call->error, call->abort_code);
653                 } else {                          679                 } else {
654                         /* Kill off the call i    680                         /* Kill off the call if it's still live. */
655                         _debug("call interrupt    681                         _debug("call interrupted");
656                         if (rxrpc_kernel_abort    682                         if (rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
657                                                !! 683                                                     RX_USER_ABORT, -EINTR, "KWI"))
658                                                << 
659                                 afs_set_call_c    684                                 afs_set_call_complete(call, -EINTR, 0);
660                 }                                 685                 }
661         }                                         686         }
                                                   >> 687 
                                                   >> 688         spin_lock_bh(&call->state_lock);
                                                   >> 689         ac->abort_code = call->abort_code;
                                                   >> 690         ac->error = call->error;
                                                   >> 691         spin_unlock_bh(&call->state_lock);
                                                   >> 692 
                                                   >> 693         ret = ac->error;
                                                   >> 694         switch (ret) {
                                                   >> 695         case 0:
                                                   >> 696                 if (call->ret_reply0) {
                                                   >> 697                         ret = (long)call->reply[0];
                                                   >> 698                         call->reply[0] = NULL;
                                                   >> 699                 }
                                                   >> 700                 /* Fall through */
                                                   >> 701         case -ECONNABORTED:
                                                   >> 702                 ac->responded = true;
                                                   >> 703                 break;
                                                   >> 704         }
                                                   >> 705 
                                                   >> 706         _debug("call complete");
                                                   >> 707         afs_put_call(call);
                                                   >> 708         _leave(" = %p", (void *)ret);
                                                   >> 709         return ret;
662 }                                                 710 }
663                                                   711 
664 /*                                                712 /*
665  * wake up a waiting call                         713  * wake up a waiting call
666  */                                               714  */
667 static void afs_wake_up_call_waiter(struct soc    715 static void afs_wake_up_call_waiter(struct sock *sk, struct rxrpc_call *rxcall,
668                                     unsigned l    716                                     unsigned long call_user_ID)
669 {                                                 717 {
670         struct afs_call *call = (struct afs_ca    718         struct afs_call *call = (struct afs_call *)call_user_ID;
671                                                   719 
672         call->need_attention = true;              720         call->need_attention = true;
673         wake_up(&call->waitq);                    721         wake_up(&call->waitq);
674 }                                                 722 }
675                                                   723 
676 /*                                                724 /*
677  * Wake up an asynchronous call.  The caller i !! 725  * wake up an asynchronous call
678  * spinlock around this, so we can't call afs_ << 
679  */                                               726  */
680 static void afs_wake_up_async_call(struct sock    727 static void afs_wake_up_async_call(struct sock *sk, struct rxrpc_call *rxcall,
681                                    unsigned lo    728                                    unsigned long call_user_ID)
682 {                                                 729 {
683         struct afs_call *call = (struct afs_ca    730         struct afs_call *call = (struct afs_call *)call_user_ID;
684         int r;                                 !! 731         int u;
685                                                   732 
686         trace_afs_notify_call(rxcall, call);      733         trace_afs_notify_call(rxcall, call);
687         call->need_attention = true;              734         call->need_attention = true;
688                                                   735 
689         if (__refcount_inc_not_zero(&call->ref !! 736         u = atomic_fetch_add_unless(&call->usage, 1, 0);
690                 trace_afs_call(call->debug_id, !! 737         if (u != 0) {
                                                   >> 738                 trace_afs_call(call, afs_call_trace_wake, u,
691                                atomic_read(&ca    739                                atomic_read(&call->net->nr_outstanding_calls),
692                                __builtin_retur    740                                __builtin_return_address(0));
693                                                   741 
694                 if (!queue_work(afs_async_call    742                 if (!queue_work(afs_async_calls, &call->async_work))
695                         afs_deferred_put_call( !! 743                         afs_put_call(call);
696         }                                         744         }
697 }                                                 745 }
698                                                   746 
699 /*                                                747 /*
                                                   >> 748  * Delete an asynchronous call.  The work item carries a ref to the call struct
                                                   >> 749  * that we need to release.
                                                   >> 750  */
                                                   >> 751 static void afs_delete_async_call(struct work_struct *work)
                                                   >> 752 {
                                                   >> 753         struct afs_call *call = container_of(work, struct afs_call, async_work);
                                                   >> 754 
                                                   >> 755         _enter("");
                                                   >> 756 
                                                   >> 757         afs_put_call(call);
                                                   >> 758 
                                                   >> 759         _leave("");
                                                   >> 760 }
                                                   >> 761 
                                                   >> 762 /*
700  * Perform I/O processing on an asynchronous c    763  * 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    764  * to the call struct that we either need to release or to pass on.
702  */                                               765  */
703 static void afs_process_async_call(struct work    766 static void afs_process_async_call(struct work_struct *work)
704 {                                                 767 {
705         struct afs_call *call = container_of(w    768         struct afs_call *call = container_of(work, struct afs_call, async_work);
706                                                   769 
707         _enter("");                               770         _enter("");
708                                                   771 
709         if (call->state < AFS_CALL_COMPLETE &&    772         if (call->state < AFS_CALL_COMPLETE && call->need_attention) {
710                 call->need_attention = false;     773                 call->need_attention = false;
711                 afs_deliver_to_call(call);        774                 afs_deliver_to_call(call);
712         }                                         775         }
713                                                   776 
                                                   >> 777         if (call->state == AFS_CALL_COMPLETE) {
                                                   >> 778                 /* We have two refs to release - one from the alloc and one
                                                   >> 779                  * queued with the work item - and we can't just deallocate the
                                                   >> 780                  * call because the work item may be queued again.
                                                   >> 781                  */
                                                   >> 782                 call->async_work.func = afs_delete_async_call;
                                                   >> 783                 if (!queue_work(afs_async_calls, &call->async_work))
                                                   >> 784                         afs_put_call(call);
                                                   >> 785         }
                                                   >> 786 
714         afs_put_call(call);                       787         afs_put_call(call);
715         _leave("");                               788         _leave("");
716 }                                                 789 }
717                                                   790 
718 static void afs_rx_attach(struct rxrpc_call *r    791 static void afs_rx_attach(struct rxrpc_call *rxcall, unsigned long user_call_ID)
719 {                                                 792 {
720         struct afs_call *call = (struct afs_ca    793         struct afs_call *call = (struct afs_call *)user_call_ID;
721                                                   794 
722         call->rxcall = rxcall;                    795         call->rxcall = rxcall;
723 }                                                 796 }
724                                                   797 
725 /*                                                798 /*
726  * Charge the incoming call preallocation.        799  * Charge the incoming call preallocation.
727  */                                               800  */
728 void afs_charge_preallocation(struct work_stru    801 void afs_charge_preallocation(struct work_struct *work)
729 {                                                 802 {
730         struct afs_net *net =                     803         struct afs_net *net =
731                 container_of(work, struct afs_    804                 container_of(work, struct afs_net, charge_preallocation_work);
732         struct afs_call *call = net->spare_inc    805         struct afs_call *call = net->spare_incoming_call;
733                                                   806 
734         for (;;) {                                807         for (;;) {
735                 if (!call) {                      808                 if (!call) {
736                         call = afs_alloc_call(    809                         call = afs_alloc_call(net, &afs_RXCMxxxx, GFP_KERNEL);
737                         if (!call)                810                         if (!call)
738                                 break;            811                                 break;
739                                                   812 
740                         call->drop_ref = true; << 
741                         call->async = true;       813                         call->async = true;
742                         call->state = AFS_CALL    814                         call->state = AFS_CALL_SV_AWAIT_OP_ID;
743                         init_waitqueue_head(&c    815                         init_waitqueue_head(&call->waitq);
744                         afs_extract_to_tmp(cal    816                         afs_extract_to_tmp(call);
745                 }                                 817                 }
746                                                   818 
747                 if (rxrpc_kernel_charge_accept    819                 if (rxrpc_kernel_charge_accept(net->socket,
748                                                   820                                                afs_wake_up_async_call,
749                                                   821                                                afs_rx_attach,
750                                                   822                                                (unsigned long)call,
751                                                   823                                                GFP_KERNEL,
752                                                   824                                                call->debug_id) < 0)
753                         break;                    825                         break;
754                 call = NULL;                      826                 call = NULL;
755         }                                         827         }
756         net->spare_incoming_call = call;          828         net->spare_incoming_call = call;
757 }                                                 829 }
758                                                   830 
759 /*                                                831 /*
760  * Discard a preallocated call when a socket i    832  * Discard a preallocated call when a socket is shut down.
761  */                                               833  */
762 static void afs_rx_discard_new_call(struct rxr    834 static void afs_rx_discard_new_call(struct rxrpc_call *rxcall,
763                                     unsigned l    835                                     unsigned long user_call_ID)
764 {                                                 836 {
765         struct afs_call *call = (struct afs_ca    837         struct afs_call *call = (struct afs_call *)user_call_ID;
766                                                   838 
767         call->rxcall = NULL;                      839         call->rxcall = NULL;
768         afs_put_call(call);                       840         afs_put_call(call);
769 }                                                 841 }
770                                                   842 
771 /*                                                843 /*
772  * Notification of an incoming call.              844  * Notification of an incoming call.
773  */                                               845  */
774 static void afs_rx_new_call(struct sock *sk, s    846 static void afs_rx_new_call(struct sock *sk, struct rxrpc_call *rxcall,
775                             unsigned long user    847                             unsigned long user_call_ID)
776 {                                                 848 {
777         struct afs_net *net = afs_sock2net(sk)    849         struct afs_net *net = afs_sock2net(sk);
778                                                   850 
779         queue_work(afs_wq, &net->charge_preall    851         queue_work(afs_wq, &net->charge_preallocation_work);
780 }                                                 852 }
781                                                   853 
782 /*                                                854 /*
783  * Grab the operation ID from an incoming cach    855  * Grab the operation ID from an incoming cache manager call.  The socket
784  * buffer is discarded on error or if we don't    856  * buffer is discarded on error or if we don't yet have sufficient data.
785  */                                               857  */
786 static int afs_deliver_cm_op_id(struct afs_cal    858 static int afs_deliver_cm_op_id(struct afs_call *call)
787 {                                                 859 {
788         int ret;                                  860         int ret;
789                                                   861 
790         _enter("{%zu}", iov_iter_count(call->i !! 862         _enter("{%zu}", iov_iter_count(call->_iter));
791                                                   863 
792         /* the operation ID forms the first fo    864         /* the operation ID forms the first four bytes of the request data */
793         ret = afs_extract_data(call, true);       865         ret = afs_extract_data(call, true);
794         if (ret < 0)                              866         if (ret < 0)
795                 return ret;                       867                 return ret;
796                                                   868 
797         call->operation_ID = ntohl(call->tmp);    869         call->operation_ID = ntohl(call->tmp);
798         afs_set_call_state(call, AFS_CALL_SV_A    870         afs_set_call_state(call, AFS_CALL_SV_AWAIT_OP_ID, AFS_CALL_SV_AWAIT_REQUEST);
799                                                   871 
800         /* ask the cache manager to route the     872         /* ask the cache manager to route the call (it'll change the call type
801          * if successful) */                      873          * if successful) */
802         if (!afs_cm_incoming_call(call))          874         if (!afs_cm_incoming_call(call))
803                 return -ENOTSUPP;                 875                 return -ENOTSUPP;
804                                                   876 
805         trace_afs_cb_call(call);                  877         trace_afs_cb_call(call);
806                                                   878 
807         /* pass responsibility for the remaine    879         /* pass responsibility for the remainer of this message off to the
808          * cache manager op */                    880          * cache manager op */
809         return call->type->deliver(call);         881         return call->type->deliver(call);
810 }                                                 882 }
811                                                   883 
812 /*                                                884 /*
813  * Advance the AFS call state when an RxRPC se    885  * Advance the AFS call state when an RxRPC service call ends the transmit
814  * phase.                                         886  * phase.
815  */                                               887  */
816 static void afs_notify_end_reply_tx(struct soc    888 static void afs_notify_end_reply_tx(struct sock *sock,
817                                     struct rxr    889                                     struct rxrpc_call *rxcall,
818                                     unsigned l    890                                     unsigned long call_user_ID)
819 {                                                 891 {
820         struct afs_call *call = (struct afs_ca    892         struct afs_call *call = (struct afs_call *)call_user_ID;
821                                                   893 
822         afs_set_call_state(call, AFS_CALL_SV_R    894         afs_set_call_state(call, AFS_CALL_SV_REPLYING, AFS_CALL_SV_AWAIT_ACK);
823 }                                                 895 }
824                                                   896 
825 /*                                                897 /*
826  * send an empty reply                            898  * send an empty reply
827  */                                               899  */
828 void afs_send_empty_reply(struct afs_call *cal    900 void afs_send_empty_reply(struct afs_call *call)
829 {                                                 901 {
830         struct afs_net *net = call->net;          902         struct afs_net *net = call->net;
831         struct msghdr msg;                        903         struct msghdr msg;
832                                                   904 
833         _enter("");                               905         _enter("");
834                                                   906 
835         rxrpc_kernel_set_tx_length(net->socket    907         rxrpc_kernel_set_tx_length(net->socket, call->rxcall, 0);
836                                                   908 
837         msg.msg_name            = NULL;           909         msg.msg_name            = NULL;
838         msg.msg_namelen         = 0;              910         msg.msg_namelen         = 0;
839         iov_iter_kvec(&msg.msg_iter, ITER_SOUR !! 911         iov_iter_kvec(&msg.msg_iter, WRITE, NULL, 0, 0);
840         msg.msg_control         = NULL;           912         msg.msg_control         = NULL;
841         msg.msg_controllen      = 0;              913         msg.msg_controllen      = 0;
842         msg.msg_flags           = 0;              914         msg.msg_flags           = 0;
843                                                   915 
844         switch (rxrpc_kernel_send_data(net->so    916         switch (rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, 0,
845                                        afs_not    917                                        afs_notify_end_reply_tx)) {
846         case 0:                                   918         case 0:
847                 _leave(" [replied]");             919                 _leave(" [replied]");
848                 return;                           920                 return;
849                                                   921 
850         case -ENOMEM:                             922         case -ENOMEM:
851                 _debug("oom");                    923                 _debug("oom");
852                 rxrpc_kernel_abort_call(net->s    924                 rxrpc_kernel_abort_call(net->socket, call->rxcall,
853                                         RXGEN_ !! 925                                         RX_USER_ABORT, -ENOMEM, "KOO");
854                                         afs_ab << 
855                 fallthrough;                   << 
856         default:                                  926         default:
857                 _leave(" [error]");               927                 _leave(" [error]");
858                 return;                           928                 return;
859         }                                         929         }
860 }                                                 930 }
861                                                   931 
862 /*                                                932 /*
863  * send a simple reply                            933  * send a simple reply
864  */                                               934  */
865 void afs_send_simple_reply(struct afs_call *ca    935 void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len)
866 {                                                 936 {
867         struct afs_net *net = call->net;          937         struct afs_net *net = call->net;
868         struct msghdr msg;                        938         struct msghdr msg;
869         struct kvec iov[1];                       939         struct kvec iov[1];
870         int n;                                    940         int n;
871                                                   941 
872         _enter("");                               942         _enter("");
873                                                   943 
874         rxrpc_kernel_set_tx_length(net->socket    944         rxrpc_kernel_set_tx_length(net->socket, call->rxcall, len);
875                                                   945 
876         iov[0].iov_base         = (void *) buf    946         iov[0].iov_base         = (void *) buf;
877         iov[0].iov_len          = len;            947         iov[0].iov_len          = len;
878         msg.msg_name            = NULL;           948         msg.msg_name            = NULL;
879         msg.msg_namelen         = 0;              949         msg.msg_namelen         = 0;
880         iov_iter_kvec(&msg.msg_iter, ITER_SOUR !! 950         iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len);
881         msg.msg_control         = NULL;           951         msg.msg_control         = NULL;
882         msg.msg_controllen      = 0;              952         msg.msg_controllen      = 0;
883         msg.msg_flags           = 0;              953         msg.msg_flags           = 0;
884                                                   954 
885         n = rxrpc_kernel_send_data(net->socket    955         n = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, len,
886                                    afs_notify_    956                                    afs_notify_end_reply_tx);
887         if (n >= 0) {                             957         if (n >= 0) {
888                 /* Success */                     958                 /* Success */
889                 _leave(" [replied]");             959                 _leave(" [replied]");
890                 return;                           960                 return;
891         }                                         961         }
892                                                   962 
893         if (n == -ENOMEM) {                       963         if (n == -ENOMEM) {
894                 _debug("oom");                    964                 _debug("oom");
895                 rxrpc_kernel_abort_call(net->s    965                 rxrpc_kernel_abort_call(net->socket, call->rxcall,
896                                         RXGEN_ !! 966                                         RX_USER_ABORT, -ENOMEM, "KOO");
897                                         afs_ab << 
898         }                                         967         }
899         _leave(" [error]");                       968         _leave(" [error]");
900 }                                                 969 }
901                                                   970 
902 /*                                                971 /*
903  * Extract a piece of data from the received d    972  * Extract a piece of data from the received data socket buffers.
904  */                                               973  */
905 int afs_extract_data(struct afs_call *call, bo    974 int afs_extract_data(struct afs_call *call, bool want_more)
906 {                                                 975 {
907         struct afs_net *net = call->net;          976         struct afs_net *net = call->net;
908         struct iov_iter *iter = call->iter;    !! 977         struct iov_iter *iter = call->_iter;
909         enum afs_call_state state;                978         enum afs_call_state state;
910         u32 remote_abort = 0;                     979         u32 remote_abort = 0;
911         int ret;                                  980         int ret;
912                                                   981 
913         _enter("{%s,%zu,%zu},%d",              !! 982         _enter("{%s,%zu},%d", call->type->name, iov_iter_count(iter), want_more);
914                call->type->name, call->iov_len << 
915                                                   983 
916         ret = rxrpc_kernel_recv_data(net->sock    984         ret = rxrpc_kernel_recv_data(net->socket, call->rxcall, iter,
917                                      &call->io !! 985                                      want_more, &remote_abort,
918                                      &call->se    986                                      &call->service_id);
919         trace_afs_receive_data(call, call->ite << 
920         if (ret == 0 || ret == -EAGAIN)           987         if (ret == 0 || ret == -EAGAIN)
921                 return ret;                       988                 return ret;
922                                                   989 
923         state = READ_ONCE(call->state);           990         state = READ_ONCE(call->state);
924         if (ret == 1) {                           991         if (ret == 1) {
925                 switch (state) {                  992                 switch (state) {
926                 case AFS_CALL_CL_AWAIT_REPLY:     993                 case AFS_CALL_CL_AWAIT_REPLY:
927                         afs_set_call_state(cal    994                         afs_set_call_state(call, state, AFS_CALL_CL_PROC_REPLY);
928                         break;                    995                         break;
929                 case AFS_CALL_SV_AWAIT_REQUEST    996                 case AFS_CALL_SV_AWAIT_REQUEST:
930                         afs_set_call_state(cal    997                         afs_set_call_state(call, state, AFS_CALL_SV_REPLYING);
931                         break;                    998                         break;
932                 case AFS_CALL_COMPLETE:           999                 case AFS_CALL_COMPLETE:
933                         kdebug("prem complete     1000                         kdebug("prem complete %d", call->error);
934                         return afs_io_error(ca    1001                         return afs_io_error(call, afs_io_error_extract);
935                 default:                          1002                 default:
936                         break;                    1003                         break;
937                 }                                 1004                 }
938                 return 0;                         1005                 return 0;
939         }                                         1006         }
940                                                   1007 
941         afs_set_call_complete(call, ret, remot    1008         afs_set_call_complete(call, ret, remote_abort);
942         return ret;                               1009         return ret;
943 }                                                 1010 }
944                                                   1011 
945 /*                                                1012 /*
946  * Log protocol error production.                 1013  * Log protocol error production.
947  */                                               1014  */
948 noinline int afs_protocol_error(struct afs_cal !! 1015 noinline int afs_protocol_error(struct afs_call *call, int error,
949                                 enum afs_eprot    1016                                 enum afs_eproto_cause cause)
950 {                                                 1017 {
951         trace_afs_protocol_error(call, cause); !! 1018         trace_afs_protocol_error(call, error, cause);
952         if (call)                              !! 1019         return error;
953                 call->unmarshalling_error = tr << 
954         return -EBADMSG;                       << 
955 }                                                 1020 }
956                                                   1021 

~ [ 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