summaryrefslogtreecommitdiff
path: root/test/shell/pvmove-basic.sh
blob: e95fc364cec1c6cb44d9b5ae9a7c154f14e5a69b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/bin/sh
# Copyright (C) 2008-2012 Red Hat, Inc. All rights reserved.
# Copyright (C) 2007 NEC Corporation
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

test_description="ensure that pvmove works with basic options"

. lib/test

which mkfs.ext2 || skip
which md5sum || skip

# ---------------------------------------------------------------------
# Utilities

lvdev_() {
  echo "$DM_DEV_DIR/$1/$2"
}

lv_is_on_() {
  local lv=$1 #allready vg/lv
  shift 1
  lvs -a -odevices --noheadings $lv | sed 's/,/\n/g' > out
#is on all specified devs
  for d in $*; do grep "$d(" out; done
#isn't on any other dev (we are set -e remember)
  for d in $*; do ! grep -v "$d(" out; done
  return 0
}

save_dev_sum_() {
  mkfs.ext2 $1 > /dev/null && md5sum $1 > md5.$(basename $1)
}

check_dev_sum_() {
  md5sum -c md5.$(basename $1)
}

create_vg_() {
  vgcreate -c n -s 128k $vg $(cat DEVICES)
}
# ---------------------------------------------------------------------
# Initialize PVs and VGs

#aux prepare_vg 5 30
aux prepare_pvs 5 5
create_vg_

# ---------------------------------------------------------------------
# Common environment setup/cleanup for each sub testcases
FIRST=""

prepare_lvs_() {
  lvcreate -l2 -n $lv1 $vg "$dev1"
    test -z "$FIRST" && lv_is_on_ $vg/$lv1 "$dev1"
  lvcreate -l9 -i3 -n $lv2 $vg "$dev2" "$dev3" "$dev4"
    test -z "$FIRST" && lv_is_on_ $vg/$lv2 "$dev2" "$dev3" "$dev4"
  lvextend -l+2 $vg/$lv1 "$dev2"
    test -z "$FIRST" && lv_is_on_ $vg/$lv1 "$dev1" "$dev2"
  lvextend -l+2 $vg/$lv1 "$dev3"
    test -z "$FIRST" && lv_is_on_ $vg/$lv1 "$dev1" "$dev2" "$dev3"
  lvextend -l+2 $vg/$lv1 "$dev1"
    test -z "$FIRST" && lv_is_on_ $vg/$lv1 "$dev1" "$dev2" "$dev3" "$dev1"
  lvcreate -l1 -n $lv3 $vg "$dev2"
    test -z "$FIRST" && lv_is_on_ $vg/$lv3 "$dev2"
  save_dev_sum_ $(lvdev_ $vg $lv1)
  save_dev_sum_ $(lvdev_ $vg $lv2)
  save_dev_sum_ $(lvdev_ $vg $lv3)
  if test -z "$FIRST" ; then
    get lv_field $vg/$lv1 devices > ${lv1}_devs
    get lv_field $vg/$lv2 devices > ${lv2}_devs
    get lv_field $vg/$lv3 devices > ${lv3}_devs
  fi
  FIRST=done
}

lv_not_changed_() {
  get lv_field $1 devices > out
  diff $(basename $1)_devs out
}

check_and_cleanup_lvs_() {
  lvs -a -o+devices $vg
  check_dev_sum_ $(lvdev_ $vg $lv1)
  check_dev_sum_ $(lvdev_ $vg $lv2)
  check_dev_sum_ $(lvdev_ $vg $lv3)
  lvs -a -o name $vg > out && ! grep ^pvmove out
  lvremove -ff $vg
  (dm_table | not grep $vg) || \
	die "ERROR: lvremove did leave some some mappings in DM behind!"
}

#COMM "check environment setup/cleanup"
prepare_lvs_
check_and_cleanup_lvs_

# ---------------------------------------------------------------------
# pvmove tests

# ---
# filter by LV

#COMM "only specified LV is moved: from pv2 to pv5 only for lv1"
prepare_lvs_
pvmove -i1 -n $vg/$lv1 "$dev2" "$dev5"
lv_is_on_ $vg/$lv1 "$dev1" "$dev5" "$dev3" "$dev1"
lv_not_changed_ $vg/$lv2
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

# ---
# segments in a LV

#COMM "the 1st seg of 3-segs LV is moved: from pv1 of lv1 to pv4"
prepare_lvs_
pvmove -i0 -n $vg/$lv1 "$dev1" "$dev4"
lv_is_on_ $vg/$lv1 "$dev4" "$dev2" "$dev3" "$dev4"
lv_not_changed_ $vg/$lv2
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "the 2nd seg of 3-segs LV is moved: from pv2 of lv1 to pv4"
prepare_lvs_
pvmove -i0 -n $vg/$lv1 "$dev2" "$dev4"
lv_is_on_ $vg/$lv1 "$dev1" "$dev4" "$dev3" "$dev1"
lv_not_changed_ $vg/$lv2
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "the 3rd seg of 3-segs LV is moved: from pv3 of lv1 to pv4"
prepare_lvs_
pvmove -i0 -n $vg/$lv1 "$dev3" "$dev4"
lv_is_on_ $vg/$lv1 "$dev1" "$dev2" "$dev4" "$dev1"
lv_not_changed_ $vg/$lv2
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

# ---
# multiple LVs matching

#COMM "1 out of 3 LVs is moved: from pv4 to pv5"
prepare_lvs_
pvmove -i0 "$dev4" "$dev5"
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev2" "$dev3" "$dev5"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "2 out of 3 LVs are moved: from pv3 to pv5"
prepare_lvs_
pvmove -i0 "$dev3" "$dev5"
lv_is_on_ $vg/$lv1 "$dev1" "$dev2" "$dev5" "$dev1"
lv_is_on_ $vg/$lv2 "$dev2" "$dev5" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "3 out of 3 LVs are moved: from pv2 to pv5"
prepare_lvs_
pvmove -i0 "$dev2" "$dev5"
lv_is_on_ $vg/$lv1 "$dev1" "$dev5" "$dev3" "$dev1"
lv_is_on_ $vg/$lv2 "$dev5" "$dev3" "$dev4"
lv_is_on_ $vg/$lv3 "$dev5"
check_and_cleanup_lvs_

# ---
# areas of striping

#COMM "move the 1st stripe: from pv2 of lv2 to pv1"
prepare_lvs_
pvmove -i0 -n $vg/$lv2 "$dev2" "$dev1"
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev1" "$dev3" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "move the 2nd stripe: from pv3 of lv2 to pv1"
prepare_lvs_
pvmove -i0 -n $vg/$lv2 "$dev3" "$dev1"
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev2" "$dev1" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "move the 3rd stripe: from pv4 of lv2 to pv1"
prepare_lvs_
pvmove -i0 -n $vg/$lv2 "$dev4" "$dev1"
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev2" "$dev3" "$dev1"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

# ---
# partial segment match (source segment splitted)

#COMM "match to the start of segment:from pv2:0-0 to pv5"
prepare_lvs_
pvmove -i0 "$dev2":0-0 "$dev5"
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev5" "$dev2" "$dev3" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "match to the middle of segment: from pv2:1-1 to pv5"
prepare_lvs_
pvmove -i0 "$dev2":1-1 "$dev5"
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev2" "$dev5" "$dev2" "$dev3" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "match to the end of segment: from pv2:2-2 to pv5"
prepare_lvs_
pvmove -i0 "$dev2":2-2 "$dev5"
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev2" "$dev5" "$dev3" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

# ---
# destination segment splitted

#COMM "no destination split: from pv2:0-2 to pv5"
prepare_lvs_
pvmove -i0 "$dev2":0-2 "$dev5"
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev5" "$dev3" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "destination split into 2: from pv2:0-2 to pv5:5-5 and pv4:5-6"
prepare_lvs_
pvmove -i0 --alloc anywhere "$dev2":0-2 "$dev5":5-5 "$dev4":5-6
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev5" "$dev4" "$dev3" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "destination split into 3: from pv2:0-2 to {pv3,4,5}:5-5"
prepare_lvs_
pvmove -i0 --alloc anywhere "$dev2":0-2 "$dev3":5-5 "$dev4":5-5 "$dev5":5-5
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev3" "$dev4" "$dev5" "$dev3" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

# ---
# alloc policy (anywhere, contiguous) with both success and failure cases

#COMM "alloc normal on same PV for source and destination: from pv3:0-2 to pv3:5-7"
prepare_lvs_
not pvmove -i0 "$dev3":0-2 "$dev3":5-7
# "(cleanup previous test)"
lv_not_changed_ $vg/$lv1
lv_not_changed_ $vg/$lv2
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "alloc anywhere on same PV for source and destination: from pv3:0-2 to pv3:5-7"
prepare_lvs_
pvmove -i0 --alloc anywhere "$dev3":0-2 "$dev3":5-7
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev2" "$dev3" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "alloc anywhere but better area available: from pv3:0-2 to pv3:5-7 or pv5:5-6,pv4:5-5"
prepare_lvs_
pvmove -i0 --alloc anywhere "$dev3":0-2 "$dev3":5-7 "$dev5":5-6 "$dev4":5-5
lv_not_changed_ $vg/$lv1
#lv_is_on_ $vg/$lv2 "$dev2" "$dev5" "$dev4" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "alloc contiguous but area not available: from pv2:0-2 to pv5:5-5 and pv4:5-6"
prepare_lvs_
not pvmove -i0 --alloc contiguous "$dev2":0-2 "$dev5":5-5 "$dev4":5-6
# "(cleanup previous test)"
lv_not_changed_ $vg/$lv1
lv_not_changed_ $vg/$lv2
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "alloc contiguous and contiguous area available: from pv2:0-2 to pv5:0-0,pv5:3-5 and pv4:5-6"
prepare_lvs_
pvmove -i0 --alloc contiguous "$dev2":0-2 "$dev5":0-0 "$dev5":3-5 "$dev4":5-6
lv_not_changed_ $vg/$lv1
lv_is_on_ $vg/$lv2 "$dev5" "$dev3" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

# ---
# multiple segments in a LV

#COMM "multiple source LVs: from pv3 to pv5"
prepare_lvs_
pvmove -i0 "$dev3" "$dev5"
lv_is_on_ $vg/$lv1 "$dev1" "$dev2" "$dev5"
lv_is_on_ $vg/$lv2 "$dev2" "$dev5" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

# ---
# move inactive LV

#COMM "move inactive LV: from pv2 to pv5"
prepare_lvs_
lvchange -an $vg/$lv1
lvchange -an $vg/$lv3
pvmove -i0 "$dev2" "$dev5"
lv_is_on_ $vg/$lv1 "$dev1" "$dev5" "$dev3"
lv_is_on_ $vg/$lv2 "$dev5" "$dev3" "$dev4"
lv_is_on_ $vg/$lv3 "$dev5"
check_and_cleanup_lvs_

# ---
# other failure cases

#COMM "no PEs to move: from pv3 to pv1"
prepare_lvs_
pvmove -i0 "$dev3" "$dev1"
not pvmove -i0 "$dev3" "$dev1"
# "(cleanup previous test)"
lv_is_on_ $vg/$lv1 "$dev1" "$dev2" "$dev1"
lv_is_on_ $vg/$lv2 "$dev2" "$dev1" "$dev4"
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "no space available: from pv2:0-0 to pv1:0-0"
prepare_lvs_
not pvmove -i0 "$dev2":0-0 "$dev1":0-0
# "(cleanup previous test)"
lv_not_changed_ $vg/$lv1
lv_not_changed_ $vg/$lv2
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM 'same source and destination: from pv1 to pv1'
prepare_lvs_
not pvmove -i0 "$dev1" "$dev1"
#"(cleanup previous test)"
lv_not_changed_ $vg/$lv1
lv_not_changed_ $vg/$lv2
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

#COMM "sum of specified destination PEs is large enough, but it includes source PEs and the free PEs are not enough"
prepare_lvs_
not pvmove --alloc anywhere "$dev1":0-2 "$dev1":0-2 "$dev5":0-0 2> err
#"(cleanup previous test)"
grep "Insufficient free space" err
lv_not_changed_ $vg/$lv1
lv_not_changed_ $vg/$lv2
lv_not_changed_ $vg/$lv3
check_and_cleanup_lvs_

# ---------------------------------------------------------------------

#COMM "pvmove abort"
prepare_lvs_
pvmove -i100 -b "$dev1" "$dev3"
pvmove --abort
check_and_cleanup_lvs_

#COMM "pvmove out of --metadatacopies 0 PV (bz252150)"
vgremove -ff $vg
pvcreate $(cat DEVICES)
pvcreate --metadatacopies 0 "$dev1" "$dev2"
create_vg_
lvcreate -l4 -n $lv1 $vg "$dev1"
pvmove "$dev1"

#COMM "pvmove fails activating mirror, properly restores state before pvmove"
dmsetup create $vg-pvmove0 --notable
not pvmove -i 1 "$dev2"
test $(dmsetup info --noheadings -c -o suspended $vg-$lv1) = "Active"
dmsetup remove $vg-pvmove0