generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / btrfs / 225
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Oracle. All Rights Reserved.
4 #
5 # FS QA Test 225
6 #
7 # Test for seed device-delete on a sprouted FS.
8 # Requires kernel patch
9 #    b5ddcffa3777  btrfs: fix put of uninitialized kobject after seed device delete
10 #
11 # Steps:
12 #  Create a seed FS. Add a RW device to make it sprout FS and then delete
13 #  the seed device.
14
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26         cd /
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33
34 # remove previous $seqres.full before test
35 rm -f $seqres.full
36
37 # real QA test starts here
38
39 # Modify as appropriate.
40 _supported_fs btrfs
41 _require_test
42 _require_scratch_dev_pool 2
43
44 _scratch_dev_pool_get 2
45
46 seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
47 sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
48
49 _mkfs_dev $seed
50 _mount $seed $SCRATCH_MNT
51
52 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 1M" $SCRATCH_MNT/foo > /dev/null
53 _scratch_unmount
54 $BTRFS_TUNE_PROG -S 1 $seed
55
56 # Mount the seed device and add the rw device
57 _mount -o ro $seed $SCRATCH_MNT
58 $BTRFS_UTIL_PROG device add -f $sprout $SCRATCH_MNT
59 _scratch_unmount
60
61 # Now remount
62 _mount $sprout $SCRATCH_MNT
63 $XFS_IO_PROG -f -c "pwrite -S 0xcd 0 1M" $SCRATCH_MNT/bar > /dev/null
64
65 echo --- before delete ----
66 od -x $SCRATCH_MNT/foo
67 od -x $SCRATCH_MNT/bar
68
69 $BTRFS_UTIL_PROG device delete $seed $SCRATCH_MNT
70 _scratch_unmount
71 _btrfs_forget_or_module_reload
72 _mount $sprout $SCRATCH_MNT
73
74 echo --- after delete ----
75 od -x $SCRATCH_MNT/foo
76 od -x $SCRATCH_MNT/bar
77
78 _scratch_dev_pool_put
79
80 # success, all done
81 status=0
82 exit