summaryrefslogtreecommitdiffstats
path: root/scripts/unload-zfs.sh
blob: 12e987bd3f25f9d6c94565b5c3aaf71aa41123b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash

prog=unload-zfs.sh
. ../.script-config

spl_module=${SPLBUILD}/modules/spl/spl.ko
zlib_module=/lib/modules/${KERNELSRCVER}/kernel/lib/zlib_deflate/zlib_deflate.ko
zavl_module=${ZFSBUILD}/lib/libavl/zavl.ko
znvpair_module=${ZFSBUILD}/lib/libnvpair/znvpair.ko
zport_module=${ZFSBUILD}/lib/libport/zport.ko
zcommon_module=${ZFSBUILD}/lib/libzcommon/zcommon.ko
zpool_module=${ZFSBUILD}/lib/libzpool/zpool.ko
zctl_module=${ZFSBUILD}/lib/libdmu-ctl/zctl.ko
zpios_module=${ZFSBUILD}/lib/libzpios/zpios.ko

die() {
	echo "${prog}: $1" >&2
	exit 1
}

unload_module() {
	echo "Unloading $1"
	/sbin/rmmod $1 || die "Failed to unload $1"
}

if [ $(id -u) != 0 ]; then
	die "Must run as root"
fi

unload_module ${zpios_module}
unload_module ${zctl_module}
unload_module ${zpool_module}
unload_module ${zcommon_module}
unload_module ${zport_module}
unload_module ${znvpair_module}
unload_module ${zavl_module}
unload_module ${zlib_module}

# Set DUMP=1 to generate debug logs on unload
if [ -n "${DUMP}" ]; then
	sysctl -w kernel.spl.debug.dump=1
	# This is racy, I don't like it, but for a helper script it will do.
	SPL_LOG=`dmesg | tail -n 1 | cut -f5 -d' '`
	${SPLBUILD}/cmd/spl ${SPL_LOG} >${SPL_LOG}.log
	echo
	echo "Dumped debug log: ${SPL_LOG}.log"
	tail -n1 ${SPL_LOG}.log
	echo
fi

unload_module ${spl_module}

echo "Successfully unloaded ZFS module stack"

exit 0