GCC 7.1 fixes
[zfs.git] / scripts / zfs.sh
blob2ffcf40da5ef8ba6fca18a9bcc45d303f79cf13c
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 # shellcheck disable=SC2034
15 PROG=zfs.sh
16 UNLOAD=
18 usage() {
19 cat << EOF
20 USAGE:
21 $0 [hvud] [module-options]
23 DESCRIPTION:
24 Load/unload the ZFS module stack.
26 OPTIONS:
27 -h Show this message
28 -v Verbose
29 -u Unload modules
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 'hvu' OPTION; do
41 case $OPTION in
43 usage
44 exit 1
47 # shellcheck disable=SC2034
48 VERBOSE=1
51 UNLOAD=1
54 usage
55 exit
57 esac
58 done
60 if [ "$(id -u)" != 0 ]; then
61 die "Must run as root"
64 if [ ${UNLOAD} ]; then
65 kill_zed
66 umount -t zfs -a
67 stack_check
68 unload_modules
69 else
70 stack_clear
71 check_modules || die "${ERROR}"
72 load_modules "$@" || die "Failed to load modules"
73 wait_udev /dev/zfs 30 || die "'/dev/zfs' was not created"
76 exit 0