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