Skip to content

Commit

Permalink
systemd zvol target
Browse files Browse the repository at this point in the history
Modify the recent zfs-volumes.target to Requires= zfs-volume@.service
units that are dynamically generated for each zvol by the existing
systemd-generator infrastructure at boot time.  This is an alternative
to the zfs-volume-wait.service.

Each unit polls once per second, exiting if it detects the zvol link,
succeeding unconditionally after a 30 second timeout.

Signed-off-by: Antonio Russo <antonio.e.russo@gmail.com>
  • Loading branch information
aerusso committed Nov 9, 2019
1 parent 6c7023a commit a667bc3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/zed/zed.d/history_event-zfs-list-cacher.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ PROPS="name,mountpoint,canmount,atime,relatime,devices,exec,readonly"
PROPS="${PROPS},setuid,nbmand,encroot,keylocation"

"${ZFS}" list -H -t filesystem -o $PROPS -r "${ZEVENT_POOL}" > "${FSLIST_TMP}"
"${ZFS}" list -H -t volume -o name -r "${ZEVENT_POOL}" | while read -r name
do
# fake "zvol" mountpoint
printf '%s\tzvol\toff\n' "$name" >> "${FSLIST_TMP}"
done

# Sort the output so that it is stable
sort "${FSLIST_TMP}" -o "${FSLIST_TMP}"
Expand Down
1 change: 1 addition & 0 deletions etc/systemd/system-generators/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $(systemdgenerator_SCRIPTS): %: %.in
-e 's,@runstatedir\@,$(runstatedir),g' \
-e 's,@sbindir\@,$(sbindir),g' \
-e 's,@sysconfdir\@,$(sysconfdir),g' \
-e 's,@systemdunitdir\@,$(systemdunitdir),g' \
$< >'$@'

# Double-colon rules are allowed; there are multiple independent definitions.
Expand Down
10 changes: 10 additions & 0 deletions etc/systemd/system-generators/zfs-mount-generator.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ fi
# avoid regressions, this dependency is reduced to "wants" rather than
# "requires". **THIS MAY CHANGE**
req_dir="${dest_norm}/local-fs.target.wants/"
zvol_reqdir="${dest_norm}/zfs-volumes.target.requires"
mkdir -p "${zvol_reqdir}"
mkdir -p "${req_dir}"

# All needed information about each ZFS is available from
Expand Down Expand Up @@ -74,6 +76,14 @@ process_line() {
p_encroot="${11}"
p_keyloc="${12}"

if [ "${p_mountpoint}" = "zvol" ] ; then
# special case of zvol
unit="zfs-volume@$(systemd-escape "${dataset}").service"
ln -s "@systemdunitdir@/zfs-volume@.service" \
"${zvol_reqdir}/${unit}"
return
fi

# Check for canmount=off .
if [ "${p_canmount}" = "off" ] ; then
return
Expand Down
2 changes: 2 additions & 0 deletions etc/systemd/system/50-zfs.preset.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ disable zfs-import-scan.service
enable zfs-import.target
enable zfs-mount.service
enable zfs-share.service
disable zfs-volumes.target
disable zfs-volume@.service
enable zfs-zed.service
enable zfs-volume-wait.service
enable zfs.target
2 changes: 2 additions & 0 deletions etc/systemd/system/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ systemdunit_DATA = \
zfs-share.service \
zfs-volume-wait.service \
zfs-import.target \
zfs-volume@.service \
zfs-volumes.target \
zfs.target

Expand All @@ -18,6 +19,7 @@ EXTRA_DIST = \
$(top_srcdir)/etc/systemd/system/zfs-import-scan.service.in \
$(top_srcdir)/etc/systemd/system/zfs-mount.service.in \
$(top_srcdir)/etc/systemd/system/zfs-share.service.in \
$(top_srcdir)/etc/systemd/system/zfs-volume@.service.in \
$(top_srcdir)/etc/systemd/system/zfs-import.target.in \
$(top_srcdir)/etc/systemd/system/zfs-volume-wait.service.in \
$(top_srcdir)/etc/systemd/system/zfs-volumes.target.in \
Expand Down
9 changes: 9 additions & 0 deletions etc/systemd/system/zfs-volume@.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=ZFS zvol %I ready
Before=zfs-volumes.target
DefaultDependencies=no

[Service]
ExecStart=/bin/sh -c 'timeout=30 ; while [ $timeout -gt 0 ] ; do [ -e "/dev/zvol/$0" ] && exit 0 ; sleep 1 ; timeout=$((timeout-1)); done ; echo "zvol $0 unavailable"' %I
Type=oneshot
RemainAfterExit=yes

0 comments on commit a667bc3

Please sign in to comment.