]> git.proxmox.com Git - mirror_zfs-debian.git/blame - debian/tests/kernel-smoke-test-scrub
Merge branch 'add_breaks_replaces_zfs_initramfs' into 'master'
[mirror_zfs-debian.git] / debian / tests / kernel-smoke-test-scrub
CommitLineData
a99554ab
AX
1#!/bin/sh
2#
3# Copyright (C) 2016 Canonical
4#
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License
7# as published by the Free Software Foundation; either version 2
8# of the License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18#
19echo -n "kernel smoke test, corrupt data and clean with a scrub: "
20TMP=/tmp
21VDEV0=${TMP}/pool0-$$.img
22VDEV1=${TMP}/pool1-$$.img
23VDEV2=${TMP}/pool2-$$.img
24VDEV3=${TMP}/pool3-$$.img
25VDEV_SZ=128
26POOL=pool-smoke-$$
27DATA=/${POOL}/random.dat
28ZFSFS="test tmp example data1 data2 data3"
29
30dd if=/dev/zero of=${VDEV0} bs=1M count=${VDEV_SZ} > /dev/null 2>&1
31dd if=/dev/zero of=${VDEV1} bs=1M count=${VDEV_SZ} > /dev/null 2>&1
32dd if=/dev/zero of=${VDEV2} bs=1M count=${VDEV_SZ} > /dev/null 2>&1
33dd if=/dev/zero of=${VDEV3} bs=1M count=${VDEV_SZ} > /dev/null 2>&1
34
35zpool create ${POOL} mirror ${VDEV0} ${VDEV1} mirror ${VDEV2} ${VDEV3}
36ret=$?
37if [ $ret -ne 0 ]; then
38 echo "FAILED: zpool create failed, exit code=$ret"
39 rm ${VDEV0} ${VDEV1} ${VDEV2} ${VDEV3}
40 exit 1
41fi
42
43#
44# Create a file
45#
46dd if=/dev/urandom of=$DATA bs=1M count=64 > /dev/null 2>&1
47sum1=$(md5sum ${DATA} | awk '{print $1}')
48
49#
50# Corrupt VDEV0
51#
52dd if=/dev/zero of=${VDEV0} bs=1M count=${VDEV_SZ} > /dev/null 2>&1
53sync
54
55#
56# Offline "corrupted" VDEV
57#
58zpool detach ${POOL} ${VDEV0}
59ret=$?
60if [ $ret -ne 0 ]; then
61 echo "FAILED: zpool detach failed, exit code=$ret"
62 zpool destroy ${POOL}
63 rm ${VDEV0} ${VDEV1} ${VDEV2} ${VDEV3}
64 exit 1
65fi
66
67#
68# Zero corrupted VDEV and re-attach
69#
70dd if=/dev/zero of=${VDEV0} bs=1M count=${VDEV_SZ} > /dev/null 2>&1
71zpool attach ${POOL} ${VDEV1} ${VDEV0} -f
72ret=$?
73if [ $ret -ne 0 ]; then
74 echo "FAILED: zpool attach failed, exit code=$ret"
75 zpool destroy ${POOL}
76 rm ${VDEV0} ${VDEV1} ${VDEV2} ${VDEV3}
77 exit 1
78fi
79
80zpool scrub ${POOL}
81ret=$?
82if [ $ret -ne 0 ]; then
83 echo "FAILED: zpool scrub failed, exit code=$ret"
84 zpool destroy ${POOL}
85 rm ${VDEV0} ${VDEV1} ${VDEV2} ${VDEV3}
86 exit 1
87fi
88
89sum2=$(md5sum ${DATA} | awk '{print $1}')
90#
91# Checksums must agree
92#
93if [ x"$sum1" != x"$sum2" ]; then
94 echo "FAILED: corrupted data on scrubbed pool"
95 zpool destroy ${POOL}
96 rm ${VDEV0} ${VDEV1} ${VDEV2} ${VDEV3}
97 exit 1
98fi
99
100zpool destroy ${POOL}
101ret=$?
102if [ $ret -ne 0 ]; then
103 echo "FAILED: zpool destroy failed, exit code=$ret"
104 #
105 # destroy failed, try to clean up, but this
106 # wil probably fail
107 #
108 rm ${VDEV0} ${VDEV1} ${VDEV2} ${VDEV3}
109 exit 1
110fi
111
112rm ${VDEV0} ${VDEV1} ${VDEV2} ${VDEV3}
113echo "PASSED"
114exit 0