Skip to content

Commit

Permalink
Support pool import retries
Browse files Browse the repository at this point in the history
Configurable KCL options provide for a maximum number of retry attempts
(default: 0) and a delay between retries (default: 5s).
  • Loading branch information
ahesford committed Jun 4, 2021
1 parent 60e827c commit 5142aa1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
14 changes: 14 additions & 0 deletions 90zfsbootmenu/zfsbootmenu-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ else
first_pass=1
fi

zbm_import_attempt=0
while true; do
if [ "${first_pass}" -eq 0 ]; then
# Try the preferred pool, exactly once
Expand Down Expand Up @@ -93,6 +94,19 @@ while true; do
continue
fi

if [ "${zbm_import_attempt}" -lt "${zbm_import_retries:-0}" ]; then
# The max number of import attempts has not been reached;
# retry unless the user decides to abort immediately
zbm_import_attempt="$((zbm_import_attempt + 1))"

zinfo "pool import failed on attempt ${zbm_import_attempt} of ${zbm_import_retries}"

if delay="${zbm_import_delay:-5}" prompt="Unable to import pool, retrying in %0.2d seconds" \
timed_prompt "[RETURN] to retry immediately" "[ESCAPE] for a recovery shell"; then
continue
fi
fi

# Allow the user to attempt recovery
emergency_shell "unable to successfully import a pool"
done
Expand Down
18 changes: 18 additions & 0 deletions 90zfsbootmenu/zfsbootmenu-parse-commandline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ else
menu_timeout=10
fi

zbm_import_retries=$( getarg zbm.import_retries )
if [ "${zbm_import_retries:-0}" -gt 0 ] 2>/dev/null ; then
# Beyond logging, this validates that zbm_import_retries is a number
info "ZFSBootMenu: will attempt up to ${zbm_import_retries} import retries"
else
zbm_import_retries=0
fi

zbm_import_delay=$( getarg zbm.import_delay )
if [ "${zbm_import_delay:-0}" -gt 0 ] 2>/dev/null ; then
# Again, this validates that zbm_import_delay is numeric in addition to logging
if [ "${zbm_import_retries}" -gt 0 ]; then
info "ZFSBootMenu: import retry delay is ${zbm_import_delay} seconds"
fi
else
zbm_import_delay=5
fi

# Allow setting of console size; there are no defaults here
# shellcheck disable=SC2034
zbm_lines=$( getarg zbm.lines=)
Expand Down
2 changes: 2 additions & 0 deletions 90zfsbootmenu/zfsbootmenu-preinit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export loglevel="${loglevel}"
export root="${root}"
export zbm_sort="${zbm_sort}"
export zbm_set_hostid="${zbm_set_hostid}"
export zbm_import_delay="${zbm_import_delay}"
export zbm_import_retries="${zbm_import_retries}"
EOF

getcmdline > "${BASE}/zbm.cmdline"
Expand Down
10 changes: 8 additions & 2 deletions man/zfsbootmenu.7
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@
.\" ========================================================================
.\"
.IX Title "zfsbootmenu 7"
.TH zfsbootmenu 7 "2021-04-23" "1.9.0" "ZFSBootMenu"
.TH zfsbootmenu 7 "2021-06-03" "1.9.0" "ZFSBootMenu"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
zfsbootmenu \- System integration
zfsbootmenu \- System Integration
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
ZFSBootMenu behavior is controlled through \s-1ZFS\s0 filesystem properties and command-line options provided to the ZFSBootMenu kernel.
Expand All @@ -152,6 +152,12 @@ When creating an initramfs or \s-1UEFI\s0 bundle, the \fI/etc/hostid\fR from the
.IP "\fBzbm.prefer=<pool>\fR" 4
.IX Item "zbm.prefer=<pool>"
By default, ZFSBootMenu will look for the \fIbootfs\fR property on the first imported pool (sorted alphabetically) to select the default boot environment. If you have multiple pools, replace \fB<pool>\fR with the name of your preferred pool to override the default.
.IP "\fBzbm.import_retries=<count>\fR" 4
.IX Item "zbm.import_retries=<count>"
If ZFSBootMenu fails to import a pool and \fB<count>\fR is a positive integer, the import will be attempted up to \fB<count>\fR times before dropping to an emergency shell to facilitate recovery. By default or if \fB<count>\fR is anything besides a positive integer, imports will not be retried.
.IP "\fBzbm.import_delay=<time>\fR" 4
.IX Item "zbm.import_delay=<time>"
If ZFSBootMenu is configured to retry imports via \fBzbm.import_retries\fR, each retried attempt will proceed after a delay of \fB<time>\fR seconds. When \fB<time>\fR is unspecified or is anything other than a positive integer, a default value of 5 seconds will be used.
.IP "\fBzbm.import_policy\fR" 4
.IX Item "zbm.import_policy"
This option controls how the pool import process should take place.
Expand Down
8 changes: 8 additions & 0 deletions pod/zfsbootmenu.7.pod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ When creating an initramfs or UEFI bundle, the I</etc/hostid> from the system is

By default, ZFSBootMenu will look for the I<bootfs> property on the first imported pool (sorted alphabetically) to select the default boot environment. If you have multiple pools, replace B<E<lt>poolE<gt>> with the name of your preferred pool to override the default.

=item B<zbm.import_retries=E<lt>countE<gt>>

If ZFSBootMenu fails to import a pool and B<E<lt>countE<gt>> is a positive integer, the import will be attempted up to B<E<lt>countE<gt>> times before dropping to an emergency shell to facilitate recovery. By default or if B<E<lt>countE<gt>> is anything besides a positive integer, imports will not be retried.

=item B<zbm.import_delay=E<lt>timeE<gt>>

If ZFSBootMenu is configured to retry imports via B<zbm.import_retries>, each retried attempt will proceed after a delay of B<E<lt>timeE<gt>> seconds. When B<E<lt>timeE<gt>> is unspecified or is anything other than a positive integer, a default value of 5 seconds will be used.

=item B<zbm.import_policy>

This option controls how the pool import process should take place.
Expand Down

0 comments on commit 5142aa1

Please sign in to comment.