1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00
lvm2/test/shell/pvmove-restart.sh
Ondrej Kozina 8c9ab2a4dd tests: simplify removal of dangling bg procs
some tests left dangling bg processes originating in
lvm2 commands being able to spawn any bg polling process
(lvchange, vgchange, pvmove, lvconvert...)

Initial fn 'add_to_kill_list' should collect processes with
specific parameters (proc's command line and parent processes ID).
After testing finishes the fn kill_listed_processes should remove these
listed by 'add_to_kill_list'.

Unfortunately it proved to be prone to an error especially in scenarios
where cmd line of initiating command contained characters required to
be espaced before passing to shell script to make it work correctly.
(Or if cmd spawned more than one bg process with same cmd line. i.e.:
vgchange or lvchange).

The new implementation is much simpler. It uses env. variable (LVM_TEST_TAG)
for marking a process desired to be killed later or during test env. teardown.
(i.e.: LVM_TEST_TAG=kill_me_$PREFIX to kill only processes related to
current test environment)
2015-04-28 22:31:40 +02:00

100 lines
2.7 KiB
Bash

#!/bin/sh
# Copyright (C) 2013-2015 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Check pvmove behavior when it's progress and machine is rebooted
. lib/inittest
aux prepare_pvs 3 60
vgcreate -s 128k $vg "$dev1" "$dev2"
pvcreate --metadatacopies 0 "$dev3"
vgextend $vg "$dev3"
# Slowdown writes
# (FIXME: generates interesting race when not used)
aux delay_dev "$dev3" 100 100 $(get first_extent_sector "$dev3"):
for mode in "--atomic" ""
do
# Create multisegment LV
lvcreate -an -Zn -l5 -n $lv1 $vg "$dev1"
lvextend -l+10 $vg/$lv1 "$dev2"
lvextend -l+5 $vg/$lv1 "$dev1"
lvextend -l+10 $vg/$lv1 "$dev2"
pvmove -i0 -n $vg/$lv1 "$dev1" "$dev3" $mode &
PVMOVE=$!
# Let's wait a bit till pvmove starts and kill it
aux wait_pvmove_lv_ready "$vg-pvmove0"
kill -9 $PVMOVE
wait
# Simulate reboot - forcibly remove related devices
# First take down $lv1 then it's pvmove0
while dmsetup status "$vg-$lv1"; do dmsetup remove "$vg-$lv1" || true; done
while dmsetup status "$vg-pvmove0"; do dmsetup remove "$vg-pvmove0" || true; done
while dmsetup status "$vg-pvmove0_mimage_1"; do dmsetup remove "$vg-pvmove0_mimage_1" || true; done
dmsetup table
# Check we really have pvmove volume
check lv_attr_bit type $vg/pvmove0 "p"
if test -e LOCAL_CLVMD ; then
# giveup all clvmd locks (faster then restarting clvmd)
# no deactivation happen, nodes are already removed
#vgchange -an $vg
# FIXME: However above solution has one big problem
# as clvmd starts to abort on internal errors on various
# errors, based on the fact pvmove is killed -9
# Restart clvmd
kill $(< LOCAL_CLVMD)
for i in $(seq 1 100) ; do
test $i -eq 100 && die "Shutdown of clvmd is too slow."
test -e "$CLVMD_PIDFILE" || break
sleep .1
done # wait for the pid removal
aux prepare_clvmd
fi
if test -e LOCAL_LVMETAD ; then
# Restart lvmetad
kill $(< LOCAL_LVMETAD)
aux prepare_lvmetad
fi
# Only PVs should be left in table...
dmsetup table
# Restart pvmove
# use exclusive activation to have usable pvmove without cmirrord
LVM_TEST_TAG="kill_me_$PREFIX" vgchange --config 'activation{polling_interval=10}' -aey $vg
aux wait_pvmove_lv_ready "$vg-pvmove0"
dmsetup table
pvmove --abort
pvmove --abort
lvs -a -o+devices $vg
lvremove -ff $vg
aux kill_listed_processes
done
# Restore delayed device back
aux delay_dev "$dev3"
vgremove -ff $vg