2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Red Hat Inc. All Rights Reserved.
7 # Race test running out of data space with concurrent discard operation on
10 # If a user constructs a test that loops repeatedly over below steps on
11 # dm-thin, block allocation can fail due to discards not having completed
12 # yet (Fixed by a685557 dm thin: handle running out of data space vs
13 # concurrent discard):
14 # 1) fill thin device via filesystem file
18 # And this maybe cause a deadlock when racing a fstrim with a filesystem
19 # (XFS) shutdown. (Fixed by 8c81dd46ef3c Force log to disk before reading
20 # the AGF during a fstrim)
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
28 status=1 # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
43 # remove previous $seqres.full before test
46 # real QA test starts here
49 _require_scratch_nocheck
50 _require_dm_target thin-pool
52 # The unlink below will result in new metadata blocks for btrfs because of CoW,
53 # and since we've filled the thinp device it'll return EIO, which will make
54 # btrfs flip read only, making it fail this test when it just won't work right
55 # for us in the first place.
56 test $FSTYP == "btrfs" && _notrun "btrfs doesn't work that way lol"
58 # Require underlying device support discard
59 _scratch_mkfs >>$seqres.full 2>&1
61 _require_batched_discard $SCRATCH_MNT
64 # Create a thin pool and a *slightly smaller* thin volume, it's helpful
65 # to reproduce the bug
66 BACKING_SIZE=$((128 * 1024 * 1024 / 512)) # 128M
67 VIRTUAL_SIZE=$((BACKING_SIZE + 1024)) # 128M + 1k
68 CLUSTER_SIZE=$((64 * 1024 / 512)) # 64K
70 _dmthin_init $BACKING_SIZE $VIRTUAL_SIZE $CLUSTER_SIZE 0
72 _mkfs_dev $DMTHIN_VOL_DEV
75 # There're two bugs at here, one is dm-thin bug, the other is filesystem
76 # (XFS especially) bug. The dm-thin bug can't handle running out of data
77 # space with concurrent discard well. Then the dm-thin bug cause fs unmount
78 # hang when racing a fstrim with a filesystem shutdown.
80 # If both of two bugs haven't been fixed, below test maybe cause deadlock.
81 # Else if the fs bug has been fixed, but the dm-thin bug hasn't. below test
82 # will cause the test fail (no deadlock).
83 # Else the test will pass.
84 for ((i=0; i<20; i++)); do
85 $XFS_IO_PROG -f -c "pwrite -b 64k 0 256M" \
86 $SCRATCH_MNT/testfile &>/dev/null
87 rm -f $SCRATCH_MNT/testfile
88 $FSTRIM_PROG $SCRATCH_MNT
94 echo "Silence is golden"