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
35 send_files_dir=$TEST_DIR/btrfs-test-$seq
38 rm -fr $send_files_dir
41 _scratch_mkfs >>$seqres.full 2>&1
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
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
51 echo "File digest before being replaced:"
52 md5sum $SCRATCH_MNT/mysnap1/foo/bar | _filter_scratch
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
70 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT/mysnap2 \
71 $SCRATCH_MNT/mysnap2_ro
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
77 echo "File digest in the original filesystem after being replaced:"
78 md5sum $SCRATCH_MNT/mysnap2_ro/foo/bar | _filter_scratch
80 # Now recreate the filesystem by receiving both send streams and verify we get
81 # the same file contents that the original filesystem had.
83 _scratch_mkfs >>$seqres.full 2>&1
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
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