btrfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / btrfs / 110
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/110
6 #
7 # Test that sending and receiving snapshots across different filesystems works
8 # for full and incremental send operations.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -fr $send_files_dir
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_fs btrfs
31 _supported_os Linux
32 _require_scratch
33
34 send_files_dir=$TEST_DIR/btrfs-test-$seq
35
36 rm -f $seqres.full
37 rm -fr $send_files_dir
38 mkdir $send_files_dir
39
40 _scratch_mkfs >>$seqres.full 2>&1
41 _scratch_mount
42
43 # Create a test file
44 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 32K" $SCRATCH_MNT/foo | _filter_xfs_io
45
46 # Create the first snapshot.
47 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap1
48
49 echo "File digest in the first filesystem, first snapshot:"
50 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
51
52 # Save send stream for this snapshot.
53 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/snap1
54
55 # Create a new filesystem and receive the snapshot.
56 _scratch_unmount
57 _scratch_mkfs >>$seqres.full 2>&1
58 _scratch_mount
59
60 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
61
62 echo "File digest in the second filesystem, first snapshot:"
63 # Must match the digest we got in the first filesystem.
64 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
65
66 # Snapshot the first snapshot as rw, modify this new snapshot and then snapshot
67 # it as RO to use in a send operation (send requires RO snapshots).
68 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT/snap1 $SCRATCH_MNT/snap2_rw
69
70 $XFS_IO_PROG -c "pwrite -S 0xbb 4K 4K" \
71         $SCRATCH_MNT/snap2_rw/foo | _filter_xfs_io
72
73 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT/snap2_rw \
74         $SCRATCH_MNT/snap2
75
76 echo "File digest in the second filesystem, second snapshot:"
77 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
78
79 _run_btrfs_util_prog send -p $SCRATCH_MNT/snap1 -f $send_files_dir/2.snap \
80         $SCRATCH_MNT/snap2
81
82 # Create a new filesystem and receive both the first snapshot, through the first
83 # send stream we created, and the second snapshot through the incremental send
84 # stream we just created. Verify this works and the file data is correct in both
85 # snapshots.
86 _scratch_unmount
87 _scratch_mkfs >>$seqres.full 2>&1
88 _scratch_mount
89
90 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
91 # Receiving the second snapshot used to fail because the send stream used an
92 # incorrect value for the clone sources uuid field - it used the uuid of
93 # snapshot 1, which is different on each filesystem, instead of the received
94 # uuid value, which is preserved across different filesystems.
95 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
96
97 echo "File digests in the third filesystem:"
98 # Must match the digests we got in the previous filesystems.
99 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
100 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
101
102 status=0
103 exit