@@ -34,7 +34,10 @@ __read_mostly unsigned int rxrpc_reap_client_connections = 900;
34
34
__read_mostly unsigned long rxrpc_conn_idle_client_expiry = 2 * 60 * HZ ;
35
35
__read_mostly unsigned long rxrpc_conn_idle_client_fast_expiry = 2 * HZ ;
36
36
37
- static void rxrpc_deactivate_bundle (struct rxrpc_bundle * bundle );
37
+ static void rxrpc_activate_bundle (struct rxrpc_bundle * bundle )
38
+ {
39
+ atomic_inc (& bundle -> active );
40
+ }
38
41
39
42
/*
40
43
* Get a connection ID and epoch for a client connection from the global pool.
@@ -109,20 +112,21 @@ void rxrpc_destroy_client_conn_ids(struct rxrpc_local *local)
109
112
/*
110
113
* Allocate a connection bundle.
111
114
*/
112
- static struct rxrpc_bundle * rxrpc_alloc_bundle (struct rxrpc_conn_parameters * cp ,
115
+ static struct rxrpc_bundle * rxrpc_alloc_bundle (struct rxrpc_call * call ,
113
116
gfp_t gfp )
114
117
{
115
118
struct rxrpc_bundle * bundle ;
116
119
117
120
bundle = kzalloc (sizeof (* bundle ), gfp );
118
121
if (bundle ) {
119
- bundle -> local = cp -> local ;
120
- bundle -> peer = rxrpc_get_peer (cp -> peer , rxrpc_peer_get_bundle );
121
- bundle -> key = cp -> key ;
122
- bundle -> exclusive = cp -> exclusive ;
123
- bundle -> upgrade = cp -> upgrade ;
124
- bundle -> service_id = cp -> service_id ;
125
- bundle -> security_level = cp -> security_level ;
122
+ bundle -> local = call -> local ;
123
+ bundle -> peer = rxrpc_get_peer (call -> peer , rxrpc_peer_get_bundle );
124
+ bundle -> key = key_get (call -> key );
125
+ bundle -> security = call -> security ;
126
+ bundle -> exclusive = test_bit (RXRPC_CALL_EXCLUSIVE , & call -> flags );
127
+ bundle -> upgrade = test_bit (RXRPC_CALL_UPGRADE , & call -> flags );
128
+ bundle -> service_id = call -> dest_srx .srx_service ;
129
+ bundle -> security_level = call -> security_level ;
126
130
refcount_set (& bundle -> ref , 1 );
127
131
atomic_set (& bundle -> active , 1 );
128
132
spin_lock_init (& bundle -> channel_lock );
@@ -146,19 +150,23 @@ static void rxrpc_free_bundle(struct rxrpc_bundle *bundle)
146
150
{
147
151
trace_rxrpc_bundle (bundle -> debug_id , 1 , rxrpc_bundle_free );
148
152
rxrpc_put_peer (bundle -> peer , rxrpc_peer_put_bundle );
153
+ key_put (bundle -> key );
149
154
kfree (bundle );
150
155
}
151
156
152
157
void rxrpc_put_bundle (struct rxrpc_bundle * bundle , enum rxrpc_bundle_trace why )
153
158
{
154
- unsigned int id = bundle -> debug_id ;
159
+ unsigned int id ;
155
160
bool dead ;
156
161
int r ;
157
162
158
- dead = __refcount_dec_and_test (& bundle -> ref , & r );
159
- trace_rxrpc_bundle (id , r - 1 , why );
160
- if (dead )
161
- rxrpc_free_bundle (bundle );
163
+ if (bundle ) {
164
+ id = bundle -> debug_id ;
165
+ dead = __refcount_dec_and_test (& bundle -> ref , & r );
166
+ trace_rxrpc_bundle (id , r - 1 , why );
167
+ if (dead )
168
+ rxrpc_free_bundle (bundle );
169
+ }
162
170
}
163
171
164
172
/*
@@ -272,20 +280,23 @@ static bool rxrpc_may_reuse_conn(struct rxrpc_connection *conn)
272
280
* Look up the conn bundle that matches the connection parameters, adding it if
273
281
* it doesn't yet exist.
274
282
*/
275
- static struct rxrpc_bundle * rxrpc_look_up_bundle (struct rxrpc_conn_parameters * cp ,
276
- gfp_t gfp )
283
+ static struct rxrpc_bundle * rxrpc_look_up_bundle (struct rxrpc_call * call , gfp_t gfp )
277
284
{
278
285
static atomic_t rxrpc_bundle_id ;
279
286
struct rxrpc_bundle * bundle , * candidate ;
280
- struct rxrpc_local * local = cp -> local ;
287
+ struct rxrpc_local * local = call -> local ;
281
288
struct rb_node * p , * * pp , * parent ;
282
289
long diff ;
290
+ bool upgrade = test_bit (RXRPC_CALL_UPGRADE , & call -> flags );
283
291
284
292
_enter ("{%px,%x,%u,%u}" ,
285
- cp -> peer , key_serial (cp -> key ), cp -> security_level , cp -> upgrade );
293
+ call -> peer , key_serial (call -> key ), call -> security_level ,
294
+ upgrade );
286
295
287
- if (cp -> exclusive )
288
- return rxrpc_alloc_bundle (cp , gfp );
296
+ if (test_bit (RXRPC_CALL_EXCLUSIVE , & call -> flags )) {
297
+ call -> bundle = rxrpc_alloc_bundle (call , gfp );
298
+ return call -> bundle ;
299
+ }
289
300
290
301
/* First, see if the bundle is already there. */
291
302
_debug ("search 1" );
@@ -294,11 +305,11 @@ static struct rxrpc_bundle *rxrpc_look_up_bundle(struct rxrpc_conn_parameters *c
294
305
while (p ) {
295
306
bundle = rb_entry (p , struct rxrpc_bundle , local_node );
296
307
297
- #define cmp (X ) ((long)bundle->X - (long)cp->X )
298
- diff = (cmp (peer ) ?:
299
- cmp (key ) ?:
300
- cmp (security_level ) ?:
301
- cmp (upgrade ));
308
+ #define cmp (X , Y ) ((long)(X) - (long)(Y) )
309
+ diff = (cmp (bundle -> peer , call -> peer ) ?:
310
+ cmp (bundle -> key , call -> key ) ?:
311
+ cmp (bundle -> security_level , call -> security_level ) ?:
312
+ cmp (bundle -> upgrade , upgrade ));
302
313
#undef cmp
303
314
if (diff < 0 )
304
315
p = p -> rb_left ;
@@ -311,9 +322,9 @@ static struct rxrpc_bundle *rxrpc_look_up_bundle(struct rxrpc_conn_parameters *c
311
322
_debug ("not found" );
312
323
313
324
/* It wasn't. We need to add one. */
314
- candidate = rxrpc_alloc_bundle (cp , gfp );
325
+ candidate = rxrpc_alloc_bundle (call , gfp );
315
326
if (!candidate )
316
- return NULL ;
327
+ return ERR_PTR ( - ENOMEM ) ;
317
328
318
329
_debug ("search 2" );
319
330
spin_lock (& local -> client_bundles_lock );
@@ -323,11 +334,11 @@ static struct rxrpc_bundle *rxrpc_look_up_bundle(struct rxrpc_conn_parameters *c
323
334
parent = * pp ;
324
335
bundle = rb_entry (parent , struct rxrpc_bundle , local_node );
325
336
326
- #define cmp (X ) ((long)bundle->X - (long)cp->X )
327
- diff = (cmp (peer ) ?:
328
- cmp (key ) ?:
329
- cmp (security_level ) ?:
330
- cmp (upgrade ));
337
+ #define cmp (X , Y ) ((long)(X) - (long)(Y) )
338
+ diff = (cmp (bundle -> peer , call -> peer ) ?:
339
+ cmp (bundle -> key , call -> key ) ?:
340
+ cmp (bundle -> security_level , call -> security_level ) ?:
341
+ cmp (bundle -> upgrade , upgrade ));
331
342
#undef cmp
332
343
if (diff < 0 )
333
344
pp = & (* pp )-> rb_left ;
@@ -341,19 +352,19 @@ static struct rxrpc_bundle *rxrpc_look_up_bundle(struct rxrpc_conn_parameters *c
341
352
candidate -> debug_id = atomic_inc_return (& rxrpc_bundle_id );
342
353
rb_link_node (& candidate -> local_node , parent , pp );
343
354
rb_insert_color (& candidate -> local_node , & local -> client_bundles );
344
- rxrpc_get_bundle (candidate , rxrpc_bundle_get_client_call );
355
+ call -> bundle = rxrpc_get_bundle (candidate , rxrpc_bundle_get_client_call );
345
356
spin_unlock (& local -> client_bundles_lock );
346
- _leave (" = %u [new]" , candidate -> debug_id );
347
- return candidate ;
357
+ _leave (" = B= %u [new]" , call -> bundle -> debug_id );
358
+ return call -> bundle ;
348
359
349
360
found_bundle_free :
350
361
rxrpc_free_bundle (candidate );
351
362
found_bundle :
352
- rxrpc_get_bundle (bundle , rxrpc_bundle_get_client_call );
353
- atomic_inc ( & bundle -> active );
363
+ call -> bundle = rxrpc_get_bundle (bundle , rxrpc_bundle_get_client_call );
364
+ rxrpc_activate_bundle ( bundle );
354
365
spin_unlock (& local -> client_bundles_lock );
355
- _leave (" = %u [found]" , bundle -> debug_id );
356
- return bundle ;
366
+ _leave (" = B= %u [found]" , call -> bundle -> debug_id );
367
+ return call -> bundle ;
357
368
}
358
369
359
370
/*
@@ -362,31 +373,25 @@ static struct rxrpc_bundle *rxrpc_look_up_bundle(struct rxrpc_conn_parameters *c
362
373
* If we return with a connection, the call will be on its waiting list. It's
363
374
* left to the caller to assign a channel and wake up the call.
364
375
*/
365
- static struct rxrpc_bundle * rxrpc_prep_call (struct rxrpc_sock * rx ,
366
- struct rxrpc_call * call ,
367
- struct rxrpc_conn_parameters * cp ,
368
- struct sockaddr_rxrpc * srx ,
369
- gfp_t gfp )
376
+ static struct rxrpc_bundle * rxrpc_prep_call (struct rxrpc_call * call , gfp_t gfp )
370
377
{
371
378
struct rxrpc_bundle * bundle ;
372
379
373
380
_enter ("{%d,%lx}," , call -> debug_id , call -> user_call_ID );
374
381
375
- cp -> peer = rxrpc_lookup_peer (cp -> local , srx , gfp );
376
- if (!cp -> peer )
382
+ call -> peer = rxrpc_lookup_peer (call -> local , & call -> dest_srx , gfp );
383
+ if (!call -> peer )
377
384
goto error ;
378
385
379
386
call -> tx_last_sent = ktime_get_real ();
380
- call -> cong_ssthresh = cp -> peer -> cong_ssthresh ;
387
+ call -> cong_ssthresh = call -> peer -> cong_ssthresh ;
381
388
if (call -> cong_cwnd >= call -> cong_ssthresh )
382
389
call -> cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE ;
383
390
else
384
391
call -> cong_mode = RXRPC_CALL_SLOW_START ;
385
- if (cp -> upgrade )
386
- __set_bit (RXRPC_CALL_UPGRADE , & call -> flags );
387
392
388
393
/* Find the client connection bundle. */
389
- bundle = rxrpc_look_up_bundle (cp , gfp );
394
+ bundle = rxrpc_look_up_bundle (call , gfp );
390
395
if (!bundle )
391
396
goto error ;
392
397
@@ -449,7 +454,7 @@ static void rxrpc_add_conn_to_bundle(struct rxrpc_bundle *bundle, gfp_t gfp)
449
454
if (old )
450
455
trace_rxrpc_client (old , -1 , rxrpc_client_replace );
451
456
candidate -> bundle_shift = shift ;
452
- atomic_inc ( & bundle -> active );
457
+ rxrpc_activate_bundle ( bundle );
453
458
bundle -> conns [i ] = candidate ;
454
459
for (j = 0 ; j < RXRPC_MAXCALLS ; j ++ )
455
460
set_bit (shift + j , & bundle -> avail_chans );
@@ -541,7 +546,6 @@ static void rxrpc_activate_one_channel(struct rxrpc_connection *conn,
541
546
542
547
rxrpc_see_call (call , rxrpc_call_see_activate_client );
543
548
list_del_init (& call -> chan_wait_link );
544
- call -> peer = rxrpc_get_peer (conn -> peer , rxrpc_peer_get_activate_call );
545
549
call -> conn = rxrpc_get_connection (conn , rxrpc_conn_get_activate_call );
546
550
call -> cid = conn -> proto .cid | channel ;
547
551
call -> call_id = call_id ;
@@ -705,14 +709,11 @@ static int rxrpc_wait_for_channel(struct rxrpc_bundle *bundle,
705
709
* find a connection for a call
706
710
* - called in process context with IRQs enabled
707
711
*/
708
- int rxrpc_connect_call (struct rxrpc_sock * rx ,
709
- struct rxrpc_call * call ,
710
- struct rxrpc_conn_parameters * cp ,
711
- struct sockaddr_rxrpc * srx ,
712
- gfp_t gfp )
712
+ int rxrpc_connect_call (struct rxrpc_call * call , gfp_t gfp )
713
713
{
714
714
struct rxrpc_bundle * bundle ;
715
- struct rxrpc_net * rxnet = cp -> local -> rxnet ;
715
+ struct rxrpc_local * local = call -> local ;
716
+ struct rxrpc_net * rxnet = local -> rxnet ;
716
717
int ret = 0 ;
717
718
718
719
_enter ("{%d,%lx}," , call -> debug_id , call -> user_call_ID );
@@ -721,7 +722,7 @@ int rxrpc_connect_call(struct rxrpc_sock *rx,
721
722
722
723
rxrpc_get_call (call , rxrpc_call_get_io_thread );
723
724
724
- bundle = rxrpc_prep_call (rx , call , cp , srx , gfp );
725
+ bundle = rxrpc_prep_call (call , gfp );
725
726
if (IS_ERR (bundle )) {
726
727
rxrpc_put_call (call , rxrpc_call_get_io_thread );
727
728
ret = PTR_ERR (bundle );
@@ -738,9 +739,6 @@ int rxrpc_connect_call(struct rxrpc_sock *rx,
738
739
/* Paired with the write barrier in rxrpc_activate_one_channel(). */
739
740
smp_rmb ();
740
741
741
- out_put_bundle :
742
- rxrpc_deactivate_bundle (bundle );
743
- rxrpc_put_bundle (bundle , rxrpc_bundle_get_client_call );
744
742
out :
745
743
_leave (" = %d" , ret );
746
744
return ret ;
@@ -758,7 +756,7 @@ int rxrpc_connect_call(struct rxrpc_sock *rx,
758
756
trace_rxrpc_client (call -> conn , ret , rxrpc_client_chan_wait_failed );
759
757
rxrpc_set_call_completion (call , RXRPC_CALL_LOCAL_ERROR , 0 , ret );
760
758
rxrpc_disconnect_client_call (bundle , call );
761
- goto out_put_bundle ;
759
+ goto out ;
762
760
}
763
761
764
762
/*
@@ -945,11 +943,15 @@ static void rxrpc_unbundle_conn(struct rxrpc_connection *conn)
945
943
/*
946
944
* Drop the active count on a bundle.
947
945
*/
948
- static void rxrpc_deactivate_bundle (struct rxrpc_bundle * bundle )
946
+ void rxrpc_deactivate_bundle (struct rxrpc_bundle * bundle )
949
947
{
950
- struct rxrpc_local * local = bundle -> local ;
948
+ struct rxrpc_local * local ;
951
949
bool need_put = false;
952
950
951
+ if (!bundle )
952
+ return ;
953
+
954
+ local = bundle -> local ;
953
955
if (atomic_dec_and_lock (& bundle -> active , & local -> client_bundles_lock )) {
954
956
if (!bundle -> exclusive ) {
955
957
_debug ("erase bundle" );
0 commit comments