xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / btrfs / 107
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Fujitsu. All Rights Reserved.
4 #
5 # FS QA Test 107
6 #
7 # Test that calling fallocate against a range which is already
8 # allocated does not truncate beyond EOF
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/defrag
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # real QA test starts here
34
35 _supported_fs btrfs
36 _require_scratch
37
38 # Use 64K file size to match any sectorsize
39 # And with a unaligned tailing range to ensure it will be at least 2 pages
40 filesize=$(( 64 * 1024 + 1024 ))
41
42 # Fallocate a range that will not cover the tailing page
43 fallocrange=$(( 64 * 1024 ))
44
45 _scratch_mkfs > /dev/null 2>&1
46 _scratch_mount
47 $XFS_IO_PROG -f -c "pwrite 0 $filesize" $SCRATCH_MNT/foo | _filter_xfs_io
48 sync
49 orig_extent_nr=`_extent_count $SCRATCH_MNT/foo`
50
51 # As all space are allocated and even written to disk, this falloc
52 # should do nothing with extent modification.
53 $XFS_IO_PROG -f -c "falloc 0 $fallocrange" $SCRATCH_MNT/foo
54 sync
55 new_extent_nr=`_extent_count $SCRATCH_MNT/foo`
56
57 echo "orig: $orig_extent_nr, new: $new_extent_nr" >> $seqres.full
58
59 if [ "x$orig_extent_nr" != "x$new_extent_nr" ]; then
60         echo "Extent beyond EOF is re-truncated"
61         echo "orig_extent_nr: $orig_extent_nr new_extent_nr: $new_extent_nr"
62 fi
63
64 # success, all done
65 status=0
66 exit