1.\" 2.\" This file is part of the ZFS Event Daemon (ZED). 3.\" Developed at Lawrence Livermore National Laboratory (LLNL-CODE-403049). 4.\" Copyright (C) 2013-2014 Lawrence Livermore National Security, LLC. 5.\" Refer to the OpenZFS git commit log for authoritative copyright attribution. 6.\" 7.\" The contents of this file are subject to the terms of the 8.\" Common Development and Distribution License Version 1.0 (CDDL-1.0). 9.\" You can obtain a copy of the license from the top-level file 10.\" "OPENSOLARIS.LICENSE" or at <http://opensource.org/licenses/CDDL-1.0>. 11.\" You may not use this file except in compliance with the license. 12.\" 13.\" Developed at Lawrence Livermore National Laboratory (LLNL-CODE-403049) 14.\" 15.Dd May 26, 2021 16.Dt ZED 8 17.Os 18. 19.Sh NAME 20.Nm ZED 21.Nd ZFS Event Daemon 22.Sh SYNOPSIS 23.Nm 24.Op Fl fFhILMvVZ 25.Op Fl d Ar zedletdir 26.Op Fl p Ar pidfile 27.Op Fl P Ar path 28.Op Fl s Ar statefile 29.Op Fl j Ar jobs 30.Op Fl b Ar buflen 31. 32.Sh DESCRIPTION 33The 34.Nm 35(ZFS Event Daemon) monitors events generated by the ZFS kernel 36module. 37When a zevent (ZFS Event) is posted, the 38.Nm 39will run any ZEDLETs (ZFS Event Daemon Linkage for Executable Tasks) 40that have been enabled for the corresponding zevent class. 41. 42.Sh OPTIONS 43.Bl -tag -width "-h" 44.It Fl h 45Display a summary of the command-line options. 46.It Fl L 47Display license information. 48.It Fl V 49Display version information. 50.It Fl v 51Be verbose. 52.It Fl f 53Force the daemon to run if at all possible, disabling security checks and 54throwing caution to the wind. 55Not recommended for use in production. 56.It Fl F 57Don't daemonise: remain attached to the controlling terminal, 58log to the standard I/O streams. 59.It Fl M 60Lock all current and future pages in the virtual memory address space. 61This may help the daemon remain responsive when the system is under heavy 62memory pressure. 63.It Fl I 64Request that the daemon idle rather than exit when the kernel modules are not loaded. 65Processing of events will start, or resume, when the kernel modules are (re)loaded. 66Under Linux the kernel modules cannot be unloaded while the daemon is running. 67.It Fl Z 68Zero the daemon's state, thereby allowing zevents still within the kernel 69to be reprocessed. 70.It Fl d Ar zedletdir 71Read the enabled ZEDLETs from the specified directory. 72.It Fl p Ar pidfile 73Write the daemon's process ID to the specified file. 74.It Fl P Ar path 75Custom 76.Ev $PATH 77for zedlets to use. 78Normally zedlets run in a locked-down environment, with hardcoded paths to the ZFS commands 79.Pq Ev $ZFS , $ZPOOL , $ZED , … , 80and a hard-coded 81.Ev $PATH . 82This is done for security reasons. 83However, the ZFS test suite uses a custom PATH for its ZFS commands, and passes it to 84.Nm 85with 86.Fl P . 87In short, 88.Fl P 89is only to be used by the ZFS test suite; never use 90it in production! 91.It Fl s Ar statefile 92Write the daemon's state to the specified file. 93.It Fl j Ar jobs 94Allow at most 95.Ar jobs 96ZEDLETs to run concurrently, 97delaying execution of new ones until they finish. 98Defaults to 99.Sy 16 . 100.It Fl b Ar buflen 101Cap kernel event buffer growth to 102.Ar buflen 103entries. 104This buffer is grown when the daemon misses an event, but results in 105unreclaimable memory use in the kernel. 106A value of 107.Sy 0 108removes the cap. 109Defaults to 110.Sy 1048576 . 111.El 112.Sh ZEVENTS 113A zevent is comprised of a list of nvpairs (name/value pairs). 114Each zevent contains an EID (Event IDentifier) that uniquely identifies it throughout 115the lifetime of the loaded ZFS kernel module; this EID is a monotonically 116increasing integer that resets to 1 each time the kernel module is loaded. 117Each zevent also contains a class string that identifies the type of event. 118For brevity, a subclass string is defined that omits the leading components 119of the class string. 120Additional nvpairs exist to provide event details. 121.Pp 122The kernel maintains a list of recent zevents that can be viewed (along with 123their associated lists of nvpairs) using the 124.Nm zpool Cm events Fl v 125command. 126. 127.Sh CONFIGURATION 128ZEDLETs to be invoked in response to zevents are located in the 129.Em enabled-zedlets 130directory 131.Pq Ar zedletdir . 132These can be symlinked or copied from the 133.Em installed-zedlets 134directory; symlinks allow for automatic updates 135from the installed ZEDLETs, whereas copies preserve local modifications. 136As a security measure, since ownership change is a privileged operation, 137ZEDLETs must be owned by root. 138They must have execute permissions for the user, 139but they must not have write permissions for group or other. 140Dotfiles are ignored. 141.Pp 142ZEDLETs are named after the zevent class for which they should be invoked. 143In particular, a ZEDLET will be invoked for a given zevent if either its 144class or subclass string is a prefix of its filename (and is followed by 145a non-alphabetic character). 146As a special case, the prefix 147.Sy all 148matches all zevents. 149Multiple ZEDLETs may be invoked for a given zevent. 150. 151.Sh ZEDLETS 152ZEDLETs are executables invoked by the ZED in response to a given zevent. 153They should be written under the presumption they can be invoked concurrently, 154and they should use appropriate locking to access any shared resources. 155Common variables used by ZEDLETs can be stored in the default rc file which 156is sourced by scripts; these variables should be prefixed with 157.Sy ZED_ . 158.Pp 159The zevent nvpairs are passed to ZEDLETs as environment variables. 160Each nvpair name is converted to an environment variable in the following 161manner: 162.Bl -enum -compact 163.It 164it is prefixed with 165.Sy ZEVENT_ , 166.It 167it is converted to uppercase, and 168.It 169each non-alphanumeric character is converted to an underscore. 170.El 171.Pp 172Some additional environment variables have been defined to present certain 173nvpair values in a more convenient form. 174An incomplete list of zevent environment variables is as follows: 175.Bl -tag -compact -width "ZEVENT_TIME_STRING" 176.It Sy ZEVENT_EID 177The Event IDentifier. 178.It Sy ZEVENT_CLASS 179The zevent class string. 180.It Sy ZEVENT_SUBCLASS 181The zevent subclass string. 182.It Sy ZEVENT_TIME 183The time at which the zevent was posted as 184.Dq Em seconds nanoseconds 185since the Epoch. 186.It Sy ZEVENT_TIME_SECS 187The 188.Em seconds 189component of 190.Sy ZEVENT_TIME . 191.It Sy ZEVENT_TIME_NSECS 192The 193.Em nanoseconds 194component of 195.Sy ZEVENT_TIME . 196.It Sy ZEVENT_TIME_STRING 197An almost-RFC3339-compliant string for 198.Sy ZEVENT_TIME . 199.El 200.Pp 201Additionally, the following ZED & ZFS variables are defined: 202.Bl -tag -compact -width "ZEVENT_TIME_STRING" 203.It Sy ZED_PID 204The daemon's process ID. 205.It Sy ZED_ZEDLET_DIR 206The daemon's current 207.Em enabled-zedlets 208directory. 209.It Sy ZFS_ALIAS 210The alias 211.Pq Dq Em name Ns - Ns Em version Ns - Ns Em release 212string of the ZFS distribution the daemon is part of. 213.It Sy ZFS_VERSION 214The ZFS version the daemon is part of. 215.It Sy ZFS_RELEASE 216The ZFS release the daemon is part of. 217.El 218.Pp 219ZEDLETs may need to call other ZFS commands. 220The installation paths of the following executables are defined as environment variables: 221.Sy ZDB , 222.Sy ZED , 223.Sy ZFS , 224.Sy ZINJECT , 225and 226.Sy ZPOOL . 227These variables may be overridden in the rc file. 228. 229.Sh FILES 230.Bl -tag -width "-c" 231.It Pa @sysconfdir@/zfs/zed.d 232The default directory for enabled ZEDLETs. 233.It Pa @sysconfdir@/zfs/zed.d/zed.rc 234The default rc file for common variables used by ZEDLETs. 235.It Pa @zfsexecdir@/zed.d 236The default directory for installed ZEDLETs. 237.It Pa @runstatedir@/zed.pid 238The default file containing the daemon's process ID. 239.It Pa @runstatedir@/zed.state 240The default file containing the daemon's state. 241.El 242. 243.Sh SIGNALS 244.Bl -tag -width "-c" 245.It Sy SIGHUP 246Reconfigure the daemon and rescan the directory for enabled ZEDLETs. 247.It Sy SIGTERM , SIGINT 248Terminate the daemon. 249.El 250. 251.Sh SEE ALSO 252.Xr zfs 8 , 253.Xr zpool 8 , 254.Xr zpool-events 8 255. 256.Sh NOTES 257The 258.Nm 259requires root privileges. 260.Pp 261Do not taunt the 262.Nm . 263. 264.Sh BUGS 265ZEDLETs are unable to return state/status information to the kernel. 266.Pp 267Internationalization support via gettext has not been added. 268