root / hw / watchdog.c @ 60398748
History | View | Annotate | Download (3.7 kB)
1 | 9dd986cc | Richard W.M. Jones | /*
|
---|---|---|---|
2 | 9dd986cc | Richard W.M. Jones | * Virtual hardware watchdog.
|
3 | 9dd986cc | Richard W.M. Jones | *
|
4 | 9dd986cc | Richard W.M. Jones | * Copyright (C) 2009 Red Hat Inc.
|
5 | 9dd986cc | Richard W.M. Jones | *
|
6 | 9dd986cc | Richard W.M. Jones | * This program is free software; you can redistribute it and/or
|
7 | 9dd986cc | Richard W.M. Jones | * modify it under the terms of the GNU General Public License
|
8 | 9dd986cc | Richard W.M. Jones | * as published by the Free Software Foundation; either version 2
|
9 | 9dd986cc | Richard W.M. Jones | * of the License, or (at your option) any later version.
|
10 | 9dd986cc | Richard W.M. Jones | *
|
11 | 9dd986cc | Richard W.M. Jones | * This program is distributed in the hope that it will be useful,
|
12 | 9dd986cc | Richard W.M. Jones | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 9dd986cc | Richard W.M. Jones | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 9dd986cc | Richard W.M. Jones | * GNU General Public License for more details.
|
15 | 9dd986cc | Richard W.M. Jones | *
|
16 | 9dd986cc | Richard W.M. Jones | * You should have received a copy of the GNU General Public License
|
17 | 8167ee88 | Blue Swirl | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
18 | 9dd986cc | Richard W.M. Jones | *
|
19 | 9dd986cc | Richard W.M. Jones | * By Richard W.M. Jones (rjones@redhat.com).
|
20 | 9dd986cc | Richard W.M. Jones | */
|
21 | 9dd986cc | Richard W.M. Jones | |
22 | 9dd986cc | Richard W.M. Jones | #include "qemu-common.h" |
23 | 09aaa160 | Markus Armbruster | #include "qemu-option.h" |
24 | 09aaa160 | Markus Armbruster | #include "qemu-config.h" |
25 | 72cf2d4f | Blue Swirl | #include "qemu-queue.h" |
26 | 9dd986cc | Richard W.M. Jones | #include "sysemu.h" |
27 | 9dd986cc | Richard W.M. Jones | #include "hw/watchdog.h" |
28 | 9dd986cc | Richard W.M. Jones | |
29 | 88b3be20 | Markus Armbruster | /* Possible values for action parameter. */
|
30 | 88b3be20 | Markus Armbruster | #define WDT_RESET 1 /* Hard reset. */ |
31 | 88b3be20 | Markus Armbruster | #define WDT_SHUTDOWN 2 /* Shutdown. */ |
32 | 88b3be20 | Markus Armbruster | #define WDT_POWEROFF 3 /* Quit. */ |
33 | 88b3be20 | Markus Armbruster | #define WDT_PAUSE 4 /* Pause. */ |
34 | 88b3be20 | Markus Armbruster | #define WDT_DEBUG 5 /* Prints a message and continues running. */ |
35 | 88b3be20 | Markus Armbruster | #define WDT_NONE 6 /* Do nothing. */ |
36 | 88b3be20 | Markus Armbruster | |
37 | 88b3be20 | Markus Armbruster | static int watchdog_action = WDT_RESET; |
38 | 72cf2d4f | Blue Swirl | static QLIST_HEAD(watchdog_list, WatchdogTimerModel) watchdog_list;
|
39 | 9dd986cc | Richard W.M. Jones | |
40 | 9dd986cc | Richard W.M. Jones | void watchdog_add_model(WatchdogTimerModel *model)
|
41 | 9dd986cc | Richard W.M. Jones | { |
42 | 72cf2d4f | Blue Swirl | QLIST_INSERT_HEAD(&watchdog_list, model, entry); |
43 | 9dd986cc | Richard W.M. Jones | } |
44 | 9dd986cc | Richard W.M. Jones | |
45 | 9dd986cc | Richard W.M. Jones | /* Returns:
|
46 | 9dd986cc | Richard W.M. Jones | * 0 = continue
|
47 | 9dd986cc | Richard W.M. Jones | * 1 = exit program with error
|
48 | 9dd986cc | Richard W.M. Jones | * 2 = exit program without error
|
49 | 9dd986cc | Richard W.M. Jones | */
|
50 | 9dd986cc | Richard W.M. Jones | int select_watchdog(const char *p) |
51 | 9dd986cc | Richard W.M. Jones | { |
52 | 9dd986cc | Richard W.M. Jones | WatchdogTimerModel *model; |
53 | 09aaa160 | Markus Armbruster | QemuOpts *opts; |
54 | 9dd986cc | Richard W.M. Jones | |
55 | 9dd986cc | Richard W.M. Jones | /* -watchdog ? lists available devices and exits cleanly. */
|
56 | 9dd986cc | Richard W.M. Jones | if (strcmp(p, "?") == 0) { |
57 | 72cf2d4f | Blue Swirl | QLIST_FOREACH(model, &watchdog_list, entry) { |
58 | 9dd986cc | Richard W.M. Jones | fprintf(stderr, "\t%s\t%s\n",
|
59 | 9dd986cc | Richard W.M. Jones | model->wdt_name, model->wdt_description); |
60 | 9dd986cc | Richard W.M. Jones | } |
61 | 9dd986cc | Richard W.M. Jones | return 2; |
62 | 9dd986cc | Richard W.M. Jones | } |
63 | 9dd986cc | Richard W.M. Jones | |
64 | 72cf2d4f | Blue Swirl | QLIST_FOREACH(model, &watchdog_list, entry) { |
65 | 9dd986cc | Richard W.M. Jones | if (strcasecmp(model->wdt_name, p) == 0) { |
66 | 09aaa160 | Markus Armbruster | /* add the device */
|
67 | 09aaa160 | Markus Armbruster | opts = qemu_opts_create(&qemu_device_opts, NULL, 0); |
68 | 09aaa160 | Markus Armbruster | qemu_opt_set(opts, "driver", p);
|
69 | 9dd986cc | Richard W.M. Jones | return 0; |
70 | 9dd986cc | Richard W.M. Jones | } |
71 | 9dd986cc | Richard W.M. Jones | } |
72 | 9dd986cc | Richard W.M. Jones | |
73 | 9dd986cc | Richard W.M. Jones | fprintf(stderr, "Unknown -watchdog device. Supported devices are:\n");
|
74 | 72cf2d4f | Blue Swirl | QLIST_FOREACH(model, &watchdog_list, entry) { |
75 | 9dd986cc | Richard W.M. Jones | fprintf(stderr, "\t%s\t%s\n",
|
76 | 9dd986cc | Richard W.M. Jones | model->wdt_name, model->wdt_description); |
77 | 9dd986cc | Richard W.M. Jones | } |
78 | 9dd986cc | Richard W.M. Jones | return 1; |
79 | 9dd986cc | Richard W.M. Jones | } |
80 | 9dd986cc | Richard W.M. Jones | |
81 | 9dd986cc | Richard W.M. Jones | int select_watchdog_action(const char *p) |
82 | 9dd986cc | Richard W.M. Jones | { |
83 | 9dd986cc | Richard W.M. Jones | if (strcasecmp(p, "reset") == 0) |
84 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_RESET; |
85 | 9dd986cc | Richard W.M. Jones | else if (strcasecmp(p, "shutdown") == 0) |
86 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_SHUTDOWN; |
87 | 9dd986cc | Richard W.M. Jones | else if (strcasecmp(p, "poweroff") == 0) |
88 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_POWEROFF; |
89 | 9dd986cc | Richard W.M. Jones | else if (strcasecmp(p, "pause") == 0) |
90 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_PAUSE; |
91 | 9dd986cc | Richard W.M. Jones | else if (strcasecmp(p, "debug") == 0) |
92 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_DEBUG; |
93 | 9dd986cc | Richard W.M. Jones | else if (strcasecmp(p, "none") == 0) |
94 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_NONE; |
95 | 9dd986cc | Richard W.M. Jones | else
|
96 | 9dd986cc | Richard W.M. Jones | return -1; |
97 | 9dd986cc | Richard W.M. Jones | |
98 | 9dd986cc | Richard W.M. Jones | return 0; |
99 | 9dd986cc | Richard W.M. Jones | } |
100 | 9dd986cc | Richard W.M. Jones | |
101 | 9dd986cc | Richard W.M. Jones | /* This actually performs the "action" once a watchdog has expired,
|
102 | 9dd986cc | Richard W.M. Jones | * ie. reboot, shutdown, exit, etc.
|
103 | 9dd986cc | Richard W.M. Jones | */
|
104 | 9dd986cc | Richard W.M. Jones | void watchdog_perform_action(void) |
105 | 9dd986cc | Richard W.M. Jones | { |
106 | 9dd986cc | Richard W.M. Jones | switch(watchdog_action) {
|
107 | 9dd986cc | Richard W.M. Jones | case WDT_RESET: /* same as 'system_reset' in monitor */ |
108 | 9dd986cc | Richard W.M. Jones | qemu_system_reset_request(); |
109 | 9dd986cc | Richard W.M. Jones | break;
|
110 | 9dd986cc | Richard W.M. Jones | |
111 | 9dd986cc | Richard W.M. Jones | case WDT_SHUTDOWN: /* same as 'system_powerdown' in monitor */ |
112 | 9dd986cc | Richard W.M. Jones | qemu_system_powerdown_request(); |
113 | 9dd986cc | Richard W.M. Jones | break;
|
114 | 9dd986cc | Richard W.M. Jones | |
115 | 9dd986cc | Richard W.M. Jones | case WDT_POWEROFF: /* same as 'quit' command in monitor */ |
116 | 9dd986cc | Richard W.M. Jones | exit(0);
|
117 | 9dd986cc | Richard W.M. Jones | break;
|
118 | 9dd986cc | Richard W.M. Jones | |
119 | 9dd986cc | Richard W.M. Jones | case WDT_PAUSE: /* same as 'stop' command in monitor */ |
120 | 9dd986cc | Richard W.M. Jones | vm_stop(0);
|
121 | 9dd986cc | Richard W.M. Jones | break;
|
122 | 9dd986cc | Richard W.M. Jones | |
123 | 9dd986cc | Richard W.M. Jones | case WDT_DEBUG:
|
124 | 9dd986cc | Richard W.M. Jones | fprintf(stderr, "watchdog: timer fired\n");
|
125 | 9dd986cc | Richard W.M. Jones | break;
|
126 | 9dd986cc | Richard W.M. Jones | |
127 | 9dd986cc | Richard W.M. Jones | case WDT_NONE:
|
128 | 9dd986cc | Richard W.M. Jones | break;
|
129 | 9dd986cc | Richard W.M. Jones | } |
130 | 9dd986cc | Richard W.M. Jones | } |