generic/520: Remove sync in clean_dir
[xfstests-dev.git] / tests / generic / 590
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 590
6 #
7 # Test commit 0c4da70c83d4 ("xfs: fix realtime file data space leak") and
8 # 69ffe5960df1 ("xfs: don't check for AG deadlock for realtime files in
9 # bunmapi"). On XFS without the fixes, truncate will hang forever. On other
10 # filesystems, this just tests writing into big fallocates.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25         test -n "$loop" && _destroy_loop_device "$loop"
26         rm -f "$TEST_DIR/$seq"
27 }
28
29 . ./common/rc
30 . ./common/filter
31
32 rm -f $seqres.full
33
34 _supported_fs generic
35 _supported_os Linux
36 _require_scratch_nocheck
37 _require_xfs_io_command "falloc"
38
39 maxextlen=$((0x1fffff))
40 bs=4096
41 rextsize=4
42 filesz=$(((maxextlen + 1) * bs))
43
44 extra_options=""
45 # If we're testing XFS, set up the realtime device to reproduce the bug.
46 if [[ $FSTYP = xfs ]]; then
47         # If we don't have a realtime device, set up a loop device on the test
48         # filesystem.
49         if [[ $USE_EXTERNAL != yes || -z $SCRATCH_RTDEV ]]; then
50                 _require_test
51                 loopsz="$((filesz + (1 << 26)))"
52                 _require_fs_space "$TEST_DIR" $((loopsz / 1024))
53                 $XFS_IO_PROG -c "truncate $loopsz" -f "$TEST_DIR/$seq"
54                 loop="$(_create_loop_device "$TEST_DIR/$seq")"
55                 USE_EXTERNAL=yes
56                 SCRATCH_RTDEV="$loop"
57         fi
58         extra_options="$extra_options -r extsize=$((bs * rextsize))"
59         extra_options="$extra_options -d agsize=$(((maxextlen + 1) * bs / 2)),rtinherit=1"
60         # disable reflink as reflink not supported with realtime devices
61         if _scratch_mkfs_xfs_supported -m reflink=0 >/dev/null 2>&1; then
62                 extra_options="$extra_options -m reflink=0"
63         fi
64         _scratch_mkfs $extra_options >>$seqres.full 2>&1
65         _try_scratch_mount >>$seqres.full 2>&1 || \
66                 _notrun "mount failed, kernel doesn't support realtime?"
67         _scratch_unmount
68 else
69         _scratch_mkfs $extra_options >>$seqres.full 2>&1
70 fi
71 _scratch_mount
72 _require_fs_space "$SCRATCH_MNT" $((filesz / 1024))
73
74 # Allocate maxextlen + 1 blocks. As long as the allocator does something sane,
75 # we should end up with two extents that look something like:
76 #
77 # u3.bmx[0-1] = [startoff,startblock,blockcount,extentflag]
78 # 0:[0,0,2097148,1]
79 # 1:[2097148,2097148,4,1]
80 #
81 # Extent 0 has blockcount = ALIGN_DOWN(maxextlen, rextsize). Extent 1 is
82 # adjacent and has blockcount = rextsize. Both are unwritten.
83 $XFS_IO_PROG -c "falloc 0 $filesz" -c fsync -f "$SCRATCH_MNT/file"
84
85 # Write extent 0 + one block of extent 1. Our extents should end up like so:
86 #
87 # u3.bmx[0-1] = [startoff,startblock,blockcount,extentflag]
88 # 0:[0,0,2097149,0]
89 # 1:[2097149,2097149,3,1]
90 #
91 # Extent 0 is written and has blockcount = ALIGN_DOWN(maxextlen, rextsize) + 1,
92 # Extent 1 is adjacent, unwritten, and has blockcount = rextsize - 1 and
93 # startblock % rextsize = 1.
94 #
95 # The -b is just to speed things up (doing GBs of I/O in 4k chunks kind of
96 # sucks).
97 $XFS_IO_PROG -c "pwrite -b 1M -W 0 $(((maxextlen + 2 - rextsize) * bs))" \
98         "$SCRATCH_MNT/file" >> "$seqres.full"
99
100 # Truncate the extents.
101 $XFS_IO_PROG -c "truncate 0" -c fsync "$SCRATCH_MNT/file"
102
103 # We need to do this before the loop device gets torn down.
104 _scratch_unmount
105 _check_scratch_fs
106
107 echo "Silence is golden"
108 status=0
109 exit