7fd7a6fa7cedef12100b889de5f0bd3f2613fb21
[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 . ./common/preamble
22 _begin_fstest auto freeze thin
23
24 # Override the default cleanup function.
25 _cleanup()
26 {
27         cd /
28         rm -f $tmp.*
29         $UMOUNT_PROG $SCRATCH_MNT >>$seqres.full 2>&1
30         $LVM_PROG vgremove -ff $vgname >>$seqres.full 2>&1
31         $LVM_PROG pvremove -ff $SCRATCH_DEV >>$seqres.full 2>&1
32 }
33
34 # Import common functions.
35
36 # real QA test starts here
37
38 # This tests for filesystem lockup not consistency, so don't check for fs
39 # consistency after test
40 _supported_fs generic
41 _require_scratch_nocheck
42 _require_dm_target thin-pool
43 _require_dm_target snapshot
44 _require_command $LVM_PROG lvm
45 _require_command "$THIN_CHECK_PROG" thin_check
46 _require_freeze
47
48 vgname=vg_$seq
49 lvname=lv_$seq
50 poolname=pool_$seq
51 snapname=snap_$seq
52 origpsize=200
53 virtsize=300
54 newpsize=300
55
56 # Ensure we have enough disk space
57 _scratch_mkfs_sized $((350 * 1024 * 1024)) >>$seqres.full 2>&1
58
59 # Create a 200MB dm-thin POOL
60 $LVM_PROG pvcreate -f $SCRATCH_DEV >>$seqres.full 2>&1
61 $LVM_PROG vgcreate -f $vgname $SCRATCH_DEV >>$seqres.full 2>&1
62
63 $LVM_PROG lvcreate  --thinpool $poolname  --errorwhenfull y \
64                     --zero n -L $origpsize \
65                     --poolmetadatasize 4M $vgname >>$seqres.full 2>&1
66
67 # Create a overprovisioned 300MB dm-thin virt. device
68 $LVM_PROG lvcreate  --virtualsize $virtsize \
69                     -T $vgname/$poolname \
70                     -n $lvname >>$seqres.full 2>&1
71
72 _mkfs_dev /dev/mapper/$vgname-$lvname >>$seqres.full 2>&1
73
74 # Running the test over the original volume doesn't reproduce the problem
75 # reliably, while, running it over a snapshot, makes the problem 100%
76 # reproducible, so, create a snapshot and run the test over it.
77 $LVM_PROG lvcreate  -k n -s $vgname/$lvname \
78                     -n $snapname >>$seqres.full 2>&1
79
80 _mount /dev/mapper/$vgname-$snapname $SCRATCH_MNT
81
82 # Consume all space available in the volume and freeze to ensure everything
83 # required to make the fs consistent is flushed to disk.
84 $XFS_IO_PROG -f -d -c 'pwrite -b 1m 0 220m' $SCRATCH_MNT/f1 >>$seqres.full 2>&1
85
86 # In XFS, this freeze will never complete until the dm-thin POOL device is
87 # extended. It is expected, and is only used so xfsaild is triggered to
88 # flush AIL items, other filesystems usually get remounted as read-only during
89 # the above write process.
90 xfs_freeze -f $SCRATCH_MNT >>$seqres.full 2>&1 &
91 freezeid=$!
92
93 # Wait enough so xfsaild can run
94 sleep 10
95
96 # Make some extra space available so the freeze above can proceed
97 $LVM_PROG lvextend -L $newpsize $vgname/$poolname >>$seqres.full 2>&1
98
99 wait $freezeid
100 ret=$?
101
102 # Different filesystems will handle the lack of real space in different ways,
103 # some will remount the filesystem in read-only mode, some will not. These tests
104 # will check if:
105 #       - The filesystem turns into Read-Only and reject further writes
106 #       - The filesystem stays in Read-Write mode, but can be frozen/thawed
107 #         without getting stuck.
108 if [ $ret -ne 0 ]; then
109         # freeze failed, filesystem should reject further writes and remount
110         # as readonly. Sometimes the previous write process won't trigger
111         # ro-remount, e.g. on ext3/4, do additional touch here to make sure
112         # filesystems see the metadata I/O error.
113         touch $SCRATCH_MNT/newfile >/dev/null 2>&1
114         ISRO=$(_fs_options /dev/mapper/$vgname-$snapname | grep -w "ro")
115         if [ -n "$ISRO" ]; then
116                 echo "Test OK"
117         else
118                 echo "Freeze failed and FS isn't Read-Only. Test Failed"
119                 status=1
120                 exit
121         fi
122 else
123         # Try to thaw the filesystem, and complete test if if succeed.
124         # NOTE: This will hang on affected XFS filesystems.
125         xfs_freeze -u $SCRATCH_MNT >>$seqres.full 2>&1
126         echo "Test OK"
127 fi
128
129 status=0
130 exit