Lines Matching refs:bundle

37 static void rxrpc_activate_bundle(struct rxrpc_bundle *bundle)
39 atomic_inc(&bundle->active);
71 * Allocate a connection bundle.
77 struct rxrpc_bundle *bundle;
79 bundle = kzalloc(sizeof(*bundle), gfp);
80 if (bundle) {
81 bundle->local = call->local;
82 bundle->peer = rxrpc_get_peer(call->peer, rxrpc_peer_get_bundle);
83 bundle->key = key_get(call->key);
84 bundle->security = call->security;
85 bundle->exclusive = test_bit(RXRPC_CALL_EXCLUSIVE, &call->flags);
86 bundle->upgrade = test_bit(RXRPC_CALL_UPGRADE, &call->flags);
87 bundle->service_id = call->dest_srx.srx_service;
88 bundle->security_level = call->security_level;
89 bundle->debug_id = atomic_inc_return(&rxrpc_bundle_id);
90 refcount_set(&bundle->ref, 1);
91 atomic_set(&bundle->active, 1);
92 INIT_LIST_HEAD(&bundle->waiting_calls);
93 trace_rxrpc_bundle(bundle->debug_id, 1, rxrpc_bundle_new);
95 return bundle;
98 struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *bundle,
103 __refcount_inc(&bundle->ref, &r);
104 trace_rxrpc_bundle(bundle->debug_id, r + 1, why);
105 return bundle;
108 static void rxrpc_free_bundle(struct rxrpc_bundle *bundle)
110 trace_rxrpc_bundle(bundle->debug_id, refcount_read(&bundle->ref),
112 rxrpc_put_peer(bundle->peer, rxrpc_peer_put_bundle);
113 key_put(bundle->key);
114 kfree(bundle);
117 void rxrpc_put_bundle(struct rxrpc_bundle *bundle, enum rxrpc_bundle_trace why)
123 if (bundle) {
124 id = bundle->debug_id;
125 dead = __refcount_dec_and_test(&bundle->ref, &r);
128 rxrpc_free_bundle(bundle);
145 rxrpc_alloc_client_connection(struct rxrpc_bundle *bundle)
148 struct rxrpc_local *local = bundle->local;
169 conn->bundle = rxrpc_get_bundle(bundle, rxrpc_bundle_get_client_conn);
170 conn->local = rxrpc_get_local(bundle->local, rxrpc_local_get_client_conn);
171 conn->peer = rxrpc_get_peer(bundle->peer, rxrpc_peer_get_client_conn);
172 conn->key = key_get(bundle->key);
173 conn->security = bundle->security;
174 conn->exclusive = bundle->exclusive;
175 conn->upgrade = bundle->upgrade;
176 conn->orig_service_id = bundle->service_id;
177 conn->security_level = bundle->security_level;
240 * Look up the conn bundle that matches the connection parameters, adding it if
245 struct rxrpc_bundle *bundle, *candidate;
256 call->bundle = rxrpc_alloc_bundle(call, gfp);
257 return call->bundle ? 0 : -ENOMEM;
260 /* First, see if the bundle is already there. */
265 bundle = rb_entry(p, struct rxrpc_bundle, local_node);
268 diff = (cmp(bundle->peer, call->peer) ?:
269 cmp(bundle->key, call->key) ?:
270 cmp(bundle->security_level, call->security_level) ?:
271 cmp(bundle->upgrade, upgrade));
294 bundle = rb_entry(parent, struct rxrpc_bundle, local_node);
297 diff = (cmp(bundle->peer, call->peer) ?:
298 cmp(bundle->key, call->key) ?:
299 cmp(bundle->security_level, call->security_level) ?:
300 cmp(bundle->upgrade, upgrade));
310 _debug("new bundle");
313 call->bundle = rxrpc_get_bundle(candidate, rxrpc_bundle_get_client_call);
315 _leave(" = B=%u [new]", call->bundle->debug_id);
321 call->bundle = rxrpc_get_bundle(bundle, rxrpc_bundle_get_client_call);
322 rxrpc_activate_bundle(bundle);
324 _leave(" = B=%u [found]", call->bundle->debug_id);
329 * Allocate a new connection and add it into a bundle.
331 static bool rxrpc_add_conn_to_bundle(struct rxrpc_bundle *bundle,
338 old = bundle->conns[slot];
340 bundle->conns[slot] = NULL;
345 conn = rxrpc_alloc_client_connection(bundle);
347 bundle->alloc_error = PTR_ERR(conn);
351 rxrpc_activate_bundle(bundle);
353 bundle->conns[slot] = conn;
355 set_bit(shift + i, &bundle->avail_chans);
360 * Add a connection to a bundle if there are no usable connections or we have
363 static bool rxrpc_bundle_has_space(struct rxrpc_bundle *bundle)
369 bundle->alloc_error = 0;
373 for (i = 0; i < ARRAY_SIZE(bundle->conns); i++) {
374 if (rxrpc_may_reuse_conn(bundle->conns[i]))
380 if (!usable && bundle->upgrade)
381 bundle->try_upgrade = true;
386 if (!bundle->avail_chans &&
387 !bundle->try_upgrade &&
388 usable < ARRAY_SIZE(bundle->conns))
395 return slot >= 0 ? rxrpc_add_conn_to_bundle(bundle, slot) : false;
407 struct rxrpc_bundle *bundle = conn->bundle;
408 struct rxrpc_call *call = list_entry(bundle->waiting_calls.next,
422 clear_bit(conn->bundle_shift + channel, &bundle->avail_chans);
461 static void rxrpc_activate_channels(struct rxrpc_bundle *bundle)
469 if (bundle->try_upgrade)
474 while (!list_empty(&bundle->waiting_calls)) {
475 avail = bundle->avail_chans & mask;
479 clear_bit(channel, &bundle->avail_chans);
482 conn = bundle->conns[slot];
486 if (bundle->try_upgrade)
506 struct rxrpc_bundle *bundle = call->bundle;
509 list_move_tail(&call->wait_link, &bundle->waiting_calls);
512 if (rxrpc_bundle_has_space(bundle))
513 rxrpc_activate_channels(bundle);
561 void rxrpc_disconnect_client_call(struct rxrpc_bundle *bundle, struct rxrpc_call *call)
565 struct rxrpc_local *local = bundle->local;
609 bundle->try_upgrade = false;
611 rxrpc_activate_channels(bundle);
616 if (may_reuse && !list_empty(&bundle->waiting_calls)) {
638 set_bit(conn->bundle_shift + channel, &conn->bundle->avail_chans);
657 * Remove a connection from a bundle.
661 struct rxrpc_bundle *bundle = conn->bundle;
671 if (bundle->conns[bindex] == conn) {
673 bundle->conns[bindex] = NULL;
675 clear_bit(conn->bundle_shift + i, &bundle->avail_chans);
676 rxrpc_put_client_connection_id(bundle->local, conn);
677 rxrpc_deactivate_bundle(bundle);
683 * Drop the active count on a bundle.
685 void rxrpc_deactivate_bundle(struct rxrpc_bundle *bundle)
690 if (!bundle)
693 local = bundle->local;
694 if (atomic_dec_and_lock(&bundle->active, &local->client_bundles_lock)) {
695 if (!bundle->exclusive) {
696 _debug("erase bundle");
697 rb_erase(&bundle->local_node, &local->client_bundles);
703 rxrpc_put_bundle(bundle, rxrpc_bundle_put_discard);