]> granicus.if.org Git - zfs/blobdiff - cmd/zed/zed_event.c
Add illumos FMD ZFS logic to ZED -- phase 2
[zfs] / cmd / zed / zed_event.c
index bd298dc414ee24413801457134b6ed7731bc1f65..c614f4fe8a574eec2a6c900086e1a36866bd515b 100644 (file)
 #include <sys/zfs_ioctl.h>
 #include <time.h>
 #include <unistd.h>
+#include <sys/fm/fs/zfs.h>
 #include "zed.h"
 #include "zed_conf.h"
+#include "zed_disk_event.h"
 #include "zed_exec.h"
 #include "zed_file.h"
 #include "zed_log.h"
 #include "zed_strings.h"
 
+#include "agents/zfs_agents.h"
+
 #define        MAXBUF  4096
 
 /*
@@ -50,6 +54,11 @@ zed_event_init(struct zed_conf *zcp)
        if (zcp->zevent_fd < 0)
                zed_log_die("Failed to open \"%s\": %s",
                    ZFS_DEV, strerror(errno));
+
+       zfs_agent_init(zcp->zfs_hdl);
+
+       if (zed_disk_event_init() != 0)
+               zed_log_die("Failed to initialize disk events");
 }
 
 /*
@@ -61,6 +70,9 @@ zed_event_fini(struct zed_conf *zcp)
        if (!zcp)
                zed_log_die("Failed zed_event_fini: %s", strerror(EINVAL));
 
+       zed_disk_event_fini();
+       zfs_agent_fini();
+
        if (zcp->zevent_fd >= 0) {
                if (close(zcp->zevent_fd) < 0)
                        zed_log_msg(LOG_WARNING, "Failed to close \"%s\": %s",
@@ -624,6 +636,17 @@ _zed_event_add_nvpair(uint64_t eid, zed_strings_t *zsp, nvpair_t *nvp)
                _zed_event_add_var(eid, zsp, prefix, name,
                    (_zed_event_value_is_hex(name) ? "0x%.16llX" : "%llu"),
                    (u_longlong_t) i64);
+               /*
+                * shadow readable strings for vdev state pairs
+                */
+               if (strcmp(name, FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE) == 0 ||
+                   strcmp(name, FM_EREPORT_PAYLOAD_ZFS_VDEV_LASTSTATE) == 0) {
+                       char alt[32];
+
+                       (void) snprintf(alt, sizeof (alt), "%s_str", name);
+                       _zed_event_add_var(eid, zsp, prefix, alt, "%s",
+                           zpool_state_to_name(i64, VDEV_AUX_NONE));
+               }
                break;
        case DATA_TYPE_DOUBLE:
                (void) nvpair_value_double(nvp, &d);
@@ -748,9 +771,8 @@ _zed_event_add_env_preserve(uint64_t eid, zed_strings_t *zsp)
 
 /*
  * Compute the "subclass" by removing the first 3 components of [class]
- * (which seem to always be either "ereport.fs.zfs" or "resource.fs.zfs").
- * Return a pointer inside the string [class], or NULL if insufficient
- * components exist.
+ * (which will always be of the form "*.fs.zfs").  Return a pointer inside
+ * the string [class], or NULL if insufficient components exist.
  */
 static const char *
 _zed_event_get_subclass(const char *class)
@@ -854,6 +876,9 @@ zed_event_service(struct zed_conf *zcp)
                zed_log_msg(LOG_WARNING,
                    "Failed to lookup zevent class (eid=%llu)", eid);
        } else {
+               /* let internal modules see this event first */
+               zfs_agent_post_event(class, NULL, nvl);
+
                zsp = zed_strings_create();
 
                nvp = NULL;
@@ -870,6 +895,7 @@ zed_event_service(struct zed_conf *zcp)
                subclass = _zed_event_get_subclass(class);
                _zed_event_add_var(eid, zsp, ZEVENT_VAR_PREFIX, "SUBCLASS",
                    "%s", (subclass ? subclass : class));
+
                _zed_event_add_time_strings(eid, zsp, etime);
 
                zed_exec_process(eid, class, subclass,