mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +03:00
tests: aux.sh integrate both teardown loops
Use 1 logic for 2 loops tearing down left device. First loops tries to remove all closed devices with 'normal' remove. Second loop tries to replace those left devices with 'error' target.
This commit is contained in:
parent
8a2448a4ed
commit
cd4e6c9b17
@ -414,36 +414,41 @@ teardown_devs_prefixed() {
|
|||||||
rm -f REMOVE_FAILED
|
rm -f REMOVE_FAILED
|
||||||
#local listdevs=( $(dm_info name,open --sort open,name | grep "$prefix.*:0") )
|
#local listdevs=( $(dm_info name,open --sort open,name | grep "$prefix.*:0") )
|
||||||
#dmsetup remove --deferred ${listdevs[@]%%:0} || touch REMOVE_FAILED
|
#dmsetup remove --deferred ${listdevs[@]%%:0} || touch REMOVE_FAILED
|
||||||
for i in {1..100}; do
|
|
||||||
local need_udev_wait=0
|
|
||||||
local cnt
|
|
||||||
while IFS=' ' read -r dm cnt; do
|
|
||||||
test "$cnt" -eq 0 || break
|
|
||||||
dmsetup remove "$dm" &>/dev/null || touch REMOVE_FAILED &
|
|
||||||
need_udev_wait=1
|
|
||||||
done < <(dm_info name,open --separator ' ' --sort open,name | grep "$prefix")
|
|
||||||
test "$need_udev_wait" -eq 1 || break
|
|
||||||
udev_wait
|
|
||||||
test -f REMOVE_FAILED && break
|
|
||||||
done # looping till there are some removed devicess
|
|
||||||
|
|
||||||
wait
|
# 2nd. loop is trying --force removal which can possibly 'unstuck' some bloked operations
|
||||||
|
for i in 0 1; do
|
||||||
|
local num_remaining_devs=999999
|
||||||
|
local num_devs=0
|
||||||
|
test "$i" = 1 && test "$stray" = 0 && break # no stray device removal
|
||||||
|
|
||||||
|
while :; do
|
||||||
|
local cnt
|
||||||
|
local sortby="name"
|
||||||
|
local need_udev_wait=0
|
||||||
|
|
||||||
if test -f REMOVE_FAILED; then
|
|
||||||
local num_devs
|
|
||||||
local num_remaining_devs=999
|
|
||||||
while num_devs=$(dm_table | grep -c "$prefix") && \
|
|
||||||
test "$num_devs" -lt "$num_remaining_devs" -a "$num_devs" -ne 0; do
|
|
||||||
test "$stray" -eq 0 || echo "## removing $num_devs stray mapped devices with names beginning with $prefix: "
|
|
||||||
# HACK: sort also by minors - so we try to close 'possibly later' created device first
|
# HACK: sort also by minors - so we try to close 'possibly later' created device first
|
||||||
for dm in $(dm_info name --sort open,-minor | grep "$prefix") ; do
|
test "$i" = 0 || sortby="-minor"
|
||||||
dmsetup remove -f "$dm" || true
|
|
||||||
done
|
|
||||||
num_remaining_devs=$num_devs
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
udev_wait
|
# when nothing left for removal, escape both loops...
|
||||||
|
dm_info name,open --separator ' ' --sort open,"$sortby" | grep "$prefix" > out || break 2
|
||||||
|
num_devs=$(wc -l < out)
|
||||||
|
test "$num_devs" -lt "$num_remaining_devs" || break # not managed to reduce table size anymore
|
||||||
|
test "$i" = 0 || echo "## removing $num_devs stray mapped devices with names beginning with $prefix: "
|
||||||
|
while IFS=' ' read -r dm cnt; do
|
||||||
|
if test "$i" = 0; then
|
||||||
|
test "$cnt" -eq 0 || break # stop loop with 1st. opened device
|
||||||
|
dmsetup remove "$dm" &>/dev/null || touch REMOVE_FAILED &
|
||||||
|
else
|
||||||
|
dmsetup remove -f "$dm" || true
|
||||||
|
fi
|
||||||
|
need_udev_wait=1
|
||||||
|
done < out
|
||||||
|
test "$need_udev_wait" -eq 1 || break
|
||||||
|
udev_wait
|
||||||
|
wait
|
||||||
|
num_remaining_devs=$num_devs
|
||||||
|
done # looping till there are some removed devicess
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown_devs() {
|
teardown_devs() {
|
||||||
|
Loading…
Reference in New Issue
Block a user