Renamed HAVE_SHARE ifdefs to HAVE_SMB_SHARE.
[zfs.git] / etc / init.d / zfs.gentoo
index 5c329ce..d7e1d10 100644 (file)
@@ -5,23 +5,21 @@
 
 depend()
 {
-       before net
-       after udev
+       # bootmisc will log to /var which may be a different zfs than root.
+       before net bootmisc
+       after udev localmount
        keyword -lxc -openvz -prefix -vserver
 }
 
 CACHEFILE=/etc/zfs/zpool.cache
-ZPOOL=/usr/sbin/zpool
-ZFS=/usr/sbin/zfs
+ZPOOL=/sbin/zpool
+ZFS=/sbin/zfs
 ZFS_MODULE=zfs
 
 checksystem() {
-       if [ -c /dev/zfs ]; then
-               einfo "ZFS modules already loaded"
-               return 0
-       else
+       if [ ! -c /dev/zfs ]; then
                einfo "Checking if ZFS modules present"
-               if [ -e  $(modprobe -l  $ZFS_MODULE | grep -q  $ZFS_MODULE) ]; then
+               if [ "x$(modprobe -l  $ZFS_MODULE | grep $ZFS_MODULE)" == "x" ]; then
                        eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
                        return 1
                fi
@@ -41,6 +39,10 @@ checksystem() {
 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=$?
@@ -75,17 +77,6 @@ start() {
                return $rv
        fi
 
-       # hack to read mounted file systems because otherwise
-       # zfs returns EPERM when a non-root user reads a mounted filesystem before root did
-       savepwd="$PWD"
-       mount | grep " type zfs " | sed 's/.*on //' | sed 's/ type zfs.*$//' | \
-       while read line
-       do
-               cd "$line" &> /dev/null
-               ls &> /dev/null
-       done
-       cd "$savepwd"
-
        eend 0
        return 0
 }
@@ -94,11 +85,14 @@ stop()
 {
        ebegin "Unmounting ZFS filesystems"
        $ZFS umount -a
+       rv=$?
        if [ $rv -ne 0 ]; then
-               eerror "Failed to umount ZFS filesystems."
+               einfo "Some ZFS filesystems not unmounted"
        fi
 
-       eend $rv
+       # Don't fail if we couldn't umount everything.  /usr might be in use.
+       eend 0
+       return 0
 }
 
 status()