Skip to contentSkip to conversation

umount loopback filessystems on autofs stop

PATCH In review Jeff Moyer 4 participants 5 messages Sep 2, 2004 – Sep 3, 2004 Kernel automounter

lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 umount loopback filessystems on autofs stop

Hello,

The netfs scripts for Red Hat go through and umount any loopback devices before attempting to umount the encompassing filesystem. This seems a sane thing to do (and I have a bug on said issue), so I've added similar functionality to the autofs init script. Attached is a patch. Comments encouraged. Testing by debian folks would be nice, too.

-Jeff

samples/rc.autofs.in renamed from samples/rc.autofs.in.umount-loopback +27 -0
@@ -351,6 +351,31 @@ function signal_automounts()
 	return $RETVAL
 }
 
+function umount_loopback()
+{
+    loops=`LC_ALL=C awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts`
+    automounts=`LC_ALL=C awk '!/^#/ && $1 ~ /^automount/ {print $2}' /proc/mounts`
+
+    for l in $loops
+    do
+	for a in $automounts
+	do
+	    command="echo $l | grep -E '^$a'"
+	    match=`echo $command | sh`
+	    if [ -n "$match" ]; then
+		echo ""
+		echo -n $"Unmounting loopback filesystem $match:  "
+		umount -d $match
+		if [ $? -eq 0 ]; then
+		    echo "done"
+		else
+		    echo "failed ($?)"
+		fi
+	    fi
+	done
+    done
+}
+
 # Redhat start/stop function.
 #
 function redhat()
@@ -386,6 +411,7 @@ case "$1" in
 	if [ -z "`pidofproc $prog`" -a -z "`getmounts`" ]; then
 		RETVAL=0
 	else
+		umount_loopback
 		signal_automounts
 		RETVAL=$?
 	fi
@@ -477,6 +503,7 @@ case "$1" in
 	;;
     stop)
 	echo 'Stopping automounter.'
+	umount_loopback
 	start-stop-daemon --stop --quiet --signal USR2 --exec $DAEMON
 	;;
     reload|restart)
#1 lore raw

Using /proc/mounts could be an issue for anyone trying to use this with a kernel that truncates /proc/mounts.

Quoted 66 lines

Hello,

The netfs scripts for Red Hat go through and umount any loopback devices before attempting to umount the encompassing filesystem. This seems a sane thing to do (and I have a bug on said issue), so I've added similar functionality to the autofs init script. Attached is a patch. Comments encouraged. Testing by debian folks would be nice, too.

(quoted diff) +0 -1
-Jeff
samples/rc.autofs.in renamed from samples/rc.autofs.in.umount-loopback +27 -0
@@ -351,6 +351,31 @@ function signal_automounts()
 	return $RETVAL
 }
 
+function umount_loopback()
+{
+    loops=`LC_ALL=C awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts`
+    automounts=`LC_ALL=C awk '!/^#/ && $1 ~ /^automount/ {print $2}' /proc/mounts`
+
+    for l in $loops
+    do
+	for a in $automounts
+	do
+	    command="echo $l | grep -E '^$a'"
+	    match=`echo $command | sh`
+	    if [ -n "$match" ]; then
+		echo ""
+		echo -n $"Unmounting loopback filesystem $match:  "
+		umount -d $match
+		if [ $? -eq 0 ]; then
+		    echo "done"
+		else
+		    echo "failed ($?)"
+		fi
+	    fi
+	done
+    done
+}
+
 # Redhat start/stop function.
 #
 function redhat()
@@ -386,6 +411,7 @@ case "$1" in
 	if [ -z "`pidofproc $prog`" -a -z "`getmounts`" ]; then
 		RETVAL=0
 	else
+		umount_loopback
 		signal_automounts
 		RETVAL=$?
 	fi
@@ -477,6 +503,7 @@ case "$1" in
 	;;
     stop)
 	echo 'Stopping automounter.'
+	umount_loopback
 	start-stop-daemon --stop --quiet --signal USR2 --exec $DAEMON
 	;;
     reload|restart)

_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs

#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 1 line · Joseph V Moss

Using /proc/mounts could be an issue for anyone trying to use this

with a kernel

Quoted 2 lines

that truncates /proc/mounts.

Which kernel truncates /proc/mounts?

Any recent kernel uses the seq_file interface which guarantees that nothing gets truncated. I have a system up and running that works fine with about 2500 mounts.

Quoted 5 lines
Quoted 5 lines

Hello,

The netfs scripts for Red Hat go through and umount any loopback devices before attempting to umount the encompassing filesystem. This seems a

sane

Quoted 7 lines
Quoted 7 lines

thing to do (and I have a bug on said issue), so I've added similar functionality to the autofs init script. Attached is a patch. Comments encouraged. Testing by debian folks would be nice, too.

-Jeff

--- autofs-4.1.3/samples/rc.autofs.in.umount-loopback 2004-09-02

15:55:21.722705296 -0400

Quoted 8 lines

samples/rc.autofs.in function signal_automounts() · line 356

Quoted 8 lines

+++ autofs-4.1.3/samples/rc.autofs.in 2004-09-02 16:16:09.985940440 -0400

samples/rc.autofs.in renamed from samples/rc.autofs.in.umount-loopback +3 -0
@@ -351,6 +351,31 @@ function signal_automounts()
 	return $RETVAL
 }
 
+function umount_loopback()
+{
+    loops=`LC_ALL=C awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/"

{print $2}' /proc/mounts`

Quoted 1 line

Review function signal_automounts() · line 357

Quoted 1 line
(quoted diff) +1 -0
+    automounts=`LC_ALL=C awk '!/^#/ && $1 ~ /^automount/ {print $2}'

/proc/mounts`

Quoted 41 lines
Quoted 41 lines
samples/rc.autofs.in renamed from samples/rc.autofs.in.umount-loopback +23 -0
+
+    for l in $loops
+    do
+	for a in $automounts
+	do
+	    command="echo $l | grep -E '^$a'"
+	    match=`echo $command | sh`
+	    if [ -n "$match" ]; then
+		echo ""
+		echo -n $"Unmounting loopback filesystem $match:  "
+		umount -d $match
+		if [ $? -eq 0 ]; then
+		    echo "done"
+		else
+		    echo "failed ($?)"
+		fi
+	    fi
+	done
+    done
+}
+
 # Redhat start/stop function.
 #
 function redhat()
@@ -386,6 +411,7 @@ case "$1" in
 	if [ -z "`pidofproc $prog`" -a -z "`getmounts`" ]; then
 		RETVAL=0
 	else
+		umount_loopback
 		signal_automounts
 		RETVAL=$?
 	fi
@@ -477,6 +503,7 @@ case "$1" in
 	;;
    stop)
 	echo 'Stopping automounter.'
+	umount_loopback
 	start-stop-daemon --stop --quiet --signal USR2 --exec $DAEMON
 	;;
    reload|restart)
Quoted 11 lines
Quoted 5 lines

_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs

_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs

- --
Mike Waychison
Sun Microsystems, Inc.
1 (650) 352-5299 voice
1 (416) 202-8336 voice
http://www.sun.com

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NOTICE: The opinions expressed in this email are held by me, and may not represent the views of Sun Microsystems, Inc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBN9d9dQs4kOxk3/MRAuv7AJ9RwuxkWHgwUkHsW/+C+Qoy/5hzhgCdFoSW fM9teS9ID1cEs0ZzVJfgO+g=
=qIAQ
-----END PGP SIGNATURE-----

#3 lore raw
Quoted 13 lines · Mike Waychison

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 1 line · Joseph V Moss

Using /proc/mounts could be an issue for anyone trying to use this

with a kernel

Quoted 2 lines

that truncates /proc/mounts.

Quoted 5 lines

Which kernel truncates /proc/mounts?

Any recent kernel uses the seq_file interface which guarantees that nothing gets truncated. I have a system up and running that works fine with about 2500 mounts.

seq_file support for /proc/mounts was introduced with 2.4.19

James Pearson

#4 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 18 lines · James Pearson
Quoted 16 lines · Mike Waychison

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 1 line · Joseph V Moss

Using /proc/mounts could be an issue for anyone trying to use this

with a kernel

Quoted 2 lines

that truncates /proc/mounts.

Which kernel truncates /proc/mounts?

Quoted 8 lines
Quoted 3 lines

Any recent kernel uses the seq_file interface which guarantees that nothing gets truncated. I have a system up and running that works fine with about 2500 mounts.

seq_file support for /proc/mounts was introduced with 2.4.19

Heh, which is only over two years old :)

Seriously, if your kernel doesn't do this right, the problem doesn't lie with Jeff's initscript patch: please consider upgrading.

- --
Mike Waychison
Sun Microsystems, Inc.
1 (650) 352-5299 voice
1 (416) 202-8336 voice
http://www.sun.com

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NOTICE: The opinions expressed in this email are held by me, and may not represent the views of Sun Microsystems, Inc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBOGPpdQs4kOxk3/MRAkGlAJkBLHG2rYJZS9IbPn/qLP2mPAitPwCfcVv3 NegYJQX2jtqQwNV9STncXnY=
=k5GF
-----END PGP SIGNATURE-----