]> git.proxmox.com Git - mirror_zfs-debian.git/blame - scripts/zpios-sanity.sh
Add FAILFAST support
[mirror_zfs-debian.git] / scripts / zpios-sanity.sh
CommitLineData
302ef151
BB
1#!/bin/bash
2#
3# ZFS/ZPOOL configuration test script.
4
5basedir="$(dirname $0)"
6
7SCRIPT_COMMON=common.sh
8if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
9. "${basedir}/${SCRIPT_COMMON}"
10else
11echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
12fi
13
14PROG=zpios-sanity.sh
15HEADER=
16
17usage() {
18cat << EOF
19USAGE:
20$0 [hvxfc]
21
22DESCRIPTION:
23 ZPIOS sanity tests
24
25OPTIONS:
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
32EOF
33}
34
35while 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
58done
59
60if [ $(id -u) != 0 ]; then
61 die "Must run as root"
62fi
63
64# Perform pre-cleanup is requested
65if [ ${CLEANUP} ]; then
66 cleanup_loop_devices
67 rm -f /tmp/zpool.cache.*
68fi
69
70zpios_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
105if [ ${DANGEROUS} ] && [ ! ${FORCE} ]; then
106 cat << EOF
107The -x option was passed which will result in UNRECOVERABLE DATA LOSS
108on on the following block devices:
109
110 /dev/sd[abcd]
111 /dev/hda
112 /dev/ram0
113 /dev/md0
114 /dev/dm-0
115
116To continue please confirm by entering YES:
117EOF
118 read CONFIRM
119 if [ ${CONFIRM} != "YES" ] && [ ${CONFIRM} != "yes" ]; then
120 exit 0;
121 fi
122fi
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#
129SAFE_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#
140DANGEROUS_CONFIGS=( \
141 hda-raid0 \
142 sda-raid0 \
143 ram0-raid0 \
144 md0-raid10 md0-raid5 \
145 dm0-raid0 \
146)
147
148for CONFIG in ${SAFE_CONFIGS[*]}; do
149 zpios_test $CONFIG tiny
150done
151
152if [ ${DANGEROUS} ]; then
153 for CONFIG in ${DANGEROUS_CONFIGS[*]}; do
154 zpios_test $CONFIG tiny
155 done
156fi
157
158exit 0