[buildd-tools-devel] [PATCH 06/11] [union] Cleanup union handling in scripts

Jan-Marek Glogowski glogow at fbihome.de
Thu Jul 30 19:10:55 UTC 2009


The underlay directory should be empty after umounts, so it
should be sufficient to remove it. This won't purge content
if umount failed.

Additionally cleanup 10mount to fail if union filesystem is
missing and just cleanup underlay in union mode.
---
 etc/setup.d/05union |    2 +-
 etc/setup.d/10mount |   38 ++++++++++++++++++++++++++------------
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/etc/setup.d/05union b/etc/setup.d/05union
index 8cc6882..4413e1b 100644
--- a/etc/setup.d/05union
+++ b/etc/setup.d/05union
@@ -60,7 +60,7 @@ if [ -n "${CHROOT_UNION_TYPE}" ] && [ "${CHROOT_UNION_TYPE}" != 'none' ]; then
 	    # For safety, use rmdir rather than rm -rf in case
 	    # umount failed.
 	    if [ "$AUTH_VERBOSITY" = "verbose" ]; then
-		echo "Purging $CHROOT_UNION_UNDERLAY_DIRECTORY"
+		echo "Removing $CHROOT_UNION_UNDERLAY_DIRECTORY"
 	    fi
 	    if [ -d "${CHROOT_UNION_UNDERLAY_DIRECTORY}" ]; then
 		rmdir "${CHROOT_UNION_UNDERLAY_DIRECTORY}"
diff --git a/etc/setup.d/10mount b/etc/setup.d/10mount
index 190dd58..0417662 100755
--- a/etc/setup.d/10mount
+++ b/etc/setup.d/10mount
@@ -67,9 +67,20 @@ do_umount_all()
 }
 
 # Mount a filesystem union
-# $1: read-only branch
+# $1: the mount location
 do_mount_fs_union()
 {
+    # Try mounting the filesystem module
+    if ! grep -q "${CHROOT_UNION_TYPE}$" /proc/filesystems; then
+	modprobe ${CHROOT_UNION_TYPE} &> /dev/null || true
+    fi
+
+    # Fail if filesystem is not available
+    if ! grep -q "${CHROOT_UNION_TYPE}$" /proc/filesystems; then
+	echo "Union filesystem '$CHROOT_UNION_TYPE' is not available"
+	exit 1
+    fi
+
     # Prepare mount options (branch config) for union type
     if [ -z "$CHROOT_UNION_MOUNT_OPTIONS" ]; then
 	case $CHROOT_UNION_TYPE in
@@ -87,7 +98,7 @@ do_mount_fs_union()
     fi
 
     # Try mounting fs
-    mount -t $CHROOT_UNION_TYPE -o "$CHROOT_UNION_MOUNT_OPTIONS" ${CHROOT_NAME} ${CHROOT_MOUNT_LOCATION}
+    mount -t $CHROOT_UNION_TYPE -o "$CHROOT_UNION_MOUNT_OPTIONS" ${CHROOT_NAME} "${1}"
 }
 
 if [ "$AUTH_VERBOSITY" = "verbose" ]; then
@@ -139,20 +150,23 @@ if [ "$CHROOT_TYPE" = "directory" ] || [ "$CHROOT_TYPE" = "file" ] || [ "$CHROOT
 
         # If recovering, we want to remount all filesystems to ensure
         # a sane state.
-	if [ $1 = "setup-recover" ]; then
-	    do_umount_all "$CHROOT_MOUNT_LOCATION"
+	if [ "${CREATE_UNION}" = "yes" ]; then
+	    CHROOT_UNION_MOUNT_LOCATION="${CHROOT_MOUNT_LOCATION}"
+	    CHROOT_MOUNT_LOCATION="${CHROOT_UNION_UNDERLAY_DIRECTORY}"
+	    if [ $1 = "setup-recover" ]; then
+		do_umount_all "$CHROOT_UNION_MOUNT_LOCATION"
+	    fi
 	fi
 
-	if [ "$CREATE_UNION" = "yes" ]; then
-	    MOUNT_LOCATION="$CHROOT_UNDERLAY_DIR"
-	else
-	    MOUNT_LOCATION="$CHROOT_MOUNT_LOCATION"
+	# If recovering, we want to remount all filesystems to ensure
+	# a sane state.
+	if [ $1 = "setup-recover" ]; then
+	    do_umount_all "$CHROOT_MOUNT_LOCATION"
 	fi
 
-	do_mount "$CHROOT_MOUNT_OPTIONS" "$CHROOT_MOUNT_DEVICE" "$MOUNT_LOCATION"
-
+	do_mount "$CHROOT_MOUNT_OPTIONS" "$CHROOT_MOUNT_DEVICE" "$CHROOT_MOUNT_LOCATION"
 	if [ "$CREATE_UNION" = "yes" ]; then
-	    do_mount_fs_union
+	    do_mount_fs_union "$CHROOT_UNION_MOUNT_LOCATION"
 	fi
 
 	if [ -n "$FSTAB" ]; then
@@ -168,7 +182,7 @@ if [ "$CHROOT_TYPE" = "directory" ] || [ "$CHROOT_TYPE" = "file" ] || [ "$CHROOT
     elif [ $1 = "setup-stop" ]; then
 
 	do_umount_all "$CHROOT_MOUNT_LOCATION"
-	if [ "${CHROOT_UNION_TYPE:-none}" != "none" ]; then
+	if [ "${CREATE_UNION}" = "yes" ]; then
 	    do_umount_all "$CHROOT_UNION_UNDERLAY_DIRECTORY"
 	fi
 
-- 
1.6.3.2




More information about the Buildd-tools-devel mailing list