Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Jan 2016 05:09:56 +0000 (UTC)
From:      Allan Jude <allanjude@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r293414 - in head/sys/boot: i386/loader userboot/userboot
Message-ID:  <201601080509.u0859uSh096968@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: allanjude
Date: Fri Jan  8 05:09:55 2016
New Revision: 293414
URL: https://svnweb.freebsd.org/changeset/base/293414

Log:
  Add support for ZFS Boot Environments to userboot (for bhyve and others)
  
  While here, also fix a possible null pointer
  
  Reported by:	lattera
  MFC after:	3 days
  Sponsored by:	ScaleEngine Inc.

Modified:
  head/sys/boot/i386/loader/main.c
  head/sys/boot/userboot/userboot/main.c

Modified: head/sys/boot/i386/loader/main.c
==============================================================================
--- head/sys/boot/i386/loader/main.c	Fri Jan  8 03:45:28 2016	(r293413)
+++ head/sys/boot/i386/loader/main.c	Fri Jan  8 05:09:55 2016	(r293414)
@@ -321,7 +321,8 @@ init_zfs_bootenv(char *currdev)
 	currdev++;
 	/* Remove the last element (current bootenv) */
 	beroot = strrchr(currdev, '/');
-	beroot[0] = '\0';
+	if (beroot != NULL)
+		beroot[0] = '\0';
 
 	beroot = currdev;
 	

Modified: head/sys/boot/userboot/userboot/main.c
==============================================================================
--- head/sys/boot/userboot/userboot/main.c	Fri Jan  8 03:45:28 2016	(r293413)
+++ head/sys/boot/userboot/userboot/main.c	Fri Jan  8 05:09:55 2016	(r293414)
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
 
 static void userboot_zfs_probe(void);
 static int userboot_zfs_found;
+static void init_zfs_bootenv(char *currdev);
 #endif
 
 #define	USERBOOT_VERSION	USERBOOT_VERSION_3
@@ -190,6 +191,10 @@ 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),
@@ -198,6 +203,29 @@ extract_currdev(void)
 
 #if defined(USERBOOT_ZFS_SUPPORT)
 static void
+init_zfs_bootenv(char *currdev)
+{
+	char *beroot;
+
+	/* Remove the trailing : */
+	currdev[strlen(currdev) - 1] = '\0';
+	setenv("zfs_be_active", currdev, 1);
+	/* Do not overwrite if already set */
+	setenv("vfs.root.mountfrom", currdev, 0);
+	/* Forward past zfs: */
+	currdev = strchr(currdev, ':');
+	currdev++;
+	/* Remove the last element (current bootenv) */
+	beroot = strrchr(currdev, '/');
+	if (beroot != NULL)
+		beroot[0] = '\0';
+
+	beroot = currdev;
+	
+	setenv("zfs_be_root", beroot, 1);
+}
+
+static void
 userboot_zfs_probe(void)
 {
 	char devname[32];
@@ -237,6 +265,33 @@ command_lszfs(int argc, char *argv[])
 	}
 	return (CMD_OK);
 }
+
+COMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments",
+	    command_reloadbe);
+
+static int
+command_reloadbe(int argc, char *argv[])
+{
+	int err;
+
+	if (argc > 2) {
+		command_errmsg = "wrong number of arguments";
+		return (CMD_ERROR);
+	}
+
+	if (argc == 2) {
+		err = zfs_bootenv(argv[1]);
+	} else {
+		err = zfs_bootenv(getenv("zfs_be_root"));
+	}
+
+	if (err != 0) {
+		command_errmsg = strerror(err);
+		return (CMD_ERROR);
+	}
+
+	return (CMD_OK);
+}
 #endif /* USERBOOT_ZFS_SUPPORT */
 
 COMMAND_SET(quit, "quit", "exit the loader", command_quit);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601080509.u0859uSh096968>