runstate.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef SYSTEM_RUNSTATE_H
  2. #define SYSTEM_RUNSTATE_H
  3. #include "qapi/qapi-types-run-state.h"
  4. #include "qemu/notify.h"
  5. bool runstate_check(RunState state);
  6. void runstate_set(RunState new_state);
  7. RunState runstate_get(void);
  8. bool runstate_is_running(void);
  9. bool runstate_needs_reset(void);
  10. void runstate_replay_enable(void);
  11. typedef void VMChangeStateHandler(void *opaque, bool running, RunState state);
  12. VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
  13. void *opaque);
  14. VMChangeStateEntry *qemu_add_vm_change_state_handler_prio(
  15. VMChangeStateHandler *cb, void *opaque, int priority);
  16. VMChangeStateEntry *
  17. qemu_add_vm_change_state_handler_prio_full(VMChangeStateHandler *cb,
  18. VMChangeStateHandler *prepare_cb,
  19. void *opaque, int priority);
  20. VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev,
  21. VMChangeStateHandler *cb,
  22. void *opaque);
  23. VMChangeStateEntry *qdev_add_vm_change_state_handler_full(
  24. DeviceState *dev, VMChangeStateHandler *cb,
  25. VMChangeStateHandler *prepare_cb, void *opaque);
  26. void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
  27. /**
  28. * vm_state_notify: Notify the state of the VM
  29. *
  30. * @running: whether the VM is running or not.
  31. * @state: the #RunState of the VM.
  32. */
  33. void vm_state_notify(bool running, RunState state);
  34. static inline bool shutdown_caused_by_guest(ShutdownCause cause)
  35. {
  36. return cause >= SHUTDOWN_CAUSE_GUEST_SHUTDOWN;
  37. }
  38. /*
  39. * In a "live" state, the vcpu clock is ticking, and the runstate notifiers
  40. * think we are running.
  41. */
  42. static inline bool runstate_is_live(RunState state)
  43. {
  44. return state == RUN_STATE_RUNNING || state == RUN_STATE_SUSPENDED;
  45. }
  46. void vm_start(void);
  47. /**
  48. * vm_prepare_start: Prepare for starting/resuming the VM
  49. *
  50. * @step_pending: whether any of the CPUs is about to be single-stepped by gdb
  51. */
  52. int vm_prepare_start(bool step_pending);
  53. /**
  54. * vm_resume: If @state is a live state, start the vm and set the state,
  55. * else just set the state.
  56. *
  57. * @state: the state to restore
  58. */
  59. void vm_resume(RunState state);
  60. int vm_stop(RunState state);
  61. int vm_stop_force_state(RunState state);
  62. int vm_shutdown(void);
  63. void vm_set_suspended(bool suspended);
  64. bool vm_get_suspended(void);
  65. typedef enum WakeupReason {
  66. /* Always keep QEMU_WAKEUP_REASON_NONE = 0 */
  67. QEMU_WAKEUP_REASON_NONE = 0,
  68. QEMU_WAKEUP_REASON_RTC,
  69. QEMU_WAKEUP_REASON_PMTIMER,
  70. QEMU_WAKEUP_REASON_OTHER,
  71. } WakeupReason;
  72. void qemu_system_reset_request(ShutdownCause reason);
  73. void qemu_system_suspend_request(void);
  74. void qemu_register_suspend_notifier(Notifier *notifier);
  75. bool qemu_wakeup_suspend_enabled(void);
  76. void qemu_system_wakeup_request(WakeupReason reason, Error **errp);
  77. void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
  78. void qemu_register_wakeup_notifier(Notifier *notifier);
  79. void qemu_register_wakeup_support(void);
  80. void qemu_system_shutdown_request_with_code(ShutdownCause reason,
  81. int exit_code);
  82. void qemu_system_shutdown_request(ShutdownCause reason);
  83. void qemu_system_powerdown_request(void);
  84. void qemu_register_powerdown_notifier(Notifier *notifier);
  85. void qemu_register_shutdown_notifier(Notifier *notifier);
  86. void qemu_system_debug_request(void);
  87. void qemu_system_vmstop_request(RunState reason);
  88. void qemu_system_vmstop_request_prepare(void);
  89. bool qemu_vmstop_requested(RunState *r);
  90. ShutdownCause qemu_shutdown_requested_get(void);
  91. ShutdownCause qemu_reset_requested_get(void);
  92. void qemu_system_killed(int signal, pid_t pid);
  93. void qemu_system_reset(ShutdownCause reason);
  94. void qemu_system_guest_panicked(GuestPanicInformation *info);
  95. void qemu_system_guest_crashloaded(GuestPanicInformation *info);
  96. void qemu_system_guest_pvshutdown(void);
  97. bool qemu_system_dump_in_progress(void);
  98. #endif