btrfs/079: fix failure to umount scratch fs due to running filefrag process
[xfstests-dev.git] / tests / btrfs / 134
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 Synology Inc. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/134
6 #
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.
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/dir257
47 mkdir $SCRATCH_MNT/dir258
48 mkdir $SCRATCH_MNT/dir259
49 mv $SCRATCH_MNT/dir257 $SCRATCH_MNT/dir258/dir257
50
51 # Filesystem looks like:
52 #
53 # .                                                             (ino 256, gen 3)
54 # |--- dir258/                                                  (ino 258, gen 7)
55 # |       |--- dir257/                                          (ino 257, gen 7)
56 # |
57 # |--- dir259/                                                  (ino 259, gen 7)
58 #
59 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
60     $SCRATCH_MNT/mysnap1 > /dev/null
61
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.
72 _scratch_cycle_mount
73 touch $SCRATCH_MNT/file258
74 mkdir $SCRATCH_MNT/new_dir259
75 mv $SCRATCH_MNT/dir257 $SCRATCH_MNT/new_dir259/dir257
76
77 # Filesystem now looks like:
78 #
79 # .                                                            (ino 256, gen 3)
80 # |--- file258                                                 (ino 258, gen 10)
81 # |
82 # |--- new_dir259/                                             (ino 259, gen 10)
83 #          |--- dir257/                                        (ino 257, gen 7)
84 #
85 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
86                  $SCRATCH_MNT/mysnap2 > /dev/null
87
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
91
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
96
97 # Now recreate the filesystem by receiving both send streams and verify we get
98 # the same content that the original filesystem had.
99 _scratch_unmount
100 _scratch_mkfs >>$seqres.full 2>&1
101 _scratch_mount
102
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
107
108 status=0
109 exit