Skip to content

Commit

Permalink
scripts: zfs.sh: unload zfs with dependencies
Browse files Browse the repository at this point in the history
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes openzfs#13274
  • Loading branch information
nabijaczleweli authored and andrewc12 committed Sep 23, 2022
1 parent ea21da6 commit 3033615
Showing 1 changed file with 8 additions and 51 deletions.
59 changes: 8 additions & 51 deletions scripts/zfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ STACK_TRACER="no"

ZED_PIDFILE=${ZED_PIDFILE:-/var/run/zed.pid}
LDMOD=${LDMOD:-/sbin/modprobe}
DELMOD=${DELMOD:-/sbin/modprobe -r}

KMOD_ZLIB_DEFLATE=${KMOD_ZLIB_DEFLATE:-zlib_deflate}
KMOD_ZLIB_INFLATE=${KMOD_ZLIB_INFLATE:-zlib_inflate}
Expand Down Expand Up @@ -110,10 +111,11 @@ check_modules_linux() {
load_module_linux() {
KMOD=$1

FILE=$(modinfo "$KMOD" 2>&1 | awk 'NR == 1 && /zlib/ && /not found/ {print "(builtin)"; exit} /^filename:/ {print $2}')
[ "$FILE" = "(builtin)" ] && return

if [ "$VERBOSE" = "yes" ]; then
FILE=$(modinfo "$KMOD" | awk '/^filename:/ {print $2}')
VERSION=$(modinfo "$KMOD" | awk '/^version:/ {print $2}')

echo "Loading: $FILE ($VERSION)"
fi

Expand All @@ -138,15 +140,7 @@ load_modules_freebsd() {
load_modules_linux() {
mkdir -p /etc/zfs

if modinfo "$KMOD_ZLIB_DEFLATE" >/dev/null 2>&1; then
modprobe "$KMOD_ZLIB_DEFLATE" >/dev/null 2>&1
fi

if modinfo "$KMOD_ZLIB_INFLATE">/dev/null 2>&1; then
modprobe "$KMOD_ZLIB_INFLATE" >/dev/null 2>&1
fi

for KMOD in $KMOD_SPL $KMOD_ZFS; do
for KMOD in "$KMOD_ZLIB_DEFLATE" "$KMOD_ZLIB_INFLATE" $KMOD_SPL $KMOD_ZFS; do
load_module_linux "$KMOD" || return 1
done

Expand All @@ -157,24 +151,6 @@ load_modules_linux() {
return 0
}

unload_module_linux() {
KMOD=$1

NAME="${KMOD##*/}"
NAME="${NAME%.ko}"

if [ "$VERBOSE" = "yes" ]; then
FILE=$(modinfo "$KMOD" | awk '/^filename:/ {print $2}')
VERSION=$(modinfo "$KMOD" | awk '/^version:/ {print $2}')

echo "Unloading: $FILE ($VERSION)"
fi

rmmod "$NAME" || echo "Failed to unload $NAME"

return 0
}

unload_modules_freebsd() {
kldunload "$KMOD_FREEBSD" || echo "Failed to unload $KMOD_FREEBSD"

Expand All @@ -186,32 +162,13 @@ unload_modules_freebsd() {
}

unload_modules_linux() {
for KMOD in $KMOD_ZFS $KMOD_SPL; do
NAME="${KMOD##*/}"
NAME="${NAME%.ko}"
USE_COUNT=$(lsmod | awk '/^'"${NAME}"'/ {print $3}')

if [ "$USE_COUNT" = "0" ] ; then
unload_module_linux "$KMOD" || return 1
elif [ "$USE_COUNT" != "" ] ; then
echo "Module ${NAME} is still in use!"
return 1
fi
done

if modinfo "$KMOD_ZLIB_DEFLATE" >/dev/null 2>&1; then
modprobe -r "$KMOD_ZLIB_DEFLATE" >/dev/null 2>&1
fi

if modinfo "$KMOD_ZLIB_INFLATE">/dev/null 2>&1; then
modprobe -r "$KMOD_ZLIB_INFLATE" >/dev/null 2>&1
fi
NAME="${KMOD_ZFS##*/}"
NAME="${NAME%.ko}"
$DELMOD "$NAME" || return

if [ "$VERBOSE" = "yes" ]; then
echo "Successfully unloaded ZFS module stack"
fi

return 0
}

stack_clear_linux() {
Expand Down

0 comments on commit 3033615

Please sign in to comment.