Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
# Copyright (C) 2008 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 'vgreduce --removemissing' works on mirrored LV"

. ./test-utils.sh

dmsetup_has_dm_devdir_support_ || exit 200

lv_is_on_ ()
{
	local lv=$vg/$1
	shift
	local pvs=$*

	echo "Check if $lv is exactly on PVs $pvs"
	rm -f out1 out2
	echo $pvs | sed 's/ /\n/g' | sort | uniq > out1

	lvs -a -odevices --noheadings $lv | \
	sed 's/([^)]*)//g; s/[ ,]/\n/g' | sort | uniq > out2

	diff --ignore-blank-lines out1 out2
}

mimages_are_on_ ()
{
	local lv=$1
	shift
	local pvs="$*"
	local mimages
	local i

	echo "Check if mirror images of $lv are on PVs $pvs"
	rm -f out1 out2
	echo $pvs | sed 's/ /\n/g' | sort | uniq > out1

	mimages=$(lvs --noheadings -a -o lv_name $vg | grep "${lv}_mimage_" | \
		sed 's/\[//g; s/\]//g')
	for i in $mimages; do
		echo "Checking $vg/$i"
		lvs -a -odevices --noheadings $vg/$i | \
			sed 's/([^)]*)//g; s/ //g; s/,/ /g' | sort | uniq >> out2
	done

	diff --ignore-blank-lines out1 out2
}

mirrorlog_is_on_()
{
	local lv="$1"_mlog
	shift
	lv_is_on_ $lv $*
}

lv_is_linear_()
{
	echo "Check if $1 is linear LV (i.e. not a mirror)"
	lvs -o stripes,attr --noheadings $vg/$1 | sed 's/ //g'
	lvs -o stripes,attr --noheadings $vg/$1 | sed 's/ //g' | grep -q '^1-'
}

rest_pvs_()
{
	local index=$1
	local num=$2
	local rem=""
	local n

	for n in $(seq 1 $(($index - 1))) $(seq $(($index + 1)) $num); do
		eval local dev=$\dev$n
		rem="$rem $dev"
	done

	echo "$rem"
}

# ---------------------------------------------------------------------
# Initialize PVs and VGs

prepare_vg 5

# ---------------------------------------------------------------------
# Common environment setup/cleanup for each sub testcases

prepare_lvs_()
{
	lvremove -ff $vg;
	if dmsetup table|grep $vg; then
		echo "ERROR: lvremove did leave some some mappings in DM behind!"
		return 1
	fi
	:
}

check_and_cleanup_lvs_()
{
	lvs -a -o+devices $vg 
	lvremove -ff $vg
	if dmsetup table|grep $vg; then
		echo "ERROR: lvremove did leave some some mappings in DM behind!"
		return 1
	fi
}

recover_vg_()
{
	enable_dev $* 
	pvcreate -ff $* 
	vgextend $vg $* 
	check_and_cleanup_lvs_
}

#COMM "check environment setup/cleanup" 
prepare_lvs_ 
check_and_cleanup_lvs_

# ---------------------------------------------------------------------
# one of mirror images has failed

#COMM "basic: fail the 2nd mirror image of 2-way mirrored LV"
prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvchange -an $vg/$lv1
aux mimages_are_on_ $lv1 $dev1 $dev2
mirrorlog_is_on_ $lv1 $dev3
disable_dev $dev2
vgreduce --removemissing --force $vg
lv_is_linear_ $lv1
lv_is_on_ $lv1 $dev1

# "cleanup"
recover_vg_ $dev2

# ---------------------------------------------------------------------
# LV has 3 images in flat,
# 1 out of 3 images fails

#COMM test_3way_mirror_fail_1_ <PV# to fail>
test_3way_mirror_fail_1_()
{
	local index=$1

	lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev4:0-1
	lvchange -an $vg/$lv1
	aux mimages_are_on_ $lv1 $dev1 $dev2 $dev3
	mirrorlog_is_on_ $lv1 $dev4
	eval disable_dev \$dev$index
	vgreduce --removemissing --force $vg
	lvs -a -o+devices $vg
	mimages_are_on_ $lv1 $(rest_pvs_ $index 3)
	mirrorlog_is_on_ $lv1 $dev4
}

for n in $(seq 1 3); do
	#COMM fail mirror image $(($n - 1)) of 3-way mirrored LV"
	prepare_lvs_
	test_3way_mirror_fail_1_ $n
	eval recover_vg_ \$dev$n
done

# ---------------------------------------------------------------------
# LV has 3 images in flat,
# 2 out of 3 images fail

#COMM test_3way_mirror_fail_2_ <PV# NOT to fail>
test_3way_mirror_fail_2_()
{
	local index=$1

	lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev4:0-1
	lvchange -an $vg/$lv1
	mimages_are_on_ $lv1 $dev1 $dev2 $dev3
	mirrorlog_is_on_ $lv1 $dev4
	rest_pvs_ $index 3
	disable_dev $(rest_pvs_ $index 3)
	vgreduce --force --removemissing $vg
	lvs -a -o+devices $vg
	aux lv_is_linear_ $lv1
	eval lv_is_on_ $lv1 \$dev$n
}

for n in $(seq 1 3); do
	#COMM fail mirror images other than mirror image $(($n - 1)) of 3-way mirrored LV
	prepare_lvs_
	test_3way_mirror_fail_2_ $n
	recover_vg_ $(rest_pvs_ $n 3)
done

# ---------------------------------------------------------------------
# LV has 4 images, 1 of them is in the temporary mirror for syncing.
# 1 out of 4 images fails

#COMM test_3way_mirror_plus_1_fail_1_ <PV# to fail>
test_3way_mirror_plus_1_fail_1_()
{
	local index=$1

	lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev5:0-1 
	lvchange -an $vg/$lv1 
	lvconvert -m+1 $vg/$lv1 $dev4 
	mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4 
	mirrorlog_is_on_ $lv1 $dev5 
	eval disable_dev \$dev$n 
	vgreduce --removemissing --force $vg 
	lvs -a -o+devices $vg 
	mimages_are_on_ $lv1 $(rest_pvs_ $index 4) 
	mirrorlog_is_on_ $lv1 $dev5
}

for n in $(seq 1 4); do
	#COMM "fail mirror image $(($n - 1)) of 4-way (1 converting) mirrored LV"
	prepare_lvs_
	test_3way_mirror_plus_1_fail_1_ $n
	eval recover_vg_ \$dev$n
done

# ---------------------------------------------------------------------
# LV has 4 images, 1 of them is in the temporary mirror for syncing.
# 3 out of 4 images fail

#COMM test_3way_mirror_plus_1_fail_3_ <PV# NOT to fail>
test_3way_mirror_plus_1_fail_3_()
{
	local index=$1

	lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev5:0-1 
	lvchange -an $vg/$lv1 
	lvconvert -m+1 $vg/$lv1 $dev4 
	mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4 
	mirrorlog_is_on_ $lv1 $dev5 
	disable_dev $(rest_pvs_ $index 4) 
	vgreduce --removemissing --force $vg 
	lvs -a -o+devices $vg 
	eval local dev=\$dev$n
	mimages_are_on_ $lv1 $dev || lv_is_on_ $lv1 $dev
	not mirrorlog_is_on_ $lv1 $dev5
}

for n in $(seq 1 4); do
	#COMM "fail mirror images other than mirror image $(($n - 1)) of 4-way (1 converting) mirrored LV"
	prepare_lvs_
	test_3way_mirror_plus_1_fail_3_ $n
	recover_vg_ $(rest_pvs_ $n 4)
done

# ---------------------------------------------------------------------
# LV has 4 images, 2 of them are in the temporary mirror for syncing.
# 1 out of 4 images fail

# test_2way_mirror_plus_2_fail_1_ <PV# to fail>
test_2way_mirror_plus_2_fail_1_()
{
	local index=$1

	lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1 
	lvchange -an $vg/$lv1 
	lvconvert -m+2 $vg/$lv1 $dev3 $dev4 
	mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4 
	mirrorlog_is_on_ $lv1 $dev5 
	eval disable_dev \$dev$n 
	vgreduce --removemissing --force $vg 
	lvs -a -o+devices $vg 
	mimages_are_on_ $lv1 $(rest_pvs_ $index 4) 
	mirrorlog_is_on_ $lv1 $dev5
}

for n in $(seq 1 4); do
	#COMM "fail mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV" 
	prepare_lvs_ 
	test_2way_mirror_plus_2_fail_1_ $n
	eval recover_vg_ \$dev$n
done

# ---------------------------------------------------------------------
# LV has 4 images, 2 of them are in the temporary mirror for syncing.
# 3 out of 4 images fail

# test_2way_mirror_plus_2_fail_3_ <PV# NOT to fail>
test_2way_mirror_plus_2_fail_3_()
{
	local index=$1

	lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1 
	lvchange -an $vg/$lv1 
	lvconvert -m+2 $vg/$lv1 $dev3 $dev4 
	mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4 
	mirrorlog_is_on_ $lv1 $dev5 
	disable_dev $(rest_pvs_ $index 4) 
	vgreduce --removemissing --force $vg 
	lvs -a -o+devices $vg 
	eval local dev=\$dev$n
	mimages_are_on_ $lv1 $dev || lv_is_on_ $lv1 $dev
	not mirrorlog_is_on_ $lv1 $dev5
}

for n in $(seq 1 4); do
	#COMM "fail mirror images other than mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV"
	prepare_lvs_
	test_2way_mirror_plus_2_fail_3_ $n
	recover_vg_ $(rest_pvs_ $n 4)
done

# ---------------------------------------------------------------------
# log device is gone (flat mirror and stacked mirror)

#COMM "fail mirror log of 2-way mirrored LV" 
prepare_lvs_ 
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1 
lvchange -an $vg/$lv1 
mimages_are_on_ $lv1 $dev1 $dev2 
mirrorlog_is_on_ $lv1 $dev5 
disable_dev $dev5 
vgreduce --removemissing --force $vg 
mimages_are_on_ $lv1 $dev1 $dev2 
not mirrorlog_is_on_ $lv1 $dev5
recover_vg_ $dev5

#COMM "fail mirror log of 3-way (1 converting) mirrored LV" 
prepare_lvs_ 
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1 
lvchange -an $vg/$lv1 
lvconvert -m+1 $vg/$lv1 $dev3 
mimages_are_on_ $lv1 $dev1 $dev2 $dev3 
mirrorlog_is_on_ $lv1 $dev5 
disable_dev $dev5 
vgreduce --removemissing --force $vg 
mimages_are_on_ $lv1 $dev1 $dev2 $dev3 
not mirrorlog_is_on_ $lv1 $dev5
recover_vg_ $dev5

# ---------------------------------------------------------------------
# all images are gone (flat mirror and stacked mirror)

#COMM "fail all mirror images of 2-way mirrored LV"
prepare_lvs_ 
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1 
lvchange -an $vg/$lv1 
mimages_are_on_ $lv1 $dev1 $dev2 
mirrorlog_is_on_ $lv1 $dev5 
disable_dev $dev1 $dev2 
vgreduce --removemissing --force $vg 
not lvs $vg/$lv1
recover_vg_ $dev1 $dev2

#COMM "fail all mirror images of 3-way (1 converting) mirrored LV"
prepare_lvs_ 
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1 
lvchange -an $vg/$lv1 
lvconvert -m+1 $vg/$lv1 $dev3 
mimages_are_on_ $lv1 $dev1 $dev2 $dev3 
mirrorlog_is_on_ $lv1 $dev5 
disable_dev $dev1 $dev2 $dev3 
vgreduce --removemissing --force $vg 
not lvs $vg/$lv1
recover_vg_ $dev1 $dev2 $dev3

# ---------------------------------------------------------------------
# Multiple LVs

#COMM "fail a mirror image of one of mirrored LV"
prepare_lvs_ 
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1 
lvchange -an $vg/$lv1 
lvcreate -l2 -m1 -n $lv2 $vg $dev3 $dev4 $dev5:1-1 
lvchange -an $vg/$lv2 
mimages_are_on_ $lv1 $dev1 $dev2 
mimages_are_on_ $lv2 $dev3 $dev4 
mirrorlog_is_on_ $lv1 $dev5 
mirrorlog_is_on_ $lv2 $dev5 
disable_dev $dev2 
vgreduce --removemissing --force $vg 
mimages_are_on_ $lv2 $dev3 $dev4 
mirrorlog_is_on_ $lv2 $dev5 
lv_is_linear_ $lv1 
lv_is_on_ $lv1 $dev1
recover_vg_ $dev2

#COMM "fail mirror images, one for each mirrored LV"
prepare_lvs_ 
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1 
lvchange -an $vg/$lv1 
lvcreate -l2 -m1 -n $lv2 $vg $dev3 $dev4 $dev5:1-1 
lvchange -an $vg/$lv2 
mimages_are_on_ $lv1 $dev1 $dev2 
mimages_are_on_ $lv2 $dev3 $dev4 
mirrorlog_is_on_ $lv1 $dev5 
mirrorlog_is_on_ $lv2 $dev5 
disable_dev $dev2 
disable_dev $dev4 
vgreduce --removemissing --force $vg 
lv_is_linear_ $lv1 
lv_is_on_ $lv1 $dev1 
lv_is_linear_ $lv2 
lv_is_on_ $lv2 $dev3
recover_vg_ $dev2 $dev4

# ---------------------------------------------------------------------
# no failure

#COMM "no failures"
prepare_lvs_ 
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1 
lvchange -an $vg/$lv1 
mimages_are_on_ $lv1 $dev1 $dev2 
mirrorlog_is_on_ $lv1 $dev5 
vgreduce --removemissing --force $vg 
mimages_are_on_ $lv1 $dev1 $dev2 
mirrorlog_is_on_ $lv1 $dev5
check_and_cleanup_lvs_

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