Skip to content

Commit 2a9a6ab

Browse files
committed
Relax insmod spl failures, try to load zfs.ko
Instead of manually loading spl.ko every time, try to load it via modprobe. Iff that fails, use modinfo to find the path to spl.ko and try to load it with spl_hostid=0. Since udevd could have already loaded zfs (and by extension, spl), insmod failures are not hard failures. Warn that the module couldn't be loaded along with the error text and then try to load zfs.ko anyway. This moves all of the on-disk / /sys hostid manipulation to after the modules have been loaded. This ensures that regardless of how spl was loaded, /sys/module/spl/parameters/spl_hostid is set to 0 to force /etc/hostid to take precedence.
1 parent f657717 commit 2a9a6ab

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

90zfsbootmenu/zfsbootmenu-init.sh

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,38 @@ fi
2525

2626
mkdir -p "${BASE}"
2727

28+
# Attempt to load spl normally
29+
if ! _modload="$( modprobe spl 2>&1 )" ; then
30+
zdebug "${_modload}"
31+
32+
# Capture the filename for spl.ko
33+
_modfilename="$( modinfo -F filename spl )"
34+
35+
if [ -n "${_modfilename}" ] ; then
36+
zinfo "loading ${_modfilename}"
37+
38+
# Load with a hostid of 0, so that /etc/hostid takes precedence and
39+
# invalid spl.spl_hostid values are ignored
40+
41+
# There's a race condition between udev and insmod spl
42+
# insmod failures are no longer a hard failure - they can be because
43+
# 1. spl.ko is already loaded because of the race condition
44+
# 2. there's an invalid parameter or value for spl.ko
45+
46+
if ! _modload="$( insmod "${_modfilename}" "spl_hostid=0" 2>&1 )" ; then
47+
zwarn "${_modload}"
48+
zwarn "unable to load SPL kernel module; attempting to load ZFS anyway"
49+
fi
50+
fi
51+
fi
52+
53+
if ! _modload="$( modprobe zfs 2>&1 )" ; then
54+
zerror "${_modload}"
55+
emergency_shell "unable to load ZFS kernel modules"
56+
fi
57+
58+
udevadm settle
59+
2860
# Write out a default or overridden hostid
2961
if [ -n "${spl_hostid}" ] ; then
3062
if write_hostid "${spl_hostid}" ; then
@@ -42,26 +74,6 @@ elif [ ! -e /etc/hostid ]; then
4274
write_hostid "${default_hostid}"
4375
fi
4476

45-
# only load spl.ko if it isn't already loaded
46-
if ! lsmod | grep -E -q "^spl" ; then
47-
# Capture the filename for spl.ko
48-
_modfilename="$( modinfo -F filename spl )"
49-
zinfo "loading ${_modfilename}"
50-
51-
# Load with a hostid of 0, so that /etc/hostid takes precedence
52-
if ! _modload="$( insmod "${_modfilename}" "spl_hostid=0" 2>&1 )" ; then
53-
zdebug "${_modload}"
54-
emergency_shell "unable to load SPL kernel module"
55-
fi
56-
fi
57-
58-
if ! _modload="$( modprobe zfs 2>&1 )" ; then
59-
zdebug "${_modload}"
60-
emergency_shell "unable to load ZFS kernel modules"
61-
fi
62-
63-
udevadm settle
64-
6577
# Prefer a specific pool when checking for a bootfs value
6678
# shellcheck disable=SC2154
6779
if [ "${root}" = "zfsbootmenu" ]; then

0 commit comments

Comments
 (0)