summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorAntonio Russo <[email protected]>2018-04-06 17:11:09 -0400
committerBrian Behlendorf <[email protected]>2018-04-06 14:11:09 -0700
commit55d80e651a8c19919b8ee6a1c05fb36ad97ab5ad (patch)
tree10250074931531d3b32418dc8780fafbc122f0f5 /cmd
parent5c27ec10889d3d8f12d59fb7e5068ed2d8697c85 (diff)
systemd mount generator and tracking ZEDLET
zfs-mount-generator implements the "systemd generator" protocol, producing systemd.mount units from the cached outputs of zfs list, during early boot, integrating with systemd. Each pool has an indpendent cache of the command zfs list -H -oname,mountpoint,canmount -tfilesystem -r $pool which is kept synchronized by the ZEDLET history_event-zfs-list-cacher.sh Datasets not in the cache will be loaded later in the boot process by zfs-mount.service, including pools without a cache. Among other things, this allows for complex mount hierarchies. Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes #7329
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zed/Makefile.am11
-rw-r--r--cmd/zed/zed.d/.gitignore1
-rwxr-xr-xcmd/zed/zed.d/history_event-zfs-list-cacher.sh.in73
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