generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 155
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/155
6 #
7 # Test that an incremental send operation works if a file that has multiple
8 # hard links has some of its hard links renamed in the send snapshot, with one
9 # of them getting the same path that some other inode had in the send snapshot.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick send
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17         cd /
18         rm -fr $send_files_dir
19         rm -f $tmp.*
20 }
21
22 # Import common functions.
23 . ./common/filter
24
25 # real QA test starts here
26 _supported_fs btrfs
27 _require_test
28 _require_scratch
29 _require_fssum
30
31 send_files_dir=$TEST_DIR/btrfs-test-$seq
32
33 rm -fr $send_files_dir
34 mkdir $send_files_dir
35
36 _scratch_mkfs >>$seqres.full 2>&1
37 _scratch_mount
38
39 mkdir $SCRATCH_MNT/a
40 touch $SCRATCH_MNT/a/f1
41 mkdir -p $SCRATCH_MNT/a/b/c
42 ln $SCRATCH_MNT/a/f1 $SCRATCH_MNT/a/b/c/f1l1
43 touch $SCRATCH_MNT/a/b/f2
44 mkdir $SCRATCH_MNT/d
45 mv $SCRATCH_MNT/a/b/c/f1l1 $SCRATCH_MNT/d/f1l1_2
46 ln $SCRATCH_MNT/a/b/f2 $SCRATCH_MNT/a/f2l1
47 ln $SCRATCH_MNT/a/b/f2 $SCRATCH_MNT/d/f2l2
48 mv $SCRATCH_MNT/a/f1 $SCRATCH_MNT/d/f1_2
49
50 # Filesystem looks like:
51 #
52 # .                                                      (ino 256)
53 # |---- a/                                               (ino 257)
54 # |     |---- b/                                         (ino 259)
55 # |     |     |---- c/                                   (ino 260)
56 # |     |     |---- f2                                   (ino 261)
57 # |     |
58 # |     |---- f2l1                                       (ino 261)
59 # |
60 # |---- d/                                               (ino 262)
61 #       |---- f1l1_2                                     (ino 258)
62 #       |---- f2l2                                       (ino 261)
63 #       |---- f1_2                                       (ino 258)
64 #
65 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
66         $SCRATCH_MNT/mysnap1 > /dev/null
67
68 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
69         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
70
71 mv $SCRATCH_MNT/d $SCRATCH_MNT/a/b/d2
72 mv $SCRATCH_MNT/a/f2l1 $SCRATCH_MNT/d
73 mkdir $SCRATCH_MNT/a/f2l1
74 ln $SCRATCH_MNT/a/b/d2/f1_2 $SCRATCH_MNT/a/b/f1l2
75 mv $SCRATCH_MNT/a/b $SCRATCH_MNT/a/f2l1/b2
76 mv $SCRATCH_MNT/a/f2l1/b2/d2 $SCRATCH_MNT/a/f2l1/b2/c/d3
77 mv $SCRATCH_MNT/a/f2l1/b2/c/d3/f2l2 $SCRATCH_MNT/a/f2l1/b2/c/d3/f2l2_2
78
79 # Filesystem now looks like:
80 #
81 # .                                                      (ino 256)
82 # |---- a/                                               (ino 257)
83 # |     |---- f2l1/                                      (ino 263)
84 # |             |---- b2/                                (ino 259)
85 # |                   |---- c/                           (ino 260)
86 # |                   |     |---- d3                     (ino 262)
87 # |                   |           |---- f1l1_2           (ino 258)
88 # |                   |           |---- f2l2_2           (ino 261)
89 # |                   |           |---- f1_2             (ino 258)
90 # |                   |
91 # |                   |---- f2                           (ino 261)
92 # |                   |---- f1l2                         (ino 258)
93 # |
94 # |---- d                                                (ino 261)
95 #
96
97 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
98                  $SCRATCH_MNT/mysnap2 > /dev/null
99 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
100                  $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
101
102 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
103 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
104         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
105
106 # Now recreate the filesystem by receiving both send streams and verify we get
107 # the same content that the original filesystem had.
108 _scratch_unmount
109 _scratch_mkfs >>$seqres.full 2>&1
110 _scratch_mount
111
112 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
113 # The incremental send operation below used to issue an unlink operation for the
114 # path "d/f2l1" after it orphanized inode 262 (renamed it to o262-7-0) and after
115 # it created the link named "d" for inode 261, which made the receiver fail on
116 # the unlink operation with error code ENOTDIR. That unlink operation should
117 # have had the path "o262-7-0/f2l2" instead.
118 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
119 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
120 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
121
122 status=0
123 exit