btrfs/012: check free size of scratch device before copying files
[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         _btrfs_rescan_devices
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34
35 # remove previous $seqres.full before test
36 rm -f $seqres.full
37
38 # real QA test starts here
39
40 # Modify as appropriate.
41 _supported_fs btrfs
42 _require_test
43 _require_scratch_dev_pool 2
44 _require_btrfs_forget_or_module_loadable
45
46 _scratch_dev_pool_get 2
47
48 seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
49 sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
50
51 _mkfs_dev $seed
52 _mount $seed $SCRATCH_MNT
53
54 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 1M" $SCRATCH_MNT/foo > /dev/null
55 _scratch_unmount
56 $BTRFS_TUNE_PROG -S 1 $seed
57
58 # Mount the seed device and add the rw device
59 _mount -o ro $seed $SCRATCH_MNT
60 $BTRFS_UTIL_PROG device add -f $sprout $SCRATCH_MNT
61 _scratch_unmount
62
63 # Now remount
64 _mount $sprout $SCRATCH_MNT
65 $XFS_IO_PROG -f -c "pwrite -S 0xcd 0 1M" $SCRATCH_MNT/bar > /dev/null
66
67 echo --- before delete ----
68 od -x $SCRATCH_MNT/foo
69 od -x $SCRATCH_MNT/bar
70
71 $BTRFS_UTIL_PROG device delete $seed $SCRATCH_MNT
72 _scratch_unmount
73 _btrfs_forget_or_module_reload
74 _mount $sprout $SCRATCH_MNT
75
76 echo --- after delete ----
77 od -x $SCRATCH_MNT/foo
78 od -x $SCRATCH_MNT/bar
79
80 _scratch_dev_pool_put
81 _btrfs_rescan_devices
82
83 # success, all done
84 status=0
85 exit