Update zfs.sh work on FreeBSD

Extend the zfs.sh script to load and unload zfs kmods on FreeBSD.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Kjeld Schouten <kjeld@schouten-lebbing.nl>
Signed-off-by: Ryan Moeller <ryan@ixsystems.com>
Closes #9746
This commit is contained in:
Ryan Moeller 2019-12-19 12:31:16 -05:00 committed by Brian Behlendorf
parent d16a207f2e
commit a3640486ff
2 changed files with 54 additions and 16 deletions

View File

@ -51,6 +51,7 @@ export KMOD_ZCOMMON=@abs_top_builddir@/module/zcommon/zcommon.ko
export KMOD_ZLUA=@abs_top_builddir@/module/lua/zlua.ko export KMOD_ZLUA=@abs_top_builddir@/module/lua/zlua.ko
export KMOD_ICP=@abs_top_builddir@/module/icp/icp.ko export KMOD_ICP=@abs_top_builddir@/module/icp/icp.ko
export KMOD_ZFS=@abs_top_builddir@/module/zfs/zfs.ko export KMOD_ZFS=@abs_top_builddir@/module/zfs/zfs.ko
export KMOD_FREEBSD=@abs_top_builddir@/module/openzfs.ko
endef endef
export EXTRA_ENVIRONMENT export EXTRA_ENVIRONMENT

View File

@ -29,6 +29,7 @@ KMOD_ZCOMMON=${KMOD_ZCOMMON:-zcommon}
KMOD_ZLUA=${KMOD_ZLUA:-zlua} KMOD_ZLUA=${KMOD_ZLUA:-zlua}
KMOD_ICP=${KMOD_ICP:-icp} KMOD_ICP=${KMOD_ICP:-icp}
KMOD_ZFS=${KMOD_ZFS:-zfs} KMOD_ZFS=${KMOD_ZFS:-zfs}
KMOD_FREEBSD=${KMOD_FREEBSD:-openzfs}
usage() { usage() {
@ -76,7 +77,7 @@ kill_zed() {
fi fi
} }
check_modules() { check_modules_linux() {
LOADED_MODULES="" LOADED_MODULES=""
MISSING_MODULES="" MISSING_MODULES=""
@ -108,7 +109,7 @@ check_modules() {
return 0 return 0
} }
load_module() { load_module_linux() {
KMOD=$1 KMOD=$1
FILE=$(modinfo "$KMOD" | awk '/^filename:/ {print $2}') FILE=$(modinfo "$KMOD" | awk '/^filename:/ {print $2}')
@ -128,7 +129,17 @@ load_module() {
return 0 return 0
} }
load_modules() { load_modules_freebsd() {
kldload "$KMOD_FREEBSD" || return 1
if [ "$VERBOSE" = "yes" ]; then
echo "Successfully loaded ZFS module stack"
fi
return 0
}
load_modules_linux() {
mkdir -p /etc/zfs mkdir -p /etc/zfs
if modinfo "$KMOD_ZLIB_DEFLATE" >/dev/null 2>&1; then if modinfo "$KMOD_ZLIB_DEFLATE" >/dev/null 2>&1; then
@ -141,7 +152,7 @@ load_modules() {
for KMOD in $KMOD_SPL $KMOD_ZAVL $KMOD_ZNVPAIR \ for KMOD in $KMOD_SPL $KMOD_ZAVL $KMOD_ZNVPAIR \
$KMOD_ZUNICODE $KMOD_ZCOMMON $KMOD_ZLUA $KMOD_ICP $KMOD_ZFS; do $KMOD_ZUNICODE $KMOD_ZCOMMON $KMOD_ZLUA $KMOD_ICP $KMOD_ZFS; do
load_module "$KMOD" || return 1 load_module_linux "$KMOD" || return 1
done done
if [ "$VERBOSE" = "yes" ]; then if [ "$VERBOSE" = "yes" ]; then
@ -151,7 +162,7 @@ load_modules() {
return 0 return 0
} }
unload_module() { unload_module_linux() {
KMOD=$1 KMOD=$1
NAME=$(basename "$KMOD" .ko) NAME=$(basename "$KMOD" .ko)
@ -167,14 +178,24 @@ unload_module() {
return 0 return 0
} }
unload_modules() { unload_modules_freebsd() {
kldunload "$KMOD_FREEBSD" || echo "Failed to unload $KMOD_FREEBSD"
if [ "$VERBOSE" = "yes" ]; then
echo "Successfully unloaded ZFS module stack"
fi
return 0
}
unload_modules_linux() {
for KMOD in $KMOD_ZFS $KMOD_ICP $KMOD_ZLUA $KMOD_ZCOMMON $KMOD_ZUNICODE \ for KMOD in $KMOD_ZFS $KMOD_ICP $KMOD_ZLUA $KMOD_ZCOMMON $KMOD_ZUNICODE \
$KMOD_ZNVPAIR $KMOD_ZAVL $KMOD_SPL; do $KMOD_ZNVPAIR $KMOD_ZAVL $KMOD_SPL; do
NAME=$(basename "$KMOD" .ko) NAME=$(basename "$KMOD" .ko)
USE_COUNT=$(lsmod | grep -E "^${NAME} " | awk '{print $3}') USE_COUNT=$(lsmod | grep -E "^${NAME} " | awk '{print $3}')
if [ "$USE_COUNT" = "0" ] ; then if [ "$USE_COUNT" = "0" ] ; then
unload_module "$KMOD" || return 1 unload_module_linux "$KMOD" || return 1
fi fi
done done
@ -193,7 +214,7 @@ unload_modules() {
return 0 return 0
} }
stack_clear() { stack_clear_linux() {
STACK_MAX_SIZE=/sys/kernel/debug/tracing/stack_max_size STACK_MAX_SIZE=/sys/kernel/debug/tracing/stack_max_size
STACK_TRACER_ENABLED=/proc/sys/kernel/stack_tracer_enabled STACK_TRACER_ENABLED=/proc/sys/kernel/stack_tracer_enabled
@ -203,7 +224,7 @@ stack_clear() {
fi fi
} }
stack_check() { stack_check_linux() {
STACK_MAX_SIZE=/sys/kernel/debug/tracing/stack_max_size STACK_MAX_SIZE=/sys/kernel/debug/tracing/stack_max_size
STACK_TRACE=/sys/kernel/debug/tracing/stack_trace STACK_TRACE=/sys/kernel/debug/tracing/stack_trace
STACK_LIMIT=15362 STACK_LIMIT=15362
@ -224,17 +245,33 @@ if [ "$(id -u)" != 0 ]; then
exit 1 exit 1
fi fi
UNAME=$(uname -s)
if [ "$UNLOAD" = "yes" ]; then if [ "$UNLOAD" = "yes" ]; then
kill_zed kill_zed
umount -t zfs -a umount -t zfs -a
stack_check case $UNAME in
unload_modules FreeBSD)
unload_modules_freebsd
;;
Linux)
stack_check_linux
unload_modules_linux
;;
esac
else else
stack_clear case $UNAME in
check_modules FreeBSD)
load_modules "$@" load_modules_freebsd
udevadm trigger ;;
udevadm settle Linux)
stack_clear_linux
check_modules_linux
load_modules_linux "$@"
udevadm trigger
udevadm settle
;;
esac
fi fi
exit 0 exit 0