btrfs/139: require 2GB scratch dev
[xfstests-dev.git] / tests / btrfs / 111
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/111
6 #
7 # Test that resending snapshots from a different filesystem is possible for
8 # both 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 # Modify our file and create the second snapshot, used later for an incremental
50 # send operation.
51 $XFS_IO_PROG -c "pwrite -S 0xbb 4K 4K" $SCRATCH_MNT/foo | _filter_xfs_io
52
53 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap2
54
55 echo "File digests in the first filesystem:"
56 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
57 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
58
59 # Save send streams for the snapshots. For the first one we use a full send
60 # operation and the for the second snapshot we use an incremental send.
61 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/snap1
62 _run_btrfs_util_prog send -p $SCRATCH_MNT/snap1 -f $send_files_dir/2.snap \
63         $SCRATCH_MNT/snap2
64
65 # Create a new filesystem and receive the snapshots.
66 _scratch_unmount
67 _scratch_mkfs >>$seqres.full 2>&1
68 _scratch_mount
69
70 _run_btrfs_util_prog receive -vv -f $send_files_dir/1.snap $SCRATCH_MNT
71 _run_btrfs_util_prog receive -vv -f $send_files_dir/2.snap $SCRATCH_MNT
72
73 echo "File digests in the second filesystem:"
74 # Must match the digests we got in the first filesystem.
75 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
76 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
77
78 # Call sync to flush all delalloc data that the receiver processes created.
79 # Although 'btrfs receive' at the end calls a btrfs specific ioctl to change
80 # the snapshot from RW mode to RO mode, which commits the current btrfs
81 # transaction, the dealalloc data is not flushed, as the transaction commit
82 # intentionally does not do it unless the fs is mounted with '-o flushoncommit'.
83 # This is a detail that should probably be addressed either in the btrfs ioctls
84 # called by 'btrfs receive' or in the tools - our test has a different purpose,
85 # so we get around this by calling 'sync' to make sure all delalloc data is
86 # durably persisted and the respective file extent items are added to the
87 # snapshot's btree.
88 sync
89
90 # Now create send streams for the snapshots from this new filesystem. For the
91 # first snapshot we do a full send while for the second snapshot we do an
92 # incremental send.
93 _run_btrfs_util_prog send -f $send_files_dir/1_2.snap $SCRATCH_MNT/snap1
94 _run_btrfs_util_prog send -p $SCRATCH_MNT/snap1 -f $send_files_dir/2_2.snap \
95         $SCRATCH_MNT/snap2
96
97 # Create a new filesystem and receive the send streams we just created from the
98 # second filesystem. This worked until the linux kernel 4.2, where a regression
99 # was introduced. The problem was that the send stream included an incorrect
100 # value for the uuid field, which matched a snapshot's uuid (which is different
101 # on each filesystem) instead of the snapshot's received_uuid value (which is
102 # preserved across different filesystems).
103 _scratch_unmount
104 _scratch_mkfs >>$seqres.full 2>&1
105 _scratch_mount
106
107 _run_btrfs_util_prog receive -vv -f $send_files_dir/1_2.snap $SCRATCH_MNT
108 _run_btrfs_util_prog receive -vv -f $send_files_dir/2_2.snap $SCRATCH_MNT
109
110 echo "File digests in the third filesystem:"
111 # Must match the digests we got in the first and second filesystems.
112 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
113 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
114
115 status=0
116 exit