]> git.proxmox.com Git - mirror_zfs.git/blob - scripts/zpios-sanity.sh
Fix 'unexpected operator' bashism
[mirror_zfs.git] / scripts / zpios-sanity.sh
1 #!/bin/bash
2 #
3 # ZFS/ZPOOL configuration test script.
4
5 basedir="$(dirname $0)"
6
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
12 fi
13
14 PROG=zpios-sanity.sh
15 HEADER=
16 FAILS=0
17
18 usage() {
19 cat << EOF
20 USAGE:
21 $0 [hvxfc]
22
23 DESCRIPTION:
24 ZPIOS sanity tests
25
26 OPTIONS:
27 -h Show this message
28 -v Verbose
29 -x Destructive hd/sd/md/dm/ram tests
30 -f Don't prompt due to -x
31 -c Cleanup lo+file devices at start
32
33 EOF
34 }
35
36 while getopts 'hvxfc?' OPTION; do
37 case $OPTION in
38 h)
39 usage
40 exit 1
41 ;;
42 v)
43 VERBOSE=1
44 ;;
45 x)
46 DANGEROUS=1
47 ;;
48 f)
49 FORCE=1
50 ;;
51 c)
52 CLEANUP=1
53 ;;
54 ?)
55 usage
56 exit
57 ;;
58 esac
59 done
60
61 if [ $(id -u) != 0 ]; then
62 die "Must run as root"
63 fi
64
65 # Perform pre-cleanup is requested
66 if [ ${CLEANUP} ]; then
67 ${ZFS_SH} -u
68 cleanup_md_devices
69 cleanup_loop_devices
70 rm -f /tmp/zpool.cache.*
71 fi
72
73 zpios_test() {
74 CONFIG=$1
75 TEST=$2
76 LOG=`mktemp`
77
78 ${ZPIOS_SH} -f -c ${CONFIG} -t ${TEST} &>${LOG}
79 if [ $? -ne 0 ]; then
80 FAILS=1
81
82 if [ ${VERBOSE} ]; then
83 printf "FAIL: %-13s\n" ${CONFIG}
84 cat ${LOG}
85 else
86 if [ ! ${HEADER} ]; then
87 head -2 ${LOG}
88 HEADER=1
89 fi
90
91 printf "FAIL: %-13s" ${CONFIG}
92 tail -1 ${LOG}
93 fi
94 else
95 if [ ${VERBOSE} ]; then
96 cat ${LOG}
97 else
98 if [ ! ${HEADER} ]; then
99 head -2 ${LOG}
100 HEADER=1
101 fi
102
103 tail -1 ${LOG}
104 fi
105 fi
106
107 rm -f ${LOG}
108 }
109
110 if [ ${DANGEROUS} ] && [ ! ${FORCE} ]; then
111 cat << EOF
112 The -x option was passed which will result in UNRECOVERABLE DATA LOSS
113 on on the following block devices:
114
115 /dev/sd[abcd]
116 /dev/hda
117 /dev/ram0
118 /dev/md0
119 /dev/dm-0
120
121 To continue please confirm by entering YES:
122 EOF
123 read CONFIRM
124 if [ ${CONFIRM} != "YES" ] && [ ${CONFIRM} != "yes" ]; then
125 exit 0;
126 fi
127 fi
128
129 #
130 # These configurations are all safe and pose no risk to any data on
131 # the system which runs them. They will confine all their IO to a
132 # file in /tmp or a loopback device configured to use a file in /tmp.
133 #
134 SAFE_CONFIGS=( \
135 file-raid0 file-raid10 file-raidz file-raidz2 \
136 lo-raid0 lo-raid10 lo-raidz lo-raidz2 \
137 )
138
139 #
140 # These configurations are down right dangerous. They will attempt
141 # to use various real block devices on your system which may contain
142 # data you car about. You are STRONGLY advised not to run this unless
143 # you are certain there is no data on the system you care about.
144 #
145 DANGEROUS_CONFIGS=( \
146 hda-raid0 \
147 sda-raid0 \
148 ram0-raid0 \
149 md0-raid10 md0-raid5 \
150 dm0-raid0 \
151 )
152
153 TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
154 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || die "Unable to load modules"
155
156 for CONFIG in ${SAFE_CONFIGS[*]}; do
157 zpios_test $CONFIG tiny
158 done
159
160 if [ ${DANGEROUS} ]; then
161 for CONFIG in ${DANGEROUS_CONFIGS[*]}; do
162 zpios_test $CONFIG tiny
163 done
164 fi
165
166 ${ZFS_SH} -u
167
168 exit $FAILS