Only unmount directories that are mounted
To avoid failures with double unmount, skip unmounting the mountpoints that are managed by block device. Change-Id: I228779eb9bf544a27a53e5017c87573023fd375a
This commit is contained in:
parent
6d0b9abc0f
commit
5b305ffa7b
@ -343,6 +343,8 @@ function unmount_dir {
|
|||||||
local dir="$1"
|
local dir="$1"
|
||||||
local real_dir
|
local real_dir
|
||||||
local mnts
|
local mnts
|
||||||
|
local split_mounts
|
||||||
|
local found_mountpoint
|
||||||
|
|
||||||
if [ ! -d $dir ]; then
|
if [ ! -d $dir ]; then
|
||||||
echo "*** $dir is not a directory"
|
echo "*** $dir is not a directory"
|
||||||
@ -353,12 +355,30 @@ function unmount_dir {
|
|||||||
# /proc/mounts is the real path
|
# /proc/mounts is the real path
|
||||||
real_dir=$(readlink -e $dir)
|
real_dir=$(readlink -e $dir)
|
||||||
|
|
||||||
|
# populate the exported mountpoints
|
||||||
|
IFS='|' read -ra split_mounts <<< "$DIB_MOUNTPOINTS"
|
||||||
|
|
||||||
|
|
||||||
# note the "/" on real_dir ... we are just looking for things
|
# note the "/" on real_dir ... we are just looking for things
|
||||||
# mounted *underneath* this directory.
|
# mounted *underneath* this directory.
|
||||||
mnts=$(awk '{print $2}' < /proc/mounts | grep "^$real_dir/" | sort -r)
|
mnts=$(awk '{print $2}' < /proc/mounts | grep "^$real_dir/" | sort -r)
|
||||||
for m in $mnts; do
|
for m in $mnts; do
|
||||||
|
# check if suffix is in array
|
||||||
|
found_mountpoint=false
|
||||||
|
for mountpoint in "${split_mounts[@]}"; do
|
||||||
|
if [[ "$mountpoint" != "/" ]]; then
|
||||||
|
if [[ "$m" == *$mountpoint ]]; then
|
||||||
|
echo "Mountpoint $m managed by block device; skipping"
|
||||||
|
found_mountpoint=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ $found_mountpoint == false ]; then
|
||||||
|
# unmount the directory as it is not managed by block device
|
||||||
echo "Unmount $m"
|
echo "Unmount $m"
|
||||||
sudo umount -fl $m || true
|
sudo umount -fl $m || true
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user