* [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
* Re: [PATCH] udev/mount.sh: try to kill active processes before umount
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
0 siblings, 1 reply; 7+ messages in thread
From: Koen Kooi @ 2010-06-22 11:02 UTC (permalink / raw)
To: openembedded-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Wouldn't a umount -l be a lot better in this case?
On 22-06-10 12:08, Steffen Sledz wrote:
> * 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
iD8DBQFMIJhGMkyGM64RGpERAo+WAJsEfFfYOKZzeSChA8FBf6SmLSlEbgCdHP2z
d2kNPcFp4RiRHac8Zqh8Hb4=
=HT9O
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] udev/mount.sh: try to kill active processes before umount
2010-06-22 11:02 ` Koen Kooi
@ 2010-06-22 12:01 ` Steffen Sledz
2010-06-22 14:29 ` Koen Kooi
2010-06-22 20:54 ` Phil Blundell
0 siblings, 2 replies; 7+ messages in thread
From: Steffen Sledz @ 2010-06-22 12:01 UTC (permalink / raw)
To: openembedded-devel
Am 22.06.2010 13:02, schrieb Koen Kooi:
> 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
--
Steffen Sledz
DResearch Digital Media Systems GmbH
Otto-Schmirgal-Str.3, D-10319 Berlin, Germany
Tel: +49 (30) 515932237 mailto:sledz@DResearch.DE
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] udev/mount.sh: try to kill active processes before umount
2010-06-22 12:01 ` Steffen Sledz
@ 2010-06-22 14:29 ` Koen Kooi
2010-06-22 19:11 ` John Willis
2010-06-22 20:54 ` Phil Blundell
1 sibling, 1 reply; 7+ messages in thread
From: Koen Kooi @ 2010-06-22 14:29 UTC (permalink / raw)
To: openembedded-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 22-06-10 14:01, Steffen Sledz wrote:
> Am 22.06.2010 13:02, schrieb Koen Kooi:
>> 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.
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-----
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] udev/mount.sh: try to kill active processes before umount
2010-06-22 14:29 ` Koen Kooi
@ 2010-06-22 19:11 ` John Willis
2010-06-23 6:13 ` Steffen Sledz
0 siblings, 1 reply; 7+ messages in thread
From: John Willis @ 2010-06-22 19:11 UTC (permalink / raw)
To: openembedded-devel
> >> 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.
>
> I don't like the idea of killing random processes, especially is that
process is
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] udev/mount.sh: try to kill active processes before umount
2010-06-22 12:01 ` Steffen Sledz
2010-06-22 14:29 ` Koen Kooi
@ 2010-06-22 20:54 ` Phil Blundell
1 sibling, 0 replies; 7+ messages in thread
From: Phil Blundell @ 2010-06-22 20:54 UTC (permalink / raw)
To: openembedded-devel
On Tue, 2010-06-22 at 14:01 +0200, Steffen Sledz wrote:
> 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.
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.
^ permalink raw reply [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