Catch return errors from zpool commands

This fixes a bug that can effect first reboot after install
using Dracut.  The Dracut module didn't check the return
value from several calls to z* functions.  This resulted in
"Using no pools available as root" on boot if the ZFS module
didn't auto-import the pools.  It's most likely to happen on
initial restart after a fresh install & requires juggling in
the Dracut emergency holographic shell to fix.

This patch checks return codes & output from zpool list and
related functions and correctly falls into the explicit zpool
import code branch if the module didn't import the pool at load.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
This commit is contained in:
Zachary Bedell 2011-07-24 16:53:15 -04:00 committed by Brian Behlendorf
parent 1ef5e8296a
commit a4719e54e8
1 changed files with 3 additions and 2 deletions

View File

@ -3,6 +3,7 @@
. /lib/dracut-lib.sh . /lib/dracut-lib.sh
ZPOOL_FORCE="" ZPOOL_FORCE=""
if getargbool 0 zfs_force -y zfs.force -y zfsforce ; then if getargbool 0 zfs_force -y zfs.force -y zfsforce ; then
warn "ZFS: Will force-import pools if necessary." warn "ZFS: Will force-import pools if necessary."
ZPOOL_FORCE="-f" ZPOOL_FORCE="-f"
@ -18,12 +19,12 @@ case "$root" in
# Might be imported by the kernel module, so try searching before # Might be imported by the kernel module, so try searching before
# we import anything. # we import anything.
zfsbootfs=`zpool list -H -o bootfs | sed 'q'` zfsbootfs=`zpool list -H -o bootfs | sed 'q'`
if [ "$zfsbootfs" = "" ] ; then if [ "$?" != "0" ] || [ "$zfsbootfs" = "" ] || [ "$zfsbootfs" = "no pools available" ] ; then
# Not there, so we need to import everything. # Not there, so we need to import everything.
info "ZFS: Attempting to import additional pools." info "ZFS: Attempting to import additional pools."
zpool import -N -a ${ZPOOL_FORCE} zpool import -N -a ${ZPOOL_FORCE}
zfsbootfs=`zpool list -H -o bootfs | sed 'q'` zfsbootfs=`zpool list -H -o bootfs | sed 'q'`
if [ "$zfsbootfs" = "" ] ; then if [ "$?" != "0" ] || [ "$zfsbootfs" = "" ] || [ "$zfsbootfs" = "no pools available" ] ; then
rootok=0 rootok=0
pool="" pool=""