2 * This file is part of the ZFS Event Daemon (ZED).
4 * Developed at Lawrence Livermore National Laboratory (LLNL-CODE-403049).
5 * Copyright (C) 2013-2014 Lawrence Livermore National Security, LLC.
6 * Refer to the ZoL git commit log for authoritative copyright attribution.
8 * The contents of this file are subject to the terms of the
9 * Common Development and Distribution License Version 1.0 (CDDL-1.0).
10 * You can obtain a copy of the license from the top-level file
11 * "OPENSOLARIS.LICENSE" or at <http://opensource.org/licenses/CDDL-1.0>.
12 * You may not use this file except in compliance with the license.
18 #include <libzfs.h> /* FIXME: Replace with libzfs_core. */
24 #include <sys/zfs_ioctl.h>
27 #include <sys/fm/fs/zfs.h>
30 #include "zed_disk_event.h"
31 #include "zed_event.h"
35 #include "zed_strings.h"
37 #include "agents/zfs_agents.h"
42 * Open the libzfs interface.
45 zed_event_init(struct zed_conf *zcp)
48 zed_log_die("Failed zed_event_init: %s", strerror(EINVAL));
50 zcp->zfs_hdl = libzfs_init();
54 zed_log_die("Failed to initialize libzfs");
57 zcp->zevent_fd = open(ZFS_DEV, O_RDWR);
58 if (zcp->zevent_fd < 0) {
61 zed_log_die("Failed to open \"%s\": %s",
62 ZFS_DEV, strerror(errno));
65 zfs_agent_init(zcp->zfs_hdl);
67 if (zed_disk_event_init() != 0) {
70 zed_log_die("Failed to initialize disk events");
77 * Close the libzfs interface.
80 zed_event_fini(struct zed_conf *zcp)
83 zed_log_die("Failed zed_event_fini: %s", strerror(EINVAL));
85 zed_disk_event_fini();
88 if (zcp->zevent_fd >= 0) {
89 if (close(zcp->zevent_fd) < 0)
90 zed_log_msg(LOG_WARNING, "Failed to close \"%s\": %s",
91 ZFS_DEV, strerror(errno));
96 libzfs_fini(zcp->zfs_hdl);
102 * Seek to the event specified by [saved_eid] and [saved_etime].
103 * This protects against processing a given event more than once.
104 * Return 0 upon a successful seek to the specified event, or -1 otherwise.
106 * A zevent is considered to be uniquely specified by its (eid,time) tuple.
107 * The unsigned 64b eid is set to 1 when the kernel module is loaded, and
108 * incremented by 1 for each new event. Since the state file can persist
109 * across a kernel module reload, the time must be checked to ensure a match.
112 zed_event_seek(struct zed_conf *zcp, uint64_t saved_eid, int64_t saved_etime[])
124 zed_log_msg(LOG_ERR, "Failed to seek zevent: %s",
130 while ((eid < saved_eid) && !found) {
131 rv = zpool_events_next(zcp->zfs_hdl, &nvl, &n_dropped,
132 ZEVENT_NONBLOCK, zcp->zevent_fd);
134 if ((rv != 0) || !nvl)
138 zed_log_msg(LOG_WARNING, "Missed %d events", n_dropped);
140 * FIXME: Increase max size of event nvlist in
141 * /sys/module/zfs/parameters/zfs_zevent_len_max ?
144 if (nvlist_lookup_uint64(nvl, "eid", &eid) != 0) {
145 zed_log_msg(LOG_WARNING, "Failed to lookup zevent eid");
146 } else if (nvlist_lookup_int64_array(nvl, "time",
147 &etime, &nelem) != 0) {
148 zed_log_msg(LOG_WARNING,
149 "Failed to lookup zevent time (eid=%llu)", eid);
150 } else if (nelem != 2) {
151 zed_log_msg(LOG_WARNING,
152 "Failed to lookup zevent time (eid=%llu, nelem=%u)",
154 } else if ((eid != saved_eid) ||
155 (etime[0] != saved_etime[0]) ||
156 (etime[1] != saved_etime[1])) {
163 if (!found && (saved_eid > 0)) {
164 if (zpool_events_seek(zcp->zfs_hdl, ZEVENT_SEEK_START,
166 zed_log_msg(LOG_WARNING, "Failed to seek to eid=0");
170 zed_log_msg(LOG_NOTICE, "Processing events since eid=%llu", eid);
171 return (found ? 0 : -1);
175 * Return non-zero if nvpair [name] should be formatted in hex; o/w, return 0.
178 _zed_event_value_is_hex(const char *name)
180 const char *hex_suffix[] = {
191 for (pp = hex_suffix; *pp; pp++) {
192 p = strstr(name, *pp);
193 if (p && strlen(p) == strlen(*pp))
200 * Add an environment variable for [eid] to the container [zsp].
202 * The variable name is the concatenation of [prefix] and [name] converted to
203 * uppercase with non-alphanumeric characters converted to underscores;
204 * [prefix] is optional, and [name] must begin with an alphabetic character.
205 * If the converted variable name already exists within the container [zsp],
206 * its existing value will be replaced with the new value.
208 * The variable value is specified by the format string [fmt].
210 * Returns 0 on success, and -1 on error (with errno set).
212 * All environment variables in [zsp] should be added through this function.
215 _zed_event_add_var(uint64_t eid, zed_strings_t *zsp,
216 const char *prefix, const char *name, const char *fmt, ...)
232 zed_log_msg(LOG_WARNING,
233 "Failed to add variable for eid=%llu: Name is empty", eid);
235 } else if (!isalpha(name[0])) {
237 zed_log_msg(LOG_WARNING,
238 "Failed to add variable for eid=%llu: "
239 "Name \"%s\" is invalid", eid, name);
243 * Construct the string key by converting PREFIX (if present) and NAME.
246 lastp = keybuf + sizeof (keybuf);
248 for (srcp = prefix; *srcp && (dstp < lastp); srcp++)
249 *dstp++ = isalnum(*srcp) ? toupper(*srcp) : '_';
251 for (srcp = name; *srcp && (dstp < lastp); srcp++)
252 *dstp++ = isalnum(*srcp) ? toupper(*srcp) : '_';
255 errno = ENAMETOOLONG;
256 zed_log_msg(LOG_WARNING,
257 "Failed to add variable for eid=%llu: Name too long", eid);
262 * Construct the string specified by "[PREFIX][NAME]=[FMT]".
265 buflen = sizeof (valbuf);
266 n = strlcpy(dstp, keybuf, buflen);
267 if (n >= sizeof (valbuf)) {
269 zed_log_msg(LOG_WARNING, "Failed to add %s for eid=%llu: %s",
270 keybuf, eid, "Exceeded buffer size");
281 zed_log_msg(LOG_WARNING, "Failed to add %s for eid=%llu: %s",
282 keybuf, eid, "Exceeded buffer size");
286 va_start(vargs, fmt);
287 n = vsnprintf(dstp, buflen, fmt, vargs);
290 if ((n < 0) || (n >= buflen)) {
292 zed_log_msg(LOG_WARNING, "Failed to add %s for eid=%llu: %s",
293 keybuf, eid, "Exceeded buffer size");
295 } else if (zed_strings_add(zsp, keybuf, valbuf) < 0) {
296 zed_log_msg(LOG_WARNING, "Failed to add %s for eid=%llu: %s",
297 keybuf, eid, strerror(errno));
304 _zed_event_add_array_err(uint64_t eid, const char *name)
307 zed_log_msg(LOG_WARNING,
308 "Failed to convert nvpair \"%s\" for eid=%llu: "
309 "Exceeded buffer size", name, eid);
314 _zed_event_add_int8_array(uint64_t eid, zed_strings_t *zsp,
315 const char *prefix, nvpair_t *nvp)
318 int buflen = sizeof (buf);
326 assert((nvp != NULL) && (nvpair_type(nvp) == DATA_TYPE_INT8_ARRAY));
328 name = nvpair_name(nvp);
329 (void) nvpair_value_int8_array(nvp, &i8p, &nelem);
330 for (i = 0, p = buf; (i < nelem) && (buflen > 0); i++) {
331 n = snprintf(p, buflen, "%d ", i8p[i]);
332 if ((n < 0) || (n >= buflen))
333 return (_zed_event_add_array_err(eid, name));
340 return (_zed_event_add_var(eid, zsp, prefix, name, "%s", buf));
344 _zed_event_add_uint8_array(uint64_t eid, zed_strings_t *zsp,
345 const char *prefix, nvpair_t *nvp)
348 int buflen = sizeof (buf);
356 assert((nvp != NULL) && (nvpair_type(nvp) == DATA_TYPE_UINT8_ARRAY));
358 name = nvpair_name(nvp);
359 (void) nvpair_value_uint8_array(nvp, &u8p, &nelem);
360 for (i = 0, p = buf; (i < nelem) && (buflen > 0); i++) {
361 n = snprintf(p, buflen, "%u ", u8p[i]);
362 if ((n < 0) || (n >= buflen))
363 return (_zed_event_add_array_err(eid, name));
370 return (_zed_event_add_var(eid, zsp, prefix, name, "%s", buf));
374 _zed_event_add_int16_array(uint64_t eid, zed_strings_t *zsp,
375 const char *prefix, nvpair_t *nvp)
378 int buflen = sizeof (buf);
386 assert((nvp != NULL) && (nvpair_type(nvp) == DATA_TYPE_INT16_ARRAY));
388 name = nvpair_name(nvp);
389 (void) nvpair_value_int16_array(nvp, &i16p, &nelem);
390 for (i = 0, p = buf; (i < nelem) && (buflen > 0); i++) {
391 n = snprintf(p, buflen, "%d ", i16p[i]);
392 if ((n < 0) || (n >= buflen))
393 return (_zed_event_add_array_err(eid, name));
400 return (_zed_event_add_var(eid, zsp, prefix, name, "%s", buf));
404 _zed_event_add_uint16_array(uint64_t eid, zed_strings_t *zsp,
405 const char *prefix, nvpair_t *nvp)
408 int buflen = sizeof (buf);
416 assert((nvp != NULL) && (nvpair_type(nvp) == DATA_TYPE_UINT16_ARRAY));
418 name = nvpair_name(nvp);
419 (void) nvpair_value_uint16_array(nvp, &u16p, &nelem);
420 for (i = 0, p = buf; (i < nelem) && (buflen > 0); i++) {
421 n = snprintf(p, buflen, "%u ", u16p[i]);
422 if ((n < 0) || (n >= buflen))
423 return (_zed_event_add_array_err(eid, name));
430 return (_zed_event_add_var(eid, zsp, prefix, name, "%s", buf));
434 _zed_event_add_int32_array(uint64_t eid, zed_strings_t *zsp,
435 const char *prefix, nvpair_t *nvp)
438 int buflen = sizeof (buf);
446 assert((nvp != NULL) && (nvpair_type(nvp) == DATA_TYPE_INT32_ARRAY));
448 name = nvpair_name(nvp);
449 (void) nvpair_value_int32_array(nvp, &i32p, &nelem);
450 for (i = 0, p = buf; (i < nelem) && (buflen > 0); i++) {
451 n = snprintf(p, buflen, "%d ", i32p[i]);
452 if ((n < 0) || (n >= buflen))
453 return (_zed_event_add_array_err(eid, name));
460 return (_zed_event_add_var(eid, zsp, prefix, name, "%s", buf));
464 _zed_event_add_uint32_array(uint64_t eid, zed_strings_t *zsp,
465 const char *prefix, nvpair_t *nvp)
468 int buflen = sizeof (buf);
476 assert((nvp != NULL) && (nvpair_type(nvp) == DATA_TYPE_UINT32_ARRAY));
478 name = nvpair_name(nvp);
479 (void) nvpair_value_uint32_array(nvp, &u32p, &nelem);
480 for (i = 0, p = buf; (i < nelem) && (buflen > 0); i++) {
481 n = snprintf(p, buflen, "%u ", u32p[i]);
482 if ((n < 0) || (n >= buflen))
483 return (_zed_event_add_array_err(eid, name));
490 return (_zed_event_add_var(eid, zsp, prefix, name, "%s", buf));
494 _zed_event_add_int64_array(uint64_t eid, zed_strings_t *zsp,
495 const char *prefix, nvpair_t *nvp)
498 int buflen = sizeof (buf);
506 assert((nvp != NULL) && (nvpair_type(nvp) == DATA_TYPE_INT64_ARRAY));
508 name = nvpair_name(nvp);
509 (void) nvpair_value_int64_array(nvp, &i64p, &nelem);
510 for (i = 0, p = buf; (i < nelem) && (buflen > 0); i++) {
511 n = snprintf(p, buflen, "%lld ", (u_longlong_t)i64p[i]);
512 if ((n < 0) || (n >= buflen))
513 return (_zed_event_add_array_err(eid, name));
520 return (_zed_event_add_var(eid, zsp, prefix, name, "%s", buf));
524 _zed_event_add_uint64_array(uint64_t eid, zed_strings_t *zsp,
525 const char *prefix, nvpair_t *nvp)
528 int buflen = sizeof (buf);
537 assert((nvp != NULL) && (nvpair_type(nvp) == DATA_TYPE_UINT64_ARRAY));
539 name = nvpair_name(nvp);
540 fmt = _zed_event_value_is_hex(name) ? "0x%.16llX " : "%llu ";
541 (void) nvpair_value_uint64_array(nvp, &u64p, &nelem);
542 for (i = 0, p = buf; (i < nelem) && (buflen > 0); i++) {
543 n = snprintf(p, buflen, fmt, (u_longlong_t)u64p[i]);
544 if ((n < 0) || (n >= buflen))
545 return (_zed_event_add_array_err(eid, name));
552 return (_zed_event_add_var(eid, zsp, prefix, name, "%s", buf));
556 _zed_event_add_string_array(uint64_t eid, zed_strings_t *zsp,
557 const char *prefix, nvpair_t *nvp)
560 int buflen = sizeof (buf);
568 assert((nvp != NULL) && (nvpair_type(nvp) == DATA_TYPE_STRING_ARRAY));
570 name = nvpair_name(nvp);
571 (void) nvpair_value_string_array(nvp, &strp, &nelem);
572 for (i = 0, p = buf; (i < nelem) && (buflen > 0); i++) {
573 n = snprintf(p, buflen, "%s ", strp[i] ? strp[i] : "<NULL>");
574 if ((n < 0) || (n >= buflen))
575 return (_zed_event_add_array_err(eid, name));
582 return (_zed_event_add_var(eid, zsp, prefix, name, "%s", buf));
586 * Convert the nvpair [nvp] to a string which is added to the environment
587 * of the child process.
588 * Return 0 on success, -1 on error.
590 * FIXME: Refactor with cmd/zpool/zpool_main.c:zpool_do_events_nvprint()?
593 _zed_event_add_nvpair(uint64_t eid, zed_strings_t *zsp, nvpair_t *nvp)
597 const char *prefix = ZEVENT_VAR_PREFIX;
609 name = nvpair_name(nvp);
610 type = nvpair_type(nvp);
613 case DATA_TYPE_BOOLEAN:
614 _zed_event_add_var(eid, zsp, prefix, name, "%s", "1");
616 case DATA_TYPE_BOOLEAN_VALUE:
617 (void) nvpair_value_boolean_value(nvp, &b);
618 _zed_event_add_var(eid, zsp, prefix, name, "%s", b ? "1" : "0");
621 (void) nvpair_value_byte(nvp, &i8);
622 _zed_event_add_var(eid, zsp, prefix, name, "%d", i8);
625 (void) nvpair_value_int8(nvp, (int8_t *)&i8);
626 _zed_event_add_var(eid, zsp, prefix, name, "%d", i8);
628 case DATA_TYPE_UINT8:
629 (void) nvpair_value_uint8(nvp, &i8);
630 _zed_event_add_var(eid, zsp, prefix, name, "%u", i8);
632 case DATA_TYPE_INT16:
633 (void) nvpair_value_int16(nvp, (int16_t *)&i16);
634 _zed_event_add_var(eid, zsp, prefix, name, "%d", i16);
636 case DATA_TYPE_UINT16:
637 (void) nvpair_value_uint16(nvp, &i16);
638 _zed_event_add_var(eid, zsp, prefix, name, "%u", i16);
640 case DATA_TYPE_INT32:
641 (void) nvpair_value_int32(nvp, (int32_t *)&i32);
642 _zed_event_add_var(eid, zsp, prefix, name, "%d", i32);
644 case DATA_TYPE_UINT32:
645 (void) nvpair_value_uint32(nvp, &i32);
646 _zed_event_add_var(eid, zsp, prefix, name, "%u", i32);
648 case DATA_TYPE_INT64:
649 (void) nvpair_value_int64(nvp, (int64_t *)&i64);
650 _zed_event_add_var(eid, zsp, prefix, name,
651 "%lld", (longlong_t)i64);
653 case DATA_TYPE_UINT64:
654 (void) nvpair_value_uint64(nvp, &i64);
655 _zed_event_add_var(eid, zsp, prefix, name,
656 (_zed_event_value_is_hex(name) ? "0x%.16llX" : "%llu"),
659 * shadow readable strings for vdev state pairs
661 if (strcmp(name, FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE) == 0 ||
662 strcmp(name, FM_EREPORT_PAYLOAD_ZFS_VDEV_LASTSTATE) == 0) {
665 (void) snprintf(alt, sizeof (alt), "%s_str", name);
666 _zed_event_add_var(eid, zsp, prefix, alt, "%s",
667 zpool_state_to_name(i64, VDEV_AUX_NONE));
670 * shadow readable strings for pool state
672 if (strcmp(name, FM_EREPORT_PAYLOAD_ZFS_POOL_STATE) == 0) {
675 (void) snprintf(alt, sizeof (alt), "%s_str", name);
676 _zed_event_add_var(eid, zsp, prefix, alt, "%s",
677 zpool_pool_state_to_name(i64));
680 case DATA_TYPE_DOUBLE:
681 (void) nvpair_value_double(nvp, &d);
682 _zed_event_add_var(eid, zsp, prefix, name, "%g", d);
684 case DATA_TYPE_HRTIME:
685 (void) nvpair_value_hrtime(nvp, (hrtime_t *)&i64);
686 _zed_event_add_var(eid, zsp, prefix, name,
687 "%llu", (u_longlong_t)i64);
689 case DATA_TYPE_NVLIST:
690 _zed_event_add_var(eid, zsp, prefix, name,
691 "%s", "_NOT_IMPLEMENTED_"); /* FIXME */
693 case DATA_TYPE_STRING:
694 (void) nvpair_value_string(nvp, &str);
695 _zed_event_add_var(eid, zsp, prefix, name,
696 "%s", (str ? str : "<NULL>"));
698 case DATA_TYPE_BOOLEAN_ARRAY:
699 _zed_event_add_var(eid, zsp, prefix, name,
700 "%s", "_NOT_IMPLEMENTED_"); /* FIXME */
702 case DATA_TYPE_BYTE_ARRAY:
703 _zed_event_add_var(eid, zsp, prefix, name,
704 "%s", "_NOT_IMPLEMENTED_"); /* FIXME */
706 case DATA_TYPE_INT8_ARRAY:
707 _zed_event_add_int8_array(eid, zsp, prefix, nvp);
709 case DATA_TYPE_UINT8_ARRAY:
710 _zed_event_add_uint8_array(eid, zsp, prefix, nvp);
712 case DATA_TYPE_INT16_ARRAY:
713 _zed_event_add_int16_array(eid, zsp, prefix, nvp);
715 case DATA_TYPE_UINT16_ARRAY:
716 _zed_event_add_uint16_array(eid, zsp, prefix, nvp);
718 case DATA_TYPE_INT32_ARRAY:
719 _zed_event_add_int32_array(eid, zsp, prefix, nvp);
721 case DATA_TYPE_UINT32_ARRAY:
722 _zed_event_add_uint32_array(eid, zsp, prefix, nvp);
724 case DATA_TYPE_INT64_ARRAY:
725 _zed_event_add_int64_array(eid, zsp, prefix, nvp);
727 case DATA_TYPE_UINT64_ARRAY:
728 _zed_event_add_uint64_array(eid, zsp, prefix, nvp);
730 case DATA_TYPE_STRING_ARRAY:
731 _zed_event_add_string_array(eid, zsp, prefix, nvp);
733 case DATA_TYPE_NVLIST_ARRAY:
734 _zed_event_add_var(eid, zsp, prefix, name,
735 "%s", "_NOT_IMPLEMENTED_"); /* FIXME */
739 zed_log_msg(LOG_WARNING,
740 "Failed to convert nvpair \"%s\" for eid=%llu: "
741 "Unrecognized type=%u", name, eid, (unsigned int) type);
747 * Restrict various environment variables to safe and sane values
748 * when constructing the environment for the child process, unless
749 * we're running with a custom $PATH (like under the ZFS test suite).
751 * Reference: Secure Programming Cookbook by Viega & Messier, Section 1.1.
754 _zed_event_add_env_restrict(uint64_t eid, zed_strings_t *zsp,
757 const char *env_restrict[][2] = {
759 { "PATH", _PATH_STDPATH },
760 { "ZDB", SBINDIR "/zdb" },
761 { "ZED", SBINDIR "/zed" },
762 { "ZFS", SBINDIR "/zfs" },
763 { "ZINJECT", SBINDIR "/zinject" },
764 { "ZPOOL", SBINDIR "/zpool" },
765 { "ZFS_ALIAS", ZFS_META_ALIAS },
766 { "ZFS_VERSION", ZFS_META_VERSION },
767 { "ZFS_RELEASE", ZFS_META_RELEASE },
772 * If we have a custom $PATH, use the default ZFS binary locations
773 * instead of the hard-coded ones.
775 const char *env_path[][2] = {
777 { "PATH", NULL }, /* $PATH copied in later on */
781 { "ZINJECT", "zinject" },
782 { "ZPOOL", "zpool" },
783 { "ZFS_ALIAS", ZFS_META_ALIAS },
784 { "ZFS_VERSION", ZFS_META_VERSION },
785 { "ZFS_RELEASE", ZFS_META_RELEASE },
788 const char *(*pa)[2];
792 pa = path != NULL ? env_path : env_restrict;
794 for (; *(*pa); pa++) {
795 /* Use our custom $PATH if we have one */
796 if (path != NULL && strcmp((*pa)[0], "PATH") == 0)
799 _zed_event_add_var(eid, zsp, NULL, (*pa)[0], "%s", (*pa)[1]);
804 * Preserve specified variables from the parent environment
805 * when constructing the environment for the child process.
807 * Reference: Secure Programming Cookbook by Viega & Messier, Section 1.1.
810 _zed_event_add_env_preserve(uint64_t eid, zed_strings_t *zsp)
812 const char *env_preserve[] = {
821 for (keyp = env_preserve; *keyp; keyp++) {
822 if ((val = getenv(*keyp)))
823 _zed_event_add_var(eid, zsp, NULL, *keyp, "%s", val);
828 * Compute the "subclass" by removing the first 3 components of [class]
829 * (which will always be of the form "*.fs.zfs"). Return a pointer inside
830 * the string [class], or NULL if insufficient components exist.
833 _zed_event_get_subclass(const char *class)
842 for (i = 0; i < 3; i++) {
852 * Convert the zevent time from a 2-element array of 64b integers
853 * into a more convenient form:
854 * - TIME_SECS is the second component of the time.
855 * - TIME_NSECS is the nanosecond component of the time.
856 * - TIME_STRING is an almost-RFC3339-compliant string representation.
859 _zed_event_add_time_strings(uint64_t eid, zed_strings_t *zsp, int64_t etime[])
865 assert(etime != NULL);
867 _zed_event_add_var(eid, zsp, ZEVENT_VAR_PREFIX, "TIME_SECS",
868 "%lld", (long long int) etime[0]);
869 _zed_event_add_var(eid, zsp, ZEVENT_VAR_PREFIX, "TIME_NSECS",
870 "%lld", (long long int) etime[1]);
872 if (!(stp = localtime((const time_t *) &etime[0]))) {
873 zed_log_msg(LOG_WARNING, "Failed to add %s%s for eid=%llu: %s",
874 ZEVENT_VAR_PREFIX, "TIME_STRING", eid, "localtime error");
875 } else if (!strftime(buf, sizeof (buf), "%Y-%m-%d %H:%M:%S%z", stp)) {
876 zed_log_msg(LOG_WARNING, "Failed to add %s%s for eid=%llu: %s",
877 ZEVENT_VAR_PREFIX, "TIME_STRING", eid, "strftime error");
879 _zed_event_add_var(eid, zsp, ZEVENT_VAR_PREFIX, "TIME_STRING",
885 * Service the next zevent, blocking until one is available.
888 zed_event_service(struct zed_conf *zcp)
898 const char *subclass;
903 zed_log_msg(LOG_ERR, "Failed to service zevent: %s",
907 rv = zpool_events_next(zcp->zfs_hdl, &nvl, &n_dropped, ZEVENT_NONE,
910 if ((rv != 0) || !nvl)
914 zed_log_msg(LOG_WARNING, "Missed %d events", n_dropped);
916 * FIXME: Increase max size of event nvlist in
917 * /sys/module/zfs/parameters/zfs_zevent_len_max ?
920 if (nvlist_lookup_uint64(nvl, "eid", &eid) != 0) {
921 zed_log_msg(LOG_WARNING, "Failed to lookup zevent eid");
922 } else if (nvlist_lookup_int64_array(
923 nvl, "time", &etime, &nelem) != 0) {
924 zed_log_msg(LOG_WARNING,
925 "Failed to lookup zevent time (eid=%llu)", eid);
926 } else if (nelem != 2) {
927 zed_log_msg(LOG_WARNING,
928 "Failed to lookup zevent time (eid=%llu, nelem=%u)",
930 } else if (nvlist_lookup_string(nvl, "class", &class) != 0) {
931 zed_log_msg(LOG_WARNING,
932 "Failed to lookup zevent class (eid=%llu)", eid);
934 /* let internal modules see this event first */
935 zfs_agent_post_event(class, NULL, nvl);
937 zsp = zed_strings_create();
940 while ((nvp = nvlist_next_nvpair(nvl, nvp)))
941 _zed_event_add_nvpair(eid, zsp, nvp);
943 _zed_event_add_env_restrict(eid, zsp, zcp->path);
944 _zed_event_add_env_preserve(eid, zsp);
946 _zed_event_add_var(eid, zsp, ZED_VAR_PREFIX, "PID",
947 "%d", (int)getpid());
948 _zed_event_add_var(eid, zsp, ZED_VAR_PREFIX, "ZEDLET_DIR",
949 "%s", zcp->zedlet_dir);
950 subclass = _zed_event_get_subclass(class);
951 _zed_event_add_var(eid, zsp, ZEVENT_VAR_PREFIX, "SUBCLASS",
952 "%s", (subclass ? subclass : class));
954 _zed_event_add_time_strings(eid, zsp, etime);
956 zed_exec_process(eid, class, subclass,
957 zcp->zedlet_dir, zcp->zedlets, zsp, zcp->zevent_fd);
959 zed_conf_write_state(zcp, eid, etime);
961 zed_strings_destroy(zsp);