xfs/007: fix regressions on V4 filesystems
[xfstests-dev.git] / tests / xfs / 204
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. 204
6 #
7 # Test fragmentation after a lot of random CoW:
8 # - Create two reflinked files.  Set extsz hint on second file.
9 # - Read the whole file into memory.
10 # - DIO write to random offsets to scatter CoW reservations.
11 # - fadvise(dontneed) the whole file to evict the pages.
12 # - falloc the whole fle to see if the extsz hints still apply.
13 # - Check the number of extents.
14 #
15 . ./common/preamble
16 _begin_fstest auto quick clone
17
18 # Import common functions.
19 . ./common/filter
20 . ./common/reflink
21
22 # real QA test starts here
23 _supported_fs xfs
24 _require_scratch_reflink
25 _require_cp_reflink
26 _require_xfs_io_command "fiemap"
27 _require_xfs_io_command "cowextsize"
28 _require_xfs_io_command "funshare"
29 _require_odirect
30
31 echo "Format and mount"
32 _scratch_mkfs > $seqres.full 2>&1
33 _scratch_mount >> $seqres.full 2>&1
34
35 testdir=$SCRATCH_MNT/test-$seq
36 mkdir $testdir
37
38 blksz=65536
39 nr=128
40 filesize=$((blksz * nr))
41 bufnr=16
42 bufsize=$((blksz * bufnr))
43
44 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
45 real_blksz=$(_get_block_size $testdir)
46 internal_blks=$((filesize / real_blksz))
47
48 echo "Create the original files"
49 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
50 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
51 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
52 _scratch_cycle_mount
53
54 echo "Compare files"
55 md5sum $testdir/file1 | _filter_scratch
56 md5sum $testdir/file2 | _filter_scratch
57
58 echo "CoW and unmount"
59 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
60 cat $testdir/file2 > /dev/null
61 $XFS_IO_PROG -d -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full
62 $XFS_IO_PROG -f -c "fadvise -d 0 $filesize" -c "fsync" $testdir/file2 >> $seqres.full
63 $XFS_IO_PROG -f -c "funshare 0 $filesize" $testdir/file2 >> $seqres.full
64 _scratch_cycle_mount
65
66 echo "Compare files"
67 md5sum $testdir/file1 | _filter_scratch
68
69 echo "Check extent counts"
70 old_extents=$(_count_extents $testdir/file1)
71 new_extents=$(_count_extents $testdir/file2)
72
73 echo "old extents: $old_extents" >> $seqres.full
74 echo "new extents: $new_extents" >> $seqres.full
75 echo "maximum extents: $internal_blks" >> $seqres.full
76 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
77         || echo "file2 badly fragmented"
78
79 # success, all done
80 status=0
81 exit