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