xfs: Add test for too-small device with stripe geometry
[xfstests-dev.git] / tests / btrfs / 168
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 168
6 #
7 # Test that we are able to do send operations when one of the source snapshots
8 # (or subvolume) has a file that is deleted while there is still a open file
9 # descriptor for that file.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
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 -f $tmp.*
22         rm -fr $send_files_dir
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 _require_test
32 _require_scratch
33 _require_btrfs_command "property"
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 # Create a subvolume used for first full send test and used to create two
46 # snapshots for the incremental send test.
47 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/sv1 | _filter_scratch
48
49 # Create some test files.
50 $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 64K" $SCRATCH_MNT/sv1/foo >>$seqres.full
51 $XFS_IO_PROG -f -c "pwrite -S 0x7b 0 90K" $SCRATCH_MNT/sv1/bar >>$seqres.full
52 $XFS_IO_PROG -f -c "pwrite -S 0xea 0 256K" $SCRATCH_MNT/sv1/baz >>$seqres.full
53
54 # Flush the previous buffered writes, since setting a subvolume to RO mode
55 # does not do it and we want to check if the data is correctly transmitted by
56 # the send operations.
57 sync
58
59 # Keep an open file descriptor on file bar.
60 exec 73<$SCRATCH_MNT/sv1/bar
61
62 # While the file descriptor is open, delete the file, set the subvolume to
63 # read-only mode and see if a full send operation succeeds.
64 unlink $SCRATCH_MNT/sv1/bar
65 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro true
66 $FSSUM_PROG -A -f -w $send_files_dir/sv1.fssum $SCRATCH_MNT/sv1
67 $BTRFS_UTIL_PROG send -f $send_files_dir/sv1.send $SCRATCH_MNT/sv1 2>&1 \
68         | _filter_scratch
69
70 # Now that the we did the full send, close the file descriptor and set the
71 # subvolume back to read-write mode.
72 exec 73>&-
73 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro false
74
75 # Now try an incremental send operation while there's an open file descriptor
76 # for a file that was deleted from the send snapshot (while it was in read-write
77 # mode).
78
79 # Create a snapshot of the subvolume, to be used later as the parent snapshot
80 # for an incremental send operation.
81 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT/sv1 $SCRATCH_MNT/snap1 \
82         | _filter_scratch
83
84 # First do a full send of this snapshot.
85 $FSSUM_PROG -A -f -w $send_files_dir/snap1.fssum $SCRATCH_MNT/snap1
86 $BTRFS_UTIL_PROG send -f $send_files_dir/snap1.send $SCRATCH_MNT/snap1 2>&1 \
87         | _filter_scratch
88
89 # Modify file baz, to check that the incremental send operation does not miss
90 # that this file has changed.
91 $XFS_IO_PROG -c "pwrite -S 0x19 4K 8K" $SCRATCH_MNT/sv1/baz >>$seqres.full
92
93 # Create a second snapshot of the subvolume, to be used later as the send
94 # snapshot of an incremental send operation.
95 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT/sv1 $SCRATCH_MNT/snap2 \
96         | _filter_scratch
97
98 # Temporarily turn the second snapshot to read-write mode and then open a file
99 # descriptor on its foo file.
100 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/snap2 ro false
101 exec 73<$SCRATCH_MNT/snap2/foo
102
103 # Delete the foo file from the second snapshot while holding the file descriptor
104 # open.
105 unlink $SCRATCH_MNT/snap2/foo
106
107 # Set the second snapshot back to RO mode, so that we can use it for the
108 # incremental send operation.
109 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/snap2 ro true
110
111 # Do the incremental send while there's an open file descriptor on file foo from
112 # the second snapshot.
113 $FSSUM_PROG -A -f -w $send_files_dir/snap2.fssum $SCRATCH_MNT/snap2
114 $BTRFS_UTIL_PROG send -f $send_files_dir/snap2.send -p $SCRATCH_MNT/snap1 \
115         $SCRATCH_MNT/snap2 2>&1 | _filter_scratch
116
117 # Now that the incremental send is done close the file descriptor on snap2/foo.
118 exec 73>&-
119
120 # Recreate the filesystem using the send streams and check all files exist,
121 # except for the ones we deleted while holding an open file descriptor on them,
122 # and with correct data and metadata (size, timestamps, ownership, permissions).
123 _scratch_unmount
124 _scratch_mkfs >>$seqres.full 2>&1
125 _scratch_mount
126
127 $BTRFS_UTIL_PROG receive -f $send_files_dir/sv1.send $SCRATCH_MNT
128 $FSSUM_PROG -r $send_files_dir/sv1.fssum $SCRATCH_MNT/sv1
129 $BTRFS_UTIL_PROG receive -f $send_files_dir/snap1.send $SCRATCH_MNT
130 $FSSUM_PROG -r $send_files_dir/snap1.fssum $SCRATCH_MNT/snap1
131 $BTRFS_UTIL_PROG receive -f $send_files_dir/snap2.send $SCRATCH_MNT
132 $FSSUM_PROG -r $send_files_dir/snap2.fssum $SCRATCH_MNT/snap2
133
134 status=0
135 exit