]> git.proxmox.com Git - mirror_zfs-debian.git/blame - scripts/zpios-sanity.sh
Merge branch 'upstream'
[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=
2ea9dc40 16FAILS=0
302ef151
BB
17
18usage() {
19cat << EOF
20USAGE:
21$0 [hvxfc]
22
23DESCRIPTION:
24 ZPIOS sanity tests
25
26OPTIONS:
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
33EOF
34}
35
36while 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
59done
60
61if [ $(id -u) != 0 ]; then
62 die "Must run as root"
63fi
64
5cbf6db9
BB
65# Initialize the test suite
66init
67
302ef151
BB
68# Perform pre-cleanup is requested
69if [ ${CLEANUP} ]; then
cbc6fab6
BB
70 ${ZFS_SH} -u
71 cleanup_md_devices
302ef151
BB
72 cleanup_loop_devices
73 rm -f /tmp/zpool.cache.*
74fi
75
76zpios_test() {
77 CONFIG=$1
78 TEST=$2
79 LOG=`mktemp`
80
81 ${ZPIOS_SH} -f -c ${CONFIG} -t ${TEST} &>${LOG}
82 if [ $? -ne 0 ]; then
2ea9dc40
BB
83 FAILS=1
84
302ef151
BB
85 if [ ${VERBOSE} ]; then
86 printf "FAIL: %-13s\n" ${CONFIG}
87 cat ${LOG}
88 else
89 if [ ! ${HEADER} ]; then
90 head -2 ${LOG}
91 HEADER=1
92 fi
93
94 printf "FAIL: %-13s" ${CONFIG}
95 tail -1 ${LOG}
96 fi
97 else
98 if [ ${VERBOSE} ]; then
99 cat ${LOG}
100 else
101 if [ ! ${HEADER} ]; then
102 head -2 ${LOG}
103 HEADER=1
104 fi
105
106 tail -1 ${LOG}
107 fi
108 fi
109
110 rm -f ${LOG}
111}
112
113if [ ${DANGEROUS} ] && [ ! ${FORCE} ]; then
114 cat << EOF
115The -x option was passed which will result in UNRECOVERABLE DATA LOSS
116on on the following block devices:
117
118 /dev/sd[abcd]
119 /dev/hda
120 /dev/ram0
121 /dev/md0
122 /dev/dm-0
123
124To continue please confirm by entering YES:
125EOF
126 read CONFIRM
127 if [ ${CONFIRM} != "YES" ] && [ ${CONFIRM} != "yes" ]; then
128 exit 0;
129 fi
130fi
131
132#
133# These configurations are all safe and pose no risk to any data on
134# the system which runs them. They will confine all their IO to a
135# file in /tmp or a loopback device configured to use a file in /tmp.
136#
137SAFE_CONFIGS=( \
138 file-raid0 file-raid10 file-raidz file-raidz2 \
139 lo-raid0 lo-raid10 lo-raidz lo-raidz2 \
140)
141
142#
143# These configurations are down right dangerous. They will attempt
144# to use various real block devices on your system which may contain
145# data you car about. You are STRONGLY advised not to run this unless
146# you are certain there is no data on the system you care about.
147#
148DANGEROUS_CONFIGS=( \
149 hda-raid0 \
150 sda-raid0 \
151 ram0-raid0 \
152 md0-raid10 md0-raid5 \
153 dm0-raid0 \
154)
155
cbc6fab6
BB
156TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
157${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || die "Unable to load modules"
158
302ef151
BB
159for CONFIG in ${SAFE_CONFIGS[*]}; do
160 zpios_test $CONFIG tiny
161done
162
163if [ ${DANGEROUS} ]; then
164 for CONFIG in ${DANGEROUS_CONFIGS[*]}; do
165 zpios_test $CONFIG tiny
166 done
167fi
168
cbc6fab6
BB
169${ZFS_SH} -u
170
2ea9dc40 171exit $FAILS