2 # FS QA Test No. btrfs/052
4 # Verify that the btrfs ioctl clone operation can operate on the same
5 # file as a source and target. That is, clone extents within the same
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2014 Filipe Manana. All Rights Reserved.
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #-----------------------------------------------------------------------
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
39 # get standard environment, filters and checks
43 # real QA test starts here
52 test_btrfs_clone_same_file()
59 _scratch_mkfs >/dev/null 2>&1
60 _scratch_mount $MOUNT_OPTIONS
62 # Create a file with 5 extents, 4 of 8Kb each and 1 of 64Kb.
63 $XFS_IO_PROG -f -c "pwrite -S 0x01 -b 8192 0 8192" $SCRATCH_MNT/foo \
66 $XFS_IO_PROG -c "pwrite -S 0x02 -b 8192 8192 8192" $SCRATCH_MNT/foo \
69 $XFS_IO_PROG -c "pwrite -S 0x03 -b 8192 16384 8192" $SCRATCH_MNT/foo \
72 $XFS_IO_PROG -c "pwrite -S 0x04 -b 8192 24576 8192" $SCRATCH_MNT/foo \
75 $XFS_IO_PROG -c "pwrite -S 0x05 -b 65536 32768 65536" $SCRATCH_MNT/foo \
79 # Digest of initial content.
80 md5sum $SCRATCH_MNT/foo | _filter_scratch
82 # Same source and target ranges - must fail.
83 $CLONER_PROG -s 8192 -d 8192 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
84 # Check file content didn't change.
85 md5sum $SCRATCH_MNT/foo | _filter_scratch
87 # Intersection between source and target ranges - must fail too.
88 $CLONER_PROG -s 4096 -d 8192 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
89 # Check file content didn't change.
90 md5sum $SCRATCH_MNT/foo | _filter_scratch
92 # Clone an entire extent from a higher range to a lower range.
93 $CLONER_PROG -s 24576 -d 0 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
95 # Check entire file, the 8Kb block at offset 0 now has the same content
96 # as the 8Kb block at offset 24576.
97 od -t x1 $SCRATCH_MNT/foo
99 # Clone an entire extent from a lower range to a higher range.
100 $CLONER_PROG -s 8192 -d 16384 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
102 # Check entire file, the 8Kb block at offset 0 now has the same content
103 # as the 8Kb block at offset 24576, and the 8Kb block at offset 16384
104 # now has the same content as the 8Kb block at offset 8192.
105 od -t x1 $SCRATCH_MNT/foo
107 # Now clone 1 extent and an half into the file range starting at offset
108 # 65536. So we get the second half of the extent at offset 16384 and the
109 # whole extent at 24576 cloned into the middle of the 64Kb extent that
110 # starts at file offset 32768. This makes the clone ioctl process more
111 # extent items from the b+tree and forces a split of the large 64Kb
112 # extent at the end of the file.
113 $CLONER_PROG -s 20480 -d 65536 -l 12288 $SCRATCH_MNT/foo \
116 # Check entire file. Besides the previous changes, we now should have
117 # 4096 bytes with the value 0x02 at file offset 65536, and 8192 bytes
118 # with value 0x04 at the file offset 69632. The ranges [32768, 65536[
119 # and [77824, 98304[ should remain with all bytes having the value 0x05.
120 od -t x1 $SCRATCH_MNT/foo
122 # Now update 8Kb of data at offset 0. The extent at this position is a
123 # clone of the extent at offset 24576. Check that writing to this offset
124 # doesn't change data at offset 24576.
125 $XFS_IO_PROG -c "pwrite -S 0xff -b 8192 0 8192" $SCRATCH_MNT/foo \
127 od -t x1 $SCRATCH_MNT/foo
129 # Check that after defragmenting the file and re-mounting, the file
130 # content remains exactly the same as before.
131 _run_btrfs_util_prog filesystem defragment $SCRATCH_MNT/foo
133 od -t x1 $SCRATCH_MNT/foo
135 # Verify that there are no consistency errors.
139 # For any of the tests below, regardless of cow/nodatacow/compression, the
140 # results as observed by an application/user should be exactly the same.
142 echo "Testing with a cow file (default)"
143 test_btrfs_clone_same_file
147 echo "Testing with a nocow file (-O nodatacow)"
148 test_btrfs_clone_same_file "nodatacow"
152 echo "Testing with a cow file and lzo compression"
153 test_btrfs_clone_same_file "compress-force=lzo"
157 echo "Testing with a cow file and zlib compression"
158 test_btrfs_clone_same_file "compress-force=zlib"
162 echo "Testing with a nocow file and lzo compression"
163 test_btrfs_clone_same_file "nodatacow,compress-force=lzo"
167 echo "Testing with a nocow file and zlib compression"
168 test_btrfs_clone_same_file "nodatacow,compress-force=zlib"