4 # Test buffer filesystem error recovery during a full overcommited dm-thin device.
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.
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.
16 # This test might hang the filesystem when ran on an unpatched kernel
18 #-----------------------------------------------------------------------
19 # Copyright (c) 2017 Red Hat, Inc. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
37 seqres=$RESULT_DIR/$seq
38 echo "QA output created by $seq"
42 status=1 # failure is the default!
43 trap "_cleanup; exit \$status" 0 1 2 3 15
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
54 # get standard environment, filters and checks
57 # real QA test starts here
59 # This tests for filesystem lockup not consistency, so don't check for fs
60 # consistency after test
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
70 # remove previous $seqres.full before test
81 # Ensure we have enough disk space
82 _scratch_mkfs_sized $((250 * 1024 * 1024)) >>$seqres.full 2>&1
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
88 $LVM_PROG lvcreate --thinpool $poolname --errorwhenfull y \
89 --zero n -L $origpsize \
90 --poolmetadatasize 4M $vgname >>$seqres.full 2>&1
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
97 _mkfs_dev /dev/mapper/$vgname-$lvname >>$seqres.full 2>&1
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
106 _mount /dev/mapper/$vgname-$snapname $SCRATCH_MNT
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
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 &
119 # Wait enough so xfsaild can run
122 # Make some extra space available so the freeze above can proceed
123 $LVM_PROG lvextend -L $newpsize $vgname/$poolname >>$seqres.full 2>&1
128 # Different filesystems will handle the lack of real space in different ways,
129 # some will remount the filesystem in read-only mode, some will not. These tests
131 # - The filesystem turns into Read-Only and reject further writes
132 # - The filesystem stays in Read-Write mode, but can be frozen/thawed
133 # without getting stuck.
134 if [ $ret -ne 0 ]; then
135 # fsfreeze failed, filesystem should reject further writes and remount
136 # as readonly. Sometimes the previous write process won't trigger
137 # ro-remount, e.g. on ext3/4, do additional touch here to make sure
138 # filesystems see the metadata I/O error.
139 touch $SCRATCH_MNT/newfile >/dev/null 2>&1
140 ISRO=$(_fs_options /dev/mapper/$vgname-$snapname | grep -w "ro")
141 if [ -n "$ISRO" ]; then
144 echo "Freeze failed and FS isn't Read-Only. Test Failed"
149 # Try to thaw the filesystem, and complete test if if succeed.
150 # NOTE: This will hang on affected XFS filesystems.
151 fsfreeze -u $SCRATCH_MNT >>$seqres.full 2>&1