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 C0FDE138200 for ; Sun, 9 Jun 2013 10:02:20 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2C17BE0801; Sun, 9 Jun 2013 10:02:20 +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 9273AE0801 for ; Sun, 9 Jun 2013 10:02:19 +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 7F3FA33E260 for ; Sun, 9 Jun 2013 10:02:18 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 26F8BE468F for ; Sun, 9 Jun 2013 10:02:17 +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: <1370772095.6a1fe6ba0d836242d2ab2b600f34cc0a98c883d2.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: 6a1fe6ba0d836242d2ab2b600f34cc0a98c883d2 X-VCS-Branch: ryao Date: Sun, 9 Jun 2013 10:02:17 +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: 702e207e-8c9b-4900-9fa8-2cd73656bf09 X-Archives-Hash: 70c96c31ffeee3d3e0e7dc273aa71bfa commit: 6a1fe6ba0d836242d2ab2b600f34cc0a98c883d2 Author: Richard Yao gentoo org> AuthorDate: Sun Jun 9 09:31:33 2013 +0000 Commit: Richard Yao gentoo org> CommitDate: Sun Jun 9 10:01:35 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/genkernel.git;a=commit;h=6a1fe6ba 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..0b76011 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 waitForZFS 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