btrfs/149: make it sectorsize independent
[xfstests-dev.git] / tests / btrfs / 149
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/149
6 #
7 # Test that an incremental send/receive operation will not fail when the
8 # destination filesystem has compression enabled and the source filesystem
9 # has an extent at a file offset 0 that is not compressed and that is
10 # shared.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -fr $send_files_dir
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/reflink
31
32 # real QA test starts here
33 _supported_fs btrfs
34 _supported_os Linux
35 _require_test
36 _require_scratch
37 _require_scratch_reflink
38 _require_odirect
39 _require_btrfs_command inspect-internal dump-super
40
41 send_files_dir=$TEST_DIR/btrfs-test-$seq
42
43 rm -f $seqres.full
44 rm -fr $send_files_dir
45 mkdir $send_files_dir
46
47 _scratch_mkfs >>$seqres.full 2>&1
48 # On 64K pagesize systems the compression is more efficient, so max_inline
49 # helps to create regular (non inline) extent irrespective of the final
50 # write size.
51 _scratch_mount "-o compress -o max_inline=0"
52
53 # Write to our file using direct IO, so that this way the write ends up not
54 # getting compressed, that is, we get a regular extent which is neither
55 # inlined nor compressed.
56 # Alternatively, we could have mounted the fs without compression enabled,
57 # which would result as well in an uncompressed regular extent.
58 sectorsize=$(_scratch_btrfs_sectorsize)
59 $XFS_IO_PROG -f -d -c "pwrite -S 0xab 0 $sectorsize" $SCRATCH_MNT/foobar |\
60         _filter_xfs_io_numbers
61
62 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
63         $SCRATCH_MNT/mysnap1 > /dev/null
64
65 # Clone the regular (not inlined) extent.
66 $XFS_IO_PROG -c \
67         "reflink $SCRATCH_MNT/foobar 0 $((2 * $sectorsize)) $sectorsize" \
68         $SCRATCH_MNT/foobar | _filter_xfs_io_numbers
69
70 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
71         $SCRATCH_MNT/mysnap2 > /dev/null
72
73 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
74                  $SCRATCH_MNT/mysnap1 2>&1 >/dev/null | _filter_scratch
75
76 # Now do an incremental send of the second snapshot. The send stream can have
77 # a clone operation to clone the extent at offset 0 to offset (2 x sectorsize).
78 # This operation would fail on the receiver if it has compression enabled, since
79 # the write operation of the extent at offset 0 was compressed because it was a
80 # buffered write operation, and btrfs' clone implementation does not allow
81 # cloning inline extents to offsets different from 0.
82 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
83                  $SCRATCH_MNT/mysnap2 2>&1 >/dev/null | _filter_scratch
84
85 sum_src_snap1=$(md5sum $SCRATCH_MNT/mysnap1/foobar | awk '{print $1}')
86 sum_src_snap2=$(md5sum $SCRATCH_MNT/mysnap2/foobar | awk '{print $1}')
87 echo "File digests in the original filesystem:" >> $seqres.full
88 echo "md5sum $SCRATCH_MNT/mysnap1/foobar " $sum_src_snap1 >> $seqres.full
89 echo "md5sum $SCRATCH_MNT/mysnap2/foobar " $sum_src_snap2 >> $seqres.full
90
91 # Now recreate the filesystem by receiving both send streams and verify we get
92 # the same file content that the original filesystem had.
93 _scratch_unmount
94 _scratch_mkfs >>$seqres.full 2>&1
95 _scratch_mount "-o compress"
96
97 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
98 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
99
100 sum_dest_snap1=$(md5sum $SCRATCH_MNT/mysnap1/foobar | awk '{print $1}')
101 sum_dest_snap2=$(md5sum $SCRATCH_MNT/mysnap2/foobar | awk '{print $1}')
102 echo "File digests in the new filesystem:" | tee -a $seqres.full
103 echo "md5sum $SCRATCH_MNT/mysnap1/foobar " $sum_src_snap1 >> $seqres.full
104 echo "md5sum $SCRATCH_MNT/mysnap2/foobar " $sum_src_snap2 >> $seqres.full
105
106 [[ $sum_src_snap1 == $sum_dest_snap1 ]] && echo "src and dest 'mysnap1' checksum matched"
107 [[ $sum_src_snap2 == $sum_dest_snap2 ]] && echo "src and dest 'mysnap2' checksum matched"
108
109 status=0
110 exit