Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Feb 2016 17:49:22 +0000 (UTC)
From:      Allan Jude <allanjude@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r295475 - in stable/10/sys/boot: efi/loader i386/loader userboot/userboot zfs
Message-ID:  <201602101749.u1AHnM19030552@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: allanjude
Date: Wed Feb 10 17:49:22 2016
New Revision: 295475
URL: https://svnweb.freebsd.org/changeset/base/295475

Log:
  Catch the EFI loader up to the latest ZFS Boot Environment Menu features
  
  MFC: r294072
    Move init_zfs_bootenv to sys/boot/zfs/zfs.c instead of having a copy in each loader
  
  MFC: r294073
    Connect the ZFS boot environment menu to the UEFI loader
  
  MFC: r295357
    Do not set vfs.root.mountfrom unnecessarily when initializing ZFS BE menu
  
  Approved by:	re (marius)
  Relnotes:	yes
  Sponsored by:	ScaleEngine Inc.

Modified:
  stable/10/sys/boot/efi/loader/main.c
  stable/10/sys/boot/i386/loader/main.c
  stable/10/sys/boot/userboot/userboot/main.c
  stable/10/sys/boot/zfs/libzfs.h
  stable/10/sys/boot/zfs/zfs.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/boot/efi/loader/main.c
==============================================================================
--- stable/10/sys/boot/efi/loader/main.c	Wed Feb 10 16:49:20 2016	(r295474)
+++ stable/10/sys/boot/efi/loader/main.c	Wed Feb 10 17:49:22 2016	(r295475)
@@ -198,6 +198,7 @@ main(int argc, CHAR16 *argv[])
 			   efi_setcurrdev, env_nounset);
 		env_setenv("loaddev", EV_VOLATILE, efi_fmtdev(&currdev), env_noset,
 			   env_nounset);
+		init_zfs_bootenv(zfs_fmtdev(&currdev));
 		break;
 	}
 #endif
@@ -504,6 +505,38 @@ 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;
+	char *root;
+
+	if (argc > 2) {
+		command_errmsg = "wrong number of arguments";
+		return (CMD_ERROR);
+	}
+
+	if (argc == 2) {
+		err = zfs_bootenv(argv[1]);
+	} else {
+		root = getenv("zfs_be_root");
+		if (root == NULL) {
+			return (CMD_OK);
+		}
+		err = zfs_bootenv(root);
+	}
+
+	if (err != 0) {
+		command_errmsg = strerror(err);
+		return (CMD_ERROR);
+	}
+
+	return (CMD_OK);
+}
 #endif
 
 #ifdef EFI_ZFS_BOOT

Modified: stable/10/sys/boot/i386/loader/main.c
==============================================================================
--- stable/10/sys/boot/i386/loader/main.c	Wed Feb 10 16:49:20 2016	(r295474)
+++ stable/10/sys/boot/i386/loader/main.c	Wed Feb 10 17:49:22 2016	(r295475)
@@ -69,7 +69,6 @@ static int		isa_inb(int port);
 static void		isa_outb(int port, int value);
 void			exit(int code);
 #ifdef LOADER_ZFS_SUPPORT
-static void		init_zfs_bootenv(char *currdev);
 static void		i386_zfs_probe(void);
 #endif
 
@@ -303,34 +302,6 @@ extract_currdev(void)
 	       env_nounset);
 }
 
-#ifdef LOADER_ZFS_SUPPORT
-static void
-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: */
-	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);
-}
-#endif
-
 COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
 
 static int

Modified: stable/10/sys/boot/userboot/userboot/main.c
==============================================================================
--- stable/10/sys/boot/userboot/userboot/main.c	Wed Feb 10 16:49:20 2016	(r295474)
+++ stable/10/sys/boot/userboot/userboot/main.c	Wed Feb 10 17:49:22 2016	(r295475)
@@ -41,7 +41,6 @@ __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
@@ -200,32 +199,6 @@ extract_currdev(void)
 
 #if defined(USERBOOT_ZFS_SUPPORT)
 static void
-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: */
-	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];

Modified: stable/10/sys/boot/zfs/libzfs.h
==============================================================================
--- stable/10/sys/boot/zfs/libzfs.h	Wed Feb 10 16:49:20 2016	(r295474)
+++ stable/10/sys/boot/zfs/libzfs.h	Wed Feb 10 17:49:22 2016	(r295475)
@@ -62,6 +62,7 @@ int	zfs_parsedev(struct zfs_devdesc *dev
 char	*zfs_fmtdev(void *vdev);
 int	zfs_probe_dev(const char *devname, uint64_t *pool_guid);
 int	zfs_list(const char *name);
+void	init_zfs_bootenv(char *currdev);
 int	zfs_bootenv(const char *name);
 int	zfs_belist_add(const char *name);
 int	zfs_set_env(void);

Modified: stable/10/sys/boot/zfs/zfs.c
==============================================================================
--- stable/10/sys/boot/zfs/zfs.c	Wed Feb 10 16:49:20 2016	(r295474)
+++ stable/10/sys/boot/zfs/zfs.c	Wed Feb 10 17:49:22 2016	(r295475)
@@ -709,6 +709,30 @@ zfs_list(const char *name)
 	return (zfs_list_dataset(spa, objid));
 }
 
+void
+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);
+	/* 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);
+}
+
 int
 zfs_bootenv(const char *name)
 {
@@ -779,8 +803,15 @@ int
 zfs_belist_add(const char *name)
 {
 
+	/* Skip special datasets that start with a $ character */
+	if (strncmp(name, "$", 1) == 0) {
+		return (0);
+	}
 	/* Add the boot environment to the head of the SLIST */
 	zfs_be = malloc(sizeof(struct zfs_be_entry));
+	if (zfs_be == NULL) {
+		return (ENOMEM);
+	}
 	zfs_be->name = name;
 	SLIST_INSERT_HEAD(&zfs_be_head, zfs_be, entries);
 	zfs_env_count++;



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