2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 Synology Inc. All Rights Reserved.
5 # FS QA Test No. btrfs/134
7 # Test that an incremental send operation works after moving a directory into
8 # a new parent directory, deleting its previous parent directory and creating
9 # a new inode that has the same inode number as the old parent.
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
22 rm -fr $send_files_dir
26 # get standard environment, filters and checks
30 # 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/dir257
47 mkdir $SCRATCH_MNT/dir258
48 mkdir $SCRATCH_MNT/dir259
49 mv $SCRATCH_MNT/dir257 $SCRATCH_MNT/dir258/dir257
51 # Filesystem looks like:
54 # |--- dir258/ (ino 258, gen 7)
55 # | |--- dir257/ (ino 257, gen 7)
57 # |--- dir259/ (ino 259, gen 7)
59 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
60 $SCRATCH_MNT/mysnap1 > /dev/null
62 mv $SCRATCH_MNT/dir258/dir257 $SCRATCH_MNT/dir257
63 rmdir $SCRATCH_MNT/dir258
64 rmdir $SCRATCH_MNT/dir259
65 # Remount the filesystem so that the next created inodes will have the numbers
66 # 258 and 259. This is because when a filesystem is mounted, btrfs sets the
67 # subvolume's inode counter to a value corresponding to the highest inode number
68 # in the subvolume plus 1. This inode counter is used to assign a unique number
69 # to each new inode and it's incremented by 1 after very inode creation.
70 # Note: we unmount and then mount instead of doing a mount with "-o remount"
71 # because otherwise the inode counter remains at value 260.
73 touch $SCRATCH_MNT/file258
74 mkdir $SCRATCH_MNT/new_dir259
75 mv $SCRATCH_MNT/dir257 $SCRATCH_MNT/new_dir259/dir257
77 # Filesystem now looks like:
80 # |--- file258 (ino 258, gen 10)
82 # |--- new_dir259/ (ino 259, gen 10)
83 # |--- dir257/ (ino 257, gen 7)
85 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
86 $SCRATCH_MNT/mysnap2 > /dev/null
88 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
89 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
90 -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
92 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
93 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
94 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
95 $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
97 # Now recreate the filesystem by receiving both send streams and verify we get
98 # the same content that the original filesystem had.
100 _scratch_mkfs >>$seqres.full 2>&1
103 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
104 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
105 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
106 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2