Skip to content

Commit

Permalink
Update zfs.sh work on FreeBSD
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ryan Moeller authored and behlendorf committed Dec 19, 2019
1 parent d16a207 commit a364048
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
1 change: 1 addition & 0 deletions scripts/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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_ICP=@abs_top_builddir@/module/icp/icp.ko
export KMOD_ZFS=@abs_top_builddir@/module/zfs/zfs.ko
export KMOD_FREEBSD=@abs_top_builddir@/module/openzfs.ko
endef

export EXTRA_ENVIRONMENT
Expand Down
69 changes: 53 additions & 16 deletions scripts/zfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ KMOD_ZCOMMON=${KMOD_ZCOMMON:-zcommon}
KMOD_ZLUA=${KMOD_ZLUA:-zlua}
KMOD_ICP=${KMOD_ICP:-icp}
KMOD_ZFS=${KMOD_ZFS:-zfs}
KMOD_FREEBSD=${KMOD_FREEBSD:-openzfs}


usage() {
Expand Down Expand Up @@ -76,7 +77,7 @@ kill_zed() {
fi
}

check_modules() {
check_modules_linux() {
LOADED_MODULES=""
MISSING_MODULES=""

Expand Down Expand Up @@ -108,7 +109,7 @@ check_modules() {
return 0
}

load_module() {
load_module_linux() {
KMOD=$1

FILE=$(modinfo "$KMOD" | awk '/^filename:/ {print $2}')
Expand All @@ -128,7 +129,17 @@ load_module() {
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

if modinfo "$KMOD_ZLIB_DEFLATE" >/dev/null 2>&1; then
Expand All @@ -141,7 +152,7 @@ load_modules() {

for KMOD in $KMOD_SPL $KMOD_ZAVL $KMOD_ZNVPAIR \
$KMOD_ZUNICODE $KMOD_ZCOMMON $KMOD_ZLUA $KMOD_ICP $KMOD_ZFS; do
load_module "$KMOD" || return 1
load_module_linux "$KMOD" || return 1
done

if [ "$VERBOSE" = "yes" ]; then
Expand All @@ -151,7 +162,7 @@ load_modules() {
return 0
}

unload_module() {
unload_module_linux() {
KMOD=$1

NAME=$(basename "$KMOD" .ko)
Expand All @@ -167,14 +178,24 @@ unload_module() {
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 \
$KMOD_ZNVPAIR $KMOD_ZAVL $KMOD_SPL; do
NAME=$(basename "$KMOD" .ko)
USE_COUNT=$(lsmod | grep -E "^${NAME} " | awk '{print $3}')

if [ "$USE_COUNT" = "0" ] ; then
unload_module "$KMOD" || return 1
unload_module_linux "$KMOD" || return 1
fi
done

Expand All @@ -193,7 +214,7 @@ unload_modules() {
return 0
}

stack_clear() {
stack_clear_linux() {
STACK_MAX_SIZE=/sys/kernel/debug/tracing/stack_max_size
STACK_TRACER_ENABLED=/proc/sys/kernel/stack_tracer_enabled

Expand All @@ -203,7 +224,7 @@ stack_clear() {
fi
}

stack_check() {
stack_check_linux() {
STACK_MAX_SIZE=/sys/kernel/debug/tracing/stack_max_size
STACK_TRACE=/sys/kernel/debug/tracing/stack_trace
STACK_LIMIT=15362
Expand All @@ -224,17 +245,33 @@ if [ "$(id -u)" != 0 ]; then
exit 1
fi

UNAME=$(uname -s)

if [ "$UNLOAD" = "yes" ]; then
kill_zed
umount -t zfs -a
stack_check
unload_modules
case $UNAME in
FreeBSD)
unload_modules_freebsd
;;
Linux)
stack_check_linux
unload_modules_linux
;;
esac
else
stack_clear
check_modules
load_modules "$@"
udevadm trigger
udevadm settle
case $UNAME in
FreeBSD)
load_modules_freebsd
;;
Linux)
stack_clear_linux
check_modules_linux
load_modules_linux "$@"
udevadm trigger
udevadm settle
;;
esac
fi

exit 0

0 comments on commit a364048

Please sign in to comment.