common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[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 _supported_os Linux
34 _require_scratch
35
36 send_files_dir=$TEST_DIR/btrfs-test-$seq
37
38 rm -f $seqres.full
39 rm -fr $send_files_dir
40 mkdir $send_files_dir
41
42 _scratch_mkfs >>$seqres.full 2>&1
43 _scratch_mount
44
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
48
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
51
52 echo "File digest before being replaced:"
53 md5sum $SCRATCH_MNT/mysnap1/foo/bar | _filter_scratch
54
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
70
71 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT/mysnap2 \
72         $SCRATCH_MNT/mysnap2_ro
73
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
77
78 echo "File digest in the original filesystem after being replaced:"
79 md5sum $SCRATCH_MNT/mysnap2_ro/foo/bar | _filter_scratch
80
81 # Now recreate the filesystem by receiving both send streams and verify we get
82 # the same file contents that the original filesystem had.
83 _scratch_unmount
84 _scratch_mkfs >>$seqres.full 2>&1
85 _scratch_mount
86
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
89
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
93
94 status=0
95 exit