summaryrefslogtreecommitdiffstats
path: root/sys/boot/i386
diff options
context:
space:
mode:
authorallanjude <allanjude@FreeBSD.org>2016-01-09 00:54:08 +0000
committerallanjude <allanjude@FreeBSD.org>2016-01-09 00:54:08 +0000
commiteeaf13194e3082c4eb14ec2a9caa050ec6d4d844 (patch)
treed4dc8d29ad4044c903dc83eaa477e6b3b5ec28ad /sys/boot/i386
parent6c5021ff92374933207ab0b12d6a066735529c1a (diff)
downloadFreeBSD-src-eeaf13194e3082c4eb14ec2a9caa050ec6d4d844.zip
FreeBSD-src-eeaf13194e3082c4eb14ec2a9caa050ec6d4d844.tar.gz
Only call init_zfs_bootenv() when the system was booted with ZFS
Add a few other safeguards to ensure things do not break when the boot device cannot be determined Reported by: flo MFC after: 3 days Sponsored by: ScaleEngine Inc.
Diffstat (limited to 'sys/boot/i386')
-rw-r--r--sys/boot/i386/loader/main.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/sys/boot/i386/loader/main.c b/sys/boot/i386/loader/main.c
index 73f3507..2b30b92 100644
--- a/sys/boot/i386/loader/main.c
+++ b/sys/boot/i386/loader/main.c
@@ -262,6 +262,7 @@ extract_currdev(void)
new_currdev.d_kind.zfs.root_guid = 0;
}
new_currdev.d_dev = &zfs_dev;
+ init_zfs_bootenv(zfs_fmtdev(&new_currdev));
#endif
} else if ((initial_bootdev & B_MAGICMASK) != B_DEVMAGIC) {
/* The passed-in boot device is bad */
@@ -295,10 +296,6 @@ extract_currdev(void)
new_currdev.d_unit = 0;
}
-#ifdef LOADER_ZFS_SUPPORT
- init_zfs_bootenv(zfs_fmtdev(&new_currdev));
-#endif
-
env_setenv("currdev", EV_VOLATILE, i386_fmtdev(&new_currdev),
i386_setcurrdev, env_nounset);
env_setenv("loaddev", EV_VOLATILE, i386_fmtdev(&new_currdev), env_noset,
@@ -311,9 +308,14 @@ init_zfs_bootenv(char *currdev)
{
char *beroot;
+ if (strlen(currdev) == 0)
+ return;
+ if(strncmp(currdev, "zfs:", 4) != 0)
+ return;
/* Remove the trailing : */
currdev[strlen(currdev) - 1] = '\0';
setenv("zfs_be_active", currdev, 1);
+ setenv("zfs_be_currpage", "1", 1);
/* Do not overwrite if already set */
setenv("vfs.root.mountfrom", currdev, 0);
/* Forward past zfs: */
@@ -323,9 +325,7 @@ init_zfs_bootenv(char *currdev)
beroot = strrchr(currdev, '/');
if (beroot != NULL)
beroot[0] = '\0';
-
beroot = currdev;
-
setenv("zfs_be_root", beroot, 1);
}
#endif
@@ -394,6 +394,7 @@ static int
command_reloadbe(int argc, char *argv[])
{
int err;
+ char *root;
if (argc > 2) {
command_errmsg = "wrong number of arguments";
@@ -403,6 +404,11 @@ command_reloadbe(int argc, char *argv[])
if (argc == 2) {
err = zfs_bootenv(argv[1]);
} else {
+ root = getenv("zfs_be_root");
+ if (root == NULL) {
+ /* There does not appear to be a ZFS pool here, exit without error */
+ return (CMD_OK);
+ }
err = zfs_bootenv(getenv("zfs_be_root"));
}
OpenPOWER on IntegriCloud