summaryrefslogtreecommitdiff
path: root/test/shell/process-each-duplicate-pvs.sh
blob: cf0ca2d3ab4193f96b0075b63923d0610c3323d5 (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
#!/bin/sh
# 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_LVMLOCKD=1

. lib/inittest

aux prepare_devs 2

pvcreate "$dev1"
vgcreate $vg1 "$dev1"

# Clone the PV
dd if="$dev1" of="$dev2" bs=256K count=1 iflag=direct oflag=direct
aux notify_lvmetad "$dev2"

# When there are cloned devices (same pvid), one will be referenced in
# lvmcache as pv->dev, and the other will not be referenced from lvmcache,
# it'll only be in device cache.  The one referenced by lvmcache is
# referred to as the "preferred" one, and is the one that is printed by a
# standard 'pvs' command.
#
# We don't know if dev1 or dev2 will be preferred, so we first check that
# and save it as PV1, the other as PV2.
#
# The rules that 'pvs' follows to choose which PVs to display are
# somewhat strange and seem arbitrary from a user perspective;
# the choice is driven largely by what's most practical in the code,
# but also by what vgimportclone needs.
#
# Some of the rules that process_each_pv is using:
# - When no pv arg is specified, print the one preferred dev.
# - When pv args are specified, print one line per specified arg,
#   i.e. don't print all duplicate pvs when one is specified.
# - Always print the preferred duplicate, even if it was not the
#   one specified, e.g. If there are two duplicates on A and B,
#   and A is the preferred device, then 'pvs A' will show A and
#   'pvs B' will show A.
# - If multiple duplicates are specified, then print each, e.g.
#   'pvs A B' will show both A and B.
# - If three duplicates exist on A, B, C, and the preferred is A,
#   and the command 'pvs B C' is run, then the A will be printed
#   first since we always print the preferred device, and then
#   either B or C will be printed.  'pvs A B C' will print all.
# - 'pvs -a' should print all the duplicates and should show
#   the same VG for each.
# - 'pvs -o+size ...' should show the correct size of the
#   devices being printed if they differ among the duplicates.
# - By using 'pvs --config' with a filter, you can filter out
#   the duplicate devs you don't want so that pvs will
#   print the devs you do want to see.
#
# The tests below check these behaviors on up to two duplicates,
# so if the process_each_pv logic changes regarding which
# duplicates are chosen, then this test will need adjusting.

# Verify that there is only one PV printed, i.e. the preferred
pvs --noheading | tee out
test $(wc -l < out) -eq 1

# Set PV1 to the perferred/cached PV, and PV2 to the other.
# Cannot use pvs -o pv_name because that command goes to
# disk and does not represent what lvmetad thinks.
PV1=$(pvs --noheading | awk '{ print $1 }')
echo PV1 is $PV1
if [ $PV1 == $dev1 ]; then
	PV2=$dev2
else
	PV2=$dev1
fi
echo PV2 is $PV2

# check listed pvs
pvs --noheading | tee out
grep $PV1 out
not grep $PV2 out

# check error messages
pvs --noheading 2>&1 | tee out
grep "Found duplicate" out >err
grep "using $PV1 not $PV2" err

# check listed pvs
pvs --noheading "$dev1" | tee out
grep $PV1 out
not grep $PV2 out

# check error messages
pvs --noheading "$dev1" 2>&1 | tee out
grep "Found duplicate" out >err
grep "using $PV1 not $PV2" err

# check listed pvs
pvs --noheading "$dev2" | tee out
grep $PV1 out
not grep $PV2 out

# check error messages
pvs --noheading "$dev2" 2>&1 | tee out
grep "Found duplicate" out >err
grep "using $PV1 not $PV2" err

# check listed pvs
pvs --noheading "$dev1" "$dev2" | tee out
grep $PV1 out
grep $PV2 out

# check error messages
pvs --noheading "$dev1" "$dev2" 2>&1 | tee out
grep "Found duplicate" out >err
grep "using $PV1 not $PV2" err

# check listed pvs
pvs --noheading -a | tee out
grep $PV1 out
grep $PV2 out
grep $PV1 out | grep $vg1
grep $PV2 out | grep $vg1

# check error messages
pvs --noheading -a 2>&1 | tee out
grep "Found duplicate" out >err
grep "using $PV1 not $PV2" err


# TODO: I'd like to test that a subsystem device is preferred
# over a non-subsystem device, but all the devices used here
# are DM devices, i.e. they are already subsystem devices,
# so I can't just wrap a standard block device with a DM
# identity mapping.