Skip to content

Commit

Permalink
sh
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewc12 committed Nov 14, 2023
1 parent 48db5af commit ab32718
Show file tree
Hide file tree
Showing 9 changed files with 661 additions and 1 deletion.
30 changes: 30 additions & 0 deletions cmd/zed/zed.d/snapshot_mount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
# shellcheck disable=SC2154
#
# Helper to mount and unmount snapshots when asked to by kernel.
#
# Mostly used in macOS.
#
set -ef

[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
. "${ZED_ZEDLET_DIR}/zed-functions.sh"

[ -n "${ZEVENT_SNAPSHOT_NAME}" ] || exit 1
[ -n "${ZEVENT_SUBCLASS}" ] || exit 2

if [ "${ZEVENT_SUBCLASS}" = "snapshot_mount" ]; then
action="mount"
elif [ "${ZEVENT_SUBCLASS}" = "snapshot_unmount" ]; then
action="unmount"
else
zed_log_err "unsupported event class \"${ZEVENT_SUBCLASS}\""
exit 3
fi

zed_exit_if_ignoring_this_event
zed_check_cmd "${ZFS}" || exit 4

"${ZFS}" "${action}" "${ZEVENT_SNAPSHOT_NAME}"

finished
1 change: 1 addition & 0 deletions cmd/zed/zed.d/snapshot_unmount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
snapshot_mount.sh
28 changes: 28 additions & 0 deletions cmd/zed/zed.d/zvol_create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
# shellcheck disable=SC2154
#
# Log the zevent via syslog.
#

# Given POOL and DATASET name for ZVOL
# DEVICE_NAME for /dev/disk*
# RAW_DEVICE_NAME for /dev/rdisk*
# Create symlink in
# /var/run/zfs/zvol/dsk/POOL/DATASET -> /dev/disk*
# /var/run/zfs/zvol/rdsk/POOL/DATASET -> /dev/rdisk*

ZVOL_ROOT="/var/run/zfs/zvol"

mkdir -p "$(dirname "${ZVOL_ROOT}/rdsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}")" "$(dirname "${ZVOL_ROOT}/dsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}")"

# Remove them if they already exist. (ln -f is not portable)
rm -f "${ZVOL_ROOT}/rdsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}" "${ZVOL_ROOT}/dsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}"

ln -s "/dev/${ZEVENT_DEVICE_NAME}" "${ZVOL_ROOT}/dsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}"
ln -s "/dev/${ZEVENT_RAW_NAME}" "${ZVOL_ROOT}/rdsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}"

logger -t "${ZED_SYSLOG_TAG:=zed}" -p "${ZED_SYSLOG_PRIORITY:=daemon.notice}" \
eid="${ZEVENT_EID}" class="${ZEVENT_SUBCLASS}" \
"${ZEVENT_POOL:+pool=$ZEVENT_POOL}/${ZEVENT_VOLUME} symlinked ${ZEVENT_DEVICE_NAME}"

echo 0
23 changes: 23 additions & 0 deletions cmd/zed/zed.d/zvol_remove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
# shellcheck disable=SC2154
#
# Log the zevent via syslog.
#

# Given POOL and DATASET name for ZVOL
# DEVICE_NAME for /dev/disk*
# RAW_DEVICE_NAME for /dev/rdisk*
# Create symlink in
# /var/run/zfs/zvol/dsk/POOL/DATASET -> /dev/disk*
# /var/run/zfs/zvol/rdsk/POOL/DATASET -> /dev/rdisk*

ZVOL_ROOT="/var/run/zfs/zvol"

rm -f "${ZVOL_ROOT}/rdsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}" "${ZVOL_ROOT}/dsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}"
rmdir "$(dirname "${ZVOL_ROOT}/rdsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}")" "$(dirname "${ZVOL_ROOT}/dsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}")"

logger -t "${ZED_SYSLOG_TAG:=zed}" -p "${ZED_SYSLOG_PRIORITY:=daemon.notice}" \
eid="${ZEVENT_EID}" class="${ZEVENT_SUBCLASS}" \
"${ZEVENT_POOL:+pool=$ZEVENT_POOL}/${ZEVENT_VOLUME} removed symlink"

echo 0
11 changes: 11 additions & 0 deletions contrib/macOS/product-scripts/poolcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

#exit code 1 means no zfs file systems mounted

echo "Mounted ZFS file system(s) check"
myvar="$(2>/dev/null /usr/bin/lsvfs zfs | /usr/bin/tail -1 | /usr/bin/awk '{print $2}')"
[ ! -z "${myvar##*[!0-9]*}" ] || exit 1
[ $myvar -ne 0 ] && exit 0
sysctl -n kstat.zfs.darwin.ldi.handle_count || exit 1
if [ x"$(sysctl -n kstat.zfs.darwin.ldi.handle_count)" != x"0" ]; then exit 0; fi
exit 1
18 changes: 18 additions & 0 deletions contrib/macOS/product-scripts/zevocheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

#exit code 1 means ZEVO is neither installed nor just uninstalled without reboot

echo "ZEVO files check"
ls /System/Library/Extensions/ZFSDriver.kext/ &>/dev/null && exit 0
ls /System/Library/Extensions/ZFSFilesystem.kext/ &>/dev/null && exit 0
ls /Library/LaunchDaemons/com.getgreenbytes* &>/dev/null && exit 0

echo "ZEVO launchctl check"
/bin/launchctl list | grep greenbytes &>/dev/null
[ $? -eq 0 ] && exit 0

echo "ZEVO kextstat check"
/usr/sbin/kextstat | grep greenbytes &>/dev/null
[ $? -eq 0 ] && exit 0

exit 1
16 changes: 16 additions & 0 deletions scripts/load_macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
#
# Expected to be run from the root of the source tree, as root;
# ./scripts/load_macos.sh
#
# Copies compiled zfs.kext to /tmp/ and prepares the requirements
# for load.
#

rsync -ar module/os/macos/zfs.kext/ /tmp/zfs.kext/

chown -R root:wheel /tmp/zfs.kext

kextload -v /tmp/zfs.kext || kextutil /tmp/zfs.kext

# log stream --source --predicate 'sender == "zfs"' --style compact
Loading

0 comments on commit ab32718

Please sign in to comment.