generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 302
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 302
6 #
7 # Test fragmentation after a lot of random CoW:
8 # - Create two reflinked files.
9 # - Directio write to random offsets to scatter CoW reservations.
10 # - Check the number of extents.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick clone
14
15 # Import common functions.
16 . ./common/filter
17 . ./common/reflink
18
19 # real QA test starts here
20 _require_scratch_reflink
21 _require_cp_reflink
22 _require_xfs_io_command "fiemap"
23 _require_odirect
24
25 echo "Format and mount"
26 _scratch_mkfs > $seqres.full 2>&1
27 _scratch_mount >> $seqres.full 2>&1
28
29 testdir=$SCRATCH_MNT/test-$seq
30 mkdir $testdir
31
32 blksz=65536
33 nr=128
34 filesize=$((blksz * nr))
35 bufnr=16
36 bufsize=$((blksz * bufnr))
37
38 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
39 real_blksz=$(_get_block_size $testdir)
40 internal_blks=$((filesize / real_blksz))
41
42 echo "Create the original files"
43 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
44 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
45 _scratch_cycle_mount
46
47 echo "Compare files"
48 md5sum $testdir/file1 | _filter_scratch
49 md5sum $testdir/file2 | _filter_scratch
50
51 echo "CoW and unmount"
52 for i in `seq 1 8`; do
53         $XFS_IO_PROG -d -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" $testdir/file2 >> $seqres.full
54 done
55 _scratch_cycle_mount
56
57 echo "Compare files"
58 md5sum $testdir/file1 | _filter_scratch
59
60 echo "Check extent counts"
61 old_extents=$(_count_extents $testdir/file1)
62 new_extents=$(_count_extents $testdir/file2)
63
64 echo "old extents: $old_extents" >> $seqres.full
65 echo "new extents: $new_extents" >> $seqres.full
66 echo "maximum extents: $internal_blks" >> $seqres.full
67 test $new_extents -le $internal_blks || echo "file2 badly fragmented"
68
69 # success, all done
70 status=0
71 exit