Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH] umount: do not hang with disconnected NFS mounts
@ 2011-06-29  8:24 Petr Uzel
  2011-06-29  9:12 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Petr Uzel @ 2011-06-29  8:24 UTC (permalink / raw)
  To: util-linux; +Cc: Konstantin Khlebnikov

[-- Attachment #1: Type: text/plain, Size: 2629 bytes --]

Since util-linux commit f4612577c942a3683b97632ad0b49671897c2070,
umount stat(2)s its argument to check whether it can be associated
with some loop device. This could hang with broken NFS mounts.

Fix by first checking mtab if umount's argument is mounted and only if
we fail, check if there is a loop device associated.

http://marc.info/?l=util-linux-ng&m=130924963804836&w=2

Reported-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
 mount/umount.c |   42 ++++++++++++++++++++++--------------------
 1 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/mount/umount.c b/mount/umount.c
index 0349cb3..96c940e 100644
--- a/mount/umount.c
+++ b/mount/umount.c
@@ -600,6 +600,7 @@ umount_file (char *arg) {
 	int fstab_has_user, fstab_has_users, fstab_has_owner, fstab_has_group;
 	int ok, status = 0;
 	struct stat statbuf;
+	char *loopdev = NULL;
 
 	if (!*arg) {		/* "" would be expanded to `pwd` */
 		die(2, _("Cannot unmount \"\"\n"));
@@ -608,26 +609,7 @@ umount_file (char *arg) {
 
 	file = canonicalize(arg); /* mtab paths are canonicalized */
 
-	/* if file is a regular file, check if it is associated
-	 * with some loop device
-	 */
-	if (!stat(file, &statbuf) && S_ISREG(statbuf.st_mode)) {
-		char *loopdev = NULL;
-		switch (find_loopdev_by_backing_file(file, &loopdev)) {
-		case 0:
-			if (verbose)
-				printf(_("%s is associated with %s, trying to unmount it\n"),
-				       arg, loopdev);
-			file = loopdev;
-			break;
-		case 2:
-			if (verbose)
-				printf(_("%s is associated with more than one loop device: not unmounting\n"),
-				       arg);
-			break;
-		}
-	}
-
+try_loopdev:
 	if (verbose > 1)
 		printf(_("Trying to unmount %s\n"), file);
 
@@ -659,6 +641,26 @@ umount_file (char *arg) {
 	if (!mc && verbose)
 		printf(_("Could not find %s in mtab\n"), file);
 
+	/* not found in mtab - check if it is associated with some loop device
+	 * (only if it is a regular file)
+	 */
+	if (!mc && !loopdev && !stat(file, &statbuf) && S_ISREG(statbuf.st_mode)) {
+		switch (find_loopdev_by_backing_file(file, &loopdev)) {
+		case 0:
+			if (verbose)
+				printf(_("%s is associated with %s\n"),
+				       arg, loopdev);
+			file = loopdev;
+			goto try_loopdev;
+			break;
+		case 2:
+			if (verbose)
+				printf(_("%s is associated with more than one loop device: not unmounting\n"),
+				       arg);
+			break;
+		}
+	}
+
 	if (mc) {
 		/*
 		 * helper - umount helper (e.g. pam_mount)
-- 
1.7.3.4


Petr

--
Petr Uzel
IRC: ptr_uzl @ freenode

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: [PATCH] umount: do not hang with disconnected NFS mounts
  2011-06-29  8:24 [PATCH] umount: do not hang with disconnected NFS mounts Petr Uzel
@ 2011-06-29  9:12 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2011-06-29  9:12 UTC (permalink / raw)
  To: util-linux, Konstantin Khlebnikov

On Wed, Jun 29, 2011 at 10:24:09AM +0200, Petr Uzel wrote:
> Since util-linux commit f4612577c942a3683b97632ad0b49671897c2070,
> umount stat(2)s its argument to check whether it can be associated
> with some loop device. This could hang with broken NFS mounts.
> 
> Fix by first checking mtab if umount's argument is mounted and only if
> we fail, check if there is a loop device associated.
> 
> http://marc.info/?l=util-linux-ng&m=130924963804836&w=2
> 
> Reported-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
> Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
> ---
>  mount/umount.c |   42 ++++++++++++++++++++++--------------------
>  1 files changed, 22 insertions(+), 20 deletions(-)

 Applied, thanks (also to Konstantin)!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

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

end of thread, other threads:[~2011-06-29  9:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-29  8:24 [PATCH] umount: do not hang with disconnected NFS mounts Petr Uzel
2011-06-29  9:12 ` Karel Zak

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