generic: Test filesystem lockup on full overprovisioned dm-thin
[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_command $LVM_PROG lvm
66 _require_freeze
67
68 # remove previous $seqres.full before test
69 rm -f $seqres.full
70
71 vgname=vg_$seq
72 lvname=lv_$seq
73 poolname=pool_$seq
74 snapname=snap_$seq
75 origpsize=100
76 virtsize=200
77 newpsize=200
78
79 # Ensure we have enough disk space
80 _scratch_mkfs_sized $((250 * 1024 * 1024)) >>$seqres.full 2>&1
81
82 # Create a 100MB dm-thin POOL
83 $LVM_PROG pvcreate -f $SCRATCH_DEV >>$seqres.full 2>&1
84 $LVM_PROG vgcreate -f $vgname $SCRATCH_DEV >>$seqres.full 2>&1
85
86 $LVM_PROG lvcreate  --thinpool $poolname  --errorwhenfull y \
87                     --zero n -L $origpsize \
88                     --poolmetadatasize 4M $vgname >>$seqres.full 2>&1
89
90 # Create a overprovisioned 200MB dm-thin virt. device
91 $LVM_PROG lvcreate  --virtualsize $virtsize \
92                     -T $vgname/$poolname \
93                     -n $lvname >>$seqres.full 2>&1
94
95 _mkfs_dev /dev/mapper/$vgname-$lvname >>$seqres.full 2>&1
96
97
98 # Running the test over the original volume doesn't reproduce the problem
99 # reliably, while, running it over a snapshot, makes the problem 100%
100 # reproducible, so, create a snapshot and run the test over it.
101 $LVM_PROG lvcreate  -k n -s $vgname/$lvname \
102                     -n $snapname >>$seqres.full 2>&1
103
104 _mount /dev/mapper/$vgname-$snapname $SCRATCH_MNT
105
106 # Consume all space available in the volume and freeze to ensure everything
107 # required to make the fs consistent is flushed to disk.
108 $XFS_IO_PROG -f -d -c 'pwrite -b 1m 0 120m' $SCRATCH_MNT/f1 >>$seqres.full 2>&1
109
110 # In XFS, this freeze will never complete until the dm-thin POOL device is
111 # extended. It is expected, and is only used so xfsaild is triggered to
112 # flush AIL items, other filesystems usually get remounted as read-only during
113 # the above write process.
114 fsfreeze -f $SCRATCH_MNT >>$seqres.full 2>&1 &
115 freezeid=$!
116
117 # Wait enough so xfsaild can run
118 sleep 10
119
120 # Make some extra space available so the freeze above can proceed
121 $LVM_PROG lvextend -L $newpsize $vgname/$poolname >>$seqres.full 2>&1
122
123 wait $freezeid
124 ret=$?
125
126
127 # Different filesystems will handle the lack of real space in different ways,
128 # some will remount the filesystem in read-only mode, some will not. These tests
129 # will check if:
130 #       - The filesystem turns into Read-Only and reject further writes
131 #       - The filesystem stays in Read-Write mode, but can be frozen/thawed
132 #         without getting stuck.
133 ISRO=$(_fs_options /dev/mapper/$vgname-$snapname | grep -w "ro")
134
135 if [ $ret -ne 0 ]; then
136         if [ -n "$ISRO" ]; then
137                 echo "Test OK"
138         else
139                 echo "Freeze failed and FS isn't Read-Only. Test Failed"
140                 status=1
141                 exit
142         fi
143 else
144         # Try to thaw the filesystem, and complete test if if succeed.
145         # NOTE: This will hang on affected XFS filesystems.
146         fsfreeze -u $SCRATCH_MNT >>$seqres.full 2>&1
147         echo "Test OK"
148 fi
149
150 status=0
151 exit