mirror_zfs/etc/init.d/zfs.gentoo
Brian Behlendorf 2a005961a4 Ensure all block devices are available
These days most disk drivers will probe for devices asynchronously.
This means it's possible that when you zfs init script runs all the
required block devices may not yet have been discovered.  The result
is the pool may fail to cleanly import at boot time.  This is
particularly common when you have a large number of devices.

The fix is for the init script to block until udev settles and we
are no longer detecting new devices.  Once the system has settled
the zfs modules can be loaded and the pool with be automatically
imported.
2011-06-30 14:45:33 -07:00

103 lines
2.1 KiB
Plaintext

#!/sbin/runscript
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-fs/zfs/files/zfs,v 0.9 2011/04/30 10:13:43 devsk Exp $
depend()
{
before net
after udev
keyword -lxc -openvz -prefix -vserver
}
CACHEFILE=/etc/zfs/zpool.cache
ZPOOL=/usr/sbin/zpool
ZFS=/usr/sbin/zfs
ZFS_MODULE=zfs
checksystem() {
if [ -c /dev/zfs ]; then
einfo "ZFS modules already loaded"
return 0
else
einfo "Checking if ZFS modules present"
if [ "x$(modprobe -l $ZFS_MODULE | grep $ZFS_MODULE)" == "x" ]; then
eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
return 1
fi
fi
einfo "Checking if zfs userspace tools present"
if [ ! -x $ZPOOL ]; then
eerror "$ZPOOL binary not found."
return 1
fi
if [ ! -x $ZFS ]; then
eerror "$ZFS binary not found."
return 1
fi
return 0
}
start() {
ebegin "Starting ZFS"
checksystem || return 1
# Delay until all required block devices are present.
udevadm settle
if [ ! -c /dev/zfs ]; then
modprobe $ZFS_MODULE
rv=$?
if [ $rv -ne 0 ]; then
eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'."
eend $rv
return $rv
fi
fi
# Import all pools described by the cache file, and then mount
# all filesystem based on their properties.
if [ -f $CACHEFILE ]; then
einfo "Importing ZFS pools"
# as per fedora script, import can fail if all pools are already imported
# The check for $rv makes no sense...but someday, it will work right.
$ZPOOL import -c $CACHEFILE -aN 2>/dev/null || true
rv=$?
if [ $rv -ne 0 ]; then
eerror "Failed to import not-yet imported pools."
eend $rv
return $rv
fi
fi
einfo "Mounting ZFS filesystems"
$ZFS mount -a
rv=$?
if [ $rv -ne 0 ]; then
eerror "Failed to mount ZFS filesystems."
eend $rv
return $rv
fi
eend 0
return 0
}
stop()
{
ebegin "Unmounting ZFS filesystems"
$ZFS umount -a
rv=$?
if [ $rv -ne 0 ]; then
eerror "Failed to umount ZFS filesystems."
fi
eend $rv
}
status()
{
# show pool status and list
$ZPOOL status && echo && $ZPOOL list
}