btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / btrfs / 218
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 218
6 #
7 # Regression test for the problem fixed by the patch
8 #
9 #  btrfs: init device stats for seed devices
10 #
11 # Make a seed device, add a sprout to it, and then make sure we can still read
12 # the device stats for both devices after we remount with the new sprout device.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         cd /
26         rm -f $tmp.*
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/filter.btrfs
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 dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
47 dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
48
49 # Create the seed device
50 _mkfs_dev $dev_seed
51 _mount $dev_seed $SCRATCH_MNT
52 $XFS_IO_PROG -f -d -c "pwrite -S 0xab 0 1M" $SCRATCH_MNT/foo > /dev/null
53 $BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
54         _filter_btrfs_filesystem_show
55 _scratch_unmount
56 $BTRFS_TUNE_PROG -S 1 $dev_seed
57
58 # Mount the seed device and add the rw device
59 _mount -o ro $dev_seed $SCRATCH_MNT
60 _run_btrfs_util_prog device add -f $dev_sprout $SCRATCH_MNT
61 $BTRFS_UTIL_PROG device stats $SCRATCH_MNT | _filter_scratch_pool
62 _scratch_unmount
63
64 # Now remount, validate the device stats do not fail
65 _mount $dev_sprout $SCRATCH_MNT
66 $BTRFS_UTIL_PROG device stats $SCRATCH_MNT | _filter_scratch_pool
67
68 _scratch_dev_pool_put
69
70 # success, all done
71 status=0
72 exit