Create a project branch for intergration of the ZFS fault monitoring and
management daemon.
Integrate from Head into ZFSD feature branch as of revision r224141.
Integrate from head into the ZFSD feature branch as of revision 224147.
Integrate from head into ZFSD feature branch as of revision 224171.
sys/cam/scsi/scsi_all.h:
	o Apply const qualifiers to in scsi_(2,3,4,8)btoul().
	o While touching these APIs, also convert them to use
	  stdint.h types.
Revamp the CAM enclosure services driver, renaming it to "enc" from "ses" in
the process.  This updated driver uses an in-kernel daemon to track state
changes and publishes physical path location information for disk elements
into the CAM device database.

share/examples/ses/Makefile.inc:
share/examples/ses/srcs/eltsub.c:
share/examples/ses/srcs/sesd.c:
share/examples/ses/srcs/getencstat.c:
share/examples/ses/srcs/setobjstat.c:
share/examples/ses/srcs/inienc.c:
share/examples/ses/srcs/getobjstat.c:
share/examples/ses/srcs/getnobj.c:
share/examples/ses/srcs/getobjmap.c:
share/examples/ses/srcs/setencstat.c:
	Update for changes in driver name and API.  The ioctl interface
	is largely unchanged and could use additional refinement.  It
	would be nice to be able to fetch the status of all elements in
	a single ioctl call and to have the ioctls that return variable
	length data allow you to query the necessary allocation size
	by passing in a zero length buffer.

sys/sparc64/conf/GENERIC:
sys/ia64/conf/GENERIC:
sys/mips/conf/OCTEON1:
sys/pc98/conf/GENERIC:
sys/i386/conf/GENERIC:
sys/amd64/conf/GENERIC:
	ses -> enc

sys/conf/files:
sys/modules/cam/Makefile:
sys/cam/scsi/scsi_enc_internal.h
sys/cam/scsi/scsi_enc_ses.c
sys/cam/scsi/scsi_enc_safte.c
sys/cam/scsi/scsi_ses.c
sys/cam/scsi/scsi_enc.c
	Split the enc driver into a generic driver file and one file
	each for the SES and SAF-TE personalities.

sys/cam/scsi/scsi_ses.h:
	o Retain this header, but use it to only hold structures derived
	  from the T10 SES spec.  The driver interface can be found in
	  scsi_enc.h.
	o Add definitions for most SES pages.

sys/cam/scsi/scsi_enc.c
sys/cam/scsi/scsi_enc.h
	o Use a function vector table to allow interaction between the
	  generic and protocol specific portions of this driver.
	o Provide a generic mechanism allowing personalities to define a
	  finite state machine that is executed from a daemon thread context.
	o Track CAM device arrival events and pass these on to personalities
	  that have registered an interest in them.  These notifications are
	  used to trigger physical path updates in the CAM EDT.

sys/cam/scsi/scsi_enc_safte.c:
	The SAF-TE personality.  This module is largely untouched by this
	update.  To achieve the same level of support as we have for SES,
	it will need to define an FSM and code to determine the physical
	paths of elements within the enclosure.

sys/cam/scsi/scsi_enc_ses.c:
	o Implement a state machine to fetch configuration, status, element
	  descriptors, and additional element status.
	o Build a "element map" that indexes into the config and status
	  data retrieved from a SES device.  Use this to simplify our
	  responses to ioctls.
	o Add support for using SAS domain/phy WWN data to determine the
	  physical path (ence@<enc WWN>/type@<elm type>/slot@<slot #>)
	  of an element.  Stubs are in place for FC, but both FC and SPI
	  will need additional work in order to be supported.

Sponsored by:	Spectra Logic Corporation
Submitted by:	gibbs, will
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c:
sys/cddl/contrib/opensolaris/uts/common/sys/sysevent/dev.h:
	Emit "dev_path" instead of "phys_path" in autoexpand
	events.  The "dev_path" already is a devfs path to
	the device and this avoids having to convert the
	physical path information into a devfs path in yet
	another location.

Sponsored by:	Spectra Logic Corporation
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 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".

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.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.

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa_impl.h:
    Add a uint64_t to the spa data structure to track the
    time (via LBOLT) 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.

Sponsored by:	 Spectra Logic Corporation
Fix building kdump.  The new scsi_ses.h requires <stdint.h> and <stddef.h>.

Sponsored by:	Spectra Logic Corporation
Integrate FreeBSD/head into projects/zfsd/head as of SVN revision 224870.
Correct the rendering of device aliases that reside in subdirectories
of a devfs.

devfs/devfs_vnops.c:
	In devfs_readlink(), convert the devfs root relative path
	of an alias's parent, that is recorded in the alias, into a
	fully qualified path that includes the root of the containing
	devfs.  This avoids the ugliness of generating a relative path
	by prepending "../"'s.  For a non-jailed process, the "symlink
	root" is the devfs's mount point.  For a jailed process, we
	must remove any jail prefix in the mount point so that our
	response matches the user process's world view.

Sponsored by:	Spectra Logic Corporation
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c:
	When attaching to a vdev by GUIDs, verify both the pool and
	vdev GUIDS instead of just the vdev GUID.

Sponsored by:	 Spectra Logic Corporation
Modify the geom vdev provider's open behavior so that it will
only unconditionally open a device by path if the open is part
of a pool create, pool split, or device add operation, and a
search of all known geom provider's label data doesn't yield a
device with matching pool and vdev GUIDs.

This fixes a bug where the wrong disk could be associated with
a vdev's configuration data when device devfs paths change due to
insert and remove events.  While, ZFS detects this kind of coding
mixup and immediately flags the device as faulted before the
confusion can cause permanent data loss, a reboot was necessary
in order to resurrect the configuration.

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c:
	Modify the open behavior to:
	    - Open by recorded device path with GUID matching
	    - If that fails, search all geom providers for a
	      device with matching GUIDs.
	    - If that fails and we are opening a "new to a
	      pool configuration" vdev, open by path.
	    - Otherwise fail the open.

Sponsored by:	Spectra Logic Corporation
Close several race conditions in the ZFS vdev geom module, most triggered
by concurrent ZFS reprobe and GEOM orphan processing.

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c:
	o Make vdev_geom_close() synchronous instead of deferring
	  its work to a GEOM event handler.  This prevents a future
	  open call from referencing a consumer that is scheduled for
	  destruction.
	o Move initialization of the consumer private pointer (which
	  references the ZFS vdev object using this consumer) into
	  vdev_geom_attach().  This guarantees that an orphan event
	  received during the small windows where the topology lock
	  is dropped in open processing, is effective in marking a
	  vdev as needing to be removed.
	o Move clearing of the consumer private pointer from
	  vdev_geom_close() into vdev_geom_detach().  When
	  vdev_geom_open() fails, vdev_geom_detach is called directly,
	  which used to bypass this necessary step.
	o Modify vdev_geom_orphan handler to ignore a consumer that
	  that is no longer associated with a vdev.

Sponsored by:	Spectra Logic Corporation
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c:
	Subscribe to attribute change notifications and update
	vdev physical path information (in core and on disk) when
	a GEOM::physpath event indicates they have changed.

Sponsored by:	Spectra Logic Corporation
Add ZFSD, a ZFS fault management daemon.  This daemon has the following
features:

 o When a vdev for an active pool is inserted into the system, it will
   re-integrate it with the pool.
 o When an unlabeled or inactive disk is inserted into the same physical
   location as a missing member of a pool with the "autoreplace" attribute
   set, the inserted disk will be used to replace the missing disk.
 o When the cumulative soft-error count for a vdev exceeds 50 errors, the
   vdev will be marked degraded, alerting users to a potential problem.
   The error counts are persisted across reboots.

The daemon is written to be easily extended for more advanced fault
management policies and to handle new features such as spare pool
management.

cddl/sbin/zfsd/zpool_list.cc:
cddl/sbin/zfsd/zpool_list.h:
	ZpoolList is a standard container allowing filtering and
	iteration of imported ZFS pool information.

cddl/sbin/zfsd/callout.cc:
cddl/sbin/zfsd/callout.h:
	Timer services built on top of the POSIX interval timer API.

cddl/sbin/zfsd/vdev.cc:
cddl/sbin/zfsd/vdev.h:
	Wrapper class used to provide easy access to Vdev nvlist data.

cddl/sbin/zfsd/zfsd.cc:
cddl/sbin/zfsd/zfsd.h:
	Daemon main, devctl socket handling, and global application state
	exported through the ZfsDaemon singleton.

cddl/sbin/zfsd/case_file.cc:
cddl/sbin/zfsd/case_file.h:
	CaseFile objects aggregate vdev faults that may require ZFSD action
	in order to maintain the health of a ZFS pool.  They also handle
	serialization/deserialization of fault data to persistent
	storage.

cddl/sbin/zfsd/vdev_iterator.cc:
cddl/sbin/zfsd/vdev_iterator.h:
	Helper class for traversing and finding vdev objects within a
	pool configuration.

cddl/sbin/zfsd/dev_ctl_event.cc:
cddl/sbin/zfsd/dev_ctl_event.h:
	Class hierarchy used to express events received via the devctl API.

cddl/sbin/zfsd/zfsd_exception.cc:
cddl/sbin/zfsd/zfsd_exception.h:
	Definition of exceptions explicitly thrown by ZFSD.

cddl/sbin/zfsd/Makefile:
cddl/sbin/Makefile:
	Add zfsd to the build.

etc/rc.d/zfsd:
	Rc script for ZFSD.

etc/defaults/rc.conf:
	ZFSD defaults, just like ZFS, to being disabled.

etc/mtree/BSD.root.dist:
	Create the etc/zfs/cases directory used to store persistent
	fault data.

Sponsored by:	Spectra Logic Corporation
Add support for SATA Enclosure Management Bridge (SEMB).
Fetch list of supported diagnostic pages for SES to find whether optional
Additional Element Status page is supported. If it's not, do not try to
query it.
Do not delay boot if we are not going to run daemon process. Otherwise
boot will wait infinitely.
Last SAF-TE spec draft defines the field to identify real number of
thermostats. Use it to report real state of things. Unluckily, when it is
zero, it is impossible to say whether there are no sensors or this field is
not implemented. In this case report "status not available" when no error
reported to not inflate expectations.

Map temperature sensors status to the respective out of range flags.