Lines Matching refs:bundle
43 static void rxrpc_deactivate_bundle(struct rxrpc_bundle *bundle);
121 struct rxrpc_bundle *bundle; in rxrpc_alloc_bundle() local
123 bundle = kzalloc(sizeof(*bundle), gfp); in rxrpc_alloc_bundle()
124 if (bundle) { in rxrpc_alloc_bundle()
125 bundle->params = *cp; in rxrpc_alloc_bundle()
126 rxrpc_get_peer(bundle->params.peer); in rxrpc_alloc_bundle()
127 refcount_set(&bundle->ref, 1); in rxrpc_alloc_bundle()
128 atomic_set(&bundle->active, 1); in rxrpc_alloc_bundle()
129 spin_lock_init(&bundle->channel_lock); in rxrpc_alloc_bundle()
130 INIT_LIST_HEAD(&bundle->waiting_calls); in rxrpc_alloc_bundle()
132 return bundle; in rxrpc_alloc_bundle()
135 struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *bundle) in rxrpc_get_bundle() argument
137 refcount_inc(&bundle->ref); in rxrpc_get_bundle()
138 return bundle; in rxrpc_get_bundle()
141 static void rxrpc_free_bundle(struct rxrpc_bundle *bundle) in rxrpc_free_bundle() argument
143 rxrpc_put_peer(bundle->params.peer); in rxrpc_free_bundle()
144 kfree(bundle); in rxrpc_free_bundle()
147 void rxrpc_put_bundle(struct rxrpc_bundle *bundle) in rxrpc_put_bundle() argument
149 unsigned int d = bundle->debug_id; in rxrpc_put_bundle()
153 dead = __refcount_dec_and_test(&bundle->ref, &r); in rxrpc_put_bundle()
157 rxrpc_free_bundle(bundle); in rxrpc_put_bundle()
164 rxrpc_alloc_client_connection(struct rxrpc_bundle *bundle, gfp_t gfp) in rxrpc_alloc_client_connection() argument
167 struct rxrpc_net *rxnet = bundle->params.local->rxnet; in rxrpc_alloc_client_connection()
179 conn->bundle = bundle; in rxrpc_alloc_client_connection()
180 conn->params = bundle->params; in rxrpc_alloc_client_connection()
198 rxrpc_get_bundle(bundle); in rxrpc_alloc_client_connection()
270 struct rxrpc_bundle *bundle, *candidate; in rxrpc_look_up_bundle() local
286 bundle = rb_entry(p, struct rxrpc_bundle, local_node); in rxrpc_look_up_bundle()
288 #define cmp(X) ((long)bundle->params.X - (long)cp->X) in rxrpc_look_up_bundle()
315 bundle = rb_entry(parent, struct rxrpc_bundle, local_node); in rxrpc_look_up_bundle()
317 #define cmp(X) ((long)bundle->params.X - (long)cp->X) in rxrpc_look_up_bundle()
343 rxrpc_get_bundle(bundle); in rxrpc_look_up_bundle()
344 atomic_inc(&bundle->active); in rxrpc_look_up_bundle()
346 _leave(" = %u [found]", bundle->debug_id); in rxrpc_look_up_bundle()
347 return bundle; in rxrpc_look_up_bundle()
362 struct rxrpc_bundle *bundle; in rxrpc_prep_call() local
379 bundle = rxrpc_look_up_bundle(cp, gfp); in rxrpc_prep_call()
380 if (!bundle) in rxrpc_prep_call()
386 spin_lock(&bundle->channel_lock); in rxrpc_prep_call()
387 list_add_tail(&call->chan_wait_link, &bundle->waiting_calls); in rxrpc_prep_call()
388 spin_unlock(&bundle->channel_lock); in rxrpc_prep_call()
390 _leave(" = [B=%x]", bundle->debug_id); in rxrpc_prep_call()
391 return bundle; in rxrpc_prep_call()
401 static void rxrpc_add_conn_to_bundle(struct rxrpc_bundle *bundle, gfp_t gfp) in rxrpc_add_conn_to_bundle() argument
402 __releases(bundle->channel_lock) in rxrpc_add_conn_to_bundle()
410 conflict = bundle->alloc_conn; in rxrpc_add_conn_to_bundle()
412 bundle->alloc_conn = true; in rxrpc_add_conn_to_bundle()
413 spin_unlock(&bundle->channel_lock); in rxrpc_add_conn_to_bundle()
419 candidate = rxrpc_alloc_client_connection(bundle, gfp); in rxrpc_add_conn_to_bundle()
421 spin_lock(&bundle->channel_lock); in rxrpc_add_conn_to_bundle()
422 bundle->alloc_conn = false; in rxrpc_add_conn_to_bundle()
425 bundle->alloc_error = PTR_ERR(candidate); in rxrpc_add_conn_to_bundle()
426 spin_unlock(&bundle->channel_lock); in rxrpc_add_conn_to_bundle()
431 bundle->alloc_error = 0; in rxrpc_add_conn_to_bundle()
433 for (i = 0; i < ARRAY_SIZE(bundle->conns); i++) { in rxrpc_add_conn_to_bundle()
437 old = bundle->conns[i]; in rxrpc_add_conn_to_bundle()
442 atomic_inc(&bundle->active); in rxrpc_add_conn_to_bundle()
443 bundle->conns[i] = candidate; in rxrpc_add_conn_to_bundle()
445 set_bit(shift + j, &bundle->avail_chans); in rxrpc_add_conn_to_bundle()
453 spin_unlock(&bundle->channel_lock); in rxrpc_add_conn_to_bundle()
469 static void rxrpc_maybe_add_conn(struct rxrpc_bundle *bundle, gfp_t gfp) in rxrpc_maybe_add_conn() argument
476 spin_lock(&bundle->channel_lock); in rxrpc_maybe_add_conn()
480 for (i = 0; i < ARRAY_SIZE(bundle->conns); i++) in rxrpc_maybe_add_conn()
481 if (rxrpc_may_reuse_conn(bundle->conns[i])) in rxrpc_maybe_add_conn()
484 if (!usable && !list_empty(&bundle->waiting_calls)) { in rxrpc_maybe_add_conn()
485 call = list_first_entry(&bundle->waiting_calls, in rxrpc_maybe_add_conn()
488 bundle->try_upgrade = true; in rxrpc_maybe_add_conn()
494 if (!bundle->avail_chans && in rxrpc_maybe_add_conn()
495 !bundle->try_upgrade && in rxrpc_maybe_add_conn()
496 !list_empty(&bundle->waiting_calls) && in rxrpc_maybe_add_conn()
497 usable < ARRAY_SIZE(bundle->conns)) in rxrpc_maybe_add_conn()
500 spin_unlock(&bundle->channel_lock); in rxrpc_maybe_add_conn()
505 return rxrpc_add_conn_to_bundle(bundle, gfp); in rxrpc_maybe_add_conn()
517 struct rxrpc_bundle *bundle = conn->bundle; in rxrpc_activate_one_channel() local
518 struct rxrpc_call *call = list_entry(bundle->waiting_calls.next, in rxrpc_activate_one_channel()
530 clear_bit(conn->bundle_shift + channel, &bundle->avail_chans); in rxrpc_activate_one_channel()
571 static void rxrpc_unidle_conn(struct rxrpc_bundle *bundle, struct rxrpc_connection *conn) in rxrpc_unidle_conn() argument
573 struct rxrpc_net *rxnet = bundle->params.local->rxnet; in rxrpc_unidle_conn()
593 static void rxrpc_activate_channels_locked(struct rxrpc_bundle *bundle) in rxrpc_activate_channels_locked() argument
599 if (bundle->try_upgrade) in rxrpc_activate_channels_locked()
604 while (!list_empty(&bundle->waiting_calls)) { in rxrpc_activate_channels_locked()
605 avail = bundle->avail_chans & mask; in rxrpc_activate_channels_locked()
609 clear_bit(channel, &bundle->avail_chans); in rxrpc_activate_channels_locked()
612 conn = bundle->conns[slot]; in rxrpc_activate_channels_locked()
616 if (bundle->try_upgrade) in rxrpc_activate_channels_locked()
618 rxrpc_unidle_conn(bundle, conn); in rxrpc_activate_channels_locked()
629 static void rxrpc_activate_channels(struct rxrpc_bundle *bundle) in rxrpc_activate_channels() argument
631 _enter("B=%x", bundle->debug_id); in rxrpc_activate_channels()
635 if (!bundle->avail_chans) in rxrpc_activate_channels()
638 spin_lock(&bundle->channel_lock); in rxrpc_activate_channels()
639 rxrpc_activate_channels_locked(bundle); in rxrpc_activate_channels()
640 spin_unlock(&bundle->channel_lock); in rxrpc_activate_channels()
647 static int rxrpc_wait_for_channel(struct rxrpc_bundle *bundle, in rxrpc_wait_for_channel() argument
656 rxrpc_maybe_add_conn(bundle, gfp); in rxrpc_wait_for_channel()
657 rxrpc_activate_channels(bundle); in rxrpc_wait_for_channel()
658 ret = bundle->alloc_error ?: -EAGAIN; in rxrpc_wait_for_channel()
664 rxrpc_maybe_add_conn(bundle, gfp); in rxrpc_wait_for_channel()
665 rxrpc_activate_channels(bundle); in rxrpc_wait_for_channel()
666 ret = bundle->alloc_error; in rxrpc_wait_for_channel()
708 struct rxrpc_bundle *bundle; in rxrpc_connect_call() local
716 bundle = rxrpc_prep_call(rx, call, cp, srx, gfp); in rxrpc_connect_call()
717 if (IS_ERR(bundle)) { in rxrpc_connect_call()
718 ret = PTR_ERR(bundle); in rxrpc_connect_call()
723 ret = rxrpc_wait_for_channel(bundle, call, gfp); in rxrpc_connect_call()
733 rxrpc_deactivate_bundle(bundle); in rxrpc_connect_call()
734 rxrpc_put_bundle(bundle); in rxrpc_connect_call()
740 spin_lock(&bundle->channel_lock); in rxrpc_connect_call()
742 spin_unlock(&bundle->channel_lock); in rxrpc_connect_call()
751 rxrpc_disconnect_client_call(bundle, call); in rxrpc_connect_call()
795 void rxrpc_disconnect_client_call(struct rxrpc_bundle *bundle, struct rxrpc_call *call) in rxrpc_disconnect_client_call() argument
799 struct rxrpc_net *rxnet = bundle->params.local->rxnet; in rxrpc_disconnect_client_call()
806 spin_lock(&bundle->channel_lock); in rxrpc_disconnect_client_call()
827 spin_unlock(&bundle->channel_lock); in rxrpc_disconnect_client_call()
848 bundle->try_upgrade = false; in rxrpc_disconnect_client_call()
850 rxrpc_activate_channels_locked(bundle); in rxrpc_disconnect_client_call()
856 if (may_reuse && !list_empty(&bundle->waiting_calls)) { in rxrpc_disconnect_client_call()
878 set_bit(conn->bundle_shift + channel, &conn->bundle->avail_chans); in rxrpc_disconnect_client_call()
898 spin_unlock(&bundle->channel_lock); in rxrpc_disconnect_client_call()
908 struct rxrpc_bundle *bundle = conn->bundle; in rxrpc_unbundle_conn() local
918 spin_lock(&bundle->channel_lock); in rxrpc_unbundle_conn()
920 if (bundle->conns[bindex] == conn) { in rxrpc_unbundle_conn()
922 bundle->conns[bindex] = NULL; in rxrpc_unbundle_conn()
924 clear_bit(conn->bundle_shift + i, &bundle->avail_chans); in rxrpc_unbundle_conn()
927 spin_unlock(&bundle->channel_lock); in rxrpc_unbundle_conn()
930 rxrpc_deactivate_bundle(bundle); in rxrpc_unbundle_conn()
938 static void rxrpc_deactivate_bundle(struct rxrpc_bundle *bundle) in rxrpc_deactivate_bundle() argument
940 struct rxrpc_local *local = bundle->params.local; in rxrpc_deactivate_bundle()
943 if (atomic_dec_and_lock(&bundle->active, &local->client_bundles_lock)) { in rxrpc_deactivate_bundle()
944 if (!bundle->params.exclusive) { in rxrpc_deactivate_bundle()
946 rb_erase(&bundle->local_node, &local->client_bundles); in rxrpc_deactivate_bundle()
952 rxrpc_put_bundle(bundle); in rxrpc_deactivate_bundle()