btrfs: test incremental send after removing a directory and all its files
[xfstests-dev.git] / tests / btrfs / 167
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test 167
6 #
7 # Test if btrfs will corrupt compressed data extent without data csum
8 # by replacing it with uncompressed data, when doing device replace.
9 #
10 # This could be fixed by the following kernel commit:
11 # ac0b4145d662 ("btrfs: scrub: Don't use inode pages for device replace")
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # real QA test starts here
36
37 # Modify as appropriate.
38 _supported_fs btrfs
39 _require_scratch_dev_pool 2
40 _require_scratch_dev_pool_equal_size
41
42 _scratch_dev_pool_get 1
43 _spare_dev_get
44 _scratch_pool_mkfs >> $seqres.full 2>&1
45
46 # Create nodatasum inode
47 _scratch_mount "-o nodatasum"
48 touch $SCRATCH_MNT/nodatasum_file
49 _scratch_remount "datasum,compress"
50 _pwrite_byte 0xcd 0 128K $SCRATCH_MNT/nodatasum_file > /dev/null
51
52 # Write the compressed data back to disk
53 sync
54
55 # Replace the device
56 _run_btrfs_util_prog replace start -Bf 1 $SPARE_DEV $SCRATCH_MNT
57
58 # Unmount to drop all cache so next read will read from disk
59 _scratch_unmount
60 _mount $SPARE_DEV $SCRATCH_MNT
61
62 # Now the EXTENT_DATA item still marks the extent as compressed,
63 # but the on-disk data is uncompressed, thus reading it as compressed
64 # will definitely cause EIO.
65 cat $SCRATCH_MNT/nodatasum_file > /dev/null
66
67 _scratch_unmount
68 _spare_dev_put
69 _scratch_dev_pool_put
70
71 echo "Silence is golden"
72
73 # success, all done
74 status=0
75 exit