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