common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / btrfs / 206
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 206
6 #
7 # Validate that without no-holes we do not get a i_size that is after a gap in
8 # the file extents on disk when punching a hole past i_size.  This is fixed by
9 # the following patches
10 #
11 #       btrfs: use the file extent tree infrastructure
12 #       btrfs: replace all uses of btrfs_ordered_update_i_size
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         cd /
26         rm -f $tmp.*
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/dmlogwrites
33
34 # remove previous $seqres.full before test
35 rm -f $seqres.full
36
37 # real QA test starts here
38 _supported_fs btrfs
39 _supported_os Linux
40 _require_test
41 _require_scratch
42 _require_log_writes
43 _require_xfs_io_command "falloc" "-k"
44 _require_xfs_io_command "fpunch"
45
46 _log_writes_init $SCRATCH_DEV
47 _log_writes_mkfs "-O ^no-holes" >> $seqres.full 2>&1
48
49 # There's not a straightforward way to commit the transaction without also
50 # flushing dirty pages, so shorten the commit interval to 1 so we're sure to get
51 # a commit with our broken file
52 _log_writes_mount -o commit=1
53
54 # This creates a gap extent because fpunch doesn't insert hole extents past
55 # i_size
56 $XFS_IO_PROG -f -c "falloc -k 4k 8k" $SCRATCH_MNT/file
57 $XFS_IO_PROG -f -c "fpunch 4k 4k" $SCRATCH_MNT/file
58
59 # The pwrite extends the i_size to cover the gap extent, and then the truncate
60 # sets the disk_i_size to 12k because it assumes everything was a-ok.
61 $XFS_IO_PROG -f -c "pwrite 0 4k" $SCRATCH_MNT/file | _filter_xfs_io
62 $XFS_IO_PROG -f -c "pwrite 0 8k" $SCRATCH_MNT/file | _filter_xfs_io
63 $XFS_IO_PROG -f -c "truncate 12k" $SCRATCH_MNT/file
64
65 # Wait for a transaction commit
66 sleep 2
67
68 _log_writes_unmount
69 _log_writes_remove
70
71 cur=$(_log_writes_find_next_fua 0)
72 echo "cur=$cur" >> $seqres.full
73 while [ ! -z "$cur" ]; do
74         _log_writes_replay_log_range $cur $SCRATCH_DEV >> $seqres.full
75
76         # We only care about the fs consistency, so just run fsck, we don't have
77         # to mount the fs to validate it
78         _check_scratch_fs
79
80         cur=$(_log_writes_find_next_fua $(($cur + 1)))
81 done
82
83 # success, all done
84 status=0
85 exit