PERFORCE change 89388 for review
Kip Macy
kmacy at FreeBSD.org
Sun Jan 8 15:21:56 PST 2006
http://perforce.freebsd.org/chv.cgi?CH=89388
Change 89388 by kmacy at kmacy:freebsd7_xen3 on 2006/01/08 23:21:06
add support for controlling reboot and shutdown via xm
don't unconditionally call SHUTDOWN_crash in shutdown_panic
don't call kfree in xenbus.h macro
Affected files ...
.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/xen_machdep.c#5 edit
.. //depot/projects/xen3/src/sys/i386-xen/include/xenbus.h#2 edit
.. //depot/projects/xen3/src/sys/kern/kern_shutdown.c#4 edit
Differences ...
==== //depot/projects/xen3/src/sys/i386-xen/i386-xen/xen_machdep.c#5 (text+ko) ====
@@ -39,6 +39,7 @@
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/reboot.h>
+#include <sys/sysproto.h>
#include <vm/vm.h>
@@ -52,6 +53,8 @@
#include <machine/intr_machdep.h>
#include <machine/md_var.h>
#include <machine/asmacros.h>
+#include <machine/xenbus.h>
+
#include <sys/socket.h>
#include <sys/sockio.h>
@@ -571,6 +574,74 @@
};
+static void shutdown_handler(struct xenbus_watch *watch,
+ const char **vec, unsigned int len)
+{
+ char *str;
+ struct xenbus_transaction *xbt;
+ int err, howto;
+ struct reboot_args uap;
+
+ howto = 0;
+
+ again:
+ xbt = xenbus_transaction_start();
+ if (IS_ERR(xbt))
+ return;
+ str = (char *)xenbus_read(xbt, "control", "shutdown", NULL);
+ /* Ignore read errors and empty reads. */
+ if (XENBUS_IS_ERR_READ(str)) {
+ xenbus_transaction_end(xbt, 1);
+ return;
+ }
+
+ xenbus_write(xbt, "control", "shutdown", "");
+
+ err = xenbus_transaction_end(xbt, 0);
+ if (err == EAGAIN) {
+ free(str, M_DEVBUF);
+ goto again;
+ }
+
+ if (strcmp(str, "reboot") == 0)
+ howto = 0;
+ else if (strcmp(str, "poweroff") == 0)
+ howto |= (RB_POWEROFF | RB_HALT);
+ else if (strcmp(str, "halt") == 0)
+ howto |= RB_HALT;
+#ifdef notyet
+ else if (strcmp(str, "suspend") == 0)
+ shutting_down = SHUTDOWN_SUSPEND;
+#endif
+ else {
+ printf("Ignoring shutdown request: %s\n", str);
+ goto done;
+ }
+
+ uap.opt = howto;
+ reboot(curthread, &uap);
+ done:
+ free(str, M_DEVBUF);
+}
+
+static struct xenbus_watch shutdown_watch = {
+ .node = "control/shutdown",
+ .callback = shutdown_handler
+};
+
+
+static void
+setup_shutdown_watcher(void *unused)
+{
+ if (register_xenbus_watch(&shutdown_watch))
+ printf("Failed to set shutdown watcher\n");
+}
+
+
+SYSINIT(shutdown, SI_SUB_PSEUDO, SI_ORDER_ANY, setup_shutdown_watcher, NULL)
+
+
+
/********** CODE WORTH KEEPING ABOVE HERE *****************/
void xen_failsafe_handler(void);
==== //depot/projects/xen3/src/sys/i386-xen/include/xenbus.h#2 (text+ko) ====
@@ -161,7 +161,7 @@
#define XENBUS_IS_ERR_READ(str) ({ \
if (!IS_ERR(str) && strlen(str) == 0) { \
- kfree(str); \
+ free(str, M_DEVBUF); \
str = ERR_PTR(-ERANGE); \
} \
IS_ERR(str); \
==== //depot/projects/xen3/src/sys/kern/kern_shutdown.c#4 (text+ko) ====
@@ -439,11 +439,12 @@
{
int loop;
+
+
+ if (howto & RB_DUMP) {
#ifdef XEN
- HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
+ HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
#endif
-
- if (howto & RB_DUMP) {
if (PANIC_REBOOT_WAIT_TIME != 0) {
if (PANIC_REBOOT_WAIT_TIME != -1) {
printf("Automatic reboot in %d seconds - "
More information about the p4-projects
mailing list