2009-04-25 12:56:19 +00:00
|
|
|
/*
|
|
|
|
* Virtual hardware watchdog.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-07-16 20:47:01 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2009-04-25 12:56:19 +00:00
|
|
|
*
|
|
|
|
* By Richard W.M. Jones (rjones@redhat.com).
|
|
|
|
*/
|
|
|
|
|
2016-01-26 18:17:30 +00:00
|
|
|
#include "qemu/osdep.h"
|
2012-12-17 17:20:00 +00:00
|
|
|
#include "qemu/option.h"
|
|
|
|
#include "qemu/config-file.h"
|
|
|
|
#include "qemu/queue.h"
|
2018-02-01 11:18:31 +00:00
|
|
|
#include "qapi/error.h"
|
2018-02-26 23:13:27 +00:00
|
|
|
#include "qapi/qapi-commands-run-state.h"
|
2018-02-11 09:36:01 +00:00
|
|
|
#include "qapi/qapi-events-run-state.h"
|
2019-08-12 05:23:59 +00:00
|
|
|
#include "sysemu/runstate.h"
|
2013-02-05 16:06:20 +00:00
|
|
|
#include "sysemu/watchdog.h"
|
2015-02-05 10:28:36 +00:00
|
|
|
#include "hw/nmi.h"
|
2016-03-20 17:16:19 +00:00
|
|
|
#include "qemu/help_option.h"
|
2022-12-16 12:57:47 +00:00
|
|
|
#include "trace.h"
|
2009-04-25 12:56:19 +00:00
|
|
|
|
2017-09-07 08:05:25 +00:00
|
|
|
static WatchdogAction watchdog_action = WATCHDOG_ACTION_RESET;
|
2009-04-25 12:56:19 +00:00
|
|
|
|
2017-09-07 08:05:25 +00:00
|
|
|
WatchdogAction get_watchdog_action(void)
|
2016-01-19 07:34:41 +00:00
|
|
|
{
|
|
|
|
return watchdog_action;
|
|
|
|
}
|
|
|
|
|
2009-04-25 12:56:19 +00:00
|
|
|
/* This actually performs the "action" once a watchdog has expired,
|
|
|
|
* ie. reboot, shutdown, exit, etc.
|
|
|
|
*/
|
|
|
|
void watchdog_perform_action(void)
|
|
|
|
{
|
2022-12-16 12:57:47 +00:00
|
|
|
trace_watchdog_perform_action(watchdog_action);
|
|
|
|
|
2014-06-24 23:34:00 +00:00
|
|
|
switch (watchdog_action) {
|
2017-09-07 08:05:25 +00:00
|
|
|
case WATCHDOG_ACTION_RESET: /* same as 'system_reset' in monitor */
|
2018-08-15 13:37:37 +00:00
|
|
|
qapi_event_send_watchdog(WATCHDOG_ACTION_RESET);
|
2017-05-15 21:41:13 +00:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2009-04-25 12:56:19 +00:00
|
|
|
break;
|
|
|
|
|
2017-09-07 08:05:25 +00:00
|
|
|
case WATCHDOG_ACTION_SHUTDOWN: /* same as 'system_powerdown' in monitor */
|
2018-08-15 13:37:37 +00:00
|
|
|
qapi_event_send_watchdog(WATCHDOG_ACTION_SHUTDOWN);
|
2009-04-25 12:56:19 +00:00
|
|
|
qemu_system_powerdown_request();
|
|
|
|
break;
|
|
|
|
|
2017-09-07 08:05:25 +00:00
|
|
|
case WATCHDOG_ACTION_POWEROFF: /* same as 'quit' command in monitor */
|
2018-08-15 13:37:37 +00:00
|
|
|
qapi_event_send_watchdog(WATCHDOG_ACTION_POWEROFF);
|
2009-04-25 12:56:19 +00:00
|
|
|
exit(0);
|
|
|
|
|
2017-09-07 08:05:25 +00:00
|
|
|
case WATCHDOG_ACTION_PAUSE: /* same as 'stop' command in monitor */
|
2014-06-27 14:31:07 +00:00
|
|
|
/* In a timer callback, when vm_stop calls qemu_clock_enable
|
|
|
|
* you would get a deadlock. Bypass the problem.
|
|
|
|
*/
|
|
|
|
qemu_system_vmstop_request_prepare();
|
2018-08-15 13:37:37 +00:00
|
|
|
qapi_event_send_watchdog(WATCHDOG_ACTION_PAUSE);
|
2014-06-27 14:31:07 +00:00
|
|
|
qemu_system_vmstop_request(RUN_STATE_WATCHDOG);
|
2009-04-25 12:56:19 +00:00
|
|
|
break;
|
|
|
|
|
2017-09-07 08:05:25 +00:00
|
|
|
case WATCHDOG_ACTION_DEBUG:
|
2018-08-15 13:37:37 +00:00
|
|
|
qapi_event_send_watchdog(WATCHDOG_ACTION_DEBUG);
|
2009-04-25 12:56:19 +00:00
|
|
|
fprintf(stderr, "watchdog: timer fired\n");
|
|
|
|
break;
|
|
|
|
|
2017-09-07 08:05:25 +00:00
|
|
|
case WATCHDOG_ACTION_NONE:
|
2018-08-15 13:37:37 +00:00
|
|
|
qapi_event_send_watchdog(WATCHDOG_ACTION_NONE);
|
2009-04-25 12:56:19 +00:00
|
|
|
break;
|
2015-02-05 10:28:36 +00:00
|
|
|
|
2017-09-07 08:05:25 +00:00
|
|
|
case WATCHDOG_ACTION_INJECT_NMI:
|
2018-08-15 13:37:37 +00:00
|
|
|
qapi_event_send_watchdog(WATCHDOG_ACTION_INJECT_NMI);
|
2016-05-20 16:28:36 +00:00
|
|
|
nmi_monitor_handle(0, NULL);
|
2015-02-05 10:28:36 +00:00
|
|
|
break;
|
2017-09-07 08:05:25 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
2009-04-25 12:56:19 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-07 08:05:26 +00:00
|
|
|
|
|
|
|
void qmp_watchdog_set_action(WatchdogAction action, Error **errp)
|
|
|
|
{
|
|
|
|
watchdog_action = action;
|
2022-12-16 12:57:47 +00:00
|
|
|
trace_watchdog_set_action(watchdog_action);
|
2017-09-07 08:05:26 +00:00
|
|
|
}
|