Fix coverity defects: CID 155964, 155965
[zfs.git] / scripts / zfs.sh
blob55584ddd1f914ed0948f97df05ccdcbefefedc54
1 #!/bin/bash
3 # A simple script to simply the loading/unloading the ZFS module stack.
5 basedir="$(dirname $0)"
7 SCRIPT_COMMON=common.sh
8 if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
9 . "${basedir}/${SCRIPT_COMMON}"
10 else
11 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
14 PROG=zfs.sh
15 UNLOAD=
17 usage() {
18 cat << EOF
19 USAGE:
20 $0 [hvud] [module-options]
22 DESCRIPTION:
23 Load/unload the ZFS module stack.
25 OPTIONS:
26 -h Show this message
27 -v Verbose
28 -u Unload modules
29 -d Save debug log on unload
31 MODULE-OPTIONS:
32 Must be of the from module="options", for example:
34 $0 zfs="zfs_prefetch_disable=1"
35 $0 zfs="zfs_prefetch_disable=1 zfs_mdcomp_disable=1"
37 EOF
40 while getopts 'hvud' OPTION; do
41 case $OPTION in
43 usage
44 exit 1
47 VERBOSE=1
50 UNLOAD=1
53 DUMP_LOG=1
56 usage
57 exit
59 esac
60 done
62 if [ $(id -u) != 0 ]; then
63 die "Must run as root"
66 if [ ${UNLOAD} ]; then
67 kill_zed
68 umount -t zfs -a
69 stack_check
70 unload_modules
71 else
72 stack_clear
73 check_modules || die "${ERROR}"
74 load_modules "$@" || die "Failed to load modules"
75 wait_udev /dev/zfs 30 || die "'/dev/zfs' was not created"
78 exit 0