overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / generic / 064
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Samsung Electronics.  All Rights Reserved.
4 #
5 # FS QA Test No. generic/064
6 #
7 # Test multiple fallocate insert/collapse range calls on same file.
8 # Call insert range on alternate blocks multiple times until the file
9 # is left with 50 extents and as many holes. Then call collapse range
10 # on the previously inserted ranges to test merge code of collapse
11 # range. Also check for data integrity and file system consistency.
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 "rm -f $tmp.*; exit \$status" 0 1 2 3 15
20
21 # get standard environment, filters and checks
22 . ./common/rc
23 . ./common/filter
24
25 # real QA test starts here
26 _supported_fs generic
27 _supported_os Linux
28
29 _require_scratch
30 _require_xfs_io_command "fiemap"
31 _require_xfs_io_command "finsert"
32 _require_xfs_io_command "fcollapse"
33
34 rm -f $seqres.full
35
36 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
37 _scratch_mount
38
39 src=$SCRATCH_MNT/testfile
40 dest=$SCRATCH_MNT/testfile.dest
41 BLOCKS=100
42 BSIZE=`_get_block_size $SCRATCH_MNT`
43 length=$(($BLOCKS * $BSIZE))
44
45 # Write file
46 _do "$XFS_IO_PROG -f -c \"pwrite 0 $length\" -c fsync $src"
47 cp $src $dest
48 extent_before=`_count_extents $dest`
49
50 # Insert alternate blocks
51 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
52         offset=$((($j*$BSIZE)*2))
53         _do "$XFS_IO_PROG -c \"finsert $offset $BSIZE\" $dest"
54 done
55
56 # Check if 50 extents are present, allowing some slop for file systems
57 # that don't have ideal allocation behavior
58 num_extents=`_count_extents $dest`
59 _within_tolerance "Extent count after inserts" $num_extents 50 0 6% -v
60
61 _check_scratch_fs
62 if [ $? -ne 0 ]; then
63         status=1
64         exit
65 fi
66
67 # Collapse alternate blocks
68 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
69         offset=$((($j*$BSIZE)))
70         _do "$XFS_IO_PROG -c \"fcollapse $offset $BSIZE\" $dest"
71 done
72
73 extent_after=`_count_extents $dest`
74 if [ $extent_before -ne $extent_after ]; then
75         echo "extents mismatched before = $extent_before after = $extent_after"
76 fi
77
78 # compare original file and test file.
79 cmp $src $dest || _fail "file bytes check failed"
80
81 # success, all done
82 status=0
83 exit