Skip to content
Permalink
Browse files

systemd zvol target

Introduce a zfs-volumes.target, which Requires= zfs-volume@.service
units that are dynamically generated for each zvol by the existing
systemd-generator infrastructure at boot time.

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 Jul 9, 2019
1 parent d230a65 commit 692600b35ffb9965e85082cd329cb4febf291455
@@ -65,6 +65,11 @@ PROPS="name,mountpoint,canmount,atime,relatime,devices,exec,readonly"
PROPS="${PROPS},setuid,nbmand"

"${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}"
@@ -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' \
$< >'$@'

distclean-local::
@@ -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
@@ -72,6 +74,14 @@ process_line() {
p_setuid="${9}"
p_nbmand="${10}"

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
@@ -4,5 +4,6 @@ disable zfs-import-scan.service
enable zfs-import.target
enable zfs-mount.service
enable zfs-share.service
disable zfs-volumes.target
enable zfs-zed.service
enable zfs.target
@@ -8,6 +8,8 @@ systemdunit_DATA = \
zfs-mount.service \
zfs-share.service \
zfs-import.target \
zfs-volume@.service \
zfs-volumes.target \
zfs.target

EXTRA_DIST = \
@@ -16,7 +18,9 @@ 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-volumes.target.in \
$(top_srcdir)/etc/systemd/system/zfs.target.in \
$(top_srcdir)/etc/systemd/system/50-zfs.preset.in

@@ -0,0 +1,9 @@
[Unit]
Description=ZFS zvol %I ready
Before=zfs-volumes.target
DefaultDependencies=no

[Service]
ExecStart=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=true
@@ -0,0 +1,5 @@
[Unit]
Description=All ZFS volumes loaded

[Install]
WantedBy=zfs.target

0 comments on commit 692600b

Please sign in to comment.
You can’t perform that action at this time.