Page MenuHomeFreeBSD

rc.d/zfs: Add shutdown to KEYWORDS
ClosedPublic

Authored by 0mp on Nov 1 2020, 11:23 AM.
Tags
Referenced Files
Unknown Object (File)
Jan 8 2024, 12:56 AM
Unknown Object (File)
Dec 20 2023, 5:15 AM
Unknown Object (File)
Dec 16 2023, 4:04 PM
Unknown Object (File)
Sep 21 2023, 4:00 AM
Unknown Object (File)
Sep 8 2023, 11:47 AM
Unknown Object (File)
Sep 4 2023, 1:06 PM
Unknown Object (File)
Jul 10 2023, 12:14 PM
Unknown Object (File)
Jul 8 2023, 2:44 AM
Subscribers

Details

Summary
rc.d/zfs: Add shutdown to KEYWORDS

The problem is that Without walling /etc/rc.d/zfs on shutdown, resources
associated with ZFS mounts are not freed and the jails will remain in dying
state. In addition, the dataset is now in a dangling state, as the jail it is
attached to is dying.

A known workaround for jails was to add the following lines to /etc/jail.conf,
to make sure theat "service zfs stop" is run when the jail is stopped:

    exec.stop = "/bin/sh /etc/rc.shutdown";
    exec.stop += "/usr/sbin/service zfs stop || /usr/bin/true";

While the workaround seems to be okay-ish for the jail situation, it is still
unclean. However, for physical hosts this may wreak havoc with the pool if
shared spares are used, as "zfs unshare" is never invoked on shutdown.

PR: 147444
Reported by: Mykah <mburkhardt__exavault_com>
Submitted by: Markus Stoff <markus__stoffdv_at>
MFC: 1 week

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=147444

Test Plan
How to reproduce:

# jail.conf
test {
        path = "/jails/test";
        exec.clean;
        exec.start = "/bin/sh /etc/rc";
        exec.stop = "/bin/sh /etc/rc.shutdown";

        # Make sure to unmount all ZFS datasets before stopping the jail
        # Required unless the jails /etc/rc.d/zfs contains '# KEYWORD: shutdown'
        exec.stop += "/usr/sbin/service zfs stop || true";

        # Mandatory to use ZFS in jail
        allow.mount;
        allow.mount.zfs;
        enforce_statfs = 1;     # must be less than 2

        # Attach ZFS dataset to jail
        exec.created = "/sbin/zfs jail test tank/jaildata";

        # Make sure the /dev/zfs device is included (it is with the default
        # devfs_ruleset = 4)
        mount.devfs;
}

# Create dataset
zfs create -o jailed=on -o mountpoint=/data tank/jaildata
mkdir -p /jails/test/data
sysrc -f /jails/test/etc/rc.conf zfs_enable=YES

# Start the jail
jail -c test

# List ZFS mounts
zfs mount | grep jaildata
tank/jaildata                   /jails/test/data

# Stop the jail
jail -r test

# List ZFS mounts (mount is still there)
zfs mount | grep jaildata
tank/jaildata                   /jails/test/data

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable