xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / generic / 017
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Samsung Electronics.  All Rights Reserved.
4 #
5 # FS QA Test No. generci/017
6 #
7 # Test multiple fallocate collapse range calls on same file.
8 # For different blocksizes, collapse a single alternate block multiple times
9 # until the file is left with 80 blocks and as much number of extents.
10 # Also check for file system consistency after completing this operation
11 # for each blocksize.
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
28 _require_scratch
29 _require_xfs_io_command "fiemap"
30 _require_xfs_io_command "fcollapse"
31 _do_die_on_error=y
32
33 _scratch_mkfs > /dev/null 2>&1
34 _scratch_mount
35
36 testfile=$SCRATCH_MNT/$seq.$$
37 BLOCKS=10240
38
39 BSIZE=`_get_block_size $SCRATCH_MNT`
40
41 length=$(($BLOCKS * $BSIZE))
42
43 # Write file
44 $XFS_IO_PROG -f -c "pwrite 0 $length" -c fsync $testfile > /dev/null
45
46 # Collapse alternate blocks 
47 for (( i = 1; i <= 7; i++ )); do
48         for (( j=0; j < $(($BLOCKS/(2**$i))); j++ )); do
49                 offset=$(($j*$BSIZE))
50                 $XFS_IO_PROG -c "fcollapse $offset $BSIZE" $testfile > /dev/null
51         done
52 done
53
54 # Check if 80 extents are present
55 $XFS_IO_PROG -c "fiemap -v" $testfile | grep "^ *[0-9]*:" |wc -l
56
57 # success, all done
58 status=0
59 exit