NetBSD Problem Report #25330

Received: (qmail 10297 invoked by uid 605); 26 Apr 2004 10:48:20 -0000
Message-Id: <200404261047.i3QAlf0i001246@dsl-62-220-19-113.berlikomm.net>
Date: Mon, 26 Apr 2004 12:47:41 +0200 (CEST)
From: space7@meinberlikomm.de
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: space7@meinberlikomm.de
To: gnats-bugs@gnats.NetBSD.org
Subject: new rc.d script, writecache which disables hdd write-cache
X-Send-Pr-Version: 3.95

>Number:         25330
>Category:       bin
>Synopsis:       new rc.d script, writecache which disables hdd write-cache
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 26 10:49:00 +0000 2004
>Closed-Date:    
>Last-Modified:  Mon Apr 26 13:25:00 +0000 2004
>Originator:     Stefan Krüger
>Release:        NetBSD 2.0D
>Organization:

>Environment:


System: NetBSD dsl-62-220-19-113.berlikomm.net 2.0D NetBSD 2.0D (PLUTO) #0: Sat Apr 24 03:36:23 CEST 2004 space7@dsl-217-199-71-157.berlikomm.net:/usr/obj/cvsroot/src/sys/arch/i386/compile/PLUTO i386
Architecture: i386
Machine: i386
>Description:
	There's no easy way to turn of the write-cache of your HDD('s)
	(unlike FreeBSD, where can set a sysctl), so I looked around
	and found out, that mirbsd is disabling the write-cache in rc,
	so I thought a rc.d script would be the best solution.

	The script does:
		* parse_fstab for /dev/[sw]d*
			taken from rc.d/fixsb, thx Darrin for your hard work,
		* disables write-cache for every HD found as early as possible
			logic taken from MirBSD's rc
		* there's also support for status, but the output looks
		  ugly...

	files included in this pr:
		* writecache (for src/etc/rc.d)
		* form.patch for src/share/sushi/system/rcconf/form
		* rc.conf.5.patch for src/share/man/man5/rc.conf.5
		* rc.conf.patch for src/etc/defaults/rc.conf
		* Makefile.patch for src/etc/rc.d/Makefile
		* postinstall.patch for src/etc/postinstall
		* special.patch for src/etc/mtree/special
		* mi.patch for src/distrib/sets/lists/etc/mi

	google for "write cache" and "softupdates" if you want to know why/more
>How-To-Repeat:
	Just look for any easy way to turn off your HDD's write-cache.
>Fix:
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	Makefile.patch
#	form.patch
#	mi.patch
#	postinstall.patch
#	rc.conf.5.patch
#	rc.conf.patch
#	special.patch
#	writecache*
#
echo x - Makefile.patch
sed 's/^X//' >Makefile.patch << 'END-of-Makefile.patch'
X--- /usr/src/etc/rc.d/Makefile	2004-04-19 19:19:26.000000000 +0200
X+++ Makefile	2004-04-26 12:32:35.000000000 +0200
X@@ -21,8 +21,8 @@
X 	route6d routed rtadvd rtclocaltime rtsold rwho \
X 	savecore screenblank sendmail securelevel smmsp sshd \
X 	staticroute swap1 swap2 sysdb sysctl syslogd \
X-	timed tpctl ttys veriexec virecover wdogctl wscons wsmoused xdm xfs \
X-	ypbind yppasswdd ypserv
X+	timed tpctl ttys veriexec virecover wdogctl writecache wscons wsmoused \
X+	xdm xfs ypbind yppasswdd ypserv
X FILESDIR=	/etc/rc.d
X FILESMODE=	${BINMODE}
X 
END-of-Makefile.patch
echo x - form.patch
sed 's/^X//' >form.patch << 'END-of-form.patch'
X--- /usr/src/share/sushi/system/rcconf/form	2004-03-25 10:47:42.000000000 +0100
X+++ form	2004-04-26 12:16:17.000000000 +0200
X@@ -10,6 +10,7 @@
X escript:30,script2,critical_filesystems_remote	Filesystems to mount early in boot process
X script:script1,no_swap		Set to yes if you have no swap configured
X script:script1,swapoff		Remove block-type swap partitions upon shutdown?
X+script:script1,writecache	Disable HDD write-cache?
X script:script1,ccd		Concatenated disk driver?
X script:script1,raidframe	RAIDframe driver (manually configured devices)?
X script:script1,cgd		Crypto file system?
END-of-form.patch
echo x - mi.patch
sed 's/^X//' >mi.patch << 'END-of-mi.patch'
X--- /usr/src/distrib/sets/lists/etc/mi	2004-04-19 19:19:07.000000000 +0200
X+++ mi	2004-04-26 12:36:45.000000000 +0200
X@@ -199,6 +199,7 @@
X ./etc/rc.d/veriexec				etc-sys-rc
X ./etc/rc.d/virecover				etc-sys-rc
X ./etc/rc.d/wdogctl				etc-sysutil-rc
X+./etc/rc.d/writecache				etc-sys-rc
X ./etc/rc.d/wscons				etc-sys-rc
X ./etc/rc.d/wsmoused				etc-sys-rc
X ./etc/rc.d/xdm					etc-x11-rc
END-of-mi.patch
echo x - postinstall.patch
sed 's/^X//' >postinstall.patch << 'END-of-postinstall.patch'
X--- /usr/src/etc/postinstall	2004-04-19 19:19:22.000000000 +0200
X+++ postinstall	2004-04-26 12:33:59.000000000 +0200
X@@ -444,7 +444,7 @@
X 		root route6d routed rtadvd rtclocaltime rtsold rwho savecore \
X 		screenblank sendmail securelevel smmsp sshd staticroute \
X 		swap1 swap2 sysdb sysctl syslogd timed ttys veriexec virecover \
X-		wdogctl wscons wsmoused \
X+		wdogctl writecache wscons wsmoused \
X 		xdm xfs ypbind yppasswdd ypserv
X 	failed=$(( ${failed} + $? ))
X 
END-of-postinstall.patch
echo x - rc.conf.5.patch
sed 's/^X//' >rc.conf.5.patch << 'END-of-rc.conf.5.patch'
X--- /usr/src/share/man/man5/rc.conf.5	2004-01-20 19:30:47.000000000 +0100
X+++ rc.conf.5	2004-04-26 12:15:38.000000000 +0200
X@@ -253,6 +253,15 @@
X .Sq NO .
X Remove block-type swap devices at shutdown time.
X Useful if swapping onto RAIDframe devices.
X+.It Sy writecache
X+.Sq YES
X+or
X+.Sq NO .
X+Disabling your HDD write-cache will enhance your chances
X+to have consistent disk after a power failure.
X+It should also be disabled when using soft-dependencies for FFS filesystems.
X+This shouldn't hurt SCSI drives (with Tagged Command Queing),
X+but you can expect a performance loss with IDE drives.
X .El
X .Ss One-time actions to perform or programs to run on boot-up
X .Bl -tag -width net_interfaces
END-of-rc.conf.5.patch
echo x - rc.conf.patch
sed 's/^X//' >rc.conf.patch << 'END-of-rc.conf.patch'
X--- /usr/src/etc/defaults/rc.conf	2004-04-19 19:19:23.000000000 +0200
X+++ rc.conf	2004-04-26 12:14:29.000000000 +0200
X@@ -81,6 +81,10 @@
X 			# partitions and don't want to be warned about it.
X swapoff=NO		# Remove block-type swap partitions upon shutdown
X 
X+#
X+# Disable HDD write cache?
X+writecache=YES
X+
X # Concatenated disk driver.
X #
X ccd=YES
END-of-rc.conf.patch
echo x - special.patch
sed 's/^X//' >special.patch << 'END-of-special.patch'
X--- /usr/src/etc/mtree/special	2004-04-19 19:19:26.000000000 +0200
X+++ special	2004-04-26 12:35:12.000000000 +0200
X@@ -215,6 +215,7 @@
X ./etc/rc.d/veriexec		type=file mode=0555
X ./etc/rc.d/virecover		type=file mode=0555
X ./etc/rc.d/wdogctl		type=file mode=0555
X+./etc/rc.d/writecache		type=file mode=0555
X ./etc/rc.d/wscons		type=file mode=0555
X ./etc/rc.d/wsmoused		type=file mode=0555
X ./etc/rc.d/xdm			type=file mode=0555
END-of-special.patch
echo x - writecache*
sed 's/^X//' >writecache* << 'END-of-writecache*'
X#!/bin/sh
X#
X# $NetBSD$
X#
X
X# BEFORE:  disks
X
X# Turn off the HDD write-cache ASAP.
X# Using write-cache with softdep is a bad thing 'nuff said.
X
X. /etc/rc.subr
X
Xname="writecache"
Xrcvar=$name
X
Xstart_cmd="writecache_start"
Xstatus_cmd="writecache_status"
X
Xextra_commands="status"
X
Xfstab=/etc/fstab
X
X# This extracts hdd devices from the file ${fstab}
Xparse_fstab()
X{
X	cat "${fstab}" 2> /dev/null | 
X	while read d m t o b f err; do
X		case "$d" in
X		\#*)
X			continue
X			;;
X		/dev/[sw]d*)
X			d="${d#/dev/}"
X			case "$_tmp" in
X			*${d%[a-p]}*)
X				;;	# Already done
X			*)
X				_tmp="$_tmp ${d%[a-p]}"
X				echo -n " ${d%[a-p]}"
X				;;
X			esac
X		esac
X	done
X}
X
Xwritecache_start()
X{
X	echo -n "Disabling HDD write-cache:"
X	for p in $(parse_fstab); do
X		/sbin/dkctl $p setcache r
X		echo -n " $p"
X	done
X	echo "."
X}
X
Xwritecache_status()
X{
X	for p in $(parse_fstab); do
X		/sbin/dkctl $p getcache
X	done
X}
X
Xload_rc_config $name
Xrun_rc_command "$1"
END-of-writecache*
exit

>Release-Note:
>Audit-Trail:

From: matthew green <mrg@eterna.com.au>
To: space7@meinberlikomm.de
Cc: gnats-bugs@gnats.NetBSD.org
Subject: re: bin/25330: new rc.d script, writecache which disables hdd write-cache 
Date: Mon, 26 Apr 2004 21:39:53 +1000



 good idea.

    	The script does:
    		* parse_fstab for /dev/[sw]d*
    			taken from rc.d/fixsb, thx Darrin for your hard work,

 i think this should use `sysctl hw.disknames`.

From: SK <space7@meinberlikomm.de>
To: matthew green <mrg@eterna.com.au>
Cc: gnats-bugs@gnats.NetBSD.org
Subject: Re: bin/25330: new rc.d script, writecache which disables hdd write-cache
Date: Mon, 26 Apr 2004 14:17:37 +0200

 This is a multi-part message in MIME format.
 --------------000502090609040102050007
 Content-Type: text/plain; charset=us-ascii; format=flowed
 Content-Transfer-Encoding: 7bit

 > good idea.
 thanks :-)


 >    	The script does:
 >    		* parse_fstab for /dev/[sw]d*
 >    			taken from rc.d/fixsb, thx Darrin for your hard work,
 > 
 > i think this should use `sysctl hw.disknames`.
 good idea, too :-)

 what do you think about my attachment?

 --------------000502090609040102050007
 Content-Type: text/plain;
  name="writecache"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="writecache"

 #!/bin/sh
 #
 # $NetBSD$
 #

 # BEFORE:  disks

 # Turn off the HDD write-cache ASAP.
 # Using write-cache with softdep is a bad thing 'nuff said.

 . /etc/rc.subr

 name="writecache"
 rcvar=$name

 start_cmd="writecache_start"
 status_cmd="writecache_status"

 extra_commands="status"

 parse_disknames()
 {
 for disk in $(/sbin/sysctl -n hw.disknames); do
 	case "$disk" in
 	[sw]d*)
 		echo -n " $disk"
 		;;
 	esac
 done
 }

 writecache_start()
 {
 	echo -n "Disabling HDD write-cache:"
 	for p in $(parse_disknames); do
 		/sbin/dkctl $p setcache r
 		echo -n " $p"
 	done
 	echo "."
 }

 writecache_status()
 {
 	for p in $(parse_disknames); do
 		/sbin/dkctl $p getcache
 	done
 }

 load_rc_config $name
 run_rc_command "$1"

 --------------000502090609040102050007--

From: matthew green <mrg@eterna.com.au>
To: SK <space7@meinberlikomm.de>
Cc: gnats-bugs@gnats.NetBSD.org
Subject: re: bin/25330: new rc.d script, writecache which disables hdd write-cache 
Date: Mon, 26 Apr 2004 22:20:05 +1000

 this isn't strictly necessary, but maybe it would be cool if
 you could choose which disks to and not to set write cache
 for...  ie, i might have a disk dedicated to "obj" dirs and
 setting the writecache on here would be a win...


 .mrg.

From: "Darrin B. Jewell" <dbj@netbsd.org>
To: space7@meinberlikomm.de
Cc: gnats-bugs@gnats.NetBSD.org
Subject: Re: bin/25330: new rc.d script, writecache which disables hdd write-cache
Date: 26 Apr 2004 09:22:27 -0400

 space7@meinberlikomm.de writes:
 > 	The script does:
 > 		* parse_fstab for /dev/[sw]d*
 > 			taken from rc.d/fixsb, thx Darrin for your hard work,
 > 		* disables write-cache for every HD found as early as possible
 > 			logic taken from MirBSD's rc

 You're welcome.  You should also consider whether "/sbin/sysctl
 hw.disknames" is a better method to discover the available disks on
 the system for your purposes.

 Darrin
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.