2011-05-03 02:39:59 +04:00
|
|
|
#!/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
|
2011-05-10 23:45:19 +04:00
|
|
|
keyword -lxc -openvz -prefix -vserver
|
2011-05-03 02:39:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CACHEFILE=/etc/zfs/zpool.cache
|
|
|
|
ZPOOL=/usr/sbin/zpool
|
|
|
|
ZFS=/usr/sbin/zfs
|
|
|
|
ZFS_MODULE=zfs
|
|
|
|
|
2011-05-10 23:45:19 +04:00
|
|
|
checksystem() {
|
|
|
|
if [ -c /dev/zfs ]; then
|
|
|
|
einfo "ZFS modules already loaded"
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
einfo "Checking if ZFS modules present"
|
2011-05-11 00:22:35 +04:00
|
|
|
if [ "x$(modprobe -l $ZFS_MODULE | grep $ZFS_MODULE)" == "x" ]; then
|
2011-05-10 23:45:19 +04:00
|
|
|
eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
|
|
|
|
return 1
|
|
|
|
fi
|
2011-05-03 02:39:59 +04:00
|
|
|
fi
|
2011-05-10 23:45:19 +04:00
|
|
|
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
|
2011-05-03 02:39:59 +04:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-05-10 23:45:19 +04:00
|
|
|
start() {
|
2011-05-03 02:39:59 +04:00
|
|
|
ebegin "Starting ZFS"
|
|
|
|
checksystem || return 1
|
2011-05-10 23:45:19 +04:00
|
|
|
if [ ! -c /dev/zfs ]; then
|
|
|
|
modprobe $ZFS_MODULE
|
2011-05-03 02:39:59 +04:00
|
|
|
rv=$?
|
2011-05-10 23:45:19 +04:00
|
|
|
if [ $rv -ne 0 ]; then
|
2011-05-03 02:39:59 +04:00
|
|
|
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.
|
2011-05-10 23:45:19 +04:00
|
|
|
if [ -f $CACHEFILE ]; then
|
2011-05-03 02:39:59 +04:00
|
|
|
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=$?
|
2011-05-10 23:45:19 +04:00
|
|
|
if [ $rv -ne 0 ]; then
|
2011-05-03 02:39:59 +04:00
|
|
|
eerror "Failed to import not-yet imported pools."
|
|
|
|
eend $rv
|
|
|
|
return $rv
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
einfo "Mounting ZFS filesystems"
|
|
|
|
$ZFS mount -a
|
|
|
|
rv=$?
|
2011-05-10 23:45:19 +04:00
|
|
|
if [ $rv -ne 0 ]; then
|
2011-05-03 02:39:59 +04:00
|
|
|
eerror "Failed to mount ZFS filesystems."
|
|
|
|
eend $rv
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
|
|
|
ebegin "Unmounting ZFS filesystems"
|
|
|
|
$ZFS umount -a
|
2011-05-11 00:22:35 +04:00
|
|
|
rv=$?
|
2011-05-10 23:45:19 +04:00
|
|
|
if [ $rv -ne 0 ]; then
|
2011-05-03 02:39:59 +04:00
|
|
|
eerror "Failed to umount ZFS filesystems."
|
|
|
|
fi
|
2011-05-10 23:45:19 +04:00
|
|
|
|
2011-05-03 02:39:59 +04:00
|
|
|
eend $rv
|
|
|
|
}
|
|
|
|
|
|
|
|
status()
|
|
|
|
{
|
|
|
|
# show pool status and list
|
|
|
|
$ZPOOL status && echo && $ZPOOL list
|
|
|
|
}
|