xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / btrfs / 054
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/054
6 #
7 # Regression test for a btrfs incremental send issue where the difference
8 # between the snapshots used by the incremental send consists of one of
9 # these cases:
10 #
11 # 1) First snapshot has a directory with name X and in the second snapshot
12 #    that directory doesn't exist anymore but a subvolume/snapshot with
13 #    the same name (X) exists;
14 #
15 # 2) First snapshot has a subvolume/snapshot with name X and in the second
16 #    snapshot that subvolume/snapshot doesn't exist anymore (might have been
17 #    replaced by a directory with the same name or not).
18 #
19 # This issue is fixed by the following linux kernel btrfs patches:
20 #
21 #    Btrfs: send, don't error in the presence of subvols/snapshots
22 #    Btrfs: set dead flag on the right root when destroying snapshot
23 #
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 tmp=/tmp/$$
29 status=1        # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 _cleanup()
33 {
34     rm -fr $send_files_dir
35     rm -fr $tmp
36 }
37
38 # get standard environment, filters and checks
39 . ./common/rc
40 . ./common/filter
41 . ./common/attr
42
43 # real QA test starts here
44 _supported_fs btrfs
45 _require_test
46 _require_scratch
47
48 send_files_dir=$TEST_DIR/btrfs-test-$seq
49
50 rm -f $seqres.full
51 rm -fr $send_files_dir
52 mkdir $send_files_dir
53
54 _scratch_mkfs >/dev/null 2>&1
55 _scratch_mount
56
57 mkdir $SCRATCH_MNT/testdir
58 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/first_subvol
59
60 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
61
62 # Replace the directory testdir with a subvolume that has the same name.
63 rmdir $SCRATCH_MNT/testdir
64 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/testdir
65
66 # Delete the subvolume first_subvol and create a directory with the same name.
67 _run_btrfs_util_prog subvolume delete $SCRATCH_MNT/first_subvol
68 mkdir $SCRATCH_MNT/first_subvol
69
70 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
71
72 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
73 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
74         $SCRATCH_MNT/mysnap2
75
76 _scratch_unmount
77 _check_scratch_fs
78
79 _scratch_mkfs >/dev/null 2>&1
80 _scratch_mount
81
82 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
83 [ -e $SCRATCH_MNT/first_subvol ] && \
84         echo "Subvolume first_subvol was not supposed to be replicated by full send!"
85
86 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
87 [ -e $SCRATCH_MNT/testdir ] && \
88         echo "Directory testdir was supposed to be deleted after incremental send!"
89
90 status=0
91 exit