Skip to content

Commit

Permalink
improve error handling for dm devices
Browse files Browse the repository at this point in the history
if setup-storage created dm devices and we exit early, cleanup the
devices using dmsetup remove, do only remove devices created by FAI
  • Loading branch information
Thomas Lange committed Aug 18, 2017
1 parent 5e9656b commit 6bf4fa6
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions lib/subroutines
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,29 @@ jobsrunning() {
ps r | egrep -qv "ps r|TIME COMMAND|rcS"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
umount_target() {

if [ "$target" != '/' ]; then
# do not umount during softupdate
umount $FAI_ROOT/proc $FAI_ROOT/sys $FAI_ROOT/dev/pts $FAI_ROOT/dev 2>/dev/null
for dir in $(mount | grep $target | egrep -v "media/mirror|tmpfs"| awk '{print $3}' | sort -r); do
mountpoint -q $dir && umount $dir
done
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cleanup_devicemapper() {

# remove device mapper devices
grep -q 'Executing: vgcreate' $LOGDIR/format.log 2>/dev/null
if [ $? -eq 0 ]; then
dmdevices=$(grep 'Executing: vgcreate' $LOGDIR/format.log | awk '{print $3}')
for d in $dmdevices; do
dmsetup remove /dev/$d/*
done
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
wait_for_jobs() {

# can be an extern script
Expand Down Expand Up @@ -558,23 +581,8 @@ task_faiend() {
sendmon "TASKEND faiend 0"

cd /
if [ "$target" != '/' ]; then
# do not umount during softupdate
umount $FAI_ROOT/proc $FAI_ROOT/sys $FAI_ROOT/dev/pts $FAI_ROOT/dev 2>/dev/null
for dir in $(mount | grep $target | egrep -v "media/mirror|tmpfs"| awk '{print $3}' | sort -r); do
umount $dir
done
fi

# remove device mapper devices
grep -q 'Executing: vgcreate' $LOGDIR/format.log 2>/dev/null
if [ $? -eq 0 ]; then
dmdevices=$(grep 'Executing: vgcreate' $LOGDIR/format.log | awk '{print $3}')
for d in $dmdevices; do
dmsetup remove /dev/$d/*
done
fi

umount_target
cleanup_devicemapper
[ $do_init_tasks -eq 0 ] && return 0
killall -q sshd udevd rsyslogd
umount $FAI_ROOT/proc $FAI_ROOT/sys $FAI_ROOT/dev/pts 2>/dev/null
Expand Down Expand Up @@ -880,6 +888,12 @@ task_partition() {

[ ! -s $LOGDIR/disk_var.sh ] && setup-storage -X |& tee $LOGDIR/format.log

# if we've created device mapper devices, do cleanup on error
grep -q 'Executing: vgcreate' $LOGDIR/format.log 2>/dev/null
if [ $? -eq 0 ]; then
trap "umount_target;cleanup_devicemapper" QUIT EXIT
fi

# partitioning tool must create $LOGDIR/disk_var.sh file
if [ ! -s $LOGDIR/disk_var.sh ]; then
local conffile=$(grep "Using config file:" $LOGDIR/format.log | cut -d: -f2 )
Expand Down

0 comments on commit 6bf4fa6

Please sign in to comment.