Lines Matching refs:bundle
43 static void rxrpc_deactivate_bundle(struct rxrpc_bundle *bundle);
116 * Allocate a connection bundle.
121 struct rxrpc_bundle *bundle;
123 bundle = kzalloc(sizeof(*bundle), gfp);
124 if (bundle) {
125 bundle->params = *cp;
126 rxrpc_get_peer(bundle->params.peer);
127 refcount_set(&bundle->ref, 1);
128 atomic_set(&bundle->active, 1);
129 spin_lock_init(&bundle->channel_lock);
130 INIT_LIST_HEAD(&bundle->waiting_calls);
132 return bundle;
135 struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *bundle)
137 refcount_inc(&bundle->ref);
138 return bundle;
141 static void rxrpc_free_bundle(struct rxrpc_bundle *bundle)
143 rxrpc_put_peer(bundle->params.peer);
144 kfree(bundle);
147 void rxrpc_put_bundle(struct rxrpc_bundle *bundle)
149 unsigned int d = bundle->debug_id;
153 dead = __refcount_dec_and_test(&bundle->ref, &r);
157 rxrpc_free_bundle(bundle);
164 rxrpc_alloc_client_connection(struct rxrpc_bundle *bundle, gfp_t gfp)
167 struct rxrpc_net *rxnet = bundle->params.local->rxnet;
179 conn->bundle = bundle;
180 conn->params = bundle->params;
202 rxrpc_get_bundle(bundle);
269 * Look up the conn bundle that matches the connection parameters, adding it if
276 struct rxrpc_bundle *bundle, *candidate;
287 /* First, see if the bundle is already there. */
292 bundle = rb_entry(p, struct rxrpc_bundle, local_node);
294 #define cmp(X) ((long)bundle->params.X - (long)cp->X)
321 bundle = rb_entry(parent, struct rxrpc_bundle, local_node);
323 #define cmp(X) ((long)bundle->params.X - (long)cp->X)
337 _debug("new bundle");
349 rxrpc_get_bundle(bundle);
350 atomic_inc(&bundle->active);
352 _leave(" = %u [found]", bundle->debug_id);
353 return bundle;
357 * Create or find a client bundle to use for a call.
368 struct rxrpc_bundle *bundle;
384 /* Find the client connection bundle. */
385 bundle = rxrpc_look_up_bundle(cp, gfp);
386 if (!bundle)
392 spin_lock(&bundle->channel_lock);
393 list_add_tail(&call->chan_wait_link, &bundle->waiting_calls);
394 spin_unlock(&bundle->channel_lock);
396 _leave(" = [B=%x]", bundle->debug_id);
397 return bundle;
405 * Allocate a new connection and add it into a bundle.
407 static void rxrpc_add_conn_to_bundle(struct rxrpc_bundle *bundle, gfp_t gfp)
408 __releases(bundle->channel_lock)
416 conflict = bundle->alloc_conn;
418 bundle->alloc_conn = true;
419 spin_unlock(&bundle->channel_lock);
425 candidate = rxrpc_alloc_client_connection(bundle, gfp);
427 spin_lock(&bundle->channel_lock);
428 bundle->alloc_conn = false;
431 bundle->alloc_error = PTR_ERR(candidate);
432 spin_unlock(&bundle->channel_lock);
437 bundle->alloc_error = 0;
439 for (i = 0; i < ARRAY_SIZE(bundle->conns); i++) {
443 old = bundle->conns[i];
448 atomic_inc(&bundle->active);
449 bundle->conns[i] = candidate;
451 set_bit(shift + j, &bundle->avail_chans);
459 spin_unlock(&bundle->channel_lock);
472 * Add a connection to a bundle if there are no usable connections or we have
475 static void rxrpc_maybe_add_conn(struct rxrpc_bundle *bundle, gfp_t gfp)
482 spin_lock(&bundle->channel_lock);
486 for (i = 0; i < ARRAY_SIZE(bundle->conns); i++)
487 if (rxrpc_may_reuse_conn(bundle->conns[i]))
490 if (!usable && !list_empty(&bundle->waiting_calls)) {
491 call = list_first_entry(&bundle->waiting_calls,
494 bundle->try_upgrade = true;
500 if (!bundle->avail_chans &&
501 !bundle->try_upgrade &&
502 !list_empty(&bundle->waiting_calls) &&
503 usable < ARRAY_SIZE(bundle->conns))
506 spin_unlock(&bundle->channel_lock);
511 return rxrpc_add_conn_to_bundle(bundle, gfp);
523 struct rxrpc_bundle *bundle = conn->bundle;
524 struct rxrpc_call *call = list_entry(bundle->waiting_calls.next,
536 clear_bit(conn->bundle_shift + channel, &bundle->avail_chans);
577 static void rxrpc_unidle_conn(struct rxrpc_bundle *bundle, struct rxrpc_connection *conn)
579 struct rxrpc_net *rxnet = bundle->params.local->rxnet;
599 static void rxrpc_activate_channels_locked(struct rxrpc_bundle *bundle)
605 if (bundle->try_upgrade)
610 while (!list_empty(&bundle->waiting_calls)) {
611 avail = bundle->avail_chans & mask;
615 clear_bit(channel, &bundle->avail_chans);
618 conn = bundle->conns[slot];
622 if (bundle->try_upgrade)
624 rxrpc_unidle_conn(bundle, conn);
635 static void rxrpc_activate_channels(struct rxrpc_bundle *bundle)
637 _enter("B=%x", bundle->debug_id);
641 if (!bundle->avail_chans)
644 spin_lock(&bundle->channel_lock);
645 rxrpc_activate_channels_locked(bundle);
646 spin_unlock(&bundle->channel_lock);
653 static int rxrpc_wait_for_channel(struct rxrpc_bundle *bundle,
662 rxrpc_maybe_add_conn(bundle, gfp);
663 rxrpc_activate_channels(bundle);
664 ret = bundle->alloc_error ?: -EAGAIN;
670 rxrpc_maybe_add_conn(bundle, gfp);
671 rxrpc_activate_channels(bundle);
672 ret = bundle->alloc_error;
714 struct rxrpc_bundle *bundle;
722 bundle = rxrpc_prep_call(rx, call, cp, srx, gfp);
723 if (IS_ERR(bundle)) {
724 ret = PTR_ERR(bundle);
729 ret = rxrpc_wait_for_channel(bundle, call, gfp);
739 rxrpc_deactivate_bundle(bundle);
740 rxrpc_put_bundle(bundle);
746 spin_lock(&bundle->channel_lock);
748 spin_unlock(&bundle->channel_lock);
757 rxrpc_disconnect_client_call(bundle, call);
801 void rxrpc_disconnect_client_call(struct rxrpc_bundle *bundle, struct rxrpc_call *call)
805 struct rxrpc_net *rxnet = bundle->params.local->rxnet;
812 spin_lock(&bundle->channel_lock);
833 spin_unlock(&bundle->channel_lock);
854 bundle->try_upgrade = false;
856 rxrpc_activate_channels_locked(bundle);
862 if (may_reuse && !list_empty(&bundle->waiting_calls)) {
884 set_bit(conn->bundle_shift + channel, &conn->bundle->avail_chans);
904 spin_unlock(&bundle->channel_lock);
910 * Remove a connection from a bundle.
914 struct rxrpc_bundle *bundle = conn->bundle;
924 spin_lock(&bundle->channel_lock);
926 if (bundle->conns[bindex] == conn) {
928 bundle->conns[bindex] = NULL;
930 clear_bit(conn->bundle_shift + i, &bundle->avail_chans);
933 spin_unlock(&bundle->channel_lock);
936 rxrpc_deactivate_bundle(bundle);
942 * Drop the active count on a bundle.
944 static void rxrpc_deactivate_bundle(struct rxrpc_bundle *bundle)
946 struct rxrpc_local *local = bundle->params.local;
949 if (atomic_dec_and_lock(&bundle->active, &local->client_bundles_lock)) {
950 if (!bundle->params.exclusive) {
951 _debug("erase bundle");
952 rb_erase(&bundle->local_node, &local->client_bundles);
958 rxrpc_put_bundle(bundle);