generic/459: add check for dm-snapshot target
[xfstests-dev.git] / tests / generic / 459
1 #! /bin/bash
2 # FS QA Test 459
3 #
4 # Test buffer filesystem error recovery during a full overcommited dm-thin device.
5 #
6 # When a dm-thin device reaches its full capacity, but the virtual device still
7 # shows available space, the filesystem should be able to handle such cases
8 # failing its operation without locking up.
9 #
10 # This test has been created first to cover a XFS problem where it loops
11 # indefinitely in xfsaild due items still in AIL. The buffers containing such
12 # items couldn't be resubmitted because the items were flush locked.
13 # But, once this doesn't require any special filesystem feature to be executed,
14 # this has been integrated as a generic test.
15 #
16 # This test might hang the filesystem when ran on an unpatched kernel
17 #
18 #-----------------------------------------------------------------------
19 # Copyright (c) 2017 Red Hat, Inc. All Rights Reserved.
20 #
21 # This program is free software; you can redistribute it and/or
22 # modify it under the terms of the GNU General Public License as
23 # published by the Free Software Foundation.
24 #
25 # This program is distributed in the hope that it would be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28 # GNU General Public License for more details.
29 #
30 # You should have received a copy of the GNU General Public License
31 # along with this program; if not, write the Free Software Foundation,
32 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
33 #-----------------------------------------------------------------------
34 #
35
36 seq=`basename $0`
37 seqres=$RESULT_DIR/$seq
38 echo "QA output created by $seq"
39
40 here=`pwd`
41 tmp=/tmp/$$
42 status=1        # failure is the default!
43 trap "_cleanup; exit \$status" 0 1 2 3 15
44
45 _cleanup()
46 {
47         cd /
48         rm -f $tmp.*
49         $UMOUNT_PROG $SCRATCH_MNT >>$seqres.full 2>&1
50         $LVM_PROG vgremove -ff $vgname >>$seqres.full 2>&1
51         $LVM_PROG pvremove -ff $SCRATCH_DEV >>$seqres.full 2>&1
52 }
53
54 # get standard environment, filters and checks
55 . ./common/rc
56
57 # real QA test starts here
58
59 # This tests for filesystem lockup not consistency, so don't check for fs
60 # consistency after test
61 _supported_fs generic
62 _supported_os Linux
63 _require_scratch_nocheck
64 _require_dm_target thin-pool
65 _require_dm_target snapshot
66 _require_command $LVM_PROG lvm
67 _require_command "$THIN_CHECK_PROG" thin_check
68 _require_freeze
69
70 # remove previous $seqres.full before test
71 rm -f $seqres.full
72
73 vgname=vg_$seq
74 lvname=lv_$seq
75 poolname=pool_$seq
76 snapname=snap_$seq
77 origpsize=100
78 virtsize=200
79 newpsize=200
80
81 # Ensure we have enough disk space
82 _scratch_mkfs_sized $((250 * 1024 * 1024)) >>$seqres.full 2>&1
83
84 # Create a 100MB dm-thin POOL
85 $LVM_PROG pvcreate -f $SCRATCH_DEV >>$seqres.full 2>&1
86 $LVM_PROG vgcreate -f $vgname $SCRATCH_DEV >>$seqres.full 2>&1
87
88 $LVM_PROG lvcreate  --thinpool $poolname  --errorwhenfull y \
89                     --zero n -L $origpsize \
90                     --poolmetadatasize 4M $vgname >>$seqres.full 2>&1
91
92 # Create a overprovisioned 200MB dm-thin virt. device
93 $LVM_PROG lvcreate  --virtualsize $virtsize \
94                     -T $vgname/$poolname \
95                     -n $lvname >>$seqres.full 2>&1
96
97 _mkfs_dev /dev/mapper/$vgname-$lvname >>$seqres.full 2>&1
98
99
100 # Running the test over the original volume doesn't reproduce the problem
101 # reliably, while, running it over a snapshot, makes the problem 100%
102 # reproducible, so, create a snapshot and run the test over it.
103 $LVM_PROG lvcreate  -k n -s $vgname/$lvname \
104                     -n $snapname >>$seqres.full 2>&1
105
106 _mount /dev/mapper/$vgname-$snapname $SCRATCH_MNT
107
108 # Consume all space available in the volume and freeze to ensure everything
109 # required to make the fs consistent is flushed to disk.
110 $XFS_IO_PROG -f -d -c 'pwrite -b 1m 0 120m' $SCRATCH_MNT/f1 >>$seqres.full 2>&1
111
112 # In XFS, this freeze will never complete until the dm-thin POOL device is
113 # extended. It is expected, and is only used so xfsaild is triggered to
114 # flush AIL items, other filesystems usually get remounted as read-only during
115 # the above write process.
116 fsfreeze -f $SCRATCH_MNT >>$seqres.full 2>&1 &
117 freezeid=$!
118
119 # Wait enough so xfsaild can run
120 sleep 10
121
122 # Make some extra space available so the freeze above can proceed
123 $LVM_PROG lvextend -L $newpsize $vgname/$poolname >>$seqres.full 2>&1
124
125 wait $freezeid
126 ret=$?
127
128
129 # Different filesystems will handle the lack of real space in different ways,
130 # some will remount the filesystem in read-only mode, some will not. These tests
131 # will check if:
132 #       - The filesystem turns into Read-Only and reject further writes
133 #       - The filesystem stays in Read-Write mode, but can be frozen/thawed
134 #         without getting stuck.
135 ISRO=$(_fs_options /dev/mapper/$vgname-$snapname | grep -w "ro")
136
137 if [ $ret -ne 0 ]; then
138         if [ -n "$ISRO" ]; then
139                 echo "Test OK"
140         else
141                 echo "Freeze failed and FS isn't Read-Only. Test Failed"
142                 status=1
143                 exit
144         fi
145 else
146         # Try to thaw the filesystem, and complete test if if succeed.
147         # NOTE: This will hang on affected XFS filesystems.
148         fsfreeze -u $SCRATCH_MNT >>$seqres.full 2>&1
149         echo "Test OK"
150 fi
151
152 status=0
153 exit