generic: test for file loss after mix of rename, fsync and inode eviction
[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 . ./common/preamble
23 _begin_fstest auto thin trim
24
25 # Override the default cleanup function.
26 _cleanup()
27 {
28         cd /
29         rm -f $tmp.*
30         _dmthin_cleanup
31 }
32
33 # Import common functions.
34 . ./common/filter
35 . ./common/dmthin
36
37 # real QA test starts here
38 _supported_fs generic
39 _require_scratch_nocheck
40 _require_dm_target thin-pool
41
42 # The unlink below will result in new metadata blocks for btrfs because of CoW,
43 # and since we've filled the thinp device it'll return EIO, which will make
44 # btrfs flip read only, making it fail this test when it just won't work right
45 # for us in the first place.
46 test $FSTYP == "btrfs"  && _notrun "btrfs doesn't work that way lol"
47
48 # Require underlying device support discard
49 _scratch_mkfs >>$seqres.full 2>&1
50 _scratch_mount
51 _require_batched_discard $SCRATCH_MNT
52 _scratch_unmount
53
54 # Create a thin pool and a *slightly smaller* thin volume, it's helpful
55 # to reproduce the bug
56 BACKING_SIZE=$((128 * 1024 * 1024 / 512))       # 128M
57 VIRTUAL_SIZE=$((BACKING_SIZE + 1024))           # 128M + 1k
58 CLUSTER_SIZE=$((64 * 1024 / 512))               # 64K
59
60 _dmthin_init $BACKING_SIZE $VIRTUAL_SIZE $CLUSTER_SIZE 0
61 _dmthin_set_fail
62 _dmthin_mkfs
63 _dmthin_mount
64
65 # There're two bugs at here, one is dm-thin bug, the other is filesystem
66 # (XFS especially) bug. The dm-thin bug can't handle running out of data
67 # space with concurrent discard well. Then the dm-thin bug cause fs unmount
68 # hang when racing a fstrim with a filesystem shutdown.
69 #
70 # If both of two bugs haven't been fixed, below test maybe cause deadlock.
71 # Else if the fs bug has been fixed, but the dm-thin bug hasn't. below test
72 # will cause the test fail (no deadlock).
73 # Else the test will pass.
74 for ((i=0; i<20; i++)); do
75         $XFS_IO_PROG -f -c "pwrite -b 64k 0 256M" \
76                 $SCRATCH_MNT/testfile &>/dev/null
77         rm -f $SCRATCH_MNT/testfile
78         $FSTRIM_PROG $SCRATCH_MNT
79 done
80
81 _dmthin_check_fs
82 _dmthin_cleanup
83
84 echo "Silence is golden"
85
86 # success, all done
87 status=0
88 exit