From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id C325A1381F3 for ; Sun, 9 Jun 2013 09:44:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 235ABE07FA; Sun, 9 Jun 2013 09:44:47 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 9A3A2E07FA for ; Sun, 9 Jun 2013 09:44:46 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8967F33DF13 for ; Sun, 9 Jun 2013 09:44:45 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 34670E530A for ; Sun, 9 Jun 2013 09:44:44 +0000 (UTC) From: "Richard Yao" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Richard Yao" Message-ID: <1370771036.8f4cf00ddc89eb1c710509a9fd23321cef356730.ryao@gentoo> Subject: [gentoo-commits] proj/genkernel:ryao commit in: defaults/ X-VCS-Repository: proj/genkernel X-VCS-Files: defaults/initrd.scripts X-VCS-Directories: defaults/ X-VCS-Committer: ryao X-VCS-Committer-Name: Richard Yao X-VCS-Revision: 8f4cf00ddc89eb1c710509a9fd23321cef356730 X-VCS-Branch: ryao Date: Sun, 9 Jun 2013 09:44:44 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 6de9b6ac-a8e1-4cb6-afad-f20f443aef21 X-Archives-Hash: fd73f2d498b87859b302398787b4d473 commit: 8f4cf00ddc89eb1c710509a9fd23321cef356730 Author: Richard Yao gentoo org> AuthorDate: Sun Jun 9 09:31:33 2013 +0000 Commit: Richard Yao gentoo org> CommitDate: Sun Jun 9 09:43:56 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/genkernel.git;a=commit;h=8f4cf00d 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 gentoo.org> --- defaults/initrd.scripts | 77 ++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index c8e7abb..2f7286b 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -2,22 +2,6 @@ . /etc/initrd.defaults -call_func_timeout() -{ - local func=$1 timeout=$2 pid watcher - [ $# -ne 2 ] && gen_die "call_func_timeout() called with $# arguments" - - ( ${func} ) & pid=$! - ( sleep ${timeout} && kill -HUP ${pid} ) 2>/dev/null & watcher=$! - if wait ${pid} 2>/dev/null; then - kill -HUP $watcher 2> /dev/null - wait $watcher - return 1 - fi - - return 0 -} - modules_load() { for module in $* do @@ -636,6 +620,12 @@ chooseKeymap() { fi } +# This is helper function meant 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; +} + startVolumes() { #good_msg 'Checking if volumes need to be started...' @@ -714,40 +704,47 @@ startVolumes() { if [ "${USE_ZFS}" = '1' ] then - if [ -z "${ZFS_POOL}" ] - then - good_msg "Importing ZFS pools" - /sbin/zpool import -N -a ${ZPOOL_FORCE} - - if [ "$?" = '0' ] - then - good_msg "Importing ZFS pools succeeded" - else - bad_msg "Imported ZFS pools failed" - fi + # Avoid race involving asynchronous module loading + if call_func_timeout wait_for_ZFS 5 + then + bad_msg "Cannot import ZFS pool because /dev/zfs is missing" else - - if [ "$(zpool list -H -o name ${ZFS_POOL} 2>&1)" = "$ZFS_POOL" ] + if [ -z "${ZFS_POOL}" ] then - good_msg "ZFS pool ${ZFS_POOL} already imported." + good_msg "Importing ZFS pools" + + /sbin/zpool import -N -a ${ZPOOL_FORCE} - if [ -n "${CRYPT_ROOT}" -o -n "${CRYPT_SWAP}" ] + if [ "$?" = '0' ] then - good_msg "LUKS detected. Reimporting ${ZFS_POOL}" - /sbin/zpool export -f "${ZFS_POOL}" - /sbin/zpool import -N ${ZPOOL_FORCE} "${ZFS_POOL}" + good_msg "Importing ZFS pools succeeded" + else + bad_msg "Imported ZFS pools failed" fi else - good_msg "Importing ZFS pool ${ZFS_POOL}" - - /sbin/zpool import -N ${ZPOOL_FORCE} "${ZFS_POOL}" - if [ "$?" = '0' ] + if [ "$(zpool list -H -o name ${ZFS_POOL} 2>&1)" = "$ZFS_POOL" ] then - good_msg "Importing ${ZFS_POOL} succeeded" + good_msg "ZFS pool ${ZFS_POOL} already imported." + + if [ -n "${CRYPT_ROOT}" -o -n "${CRYPT_SWAP}" ] + then + good_msg "LUKS detected. Reimporting ${ZFS_POOL}" + /sbin/zpool export -f "${ZFS_POOL}" + /sbin/zpool import -N ${ZPOOL_FORCE} "${ZFS_POOL}" + fi else - bad_msg "Importing ${ZFS_POOL} failed" + good_msg "Importing ZFS pool ${ZFS_POOL}" + + /sbin/zpool import -N ${ZPOOL_FORCE} "${ZFS_POOL}" + + if [ "$?" = '0' ] + then + good_msg "Import of ${ZFS_POOL} succeeded" + else + bad_msg "Import of ${ZFS_POOL} failed" + fi fi fi fi