summaryrefslogtreecommitdiff
path: root/tests/btrfs/083
blob: ae8cf9d465870485ead64d8b02f447f2751c9fcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test No. btrfs/083
#
# Test for incremental send where the difference between the parent and child
# snapshots is that a directory A was renamed and a directory B was renamed to
# the name directory A had before (in the parent snapshot), but directory A's
# rename must happen before some other directory C is renamed.
#
# This issue was fixed by the following linux kernel btrfs patch:
#
#   Btrfs: incremental send, don't rename a directory too soon
#
. ./common/preamble
_begin_fstest auto quick send

# Override the default cleanup function.
_cleanup()
{
	rm -fr $send_files_dir
	rm -f $tmp.*
}

. ./common/filter

_supported_fs btrfs
_require_scratch
_require_fssum

send_files_dir=$TEST_DIR/btrfs-test-$seq

rm -fr $send_files_dir
mkdir $send_files_dir

_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount

mkdir $SCRATCH_MNT/a
mkdir $SCRATCH_MNT/b
mkdir $SCRATCH_MNT/c
touch $SCRATCH_MNT/a/file

mkdir $SCRATCH_MNT/d
mkdir $SCRATCH_MNT/e
touch $SCRATCH_MNT/e/file2
mkdir $SCRATCH_MNT/f

# Filesystem looks like:
#
# .                                       (ino 256)
# |---- a/                                (ino 257)
# |     |---- file                        (ino 260)
# |
# |---- b/                                (ino 258)
# |---- c/                                (ino 259)
# |---- d/                                (ino 261)
# |---- e/                                (ino 262)
# |     |--- file2                        (ino 263)
# |
# |---- f/                                (ino 264)
#
_btrfs subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1

# Now make inode 257 a child of inode 259 and rename inode 258 to the name that
# inode 257 had before. When the incremental send processes inode 257, it can't
# do the rename immediately because inode 259 must be renamed first, so inode's
# 257 rename is delayed and happens after the rename for inode 259 is done.
# Since send processes inodes by ascending order of their number, inode 258
# can't be renamed before inode 257 is renamed and therefore must be delayed
# as well. So the send stream must issue rename commands in the following order:
#
# 1 - rename inode 259 ('c' -> 'x')
# 2 - rename inode 257 ('a' -> 'x/y')
# 3 - rename inode 258 ('b' -> 'a')
#
# Before the fix mentioned above, the send stream attempted to rename inode 258
# before inode 257 was renamed, resulting in a client error mentioning
# 'directory not empty'.
#
# Same logic applies to 'd', 'e' and 'f', but the difference is that in the
# second snapshot 'e' is associated to an inode with a lower inode number than
# in the first snapshot.
#
mv $SCRATCH_MNT/c $SCRATCH_MNT/x
mv $SCRATCH_MNT/a $SCRATCH_MNT/x/y
mv $SCRATCH_MNT/b $SCRATCH_MNT/a

mv $SCRATCH_MNT/f $SCRATCH_MNT/f2
mv $SCRATCH_MNT/e $SCRATCH_MNT/f2/e2
mv $SCRATCH_MNT/d $SCRATCH_MNT/e

# Filesystem now looks like:
#
#
# .                                       (ino 256)
# |---- a/                                (ino 258)
# |---- x/                                (ino 259)
# |     |---- y/                          (ino 257)
# |           |----- file                 (ino 260)
# |
# |---- e/                                (ino 261)
# |---- f2/                               (ino 264)
# |     |----- e2/                        (ino 262)
#              |---- file2                (ino 263)

_btrfs subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2

run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
	-x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2

_btrfs send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
_btrfs send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
	$SCRATCH_MNT/mysnap2

# Now recreate the filesystem by receiving both send streams and verify we get
# the same content that the original filesystem had.
_scratch_unmount
_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount

_btrfs receive -f $send_files_dir/1.snap $SCRATCH_MNT
run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1

_btrfs receive -f $send_files_dir/2.snap $SCRATCH_MNT
run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2

echo "Silence is golden"

status=0
exit