2 # FS QA Test No. btrfs/056
4 # Regression test for btrfs ioctl clone operation + fsync + log recovery.
5 # The issue was that doing an fsync after cloning into a file didn't gave any
6 # persistence guarantees as it should. What happened was that the in memory
7 # metadata (extent maps) weren't updated, which made the fsync code not able
8 # to detect that file data has been changed.
10 # This issue is fixed by the following linux kernel btrfs patch:
12 # Btrfs: make fsync work after cloning into a file
14 #-----------------------------------------------------------------------
15 # Copyright (c) 2014 Filipe Manana. All Rights Reserved.
17 # This program is free software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License as
19 # published by the Free Software Foundation.
21 # This program is distributed in the hope that it would be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write the Free Software Foundation,
28 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #-----------------------------------------------------------------------
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
37 status=1 # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
46 # get standard environment, filters and checks
51 # real QA test starts here
56 _require_btrfs_fs_feature "no_holes"
57 _require_btrfs_mkfs_feature "no-holes"
58 _require_dm_target flakey
63 test_btrfs_clone_fsync_log_recover()
65 _scratch_mkfs "$1" >/dev/null 2>&1
67 SAVE_MOUNT_OPTIONS="$MOUNT_OPTIONS"
68 MOUNT_OPTIONS="$MOUNT_OPTIONS $2"
71 BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
73 EXTENT_SIZE=$((2 * $BLOCK_SIZE))
75 # Create a file with 4 extents and 1 hole, all with a size of
77 # The hole is in the block range [4, 5].
78 $XFS_IO_PROG -s -f -c "pwrite -S 0x01 -b $EXTENT_SIZE 0 $EXTENT_SIZE" \
79 -c "pwrite -S 0x02 -b $EXTENT_SIZE $((2 * $BLOCK_SIZE)) $EXTENT_SIZE" \
80 -c "pwrite -S 0x04 -b $EXTENT_SIZE $((6 * $BLOCK_SIZE)) $EXTENT_SIZE" \
81 -c "pwrite -S 0x05 -b $EXTENT_SIZE $((8 * $BLOCK_SIZE)) $EXTENT_SIZE" \
82 $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
84 # Clone destination file, 1 extent of 24 blocks.
85 $XFS_IO_PROG -f -c "pwrite -S 0xff -b $((24 * $BLOCK_SIZE)) 0 $((24 * $BLOCK_SIZE))" \
86 -c "fsync" $SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
88 # Clone second half of the 2nd extent, the 2 block hole, the 3rd extent
89 # and the first half of the 4th extent into file bar.
90 $CLONER_PROG -s $((3 * $BLOCK_SIZE)) -d 0 -l $((6 * $BLOCK_SIZE)) \
91 $SCRATCH_MNT/foo $SCRATCH_MNT/bar
92 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
94 # Test small files too consisting of 1 inline extent
95 EXTENT_SIZE=$(($BLOCK_SIZE - 48))
96 $XFS_IO_PROG -f -c "pwrite -S 0x00 -b $EXTENT_SIZE 0 $EXTENT_SIZE" -c "fsync" \
97 $SCRATCH_MNT/foo2 | _filter_xfs_io_blocks_modified
99 EXTENT_SIZE=$(($BLOCK_SIZE - 1048))
100 $XFS_IO_PROG -f -c "pwrite -S 0xcc -b $EXTENT_SIZE 0 $EXTENT_SIZE" -c "fsync" \
101 $SCRATCH_MNT/bar2 | _filter_xfs_io_blocks_modified
103 # Clone the entire foo2 file into bar2, overwriting all data in bar2
104 # and increasing its size.
105 EXTENT_SIZE=$(($BLOCK_SIZE - 48))
106 $CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo2 $SCRATCH_MNT/bar2
107 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar2
109 _flakey_drop_and_remount yes
111 # Verify the cloned range was persisted by fsync and the log recovery
112 # code did its work well.
113 echo "Verifying file bar content"
114 od -t x1 $SCRATCH_MNT/bar | _filter_od
116 echo "Verifying file bar2 content"
117 od -t x1 $SCRATCH_MNT/bar2 | _filter_od
121 # Verify that there are no consistency errors.
122 _check_scratch_fs $FLAKEY_DEV
125 MOUNT_OPTIONS="$SAVE_MOUNT_OPTIONS"
128 # Regardless of the NO_HOLES feature being enabled or not, the test results
129 # should be exactly the same for both cases.
131 echo "Testing without the NO_HOLES feature"
132 # As of btrfs-progs 3.14.x, the no-holes feature isn't enabled by default.
133 # But explicitly disable it at mkfs time as it might be enabled by default
134 # in future versions.
135 test_btrfs_clone_fsync_log_recover "-O ^no-holes"
137 echo "Testing without the NO_HOLES feature and compression (lzo)"
138 test_btrfs_clone_fsync_log_recover "-O ^no-holes" "-o compress-force=lzo"
140 echo "Testing with the NO_HOLES feature enabled"
141 test_btrfs_clone_fsync_log_recover "-O no-holes"
143 echo "Testing with the NO_HOLES feature enabled and compression (lzo)"
144 test_btrfs_clone_fsync_log_recover "-O no-holes" "-o compress-force=lzo"