diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/zed/Makefile.am | 11 | ||||
-rw-r--r-- | cmd/zed/zed.d/.gitignore | 1 | ||||
-rwxr-xr-x | cmd/zed/zed.d/history_event-zfs-list-cacher.sh.in | 73 |
3 files changed, 84 insertions, 1 deletions
diff --git a/cmd/zed/Makefile.am b/cmd/zed/Makefile.am index 37739696e..e9e38d8e5 100644 --- a/cmd/zed/Makefile.am +++ b/cmd/zed/Makefile.am @@ -4,7 +4,8 @@ DEFAULT_INCLUDES += \ -I$(top_srcdir)/include \ -I$(top_srcdir)/lib/libspl/include -EXTRA_DIST = zed.d/README +EXTRA_DIST = zed.d/README \ + zed.d/history_event-zfs-list-cacher.sh.in sbin_PROGRAMS = zed @@ -60,6 +61,7 @@ dist_zedexec_SCRIPTS = \ zed.d/all-syslog.sh \ zed.d/data-notify.sh \ zed.d/generic-notify.sh \ + zed.d/history_event-zfs-list-cacher.sh \ zed.d/resilver_finish-notify.sh \ zed.d/scrub_finish-notify.sh \ zed.d/statechange-led.sh \ @@ -69,6 +71,13 @@ dist_zedexec_SCRIPTS = \ zed.d/pool_import-led.sh \ zed.d/resilver_finish-start-scrub.sh +zed.d/history_event-zfs-list-cacher.sh: %: %.in + -$(SED) -e 's,@bindir\@,$(bindir),g' \ + -e 's,@runstatedir\@,$(runstatedir),g' \ + -e 's,@sbindir\@,$(sbindir),g' \ + -e 's,@sysconfdir\@,$(sysconfdir),g' \ + $< >'$@' + zedconfdefaults = \ all-syslog.sh \ data-notify.sh \ diff --git a/cmd/zed/zed.d/.gitignore b/cmd/zed/zed.d/.gitignore new file mode 100644 index 000000000..46a00945a --- /dev/null +++ b/cmd/zed/zed.d/.gitignore @@ -0,0 +1 @@ +history_event-zfs-list-cacher.sh diff --git a/cmd/zed/zed.d/history_event-zfs-list-cacher.sh.in b/cmd/zed/zed.d/history_event-zfs-list-cacher.sh.in new file mode 100755 index 000000000..348c8d67a --- /dev/null +++ b/cmd/zed/zed.d/history_event-zfs-list-cacher.sh.in @@ -0,0 +1,73 @@ +#!/bin/sh +# +# Track changes to enumerated pools for use in early-boot +set -ef + +FSLIST_DIR="@sysconfdir@/zfs/zfs-list.cache" +FSLIST_TMP="@runstatedir@/zfs-list.cache.new" +FSLIST="${FSLIST_DIR}/${ZEVENT_POOL}" + +# If the pool specific cache file is not writeable, abort +[ -w "${FSLIST}" ] || exit 0 + +[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc" +. "${ZED_ZEDLET_DIR}/zed-functions.sh" + +zed_exit_if_ignoring_this_event +zed_check_cmd "${ZFS}" sort diff grep + +# If we are acting on a snapshot, we have nothing to do +printf '%s' "${ZEVENT_HISTORY_DSNAME}" | grep '@' && exit 0 + +# We obtain a lock on zfs-list to avoid any simultaneous writes. +# If we run into trouble, log and drop the lock +abort_alter() { + zed_log_msg "Error updating zfs-list.cache!" + zed_unlock zfs-list +} + +finished() { + zed_unlock zfs-list + trap - EXIT + exit 0 +} + +case "${ZEVENT_HISTORY_INTERNAL_NAME}" in + create|"finish receiving"|import|destroy|rename) + ;; + + export) + zed_lock zfs-list + trap abort_alter EXIT + echo > "${FSLIST}" + finished + ;; + + set|inherit) + # Only act if the mountpoint or canmount setting is altered. + case "${ZEVENT_HISTORY_INTERNAL_STR}" in + canmount=*|mountpoint=*) ;; + *) exit 0 ;; + esac + ;; + + *) + # Ignore all other events. + exit 0 + ;; +esac + +zed_lock zfs-list +trap abort_alter EXIT + +"${ZFS}" list -H -tfilesystem -oname,mountpoint,canmount -r "${ZEVENT_POOL}" \ + >"${FSLIST_TMP}" + +# Sort the output so that it is stable +sort "${FSLIST_TMP}" -o "${FSLIST_TMP}" + +# Don't modify the file if it hasn't changed +diff -q "${FSLIST_TMP}" "${FSLIST}" || mv "${FSLIST_TMP}" "${FSLIST}" +rm -f "${FSLIST_TMP}" + +finished |