btrfs/079: fix failure to umount scratch fs due to running filefrag process
[xfstests-dev.git] / tests / btrfs / 128
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/128
6 #
7 # Test that, under a particular scenario, an incremental send operation does
8 # not leak memory (which used to emit a warning in dmesg/syslog).
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -fr $send_files_dir
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_fs btrfs
31 _supported_os Linux
32 _require_test
33 _require_scratch
34 _require_fssum
35
36 send_files_dir=$TEST_DIR/btrfs-test-$seq
37
38 rm -f $seqres.full
39 rm -fr $send_files_dir
40 mkdir $send_files_dir
41
42 _scratch_mkfs >>$seqres.full 2>&1
43 _scratch_mount
44
45 mkdir $SCRATCH_MNT/a
46 mkdir $SCRATCH_MNT/tmp
47 mkdir $SCRATCH_MNT/del
48 mv $SCRATCH_MNT/tmp $SCRATCH_MNT/del
49 mkdir $SCRATCH_MNT/a/c
50 mkdir $SCRATCH_MNT/del/x
51 mkdir $SCRATCH_MNT/del/y
52
53 # Filesystem looks like:
54 #
55 # .                                                             (ino 256)
56 # |--- a/                                                       (ino 257)
57 # |    |--- c/                                                  (ino 260)
58 # |
59 # |--- del/                                                     (ino 259)
60 #       |--- tmp/                                               (ino 258)
61 #       |--- x/                                                 (ino 261)
62 #       |--- y/                                                 (ino 262)
63 #
64 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
65
66 # It used to be that when attempting to issue an rmdir operation for inode 259,
67 # the kernel allocated an orphan_dir_info structure so that later after doing
68 # the delayed rename operation for inode 258 (which happened once inode 260 was
69 # renamed) it would check if it could finally issue a rmdir instruction for
70 # inode 259. If it couldn't, it would not release the previously allocated
71 # orphan_dir_info structure immediately. Instead it would only release it once
72 # it finished the send stream and it would emit a warning in dmesg/syslog.
73 #
74 mv $SCRATCH_MNT/a/c $SCRATCH_MNT
75 mv $SCRATCH_MNT/del/x $SCRATCH_MNT/a
76 mv $SCRATCH_MNT/del/y $SCRATCH_MNT/a
77 mv $SCRATCH_MNT/del/tmp $SCRATCH_MNT/c
78 rmdir $SCRATCH_MNT/del
79
80 # Filesystem now looks like:
81 #
82 # .                                                             (ino 256)
83 # |--- a/                                                       (ino 257)
84 # |    |--- x/                                                  (ino 261)
85 # |    |--- y/                                                  (ino 262)
86 # |
87 # |--- c/                                                       (ino 260)
88 #      |--- tmp/                                                (ino 258)
89 #
90 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
91
92 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
93 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
94         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
95
96 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
97 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
98         $SCRATCH_MNT/mysnap2
99
100 # Now recreate the filesystem by receiving both send streams and verify we get
101 # the same content that the original filesystem had.
102 _scratch_unmount
103 _scratch_mkfs >>$seqres.full 2>&1
104 _scratch_mount
105
106 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
107 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
108 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
109 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
110
111 echo "Silence is golden"
112 status=0
113 exit