btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / btrfs / 183
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 183
6 #
7 # Regression test for read corruption of compressed and shared extents after
8 # punching holes into a file.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
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 -f $tmp.*
21 }
22
23 # get standard environment, filters and checks
24 . ./common/rc
25 . ./common/filter
26 . ./common/reflink
27
28 # real QA test starts here
29 _supported_fs btrfs
30 _require_scratch_reflink
31 _require_xfs_io_command "fpunch"
32
33 rm -f $seqres.full
34
35 _scratch_mkfs >>$seqres.full 2>&1
36 _scratch_mount "-o compress"
37
38 # Create a file with 3 consecutive compressed extents, each corresponds to 128Kb
39 # of data (uncompressed size) and each is stored on disk as a 4Kb extent
40 # (compressed size, regardless of compression algorithm used).
41 # Each extent starts with 4Kb of zeroes, while the remaining bytes all have a
42 # value of 0xff.
43 $XFS_IO_PROG -f -c "pwrite -S 0xff 0 384K" \
44              -c "pwrite -S 0x00 0 4K" \
45              -c "pwrite -S 0x00 128K 4K" \
46              -c "pwrite -S 0x00 256K 4K" \
47              $SCRATCH_MNT/foobar | _filter_xfs_io
48
49 echo "File digest after initial creation:"
50 md5sum $SCRATCH_MNT/foobar | _filter_scratch
51
52 # Clone the first extent into offsets 128K and 256K.
53 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foobar 0 128K 128K" \
54              -c "reflink $SCRATCH_MNT/foobar 0 256K 128K" \
55              $SCRATCH_MNT/foobar | _filter_xfs_io
56
57 echo "File digest after reflinking:"
58 md5sum $SCRATCH_MNT/foobar | _filter_scratch
59
60 # Punch holes into the regions that are already full of zeroes.
61 $XFS_IO_PROG -c "fpunch 0 4K" \
62              -c "fpunch 128K 4K" \
63              -c "fpunch 256K 4K" \
64              $SCRATCH_MNT/foobar
65
66 echo "File digest after punching holes:"
67 md5sum $SCRATCH_MNT/foobar | _filter_scratch
68
69 echo 1 > /proc/sys/vm/drop_caches
70
71 echo "File digest after dropping page cache:"
72 md5sum $SCRATCH_MNT/foobar | _filter_scratch
73
74 status=0
75 exit