btrfs/079: fix failure to umount scratch fs due to running filefrag process
[xfstests-dev.git] / tests / btrfs / 044
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/044
6 #
7 # Regression test for a btrfs incremental send issue where under certain
8 # scenarios invalid paths for utimes, chown and chmod operations were sent
9 # to the send stream, causing btrfs receive to fail.
10 #
11 # If a directory had a move/rename operation delayed, and none of its parent
12 # directories, except for the immediate one, had delayed move/rename operations,
13 # after processing the directory's references, the incremental send code would
14 # issue invalid paths for utimes, chown and chmod operations.
15 #
16 # This issue is fixed by the following linux kernel btrfs patch:
17 #
18 #   Btrfs: fix send issuing outdated paths for utimes, chown and chmod
19 #
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 tmp=`mktemp -d`
25 status=1        # failure is the default!
26 trap "_cleanup; exit \$status" 0 1 2 3 15
27
28 _cleanup()
29 {
30     rm -fr $tmp
31 }
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36
37 # real QA test starts here
38 _supported_fs btrfs
39 _supported_os Linux
40 _require_scratch
41 _require_fssum
42
43 rm -f $seqres.full
44
45 _scratch_mkfs >/dev/null 2>&1
46 _scratch_mount
47
48 umask 0
49 mkdir -p $SCRATCH_MNT/a/b/c/d/e
50 mkdir $SCRATCH_MNT/a/b/c/f
51 echo 'ola ' > $SCRATCH_MNT/a/b/c/d/e/file.txt
52 chmod 0777 $SCRATCH_MNT/a/b/c/d/e
53
54 # Filesystem looks like:
55 #
56 # .                                   (ino 256)
57 # |-- a/                              (ino 257)
58 #     |-- b/                          (ino 258)
59 #         |-- c/                      (ino 259)
60 #             |-- d/                  (ino 260)
61 #             |   |-- e/              (ino 261)
62 #             |       |-- file.txt    (ino 262)
63 #             |
64 #             |-- f/                  (ino 263)
65
66 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
67
68 echo 'mundo' >> $SCRATCH_MNT/a/b/c/d/e/file.txt
69 mv $SCRATCH_MNT/a/b/c/d/e/file.txt $SCRATCH_MNT/a/b/c/d/e/file2.txt
70 mv $SCRATCH_MNT/a/b/c/f $SCRATCH_MNT/a/b/f2
71 mv $SCRATCH_MNT/a/b/c/d/e $SCRATCH_MNT/a/b/f2/e2
72 mv $SCRATCH_MNT/a/b/c $SCRATCH_MNT/a/b/c2
73 mv $SCRATCH_MNT/a/b/c2/d $SCRATCH_MNT/a/b/c2/d2
74 chmod 0700 $SCRATCH_MNT/a/b/f2/e2
75
76 # Filesystem now looks like:
77 #
78 # .                              (ino 256)
79 # |-- a/                         (ino 257)
80 #     |-- b/                     (ino 258)
81 #         |-- c2/                (ino 259)
82 #         |   |-- d2/            (ino 260)
83 #         |
84 #         |-- f2/                (ino 263)
85 #             |-- e2             (ino 261)
86 #                 |-- file2.txt  (ino 263)
87
88 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
89
90 run_check $FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
91 run_check $FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
92         $SCRATCH_MNT/mysnap2
93
94 _run_btrfs_util_prog send -f $tmp/1.snap $SCRATCH_MNT/mysnap1
95 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $tmp/2.snap \
96         $SCRATCH_MNT/mysnap2
97
98 _check_scratch_fs
99
100 _scratch_unmount
101 _scratch_mkfs >/dev/null 2>&1
102 _scratch_mount
103
104 _run_btrfs_util_prog receive -f $tmp/1.snap $SCRATCH_MNT
105 run_check $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1
106
107 _run_btrfs_util_prog receive -f $tmp/2.snap $SCRATCH_MNT
108 run_check $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2
109
110 status=0
111 exit