btrfs: seed device replace test
[xfstests-dev.git] / tests / btrfs / 163
1 #! /bin/bash
2 # FS QA Test 163
3 #
4 # Test case to verify that a seed device can be replaced
5 #  Create a seed device
6 #  Create a sprout device
7 #  Remount RW
8 #  Run device replace on the seed device
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2018 Oracle.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38         cd /
39         rm -f $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/filter.btrfs
46
47 # remove previous $seqres.full before test
48 rm -f $seqres.full
49
50 # real QA test starts here
51
52 # Modify as appropriate.
53 _supported_fs btrfs
54 _supported_os Linux
55 _require_command "$BTRFS_TUNE_PROG" btrfstune
56 _require_scratch_dev_pool 3
57
58 _scratch_dev_pool_get 3
59
60 dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
61 dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
62 dev_replace_tgt=$(echo $SCRATCH_DEV_POOL | awk '{print $3}')
63
64 create_seed()
65 {
66         _mkfs_dev $dev_seed
67         run_check _mount $dev_seed $SCRATCH_MNT
68         $XFS_IO_PROG -f -d -c "pwrite -S 0xab 0 256K" $SCRATCH_MNT/foobar >\
69                 /dev/null
70         echo -- gloden --
71         od -x $SCRATCH_MNT/foobar
72         _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
73         _scratch_unmount
74         $BTRFS_TUNE_PROG -S 1 $dev_seed
75         run_check _mount $dev_seed $SCRATCH_MNT
76 }
77
78 add_sprout()
79 {
80         _run_btrfs_util_prog device add -f $dev_sprout $SCRATCH_MNT
81         _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
82 }
83
84 replace_seed()
85 {
86         _run_btrfs_util_prog replace start -fB $dev_seed $dev_replace_tgt $SCRATCH_MNT
87         _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
88         _scratch_unmount
89         run_check _mount $dev_replace_tgt $SCRATCH_MNT
90         echo -- sprout --
91         od -x $SCRATCH_MNT/foobar
92         _scratch_unmount
93
94 }
95
96 seed_is_mountable()
97 {
98         run_check _mount $dev_seed $SCRATCH_MNT
99         _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
100         _scratch_unmount
101 }
102
103 create_seed
104 add_sprout
105 replace_seed
106
107 seed_is_mountable
108
109 _scratch_dev_pool_put
110
111 status=0
112 exit