2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensuring that copy on write in directio mode works when free space
8 # is heavily fragmented.
10 # - Reflink the odd blocks of the first file into a third file.
11 # - Reflink the even blocks of the second file into the third file.
12 # - Try to fragment the free space by allocating a huge file and
13 # punching out every other block.
14 # - CoW across the halfway mark.
15 # - Check that the files are now different where we say they're different.
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
23 status=1 # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
29 # rm -rf $tmp.* $testdir
32 # get standard environment, filters and checks
37 # real QA test starts here
39 _require_scratch_reflink
41 _require_xfs_io_command "falloc"
42 _require_xfs_io_command "fpunch"
43 test $FSTYP = "btrfs" && _notrun "Can't fragment free space on btrfs."
52 # consume nearly all available space (leave ~1MB)
53 avail=`_get_available_space $SCRATCH_MNT`
54 echo "$avail bytes left"
55 filesize=$((avail - 1048576))
56 $XFS_IO_PROG -fc "truncate $filesize" $file
59 chunksizemb=$((filesize / chunks / 1048576))
60 seq 1 $chunks | while read f; do
61 echo "$((f * chunksizemb)) file size $f / 20"
62 $XFS_IO_PROG -fc "falloc -k $(( (f - 1) * chunksizemb))m ${chunksizemb}m" $file
66 chunksizemb=$((filesize / chunks / 1048576))
67 seq 80 $chunks | while read f; do
68 echo "$((f * chunksizemb)) file size $f / $chunks"
69 $XFS_IO_PROG -fc "falloc -k $(( (f - 1) * chunksizemb))m ${chunksizemb}m" $file
72 filesizemb=$((filesize / 1048576))
73 $XFS_IO_PROG -fc "falloc -k 0 ${filesizemb}m" $file
76 avail=`_get_available_space $SCRATCH_MNT`
77 $XFS_IO_PROG -fc "pwrite -S 0x65 0 $avail" ${file}
79 # Punch out whatever we need
80 seq 1 $((nr * 4)) | while read f; do
81 $XFS_IO_PROG -f -c "fpunch $((f * 2 * blksz)) $blksz" $file
85 echo "Format and mount"
86 _scratch_mkfs > $seqres.full 2>&1
87 _scratch_mount >> $seqres.full 2>&1
89 testdir=$SCRATCH_MNT/test-$seq
92 echo "Create the original files"
95 filesize=$((blksz * nr))
96 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
97 _pwrite_byte 0x62 0 $filesize $testdir/file2 >> $seqres.full
98 seq 0 2 $((nr-1)) | while read f; do
99 _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
100 _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
102 seq 1 2 $((nr-1)) | while read f; do
103 _reflink_range $testdir/file2 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
104 _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
107 _fragment_freesp $testdir/bigfile >> $seqres.full 2>&1
108 filesize=$((blksz * nr))
112 md5sum $testdir/file1 | _filter_scratch
113 md5sum $testdir/file2 | _filter_scratch
114 md5sum $testdir/file3 | _filter_scratch
115 md5sum $testdir/file3.chk | _filter_scratch
117 echo "CoW with multiple extents?"
118 cowoff=$((filesize / 4))
119 cowsz=$((filesize / 2))
120 $XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
121 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
125 md5sum $testdir/file1 | _filter_scratch
126 md5sum $testdir/file2 | _filter_scratch
127 md5sum $testdir/file3 | _filter_scratch
128 md5sum $testdir/file3.chk | _filter_scratch