summaryrefslogtreecommitdiff
path: root/test/shell/lvm-on-md.sh
blob: 83478e5a10b5b9e4b8d22c25dccba3a46a61adca (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
#!/usr/bin/env bash

# Copyright (C) 2018-2021 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
SKIP_WITH_LVMLOCKD=1

. lib/inittest

RUNDIR="/run"
test -d "$RUNDIR" || RUNDIR="/var/run"
PVS_ONLINE_DIR="$RUNDIR/lvm/pvs_online"
VGS_ONLINE_DIR="$RUNDIR/lvm/vgs_online"
HINTS="$RUNDIR/lvm/hints"

DFDIR="$LVM_SYSTEM_DIR/devices"
DF="$DFDIR/system.devices"

_clear_online_files() {
        # wait till udev is finished
        aux udev_wait
        rm -f "$PVS_ONLINE_DIR"/* "$VGS_ONLINE_DIR"/*
}


# This stops lvm from taking advantage of hints which
# will have already excluded md components.

# This stops lvm from asking udev if a dev is an md component.
# LVM will ask udev if a dev is an md component, but we don't
# want to rely on that ability in this test.
aux lvmconf "devices/md_component_detection = 1" \
	"devices/hints = \"none\"" \
	"devices/obtain_device_list_from_udev = 0" \
	"devices/search_for_devnames = \"none\""

aux extend_filter_md "a|/dev/md|"

aux prepare_devs 3

for level in 1 0 ; do

# create 2 disk MD raid1 array
# by default using metadata format 1.0 with data at the end of device
#
# When a raid0 md array is stopped, the components will not look like
# duplicate PVs as they do with raid1.
# mdadm does not seem to like --chunk=64 with raid1
case "$level" in
0) CHUNK="--chunk=64" ;;
*) CHUNK="" ;;
esac
aux mdadm_create --metadata=1.0 --level=$level $CHUNK --raid-devices=2 "$dev1" "$dev2"
mddev=$(< MD_DEV)

vgcreate $vg "$mddev"

lvmdevices || true
pvs -o+deviceidtype,deviceid

PVIDMD=$(get pv_field "$mddev" uuid | tr -d - )

lvcreate -n $lv1 -l 2 $vg
lvcreate -n $lv2 -l 2 -an $vg

lvchange -ay $vg/$lv2
check lv_field $vg/$lv1 lv_active "active"

# lvm does not show md components as PVs
pvs "$mddev"
not pvs "$dev1"
not pvs "$dev2"
pvs | tee out
not grep "$dev1" out
not grep "$dev2" out

vgchange -an $vg

# When the md device is started, lvm will see that and know to
# scan for md components, so stop the md device to remove this
# advantage so we will test the fallback detection.
mdadm --stop "$mddev"
aux udev_wait

# The md components should still be detected and excluded.
not pvs "$dev1"
not pvs "$dev2"
pvs | tee out
not grep "$dev1" out
not grep "$dev2" out

pvs 2>&1|tee out
not grep "Not using device" out

# should not activate from the md legs
not vgchange -ay $vg

# should not show an active lv
not dmsetup info $vg-$lv1

# should not allow updating vg
not lvcreate -l1 $vg

# should not activate from the md legs
_clear_online_files
pvscan --cache -aay "$dev1"
pvscan --cache -aay "$dev2"

test ! -f "$RUNDIR/lvm/pvs_online/$PVIDMD"
test ! -f "$RUNDIR/lvm/vgs_online/$vg"

# should not show an active lv
not dmsetup info $vg-$lv1

aux mdadm_assemble "$mddev" "$dev1" "$dev2"

not pvs "$dev1"
not pvs "$dev2"
pvs | tee out
not grep "$dev1" out
not grep "$dev2" out

lvs $vg
vgchange -an $vg

# should not activate from the md legs
_clear_online_files
pvscan --cache -aay "$dev1"
pvscan --cache -aay "$dev2"

test ! -f "$RUNDIR/lvm/pvs_online/$PVIDMD"
test ! -f "$RUNDIR/lvm/vgs_online/$vg"

# should not show an active lv
not dmsetup info $vg-$lv1

vgchange -ay $vg

check lv_field $vg/$lv1 lv_active "active"

vgchange -an $vg

_clear_online_files
pvscan --cache -aay "$mddev"

test -f "$RUNDIR/lvm/pvs_online/$PVIDMD"
test -f "$RUNDIR/lvm/vgs_online/$vg"

check active $vg $lv1

vgchange -an $vg
vgremove -f $vg

aux cleanup_md_dev
aux wipefs_a "$dev1"
aux wipefs_a "$dev2"
aux udev_wait

done


# Repeat tests using the default config settings

aux lvmconf "devices/hints = \"all\"" \
	"devices/obtain_device_list_from_udev = 1" \
	"devices/search_for_devnames = \"none\""

rm $DF || true

# create 2 disk MD raid0 array
# by default using metadata format 1.0 with data at the end of device
# When a raid0 md array is stopped, the components will not look like
# duplicate PVs as they do with raid1.

aux mdadm_create --metadata=1.0 --level=0 --chunk=64 --raid-devices=2 "$dev1" "$dev2"
mddev=$(< MD_DEV)

# Create an unused PV so that there is at least one PV in the hints
# when the MD dev is stopped.  If there are no PVs, the hints are
# empty, and the code falls back to scanning all, and we do not end
# up testing the code with hints actively used.
pvcreate "$dev3"

vgcreate $vg "$mddev"

PVIDMD=$(get pv_field "$mddev" uuid | tr -d - )

lvcreate -n $lv1 -l 2 $vg
lvcreate -n $lv2 -l 2 -an $vg

lvchange -ay $vg/$lv2
check lv_field $vg/$lv1 lv_active "active"

# lvm does not show md components as PVs
pvs "$mddev"
not pvs "$dev1"
not pvs "$dev2"
pvs > out
not grep "$dev1" out
not grep "$dev2" out

grep "$mddev" "$HINTS"
grep "$dev3" "$HINTS"
not grep "$dev1" "$HINTS"
not grep "$dev2" "$HINTS"

vgchange -an $vg

# When the md device is started, lvm will see that and know to
# scan for md components, so stop the md device to remove this
# advantage so we will test the fallback detection.
mdadm --stop "$mddev"
aux udev_wait

# A WARNING indicating duplicate PVs is printed by 'pvs' in this
# case.  It's printed during the scan, but after the scan, the
# md component detection is run on the devs and they are dropped
# when we see they are md components. So, we ignore the warning
# containing the word duplicate, and look for the "Not using device"
# message, which shouldn't appear, as it would indicate that
# we didn't drop the md components.
# FIXME: we should avoid printing the premature warning indicating
# duplicate PVs which are eventually recognized as md components
# and dropped.
pvs 2>&1|tee out1
grep -v -e WARNING -e "Devices file PVID" out1 > out2
not grep "Not using device" out2
not grep "$mddev" out2
not grep "$dev1" out2
not grep "$dev2" out2
grep "$dev3" out2
cat "$HINTS"

pvs 2>&1|tee out1
grep -v -e WARNING -e "Devices file PVID" out1 > out2
not grep "Not using device" out2
not grep "$mddev" out2
not grep "$dev1" out2
not grep "$dev2" out2
grep "$dev3" out2
cat "$HINTS"

# The md components should still be detected and excluded.
not pvs "$dev1"
not pvs "$dev2"
pvs | tee out
not grep "$dev1" out
not grep "$dev2" out
grep "$dev3" out

# should not activate from the md legs
not vgchange -ay $vg

# should not show an active lv
not dmsetup info $vg-$lv1

# should not allow updating vg
not lvcreate -l1 $vg

# should not activate from the md legs
_clear_online_files
pvscan --cache -aay "$dev1"
pvscan --cache -aay "$dev2"

test ! -f "$RUNDIR/lvm/pvs_online/$PVIDMD"
test ! -f "$RUNDIR/lvm/vgs_online/$vg"

# should not show an active lv
not dmsetup info $vg-$lv1

# start the md dev
aux mdadm_assemble "$mddev" "$dev1" "$dev2"

not pvs "$dev1"
not pvs "$dev2"
pvs | tee out
not grep "$dev1" out
not grep "$dev2" out

lvs $vg
vgchange -an $vg

# should not activate from the md legs
_clear_online_files
pvscan --cache -aay "$dev1"
pvscan --cache -aay "$dev2"

test ! -f "$RUNDIR/lvm/pvs_online/$PVIDMD"
test ! -f "$RUNDIR/lvm/vgs_online/$vg"

# should not show an active lv
not dmsetup info $vg-$lv1

vgchange -ay $vg

check lv_field $vg/$lv1 lv_active "active"

vgchange -an $vg

_clear_online_files
pvscan --cache -aay "$mddev"

test -f "$RUNDIR/lvm/pvs_online/$PVIDMD"
test -f "$RUNDIR/lvm/vgs_online/$vg"

check active $vg $lv1

vgchange -an $vg
vgremove -f $vg

aux cleanup_md_dev