summaryrefslogtreecommitdiff
path: root/test/shell/missing-pv.sh
blob: e1ff659172b24307787b2739fa480fa374e46d1d (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
#!/usr/bin/env bash

# Copyright (C) 2008-2013,2018 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.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

SKIP_WITH_LVMPOLLD=1

. lib/inittest

aux prepare_vg 3

lvcreate -n $lv1 -L8M --type mirror -m 1 $vg
lvcreate -n $lv2 -L8M --type mirror -m 1 $vg

vgchange -an $vg

pvs
vgs
lvs -a -o+devices

# Fail one leg of each mirror LV.
aux disable_dev "$dev1"

pvs -o+missing |tee out
grep missing out |tee out2
grep unknown out2
vgs -o+partial,missing_pv_count
check vg_field $vg vg_partial "partial"
check vg_field $vg vg_missing_pv_count 1
lvs -a -o+devices

# Cannot do normal activate of either LV with a failed leg.
not lvchange -ay $vg/$lv1
not lvchange -ay $vg/$lv2

# Can activate with partial option.
lvchange -ay --activationmode partial $vg/$lv1
lvchange -ay --activationmode partial $vg/$lv2

pvs -o+missing |tee out
grep missing out |tee out2
grep unknown out2
vgs -o+partial,missing_pv_count
check vg_field $vg vg_partial "partial"
check vg_field $vg vg_missing_pv_count 1
lvs -a -o+devices

# Repair lv1 so it no longer uses failed dev.
lvconvert --repair --yes $vg/$lv1

# Check that MISSING flag is set in ondisk metadata,
# it should have been written by the lvconvert since the
# missing PV is still used by lv2.
pvck --dump metadata "$dev2" > meta
grep MISSING meta
rm meta

pvs -o+missing |tee out
grep missing out |tee out2
grep unknown out2
vgs -o+partial,missing_pv_count
check vg_field $vg vg_partial "partial"
check vg_field $vg vg_missing_pv_count 1
lvs -a -o+devices

# Verify normal activation is possible of lv1 since it's
# not using any failed devs, and partial activation is
# required for lv2 since it's still using the failed dev.
vgchange -an $vg
lvchange -ay $vg/$lv1
not lvchange -ay $vg/$lv2
vgchange -an $vg

aux enable_dev "$dev1"

pvs -o+missing |tee out
grep missing out |tee out2
grep "$dev1" out2
vgs -o+partial,missing_pv_count
check vg_field $vg vg_partial "partial"
check vg_field $vg vg_missing_pv_count 1
lvs -a -o+devices

# TODO: check that lv2 has partial flag, lv1 does not
# (there's no partial reporting option, only attr p.)

# Check that MISSING flag is still set in ondisk
# metadata since the previously missing dev is still
# used by lv2.
pvck --dump metadata "$dev2" > meta
grep MISSING meta
rm meta

# The missing pv restrictions still apply even after
# the dev has reappeared since it has the MISSING flag.
not lvchange -ay $vg/$lv2
not lvcreate -l1 $vg

# Update old metadata on the previously missing PV.
# This should not clear the MISSING flag because the
# previously missing PV is still used by lv2.
# This would be done by any command that writes
# metadata, e.g. lvcreate, but since we are in a
# state with a missing pv, most commands that write
# metadata are restricted, so use a command that
# explicitly writes/fixes metadata.
vgck --updatemetadata $vg

pvs -o+missing |tee out
grep missing out |tee out2
grep "$dev1" out2
vgs -o+partial,missing_pv_count
check vg_field $vg vg_partial "partial"
check vg_field $vg vg_missing_pv_count 1
lvs -a -o+devices

# Check that MISSING flag is still set in ondisk metadata since the
# previously missing dev is still used by lv2.
pvck --dump metadata "$dev2" > meta
grep MISSING meta
rm meta

# The missing pv restrictions still apply since it has the MISSING flag.
not lvchange -ay $vg/$lv2
not lvcreate -l1 $vg

lvchange -ay --activationmode partial  $vg/$lv2

# Replace the missing leg of LV2 so no LV will be using the dev that was
# missing.  The MISSING_PV flag will not have been cleared from the
# metadata yet; that will take another metadata update.
lvconvert --repair --yes $vg/$lv2

lvs -a -o+devices | tee out
not grep "$dev1" out

# The MISSING_PV flag hasn't been cleared from the metadata yet, but now
# that the PV is not used by any more LVs, that flag will be cleared from
# the metadata in the next update.
pvck --dump metadata "$dev2" > meta
grep MISSING meta
rm meta

# Reporting commands run vg_read which sees MISSING_PV in the metadata,
# but vg_read then sees the dev is no longer used by any LV, so vg_read
# clears the MISSING_PV flag in the vg struct (not in the metadata) before
# returning the vg struct to the caller.  It's cleared in the vg struct so
# that the limitations of having a missing PV are not applied to the
# command.  The caller sees/uses/reports the VG as having no missing PV,
# even though the metadata still contains MISSING_PV.  The MISSING_PV flag
# is no longer needed in the metadata, but there has simply not been a
# metadata update yet to clear it.
# The message that's printed in this case is:
# WARNING: VG %s has unused reappeared PV %s %s
pvs -o+missing |tee out
not grep missing out
vgs -o+partial,missing_pv_count
check vg_field $vg vg_partial ""
check vg_field $vg vg_missing_pv_count 0

# Run any command that updates the metadata, and the MISSING_PV flag will
# be cleared.  Here just use lvcreate -l1, or we could use
# vgck --updatemetadata.
lvcreate -l1 $vg

# Now the MISSING flag is removed from the ondisk metadata.
pvck --dump metadata "$dev2" > meta
not grep MISSING meta
rm meta

# and commands continue to report no missing PV
pvs -o+missing |tee out
not grep missing out
vgs -o+partial,missing_pv_count
check vg_field $vg vg_partial ""
check vg_field $vg vg_missing_pv_count 0

vgchange -an $vg

vgremove -ff $vg