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
|
#!/usr/bin/env bash
# Copyright (C) 2012 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
# hints are currently disabled with lvmlockd
SKIP_WITH_LVMLOCKD=1
. lib/inittest
# Since this test is currently using 'system's' hints,
# it cannot be running, while lvmdbusd operates in the system.
# FIXME: sometimes test suite itself 'leaks' lvmdbusd process.
pgrep lvmdbusd && skip "Can't run this test, while lvmdbusd is running"
RUNDIR="/run"
test -d "$RUNDIR" || RUNDIR="/var/run"
HINTS="$RUNDIR/lvm/hints"
NOHINTS="$RUNDIR/lvm/nohints"
NEWHINTS="$RUNDIR/lvm/newhints"
PREV="$RUNDIR/lvm/prev-hints"
# TODO:
# Test commands that ignore hints
# Test flock
aux lvmconf 'devices/scan_lvs = 0'
aux prepare_devs 6
# no PVs yet so hints should have no devs
pvs
not grep scan: $HINTS
#
# test --nohints option
#
pvcreate "$dev1"
pvcreate "$dev2"
# pvs --nohints does not create hints
pvs --nohints |tee out
grep "$dev1" out
grep "$dev2" out
not grep "$dev1" $HINTS
not grep "$dev2" $HINTS
# pvs creates hints
pvs
grep "$dev1" $HINTS
grep "$dev2" $HINTS
# save hints with dev1 and dev2 before dev3 is created
cp $HINTS $PREV
# pvcreate --nohints invalidates hints
pvcreate --nohints "$dev3"
ls $NEWHINTS
# pvs --nohints does not update hints
pvs --nohints |tee out
grep "$dev1" out
grep "$dev2" out
grep "$dev3" out
not grep "$dev3" $HINTS
# restore old hint file without dev3
cp $PREV $HINTS
# pvs --nohints does not update hints
pvs --nohints |tee out
grep "$dev1" out
grep "$dev2" out
grep "$dev3" out
grep "$dev1" $HINTS
grep "$dev2" $HINTS
not grep "$dev3" $HINTS
# pvs updates hints
pvs |tee out
grep "$dev1" out
grep "$dev2" out
grep "$dev3" out
grep "$dev1" $HINTS
grep "$dev2" $HINTS
grep "$dev3" $HINTS
aux wipefs_a "$dev1" "$dev2" "$dev3"
#
# vg1 uses dev1,dev2
#
# Test basics that PVs are in hints, not non-PV devs,
# and that only PVs are scanned when using hints.
#
rm $HINTS
vgcreate $vg1 "$dev1" "$dev2"
lvcreate -n $lv1 -l 4 $vg1
# test that only the two PVs are in hints
pvs
grep -v -E "$dev1|$dev2" $HINTS > tmptest
not grep scan: tmptest
# test that 'pvs' submits only three reads, one for each PV in hints
# for initial scan, and one more in vg_read rescan check
if which strace; then
strace -e io_submit pvs 2>&1|tee tmptest
test "$(grep -c io_submit tmptest)" -eq 3
# test that 'pvs -a' submits seven reads, one for each device,
# and one more in vg_read rescan check
strace -e io_submit pvs -a 2>&1|tee tmptest
test "$(grep -c io_submit tmptest)" -eq 7
fi
#
# vg2 uses dev3,dev4
#
# Test common commands that cause hints to be refreshed:
# pvcreate/vgcreate/vgextend/vgreduce/vgremove/pvremove
#
not pvs "$dev3"
not grep "$dev3" $HINTS
cp $HINTS $PREV
pvcreate "$dev3"
grep "# Created empty" $HINTS
cat $NEWHINTS
# next cmd recreates hints
pvs "$dev3"
grep "$dev3" $HINTS
not diff $HINTS $PREV
not cat $NEWHINTS
not vgs $vg2
cp $HINTS $PREV
vgcreate $vg2 "$dev3"
grep "# Created empty" $HINTS
cat $NEWHINTS
# next cmd recreates hints
vgs $vg2
grep $vg2 $HINTS
not diff $HINTS $PREV
not cat $NEWHINTS
cp $HINTS $PREV
vgextend $vg2 "$dev4"
grep "# Created empty" $HINTS
cat $NEWHINTS
# next cmd recreates hints
vgs $vg2
grep "$dev4" $HINTS
not diff $HINTS $PREV
not cat $NEWHINTS
cp $HINTS $PREV
vgreduce $vg2 "$dev4"
grep "# Created empty" $HINTS
cat $NEWHINTS
# next cmd recreates hints
vgs $vg2
grep "$dev4" $HINTS
not diff $HINTS $PREV
not cat $NEWHINTS
cp $HINTS $PREV
vgremove $vg2
grep "# Created empty" $HINTS
cat $NEWHINTS
# next cmd recreates hints
not vgs $vg2
not grep $vg2 $HINTS
not diff $HINTS $PREV
not cat $NEWHINTS
cp $HINTS $PREV
pvremove "$dev3" "$dev4"
grep "# Created empty" $HINTS
cat $NEWHINTS
# next cmd recreates hints
not pvs "$dev3"
not pvs "$dev4"
not grep "$dev3" $HINTS
not grep "$dev4" $HINTS
not diff $HINTS $PREV
not cat $NEWHINTS
#
# Test that adding a new device and removing a device
# causes hints to be recreated.
#
# with a devices file the appearance of a new device on
# the system does not disturb lvm, so this test doesn't
# apply
#
if ! lvmdevices; then
not pvs "$dev5"
# create a new temp device that will cause hint hash to change
DEVNAME=${PREFIX}pv99
echo "0 $(blockdev --getsize "$dev5") linear $dev5 0" | dmsetup create $DEVNAME
dmsetup status $DEVNAME
cp $HINTS $PREV
# pvs ignores current hints because of different dev hash and refreshes new hints
pvs
# devs listed in hints before and after are the same
grep scan: $PREV > scan1
grep scan: $HINTS > scan2
diff scan1 scan2
# hash listed before and after are different
cat $PREV
cat $HINTS
grep devs_hash $PREV > devs_hash1
grep devs_hash $HINTS > devs_hash2
not diff devs_hash1 devs_hash2
# hints are stable/unchanging
cp $HINTS $PREV
pvs
diff $HINTS $PREV
# remove the temp device which will cause hint hash to change again
dmsetup remove $DEVNAME
cp $HINTS $PREV
# pvs ignores current hints because of different dev hash and refreshes new hints
pvs
# devs listed in hints before and after are the same
grep scan: $PREV > scan1
grep scan: $HINTS > scan2
diff scan1 scan2
# hash listed before and after are different
grep devs_hash $PREV > devs_hash1
grep devs_hash $HINTS > devs_hash2
not diff devs_hash1 devs_hash2
# end of new device test for non-devicesfile case
fi
#
# Test that hints don't change from a bunch of commands
# that use hints and shouldn't change it.
#
# first create some more metadata using vg2
pvcreate "$dev3" "$dev4"
vgcreate $vg2 "$dev3"
lvcreate -n $lv1 -l1 $vg2
lvcreate -n $lv2 -l1 $vg2
cp $HINTS $PREV
lvm fullreport
lvchange -ay $vg1
lvchange -an $vg1
lvcreate -l1 -n $lv2 $vg1
lvcreate -l1 -an -n $lv3 $vg1
lvchange -an $vg1
lvremove $vg1/$lv3
lvresize --fs ignore -l+1 $vg1/$lv2
lvresize --fs ignore -l-1 $vg1/$lv2
lvdisplay
pvdisplay
vgdisplay
lvs
pvs
vgs
vgchange -ay $vg2
vgchange -an $vg2
vgck $vg2
lvrename $vg1 $lv2 $lv3
# no change in hints after all that
diff $HINTS $PREV
#
# Test that changing the filter will cause hint refresh
#
rm $HINTS $PREV
vgs
cp $HINTS $PREV
# this changes the filter to exclude dev5 which is not a PV
aux hide_dev "$dev5"
# next cmd sees different filter, ignores hints, creates new hints
pvs
not diff $HINTS $PREV
# run cmds using new filter
pvs
cp $HINTS $PREV
vgs
# hints are stable once refreshed
diff $HINTS $PREV
# this changes the filter to include dev5
aux unhide_dev "$dev5"
# next cmd sees different filter, ignores hints, creates new hints
pvs
not diff $HINTS $PREV
# hints are stable
cp $HINTS $PREV
vgs
diff $HINTS $PREV
#
# Test that changing scan_lvs will cause hint refresh
#
rm $HINTS $PREV
vgs
cp $HINTS $PREV
# change lvm.conf
aux lvmconf 'devices/scan_lvs = 1'
# next cmd sees new setting, ignores hints, creates new hints
pvs
not diff $HINTS $PREV
# run cmds using new filter
pvs
cp $HINTS $PREV
vgs
# hints are stable once refreshed
diff $HINTS $PREV
# change lvm.conf back
aux lvmconf 'devices/scan_lvs = 0'
# next cmd sees different scan_lvs, ignores hints, creates new hints
pvs
not diff $HINTS $PREV
# hints are stable once refreshed
cp $HINTS $PREV
pvs
diff $HINTS $PREV
#
# Test pvscan --cache to force hints refresh
#
# pvs (no change), pvscan (hints are new), pvs (no change)
rm $HINTS $PREV
pvs
cp $HINTS $PREV
# this next pvscan recreates the hints file
pvscan --cache
# the only diff will be "Created by pvscan ..." vs "Created by pvs ..."
not diff $HINTS $PREV
cp $HINTS $PREV
pvs
diff $HINTS $PREV
grep 'Created by pvscan' $HINTS
# dev4 is a PV not used by a VG, dev5 is not a PV
# using dd to copy skirts hint tracking so dev5 won't be seen
# (unless the dd triggers udev which triggers pvscan --cache $dev5,
# but I've not seen that happen in tests so far.)
dd if="$dev4" of="$dev5" bs=1M
# this pvs won't see dev5
pvs > foo
cat foo
grep "$dev4" foo
not grep "$dev5" foo
# no hints have changed after dd and pvs since dd cannot be detected
diff $HINTS $PREV
# force hints refresh, will see duplicate now
pvscan --cache
not diff $HINTS $PREV
cat $HINTS
pvs -a > foo
# after force refresh, both devs (dups) appear in output
cat foo
grep "$dev4" foo
grep "$dev5" foo
# clear PV from dev5
dd if=/dev/zero of="$dev5" bs=1M count=1
# this pvs won't use hints because of duplicate PVs,
# and will create new hints
cp $HINTS $PREV
pvs > foo
not diff $HINTS $PREV
grep "$dev4" foo
not grep "$dev5" foo
grep "$dev4" $HINTS
not grep "$dev5" $HINTS
#
# Test pvscan --cache <dev> forces refresh
#
rm $HINTS $PREV
pvs
cp $HINTS $PREV
# this next pvscan creates newhints to trigger a refresh
pvscan --cache "$dev4"
cat $NEWHINTS
# this next pvs creates new hints
pvs
# the only diff will be "Created by..."
not diff $HINTS $PREV
#
# Test pvck --repair forces refresh
#
rm $HINTS $PREV
pvs
cp $HINTS $PREV
pvck --repairtype label_header -y "$dev3"
cat $NEWHINTS
grep 'Created empty by pvck' $HINTS
# this next pvs creates new hints
pvs
# the only diff will be "Created by..."
not diff $HINTS $PREV
#
# Test incorrect dev-to-pvid info in hints is detected
# dev4 is a PV not in a VG
#
pvs
cp $HINTS tmp-old
# this pvchange will invalidate current hints
pvchange -u "$dev4"
grep "# Created empty" $HINTS
cat $NEWHINTS
# this next pvs will create new hints with the new uuid
pvs
grep "$dev4" $HINTS > tmp-newuuid
cp $HINTS tmp-new
not diff tmp-old tmp-new
# hints are stable
pvs
diff $HINTS tmp-new
# replace the current hints with the old hints with the old uuid
cp tmp-old $HINTS
# this next pvs will see wrong dev-to-pvid mapping and invalidate hints
pvs
cat $HINTS
cat $NEWHINTS
# this next pvs will create new hints with the new uuid
pvs
cat $HINTS
grep -f tmp-newuuid $HINTS
rm tmp-old tmp-new tmp-newuuid
#
# Test incorrect pvid-to-vgname info in hints is detected
#
# this vgcreate invalidates current hints
vgcreate $vg3 "$dev4"
# this pvs creates new hints
pvs
cp $HINTS tmp-old
# this vgrename will invalidate current hints
vgrename $vg3 $vg4
# this pvs will create new hints with the new vg name
pvs
cp $HINTS tmp-new
not diff tmp-old tmp-new
# replace the current hints with the old hints with the old vg name
cp tmp-old $HINTS
# this pvs will see wrong pvid-to-vgname mapping and invalidate hints
pvs
cat $NEWHINTS
# this pvs will create new hints with the new vg name
pvs
grep $vg4 $HINTS
vgremove -y $vg4
vgremove -y $vg2
vgremove -y $vg1
|