summaryrefslogtreecommitdiff
path: root/tests/btrfs/168
blob: 7879ec056cebe598f4c819f59c49a8b73836b147 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test No. 168
#
# Test that we are able to do send operations when one of the source snapshots
# (or subvolume) has a file that is deleted while there is still a open file
# descriptor for that file.
#
. ./common/preamble
_begin_fstest auto quick send

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

. ./common/filter

_supported_fs btrfs
_require_test
_require_scratch
_require_btrfs_command "property"
_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

# Create a subvolume used for first full send test and used to create two
# snapshots for the incremental send test.
$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/sv1 | _filter_scratch

# Create some test files.
$XFS_IO_PROG -f -c "pwrite -S 0xf1 0 64K" $SCRATCH_MNT/sv1/foo >>$seqres.full
$XFS_IO_PROG -f -c "pwrite -S 0x7b 0 90K" $SCRATCH_MNT/sv1/bar >>$seqres.full
$XFS_IO_PROG -f -c "pwrite -S 0xea 0 256K" $SCRATCH_MNT/sv1/baz >>$seqres.full

# Flush the previous buffered writes, since setting a subvolume to RO mode
# does not do it and we want to check if the data is correctly transmitted by
# the send operations.
sync

# Keep an open file descriptor on file bar.
exec 73<$SCRATCH_MNT/sv1/bar

# While the file descriptor is open, delete the file, set the subvolume to
# read-only mode and see if a full send operation succeeds.
unlink $SCRATCH_MNT/sv1/bar
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro true
$FSSUM_PROG -A -f -w $send_files_dir/sv1.fssum $SCRATCH_MNT/sv1
$BTRFS_UTIL_PROG send -f $send_files_dir/sv1.send $SCRATCH_MNT/sv1 2>&1 \
	| _filter_scratch

# Now that the we did the full send, close the file descriptor and set the
# subvolume back to read-write mode.
exec 73>&-
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro false

# Now try an incremental send operation while there's an open file descriptor
# for a file that was deleted from the send snapshot (while it was in read-write
# mode).

# Create a snapshot of the subvolume, to be used later as the parent snapshot
# for an incremental send operation.
_btrfs subvolume snapshot -r $SCRATCH_MNT/sv1 $SCRATCH_MNT/snap1

# First do a full send of this snapshot.
$FSSUM_PROG -A -f -w $send_files_dir/snap1.fssum $SCRATCH_MNT/snap1
$BTRFS_UTIL_PROG send -f $send_files_dir/snap1.send $SCRATCH_MNT/snap1 2>&1 \
	| _filter_scratch

# Modify file baz, to check that the incremental send operation does not miss
# that this file has changed.
$XFS_IO_PROG -c "pwrite -S 0x19 4K 8K" $SCRATCH_MNT/sv1/baz >>$seqres.full

# Create a second snapshot of the subvolume, to be used later as the send
# snapshot of an incremental send operation.
_btrfs subvolume snapshot -r $SCRATCH_MNT/sv1 $SCRATCH_MNT/snap2

# Temporarily turn the second snapshot to read-write mode and then open a file
# descriptor on its foo file.
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/snap2 ro false
exec 73<$SCRATCH_MNT/snap2/foo

# Delete the foo file from the second snapshot while holding the file descriptor
# open.
unlink $SCRATCH_MNT/snap2/foo

# Set the second snapshot back to RO mode, so that we can use it for the
# incremental send operation.
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/snap2 ro true

# Do the incremental send while there's an open file descriptor on file foo from
# the second snapshot.
$FSSUM_PROG -A -f -w $send_files_dir/snap2.fssum $SCRATCH_MNT/snap2
$BTRFS_UTIL_PROG send -f $send_files_dir/snap2.send -p $SCRATCH_MNT/snap1 \
	$SCRATCH_MNT/snap2 2>&1 | _filter_scratch

# Now that the incremental send is done close the file descriptor on snap2/foo.
exec 73>&-

# Recreate the filesystem using the send streams and check all files exist,
# except for the ones we deleted while holding an open file descriptor on them,
# and with correct data and metadata (size, timestamps, ownership, permissions).
_scratch_unmount
_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount

$BTRFS_UTIL_PROG receive -f $send_files_dir/sv1.send $SCRATCH_MNT
$FSSUM_PROG -r $send_files_dir/sv1.fssum $SCRATCH_MNT/sv1
$BTRFS_UTIL_PROG receive -f $send_files_dir/snap1.send $SCRATCH_MNT
$FSSUM_PROG -r $send_files_dir/snap1.fssum $SCRATCH_MNT/snap1
$BTRFS_UTIL_PROG receive -f $send_files_dir/snap2.send $SCRATCH_MNT
$FSSUM_PROG -r $send_files_dir/snap2.fssum $SCRATCH_MNT/snap2

status=0
exit