scripts: zfs.sh: make usage make sense

We don't pass the arguments as arguments

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13274
This commit is contained in:
наб 2022-04-04 12:55:41 +02:00 committed by Brian Behlendorf
parent f6f505c4d6
commit d18da59d30

View File

@ -3,7 +3,7 @@
# A simple script to load/unload the ZFS module stack. # A simple script to load/unload the ZFS module stack.
# #
BASE_DIR=$(dirname "$0") BASE_DIR=${0%/*}
SCRIPT_COMMON=common.sh SCRIPT_COMMON=common.sh
if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
. "${BASE_DIR}/${SCRIPT_COMMON}" . "${BASE_DIR}/${SCRIPT_COMMON}"
@ -11,7 +11,6 @@ else
echo "Missing helper script ${SCRIPT_COMMON}" && exit 1 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
fi fi
PROG=zfs.sh
VERBOSE="no" VERBOSE="no"
UNLOAD="no" UNLOAD="no"
LOAD="yes" LOAD="yes"
@ -28,9 +27,9 @@ KMOD_FREEBSD=${KMOD_FREEBSD:-openzfs}
usage() { usage() {
cat << EOF cat << EOF
USAGE: USAGE:
$0 [hvudS] [module-options] $0 [hvudS]
DESCRIPTION: DESCRIPTION:
Load/unload the ZFS module stack. Load/unload the ZFS module stack.
@ -42,14 +41,11 @@ OPTIONS:
-u Unload modules -u Unload modules
-S Enable kernel stack tracer -S Enable kernel stack tracer
EOF EOF
exit 1
} }
while getopts 'hvruS' OPTION; do while getopts 'hvruS' OPTION; do
case $OPTION in case $OPTION in
h)
usage
exit 1
;;
v) v)
VERBOSE="yes" VERBOSE="yes"
;; ;;
@ -64,14 +60,13 @@ while getopts 'hvruS' OPTION; do
S) S)
STACK_TRACER="yes" STACK_TRACER="yes"
;; ;;
?)
usage
exit
;;
*) *)
usage
;; ;;
esac esac
done done
shift $(( OPTIND - 1 ))
[ $# -eq 0 ] || usage
kill_zed() { kill_zed() {
if [ -f "$ZED_PIDFILE" ]; then if [ -f "$ZED_PIDFILE" ]; then
@ -98,7 +93,7 @@ check_modules_linux() {
done done
if [ -n "$LOADED_MODULES" ]; then if [ -n "$LOADED_MODULES" ]; then
printf "Unload the kernel modules by running '%s -u':\n" "$PROG" printf "Unload the kernel modules by running '%s -u':\n" "$0"
printf "%b" "$LOADED_MODULES" printf "%b" "$LOADED_MODULES"
exit 1 exit 1
fi fi
@ -115,10 +110,10 @@ check_modules_linux() {
load_module_linux() { load_module_linux() {
KMOD=$1 KMOD=$1
if [ "$VERBOSE" = "yes" ]; then
FILE=$(modinfo "$KMOD" | awk '/^filename:/ {print $2}') FILE=$(modinfo "$KMOD" | awk '/^filename:/ {print $2}')
VERSION=$(modinfo "$KMOD" | awk '/^version:/ {print $2}') VERSION=$(modinfo "$KMOD" | awk '/^version:/ {print $2}')
if [ "$VERBOSE" = "yes" ]; then
echo "Loading: $FILE ($VERSION)" echo "Loading: $FILE ($VERSION)"
fi fi
@ -167,11 +162,12 @@ unload_module_linux() {
NAME="${KMOD##*/}" NAME="${KMOD##*/}"
NAME="${NAME%.ko}" NAME="${NAME%.ko}"
if [ "$VERBOSE" = "yes" ]; then
FILE=$(modinfo "$KMOD" | awk '/^filename:/ {print $2}') FILE=$(modinfo "$KMOD" | awk '/^filename:/ {print $2}')
VERSION=$(modinfo "$KMOD" | awk '/^version:/ {print $2}') VERSION=$(modinfo "$KMOD" | awk '/^version:/ {print $2}')
if [ "$VERBOSE" = "yes" ]; then echo "Unloading: $FILE ($VERSION)"
echo "Unloading: $KMOD ($VERSION)"
fi fi
rmmod "$NAME" || echo "Failed to unload $NAME" rmmod "$NAME" || echo "Failed to unload $NAME"
@ -275,7 +271,7 @@ if [ "$LOAD" = "yes" ]; then
Linux) Linux)
stack_clear_linux stack_clear_linux
check_modules_linux check_modules_linux
load_modules_linux "$@" load_modules_linux
udevadm trigger udevadm trigger
udevadm settle udevadm settle
;; ;;