freebsd-dev/lib
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
..
libavl Remove autotools products 2012-08-27 11:47:44 -07:00
libefi Use (void) memcpy(), not (void *) memcpy() 2015-01-30 09:43:04 -08:00
libnvpair Illumos #2619 and #2747 2013-01-08 10:35:35 -08:00
libshare Remove unconditional sharetab update 2014-01-07 09:48:09 -08:00
libspl Fix type mismatch on 32-bit systems 2015-05-11 12:15:41 -07:00
libunicode Remove autotools products 2012-08-27 11:47:44 -07:00
libuutil Remove autotools products 2012-08-27 11:47:44 -07:00
libzfs Wait in libzfs_init() for the /dev/zfs device 2015-05-22 13:31:58 -07:00
libzfs_core Illumos 5765 - add support for estimating send stream size with lzc_send_space when source is a bookmark 2015-05-13 09:03:59 -07:00
libzpool Illumos #5244 - zio pipeline callers should explicitly invoke next stage 2015-04-30 15:07:47 -07:00
Makefile.am Illumos #2882, #2883, #2900 2013-09-04 15:49:00 -07:00