Move parsing policy for invalid GUIDs into the Guid class.

        cddl/sbin/zfsd/guid.cc:
        cddl/sbin/zfsd/guid.h:
                o Allow a Guid to be constructed from a string.  The empty
                  string is treated as an invalid Guid.
                o Rename NONE_FLAG to INVALID_GUID to clarify its meaning.
                  The concept of a Guid being "none" only applies in certain
                  contexts like reading a spare label.

        cddl/sbin/zfsd/dev_ctl_event.cc:
                Modify ZfsEvent's constructor  to just use Guid's string
                contructor instead of embedding logic to manually create
                invalid guids when these nvpairs do not exist.

        stable/cddl/sbin/zfsd/vdev.cc:
                Rely on Guid's default constructor creating an invalid
                guid to simplify the handling of pool GUIDs parsed from
                a label.  This also fixes a vdev/pool guid variable mixup
                bug that, due to Guid's default construction, had no ill
                effects.

Submitted by:	gibbs
Approved by:	ken (mentor)
Sponsored By:	Spectra Logic Corporation
Modify ParseException so that it records the parse buffer upon construction.
This allows it to be caught at any level in the program and logged with full
fidelity.

	cddl/sbin/zfsd/dev_ctl_event.cc:
	cddl/sbin/zfsd/dev_ctl_event.h:
		Update ParseException implementation: take the parse buffer
		string on construction and don't require the parse buffer
		string when logging or converting the exception to a string.

	cddl/sbin/zfsd/dev_ctl_event.cc:
	cddl/sbin/zfsd/case_file.cc:
		Adjust to Log() and ToString() taking no arguments.

Submitted by:	gibbs
Approved by:	ken (mentor)
Sponsored By:	Spectra Logic
In the static method CaseFile::DeSerializeFile(), break out the acutal parsing
of the serialization stream into the instance method
CaseFile::DeSerialize(ifstream &caseStream).

	cddl/sbin/zfsd/case_file.h:
		Declaration of CaseFile::DeSerialize().

	cddl/sbin/zfsd/case_file.cc:
		o Factor out CaseFile::DeSerialize() from
		  CaseFile::DeSerializeFile().

		o In CaseFile::DeSerialize() remove a superfluous
		  return statement after a throw.

Submitted by:	gibbs
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
Remove information about devd reconnection policies that was distributed within
comments and syslog() strings in functions well below where these decisions are
made.

	stable/cddl/sbin/zfsd/zfsd.cc:
		o In ZfsDaemon::DisconnectFromDevd(), log when the
		  connection is torn down.  This removes the need to
		  guess that this will happen in comments or log strings
		  in code that all eventually sends us to this function.
		o In ZfsDaemon::EventsPending(), treat poll returning
		  -1 with an errno other than EINTR, or 0 as a program
		  terminating event just as it is in the other case
		  where we invoke poll.  These events indicate poll or
		  our code is seriously broken.
		o In ZfsDaemon::EventsPending(), prioritize emitting
		  a POLLERR event over POLLHUP in case they are both
		  set.  POLLHUP is benign, but POLLERR may indicate
		  something we need to investigate.
		o In ZfsDaemon::EventLoop(), remove comments and log
		  strings that claim knowledge of policy implemented
		  in EventLoop's caller, ZfsDaemon::Run().

Submitted by:	gibbs
Approved by:	ken (mentor)
Obtained from:	Spectra Logic Corporation
cddl/sbin/zfsd/zfsd.cc
	In ZfsdDaemon::EventsPending(), we do not block waiting for events,
	so poll will return 0 if no events are pending.  Don't treat this as
	a fatal error.

Submitted by:	gibbs
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
Fix compiler warnings in zfsd

	cddl/sbin/zfsd/case_file.cc:
		Use proper printf/scanf format specifiers so Zfsd operates
		on uint64_t variables instead of uintmax_t variables that
		are then assumed to be 64 bits in size.

	cddl/sbin/zfsd/case_file.cc:
	cddl/sbin/zfsd/vdev.cc:
		When fetching datastructures from nvlists that are an array
		of uint64_ts, use a uint64_t pointer to call into the nvlist
		API and a reinterpret_cast<> to convert it to the pointer
		type of interest.  Fixes strict-aliasing warnings.

Submitted by:	gibbs
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
Style, comment, and warning message improvements to zfsd.

	* zfsd.h
	  Clarified member documentation

	* zfsd.cc
	  Clarified warning message

	* case_file.cc
	  Omits a space before the { of a control block

	* vdev_iterator.cc
	* zfsd.cc
	  Return statements must enclose their values in parenthesis

	* dev_ctl_event.cc:
	  Omit a space after flow control keywords

	* case_file.cc:
	* vdev_iterator.cc
	* zfsd.cc
	* case_file.h
	* dev_ctl_event.h
	* guid.h
	* zfsd_exception.h
	* zpool_list.h
	* dev_ctl_event.cc
	  Trailing whitespace

	* zfsd.cc
	* zpool_list.cc
	  Braces around a single line statement following a control block

Submitted by:	alans
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
zfsd will attempt to activate a hotspare in response to a drive becoming
DEGRADED or FAULTED.

	case_file.cc
		Attempt to activate a spare whenver we get a
		"resource.fs.zfs.statechange" event and the vdev state is
		either DEGRADED or FAULTED.

Submitted by:	alans
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
Fixed ZfsEvent::ProcessPoolEvent(): it was never getting called, and didn't
have the right string for removal events.

	dev_ctl_event.cc
	  Fixed event strings

	dev_ctl_event.h
	  Made a function virtual to facilitate unit testing

	zfsd.cc
	  Fixed a printf format warning in ExtractEvent.

Submitted by:	alans
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
When a vdev generates IO errors, mark it as FAULTED instead of DEGRADED.
Checksum errors will still be marked as DEGRADED.  This matches the behavior
of Illumos.  I had to make a number of methods virtual to facilitate unit
testing.

Submitted by:	alans
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
Make zfsd WARNS=1 safe.

	cddl/sbin/zfsd/zfsd.h
		Make Reader's destructor virtual, because it has virtual
		functions

	cddl/sbin/zfsd/Makefile
		Add WARNS=1 and -Wall

Submitted by:	will
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
Fix a bug in zfsd: when a drive is experiencing a rapid storm of IO or
checksum errors, zfsd will not degrade/fault it until hundreds or thousands
of errors have occured.

	cddl/sbin/zfsd/case_file.cc
		RefreshVdevState() iterates through all the system's zpools,
		which involves the ioctls ZFS_IOC_POOL_CONFIGS and
		ZFS_IOC_POOL_STATS.  Both of those acquire
		spa_namespace_lock, which may block for a long time under
		certain circumstances, including when the system has a storm
		of IO or checksum errors.  This change eliminates the call
		to RefreshVdevState() whenever a ZFSEvent is received.
		Instead, RefreshVdevState() will only be called when a
		CaseFile is closed, if necessary.  This way, zfsd won't
		spend too much time blocking on ioctl()s and miss reading
		events from devd.

Submitted by:	alans
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
cddl/sbin/zfsd/case_file.cc
	Comment change.  No functional change.

Submitted by:	alans
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
zfsd should activate a spare that is newly added to an already-degraded pool

	cddl/sbin/zfsd/case_file.cc
	cddl/sbin/zfsd/case_file.h
	cddl/sbin/zfsd/dev_ctl_event.cc
		When a config_sync event arrives, reevaluate all open
		casefiles on the same pool.

	cddl/sbin/zfsd/case_file.cc
		When evaluating a config_sync event, try to activate spares
		if our pool is unhealthy.  This is necessary because we
		don't get any more specific event when a spare is added to a
		pool.  This required adding the CaseFileReEvaluator functor
		and the CaseFile::ReEvaluateByGuid method.

	cddl/sbin/zfsd/case_file.cc
		When processing a statechange event, refresh the vdev state.
		This is necessary because we could be reevaluating an
		already-existing casefile that was opened before the pool
		became degraded.  Also, always consume the event, even if we
		couldn't activate the spare.  It's no longer necessary to
		queue the statechange event since we can now reevaluate
		CaseFiles on a config_sync event.

	cddl/sbin/zfsd/case_file.cc
		In CloseIfSolved(), don't close casefiles for DEGRADED or
		FAULTED vdevs since we now have the ability to fix them.

	cddl/sbin/zfsd/dev_ctl_event.cc
	cddl/sbin/zfsd/dev_ctl_event.h
	cddl/sbin/zfsd/zfsd.cc
		Redelegated responsibility for queueing events from
		DevCtlEvent(and its child classes) to ZfsDaemon.

	cddl/sbin/zfsd/zfsd.cc
		In the SIGINFO handler, print unconsumed events as well as
		saved casefiles.

Submitted by:	alans
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
cddl/sbin/zfsd/case_file.cc
	Log message correction: replacements are not necessarily by physical
	path.

Submitted by:	alans
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
Extract devctl event processing support out of zfsd and into a new library:
libdevctl.

	etc/mtree/BSD.include.dist:
		Add the /usr/include/devctl directory to the base system.

	lib/Makefile:
	lib/libdevctl/Makefile:
		Build support for the new library.

	lib/libdevctl/consumer.cc:
	lib/libdevctl/consumer.h:
	cddl/sbin/zfsd/zfsd.cc:
	cddl/sbin/zfsd/zfsd.h:
		New class, DevCtl::Consumer, from functionality extracted
		from ZfsDaemon, which can connect to devd, parse an event
		stream, and invoke event handlers.

	lib/libdevctl/event.cc:
	lib/libdevctl/event.h:
	cddl/sbin/zfsd/dev_ctl_event.cc:
	cddl/sbin/zfsd/dev_ctl_event.h:
		Strip Zfsd specific event handling from Zfsd's event classes
		to create DevCtl::Event, DevCtl::DevfsEvent, and
		DevCtl::ZfsEvent.

	lib/libdevctl/event_buffer.cc:
	lib/libdevctl/event_buffer.h:
	cddl/sbin/zfsd/zfsd.cc:
	cddl/sbin/zfsd/zfsd.h:
		DevCtl::EventBuffer: buffer for incoming devctl stream used
		to parse/extract individual event strings.

	lib/libdevctl/event_factory.cc:
	lib/libdevctl/event_factory.h:
	cddl/sbin/zfsd/zfsd.cc:
	cddl/sbin/zfsd/zfsd.h:
		DevCtl::EventFactory: Method map for converting event
		strings to Devctl::Event objects.

	lib/libdevctl/exception.cc:
	lib/libdevctl/exception.h:
	cddl/sbin/zfsd/zfsd_exception.cc:
	cddl/sbin/zfsd/zfsd_exception.h:
		DevCtl::Exception and DevCtl::ParseException, the exceptions
		which are thrown by this library.

	lib/libdevctl/guid.cc:
	lib/libdevctl/guid.h:
	cddl/sbin/zfsd/guid.cc:
	cddl/sbin/zfsd/guid.h:
		DevCtl::Guid: Helper routines for dealing with 64bit GUIDs
		such as found in Zfs pools and vdevs.

	lib/libdevctl/reader.cc:
	lib/libdevctl/reader.h:
	cddl/sbin/zfsd/zfsd.cc:
	cddl/sbin/zfsd/zfsd.h:
		DevCtl::Reader class hierarchy.  Used to direct a Consumer
		to an event stream (e.g. from devd or a local/saved file).

	cddl/sbin/zfsd/zfsd_event.cc:
	cddl/sbin/zfsd/zfsd_event.h:
		Zfsd specialization of DevCtl::Event types.

	cddl/sbin/zfsd/zfsd_exception.cc:
	cddl/sbin/zfsd/zfsd_exception.h:
		Zfsd specific exception types, now derived from
		DevCtl::Excpetion.

	cddl/sbin/zfsd/Makefile:
	cddl/sbin/zfsd/callout.cc:
	cddl/sbin/zfsd/callout.h:
	cddl/sbin/zfsd/case_file.cc:
	cddl/sbin/zfsd/case_file.h:
	cddl/sbin/zfsd/vdev.cc:
	cddl/sbin/zfsd/vdev.h:
	cddl/sbin/zfsd/vdev_iterator.cc:
	cddl/sbin/zfsd/vdev_iterator.h:
	cddl/sbin/zfsd/zfsd.cc:
	cddl/sbin/zfsd/zfsd.h:
	cddl/sbin/zfsd/zfsd_event.cc:
	cddl/sbin/zfsd/zfsd_event.h:
	cddl/sbin/zfsd/zfsd_exception.cc:
	cddl/sbin/zfsd/zfsd_exception.h:
	cddl/sbin/zfsd/zfsd_main.cc:
	cddl/sbin/zfsd/zpool_list.cc:
	cddl/sbin/zfsd/zpool_list.h:
		Miscelaneuous refactoring to support using libdevctl instead
		of local implementation.

	cddl/sbin/zfsd/Makefile:
	cddl/sbin/zfsd/Makefile.common:
	tools/regression/zfsd/Makefile:
		Export common build information for zfsd and its unit tests
		to a "Makefile.common".

Submitted by:	gibbs
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
Fix a bug in zfsd: If you pull two drives on a raidz2 pool with at least two
available hotspares, only one will be activated.

	cddl/sbin/zfsd/case_file.cc
		CaseFile::Replace should return false when zpool_vdev_attach
		fails.  That way, the operation will be reattempted the next
		time that a config_sync event arrives.

Submitted by:	alans
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
Fix a few libdevctl bugs found by inspection

	lib/libdevctl/consumer.cc:
		In Consummer::ConnectToDevd(), invoke DisconnectFromDevd()
		if our connect fails so that the connection to DevD is
		recorded as closed.  This avoids fooling future invocations
		of ConnectToDevd() into thinking the connection is already
		established.

		In Consumer::FlushEvents(), handle in_avail() returning -1,
		which indicates and error.

		In Consumer::EventsPending(), update exception string to
		reflect the conversion of this class from ZfsDaemon to
		Consumer when it was refactored out of zfsd.

Submitted by:	gibbs
Approved by:	ken (mentor)
Obtained from:	Spectra Logic Corporation
Modify Zfsd to honor shutdown signals even when started during a devctl
event flood.

	cddl/sbin/zfsd/zfsd.cc:
		In ZfsDaemon::Run(), catch DevCtl::Exceptions instead of one
		of its derived classes ZfsdExceptions.  libdevctl, which
		contains some of the methods we call in this context, only
		emits DevCtl::Exceptions, and we must catch these too.

		In ZfsDaemon::DetectMissedEvents(), monitor
		s_terminateEventLoop so we are guaranteed to exit our loop
		if a shutdown is requested.

Submitted by:	gibbs
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation
Fix registration of a default event builder for the Consumer class.

	lib/libdevctl/consumer.cc:
		In Consumer::ConnectToDevd(), improve syslog output.

	lib/libdevctl/event.cc:
	lib/libdevctl/event.h:
		Implement pure virtual method in the Event class so that it
		can be instantiated.

		Provide a generic EventBuilder method that builds generic
		Events.  This is expected to be used by consumers of this
		library that just need key=>value data for all events
		received.

	lib/libdevctl/event_factory.cc:
		In EventFactory::Build, fix segmentation violation
                when a default event builder is registered and no
                more specific event builder is found in the factory's
                registry.

Submitted by:	gibbs
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corporation