x86: add pgd_large() on 64-bit, for consistency
[wrt350n-kernel.git] / net / rxrpc / ar-call.c
blobd9231245a79aba9b3331d2a81b6bfd90820d7fd9
1 /* RxRPC individual remote procedure call handling
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/circ_buf.h>
14 #include <net/sock.h>
15 #include <net/af_rxrpc.h>
16 #include "ar-internal.h"
18 const char *const rxrpc_call_states[] = {
19 [RXRPC_CALL_CLIENT_SEND_REQUEST] = "ClSndReq",
20 [RXRPC_CALL_CLIENT_AWAIT_REPLY] = "ClAwtRpl",
21 [RXRPC_CALL_CLIENT_RECV_REPLY] = "ClRcvRpl",
22 [RXRPC_CALL_CLIENT_FINAL_ACK] = "ClFnlACK",
23 [RXRPC_CALL_SERVER_SECURING] = "SvSecure",
24 [RXRPC_CALL_SERVER_ACCEPTING] = "SvAccept",
25 [RXRPC_CALL_SERVER_RECV_REQUEST] = "SvRcvReq",
26 [RXRPC_CALL_SERVER_ACK_REQUEST] = "SvAckReq",
27 [RXRPC_CALL_SERVER_SEND_REPLY] = "SvSndRpl",
28 [RXRPC_CALL_SERVER_AWAIT_ACK] = "SvAwtACK",
29 [RXRPC_CALL_COMPLETE] = "Complete",
30 [RXRPC_CALL_SERVER_BUSY] = "SvBusy ",
31 [RXRPC_CALL_REMOTELY_ABORTED] = "RmtAbort",
32 [RXRPC_CALL_LOCALLY_ABORTED] = "LocAbort",
33 [RXRPC_CALL_NETWORK_ERROR] = "NetError",
34 [RXRPC_CALL_DEAD] = "Dead ",
37 struct kmem_cache *rxrpc_call_jar;
38 LIST_HEAD(rxrpc_calls);
39 DEFINE_RWLOCK(rxrpc_call_lock);
40 static unsigned rxrpc_call_max_lifetime = 60;
41 static unsigned rxrpc_dead_call_timeout = 2;
43 static void rxrpc_destroy_call(struct work_struct *work);
44 static void rxrpc_call_life_expired(unsigned long _call);
45 static void rxrpc_dead_call_expired(unsigned long _call);
46 static void rxrpc_ack_time_expired(unsigned long _call);
47 static void rxrpc_resend_time_expired(unsigned long _call);
50 * allocate a new call
52 static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
54 struct rxrpc_call *call;
56 call = kmem_cache_zalloc(rxrpc_call_jar, gfp);
57 if (!call)
58 return NULL;
60 call->acks_winsz = 16;
61 call->acks_window = kmalloc(call->acks_winsz * sizeof(unsigned long),
62 gfp);
63 if (!call->acks_window) {
64 kmem_cache_free(rxrpc_call_jar, call);
65 return NULL;
68 setup_timer(&call->lifetimer, &rxrpc_call_life_expired,
69 (unsigned long) call);
70 setup_timer(&call->deadspan, &rxrpc_dead_call_expired,
71 (unsigned long) call);
72 setup_timer(&call->ack_timer, &rxrpc_ack_time_expired,
73 (unsigned long) call);
74 setup_timer(&call->resend_timer, &rxrpc_resend_time_expired,
75 (unsigned long) call);
76 INIT_WORK(&call->destroyer, &rxrpc_destroy_call);
77 INIT_WORK(&call->processor, &rxrpc_process_call);
78 INIT_LIST_HEAD(&call->accept_link);
79 skb_queue_head_init(&call->rx_queue);
80 skb_queue_head_init(&call->rx_oos_queue);
81 init_waitqueue_head(&call->tx_waitq);
82 spin_lock_init(&call->lock);
83 rwlock_init(&call->state_lock);
84 atomic_set(&call->usage, 1);
85 call->debug_id = atomic_inc_return(&rxrpc_debug_id);
86 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
88 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
90 call->rx_data_expect = 1;
91 call->rx_data_eaten = 0;
92 call->rx_first_oos = 0;
93 call->ackr_win_top = call->rx_data_eaten + 1 + RXRPC_MAXACKS;
94 call->creation_jif = jiffies;
95 return call;
99 * allocate a new client call and attempt to to get a connection slot for it
101 static struct rxrpc_call *rxrpc_alloc_client_call(
102 struct rxrpc_sock *rx,
103 struct rxrpc_transport *trans,
104 struct rxrpc_conn_bundle *bundle,
105 gfp_t gfp)
107 struct rxrpc_call *call;
108 int ret;
110 _enter("");
112 ASSERT(rx != NULL);
113 ASSERT(trans != NULL);
114 ASSERT(bundle != NULL);
116 call = rxrpc_alloc_call(gfp);
117 if (!call)
118 return ERR_PTR(-ENOMEM);
120 sock_hold(&rx->sk);
121 call->socket = rx;
122 call->rx_data_post = 1;
124 ret = rxrpc_connect_call(rx, trans, bundle, call, gfp);
125 if (ret < 0) {
126 kmem_cache_free(rxrpc_call_jar, call);
127 return ERR_PTR(ret);
130 spin_lock(&call->conn->trans->peer->lock);
131 list_add(&call->error_link, &call->conn->trans->peer->error_targets);
132 spin_unlock(&call->conn->trans->peer->lock);
134 call->lifetimer.expires = jiffies + rxrpc_call_max_lifetime * HZ;
135 add_timer(&call->lifetimer);
137 _leave(" = %p", call);
138 return call;
142 * set up a call for the given data
143 * - called in process context with IRQs enabled
145 struct rxrpc_call *rxrpc_get_client_call(struct rxrpc_sock *rx,
146 struct rxrpc_transport *trans,
147 struct rxrpc_conn_bundle *bundle,
148 unsigned long user_call_ID,
149 int create,
150 gfp_t gfp)
152 struct rxrpc_call *call, *candidate;
153 struct rb_node *p, *parent, **pp;
155 _enter("%p,%d,%d,%lx,%d",
156 rx, trans ? trans->debug_id : -1, bundle ? bundle->debug_id : -1,
157 user_call_ID, create);
159 /* search the extant calls first for one that matches the specified
160 * user ID */
161 read_lock(&rx->call_lock);
163 p = rx->calls.rb_node;
164 while (p) {
165 call = rb_entry(p, struct rxrpc_call, sock_node);
167 if (user_call_ID < call->user_call_ID)
168 p = p->rb_left;
169 else if (user_call_ID > call->user_call_ID)
170 p = p->rb_right;
171 else
172 goto found_extant_call;
175 read_unlock(&rx->call_lock);
177 if (!create || !trans)
178 return ERR_PTR(-EBADSLT);
180 /* not yet present - create a candidate for a new record and then
181 * redo the search */
182 candidate = rxrpc_alloc_client_call(rx, trans, bundle, gfp);
183 if (IS_ERR(candidate)) {
184 _leave(" = %ld", PTR_ERR(candidate));
185 return candidate;
188 candidate->user_call_ID = user_call_ID;
189 __set_bit(RXRPC_CALL_HAS_USERID, &candidate->flags);
191 write_lock(&rx->call_lock);
193 pp = &rx->calls.rb_node;
194 parent = NULL;
195 while (*pp) {
196 parent = *pp;
197 call = rb_entry(parent, struct rxrpc_call, sock_node);
199 if (user_call_ID < call->user_call_ID)
200 pp = &(*pp)->rb_left;
201 else if (user_call_ID > call->user_call_ID)
202 pp = &(*pp)->rb_right;
203 else
204 goto found_extant_second;
207 /* second search also failed; add the new call */
208 call = candidate;
209 candidate = NULL;
210 rxrpc_get_call(call);
212 rb_link_node(&call->sock_node, parent, pp);
213 rb_insert_color(&call->sock_node, &rx->calls);
214 write_unlock(&rx->call_lock);
216 write_lock_bh(&rxrpc_call_lock);
217 list_add_tail(&call->link, &rxrpc_calls);
218 write_unlock_bh(&rxrpc_call_lock);
220 _net("CALL new %d on CONN %d", call->debug_id, call->conn->debug_id);
222 _leave(" = %p [new]", call);
223 return call;
225 /* we found the call in the list immediately */
226 found_extant_call:
227 rxrpc_get_call(call);
228 read_unlock(&rx->call_lock);
229 _leave(" = %p [extant %d]", call, atomic_read(&call->usage));
230 return call;
232 /* we found the call on the second time through the list */
233 found_extant_second:
234 rxrpc_get_call(call);
235 write_unlock(&rx->call_lock);
236 rxrpc_put_call(candidate);
237 _leave(" = %p [second %d]", call, atomic_read(&call->usage));
238 return call;
242 * set up an incoming call
243 * - called in process context with IRQs enabled
245 struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *rx,
246 struct rxrpc_connection *conn,
247 struct rxrpc_header *hdr,
248 gfp_t gfp)
250 struct rxrpc_call *call, *candidate;
251 struct rb_node **p, *parent;
252 __be32 call_id;
254 _enter(",%d,,%x", conn->debug_id, gfp);
256 ASSERT(rx != NULL);
258 candidate = rxrpc_alloc_call(gfp);
259 if (!candidate)
260 return ERR_PTR(-EBUSY);
262 candidate->socket = rx;
263 candidate->conn = conn;
264 candidate->cid = hdr->cid;
265 candidate->call_id = hdr->callNumber;
266 candidate->channel = ntohl(hdr->cid) & RXRPC_CHANNELMASK;
267 candidate->rx_data_post = 0;
268 candidate->state = RXRPC_CALL_SERVER_ACCEPTING;
269 if (conn->security_ix > 0)
270 candidate->state = RXRPC_CALL_SERVER_SECURING;
272 write_lock_bh(&conn->lock);
274 /* set the channel for this call */
275 call = conn->channels[candidate->channel];
276 _debug("channel[%u] is %p", candidate->channel, call);
277 if (call && call->call_id == hdr->callNumber) {
278 /* already set; must've been a duplicate packet */
279 _debug("extant call [%d]", call->state);
280 ASSERTCMP(call->conn, ==, conn);
282 read_lock(&call->state_lock);
283 switch (call->state) {
284 case RXRPC_CALL_LOCALLY_ABORTED:
285 if (!test_and_set_bit(RXRPC_CALL_ABORT, &call->events))
286 rxrpc_queue_call(call);
287 case RXRPC_CALL_REMOTELY_ABORTED:
288 read_unlock(&call->state_lock);
289 goto aborted_call;
290 default:
291 rxrpc_get_call(call);
292 read_unlock(&call->state_lock);
293 goto extant_call;
297 if (call) {
298 /* it seems the channel is still in use from the previous call
299 * - ditch the old binding if its call is now complete */
300 _debug("CALL: %u { %s }",
301 call->debug_id, rxrpc_call_states[call->state]);
303 if (call->state >= RXRPC_CALL_COMPLETE) {
304 conn->channels[call->channel] = NULL;
305 } else {
306 write_unlock_bh(&conn->lock);
307 kmem_cache_free(rxrpc_call_jar, candidate);
308 _leave(" = -EBUSY");
309 return ERR_PTR(-EBUSY);
313 /* check the call number isn't duplicate */
314 _debug("check dup");
315 call_id = hdr->callNumber;
316 p = &conn->calls.rb_node;
317 parent = NULL;
318 while (*p) {
319 parent = *p;
320 call = rb_entry(parent, struct rxrpc_call, conn_node);
322 if (call_id < call->call_id)
323 p = &(*p)->rb_left;
324 else if (call_id > call->call_id)
325 p = &(*p)->rb_right;
326 else
327 goto old_call;
330 /* make the call available */
331 _debug("new call");
332 call = candidate;
333 candidate = NULL;
334 rb_link_node(&call->conn_node, parent, p);
335 rb_insert_color(&call->conn_node, &conn->calls);
336 conn->channels[call->channel] = call;
337 sock_hold(&rx->sk);
338 atomic_inc(&conn->usage);
339 write_unlock_bh(&conn->lock);
341 spin_lock(&conn->trans->peer->lock);
342 list_add(&call->error_link, &conn->trans->peer->error_targets);
343 spin_unlock(&conn->trans->peer->lock);
345 write_lock_bh(&rxrpc_call_lock);
346 list_add_tail(&call->link, &rxrpc_calls);
347 write_unlock_bh(&rxrpc_call_lock);
349 _net("CALL incoming %d on CONN %d", call->debug_id, call->conn->debug_id);
351 call->lifetimer.expires = jiffies + rxrpc_call_max_lifetime * HZ;
352 add_timer(&call->lifetimer);
353 _leave(" = %p {%d} [new]", call, call->debug_id);
354 return call;
356 extant_call:
357 write_unlock_bh(&conn->lock);
358 kmem_cache_free(rxrpc_call_jar, candidate);
359 _leave(" = %p {%d} [extant]", call, call ? call->debug_id : -1);
360 return call;
362 aborted_call:
363 write_unlock_bh(&conn->lock);
364 kmem_cache_free(rxrpc_call_jar, candidate);
365 _leave(" = -ECONNABORTED");
366 return ERR_PTR(-ECONNABORTED);
368 old_call:
369 write_unlock_bh(&conn->lock);
370 kmem_cache_free(rxrpc_call_jar, candidate);
371 _leave(" = -ECONNRESET [old]");
372 return ERR_PTR(-ECONNRESET);
376 * find an extant server call
377 * - called in process context with IRQs enabled
379 struct rxrpc_call *rxrpc_find_server_call(struct rxrpc_sock *rx,
380 unsigned long user_call_ID)
382 struct rxrpc_call *call;
383 struct rb_node *p;
385 _enter("%p,%lx", rx, user_call_ID);
387 /* search the extant calls for one that matches the specified user
388 * ID */
389 read_lock(&rx->call_lock);
391 p = rx->calls.rb_node;
392 while (p) {
393 call = rb_entry(p, struct rxrpc_call, sock_node);
395 if (user_call_ID < call->user_call_ID)
396 p = p->rb_left;
397 else if (user_call_ID > call->user_call_ID)
398 p = p->rb_right;
399 else
400 goto found_extant_call;
403 read_unlock(&rx->call_lock);
404 _leave(" = NULL");
405 return NULL;
407 /* we found the call in the list immediately */
408 found_extant_call:
409 rxrpc_get_call(call);
410 read_unlock(&rx->call_lock);
411 _leave(" = %p [%d]", call, atomic_read(&call->usage));
412 return call;
416 * detach a call from a socket and set up for release
418 void rxrpc_release_call(struct rxrpc_call *call)
420 struct rxrpc_connection *conn = call->conn;
421 struct rxrpc_sock *rx = call->socket;
423 _enter("{%d,%d,%d,%d}",
424 call->debug_id, atomic_read(&call->usage),
425 atomic_read(&call->ackr_not_idle),
426 call->rx_first_oos);
428 spin_lock_bh(&call->lock);
429 if (test_and_set_bit(RXRPC_CALL_RELEASED, &call->flags))
430 BUG();
431 spin_unlock_bh(&call->lock);
433 /* dissociate from the socket
434 * - the socket's ref on the call is passed to the death timer
436 _debug("RELEASE CALL %p (%d CONN %p)", call, call->debug_id, conn);
438 write_lock_bh(&rx->call_lock);
439 if (!list_empty(&call->accept_link)) {
440 _debug("unlinking once-pending call %p { e=%lx f=%lx }",
441 call, call->events, call->flags);
442 ASSERT(!test_bit(RXRPC_CALL_HAS_USERID, &call->flags));
443 list_del_init(&call->accept_link);
444 sk_acceptq_removed(&rx->sk);
445 } else if (test_bit(RXRPC_CALL_HAS_USERID, &call->flags)) {
446 rb_erase(&call->sock_node, &rx->calls);
447 memset(&call->sock_node, 0xdd, sizeof(call->sock_node));
448 clear_bit(RXRPC_CALL_HAS_USERID, &call->flags);
450 write_unlock_bh(&rx->call_lock);
452 /* free up the channel for reuse */
453 spin_lock(&conn->trans->client_lock);
454 write_lock_bh(&conn->lock);
455 write_lock(&call->state_lock);
457 if (conn->channels[call->channel] == call)
458 conn->channels[call->channel] = NULL;
460 if (conn->out_clientflag && conn->bundle) {
461 conn->avail_calls++;
462 switch (conn->avail_calls) {
463 case 1:
464 list_move_tail(&conn->bundle_link,
465 &conn->bundle->avail_conns);
466 case 2 ... RXRPC_MAXCALLS - 1:
467 ASSERT(conn->channels[0] == NULL ||
468 conn->channels[1] == NULL ||
469 conn->channels[2] == NULL ||
470 conn->channels[3] == NULL);
471 break;
472 case RXRPC_MAXCALLS:
473 list_move_tail(&conn->bundle_link,
474 &conn->bundle->unused_conns);
475 ASSERT(conn->channels[0] == NULL &&
476 conn->channels[1] == NULL &&
477 conn->channels[2] == NULL &&
478 conn->channels[3] == NULL);
479 break;
480 default:
481 printk(KERN_ERR "RxRPC: conn->avail_calls=%d\n",
482 conn->avail_calls);
483 BUG();
487 spin_unlock(&conn->trans->client_lock);
489 if (call->state < RXRPC_CALL_COMPLETE &&
490 call->state != RXRPC_CALL_CLIENT_FINAL_ACK) {
491 _debug("+++ ABORTING STATE %d +++\n", call->state);
492 call->state = RXRPC_CALL_LOCALLY_ABORTED;
493 call->abort_code = RX_CALL_DEAD;
494 set_bit(RXRPC_CALL_ABORT, &call->events);
495 rxrpc_queue_call(call);
497 write_unlock(&call->state_lock);
498 write_unlock_bh(&conn->lock);
500 /* clean up the Rx queue */
501 if (!skb_queue_empty(&call->rx_queue) ||
502 !skb_queue_empty(&call->rx_oos_queue)) {
503 struct rxrpc_skb_priv *sp;
504 struct sk_buff *skb;
506 _debug("purge Rx queues");
508 spin_lock_bh(&call->lock);
509 while ((skb = skb_dequeue(&call->rx_queue)) ||
510 (skb = skb_dequeue(&call->rx_oos_queue))) {
511 sp = rxrpc_skb(skb);
512 if (sp->call) {
513 ASSERTCMP(sp->call, ==, call);
514 rxrpc_put_call(call);
515 sp->call = NULL;
517 skb->destructor = NULL;
518 spin_unlock_bh(&call->lock);
520 _debug("- zap %s %%%u #%u",
521 rxrpc_pkts[sp->hdr.type],
522 ntohl(sp->hdr.serial),
523 ntohl(sp->hdr.seq));
524 rxrpc_free_skb(skb);
525 spin_lock_bh(&call->lock);
527 spin_unlock_bh(&call->lock);
529 ASSERTCMP(call->state, !=, RXRPC_CALL_COMPLETE);
532 del_timer_sync(&call->resend_timer);
533 del_timer_sync(&call->ack_timer);
534 del_timer_sync(&call->lifetimer);
535 call->deadspan.expires = jiffies + rxrpc_dead_call_timeout * HZ;
536 add_timer(&call->deadspan);
538 _leave("");
542 * handle a dead call being ready for reaping
544 static void rxrpc_dead_call_expired(unsigned long _call)
546 struct rxrpc_call *call = (struct rxrpc_call *) _call;
548 _enter("{%d}", call->debug_id);
550 write_lock_bh(&call->state_lock);
551 call->state = RXRPC_CALL_DEAD;
552 write_unlock_bh(&call->state_lock);
553 rxrpc_put_call(call);
557 * mark a call as to be released, aborting it if it's still in progress
558 * - called with softirqs disabled
560 static void rxrpc_mark_call_released(struct rxrpc_call *call)
562 bool sched;
564 write_lock(&call->state_lock);
565 if (call->state < RXRPC_CALL_DEAD) {
566 sched = false;
567 if (call->state < RXRPC_CALL_COMPLETE) {
568 _debug("abort call %p", call);
569 call->state = RXRPC_CALL_LOCALLY_ABORTED;
570 call->abort_code = RX_CALL_DEAD;
571 if (!test_and_set_bit(RXRPC_CALL_ABORT, &call->events))
572 sched = true;
574 if (!test_and_set_bit(RXRPC_CALL_RELEASE, &call->events))
575 sched = true;
576 if (sched)
577 rxrpc_queue_call(call);
579 write_unlock(&call->state_lock);
583 * release all the calls associated with a socket
585 void rxrpc_release_calls_on_socket(struct rxrpc_sock *rx)
587 struct rxrpc_call *call;
588 struct rb_node *p;
590 _enter("%p", rx);
592 read_lock_bh(&rx->call_lock);
594 /* mark all the calls as no longer wanting incoming packets */
595 for (p = rb_first(&rx->calls); p; p = rb_next(p)) {
596 call = rb_entry(p, struct rxrpc_call, sock_node);
597 rxrpc_mark_call_released(call);
600 /* kill the not-yet-accepted incoming calls */
601 list_for_each_entry(call, &rx->secureq, accept_link) {
602 rxrpc_mark_call_released(call);
605 list_for_each_entry(call, &rx->acceptq, accept_link) {
606 rxrpc_mark_call_released(call);
609 read_unlock_bh(&rx->call_lock);
610 _leave("");
614 * release a call
616 void __rxrpc_put_call(struct rxrpc_call *call)
618 ASSERT(call != NULL);
620 _enter("%p{u=%d}", call, atomic_read(&call->usage));
622 ASSERTCMP(atomic_read(&call->usage), >, 0);
624 if (atomic_dec_and_test(&call->usage)) {
625 _debug("call %d dead", call->debug_id);
626 ASSERTCMP(call->state, ==, RXRPC_CALL_DEAD);
627 rxrpc_queue_work(&call->destroyer);
629 _leave("");
633 * clean up a call
635 static void rxrpc_cleanup_call(struct rxrpc_call *call)
637 _net("DESTROY CALL %d", call->debug_id);
639 ASSERT(call->socket);
641 memset(&call->sock_node, 0xcd, sizeof(call->sock_node));
643 del_timer_sync(&call->lifetimer);
644 del_timer_sync(&call->deadspan);
645 del_timer_sync(&call->ack_timer);
646 del_timer_sync(&call->resend_timer);
648 ASSERT(test_bit(RXRPC_CALL_RELEASED, &call->flags));
649 ASSERTCMP(call->events, ==, 0);
650 if (work_pending(&call->processor)) {
651 _debug("defer destroy");
652 rxrpc_queue_work(&call->destroyer);
653 return;
656 if (call->conn) {
657 spin_lock(&call->conn->trans->peer->lock);
658 list_del(&call->error_link);
659 spin_unlock(&call->conn->trans->peer->lock);
661 write_lock_bh(&call->conn->lock);
662 rb_erase(&call->conn_node, &call->conn->calls);
663 write_unlock_bh(&call->conn->lock);
664 rxrpc_put_connection(call->conn);
667 if (call->acks_window) {
668 _debug("kill Tx window %d",
669 CIRC_CNT(call->acks_head, call->acks_tail,
670 call->acks_winsz));
671 smp_mb();
672 while (CIRC_CNT(call->acks_head, call->acks_tail,
673 call->acks_winsz) > 0) {
674 struct rxrpc_skb_priv *sp;
675 unsigned long _skb;
677 _skb = call->acks_window[call->acks_tail] & ~1;
678 sp = rxrpc_skb((struct sk_buff *) _skb);
679 _debug("+++ clear Tx %u", ntohl(sp->hdr.seq));
680 rxrpc_free_skb((struct sk_buff *) _skb);
681 call->acks_tail =
682 (call->acks_tail + 1) & (call->acks_winsz - 1);
685 kfree(call->acks_window);
688 rxrpc_free_skb(call->tx_pending);
690 rxrpc_purge_queue(&call->rx_queue);
691 ASSERT(skb_queue_empty(&call->rx_oos_queue));
692 sock_put(&call->socket->sk);
693 kmem_cache_free(rxrpc_call_jar, call);
697 * destroy a call
699 static void rxrpc_destroy_call(struct work_struct *work)
701 struct rxrpc_call *call =
702 container_of(work, struct rxrpc_call, destroyer);
704 _enter("%p{%d,%d,%p}",
705 call, atomic_read(&call->usage), call->channel, call->conn);
707 ASSERTCMP(call->state, ==, RXRPC_CALL_DEAD);
709 write_lock_bh(&rxrpc_call_lock);
710 list_del_init(&call->link);
711 write_unlock_bh(&rxrpc_call_lock);
713 rxrpc_cleanup_call(call);
714 _leave("");
718 * preemptively destroy all the call records from a transport endpoint rather
719 * than waiting for them to time out
721 void __exit rxrpc_destroy_all_calls(void)
723 struct rxrpc_call *call;
725 _enter("");
726 write_lock_bh(&rxrpc_call_lock);
728 while (!list_empty(&rxrpc_calls)) {
729 call = list_entry(rxrpc_calls.next, struct rxrpc_call, link);
730 _debug("Zapping call %p", call);
732 list_del_init(&call->link);
734 switch (atomic_read(&call->usage)) {
735 case 0:
736 ASSERTCMP(call->state, ==, RXRPC_CALL_DEAD);
737 break;
738 case 1:
739 if (del_timer_sync(&call->deadspan) != 0 &&
740 call->state != RXRPC_CALL_DEAD)
741 rxrpc_dead_call_expired((unsigned long) call);
742 if (call->state != RXRPC_CALL_DEAD)
743 break;
744 default:
745 printk(KERN_ERR "RXRPC:"
746 " Call %p still in use (%d,%d,%s,%lx,%lx)!\n",
747 call, atomic_read(&call->usage),
748 atomic_read(&call->ackr_not_idle),
749 rxrpc_call_states[call->state],
750 call->flags, call->events);
751 if (!skb_queue_empty(&call->rx_queue))
752 printk(KERN_ERR"RXRPC: Rx queue occupied\n");
753 if (!skb_queue_empty(&call->rx_oos_queue))
754 printk(KERN_ERR"RXRPC: OOS queue occupied\n");
755 break;
758 write_unlock_bh(&rxrpc_call_lock);
759 cond_resched();
760 write_lock_bh(&rxrpc_call_lock);
763 write_unlock_bh(&rxrpc_call_lock);
764 _leave("");
768 * handle call lifetime being exceeded
770 static void rxrpc_call_life_expired(unsigned long _call)
772 struct rxrpc_call *call = (struct rxrpc_call *) _call;
774 if (call->state >= RXRPC_CALL_COMPLETE)
775 return;
777 _enter("{%d}", call->debug_id);
778 read_lock_bh(&call->state_lock);
779 if (call->state < RXRPC_CALL_COMPLETE) {
780 set_bit(RXRPC_CALL_LIFE_TIMER, &call->events);
781 rxrpc_queue_call(call);
783 read_unlock_bh(&call->state_lock);
787 * handle resend timer expiry
789 static void rxrpc_resend_time_expired(unsigned long _call)
791 struct rxrpc_call *call = (struct rxrpc_call *) _call;
793 _enter("{%d}", call->debug_id);
795 if (call->state >= RXRPC_CALL_COMPLETE)
796 return;
798 read_lock_bh(&call->state_lock);
799 clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
800 if (call->state < RXRPC_CALL_COMPLETE &&
801 !test_and_set_bit(RXRPC_CALL_RESEND_TIMER, &call->events))
802 rxrpc_queue_call(call);
803 read_unlock_bh(&call->state_lock);
807 * handle ACK timer expiry
809 static void rxrpc_ack_time_expired(unsigned long _call)
811 struct rxrpc_call *call = (struct rxrpc_call *) _call;
813 _enter("{%d}", call->debug_id);
815 if (call->state >= RXRPC_CALL_COMPLETE)
816 return;
818 read_lock_bh(&call->state_lock);
819 if (call->state < RXRPC_CALL_COMPLETE &&
820 !test_and_set_bit(RXRPC_CALL_ACK, &call->events))
821 rxrpc_queue_call(call);
822 read_unlock_bh(&call->state_lock);