udev/mount.sh: try to kill active processes before umount
PATCH 1/1 udev/mount.sh: try to kill active processes before umount
* umount will fail if there are processes accessing files at the device. Therefor try to kill these processes using fuser if available.
--- recipes/udev/files/mount.sh | 21 ++++++++++++++++++++- recipes/udev/files/slugos/mount.sh | 21 ++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-)
recipes/udev/files/mount.sh +20 -1
@@ -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
recipes/udev/files/slugos/mount.sh +20 -1
@@ -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
Signature · 1 line
1.6.4.2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Wouldn't a umount -l be a lot better in this case?
Quoted 78 lines · Steffen Sledz
* 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 <[email protected]>--- recipes/udev/files/mount.sh | 21 ++++++++++++++++++++- recipes/udev/files/slugos/mount.sh | 21 ++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-)recipes/udev/files/mount.sh +20
-1@@ -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-mounterrecipes/udev/files/slugos/mount.sh +13
-1@@ -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"
recipes/udev/files/slugos/mount.sh fi · line 100
Quoted 10 lines
recipes/udev/files/slugos/mount.sh +7
-0+ $UMOUNT -f $mnt + else + $UMOUNT $mnt + fi + else + $UMOUNT $mnt + fi done # Remove empty directories from auto-mounter
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
iD8DBQFMIJhGMkyGM64RGpERAo+WAJsEfFfYOKZzeSChA8FBf6SmLSlEbgCdHP2z d2kNPcFp4RiRHac8Zqh8Hb4=
=HT9O
-----END PGP SIGNATURE-----
Am 22.06.2010 13:02, schrieb Koen Kooi:
Quoted 1 line
Wouldn't a umount -l be a lot better in this case?
I'm not sure if this would do the right things.
mount.sh is called with REMOVE action when the device *is disconnected* i.e. the filesystem is no longer available. So i believe it is not possible to "cleanup all references to the filesystem as soon as it is not busy anymore".
I think killing all the processes is the only way here.
Steffen
Signature · 8 lines
Steffen Sledz DResearch Digital Media Systems GmbH Otto-Schmirgal-Str.3, D-10319 Berlin, Germany Tel: +49 (30) 515932237 mailto:[email protected] Fax: +49 (30) 515932299 http://www.DResearch.DE Geschäftsführer: Dr. Michael Weber, Werner Mögle; Amtsgericht Berlin Charlottenburg; HRB 54412; Ust.-IDNr. DE169013825; WEEE Reg.-Nr. DE 85995642
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 11 lines · Steffen Sledz
Am 22.06.2010 13:02, schrieb Koen Kooi:
Quoted 1 line
Wouldn't a umount -l be a lot better in this case?
I'm not sure if this would do the right things.
mount.shis called with REMOVE action when the device *is disconnected* i.e. the filesystem is no longer available. So i believe it is not possible to "cleanup all references to the filesystem as soon as it is not busy anymore".I think killing all the processes is the only way here.
I don't like the idea of killing random processes, especially is that process is smart enough to "move on" after a timeout.
regards,
Koen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
iD8DBQFMIMiwMkyGM64RGpERAiFVAKCzGeqyIx8Mh+EHcXz8/w3uK20D0ACfXR++ x3OaWYcazQ9Wc1/cObARf2E=
=xOUQ
-----END PGP SIGNATURE-----
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Wouldn't a umount -l be a lot better in this case?
I'm not sure if this would do the right things.
Quoted 8 lines
Quoted 6 lines
mount.shis called with REMOVE action when the device *is disconnected* i.e. the filesystem is no longer available. So i believe it is not possible to "cleanup all references to the filesystem as soon as it is not busy anymore".I think killing all the processes is the only way here.
I don't like the idea of killing random processes, especially is that
process is
Quoted 1 line
smart enough to "move on" after a timeout.
I concur, the issue at hand is a little 'rock and a hard place' (what is the 'correct' way to deal with processes left over when the file system has most definitely been pulled with prejudice ;)). Killing processes feels a little wrong as a lot of apps can recover from filesystem pulls.
That said, we have been experimenting with umount -l on the OpenPandora with some promising initial results. We are also playing with some other changes that may also be of wider interest (mountpoints based on SD card labels if they exist etc.). I'll keep this thread updated with the results of testing, if it works out well I was going to suggest some of the changes for the stock mount.sh.
There is little harm in a umount -l in the short term.
Regards,
John
Am 22.06.2010 21:11, schrieb John Willis:
Quoted 1 line
There is little harm in a umount -l in the short term.
OK, i've prepared a new patch for this.
Because i forgot the --in-reply-to it started a new thread. Sorry.
Steffen
Quoted 6 lines · Steffen Sledz
mount.shis called with REMOVE action when the device *is disconnected* i.e. the filesystem is no longer available. So i believe it is not possible to "cleanup all references to the filesystem as soon as it is not busy anymore".I think killing all the processes is the only way here.
I don't think that's necessarily true. Any process that is holding a file open on the removed device will get an I/O error the next time it tries to access that filesystem. Obviously, whether or not it handles that error correctly is open to question, but increasingly many apps do get it right and it seems a bit sad to kill them all off just in case one doesn't do the right thing.
In the worst case, an app that chronically ignores I/O errors will just keep the file descriptor open forever (or until it exits normally). That doesn't sound like such an awful outcome.
p.