From dd1683bac85b2f4523ab1fbacecb88fa25a60524 Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Tue, 29 Sep 2015 23:53:07 +0200 Subject: [PATCH] Some minor fixes to the initramfs script. * Apparently "var > 0" doesn't work. Use 'var -gt 0' instead. But that means that 'var' needs to be set, so set this to '0' if it's not already set at the beginning of the initrd script. * Fixing return variable from a bunch of assist functions. Returned false when they should have returned true! Thanx to markdesouza @ GitHub for help findind this. Closes: #3869 * Make sure we set/reset IFS when retreiving sub-filesystems in recursive_mount_filesystems(). * Set and reset IFS in read_{mtab,fstab}(). --- contrib/initramfs/scripts/zfs | 8 +++++-- contrib/shell-common/zfs-functions.in | 32 ++++++++++++--------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/contrib/initramfs/scripts/zfs b/contrib/initramfs/scripts/zfs index bd6d5ef91889..589f8884c095 100644 --- a/contrib/initramfs/scripts/zfs +++ b/contrib/initramfs/scripts/zfs @@ -16,6 +16,10 @@ ZPOOL="/sbin/zpool" ZPOOL_CACHE="/etc/zfs/zpool.cache" export ZFS ZPOOL ZPOOL_CACHE +# Needs to be set for rest of the code to work. +[ -z "${ZFS_INITRD_PRE_MOUNTROOT_SLEEP}" ] && ZFS_INITRD_PRE_MOUNTROOT_SLEEP=0 +[ -z "${ZFS_INITRD_POST_MODPROBE_SLEEP}" ] && ZFS_INITRD_POST_MODPROBE_SLEEP=0 + # This runs any scripts that should run before we start importing # pools and mounting any filesystems. pre_mountroot() @@ -44,7 +48,7 @@ pre_mountroot() # with more logging etc. load_module_initrd() { - if [ "$ZFS_INITRD_PRE_MOUNTROOT_SLEEP" > 0 ] + if [ "$ZFS_INITRD_PRE_MOUNTROOT_SLEEP" -gt 0 ] then check_boolean "$quiet" || \ zfs_log_begin_msg "Sleeping for" \ @@ -67,7 +71,7 @@ load_module_initrd() # Load the module load_module "zfs" || return 1 - if [ "$ZFS_INITRD_POST_MODPROBE_SLEEP" > 0 ] + if [ "$ZFS_INITRD_POST_MODPROBE_SLEEP" -gt 0 ] then check_boolean "$quiet" || \ zfs_log_begin_msg "Sleeping for" \ diff --git a/contrib/shell-common/zfs-functions.in b/contrib/shell-common/zfs-functions.in index ee2b51c8e6d2..5ff7a0dec5b5 100644 --- a/contrib/shell-common/zfs-functions.in +++ b/contrib/shell-common/zfs-functions.in @@ -405,7 +405,9 @@ recursive_mount_filesystems() # Go through the complete list (recursivly) of all filesystems # below the first (root) dataset. + zfs_set_ifs " " filesystems="$("${ZFS}" list -oname -tfilesystem -H -r "${fs}")" + zfs_set_ifs "${OLD_IFS}" for f in ${filesystems} ${ZFS_INITRD_ADDITIONAL_DATASETS} do # Ignore the first (root) fs. Should already be @@ -428,6 +430,8 @@ read_mtab() local match="$1" local fs mntpnt fstype opts rest TMPFILE + zfs_set_ifs "${OLD_IFS}" + # Unset all MTAB_* variables unset $(env | grep ^MTAB_ | sed 's,=.*,,') @@ -449,9 +453,11 @@ read_mtab() fs=$(printf '%b\n' "$fs") # Set the variable. - eval export MTAB_$mntpnt=\"$fs\" + eval export MTAB_$mntpnt="\"$fs\"" fi done < /proc/mounts + + zfs_set_ifs "${TMP_IFS}" } # Check if specified filesystem is mounted. @@ -472,7 +478,9 @@ in_mtab() read_fstab() { local match="$1" - local i var TMPFILE + local i var TMPFILE fs mntpnt fstype opts + + zfs_set_ifs "${OLD_IFS}" # Unset all FSTAB_* variables unset $(env | grep ^FSTAB_ | sed 's,=.*,,') @@ -482,13 +490,15 @@ read_fstab() echo "$fs" | egrep -qE '^#|^$' && continue if echo "$fs $mntpnt $fstype $opts" | grep -qE "$match"; then - eval export FSTAB_dev_$i="$fs" + eval export FSTAB_dev_$i="\"$fs\"" fs=$(printf '%b\n' "$fs" | sed 's,/,_,g') - eval export FSTAB_$i="$mntpnt" + eval export FSTAB_$i="\"$mntpnt\"" i=$((i + 1)) fi done < /etc/fstab + + zfs_set_ifs "${TMP_IFS}" } # Check to see if specified filesystem is in fstab @@ -716,8 +726,6 @@ import_pool() else return 1 fi - else - return 1 fi fi @@ -801,8 +809,6 @@ mount_fs() else return 1 fi - else - return 1 fi return 0 @@ -844,8 +850,6 @@ decrypt_fs() else return 1 fi - else - return 1 fi done @@ -868,8 +872,6 @@ decrypt_fs() else return 1 fi - else - return 1 fi return 0 @@ -897,8 +899,6 @@ destroy_fs() else return 1 fi - else - return 1 fi return 0 @@ -939,8 +939,6 @@ clone_snap() else return 1 fi - else - return 1 fi return 0 @@ -966,8 +964,6 @@ rollback_snap() else return 1 fi - else - return 1 fi return 0