summaryrefslogtreecommitdiff
path: root/test/shell/process-each-duplicate-pvs.sh
blob: f3063ab39d736648ae8ba098790d907dbb0b86cc (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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
#!/usr/bin/env bash

# Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
#
# 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.

test_description='Test duplicate PVs'

SKIP_WITH_LVMPOLLD=1
SKIP_WITH_CLVMD=1

# This test should work with real device ids (not devnames).
# When PVs are being overwritten by the test, the devices file is
# excluding them since with idtype=devname the devices file falls
# back to including devs based on PVIDs in the devices file,
# but the 'dd' is clobbering the PVIDs so those devs aren't included
# so the 'pvs' commands below don't report them. 
# In general this is better behavior, but needs to be tested
# with proper device ids.
SKIP_WITH_DEVICES_FILE=1

. lib/inittest

aux prepare_devs 6 16

# The LV-using-PV tests (DEV_USED_FOR_LV, where a PV is
# preferred if an active LV is using it) depend on sysfs
# info that is not available in RHEL5 kernels.
aux driver_at_least 4 15 || skip

aux lvmconf 'devices/allow_changes_with_duplicate_pvs = 0'

pvcreate "$dev1"
pvcreate "$dev2"
vgcreate $SHARED $vg1 "$dev1"
vgcreate $SHARED $vg2 "$dev2"
pvresize --setphysicalvolumesize 8m -y "$dev2"
lvcreate -an -l1 -n $lv1 $vg1

# Both devs are shown and used by the VG

pvs 2>&1 | tee out

grep "$dev1" out
grep "$dev2" out
grep "$dev1" out | grep $vg1
grep "$dev2" out | grep $vg2
check pv_field "$dev1" pv_allocatable "allocatable"
check pv_field "$dev2" pv_allocatable "allocatable"
not grep WARNING out

UUID1=$(get pv_field "$dev1" uuid)
UUID2=$(get pv_field "$dev2" uuid)

SIZE1=$(get pv_field "$dev1" dev_size)
SIZE2=$(get pv_field "$dev2" dev_size)

MINOR1=$(get pv_field "$dev1" minor)
MINOR2=$(get pv_field "$dev2" minor)

check pv_field "$dev1" dev_size "$SIZE1"
check pv_field "$dev2" dev_size "$SIZE2"

# Copy dev1 over dev2.
dd if="$dev1" of="$dev2" bs=1M iflag=direct oflag=direct,sync
#pvscan --cache

# The single preferred dev is shown from 'pvs'.
pvs -o+uuid,duplicate 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

# Don't know yet if dev1 or dev2 is preferred, so count just one is.
test "$(grep -c "$vg1" main)" -eq 1
test "$(grep -c "$UUID1" main)" -eq 1
not grep duplicate main
not grep $vg2 main
not grep $UUID2 main

grep "Not using device" warn
grep "prefers device" warn

# Find which is the preferred dev and which is the duplicate.
PV=$(pvs --noheadings -o name -S uuid="$UUID1" | xargs)
if [ "$PV" = "$dev1" ]; then
	DUP=$dev2
else
	DUP=$dev1
fi

echo "PV is $PV"
echo "DUP is $DUP"

grep "$PV" main
not grep "$DUP" main

# Repeat above checking preferred/dup in output
pvs 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$PV" main
not grep "$DUP" main

# The duplicate dev is included in 'pvs -a'
pvs -a -o+uuid,duplicate 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$dev1" main
grep "$dev2" main
grep $PV main
grep $DUP main
test "$(grep -c duplicate main)" -eq 1
grep $DUP main | grep duplicate
not grep $vg2 main
not grep $UUID2 main
grep "$dev1" main | grep $vg1
grep "$dev2" main | grep $vg1
grep "$dev1" main | grep $UUID1
grep "$dev2" main | grep $UUID1

grep "Not using device" warn
grep "prefers device" warn

#
# Passing a dev name arg always includes that dev.
#

pvs -o+uuid "$dev1" 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$dev1" main
not grep "$dev2" main
grep "$UUID1" main
grep "$vg1" main
grep "Not using device" warn
grep "prefers device" warn

pvs -o+uuid "$dev2" 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$dev2" main
not grep "$dev1" main
grep "$UUID1" main
grep "$vg1" main
grep "Not using device" warn
grep "prefers device" warn

pvs -o+uuid,duplicate "$dev1" "$dev2" 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$dev1" main
grep "$dev2" main
grep "$dev1" main | grep $vg1
grep "$dev2" main | grep $vg1
grep "$dev1" main | grep $UUID1
grep "$dev2" main | grep $UUID1
test "$(grep -c duplicate main)" -eq 1
grep $DUP main | grep duplicate

#
# Test specific report fields for each dev.
#

pvs --noheadings -o vg_name,vg_uuid "$dev1" 2>&1 | tee out1
pvs --noheadings -o vg_name,vg_uuid "$dev2" 2>&1 | tee out2

grep -v WARNING out1 > main1 || true
grep -v WARNING out2 > main2 || true
diff main1 main2
rm out1 out2 main1 main2 || true

check pv_field "$dev1" pv_in_use "used"
check pv_field "$dev2" pv_in_use "used"

check pv_field "$PV"  pv_allocatable "allocatable"
check pv_field "$DUP" pv_allocatable ""

check pv_field "$PV"  pv_duplicate ""
check pv_field "$DUP" pv_duplicate "duplicate"

pvs --noheadings -o name,pv_allocatable "$dev1" "$dev2" 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$PV" main
grep "$DUP" main
grep "$dev1" main
grep "$dev2" main
test "$(grep -c allocatable main)" -eq 1

pvs --noheadings -o name,pv_duplicate "$dev1" "$dev2" 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$PV" main
grep "$DUP" main
grep "$dev1" main
grep "$dev2" main
test "$(grep -c duplicate main)" -eq 1

#
# A filter can be used to show only one.
#

pvs --config "devices { filter=[ \"a|$dev2|\", \"r|.*|\" ] }" 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

not grep "$dev1" main
grep "$dev2" main

not grep "Not using device" warn
not grep "prefers device" warn


pvs --config "devices { filter=[ \"a|$dev1|\", \"r|.*|\"] }" 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$dev1" main
not grep "$dev2" main

not grep "Not using device" warn
not grep "prefers device" warn

# PV size and minor is still reported correctly for each.

check pv_field "$dev1" dev_size "$SIZE1"
check pv_field "$dev2" dev_size "$SIZE2"

check pv_field "$dev1" minor "$MINOR1"
check pv_field "$dev2" minor "$MINOR2"

# With allow_changes_with_duplicate_pvs=0, a VG with duplicate devs
# cannot be modified or activated.

not lvcreate -an -l1 -n $lv2 $vg1
not lvremove $vg1/$lv1
not lvchange -ay $vg1/$lv1
not vgremove $vg1


# With allow_changes_with_duplicate_pvs=1, changes above are permitted.

aux lvmconf 'devices/allow_changes_with_duplicate_pvs = 1'

lvcreate -an -l1 -n $lv2 $vg1
lvremove $vg1/$lv1
lvchange -ay $vg1/$lv2
lvchange -an $vg1/$lv2
lvremove $vg1/$lv2
vgremove -f $vg1
pvremove -ff -y "$dev1"
pvremove -ff -y "$dev2"


# dev3 and dev4 are copies, orphans

pvcreate "$dev3"
pvcreate "$dev4"
pvresize --setphysicalvolumesize 8m -y "$dev4"

UUID3=$(get pv_field "$dev3" uuid)
UUID4=$(get pv_field "$dev4" uuid)

SIZE3=$(get pv_field "$dev3" dev_size)
SIZE4=$(get pv_field "$dev4" dev_size)

check pv_field "$dev3" dev_size "$SIZE3"
check pv_field "$dev4" dev_size "$SIZE4"

pvs 2>&1 | tee out

grep "$dev3" out
grep "$dev4" out

dd if="$dev3" of="$dev4" bs=1M iflag=direct oflag=direct,sync
#pvscan --cache

# One appears with 'pvs'

pvs -o+uuid 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

test "$(grep -c "$UUID3" main)" -eq 1
not grep "$UUID4" main

grep "Not using device" warn
grep "prefers device" warn

# Both appear with 'pvs -a'

pvs -a -o+uuid 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

test "$(grep -c "$UUID3" main)" -eq 2

grep "$dev3" main
grep "$dev4" main

grep $UUID3 main
not grep $UUID4 main

grep "Not using device" warn
grep "prefers device" warn

# Show each dev individually and both together

pvs -o+uuid "$dev3" 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$dev3" main
not grep "$dev4" main

grep "Not using device" warn
grep "prefers device" warn

pvs -o+uuid "$dev4" 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

not grep "$dev3" main
grep "$dev4" main

grep "Not using device" warn
grep "prefers device" warn

pvs -o+uuid "$dev3" "$dev4" 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$dev3" main
grep "$dev4" main

grep "Not using device" warn
grep "prefers device" warn

# Same sizes shown.

check pv_field "$dev3" dev_size "$SIZE3"
check pv_field "$dev4" dev_size "$SIZE4"

# Verify that devs being used by an active LV are
# preferred over duplicates that are not used by an LV.

aux clear_devs "$dev3" "$dev4"
#pvscan --cache

# The previous steps prevent us from nicely cleaning up
# the vg lockspace in lvmlockd, so just restart it;
# what follows could also just be split into a separate test.
if test -n "$LVM_TEST_LVMLOCKD_TEST" ; then
	killall -9 lvmlockd
	sleep 2
	aux prepare_lvmlockd
fi

vgcreate $SHARED "$vg2" "$dev3" "$dev4"
lvcreate -l1 -n $lv1 $vg2 "$dev3"
lvcreate -l1 -n $lv2 $vg2 "$dev4"

dd if="$dev3" of="$dev5" bs=1M iflag=direct oflag=direct,sync
dd if="$dev4" of="$dev6" bs=1M iflag=direct oflag=direct,sync
# dev5/dev6 not pvs so dd'ing pv onto them causes invalid hints
# that won't be detected, so 5/6 won't be scanned unless we
# force hint recreation
pvscan --cache

pvs -o+uuid,duplicate 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$dev3" main
grep "$dev4" main
not grep duplicate main
check pv_field "$dev3" pv_duplicate ""
check pv_field "$dev4" pv_duplicate ""
check pv_field "$dev5" pv_duplicate "duplicate"
check pv_field "$dev6" pv_duplicate "duplicate"

grep "prefers device $dev3" warn
grep "prefers device $dev4" warn
not grep "prefers device $dev5" warn
not grep "prefers device $dev6" warn

pvs -a -o+uuid,duplicate 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

test "$(grep -c duplicate main)" -eq 2
grep "$dev3" main
grep "$dev4" main
grep "$dev5" main
grep "$dev6" main

grep "prefers device $dev3" warn
grep "prefers device $dev4" warn
not grep "prefers device $dev5" warn
not grep "prefers device $dev6" warn

pvs -o+uuid,duplicate "$dev3" "$dev4" "$dev5" "$dev6" 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

test "$(grep -c duplicate main)" -eq 2
grep "$dev3" main
grep "$dev4" main
grep "$dev5" main
grep "$dev6" main

grep "prefers device $dev3" warn
grep "prefers device $dev4" warn
not grep "prefers device $dev5" warn
not grep "prefers device $dev6" warn


dd if=/dev/zero of="$dev5" bs=1M oflag=direct,sync || true
dd if=/dev/zero of="$dev6" bs=1M oflag=direct,sync || true
#pvscan --cache

lvremove -y $vg2/$lv1
lvremove -y $vg2/$lv2
vgremove $vg2
pvremove -ff -y "$dev3"
pvremove -ff -y "$dev4"

dd if=/dev/zero of="$dev3" bs=1M oflag=direct,sync || true
dd if=/dev/zero of="$dev4" bs=1M oflag=direct,sync || true
#pvscan --cache

# Reverse devs in the previous in case dev3/dev4 would be
# preferred even without an active LV using them.

vgcreate $SHARED $vg2 "$dev5" "$dev6"
lvcreate -l1 -n $lv1 $vg2 "$dev5"
lvcreate -l1 -n $lv2 $vg2 "$dev6"

dd if="$dev5" of="$dev3" bs=1M iflag=direct oflag=direct,sync
dd if="$dev6" of="$dev4" bs=1M iflag=direct oflag=direct,sync
# dev3/dev4 are not pvs (zeroed above) so dd'ing pv onto them causes
# invalid hints that won't be detected, so 3/4 won't be scanned
# unless we force hint recreation
pvscan --cache

pvs -o+uuid,duplicate 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

grep "$dev5" main
grep "$dev6" main
not grep duplicate main
check pv_field "$dev5" pv_duplicate ""
check pv_field "$dev6" pv_duplicate ""
check pv_field "$dev3" pv_duplicate "duplicate"
check pv_field "$dev4" pv_duplicate "duplicate"

pvs -a -o+uuid,duplicate 2>&1 | tee out

rm warn main || true
grep    WARNING out > warn || true
grep -v WARNING out > main || true

test "$(grep -c duplicate main)" -eq 2
grep "$dev3" main
grep "$dev4" main
grep "$dev5" main
grep "$dev6" main

grep "prefers device $dev5" warn
grep "prefers device $dev6" warn
not grep "prefers device $dev3" warn
not grep "prefers device $dev4" warn

dd if=/dev/zero of="$dev3" bs=1M oflag=direct,sync || true
dd if=/dev/zero of="$dev4" bs=1M oflag=direct,sync || true
#pvscan --cache

lvremove -y $vg2/$lv1
lvremove -y $vg2/$lv2
vgremove $vg2