[SCM] live-build branch, debian-next, updated. debian/3.0_a25-1-28-g0d2cc22

Daniel Baumann daniel at debian.org
Thu Jul 21 14:59:47 UTC 2011


The following commit has been merged in the debian-next branch:
commit 0d2cc22efc66e919848fe0b6559e5b59b08e0afa
Author: Cody A.W. Somerville <cody.somerville at canonical.com>
Date:   Thu Jul 21 17:00:54 2011 +0200

    Adding function for more resilient detachment of loopback devices.

diff --git a/functions/losetup.sh b/functions/losetup.sh
index df7e2d2..039ff3e 100755
--- a/functions/losetup.sh
+++ b/functions/losetup.sh
@@ -7,6 +7,29 @@
 ## This is free software, and you are welcome to redistribute it
 ## under certain conditions; see COPYING for details.
 
+Lodetach ()
+{
+	DEVICE="${1}"
+	ATTEMPT="${2:-1}"
+
+	if [ "${ATTEMPT}" -gt 3 ]
+	then
+		Echo_error "Failed to detach loop device '${DEVICE}'."
+		exit 1
+	fi
+
+	# Changes to block devices result in uevents which trigger rules which in
+	# turn access the loop device (ex. udisks-part-id, blkid) which can cause
+	# a race condition. We call 'udevadm settle' to help avoid this.
+	${LB_ROOT_COMMAND} udevadm settle
+
+	# Loop back devices aren't the most reliable when it comes to writes.
+	# We sleep and sync for good measure - better than build failure.
+	sync
+	sleep 1
+
+	${LB_ROOT_COMMAND} ${LB_LOSETUP} -d "${DEVICE}" || Lodetach "${DEVICE}" "$(expr ${ATTEMPT} + 1)"
+}
 
 Losetup ()
 {
@@ -14,9 +37,9 @@ Losetup ()
 	FILE="${2}"
 	PARTITION="${3:-1}"
 
-	${LB_ROOT_COMMAND} ${LB_LOSETUP} "${DEVICE}" "${FILE}"
+	${LB_ROOT_COMMAND} ${LB_LOSETUP} --read-only "${DEVICE}" "${FILE}"
 	FDISK_OUT="$(${LB_FDISK} -l -u ${DEVICE} 2>&1)"
-	${LB_ROOT_COMMAND} ${LB_LOSETUP} -d "${DEVICE}"
+	Lodetach "${DEVICE}"
 
 	LOOPDEVICE="$(echo ${DEVICE}p${PARTITION})"
 
diff --git a/scripts/build/lb_binary_usb b/scripts/build/lb_binary_usb
index e6c29ea..96feee4 100755
--- a/scripts/build/lb_binary_usb
+++ b/scripts/build/lb_binary_usb
@@ -164,8 +164,7 @@ case "${LB_BUILD_WITH_CHROOT}" in
 		;;
 esac
 
-sleep 1
-${LB_LOSETUP} -d ${FREELO}
+Lodetach ${FREELO}
 
 FREELO="$(${LB_LOSETUP} -f)"
 Losetup $FREELO chroot/binary.img 1
@@ -254,8 +253,7 @@ then
 	esac
 fi
 
-sleep 1
-${LB_LOSETUP} -d ${FREELO}
+Lodetach ${FREELO}
 
 echo "!!! The above error/warning messages can be ignored !!!"
 
@@ -274,8 +272,7 @@ case "${LB_BUILD_WITH_CHROOT}" in
 		;;
 esac
 
-sleep 1
-${LB_LOSETUP} -d ${FREELO}
+Lodetach ${FREELO}
 
 if [ -n "${MAKEDEV}" ]
 then
diff --git a/scripts/build/lb_source_usb b/scripts/build/lb_source_usb
index 166e86a..9a598e4 100755
--- a/scripts/build/lb_source_usb
+++ b/scripts/build/lb_source_usb
@@ -93,8 +93,7 @@ Echo_warning "!!! The following error/warning messages can be ignored !!!"
 Losetup $FREELO source.img 0
 Chroot chroot "parted -s ${FREELO} mklabel msdos" || true
 Chroot chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
-sleep 1
-${LB_LOSETUP} -d ${FREELO}
+Lodetach ${FREELO}
 
 Losetup $FREELO source.img 1
 
@@ -122,15 +121,13 @@ ${LB_ROOT_COMMAND} mount ${FREELO} source.tmp
 cp -r source/* source.tmp
 ${LB_ROOT_COMMAND} umount source.tmp
 rmdir source.tmp
-sleep 1
-${LB_LOSETUP} -d ${FREELO}
+Lodetach ${FREELO}
 Echo_warning "!!! The above error/warning messages can be ignored !!!"
 
 FREELO="$(${LB_LOSETUP} -f)"
 Losetup "$FREELO" source.img 0
 Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
-sleep 1
-${LB_LOSETUP} -d ${FREELO}
+Lodetach ${FREELO}
 
 if [ -n "${MAKEDEV}" ]
 then

-- 
live-build



More information about the debian-live-changes mailing list