commit:     5c5c32aa7261a29a3ac48035086bb59449d3804d
Author:     Georgy Yakovlev <ya <AT> sysdump <DOT> net>
AuthorDate: Wed Jun  6 02:33:07 2018 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Wed Jun  6 06:02:35 2018 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=5c5c32aa

Add option to force importing zpool using cache

Add simple option to pass to kernel via loader.

dozfs=cache will use /etc/zfs/zpool.cache
avoiding 30+ second wait for udev in zpool import

Also it's possible to use both cache and force
at the same time:
dozfs=force,cache (order is not important) will
force import and use cache.

Closes: https://bugs.gentoo.org/627320
Signed-off-by: Georgy Yakovlev <ya <AT> sysdump.net>

 defaults/initrd.scripts |  6 +++---
 defaults/linuxrc        | 19 +++++++++++++++----
 doc/genkernel.8.txt     |  6 +++---
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index 2fb0eb4..f8f9825 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -1181,7 +1181,7 @@ startVolumes() {
                then
                        good_msg "Importing ZFS pools"
 
-                       /sbin/zpool import -N -a ${ZPOOL_FORCE}
+                       /sbin/zpool import -N -a ${ZPOOL_CACHE} ${ZPOOL_FORCE}
 
                        if [ "$?" = '0' ]
                        then
@@ -1199,12 +1199,12 @@ startVolumes() {
                                then
                                        good_msg "LUKS detected. Reimporting 
${ZFS_POOL}"
                                        /sbin/zpool export -f "${ZFS_POOL}"
-                                       /sbin/zpool import -N ${ZPOOL_FORCE} 
"${ZFS_POOL}"
+                                       /sbin/zpool import -N ${ZPOOL_CACHE} 
${ZPOOL_FORCE} "${ZFS_POOL}"
                                fi
                        else
                                good_msg "Importing ZFS pool ${ZFS_POOL}"
 
-                               /sbin/zpool import -N ${ZPOOL_FORCE} 
"${ZFS_POOL}"
+                               /sbin/zpool import -N ${ZPOOL_CACHE} 
${ZPOOL_FORCE} "${ZFS_POOL}"
 
                                if [ "$?" = '0' ]
                                then

diff --git a/defaults/linuxrc b/defaults/linuxrc
index d58ef06..81e7799 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -111,10 +111,21 @@ do
                dozfs*)
                        USE_ZFS=1
 
-                       if [ "${x#*=}" = 'force' ]
-                       then
-                               ZPOOL_FORCE=-f
-                       fi
+                       case "${x#*=}" in
+                               *force*)
+                                       ZPOOL_FORCE=-f
+                               ;;
+                       esac
+
+                       case "${x#*=}" in
+                               *cache*)
+                                       if [ -s "/etc/zfs/zpool.cache" ]; then
+                                               ZPOOL_CACHE="-c 
/etc/zfs/zpool.cache"
+                                       else
+                                               bad_msg "zpool.cache not found 
or empty, zpool import will be slow"
+                                       fi
+                               ;;
+                       esac
                ;;
                dobtrfs*)
                        USE_BTRFS=1

diff --git a/doc/genkernel.8.txt b/doc/genkernel.8.txt
index 908212e..ca84816 100644
--- a/doc/genkernel.8.txt
+++ b/doc/genkernel.8.txt
@@ -522,9 +522,9 @@ recognized by the kernel itself.
 *domdadm*::
     Scan for RAID arrays on bootup
 
-*dozfs*[=force]::
-    Scan for bootable ZFS pools on bootup. Optionally force import if
-    necessary.
+*dozfs*[=cache,force]::
+    Scan for bootable ZFS pools on bootup. Optionally use cachefile or force 
import if
+    necessary or perform both actions.
 
 *dobtrfs*::
     Scan for attached Btrfs devices on bootup.

Reply via email to