dsl_dataset: put IO-inducing frees on the pool deadlist
[zfs.git] / cmd / zed / zed.d / history_event-zfs-list-cacher.sh.in
blob8c5031a38c6a61104447830a8169f7ab5b4439fa
1 #!/bin/sh
2 # shellcheck disable=SC2154
4 # Track changes to enumerated pools for use in early-boot
5 set -ef
7 FSLIST="@sysconfdir@/zfs/zfs-list.cache/${ZEVENT_POOL}"
8 FSLIST_TMP="@runstatedir@/zfs-list.cache@${ZEVENT_POOL}"
10 # If the pool specific cache file is not writeable, abort
11 [ -w "${FSLIST}" ] || exit 0
13 [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
14 . "${ZED_ZEDLET_DIR}/zed-functions.sh"
16 [ "$ZEVENT_SUBCLASS" != "history_event" ] && exit 0
17 zed_check_cmd "${ZFS}" sort diff
19 # If we are acting on a snapshot, we have nothing to do
20 [ "${ZEVENT_HISTORY_DSNAME%@*}" = "${ZEVENT_HISTORY_DSNAME}" ] || exit 0
22 # We lock the output file to avoid simultaneous writes.
23 # If we run into trouble, log and drop the lock
24 abort_alter() {
25 zed_log_msg "Error updating zfs-list.cache for ${ZEVENT_POOL}!"
26 zed_unlock "${FSLIST}"
29 finished() {
30 zed_unlock "${FSLIST}"
31 trap - EXIT
32 exit 0
35 case "${ZEVENT_HISTORY_INTERNAL_NAME}" in
36 create|"finish receiving"|import|destroy|rename)
39 export)
40 zed_lock "${FSLIST}"
41 trap abort_alter EXIT
42 echo > "${FSLIST}"
43 finished
46 set|inherit)
47 # Only act if one of the tracked properties is altered.
48 case "${ZEVENT_HISTORY_INTERNAL_STR%%=*}" in
49 canmount|mountpoint|atime|relatime|devices|exec|readonly| \
50 setuid|nbmand|encroot|keylocation|org.openzfs.systemd:requires| \
51 org.openzfs.systemd:requires-mounts-for| \
52 org.openzfs.systemd:before|org.openzfs.systemd:after| \
53 org.openzfs.systemd:wanted-by|org.openzfs.systemd:required-by| \
54 org.openzfs.systemd:nofail|org.openzfs.systemd:ignore \
55 ) ;;
56 *) exit 0 ;;
57 esac
61 # Ignore all other events.
62 exit 0
64 esac
66 zed_lock "${FSLIST}"
67 trap abort_alter EXIT
69 PROPS="name,mountpoint,canmount,atime,relatime,devices,exec\
70 ,readonly,setuid,nbmand,encroot,keylocation\
71 ,org.openzfs.systemd:requires,org.openzfs.systemd:requires-mounts-for\
72 ,org.openzfs.systemd:before,org.openzfs.systemd:after\
73 ,org.openzfs.systemd:wanted-by,org.openzfs.systemd:required-by\
74 ,org.openzfs.systemd:nofail,org.openzfs.systemd:ignore"
76 "${ZFS}" list -H -t filesystem -o "${PROPS}" -r "${ZEVENT_POOL}" > "${FSLIST_TMP}"
78 # Sort the output so that it is stable
79 sort "${FSLIST_TMP}" -o "${FSLIST_TMP}"
81 # Don't modify the file if it hasn't changed
82 diff -q "${FSLIST_TMP}" "${FSLIST}" || cat "${FSLIST_TMP}" > "${FSLIST}"
83 rm -f "${FSLIST_TMP}"
85 finished