MFC r251632: illumos #3743 zfs needs a refcount audit

Audit zap cursor usage and correct missing calls to zap_cursor_fini().

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_errlog.c:
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zap.c:
	Correct early exit handling of several functions that
	previously failed to close a cursor prior to returning.

Submitted by:	gibbs

Audit holders of dmu_bufs and correct missing calls to dmu_buf_rele().

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_dataset.c:
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zap.c:
	Correct early exit handling of several functions that
	previously failed to release a dmu_buf prior to returning.

Submitted by:	will

Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		Eric Schrock <eric.schrock@delphix.com>,
		George Wilson <george.wilson@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic
MFC r251633: illumos #3744 zfs shouldn't ignore errors unmounting
snapshots

Propagate errors from zfs_unmount_snap() up to its callers wherever
feasible.

Submitted by:	will
Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic
MFC r251634: illumos #3745 zpool create should treat -O mountpoint and -m the same

cddl/contrib/opensolaris/cmd/zpool/zpool_main.c:  (change 644608)
	This allows specifying a mountpoint using the latter form and having
	its value checked and used as it would be using the former form.

	As a consequence of this change:

	1. The mountpoint property is set in the fsprops nvlist prior
	   to creating the pool, rather than being set after creating
	   the pool.  To me, this is the proper approach, since it
	   avoids creating the pool if the mountpoint setting would
	   cause the command to fail.
	2. The mountpoint property, unlike all others, can be specified
	   more than once.  Only the last setting takes effect.  This
	   is to avoid breaking potential existing users that specify
	   -m more than once.

Submitted by:	will

cddl/contrib/opensolaris/lib/libzfs/common/libzfs_pool.c
	Fix "zpool create -R <whatever> -m <whatever>".  Ever since
	change 644608, this has been broken.  The problem is that some
	old code in libzfs_pool.c would force a pool's mountpoint to
	"/" when creating a pool with an altroot.  That probably
	implemented some old policy decision regarding altroots, but it
	conflicts with the current manpage.  It also had no effect
	until 644608, because the zpool command would _always_ change
	the pool's mountpoint after creating it.  The solution is to
	delete the old code from libzfs_pool.c.

Submitted by:	asomers

Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic
MFC r251635: illumos #3747 txg commit callbacks don't work

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/txg.c:
	Fix commit callbacks by moving them to the task's list.
	Previously, list_move_tail() returned without doing anything because
	the task list was passed as the source rather than destination.

cddl/contrib/opensolaris/cmd/ztest/ztest.c:
	Check the commit callback threshold correctly.

Submitted by:	will
Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic
MFC r251636: illumos #3749 zfs event processing should work on R/O root
filesystems

This log is a modified version of the original one written by gibbs@,
to account for changes made during the illumos RTI process.

Allow ZFS asynchronous event handling to proceed even if the root file
system is mounted read-only.  This restriction appears to have been put
in place to avoid errors with updating the configuration cache file.
However:

 o The majority of asynchronous event handling does not involve
   configuration cache file updates.
 o The configuration cache file need not be on the root file system,
   so the check was not complete.
 o Other classes of errors (e.g. file system full) can also prevent
   a successful update yet do not prevent asynchronous event processing.
 o Configurations such as NanoBSD never have a read-write root,
   so ZFS event processing is permanently disabled in these systems.
 o Failure to handle asynchronous events promptly can extend the
   window of time that a pool is in a critical state.

At worst, a missed configuration cache update will force the operator to
perform a manual "zfs import" (note -f is not required) to inform the
system about a newly created pool.  To minimize the likelihood of this
rare occurrence, configuration cache write failures now emit FMA events
(via devctl) so the operator can take corrective action, and the write
is retried every 5 minutes.  The retry interval, in seconds, is tunable
via the sysctl "vfs.zfs.ccw_retry_interval".

As a side effect of reporting configuration cache events, other sysevents,
such as re-silver start/stop, are now also reported via devctl.

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c:
	o As is done in zfs_fm.c, provide a manual declaration for
	  devctl_notify().  Both declarations could be combined
	  into spa_impl.h, but the declaration is fault management
	  related, not spa specific.  sys/fm/fs/zfs.h would be ideal
	  if it weren't so public and reserved for FMA string
	  definitions.  I'm open to suggestions on how to improve
	  this nit while minimizing our divergence from Solaris.
	o Use devctl_notify() to implement sysevent support in
	  spa_event_notify().  The subsystem is EC_ZFS so that
	  these events can never collide with those emitted in
	  zfs_fm.c.
	o Add the sysctl "vfs.zfs.ccw_retry_interval".  The value
	  defaults to 5 minutes and is used to rate limit, on a
	  per-pool basis, configuration cache file write attempts.
	o Modify spa_async_dispatch to honor configuration cache
	  write limiting.  If other events are pending, a configuration
	  cache write will be attempted at the same time, so the
	  rate limiting only applies when the asynchronous dispatch
	  system is otherwise idle.  Async events should be rare
	  (e.g. device arrival/departure) and configuration cache
	  writes rarer, so a more complicated system to strictly
	  honor the retry limit seems unwarranted.
	o Remove check in spa_async_dispatch() for the root file
	  system being read-write.

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c:
	Instead of silently ignoring configuration cache write
	failures, report them via a new FMA event as well as
	to the console.  The current zfs_ereport_post() doesn't
	allow arbitrary name=value pairs to be appended to the
	report, so the configuration cache file name is only
	available on the console output.  This limitation should
	be addressed in a future update.

	Note: This error report is only posted once per incident,
	to avoid spamming.

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa_impl.h:
	Add a hrtime_t to the spa data structure to track the
	time (via gethrtime()) of the last configuration cache file
	write failure.  This is referenced in spa_async_dispatch()
	to effect the rate limiting.

sys/cddl/contrib/opensolaris/uts/common/sys/fm/fs/zfs.h:
	  Add FM_EREPORT_ZFS_CONFIG_CACHE_WRITE as an ereport class.

Submitted by:	gibbs
Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		Eric Schrock <eric.schrock@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic
MFC r251646 + r252219:

MFV r251644:

Poor ZFS send / receive performance due to snapshot
hold / release processing (by smh@)

Illumos ZFS issues:
3740 Poor ZFS send / receive performance due to snapshot
     hold / release processing

MFV r252215:

Restore a previous behavior before r251646, where when destructing
ZFS snapshot, the ioctl would return ENOENT when it hit any of
them in the errlist (the new behavior was only return ENOENT when
all returns error).

Illumos ZFS issues:
  3829 fix for 3740 changed behavior of zfs destroy/hold/release ioctl
MFC r252218:

Diff reduction against Illumos, no real change to code itself.

This marks vendor branch revision 252213 as merged, the actual code was
committed in r245479.
MFC r252360:

Don't attempt to do DHCP on certain interfaces, similar to what's done for
ipv6_autoconfif() in r212577.
MFC r252523:

When listing with -f, skip all memory disks that are not vnode-backed.

Noticed by:	kevlo