Skip to content

Commit

Permalink
Upstream: Add snapshot and zvol events
Browse files Browse the repository at this point in the history
For kernel to send snapshot mount/unmount events to zed.

For kernel to send symlink creates/removes on zvol plumbing.
(/dev/run/dsk/zvol/$pool/$zvol -> /dev/diskX)

If zed misses the ENODEV, all errors after are EINVAL. Treat any error
as kernel module failure.

handle pthread_setname_np() differently for macOS

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Aug 12, 2021
1 parent bc93935 commit 143a1a8
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/zed/agents/zfs_agents.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ zfs_agent_dispatch(const char *class, const char *subclass, nvlist_t *nvl)
static void *
zfs_agent_consumer_thread(void *arg)
{
#ifdef __APPLE__
pthread_setname_np("agents");
#endif
for (;;) {
agent_event_t *event;

Expand Down Expand Up @@ -392,7 +395,9 @@ zfs_agent_init(libzfs_handle_t *zfs_hdl)
list_destroy(&agent_events);
zed_log_die("Failed to initialize agents");
}
#ifndef __APPLE__
pthread_setname_np(g_agents_tid, "agents");
#endif
}

void
Expand Down
5 changes: 5 additions & 0 deletions cmd/zed/agents/zfs_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,9 @@ zfs_slm_deliver_event(const char *class, const char *subclass, nvlist_t *nvl)
static void *
zfs_enum_pools(void *arg)
{
#ifdef __APPLE__
pthread_setname_np("enum-pools");
#endif
(void) zpool_iter(g_zfshdl, zfs_unavail_pool, (void *)&g_pool_list);
/*
* Linux - instead of using a thread pool, each list entry
Expand Down Expand Up @@ -946,7 +949,9 @@ zfs_slm_init()
return (-1);
}

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

Expand Down
3 changes: 3 additions & 0 deletions cmd/zed/agents/zfs_retire.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include <libzutil.h>
#include <libzfs.h>
#include <string.h>
#ifdef __APPLE__
#include <libgen.h>
#endif

#include "zfs_agents.h"
#include "fmd_api.h"
Expand Down
2 changes: 1 addition & 1 deletion cmd/zed/zed.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ main(int argc, char *argv[])
rv = zed_event_service(&zcp);

/* ENODEV: When kernel module is unloaded (osx) */
if (rv == ENODEV)
if (rv != 0)
break;
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/zed/zed_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <unistd.h>
Expand All @@ -31,6 +32,12 @@
#include "zed_log.h"
#include "zed_strings.h"

#ifdef __APPLE__
ssize_t readv(int, const struct iovec *, int);
ssize_t writev(int, const struct iovec *, int);
#endif


/*
* Initialise the configuration with default values.
*/
Expand Down
6 changes: 6 additions & 0 deletions cmd/zed/zed_disk_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ zed_udev_monitor(void *arg)
struct udev_monitor *mon = arg;
char *tmp, *tmp2;

#ifdef __APPLE__
pthread_setname_np("udev monitor");
#endif

zed_log_msg(LOG_INFO, "Waiting for new udev disk events...");

while (1) {
Expand Down Expand Up @@ -381,7 +385,9 @@ zed_disk_event_init()
return (-1);
}

#ifndef __APPLE__
pthread_setname_np(g_mon_tid, "udev monitor");
#endif
zed_log_msg(LOG_INFO, "zed_disk_event_init");

return (0);
Expand Down
8 changes: 7 additions & 1 deletion cmd/zed/zed_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>

#include "zed_exec.h"
#include "zed_log.h"
#include "zed_strings.h"
Expand Down Expand Up @@ -196,6 +198,9 @@ _reap_children(void *arg)
struct rusage usage;
struct sigaction sa = {};

#ifdef __APPLE__
pthread_setname_np("reap ZEDLETs");
#endif
(void) sigfillset(&sa.sa_mask);
(void) sigdelset(&sa.sa_mask, SIGCHLD);
(void) pthread_sigmask(SIG_SETMASK, &sa.sa_mask, NULL);
Expand Down Expand Up @@ -332,8 +337,9 @@ zed_exec_process(uint64_t eid, const char *class, const char *subclass,
if (pthread_create(&_reap_children_tid, NULL,
_reap_children, NULL) != 0)
return (-1);
#ifndef __APPLE__
pthread_setname_np(_reap_children_tid, "reap ZEDLETs");

#endif
avl_create(&_launched_processes, _launched_process_node_compare,
sizeof (struct launched_process_node),
offsetof(struct launched_process_node, node));
Expand Down
5 changes: 5 additions & 0 deletions include/sys/fm/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ extern "C" {
#define FM_RESOURCE_AUTOREPLACE "autoreplace"
#define FM_RESOURCE_STATECHANGE "statechange"

#define FM_RESOURCE_ZFS_SNAPSHOT_MOUNT "snapshot_mount"
#define FM_RESOURCE_ZFS_SNAPSHOT_UNMOUNT "snapshot_unmount"
#define FM_RESOURCE_ZVOL_CREATE_SYMLINK "zvol.create"
#define FM_RESOURCE_ZVOL_REMOVE_SYMLINK "zvol.remove"

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/sys/spa.h
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,8 @@ extern void spa_configfile_set(spa_t *, nvlist_t *, boolean_t);
/* asynchronous event notification */
extern void spa_event_notify(spa_t *spa, vdev_t *vdev, nvlist_t *hist_nvl,
const char *name);
extern void zfs_ereport_zvol_post(const char *subclass, const char *name,
const char *bsd, const char *rbsd);

/* waiting for pool activities to complete */
extern int spa_wait(const char *pool, zpool_wait_activity_t activity,
Expand Down
2 changes: 2 additions & 0 deletions include/sys/zio.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,8 @@ extern int zfs_ereport_post_checksum(spa_t *spa, vdev_t *vd,
struct zio_bad_cksum *info);

void zio_vsd_default_cksum_report(zio_t *zio, zio_cksum_report_t *zcr);
extern void zfs_ereport_snapshot_post(const char *subclass, spa_t *spa,
const char *name);

/* Called from spa_sync(), but primarily an injection handler */
extern void spa_handle_ignored_writes(spa_t *spa);
Expand Down
41 changes: 41 additions & 0 deletions module/zfs/zfs_fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,47 @@ zfs_ereport_fini(void)
mutex_destroy(&recent_events_lock);
}

void
zfs_ereport_snapshot_post(const char *subclass, spa_t *spa, const char *name)
{
nvlist_t *aux;

aux = fm_nvlist_create(NULL);
nvlist_add_string(aux, "snapshot_name", name);

zfs_post_common(spa, NULL, FM_RSRC_CLASS, subclass, aux);
fm_nvlist_destroy(aux, FM_NVA_FREE);
}

void
zfs_ereport_zvol_post(const char *subclass, const char *name, const char *bsd,
const char *rbsd)
{
nvlist_t *aux;
char *r;
spa_t *spa;
boolean_t has_lock = B_FALSE;

has_lock = mutex_owned(&spa_namespace_lock);
if (!has_lock) mutex_enter(&spa_namespace_lock);
spa = spa_lookup(name);
if (!has_lock) mutex_exit(&spa_namespace_lock);
if (!spa)
return;

aux = fm_nvlist_create(NULL);
nvlist_add_string(aux, "BSD_disk", bsd);
nvlist_add_string(aux, "BSD_rdisk", rbsd);
r = strchr(name, '/');
if (r && r[1])
nvlist_add_string(aux, "DATASET", &r[1]);

zfs_post_common(spa, NULL, FM_RSRC_CLASS, subclass, aux);
fm_nvlist_destroy(aux, FM_NVA_FREE);
}
#endif

#if defined(_KERNEL)
EXPORT_SYMBOL(zfs_ereport_post);
EXPORT_SYMBOL(zfs_ereport_is_valid);
EXPORT_SYMBOL(zfs_ereport_post_checksum);
Expand Down

0 comments on commit 143a1a8

Please sign in to comment.