Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / test / t-mirror-lvconvert.sh
bloba699716b2282ee0eae43080298bb9e1e9fe0a8cd
1 # Copyright (C) 2008 Red Hat, Inc. All rights reserved.
2 # Copyright (C) 2007 NEC Corporation
4 # This copyrighted material is made available to anyone wishing to use,
5 # modify, copy, or redistribute it subject to the terms and conditions
6 # of the GNU General Public License v.2.
8 # You should have received a copy of the GNU General Public License
9 # along with this program; if not, write to the Free Software Foundation,
10 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
12 . ./test-utils.sh
14 dmsetup_has_dm_devdir_support_ || exit 200
16 mimages_are_redundant_ ()
18 local vg=$1
19 local lv=$vg/$2
20 local i
22 rm -f out
23 for i in $(lvs -odevices --noheadings $lv | sed 's/([^)]*)//g; s/,/ /g'); do
24 lvs -a -odevices --noheadings $vg/$i | sed 's/([^)]*)//g; s/,/ /g' | \
25 sort | uniq >> out
26 done
28 # if any duplication is found, it's not redundant
29 sort out | uniq -d | grep . && return 1
31 return 0
34 lv_is_contiguous_ ()
36 local lv=$1
38 # if the lv has multiple segments, it's not contiguous
39 [ $(lvs -a --segments --noheadings $lv | wc -l) -ne 1 ] && return 1
41 return 0
44 mimages_are_contiguous_ ()
46 local vg=$1
47 local lv=$vg/$2
48 local i
50 for i in $(lvs -odevices --noheadings $lv | sed 's/([^)]*)//g; s/,/ /g'); do
51 lv_is_contiguous_ $vg/$i || return 1
52 done
54 return 0
57 mirrorlog_is_on_()
59 local lv="$1"_mlog
60 shift 1
61 lvs -a -odevices --noheadings $lv | sed 's/,/\n/g' > out
62 for d in $*; do grep "$d(" out || return 1; done
63 for d in $*; do grep -v "$d(" out > out2 || true; mv out2 out; done
64 grep . out && return 1
65 return 0
68 save_dev_sum_()
70 mkfs.ext3 $1 > /dev/null &&
71 md5sum $1 > md5.$(basename $1)
74 check_dev_sum_()
76 md5sum $1 > md5.tmp && cmp md5.$(basename $1) md5.tmp
79 check_mirror_count_()
81 local lv=$1
82 local mirrors=$2
83 [ "$mirrors" -eq "$(lvs --noheadings -ostripes $lv)" ]
86 check_mirror_log_()
88 local lv=$1
89 local mlog=$(lvs --noheadings -omirror_log $lv | sed -e 's/ //g')
90 [ "$(basename $lv)_mlog" = "$mlog" ]
93 wait_conversion_()
95 local lv=$1
96 while (lvs --noheadings -oattr "$lv" | grep -q '^ *c'); do sleep 1; done
99 check_no_tmplvs_()
101 local lv=$1
102 lvs -a --noheadings -oname $(dirname $lv) > out
103 ! grep tmp out
106 aux prepare_vg 5
108 # ---------------------------------------------------------------------
109 # Common environment setup/cleanup for each sub testcases
111 prepare_lvs_()
113 lvremove -ff $vg
114 if dmsetup table|grep $vg; then
115 echo "ERROR: lvremove did leave some some mappings in DM behind!"
116 return 1
121 check_and_cleanup_lvs_()
123 lvs -a -o+devices $vg
124 lvremove -ff $vg
125 if dmsetup table|grep $vg; then
126 echo "ERROR: lvremove did leave some some mappings in DM behind!"
127 return 1
131 prepare_lvs_
132 check_and_cleanup_lvs_
134 # ---------------------------------------------------------------------
135 # mirrored LV tests
137 # ---
138 # add mirror to mirror
140 # add 1 mirror
141 prepare_lvs_
142 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
143 check_mirror_count_ $vg/$lv1 2
144 check_mirror_log_ $vg/$lv1
145 lvconvert -m+1 -i1 $vg/$lv1 $dev4
146 check_no_tmplvs_ $vg/$lv1
147 check_mirror_count_ $vg/$lv1 3
148 mimages_are_redundant_ $vg $lv1
149 mirrorlog_is_on_ $vg/$lv1 $dev3
150 check_and_cleanup_lvs_
152 # add 2 mirrors
153 prepare_lvs_
154 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
155 check_mirror_count_ $vg/$lv1 2
156 check_mirror_log_ $vg/$lv1
157 lvconvert -m+2 -i1 $vg/$lv1 $dev4 $dev5
158 check_no_tmplvs_ $vg/$lv1
159 check_mirror_count_ $vg/$lv1 4
160 mimages_are_redundant_ $vg $lv1
161 mirrorlog_is_on_ $vg/$lv1 $dev3
162 check_and_cleanup_lvs_
164 # add 1 mirror to core log mirror
165 prepare_lvs_
166 lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
167 check_mirror_count_ $vg/$lv1 2
168 not check_mirror_log_ $vg/$lv1
169 lvconvert -m+1 -i1 --mirrorlog core $vg/$lv1 $dev4
170 check_no_tmplvs_ $vg/$lv1
171 check_mirror_count_ $vg/$lv1 3
172 not check_mirror_log_ $vg/$lv1
173 mimages_are_redundant_ $vg $lv1
174 check_and_cleanup_lvs_
176 # add 2 mirrors to core log mirror"
177 prepare_lvs_
178 lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
179 check_mirror_count_ $vg/$lv1 2
180 not check_mirror_log_ $vg/$lv1
181 lvconvert -m+2 -i1 --mirrorlog core $vg/$lv1 $dev4 $dev5
182 check_no_tmplvs_ $vg/$lv1
183 check_mirror_count_ $vg/$lv1 4
184 not check_mirror_log_ $vg/$lv1
185 mimages_are_redundant_ $vg $lv1
186 check_and_cleanup_lvs_
188 # ---
189 # add to converting mirror
191 # add 1 mirror then add 1 more mirror during conversion
192 prepare_lvs_
193 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
194 check_mirror_count_ $vg/$lv1 2
195 check_mirror_log_ $vg/$lv1
196 lvconvert -m+1 -b $vg/$lv1 $dev4
197 lvconvert -m+1 -i3 $vg/$lv1 $dev5
198 check_no_tmplvs_ $vg/$lv1
199 check_mirror_count_ $vg/$lv1 4
200 mimages_are_redundant_ $vg $lv1
201 mirrorlog_is_on_ $vg/$lv1 $dev3
202 check_and_cleanup_lvs_
204 # ---
205 # add mirror and disk log
207 # "add 1 mirror and disk log"
208 prepare_lvs_
209 lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
210 check_mirror_count_ $vg/$lv1 2
211 not check_mirror_log_ $vg/$lv1
212 lvconvert -m+1 --mirrorlog disk -i1 $vg/$lv1 $dev4 $dev3:0-1
213 check_no_tmplvs_ $vg/$lv1
214 check_mirror_count_ $vg/$lv1 3
215 check_mirror_log_ $vg/$lv1
216 mimages_are_redundant_ $vg $lv1
217 mirrorlog_is_on_ $vg/$lv1 $dev3
218 check_and_cleanup_lvs_
220 # ---
221 # check polldaemon restarts
223 # convert inactive mirror and start polling
224 prepare_lvs_
225 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
226 check_mirror_count_ $vg/$lv1 2
227 lvchange -an $vg/$lv1
228 lvconvert -m+1 $vg/$lv1 $dev4
229 lvchange -ay $vg/$lv1
230 wait_conversion_ $vg/$lv1
231 lvs -a
232 check_no_tmplvs_ $vg/$lv1
233 check_and_cleanup_lvs_
235 # ---------------------------------------------------------------------
236 # removal during conversion
238 # "remove newly added mirror"
239 prepare_lvs_
240 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
241 check_mirror_count_ $vg/$lv1 2
242 check_mirror_log_ $vg/$lv1
243 lvconvert -m+1 -b $vg/$lv1 $dev4
244 lvconvert -m-1 $vg/$lv1 $dev4
245 wait_conversion_ $vg/$lv1
246 check_no_tmplvs_ $vg/$lv1
247 check_mirror_count_ $vg/$lv1 2
248 mimages_are_redundant_ $vg $lv1
249 mirrorlog_is_on_ $vg/$lv1 $dev3
250 check_and_cleanup_lvs_
252 # "remove one of newly added mirrors"
253 prepare_lvs_
254 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
255 check_mirror_count_ $vg/$lv1 2
256 check_mirror_log_ $vg/$lv1
257 lvconvert -m+2 -b $vg/$lv1 $dev4 $dev5
258 lvconvert -m-1 $vg/$lv1 $dev4
259 lvconvert -i1 $vg/$lv1
260 wait_conversion_ $vg/$lv1
261 check_no_tmplvs_ $vg/$lv1
262 check_mirror_count_ $vg/$lv1 3
263 mimages_are_redundant_ $vg $lv1
264 mirrorlog_is_on_ $vg/$lv1 $dev3
265 check_and_cleanup_lvs_
267 # "remove from original mirror (the original is still mirror)"
268 prepare_lvs_
269 lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev5 $dev3:0-1
270 check_mirror_count_ $vg/$lv1 3
271 check_mirror_log_ $vg/$lv1
272 lvconvert -m+1 -b $vg/$lv1 $dev4
273 lvconvert -m-1 $vg/$lv1 $dev2
274 lvconvert -i1 $vg/$lv1
275 wait_conversion_ $vg/$lv1
276 check_no_tmplvs_ $vg/$lv1
277 check_mirror_count_ $vg/$lv1 3
278 mimages_are_redundant_ $vg $lv1
279 mirrorlog_is_on_ $vg/$lv1 $dev3
280 check_and_cleanup_lvs_
282 # "remove from original mirror (the original becomes linear)"
283 prepare_lvs_
284 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
285 check_mirror_count_ $vg/$lv1 2
286 check_mirror_log_ $vg/$lv1
287 lvconvert -m+1 -b $vg/$lv1 $dev4
288 lvconvert -m-1 $vg/$lv1 $dev2
289 lvconvert -i1 $vg/$lv1
290 wait_conversion_ $vg/$lv1
291 check_no_tmplvs_ $vg/$lv1
292 check_mirror_count_ $vg/$lv1 2
293 mimages_are_redundant_ $vg $lv1
294 mirrorlog_is_on_ $vg/$lv1 $dev3
295 check_and_cleanup_lvs_
297 # ---------------------------------------------------------------------
299 # "rhbz440405: lvconvert -m0 incorrectly fails if all PEs allocated"
300 prepare_lvs_
301 lvcreate -l`pvs --noheadings -ope_count $dev1` -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
302 check_mirror_count_ $vg/$lv1 2
303 check_mirror_log_ $vg/$lv1
304 lvconvert -m0 $vg/$lv1 $dev1
305 check_no_tmplvs_ $vg/$lv1
306 check_mirror_count_ $vg/$lv1 1
307 check_and_cleanup_lvs_
309 # "rhbz264241: lvm mirror doesn't lose it's "M" --nosync attribute after being down and the up converted"
310 prepare_lvs_
311 lvcreate -l2 -m1 -n$lv1 --nosync $vg
312 lvconvert -m0 $vg/$lv1
313 lvconvert -m1 $vg/$lv1
314 lvs --noheadings -o attr $vg/$lv1 | grep '^ *m'
315 check_and_cleanup_lvs_
317 # lvconvert from linear (on multiple PVs) to mirror
318 prepare_lvs_
319 lvcreate -l 8 -n $lv1 $vg $dev1:0-3 $dev2:0-3
320 lvconvert -m1 $vg/$lv1
321 check_mirror_count_ $vg/$lv1 2
322 check_mirror_log_ $vg/$lv1
323 check_and_cleanup_lvs_
325 # BZ 463272: disk log mirror convert option is lost if downconvert option is also given
326 prepare_lvs_
327 lvcreate -l1 -m2 --corelog -n $lv1 $vg
328 lvconvert -m1 --mirrorlog disk $vg/$lv1
329 check_mirror_log_ $vg/$lv1