201d8b9ff8b70a33d71abf39db669daea8cbe761
[xfstests-dev.git] / tests / generic / 500
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 500
6 #
7 # Race test running out of data space with concurrent discard operation on
8 # dm-thin.
9 #
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
15 # 2) remove file
16 # 3) fstrim
17 #
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)
21 #
22 seq=`basename $0`
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
25
26 here=`pwd`
27 tmp=/tmp/$$
28 status=1        # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
30
31 _cleanup()
32 {
33         cd /
34         rm -f $tmp.*
35         _dmthin_cleanup
36 }
37
38 # get standard environment, filters and checks
39 . ./common/rc
40 . ./common/filter
41 . ./common/dmthin
42
43 # remove previous $seqres.full before test
44 rm -f $seqres.full
45
46 # real QA test starts here
47 _supported_fs generic
48 _supported_os Linux
49 _require_scratch_nocheck
50 _require_dm_target thin-pool
51
52 # Require underlying device support discard
53 _scratch_mkfs >>$seqres.full 2>&1
54 _scratch_mount
55 _require_batched_discard $SCRATCH_MNT
56 _scratch_unmount
57
58 # Create a thin pool and a *slightly smaller* thin volume, it's helpful
59 # to reproduce the bug
60 BACKING_SIZE=$((128 * 1024 * 1024 / 512))       # 128M
61 VIRTUAL_SIZE=$((BACKING_SIZE + 1024))           # 128M + 1k
62 CLUSTER_SIZE=$((64 * 1024 / 512))               # 64K
63
64 _dmthin_init $BACKING_SIZE $VIRTUAL_SIZE $CLUSTER_SIZE 0
65 _dmthin_set_fail
66 _mkfs_dev $DMTHIN_VOL_DEV
67 _dmthin_mount
68
69 # There're two bugs at here, one is dm-thin bug, the other is filesystem
70 # (XFS especially) bug. The dm-thin bug can't handle running out of data
71 # space with concurrent discard well. Then the dm-thin bug cause fs unmount
72 # hang when racing a fstrim with a filesystem shutdown.
73 #
74 # If both of two bugs haven't been fixed, below test maybe cause deadlock.
75 # Else if the fs bug has been fixed, but the dm-thin bug hasn't. below test
76 # will cause the test fail (no deadlock).
77 # Else the test will pass.
78 for ((i=0; i<20; i++)); do
79         $XFS_IO_PROG -f -c "pwrite -b 64k 0 256M" \
80                 $SCRATCH_MNT/testfile &>/dev/null
81         rm -f $SCRATCH_MNT/testfile
82         $FSTRIM_PROG $SCRATCH_MNT
83 done
84
85 _dmthin_check_fs
86 _dmthin_cleanup
87
88 echo "Silence is golden"
89
90 # success, all done
91 status=0
92 exit