Skip to content

Commit 999e6c2

Browse files
committed
Drop import_args variable and let import_pool build its own arguments
Rather than define `import_args` in zfsbootmenu-parse-commandline.sh based on the value of `force_import` and `read_write` on the ZBM kernel command line, the parser just defines `force_import` and `read_write` variables based on these arguments. The `import_pool` function uses these variables directly to determine the right command-line arguments to pass to `zpool import`. This is a bit cleaner and allows for a construct like read_write=yes import_pool zpool to force rw imports rathern than rewriting `import_args`. Note that passing `read_write=yes` in that call does not override the value in the environment, so other calls to `import_pool` will fall back to expected behavior. Closes #75.
1 parent b85d836 commit 999e6c2

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

90zfsbootmenu/zfsbootmenu-exec.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/bin/bash
22

3-
export import_args
43
export spl_hostid
54
export force_import
65
export read_write
76
export menu_timeout
87
export root
98

109
# https://busybox.net/FAQ.html#job_control
11-
exec setsid sh -c 'exec /bin/zfsbootmenu </dev/tty1 >/dev/tty1 2>&1'
10+
exec setsid bash -c 'exec /bin/zfsbootmenu </dev/tty1 >/dev/tty1 2>&1'

90zfsbootmenu/zfsbootmenu-lib.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,27 @@ find_online_pools() {
554554
# returns: 0 on success, 1 on failure
555555

556556
import_pool() {
557-
local pool
557+
local pool import_args
558+
558559
pool="${1}"
559560

561+
# Import /never/ mounts filesystems
562+
import_args=( "-N" )
563+
564+
# shellcheck disable=SC2154
565+
if [ "${force_import}" ]; then
566+
import_args+=( "-f" )
567+
fi
568+
569+
# shellcheck disable=SC2154
570+
if [ "${read_write}" ]; then
571+
import_args+=( "-o" "readonly=on" )
572+
else
573+
import_args+=( "-o" "readonly=off" )
574+
fi
575+
560576
# shellcheck disable=SC2086
561-
status="$( zpool import ${import_args} ${pool} )"
577+
status="$( zpool import "${import_args[@]}" ${pool} )"
562578
ret=$?
563579

564580
return ${ret}
@@ -641,9 +657,8 @@ set_rw_pool() {
641657
fi
642658
fi
643659

644-
import_args="${import_args/readonly=on/readonly=off}"
645660
if export_pool "${pool}" ; then
646-
import_pool "${pool}"
661+
read_write=yes import_pool "${pool}"
647662
return $?
648663
fi
649664

90zfsbootmenu/zfsbootmenu-parse-commandline.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ fi
1818

1919
# Force import pools only when explicitly told to do so
2020
if getargbool 0 force_import ; then
21+
# shellcheck disable=SC2034
22+
force_import="yes"
2123
info "ZFSBootMenu: Enabling force import of ZFS pools"
22-
import_args="-o readonly=on -f -N"
23-
else
24-
import_args="-o readonly=on -N"
2524
fi
2625

2726
# Import pools by default in read-write mode
2827
if getargbool 0 read_write ; then
28+
# shellcheck disable=SC2034
29+
read_write="yes"
2930
info "ZFSBootMenu: Enabling read-write ZFS pool import"
30-
import_args="${import_args/readonly=on/readonly=off}"
3131
fi
3232

3333
# Set a menu timeout, to allow immediate booting

0 commit comments

Comments
 (0)