zfsonlinux/zfs — pull request #2206 by dun (2014-03-23 17:20:07+00:00)
Title: Initial implementation of zed (ZFS Event Daemon)

zed monitors ZFS events. When a zevent is posted, zed will run any scripts that have been enabled for the corresponding zevent class. Multiple scripts may be invoked for a given zevent. The zevent nvpairs are passed to the scripts as environment variables. Refer to the zed(8) manpage for details.

Events are processed synchronously by the single thread, and there is no maximum timeout for script execution. Consequently, a misbehaving script can delay (or forever block) the processing of subsequent zevents. Plans are to address this in future commits.

An EID (Event IDentifier) has been added to each event to uniquely identify it throughout the lifetime of the loaded ZFS kernel module; it is a monotonically increasing integer that resets to 1 each time the module is loaded.

Initial scripts have been developed to log zevents to syslog, automatically rebuild to a hot spare device, and send email in response to checksum / data / io / resilver.finish / scrub.finish zevents. To enable email notifications, configure ZED_EMAIL in zed.rc (which is serving as a config file of sorts until a proper configuration file is implemented). To enable hot sparing, uncomment ZED_SPARE_ON_IO_ERRORS and ZED_SPARE_ON_CHECKSUM_ERRORS in zed.rc; note that the autoexpand property is not yet supported.

Since pull #2085:
- added systemd unit file
- replaced zpool_events_next() "block" parm w/ "flags"
- fixed issues with scripts running under dash
- added data-email.sh
- added io-email.sh (combined with checksum-email.sh)
- combined resilver.finish-email.sh with scrub.finish-email.sh
- added generic-email.sh for sending email in response to a particular zevent class
- changed script execution cwd to the root dir; enabled-scripts dir location now available as ZED_SCRIPT_DIR

I have not yet gotten to the following:
- sysvinit scripts (FransUrbo/zfs@f2d0321)
- io-spare.sh updates (FransUrbo/zfs@949a9b7 & FransUrbo/zfs@11b84cc)

zed is a work-in-progress.

Assimilates pull #2085 and lays the groundwork for moving forward on issue #2.