generic: test for file loss after mix of rename, fsync and inode eviction
[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 . ./common/preamble
13 _begin_fstest auto prealloc collapse
14
15 # Import common functions.
16 . ./common/filter
17
18 # real QA test starts here
19 _supported_fs generic
20
21 _require_scratch
22 _require_xfs_io_command "fiemap"
23 _require_xfs_io_command "fcollapse"
24 _do_die_on_error=y
25
26 _scratch_mkfs > /dev/null 2>&1
27 _scratch_mount
28
29 testfile=$SCRATCH_MNT/$seq.$$
30 BLOCKS=10240
31
32 BSIZE=`_get_block_size $SCRATCH_MNT`
33
34 length=$(($BLOCKS * $BSIZE))
35
36 # Write file
37 $XFS_IO_PROG -f -c "pwrite 0 $length" -c fsync $testfile > /dev/null
38
39 # Collapse alternate blocks 
40 for (( i = 1; i <= 7; i++ )); do
41         for (( j=0; j < $(($BLOCKS/(2**$i))); j++ )); do
42                 offset=$(($j*$BSIZE))
43                 $XFS_IO_PROG -c "fcollapse $offset $BSIZE" $testfile > /dev/null
44         done
45 done
46
47 # Check if 80 extents are present
48 $XFS_IO_PROG -c "fiemap -v" $testfile | grep "^ *[0-9]*:" |wc -l
49
50 # success, all done
51 status=0
52 exit