Created
April 11, 2014 01:02
-
-
Save lundman/10435317 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/cmd/zed/zed_event.c b/cmd/zed/zed_event.c | |
index e504aef..3eae791 100644 | |
--- a/cmd/zed/zed_event.c | |
+++ b/cmd/zed/zed_event.c | |
@@ -36,6 +36,7 @@ | |
#include <sys/zfs_ioctl.h> | |
#include <time.h> | |
#include <unistd.h> | |
+#include <signal.h> | |
#include "zed.h" | |
#include "zed_conf.h" | |
#include "zed_exec.h" | |
@@ -52,9 +53,22 @@ zed_event_init(struct zed_conf *zcp) | |
if (!zcp) | |
zed_log_die("Failed zed_event_init: %s", strerror(EINVAL)); | |
+ retry: | |
zcp->zfs_hdl = libzfs_init(); | |
- if (!zcp->zfs_hdl) | |
+ if (!zcp->zfs_hdl) { | |
+ | |
+ /* | |
+ * If we failed to open /dev/zfs, but force was requested, we | |
+ * sleep waiting for it to come alive. This lets zed sit around | |
+ * waiting for the kernel module to load. | |
+ */ | |
+ if (zcp->do_force) { | |
+ sleep(30); | |
+ goto retry; | |
+ } | |
+ | |
zed_log_die("Failed to initialize libzfs"); | |
+ } | |
diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c | |
index ac63410..3c92960 100644 | |
--- a/lib/libzfs/libzfs_pool.c | |
+++ b/lib/libzfs/libzfs_pool.c | |
@@ -3871,8 +3871,13 @@ zpool_events_next(libzfs_handle_t *hdl, nvlist_t **nvp, | |
retry: | |
if (zfs_ioctl(hdl, ZFS_IOC_EVENTS_NEXT, &zc) != 0) { | |
switch (errno) { | |
+#ifdef __APPLE__ | |
+ case ENODEV: | |
+ /* fall through */ | |
+ error = errno; | |
+#endif | |
case ESHUTDOWN: | |
- error = zfs_error_fmt(hdl, EZFS_POOLUNAVAIL, | |
+ (void) zfs_error_fmt(hdl, EZFS_POOLUNAVAIL, | |
dgettext(TEXT_DOMAIN, "zfs shutdown")); | |
goto out; | |
case ENOENT: | |
@@ -774,6 +788,13 @@ zed_event_service(struct zed_conf *zcp) | |
rv = zpool_events_next(zcp->zfs_hdl, &nvl, &n_dropped, ZEVENT_NONE, | |
zcp->zevent_fd); | |
+#ifdef __APPLE__ | |
+ if (rv == ENODEV) { | |
+ /* _got_exit is static, so lets signal ourselves */ | |
+ kill(0, SIGTERM); | |
+ } | |
+#endif | |
+ | |
if ((rv != 0) || !nvl) | |
return; | |
diff --git a/cmd/zed/zed.c b/cmd/zed/zed.c | |
index c54a59b..36e3e1c 100644 | |
--- a/cmd/zed/zed.c | |
+++ b/cmd/zed/zed.c | |
@@ -217,6 +217,7 @@ main(int argc, char *argv[]) | |
if (zed_conf_read_state(zcp, &saved_eid, saved_etime) < 0) | |
exit(EXIT_FAILURE); | |
+ retry: | |
zed_event_init(zcp); | |
zed_event_seek(zcp, saved_eid, saved_etime); | |
@@ -229,6 +230,10 @@ main(int argc, char *argv[]) | |
} | |
zed_log_msg(LOG_NOTICE, "Exiting"); | |
zed_event_fini(zcp); | |
+ if (zcp->do_force) { | |
+ _got_exit = 0; | |
+ goto retry; | |
+ } | |
zed_conf_destroy(zcp); | |
zed_log_fini(); | |
exit(EXIT_SUCCESS); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment