2 * Virtual hardware watchdog.
4 * Copyright (C) 2009 Red Hat Inc.
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 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 * By Richard W.M. Jones (rjones@redhat.com).
22 #include "qemu/osdep.h"
23 #include "qemu/option.h"
24 #include "qemu/config-file.h"
25 #include "qemu/queue.h"
26 #include "qapi/error.h"
27 #include "qapi/qapi-commands-run-state.h"
28 #include "qapi/qapi-events-run-state.h"
29 #include "sysemu/runstate.h"
30 #include "sysemu/watchdog.h"
32 #include "qemu/help_option.h"
35 static WatchdogAction watchdog_action
= WATCHDOG_ACTION_RESET
;
37 WatchdogAction
get_watchdog_action(void)
39 return watchdog_action
;
42 /* This actually performs the "action" once a watchdog has expired,
43 * ie. reboot, shutdown, exit, etc.
45 void watchdog_perform_action(void)
47 trace_watchdog_perform_action(watchdog_action
);
49 switch (watchdog_action
) {
50 case WATCHDOG_ACTION_RESET
: /* same as 'system_reset' in monitor */
51 qapi_event_send_watchdog(WATCHDOG_ACTION_RESET
);
52 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
55 case WATCHDOG_ACTION_SHUTDOWN
: /* same as 'system_powerdown' in monitor */
56 qapi_event_send_watchdog(WATCHDOG_ACTION_SHUTDOWN
);
57 qemu_system_powerdown_request();
60 case WATCHDOG_ACTION_POWEROFF
: /* same as 'quit' command in monitor */
61 qapi_event_send_watchdog(WATCHDOG_ACTION_POWEROFF
);
64 case WATCHDOG_ACTION_PAUSE
: /* same as 'stop' command in monitor */
65 /* In a timer callback, when vm_stop calls qemu_clock_enable
66 * you would get a deadlock. Bypass the problem.
68 qemu_system_vmstop_request_prepare();
69 qapi_event_send_watchdog(WATCHDOG_ACTION_PAUSE
);
70 qemu_system_vmstop_request(RUN_STATE_WATCHDOG
);
73 case WATCHDOG_ACTION_DEBUG
:
74 qapi_event_send_watchdog(WATCHDOG_ACTION_DEBUG
);
75 fprintf(stderr
, "watchdog: timer fired\n");
78 case WATCHDOG_ACTION_NONE
:
79 qapi_event_send_watchdog(WATCHDOG_ACTION_NONE
);
82 case WATCHDOG_ACTION_INJECT_NMI
:
83 qapi_event_send_watchdog(WATCHDOG_ACTION_INJECT_NMI
);
84 nmi_monitor_handle(0, NULL
);
92 void qmp_watchdog_set_action(WatchdogAction action
, Error
**errp
)
94 watchdog_action
= action
;
95 trace_watchdog_set_action(watchdog_action
);