]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_vdevs.ksh
Pool allocation classes
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zpool_split / zpool_split_vdevs.ksh
1 #!/bin/ksh -p
2 #
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
6 # 1.0 of the CDDL.
7 #
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
11 #
12
13 #
14 # Copyright 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15 #
16
17 . $STF_SUITE/include/libtest.shlib
18 . $STF_SUITE/include/math.shlib
19
20 #
21 # DESCRIPTION:
22 # 'zpool split' should only work on mirrors. Every other VDEV layout is not
23 # supported.
24 #
25 # STRATEGY:
26 # Create pools with various VDEV layouts and verify only mirrors can be split
27 #
28
29 verify_runnable "both"
30
31 function cleanup
32 {
33 destroy_pool $TESTPOOL
34 destroy_pool $TESTPOOL2
35 rm -f $FILEDEV_PREFIX*
36 }
37
38 #
39 # Given a vdev type generate a pool configuration which can be immediately
40 # used as "zpool create $poolname $config" or "zpool add $poolname $config".
41 # Supported vdev types are:
42 # "d" - single disk
43 # "t" - stripe
44 # "m" - mirror
45 # "m3" - 3-way mirror
46 # "z1" - raidz1
47 # "z2" - raidz2
48 # "z3" - raidz3
49 # "s" - spare
50 # "l" - log
51 # "ll" - mirrored log
52 # "c" - cache
53 # "sc" - special class
54 #
55 function pool_config # <vdev-type>
56 {
57 typeset config=""
58 typeset -A disks
59 disks[d]="d1"
60 disks[t]="t1 t2"
61 disks[m]="m1 m2"
62 disks[m3]="m1 m2 m3"
63 disks[z1]="z1 z2"
64 disks[z2]="z1 z2 z3"
65 disks[z3]="z1 z2 z3 z4"
66 disks[s]="s1"
67 disks[l]="l1"
68 disks[ll]="l1 l2"
69 disks[c]="c1"
70 disks[sc]="sc1 sc2"
71 case $1 in
72 d|t) # single disk or stripe
73 vdev='' ;;
74 m|m3) # 2-way or 3-way mirror
75 vdev='mirror';;
76 z1) # raidz1
77 vdev='raidz1';;
78 z2) # raidz2
79 vdev='raidz2';;
80 z3) # raidz3
81 vdev='raidz3';;
82 s) # spare
83 vdev='spare';;
84 l) # log
85 vdev='log';;
86 ll) # mirrored log
87 vdev='log mirror';;
88 c) # cache
89 vdev='cache';;
90 sc) # mirrored special class
91 vdev='special mirror';;
92 *)
93 log_fail "setup_pool: unsupported vdev type '$1'"
94 esac
95 config="$vdev"
96 for tok in ${disks[$1]}; do
97 filedev="$FILEDEV_PREFIX-$tok"
98 # if $filedev exists we are requesting the same vdev type twice
99 # in a row (eg. pool of striped mirrors): add a random suffix.
100 while [[ -f $filedev ]]; do
101 filedev="$filedev.$RANDOM"
102 done
103 truncate -s $SPA_MINDEVSIZE "$filedev"
104 config="$config $filedev"
105 done
106 echo "$config"
107 }
108
109 log_assert "'zpool split' should work only on mirror VDEVs"
110 log_onexit cleanup
111
112 # "good" and "bad" pool layouts
113 # first token is always used with "zpool create"
114 # second to last tokens, if any, are used with "zpool add"
115 typeset -a goodconfs=("m" "m l" "m s" "m c" "m m" "m3" "m3 m3" "m m3 l s c" "m m sc")
116 typeset -a badconfs=("d" "z1" "z2" "z3" "m d" "m3 d" "m z1" "m z2" "m z3")
117 typeset FILEDEV_PREFIX="$TEST_BASE_DIR/filedev"
118 typeset altroot="$TESTDIR/altroot-$TESTPOOL2"
119
120 # Create pools with various VDEV layouts and verify only mirrors can be split
121 for config in "${goodconfs[@]}"
122 do
123 create_config="${config%% *}"
124 add_config="$(awk '{$1= "";print $0}' <<< $config)"
125 log_must zpool create $TESTPOOL $(pool_config $create_config)
126 for vdev in $add_config; do
127 log_must zpool add $TESTPOOL -f $(pool_config $vdev)
128 done
129 log_must zpool split -R $altroot $TESTPOOL $TESTPOOL2
130 log_must poolexists $TESTPOOL2
131 log_must test "$(get_pool_prop 'altroot' $TESTPOOL2)" == "$altroot"
132 cleanup
133 done
134
135 # Every other pool layout should *not* be splittable
136 for config in "${badconfs[@]}"
137 do
138 create_config="${config%% *}"
139 add_config="$(awk '{$1= "";print $0}' <<< $config)"
140 log_must zpool create $TESTPOOL $(pool_config $create_config)
141 for vdev in $add_config; do
142 log_must zpool add $TESTPOOL -f $(pool_config $vdev)
143 done
144 log_mustnot zpool split -R $altroot $TESTPOOL $TESTPOOL2
145 log_mustnot poolexists $TESTPOOL2
146 cleanup
147 done
148
149 log_pass "'zpool split' works only on mirror VDEVs"