misc: move exit status into trap handler
[xfstests-dev.git] / tests / btrfs / 137
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/137
6 #
7 # Test that both incremental and full send operations preserve file holes.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         cd /
20         rm -fr $send_files_dir
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/punch
28
29 # real QA test starts here
30 _supported_fs btrfs
31 _require_test
32 _require_scratch
33 _require_xfs_io_command "fiemap"
34
35 send_files_dir=$TEST_DIR/btrfs-test-$seq
36
37 rm -f $seqres.full
38 rm -fr $send_files_dir
39 mkdir $send_files_dir
40
41 _scratch_mkfs >>$seqres.full 2>&1
42 _scratch_mount
43
44 # Create the first test file.
45 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 4K" $SCRATCH_MNT/foo | _filter_xfs_io
46
47 # Create a second test file with a 1Mb hole.
48 $XFS_IO_PROG -f \
49      -c "pwrite -S 0xaa 0 4K" \
50      -c "pwrite -S 0xbb 1028K 4K" \
51      $SCRATCH_MNT/bar | _filter_xfs_io
52
53 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
54         $SCRATCH_MNT/snap1 >/dev/null
55
56 # Now add one new extent to our first test file, increasing its size and leaving
57 # a 1Mb hole between the first extent and this new extent.
58 $XFS_IO_PROG -c "pwrite -S 0xbb 1028K 4K" $SCRATCH_MNT/foo | _filter_xfs_io
59
60 # Now overwrite the last extent of our second test file.
61 $XFS_IO_PROG -c "pwrite -S 0xcc 1028K 4K" $SCRATCH_MNT/bar | _filter_xfs_io
62
63 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
64                  $SCRATCH_MNT/snap2 >/dev/null
65
66 echo
67 echo "File digests in the original filesystem:"
68 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
69 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
70 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
71 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
72
73 echo
74 echo "File snap1/foo fiemap results in the original filesystem:"
75 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
76 echo
77 echo "File snap1/bar fiemap results in the original filesystem:"
78 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
79 echo
80 echo "File snap2/foo fiemap results in the original filesystem:"
81 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
82 echo
83 echo "File snap2/bar fiemap results in the original filesystem:"
84 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap
85 echo
86
87 # Create the send streams to apply later on a new filesystem.
88 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/snap1 2>&1 \
89         | _filter_scratch
90 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/snap1 -f $send_files_dir/2.snap \
91         $SCRATCH_MNT/snap2 2>&1 | _filter_scratch
92
93 # Create a new filesystem, receive the send streams and verify that the file
94 # contents are the same as in the original filesystem and that the file holes
95 # exists in both snapshots.
96 _scratch_unmount
97 _scratch_mkfs >>$seqres.full 2>&1
98 _scratch_mount
99 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT >/dev/null
100 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT >/dev/null
101
102 echo
103 echo "File digests in the new filesystem:"
104 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
105 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
106 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
107 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
108
109 echo
110 echo "File snap1/foo fiemap results in the new filesystem:"
111 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
112 echo
113 echo "File snap1/bar fiemap results in the new filesystem:"
114 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
115 echo
116 echo "File snap2/foo fiemap results in the new filesystem:"
117 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
118 echo
119 echo "File snap2/bar fiemap results in the new filesystem:"
120 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap
121
122 status=0
123 exit