btrfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / btrfs / 147
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/147
6 #
7 # Test that an incremental send/receive operation works correctly after moving
8 # some directory inode A, renaming a regular file inode B into the old name of
9 # inode A and finally creating a new hard link for inode B at directory inode A.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -fr $send_files_dir
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # real QA test starts here
31 _supported_fs btrfs
32 _supported_os Linux
33 _require_test
34 _require_scratch
35 _require_fssum
36
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
38
39 rm -f $seqres.full
40 rm -fr $send_files_dir
41 mkdir $send_files_dir
42
43 _scratch_mkfs >>$seqres.full 2>&1
44 _scratch_mount
45
46 mkdir $SCRATCH_MNT/dir1
47 mkdir $SCRATCH_MNT/dir1/dir2
48 mkdir $SCRATCH_MNT/dir1/dir2/dir3
49 mkdir $SCRATCH_MNT/dir5
50 touch $SCRATCH_MNT/dir1/dir2/dir3/file1
51 mkdir $SCRATCH_MNT/dir1/dir2/dir3/dir4
52
53 # Filesystem looks like:
54 #
55 # .                                                      (ino 256)
56 # |
57 # |--- dir1/                                             (ino 257)
58 # |      |--- dir2/                                      (ino 258)
59 # |             |--- dir3/                               (ino 259)
60 # |                   |--- file1                         (ino 261)
61 # |                   |--- dir4/                         (ino 262)
62 # |
63 # |--- dir5/                                             (ino 260)
64 #
65 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
66         $SCRATCH_MNT/mysnap1 > /dev/null
67
68 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
69         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
70
71 mkdir $SCRATCH_MNT/dir1/dir6
72 mv $SCRATCH_MNT/dir5 $SCRATCH_MNT/dir1/dir2/dir3/dir4/dir55
73 ln $SCRATCH_MNT/dir1/dir2/dir3/file1 $SCRATCH_MNT/dir1/dir2/dir3/dir4/file11
74 mv $SCRATCH_MNT/dir1/dir2/dir3/dir4 $SCRATCH_MNT/dir1/dir6/dir44
75 mv $SCRATCH_MNT/dir1/dir2/dir3/file1 $SCRATCH_MNT/dir1/dir2/dir3/dir4
76
77 # Filesystem now looks like:
78 #
79 # .                                                      (ino 256)
80 # |
81 # |--- dir1/                                             (ino 257)
82 #        |--- dir2/                                      (ino 258)
83 #        |      |--- dir3/                               (ino 259)
84 #        |            |--- dir4                          (ino 261)
85 #        |
86 #        |--- dir6/                                      (ino 263)
87 #               |--- dir44/                              (ino 262)
88 #                      |--- file11                       (ino 261)
89 #                      |--- dir55/                       (ino 260)
90 #
91 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
92                  $SCRATCH_MNT/mysnap2 > /dev/null
93
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
96
97 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
98 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
99         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
100
101 # Now recreate the filesystem by receiving both send streams and verify we get
102 # the same content that the original filesystem had.
103 _scratch_unmount
104 _scratch_mkfs >>$seqres.full 2>&1
105 _scratch_mount
106
107 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
108 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
109 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
110 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
111
112 status=0
113 exit