xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / xfs / 114
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 114
6 #
7 # Make sure that we can handle insert-range followed by collapse-range.
8 # In particular, make sure that fcollapse works for rmap when the
9 # extents on either side of the collapse area are mergeable.
10 #
11 seq=`basename "$0"`
12 seqres="$RESULT_DIR/$seq"
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1    # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -rf "$tmp".*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/reflink
30
31 # real QA test starts here
32 _supported_fs xfs
33 _require_test_program "punch-alternating"
34 _require_xfs_scratch_rmapbt
35 _require_xfs_io_command "fcollapse"
36 _require_xfs_io_command "finsert"
37
38 rm -f "$seqres.full"
39
40 echo "Format and mount"
41 _scratch_mkfs > "$seqres.full" 2>&1
42 _scratch_mount
43 blksz=65536
44 blocks1=150     # enough extents to force btree format
45 blocks2=16      # local format
46 len1=$((blocks1 * blksz))
47 len2=$((blocks2 * blksz))
48 file_blksz=$(_get_file_block_size $SCRATCH_MNT)
49
50 echo "Create some files"
51 $XFS_IO_PROG -f \
52         -c "falloc 0 $len1" \
53         -c "pwrite -S 0x68 -b 1048576 0 $len1" \
54         $SCRATCH_MNT/f1 >> $seqres.full
55 $XFS_IO_PROG -f \
56         -c "falloc 0 $len2" \
57         -c "pwrite -S 0x68 -b 1048576 0 $len2" \
58         $SCRATCH_MNT/f2 >> $seqres.full
59
60 $here/src/punch-alternating -o $((16 * blksz / file_blksz)) \
61         -s $((blksz / file_blksz)) \
62         -i $((blksz * 2 / file_blksz)) \
63         $SCRATCH_MNT/f1 >> "$seqres.full"
64
65 echo "Insert and write file range"
66 $XFS_IO_PROG \
67         -c "finsert $((8 * blksz)) $blksz" \
68         -c "pwrite -S 0x69 $((8 * blksz)) $blksz" \
69         -c "fsync" \
70         $SCRATCH_MNT/f1 >> $seqres.full
71 $XFS_IO_PROG \
72         -c "finsert $((8 * blksz)) $blksz" \
73         -c "pwrite -S 0x69 $((8 * blksz)) $blksz" \
74         -c "fsync" \
75         $SCRATCH_MNT/f2 >> $seqres.full
76
77 # Make reflink copies to force it to use the fancy rmap operations.
78 # The test's functionality doesn't depend on the fs supporting reflink.
79 _cp_reflink $SCRATCH_MNT/f1 $SCRATCH_MNT/e1 >> $seqres.full 2>&1
80 _cp_reflink $SCRATCH_MNT/f2 $SCRATCH_MNT/e2 >> $seqres.full 2>&1
81
82 echo "f1 bmap" >> $seqres.full
83 $XFS_IO_PROG -c 'bmap -elpv' $SCRATCH_MNT/f1 >> $seqres.full
84 echo "f2 bmap" >> $seqres.full
85 $XFS_IO_PROG -c 'bmap -elpv' $SCRATCH_MNT/f2 >> $seqres.full
86 echo "fsmap" >> $seqres.full
87 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT >> $seqres.full
88
89 echo "Remount"
90 _scratch_unmount
91 _scratch_xfs_check
92 _scratch_mount
93
94 echo "Collapse file"
95 $XFS_IO_PROG -c "fcollapse $((8 * blksz)) $blksz" $SCRATCH_MNT/f1 >> $seqres.full
96 $XFS_IO_PROG -c "fcollapse $((8 * blksz)) $blksz" $SCRATCH_MNT/f2 >> $seqres.full
97
98 echo "f1 bmap" >> $seqres.full
99 $XFS_IO_PROG -c 'bmap -elpv' $SCRATCH_MNT/f1 >> $seqres.full
100 echo "f2 bmap" >> $seqres.full
101 $XFS_IO_PROG -c 'bmap -elpv' $SCRATCH_MNT/f2 >> $seqres.full
102 echo "fsmap" >> $seqres.full
103 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT >> $seqres.full
104
105 echo "Check file"
106 md5sum $SCRATCH_MNT/f1 | _filter_scratch
107 md5sum $SCRATCH_MNT/f2 | _filter_scratch
108 od -tx1 -Ad -c $SCRATCH_MNT/f1 >> $seqres.full
109 od -tx1 -Ad -c $SCRATCH_MNT/f2 >> $seqres.full
110
111 # success, all done
112 status=0
113 exit