fstests: move test group info to test files
[xfstests-dev.git] / tests / btrfs / 056
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/056
6 #
7 # Regression test for btrfs ioctl clone operation + fsync + log recovery.
8 # The issue was that doing an fsync after cloning into a file didn't gave any
9 # persistence guarantees as it should. What happened was that the in memory
10 # metadata (extent maps) weren't updated, which made the fsync code not able
11 # to detect that file data has been changed.
12 #
13 # This issue is fixed by the following linux kernel btrfs patch:
14 #
15 #    Btrfs: make fsync work after cloning into a file
16 #
17 . ./common/preamble
18 _begin_fstest auto quick clone log
19
20 # Override the default cleanup function.
21 _cleanup()
22 {
23         _cleanup_flakey
24         rm -fr $tmp
25 }
26
27 # Import common functions.
28 . ./common/filter
29 . ./common/dmflakey
30
31 # real QA test starts here
32 _supported_fs btrfs
33 _require_scratch
34 _require_cloner
35 _require_btrfs_fs_feature "no_holes"
36 _require_btrfs_mkfs_feature "no-holes"
37 _require_dm_target flakey
38
39 test_btrfs_clone_fsync_log_recover()
40 {
41         _scratch_mkfs "$1" >/dev/null 2>&1
42         _init_flakey
43         SAVE_MOUNT_OPTIONS="$MOUNT_OPTIONS"
44         MOUNT_OPTIONS="$MOUNT_OPTIONS $2"
45         _mount_flakey
46
47         BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
48
49         EXTENT_SIZE=$((2 * $BLOCK_SIZE))
50
51         # Create a file with 4 extents and 1 hole, all with a size of
52         # 2 blocks each.
53         # The hole is in the block range [4, 5].
54         $XFS_IO_PROG -s -f -c "pwrite -S 0x01 -b $EXTENT_SIZE 0 $EXTENT_SIZE" \
55                         -c "pwrite -S 0x02 -b $EXTENT_SIZE $((2 * $BLOCK_SIZE)) $EXTENT_SIZE" \
56                         -c "pwrite -S 0x04 -b $EXTENT_SIZE $((6 * $BLOCK_SIZE)) $EXTENT_SIZE" \
57                         -c "pwrite -S 0x05 -b $EXTENT_SIZE $((8 * $BLOCK_SIZE)) $EXTENT_SIZE" \
58                 $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
59
60         # Clone destination file, 1 extent of 24 blocks.
61         $XFS_IO_PROG -f -c "pwrite -S 0xff -b $((24 * $BLOCK_SIZE)) 0 $((24 * $BLOCK_SIZE))" \
62                      -c "fsync" $SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
63
64         # Clone second half of the 2nd extent, the 2 block hole, the 3rd extent
65         # and the first half of the 4th extent into file bar.
66         $CLONER_PROG -s $((3 * $BLOCK_SIZE)) -d 0 -l $((6 * $BLOCK_SIZE)) \
67                      $SCRATCH_MNT/foo $SCRATCH_MNT/bar
68         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
69
70         # Test small files too consisting of 1 inline extent
71         EXTENT_SIZE=$(($BLOCK_SIZE - 48))
72         $XFS_IO_PROG -f -c "pwrite -S 0x00 -b $EXTENT_SIZE 0 $EXTENT_SIZE" -c "fsync" \
73                 $SCRATCH_MNT/foo2 | _filter_xfs_io_blocks_modified
74
75         EXTENT_SIZE=$(($BLOCK_SIZE - 1048))
76         $XFS_IO_PROG -f -c "pwrite -S 0xcc -b $EXTENT_SIZE 0 $EXTENT_SIZE" -c "fsync" \
77                 $SCRATCH_MNT/bar2 | _filter_xfs_io_blocks_modified
78
79         # Clone the entire foo2 file into bar2, overwriting all data in bar2
80         # and increasing its size.
81         EXTENT_SIZE=$(($BLOCK_SIZE - 48))
82         $CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo2 $SCRATCH_MNT/bar2
83         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar2
84
85         _flakey_drop_and_remount yes
86
87         # Verify the cloned range was persisted by fsync and the log recovery
88         # code did its work well.
89         echo "Verifying file bar content"
90         od -t x1 $SCRATCH_MNT/bar | _filter_od
91
92         echo "Verifying file bar2 content"
93         od -t x1 $SCRATCH_MNT/bar2 | _filter_od
94
95         _unmount_flakey
96
97         # Verify that there are no consistency errors.
98         _check_scratch_fs $FLAKEY_DEV
99
100         _cleanup_flakey
101         MOUNT_OPTIONS="$SAVE_MOUNT_OPTIONS"
102 }
103
104 # Regardless of the NO_HOLES feature being enabled or not, the test results
105 # should be exactly the same for both cases.
106
107 echo "Testing without the NO_HOLES feature"
108 # As of btrfs-progs 3.14.x, the no-holes feature isn't enabled by default.
109 # But explicitly disable it at mkfs time as it might be enabled by default
110 # in future versions.
111 test_btrfs_clone_fsync_log_recover "-O ^no-holes"
112
113 echo "Testing without the NO_HOLES feature and compression (lzo)"
114 test_btrfs_clone_fsync_log_recover "-O ^no-holes" "-o compress-force=lzo"
115
116 echo "Testing with the NO_HOLES feature enabled"
117 test_btrfs_clone_fsync_log_recover "-O no-holes"
118
119 echo "Testing with the NO_HOLES feature enabled and compression (lzo)"
120 test_btrfs_clone_fsync_log_recover "-O no-holes" "-o compress-force=lzo"
121
122 status=0
123 exit