]> granicus.if.org Git - zfs/commitdiff
Properly use the Dracut cleanup hook to order pool shutdown
authorRudd-O <rudd-o@rudd-o.com>
Mon, 17 Oct 2016 18:51:15 +0000 (18:51 +0000)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 17 Oct 2016 18:51:15 +0000 (11:51 -0700)
When Dracut starts up, it needs to determine whether a pool will remain
"hanging open" before the system shuts off. In such a case, then the
code to clean up the pool (using the previous export -F work) must
be invoked. Since Dracut has had a recent change that makes
mount-zfs.sh simply not run when the root dataset is already mounted,
we must use the cleanup hook to order Dracut to do shutdown cleanup.

Important note: this code will not accomplish its stated goal until this
bug is fixed: https://bugzilla.redhat.com/show_bug.cgi?id=1385432

That bug impacts more than just ZFS. It impacts LUKS, dmraid, and
unmount during poweroff. It is a Fedora-wide bug.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Manuel Amador (Rudd-O) <rudd-o@rudd-o.com>
Closes #5287

contrib/dracut/90zfs/Makefile.am
contrib/dracut/90zfs/module-setup.sh.in
contrib/dracut/90zfs/mount-zfs.sh.in
contrib/dracut/90zfs/zfs-needshutdown.sh.in [new file with mode: 0644]

index 2777a814276891931268a5796dba1d9ccb3426dc..243a5200fa1e9ffa3b50519bb785336e8e5bc507 100644 (file)
@@ -5,6 +5,7 @@ pkgdracut_SCRIPTS = \
        mount-zfs.sh \
        parse-zfs.sh \
        zfs-generator.sh \
+       zfs-needshutdown.sh \
        zfs-lib.sh
 
 EXTRA_DIST = \
@@ -13,6 +14,7 @@ EXTRA_DIST = \
        $(top_srcdir)/contrib/dracut/90zfs/mount-zfs.sh.in \
        $(top_srcdir)/contrib/dracut/90zfs/parse-zfs.sh.in \
        $(top_srcdir)/contrib/dracut/90zfs/zfs-generator.sh.in \
+       $(top_srcdir)/contrib/dracut/90zfs/zfs-needshutdown.sh.in \
        $(top_srcdir)/contrib/dracut/90zfs/zfs-lib.sh.in
 
 $(pkgdracut_SCRIPTS):%:%.in
index 240847a77c7280298fb581364225ec3515366fcc..a653b50f4bc6d47b6b537ed04fe60e967be85cc1 100755 (executable)
@@ -58,6 +58,7 @@ install() {
                inst_script "${moddir}/zfs-generator.sh" "$systemdutildir"/system-generators/dracut-zfs-generator
        fi
        inst_hook mount 98 "${moddir}/mount-zfs.sh"
+       inst_hook cleanup 99 "${moddir}/zfs-needshutdown.sh"
        inst_hook shutdown 20 "${moddir}/export-zfs.sh"
 
        inst_simple "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
index db5ccddf2d9093cf503649808f2495a0ffc4be4e..e7f217736e24b6ac391d44c7ffacc54579ef5f35 100755 (executable)
@@ -22,7 +22,6 @@ if [ -e "$GENERATOR_FILE" -a -e "$GENERATOR_EXTENSION" ] ; then
        # Let us tell the initrd to run on shutdown.
        # We have a shutdown hook to run
        # because we imported the pool.
-       need_shutdown
        # We now prevent Dracut from running this thing again.
        for zfsmounthook in "$hookdir"/mount/*zfs* ; do
                if [ -f "$zfsmounthook" ] ; then
@@ -60,7 +59,6 @@ if import_pool "${ZFS_POOL}" ; then
        # Let us tell the initrd to run on shutdown.
        # We have a shutdown hook to run
        # because we imported the pool.
-       need_shutdown
        info "ZFS: Mounting dataset ${ZFS_DATASET}..."
        if mount_dataset "${ZFS_DATASET}" ; then
                ROOTFS_MOUNTED=yes
diff --git a/contrib/dracut/90zfs/zfs-needshutdown.sh.in b/contrib/dracut/90zfs/zfs-needshutdown.sh.in
new file mode 100644 (file)
index 0000000..e3d1b59
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
+
+if zpool list 2>&1 | grep -q 'no pools available' ; then
+    info "ZFS: No active pools, no need to export anything."
+else
+    info "ZFS: There is an active pool, will export it."
+    need_shutdown
+fi