diff options
author | allanjude <allanjude@FreeBSD.org> | 2016-02-10 17:49:22 +0000 |
---|---|---|
committer | allanjude <allanjude@FreeBSD.org> | 2016-02-10 17:49:22 +0000 |
commit | c68557a9bd7089609250f173b1b1bdb906f8d141 (patch) | |
tree | 3bfbf76753f2cb774e7a17aebaebe4bec5db2f85 | |
parent | ab8cd691029d03339e2c5ca0d056aae390b2e7ac (diff) | |
download | FreeBSD-src-c68557a9bd7089609250f173b1b1bdb906f8d141.zip FreeBSD-src-c68557a9bd7089609250f173b1b1bdb906f8d141.tar.gz |
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.
-rw-r--r-- | sys/boot/efi/loader/main.c | 33 | ||||
-rw-r--r-- | sys/boot/i386/loader/main.c | 29 | ||||
-rw-r--r-- | sys/boot/userboot/userboot/main.c | 27 | ||||
-rw-r--r-- | sys/boot/zfs/libzfs.h | 1 | ||||
-rw-r--r-- | sys/boot/zfs/zfs.c | 31 |
5 files changed, 65 insertions, 56 deletions
diff --git a/sys/boot/efi/loader/main.c b/sys/boot/efi/loader/main.c index a90a87e..f796b4d 100644 --- a/sys/boot/efi/loader/main.c +++ b/sys/boot/efi/loader/main.c @@ -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 diff --git a/sys/boot/i386/loader/main.c b/sys/boot/i386/loader/main.c index be08271..6e783cd 100644 --- a/sys/boot/i386/loader/main.c +++ b/sys/boot/i386/loader/main.c @@ -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 diff --git a/sys/boot/userboot/userboot/main.c b/sys/boot/userboot/userboot/main.c index e4d546a..d8e9349 100644 --- a/sys/boot/userboot/userboot/main.c +++ b/sys/boot/userboot/userboot/main.c @@ -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]; diff --git a/sys/boot/zfs/libzfs.h b/sys/boot/zfs/libzfs.h index b289849..ee64d1c 100644 --- a/sys/boot/zfs/libzfs.h +++ b/sys/boot/zfs/libzfs.h @@ -62,6 +62,7 @@ int zfs_parsedev(struct zfs_devdesc *dev, const char *devspec, 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); diff --git a/sys/boot/zfs/zfs.c b/sys/boot/zfs/zfs.c index c339b2d..ef79cb4 100644 --- a/sys/boot/zfs/zfs.c +++ b/sys/boot/zfs/zfs.c @@ -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++; |