e1fb7b50643f21f4dd0f6569a86c998f97979c38
[xfstests-dev.git] / tests / btrfs / 129
1 #! /bin/bash
2 # FS QA Test No. btrfs/129
3 #
4 # Test that an incremental send operation does not prematurely issues rmdir
5 # operations under a particular scenario (the rmdir operation is sent before
6 # the target directory is empty).
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
10 # Author: Filipe Manana <fdmanana@suse.com>
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cd /
38         rm -fr $send_files_dir
39         rm -f $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45
46 # real QA test starts here
47 _supported_fs btrfs
48 _supported_os Linux
49 _require_test
50 _require_scratch
51 _require_fssum
52
53 send_files_dir=$TEST_DIR/btrfs-test-$seq
54
55 rm -f $seqres.full
56 rm -fr $send_files_dir
57 mkdir $send_files_dir
58
59 _scratch_mkfs >>$seqres.full 2>&1
60 _scratch_mount
61
62 mkdir $SCRATCH_MNT/a
63 mkdir $SCRATCH_MNT/tmp
64 mkdir $SCRATCH_MNT/del
65 mv $SCRATCH_MNT/tmp $SCRATCH_MNT/del
66 mkdir $SCRATCH_MNT/a/c
67 mkdir $SCRATCH_MNT/del/x
68
69 # Filesystem looks like:
70 #
71 # .                                                             (ino 256)
72 # |--- a/                                                       (ino 257)
73 # |    |--- c/                                                  (ino 260)
74 # |
75 # |--- del/                                                     (ino 259)
76 #       |--- tmp/                                               (ino 258)
77 #       |--- x/                                                 (ino 261)
78 #
79 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
80
81 # When inode 260 was processed, rename operations for it and for inode 258 were
82 # issued (the rename for inode 260 must happen before the rename for inode 258).
83 # Then immediately after issuing the rename operation for inode 258, and before
84 # inode 261 was processed, the send stream issued a rmdir operation for inode
85 # 260, which would make the receiver fail with the error ENOTEMPTY because inode
86 # 261 was not yet renamed, it was still a child of inode 260 at that time.
87 #
88 mv $SCRATCH_MNT/a/c $SCRATCH_MNT
89 mv $SCRATCH_MNT/del/x $SCRATCH_MNT/a
90 mv $SCRATCH_MNT/del/tmp $SCRATCH_MNT/c
91 rmdir $SCRATCH_MNT/del
92
93 # Filesystem now looks like:
94 #
95 # .                                                             (ino 256)
96 # |--- a/                                                       (ino 257)
97 # |    |--- x/                                                  (ino 261)
98 # |
99 # |--- c/                                                       (ino 260)
100 #      |--- tmp/                                                (ino 258)
101 #
102 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
103
104 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
105 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
106         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
107
108 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
109 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
110         $SCRATCH_MNT/mysnap2
111
112 # Now recreate the filesystem by receiving both send streams and verify we get
113 # the same content that the original filesystem had.
114 _scratch_unmount
115 _scratch_mkfs >>$seqres.full 2>&1
116 _scratch_mount
117
118 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
119 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
120 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
121 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
122
123 echo "Silence is golden"
124 status=0
125 exit