Module Name:    src
Committed By:   jym
Date:           Sat Aug 27 15:56:48 UTC 2011

Modified Files:
        src/sys/arch/xen/include [jym-xensuspend]: shutdown_xenbus.h xen.h
        src/sys/arch/xen/x86 [jym-xensuspend]: hypervisor_machdep.c
        src/sys/arch/xen/xen [jym-xensuspend]: shutdown_xenbus.c xen_machdep.c

Log Message:
Rename the functions for suspend to reflect that Xen does not hijack
the ACPI "sleepstate" sysctl(7) node anymore.

Add a boolean value to mark that the save/suspend operation has been
notified by dom0, so as to avoid possible errors where admin would like
to schedule the domain for sleep without dom0 being prepared for that. Fail
with EAGAIN in this case.

Sprinkle some KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.34.1 src/sys/arch/xen/include/shutdown_xenbus.h
cvs rdiff -u -r1.30.8.7 -r1.30.8.8 src/sys/arch/xen/include/xen.h
cvs rdiff -u -r1.11.8.9 -r1.11.8.10 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.5.8.3 -r1.5.8.4 src/sys/arch/xen/xen/shutdown_xenbus.c
cvs rdiff -u -r1.4.12.9 -r1.4.12.10 src/sys/arch/xen/xen/xen_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/xen/include/shutdown_xenbus.h
diff -u src/sys/arch/xen/include/shutdown_xenbus.h:1.3 src/sys/arch/xen/include/shutdown_xenbus.h:1.3.34.1
--- src/sys/arch/xen/include/shutdown_xenbus.h:1.3	Wed Oct 17 19:58:29 2007
+++ src/sys/arch/xen/include/shutdown_xenbus.h	Sat Aug 27 15:56:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: shutdown_xenbus.h,v 1.3 2007/10/17 19:58:29 garbled Exp $	*/
+/*	$NetBSD: shutdown_xenbus.h,v 1.3.34.1 2011/08/27 15:56:48 jym Exp $	*/
 
 /*-
  * Copyright (c)2006 YAMAMOTO Takashi,
@@ -29,6 +29,9 @@
 #ifndef _XEN_SHUTDOWN_XENBUS_H_
 #define	_XEN_SHUTDOWN_XENBUS_H_
 
+/* Whether dom0 ordered a suspend (true) or not (false) */
+bool xen_suspend_allow;
+
 void shutdown_xenbus_setup(void);
 
 #endif /* _XEN_SHUTDOWN_XENBUS_H_ */

Index: src/sys/arch/xen/include/xen.h
diff -u src/sys/arch/xen/include/xen.h:1.30.8.7 src/sys/arch/xen/include/xen.h:1.30.8.8
--- src/sys/arch/xen/include/xen.h:1.30.8.7	Sat Aug 27 15:48:35 2011
+++ src/sys/arch/xen/include/xen.h	Sat Aug 27 15:56:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen.h,v 1.30.8.7 2011/08/27 15:48:35 jym Exp $	*/
+/*	$NetBSD: xen.h,v 1.30.8.8 2011/08/27 15:56:48 jym Exp $	*/
 
 /*
  *
@@ -73,7 +73,7 @@
 void	idle_block(void);
 
 /* xen_machdep.c */
-void	sysctl_xen_sleepstate_setup(void);
+void	sysctl_xen_suspend_setup(void);
 
 #if defined(XENDEBUG) || 1 /* XXX */
 #include <sys/stdarg.h>

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.11.8.9 src/sys/arch/xen/x86/hypervisor_machdep.c:1.11.8.10
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.11.8.9	Sat Aug 27 15:44:09 2011
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Sat Aug 27 15:56:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.11.8.9 2011/08/27 15:44:09 jym Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.11.8.10 2011/08/27 15:56:48 jym Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.11.8.9 2011/08/27 15:44:09 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.11.8.10 2011/08/27 15:56:48 jym Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -383,7 +383,7 @@
  	/* dom0 does not require the arch-dependent P2M translation table */
 	if (!xendomain_is_dom0()) {
 		build_p2m_frame_list_list();
-		sysctl_xen_sleepstate_setup();
+		sysctl_xen_suspend_setup();
 	}
 }
 

Index: src/sys/arch/xen/xen/shutdown_xenbus.c
diff -u src/sys/arch/xen/xen/shutdown_xenbus.c:1.5.8.3 src/sys/arch/xen/xen/shutdown_xenbus.c:1.5.8.4
--- src/sys/arch/xen/xen/shutdown_xenbus.c:1.5.8.3	Sun Nov  1 21:43:28 2009
+++ src/sys/arch/xen/xen/shutdown_xenbus.c	Sat Aug 27 15:56:48 2011
@@ -1,4 +1,4 @@
-/*	$Id: shutdown_xenbus.c,v 1.5.8.3 2009/11/01 21:43:28 jym Exp $	*/
+/*	$Id: shutdown_xenbus.c,v 1.5.8.4 2011/08/27 15:56:48 jym Exp $	*/
 
 /*-
  * Copyright (c)2006 YAMAMOTO Takashi,
@@ -56,7 +56,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: shutdown_xenbus.c,v 1.5.8.3 2009/11/01 21:43:28 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: shutdown_xenbus.c,v 1.5.8.4 2011/08/27 15:56:48 jym Exp $");
 
 #include <sys/param.h>
 #include <sys/malloc.h>
@@ -130,6 +130,7 @@
 	} else if (strcmp(reqstr, "reboot") == 0) {
 		sysmon_pswitch_event(&xenbus_reset, PSWITCH_EVENT_PRESSED);
 	} else if (strcmp(reqstr, "suspend") == 0) {
+		xen_suspend_allow = true;
 		sysmon_pswitch_event(&xenbus_sleep, PSWITCH_EVENT_PRESSED);
 	} else {
 		printf("ignore shutdown request: %s\n", reqstr);
@@ -145,6 +146,7 @@
 void
 shutdown_xenbus_setup(void)
 {
+	xen_suspend_allow = false;
 
 	if (sysmon_pswitch_register(&xenbus_power) != 0 ||
 	    sysmon_pswitch_register(&xenbus_reset) != 0 ||

Index: src/sys/arch/xen/xen/xen_machdep.c
diff -u src/sys/arch/xen/xen/xen_machdep.c:1.4.12.9 src/sys/arch/xen/xen/xen_machdep.c:1.4.12.10
--- src/sys/arch/xen/xen/xen_machdep.c:1.4.12.9	Wed Aug 24 21:37:05 2011
+++ src/sys/arch/xen/xen/xen_machdep.c	Sat Aug 27 15:56:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_machdep.c,v 1.4.12.9 2011/08/24 21:37:05 jym Exp $	*/
+/*	$NetBSD: xen_machdep.c,v 1.4.12.10 2011/08/27 15:56:48 jym Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.4.12.9 2011/08/24 21:37:05 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.4.12.10 2011/08/27 15:56:48 jym Exp $");
 
 #include "opt_xen.h"
 
@@ -67,6 +67,7 @@
 #include <sys/pmf.h>
 
 #include <xen/hypervisor.h>
+#include <xen/shutdown_xenbus.h>
 
 #define DPRINTK(x) printk x
 #if 0
@@ -77,7 +78,7 @@
 
 uint64_t tsc_freq;	/* XXX */
 
-static int sysctl_xen_sleepstate(SYSCTLFN_ARGS);
+static int sysctl_xen_suspend(SYSCTLFN_ARGS);
 static void xen_suspend_domain(void);
 static void xen_prepare_suspend(void);
 static void xen_prepare_resume(void);
@@ -222,7 +223,7 @@
  * controls domain suspend/save.
  */
 void
-sysctl_xen_sleepstate_setup(void)
+sysctl_xen_suspend_setup(void)
 {
 	const struct sysctlnode *node = NULL;
 
@@ -232,30 +233,30 @@
 	 */
 	KASSERT(!(xendomain_is_dom0()));
 
-	sysctl_createv(clog, 0, NULL, &node,
+	sysctl_createv(NULL, 0, NULL, &node,
 	    CTLFLAG_PERMANENT,
 	    CTLTYPE_NODE, "machdep", NULL,
 	    NULL, 0, NULL, 0,
 	    CTL_MACHDEP, CTL_EOL);
 
-	sysctl_createv(clog, 0, &node, &node,
+	sysctl_createv(NULL, 0, &node, &node,
 	    CTLFLAG_PERMANENT,
 	    CTLTYPE_NODE, "xen",
 	    SYSCTL_DESCR("Xen top level node"),
 	    NULL, 0, NULL, 0,
 	    CTL_CREATE, CTL_EOL);
 
-	sysctl_createv(clog, 0, &node, &node,
+	sysctl_createv(NULL, 0, &node, &node,
 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
 	    CTLTYPE_INT, "suspend",
-	    SYSCTL_DESCR("Suspend/save control of current Xen domain"),
-	    NULL, sysctl_xen_sleepstate, 0, NULL, 0,
+	    SYSCTL_DESCR("Suspend/save current Xen domain"),
+	    sysctl_xen_suspend, 0, NULL, 0,
 	    CTL_CREATE, CTL_EOL);
 }
 
 static int
-sysctl_xen_sleepstate(SYSCTLFN_ARGS) {
-
+sysctl_xen_suspend(SYSCTLFN_ARGS)
+{
 	int error, t;
 	struct sysctlnode node;
 
@@ -266,6 +267,10 @@
 	if (error || newp == NULL)
 		return error;
 
+	/* only allow domain to suspend when dom0 instructed to do so */
+	if (xen_suspend_allow == false)
+		return EAGAIN;
+
 	xen_suspend_domain();
 
 	return 0;
@@ -276,8 +281,8 @@
  * Last operations before suspending domain
  */
 static void
-xen_prepare_suspend(void) {
-
+xen_prepare_suspend(void)
+{
 	kpreempt_disable();
 
 	/*
@@ -315,8 +320,8 @@
  * First operations before restoring domain context
  */
 static void
-xen_prepare_resume(void) {
-
+xen_prepare_resume(void)
+{
 	/* map the new shared_info page */
 	if (HYPERVISOR_update_va_mapping((vaddr_t)HYPERVISOR_shared_info,
 	    xen_start_info.shared_info | PG_RW | PG_V,
@@ -341,6 +346,8 @@
 	DPRINTK(("preparing domain resume\n"));
 	aprint_verbose("preparing domain resume\n");
 
+	xen_suspend_allow = false;
+
 	xen_resumeclocks();
 
 	kpreempt_enable();
@@ -348,8 +355,8 @@
 }
 
 static void
-xen_suspend_domain(void) {
-
+xen_suspend_domain(void)
+{
 	paddr_t mfn;
 	int s = splvm();
 

Reply via email to