common: Check the file system consistency on SCRATCH_DEV
[xfstests-dev.git] / tests / btrfs / 044
1 #! /bin/bash
2 # FS QA Test No. btrfs/044
3 #
4 # Regression test for a btrfs incremental send issue where under certain
5 # scenarios invalid paths for utimes, chown and chmod operations were sent
6 # to the send stream, causing btrfs receive to fail.
7 #
8 # If a directory had a move/rename operation delayed, and none of its parent
9 # directories, except for the immediate one, had delayed move/rename operations,
10 # after processing the directory's references, the incremental send code would
11 # issue invalid paths for utimes, chown and chmod operations.
12 #
13 # This issue is fixed by the following linux kernel btrfs patch:
14 #
15 #   Btrfs: fix send issuing outdated paths for utimes, chown and chmod
16 #
17 #-----------------------------------------------------------------------
18 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
19 #
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of the GNU General Public License as
22 # published by the Free Software Foundation.
23 #
24 # This program is distributed in the hope that it would be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 # GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write the Free Software Foundation,
31 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
32 #-----------------------------------------------------------------------
33 #
34
35 seq=`basename $0`
36 seqres=$RESULT_DIR/$seq
37 echo "QA output created by $seq"
38
39 tmp=`mktemp -d`
40 status=1        # failure is the default!
41 trap "_cleanup; exit \$status" 0 1 2 3 15
42
43 _cleanup()
44 {
45     rm -fr $tmp
46 }
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51
52 # real QA test starts here
53 _supported_fs btrfs
54 _supported_os Linux
55 _require_scratch
56 _require_fssum
57 _need_to_be_root
58
59 rm -f $seqres.full
60
61 _scratch_mkfs >/dev/null 2>&1
62 _scratch_mount
63
64 umask 0
65 mkdir -p $SCRATCH_MNT/a/b/c/d/e
66 mkdir $SCRATCH_MNT/a/b/c/f
67 echo 'ola ' > $SCRATCH_MNT/a/b/c/d/e/file.txt
68 chmod 0777 $SCRATCH_MNT/a/b/c/d/e
69
70 # Filesystem looks like:
71 #
72 # .                                   (ino 256)
73 # |-- a/                              (ino 257)
74 #     |-- b/                          (ino 258)
75 #         |-- c/                      (ino 259)
76 #             |-- d/                  (ino 260)
77 #             |   |-- e/              (ino 261)
78 #             |       |-- file.txt    (ino 262)
79 #             |
80 #             |-- f/                  (ino 263)
81
82 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
83
84 echo 'mundo' >> $SCRATCH_MNT/a/b/c/d/e/file.txt
85 mv $SCRATCH_MNT/a/b/c/d/e/file.txt $SCRATCH_MNT/a/b/c/d/e/file2.txt
86 mv $SCRATCH_MNT/a/b/c/f $SCRATCH_MNT/a/b/f2
87 mv $SCRATCH_MNT/a/b/c/d/e $SCRATCH_MNT/a/b/f2/e2
88 mv $SCRATCH_MNT/a/b/c $SCRATCH_MNT/a/b/c2
89 mv $SCRATCH_MNT/a/b/c2/d $SCRATCH_MNT/a/b/c2/d2
90 chmod 0700 $SCRATCH_MNT/a/b/f2/e2
91
92 # Filesystem now looks like:
93 #
94 # .                              (ino 256)
95 # |-- a/                         (ino 257)
96 #     |-- b/                     (ino 258)
97 #         |-- c2/                (ino 259)
98 #         |   |-- d2/            (ino 260)
99 #         |
100 #         |-- f2/                (ino 263)
101 #             |-- e2             (ino 261)
102 #                 |-- file2.txt  (ino 263)
103
104 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
105
106 run_check $FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
107 run_check $FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
108         $SCRATCH_MNT/mysnap2
109
110 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $tmp/1.snap
111 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
112         -f $tmp/2.snap
113
114 _check_scratch_fs
115
116 _scratch_unmount
117 _scratch_mkfs >/dev/null 2>&1
118 _scratch_mount
119
120 _run_btrfs_util_prog receive $SCRATCH_MNT -f $tmp/1.snap
121 run_check $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1
122
123 _run_btrfs_util_prog receive $SCRATCH_MNT -f $tmp/2.snap
124 run_check $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2
125
126 status=0
127 exit