From 9bb2beea5be2839587129dfe01329933ea103edb Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Sun, 9 Jun 2013 05:31:33 -0400 Subject: [PATCH] Import pool after ZFS module finishes loading There is a race between ZFS module initialization and our attempt to import pools. We address this by doing a busy wait for the /dev/zfs device to appear. We wait a maximum of 5 seconds for the device to appear. We also slightly alter output messages to be more readable. Signed-off-by: Richard Yao Conflicts: defaults/initrd.scripts --- defaults/initrd.scripts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index b353817..d78ecfe 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -829,6 +829,12 @@ choose_keymap() { fi } +# This helper function is to be called using call_func_timeout. +# It enables us to wait a reasonable amount of time until /dev/zfs appears. +waitForZFS() { + while [ ! -c /dev/zfs ]; do echo >/dev/null; done; +} + start_volumes() { #good_msg 'Checking if volumes need to be started...' @@ -914,7 +920,12 @@ start_volumes() { if [ "${USE_ZFS}" = '1' ] then - if [ -z "${ZFS_POOL}" ] + + # Avoid race involving asynchronous module loading + if call_func_timeout waitForZFS 5 + then + bad_msg "Cannot import ZFS pool because /dev/zfs is missing" + elif [ -z "${ZFS_POOL}" ] then good_msg "Importing ZFS pools" @@ -945,9 +956,9 @@ start_volumes() { if [ "$?" = '0' ] then - good_msg "Importing ${ZFS_POOL} succeeded" + good_msg "Import of ${ZFS_POOL} succeeded" else - bad_msg "Importing ${ZFS_POOL} failed" + bad_msg "Import of ${ZFS_POOL} failed" fi fi fi