From fbe958861eef9522d1f5d12ca7fc16f1be145116 Mon Sep 17 00:00:00 2001 From: Allan Jude Date: Fri, 15 Jan 2016 05:45:10 +0000 Subject: [PATCH] Move init_zfs_bootenv to sys/boot/zfs/zfs.c instead of having a copy in each loader While here, add a filter to ignore special datasets MFC after: 3 days Sponsored by: ScaleEngine Inc. --- sys/boot/i386/loader/main.c | 29 --------------------------- sys/boot/userboot/userboot/main.c | 27 ------------------------- sys/boot/zfs/libzfs.h | 1 + sys/boot/zfs/zfs.c | 33 +++++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 56 deletions(-) diff --git a/sys/boot/i386/loader/main.c b/sys/boot/i386/loader/main.c index 644747e8151..c0782fc70e3 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 @@ -306,34 +305,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 a52550cbaea..e64bbc70241 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 @@ -199,32 +198,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) { diff --git a/sys/boot/zfs/libzfs.h b/sys/boot/zfs/libzfs.h index b28984958c9..ee64d1cf32d 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 c8b1284bc8c..8e6d420b4e9 100644 --- a/sys/boot/zfs/zfs.c +++ b/sys/boot/zfs/zfs.c @@ -709,6 +709,32 @@ 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); + /* 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); +} + int zfs_bootenv(const char *name) { @@ -779,8 +805,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++;