]> git.proxmox.com Git - mirror_zfs-debian.git/blame - debian/tests/kernel-smoke-test-snapshot
Expand zfs-test and add Breaks/Conflicts
[mirror_zfs-debian.git] / debian / tests / kernel-smoke-test-snapshot
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, ZFS snapshot: "
20TMP=/tmp
21VDEV0=${TMP}/pool0-$$.img
22VDEV1=${TMP}/pool1-$$.img
23POOL=pool-smoke-$$
24MARKER=/${POOL}/test/marker
25
26dd if=/dev/zero of=${VDEV0} bs=1M count=512 > /dev/null 2>&1
27dd if=/dev/zero of=${VDEV1} bs=1M count=512 > /dev/null 2>&1
28
29zpool create ${POOL} ${VDEV0} ${VDEV1}
30ret=$?
31if [ $ret -ne 0 ]; then
32 echo "FAILED: zpool create failed, exit code=$ret"
33 rm ${VDEV0} ${VDEV1}
34 exit 1
35fi
36
37zfs create ${POOL}/test
38ret=$?
39if [ $ret -ne 0 ]; then
40 echo "FAILED: zfs create failed, exit code=$ret"
41 zpool destroy ${POOL}
42 rm ${VDEV0} ${VDEV1}
43 exit 1
44fi
45
46#
47# Populate with files..
48#
49cp -rp /etc /${POOL}/test
50echo $$ > ${MARKER}
51
52#
53# Make a snapshot
54#
55zfs snapshot -r ${POOL}/test@snap
56ret=$?
57if [ $ret -ne 0 ]; then
58 echo "FAILED: zfs snapshot failed, exit code=$ret"
59 zpool destroy ${POOL}
60 rm ${VDEV0} ${VDEV1}
61 exit 1
62fi
63
64#
65# Remove files
66#
67rm -rf /${POOL}/test/etc ${MARKER}
68
69#
70# Roll back
71#
72zfs rollback ${POOL}/test@snap
73ret=$?
74if [ $ret -ne 0 ]; then
75 echo "FAILED: zfs rollback failed, exit code=$ret"
76 zpool destroy ${POOL}
77 rm ${VDEV0} ${VDEV1}
78 exit 1
79fi
80
81#
82# Check rolled back marker contains sane data
83#
84if [ ! -e ${MARKER} ]; then
85 echo "FAILED: zfs rollback failed, ${MARKER} not restored"
86 zpool destroy ${POOL}
87 rm ${VDEV0} ${VDEV1}
88 exit 1
89fi
90data=$(cat ${MARKER})
91if [ $data -ne $$ ]; then
92 echo "FAILED: zfs rollback failed, ${MARKER} contained unexpected data"
93 zpool destroy ${POOL}
94 rm ${VDEV0} ${VDEV1}
95 exit 1
96fi
97
98zfs destroy ${POOL}/test@snap
99ret=$?
100if [ $ret -ne 0 ]; then
101 echo "FAILED: zfs destroy snapshot failed, exit code=$ret"
102 zpool destroy ${POOL}
103 rm ${VDEV0} ${VDEV1}
104 exit 1
105fi
106
107zpool destroy ${POOL}
108ret=$?
109if [ $ret -ne 0 ]; then
110 echo "FAILED: zpool destroy failed, exit code=$ret"
111 #
112 # destroy failed, try to clean up, but this
113 # wil probably fail
114 #
115 rm ${VDEV0} ${VDEV1}
116 exit 1
117fi
118
119rm ${VDEV0} ${VDEV1}
120echo "PASSED"
121exit 0