Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Handle extern requests for shutdown, reboot and sysrq |
| 3 | */ |
| 4 | #include <linux/kernel.h> |
| 5 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 6 | #include <linux/slab.h> |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 7 | #include <linux/reboot.h> |
| 8 | #include <linux/sysrq.h> |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 9 | #include <linux/stop_machine.h> |
| 10 | #include <linux/freezer.h> |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 11 | |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 12 | #include <xen/xen.h> |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 13 | #include <xen/xenbus.h> |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 14 | #include <xen/grant_table.h> |
| 15 | #include <xen/events.h> |
| 16 | #include <xen/hvc-console.h> |
| 17 | #include <xen/xen-ops.h> |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 18 | |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 19 | #include <asm/xen/hypercall.h> |
| 20 | #include <asm/xen/page.h> |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 21 | #include <asm/xen/hypervisor.h> |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 22 | |
| 23 | enum shutdown_state { |
| 24 | SHUTDOWN_INVALID = -1, |
| 25 | SHUTDOWN_POWEROFF = 0, |
| 26 | SHUTDOWN_SUSPEND = 2, |
| 27 | /* Code 3 is SHUTDOWN_CRASH, which we don't use because the domain can only |
| 28 | report a crash, not be instructed to crash! |
| 29 | HALT is the same as POWEROFF, as far as we're concerned. The tools use |
| 30 | the distinction when we return the reason code to them. */ |
| 31 | SHUTDOWN_HALT = 4, |
| 32 | }; |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 33 | |
| 34 | /* Ignore multiple shutdown requests. */ |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 35 | static enum shutdown_state shutting_down = SHUTDOWN_INVALID; |
| 36 | |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 37 | struct suspend_info { |
| 38 | int cancelled; |
Ian Campbell | 36b401e | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 39 | unsigned long arg; /* extra hypercall argument */ |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
Jeremy Fitzhardinge | c782772 | 2008-05-29 09:02:19 +0100 | [diff] [blame] | 42 | #ifdef CONFIG_PM_SLEEP |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 43 | static int xen_hvm_suspend(void *data) |
| 44 | { |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 45 | struct suspend_info *si = data; |
Ian Campbell | 8dd3838 | 2011-02-17 10:31:20 +0000 | [diff] [blame] | 46 | int err; |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 47 | |
| 48 | BUG_ON(!irqs_disabled()); |
| 49 | |
Ian Campbell | 8dd3838 | 2011-02-17 10:31:20 +0000 | [diff] [blame] | 50 | err = sysdev_suspend(PMSG_SUSPEND); |
| 51 | if (err) { |
| 52 | printk(KERN_ERR "xen_hvm_suspend: sysdev_suspend failed: %d\n", |
| 53 | err); |
| 54 | return err; |
| 55 | } |
| 56 | |
Ian Campbell | bd1c0ad | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 57 | /* |
| 58 | * This hypercall returns 1 if suspend was cancelled |
| 59 | * or the domain was merely checkpointed, and 0 if it |
| 60 | * is resuming in a new domain. |
| 61 | */ |
Ian Campbell | 36b401e | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 62 | si->cancelled = HYPERVISOR_suspend(si->arg); |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 63 | |
Ian Campbell | 03c8142 | 2011-02-17 11:04:20 +0000 | [diff] [blame^] | 64 | xen_arch_hvm_post_suspend(si->cancelled); |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 65 | gnttab_resume(); |
| 66 | |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 67 | if (!si->cancelled) { |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 68 | xen_irq_resume(); |
Stefano Stabellini | 6411fe69 | 2010-12-01 14:51:44 +0000 | [diff] [blame] | 69 | xen_console_resume(); |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 70 | xen_timer_resume(); |
| 71 | } |
| 72 | |
Ian Campbell | 8dd3838 | 2011-02-17 10:31:20 +0000 | [diff] [blame] | 73 | sysdev_resume(); |
| 74 | |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 78 | static int xen_suspend(void *data) |
| 79 | { |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 80 | struct suspend_info *si = data; |
Jeremy Fitzhardinge | 359cdd3 | 2008-05-26 23:31:28 +0100 | [diff] [blame] | 81 | int err; |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 82 | |
| 83 | BUG_ON(!irqs_disabled()); |
| 84 | |
Rafael J. Wysocki | 770824b | 2009-02-22 18:38:50 +0100 | [diff] [blame] | 85 | err = sysdev_suspend(PMSG_SUSPEND); |
| 86 | if (err) { |
| 87 | printk(KERN_ERR "xen_suspend: sysdev_suspend failed: %d\n", |
| 88 | err); |
Rafael J. Wysocki | 770824b | 2009-02-22 18:38:50 +0100 | [diff] [blame] | 89 | return err; |
| 90 | } |
Jeremy Fitzhardinge | 359cdd3 | 2008-05-26 23:31:28 +0100 | [diff] [blame] | 91 | |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 92 | xen_mm_pin_all(); |
| 93 | gnttab_suspend(); |
Ian Campbell | 03c8142 | 2011-02-17 11:04:20 +0000 | [diff] [blame^] | 94 | xen_arch_pre_suspend(); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * This hypercall returns 1 if suspend was cancelled |
| 98 | * or the domain was merely checkpointed, and 0 if it |
| 99 | * is resuming in a new domain. |
| 100 | */ |
Ian Campbell | 36b401e | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 101 | si->cancelled = HYPERVISOR_suspend(si->arg); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 102 | |
Ian Campbell | 03c8142 | 2011-02-17 11:04:20 +0000 | [diff] [blame^] | 103 | xen_arch_post_suspend(si->cancelled); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 104 | gnttab_resume(); |
| 105 | xen_mm_unpin_all(); |
| 106 | |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 107 | if (!si->cancelled) { |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 108 | xen_irq_resume(); |
| 109 | xen_console_resume(); |
Isaku Yamahata | ad55db9 | 2008-07-08 15:06:32 -0700 | [diff] [blame] | 110 | xen_timer_resume(); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Ian Campbell | 1e6fcf8 | 2009-03-25 17:46:42 +0000 | [diff] [blame] | 113 | sysdev_resume(); |
Ian Campbell | 1e6fcf8 | 2009-03-25 17:46:42 +0000 | [diff] [blame] | 114 | |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | static void do_suspend(void) |
| 119 | { |
| 120 | int err; |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 121 | struct suspend_info si; |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 122 | |
| 123 | shutting_down = SHUTDOWN_SUSPEND; |
| 124 | |
| 125 | #ifdef CONFIG_PREEMPT |
| 126 | /* If the kernel is preemptible, we need to freeze all the processes |
| 127 | to prevent them from being in the middle of a pagetable update |
| 128 | during suspend. */ |
| 129 | err = freeze_processes(); |
| 130 | if (err) { |
| 131 | printk(KERN_ERR "xen suspend: freeze failed %d\n", err); |
Tejun Heo | 3fc1f1e | 2010-05-06 18:49:20 +0200 | [diff] [blame] | 132 | goto out; |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 133 | } |
| 134 | #endif |
| 135 | |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 136 | err = dpm_suspend_start(PMSG_SUSPEND); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 137 | if (err) { |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 138 | printk(KERN_ERR "xen suspend: dpm_suspend_start %d\n", err); |
Ian Campbell | 65f6338 | 2009-12-01 11:47:14 +0000 | [diff] [blame] | 139 | goto out_thaw; |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Ian Campbell | c5cae66 | 2009-12-17 13:57:09 +0000 | [diff] [blame] | 142 | printk(KERN_DEBUG "suspending xenstore...\n"); |
| 143 | xs_suspend(); |
| 144 | |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 145 | err = dpm_suspend_noirq(PMSG_SUSPEND); |
Rafael J. Wysocki | 2ed8d2b | 2009-03-16 22:34:06 +0100 | [diff] [blame] | 146 | if (err) { |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 147 | printk(KERN_ERR "dpm_suspend_noirq failed: %d\n", err); |
Ian Campbell | 65f6338 | 2009-12-01 11:47:14 +0000 | [diff] [blame] | 148 | goto out_resume; |
Rafael J. Wysocki | 2ed8d2b | 2009-03-16 22:34:06 +0100 | [diff] [blame] | 149 | } |
| 150 | |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 151 | si.cancelled = 1; |
| 152 | |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 153 | if (xen_hvm_domain()) |
Ian Campbell | 36b401e | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 154 | si.arg = 0UL; |
| 155 | else |
| 156 | si.arg = virt_to_mfn(xen_start_info); |
| 157 | |
| 158 | if (xen_hvm_domain()) |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 159 | err = stop_machine(xen_hvm_suspend, &si, cpumask_of(0)); |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 160 | else |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 161 | err = stop_machine(xen_suspend, &si, cpumask_of(0)); |
Jeremy Fitzhardinge | 922cc38a | 2009-11-24 09:58:49 -0800 | [diff] [blame] | 162 | |
| 163 | dpm_resume_noirq(PMSG_RESUME); |
| 164 | |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 165 | if (err) { |
| 166 | printk(KERN_ERR "failed to start xen_suspend: %d\n", err); |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 167 | si.cancelled = 1; |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 168 | } |
| 169 | |
Ian Campbell | c5cae66 | 2009-12-17 13:57:09 +0000 | [diff] [blame] | 170 | out_resume: |
Ian Campbell | ceb1802 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 171 | if (!si.cancelled) { |
Isaku Yamahata | ad55db9 | 2008-07-08 15:06:32 -0700 | [diff] [blame] | 172 | xen_arch_resume(); |
Ian Campbell | de5b31b | 2009-02-09 12:05:50 -0800 | [diff] [blame] | 173 | xs_resume(); |
Isaku Yamahata | ad55db9 | 2008-07-08 15:06:32 -0700 | [diff] [blame] | 174 | } else |
Ian Campbell | de5b31b | 2009-02-09 12:05:50 -0800 | [diff] [blame] | 175 | xs_suspend_cancel(); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 176 | |
Alan Stern | d161630 | 2009-05-24 22:05:42 +0200 | [diff] [blame] | 177 | dpm_resume_end(PMSG_RESUME); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 178 | |
Jeremy Fitzhardinge | 359cdd3 | 2008-05-26 23:31:28 +0100 | [diff] [blame] | 179 | /* Make sure timer events get retriggered on all CPUs */ |
| 180 | clock_was_set(); |
Ian Campbell | 65f6338 | 2009-12-01 11:47:14 +0000 | [diff] [blame] | 181 | |
| 182 | out_thaw: |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 183 | #ifdef CONFIG_PREEMPT |
| 184 | thaw_processes(); |
Ian Campbell | 65f6338 | 2009-12-01 11:47:14 +0000 | [diff] [blame] | 185 | out: |
Tejun Heo | 3fc1f1e | 2010-05-06 18:49:20 +0200 | [diff] [blame] | 186 | #endif |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 187 | shutting_down = SHUTDOWN_INVALID; |
| 188 | } |
Jeremy Fitzhardinge | c782772 | 2008-05-29 09:02:19 +0100 | [diff] [blame] | 189 | #endif /* CONFIG_PM_SLEEP */ |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 190 | |
Ian Campbell | 5527172 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 191 | struct shutdown_handler { |
| 192 | const char *command; |
| 193 | void (*cb)(void); |
| 194 | }; |
| 195 | |
| 196 | static void do_poweroff(void) |
| 197 | { |
| 198 | shutting_down = SHUTDOWN_POWEROFF; |
| 199 | orderly_poweroff(false); |
| 200 | } |
| 201 | |
| 202 | static void do_reboot(void) |
| 203 | { |
| 204 | shutting_down = SHUTDOWN_POWEROFF; /* ? */ |
| 205 | ctrl_alt_del(); |
| 206 | } |
| 207 | |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 208 | static void shutdown_handler(struct xenbus_watch *watch, |
| 209 | const char **vec, unsigned int len) |
| 210 | { |
| 211 | char *str; |
| 212 | struct xenbus_transaction xbt; |
| 213 | int err; |
Ian Campbell | 5527172 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 214 | static struct shutdown_handler handlers[] = { |
| 215 | { "poweroff", do_poweroff }, |
| 216 | { "halt", do_poweroff }, |
| 217 | { "reboot", do_reboot }, |
| 218 | #ifdef CONFIG_PM_SLEEP |
| 219 | { "suspend", do_suspend }, |
| 220 | #endif |
| 221 | {NULL, NULL}, |
| 222 | }; |
| 223 | static struct shutdown_handler *handler; |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 224 | |
| 225 | if (shutting_down != SHUTDOWN_INVALID) |
| 226 | return; |
| 227 | |
| 228 | again: |
| 229 | err = xenbus_transaction_start(&xbt); |
| 230 | if (err) |
| 231 | return; |
| 232 | |
| 233 | str = (char *)xenbus_read(xbt, "control", "shutdown", NULL); |
| 234 | /* Ignore read errors and empty reads. */ |
| 235 | if (XENBUS_IS_ERR_READ(str)) { |
| 236 | xenbus_transaction_end(xbt, 1); |
| 237 | return; |
| 238 | } |
| 239 | |
Ian Campbell | 5527172 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 240 | for (handler = &handlers[0]; handler->command; handler++) { |
| 241 | if (strcmp(str, handler->command) == 0) |
| 242 | break; |
| 243 | } |
| 244 | |
| 245 | /* Only acknowledge commands which we are prepared to handle. */ |
| 246 | if (handler->cb) |
| 247 | xenbus_write(xbt, "control", "shutdown", ""); |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 248 | |
| 249 | err = xenbus_transaction_end(xbt, 0); |
| 250 | if (err == -EAGAIN) { |
| 251 | kfree(str); |
| 252 | goto again; |
| 253 | } |
| 254 | |
Ian Campbell | 5527172 | 2011-02-17 11:04:20 +0000 | [diff] [blame] | 255 | if (handler->cb) { |
| 256 | handler->cb(); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 257 | } else { |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 258 | printk(KERN_INFO "Ignoring shutdown request: %s\n", str); |
| 259 | shutting_down = SHUTDOWN_INVALID; |
| 260 | } |
| 261 | |
| 262 | kfree(str); |
| 263 | } |
| 264 | |
Randy Dunlap | f3bc318 | 2010-05-24 14:33:41 -0700 | [diff] [blame] | 265 | #ifdef CONFIG_MAGIC_SYSRQ |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 266 | static void sysrq_handler(struct xenbus_watch *watch, const char **vec, |
| 267 | unsigned int len) |
| 268 | { |
| 269 | char sysrq_key = '\0'; |
| 270 | struct xenbus_transaction xbt; |
| 271 | int err; |
| 272 | |
| 273 | again: |
| 274 | err = xenbus_transaction_start(&xbt); |
| 275 | if (err) |
| 276 | return; |
| 277 | if (!xenbus_scanf(xbt, "control", "sysrq", "%c", &sysrq_key)) { |
| 278 | printk(KERN_ERR "Unable to read sysrq code in " |
| 279 | "control/sysrq\n"); |
| 280 | xenbus_transaction_end(xbt, 1); |
| 281 | return; |
| 282 | } |
| 283 | |
| 284 | if (sysrq_key != '\0') |
| 285 | xenbus_printf(xbt, "control", "sysrq", "%c", '\0'); |
| 286 | |
| 287 | err = xenbus_transaction_end(xbt, 0); |
| 288 | if (err == -EAGAIN) |
| 289 | goto again; |
| 290 | |
| 291 | if (sysrq_key != '\0') |
Dmitry Torokhov | f335397 | 2010-08-17 21:15:47 -0700 | [diff] [blame] | 292 | handle_sysrq(sysrq_key); |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 295 | static struct xenbus_watch sysrq_watch = { |
| 296 | .node = "control/sysrq", |
| 297 | .callback = sysrq_handler |
| 298 | }; |
Randy Dunlap | f3bc318 | 2010-05-24 14:33:41 -0700 | [diff] [blame] | 299 | #endif |
| 300 | |
| 301 | static struct xenbus_watch shutdown_watch = { |
| 302 | .node = "control/shutdown", |
| 303 | .callback = shutdown_handler |
| 304 | }; |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 305 | |
| 306 | static int setup_shutdown_watcher(void) |
| 307 | { |
| 308 | int err; |
| 309 | |
| 310 | err = register_xenbus_watch(&shutdown_watch); |
| 311 | if (err) { |
| 312 | printk(KERN_ERR "Failed to set shutdown watcher\n"); |
| 313 | return err; |
| 314 | } |
| 315 | |
Randy Dunlap | f3bc318 | 2010-05-24 14:33:41 -0700 | [diff] [blame] | 316 | #ifdef CONFIG_MAGIC_SYSRQ |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 317 | err = register_xenbus_watch(&sysrq_watch); |
| 318 | if (err) { |
| 319 | printk(KERN_ERR "Failed to set sysrq watcher\n"); |
| 320 | return err; |
| 321 | } |
Randy Dunlap | f3bc318 | 2010-05-24 14:33:41 -0700 | [diff] [blame] | 322 | #endif |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | static int shutdown_event(struct notifier_block *notifier, |
| 328 | unsigned long event, |
| 329 | void *data) |
| 330 | { |
| 331 | setup_shutdown_watcher(); |
| 332 | return NOTIFY_DONE; |
| 333 | } |
| 334 | |
Stefano Stabellini | 016b6f5 | 2010-05-14 12:45:07 +0100 | [diff] [blame] | 335 | int xen_setup_shutdown_event(void) |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 336 | { |
| 337 | static struct notifier_block xenstore_notifier = { |
| 338 | .notifier_call = shutdown_event |
| 339 | }; |
Stefano Stabellini | 702d4eb9 | 2010-12-02 17:54:50 +0000 | [diff] [blame] | 340 | |
| 341 | if (!xen_domain()) |
| 342 | return -ENODEV; |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 343 | register_xenstore_notifier(&xenstore_notifier); |
| 344 | |
| 345 | return 0; |
| 346 | } |
Stefano Stabellini | 183d03c | 2010-05-17 17:08:21 +0100 | [diff] [blame] | 347 | EXPORT_SYMBOL_GPL(xen_setup_shutdown_event); |
Jeremy Fitzhardinge | 3e2b8fb | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 348 | |
Stefano Stabellini | 702d4eb9 | 2010-12-02 17:54:50 +0000 | [diff] [blame] | 349 | subsys_initcall(xen_setup_shutdown_event); |