2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test several scenarios of cloning operations where the source range includes
8 # inline extents. They used to not be supported on btrfs because their
9 # implementation was not straightforward, and therefore these operations used
10 # to fail with errno EOPNOTSUPP on older kernels.
12 # Support for this was added by a patch with the following subject:
14 # "Btrfs: implement full reflink support for inline extents"
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
20 status=1 # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
29 # get standard environment, filters and checks
34 # real QA test starts here
37 _require_scratch_reflink
38 _require_xfs_io_command "falloc" "-k"
39 _require_command "$CHATTR_PROG" chattr
40 _require_btrfs_fs_feature "no_holes"
41 _require_btrfs_mkfs_feature "no-holes"
45 rm -f $SCRATCH_MNT/foo* $SCRATCH_MNT/bar*
47 # File foo1 has an inline extent encoding 4K of data followed by a regular
48 # extent. It has a file size of 128K.
49 echo "Creating file foo1"
50 touch $SCRATCH_MNT/foo1
51 $CHATTR_PROG +c $SCRATCH_MNT/foo1
52 $XFS_IO_PROG -c "pwrite -S 0xab 0 4K" \
54 -c "pwrite -S 0xab 4K 124K" \
55 $SCRATCH_MNT/foo1 | _filter_xfs_io
57 # File bar1 has a single 128K extent, and a file size of 128K.
58 echo "Creating file bar1"
59 $XFS_IO_PROG -f -c "pwrite -S 0xcd 0 128K" $SCRATCH_MNT/bar1 | _filter_xfs_io
61 echo "Cloning foo1 into the end of bar1"
62 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo1 0 128K 128K" $SCRATCH_MNT/bar1 \
65 echo "File bar1 digest = $(_md5_checksum $SCRATCH_MNT/bar1)"
67 # File foo2 has an inline extent with 1000 bytes of data and it's followed
68 # by a regular extent of 60K. It has a file size of 64K.
69 echo "Creating file foo2"
70 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 1000" \
73 -c "pwrite -S 0xab 4K 60K" \
74 $SCRATCH_MNT/foo2 | _filter_xfs_io
76 # File bar2 has a regular extent of 64K and a file size of 64K too.
77 echo "Creating file bar2"
78 $XFS_IO_PROG -f -c "pwrite -S 0xcd 0 64K" $SCRATCH_MNT/bar2 | _filter_xfs_io
80 echo "Cloning foo2 into the end of bar2"
81 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo2 0 64K 64K" $SCRATCH_MNT/bar2 \
84 echo "File bar2 digest = $(_md5_checksum $SCRATCH_MNT/bar2)"
86 # File bar3 has a regular extent of 128K and a file size of 128K too.
87 echo "Creating file bar3"
88 $XFS_IO_PROG -f -c "pwrite -S 0xcd 0 128K" $SCRATCH_MNT/bar3 \
91 echo "Cloning foo2 into the middle of bar3"
92 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo2 0 64K 64K" $SCRATCH_MNT/bar3 \
95 echo "File bar3 digest = $(_md5_checksum $SCRATCH_MNT/bar3)"
97 # File bar4 has a 64K hole at offset 0 followed by a 64K regular extent, and
98 # a file size of 128K.
99 echo "Creating file bar4"
100 $XFS_IO_PROG -f -c "pwrite -S 0xcd 64K 64K" $SCRATCH_MNT/bar4 | _filter_xfs_io
102 echo "Cloning foo1 into bar4"
103 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo1 0 0 128K" $SCRATCH_MNT/bar4 \
106 echo "File bar4 digest = $(_md5_checksum $SCRATCH_MNT/bar4)"
108 # File bar5 has a 1Mb prealloc extent at file offset 0 and a file size of 0.
109 echo "Creating file bar5"
110 $XFS_IO_PROG -f -c "falloc -k 0 1M" $SCRATCH_MNT/bar5
112 echo "Cloning foo1 into bar5"
113 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo1 0 0 128K" $SCRATCH_MNT/bar5 \
116 echo "File bar5 digest = $(_md5_checksum $SCRATCH_MNT/bar5)"
118 # File bar6 has an inline extent encoding 500 bytes of data followed by a
119 # prealloc extent of 1Mb at file offset 4K. The file size is 500 bytes.
120 echo "Creating file bar6"
121 $XFS_IO_PROG -f -c "pwrite -S 0xef 0 500" \
122 -c "falloc -k 4K 1M" \
123 $SCRATCH_MNT/bar6 | _filter_xfs_io
125 echo "Cloning foo1 into bar6"
126 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo1 0 0 128K" $SCRATCH_MNT/bar6 \
129 echo "File bar6 digest = $(_md5_checksum $SCRATCH_MNT/bar6)"
131 # Unmount and mount again the filesystem. We want to verify the reflink
132 # operations were durably persisted.
135 echo "File digests after mounting again the filesystem:"
136 echo "File bar1 digest = $(_md5_checksum $SCRATCH_MNT/bar1)"
137 echo "File bar2 digest = $(_md5_checksum $SCRATCH_MNT/bar2)"
138 echo "File bar3 digest = $(_md5_checksum $SCRATCH_MNT/bar3)"
139 echo "File bar4 digest = $(_md5_checksum $SCRATCH_MNT/bar4)"
140 echo "File bar5 digest = $(_md5_checksum $SCRATCH_MNT/bar5)"
141 echo "File bar6 digest = $(_md5_checksum $SCRATCH_MNT/bar6)"
144 _scratch_mkfs "-O ^no-holes" >>$seqres.full 2>&1
148 echo "Testing with defaults"
153 echo "Testing with -o compress"
155 _scratch_cycle_mount "compress"
159 echo "Testing with -o nodatacow"
161 _scratch_cycle_mount "nodatacow"
165 echo "Testing with -O no-holes"
168 _scratch_mkfs "-O no-holes" >>$seqres.full 2>&1