zfs/etc/systemd/system
Brian Behlendorf 87abfcba22 Wait in libzfs_init() for the /dev/zfs device
While module loading itself is synchronous the creation of the /dev/zfs
device is not.  This is because /dev/zfs is typically created by a udev
rule after the module is registered and presented to user space through
sysfs.  This small window between module loading and device creation
can result in spurious failures of libzfs_init().

This patch closes that race by extending libzfs_init() so it can detect
that the modules are loaded and only if required wait for the /dev/zfs
device to be created.  This allows scripts to reliably use the following
shell construct without the need for additional error handling.

$ /sbin/modprobe zfs && /sbin/zpool import -a

To minimize the potential time waiting in libzfs_init() a strategy
similar to adaptive mutexes is employed.  The function will busy-wait
for up to 10ms based on the expectation that the modules were just
loaded and therefore the /dev/zfs will be created imminently.  If it
takes longer than this it will fall back to polling for up to 10 seconds.

This behavior can be customized to some degree by setting the following
new environment variables.  This functionality is provided for backwards
compatibility with existing scripts which depend on the module auto-load
behavior.  By default module auto-loading is now disabled.

* ZFS_MODULE_LOADING="YES|yes|ON|on" - Attempt to load modules.
* ZFS_MODULE_TIMEOUT="<seconds>"     - Seconds to wait for /dev/zfs

The zfs-import-* systemd service files have been updated to call
'/sbin/modprobe zfs' so they no longer rely on the legacy auto-loading
behavior.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Chris Dunlap <cdunlap@llnl.gov>
Signed-off-by: Richard Yao <ryao@gentoo.org>
Closes #2556
2015-05-22 13:31:58 -07:00
..
.gitignore Add systemd unit files for ZFS startup 2014-02-05 12:25:30 -08:00
50-zfs.preset.in Add systemd unit files for ZFS startup 2014-02-05 12:25:30 -08:00
Makefile.am Add systemd unit file for zed 2014-04-02 13:10:08 -07:00
zed.service.in Change startup mode of ZED 2014-09-02 14:18:53 -07:00
zfs-import-cache.service.in Wait in libzfs_init() for the /dev/zfs device 2015-05-22 13:31:58 -07:00
zfs-import-scan.service.in Wait in libzfs_init() for the /dev/zfs device 2015-05-22 13:31:58 -07:00
zfs-mount.service.in Add systemd unit files for ZFS startup 2014-02-05 12:25:30 -08:00
zfs-share.service.in Improve systemd script to not leave stale sharetab 2014-12-18 09:54:56 -08:00
zfs.target.in Add systemd unit file for zed 2014-04-02 13:10:08 -07:00