1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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"
31#include "hw/nmi.h"
32#include "qemu/help_option.h"
33
34static WatchdogAction watchdog_action = WATCHDOG_ACTION_RESET;
35static QLIST_HEAD(, WatchdogTimerModel) watchdog_list;
36
37void watchdog_add_model(WatchdogTimerModel *model)
38{
39 QLIST_INSERT_HEAD(&watchdog_list, model, entry);
40}
41
42
43
44
45
46
47int select_watchdog(const char *p)
48{
49 WatchdogTimerModel *model;
50 QemuOpts *opts;
51
52
53 if (is_help_option(p)) {
54 QLIST_FOREACH(model, &watchdog_list, entry) {
55 fprintf(stderr, "\t%s\t%s\n",
56 model->wdt_name, model->wdt_description);
57 }
58 return 2;
59 }
60
61 QLIST_FOREACH(model, &watchdog_list, entry) {
62 if (strcasecmp(model->wdt_name, p) == 0) {
63
64 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
65 &error_abort);
66 qemu_opt_set(opts, "driver", p, &error_abort);
67 return 0;
68 }
69 }
70
71 fprintf(stderr, "Unknown -watchdog device. Supported devices are:\n");
72 QLIST_FOREACH(model, &watchdog_list, entry) {
73 fprintf(stderr, "\t%s\t%s\n",
74 model->wdt_name, model->wdt_description);
75 }
76 return 1;
77}
78
79WatchdogAction get_watchdog_action(void)
80{
81 return watchdog_action;
82}
83
84
85
86
87void watchdog_perform_action(void)
88{
89 switch (watchdog_action) {
90 case WATCHDOG_ACTION_RESET:
91 qapi_event_send_watchdog(WATCHDOG_ACTION_RESET);
92 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
93 break;
94
95 case WATCHDOG_ACTION_SHUTDOWN:
96 qapi_event_send_watchdog(WATCHDOG_ACTION_SHUTDOWN);
97 qemu_system_powerdown_request();
98 break;
99
100 case WATCHDOG_ACTION_POWEROFF:
101 qapi_event_send_watchdog(WATCHDOG_ACTION_POWEROFF);
102 exit(0);
103
104 case WATCHDOG_ACTION_PAUSE:
105
106
107
108 qemu_system_vmstop_request_prepare();
109 qapi_event_send_watchdog(WATCHDOG_ACTION_PAUSE);
110 qemu_system_vmstop_request(RUN_STATE_WATCHDOG);
111 break;
112
113 case WATCHDOG_ACTION_DEBUG:
114 qapi_event_send_watchdog(WATCHDOG_ACTION_DEBUG);
115 fprintf(stderr, "watchdog: timer fired\n");
116 break;
117
118 case WATCHDOG_ACTION_NONE:
119 qapi_event_send_watchdog(WATCHDOG_ACTION_NONE);
120 break;
121
122 case WATCHDOG_ACTION_INJECT_NMI:
123 qapi_event_send_watchdog(WATCHDOG_ACTION_INJECT_NMI);
124 nmi_monitor_handle(0, NULL);
125 break;
126
127 default:
128 assert(0);
129 }
130}
131
132void qmp_watchdog_set_action(WatchdogAction action, Error **errp)
133{
134 watchdog_action = action;
135}
136