btrfs/163: replace sprout instead of seed
[xfstests-dev.git] / tests / btrfs / 163
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test 163
6 #
7 # Test case to verify that a sprouted device can be replaced
8 #  Create a seed device
9 #  Create a sprout device
10 #  Remount RW
11 #  Run device replace on the sprout device
12 #
13 # Depends on the kernel patch
14 #   c6a5d954950c btrfs: fail replace of seed device
15
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 tmp=/tmp/$$
22 status=1        # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27         cd /
28         rm -f $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34 . ./common/filter.btrfs
35
36 # remove previous $seqres.full before test
37 rm -f $seqres.full
38
39 # real QA test starts here
40
41 # Modify as appropriate.
42 _supported_fs btrfs
43 _require_command "$BTRFS_TUNE_PROG" btrfstune
44 _require_scratch_dev_pool 3
45 _require_btrfs_forget_or_module_loadable
46
47 _scratch_dev_pool_get 3
48
49 dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
50 dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
51 dev_replace_tgt=$(echo $SCRATCH_DEV_POOL | awk '{print $3}')
52
53 create_seed()
54 {
55         _mkfs_dev $dev_seed
56         run_check _mount $dev_seed $SCRATCH_MNT
57         $XFS_IO_PROG -f -d -c "pwrite -S 0xab 0 4M" $SCRATCH_MNT/foobar >\
58                 /dev/null
59         echo -- golden --
60         od -x $SCRATCH_MNT/foobar
61         _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
62         _scratch_unmount
63         $BTRFS_TUNE_PROG -S 1 $dev_seed
64         run_check _mount $dev_seed $SCRATCH_MNT
65 }
66
67 add_sprout()
68 {
69         _run_btrfs_util_prog device add -f $dev_sprout $SCRATCH_MNT
70         _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
71         _mount -o remount,rw $dev_sprout $SCRATCH_MNT
72         $XFS_IO_PROG -f -c "pwrite -S 0xcd 0 4M" $SCRATCH_MNT/foobar2 >\
73                 /dev/null
74 }
75
76 replace_sprout()
77 {
78         _run_btrfs_util_prog replace start -fB $dev_sprout $dev_replace_tgt $SCRATCH_MNT
79         _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
80         _scratch_unmount
81         _btrfs_forget_or_module_reload
82         run_check _mount -o device=$dev_seed $dev_replace_tgt $SCRATCH_MNT
83         echo -- sprout --
84         od -x $SCRATCH_MNT/foobar
85         od -x $SCRATCH_MNT/foobar2
86         _scratch_unmount
87
88 }
89
90 seed_is_mountable()
91 {
92         _btrfs_forget_or_module_reload
93         run_check _mount $dev_seed $SCRATCH_MNT
94         _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
95         _scratch_unmount
96 }
97
98 create_seed
99 add_sprout
100 replace_sprout
101
102 seed_is_mountable
103
104 _scratch_dev_pool_put
105
106 status=0
107 exit