summaryrefslogtreecommitdiffstats
path: root/sys/boot
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
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')
-rw-r--r--sys/boot/i386/loader/main.c18
-rw-r--r--sys/boot/userboot/userboot/main.c19
-rw-r--r--sys/boot/zfs/zfs.c9
3 files changed, 31 insertions, 15 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"));
}
diff --git a/sys/boot/userboot/userboot/main.c b/sys/boot/userboot/userboot/main.c
index 335c8fd..a52550c 100644
--- a/sys/boot/userboot/userboot/main.c
+++ b/sys/boot/userboot/userboot/main.c
@@ -168,6 +168,7 @@ extract_currdev(void)
zdev.d_type = zdev.d_dev->dv_type;
dev = *(struct disk_devdesc *)&zdev;
+ init_zfs_bootenv(zfs_fmtdev(&dev));
} else
#endif
@@ -191,10 +192,6 @@ extract_currdev(void)
dev.d_unit = 0;
}
-#if defined(USERBOOT_ZFS_SUPPORT)
- init_zfs_bootenv(zfs_fmtdev(&dev));
-#endif
-
env_setenv("currdev", EV_VOLATILE, userboot_fmtdev(&dev),
userboot_setcurrdev, env_nounset);
env_setenv("loaddev", EV_VOLATILE, userboot_fmtdev(&dev),
@@ -207,9 +204,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: */
@@ -219,9 +221,7 @@ init_zfs_bootenv(char *currdev)
beroot = strrchr(currdev, '/');
if (beroot != NULL)
beroot[0] = '\0';
-
beroot = currdev;
-
setenv("zfs_be_root", beroot, 1);
}
@@ -273,6 +273,7 @@ static int
command_reloadbe(int argc, char *argv[])
{
int err;
+ char *root;
if (argc > 2) {
command_errmsg = "wrong number of arguments";
@@ -282,7 +283,11 @@ command_reloadbe(int argc, char *argv[])
if (argc == 2) {
err = zfs_bootenv(argv[1]);
} else {
- err = zfs_bootenv(getenv("zfs_be_root"));
+ root = getenv("zfs_be_root");
+ if (root == NULL) {
+ return (CMD_OK);
+ }
+ err = zfs_bootenv(root);
}
if (err != 0) {
diff --git a/sys/boot/zfs/zfs.c b/sys/boot/zfs/zfs.c
index fdb79bb..c339b2d 100644
--- a/sys/boot/zfs/zfs.c
+++ b/sys/boot/zfs/zfs.c
@@ -712,13 +712,18 @@ zfs_list(const char *name)
int
zfs_bootenv(const char *name)
{
- static char poolname[ZFS_MAXNAMELEN], *dsname;
+ static char poolname[ZFS_MAXNAMELEN], *dsname, *root;
char becount[4];
uint64_t objid;
spa_t *spa;
int len, rv, pages, perpage, currpage;
- if (strcmp(name, getenv("zfs_be_root")) != 0) {
+ if (name == NULL)
+ return (EINVAL);
+ if ((root = getenv("zfs_be_root")) == NULL)
+ return (EINVAL);
+
+ if (strcmp(name, root) != 0) {
if (setenv("zfs_be_root", name, 1) != 0)
return (ENOMEM);
}
OpenPOWER on IntegriCloud