SVN: rc-scripts/trunk/rc.d/init.d/functions

arekm arekm at pld-linux.org
Fri Dec 3 11:25:01 CET 2010


Author: arekm
Date: Fri Dec  3 11:25:01 2010
New Revision: 11929

Modified:
   rc-scripts/trunk/rc.d/init.d/functions
Log:
__umount_*loop from FC.

Modified: rc-scripts/trunk/rc.d/init.d/functions
==============================================================================
--- rc-scripts/trunk/rc.d/init.d/functions	(original)
+++ rc-scripts/trunk/rc.d/init.d/functions	Fri Dec  3 11:25:01 2010
@@ -1037,6 +1037,66 @@
 	fi
 }
 
+# __umount_loop awk_program fstab_file first_msg retry_msg umount_args
+# awk_program should process fstab_file and return a list of fstab-encoded
+# paths; it doesn't have to handle comments in fstab_file.
+__umount_loop() {
+	local remaining sig=
+	local retry=3 count
+
+	remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
+	while [ -n "$remaining" -a "$retry" -gt 0 ]; do
+		if [ "$retry" -eq 3 ]; then
+			run_cmd "$3" fstab-decode umount $5 $remaining
+		else
+			run_cmd "$4" fstab-decode umount $5 $remaining
+		fi
+		count=4
+		remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
+		while [ "$count" -gt 0 ]; do
+			[ -z "$remaining" ] && break
+			count=$(($count-1))
+			usleep 500000
+			remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
+		done
+		[ -z "$remaining" ] && break
+		fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null
+		sleep 3
+		retry=$(($retry -1))
+		sig=-9
+	done
+}
+
+# Similar to __umount loop above, specialized for loopback devices
+__umount_loopback_loop() {
+	local remaining devremaining sig=
+	local retry=3
+
+	remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
+	devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
+	while [ -n "$remaining" -a "$retry" -gt 0 ]; do
+		if [ "$retry" -eq 3 ]; then
+			run_cmd "Unmounting loopback filesystems: " \
+				fstab-decode umount $remaining
+		else
+			run_cmd "Unmounting loopback filesystems (retry):" \
+				fstab-decode umount $remaining
+		fi
+		for dev in $devremaining ; do
+			losetup $dev > /dev/null 2>&1 && \
+				run_cmd "Detaching loopback device $dev: " \
+				losetup -d $dev
+		done
+		remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
+		devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
+		[ -z "$remaining" ] && break
+		fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null
+		sleep 3
+		retry=$(($retry -1))
+		sig=-9
+	done
+}
+
 rc_cache_init() {
 	# If we have cachefile, use it.
 	# If we don't, create memory variables and try to save silently,


More information about the pld-cvs-commit mailing list