Skip to content

Commit

Permalink
Some minor fixes to the initramfs script.
Browse files Browse the repository at this point in the history
* 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}().
  • Loading branch information
FransUrbo committed Oct 2, 2015
1 parent 545dcd5 commit dd1683b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
8 changes: 6 additions & 2 deletions contrib/initramfs/scripts/zfs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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" \
Expand All @@ -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" \
Expand Down
32 changes: 14 additions & 18 deletions contrib/shell-common/zfs-functions.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,=.*,,')

Expand All @@ -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.
Expand All @@ -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,=.*,,')
Expand All @@ -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
Expand Down Expand Up @@ -716,8 +726,6 @@ import_pool()
else
return 1
fi
else
return 1
fi
fi

Expand Down Expand Up @@ -801,8 +809,6 @@ mount_fs()
else
return 1
fi
else
return 1
fi

return 0
Expand Down Expand Up @@ -844,8 +850,6 @@ decrypt_fs()
else
return 1
fi
else
return 1
fi
done

Expand All @@ -868,8 +872,6 @@ decrypt_fs()
else
return 1
fi
else
return 1
fi

return 0
Expand Down Expand Up @@ -897,8 +899,6 @@ destroy_fs()
else
return 1
fi
else
return 1
fi

return 0
Expand Down Expand Up @@ -939,8 +939,6 @@ clone_snap()
else
return 1
fi
else
return 1
fi

return 0
Expand All @@ -966,8 +964,6 @@ rollback_snap()
else
return 1
fi
else
return 1
fi

return 0
Expand Down

0 comments on commit dd1683b

Please sign in to comment.