btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / btrfs / 133
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 Synology Inc. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/133
6 #
7 # Test that an incremental send operation does not fail when a new inode
8 # replaces an old inode that has the same number but different generation,
9 # and both are direct children of the subvolume/snapshot root.
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/a1
46 mkdir $SCRATCH_MNT/a2
47
48 # Filesystem looks like:
49 #
50 # .                                                             (ino 256)
51 # |--- a1/                                                      (ino 257)
52 # |--- a2/                                                      (ino 258)
53 #
54 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
55     $SCRATCH_MNT/mysnap1 > /dev/null
56
57 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
58         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
59
60 _scratch_unmount
61 _scratch_mkfs >>$seqres.full 2>&1
62 _scratch_mount
63 touch $SCRATCH_MNT/a2
64
65 # Filesystem now looks like:
66 #
67 # .                                                             (ino 256)
68 # |--- a2                                                       (ino 257)
69 #
70 # Notice that at this point inode 257 has a generation with value 7, which is
71 # the generation value for a brand new filesystem.
72
73 # Now create the second snapshot. This makes the filesystem's current generation
74 # value to increase to the value 8, due to a transaction commit performed by the
75 # snapshot creation ioctl.
76 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
77     $SCRATCH_MNT/mysnap2 > /dev/null
78
79 # Now receive the first snapshot created in the first filesystem.
80 # Before creating any inodes, the receive command creates the first snapshot,
81 # which causes a transaction commit and therefore bumps the filesystem's current
82 # generation to the value 9. All the inodes created end up getting a generation
83 # value of 9 and the snapshot's root inode (256) gets a generation value of 8.
84 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
85 rm $send_files_dir/1.snap
86
87 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
88 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
89
90 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
91         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
92 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
93         $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
94
95 # Now recreate the filesystem by receiving both send streams and verify we get
96 # the same content that the original filesystem had.
97 # The receive for the second snapshot used to fail because the send stream had
98 # an operation to rename the new inode 257 (generation 7) from its orphan name
99 # to its final name (a2) before the operation to delete (rmdir) the inode 258.
100 _scratch_unmount
101 _scratch_mkfs >>$seqres.full 2>&1
102 _scratch_mount
103
104 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
105 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
106 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
107 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
108
109 status=0
110 exit