generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 221
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/221
6 #
7 # Test that an incremental send operation emits the correct path for link and
8 # rename operation after swapping the names and locations of several inodes in
9 # a way that creates a nasty dependency of rename and link operations. Notably
10 # one file has its name and location swapped with a directory for which it used
11 # to have a directory entry in it.
12 #
13 . ./common/preamble
14 _begin_fstest auto quick send
15
16 # Override the default cleanup function.
17 _cleanup()
18 {
19         cd /
20         rm -fr $send_files_dir
21         rm -f $tmp.*
22 }
23
24 # Import common functions.
25 . ./common/filter
26
27 # real QA test starts here
28 _supported_fs btrfs
29 _require_test
30 _require_scratch
31 _require_fssum
32
33 send_files_dir=$TEST_DIR/btrfs-test-$seq
34
35 rm -fr $send_files_dir
36 mkdir $send_files_dir
37
38 _scratch_mkfs >>$seqres.full 2>&1
39 _scratch_mount
40
41 touch $SCRATCH_MNT/a
42 touch $SCRATCH_MNT/b
43 mkdir $SCRATCH_MNT/testdir
44 # We want "a" to have a lower inode number than its parent directory, so it
45 # was created before the directory and then moved into it.
46 mv $SCRATCH_MNT/a $SCRATCH_MNT/testdir/a
47
48 # Filesystem looks like:
49 #
50 # .                                                      (ino 256)
51 # |----- testdir/                                        (ino 259)
52 # |          |----- a                                    (ino 257)
53 # |
54 # |----- b                                               (ino 258)
55 #
56 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
57         $SCRATCH_MNT/mysnap1 > /dev/null
58
59 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
60         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
61
62 # Now rename 259 to "testdir_2", then change the name of 257 to "testdir" and
63 # make it a direct descendant of the root inode (256). Also create a new link
64 # for inode 257 with the old name of inode 258. By swapping the names and
65 # location of several inodes and create a nasty dependency chain of rename and
66 # link operations.
67 mv $SCRATCH_MNT/testdir/a $SCRATCH_MNT/a2
68 touch $SCRATCH_MNT/testdir/a
69 mv $SCRATCH_MNT/b $SCRATCH_MNT/b2
70 ln $SCRATCH_MNT/a2 $SCRATCH_MNT/b
71 mv $SCRATCH_MNT/testdir $SCRATCH_MNT/testdir_2
72 mv $SCRATCH_MNT/a2 $SCRATCH_MNT/testdir
73
74 # Filesystem now looks like:
75 #
76 # .                                                      (ino 256)
77 # |----- testdir_2/                                      (ino 259)
78 # |          |----- a                                    (ino 260)
79 # |
80 # |----- testdir                                         (ino 257)
81 # |----- b                                               (ino 257)
82 # |----- b2                                              (ino 258)
83 #
84
85 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
86                  $SCRATCH_MNT/mysnap2 > /dev/null
87 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
88                  $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
89
90 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
91 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
92         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
93
94 # Now recreate the filesystem by receiving both send streams and verify we get
95 # the same content that the original filesystem had.
96 _scratch_unmount
97 _scratch_mkfs >>$seqres.full 2>&1
98 _scratch_mount
99
100 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
101
102 # The receive operation below used to fail because when attemping to create the
103 # hard link named "b" for inode 257, the link operation contained a target path
104 # of "o259-6-0/a", which caused the receiver process to fail because inode 259
105 # was not yet orphanized (renamed to "o259-6-0"), it still had the name "testdir"
106 # when the link operation was issued.
107 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
108
109 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
110 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
111
112 status=0
113 exit