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>
6 # FS QA Test No. btrfs/105
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.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
23 rm -fr $send_files_dir
27 # get standard environment, filters and checks
31 # real QA test starts here
36 send_files_dir=$TEST_DIR/btrfs-test-$seq
39 rm -fr $send_files_dir
42 _scratch_mkfs >>$seqres.full 2>&1
45 # Create our test file with a single extent of 64K.
46 mkdir -p $SCRATCH_MNT/foo
47 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K" $SCRATCH_MNT/foo/bar | _filter_xfs_io
49 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
50 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/mysnap2
52 echo "File digest before being replaced:"
53 md5sum $SCRATCH_MNT/mysnap1/foo/bar | _filter_scratch
55 # Remove the file and then create a new one in the same location with the same
56 # name but with different content. This new file ends up getting the same inode
57 # number as the previous one, because that inode number was the highest inode
58 # number used by the snapshot's root and therefore when attempting to find the
59 # a new inode number for the new file, we end up reusing the same inode number.
60 # This happens because currently btrfs uses the highest inode number summed by 1
61 # for the first inode created once a snapshot's root is loaded (done at
62 # fs/btrfs/inode-map.c:btrfs_find_free_objectid in the linux kernel tree).
63 # Having these two different files in the snapshots with the same inode number
64 # (but different generation numbers) caused the btrfs send code to emit an
65 # incorrect path for the file when issuing an unlink operation because it failed
66 # to realize they were different files.
67 rm -f $SCRATCH_MNT/mysnap2/foo/bar
68 $XFS_IO_PROG -f -c "pwrite -S 0xbb 0 96K" \
69 $SCRATCH_MNT/mysnap2/foo/bar | _filter_xfs_io
71 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT/mysnap2 \
72 $SCRATCH_MNT/mysnap2_ro
74 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
75 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
76 $SCRATCH_MNT/mysnap2_ro
78 echo "File digest in the original filesystem after being replaced:"
79 md5sum $SCRATCH_MNT/mysnap2_ro/foo/bar | _filter_scratch
81 # Now recreate the filesystem by receiving both send streams and verify we get
82 # the same file contents that the original filesystem had.
84 _scratch_mkfs >>$seqres.full 2>&1
87 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
88 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
90 echo "File digest in the new filesystem:"
91 # Must match the digest from the new file.
92 md5sum $SCRATCH_MNT/mysnap2_ro/foo/bar | _filter_scratch