Subject: bin/25330: new rc.d script, writecache which disables hdd write-cache
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <space7@meinberlikomm.de>
List: netbsd-bugs
Date: 04/26/2004 12:47:41
>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 UTC 2004
>Closed-Date:
>Last-Modified:
>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+++ 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+++ 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+++ 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+++ 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+++ 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+++ 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+++ 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:
>Unformatted: