3 # A simple script to load/unload the ZFS module stack.
7 SCRIPT_COMMON
=common.sh
8 if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
9 .
"${BASE_DIR}/${SCRIPT_COMMON}"
11 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
19 ZED_PIDFILE
=${ZED_PIDFILE:-/var/run/zed.pid}
20 LDMOD
=${LDMOD:-/sbin/modprobe}
21 DELMOD
=${DELMOD:-/sbin/rmmod}
23 KMOD_ZLIB_DEFLATE
=${KMOD_ZLIB_DEFLATE:-zlib_deflate}
24 KMOD_ZLIB_INFLATE
=${KMOD_ZLIB_INFLATE:-zlib_inflate}
25 KMOD_SPL
=${KMOD_SPL:-spl}
26 KMOD_ZFS
=${KMOD_ZFS:-zfs}
27 KMOD_FREEBSD
=${KMOD_FREEBSD:-openzfs}
36 Load/unload the ZFS module stack.
43 -S Enable kernel stack tracer
48 while getopts 'hvruS' OPTION
; do
69 shift $
(( OPTIND
- 1 ))
73 if [ -f "$ZED_PIDFILE" ]; then
74 read -r PID
<"$ZED_PIDFILE"
79 check_modules_linux
() {
83 for KMOD
in $KMOD_SPL $KMOD_ZFS; do
87 if lsmod |
grep -E -q "^${NAME}"; then
88 LOADED_MODULES
="$LOADED_MODULES\t$NAME\n"
91 if ! modinfo
"$KMOD" >/dev
/null
2>&1; then
92 MISSING_MODULES
="$MISSING_MODULES\t${KMOD}\n"
96 if [ -n "$LOADED_MODULES" ]; then
97 printf "Unload the kernel modules by running '%s -u':\n" "$0"
98 printf "%b" "$LOADED_MODULES"
102 if [ -n "$MISSING_MODULES" ]; then
103 printf "The following kernel modules can not be found:\n"
104 printf "%b" "$MISSING_MODULES"
111 load_module_linux
() {
114 FILE
=$
(modinfo
"$KMOD" 2>&1 |
awk 'NR == 1 && /zlib/ && /not found/ {print "(builtin)"; exit} /^filename:/ {print $2}')
115 [ "$FILE" = "(builtin)" ] && return
117 if [ "$VERBOSE" = "yes" ]; then
118 VERSION
=$
(modinfo
"$KMOD" |
awk '/^version:/ {print $2}')
119 echo "Loading: $FILE ($VERSION)"
122 if ! $LDMOD "$KMOD" >/dev
/null
2>&1; then
123 echo "Failed to load $KMOD"
130 load_modules_freebsd
() {
131 kldload
"$KMOD_FREEBSD" ||
return 1
133 if [ "$VERBOSE" = "yes" ]; then
134 echo "Successfully loaded ZFS module stack"
140 load_modules_linux
() {
143 for KMOD
in "$KMOD_ZLIB_DEFLATE" "$KMOD_ZLIB_INFLATE" $KMOD_SPL $KMOD_ZFS; do
144 load_module_linux
"$KMOD" ||
return 1
147 if [ "$VERBOSE" = "yes" ]; then
148 echo "Successfully loaded ZFS module stack"
154 unload_modules_freebsd
() {
155 kldunload
"$KMOD_FREEBSD" ||
echo "Failed to unload $KMOD_FREEBSD"
157 if [ "$VERBOSE" = "yes" ]; then
158 echo "Successfully unloaded ZFS module stack"
164 unload_modules_linux
() {
165 legacy_kmods
="icp zzstd zlua zcommon zunicode znvpair zavl"
166 for KMOD
in "$KMOD_ZFS" $legacy_kmods "$KMOD_SPL"; do
169 ! [ -d "/sys/module/$NAME" ] ||
$DELMOD "$NAME" ||
return
172 if [ "$VERBOSE" = "yes" ]; then
173 echo "Successfully unloaded ZFS module stack"
177 stack_clear_linux
() {
178 STACK_MAX_SIZE
=/sys
/kernel
/debug
/tracing
/stack_max_size
179 STACK_TRACER_ENABLED
=/proc
/sys
/kernel
/stack_tracer_enabled
181 if [ "$STACK_TRACER" = "yes" ] && [ -e "$STACK_MAX_SIZE" ]; then
182 echo 1 >"$STACK_TRACER_ENABLED"
183 echo 0 >"$STACK_MAX_SIZE"
187 stack_check_linux
() {
188 STACK_MAX_SIZE
=/sys
/kernel
/debug
/tracing
/stack_max_size
189 STACK_TRACE
=/sys
/kernel
/debug
/tracing
/stack_trace
192 if [ -e "$STACK_MAX_SIZE" ]; then
193 read -r STACK_SIZE
<"$STACK_MAX_SIZE"
194 if [ "$STACK_SIZE" -ge "$STACK_LIMIT" ]; then
196 echo "Warning: max stack size $STACK_SIZE bytes"
202 if [ "$(id -u)" != 0 ]; then
203 echo "Must run as root"
209 if [ "$UNLOAD" = "yes" ]; then
214 unload_modules_freebsd
221 echo "unknown system: $UNAME" >&2
226 if [ "$LOAD" = "yes" ]; then
239 echo "unknown system: $UNAME" >&2