fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / btrfs / 200
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 200
6 #
7 # Check that send operations (full and incremental) are able to issue clone
8 # operations for extents that are shared between the same file.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         cd /
20         rm -f $tmp.*
21         rm -fr $send_files_dir
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/reflink
28 . ./common/punch
29
30 # real QA test starts here
31 _supported_fs btrfs
32 _require_fssum
33 _require_test
34 _require_scratch_reflink
35 _require_xfs_io_command "fiemap"
36
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
38
39 rm -f $seqres.full
40 rm -fr $send_files_dir
41 mkdir $send_files_dir
42
43 _scratch_mkfs >>$seqres.full 2>&1
44 _scratch_mount
45
46 # Create our first test file, which has an extent that is shared only with
47 # itself and no other files. We want to verify a full send operation will
48 # clone the extent.
49 $XFS_IO_PROG -f -c "pwrite -S 0xb1 -b 64K 0 64K" $SCRATCH_MNT/foo \
50         | _filter_xfs_io
51 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo 0 64K 64K" $SCRATCH_MNT/foo \
52         | _filter_xfs_io
53
54 # Create out second test file which initially, for the first send operation,
55 # only has a single extent that is not shared.
56 $XFS_IO_PROG -f -c "pwrite -S 0xc7 -b 64K 0 64K" $SCRATCH_MNT/bar \
57         | _filter_xfs_io
58
59 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
60         | _filter_scratch
61
62 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
63         | _filter_scratch
64
65 # Now clone the existing extent in file bar to itself at a different offset.
66 # We want to verify the incremental send operation below will issue a clone
67 # operation instead of a write operation.
68 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/bar 0 64K 64K" $SCRATCH_MNT/bar \
69         | _filter_xfs_io
70
71 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
72         | _filter_scratch
73
74 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
75         $SCRATCH_MNT/incr 2>&1 | _filter_scratch
76
77 # Compute digests of the snapshot trees so that later we can compare against
78 # digests of the trees in the new filesystem, to see if they match (no data or
79 # metadata corruption happened).
80 $FSSUM_PROG -A -f -w $send_files_dir/base.fssum $SCRATCH_MNT/base
81 $FSSUM_PROG -A -f -w $send_files_dir/incr.fssum \
82         -x $SCRATCH_MNT/incr/base $SCRATCH_MNT/incr
83
84 # Now recreate the filesystem by receiving both send streams and verify we get
85 # the same file contents that the original filesystem had and that files foo
86 # and bar have shared extents.
87 _scratch_unmount
88 _scratch_mkfs >>$seqres.full 2>&1
89 _scratch_mount
90
91 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
92 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
93
94 # Compute digests of the snapshot trees in the new filesystem and compare them
95 # to the ones in the original filesystem, they must match.
96 $FSSUM_PROG -r $send_files_dir/base.fssum $SCRATCH_MNT/base
97 $FSSUM_PROG -r $send_files_dir/incr.fssum $SCRATCH_MNT/incr
98
99 num_extents=$(_count_extents $SCRATCH_MNT/base/foo)
100 num_exclusive_extents=$(_count_exclusive_extents $SCRATCH_MNT/base/foo)
101 if [ $num_extents -ne 2 ] || [ $num_exclusive_extents -ne 1 ]; then
102         echo "File foo does not have 2 shared extents in the base snapshot"
103         $XFS_IO_PROG -r -c "fiemap" $SCRATCH_MNT/base/foo
104 fi
105
106 num_extents=$(_count_extents $SCRATCH_MNT/incr/foo)
107 num_exclusive_extents=$(_count_exclusive_extents $SCRATCH_MNT/incr/foo)
108 if [ $num_extents -ne 2 ] || [ $num_exclusive_extents -ne 1 ]; then
109         echo "File foo does not have 2 shared extents in the incr snapshot"
110         $XFS_IO_PROG -r -c "fiemap" $SCRATCH_MNT/incr/foo
111 fi
112
113 num_extents=$(_count_extents $SCRATCH_MNT/incr/bar)
114 num_exclusive_extents=$(_count_exclusive_extents $SCRATCH_MNT/incr/bar)
115 if [ $num_extents -ne 2 ] || [ $num_exclusive_extents -ne 1 ]; then
116         echo "File bar does not have 2 shared extents in the incr snapshot"
117         $XFS_IO_PROG -r -c "fiemap" $SCRATCH_MNT/incr/bar
118 fi
119
120 status=0
121 exit