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