~ [ 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 ccs-tools-1.8.12)


  1 // SPDX-License-Identifier: GPL-2.0-or-later        1 
  2 /* Maintain an RxRPC server socket to do AFS c    
  3  *                                                
  4  * Copyright (C) 2007 Red Hat, Inc. All Rights    
  5  * Written by David Howells (dhowells@redhat.c    
  6  */                                               
  7                                                   
  8 #include <linux/slab.h>                           
  9 #include <linux/sched/signal.h>                   
 10                                                   
 11 #include <net/sock.h>                             
 12 #include <net/af_rxrpc.h>                         
 13 #include "internal.h"                             
 14 #include "afs_cm.h"                               
 15 #include "protocol_yfs.h"                         
 16 #define RXRPC_TRACE_ONLY_DEFINE_ENUMS             
 17 #include <trace/events/rxrpc.h>                   
 18                                                   
 19 struct workqueue_struct *afs_async_calls;         
 20                                                   
 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_async_call(struct sock    
 24 static void afs_process_async_call(struct work    
 25 static void afs_rx_new_call(struct sock *, str    
 26 static void afs_rx_discard_new_call(struct rxr    
 27 static int afs_deliver_cm_op_id(struct afs_cal    
 28                                                   
 29 /* asynchronous incoming call initial processi    
 30 static const struct afs_call_type afs_RXCMxxxx    
 31         .name           = "CB.xxxx",              
 32         .deliver        = afs_deliver_cm_op_id    
 33 };                                                
 34                                                   
 35 /*                                                
 36  * open an RxRPC socket and bind it to be a se    
 37  * - the socket is left in blocking mode and n    
 38  */                                               
 39 int afs_open_socket(struct afs_net *net)          
 40 {                                                 
 41         struct sockaddr_rxrpc srx;                
 42         struct socket *socket;                    
 43         int ret;                                  
 44                                                   
 45         _enter("");                               
 46                                                   
 47         ret = sock_create_kern(net->net, AF_RX    
 48         if (ret < 0)                              
 49                 goto error_1;                     
 50                                                   
 51         socket->sk->sk_allocation = GFP_NOFS;     
 52                                                   
 53         /* bind the callback manager's address    
 54         memset(&srx, 0, sizeof(srx));             
 55         srx.srx_family                  = AF_R    
 56         srx.srx_service                 = CM_S    
 57         srx.transport_type              = SOCK    
 58         srx.transport_len               = size    
 59         srx.transport.sin6.sin6_family  = AF_I    
 60         srx.transport.sin6.sin6_port    = hton    
 61                                                   
 62         ret = rxrpc_sock_set_min_security_leve    
 63                                                   
 64         if (ret < 0)                              
 65                 goto error_2;                     
 66                                                   
 67         ret = kernel_bind(socket, (struct sock    
 68         if (ret == -EADDRINUSE) {                 
 69                 srx.transport.sin6.sin6_port =    
 70                 ret = kernel_bind(socket, (str    
 71         }                                         
 72         if (ret < 0)                              
 73                 goto error_2;                     
 74                                                   
 75         srx.srx_service = YFS_CM_SERVICE;         
 76         ret = kernel_bind(socket, (struct sock    
 77         if (ret < 0)                              
 78                 goto error_2;                     
 79                                                   
 80         /* Ideally, we'd turn on service upgra    
 81          * OpenAFS is buggy and leaks the user    
 82          * packet and between FS packets and C    
 83          * upgrade on an FS packet, OpenAFS wi    
 84          * it sends back to us.                   
 85          */                                       
 86                                                   
 87         rxrpc_kernel_new_call_notification(soc    
 88                                            afs    
 89                                                   
 90         ret = kernel_listen(socket, INT_MAX);     
 91         if (ret < 0)                              
 92                 goto error_2;                     
 93                                                   
 94         net->socket = socket;                     
 95         afs_charge_preallocation(&net->charge_    
 96         _leave(" = 0");                           
 97         return 0;                                 
 98                                                   
 99 error_2:                                          
100         sock_release(socket);                     
101 error_1:                                          
102         _leave(" = %d", ret);                     
103         return ret;                               
104 }                                                 
105                                                   
106 /*                                                
107  * close the RxRPC socket AFS was using           
108  */                                               
109 void afs_close_socket(struct afs_net *net)        
110 {                                                 
111         _enter("");                               
112                                                   
113         kernel_listen(net->socket, 0);            
114         flush_workqueue(afs_async_calls);         
115                                                   
116         if (net->spare_incoming_call) {           
117                 afs_put_call(net->spare_incomi    
118                 net->spare_incoming_call = NUL    
119         }                                         
120                                                   
121         _debug("outstanding %u", atomic_read(&    
122         wait_var_event(&net->nr_outstanding_ca    
123                        !atomic_read(&net->nr_o    
124         _debug("no outstanding calls");           
125                                                   
126         kernel_sock_shutdown(net->socket, SHUT    
127         flush_workqueue(afs_async_calls);         
128         sock_release(net->socket);                
129                                                   
130         _debug("dework");                         
131         _leave("");                               
132 }                                                 
133                                                   
134 /*                                                
135  * Allocate a call.                               
136  */                                               
137 static struct afs_call *afs_alloc_call(struct     
138                                        const s    
139                                        gfp_t g    
140 {                                                 
141         struct afs_call *call;                    
142         int o;                                    
143                                                   
144         call = kzalloc(sizeof(*call), gfp);       
145         if (!call)                                
146                 return NULL;                      
147                                                   
148         call->type = type;                        
149         call->net = net;                          
150         call->debug_id = atomic_inc_return(&rx    
151         refcount_set(&call->ref, 1);              
152         INIT_WORK(&call->async_work, afs_proce    
153         INIT_WORK(&call->free_work, afs_deferr    
154         init_waitqueue_head(&call->waitq);        
155         spin_lock_init(&call->state_lock);        
156         call->iter = &call->def_iter;             
157                                                   
158         o = atomic_inc_return(&net->nr_outstan    
159         trace_afs_call(call->debug_id, afs_cal    
160                        __builtin_return_addres    
161         return call;                              
162 }                                                 
163                                                   
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 /*                                                
195  * Dispose of a reference on a call.              
196  */                                               
197 void afs_put_call(struct afs_call *call)          
198 {                                                 
199         struct afs_net *net = call->net;          
200         unsigned int debug_id = call->debug_id    
201         bool zero;                                
202         int r, o;                                 
203                                                   
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    
208         if (zero)                                 
209                 afs_free_call(call);              
210 }                                                 
211                                                   
212 static void afs_deferred_free_worker(struct wo    
213 {                                                 
214         struct afs_call *call = container_of(w    
215                                                   
216         afs_free_call(call);                      
217 }                                                 
218                                                   
219 /*                                                
220  * Dispose of a reference on a call, deferring    
221  * to avoid lock recursion.                       
222  */                                               
223 void afs_deferred_put_call(struct afs_call *ca    
224 {                                                 
225         struct afs_net *net = call->net;          
226         unsigned int debug_id = call->debug_id    
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 }                                                 
237                                                   
238 static struct afs_call *afs_get_call(struct af    
239                                      enum afs_    
240 {                                                 
241         int r;                                    
242                                                   
243         __refcount_inc(&call->ref, &r);           
244                                                   
245         trace_afs_call(call->debug_id, why, r     
246                        atomic_read(&call->net-    
247                        __builtin_return_addres    
248         return call;                              
249 }                                                 
250                                                   
251 /*                                                
252  * Queue the call for actual work.                
253  */                                               
254 static void afs_queue_call_work(struct afs_cal    
255 {                                                 
256         if (call->type->work) {                   
257                 INIT_WORK(&call->work, call->t    
258                                                   
259                 afs_get_call(call, afs_call_tr    
260                 if (!queue_work(afs_wq, &call-    
261                         afs_put_call(call);       
262         }                                         
263 }                                                 
264                                                   
265 /*                                                
266  * allocate a call with flat request and reply    
267  */                                               
268 struct afs_call *afs_alloc_flat_call(struct af    
269                                      const str    
270                                      size_t re    
271 {                                                 
272         struct afs_call *call;                    
273                                                   
274         call = afs_alloc_call(net, type, GFP_N    
275         if (!call)                                
276                 goto nomem_call;                  
277                                                   
278         if (request_size) {                       
279                 call->request_size = request_s    
280                 call->request = kmalloc(reques    
281                 if (!call->request)               
282                         goto nomem_free;          
283         }                                         
284                                                   
285         if (reply_max) {                          
286                 call->reply_max = reply_max;      
287                 call->buffer = kmalloc(reply_m    
288                 if (!call->buffer)                
289                         goto nomem_free;          
290         }                                         
291                                                   
292         afs_extract_to_buf(call, call->reply_m    
293         call->operation_ID = type->op;            
294         init_waitqueue_head(&call->waitq);        
295         return call;                              
296                                                   
297 nomem_free:                                       
298         afs_put_call(call);                       
299 nomem_call:                                       
300         return NULL;                              
301 }                                                 
302                                                   
303 /*                                                
304  * clean up a call with flat buffer               
305  */                                               
306 void afs_flat_call_destructor(struct afs_call     
307 {                                                 
308         _enter("");                               
309                                                   
310         kfree(call->request);                     
311         call->request = NULL;                     
312         kfree(call->buffer);                      
313         call->buffer = NULL;                      
314 }                                                 
315                                                   
316 /*                                                
317  * Advance the AFS call state when the RxRPC c    
318  */                                               
319 static void afs_notify_end_request_tx(struct s    
320                                       struct r    
321                                       unsigned    
322 {                                                 
323         struct afs_call *call = (struct afs_ca    
324                                                   
325         afs_set_call_state(call, AFS_CALL_CL_R    
326 }                                                 
327                                                   
328 /*                                                
329  * Initiate a call and synchronously queue up     
330  * error is stored into the call struct, which    
331  */                                               
332 void afs_make_call(struct afs_call *call, gfp_    
333 {                                                 
334         struct rxrpc_call *rxcall;                
335         struct msghdr msg;                        
336         struct kvec iov[1];                       
337         size_t len;                               
338         s64 tx_total_len;                         
339         int ret;                                  
340                                                   
341         _enter(",{%pISp+%u},", rxrpc_kernel_re    
342                                                   
343         ASSERT(call->type != NULL);               
344         ASSERT(call->type->name != NULL);         
345                                                   
346         _debug("____MAKE %p{%s,%x} [%d]____",     
347                call, call->type->name, key_ser    
348                atomic_read(&call->net->nr_outs    
349                                                   
350         trace_afs_make_call(call);                
351                                                   
352         /* Work out the length we're going to     
353          * calls such as FS.StoreData where th    
354          * after the initial fixed part.          
355          */                                       
356         tx_total_len = call->request_size;        
357         if (call->write_iter)                     
358                 tx_total_len += iov_iter_count    
359                                                   
360         /* If the call is going to be asynchro    
361          * the call to hold itself so the call    
362          */                                       
363         if (call->async) {                        
364                 afs_get_call(call, afs_call_tr    
365                 call->drop_ref = true;            
366         }                                         
367                                                   
368         /* create a call */                       
369         rxcall = rxrpc_kernel_begin_call(call-    
370                                          (unsi    
371                                          tx_to    
372                                          call-    
373                                          gfp,     
374                                          (call    
375                                           afs_    
376                                           afs_    
377                                          call-    
378                                          call-    
379                                          (call    
380                                           RXRP    
381                                          call-    
382         if (IS_ERR(rxcall)) {                     
383                 ret = PTR_ERR(rxcall);            
384                 call->error = ret;                
385                 goto error_kill_call;             
386         }                                         
387                                                   
388         call->rxcall = rxcall;                    
389         call->issue_time = ktime_get_real();      
390                                                   
391         /* send the request */                    
392         iov[0].iov_base = call->request;          
393         iov[0].iov_len  = call->request_size;     
394                                                   
395         msg.msg_name            = NULL;           
396         msg.msg_namelen         = 0;              
397         iov_iter_kvec(&msg.msg_iter, ITER_SOUR    
398         msg.msg_control         = NULL;           
399         msg.msg_controllen      = 0;              
400         msg.msg_flags           = MSG_WAITALL     
401                                                   
402         ret = rxrpc_kernel_send_data(call->net    
403                                      &msg, cal    
404                                      afs_notif    
405         if (ret < 0)                              
406                 goto error_do_abort;              
407                                                   
408         if (call->write_iter) {                   
409                 msg.msg_iter = *call->write_it    
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)                      
421                         goto error_do_abort;      
422         }                                         
423                                                   
424         /* Note that at this point, we may hav    
425          * - and an asynchronous call may alre    
426          *                                        
427          * afs_wait_for_call_to_complete(call)    
428          * must be called to synchronously cle    
429          */                                       
430         return;                                   
431                                                   
432 error_do_abort:                                   
433         if (ret != -ECONNABORTED) {               
434                 rxrpc_kernel_abort_call(call->    
435                                         RX_USE    
436                                         afs_ab    
437         } else {                                  
438                 len = 0;                          
439                 iov_iter_kvec(&msg.msg_iter, I    
440                 rxrpc_kernel_recv_data(call->n    
441                                        &msg.ms    
442                                        &call->    
443                 call->responded = true;           
444         }                                         
445         call->error = ret;                        
446         trace_afs_call_done(call);                
447 error_kill_call:                                  
448         if (call->type->done)                     
449                 call->type->done(call);           
450                                                   
451         /* We need to dispose of the extra ref    
452          * The call, however, might be queued     
453          * make sure we don't get any more not    
454          */                                       
455         if (call->rxcall)                         
456                 rxrpc_kernel_shutdown_call(cal    
457         if (call->async) {                        
458                 if (cancel_work_sync(&call->as    
459                         afs_put_call(call);       
460                 afs_set_call_complete(call, re    
461         }                                         
462                                                   
463         call->error = ret;                        
464         call->state = AFS_CALL_COMPLETE;          
465         _leave(" = %d", ret);                     
466 }                                                 
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 }                                                 
500                                                   
501 /*                                                
502  * deliver messages to a call                     
503  */                                               
504 static void afs_deliver_to_call(struct afs_cal    
505 {                                                 
506         enum afs_call_state state;                
507         size_t len;                               
508         u32 abort_code, remote_abort = 0;         
509         int ret;                                  
510                                                   
511         _enter("%s", call->type->name);           
512                                                   
513         while (state = READ_ONCE(call->state),    
514                state == AFS_CALL_CL_AWAIT_REPL    
515                state == AFS_CALL_SV_AWAIT_OP_I    
516                state == AFS_CALL_SV_AWAIT_REQU    
517                state == AFS_CALL_SV_AWAIT_ACK     
518                ) {                                
519                 if (state == AFS_CALL_SV_AWAIT    
520                         len = 0;                  
521                         iov_iter_kvec(&call->d    
522                         ret = rxrpc_kernel_rec    
523                                                   
524                                                   
525                                                   
526                         trace_afs_receive_data    
527                                                   
528                         if (ret == -EINPROGRES    
529                                 return;           
530                         if (ret < 0 || ret ==     
531                                 if (ret == 1)     
532                                         ret =     
533                                 goto call_comp    
534                         }                         
535                         return;                   
536                 }                                 
537                                                   
538                 ret = call->type->deliver(call    
539                 state = READ_ONCE(call->state)    
540                 if (ret == 0 && call->unmarsha    
541                         ret = -EBADMSG;           
542                 switch (ret) {                    
543                 case 0:                           
544                         call->responded = true    
545                         afs_queue_call_work(ca    
546                         if (state == AFS_CALL_    
547                                 if (call->op)     
548                                         set_bi    
549                                                   
550                                 goto call_comp    
551                         }                         
552                         ASSERTCMP(state, >, AF    
553                         goto done;                
554                 case -EINPROGRESS:                
555                 case -EAGAIN:                     
556                         goto out;                 
557                 case -ECONNABORTED:               
558                         ASSERTCMP(state, ==, A    
559                         call->responded = true    
560                         afs_log_error(call, ca    
561                         goto done;                
562                 case -ENOTSUPP:                   
563                         call->responded = true    
564                         abort_code = RXGEN_OPC    
565                         rxrpc_kernel_abort_cal    
566                                                   
567                                                   
568                         goto local_abort;         
569                 case -EIO:                        
570                         pr_err("kAFS: Call %u     
571                                call->debug_id,    
572                         fallthrough;              
573                 case -ENODATA:                    
574                 case -EBADMSG:                    
575                 case -EMSGSIZE:                   
576                 case -ENOMEM:                     
577                 case -EFAULT:                     
578                         abort_code = RXGEN_CC_    
579                         if (state != AFS_CALL_    
580                                 abort_code = R    
581                         rxrpc_kernel_abort_cal    
582                                                   
583                                                   
584                         goto local_abort;         
585                 default:                          
586                         abort_code = RX_CALL_D    
587                         rxrpc_kernel_abort_cal    
588                                                   
589                                                   
590                         goto local_abort;         
591                 }                                 
592         }                                         
593                                                   
594 done:                                             
595         if (call->type->done)                     
596                 call->type->done(call);           
597 out:                                              
598         _leave("");                               
599         return;                                   
600                                                   
601 local_abort:                                      
602         abort_code = 0;                           
603 call_complete:                                    
604         afs_set_call_complete(call, ret, remot    
605         state = AFS_CALL_COMPLETE;                
606         goto done;                                
607 }                                                 
608                                                   
609 /*                                                
610  * Wait synchronously for a call to complete.     
611  */                                               
612 void afs_wait_for_call_to_complete(struct afs_    
613 {                                                 
614         bool rxrpc_complete = false;              
615                                                   
616         _enter("");                               
617                                                   
618         if (!afs_check_call_state(call, AFS_CA    
619                 DECLARE_WAITQUEUE(myself, curr    
620                                                   
621                 add_wait_queue(&call->waitq, &    
622                 for (;;) {                        
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                                                   
634                         if (afs_check_call_sta    
635                                 break;            
636                                                   
637                         if (!rxrpc_kernel_chec    
638                                 /* rxrpc termi    
639                                 rxrpc_complete    
640                                 break;            
641                         }                         
642                                                   
643                         schedule();               
644                 }                                 
645                                                   
646                 remove_wait_queue(&call->waitq    
647                 __set_current_state(TASK_RUNNI    
648         }                                         
649                                                   
650         if (!afs_check_call_state(call, AFS_CA    
651                 if (rxrpc_complete) {             
652                         afs_set_call_complete(    
653                 } else {                          
654                         /* Kill off the call i    
655                         _debug("call interrupt    
656                         if (rxrpc_kernel_abort    
657                                                   
658                                                   
659                                 afs_set_call_c    
660                 }                                 
661         }                                         
662 }                                                 
663                                                   
664 /*                                                
665  * wake up a waiting call                         
666  */                                               
667 static void afs_wake_up_call_waiter(struct soc    
668                                     unsigned l    
669 {                                                 
670         struct afs_call *call = (struct afs_ca    
671                                                   
672         call->need_attention = true;              
673         wake_up(&call->waitq);                    
674 }                                                 
675                                                   
676 /*                                                
677  * Wake up an asynchronous call.  The caller i    
678  * spinlock around this, so we can't call afs_    
679  */                                               
680 static void afs_wake_up_async_call(struct sock    
681                                    unsigned lo    
682 {                                                 
683         struct afs_call *call = (struct afs_ca    
684         int r;                                    
685                                                   
686         trace_afs_notify_call(rxcall, call);      
687         call->need_attention = true;              
688                                                   
689         if (__refcount_inc_not_zero(&call->ref    
690                 trace_afs_call(call->debug_id,    
691                                atomic_read(&ca    
692                                __builtin_retur    
693                                                   
694                 if (!queue_work(afs_async_call    
695                         afs_deferred_put_call(    
696         }                                         
697 }                                                 
698                                                   
699 /*                                                
700  * Perform I/O processing on an asynchronous c    
701  * to the call struct that we either need to r    
702  */                                               
703 static void afs_process_async_call(struct work    
704 {                                                 
705         struct afs_call *call = container_of(w    
706                                                   
707         _enter("");                               
708                                                   
709         if (call->state < AFS_CALL_COMPLETE &&    
710                 call->need_attention = false;     
711                 afs_deliver_to_call(call);        
712         }                                         
713                                                   
714         afs_put_call(call);                       
715         _leave("");                               
716 }                                                 
717                                                   
718 static void afs_rx_attach(struct rxrpc_call *r    
719 {                                                 
720         struct afs_call *call = (struct afs_ca    
721                                                   
722         call->rxcall = rxcall;                    
723 }                                                 
724                                                   
725 /*                                                
726  * Charge the incoming call preallocation.        
727  */                                               
728 void afs_charge_preallocation(struct work_stru    
729 {                                                 
730         struct afs_net *net =                     
731                 container_of(work, struct afs_    
732         struct afs_call *call = net->spare_inc    
733                                                   
734         for (;;) {                                
735                 if (!call) {                      
736                         call = afs_alloc_call(    
737                         if (!call)                
738                                 break;            
739                                                   
740                         call->drop_ref = true;    
741                         call->async = true;       
742                         call->state = AFS_CALL    
743                         init_waitqueue_head(&c    
744                         afs_extract_to_tmp(cal    
745                 }                                 
746                                                   
747                 if (rxrpc_kernel_charge_accept    
748                                                   
749                                                   
750                                                   
751                                                   
752                                                   
753                         break;                    
754                 call = NULL;                      
755         }                                         
756         net->spare_incoming_call = call;          
757 }                                                 
758                                                   
759 /*                                                
760  * Discard a preallocated call when a socket i    
761  */                                               
762 static void afs_rx_discard_new_call(struct rxr    
763                                     unsigned l    
764 {                                                 
765         struct afs_call *call = (struct afs_ca    
766                                                   
767         call->rxcall = NULL;                      
768         afs_put_call(call);                       
769 }                                                 
770                                                   
771 /*                                                
772  * Notification of an incoming call.              
773  */                                               
774 static void afs_rx_new_call(struct sock *sk, s    
775                             unsigned long user    
776 {                                                 
777         struct afs_net *net = afs_sock2net(sk)    
778                                                   
779         queue_work(afs_wq, &net->charge_preall    
780 }                                                 
781                                                   
782 /*                                                
783  * Grab the operation ID from an incoming cach    
784  * buffer is discarded on error or if we don't    
785  */                                               
786 static int afs_deliver_cm_op_id(struct afs_cal    
787 {                                                 
788         int ret;                                  
789                                                   
790         _enter("{%zu}", iov_iter_count(call->i    
791                                                   
792         /* the operation ID forms the first fo    
793         ret = afs_extract_data(call, true);       
794         if (ret < 0)                              
795                 return ret;                       
796                                                   
797         call->operation_ID = ntohl(call->tmp);    
798         afs_set_call_state(call, AFS_CALL_SV_A    
799                                                   
800         /* ask the cache manager to route the     
801          * if successful) */                      
802         if (!afs_cm_incoming_call(call))          
803                 return -ENOTSUPP;                 
804                                                   
805         trace_afs_cb_call(call);                  
806                                                   
807         /* pass responsibility for the remaine    
808          * cache manager op */                    
809         return call->type->deliver(call);         
810 }                                                 
811                                                   
812 /*                                                
813  * Advance the AFS call state when an RxRPC se    
814  * phase.                                         
815  */                                               
816 static void afs_notify_end_reply_tx(struct soc    
817                                     struct rxr    
818                                     unsigned l    
819 {                                                 
820         struct afs_call *call = (struct afs_ca    
821                                                   
822         afs_set_call_state(call, AFS_CALL_SV_R    
823 }                                                 
824                                                   
825 /*                                                
826  * send an empty reply                            
827  */                                               
828 void afs_send_empty_reply(struct afs_call *cal    
829 {                                                 
830         struct afs_net *net = call->net;          
831         struct msghdr msg;                        
832                                                   
833         _enter("");                               
834                                                   
835         rxrpc_kernel_set_tx_length(net->socket    
836                                                   
837         msg.msg_name            = NULL;           
838         msg.msg_namelen         = 0;              
839         iov_iter_kvec(&msg.msg_iter, ITER_SOUR    
840         msg.msg_control         = NULL;           
841         msg.msg_controllen      = 0;              
842         msg.msg_flags           = 0;              
843                                                   
844         switch (rxrpc_kernel_send_data(net->so    
845                                        afs_not    
846         case 0:                                   
847                 _leave(" [replied]");             
848                 return;                           
849                                                   
850         case -ENOMEM:                             
851                 _debug("oom");                    
852                 rxrpc_kernel_abort_call(net->s    
853                                         RXGEN_    
854                                         afs_ab    
855                 fallthrough;                      
856         default:                                  
857                 _leave(" [error]");               
858                 return;                           
859         }                                         
860 }                                                 
861                                                   
862 /*                                                
863  * send a simple reply                            
864  */                                               
865 void afs_send_simple_reply(struct afs_call *ca    
866 {                                                 
867         struct afs_net *net = call->net;          
868         struct msghdr msg;                        
869         struct kvec iov[1];                       
870         int n;                                    
871                                                   
872         _enter("");                               
873                                                   
874         rxrpc_kernel_set_tx_length(net->socket    
875                                                   
876         iov[0].iov_base         = (void *) buf    
877         iov[0].iov_len          = len;            
878         msg.msg_name            = NULL;           
879         msg.msg_namelen         = 0;              
880         iov_iter_kvec(&msg.msg_iter, ITER_SOUR    
881         msg.msg_control         = NULL;           
882         msg.msg_controllen      = 0;              
883         msg.msg_flags           = 0;              
884                                                   
885         n = rxrpc_kernel_send_data(net->socket    
886                                    afs_notify_    
887         if (n >= 0) {                             
888                 /* Success */                     
889                 _leave(" [replied]");             
890                 return;                           
891         }                                         
892                                                   
893         if (n == -ENOMEM) {                       
894                 _debug("oom");                    
895                 rxrpc_kernel_abort_call(net->s    
896                                         RXGEN_    
897                                         afs_ab    
898         }                                         
899         _leave(" [error]");                       
900 }                                                 
901                                                   
902 /*                                                
903  * Extract a piece of data from the received d    
904  */                                               
905 int afs_extract_data(struct afs_call *call, bo    
906 {                                                 
907         struct afs_net *net = call->net;          
908         struct iov_iter *iter = call->iter;       
909         enum afs_call_state state;                
910         u32 remote_abort = 0;                     
911         int ret;                                  
912                                                   
913         _enter("{%s,%zu,%zu},%d",                 
914                call->type->name, call->iov_len    
915                                                   
916         ret = rxrpc_kernel_recv_data(net->sock    
917                                      &call->io    
918                                      &call->se    
919         trace_afs_receive_data(call, call->ite    
920         if (ret == 0 || ret == -EAGAIN)           
921                 return ret;                       
922                                                   
923         state = READ_ONCE(call->state);           
924         if (ret == 1) {                           
925                 switch (state) {                  
926                 case AFS_CALL_CL_AWAIT_REPLY:     
927                         afs_set_call_state(cal    
928                         break;                    
929                 case AFS_CALL_SV_AWAIT_REQUEST    
930                         afs_set_call_state(cal    
931                         break;                    
932                 case AFS_CALL_COMPLETE:           
933                         kdebug("prem complete     
934                         return afs_io_error(ca    
935                 default:                          
936                         break;                    
937                 }                                 
938                 return 0;                         
939         }                                         
940                                                   
941         afs_set_call_complete(call, ret, remot    
942         return ret;                               
943 }                                                 
944                                                   
945 /*                                                
946  * Log protocol error production.                 
947  */                                               
948 noinline int afs_protocol_error(struct afs_cal    
949                                 enum afs_eprot    
950 {                                                 
951         trace_afs_protocol_error(call, cause);    
952         if (call)                                 
953                 call->unmarshalling_error = tr    
954         return -EBADMSG;                          
955 }                                                 
956                                                   

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