Openembedded Devel Discussions
 help / color / mirror / Atom feed
* [PATCH] udev/mount.sh: try to kill active processes before umount
@ 2010-06-22 10:08 Steffen Sledz
  2010-06-22 11:02 ` Koen Kooi
  0 siblings, 1 reply; 7+ messages in thread
From: Steffen Sledz @ 2010-06-22 10:08 UTC (permalink / raw)
  To: openembedded-devel

* umount will fail if there are processes accessing files at the
  device. Therefor try to kill these processes using fuser if
  available.

Signed-off-by: Steffen Sledz <sledz@dresearch.de>
---
 recipes/udev/files/mount.sh        |   21 ++++++++++++++++++++-
 recipes/udev/files/slugos/mount.sh |   21 ++++++++++++++++++++-
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/recipes/udev/files/mount.sh b/recipes/udev/files/mount.sh
index be8b3df..79c6891 100644
--- a/recipes/udev/files/mount.sh
+++ b/recipes/udev/files/mount.sh
@@ -8,6 +8,7 @@
 MOUNT="/bin/mount"
 PMOUNT="/usr/bin/pmount"
 UMOUNT="/bin/umount"
+FUSER="/usr/bin/fuser"
 name="`basename "$DEVNAME"`"
 
 for line in `cat /etc/udev/mount.blacklist | grep -v ^#`
@@ -64,7 +65,25 @@ fi
 if [ "$ACTION" = "remove" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then
 	for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " `
 	do
-		$UMOUNT $mnt
+		if [ -x "$FUSER" ]; then
+			$FUSER -k -KILL -m $mnt
+			for try in `seq 10`
+			do
+				$FUSER -m $mnt || break
+				sleep 1
+				logger "mount.sh/automount" "$try secs waited for processes active at $mnt to finish on SIGKILL"
+			done
+
+			if $FUSER -m $mnt 
+			then
+				logger "mount.sh/automount" "Could not kill all processes using files at $mnt, try forced umount"
+				$UMOUNT -f $mnt
+			else
+				$UMOUNT $mnt
+			fi
+		else
+			$UMOUNT $mnt
+		fi
 	done
 	
 	# Remove empty directories from auto-mounter
diff --git a/recipes/udev/files/slugos/mount.sh b/recipes/udev/files/slugos/mount.sh
index 0990a7e..f67c3ff 100644
--- a/recipes/udev/files/slugos/mount.sh
+++ b/recipes/udev/files/slugos/mount.sh
@@ -8,6 +8,7 @@
 MOUNT="/bin/mount"
 PMOUNT="/usr/bin/pmount"
 UMOUNT="/bin/umount"
+FUSER="/usr/bin/fuser"
 name="`basename "$DEVNAME"`"
 
 if ( blkid "$DEVNAME" | grep -q 'TYPE="mdraid"' )
@@ -75,7 +76,25 @@ fi
 if [ "$ACTION" = "remove" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then
 	for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " `
 	do
-		$UMOUNT $mnt
+		if [ -x "$FUSER" ]; then
+			$FUSER -k -KILL -m $mnt
+			for try in `seq 10`
+			do
+				$FUSER -m $mnt || break
+				sleep 1
+				logger "mount.sh/automount" "$try secs waited for processes active at $mnt to finish on SIGKILL"
+			done
+
+			if $FUSER -m $mnt 
+			then
+				logger "mount.sh/automount" "Could not kill all processes using files at $mnt, try forced umount"
+				$UMOUNT -f $mnt
+			else
+				$UMOUNT $mnt
+			fi
+		else
+			$UMOUNT $mnt
+		fi
 	done
 	
 	# Remove empty directories from auto-mounter
-- 
1.6.4.2




^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-06-23  6:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-22 10:08 [PATCH] udev/mount.sh: try to kill active processes before umount Steffen Sledz
2010-06-22 11:02 ` Koen Kooi
2010-06-22 12:01   ` Steffen Sledz
2010-06-22 14:29     ` Koen Kooi
2010-06-22 19:11       ` John Willis
2010-06-23  6:13         ` Steffen Sledz
2010-06-22 20:54     ` Phil Blundell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox