aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorRyan Moeller <[email protected]>2019-12-19 12:31:16 -0500
committerBrian Behlendorf <[email protected]>2019-12-19 09:31:16 -0800
commita3640486fffc592806c16f5149170ed659c94c2c (patch)
tree141f174ec0a001d7f5345d6b00362a414b6492bb /scripts
parentd16a207f2edd19ece593967e7e83b7e2217d04f9 (diff)
Update zfs.sh work on FreeBSD
Extend the zfs.sh script to load and unload zfs kmods on FreeBSD. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Kjeld Schouten <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #9746
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.am1
-rwxr-xr-xscripts/zfs.sh69
2 files changed, 54 insertions, 16 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index d275a41c4..1d4306492 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -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
diff --git a/scripts/zfs.sh b/scripts/zfs.sh
index 015b3ba9d..e1cfdc5e1 100755
--- a/scripts/zfs.sh
+++ b/scripts/zfs.sh
@@ -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() {
@@ -76,7 +77,7 @@ kill_zed() {
fi
}
-check_modules() {
+check_modules_linux() {
LOADED_MODULES=""
MISSING_MODULES=""
@@ -108,7 +109,7 @@ check_modules() {
return 0
}
-load_module() {
+load_module_linux() {
KMOD=$1
FILE=$(modinfo "$KMOD" | awk '/^filename:/ {print $2}')
@@ -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
@@ -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
@@ -151,7 +162,7 @@ load_modules() {
return 0
}
-unload_module() {
+unload_module_linux() {
KMOD=$1
NAME=$(basename "$KMOD" .ko)
@@ -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
@@ -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
@@ -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
@@ -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