generic/563: use a loop device to avoid partition incompatibility
[xfstests-dev.git] / tests / btrfs / 105
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 # Copyright (C) 2015 Martin Raiber <martin@urbackup.org>
5 #
6 # FS QA Test No. btrfs/105
7 #
8 # Test that an incremental send works after a file from the parent snapshot
9 # gets replaced in the send snapshot by another one at the same exact location,
10 # with the same name and with the same inode number.
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
31 # real QA test starts here
32 _supported_fs btrfs
33 _require_scratch
34
35 send_files_dir=$TEST_DIR/btrfs-test-$seq
36
37 rm -f $seqres.full
38 rm -fr $send_files_dir
39 mkdir $send_files_dir
40
41 _scratch_mkfs >>$seqres.full 2>&1
42 _scratch_mount
43
44 # Create our test file with a single extent of 64K.
45 mkdir -p $SCRATCH_MNT/foo
46 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K" $SCRATCH_MNT/foo/bar | _filter_xfs_io
47
48 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
49 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/mysnap2
50
51 echo "File digest before being replaced:"
52 md5sum $SCRATCH_MNT/mysnap1/foo/bar | _filter_scratch
53
54 # Remove the file and then create a new one in the same location with the same
55 # name but with different content. This new file ends up getting the same inode
56 # number as the previous one, because that inode number was the highest inode
57 # number used by the snapshot's root and therefore when attempting to find the
58 # a new inode number for the new file, we end up reusing the same inode number.
59 # This happens because currently btrfs uses the highest inode number summed by 1
60 # for the first inode created once a snapshot's root is loaded (done at
61 # fs/btrfs/inode-map.c:btrfs_find_free_objectid in the linux kernel tree).
62 # Having these two different files in the snapshots with the same inode number
63 # (but different generation numbers) caused the btrfs send code to emit an
64 # incorrect path for the file when issuing an unlink operation because it failed
65 # to realize they were different files.
66 rm -f $SCRATCH_MNT/mysnap2/foo/bar
67 $XFS_IO_PROG -f -c "pwrite -S 0xbb 0 96K" \
68         $SCRATCH_MNT/mysnap2/foo/bar | _filter_xfs_io
69
70 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT/mysnap2 \
71         $SCRATCH_MNT/mysnap2_ro
72
73 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
74 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
75         $SCRATCH_MNT/mysnap2_ro
76
77 echo "File digest in the original filesystem after being replaced:"
78 md5sum $SCRATCH_MNT/mysnap2_ro/foo/bar | _filter_scratch
79
80 # Now recreate the filesystem by receiving both send streams and verify we get
81 # the same file contents that the original filesystem had.
82 _scratch_unmount
83 _scratch_mkfs >>$seqres.full 2>&1
84 _scratch_mount
85
86 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
87 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
88
89 echo "File digest in the new filesystem:"
90 # Must match the digest from the new file.
91 md5sum $SCRATCH_MNT/mysnap2_ro/foo/bar | _filter_scratch
92
93 status=0
94 exit