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 284EF1381F3 for ; Sun, 9 Jun 2013 09:58:24 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 60FCBE081D; Sun, 9 Jun 2013 09:58:23 +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 80C19E07FB for ; Sun, 9 Jun 2013 09:58:22 +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 6721433E2EE for ; Sun, 9 Jun 2013 09:58:21 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 0A921E545F for ; Sun, 9 Jun 2013 09:58:20 +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: <1370771844.643b61faf11add722bcaef2e0bd9c22e9b440c5f.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: 643b61faf11add722bcaef2e0bd9c22e9b440c5f X-VCS-Branch: ryao Date: Sun, 9 Jun 2013 09:58:20 +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: 8cb70a6d-6e93-4b88-9dce-372ee6d2e3a2 X-Archives-Hash: 1099c74d6195afc1e63b4652d0bc47b2 commit: 643b61faf11add722bcaef2e0bd9c22e9b440c5f Author: Richard Yao gentoo org> AuthorDate: Sun Jun 9 09:31:33 2013 +0000 Commit: Richard Yao gentoo org> CommitDate: Sun Jun 9 09:57:24 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/genkernel.git;a=commit;h=643b61fa 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 | 61 ++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index c8e7abb..bc647d8 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -636,6 +636,12 @@ chooseKeymap() { 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; +} + startVolumes() { #good_msg 'Checking if volumes need to be started...' @@ -714,40 +720,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" - if [ -n "${CRYPT_ROOT}" -o -n "${CRYPT_SWAP}" ] + /sbin/zpool import -N -a ${ZPOOL_FORCE} + + 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