diff options
author | Jorgen Lundman <[email protected]> | 2020-06-23 01:53:34 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-22 09:53:34 -0700 |
commit | 68301ba20e0a6543304a63d22b558fddea130d79 (patch) | |
tree | 43957064dfa3f0f3571fc73878d76cf37620bd86 /cmd/zed/zed_event.c | |
parent | 42d8d1d66ac1d3629ab22f65cd0787933cfb60ab (diff) |
zed additional features
This commit adds two features to zed, that macOS desires. The first
is that when you unload the kernel module, zed would enter into a
cpubusy loop calling zfs_events_next() repeatedly. We now look for
ENODEV, returned by kernel, so zed can exit gracefully.
Second feature is -I (idle) (alas -P persist was taken) is for the
deamon to;
1; if started without ZFS kernel module, stick around waiting for it.
2; if kernel module is unloaded, go back to 1.
This is due to daemons in macOS is started by launchctl, and is
expected to stick around.
Currently, the busy loop only exists when errno is ENODEV. This is
to ensure that functionality that upstream expects is not changed.
It did not care about errors before, and it still does not. (with the
exception of ENODEV).
However, it is probably better that all errors
(ERESTART notwithstanding) exits the loop, and the issues complaining
about zed taking all CPU will go away.
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Jorgen Lundman <[email protected]>
Closes #10476
Diffstat (limited to 'cmd/zed/zed_event.c')
-rw-r--r-- | cmd/zed/zed_event.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/cmd/zed/zed_event.c b/cmd/zed/zed_event.c index 197c25386..1c5d00e29 100644 --- a/cmd/zed/zed_event.c +++ b/cmd/zed/zed_event.c @@ -41,25 +41,36 @@ /* * Open the libzfs interface. */ -void +int zed_event_init(struct zed_conf *zcp) { if (!zcp) zed_log_die("Failed zed_event_init: %s", strerror(EINVAL)); zcp->zfs_hdl = libzfs_init(); - if (!zcp->zfs_hdl) + if (!zcp->zfs_hdl) { + if (zcp->do_idle) + return (-1); zed_log_die("Failed to initialize libzfs"); + } zcp->zevent_fd = open(ZFS_DEV, O_RDWR); - if (zcp->zevent_fd < 0) + if (zcp->zevent_fd < 0) { + if (zcp->do_idle) + return (-1); zed_log_die("Failed to open \"%s\": %s", ZFS_DEV, strerror(errno)); + } zfs_agent_init(zcp->zfs_hdl); - if (zed_disk_event_init() != 0) + if (zed_disk_event_init() != 0) { + if (zcp->do_idle) + return (-1); zed_log_die("Failed to initialize disk events"); + } + + return (0); } /* @@ -873,7 +884,7 @@ _zed_event_add_time_strings(uint64_t eid, zed_strings_t *zsp, int64_t etime[]) /* * Service the next zevent, blocking until one is available. */ -void +int zed_event_service(struct zed_conf *zcp) { nvlist_t *nvl; @@ -891,13 +902,13 @@ zed_event_service(struct zed_conf *zcp) errno = EINVAL; zed_log_msg(LOG_ERR, "Failed to service zevent: %s", strerror(errno)); - return; + return (EINVAL); } rv = zpool_events_next(zcp->zfs_hdl, &nvl, &n_dropped, ZEVENT_NONE, zcp->zevent_fd); if ((rv != 0) || !nvl) - return; + return (errno); if (n_dropped > 0) { zed_log_msg(LOG_WARNING, "Missed %d events", n_dropped); @@ -950,4 +961,5 @@ zed_event_service(struct zed_conf *zcp) zed_strings_destroy(zsp); } nvlist_free(nvl); + return (0); } |