3 # A simple script to load/unload the ZFS module stack.
6 BASE_DIR
=$
(dirname "$0")
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}
22 KMOD_ZLIB_DEFLATE
=${KMOD_ZLIB_DEFLATE:-zlib_deflate}
23 KMOD_ZLIB_INFLATE
=${KMOD_ZLIB_INFLATE:-zlib_inflate}
24 KMOD_SPL
=${KMOD_SPL:-spl}
25 KMOD_ZAVL
=${KMOD_ZAVL:-zavl}
26 KMOD_ZNVPAIR
=${KMOD_ZNVPAIR:-znvpair}
27 KMOD_ZUNICODE
=${KMOD_ZUNICODE:-zunicode}
28 KMOD_ZCOMMON
=${KMOD_ZCOMMON:-zcommon}
29 KMOD_ZLUA
=${KMOD_ZLUA:-zlua}
30 KMOD_ICP
=${KMOD_ICP:-icp}
31 KMOD_ZFS
=${KMOD_ZFS:-zfs}
37 $0 [hvudS] [module-options]
40 Load/unload the ZFS module stack.
46 -S Enable kernel stack tracer
50 while getopts 'hvuS' OPTION
; do
73 if [ -f "$ZED_PIDFILE" ]; then
74 PID
=$
(cat "$ZED_PIDFILE")
83 for KMOD
in $KMOD_SPL $KMOD_ZAVL $KMOD_ZNVPAIR \
84 $KMOD_ZUNICODE $KMOD_ZCOMMON $KMOD_ZLUA $KMOD_ICP $KMOD_ZFS; do
85 NAME
=$
(basename "$KMOD" .ko
)
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" "$PROG"
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"
114 FILE
=$
(modinfo
"$KMOD" |
awk '/^filename:/ {print $2}')
115 VERSION
=$
(modinfo
"$KMOD" |
awk '/^version:/ {print $2}')
117 if [ "$VERBOSE" = "yes" ]; then
118 echo "Loading: $FILE ($VERSION)"
121 $LDMOD "$KMOD" >/dev
/null
2>&1
122 # shellcheck disable=SC2181
123 if [ $?
-ne 0 ]; then
124 echo "Failed to load $KMOD"
134 if modinfo
"$KMOD_ZLIB_DEFLATE" >/dev
/null
2>&1; then
135 modprobe
"$KMOD_ZLIB_DEFLATE" >/dev
/null
2>&1
138 if modinfo
"$KMOD_ZLIB_INFLATE">/dev
/null
2>&1; then
139 modprobe
"$KMOD_ZLIB_INFLATE" >/dev
/null
2>&1
142 for KMOD
in $KMOD_SPL $KMOD_ZAVL $KMOD_ZNVPAIR \
143 $KMOD_ZUNICODE $KMOD_ZCOMMON $KMOD_ZLUA $KMOD_ICP $KMOD_ZFS; do
144 load_module
"$KMOD" ||
return 1
147 if [ "$VERBOSE" = "yes" ]; then
148 echo "Successfully loaded ZFS module stack"
157 NAME
=$
(basename "$KMOD" .ko
)
158 FILE
=$
(modinfo
"$KMOD" |
awk '/^filename:/ {print $2}')
159 VERSION
=$
(modinfo
"$KMOD" |
awk '/^version:/ {print $2}')
161 if [ "$VERBOSE" = "yes" ]; then
162 echo "Unloading: $KMOD ($VERSION)"
165 rmmod
"$NAME" ||
echo "Failed to unload $NAME"
171 for KMOD
in $KMOD_ZFS $KMOD_ICP $KMOD_ZLUA $KMOD_ZCOMMON $KMOD_ZUNICODE \
172 $KMOD_ZNVPAIR $KMOD_ZAVL $KMOD_SPL; do
173 NAME
=$
(basename "$KMOD" .ko
)
174 USE_COUNT
=$
(lsmod |
grep -E "^${NAME} " |
awk '{print $3}')
176 if [ "$USE_COUNT" = "0" ] ; then
177 unload_module
"$KMOD" ||
return 1
181 if modinfo
"$KMOD_ZLIB_DEFLATE" >/dev
/null
2>&1; then
182 modprobe
-r "$KMOD_ZLIB_DEFLATE" >/dev
/null
2>&1
185 if modinfo
"$KMOD_ZLIB_INFLATE">/dev
/null
2>&1; then
186 modprobe
-r "$KMOD_ZLIB_INFLATE" >/dev
/null
2>&1
189 if [ "$VERBOSE" = "yes" ]; then
190 echo "Successfully unloaded ZFS module stack"
197 STACK_MAX_SIZE
=/sys
/kernel
/debug
/tracing
/stack_max_size
198 STACK_TRACER_ENABLED
=/proc
/sys
/kernel
/stack_tracer_enabled
200 if [ "$STACK_TRACER" = "yes" ] && [ -e "$STACK_MAX_SIZE" ]; then
201 echo 1 >"$STACK_TRACER_ENABLED"
202 echo 0 >"$STACK_MAX_SIZE"
207 STACK_MAX_SIZE
=/sys
/kernel
/debug
/tracing
/stack_max_size
208 STACK_TRACE
=/sys
/kernel
/debug
/tracing
/stack_trace
211 if [ -e "$STACK_MAX_SIZE" ]; then
212 STACK_SIZE
=$
(cat "$STACK_MAX_SIZE")
214 if [ "$STACK_SIZE" -ge "$STACK_LIMIT" ]; then
216 echo "Warning: max stack size $STACK_SIZE bytes"
222 if [ "$(id -u)" != 0 ]; then
223 echo "Must run as root"
227 if [ "$UNLOAD" = "yes" ]; then