[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH initramfs-tools 09/10] local: Invoke local-block scripts from the loop in local_device_setup



Currently we invoke the local-top script once (and possibly
local-block once for /usr) and then poll for block devices to appear
if that wasn't sufficient.  This works for synchronously discovered
devices, devices stacked on top of them (using lvm2/mdadm/cryptsetup)
and asynchronously discovered devices like USB storage.  It doesn't
work for devices stacked on top of USB unless they are set up entirely
via udev hooks.

We need to invoke local-block again before each time we poll.
As the local-block scripts might not be that quick and we don't
have a good way to include their run-time in the timeout check,
wait 1 second rather than 0.1 second between polls.

Closes: #678696
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 initramfs-tools.8 |  8 +++++---
 scripts/local     | 31 ++++++++++++++++---------------
 2 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/initramfs-tools.8 b/initramfs-tools.8
index 01815b9..1cbedd5 100644
--- a/initramfs-tools.8
+++ b/initramfs-tools.8
@@ -416,9 +416,11 @@ present (local) or the network interface is expected to be usable (NFS).
 .TP
 \fB\fI
 local-block
-These scripts are called with the name of a local device other than
-that used for root.  After these scripts have been executed, that
-device node is expected to be present.
+These scripts are called with the name of a local block device.  After
+these scripts have been executed, that device node should be present.
+If the local-top or local-block scripts fail to create the wanted
+device node, the local-block scripts will be called periodically to
+try again.
 
 .TP
 \fB\fI
diff --git a/scripts/local b/scripts/local
index 9a37236..54eb674 100644
--- a/scripts/local
+++ b/scripts/local
@@ -58,26 +58,29 @@ local_device_setup()
 	fi
 
 	# If the root device hasn't shown up yet, give it a little while
-	# to deal with removable devices
+	# to allow for asynchronous device discovery (e.g. USB).  We
+	# also need to keep invoking the local-block scripts in case
+	# there are devices stacked on top of those.
 	if [ ! -e "$1" ] || ! $(get_fstype "$1" >/dev/null); then
 		log_begin_msg "Waiting for $2 file system"
 
-		# Default delay is 30s
+		# Default delay is 30s (approximately)
 		slumber=${ROOTDELAY:-30}
 
-		slumber=$(( ${slumber} * 10 ))
-		while [ ! -e "$1" ] \
-		|| ! $(get_fstype "$1" >/dev/null); do
-			/bin/sleep 0.1
+		while true; do
+			sleep 1
+			local_block "$1"
+			if [ -e "$1" ] && get_fstype "$1" >/dev/null; then
+				wait_for_udev 10
+				log_end_msg 0
+				break
+			fi
 			slumber=$(( ${slumber} - 1 ))
-			[ ${slumber} -gt 0 ] || break
+			if [ ${slumber} -eq 0 ]; then
+				log_end_msg 1 || true
+				break
+			fi
 		done
-
-		if [ ${slumber} -gt 0 ]; then
-			log_end_msg 0
-		else
-			log_end_msg 1 || true
-		fi
 	fi
 
 	# We've given up, but we'll let the user fix matters if they can
@@ -154,8 +157,6 @@ local_mount_fs()
 	read_fstab_entry "$1"
 	MNT_FSNAME=$(resolve_device "$MNT_FSNAME")
 
-	local_block "$MNT_FSNAME"
-
 	local_device_setup "$MNT_FSNAME" "$1"
 
 	local_premount


-- 
Ben Hutchings
Anthony's Law of Force: Don't force it, get a larger hammer.

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: