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

--- Comment #4 from Markus Stoff <ms-freebsd-bugzi...@stoffnet.at> ---
It's amazing that after more than 10 years a single line could not be added.

Please find attached the diff to facilitate that change. If there is a reason
why /etc/rc.d/zfs should not be called by rc.shutdown, please let us know.


Patch:

rc.shutdown calls rcorder(8) with the '-k shutdown' option. rcorder(8) will
therefore only return files declaring the 'shutdown' keyword:
# KEYWORD: shutdown

As of 12.1, /etc/rc.d/zfs does not declare any keywords. This patch adds the
'shutdown' keyword.


Use case: Providing ZFS datasets to a jail


Problem:

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


Workaround:

In /etc/jail.conf, make sure to run 'service zfs stop' when the jail is
stopped:

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


Desaster recovery:

With the jail in dying state, issue:

# After the following statements, the dataset will be unmounted and the jail
# will finally be gone
zfs set jailed=off tank/jaildata
zfs unmount tank/jaildata

# Don't forget to set jailed=on before starting the jail again
zfs set jailed=on tank/jaildata


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";

        # 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


Additional Remarks:

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.

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
freebsd-bugs@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"

Reply via email to