generic: test for non-zero used blocks while writing into a file
[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 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -fr $send_files_dir
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # real QA test starts here
31 _supported_fs btrfs
32 _require_test
33 _require_scratch
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 mkdir $SCRATCH_MNT/a
46 touch $SCRATCH_MNT/a/f1
47 mkdir -p $SCRATCH_MNT/a/b/c
48 ln $SCRATCH_MNT/a/f1 $SCRATCH_MNT/a/b/c/f1l1
49 touch $SCRATCH_MNT/a/b/f2
50 mkdir $SCRATCH_MNT/d
51 mv $SCRATCH_MNT/a/b/c/f1l1 $SCRATCH_MNT/d/f1l1_2
52 ln $SCRATCH_MNT/a/b/f2 $SCRATCH_MNT/a/f2l1
53 ln $SCRATCH_MNT/a/b/f2 $SCRATCH_MNT/d/f2l2
54 mv $SCRATCH_MNT/a/f1 $SCRATCH_MNT/d/f1_2
55
56 # Filesystem looks like:
57 #
58 # .                                                      (ino 256)
59 # |---- a/                                               (ino 257)
60 # |     |---- b/                                         (ino 259)
61 # |     |     |---- c/                                   (ino 260)
62 # |     |     |---- f2                                   (ino 261)
63 # |     |
64 # |     |---- f2l1                                       (ino 261)
65 # |
66 # |---- d/                                               (ino 262)
67 #       |---- f1l1_2                                     (ino 258)
68 #       |---- f2l2                                       (ino 261)
69 #       |---- f1_2                                       (ino 258)
70 #
71 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
72         $SCRATCH_MNT/mysnap1 > /dev/null
73
74 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
75         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
76
77 mv $SCRATCH_MNT/d $SCRATCH_MNT/a/b/d2
78 mv $SCRATCH_MNT/a/f2l1 $SCRATCH_MNT/d
79 mkdir $SCRATCH_MNT/a/f2l1
80 ln $SCRATCH_MNT/a/b/d2/f1_2 $SCRATCH_MNT/a/b/f1l2
81 mv $SCRATCH_MNT/a/b $SCRATCH_MNT/a/f2l1/b2
82 mv $SCRATCH_MNT/a/f2l1/b2/d2 $SCRATCH_MNT/a/f2l1/b2/c/d3
83 mv $SCRATCH_MNT/a/f2l1/b2/c/d3/f2l2 $SCRATCH_MNT/a/f2l1/b2/c/d3/f2l2_2
84
85 # Filesystem now looks like:
86 #
87 # .                                                      (ino 256)
88 # |---- a/                                               (ino 257)
89 # |     |---- f2l1/                                      (ino 263)
90 # |             |---- b2/                                (ino 259)
91 # |                   |---- c/                           (ino 260)
92 # |                   |     |---- d3                     (ino 262)
93 # |                   |           |---- f1l1_2           (ino 258)
94 # |                   |           |---- f2l2_2           (ino 261)
95 # |                   |           |---- f1_2             (ino 258)
96 # |                   |
97 # |                   |---- f2                           (ino 261)
98 # |                   |---- f1l2                         (ino 258)
99 # |
100 # |---- d                                                (ino 261)
101 #
102
103 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
104                  $SCRATCH_MNT/mysnap2 > /dev/null
105 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
106                  $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
107
108 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
109 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
110         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
111
112 # Now recreate the filesystem by receiving both send streams and verify we get
113 # the same content that the original filesystem had.
114 _scratch_unmount
115 _scratch_mkfs >>$seqres.full 2>&1
116 _scratch_mount
117
118 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
119 # The incremental send operation below used to issue an unlink operation for the
120 # path "d/f2l1" after it orphanized inode 262 (renamed it to o262-7-0) and after
121 # it created the link named "d" for inode 261, which made the receiver fail on
122 # the unlink operation with error code ENOTDIR. That unlink operation should
123 # have had the path "o262-7-0/f2l2" instead.
124 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
125 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
126 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
127
128 status=0
129 exit