call_state.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* Call state changing functions.
  3. *
  4. * Copyright (C) 2022 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #include "ar-internal.h"
  8. /*
  9. * Transition a call to the complete state.
  10. */
  11. bool rxrpc_set_call_completion(struct rxrpc_call *call,
  12. enum rxrpc_call_completion compl,
  13. u32 abort_code,
  14. int error)
  15. {
  16. if (__rxrpc_call_state(call) == RXRPC_CALL_COMPLETE)
  17. return false;
  18. call->abort_code = abort_code;
  19. call->error = error;
  20. call->completion = compl;
  21. /* Allow reader of completion state to operate locklessly */
  22. rxrpc_set_call_state(call, RXRPC_CALL_COMPLETE);
  23. trace_rxrpc_call_complete(call);
  24. wake_up(&call->waitq);
  25. rxrpc_notify_socket(call);
  26. return true;
  27. }
  28. /*
  29. * Record that a call successfully completed.
  30. */
  31. bool rxrpc_call_completed(struct rxrpc_call *call)
  32. {
  33. return rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0);
  34. }
  35. /*
  36. * Record that a call is locally aborted.
  37. */
  38. bool rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq,
  39. u32 abort_code, int error, enum rxrpc_abort_reason why)
  40. {
  41. trace_rxrpc_abort(call->debug_id, why, call->cid, call->call_id, seq,
  42. abort_code, error);
  43. if (!rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED,
  44. abort_code, error))
  45. return false;
  46. if (test_bit(RXRPC_CALL_EXPOSED, &call->flags))
  47. rxrpc_send_abort_packet(call);
  48. return true;
  49. }
  50. /*
  51. * Record that a call errored out before even getting off the ground, thereby
  52. * setting the state to allow it to be destroyed.
  53. */
  54. void rxrpc_prefail_call(struct rxrpc_call *call, enum rxrpc_call_completion compl,
  55. int error)
  56. {
  57. call->abort_code = RX_CALL_DEAD;
  58. call->error = error;
  59. call->completion = compl;
  60. call->_state = RXRPC_CALL_COMPLETE;
  61. trace_rxrpc_call_complete(call);
  62. WARN_ON_ONCE(__test_and_set_bit(RXRPC_CALL_RELEASED, &call->flags));
  63. }