Subject: Recording reboot in boothowto
To: None <tech-kern@netbsd.org>
From: Joerg Sonnenberger <joerg@britannica.bec.de>
List: tech-kern
Date: 12/15/2007 12:31:54
--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi all,
there are some drivers that want to behave different between shutdown
for reboot/halt and shutdown for powerdown and /suspend. Into this class
at least the disk drivers fall (PR 37508 for reference).

I don't want to add an additional argument for the suspend callback as
it will be rarely used. I can't think of much hardware besides disks
where you would want to do that.

What do you think of the attached patch to make it possible for drivers
to distinguish the cases based on boothowto? The suggested patch for
wd.c is in the PR.

Joerg

--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="reboot.diff"

Index: compat/common/kern_xxx_12.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/compat/common/kern_xxx_12.c,v
retrieving revision 1.12
diff -u -p -r1.12 kern_xxx_12.c
--- compat/common/kern_xxx_12.c	9 Feb 2007 21:55:16 -0000	1.12
+++ compat/common/kern_xxx_12.c	14 Dec 2007 21:12:09 -0000
@@ -52,12 +52,15 @@ compat_12_sys_reboot(struct lwp *l, void
 	struct compat_12_sys_reboot_args /* {
 		syscallarg(int) opt;
 	} */ *uap = v;
-	int error;
+	int error, opt;
 
 	if ((error = kauth_authorize_system(l->l_cred,
 	    KAUTH_SYSTEM_REBOOT, 0, NULL, NULL, NULL)) != 0)
 		return (error);
-	cpu_reboot(SCARG(uap, opt), NULL);
+	opt = SCARG(uap, opt);
+	if ((opt & RB_HALT) == 0)
+		opt |= RB_REBOOT;
+	cpu_reboot(opt, NULL);
 	return (0);
 }
 /*#endif COMPAT_12 */
Index: compat/ibcs2/ibcs2_misc.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/compat/ibcs2/ibcs2_misc.c,v
retrieving revision 1.96
diff -u -p -r1.96 ibcs2_misc.c
--- compat/ibcs2/ibcs2_misc.c	12 Dec 2007 22:07:58 -0000	1.96
+++ compat/ibcs2/ibcs2_misc.c	14 Dec 2007 21:11:31 -0000
@@ -1139,7 +1139,7 @@ ibcs2_sys_uadmin(struct lwp *l, void *v,
 			cpu_reboot(RB_HALT, NULL);
 		case SCO_AD_BOOT:
 		case SCO_AD_IBOOT:
-			cpu_reboot(RB_AUTOBOOT, NULL);
+			cpu_reboot(RB_REBOOT, NULL);
 		}
 		return EINVAL;
 	case SCO_A_REMOUNT:
Index: ddb/db_command.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/ddb/db_command.c,v
retrieving revision 1.112
diff -u -p -r1.112 db_command.c
--- ddb/db_command.c	13 Dec 2007 02:45:11 -0000	1.112
+++ ddb/db_command.c	14 Dec 2007 21:11:06 -0000
@@ -1298,6 +1298,8 @@ db_reboot_cmd(db_expr_t addr, bool have_
 	 * called from cpu_reboot.
 	 */
 	db_recover = 0;
+	if (((int)bootflags & RB_HALT) == 0)
+		bootflags |= RB_REBOOT;
 	cpu_reboot((int)bootflags, NULL);
 }
 
@@ -1361,7 +1363,7 @@ db_sync_cmd(db_expr_t addr, bool have_ad
 	 * called from cpu_reboot.
 	 */
 	db_recover = 0;
-	cpu_reboot(RB_DUMP, NULL);
+	cpu_reboot(RB_REBOOT | RB_DUMP, NULL);
 }
 
 /*
Index: dev/sysmon/swwdog.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/dev/sysmon/swwdog.c,v
retrieving revision 1.7
diff -u -p -r1.7 swwdog.c
--- dev/sysmon/swwdog.c	9 Jul 2007 21:01:23 -0000	1.7
+++ dev/sysmon/swwdog.c	14 Dec 2007 21:08:28 -0000
@@ -157,5 +157,5 @@ swwdog_panic(void *vsc)
 	if (do_panic)
 		panic("watchdog timer expired");
 	else
-		cpu_reboot(0, NULL);
+		cpu_reboot(RB_REBOOT, NULL);
 }
Index: dev/sysmon/sysmon_power.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/dev/sysmon/sysmon_power.c,v
retrieving revision 1.34
diff -u -p -r1.34 sysmon_power.c
--- dev/sysmon/sysmon_power.c	9 Dec 2007 20:57:19 -0000	1.34
+++ dev/sysmon/sysmon_power.c	14 Dec 2007 21:08:44 -0000
@@ -956,7 +956,7 @@ sysmon_pswitch_event(struct sysmon_pswit
 		 */
 		printf("%s: reset button pressed, rebooting!\n",
 		    smpsw->smpsw_name);
-		cpu_reboot(0, NULL);
+		cpu_reboot(RB_REBOOT, NULL);
 		break;
 
 	case PSWITCH_TYPE_SLEEP:
Index: kern/kern_subr.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/kern/kern_subr.c,v
retrieving revision 1.167
diff -u -p -r1.167 kern_subr.c
--- kern/kern_subr.c	9 Dec 2007 20:28:43 -0000	1.167
+++ kern/kern_subr.c	14 Dec 2007 21:06:32 -0000
@@ -940,7 +940,7 @@ setroot(struct device *bootdv, int bootp
 			if (len == 4 && strcmp(buf, "halt") == 0)
 				cpu_reboot(RB_HALT, NULL);
 			else if (len == 6 && strcmp(buf, "reboot") == 0)
-				cpu_reboot(0, NULL);
+				cpu_reboot(RB_REBOOT, NULL);
 #if defined(DDB)
 			else if (len == 3 && strcmp(buf, "ddb") == 0) {
 				console_debugger();
@@ -1213,7 +1213,7 @@ parsedisk(char *str, int len, int defpar
 	if (len == 4 && strcmp(str, "halt") == 0)
 		cpu_reboot(RB_HALT, NULL);
 	else if (len == 6 && strcmp(str, "reboot") == 0)
-		cpu_reboot(0, NULL);
+		cpu_reboot(RB_REBOOT, NULL);
 #if defined(DDB)
 	else if (len == 3 && strcmp(str, "ddb") == 0)
 		console_debugger();
Index: kern/kern_xxx.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/kern/kern_xxx.c,v
retrieving revision 1.66
diff -u -p -r1.66 kern_xxx.c
--- kern/kern_xxx.c	9 Nov 2007 14:50:52 -0000	1.66
+++ kern/kern_xxx.c	14 Dec 2007 21:11:49 -0000
@@ -56,7 +56,7 @@ sys_reboot(struct lwp *l, void *v, regis
 		syscallarg(int) opt;
 		syscallarg(char *) bootstr;
 	} */ *uap = v;
-	int error;
+	int error, opt;
 	char *bootstr, bs[128];
 
 	if ((error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_REBOOT,
@@ -74,7 +74,10 @@ sys_reboot(struct lwp *l, void *v, regis
 	/*
 	 * Not all ports use the bootstr currently.
 	 */
-	cpu_reboot(SCARG(uap, opt), bootstr);
+	opt = SCARG(uap, opt);
+	if ((opt & RB_HALT) == 0)
+		opt |= RB_REBOOT;
+	cpu_reboot(opt, bootstr);
 	return (0);
 }
 
Index: kern/subr_prf.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/kern/subr_prf.c,v
retrieving revision 1.111
diff -u -p -r1.111 subr_prf.c
--- kern/subr_prf.c	7 Nov 2007 00:19:08 -0000	1.111
+++ kern/subr_prf.c	14 Dec 2007 21:08:23 -0000
@@ -192,7 +192,7 @@ panic(const char *fmt, ...)
 	int bootopt;
 	va_list ap;
 
-	bootopt = RB_AUTOBOOT;
+	bootopt = RB_AUTOBOOT | RB_REBOOT;
 	if (dumponpanic)
 		bootopt |= RB_DUMP;
 	if (doing_shutdown)
Index: sys/reboot.h
===================================================================
RCS file: /data/repo/netbsd/src/sys/sys/reboot.h,v
retrieving revision 1.24
diff -u -p -r1.24 reboot.h
--- sys/reboot.h	17 Nov 2007 18:12:31 -0000	1.24
+++ sys/reboot.h	14 Dec 2007 21:15:56 -0000
@@ -45,7 +45,7 @@
 #define	RB_NOSYNC	0x00000004	/* dont sync before reboot */
 #define	RB_HALT		0x00000008	/* don't reboot, just halt */
 #define	RB_INITNAME	0x00000010	/* name given for /etc/init (unused) */
-#define	__RB_UNUSED1	0x00000020	/* was RB_DFLTROOT, obsolete */
+#define	RB_REBOOT	0x00000020	/* try to reboot, overriden by RB_HALT */
 #define	RB_KDB		0x00000040	/* give control to kernel debugger */
 #define	RB_RDONLY	0x00000080	/* mount root fs read-only */
 #define	RB_DUMP		0x00000100	/* dump kernel memory before reboot */

--wRRV7LY7NUeQGEoC--