Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper async reaping (or alarm(2)-based delooping at least) for ZED #11807

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/zed/agents/zfs_agents.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ zfs_agent_init(libzfs_handle_t *zfs_hdl)
list_destroy(&agent_events);
zed_log_die("Failed to initialize agents");
}
pthread_setname_np(g_agents_tid, "agents");
}

void
Expand Down
1 change: 1 addition & 0 deletions cmd/zed/agents/zfs_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ zfs_slm_init()
return (-1);
}

pthread_setname_np(g_zfs_tid, "enum-pools");
list_create(&g_device_list, sizeof (struct pendingdev),
offsetof(struct pendingdev, pd_node));

Expand Down
6 changes: 5 additions & 1 deletion cmd/zed/zed.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ _setup_sig_handlers(void)
zed_log_die("Failed to initialize sigset");

sa.sa_flags = SA_RESTART;
sa.sa_handler = SIG_IGN;

sa.sa_handler = SIG_IGN;
if (sigaction(SIGPIPE, &sa, NULL) < 0)
zed_log_die("Failed to ignore SIGPIPE");

Expand All @@ -75,6 +75,10 @@ _setup_sig_handlers(void)
sa.sa_handler = _hup_handler;
if (sigaction(SIGHUP, &sa, NULL) < 0)
zed_log_die("Failed to register SIGHUP handler");

(void) sigaddset(&sa.sa_mask, SIGCHLD);
if (pthread_sigmask(SIG_BLOCK, &sa.sa_mask, NULL) < 0)
zed_log_die("Failed to block SIGCHLD");
}

/*
Expand Down
17 changes: 16 additions & 1 deletion cmd/zed/zed_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ zed_conf_create(void)
zcp->state_fd = -1; /* opened via zed_conf_open_state() */
zcp->zfs_hdl = NULL; /* opened via zed_event_init() */
zcp->zevent_fd = -1; /* opened via zed_event_init() */
zcp->max_jobs = 16;

if (!(zcp->conf_file = strdup(ZED_CONF_FILE)))
goto nomem;
Expand Down Expand Up @@ -172,6 +173,8 @@ _zed_conf_display_help(const char *prog, int got_err)
"Write daemon's PID to FILE.", ZED_PID_FILE);
fprintf(fp, "%*c%*s %s [%s]\n", w1, 0x20, -w2, "-s FILE",
"Write daemon's state to FILE.", ZED_STATE_FILE);
fprintf(fp, "%*c%*s %s [%d]\n", w1, 0x20, -w2, "-j JOBS",
"Start at most JOBS at once.", 16);
fprintf(fp, "\n");

exit(got_err ? EXIT_FAILURE : EXIT_SUCCESS);
Expand Down Expand Up @@ -251,8 +254,9 @@ _zed_conf_parse_path(char **resultp, const char *path)
void
zed_conf_parse_opts(struct zed_conf *zcp, int argc, char **argv)
{
const char * const opts = ":hLVc:d:p:P:s:vfFMZI";
const char * const opts = ":hLVc:d:p:P:s:vfFMZIj:";
int opt;
unsigned long raw;

if (!zcp || !argv || !argv[0])
zed_log_die("Failed to parse options: Internal error");
Expand Down Expand Up @@ -303,6 +307,17 @@ zed_conf_parse_opts(struct zed_conf *zcp, int argc, char **argv)
case 'Z':
zcp->do_zero = 1;
break;
case 'j':
errno = 0;
raw = strtoul(optarg, NULL, 0);
if (errno == ERANGE || raw > INT16_MAX) {
zed_log_die("%lu is too many jobs", raw);
} if (raw == 0) {
zed_log_die("0 jobs makes no sense");
} else {
zcp->max_jobs = raw;
}
break;
case '?':
default:
if (optopt == '?')
Expand Down
1 change: 1 addition & 0 deletions cmd/zed/zed_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct zed_conf {
libzfs_handle_t *zfs_hdl; /* handle to libzfs */
int zevent_fd; /* fd for access to zevents */
char *path; /* custom $PATH for zedlets to use */
int16_t max_jobs; /* max zedlets to run at one time */
};

struct zed_conf *zed_conf_create(void);
Expand Down
1 change: 1 addition & 0 deletions cmd/zed/zed_disk_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ zed_disk_event_init()
return (-1);
}

pthread_setname_np(g_mon_tid, "udev monitor");
zed_log_msg(LOG_INFO, "zed_disk_event_init");

return (0);
Expand Down
7 changes: 4 additions & 3 deletions cmd/zed/zed_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <libzfs.h> /* FIXME: Replace with libzfs_core. */
#include <libzfs_core.h>
#include <paths.h>
#include <stdarg.h>
#include <stdio.h>
Expand Down Expand Up @@ -96,6 +96,8 @@ zed_event_fini(struct zed_conf *zcp)
libzfs_fini(zcp->zfs_hdl);
zcp->zfs_hdl = NULL;
}

zed_exec_fini();
}

/*
Expand Down Expand Up @@ -953,8 +955,7 @@ zed_event_service(struct zed_conf *zcp)

_zed_event_add_time_strings(eid, zsp, etime);

zed_exec_process(eid, class, subclass,
zcp->zedlet_dir, zcp->zedlets, zsp, zcp->zevent_fd);
zed_exec_process(eid, class, subclass, zcp, zsp);

zed_conf_write_state(zcp, eid, etime);

Expand Down
Loading