2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/227
7 # Test that an incremental send operation succeeds, and produces the correct
8 # results, after removing a directory and all its files, unmounting the
9 # filesystem, mounting the filesystem again and creating a new file (or
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
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
40 rm -fr $send_files_dir
43 _scratch_mkfs >>$seqres.full 2>&1
46 mkdir $SCRATCH_MNT/dir
47 touch $SCRATCH_MNT/dir/file1
48 touch $SCRATCH_MNT/dir/file2
49 touch $SCRATCH_MNT/dir/file3
51 # Filesystem looks like:
54 # |----- dir/ (ino 257)
55 # |----- file1 (ino 258)
56 # |----- file2 (ino 259)
57 # |----- file3 (ino 260)
60 # Now create the base snapshot, which is going to be the parent snapshot for
61 # a later incremental send.
62 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
63 $SCRATCH_MNT/mysnap1 > /dev/null
65 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
66 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
68 # Now remove our directory and all its files.
69 rm -fr $SCRATCH_MNT/dir
71 # Unmount the filesystem and mount it again. This is to ensure that the next
72 # inode that is created ends up with the same inode number that our directory
73 # "dir" had, 257, which is the first free "objectid" available after mounting
74 # again the filesystem.
77 # Now create a new file (it could be a directory as well).
78 touch $SCRATCH_MNT/newfile
80 # Filesystem now looks like:
83 # |----- newfile (ino 257)
86 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
87 $SCRATCH_MNT/mysnap2 > /dev/null
88 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
89 $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
91 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
92 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
93 -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
95 # Now recreate the filesystem by receiving both send streams and verify we get
96 # the same content that the original filesystem had.
98 _scratch_mkfs >>$seqres.full 2>&1
101 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
103 # The receive operation below used to fail with the following error:
105 # ERROR: chown o257-9-0 failed: No such file or directory
107 # This is because when the kernel was processing old inode 257 (the directory),
108 # it had to delay its removal because its children inodes, "file1", "file2" and
109 # "file3", have higher inode numbers and will be processed (and unlinked) later.
110 # Then when it processed the new inode 257 (named "newfile"), it got confused
111 # and though that this inode was the one with a delayed removal and therefore
112 # generate an orphan name for it ("o257-9-0") instead of its current name of
113 # "newfile", causing the receiver to fail since there is no file with that
116 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
118 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
119 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2