Skip to content

Commit 3836534

Browse files
committed
Make lines stay within 80 char limit.
Signed-off-by: Turbo Fredriksson <[email protected]>
1 parent b5c3d23 commit 3836534

File tree

1 file changed

+61
-36
lines changed
  • contrib/initramfs/scripts

1 file changed

+61
-36
lines changed

contrib/initramfs/scripts/zfs

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ shell() {
2525
fi
2626
}
2727

28+
get_cmdline()
29+
{
30+
_option="${1}"
31+
32+
# shellcheck disable=SC2089
33+
grep -qiE "(^|[^\\](\\\\)* )(${_option})=(on|yes|1)( |$)" /proc/cmdline
34+
}
35+
2836
# This runs any scripts that should run before we start importing
2937
# pools and mounting any filesystems.
3038
pre_mountroot()
@@ -197,7 +205,8 @@ import_pool()
197205

198206
# Verify that the pool isn't already imported
199207
# Make as sure as we can to not require '-f' to import.
200-
"${ZPOOL}" get -H -o value name,guid 2>/dev/null | grep -Fxq "${_import_pool}" && return 0
208+
"${ZPOOL}" get -H -o value name,guid 2>/dev/null | \
209+
grep -Fxq "${_import_pool}" && return 0
201210

202211
# For backwards compatibility, make sure that ZPOOL_IMPORT_PATH is set
203212
# to something we can use later with the real import(s). We want to
@@ -242,7 +251,8 @@ import_pool()
242251
[ "${quiet}" != "y" ] && zfs_log_begin_msg \
243252
"Importing pool '${_import_pool}' using cachefile."
244253

245-
ZFS_CMD="${ZPOOL} import -c ${ZPOOL_CACHE} -N ${ZPOOL_FORCE} ${ZPOOL_IMPORT_OPTS}"
254+
ZFS_CMD="${ZPOOL} import -c ${ZPOOL_CACHE} -N ${ZPOOL_FORCE}"
255+
ZFS_CMD="${ZFS_CMD} ${ZPOOL_IMPORT_OPTS}"
246256
ZFS_STDERR="$(${ZFS_CMD} "${_import_pool}" 2>&1)"
247257
ZFS_ERROR="${?}"
248258
fi
@@ -280,7 +290,8 @@ load_module_initrd()
280290

281291
if [ "${ZFS_INITRD_PRE_MOUNTROOT_SLEEP}" -gt 0 ]
282292
then
283-
[ "${quiet}" != "y" ] && zfs_log_begin_msg "Delaying for up to '${ZFS_INITRD_PRE_MOUNTROOT_SLEEP}' seconds."
293+
[ "${quiet}" != "y" ] && \
294+
zfs_log_begin_msg "Delaying for up to '${ZFS_INITRD_PRE_MOUNTROOT_SLEEP}' seconds."
284295
fi
285296

286297
START="$(/bin/date -u +%s)"
@@ -345,7 +356,8 @@ mount_fs()
345356
_mount_fs="${1}"
346357

347358
# Check that the filesystem exists
348-
"${ZFS}" list -oname -tfilesystem -H "${_mount_fs}" > /dev/null 2>&1 || return 1
359+
"${ZFS}" list -oname -tfilesystem -H "${_mount_fs}" \
360+
> /dev/null 2>&1 || return 1
349361

350362
# Skip filesystems with canmount=off. The root fs should not have
351363
# canmount=off, but ignore it for backwards compatibility just in case.
@@ -389,9 +401,11 @@ mount_fs()
389401
decrypt_fs "${_mount_fs}"
390402

391403
[ "${quiet}" != "y" ] && \
392-
zfs_log_begin_msg "Mounting '${_mount_fs}' on '${rootmnt}/${_mountpoint}'"
404+
zfs_log_begin_msg \
405+
"Mounting '${_mount_fs}' on '${rootmnt}/${_mountpoint}'"
393406
[ -n "${ZFS_DEBUG}" ] && \
394-
zfs_log_begin_msg "CMD: '${ZFS_CMD} ${_mount_fs} ${rootmnt}/${_mountpoint}'"
407+
zfs_log_begin_msg \
408+
"CMD: '${ZFS_CMD} ${_mount_fs} ${rootmnt}/${_mountpoint}'"
395409

396410
ZFS_STDERR="$(${ZFS_CMD} "${_mount_fs}" "${rootmnt}/${_mountpoint}" 2>&1)"
397411
ZFS_ERROR="${?}"
@@ -420,8 +434,10 @@ decrypt_fs()
420434
{
421435
_decrypt_fs="${1}"
422436

423-
# If pool encryption is active and the zfs command understands '-o encryption'
424-
if [ "$("${ZPOOL}" list -H -o feature@encryption "${_decrypt_fs%%/*}")" = 'active' ]
437+
# If pool encryption is active and the zfs command understands
438+
# '-o encryption'.
439+
_enc="$("${ZPOOL}" list -H -o feature@encryption "${_decrypt_fs%%/*}")"
440+
if [ "${_enc}" = 'active' ]
425441
then
426442
# Determine dataset that holds key for root dataset
427443
ENCRYPTIONROOT="$(get_fs_value "${_decrypt_fs}" encryptionroot)"
@@ -437,7 +453,8 @@ decrypt_fs()
437453
[ "${KEYSTATUS}" = "unavailable" ] || return 0
438454

439455
# Try extensions first
440-
for key in "/etc/zfs/initramfs-tools-load-key" "/etc/zfs/initramfs-tools-load-key.d/"*
456+
for key in "/etc/zfs/initramfs-tools-load-key" \
457+
"/etc/zfs/initramfs-tools-load-key.d/"*
441458
do
442459
[ -r "${key}" ] || continue
443460
(. "${key}") && {
@@ -458,7 +475,8 @@ decrypt_fs()
458475
echo "plymouth" > /run/zfs_console_askpwd_cmd
459476
for _ in 1 2 3
460477
do
461-
plymouth ask-for-password --prompt "Encrypted ZFS password for ${ENCRYPTIONROOT}" | \
478+
plymouth ask-for-password --prompt \
479+
"Encrypted ZFS password for ${ENCRYPTIONROOT}" | \
462480
"${ZFS}" load-key "${ENCRYPTIONROOT}" && break
463481
done
464482

@@ -468,13 +486,16 @@ decrypt_fs()
468486
echo "systemd-ask-password" > /run/zfs_console_askpwd_cmd
469487
for _ in 1 2 3
470488
do
471-
systemd-ask-password --no-tty "Encrypted ZFS password for ${ENCRYPTIONROOT}" | \
489+
systemd-ask-password \
490+
--no-tty \
491+
"Encrypted ZFS password for ${ENCRYPTIONROOT}" | \
472492
"${ZFS}" load-key "${ENCRYPTIONROOT}" && break
473493
done
474494

475495
# Prompt with ZFS tty, otherwise
476496
else
477-
# Temporarily setting "printk" to "7" allows the prompt to appear even when the "quiet" kernel option has been used
497+
# Temporarily setting "printk" to "7" allows the prompt to
498+
# appear even when the "quiet" kernel option has been used.
478499
echo "load-key" > /run/zfs_console_askpwd_cmd
479500
read -r storeprintk _ < /proc/sys/kernel/printk
480501
echo 7 > /proc/sys/kernel/printk
@@ -508,9 +529,11 @@ destroy_fs()
508529
echo "Message: ${ZFS_STDERR}"
509530
echo "Error: ${ZFS_ERROR}"
510531
echo ""
511-
echo "Failed to destroy '${_destroy_fs}'. Please make sure that it is not available."
532+
echo "Failed to destroy '${_destroy_fs}'."
533+
echo "Please make sure that it is not available."
512534
echo "Hint: Try: zfs destroy -Rfn ${_destroy_fs}"
513-
echo "If this dryrun looks good, then remove the 'n' from '-Rfn' and try again."
535+
echo "If this dryrun looks good, then remove the 'n' from '-Rfn'" \
536+
"and try again."
514537
shell
515538
else
516539
[ "${quiet}" != "y" ] && zfs_log_end_msg
@@ -529,7 +552,8 @@ clone_snap()
529552
_clone_destfs="${2}"
530553
_clone_mountpoint="${3}"
531554

532-
[ "${quiet}" != "y" ] && zfs_log_begin_msg "Cloning '${_clone_snap}' to '${_clone_destfs}'"
555+
[ "${quiet}" != "y" ] && \
556+
zfs_log_begin_msg "Cloning '${_clone_snap}' to '${_clone_destfs}'"
533557

534558
# Clone the snapshot into a dataset we can boot from
535559
# + We don't want this filesystem to be automatically mounted, we
@@ -659,7 +683,7 @@ setup_snapshot_booting()
659683
_snapname="${_boot_snap##*@}"
660684
ZFS_BOOTFS="${_rootfs}_${_snapname}"
661685

662-
if ! grep -qiE '(^|[^\\](\\\\)* )(rollback)=(on|yes|1)( |$)' /proc/cmdline
686+
if ! get_cmdline 'rollback'
663687
then
664688
# If the destination dataset for the clone
665689
# already exists, destroy it. Recursively
@@ -679,18 +703,18 @@ setup_snapshot_booting()
679703
for s in $("${ZFS}" list -H -oname -tsnapshot -r "${_rootfs}" | \
680704
grep "${_snapname}")
681705
do
682-
if grep -qiE '(^|[^\\](\\\\)* )(rollback)=(on|yes|1)( |$)' /proc/cmdline
706+
if get_cmdline 'rollback'
683707
then
684708
# Rollback snapshot
685709
rollback_snap "${s}" || _retval="$((_retval + 1))"
686710
ZFS_BOOTFS="${_rootfs}"
687711
else
688712
# Setup a destination filesystem name.
689713
# Ex: Called with 'rpool/ROOT/debian@snap2'
690-
# rpool/ROOT/debian@snap2 => rpool/ROOT/debian_snap2
691-
# rpool/ROOT/debian/boot@snap2 => rpool/ROOT/debian_snap2/boot
692-
# rpool/ROOT/debian/usr@snap2 => rpool/ROOT/debian_snap2/usr
693-
# rpool/ROOT/debian/var@snap2 => rpool/ROOT/debian_snap2/var
714+
# rpool/ROOT/debian@snap2 => rpool/ROOT/debian_snap2
715+
# rpool/ROOT/debian/boot@snap2 => rpool/ROOT/debian_snap2/boot
716+
# rpool/ROOT/debian/usr@snap2 => rpool/ROOT/debian_snap2/usr
717+
# rpool/ROOT/debian/var@snap2 => rpool/ROOT/debian_snap2/var
694718
_subfs="${s##"${_rootfs}"}"
695719
_subfs="${_subfs%%@"${_snapname}"}"
696720

@@ -737,7 +761,7 @@ mountroot()
737761

738762
# ------------
739763
# Support debug option
740-
if grep -qiE '(^|[^\\](\\\\)* )(zfs_debug|zfs\.debug|zfsdebug)=(on|yes|1)( |$)' /proc/cmdline
764+
if get_cmdline 'zfs_debug|zfs\.debug|zfsdebug'
741765
then
742766
ZFS_DEBUG=1
743767
mkdir /var/log
@@ -794,22 +818,22 @@ mountroot()
794818
# ----------------------------------------------------------------
795819
# P A R S E C O M M A N D L I N E O P T I O N S
796820

797-
# This part is the really ugly part - there's so many options and permutations
798-
# 'out there', and if we should make this the 'primary' source for ZFS initrd
799-
# scripting, we need/should support them all.
821+
# This part is the really ugly part - there's so many options and
822+
# permutations 'out there', and if we should make this the 'primary'
823+
# source for ZFS initrd scripting, we need/should support them all.
800824
#
801825
# Supports the following kernel command line argument combinations
802826
# (in this order - first match win):
803827
#
804-
# rpool=<pool> (tries to finds bootfs automatically)
805-
# bootfs=<pool>/<dataset> (uses this for rpool - first part)
806-
# rpool=<pool> bootfs=<pool>/<dataset>
807-
# -B zfs-bootfs=<pool>/<fs> (uses this for rpool - first part)
808-
# rpool=rpool (default if none of the above is used)
809-
# root=<pool>/<dataset> (uses this for rpool - first part)
810-
# root=ZFS=<pool>/<dataset> (uses this for rpool - first part, without 'ZFS=')
811-
# root=zfs:AUTO (tries to detect both pool and rootfs)
812-
# root=zfs:<pool>/<dataset> (uses this for rpool - first part, without 'zfs:')
828+
# rpool=<pool> (tries to finds bootfs automatically)
829+
# bootfs=<pool>/<dataset> (uses this for rpool - first part)
830+
# rpool=<pool> bootfs=<pool>/<dataset>
831+
# -B zfs-bootfs=<pool>/<fs> (uses this for rpool - first part)
832+
# rpool=rpool (default if none of the above is used)
833+
# root=<pool>/<dataset> (uses this for rpool - first part)
834+
# root=ZFS=<pool>/<dataset> (uses this for rpool - first part, without 'ZFS=')
835+
# root=zfs:AUTO (tries to detect both pool and rootfs)
836+
# root=zfs:<pool>/<dataset> (uses this for rpool - first part, without 'zfs:')
813837
#
814838
# Option <dataset> could also be <snapshot>
815839
# Option <pool> could also be <guid>
@@ -821,7 +845,7 @@ mountroot()
821845
# This should (almost) never be needed, but it's here for
822846
# completeness.
823847
ZPOOL_FORCE=""
824-
if grep -qiE '(^|[^\\](\\\\)* )(zfs_force|zfs\.force|zfsforce)=(on|yes|1)( |$)' /proc/cmdline
848+
if get_cmdline 'zfs_force|zfs\.force|zfsforce'
825849
then
826850
ZPOOL_FORCE="-f"
827851
fi
@@ -969,7 +993,8 @@ mountroot()
969993
echo " not specified on the kernel command line."
970994
echo ""
971995
echo "Manually mount the root filesystem on ${rootmnt} and then exit."
972-
echo "Hint: Try: mount -o zfsutil -t zfs ${ZFS_RPOOL:-rpool}/ROOT/system ${rootmnt}"
996+
echo "Hint: Try: mount -o zfsutil -t zfs " \
997+
"${ZFS_RPOOL:-rpool}/ROOT/system ${rootmnt}"
973998
shell
974999
fi
9751000

0 commit comments

Comments
 (0)