From owner-p4-projects@FreeBSD.ORG Sun Jan 8 23:21:56 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id DA70C16A422; Sun, 8 Jan 2006 23:21:55 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 96A6616A41F for ; Sun, 8 Jan 2006 23:21:55 +0000 (GMT) (envelope-from kmacy@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 563DA43D45 for ; Sun, 8 Jan 2006 23:21:55 +0000 (GMT) (envelope-from kmacy@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k08NLt3Q071270 for ; Sun, 8 Jan 2006 23:21:55 GMT (envelope-from kmacy@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k08NLtAA071267 for perforce@freebsd.org; Sun, 8 Jan 2006 23:21:55 GMT (envelope-from kmacy@freebsd.org) Date: Sun, 8 Jan 2006 23:21:55 GMT Message-Id: <200601082321.k08NLtAA071267@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to kmacy@freebsd.org using -f From: Kip Macy To: Perforce Change Reviews Cc: Subject: PERFORCE change 89388 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Jan 2006 23:21:56 -0000 http://perforce.freebsd.org/chv.cgi?CH=89388 Change 89388 by kmacy@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 #include #include +#include #include @@ -52,6 +53,8 @@ #include #include #include +#include + #include #include @@ -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 - "