2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Test non-recovery of unused CoW reservations for dirty files:
8 # - Create two reflinked files. Set extsz hint on second file.
9 # - Dirty a single byte on a number of CoW reservations in the second file.
10 # - Fsync to flush out the dirty pages.
11 # - Dirty a single byte anywhere in the second file.
12 # - Wait for the reclaim to run.
13 # - Write more and see how bad fragmentation is.
16 _begin_fstest auto quick clone
18 # Override the default cleanup function.
22 test -n "$old_cowgc_interval" && \
23 _xfs_set_cowgc_interval $old_cowgc_interval
27 # Import common functions.
31 # real QA test starts here
33 _require_xfs_io_command "cowextsize"
34 _require_scratch_reflink
36 _require_xfs_io_command "falloc"
37 _require_xfs_io_command "fiemap"
39 old_cowgc_interval=$(_xfs_get_cowgc_interval)
41 echo "Format and mount"
42 _scratch_mkfs > $seqres.full 2>&1
43 _scratch_mount >> $seqres.full 2>&1
45 testdir=$SCRATCH_MNT/test-$seq
50 filesize=$((blksz * nr))
52 bufsize=$((blksz * bufnr))
54 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
55 real_blksz=$(_get_block_size $testdir)
56 internal_blks=$((filesize / real_blksz))
58 echo "Create the original files"
59 $XFS_IO_PROG -c "cowextsize $bufsize" $testdir
60 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
61 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file2.chk >> $seqres.full
62 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
66 md5sum $testdir/file1 | _filter_scratch
67 md5sum $testdir/file2 | _filter_scratch
68 md5sum $testdir/file2.chk | _filter_scratch
70 echo "CoW and leave leftovers"
71 _xfs_set_cowgc_interval 2
72 seq 2 2 $((nr - 1)) | while read f; do
73 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2 >> $seqres.full
74 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2.chk >> $seqres.full
78 echo "Wait for CoW expiration"
79 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * 2)) 1" $testdir/file2 >> $seqres.full
82 echo "Allocate free space"
83 for i in $(seq 1 32); do
84 $XFS_IO_PROG -f -c "falloc 0 1" $testdir/junk.$i >> $seqres.full
86 $XFS_IO_PROG -f -c "falloc 0 $filesize" $testdir/junk >> $seqres.full
88 echo "CoW and leave leftovers"
89 _xfs_set_cowgc_interval $old_cowgc_interval
90 seq 2 2 $((nr - 1)) | while read f; do
91 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2 >> $seqres.full
92 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2.chk >> $seqres.full
97 md5sum $testdir/file1 | _filter_scratch
98 md5sum $testdir/file2 | _filter_scratch
99 md5sum $testdir/file2.chk | _filter_scratch
101 echo "Check extent counts"
102 old_extents=$(_count_extents $testdir/file1)
103 new_extents=$(_count_extents $testdir/file2)
105 echo "old extents: $old_extents" >> $seqres.full
106 echo "new extents: $new_extents" >> $seqres.full
107 echo "maximum extents: $internal_blks" >> $seqres.full
108 test $new_extents -le $((2 * nr / bufnr)) || echo "file2 more fragmented than expected"