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 pvmove works with basic options"
17 dmsetup_has_dm_devdir_support_ ||
exit 200
19 # ---------------------------------------------------------------------
27 local lv
=$1 #allready vg/lv
29 lvs
-a -odevices --noheadings $lv |
sed 's/,/\n/g' > out
30 #is on all specified devs
31 for d
in $
*; do grep "$d(" out
; done
32 #isn't on any other dev (we are set -e remember)
33 for d
in $
*; do ! grep -v "$d(" out
; done
38 mkfs.ext3
$1 > /dev
/null
&&
39 md5sum $1 > md5.$
(basename $1)
43 md5sum $1 > md5.tmp
&& cmp md5.$
(basename $1) md5.tmp
46 # ---------------------------------------------------------------------
47 # Initialize PVs and VGs
51 # ---------------------------------------------------------------------
52 # Common environment setup/cleanup for each sub testcases
55 lvcreate
-l2 -n $lv1 $vg $dev1
56 lv_is_on_
$vg/$lv1 $dev1
57 lvcreate
-l9 -i3 -n $lv2 $vg $dev2 $dev3 $dev4
58 lv_is_on_
$vg/$lv2 $dev2 $dev3 $dev4
59 lvextend
-l+2 $vg/$lv1 $dev2
60 lv_is_on_
$vg/$lv1 $dev1 $dev2
61 lvextend
-l+2 $vg/$lv1 $dev3
62 lv_is_on_
$vg/$lv1 $dev1 $dev2 $dev3
63 lvextend
-l+2 $vg/$lv1 $dev1
64 lv_is_on_
$vg/$lv1 $dev1 $dev2 $dev3 $dev1
65 lvcreate
-l1 -n $lv3 $vg $dev2
66 lv_is_on_
$vg/$lv3 $dev2
67 save_dev_sum_ $
(lvdev_
$vg $lv1)
68 save_dev_sum_ $
(lvdev_
$vg $lv2)
69 save_dev_sum_ $
(lvdev_
$vg $lv3)
70 lvs
-a -o devices
--noheadings $vg/$lv1 > ${lv1}_devs
71 lvs
-a -o devices
--noheadings $vg/$lv2 > ${lv2}_devs
72 lvs
-a -o devices
--noheadings $vg/$lv3 > ${lv3}_devs
76 lvs
-a -o devices
--noheadings $1 > out
77 diff $
(basename $1)_devs out
80 check_and_cleanup_lvs_
() {
82 check_dev_sum_ $
(lvdev_
$vg $lv1)
83 check_dev_sum_ $
(lvdev_
$vg $lv2)
84 check_dev_sum_ $
(lvdev_
$vg $lv3)
85 lvs
-a -o name
$vg > out
&& ! grep ^pvmove out
87 if ! dmsetup table|not
grep $vg; then
88 echo "ERROR: lvremove did leave some some mappings in DM behind!" &&
94 #COMM "check environment setup/cleanup"
96 check_and_cleanup_lvs_
98 # ---------------------------------------------------------------------
104 #COMM "only specified LV is moved: from pv2 to pv5 only for lv1"
106 pvmove
-i1 -n $vg/$lv1 $dev2 $dev5
107 lv_is_on_
$vg/$lv1 $dev1 $dev5 $dev3 $dev1
108 lv_not_changed_
$vg/$lv2
109 lv_not_changed_
$vg/$lv3
110 check_and_cleanup_lvs_
115 #COMM "the 1st seg of 3-segs LV is moved: from pv1 of lv1 to pv4"
117 pvmove
-i1 -n $vg/$lv1 $dev1 $dev4
118 lv_is_on_
$vg/$lv1 $dev4 $dev2 $dev3 $dev4
119 lv_not_changed_
$vg/$lv2
120 lv_not_changed_
$vg/$lv3
121 check_and_cleanup_lvs_
123 #COMM "the 2nd seg of 3-segs LV is moved: from pv2 of lv1 to pv4"
125 pvmove
-i1 -n $vg/$lv1 $dev2 $dev4
126 lv_is_on_
$vg/$lv1 $dev1 $dev4 $dev3 $dev1
127 lv_not_changed_
$vg/$lv2
128 lv_not_changed_
$vg/$lv3
129 check_and_cleanup_lvs_
131 #COMM "the 3rd seg of 3-segs LV is moved: from pv3 of lv1 to pv4"
133 pvmove
-i1 -n $vg/$lv1 $dev3 $dev4
134 lv_is_on_
$vg/$lv1 $dev1 $dev2 $dev4 $dev1
135 lv_not_changed_
$vg/$lv2
136 lv_not_changed_
$vg/$lv3
137 check_and_cleanup_lvs_
140 # multiple LVs matching
142 #COMM "1 out of 3 LVs is moved: from pv4 to pv5"
144 pvmove
-i1 $dev4 $dev5
145 lv_not_changed_
$vg/$lv1
146 lv_is_on_
$vg/$lv2 $dev2 $dev3 $dev5
147 lv_not_changed_
$vg/$lv3
148 check_and_cleanup_lvs_
150 #COMM "2 out of 3 LVs are moved: from pv3 to pv5"
152 pvmove
-i1 $dev3 $dev5
153 lv_is_on_
$vg/$lv1 $dev1 $dev2 $dev5 $dev1
154 lv_is_on_
$vg/$lv2 $dev2 $dev5 $dev4
155 lv_not_changed_
$vg/$lv3
156 check_and_cleanup_lvs_
158 #COMM "3 out of 3 LVs are moved: from pv2 to pv5"
160 pvmove
-i1 $dev2 $dev5
161 lv_is_on_
$vg/$lv1 $dev1 $dev5 $dev3 $dev1
162 lv_is_on_
$vg/$lv2 $dev5 $dev3 $dev4
163 lv_is_on_
$vg/$lv3 $dev5
164 check_and_cleanup_lvs_
169 #COMM "move the 1st stripe: from pv2 of lv2 to pv1"
171 pvmove
-i1 -n $vg/$lv2 $dev2 $dev1
172 lv_not_changed_
$vg/$lv1
173 lv_is_on_
$vg/$lv2 $dev1 $dev3 $dev4
174 lv_not_changed_
$vg/$lv3
175 check_and_cleanup_lvs_
177 #COMM "move the 2nd stripe: from pv3 of lv2 to pv1"
179 pvmove
-i1 -n $vg/$lv2 $dev3 $dev1
180 lv_not_changed_
$vg/$lv1
181 lv_is_on_
$vg/$lv2 $dev2 $dev1 $dev4
182 lv_not_changed_
$vg/$lv3
183 check_and_cleanup_lvs_
185 #COMM "move the 3rd stripe: from pv4 of lv2 to pv1"
187 pvmove
-i1 -n $vg/$lv2 $dev4 $dev1
188 lv_not_changed_
$vg/$lv1
189 lv_is_on_
$vg/$lv2 $dev2 $dev3 $dev1
190 lv_not_changed_
$vg/$lv3
191 check_and_cleanup_lvs_
194 # partial segment match (source segment splitted)
196 #COMM "match to the start of segment:from pv2:0-0 to pv5"
198 pvmove
-i1 $dev2:0-0 $dev5
199 lv_not_changed_
$vg/$lv1
200 lv_is_on_
$vg/$lv2 $dev5 $dev2 $dev3 $dev4
201 lv_not_changed_
$vg/$lv3
202 check_and_cleanup_lvs_
204 #COMM "match to the middle of segment: from pv2:1-1 to pv5"
206 pvmove
-i1 $dev2:1-1 $dev5
207 lv_not_changed_
$vg/$lv1
208 lv_is_on_
$vg/$lv2 $dev2 $dev5 $dev2 $dev3 $dev4
209 lv_not_changed_
$vg/$lv3
210 check_and_cleanup_lvs_
212 #COMM "match to the end of segment: from pv2:2-2 to pv5"
214 pvmove
-i1 $dev2:2-2 $dev5
215 lv_not_changed_
$vg/$lv1
216 lv_is_on_
$vg/$lv2 $dev2 $dev5 $dev3 $dev4
217 lv_not_changed_
$vg/$lv3
218 check_and_cleanup_lvs_
221 # destination segment splitted
223 #COMM "no destination split: from pv2:0-2 to pv5"
225 pvmove
-i1 $dev2:0-2 $dev5
226 lv_not_changed_
$vg/$lv1
227 lv_is_on_
$vg/$lv2 $dev5 $dev3 $dev4
228 lv_not_changed_
$vg/$lv3
229 check_and_cleanup_lvs_
231 #COMM "destination split into 2: from pv2:0-2 to pv5:5-5 and pv4:5-6"
233 pvmove
-i1 $dev2:0-2 $dev5:5-5 $dev4:5-6
234 lv_not_changed_
$vg/$lv1
235 lv_is_on_
$vg/$lv2 $dev5 $dev4 $dev3 $dev4
236 lv_not_changed_
$vg/$lv3
237 check_and_cleanup_lvs_
239 #COMM "destination split into 3: from pv2:0-2 to {pv3,4,5}:5-5"
241 pvmove
-i1 $dev2:0-2 $dev3:5-5 $dev4:5-5 $dev5:5-5
242 lv_not_changed_
$vg/$lv1
243 lv_is_on_
$vg/$lv2 $dev3 $dev4 $dev5 $dev3 $dev4
244 lv_not_changed_
$vg/$lv3
245 check_and_cleanup_lvs_
248 # alloc policy (anywhere, contiguous) with both success and failure cases
250 #COMM "alloc normal on same PV for source and destination: from pv3:0-2 to pv3:5-7"
252 not pvmove
-i1 $dev3:0-2 $dev3:5-7
253 # "(cleanup previous test)"
254 lv_not_changed_
$vg/$lv1
255 lv_not_changed_
$vg/$lv2
256 lv_not_changed_
$vg/$lv3
257 check_and_cleanup_lvs_
259 #COMM "alloc anywhere on same PV for source and destination: from pv3:0-2 to pv3:5-7"
261 pvmove
-i1 --alloc anywhere
$dev3:0-2 $dev3:5-7
262 lv_not_changed_
$vg/$lv1
263 lv_is_on_
$vg/$lv2 $dev2 $dev3 $dev4
264 lv_not_changed_
$vg/$lv3
265 check_and_cleanup_lvs_
267 #COMM "alloc anywhere but better area available: from pv3:0-2 to pv3:5-7 or pv5:5-6,pv4:5-5"
269 pvmove
-i1 --alloc anywhere
$dev3:0-2 $dev3:5-7 $dev5:5-6 $dev4:5-5
270 lv_not_changed_
$vg/$lv1
271 lv_is_on_
$vg/$lv2 $dev2 $dev5 $dev4 $dev4
272 lv_not_changed_
$vg/$lv3
273 check_and_cleanup_lvs_
275 #COMM "alloc contiguous but area not available: from pv2:0-2 to pv5:5-5 and pv4:5-6"
277 not pvmove
-i1 --alloc contiguous
$dev2:0-2 $dev5:5-5 $dev4:5-6
278 # "(cleanup previous test)"
279 lv_not_changed_
$vg/$lv1
280 lv_not_changed_
$vg/$lv2
281 lv_not_changed_
$vg/$lv3
282 check_and_cleanup_lvs_
284 #COMM "alloc contiguous and contiguous area available: from pv2:0-2 to pv5:0-0,pv5:3-5 and pv4:5-6"
286 pvmove
-i1 --alloc contiguous
$dev2:0-2 $dev5:0-0 $dev5:3-5 $dev4:5-6
287 lv_not_changed_
$vg/$lv1
288 lv_is_on_
$vg/$lv2 $dev5 $dev3 $dev4
289 lv_not_changed_
$vg/$lv3
290 check_and_cleanup_lvs_
293 # multiple segments in a LV
295 #COMM "multiple source LVs: from pv3 to pv5"
297 pvmove
-i1 $dev3 $dev5
298 lv_is_on_
$vg/$lv1 $dev1 $dev2 $dev5
299 lv_is_on_
$vg/$lv2 $dev2 $dev5 $dev4
300 lv_not_changed_
$vg/$lv3
301 check_and_cleanup_lvs_
306 #COMM "move inactive LV: from pv2 to pv5"
308 lvchange
-an $vg/$lv1
309 lvchange
-an $vg/$lv3
310 pvmove
-i1 $dev2 $dev5
311 lv_is_on_
$vg/$lv1 $dev1 $dev5 $dev3
312 lv_is_on_
$vg/$lv2 $dev5 $dev3 $dev4
313 lv_is_on_
$vg/$lv3 $dev5
314 check_and_cleanup_lvs_
317 # other failure cases
319 #COMM "no PEs to move: from pv3 to pv1"
321 pvmove
-i1 $dev3 $dev1
322 not pvmove
-i1 $dev3 $dev1
323 # "(cleanup previous test)"
324 lv_is_on_
$vg/$lv1 $dev1 $dev2 $dev1
325 lv_is_on_
$vg/$lv2 $dev2 $dev1 $dev4
326 lv_not_changed_
$vg/$lv3
327 check_and_cleanup_lvs_
329 #COMM "no space available: from pv2:0-0 to pv1:0-0"
331 not pvmove
-i1 $dev2:0-0 $dev1:0-0
332 # "(cleanup previous test)"
333 lv_not_changed_
$vg/$lv1
334 lv_not_changed_
$vg/$lv2
335 lv_not_changed_
$vg/$lv3
336 check_and_cleanup_lvs_
338 #COMM 'same source and destination: from pv1 to pv1'
340 not pvmove
-i1 $dev1 $dev1
341 #"(cleanup previous test)"
342 lv_not_changed_
$vg/$lv1
343 lv_not_changed_
$vg/$lv2
344 lv_not_changed_
$vg/$lv3
345 check_and_cleanup_lvs_
347 #COMM "sum of specified destination PEs is large enough, but it includes source PEs and the free PEs are not enough"
349 not pvmove
--alloc anywhere
$dev1:0-2 $dev1:0-2 $dev5:0-0 2> err
350 #"(cleanup previous test)"
351 grep "Insufficient free space" err
352 lv_not_changed_
$vg/$lv1
353 lv_not_changed_
$vg/$lv2
354 lv_not_changed_
$vg/$lv3
355 check_and_cleanup_lvs_
357 # ---------------------------------------------------------------------
361 pvmove
-i100 -b $dev1 $dev3
363 check_and_cleanup_lvs_
365 #COMM "pvmove out of --metadatacopies 0 PV (bz252150)"
368 pvcreate
--metadatacopies 0 $dev1 $dev2
370 lvcreate
-l4 -n $lv1 $vg $dev1
373 #COMM "pvmove fails activating mirror, properly restores state before pvmove"
374 dmsetup create
"$vg-pvmove0" --notable
375 not pvmove
-i 1 $dev2
376 test $
(dmsetup info
--noheadings -c -o suspended
"$vg-$lv1") = "Active"
377 dmsetup remove
"$vg-pvmove0"