NetBSD PR misc/30074

http://mail-index.netbsd.org/current-users/2005/04/22/0017.html
http://mail-index.netbsd.org/current-users/2007/06/30/0004.html

Index: share/man/man5/rc.conf.5
===================================================================
RCS file: /cvsroot/src/share/man/man5/rc.conf.5,v
retrieving revision 1.143
diff -u -p -r1.143 rc.conf.5
--- share/man/man5/rc.conf.5	20 Apr 2010 12:09:05 -0000	1.143
+++ share/man/man5/rc.conf.5	3 May 2010 15:56:06 -0000
@@ -320,6 +320,36 @@ unbootable even if the file system check
 Boolean value.
 Should be true if you have deliberately configured your system with no swap.
 If false and no swap devices are configured, the system will warn you.
+.It Sy raidframeparity_early
+Boolean value.
+If true, check and possibly rewrite parity on all RAIDframe devices early
+in the boot process (before
+.Xr fsck 8
+is run) and abort the boot if rewriting fails.
+.Bl -hang
+.It Em Note :
+Data on a RAID set is not protected against a component failure until
+parity is up-to-date!
+.El
+.It Sy raidframeparity_early_disks
+A space separated list of RAIDframe devices.
+Parity on these devices will be checked and possibly be rewritten early
+in the boot process as described under
+.Sy raidframeparity_early .
+Only applicable if
+.Sy raidframeparity_early
+is false (default); otherwise all available RAIDframe devices are checked
+early, not only those listed here.
+.It Sy raidframeparity_late_disks
+A space separated list of RAIDframe devices.
+Parity on these devices will be checked and possibly be rewritten late
+in the boot process, continuing the boot after the checks have been
+initiated.
+This is the default behaviour.
+Only applicable if
+.Sy raidframeparity_early
+is false (default); otherwise all available RAIDframe devices are checked
+early, even those listed here.
 .It Sy swapoff
 Boolean value.
 Remove block-type swap devices at shutdown time.
Index: etc/defaults/rc.conf
===================================================================
RCS file: /cvsroot/src/etc/defaults/rc.conf,v
retrieving revision 1.109
diff -u -p -r1.109 rc.conf
--- etc/defaults/rc.conf	1 Oct 2009 16:36:20 -0000	1.109
+++ etc/defaults/rc.conf	3 May 2010 15:56:06 -0000
@@ -108,6 +108,13 @@ ccd=YES
 #
 raidframe=YES
 
+# When and how to check and possibly rewrite RAIDframe parity.
+#
+raidframeparity_early=NO	# Set to YES to check parity on all RAIDframe
+				# devices early in the boot process and not to
+				# continue until it completes successfully.
+				# For more fine-grained options see rc.conf(5).
+
 # Crypto file system.
 #
 cgd=YES
Index: etc/rc.d/raidframe
===================================================================
RCS file: /cvsroot/src/etc/rc.d/raidframe,v
retrieving revision 1.10
diff -u -p -r1.10 raidframe
--- etc/rc.d/raidframe	21 Apr 2009 16:08:57 -0000	1.10
+++ etc/rc.d/raidframe	3 May 2010 15:56:06 -0000
@@ -5,6 +5,7 @@
 
 # PROVIDE: raidframe
 # BEFORE:  DISKS
+# BEFORE:  raidframeparity_early
 
 $_rc_subr_loaded . /etc/rc.subr
 
Index: etc/rc.d/raidframeparity
===================================================================
RCS file: /cvsroot/src/etc/rc.d/raidframeparity,v
retrieving revision 1.4
diff -u -p -r1.4 raidframeparity
--- etc/rc.d/raidframeparity	15 Apr 2009 21:33:57 -0000	1.4
+++ etc/rc.d/raidframeparity	3 May 2010 15:56:06 -0000
@@ -10,14 +10,28 @@ $_rc_subr_loaded . /etc/rc.subr
 
 name="raidframeparity"
 start_cmd="raidframeparity_start"
+start_precmd="raidframeparity_prestart"
 stop_cmd=":"
 
+raidframeparity_prestart()
+{
+	checkyesno raidframeparity_early && return 1
+
+	if [ -z "$raidframeparity_late_disks" ]; then
+		if [ -z "$raidframeparity_early_disks" ]; then
+			raidframeparity_late_disks=$(sysctl -n hw.disknames)
+		else
+			return 1
+		fi
+	fi
+}
+
 raidframeparity_start()
 {
 	# Initiate parity/mirror reconstruction as needed, in the background.
 	#
 	(
-		for dev in $(sysctl -n hw.disknames); do
+		for dev in $raidframeparity_late_disks; do
 			case $dev in
 			raid[0-9]*)
 				raidctl -P $dev
--- /dev/null	2007-06-30 13:49:58.000000000 +0200
+++ etc/rc.d/raidframeparity_early	2007-06-30 13:34:53.000000000 +0200
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# $NetBSD$
+#
+
+# PROVIDE: disks raidframeparity_early
+
+$_rc_subr_loaded . /etc/rc.subr
+
+name="raidframeparity_early"
+start_cmd="raidframeparity_early_start"
+start_precmd="raidframeparity_early_prestart"
+stop_cmd=":"
+
+raidframeparity_early_prestart()
+{
+	if checkyesno raidframeparity_early; then
+		raidframeparity_early_disks=$(sysctl -n hw.disknames)
+	fi
+
+	if [ -z "$raidframeparity_early_disks" ]; then
+		return 1
+	fi
+}
+
+raidframeparity_early_start()
+{
+	# Initiate parity/mirror reconstruction as needed,
+	# aborting boot if this fails.
+	#
+	for dev in $raidframeparity_early_disks; do
+		case $dev in
+		raid[0-9]*)
+			raidctl -v -P $dev || stop_boot
+			;;
+		esac
+	done
+}
+
+load_rc_config $name
+run_rc_command "$1"
Index: etc/rc.d/Makefile
===================================================================
RCS file: /cvsroot/src/etc/rc.d/Makefile,v
retrieving revision 1.80
diff -u -p -r1.80 Makefile
--- etc/rc.d/Makefile	29 Sep 2009 23:56:27 -0000	1.80
+++ etc/rc.d/Makefile	3 May 2010 15:56:06 -0000
@@ -31,7 +31,7 @@ CONFIGFILES=\
 		named ndbootd network newsyslog nfsd nfslocking ntpd ntpdate \
 		perusertmp pf pf_boot pflogd postfix powerd ppp pwcheck \
 		quota \
-		racoon rpcbind raidframe raidframeparity rarpd rbootd rndctl \
+		racoon rpcbind raidframe raidframeparity raidframeparity_early rarpd rbootd rndctl \
 		root route6d routed rtadvd rtclocaltime rtsold rwho \
 		savecore screenblank sdpd securelevel sshd \
 		staticroute swap1 swap2 sysctl sysdb syslogd \
Index: etc/mtree/special
===================================================================
RCS file: /cvsroot/src/etc/mtree/special,v
retrieving revision 1.131
diff -u -p -r1.131 special
--- etc/mtree/special	29 Sep 2009 23:56:27 -0000	1.131
+++ etc/mtree/special	3 May 2010 15:56:06 -0000
@@ -254,6 +254,7 @@
 ./etc/rc.d/racoon		type=file mode=0555
 ./etc/rc.d/raidframe		type=file mode=0555
 ./etc/rc.d/raidframeparity	type=file mode=0555
+./etc/rc.d/raidframeparity_early type=file mode=0555
 ./etc/rc.d/rarpd		type=file mode=0555
 ./etc/rc.d/rbootd		type=file mode=0555
 ./etc/rc.d/rndctl		type=file mode=0555
Index: distrib/sets/lists/etc/mi
===================================================================
RCS file: /cvsroot/src/distrib/sets/lists/etc/mi,v
retrieving revision 1.216
diff -u -p -r1.216 mi
--- distrib/sets/lists/etc/mi	5 Feb 2010 09:44:23 -0000	1.216
+++ distrib/sets/lists/etc/mi	3 May 2010 15:56:07 -0000
@@ -249,6 +249,7 @@
 ./etc/rc.d/racoon				etc-net-rc
 ./etc/rc.d/raidframe				etc-sys-rc
 ./etc/rc.d/raidframeparity			etc-sys-rc
+./etc/rc.d/raidframeparity_early		etc-sys-rc
 ./etc/rc.d/rarpd				etc-bootserver-rc
 ./etc/rc.d/rbootd				etc-bootserver-rc
 ./etc/rc.d/rndctl				etc-sys-rc
Index: usr.sbin/postinstall/postinstall
===================================================================
RCS file: /cvsroot/src/usr.sbin/postinstall/postinstall,v
retrieving revision 1.108
diff -u -p -r1.108 postinstall
--- usr.sbin/postinstall/postinstall	23 Apr 2010 19:21:08 -0000	1.108
+++ usr.sbin/postinstall/postinstall	3 May 2010 15:56:07 -0000
@@ -1060,7 +1060,7 @@ do_rc()
 		named ndbootd network newsyslog nfsd nfslocking ntpd ntpdate \
 		perusertmp pf pf_boot pflogd postfix powerd ppp pwcheck \
 		quota \
-		racoon rpcbind raidframe raidframeparity rarpd rbootd rndctl \
+		racoon rpcbind raidframe raidframeparity raidframeparity_early rarpd rbootd rndctl \
 		root route6d routed rtadvd rtclocaltime rtsold rwho \
 		savecore screenblank sdpd securelevel sshd \
 		staticroute swap1 swap2 sysctl sysdb syslogd \
