Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / test / t-mirror-basic.sh
bloba68007ca067ab4ff0fa511829ac076028129fc1c
1 #!/bin/sh
2 # Copyright (C) 2008 Red Hat, Inc. All rights reserved.
3 # Copyright (C) 2007 NEC Corporation
5 # This copyrighted material is made available to anyone wishing to use,
6 # modify, copy, or redistribute it subject to the terms and conditions
7 # of the GNU General Public License v.2.
9 # You should have received a copy of the GNU General Public License
10 # along with this program; if not, write to the Free Software Foundation,
11 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13 test_description="ensure that basic operations on mirrored LV works"
15 . ./test-utils.sh
17 dmsetup_has_dm_devdir_support_ || exit 200
19 # ---------------------------------------------------------------------
20 # Utilities
22 lvdev_()
24 echo "$G_dev_/$1/$2"
27 mimages_are_redundant_ ()
29 local vg=$1
30 local lv=$vg/$2
31 local i
33 rm -f out
34 for i in $(lvs -odevices --noheadings $lv | sed 's/([^)]*)//g; s/,/ /g'); do
35 lvs -a -odevices --noheadings $vg/$i | sed 's/([^)]*)//g; s/,/ /g' | \
36 sort | uniq >> out
37 done
39 # if any duplication is found, it's not redundant
40 sort out | uniq -d | grep . && return 1
42 return 0
45 lv_is_contiguous_ ()
47 local lv=$1
49 # if the lv has multiple segments, it's not contiguous
50 [ $(lvs -a --segments --noheadings $lv | wc -l) -ne 1 ] && return 1
52 return 0
55 lv_is_clung_ ()
57 local lv=$1
59 # if any duplication is found, it's not redundant
60 [ $(lvs -a -odevices --noheadings $lv | sed 's/([^)]*)//g' | \
61 sort | uniq | wc -l) -ne 1 ] && return 1
63 return 0
66 mimages_are_contiguous_ ()
68 local vg=$1
69 local lv=$vg/$2
70 local i
72 for i in $(lvs -odevices --noheadings $lv | sed 's/([^)]*)//g; s/,/ /g'); do
73 lv_is_contiguous_ $vg/$i || return 1
74 done
76 return 0
79 mimages_are_clung_ ()
81 local vg=$1
82 local lv=$vg/$2
83 local i
85 for i in $(lvs -odevices --noheadings $lv | sed 's/([^)]*)//g; s/,/ /g'); do
86 lv_is_clung_ $vg/$i || return 1
87 done
89 return 0
92 mirrorlog_is_on_()
94 local lv="$1"_mlog
95 shift 1
96 lvs -a -odevices --noheadings $lv | sed 's/,/\n/g' > out
97 for d in $*; do grep "$d(" out; done
98 for d in $*; do ! grep -v "$d(" out; done
99 return 0
102 save_dev_sum_()
104 mkfs.ext3 $1 > /dev/null &&
105 md5sum $1 > md5.$(basename $1)
108 check_dev_sum_()
110 md5sum $1 > md5.tmp && cmp md5.$(basename $1) md5.tmp
113 # ---------------------------------------------------------------------
114 # Initialize PVs and VGs
116 aux prepare_vg 5 80
118 # ---------------------------------------------------------------------
119 # Common environment setup/cleanup for each sub testcases
121 prepare_lvs_()
123 lvremove -ff $vg;
124 if dmsetup table|grep $vg; then
125 echo "ERROR: lvremove did leave some some mappings in DM behind!"
126 return 1
131 check_and_cleanup_lvs_()
133 lvs -a -o+devices $vg
134 lvremove -ff $vg
135 if dmsetup table|grep $vg; then
136 echo "ERROR: lvremove did leave some some mappings in DM behind!"
137 return 1
141 #COMM "check environment setup/cleanup"
142 prepare_lvs_
143 check_and_cleanup_lvs_
145 # ---------------------------------------------------------------------
146 # mirrored LV tests
148 # ---
149 # create
151 #COMM "create 2-way mirror with disklog from 3 PVs"
152 prepare_lvs_
153 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
154 mimages_are_redundant_ $vg $lv1
155 mirrorlog_is_on_ $vg/$lv1 $dev3
156 check_and_cleanup_lvs_
158 #COMM "create 2-way mirror with corelog from 2 PVs"
159 prepare_lvs_
160 lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
161 mimages_are_redundant_ $vg $lv1
162 check_and_cleanup_lvs_
164 #COMM "create 3-way mirror with disklog from 4 PVs"
165 prepare_lvs_
166 lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev4 $dev3:0-1
167 mimages_are_redundant_ $vg $lv1
168 mirrorlog_is_on_ $vg/$lv1 $dev3
169 check_and_cleanup_lvs_
171 #COMM "lvcreate --nosync is in 100% sync after creation (bz429342)"
172 prepare_lvs_
173 lvcreate -l2 -m1 --nosync -n $lv1 $vg $dev1 $dev2 $dev3:0-1 2>out
174 grep "New mirror won't be synchronised." out
175 lvs -o copy_percent --noheadings $vg/$lv1 |grep 100.00
176 check_and_cleanup_lvs_
178 # ---
179 # convert
181 #COMM "convert from linear to 2-way mirror"
182 prepare_lvs_
183 lvcreate -l2 -n $lv1 $vg $dev1
184 lvconvert -m+1 $vg/$lv1 $dev2 $dev3:0-1
185 mimages_are_redundant_ $vg $lv1
186 mirrorlog_is_on_ $vg/$lv1 $dev3
187 check_and_cleanup_lvs_
189 #COMM "convert from 2-way mirror to linear"
190 prepare_lvs_
191 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
192 lvconvert -m-1 $vg/$lv1
193 mimages_are_redundant_ $vg $lv1
194 check_and_cleanup_lvs_
196 for status in active inactive; do
197 # bz192865 lvconvert log of an inactive mirror lv
198 #COMM "convert from disklog to corelog"
199 prepare_lvs_
200 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
201 test $status = "inactive" && lvchange -an $vg/$lv1
202 yes | lvconvert --mirrorlog core $vg/$lv1
203 mimages_are_redundant_ $vg $lv1
204 check_and_cleanup_lvs_
206 #COMM "convert from corelog to disklog"
207 prepare_lvs_
208 lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
209 test $status = "inactive" && lvchange -an $vg/$lv1
210 lvconvert --mirrorlog disk $vg/$lv1 $dev3:0-1
211 mimages_are_redundant_ $vg $lv1
212 mirrorlog_is_on_ $vg/$lv1 $dev3
213 check_and_cleanup_lvs_
214 done
216 # ---
217 # resize
219 #COMM "extend 2-way mirror"
220 prepare_lvs_
221 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
222 lvchange -an $vg/$lv1
223 lvextend -l+2 $vg/$lv1
224 mimages_are_redundant_ $vg $lv1
225 mimages_are_contiguous_ $vg $lv1
226 check_and_cleanup_lvs_
228 #COMM "reduce 2-way mirror"
229 prepare_lvs_
230 lvcreate -l4 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
231 lvchange -an $vg/$lv1
232 lvreduce -l-2 $vg/$lv1
233 check_and_cleanup_lvs_
235 #COMM "extend 2-way mirror (cling if not contiguous)"
236 prepare_lvs_
237 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
238 lvcreate -l1 -n $lv2 $vg $dev1
239 lvcreate -l1 -n $lv3 $vg $dev2
240 lvchange -an $vg/$lv1
241 lvextend -l+2 $vg/$lv1
242 mimages_are_redundant_ $vg $lv1
243 mimages_are_clung_ $vg $lv1
244 check_and_cleanup_lvs_
246 # ---
247 # failure cases
249 #COMM "create 2-way mirror with disklog from 2 PVs"
250 prepare_lvs_
251 not lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2
252 # "(cleanup previous test)"
253 check_and_cleanup_lvs_
255 #COMM "convert linear to 2-way mirror with 1 PV"
256 prepare_lvs_
257 lvcreate -l2 -n $lv1 $vg $dev1
258 not lvconvert -m+1 --mirrorlog core $vg/$lv1 $dev1
259 # "(cleanup previous test)"
260 check_and_cleanup_lvs_
262 # ---
263 # resync
264 # FIXME: using dm-delay to properly check whether the resync really started
266 #COMM "force resync 2-way active mirror"
267 prepare_lvs_
268 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
269 mirrorlog_is_on_ $vg/$lv1 $dev3
270 yes | lvchange --resync $vg/$lv1
271 mirrorlog_is_on_ $vg/$lv1 $dev3
272 check_and_cleanup_lvs_
274 #COMM "force resync 2-way inactive mirror"
275 prepare_lvs_
276 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
277 lvchange -an $vg/$lv1
278 mirrorlog_is_on_ $vg/$lv1 $dev3
279 lvchange --resync $vg/$lv1
280 mirrorlog_is_on_ $vg/$lv1 $dev3
281 check_and_cleanup_lvs_
283 # ---------------------------------------------------------------------