Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F84263916
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
39 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/etc/Makefile.am b/etc/Makefile.am
index aa9ff182c863..4d2002036102 100644
--- a/etc/Makefile.am
+++ b/etc/Makefile.am
@@ -1,9 +1,10 @@
include $(top_srcdir)/config/Shellcheck.am
SUBDIRS = zfs sudoers.d
-SHELLCHECKDIRS = zfs
+SHELLCHECKDIRS = default $(ZFS_INIT_SYSV) zfs
+SHELLCHECK_OPTS = --enable=all
+
if BUILD_LINUX
-SHELLCHECKDIRS += default $(ZFS_INIT_SYSV)
SUBDIRS += default $(ZFS_INIT_SYSTEMD) $(ZFS_INIT_SYSV) $(ZFS_MODULE_LOAD)
endif
DIST_SUBDIRS = default init.d zfs systemd modules-load.d sudoers.d
diff --git a/etc/default/Makefile.am b/etc/default/Makefile.am
index 0f7c96698d45..74a4edd62873 100644
--- a/etc/default/Makefile.am
+++ b/etc/default/Makefile.am
@@ -1,8 +1,9 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am
initconf_SCRIPTS = zfs
SUBSTFILES += $(initconf_SCRIPTS)
-SHELLCHECK_SHELL = sh
+SHELLCHECK_SHELL = dash
+SHELLCHECK_OPTS = --enable=all
diff --git a/etc/default/zfs.in b/etc/default/zfs.in
index fb4a1b65e348..ae813e9de9dd 100644
--- a/etc/default/zfs.in
+++ b/etc/default/zfs.in
@@ -1,110 +1,111 @@
# OpenZFS userland configuration.
+# shellcheck disable=SC2154
# NOTE: This file is intended for sysv init and initramfs.
# Changing some of these settings may not make any difference on
# systemd-based setup, e.g. setting ZFS_MOUNT=no will not prevent systemd
# from launching zfs-mount.service during boot.
# See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=901436
# To enable a boolean setting, set it to yes, on, true, or 1.
# Anything else will be interpreted as unset.
# shellcheck disable=SC2034
# Run `zfs load-key` during system start?
ZFS_LOAD_KEY='yes'
# Run `zfs unload-key` during system stop?
ZFS_UNLOAD_KEY='no'
# Run `zfs mount -a` during system start?
ZFS_MOUNT='yes'
# Run `zfs unmount -a` during system stop?
ZFS_UNMOUNT='yes'
# Run `zfs share -a` during system start?
# nb: The shareiscsi, sharenfs, and sharesmb dataset properties.
ZFS_SHARE='yes'
# Run `zfs unshare -a` during system stop?
ZFS_UNSHARE='yes'
# By default, a verbatim import of all pools is performed at boot based on the
# contents of the default zpool cache file. The contents of the cache are
# managed automatically by the 'zpool import' and 'zpool export' commands.
#
# By setting this to 'yes', the system will instead search all devices for
# pools and attempt to import them all at boot, even those that have been
# exported. Under this mode, the search path can be controlled by the
# ZPOOL_IMPORT_PATH variable and a list of pools that should not be imported
# can be listed in the ZFS_POOL_EXCEPTIONS variable.
#
# Note that importing all visible pools may include pools that you don't
# expect, such as those on removable devices and SANs, and those pools may
# proceed to mount themselves in places you do not want them to. The results
# can be unpredictable and possibly dangerous. Only enable this option if you
# understand this risk and have complete physical control over your system and
# SAN to prevent the insertion of malicious pools.
ZPOOL_IMPORT_ALL_VISIBLE='no'
# Specify specific path(s) to look for device nodes and/or links for the
# pool import(s). See zpool(8) for more information about this variable.
# It supersedes the old USE_DISK_BY_ID which indicated that it would only
# try '/dev/disk/by-id'.
# The old variable will still work in the code, but is deprecated.
#ZPOOL_IMPORT_PATH="/dev/disk/by-vdev:/dev/disk/by-id"
# List of pools that should NOT be imported at boot
# when ZPOOL_IMPORT_ALL_VISIBLE is 'yes'.
# This is a space separated list.
#ZFS_POOL_EXCEPTIONS="test2"
# Should the datasets be mounted verbosely?
# A mount counter will be used when mounting if set to 'yes'.
VERBOSE_MOUNT='no'
# Should we allow overlay mounts?
# This is standard in Linux, but not ZFS which comes from Solaris where this
# is not allowed).
DO_OVERLAY_MOUNTS='no'
# Any additional option to the 'zfs import' commandline?
# Include '-o' for each option wanted.
# You don't need to put '-f' in here, unless you want it ALL the time.
# Using the option 'zfsforce=1' on the grub/kernel command line will
# do the same, but on a case-to-case basis.
ZPOOL_IMPORT_OPTS=""
# Full path to the ZFS cache file?
# See "cachefile" in zpool(8).
# The default is "@sysconfdir@/zfs/zpool.cache".
#ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"
#
# Setting ZPOOL_CACHE to an empty string ('') AND setting ZPOOL_IMPORT_OPTS to
# "-c @sysconfdir@/zfs/zpool.cache" will _enforce_ the use of a cache file.
# This is needed in some cases (extreme amounts of VDEVs, multipath etc).
# Generally, the use of a cache file is usually not recommended on Linux
# because it sometimes is more trouble than it's worth (laptops with external
# devices or when/if device nodes changes names).
#ZPOOL_IMPORT_OPTS="-c @sysconfdir@/zfs/zpool.cache"
#ZPOOL_CACHE=""
# Any additional option to the 'zfs mount' command line?
# Include '-o' for each option wanted.
MOUNT_EXTRA_OPTIONS=""
# Build kernel modules with the --enable-debug switch?
# Only applicable for Debian GNU/Linux {dkms,initramfs}.
ZFS_DKMS_ENABLE_DEBUG='no'
# Build kernel modules with the --enable-debuginfo switch?
# Only applicable for Debian GNU/Linux {dkms,initramfs}.
ZFS_DKMS_ENABLE_DEBUGINFO='no'
# Keep debugging symbols in kernel modules?
# Only applicable for Debian GNU/Linux {dkms,initramfs}.
ZFS_DKMS_DISABLE_STRIP='no'
# Optional arguments for the ZFS Event Daemon (ZED).
# See zed(8) for more information on available options.
#ZED_ARGS="-M"
diff --git a/etc/init.d/Makefile.am b/etc/init.d/Makefile.am
index 658623fda4aa..c336d607551d 100644
--- a/etc/init.d/Makefile.am
+++ b/etc/init.d/Makefile.am
@@ -1,10 +1,11 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am
EXTRA_DIST += README.md
init_SCRIPTS = zfs-import zfs-load-key zfs-mount zfs-share zfs-zed
SUBSTFILES += $(init_SCRIPTS)
-SHELLCHECK_SHELL = dash # local variables
+SHELLCHECK_SHELL = dash
+SHELLCHECK_OPTS = --enable=all
diff --git a/etc/init.d/zfs-import.in b/etc/init.d/zfs-import.in
index 130174f74d06..a9a0604f81ac 100755
--- a/etc/init.d/zfs-import.in
+++ b/etc/init.d/zfs-import.in
@@ -1,337 +1,338 @@
#!@DEFAULT_INIT_SHELL@
+# shellcheck disable=SC2154
#
# zfs-import This script will import ZFS pools
#
# chkconfig: 2345 01 99
# description: This script will perform a verbatim import of ZFS pools
# during system boot.
# probe: true
#
### BEGIN INIT INFO
# Provides: zfs-import
# Required-Start: mtab
# Required-Stop: $local_fs mtab
# Default-Start: S
# Default-Stop: 0 1 6
# X-Start-Before: checkfs
# X-Stop-After: zfs-mount
# Short-Description: Import ZFS pools
# Description: Run the `zpool import` command.
### END INIT INFO
#
# NOTE: Not having '$local_fs' on Required-Start but only on Required-Stop
# is on purpose. If we have '$local_fs' in both (and X-Start-Before=checkfs)
# we get conflicts - import needs to be started extremely early,
# but not stopped too late.
#
# Released under the 2-clause BSD license.
#
# This script is based on debian/zfsutils.zfs.init from the
# Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
# Source the common init script
. @sysconfdir@/zfs/zfs-functions
# ----------------------------------------------------
do_depend()
{
before swap
after sysfs udev
keyword -lxc -openvz -prefix -vserver
}
# Use the zpool cache file to import pools
do_verbatim_import()
{
if [ -f "$ZPOOL_CACHE" ]
then
zfs_action "Importing ZFS pool(s)" \
"$ZPOOL" import -c "$ZPOOL_CACHE" -N -a
fi
}
# Support function to get a list of all pools, separated with ';'
find_pools()
{
local pools
pools=$("$@" 2> /dev/null | \
sed -Ee '/pool:|^[a-zA-Z0-9]/!d' -e 's@.*: @@' | \
sort | \
tr '\n' ';')
echo "${pools%%;}" # Return without the last ';'.
}
# Find and import all visible pools, even exported ones
do_import_all_visible()
{
local already_imported available_pools pool npools
local exception dir ZPOOL_IMPORT_PATH RET=0 r=1
# In case not shutdown cleanly.
# shellcheck disable=SC2154
[ -n "$init" ] && rm -f /etc/dfs/sharetab
# Just simplify code later on.
if [ -n "$USE_DISK_BY_ID" ] && [ "$USE_DISK_BY_ID" != 'yes' ]
then
# It's something, but not 'yes' so it's no good to us.
unset USE_DISK_BY_ID
fi
# Find list of already imported pools.
already_imported=$(find_pools "$ZPOOL" list -H -oname)
available_pools=$(find_pools "$ZPOOL" import)
# Just in case - seen it happen (that a pool isn't visible/found
# with a simple "zpool import" but only when using the "-d"
# option or setting ZPOOL_IMPORT_PATH).
if [ -d "/dev/disk/by-id" ]
then
npools=$(find_pools "$ZPOOL" import -d /dev/disk/by-id)
if [ -n "$npools" ]
then
# Because we have found extra pool(s) here, which wasn't
# found 'normally', we need to force USE_DISK_BY_ID to
# make sure we're able to actually import it/them later.
USE_DISK_BY_ID='yes'
if [ -n "$available_pools" ]
then
# Filter out duplicates (pools found with the simpl
# "zpool import" but which is also found with the
# "zpool import -d ...").
npools=$(echo "$npools" | sed "s,$available_pools,,")
# Add the list to the existing list of
# available pools
available_pools="$available_pools;$npools"
else
available_pools="$npools"
fi
fi
fi
# Filter out any exceptions...
if [ -n "$ZFS_POOL_EXCEPTIONS" ]
then
local found=""
local apools=""
OLD_IFS="$IFS" ; IFS=";"
for pool in $available_pools
do
for exception in $ZFS_POOL_EXCEPTIONS
do
[ "$pool" = "$exception" ] && continue 2
found="$pool"
done
if [ -n "$found" ]
then
if [ -n "$apools" ]
then
apools="$apools;$pool"
else
apools="$pool"
fi
fi
done
IFS="$OLD_IFS"
available_pools="$apools"
fi
# For backwards compatibility, make sure that ZPOOL_IMPORT_PATH is set
# to something we can use later with the real import(s). We want to
# make sure we find all by* dirs, BUT by-vdev should be first (if it
# exists).
if [ -n "$USE_DISK_BY_ID" ] && [ -z "$ZPOOL_IMPORT_PATH" ]
then
local dirs
dirs="$(for dir in $(echo /dev/disk/by-*)
do
# Ignore by-vdev here - we want it first!
echo "$dir" | grep -q /by-vdev && continue
[ ! -d "$dir" ] && continue
printf "%s" "$dir:"
done | sed 's,:$,,g')"
if [ -d "/dev/disk/by-vdev" ]
then
# Add by-vdev at the beginning.
ZPOOL_IMPORT_PATH="/dev/disk/by-vdev:"
fi
# Help with getting LUKS partitions etc imported.
if [ -d "/dev/mapper" ]; then
if [ -n "$ZPOOL_IMPORT_PATH" ]; then
ZPOOL_IMPORT_PATH="$ZPOOL_IMPORT_PATH:/dev/mapper:"
else
ZPOOL_IMPORT_PATH="/dev/mapper:"
fi
fi
# ... and /dev at the very end, just for good measure.
ZPOOL_IMPORT_PATH="$ZPOOL_IMPORT_PATH$dirs:/dev"
fi
# Needs to be exported for "zpool" to catch it.
[ -n "$ZPOOL_IMPORT_PATH" ] && export ZPOOL_IMPORT_PATH
# Mount all available pools (except those set in ZFS_POOL_EXCEPTIONS.
#
# If not interactive (run from init - variable init='/sbin/init')
# we get ONE line for all pools being imported, with just a dot
# as status for each pool.
# Example: Importing ZFS pool(s)... [OK]
#
# If it IS interactive (started from the shell manually), then we
# get one line per pool importing.
# Example: Importing ZFS pool pool1 [OK]
# Importing ZFS pool pool2 [OK]
# [etc]
[ -n "$init" ] && zfs_log_begin_msg "Importing ZFS pool(s)"
OLD_IFS="$IFS" ; IFS=";"
for pool in $available_pools
do
[ -z "$pool" ] && continue
# We have pools that haven't been imported - import them
if [ -n "$init" ]
then
# Not interactive - a dot for each pool.
# Except on Gentoo where this doesn't work.
zfs_log_progress_msg "."
else
# Interactive - one 'Importing ...' line per pool
zfs_log_begin_msg "Importing ZFS pool $pool"
fi
# Import by using ZPOOL_IMPORT_PATH (either set above or in
# the config file) _or_ with the 'built in' default search
# paths. This is the preferred way.
# shellcheck disable=SC2086
"$ZPOOL" import -N ${ZPOOL_IMPORT_OPTS} "$pool" 2> /dev/null
r="$?" ; RET=$((RET + r))
if [ "$r" -eq 0 ]
then
# Output success and process the next pool
[ -z "$init" ] && zfs_log_end_msg 0
continue
fi
# We don't want a fail msg here, we're going to try import
# using the cache file soon and that might succeed.
[ ! -f "$ZPOOL_CACHE" ] && zfs_log_end_msg "$RET"
if [ "$r" -gt 0 ] && [ -f "$ZPOOL_CACHE" ]
then
# Failed to import without a cache file. Try WITH...
if [ -z "$init" ] && check_boolean "$VERBOSE_MOUNT"
then
# Interactive + Verbose = more information
zfs_log_progress_msg " using cache file"
fi
# shellcheck disable=SC2086
"$ZPOOL" import -c "$ZPOOL_CACHE" -N ${ZPOOL_IMPORT_OPTS} \
"$pool" 2> /dev/null
r="$?" ; RET=$((RET + r))
if [ "$r" -eq 0 ]
then
[ -z "$init" ] && zfs_log_end_msg 0
continue 3 # Next pool
fi
zfs_log_end_msg "$RET"
fi
done
[ -n "$init" ] && zfs_log_end_msg "$RET"
IFS="$OLD_IFS"
[ -n "$already_imported" ] && [ -z "$available_pools" ] && return 0
return "$RET"
}
do_import()
{
if check_boolean "$ZPOOL_IMPORT_ALL_VISIBLE"
then
do_import_all_visible
else
# This is the default option
do_verbatim_import
fi
}
# Output the status and list of pools
do_status()
{
check_module_loaded "zfs" || exit 0
"$ZPOOL" status && echo "" && "$ZPOOL" list
}
do_start()
{
if check_boolean "$VERBOSE_MOUNT"
then
zfs_log_begin_msg "Checking if ZFS userspace tools present"
fi
if checksystem
then
check_boolean "$VERBOSE_MOUNT" && zfs_log_end_msg 0
check_boolean "$VERBOSE_MOUNT" && \
zfs_log_begin_msg "Loading kernel ZFS infrastructure"
if ! load_module "zfs"
then
check_boolean "$VERBOSE_MOUNT" && zfs_log_end_msg 1
return 5
fi
check_boolean "$VERBOSE_MOUNT" && zfs_log_end_msg 0
do_import && udev_trigger # just to make sure we get zvols.
return 0
else
return 1
fi
}
# ----------------------------------------------------
if [ ! -e /sbin/openrc-run ]
then
case "$1" in
start)
do_start
;;
stop)
# no-op
;;
status)
do_status
;;
force-reload|condrestart|reload|restart)
# no-op
;;
*)
[ -n "$1" ] && echo "Error: Unknown command $1."
echo "Usage: $0 {start|status}"
exit 3
;;
esac
exit $?
else
# Create wrapper functions since Gentoo don't use the case part.
depend() { do_depend; }
start() { do_start; }
status() { do_status; }
fi
diff --git a/etc/init.d/zfs-load-key.in b/etc/init.d/zfs-load-key.in
index 2f8deffdc809..53c7766b793a 100755
--- a/etc/init.d/zfs-load-key.in
+++ b/etc/init.d/zfs-load-key.in
@@ -1,131 +1,132 @@
#!@DEFAULT_INIT_SHELL@
+# shellcheck disable=SC2154
#
# zfs-load-key This script will load/unload the zfs filesystems keys.
#
# chkconfig: 2345 06 99
# description: This script will load or unload the zfs filesystems keys during
# system boot/shutdown. Only filesystems with key path set
# in keylocation property. See the zfs(8) man page for details.
# probe: true
#
### BEGIN INIT INFO
# Provides: zfs-load-key
# Required-Start: $local_fs zfs-import
# Required-Stop: $local_fs zfs-import
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Start-Before: zfs-mount
# X-Stop-After: zfs-zed
# Short-Description: Load ZFS keys for filesystems and volumes
# Description: Run the `zfs load-key` or `zfs unload-key` commands.
### END INIT INFO
#
# Released under the 2-clause BSD license.
#
# This script is based on debian/zfsutils.zfs.init from the
# Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
# Source the common init script
. @sysconfdir@/zfs/zfs-functions
# ----------------------------------------------------
do_depend()
{
# bootmisc will log to /var which may be a different zfs than root.
before bootmisc logger zfs-mount
after zfs-import sysfs
keyword -lxc -openvz -prefix -vserver
}
# Load keys for all datasets/filesystems
do_load_keys()
{
zfs_log_begin_msg "Load ZFS filesystem(s) keys"
"$ZFS" list -Ho name,encryptionroot,keystatus,keylocation |
while IFS=" " read -r name encryptionroot keystatus keylocation; do
if [ "$encryptionroot" != "-" ] &&
[ "$name" = "$encryptionroot" ] &&
[ "$keystatus" = "unavailable" ] &&
[ "$keylocation" != "prompt" ] &&
[ "$keylocation" != "none" ]
then
zfs_action "Load key for $encryptionroot" \
"$ZFS" load-key "$encryptionroot"
fi
done
zfs_log_end_msg 0
return 0
}
# Unload keys for all datasets/filesystems
do_unload_keys()
{
zfs_log_begin_msg "Unload ZFS filesystem(s) key"
"$ZFS" list -Ho name,encryptionroot,keystatus | sed '1!G;h;$!d' |
while IFS=" " read -r name encryptionroot keystatus; do
if [ "$encryptionroot" != "-" ] &&
[ "$name" = "$encryptionroot" ] &&
[ "$keystatus" = "available" ]
then
zfs_action "Unload key for $encryptionroot" \
"$ZFS" unload-key "$encryptionroot"
fi
done
zfs_log_end_msg 0
return 0
}
do_start()
{
check_boolean "$ZFS_LOAD_KEY" || exit 0
check_module_loaded "zfs" || exit 0
do_load_keys
}
do_stop()
{
check_boolean "$ZFS_UNLOAD_KEY" || exit 0
check_module_loaded "zfs" || exit 0
do_unload_keys
}
# ----------------------------------------------------
if [ ! -e /sbin/openrc-run ]
then
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
force-reload|condrestart|reload|restart|status)
# no-op
;;
*)
[ -n "$1" ] && echo "Error: Unknown command $1."
echo "Usage: $0 {start|stop}"
exit 3
;;
esac
exit $?
else
# Create wrapper functions since Gentoo don't use the case part.
depend() { do_depend; }
start() { do_start; }
stop() { do_stop; }
fi
diff --git a/etc/init.d/zfs-mount.in b/etc/init.d/zfs-mount.in
index 000619b6717c..d196d1555a45 100755
--- a/etc/init.d/zfs-mount.in
+++ b/etc/init.d/zfs-mount.in
@@ -1,224 +1,225 @@
#!@DEFAULT_INIT_SHELL@
+# shellcheck disable=SC2154
#
# zfs-mount This script will mount/umount the zfs filesystems.
#
# chkconfig: 2345 06 99
# description: This script will mount/umount the zfs filesystems during
# system boot/shutdown. Configuration of which filesystems
# should be mounted is handled by the zfs 'mountpoint' and
# 'canmount' properties. See the zfs(8) man page for details.
# It is also responsible for all userspace zfs services.
# probe: true
#
### BEGIN INIT INFO
# Provides: zfs-mount
# Required-Start: $local_fs zfs-import
# Required-Stop: $local_fs zfs-import
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Stop-After: zfs-zed
# Short-Description: Mount ZFS filesystems and volumes
# Description: Run the `zfs mount -a` or `zfs umount -a` commands.
### END INIT INFO
#
# Released under the 2-clause BSD license.
#
# This script is based on debian/zfsutils.zfs.init from the
# Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
# Source the common init script
. @sysconfdir@/zfs/zfs-functions
# ----------------------------------------------------
chkroot() {
while read -r _ mp _; do
if [ "$mp" = "/" ]; then
return 0
fi
done < /proc/self/mounts
return 1
}
do_depend()
{
# Try to allow people to mix and match fstab with ZFS in a way that makes sense.
if [ "$(mountinfo -s /)" = 'zfs' ]
then
before localmount
else
after localmount
fi
# bootmisc will log to /var which may be a different zfs than root.
before bootmisc logger
after zfs-import sysfs
use mtab
keyword -lxc -openvz -prefix -vserver
}
# Mount all datasets/filesystems
do_mount()
{
local verbose overlay i mntpt
check_boolean "$VERBOSE_MOUNT" && verbose=v
check_boolean "$DO_OVERLAY_MOUNTS" && overlay=O
zfs_action "Mounting ZFS filesystem(s)" \
- "$ZFS" mount -a$verbose$overlay "$MOUNT_EXTRA_OPTIONS"
+ "$ZFS" mount "-a$verbose$overlay" "$MOUNT_EXTRA_OPTIONS"
# Require each volume/filesystem to have 'noauto' and no fsck
# option. This shouldn't really be necessary, as long as one
# can get zfs-import to run sufficiently early on in the boot
# process - before local mounts. This is just here in case/if
# this isn't possible.
check_boolean "$VERBOSE_MOUNT" && \
zfs_log_begin_msg "Mounting volumes and filesystems registered in fstab"
read_mtab "^/dev/(zd|zvol)"
read_fstab "^/dev/(zd|zvol)"
i=0; var="FSTAB_0"
while [ -n "$(eval echo "\$$var")" ]
do
mntpt=$(eval echo "\$$var")
dev=$(eval echo "\$FSTAB_dev_$i")
if ! in_mtab "$mntpt" && ! is_mounted "$mntpt" && [ -e "$dev" ]
then
check_boolean "$VERBOSE_MOUNT" && \
zfs_log_progress_msg "$mntpt "
fsck "$dev" && mount "$mntpt"
fi
i=$((i + 1))
var=$(eval echo "FSTAB_$i")
done
read_mtab "[[:space:]]zfs[[:space:]]"
read_fstab "[[:space:]]zfs[[:space:]]"
i=0; var=$(eval echo "FSTAB_$i")
while [ -n "$(eval echo "\$$var")" ]
do
mntpt=$(eval echo "\$$var")
if ! in_mtab "$mntpt" && ! is_mounted "$mntpt"
then
check_boolean "$VERBOSE_MOUNT" && \
zfs_log_progress_msg "$mntpt "
mount "$mntpt"
fi
i=$((i + 1))
var=$(eval echo "FSTAB_$i")
done
check_boolean "$VERBOSE_MOUNT" && zfs_log_end_msg 0
return 0
}
# Unmount all filesystems
do_unmount()
{
local i var mntpt
# This shouldn't really be necessary, as long as one can get
# zfs-import to run sufficiently late in the shutdown/reboot process
# - after unmounting local filesystems. This is just here in case/if
# this isn't possible.
zfs_action "Unmounting ZFS filesystems" "$ZFS" unmount -a
check_boolean "$VERBOSE_MOUNT" && \
zfs_log_begin_msg "Unmounting volumes and filesystems registered in fstab"
read_mtab "^/dev/(zd|zvol)"
read_fstab "^/dev/(zd|zvol)"
i=0; var="FSTAB_0"
while [ -n "$(eval echo "\$$var")" ]
do
mntpt=$(eval echo "\$$var")
dev=$(eval echo "\$FSTAB_dev_$i")
if in_mtab "$mntpt"
then
check_boolean "$VERBOSE_MOUNT" && \
zfs_log_progress_msg "$mntpt "
umount "$mntpt"
fi
i=$((i + 1))
var=$(eval echo "FSTAB_$i")
done
read_mtab "[[:space:]]zfs[[:space:]]"
read_fstab "[[:space:]]zfs[[:space:]]"
i=0; var="FSTAB_0"
while [ -n "$(eval echo "\$$var")" ]
do
mntpt=$(eval echo "\$$var")
if in_mtab "$mntpt"; then
check_boolean "$VERBOSE_MOUNT" && \
zfs_log_progress_msg "$mntpt "
umount "$mntpt"
fi
i=$((i + 1))
var=$(eval echo "FSTAB_$i")
done
check_boolean "$VERBOSE_MOUNT" && zfs_log_end_msg 0
return 0
}
do_start()
{
check_boolean "$ZFS_MOUNT" || exit 0
check_module_loaded "zfs" || exit 0
# Ensure / exists in /proc/self/mounts.
# This should be handled by rc.sysinit but lets be paranoid.
if ! chkroot
then
mount -f /
fi
do_mount
}
do_stop()
{
check_boolean "$ZFS_UNMOUNT" || exit 0
check_module_loaded "zfs" || exit 0
do_unmount
}
# ----------------------------------------------------
if [ ! -e /sbin/openrc-run ]
then
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
force-reload|condrestart|reload|restart|status)
# no-op
;;
*)
[ -n "$1" ] && echo "Error: Unknown command $1."
echo "Usage: $0 {start|stop}"
exit 3
;;
esac
exit $?
else
# Create wrapper functions since Gentoo don't use the case part.
depend() { do_depend; }
start() { do_start; }
stop() { do_stop; }
fi
diff --git a/etc/init.d/zfs-share.in b/etc/init.d/zfs-share.in
index ef628fe46363..88978071cbf6 100755
--- a/etc/init.d/zfs-share.in
+++ b/etc/init.d/zfs-share.in
@@ -1,83 +1,84 @@
#!@DEFAULT_INIT_SHELL@
+# shellcheck disable=SC2154
#
# zfs-share This script will network share zfs filesystems and volumes.
#
# chkconfig: 2345 30 99
# description: Run the `zfs share -a` or `zfs unshare -a` commands
# for controlling iSCSI, NFS, or CIFS network shares.
# probe: true
#
### BEGIN INIT INFO
# Provides: zfs-share
# Required-Start: $local_fs $network $remote_fs zfs-mount
# Required-Stop: $local_fs $network $remote_fs zfs-mount
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start: iscsi iscsitarget istgt scst @DEFAULT_INIT_NFS_SERVER@ samba samba4 zfs-mount zfs-zed
# Should-Stop: iscsi iscsitarget istgt scst @DEFAULT_INIT_NFS_SERVER@ samba samba4 zfs-mount zfs-zed
# Short-Description: Network share ZFS datasets and volumes.
# Description: Run the `zfs share -a` or `zfs unshare -a` commands
# for controlling iSCSI, NFS, or CIFS network shares.
### END INIT INFO
#
# Released under the 2-clause BSD license.
#
# This script is based on debian/zfsutils.zfs.init from the
# Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
# Source the common init script
. @sysconfdir@/zfs/zfs-functions
# ----------------------------------------------------
do_depend()
{
after sysfs zfs-mount zfs-zed
keyword -lxc -openvz -prefix -vserver
}
do_start()
{
check_boolean "$ZFS_SHARE" || exit 0
check_module_loaded "zfs" || exit 0
zfs_action "Sharing ZFS filesystems" "$ZFS" share -a
}
do_stop()
{
check_boolean "$ZFS_UNSHARE" || exit 0
check_module_loaded "zfs" || exit 0
zfs_action "Unsharing ZFS filesystems" "$ZFS" unshare -a
}
# ----------------------------------------------------
if [ ! -e /sbin/openrc-run ]; then
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
force-reload|reload|restart|status)
# no-op
;;
*)
[ -n "$1" ] && echo "Error: Unknown command $1."
echo "Usage: $0 {start|stop}"
exit 3
;;
esac
exit $?
else
# Create wrapper functions since Gentoo don't use the case part.
depend() { do_depend; }
start() { do_start; }
stop() { do_stop; }
fi
diff --git a/etc/init.d/zfs-zed.in b/etc/init.d/zfs-zed.in
index e5256cbc6280..47f742259b27 100755
--- a/etc/init.d/zfs-zed.in
+++ b/etc/init.d/zfs-zed.in
@@ -1,129 +1,130 @@
#!@DEFAULT_INIT_SHELL@
+# shellcheck disable=SC2154
#
# zfs-zed
#
# chkconfig: 2345 29 99
# description: This script will start and stop the ZFS Event Daemon.
# probe: true
#
### BEGIN INIT INFO
# Provides: zfs-zed
# Required-Start: zfs-mount
# Required-Stop: zfs-mount
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Stop-After: zfs-share
# Short-Description: ZFS Event Daemon
# Description: zed monitors ZFS events. When a zevent is posted, zed
# will run any scripts that have been enabled for the
# corresponding zevent class.
### END INIT INFO
#
# Released under the 2-clause BSD license.
#
# This script is based on debian/zfsutils.zfs.init from the
# Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
# Source the common init script
. @sysconfdir@/zfs/zfs-functions
ZED_NAME="zed"
ZED_PIDFILE="@runstatedir@/$ZED_NAME.pid"
# shellcheck disable=SC2034
extra_started_commands="reload"
# Exit if the package is not installed
[ -x "$ZED" ] || exit 0
# ----------------------------------------------------
do_depend()
{
after zfs-mount localmount
}
do_start()
{
check_module_loaded "zfs" || exit 0
ZED_ARGS="$ZED_ARGS -p $ZED_PIDFILE"
zfs_action "Starting ZFS Event Daemon" zfs_daemon_start \
"$ZED_PIDFILE" "$ZED" "$ZED_ARGS"
return "$?"
}
do_stop()
{
local pools
check_module_loaded "zfs" || exit 0
zfs_action "Stopping ZFS Event Daemon" zfs_daemon_stop \
"$ZED_PIDFILE" "$ZED" "$ZED_NAME" || return "$?"
# Let's see if we have any pools imported
pools=$("$ZPOOL" list -H -oname)
if [ -z "$pools" ]
then
# No pools imported, it is/should be safe/possible to
# unload modules.
zfs_action "Unloading modules" rmmod zfs zunicode \
zavl zcommon znvpair zlua spl
return "$?"
fi
}
do_status()
{
check_module_loaded "zfs" || exit 0
zfs_daemon_status "$ZED_PIDFILE" "$ZED" "$ZED_NAME"
return "$?"
}
do_reload()
{
check_module_loaded "zfs" || exit 0
zfs_action "Reloading ZFS Event Daemon" zfs_daemon_reload \
"$ZED_PIDFILE" "$ZED_NAME"
return "$?"
}
# ----------------------------------------------------
if [ ! -e /sbin/openrc-run ]; then
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
status)
do_status
;;
reload|force-reload)
do_reload
;;
restart)
do_stop
do_start
;;
*)
[ -n "$1" ] && echo "Error: Unknown command $1."
echo "Usage: $0 {start|stop|status|reload|restart}"
exit 1
;;
esac
exit $?
else
# Create wrapper functions since Gentoo don't use the case part.
depend() { do_depend; }
start() { do_start; }
stop() { do_stop; }
status() { do_status; }
reload() { do_reload; }
fi
diff --git a/etc/zfs/Makefile.am b/etc/zfs/Makefile.am
index 3dee81c75860..b7dbd33ccf49 100644
--- a/etc/zfs/Makefile.am
+++ b/etc/zfs/Makefile.am
@@ -1,18 +1,19 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am
pkgsysconfdir = $(sysconfdir)/zfs
dist_pkgsysconf_DATA = \
vdev_id.conf.alias.example \
vdev_id.conf.sas_direct.example \
vdev_id.conf.sas_switch.example \
vdev_id.conf.multipath.example \
vdev_id.conf.scsi.example
pkgsysconf_SCRIPTS = \
zfs-functions
SUBSTFILES += $(pkgsysconf_SCRIPTS)
-SHELLCHECK_SHELL = dash # local variables
+SHELLCHECK_OPTS = --enable=all
+SHELLCHECK_SHELL = dash
diff --git a/etc/zfs/zfs-functions.in b/etc/zfs/zfs-functions.in
index 30441dc35d4b..2ff1a186188f 100644
--- a/etc/zfs/zfs-functions.in
+++ b/etc/zfs/zfs-functions.in
@@ -1,432 +1,433 @@
# This is a script with common functions etc used by zfs-import, zfs-load-key,
# zfs-mount, zfs-share and zfs-zed.
#
# It is _NOT_ to be called independently
#
# Released under the 2-clause BSD license.
#
# This script is based on debian/zfsutils.zfs.init from the
# Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
PATH=/sbin:/bin:/usr/bin:/usr/sbin
# Source function library
if [ -f /etc/rc.d/init.d/functions ]; then
# RedHat and derivatives
. /etc/rc.d/init.d/functions
elif [ -L /etc/init.d/functions.sh ]; then
# Gentoo
. /etc/init.d/functions.sh
elif [ -f /lib/lsb/init-functions ]; then
# LSB, Debian, and derivatives
. /lib/lsb/init-functions
fi
# Of course the functions we need are called differently
# on different distributions - it would be way too easy
# otherwise!!
if type log_failure_msg > /dev/null 2>&1 ; then
# LSB functions - fall through
zfs_log_begin_msg() { log_begin_msg "$1"; }
zfs_log_end_msg() { log_end_msg "$1"; }
zfs_log_failure_msg() { log_failure_msg "$1"; }
zfs_log_progress_msg() { log_progress_msg "$1"; }
elif type success > /dev/null 2>&1 ; then
# Fedora/RedHat functions
zfs_set_ifs() {
# For some reason, the init function library have a problem
# with a changed IFS, so this function goes around that.
local tIFS="$1"
if [ -n "$tIFS" ]
then
TMP_IFS="$IFS"
IFS="$tIFS"
fi
}
zfs_log_begin_msg() { printf "%s" "$1 "; }
zfs_log_end_msg() {
+ # shellcheck disable=SC2154
zfs_set_ifs "$OLD_IFS"
if [ "$1" -eq 0 ]; then
success
else
failure
fi
echo
zfs_set_ifs "$TMP_IFS"
}
zfs_log_failure_msg() {
zfs_set_ifs "$OLD_IFS"
failure
echo
zfs_set_ifs "$TMP_IFS"
}
zfs_log_progress_msg() { printf "%s" "$""$1"; }
elif type einfo > /dev/null 2>&1 ; then
# Gentoo functions
zfs_log_begin_msg() { ebegin "$1"; }
zfs_log_end_msg() { eend "$1"; }
zfs_log_failure_msg() { eend "$1"; }
# zfs_log_progress_msg() { printf "%s" "$1"; }
zfs_log_progress_msg() { :; }
else
# Unknown - simple substitutes.
zfs_log_begin_msg() { printf "%s" "$1"; }
zfs_log_end_msg() {
ret=$1
if [ "$ret" -ge 1 ]; then
echo " failed!"
else
echo " success"
fi
return "$ret"
}
zfs_log_failure_msg() { echo "$1"; }
zfs_log_progress_msg() { printf "%s" "$1"; }
fi
# Paths to what we need
ZFS="@sbindir@/zfs"
ZED="@sbindir@/zed"
ZPOOL="@sbindir@/zpool"
ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"
# Sensible defaults
ZFS_LOAD_KEY='yes'
ZFS_UNLOAD_KEY='no'
ZFS_MOUNT='yes'
ZFS_UNMOUNT='yes'
ZFS_SHARE='yes'
ZFS_UNSHARE='yes'
# Source zfs configuration, overriding the defaults
if [ -f @initconfdir@/zfs ]; then
. @initconfdir@/zfs
fi
# ----------------------------------------------------
export ZFS ZED ZPOOL ZPOOL_CACHE ZFS_LOAD_KEY ZFS_UNLOAD_KEY ZFS_MOUNT ZFS_UNMOUNT \
ZFS_SHARE ZFS_UNSHARE
zfs_action()
{
local MSG="$1"; shift
local CMD="$*"
local ret
zfs_log_begin_msg "$MSG "
$CMD
ret=$?
if [ "$ret" -eq 0 ]; then
- zfs_log_end_msg $ret
+ zfs_log_end_msg "$ret"
else
- zfs_log_failure_msg $ret
+ zfs_log_failure_msg "$ret"
fi
- return $ret
+ return "$ret"
}
# Returns
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
# 3 if unsupported
#
zfs_daemon_start()
{
local PIDFILE="$1"; shift
local DAEMON_BIN="$1"; shift
if type start-stop-daemon > /dev/null 2>&1 ; then
# LSB functions
start-stop-daemon --start --quiet --pidfile "$PIDFILE" \
--exec "$DAEMON_BIN" --test > /dev/null || return 1
# shellcheck disable=SC2086
start-stop-daemon --start --quiet --exec "$DAEMON_BIN" -- \
"$@" || return 2
# On Debian, there's a 'sendsigs' script that will
# kill basically everything quite early and zed is stopped
# much later than that. We don't want zed to be among them,
# so add the zed pid to list of pids to ignore.
if [ -f "$PIDFILE" ] && [ -d /run/sendsigs.omit.d ]
then
ln -sf "$PIDFILE" /run/sendsigs.omit.d/zed
fi
elif type daemon > /dev/null 2>&1 ; then
# Fedora/RedHat functions
# shellcheck disable=SC2086
daemon --pidfile "$PIDFILE" "$DAEMON_BIN" "$@"
return $?
else
# Unsupported
return 3
fi
return 0
}
# Returns
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# 3 if unsupported
#
zfs_daemon_stop()
{
local PIDFILE="$1"
local DAEMON_BIN="$2"
local DAEMON_NAME="$3"
if type start-stop-daemon > /dev/null 2>&1 ; then
# LSB functions
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
--pidfile "$PIDFILE" --name "$DAEMON_NAME"
ret="$?"
[ "$ret" = 0 ] && rm -f "$PIDFILE"
return "$ret"
elif type killproc > /dev/null 2>&1 ; then
# Fedora/RedHat functions
killproc -p "$PIDFILE" "$DAEMON_NAME"
ret="$?"
[ "$ret" = 0 ] && rm -f "$PIDFILE"
return "$ret"
else
# Unsupported
return 3
fi
return 0
}
# Returns status
zfs_daemon_status()
{
local PIDFILE="$1"
local DAEMON_BIN="$2"
local DAEMON_NAME="$3"
if type status_of_proc > /dev/null 2>&1 ; then
# LSB functions
status_of_proc "$DAEMON_NAME" "$DAEMON_BIN"
return $?
elif type status > /dev/null 2>&1 ; then
# Fedora/RedHat functions
status -p "$PIDFILE" "$DAEMON_NAME"
return $?
else
# Unsupported
return 3
fi
return 0
}
zfs_daemon_reload()
{
local PIDFILE="$1"
local DAEMON_NAME="$2"
if type start-stop-daemon > /dev/null 2>&1 ; then
# LSB functions
start-stop-daemon --stop --signal 1 --quiet \
--pidfile "$PIDFILE" --name "$DAEMON_NAME"
return $?
elif type killproc > /dev/null 2>&1 ; then
# Fedora/RedHat functions
killproc -p "$PIDFILE" "$DAEMON_NAME" -HUP
return $?
else
# Unsupported
return 3
fi
return 0
}
zfs_installed()
{
if [ ! -x "$ZPOOL" ]; then
return 1
else
# Test if it works (will catch missing/broken libs etc)
"$ZPOOL" -? > /dev/null 2>&1
return $?
fi
if [ ! -x "$ZFS" ]; then
return 2
else
# Test if it works (will catch missing/broken libs etc)
"$ZFS" -? > /dev/null 2>&1
return $?
fi
return 0
}
# Trigger udev and wait for it to settle.
udev_trigger()
{
if [ -x /sbin/udevadm ]; then
/sbin/udevadm trigger --action=change --subsystem-match=block
/sbin/udevadm settle
elif [ -x /sbin/udevsettle ]; then
/sbin/udevtrigger
/sbin/udevsettle
fi
}
# Do a lot of checks to make sure it's 'safe' to continue with the import.
checksystem()
{
if grep -qiE '(^|[^\\](\\\\)* )zfs=(off|no|0)( |$)' /proc/cmdline;
then
# Called with zfs=(off|no|0) - bail because we don't
# want anything import, mounted or shared.
# HOWEVER, only do this if we're called at the boot up
# (from init), not if we're running interactively (as in
# from the shell - we know what we're doing).
# shellcheck disable=SC2154
[ -n "$init" ] && exit 3
fi
# Check if ZFS is installed.
zfs_installed || return 5
# Just make sure that /dev/zfs is created.
udev_trigger
return 0
}
get_root_pool()
{
# shellcheck disable=SC2046
set -- $(mount | grep ' on / ')
[ "$5" = "zfs" ] && echo "${1%%/*}"
}
# Check if a variable is 'yes' (any case) or '1'
# Returns TRUE if set.
check_boolean()
{
local var="$1"
echo "$var" | grep -Eiq "^yes$|^on$|^true$|^1$" && return 0 || return 1
}
check_module_loaded()
{
module="$1"
[ -r "/sys/module/${module}/version" ] && return 0 || return 1
}
load_module()
{
module="$1"
# Load the zfs module stack
if ! check_module_loaded "$module"; then
if ! /sbin/modprobe "$module"; then
return 5
fi
fi
return 0
}
# first parameter is a regular expression that filters mtab
read_mtab()
{
local match="$1"
local fs mntpnt fstype opts rest
# Unset all MTAB_* variables
# shellcheck disable=SC2046
unset $(env | sed -e '/^MTAB_/!d' -e 's,=.*,,')
while read -r fs mntpnt fstype opts rest; do
if echo "$fs $mntpnt $fstype $opts" | grep -qE "$match"; then
# * Fix problems (!?) in the mounts file. It will record
# 'rpool 1' as 'rpool\0401' instead of 'rpool\00401'
# which seems to be the correct (at least as far as
# 'printf' is concerned).
# * We need to use the external echo, because the
# internal one would interpret the backslash code
# (incorrectly), giving us a instead.
mntpnt=$(/bin/echo "$mntpnt" | sed 's,\\0,\\00,g')
fs=$(/bin/echo "$fs" | sed 's,\\0,\\00,')
# Remove 'unwanted' characters.
mntpnt=$(printf '%b' "$mntpnt" | tr -d '/. -')
fs=$(printf '%b' "$fs")
# Set the variable.
eval export "MTAB_$mntpnt=\"$fs\""
fi
done < /proc/self/mounts
}
in_mtab()
{
local mntpnt="$1"
# Remove 'unwanted' characters.
mntpnt=$(printf '%b' "$mntpnt" | tr -d '/. -')
local var
var="$(eval echo "MTAB_$mntpnt")"
[ "$(eval echo "$""$var")" != "" ]
return "$?"
}
# first parameter is a regular expression that filters fstab
read_fstab()
{
local match="$1"
local i var
# Unset all FSTAB_* variables
# shellcheck disable=SC2046
unset $(env | sed -e '/^FSTAB_/!d' -e 's,=.*,,')
i=0
while read -r fs mntpnt fstype opts; do
echo "$fs" | grep -qE '^#|^$' && continue
echo "$mntpnt" | grep -qE '^none|^swap' && continue
echo "$fstype" | grep -qE '^swap' && continue
if echo "$fs $mntpnt $fstype $opts" | grep -qE "$match"; then
eval export "FSTAB_dev_$i=$fs"
fs=$(printf '%b' "$fs" | tr '/' '_')
eval export "FSTAB_$i=$mntpnt"
i=$((i + 1))
fi
done < /etc/fstab
}
in_fstab()
{
local var
var="$(eval echo "FSTAB_$1")"
[ "${var}" != "" ]
return $?
}
is_mounted()
{
local mntpt="$1"
local mp
while read -r _ mp _; do
[ "$mp" = "$mntpt" ] && return 0
done < /proc/self/mounts
return 1
}
File Metadata
Details
Attached
Mime Type
application/octet-stream
Expires
Thu, May 23, 3:36 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9558100
Default Alt Text
(39 KB)
Attached To
Mode
rG FreeBSD src repository
Attached
Detach File
Event Timeline
Log In to Comment