Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 234224
b: refs/heads/master
c: 5527172
h: refs/heads/master
v: v3
  • Loading branch information
Ian Campbell authored and Stefano Stabellini committed Feb 25, 2011
1 parent bed15a0 commit 1ee2039
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e057a4b6e0eb6701f6ec923be2075d4984cef51a
refs/heads/master: 552717231e50b478dfd19d63fd97879476ae051d
49 changes: 37 additions & 12 deletions trunk/drivers/xen/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,39 @@ static void do_suspend(void)
}
#endif /* CONFIG_PM_SLEEP */

struct shutdown_handler {
const char *command;
void (*cb)(void);
};

static void do_poweroff(void)
{
shutting_down = SHUTDOWN_POWEROFF;
orderly_poweroff(false);
}

static void do_reboot(void)
{
shutting_down = SHUTDOWN_POWEROFF; /* ? */
ctrl_alt_del();
}

static void shutdown_handler(struct xenbus_watch *watch,
const char **vec, unsigned int len)
{
char *str;
struct xenbus_transaction xbt;
int err;
static struct shutdown_handler handlers[] = {
{ "poweroff", do_poweroff },
{ "halt", do_poweroff },
{ "reboot", do_reboot },
#ifdef CONFIG_PM_SLEEP
{ "suspend", do_suspend },
#endif
{NULL, NULL},
};
static struct shutdown_handler *handler;

if (shutting_down != SHUTDOWN_INVALID)
return;
Expand All @@ -194,25 +221,23 @@ static void shutdown_handler(struct xenbus_watch *watch,
return;
}

xenbus_write(xbt, "control", "shutdown", "");
for (handler = &handlers[0]; handler->command; handler++) {
if (strcmp(str, handler->command) == 0)
break;
}

/* Only acknowledge commands which we are prepared to handle. */
if (handler->cb)
xenbus_write(xbt, "control", "shutdown", "");

err = xenbus_transaction_end(xbt, 0);
if (err == -EAGAIN) {
kfree(str);
goto again;
}

if (strcmp(str, "poweroff") == 0 ||
strcmp(str, "halt") == 0) {
shutting_down = SHUTDOWN_POWEROFF;
orderly_poweroff(false);
} else if (strcmp(str, "reboot") == 0) {
shutting_down = SHUTDOWN_POWEROFF; /* ? */
ctrl_alt_del();
#ifdef CONFIG_PM_SLEEP
} else if (strcmp(str, "suspend") == 0) {
do_suspend();
#endif
if (handler->cb) {
handler->cb();
} else {
printk(KERN_INFO "Ignoring shutdown request: %s\n", str);
shutting_down = SHUTDOWN_INVALID;
Expand Down

0 comments on commit 1ee2039

Please sign in to comment.